diff --git "a/shard_new_new_cleaned_v_text_16.csv" "b/shard_new_new_cleaned_v_text_16.csv"
new file mode 100644--- /dev/null
+++ "b/shard_new_new_cleaned_v_text_16.csv"
@@ -0,0 +1,282443 @@
+text
+"LIBAVFILTER_$MAJOR {
+ global: avfilter_*; av_*;
+ local: *;
+};
+"
+"LIBAVCODEC_$MAJOR {
+ global: av*;
+ audio_resample;
+ audio_resample_close;
+ #deprecated, remove after next bump
+ img_get_alpha_info;
+ dsputil_init;
+ ff_find_pix_fmt;
+ ff_framenum_to_drop_timecode;
+ ff_framenum_to_smtpe_timecode;
+ ff_raw_pix_fmt_tags;
+ ff_init_smtpe_timecode;
+ ff_fft*;
+ ff_mdct*;
+ ff_dct*;
+ ff_rdft*;
+ ff_prores_idct_put_10_sse2;
+ ff_simple_idct*;
+ ff_aanscales;
+ ff_faan*;
+ ff_mmx_idct;
+ ff_fdct*;
+ fdct_ifast;
+ j_rev_dct;
+ ff_mmxext_idct;
+ ff_idct_xvid*;
+ ff_jpeg_fdct*;
+ #XBMC's configure checks for ff_vdpau_vc1_decode_picture()
+ ff_vdpau_vc1_decode_picture;
+ local: *;
+};
+"
+"LIBPOSTPROC_$MAJOR {
+ global: postproc_*; pp_*;
+ local: *;
+};
+"
+"LIBSWSCALE_$MAJOR {
+ global: swscale_*; sws_*; ff_*;
+ local: *;
+};
+"
+"LIBAVDEVICE_$MAJOR {
+ global: avdevice_*;
+ local: *;
+};
+"
+"module my_and_module
+(
+ input a,
+ input b,
+ output wire ab
+);
+
+assign ab = a && b;
+
+endmodule
+"
+"class test;
+endclass
+"
+"class test;
+endclass
+"
+"class test;
+endclass
+"
+"`include ""defines.vh""
+
+module rtl
+#(
+ width = `WIDTH
+)
+(
+ input clk,
+ input rst_n,
+ input a,
+ input b,
+ output wire ab,
+ output reg Qab
+);
+
+wire [width-1:0] a_wire;
+
+my_and_module my_and_module(.a(a), .b(b), .ab(ab));
+
+always @(posedge clk or negedge rst_n) begin
+ if (!rst_n) begin
+ Qab <= 0;
+ end else begin
+ Qab <= ab;
+ end
+end
+
+endmodule
+"
+"//==============================================================================
+//\tFile:\t\t$URL: svn+ssh://repositorypub@repository.eecs.berkeley.edu/public/Projects/GateLib/branches/dev/Publications/Tutorials/Publications/EECS150/Labs/ChipScopeSerial/Framework/ParityGen.v $
+//\tVersion:\t$Revision: 26904 $
+//\tAuthor:\t\tGreg Gibeling (http://www.gdgib.com)
+//\tCopyright:\tCopyright 2003-2010 UC Berkeley
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tLicense
+//==============================================================================
+//\tCopyright (c) 2003-2010, Regents of the University of California
+//\tAll rights reserved.
+//
+//\tRedistribution and use in source and binary forms, with or without modification,
+//\tare permitted provided that the following conditions are met:
+//
+//\t\t- Redistributions of source code must retain the above copyright notice,
+//\t\t\tthis list of conditions and the following disclaimer.
+//\t\t- Redistributions in binary form must reproduce the above copyright
+//\t\t\tnotice, this list of conditions and the following disclaimer
+//\t\t\tin the documentation and/or other materials provided with the
+//\t\t\tdistribution.
+//\t\t- Neither the name of the University of California, Berkeley nor the
+//\t\t\tnames of its contributors may be used to endorse or promote
+//\t\t\tproducts derived from this software without specific prior
+//\t\t\twritten permission.
+//
+//\tTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND
+//\tANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//\tWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+//\tDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+//\tANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+//\t(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//\tLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+//\tANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//\t(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//\tSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================================
+
+//------------------------------------------------------------------------------
+//\tModule:\t\tParityGen
+//\tDesc:\t\tRS232/16550 selectable parity bit generator.
+//\tParams:\t\tParity:
+//\t\t\t\t\t\t0:\tNone
+//\t\t\t\t\t\t1:\tOdd
+//\t\t\t\t\t\t2:\tEven
+//\t\t\t\t\t\t3:\tMark
+//\t\t\t\t\t\t4:\tSpace
+//\t\t\t\tWidth:\tInput width (in bits)
+//------------------------------------------------------------------------------
+module\tParityGen(In, Out);
+\t//--------------------------------------------------------------------------
+\t//\tParameters
+\t//--------------------------------------------------------------------------
+\tparameter\t\t\t\tParity =\t\t\t\t0,
+\t\t\t\t\t\t\tWidth =\t\t\t\t\t8;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tI/O
+\t//--------------------------------------------------------------------------
+\tinput\t[Width-1:0]\t\tIn;
+\toutput reg\t\t\t\tOut;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tParity Computation
+\t//--------------------------------------------------------------------------
+\talways @ (In) begin
+\t\tcase (Parity)
+\t\t\t1: Out =\t\t\t\t\t\t\t\t~^In;
+\t\t\t2: Out =\t\t\t\t\t\t\t\t^In;
+\t\t\t3: Out =\t\t\t\t\t\t\t\t1;
+\t\t\t4: Out =\t\t\t\t\t\t\t\t0;
+\t\t\tdefault: Out =\t\t\t\t\t\t\t1\'b0;
+\t\tendcase
+\tend
+\t//--------------------------------------------------------------------------
+endmodule
+//------------------------------------------------------------------------------"
+"//==============================================================================
+//\tFile:\t\t$URL: svn+ssh://repositorypub@repository.eecs.berkeley.edu/public/Projects/GateLib/branches/dev/Firmware/UART/Hardware/UATransmitter.v $
+//\tVersion:\t$Revision: 26904 $
+//\tAuthor:\t\tGreg Gibeling (http://www.gdgib.com)
+//\tCopyright:\tCopyright 2003-2010 UC Berkeley
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tLicense
+//==============================================================================
+//\tCopyright (c) 2003-2010, Regents of the University of California
+//\tAll rights reserved.
+//
+//\tRedistribution and use in source and binary forms, with or without modification,
+//\tare permitted provided that the following conditions are met:
+//
+//\t\t- Redistributions of source code must retain the above copyright notice,
+//\t\t\tthis list of conditions and the following disclaimer.
+//\t\t- Redistributions in binary form must reproduce the above copyright
+//\t\t\tnotice, this list of conditions and the following disclaimer
+//\t\t\tin the documentation and/or other materials provided with the
+//\t\t\tdistribution.
+//\t\t- Neither the name of the University of California, Berkeley nor the
+//\t\t\tnames of its contributors may be used to endorse or promote
+//\t\t\tproducts derived from this software without specific prior
+//\t\t\twritten permission.
+//
+//\tTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND
+//\tANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//\tWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+//\tDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+//\tANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+//\t(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//\tLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+//\tANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//\t(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//\tSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tIncludes
+//==============================================================================
+`include ""Const.v""
+//==============================================================================
+
+//------------------------------------------------------------------------------
+//\tModule:\t\tUATransmitter
+//\tDesc:\t\tStandard Universal Asynchronous RS232/16550 type transmitter.
+//\tParams:\t\tClockFreq: Frequency (in Hz) of the ""Clock"" being fed to this
+//\t\t\t\t\t\tmodule.
+//\t\t\t\tBaud:\tDesired Baud rate. This is the rate at which this
+//\t\t\t\t\t\tmodule will send bits, and should be at most 1/4th
+//\t\t\t\t\t\tof the clock rate (or so).
+//\t\t\t\tWidth:\tWord width (in bits) of the words (bytes) send over
+//\t\t\t\t\t\tthe serial line.
+//\t\t\t\tParity:\tThe type of parity bit to be appended to each word of
+//\t\t\t\t\t\tdata.
+//\t\t\t\t\t\t0:\tNone
+//\t\t\t\t\t\t1:\tEven
+//\t\t\t\t\t\t2:\tOdd
+//\t\t\t\t\t\t3:\tMark
+//\t\t\t\t\t\t4:\tSpace
+//\t\t\t\tStopBits:The number of bit-periods to send the stop condition.
+//\t\t\t\t\t\tGenerally 1 or 2, though larger numbers are possible.
+//\tEx:\t\t\t(27000000, 9600, 8, 0, 1) Standard 9600baud 8-N-1 serial port
+//\t\t\t\t\t\tsettings used as the default by many devices, based
+//\t\t\t\t\t\ton a 27MHz clock.
+//------------------------------------------------------------------------------
+module UATransmitter(Clock, Reset, DataIn, DataInValid, DataInReady, SOut);
+\t//--------------------------------------------------------------------------
+\t//\tParameters
+\t//--------------------------------------------------------------------------
+\tparameter\t\t\t\tClockFreq =\t\t\t\t27000000,
+\t\t\t\t\t\t\tBaud =\t\t\t\t\t115200,
+\t\t\t\t\t\t\tWidth =\t\t\t\t\t8,
+\t\t\t\t\t\t\tParity =\t\t\t\t0,
+\t\t\t\t\t\t\tStopBits =\t\t\t\t1;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tLocal Parameters
+\t//--------------------------------------------------------------------------
+\t`ifdef MACROSAFE
+\tlocalparam\t\t\t\tDivisor =\t\t\t\tClockFreq / Baud,
+\t\t\t\t\t\t\tDivWidth =\t\t\t\t`log2(Divisor),
+\t\t\t\t\t\t\tCapture =\t\t\t\t(Divisor / 2),
+\t\t\t\t\t\t\tBitCount =\t\t\t\tWidth + StopBits + (Parity ? 1 : 0) + 1,
+\t\t\t\t\t\t\tBCWidth =\t\t\t\t`log2(BitCount + 1),
+\t\t\t\t\t\t\tActualBaud =\t\t\tClockFreq / Divisor;
+\t`endif
+
+\t`ifdef SIMULATION
+\tlocalparam real\t\t\tMaxBaud =\t\t\t\tClockFreq / ((Divisor * (BitCount - 0.5)) / BitCount),
+\t\t\t\t\t\t\tMinBaud =\t\t\t\tClockFreq / ((Divisor * (BitCount + 0.5)) / BitCount);
+\t`endif
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tConstant Debugging Statements
+\t//--------------------------------------------------------------------------
+\t`ifdef SIMULATION
+\t\tinitial begin
+\t\t\t$display(""DEBUG[%m @ %t]: UART Parameters"", $time);
+\t\t\t$display("" ClockFreq = %d"", ClockFreq);
+\t\t\t$display("" Baud = %d"", Baud);
+\t\t\t$display("" Width = %d"", Width);
+\t\t\t$display("" Parity = %d"", Parity);
+\t\t\t$display("" StopBits = %d"", StopBits);
+
+\t\t\t/*$display("" Divisor = %d"", Divisor);
+\t\t\t$display("" DivWidth = %d"", DivWidth);
+\t\t\t$display("" Capture = %d"", Capture);
+\t\t\t$display("" BitCount = %d"", BitCount);
+\t\t\t$display("" BCWidth = %d"", BCWidth);*/
+
+\t\t\t$display("" ActualBaud = %d"", ActualBaud);
+\t\t\t$display("" MaxBaud = %f"", MaxBaud);
+\t\t\t$display("" MinBaud = %f"", MinBaud);
+\t\tend
+\t`endif
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tSystem Inputs
+\t//--------------------------------------------------------------------------
+\tinput\t\t\t\t\tClock, Reset;\t
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tParallel Data Input
+\t//--------------------------------------------------------------------------
+\tinput\t[Width-1:0]\t\tDataIn;
+\tinput\t\t\t\t\tDataInValid;
+\toutput\t\t\t\t\tDataInReady;
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tSerial Interface
+\t//--------------------------------------------------------------------------
+\toutput\t\t\t\t\tSOut;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\t Wires and Regs
+\t//--------------------------------------------------------------------------
+\twire\t\t\t\t\tIntSOut;
+
+\twire\t[DivWidth-1:0]\tTxDivCount;
+\twire\t[BCWidth-1:0]\tTxBitCount;
+\twire\t[BitCount-1:0]\tTxData;
+\twire\t\t\t\t\tTxShiftEnable, TxRunning, TxBit, TxStart, TxParity;
+\twire\t[BitCount-1:0]\tDataInAugmented;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tAssigns and Decodes
+\t//--------------------------------------------------------------------------
+\tassign\tTxShiftEnable =\t\t\t\t\t\t\t(TxDivCount == (Divisor - 1));
+\tassign\tTxRunning =\t\t\t\t\t\t\t\t(TxBitCount < BitCount);
+\tassign\tTxBit =\t\t\t\t\t\t\t\t\tTxRunning & TxShiftEnable;
+\tassign\tTxStart =\t\t\t\t\t\t\t\tDataInValid & DataInReady;
+
+\tassign\tDataInReady =\t\t\t\t\t\t\t~TxRunning & ~Reset;
+\tassign\tDataInAugmented =\t\t\t\t\t\tParity ? {{StopBits{1\'b1}}, TxParity, DataIn, 1\'b0} : {{StopBits{1\'b1}}, DataIn, 1\'b0};
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tIO Register
+\t//--------------------------------------------------------------------------
+\tIORegister\t\tIOR(\t\t.Clock(\t\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\t1\'b0),
+\t\t\t\t\t\t\t\t.Set(\t\t\t\t1\'b0),
+\t\t\t\t\t\t\t\t.Enable(\t\t\t1\'b1),
+\t\t\t\t\t\t\t\t.In(\t\t\t\tIntSOut),
+\t\t\t\t\t\t\t\t.Out(\t\t\t\tSOut));
+\tdefparam\t\tIOR.Width =\t\t\t\t\t\t1;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tClock Divider Counter
+\t//--------------------------------------------------------------------------
+\tCounter\t\t\tTxDivCounter(.Clock(\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\tReset | (TxDivCount == (Divisor-1)) | TxStart),
+\t\t\t\t\t\t\t\t.Set(\t\t\t\t1\'b0),
+\t\t\t\t\t\t\t\t.Load(\t\t\t\t1\'b0),
+\t\t\t\t\t\t\t\t.Enable(\t\t\t1\'b1),
+\t\t\t\t\t\t\t\t.In(\t\t\t\t{DivWidth{1\'bx}}),
+\t\t\t\t\t\t\t\t.Count(\t\t\t\tTxDivCount));
+\tdefparam\t\tTxDivCounter.Width =\t\t\tDivWidth;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tBit Counter
+\t//--------------------------------------------------------------------------
+\tCounter\t\t\tTxBitCounter(.Clock(\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\tTxStart),
+\t\t\t\t\t\t\t\t.Set(\t\t\t\tReset),
+\t\t\t\t\t\t\t\t.Load(\t\t\t\t1\'b0),
+\t\t\t\t\t\t\t\t.Enable(\t\t\tTxBit),
+\t\t\t\t\t\t\t\t.In(\t\t\t\t{BCWidth{1\'bx}}),
+\t\t\t\t\t\t\t\t.Count(\t\t\t\tTxBitCount));
+\tdefparam\t\tTxBitCounter.Width =\t\t\tBCWidth;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tShift Register and Bit Reversal
+\t//--------------------------------------------------------------------------
+\tShiftRegister\tTxShift(\t.PIn(\t\t\t\tReset ? {BitCount{1\'b1}} : TxData),
+\t\t\t\t\t\t\t\t.SIn(\t\t\t\t1\'b1),
+\t\t\t\t\t\t\t\t.POut(\t\t\t\t),
+\t\t\t\t\t\t\t\t.SOut(\t\t\t\tIntSOut),
+\t\t\t\t\t\t\t\t.Load(\t\t\t\tTxStart | Reset),
+\t\t\t\t\t\t\t\t.Enable(\t\t\tTxShiftEnable),
+\t\t\t\t\t\t\t\t.Clock(\t\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\t1\'b0));
+\tdefparam\t\tTxShift.PWidth =\t\t\t\tBitCount;
+\tdefparam\t\tTxShift.SWidth =\t\t\t\t1;
+\tReverse\t\t\tTxReverse(\t.In(\t\t\t\tDataInAugmented),
+\t\t\t\t\t\t\t\t.Out(\t\t\t\tTxData));
+\tdefparam\t\tTxReverse.Width =\t\t\t\tBitCount;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tParity Generator
+\t//--------------------------------------------------------------------------
+\tParityGen\t\tTxParityGen(.In(\t\t\t\tDataIn),
+\t\t\t\t\t\t\t\t.Out(\t\t\t\tTxParity));
+\tdefparam\t\tTxParityGen.Width =\t\t\t\tWidth;
+\tdefparam\t\tTxParityGen.Parity =\t\t\tParity;
+\t//--------------------------------------------------------------------------
+endmodule
+//------------------------------------------------------------------------------
+"
+"//==============================================================================
+//\tFile:\t\t$URL: svn+ssh://repositorypub@repository.eecs.berkeley.edu/public/Projects/GateLib/branches/dev/Publications/Tutorials/Publications/EECS150/Labs/ChipScopeSerial/Framework/Counter.v $
+//\tVersion:\t$Revision: 26904 $
+//\tAuthor:\t\tGreg Gibeling (http://www.gdgib.com)
+//\tCopyright:\tCopyright 2003-2010 UC Berkeley
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tLicense
+//==============================================================================
+//\tCopyright (c) 2003-2010, Regents of the University of California
+//\tAll rights reserved.
+//
+//\tRedistribution and use in source and binary forms, with or without modification,
+//\tare permitted provided that the following conditions are met:
+//
+//\t\t- Redistributions of source code must retain the above copyright notice,
+//\t\t\tthis list of conditions and the following disclaimer.
+//\t\t- Redistributions in binary form must reproduce the above copyright
+//\t\t\tnotice, this list of conditions and the following disclaimer
+//\t\t\tin the documentation and/or other materials provided with the
+//\t\t\tdistribution.
+//\t\t- Neither the name of the University of California, Berkeley nor the
+//\t\t\tnames of its contributors may be used to endorse or promote
+//\t\t\tproducts derived from this software without specific prior
+//\t\t\twritten permission.
+//
+//\tTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND
+//\tANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//\tWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+//\tDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+//\tANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+//\t(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//\tLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+//\tANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//\t(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//\tSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================================
+
+//------------------------------------------------------------------------------
+//\tModule:\t\tCounter
+//\tDesc:\t\tStandard binary counter.
+//\tParams:\t\tWidth:\tThe bitwidth of the counter.
+//\t\t\t\tLimited:Should the counter saturate rather than roll over?
+//\t\t\t\tDown:\tShould the counter count down (decrement) rather than
+//\t\t\t\t\t\tup (increment)? Note that this will, obviously, affect
+//\t\t\t\t\t\tthe limit, if used.
+//\tAuthor:\t\tGreg Gibeling
+//\tVersion:\t$Revision: 26904 $
+//------------------------------------------------------------------------------
+module\tCounter(Clock, Reset, Set, Load, Enable, In, Count);
+\t//--------------------------------------------------------------------------
+\t//\tParameters
+\t//--------------------------------------------------------------------------
+\tparameter\t\t\t\tWidth = \t\t\t\t32,
+\t\t\t\t\t\t\tLimited =\t\t\t\t0,
+\t\t\t\t\t\t\tDown =\t\t\t\t\t0,
+\t\t\t\t\t\t\tInitial =\t\t\t\t{Width{1\'bx}},
+\t\t\t\t\t\t\tAsyncReset =\t\t\t0,
+\t\t\t\t\t\t\tAsyncSet =\t\t\t\t0;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tI/O
+\t//--------------------------------------------------------------------------
+\tinput\t\t\t\t\tClock, Reset, Set, Load, Enable;
+\tinput\t[Width-1:0]\t\tIn;
+\toutput\t[Width-1:0]\t\tCount;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tWires
+\t//--------------------------------------------------------------------------
+\twire\t\t\t\t\tNoLimit;
+\t
+\twire\t\t\t\t\tRegEnable;
+\twire\t[Width-1:0]\t\tRegIn;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tAssigns
+\t//--------------------------------------------------------------------------
+\tassign\tNoLimit =\t\t\t\t\t\t\t\t!Limited;
+\t
+\tassign\tRegEnable =\t\t\t\t\t\t\t\tLoad | (Enable & (NoLimit | (Down ? |Count : ~&Count)));
+\tassign\tRegIn =\t\t\t\t\t\t\t\t\tLoad ? In : (Down ? (Count - 1) : (Count + 1));
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tRegister
+\t//--------------------------------------------------------------------------
+\tRegister\t\t#(\t\t\t.Width(\t\t\t\tWidth),
+\t\t\t\t\t\t\t\t.Initial(\t\t\tInitial),
+\t\t\t\t\t\t\t\t.AsyncReset(\t\tAsyncReset),
+\t\t\t\t\t\t\t\t.AsyncSet(\t\t\tAsyncSet))
+\t\t\t\t\tRegister(\t.Clock(\t\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\tReset),
+\t\t\t\t\t\t\t\t.Set(\t\t\t\tSet),
+\t\t\t\t\t\t\t\t.Enable(\t\t\tRegEnable),
+\t\t\t\t\t\t\t\t.In(\t\t\t\tRegIn),
+\t\t\t\t\t\t\t\t.Out(\t\t\t\tCount));
+\t//--------------------------------------------------------------------------
+endmodule
+//------------------------------------------------------------------------------
+"
+"//==============================================================================
+//\tFile:\t\t$URL: svn+ssh://repositorypub@repository.eecs.berkeley.edu/public/Projects/GateLib/branches/dev/Publications/Tutorials/Publications/EECS150/Labs/ChipScopeSerial/Framework/IORegister.v $
+//\tVersion:\t$Revision: 26904 $
+//\tAuthor:\t\tGreg Gibeling (http://www.gdgib.com)
+//\tCopyright:\tCopyright 2003-2010 UC Berkeley
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tLicense
+//==============================================================================
+//\tCopyright (c) 2005-2010, Regents of the University of California
+//\tAll rights reserved.
+//
+//\tRedistribution and use in source and binary forms, with or without modification,
+//\tare permitted provided that the following conditions are met:
+//
+//\t\t- Redistributions of source code must retain the above copyright notice,
+//\t\t\tthis list of conditions and the following disclaimer.
+//\t\t- Redistributions in binary form must reproduce the above copyright
+//\t\t\tnotice, this list of conditions and the following disclaimer
+//\t\t\tin the documentation and/or other materials provided with the
+//\t\t\tdistribution.
+//\t\t- Neither the name of the University of California, Berkeley nor the
+//\t\t\tnames of its contributors may be used to endorse or promote
+//\t\t\tproducts derived from this software without specific prior
+//\t\t\twritten permission.
+//
+//\tTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND
+//\tANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//\tWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+//\tDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+//\tANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+//\t(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//\tLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+//\tANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//\t(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//\tSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================================
+
+//------------------------------------------------------------------------------
+//\tModule:\t\tIORegister
+//\tDesc:\t\tA register which should be packed in to IO pads.
+//\tAuthor:\t\tGreg Gibeling
+//\tVersion:\t$Revision: 26904 $
+//------------------------------------------------------------------------------
+module\tIORegister(Clock, Reset, Set, Enable, In, Out);
+\t//--------------------------------------------------------------------------
+\t//\tParameters
+\t//--------------------------------------------------------------------------
+\tparameter\t\t\t\tWidth = \t\t\t\t32,
+\t\t\t\t\t\t\tInitial =\t\t\t\t{Width{1\'bx}},
+\t\t\t\t\t\t\tAsyncReset =\t\t\t0,
+\t\t\t\t\t\t\tAsyncSet =\t\t\t\t0,
+\t\t\t\t\t\t\tResetValue =\t\t\t{Width{1\'b0}},
+\t\t\t\t\t\t\tSetValue =\t\t\t\t{Width{1\'b1}};
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tInputs & Outputs
+\t//--------------------------------------------------------------------------
+\tinput\t\t\t\t\tClock, Enable, Reset, Set;
+\tinput\t[Width-1:0]\t\tIn;
+\toutput reg [Width-1:0]\tOut =\t\t\t\t\tInitial /* synthesis syn_useioff = 1 iob = true useioff = 1 */;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tBehavioral Register
+\t//--------------------------------------------------------------------------
+\tgenerate if (AsyncReset) begin:AR
+\t\tif (AsyncSet) begin:AS
+\t\t\talways @ (posedge Clock or posedge Reset or posedge Set) begin
+\t\t\t\tif (Reset) Out <=\t\t\t\t\tResetValue;
+\t\t\t\telse if (Set) Out <=\t\t\t\tSetValue;
+\t\t\t\telse if (Enable) Out <=\t\t\t\tIn;
+\t\t\tend
+\t\tend else begin:SS
+\t\t\talways @ (posedge Clock or posedge Reset) begin
+\t\t\t\tif (Reset) Out <=\t\t\t\t\tResetValue;
+\t\t\t\telse if (Set) Out <=\t\t\t\tSetValue;
+\t\t\t\telse if (Enable) Out <=\t\t\t\tIn;
+\t\t\tend
+\t\tend
+\tend else begin:SR
+\t\tif (AsyncSet) begin:AS
+\t\t\talways @ (posedge Clock or posedge Set) begin
+\t\t\t\tif (Reset) Out <=\t\t\t\t\tResetValue;
+\t\t\t\telse if (Set) Out <=\t\t\t\tSetValue;
+\t\t\t\telse if (Enable) Out <=\t\t\t\tIn;
+\t\t\tend
+\t\tend else begin:SS
+\t\t\talways @ (posedge Clock) begin
+\t\t\t\tif (Reset) Out <=\t\t\t\t\tResetValue;
+\t\t\t\telse if (Set) Out <=\t\t\t\tSetValue;
+\t\t\t\telse if (Enable) Out <=\t\t\t\tIn;
+\t\t\tend
+\t\tend
+\tend endgenerate
+\t//--------------------------------------------------------------------------
+endmodule
+//------------------------------------------------------------------------------
+"
+"//==============================================================================
+//\tFile:\t\t$URL: svn+ssh://repositorypub@repository.eecs.berkeley.edu/public/Projects/GateLib/branches/dev/Firmware/UART/Hardware/UART.v $
+//\tVersion:\t$Revision: 26904 $
+//\tAuthor:\t\tGreg Gibeling (http://www.gdgib.com)
+//\tCopyright:\tCopyright 2003-2010 UC Berkeley
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tLicense
+//==============================================================================
+//\tCopyright (c) 2003-2010, Regents of the University of California
+//\tAll rights reserved.
+//
+//\tRedistribution and use in source and binary forms, with or without modification,
+//\tare permitted provided that the following conditions are met:
+//
+//\t\t- Redistributions of source code must retain the above copyright notice,
+//\t\t\tthis list of conditions and the following disclaimer.
+//\t\t- Redistributions in binary form must reproduce the above copyright
+//\t\t\tnotice, this list of conditions and the following disclaimer
+//\t\t\tin the documentation and/or other materials provided with the
+//\t\t\tdistribution.
+//\t\t- Neither the name of the University of California, Berkeley nor the
+//\t\t\tnames of its contributors may be used to endorse or promote
+//\t\t\tproducts derived from this software without specific prior
+//\t\t\twritten permission.
+//
+//\tTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND
+//\tANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//\tWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+//\tDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+//\tANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+//\t(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//\tLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+//\tANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//\t(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//\tSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tIncludes
+//==============================================================================
+`include ""Const.v""
+//==============================================================================
+
+//------------------------------------------------------------------------------
+//\tModule:\t\tUART
+//\tDesc:\t\tStandard Universal Asynchronous RS232/16550 type transceiver.
+//\tParams:\t\tClockFreq: Frequency (in Hz) of the ""Clock"" being fed to this
+//\t\t\t\t\t\tmodule.
+//\t\t\t\tBaud:\tDesired Baud rate. This is the rate at which this
+//\t\t\t\t\t\tmodule will send bits, and should be at most 1/4th
+//\t\t\t\t\t\tof the clock rate (or so).
+//\t\t\t\tWidth:\tWord width (in bits) of the words (bytes) send over
+//\t\t\t\t\t\tthe serial line.
+//\t\t\t\tParity:\tThe type of parity bit to be appended to each word of
+//\t\t\t\t\t\tdata.
+//\t\t\t\t\t\t0:\tNone
+//\t\t\t\t\t\t1:\tOdd
+//\t\t\t\t\t\t2:\tEven
+//\t\t\t\t\t\t3:\tMark
+//\t\t\t\t\t\t4:\tSpace
+//\t\t\t\tStopBits:The number of bit-periods to send the stop condition.
+//\t\t\t\t\t\tGenerally 1 or 2, though larger numbers are possible.
+//\tEx:\t\t\t(27000000, 9600, 8, 0, 1) Standard 9600baud 8-N-1 serial port
+//\t\t\t\t\t\tsettings used as the default by many devices, based
+//\t\t\t\t\t\ton a 27MHz clock.
+//------------------------------------------------------------------------------
+module\tUART(Clock, Reset, DataIn, DataInValid, DataInReady, DataOut, DataOutValid, DataOutReady, SIn, SOut);
+\t//--------------------------------------------------------------------------
+\t//\tParameters
+\t//--------------------------------------------------------------------------
+\tparameter\t\t\t\tClockFreq =\t\t\t\t27000000,
+\t\t\t\t\t\t\tBaud =\t\t\t\t\t115200,
+\t\t\t\t\t\t\tWidth =\t\t\t\t\t8,
+\t\t\t\t\t\t\tParity =\t\t\t\t0,
+\t\t\t\t\t\t\tStopBits =\t\t\t\t1;
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tSystem Inputs
+\t//--------------------------------------------------------------------------
+\tinput\t\t\t\t\tClock, Reset;\t
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tParallel Data Input
+\t//--------------------------------------------------------------------------
+\tinput\t[Width-1:0]\t\tDataIn;
+\tinput\t\t\t\t\tDataInValid;
+\toutput\t\t\t\t\tDataInReady;
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tParallel Data Output
+\t//--------------------------------------------------------------------------
+\toutput\t[Width-1:0]\t\tDataOut;
+\toutput\t\t\t\t\tDataOutValid;
+\tinput\t\t\t\t\tDataOutReady;
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tSerial Interface
+\t//--------------------------------------------------------------------------
+\tinput\t\t\t\t\tSIn;
+\toutput\t\t\t\t\tSOut;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tTransmitter
+\t//--------------------------------------------------------------------------
+\tUATransmitter\tTX(\t\t\t.Clock(\t\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\tReset),
+\t\t\t\t\t\t\t\t.DataIn(\t\t\tDataIn),
+\t\t\t\t\t\t\t\t.DataInValid(\t\tDataInValid),
+\t\t\t\t\t\t\t\t.DataInReady(\t\tDataInReady),
+\t\t\t\t\t\t\t\t.SOut(\t\t\t\tSOut));
+\tdefparam\t\tTX.ClockFreq =\t\t\t\t\tClockFreq;
+\tdefparam\t\tTX.Baud =\t\t\t\t\t\tBaud;
+\tdefparam\t\tTX.Width =\t\t\t\t\t\tWidth;
+\tdefparam\t\tTX.Parity =\t\t\t\t\t\tParity;
+\tdefparam\t\tTX.StopBits =\t\t\t\t\tStopBits;
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tReceiver
+\t//--------------------------------------------------------------------------
+\tUAReceiver\t\tRX(\t\t\t.Clock(\t\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\tReset),
+\t\t\t\t\t\t\t\t.DataOut(\t\t\tDataOut),
+\t\t\t\t\t\t\t\t.DataOutValid(\t\tDataOutValid),
+\t\t\t\t\t\t\t\t.DataOutReady(\t\tDataOutReady),
+\t\t\t\t\t\t\t\t.SIn(\t\t\t\tSIn));
+\tdefparam\t\tRX.ClockFreq =\t\t\t\t\tClockFreq;
+\tdefparam\t\tRX.Baud =\t\t\t\t\t\tBaud;
+\tdefparam\t\tRX.Width =\t\t\t\t\t\tWidth;
+\tdefparam\t\tRX.Parity =\t\t\t\t\t\tParity;
+\tdefparam\t\tRX.StopBits =\t\t\t\t\tStopBits;
+\t//--------------------------------------------------------------------------
+endmodule
+//------------------------------------------------------------------------------"
+"//==============================================================================
+//\tFile:\t\t$URL: svn+ssh://repositorypub@repository.eecs.berkeley.edu/public/Projects/GateLib/branches/dev/Publications/Tutorials/Publications/EECS150/Labs/ChipScopeSerial/Framework/Reverse.v $
+//\tVersion:\t$Revision: 26904 $
+//\tAuthor:\t\tGreg Gibeling (http://www.gdgib.com)
+//\tCopyright:\tCopyright 2003-2010 UC Berkeley
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tLicense
+//==============================================================================
+//\tCopyright (c) 2003-2010, Regents of the University of California
+//\tAll rights reserved.
+//
+//\tRedistribution and use in source and binary forms, with or without modification,
+//\tare permitted provided that the following conditions are met:
+//
+//\t\t- Redistributions of source code must retain the above copyright notice,
+//\t\t\tthis list of conditions and the following disclaimer.
+//\t\t- Redistributions in binary form must reproduce the above copyright
+//\t\t\tnotice, this list of conditions and the following disclaimer
+//\t\t\tin the documentation and/or other materials provided with the
+//\t\t\tdistribution.
+//\t\t- Neither the name of the University of California, Berkeley nor the
+//\t\t\tnames of its contributors may be used to endorse or promote
+//\t\t\tproducts derived from this software without specific prior
+//\t\t\twritten permission.
+//
+//\tTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND
+//\tANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//\tWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+//\tDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+//\tANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+//\t(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//\tLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+//\tANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//\t(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//\tSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================================
+
+//------------------------------------------------------------------------------
+//\tModule:\t\tReverse
+//\tDesc:\t\tParameterized bit reversal module: a fancy wire.
+//\t\t\t\tEssentially this module is just a very complex set of wires, all
+//\t\t\t\tit does it reverse the bits in a bus. A ""group"" is a group of
+//\t\t\t\t""chunks"" that should be reversed, ""set"" is the number of
+//\t\t\t\t""chunks"" per ""group"". This module will reverse the order of the
+//\t\t\t\t""chunks"" within each ""group"".
+//\tParams:\t\tWidth:\tThis sets the input and output bus width of the module
+//\t\t\t\tChunk:\tThis is the size of a block of wires which should
+//\t\t\t\t\t\tbe kept in order. The default is 1 meaning each wire
+//\t\t\t\t\t\tshould be treated separately.
+//\t\t\t\tSet:\tThe number of chunks in a set, the default is the
+//\t\t\t\t\t\tbitwidth of the input bus, meaning that the whole input
+//\t\t\t\t\t\tbus is treated as a set.
+//\tEx:\t\t\t(32,1,32) Will reverse the bit order of a 32bit bus.
+//\t\t\t\t(32,1,8)Will reverse the MSb/LSb order of the bytes in a 32bit
+//\t\t\t\t\t\tbus.
+//\t\t\t\t(32,4,2)will reverse the MSNibble/LSNibble of each byte in a
+//\t\t\t\t\t\t32bit bus.
+//\tAuthor:\t\tGreg Gibeling
+//\tVersion:\t$Revision: 26904 $
+//------------------------------------------------------------------------------
+module\tReverse(In, Out);
+\t//--------------------------------------------------------------------------
+\t//\tParameters
+\t//--------------------------------------------------------------------------
+\tparameter\t\t\t\tWidth =\t\t\t\t\t32,
+\t\t\t\t\t\t\tChunk =\t\t\t\t\t1,
+\t\t\t\t\t\t\tSet =\t\t\t\t\tWidth;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tConstants
+\t//--------------------------------------------------------------------------
+\tlocalparam\t\t\t\tGroup =\t\t\t\t\tChunk * Set;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tI/O
+\t//--------------------------------------------------------------------------
+\tinput\t[Width-1:0]\t\tIn;
+\toutput\t[Width-1:0]\t\tOut;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tA Complicated Wire
+\t//--------------------------------------------------------------------------
+\tgenvar\t\t\t\t\ti;
+\tgenerate for(i = 0; i < Width; i = i + 1) begin:REVERSE
+\t\tassign Out[i] =\t\t\t\t\t\t\t\tIn[((Set - 1 - ((i % Group) / Chunk)) * Chunk) + ((i % Group) % Chunk) + ((i / Group) * Group)];
+\tend endgenerate
+\t//--------------------------------------------------------------------------
+endmodule
+//------------------------------------------------------------------------------
+"
+"//==============================================================================
+//\tFile:\t\t$URL: svn+ssh://repositorypub@repository.eecs.berkeley.edu/public/Projects/GateLib/branches/dev/Publications/Tutorials/Publications/EECS150/Labs/ChipScopeSerial/Framework/ShiftRegister.v $
+//\tVersion:\t$Revision: 26904 $
+//\tAuthor:\t\tGreg Gibeling (http://www.gdgib.com)
+//\tCopyright:\tCopyright 2003-2010 UC Berkeley
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tLicense
+//==============================================================================
+//\tCopyright (c) 2005-2010, Regents of the University of California
+//\tAll rights reserved.
+//
+//\tRedistribution and use in source and binary forms, with or without modification,
+//\tare permitted provided that the following conditions are met:
+//
+//\t\t- Redistributions of source code must retain the above copyright notice,
+//\t\t\tthis list of conditions and the following disclaimer.
+//\t\t- Redistributions in binary form must reproduce the above copyright
+//\t\t\tnotice, this list of conditions and the following disclaimer
+//\t\t\tin the documentation and/or other materials provided with the
+//\t\t\tdistribution.
+//\t\t- Neither the name of the University of California, Berkeley nor the
+//\t\t\tnames of its contributors may be used to endorse or promote
+//\t\t\tproducts derived from this software without specific prior
+//\t\t\twritten permission.
+//
+//\tTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND
+//\tANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//\tWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+//\tDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+//\tANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+//\t(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//\tLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+//\tANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//\t(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//\tSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================================
+
+//------------------------------------------------------------------------------
+//\tModule:\t\tShiftRegister
+//\tDesc:\t\tThis is a general parallel to serial and serial to parallel
+//\t\t\t\tconverter. Note that it can work with \'serial\' data streams
+//\t\t\t\tthat are more than a single bit wide. This is useful for
+//\t\t\t\texample when a signal must cross a 32b/8b boundary.
+//\t\t\t\tThis also means it can be used to delay a signal quite easily.
+//\tParams:\t\tPWidth:\tSets the bitwidth of the parallel data (both in and
+//\t\t\t\t\t\tout of the module)
+//\t\t\t\tSWidth:\tSets the bitwidth of the serial data (both in and out
+//\t\t\t\t\t\tof the module)
+//\t\t\t\tReverse:Shift MSb to LSb?
+//\tEx:\t\t\t(32,1) will convert 32bit wide data into 1bit serial data
+//\t\t\t\t(32,8) will convert 32bit words into bytes
+//\tAuthor:\t\tGreg Gibeling
+//\tVersion:\t$Revision: 26904 $
+//------------------------------------------------------------------------------
+module\tShiftRegister(Clock, Reset, Load, Enable, PIn, SIn, POut, SOut);
+\t//--------------------------------------------------------------------------
+\t//\tParameters
+\t//--------------------------------------------------------------------------
+\tparameter\t\t\t\tPWidth =\t\t\t\t32,\t\t// The parallel width
+\t\t\t\t\t\t\tSWidth =\t\t\t\t1,\t\t// The serial width
+\t\t\t\t\t\t\tReverse =\t\t\t\t0,
+\t\t\t\t\t\t\tInitial =\t\t\t\t{PWidth{1\'bx}},
+\t\t\t\t\t\t\tAsyncReset =\t\t\t0;
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tControl Inputs
+\t//--------------------------------------------------------------------------
+\tinput\t\t\t\t\tClock, Reset, Load, Enable;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tParallel and Serial I/O
+\t//--------------------------------------------------------------------------
+\tinput\t[PWidth-1:0]\tPIn;
+\tinput\t[SWidth-1:0]\tSIn;
+\toutput \t[PWidth-1:0]\tPOut;
+\toutput\t[SWidth-1:0]\tSOut;
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tAssigns
+\t//--------------------------------------------------------------------------
+\tassign\tSOut =\t\t\t\t\t\t\t\t\tReverse ? POut[SWidth-1:0] : POut[PWidth-1:PWidth-SWidth];
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tBehavioral Shift Register Core
+\t//--------------------------------------------------------------------------
+\tgenerate if (PWidth == SWidth) begin:REG
+\t\tHardRegister #(\t\t\t.Width(\t\t\t\tPWidth),
+\t\t\t\t\t\t\t\t.Initial(\t\t\tInitial),
+\t\t\t\t\t\t\t\t.AsyncReset(\t\tAsyncReset))
+\t\t\t\t\tRegister(\t.Clock(\t\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\tReset),
+\t\t\t\t\t\t\t\t.Set(\t\t\t\t1\'b0),
+\t\t\t\t\t\t\t\t.Enable(\t\t\tLoad | Enable),
+\t\t\t\t\t\t\t\t.In(\t\t\t\tLoad ? PIn : SIn),
+\t\t\t\t\t\t\t\t.Out(\t\t\t\tPOut));
+\tend else begin:SHIFT
+\t\tHardRegister #(\t\t\t.Width(\t\t\t\tPWidth),
+\t\t\t\t\t\t\t\t.Initial(\t\t\tInitial),
+\t\t\t\t\t\t\t\t.AsyncReset(\t\tAsyncReset))
+\t\t\t\t\tRegister(\t.Clock(\t\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\tReset),
+\t\t\t\t\t\t\t\t.Set(\t\t\t\t1\'b0),
+\t\t\t\t\t\t\t\t.Enable(\t\t\tLoad | Enable),
+\t\t\t\t\t\t\t\t.In(\t\t\t\tLoad ? PIn : (Reverse ? {SIn, POut[PWidth-1:SWidth]} : {POut[PWidth-SWidth-1:0], SIn})),
+\t\t\t\t\t\t\t\t.Out(\t\t\t\tPOut));
+\tend endgenerate
+\t//--------------------------------------------------------------------------
+endmodule
+//------------------------------------------------------------------------------
+"
+"//==============================================================================
+//\tFile:\t\t$URL: svn+ssh://repositorypub@repository.eecs.berkeley.edu/public/Projects/GateLib/branches/dev/Publications/Tutorials/Publications/EECS150/Labs/ChipScopeSerial/Framework/HardRegister.v $
+//\tVersion:\t$Revision: 26904 $
+//\tAuthor:\t\tGreg Gibeling (http://www.gdgib.com)
+//\tCopyright:\tCopyright 2003-2010 UC Berkeley
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tLicense
+//==============================================================================
+//\tCopyright (c) 2005-2010, Regents of the University of California
+//\tAll rights reserved.
+//
+//\tRedistribution and use in source and binary forms, with or without modification,
+//\tare permitted provided that the following conditions are met:
+//
+//\t\t- Redistributions of source code must retain the above copyright notice,
+//\t\t\tthis list of conditions and the following disclaimer.
+//\t\t- Redistributions in binary form must reproduce the above copyright
+//\t\t\tnotice, this list of conditions and the following disclaimer
+//\t\t\tin the documentation and/or other materials provided with the
+//\t\t\tdistribution.
+//\t\t- Neither the name of the University of California, Berkeley nor the
+//\t\t\tnames of its contributors may be used to endorse or promote
+//\t\t\tproducts derived from this software without specific prior
+//\t\t\twritten permission.
+//
+//\tTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND
+//\tANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//\tWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+//\tDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+//\tANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+//\t(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//\tLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+//\tANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//\t(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//\tSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================================
+
+//------------------------------------------------------------------------------
+//\tModule:\t\tHardRegister
+//\tDesc:\t\tA register which should not be removed by synthesis
+//\tAuthor:\t\tGreg Gibeling
+//\tVersion:\t$Revision: 26904 $
+//------------------------------------------------------------------------------
+module\tHardRegister(Clock, Reset, Set, Enable, In, Out) /* synthesis syn_hier = ""hard"" */;
+\t//--------------------------------------------------------------------------
+\t//\tParameters
+\t//--------------------------------------------------------------------------
+\tparameter\t\t\t\tWidth = \t\t\t\t32,
+\t\t\t\t\t\t\tInitial =\t\t\t\t{Width{1\'bx}},
+\t\t\t\t\t\t\tAsyncReset =\t\t\t0,
+\t\t\t\t\t\t\tAsyncSet =\t\t\t\t0,
+\t\t\t\t\t\t\tResetValue =\t\t\t{Width{1\'b0}},
+\t\t\t\t\t\t\tSetValue =\t\t\t\t{Width{1\'b1}};
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tInputs & Outputs
+\t//--------------------------------------------------------------------------
+\tinput\t\t\t\t\tClock, Enable, Reset, Set;
+\tinput\t[Width-1:0]\t\tIn;
+\toutput reg [Width-1:0]\tOut =\t\t\t\t\tInitial /* synthesis syn_keep = 1 */;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tBehavioral Register
+\t//--------------------------------------------------------------------------
+\tgenerate if (AsyncReset) begin:AR
+\t\tif (AsyncSet) begin:AS
+\t\t\talways @ (posedge Clock or posedge Reset or posedge Set) begin
+\t\t\t\tif (Reset) Out <=\t\t\t\t\tResetValue;
+\t\t\t\telse if (Set) Out <=\t\t\t\tSetValue;
+\t\t\t\telse if (Enable) Out <=\t\t\t\tIn;
+\t\t\tend
+\t\tend else begin:SS
+\t\t\talways @ (posedge Clock or posedge Reset) begin
+\t\t\t\tif (Reset) Out <=\t\t\t\t\tResetValue;
+\t\t\t\telse if (Set) Out <=\t\t\t\tSetValue;
+\t\t\t\telse if (Enable) Out <=\t\t\t\tIn;
+\t\t\tend
+\t\tend
+\tend else begin:SR
+\t\tif (AsyncSet) begin:AS
+\t\t\talways @ (posedge Clock or posedge Set) begin
+\t\t\t\tif (Reset) Out <=\t\t\t\t\tResetValue;
+\t\t\t\telse if (Set) Out <=\t\t\t\tSetValue;
+\t\t\t\telse if (Enable) Out <=\t\t\t\tIn;
+\t\t\tend
+\t\tend else begin:SS
+\t\t\talways @ (posedge Clock) begin
+\t\t\t\tif (Reset) Out <=\t\t\t\t\tResetValue;
+\t\t\t\telse if (Set) Out <=\t\t\t\tSetValue;
+\t\t\t\telse if (Enable) Out <=\t\t\t\tIn;
+\t\t\tend
+\t\tend
+\tend endgenerate
+\t//--------------------------------------------------------------------------
+endmodule
+//------------------------------------------------------------------------------
+"
+"//==============================================================================
+//\tFile:\t\t$URL: svn+ssh://repositorypub@repository.eecs.berkeley.edu/public/Projects/GateLib/branches/dev/Firmware/UART/Hardware/UAReceiver.v $
+//\tVersion:\t$Revision: 26904 $
+//\tAuthor:\t\tGreg Gibeling (http://www.gdgib.com)
+//\tCopyright:\tCopyright 2003-2010 UC Berkeley
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tLicense
+//==============================================================================
+//\tCopyright (c) 2003-2010, Regents of the University of California
+//\tAll rights reserved.
+//
+//\tRedistribution and use in source and binary forms, with or without modification,
+//\tare permitted provided that the following conditions are met:
+//
+//\t\t- Redistributions of source code must retain the above copyright notice,
+//\t\t\tthis list of conditions and the following disclaimer.
+//\t\t- Redistributions in binary form must reproduce the above copyright
+//\t\t\tnotice, this list of conditions and the following disclaimer
+//\t\t\tin the documentation and/or other materials provided with the
+//\t\t\tdistribution.
+//\t\t- Neither the name of the University of California, Berkeley nor the
+//\t\t\tnames of its contributors may be used to endorse or promote
+//\t\t\tproducts derived from this software without specific prior
+//\t\t\twritten permission.
+//
+//\tTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND
+//\tANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//\tWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+//\tDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+//\tANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+//\t(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//\tLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+//\tANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//\t(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//\tSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tIncludes
+//==============================================================================
+`include ""Const.v""
+//==============================================================================
+
+//------------------------------------------------------------------------------
+//\tModule:\t\tUAReceiver
+//\tDesc:\t\tStandard Universal Asynchronous RS232/16550 type receiver.
+//\tParams:\t\tClockFreq: Frequency (in Hz) of the ""Clock"" being fed to this
+//\t\t\t\t\t\tmodule.
+//\t\t\t\tBaud:\tDesired Baud rate. This is the rate at which this
+//\t\t\t\t\t\tmodule will send bits, and should be at most 1/4th
+//\t\t\t\t\t\tof the clock rate (or so).
+//\t\t\t\tWidth:\tWord width (in bits) of the words (bytes) send over
+//\t\t\t\t\t\tthe serial line.
+//\t\t\t\tParity:\tThe type of parity bit to be appended to each word of
+//\t\t\t\t\t\tdata.
+//\t\t\t\t\t\t0:\tNone
+//\t\t\t\t\t\t1:\tEven
+//\t\t\t\t\t\t2:\tOdd
+//\t\t\t\t\t\t3:\tMark
+//\t\t\t\t\t\t4:\tSpace
+//\t\t\t\tStopBits:The number of bit-periods to send the stop condition.
+//\t\t\t\t\t\tGenerally 1 or 2, though larger numbers are possible.
+//\tEx:\t\t\t(27000000, 9600, 8, 0, 1) Standard 9600baud 8-N-1 serial port
+//\t\t\t\t\t\tsettings used as the default by many devices, based
+//\t\t\t\t\t\ton a 27MHz clock.
+//------------------------------------------------------------------------------
+module UAReceiver(Clock, Reset, DataOut, DataOutValid, DataOutReady, SIn);
+\t//--------------------------------------------------------------------------
+\t//\tParameters
+\t//--------------------------------------------------------------------------
+\tparameter\t\t\t\tClockFreq =\t\t\t\t27000000,
+\t\t\t\t\t\t\tBaud =\t\t\t\t\t115200,
+\t\t\t\t\t\t\tWidth =\t\t\t\t\t8,
+\t\t\t\t\t\t\tParity =\t\t\t\t0,
+\t\t\t\t\t\t\tStopBits =\t\t\t\t1;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tLocal Parameters
+\t//--------------------------------------------------------------------------
+\t`ifdef MACROSAFE
+\tlocalparam\t\t\t\tDivisor =\t\t\t\tClockFreq / Baud,
+\t\t\t\t\t\t\tDivWidth =\t\t\t\t`log2(Divisor),
+\t\t\t\t\t\t\tCapture =\t\t\t\t(Divisor / 2),
+\t\t\t\t\t\t\tBitCount =\t\t\t\tWidth + StopBits + (Parity ? 1 : 0) + 1,
+\t\t\t\t\t\t\tBCWidth =\t\t\t\t`log2(BitCount + 1),
+\t\t\t\t\t\t\tActualBaud =\t\t\tClockFreq / Divisor;
+\t`endif
+
+\t`ifdef SIMULATION
+\tlocalparam real\t\t\tMaxBaud =\t\t\t\tClockFreq / ((Divisor * (BitCount - 0.5)) / BitCount),
+\t\t\t\t\t\t\tMinBaud =\t\t\t\tClockFreq / ((Divisor * (BitCount + 0.5)) / BitCount);
+\t`endif
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tConstant Debugging Statements
+\t//--------------------------------------------------------------------------
+\t`ifdef SIMULATION
+\t\tinitial begin
+\t\t\t$display(""DEBUG[%m @ %t]: UART Parameters"", $time);
+\t\t\t$display("" ClockFreq = %d"", ClockFreq);
+\t\t\t$display("" Baud = %d"", Baud);
+\t\t\t$display("" Width = %d"", Width);
+\t\t\t$display("" Parity = %d"", Parity);
+\t\t\t$display("" StopBits = %d"", StopBits);
+
+\t\t\t/*$display("" Divisor = %d"", Divisor);
+\t\t\t$display("" DivWidth = %d"", DivWidth);
+\t\t\t$display("" Capture = %d"", Capture);
+\t\t\t$display("" BitCount = %d"", BitCount);
+\t\t\t$display("" BCWidth = %d"", BCWidth);*/
+
+\t\t\t$display("" ActualBaud = %d"", ActualBaud);
+\t\t\t$display("" MaxBaud = %f"", MaxBaud);
+\t\t\t$display("" MinBaud = %f"", MinBaud);
+\t\tend
+\t`endif
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tSystem Inputs
+\t//--------------------------------------------------------------------------
+\tinput\t\t\t\t\tClock, Reset;\t
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tParallel Data Output
+\t//--------------------------------------------------------------------------
+\toutput\t[Width-1:0]\t\tDataOut;
+\toutput\t\t\t\t\tDataOutValid;
+\tinput\t\t\t\t\tDataOutReady;
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tSerial Interface
+\t//--------------------------------------------------------------------------
+\tinput\t\t\t\t\tSIn;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\t Wires and Regs
+\t//--------------------------------------------------------------------------
+\twire\t\t\t\t\tIntSIn;
+
+\twire\t[DivWidth-1:0]\tRxDivCount;
+\twire\t[BCWidth-1:0]\tRxBitCount;
+\twire\t[BitCount-1:0]\tRxData;
+\twire\t\t\t\t\tRxShiftEnable, RxRunning, RxBit, RxStart, RxTransfered;
+
+\twire\t\t\t\t\tRxStartBit, RxActualParity;
+\twire\t[StopBits-1:0]\tRxStopBits;
+
+\twire\t\t\t\t\tRxParity;
+\twire\t[Width-1:0]\t\tRxDataStripped;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tAssigns and Decodes
+\t//--------------------------------------------------------------------------
+\tassign\tRxShiftEnable =\t\t\t\t\t\t\t(RxDivCount == Capture);
+\tassign\tRxRunning =\t\t\t\t\t\t\t\t(RxBitCount < BitCount);
+\tassign\tRxBit =\t\t\t\t\t\t\t\t\tRxRunning & RxShiftEnable;
+\tassign\tRxStart =\t\t\t\t\t\t\t\t~IntSIn & ~RxRunning;
+\t
+\tassign\tRxStartBit =\t\t\t\t\t\t\tRxData[BitCount-1];
+\tassign\tRxActualParity =\t\t\t\t\t\tRxData[StopBits];
+\tassign\tRxStopBits =\t\t\t\t\t\t\tRxData[StopBits-1:0];
+\t
+\tassign\tDataOutValid =\t\t\t\t\t\t\t(~RxStartBit) & (&RxStopBits) & ~RxTransfered & (Parity ? ~(RxParity ^ RxActualParity) : 1\'b1);
+\tassign\tRxDataStripped =\t\t\t\t\t\tParity ? RxData[BitCount-2:StopBits+1] : RxData[BitCount-2:StopBits];
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tIO Register
+\t//--------------------------------------------------------------------------
+\tIORegister\t\tIOR(\t\t.Clock(\t\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\t1\'b0),
+\t\t\t\t\t\t\t\t.Set(\t\t\t\t1\'b0),
+\t\t\t\t\t\t\t\t.Enable(\t\t\t1\'b1),
+\t\t\t\t\t\t\t\t.In(\t\t\t\tSIn),
+\t\t\t\t\t\t\t\t.Out(\t\t\t\tIntSIn));
+\tdefparam\t\tIOR.Width =\t\t\t\t\t\t1;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tClock Divider Counter
+\t//--------------------------------------------------------------------------
+\tCounter\t\t\tRxDivCounter(.Clock(\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\tReset | (RxDivCount == (Divisor-1)) | RxStart),
+\t\t\t\t\t\t\t\t.Set(\t\t\t\t1\'b0),
+\t\t\t\t\t\t\t\t.Load(\t\t\t\t1\'b0),
+\t\t\t\t\t\t\t\t.Enable(\t\t\t1\'b1),
+\t\t\t\t\t\t\t\t.In(\t\t\t\t{DivWidth{1\'bx}}),
+\t\t\t\t\t\t\t\t.Count(\t\t\t\tRxDivCount));
+\tdefparam\t\tRxDivCounter.Width =\t\t\tDivWidth;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tBit Counter
+\t//--------------------------------------------------------------------------
+\tCounter\t\t\tRxBitCounter(.Clock(\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\tRxStart),
+\t\t\t\t\t\t\t\t.Set(\t\t\t\tReset),
+\t\t\t\t\t\t\t\t.Load(\t\t\t\t1\'b0),
+\t\t\t\t\t\t\t\t.Enable(\t\t\tRxBit),
+\t\t\t\t\t\t\t\t.In(\t\t\t\t{BCWidth{1\'bx}}),
+\t\t\t\t\t\t\t\t.Count(\t\t\t\tRxBitCount));
+\tdefparam\t\tRxBitCounter.Width =\t\t\tBCWidth;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tShift Register and Bit Reversal
+\t//--------------------------------------------------------------------------
+\tShiftRegister\tRxShift(\t.PIn(\t\t\t\t{BitCount{1\'b1}}),
+\t\t\t\t\t\t\t\t.SIn(\t\t\t\tIntSIn),
+\t\t\t\t\t\t\t\t.POut(\t\t\t\tRxData),
+\t\t\t\t\t\t\t\t.SOut(\t\t\t\t),
+\t\t\t\t\t\t\t\t.Load(\t\t\t\tReset),
+\t\t\t\t\t\t\t\t.Enable(\t\t\tRxShiftEnable),
+\t\t\t\t\t\t\t\t.Clock(\t\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\t1\'b0));
+\tdefparam\t\tRxShift.PWidth =\t\t\t\tBitCount;
+\tdefparam\t\tRxShift.SWidth =\t\t\t\t1;
+\tReverse\t\t\tRxReverse(\t.In(\t\t\t\tRxDataStripped),
+\t\t\t\t\t\t\t\t.Out(\t\t\t\tDataOut));
+\tdefparam\t\tRxReverse.Width =\t\t\t\tWidth;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tRegister
+\t//--------------------------------------------------------------------------
+\tRegister\t\tRXTR(\t\t.Clock(\t\t\t\tClock),
+\t\t\t\t\t\t\t\t.Reset(\t\t\t\t1\'b0),
+\t\t\t\t\t\t\t\t.Set(\t\t\t\tReset | (DataOutReady & DataOutValid)),
+\t\t\t\t\t\t\t\t.Enable(\t\t\tRxShiftEnable),
+\t\t\t\t\t\t\t\t.In(\t\t\t\t(RxBitCount != (BitCount - 1))),
+\t\t\t\t\t\t\t\t.Out(\t\t\t\tRxTransfered));
+\tdefparam\t\tRXTR.Width =\t\t\t\t\t1;
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tParity Generator
+\t//--------------------------------------------------------------------------
+\tParityGen\t\tRxParityGen(.In(\t\t\t\tDataOut),
+\t\t\t\t\t\t\t\t.Out(\t\t\t\tRxParity));
+\tdefparam\t\tRxParityGen.Width =\t\t\t\tWidth;
+\tdefparam\t\tRxParityGen.Parity =\t\t\tParity;
+\t//--------------------------------------------------------------------------
+endmodule
+//------------------------------------------------------------------------------
+"
+"//==============================================================================
+//\tFile:\t\t$URL: svn+ssh://repositorypub@repository.eecs.berkeley.edu/public/Projects/GateLib/branches/dev/Publications/Tutorials/Publications/EECS150/Labs/ChipScopeSerial/Framework/Register.v $
+//\tVersion:\t$Revision: 26904 $
+//\tAuthor:\t\tGreg Gibeling (http://www.gdgib.com)
+//\tCopyright:\tCopyright 2003-2010 UC Berkeley
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tLicense
+//==============================================================================
+//\tCopyright (c) 2003-2010, Regents of the University of California
+//\tAll rights reserved.
+//
+//\tRedistribution and use in source and binary forms, with or without modification,
+//\tare permitted provided that the following conditions are met:
+//
+//\t\t- Redistributions of source code must retain the above copyright notice,
+//\t\t\tthis list of conditions and the following disclaimer.
+//\t\t- Redistributions in binary form must reproduce the above copyright
+//\t\t\tnotice, this list of conditions and the following disclaimer
+//\t\t\tin the documentation and/or other materials provided with the
+//\t\t\tdistribution.
+//\t\t- Neither the name of the University of California, Berkeley nor the
+//\t\t\tnames of its contributors may be used to endorse or promote
+//\t\t\tproducts derived from this software without specific prior
+//\t\t\twritten permission.
+//
+//\tTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND
+//\tANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//\tWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+//\tDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+//\tANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+//\t(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//\tLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+//\tANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//\t(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//\tSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================================
+
+//------------------------------------------------------------------------------
+//\tModule:\t\tRegister
+//\tDesc:\t\tIf you don\'t know, I can\'t help you.
+//\tAuthor:\t\tGreg Gibeling
+//\tVersion:\t$Revision: 26904 $
+//------------------------------------------------------------------------------
+module\tRegister(Clock, Reset, Set, Enable, In, Out);
+\t//--------------------------------------------------------------------------
+\t//\tParameters
+\t//--------------------------------------------------------------------------
+\tparameter\t\t\t\tWidth = \t\t\t\t32,
+\t\t\t\t\t\t\tInitial =\t\t\t\t{Width{1\'bx}},
+\t\t\t\t\t\t\tAsyncReset =\t\t\t0,
+\t\t\t\t\t\t\tAsyncSet =\t\t\t\t0,
+\t\t\t\t\t\t\tResetValue =\t\t\t{Width{1\'b0}},
+\t\t\t\t\t\t\tSetValue =\t\t\t\t{Width{1\'b1}};
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tInputs & Outputs
+\t//--------------------------------------------------------------------------
+\tinput\t\t\t\t\tClock, Enable, Reset, Set;
+\tinput\t[Width-1:0]\t\tIn;
+\toutput reg [Width-1:0]\tOut =\t\t\t\t\tInitial;
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tBehavioral Register
+\t//--------------------------------------------------------------------------
+\tgenerate if (AsyncReset) begin:AR
+\t\tif (AsyncSet) begin:AS
+\t\t\talways @ (posedge Clock or posedge Reset or posedge Set) begin
+\t\t\t\tif (Reset) Out <=\t\t\t\t\tResetValue;
+\t\t\t\telse if (Set) Out <=\t\t\t\tSetValue;
+\t\t\t\telse if (Enable) Out <=\t\t\t\tIn;
+\t\t\tend
+\t\tend else begin:SS
+\t\t\talways @ (posedge Clock or posedge Reset) begin
+\t\t\t\tif (Reset) Out <=\t\t\t\t\tResetValue;
+\t\t\t\telse if (Set) Out <=\t\t\t\tSetValue;
+\t\t\t\telse if (Enable) Out <=\t\t\t\tIn;
+\t\t\tend
+\t\tend
+\tend else begin:SR
+\t\tif (AsyncSet) begin:AS
+\t\t\talways @ (posedge Clock or posedge Set) begin
+\t\t\t\tif (Reset) Out <=\t\t\t\t\tResetValue;
+\t\t\t\telse if (Set) Out <=\t\t\t\tSetValue;
+\t\t\t\telse if (Enable) Out <=\t\t\t\tIn;
+\t\t\tend
+\t\tend else begin:SS
+\t\t\talways @ (posedge Clock) begin
+\t\t\t\tif (Reset) Out <=\t\t\t\t\tResetValue;
+\t\t\t\telse if (Set) Out <=\t\t\t\tSetValue;
+\t\t\t\telse if (Enable) Out <=\t\t\t\tIn;
+\t\t\tend
+\t\tend
+\tend endgenerate
+\t//--------------------------------------------------------------------------
+endmodule
+//------------------------------------------------------------------------------
+"
+"//==============================================================================
+//\tFile: $URL: svn+ssh://repositorypub@repository.eecs.berkeley.edu/public/Projects/GateLib/branches/dev/Publications/Tutorials/Publications/EECS150/Labs/ChipScopeSerial/Solution/Gateway.v $
+//\tVersion: $Revision: 26904 $
+//\tAuthor: John Wawrzynek
+//\t\t\t Chris Fletcher (http://cwfletcher.net)
+//\tCopyright: Copyright 2009-2010 UC Berkeley
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tLicense
+//==============================================================================
+//\tCopyright (c) 2005-2010, Regents of the University of California
+//\tAll rights reserved.
+//
+//\tRedistribution and use in source and binary forms, with or without modification,
+//\tare permitted provided that the following conditions are met:
+//
+//\t\t- Redistributions of source code must retain the above copyright notice,
+//\t\t\tthis list of conditions and the following disclaimer.
+//\t\t- Redistributions in binary form must reproduce the above copyright
+//\t\t\tnotice, this list of conditions and the following disclaimer
+//\t\t\tin the documentation and/or other materials provided with the
+//\t\t\tdistribution.
+//\t\t- Neither the name of the University of California, Berkeley nor the
+//\t\t\tnames of its contributors may be used to endorse or promote
+//\t\t\tproducts derived from this software without specific prior
+//\t\t\twritten permission.
+//
+//\tTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND
+//\tANY EXPRESS OR InIMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE InIMPLIED
+//\tWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+//\tDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+//\tANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+//\t(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//\tLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+//\tANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//\t(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//\tSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================================
+
+//------------------------------------------------------------------------------
+//\tModule:\t
+//\tDesc:\t
+//
+//\tAuthor:\tJohn Wawrzynek
+//\t\t\tChris Fletcher
+//\tVersion:\t$Revision: 26904 $
+//------------------------------------------------------------------------------
+module Gateway(
+\t\t\t//------------------------------------------------------------------
+\t\t\t//\tClock and Related Signals
+\t\t\t//------------------------------------------------------------------
+\t\t\tClock,
+\t\t\tReset,
+\t\t\t//------------------------------------------------------------------
+\t\t\t
+\t\t\t//------------------------------------------------------------------
+\t\t\t//\tUART Interface
+\t\t\t//------------------------------------------------------------------
+\t\t\tDataIn,
+\t\t\tDataInValid,
+\t\t\tDataInReady,
+\t\t\tDataOut,
+\t\t\tDataOutValid,
+\t\t\tDataOutReady,
+\t\t\t//------------------------------------------------------------------
+\t\t\t
+\t\t\t//------------------------------------------------------------------
+\t\t\t//\tProcessor Interface
+\t\t\t//------------------------------------------------------------------
+\t\t\tProcessorDataIn,
+\t\t\tProcessorDataOut,
+\t\t\tProcessorAddress,
+\t\t\tProcessorMemRead,
+\t\t\tProcessorMemWrite
+\t\t\t//------------------------------------------------------------------
+\t);
+\t//--------------------------------------------------------------------------
+\t//\tParameters
+\t//--------------------------------------------------------------------------
+\tparameter\t\tCWidth = \t\t\t\t\t\t8, \t\t\t\t// char width
+\t\t\t\t\tWWidth = \t\t\t\t\t\t32, \t\t\t// word width
+\t\t\t\t\tAWidth =\t\t\t\t\t\tWWidth;
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tAddress map
+\t//--------------------------------------------------------------------------
+\tlocalparam\t\tADDRESS_ControlIn = \t\t\t32\'hffff_0000,\t// control input
+\t\t\t\t\tADDRESS_DataIn =\t\t\t\t32\'hffff_0004,\t// data input
+\t\t\t\t\tADDRESS_ControlOut =\t\t\t32\'hffff_0008,\t// control output
+\t\t\t\t\tADDRESS_DataOut = \t\t\t\t32\'hffff_000C;\t// data output
+\t//--------------------------------------------------------------------------
+
+\t//--------------------------------------------------------------------------
+\t//\tClock and Related Signals
+\t//--------------------------------------------------------------------------
+\tinput wire \t\t\t\t\t\t\t\t\t\tClock, Reset;
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tUART Interface
+\t//--------------------------------------------------------------------------
+\tinput\t\t\t[CWidth-1:0]\t\t\t\t\tDataIn;
+\tinput\t\t\t\t\t\t\t\t\t\t\tDataInValid;
+\toutput\t\t\t\t\t\t\t\t\t\t\tDataInReady;
+\toutput\t\t\t[CWidth-1:0]\t\t\t\t\tDataOut;
+\toutput\t\t\t\t\t\t\t\t\t\t\tDataOutValid;
+\tinput\t\t\t\t\t\t\t\t\t\t\tDataOutReady;
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tProcessor Interface
+\t//--------------------------------------------------------------------------
+\toutput wire\t\t[WWidth-1:0]\t\t\t\t\tProcessorDataIn;
+\tinput wire\t\t[WWidth-1:0]\t\t\t\t\tProcessorDataOut, ProcessorAddress;
+\tinput wire\t\t\t\t\t\t\t\t\t\tProcessorMemRead, ProcessorMemWrite;
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tWires / Reg Declarations
+\t//--------------------------------------------------------------------------
+\twire\t\t\t[CWidth-1:0]\t\t\t\t\tDataInReg;
+\twire\t\t\t\t\t\t\t\t\t\t\tControlInReady, PollingControlIn, PollingControlOut, WritingData;
+\t//--------------------------------------------------------------------------\t
+\t
+\t//--------------------------------------------------------------------------
+\t//\tPort Assigns
+\t//--------------------------------------------------------------------------
+\tassign\t\t\tDataInReady =\t\t\t\t\t~ControlInReady;
+\tassign\t\t\tProcessorDataIn =\t\t\t\t(PollingControlIn) ? {{WWidth-1{1\'b0}}, ControlInReady} : (PollingControlOut) ? {{WWidth-1{1\'b0}}, DataOutValid} : {{WWidth-CWidth-1{1\'b0}}, DataInReg};
+\t//--------------------------------------------------------------------------\t\t
+
+\t//--------------------------------------------------------------------------
+\t//\tAssigns
+\t//--------------------------------------------------------------------------
+\tassign\t\t\tUARTDataInTransfer = \t\t\tDataInReady & DataInValid;
+\tassign\t\t\tUARTDataOutTransfer = \t\t\tDataOutReady & DataOutValid;
+\tassign\t\t\tPollingControlIn =\t\t\t\tProcessorAddress == ADDRESS_ControlIn;
+\tassign\t\t\tPollingControlOut = \t\t\tProcessorAddress == ADDRESS_ControlOut;
+\tassign\t\t\tReadingData = \t\t\t\t\tProcessorMemRead & ProcessorAddress == ADDRESS_DataIn;
+\tassign\t\t\tWritingData = \t\t\t\t\tProcessorMemWrite & ProcessorAddress == ADDRESS_DataOut;\t
+\t//--------------------------------------------------------------------------
+\t
+\t//--------------------------------------------------------------------------
+\t//\tControl Registers
+\t//--------------------------------------------------------------------------
+\tRegister \t\t#(\t\t\t.Width(\t\t\t\t1))
+\t\t\t\t\tcIn (.Clock(Clock), .Reset(Reset | ReadingData), .Set(UARTDataInTransfer), .Enable(1\'b0), .In(1\'bx), .Out(ControlInReady)),
+\t\t\t\t\tcOut (.Clock(Clock), .Reset(Reset | UARTDataOutTransfer), .Set(WritingData), .Enable(1\'b0), .In(1\'bx), .Out(DataOutValid));
+\t//--------------------------------------------------------------------------\t\t\t\t
+\t
+\t//--------------------------------------------------------------------------
+\t//\tData Registers
+\t//--------------------------------------------------------------------------
+\tRegister\t\t#(\t\t\t.Width(\t\t\t\tCWidth))
+\t\t\t\t\tdIn (.Clock(Clock), .Reset(Reset), .Set(1\'b0), .Enable(UARTDataInTransfer), .In(DataIn), .Out(DataInReg)),
+\t\t\t\t\tdOut (.Clock(Clock), .Reset(Reset), .Set(1\'b0), .Enable(WritingData), .In(ProcessorDataOut[7:0]), .Out(DataOut));\t
+\t//--------------------------------------------------------------------------
+endmodule
+//------------------------------------------------------------------------------
+"
+"//==============================================================================
+//\tFile:\t\t$URL: svn+ssh://repositorypub@repository.eecs.berkeley.edu/public/Projects/GateLib/branches/dev/Publications/Tutorials/Publications/EECS150/Labs/ChipScopeSerial/Framework/Const.v $
+//\tVersion:\t$Revision: 26904 $
+//\tAuthor:\t\tGreg Gibeling (http://www.gdgib.com)
+//\tCopyright:\tCopyright 2003-2010 UC Berkeley
+//==============================================================================
+
+//==============================================================================
+//\tSection:\tLicense
+//==============================================================================
+//\tCopyright (c) 2005-2010, Regents of the University of California
+//\tAll rights reserved.
+//
+//\tRedistribution and use in source and binary forms, with or without modification,
+//\tare permitted provided that the following conditions are met:
+//
+//\t\t- Redistributions of source code must retain the above copyright notice,
+//\t\t\tthis list of conditions and the following disclaimer.
+//\t\t- Redistributions in binary form must reproduce the above copyright
+//\t\t\tnotice, this list of conditions and the following disclaimer
+//\t\t\tin the documentation and/or other materials provided with the
+//\t\t\tdistribution.
+//\t\t- Neither the name of the University of California, Berkeley nor the
+//\t\t\tnames of its contributors may be used to endorse or promote
+//\t\t\tproducts derived from this software without specific prior
+//\t\t\twritten permission.
+//
+//\tTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND
+//\tANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//\tWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+//\tDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+//\tANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+//\t(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//\tLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+//\tANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//\t(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//\tSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================================
+
+//------------------------------------------------------------------------------
+//\tSection:\tSimulation Flag
+//\tDesc:\t\tThis little nebulous block will define the flags:
+//\t\t\t\t-SIMULATION\tSimulating
+//\t\t\t\t-MODELSIM\tSimulating using ModelSim
+//\t\t\t\t-XST\t\tSynthesizing with XST
+//\t\t\t\t-SYNPLIFY\tSynthesizing with Synplify
+//\t\t\t\t-SYNTHESIS\tSynthesizing
+//\t\t\t\t-MACROSAFE\tSafe to use macros (Synplify or ModelSim)
+//
+//\tYOU SHOULD DEFINE THE ""MODELSIM"" FLAG FOR SIMULATION!!!!
+//------------------------------------------------------------------------------
+`ifdef synthesis // if Synplify
+\t`define SYNPLIFY
+\t`define SYNTHESIS
+\t`define MACROSAFE
+`else // if not Synplify
+\t`ifdef MODELSIM
+\t\t`define SIMULATION
+\t\t`define MACROSAFE
+\t`else
+\t\t`define XST
+\t\t// synthesis translate_off // if XST then stop compiling
+\t\t\t`undef XST
+\t\t\t`define SIMULATION
+\t\t\t`define MODELSIM
+\t\t// synthesis translate_on // if XST then resume compiling
+\t\t`ifdef XST
+\t\t\t`define SYNTHESIS
+\t\t\t`define MACROSAFE
+\t\t`endif
+\t`endif
+`endif
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+//\tSection:\tLog2 Macro
+//\tDesc:\t\tA macro to take the log base 2 of any number. Useful for
+//\t\t\t\tcalculating bitwidths. Warning, this actually calculates
+//\t\t\t\tlog2(x-1), not log2(x).
+//------------------------------------------------------------------------------
+`ifdef MACROSAFE
+`define log2(x)\t\t((((x) > 1) ? 1 : 0) + \\
+\t\t\t(((x) > 2) ? 1 : 0) + \\
+\t\t\t(((x) > 4) ? 1 : 0) + \\
+\t\t\t(((x) > 8) ? 1 : 0) + \\
+\t\t\t(((x) > 16) ? 1 : 0) + \\
+\t\t\t(((x) > 32) ? 1 : 0) + \\
+\t\t\t(((x) > 64) ? 1 : 0) + \\
+\t\t\t(((x) > 128) ? 1 : 0) + \\
+\t\t\t(((x) > 256) ? 1 : 0) + \\
+\t\t\t(((x) > 512) ? 1 : 0) + \\
+\t\t\t(((x) > 1024) ? 1 : 0) + \\
+\t\t\t(((x) > 2048) ? 1 : 0) + \\
+\t\t\t(((x) > 4096) ? 1 : 0) + \\
+\t\t\t(((x) > 8192) ? 1 : 0) + \\
+\t\t\t(((x) > 16384) ? 1 : 0) + \\
+\t\t\t(((x) > 32768) ? 1 : 0) + \\
+\t\t\t(((x) > 65536) ? 1 : 0) + \\
+\t\t\t(((x) > 131072) ? 1 : 0) + \\
+\t\t\t(((x) > 262144) ? 1 : 0) + \\
+\t\t\t(((x) > 524288) ? 1 : 0) + \\
+\t\t\t(((x) > 1048576) ? 1 : 0) + \\
+\t\t\t(((x) > 2097152) ? 1 : 0) + \\
+\t\t\t(((x) > 4194304) ? 1 : 0) + \\
+\t\t\t(((x) > 8388608) ? 1 : 0) + \\
+\t\t\t(((x) > 16777216) ? 1 : 0) + \\
+\t\t\t(((x) > 33554432) ? 1 : 0) + \\
+\t\t\t(((x) > 67108864) ? 1 : 0) + \\
+\t\t\t(((x) > 134217728) ? 1 : 0) + \\
+\t\t\t(((x) > 268435456) ? 1 : 0) + \\
+\t\t\t(((x) > 536870912) ? 1 : 0) + \\
+\t\t\t(((x) > 1073741824) ? 1 : 0))
+`endif
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+//\tSection:\tLog2 Floor Macro
+//\tDesc:\t\tA macro to take the floor of the log base 2 of any number.
+//------------------------------------------------------------------------------
+`ifdef MACROSAFE
+`define log2f(x)\t((((x) >= 2) ? 1 : 0) + \\
+\t\t\t(((x) >= 4) ? 1 : 0) + \\
+\t\t\t(((x) >= 8) ? 1 : 0) + \\
+\t\t\t(((x) >= 16) ? 1 : 0) + \\
+\t\t\t(((x) >= 32) ? 1 : 0) + \\
+\t\t\t(((x) >= 64) ? 1 : 0) + \\
+\t\t\t(((x) >= 128) ? 1 : 0) + \\
+\t\t\t(((x) >= 256) ? 1 : 0) + \\
+\t\t\t(((x) >= 512) ? 1 : 0) + \\
+\t\t\t(((x) >= 1024) ? 1 : 0) + \\
+\t\t\t(((x) >= 2048) ? 1 : 0) + \\
+\t\t\t(((x) >= 4096) ? 1 : 0) + \\
+\t\t\t(((x) >= 8192) ? 1 : 0) + \\
+\t\t\t(((x) >= 16384) ? 1 : 0) + \\
+\t\t\t(((x) >= 32768) ? 1 : 0) + \\
+\t\t\t(((x) >= 65536) ? 1 : 0) + \\
+\t\t\t(((x) >= 131072) ? 1 : 0) + \\
+\t\t\t(((x) >= 262144) ? 1 : 0) + \\
+\t\t\t(((x) >= 524288) ? 1 : 0) + \\
+\t\t\t(((x) >= 1048576) ? 1 : 0) + \\
+\t\t\t(((x) >= 2097152) ? 1 : 0) + \\
+\t\t\t(((x) >= 4194304) ? 1 : 0) + \\
+\t\t\t(((x) >= 8388608) ? 1 : 0) + \\
+\t\t\t(((x) >= 16777216) ? 1 : 0) + \\
+\t\t\t(((x) >= 33554432) ? 1 : 0) + \\
+\t\t\t(((x) >= 67108864) ? 1 : 0) + \\
+\t\t\t(((x) >= 134217728) ? 1 : 0) + \\
+\t\t\t(((x) >= 268435456) ? 1 : 0) + \\
+\t\t\t(((x) >= 536870912) ? 1 : 0) + \\
+\t\t\t(((x) >= 1073741824) ? 1 : 0))
+`endif
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+//\tSection:\tPow2 Macro
+//\tDesc:\t\tA macro to take the 2 to the power of any number. Useful for
+//\t\t\t\tcalculating bitwidths.
+//------------------------------------------------------------------------------
+`ifdef MACROSAFE
+`define pow2(x)\t\t((((x) >= 1) ? 2 : 1) * \\
+\t\t\t(((x) >= 2) ? 2 : 1) * \\
+\t\t\t(((x) >= 3) ? 2 : 1) * \\
+\t\t\t(((x) >= 4) ? 2 : 1) * \\
+\t\t\t(((x) >= 5) ? 2 : 1) * \\
+\t\t\t(((x) >= 6) ? 2 : 1) * \\
+\t\t\t(((x) >= 7) ? 2 : 1) * \\
+\t\t\t(((x) >= 8) ? 2 : 1) * \\
+\t\t\t(((x) >= 9) ? 2 : 1) * \\
+\t\t\t(((x) >= 10) ? 2 : 1) * \\
+\t\t\t(((x) >= 11) ? 2 : 1) * \\
+\t\t\t(((x) >= 12) ? 2 : 1) * \\
+\t\t\t(((x) >= 13) ? 2 : 1) * \\
+\t\t\t(((x) >= 14) ? 2 : 1) * \\
+\t\t\t(((x) >= 15) ? 2 : 1) * \\
+\t\t\t(((x) >= 16) ? 2 : 1) * \\
+\t\t\t(((x) >= 17) ? 2 : 1) * \\
+\t\t\t(((x) >= 18) ? 2 : 1) * \\
+\t\t\t(((x) >= 19) ? 2 : 1) * \\
+\t\t\t(((x) >= 20) ? 2 : 1) * \\
+\t\t\t(((x) >= 21) ? 2 : 1) * \\
+\t\t\t(((x) >= 22) ? 2 : 1) * \\
+\t\t\t(((x) >= 23) ? 2 : 1) * \\
+\t\t\t(((x) >= 24) ? 2 : 1) * \\
+\t\t\t(((x) >= 25) ? 2 : 1) * \\
+\t\t\t(((x) >= 26) ? 2 : 1) * \\
+\t\t\t(((x) >= 27) ? 2 : 1) * \\
+\t\t\t(((x) >= 28) ? 2 : 1) * \\
+\t\t\t(((x) >= 29) ? 2 : 1) * \\
+\t\t\t(((x) >= 30) ? 2 : 1) * \\
+\t\t\t(((x) >= 31) ? 2 : 1))
+`endif
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+//\tSection:\tMax/Min Macros
+//\tDesc:\t\tStandard binary max/min macros
+//------------------------------------------------------------------------------
+`ifdef MACROSAFE
+`define max(x,y)\t((x) > (y) ? (x) : (y))
+`define min(x,y)\t((x) < (y) ? (x) : (y))
+`endif
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+//\tSection:\tInteger Division Macros
+//\tDesc:\t\tRounding and ceiling for integer division
+//------------------------------------------------------------------------------
+`ifdef MACROSAFE
+`define\tdivceil(x,y)\t(((x) + ((y) - 1)) / (y))
+`define\tdivrnd(x,y)\t(((x) + ((y) >> 1)) / (y))
+`endif
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+//\tSection:\tPopulation Count
+//\tDesc:\t\tA population counter macro for 32bit values
+//------------------------------------------------------------------------------
+`ifdef MACROSAFE
+`define popcount(x)\t\t((((x) & 1) ? 1 : 0) + \\
+\t\t\t(((x) & 2) ? 1 : 0) + \\
+\t\t\t(((x) & 4) ? 1 : 0) + \\
+\t\t\t(((x) & 8) ? 1 : 0) + \\
+\t\t\t(((x) & 16) ? 1 : 0) + \\
+\t\t\t(((x) & 32) ? 1 : 0) + \\
+\t\t\t(((x) & 64) ? 1 : 0) + \\
+\t\t\t(((x) & 128) ? 1 : 0) + \\
+\t\t\t(((x) & 256) ? 1 : 0) + \\
+\t\t\t(((x) & 512) ? 1 : 0) + \\
+\t\t\t(((x) & 1024) ? 1 : 0) + \\
+\t\t\t(((x) & 2048) ? 1 : 0) + \\
+\t\t\t(((x) & 4096) ? 1 : 0) + \\
+\t\t\t(((x) & 8192) ? 1 : 0) + \\
+\t\t\t(((x) & 16384) ? 1 : 0) + \\
+\t\t\t(((x) & 32768) ? 1 : 0) + \\
+\t\t\t(((x) & 65536) ? 1 : 0) + \\
+\t\t\t(((x) & 131072) ? 1 : 0) + \\
+\t\t\t(((x) & 262144) ? 1 : 0) + \\
+\t\t\t(((x) & 524288) ? 1 : 0) + \\
+\t\t\t(((x) & 1048576) ? 1 : 0) + \\
+\t\t\t(((x) & 2097152) ? 1 : 0) + \\
+\t\t\t(((x) & 4194304) ? 1 : 0) + \\
+\t\t\t(((x) & 8388608) ? 1 : 0) + \\
+\t\t\t(((x) & 16777216) ? 1 : 0) + \\
+\t\t\t(((x) & 33554432) ? 1 : 0) + \\
+\t\t\t(((x) & 67108864) ? 1 : 0) + \\
+\t\t\t(((x) & 134217728) ? 1 : 0) + \\
+\t\t\t(((x) & 268435456) ? 1 : 0) + \\
+\t\t\t(((x) & 536870912) ? 1 : 0) + \\
+\t\t\t(((x) & 1073741824) ? 1 : 0))
+`endif
+//------------------------------------------------------------------------------
+"
+"/*
+ * Copyright (c) 2009 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module hex_display (
+ input [15:0] num,
+ input en,
+
+ output [6:0] hex0,
+ output [6:0] hex1,
+ output [6:0] hex2,
+ output [6:0] hex3
+ );
+
+ // Module instantiations
+ seg_7 hex_group0 (
+ .num (num[3:0]),
+ .en (en),
+ .seg (hex0)
+ );
+
+ seg_7 hex_group1 (
+ .num (num[7:4]),
+ .en (en),
+ .seg (hex1)
+ );
+
+ seg_7 hex_group2 (
+ .num (num[11:8]),
+ .en (en),
+ .seg (hex2)
+ );
+
+ seg_7 hex_group3 (
+ .num (num[15:12]),
+ .en (en),
+ .seg (hex3)
+ );
+
+endmodule
+"
+"////////////////////////////////////////////////////////////////////////////////\r
+// Original Author: Schuyler Eldridge\r
+// Contact Point: Schuyler Eldridge (schuyler.eldridge@gmail.com)\r
+// button_debounce.v\r
+// Created: 4.5.2012\r
+// Modified: 4.5.2012\r
+//\r
+// Testbench for button_debounce.v.\r
+// \r
+// Copyright (C) 2012 Schuyler Eldridge, Boston University\r
+//\r
+// This program is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License.\r
+//\r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program. If not, see .\r
+////////////////////////////////////////////////////////////////////////////////\r
+`timescale 1ns / 1ps\r
+module t_button_debounce();\r
+\r
+ parameter\r
+ CLK_FREQUENCY = 66000000,\r
+ DEBOUNCE_HZ = 2;\r
+\r
+ reg clk, reset_n, button;\r
+ wire debounce;\r
+ \r
+ button_debounce\r
+ #(\r
+ .CLK_FREQUENCY(CLK_FREQUENCY),\r
+ .DEBOUNCE_HZ(DEBOUNCE_HZ)\r
+ )\r
+ button_debounce\r
+ (\r
+ .clk(clk),\r
+ .reset_n(reset_n),\r
+ .button(button),\r
+ .debounce(debounce)\r
+ );\r
+\r
+ initial begin\r
+ clk = 1'bx; reset_n = 1'bx; button = 1'bx;\r
+ #10 reset_n = 1;\r
+ #10 reset_n = 0; clk = 0;\r
+ #10 reset_n = 1;\r
+ #10 button = 0;\r
+ end\r
+\r
+ always\r
+ #5 clk = ~clk;\r
+\r
+ always begin\r
+ #100 button = ~button;\r
+ #0.1 button = ~button;\r
+ #0.1 button = ~button;\r
+ #0.1 button = ~button;\r
+ #0.1 button = ~button;\r
+ #0.1 button = ~button;\r
+ #0.1 button = ~button;\r
+ #0.1 button = ~button;\r
+ #0.1 button = ~button;\r
+ end\r
+ \r
+endmodule\r
+"
+"////////////////////////////////////////////////////////////////////////////////\r
+// Original Author: Schuyler Eldridge\r
+// Contact Point: Schuyler Eldridge (schuyler.eldridge@gmail.com)\r
+// div_pipelined.v\r
+// Created: 4.3.2012\r
+// Modified: 4.5.2012\r
+//\r
+// Testbench for div_pipelined.v\r
+//\r
+// Copyright (C) 2012 Schuyler Eldridge, Boston University\r
+//\r
+// This program is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License.\r
+//\r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program. If not, see .\r
+////////////////////////////////////////////////////////////////////////////////\r
+`timescale 1ns / 1ps\r
+module t_div_pipelined();\r
+\r
+ reg clk, start, reset_n;\r
+ reg [7:0] dividend, divisor;\r
+ wire data_valid, div_by_zero;\r
+ wire [7:0] quotient, quotient_correct;\r
+\r
+ parameter\r
+ BITS = 8;\r
+\r
+ div_pipelined\r
+ #(\r
+ .BITS(BITS)\r
+ )\r
+ div_pipelined\r
+ (\r
+ .clk(clk),\r
+ .reset_n(reset_n),\r
+ .dividend(dividend),\r
+ .divisor(divisor),\r
+ .quotient(quotient),\r
+ .div_by_zero(div_by_zero),\r
+ // .quotient_correct(quotient_correct),\r
+ .start(start),\r
+ .data_valid(data_valid)\r
+ );\r
+\r
+ initial begin\r
+ #10 reset_n = 0;\r
+ #50 reset_n = 1;\r
+ #1\r
+ clk = 0;\r
+ dividend = -1;\r
+ divisor = 127;\r
+ #1000 $finish;\r
+ end\r
+\r
+// always\r
+// #20 dividend = dividend + 1;\r
+\r
+ always begin\r
+ #10 divisor = divisor - 1; start = 1;\r
+ #10 start = 0;\r
+ end\r
+\r
+ always\r
+ #5 clk = ~clk;\r
+\r
+ \r
+endmodule\r
+ "
+"////////////////////////////////////////////////////////////////////////////////\r
+// Original Author: Schuyler Eldridge\r
+// Contact Point: Schuyler Eldridge (schuyler.eldridge@gmail.com)\r
+// sqrt_pipelined.v\r
+// Created: 4.2.2012\r
+// Modified: 4.5.2012\r
+//\r
+// Implements a fixed-point parameterized pipelined square root\r
+// operation on an unsigned input of any bit length. The number of\r
+// stages in the pipeline is equal to the number of output bits in the\r
+// computation. This pipelien sustains a throughput of one computation\r
+// per clock cycle.\r
+// \r
+// Copyright (C) 2012 Schuyler Eldridge, Boston University\r
+//\r
+// This program is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License.\r
+//\r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program. If not, see .\r
+////////////////////////////////////////////////////////////////////////////////\r
+`timescale 1ns / 1ps\r
+module sqrt_pipelined\r
+ (\r
+ input clk, // clock\r
+ input reset_n, // asynchronous reset\r
+ input start, // optional start signal\r
+ input [INPUT_BITS-1:0] radicand, // unsigned radicand\r
+ output reg data_valid, // optional data valid signal\r
+ output reg [OUTPUT_BITS-1:0] root // unsigned root \r
+ );\r
+\r
+ // WARNING!!! THESE PARAMETERS ARE INTENDED TO BE MODIFIED IN A TOP\r
+ // LEVEL MODULE. LOCAL CHANGES HERE WILL, MOST LIKELY, BE\r
+ // OVERWRITTEN!\r
+ parameter\r
+ INPUT_BITS = 16; // number of input bits (any integer)\r
+ localparam\r
+ OUTPUT_BITS = INPUT_BITS / 2 + INPUT_BITS % 2; // number of output bits\r
+ \r
+ reg [OUTPUT_BITS-1:0] start_gen; // valid data propagation\r
+ reg [OUTPUT_BITS*INPUT_BITS-1:0] root_gen; // root values\r
+ reg [OUTPUT_BITS*INPUT_BITS-1:0] radicand_gen; // radicand values\r
+ wire [OUTPUT_BITS*INPUT_BITS-1:0] mask_gen; // mask values\r
+\r
+ // This is the first stage of the pipeline.\r
+ always @ (posedge clk or negedge reset_n) begin\r
+ if (!reset_n) begin\r
+ start_gen[0] <= 0;\r
+ radicand_gen[INPUT_BITS-1:0] <= 0;\r
+ root_gen[INPUT_BITS-1:0] <= 0;\r
+ end\r
+ else begin\r
+ start_gen[0] <= start;\r
+ if ( mask_gen[INPUT_BITS-1:0] <= radicand ) begin\r
+ radicand_gen[INPUT_BITS-1:0] <= radicand - mask_gen[INPUT_BITS-1:0];\r
+ root_gen[INPUT_BITS-1:0] <= mask_gen[INPUT_BITS-1:0];\r
+ end\r
+ else begin\r
+ radicand_gen[INPUT_BITS-1:0] <= radicand;\r
+ root_gen[INPUT_BITS-1:0] <= 0;\r
+ end\r
+ end\r
+ end\r
+\r
+ // Main generate loop to create the masks and pipeline stages.\r
+ generate\r
+ genvar i;\r
+ // Generate all the mask values. These are built up in the\r
+ // following fashion:\r
+ // LAST MASK: 0x00...001 \r
+ // 0x00...004 Increasing # OUTPUT_BITS\r
+ // 0x00...010 |\r
+ // 0x00...040 v\r
+ // ...\r
+ // FIRST MASK: 0x10...000 # masks == # OUTPUT_BITS\r
+ // \r
+ // Note that the first mask used can either be of the 0x1... or\r
+ // 0x4... variety. This is purely determined by the number of\r
+ // computation stages. However, the last mask used will always be\r
+ // 0x1 and the second to last mask used will always be 0x4.\r
+ for (i = 0; i < OUTPUT_BITS; i = i + 1) begin: mask_4\r
+ if (i % 2) // i is odd, this is a 4 mask\r
+ assign mask_gen[INPUT_BITS*(OUTPUT_BITS-i)-1:INPUT_BITS*(OUTPUT_BITS-i-1)] = 4 << 4 * (i/2);\r
+ else // i is even, this is a 1 mask\r
+ assign mask_gen[INPUT_BITS*(OUTPUT_BITS-i)-1:INPUT_BITS*(OUTPUT_BITS-i-1)] = 1 << 4 * (i/2);\r
+ end\r
+ // Generate all the pipeline stages to compute the square root of\r
+ // the input radicand stream. The general approach is to compare\r
+ // the current values of the root plus the mask to the\r
+ // radicand. If root/mask sum is greater than the radicand,\r
+ // subtract the mask and the root from the radicand and store the\r
+ // radicand for the next stage. Additionally, the root is\r
+ // increased by the value of the mask and stored for the next\r
+ // stage. If this test fails, then the radicand and the root\r
+ // retain their value through to the next stage. The one weird\r
+ // thing is that the mask indices appear to be incremented by one\r
+ // additional position. This is not the case, however, because the\r
+ // first mask is used in the first stage (always block after the\r
+ // generate statement).\r
+ for (i = 0; i < OUTPUT_BITS - 1; i = i + 1) begin: pipeline\r
+ always @ (posedge clk or negedge reset_n) begin : pipeline_stage\r
+ if (!reset_n) begin\r
+ start_gen[i+1] <= 0;\r
+ radicand_gen[INPUT_BITS*(i+2)-1:INPUT_BITS*(i+1)] <= 0;\r
+ root_gen[INPUT_BITS*(i+2)-1:INPUT_BITS*(i+1)] <= 0;\r
+ end\r
+ else begin\r
+ start_gen[i+1] <= start_gen[i];\r
+ if ((root_gen[INPUT_BITS*(i+1)-1:INPUT_BITS*i] + \r
+ mask_gen[INPUT_BITS*(i+2)-1:INPUT_BITS*(i+1)]) <= radicand_gen[INPUT_BITS*(i+1)-1:INPUT_BITS*i]) begin\r
+\t radicand_gen[INPUT_BITS*(i+2)-1:INPUT_BITS*(i+1)] <= radicand_gen[INPUT_BITS*(i+1)-1:INPUT_BITS*i] - \r
+ mask_gen[INPUT_BITS*(i+2)-1:INPUT_BITS*(i+1)] - \r
+ root_gen[INPUT_BITS*(i+1)-1:INPUT_BITS*i];\r
+\t root_gen[INPUT_BITS*(i+2)-1:INPUT_BITS*(i+1)] <= (root_gen[INPUT_BITS*(i+1)-1:INPUT_BITS*i] >> 1) + \r
+ mask_gen[INPUT_BITS*(i+2)-1:INPUT_BITS*(i+1)];\r
+ end\r
+ else begin\r
+\t radicand_gen[INPUT_BITS*(i+2)-1:INPUT_BITS*(i+1)] <= radicand_gen[INPUT_BITS*(i+1)-1:INPUT_BITS*i];\r
+\t root_gen[INPUT_BITS*(i+2)-1:INPUT_BITS*(i+1)] <= root_gen[INPUT_BITS*(i+1)-1:INPUT_BITS*i] >> 1;\r
+ end\r
+ end\r
+ end\r
+ end\r
+ endgenerate\r
+\r
+ // This is the final stage which just implements a rounding\r
+ // operation. This stage could be tacked on as a combinational logic\r
+ // stage, but who cares about latency, anyway? This is NOT a true\r
+ // rounding stage. In order to add convergent rounding, you need to\r
+ // increase the input bit width by 2 (increase the number of\r
+ // pipeline stages by 1) and implement rounding in the module that\r
+ // instantiates this one. \r
+ always @ (posedge clk or negedge reset_n) begin\r
+ if (!reset_n) begin\r
+ data_valid <= 0;\r
+ root <= 0;\r
+ end\r
+ else begin\r
+ data_valid <= start_gen[OUTPUT_BITS-1];\r
+ if (root_gen[OUTPUT_BITS*INPUT_BITS-1:OUTPUT_BITS*INPUT_BITS-INPUT_BITS] > root_gen[OUTPUT_BITS*INPUT_BITS-1:OUTPUT_BITS*INPUT_BITS-INPUT_BITS])\r
+ root <= root_gen[OUTPUT_BITS*INPUT_BITS-1:OUTPUT_BITS*INPUT_BITS-INPUT_BITS] + 1;\r
+ else\r
+ root <= root_gen[OUTPUT_BITS*INPUT_BITS-1:OUTPUT_BITS*INPUT_BITS-INPUT_BITS];\r
+ end\r
+ end\r
+\r
+endmodule\r
+"
+"////////////////////////////////////////////////////////////////////////////////\r
+// Original Author: Schuyler Eldridge\r
+// Contact Point: Schuyler Eldridge (schuyler.eldridge@gmail.com)\r
+// pipeline_registers.v\r
+// Created: 4.4.2012\r
+// Modified: 4.4.2012\r
+//\r
+// Implements a series of pipeline registers specified by the input\r
+// parameters BIT_WIDTH and NUMBER_OF_STAGES. BIT_WIDTH determines the\r
+// size of the signal passed through each of the pipeline\r
+// registers. NUMBER_OF_STAGES is the number of pipeline registers\r
+// generated. This accepts values of 0 (yes, it just passes data from\r
+// input to output...) up to however many stages specified.\r
+// Copyright (C) 2012 Schuyler Eldridge, Boston University\r
+//\r
+// This program is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License.\r
+//\r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program. If not, see .\r
+////////////////////////////////////////////////////////////////////////////////\r
+`timescale 1ns / 1ps\r
+module pipeline_registers\r
+ (\r
+ input clk,\r
+ input reset_n,\r
+ input [BIT_WIDTH-1:0] pipe_in,\r
+ output reg [BIT_WIDTH-1:0] pipe_out\r
+ );\r
+\r
+ // WARNING!!! THESE PARAMETERS ARE INTENDED TO BE MODIFIED IN A TOP\r
+ // LEVEL MODULE. LOCAL CHANGES HERE WILL, MOST LIKELY, BE\r
+ // OVERWRITTEN!\r
+ parameter \r
+ BIT_WIDTH = 10,\r
+ NUMBER_OF_STAGES = 5;\r
+\r
+ // Main generate function for conditional hardware instantiation\r
+ generate\r
+ genvar i;\r
+ // Pass-through case for the odd event that no pipeline stages are\r
+ // specified.\r
+ if (NUMBER_OF_STAGES == 0) begin\r
+ always @ *\r
+ pipe_out = pipe_in;\r
+ end\r
+ // Single flop case for a single stage pipeline\r
+ else if (NUMBER_OF_STAGES == 1) begin\r
+ always @ (posedge clk or negedge reset_n)\r
+ pipe_out <= (!reset_n) ? 0 : pipe_in;\r
+ end\r
+ // Case for 2 or more pipeline stages\r
+ else begin\r
+ // Create the necessary regs\r
+ reg [BIT_WIDTH*(NUMBER_OF_STAGES-1)-1:0] pipe_gen;\r
+ // Create logic for the initial and final pipeline registers\r
+ always @ (posedge clk or negedge reset_n) begin\r
+ if (!reset_n) begin\r
+ pipe_gen[BIT_WIDTH-1:0] <= 0;\r
+ pipe_out <= 0;\r
+ end\r
+ else begin\r
+ pipe_gen[BIT_WIDTH-1:0] <= pipe_in;\r
+ pipe_out <= pipe_gen[BIT_WIDTH*(NUMBER_OF_STAGES-1)-1:BIT_WIDTH*(NUMBER_OF_STAGES-2)];\r
+ end\r
+ end\r
+ // Create the intermediate pipeline registers if there are 3 or\r
+ // more pipeline stages\r
+ for (i = 1; i < NUMBER_OF_STAGES-1; i = i + 1) begin : pipeline\r
+ always @ (posedge clk or negedge reset_n)\r
+ pipe_gen[BIT_WIDTH*(i+1)-1:BIT_WIDTH*i] <= (!reset_n) ? 0 : pipe_gen[BIT_WIDTH*i-1:BIT_WIDTH*(i-1)];\r
+ end\r
+ end\r
+ endgenerate\r
+ \r
+endmodule\r
+"
+"////////////////////////////////////////////////////////////////////////////////\r
+// Original Author: Schuyler Eldridge\r
+// Contact Point: Schuyler Eldridge (schuyler.eldridge@gmail.com)\r
+// t_sqrt_pipelined.v\r
+// Created: 4.2.2012\r
+// Modified: 4.5.2012\r
+//\r
+// Testbench for generic sqrt operation\r
+// \r
+// Copyright (C) 2012 Schuyler Eldridge, Boston University\r
+//\r
+// This program is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License.\r
+//\r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program. If not, see .\r
+////////////////////////////////////////////////////////////////////////////////\r
+`timescale 1ns / 1ps\r
+module t_sqrt_pipelined();\r
+\r
+ parameter \r
+ INPUT_BITS = 4;\r
+ localparam\r
+ OUTPUT_BITS = INPUT_BITS / 2 + INPUT_BITS % 2;\r
+ \r
+ reg [INPUT_BITS-1:0] radicand;\r
+ reg clk, start, reset_n;\r
+\r
+ wire [OUTPUT_BITS-1:0] root;\r
+ wire data_valid;\r
+// wire [7:0] root_good;\r
+\r
+ sqrt_pipelined \r
+ #(\r
+ .INPUT_BITS(INPUT_BITS)\r
+ )\r
+ sqrt_pipelined \r
+ (\r
+ .clk(clk),\r
+ .reset_n(reset_n),\r
+ .start(start),\r
+ .radicand(radicand), \r
+ .data_valid(data_valid),\r
+ .root(root)\r
+ );\r
+\r
+ initial begin\r
+ radicand = 16'bx; clk = 1'bx; start = 1'bx; reset_n = 1'bx;;\r
+ #10 reset_n = 0; clk = 0;\r
+ #50 reset_n = 1; radicand = 0;\r
+// #40 radicand = 81; start = 1;\r
+// #10 radicand = 16'bx; start = 0;\r
+ #10000 $finish;\r
+ end\r
+\r
+ always\r
+ #5 clk = ~clk;\r
+\r
+ always begin\r
+ #10 radicand = radicand + 1; start = 1;\r
+ #10 start = 0;\r
+ end\r
+ \r
+\r
+// always begin\r
+// #80 start = 1;\r
+// #10 start = 0;\r
+// end\r
+\r
+endmodule\r
+\r
+"
+"/*
+ * VGA top level file
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vga (
+ // Wishbone signals
+ input wb_clk_i, // 25 Mhz VDU clock
+ input wb_rst_i,
+ input [15:0] wb_dat_i,
+ output [15:0] wb_dat_o,
+ input [16:1] wb_adr_i,
+ input wb_we_i,
+ input wb_tga_i,
+ input [ 1:0] wb_sel_i,
+ input wb_stb_i,
+ input wb_cyc_i,
+ output wb_ack_o,
+
+ // VGA pad signals
+ output [ 3:0] vga_red_o,
+ output [ 3:0] vga_green_o,
+ output [ 3:0] vga_blue_o,
+ output horiz_sync,
+ output vert_sync,
+
+ // CSR SRAM master interface
+ output [17:1] csrm_adr_o,
+ output [ 1:0] csrm_sel_o,
+ output csrm_we_o,
+ output [15:0] csrm_dat_o,
+ input [15:0] csrm_dat_i
+ );
+
+
+ // Registers and nets
+ //
+ // csr address
+ reg [17:1] csr_adr_i;
+ reg csr_stb_i;
+
+ // Config wires
+ wire [15:0] conf_wb_dat_o;
+ wire conf_wb_ack_o;
+
+ // Mem wires
+ wire [15:0] mem_wb_dat_o;
+ wire mem_wb_ack_o;
+
+ // LCD wires
+ wire [17:1] csr_adr_o;
+ wire [15:0] csr_dat_i;
+ wire csr_stb_o;
+ wire v_retrace;
+ wire vh_retrace;
+ wire w_vert_sync;
+
+ // VGA configuration registers
+ wire shift_reg1;
+ wire graphics_alpha;
+ wire memory_mapping1;
+ wire [ 1:0] write_mode;
+ wire [ 1:0] raster_op;
+ wire read_mode;
+ wire [ 7:0] bitmask;
+ wire [ 3:0] set_reset;
+ wire [ 3:0] enable_set_reset;
+ wire [ 3:0] map_mask;
+ wire x_dotclockdiv2;
+ wire chain_four;
+ wire [ 1:0] read_map_select;
+ wire [ 3:0] color_compare;
+ wire [ 3:0] color_dont_care;
+
+ // Wishbone master to SRAM
+ wire [17:1] wbm_adr_o;
+ wire [ 1:0] wbm_sel_o;
+ wire wbm_we_o;
+ wire [15:0] wbm_dat_o;
+ wire [15:0] wbm_dat_i;
+ wire wbm_stb_o;
+ wire wbm_ack_i;
+
+ wire stb;
+
+ // CRT wires
+ wire [ 5:0] cur_start;
+ wire [ 5:0] cur_end;
+ wire [15:0] start_addr;
+ wire [ 4:0] vcursor;
+ wire [ 6:0] hcursor;
+ wire [ 6:0] horiz_total;
+ wire [ 6:0] end_horiz;
+ wire [ 6:0] st_hor_retr;
+ wire [ 4:0] end_hor_retr;
+ wire [ 9:0] vert_total;
+ wire [ 9:0] end_vert;
+ wire [ 9:0] st_ver_retr;
+ wire [ 3:0] end_ver_retr;
+
+ // attribute_ctrl wires
+ wire [3:0] pal_addr;
+ wire pal_we;
+ wire [7:0] pal_read;
+ wire [7:0] pal_write;
+
+ // dac_regs wires
+ wire dac_we;
+ wire [1:0] dac_read_data_cycle;
+ wire [7:0] dac_read_data_register;
+ wire [3:0] dac_read_data;
+ wire [1:0] dac_write_data_cycle;
+ wire [7:0] dac_write_data_register;
+ wire [3:0] dac_write_data;
+
+ // Module instances
+ //
+ vga_config_iface config_iface (
+ .wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wb_dat_i (wb_dat_i),
+ .wb_dat_o (conf_wb_dat_o),
+ .wb_adr_i (wb_adr_i[4:1]),
+ .wb_we_i (wb_we_i),
+ .wb_sel_i (wb_sel_i),
+ .wb_stb_i (stb & wb_tga_i),
+ .wb_ack_o (conf_wb_ack_o),
+
+ .shift_reg1 (shift_reg1),
+ .graphics_alpha (graphics_alpha),
+ .memory_mapping1 (memory_mapping1),
+ .write_mode (write_mode),
+ .raster_op (raster_op),
+ .read_mode (read_mode),
+ .bitmask (bitmask),
+ .set_reset (set_reset),
+ .enable_set_reset (enable_set_reset),
+ .map_mask (map_mask),
+ .x_dotclockdiv2 (x_dotclockdiv2),
+ .chain_four (chain_four),
+ .read_map_select (read_map_select),
+ .color_compare (color_compare),
+ .color_dont_care (color_dont_care),
+
+ .pal_addr (pal_addr),
+ .pal_we (pal_we),
+ .pal_read (pal_read),
+ .pal_write (pal_write),
+
+ .dac_we (dac_we),
+ .dac_read_data_cycle (dac_read_data_cycle),
+ .dac_read_data_register (dac_read_data_register),
+ .dac_read_data (dac_read_data),
+ .dac_write_data_cycle (dac_write_data_cycle),
+ .dac_write_data_register (dac_write_data_register),
+ .dac_write_data (dac_write_data),
+
+ .cur_start (cur_start),
+ .cur_end (cur_end),
+ .start_addr (start_addr),
+ .vcursor (vcursor),
+ .hcursor (hcursor),
+
+ .horiz_total (horiz_total),
+ .end_horiz (end_horiz),
+ .st_hor_retr (st_hor_retr),
+ .end_hor_retr (end_hor_retr),
+ .vert_total (vert_total),
+ .end_vert (end_vert),
+ .st_ver_retr (st_ver_retr),
+ .end_ver_retr (end_ver_retr),
+
+ .v_retrace (v_retrace),
+ .vh_retrace (vh_retrace)
+ );
+
+ vga_lcd lcd (
+ .clk (wb_clk_i),
+ .rst (wb_rst_i),
+
+ .shift_reg1 (shift_reg1),
+ .graphics_alpha (graphics_alpha),
+
+ .pal_addr (pal_addr),
+ .pal_we (pal_we),
+ .pal_read (pal_read),
+ .pal_write (pal_write),
+
+ .dac_we (dac_we),
+ .dac_read_data_cycle (dac_read_data_cycle),
+ .dac_read_data_register (dac_read_data_register),
+ .dac_read_data (dac_read_data),
+ .dac_write_data_cycle (dac_write_data_cycle),
+ .dac_write_data_register (dac_write_data_register),
+ .dac_write_data (dac_write_data),
+
+ .csr_adr_o (csr_adr_o),
+ .csr_dat_i (csr_dat_i),
+ .csr_stb_o (csr_stb_o),
+
+ .vga_red_o (vga_red_o),
+ .vga_green_o (vga_green_o),
+ .vga_blue_o (vga_blue_o),
+ .horiz_sync (horiz_sync),
+ .vert_sync (w_vert_sync),
+
+ .cur_start (cur_start),
+ .cur_end (cur_end),
+ .vcursor (vcursor),
+ .hcursor (hcursor),
+
+ .horiz_total (horiz_total),
+ .end_horiz (end_horiz),
+ .st_hor_retr (st_hor_retr),
+ .end_hor_retr (end_hor_retr),
+ .vert_total (vert_total),
+ .end_vert (end_vert),
+ .st_ver_retr (st_ver_retr),
+ .end_ver_retr (end_ver_retr),
+
+ .x_dotclockdiv2 (x_dotclockdiv2),
+
+ .v_retrace (v_retrace),
+ .vh_retrace (vh_retrace)
+ );
+
+ vga_cpu_mem_iface cpu_mem_iface (
+ .wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+
+ .wbs_adr_i (wb_adr_i),
+ .wbs_sel_i (wb_sel_i),
+ .wbs_we_i (wb_we_i),
+ .wbs_dat_i (wb_dat_i),
+ .wbs_dat_o (mem_wb_dat_o),
+ .wbs_stb_i (stb & !wb_tga_i),
+ .wbs_ack_o (mem_wb_ack_o),
+
+ .wbm_adr_o (wbm_adr_o),
+ .wbm_sel_o (wbm_sel_o),
+ .wbm_we_o (wbm_we_o),
+ .wbm_dat_o (wbm_dat_o),
+ .wbm_dat_i (wbm_dat_i),
+ .wbm_stb_o (wbm_stb_o),
+ .wbm_ack_i (wbm_ack_i),
+
+ .chain_four (chain_four),
+ .memory_mapping1 (memory_mapping1),
+ .write_mode (write_mode),
+ .raster_op (raster_op),
+ .read_mode (read_mode),
+ .bitmask (bitmask),
+ .set_reset (set_reset),
+ .enable_set_reset (enable_set_reset),
+ .map_mask (map_mask),
+ .read_map_select (read_map_select),
+ .color_compare (color_compare),
+ .color_dont_care (color_dont_care)
+ );
+
+ vga_mem_arbitrer mem_arbitrer (
+ .clk_i (wb_clk_i),
+ .rst_i (wb_rst_i),
+
+ .wb_adr_i (wbm_adr_o),
+ .wb_sel_i (wbm_sel_o),
+ .wb_we_i (wbm_we_o),
+ .wb_dat_i (wbm_dat_o),
+ .wb_dat_o (wbm_dat_i),
+ .wb_stb_i (wbm_stb_o),
+ .wb_ack_o (wbm_ack_i),
+
+ .csr_adr_i (csr_adr_i),
+ .csr_dat_o (csr_dat_i),
+ .csr_stb_i (csr_stb_i),
+
+ .csrm_adr_o (csrm_adr_o),
+ .csrm_sel_o (csrm_sel_o),
+ .csrm_we_o (csrm_we_o),
+ .csrm_dat_o (csrm_dat_o),
+ .csrm_dat_i (csrm_dat_i)
+ );
+
+ // Continous assignments
+ assign wb_dat_o = wb_tga_i ? conf_wb_dat_o : mem_wb_dat_o;
+ assign wb_ack_o = wb_tga_i ? conf_wb_ack_o : mem_wb_ack_o;
+ assign stb = wb_stb_i & wb_cyc_i;
+ assign vert_sync = ~graphics_alpha ^ w_vert_sync;
+
+ // Behaviour
+ // csr_adr_i
+ always @(posedge wb_clk_i)
+ csr_adr_i <= wb_rst_i ? 17'h0 : csr_adr_o + start_addr[15:1];
+
+ // csr_stb_i
+ always @(posedge wb_clk_i)
+ csr_stb_i <= wb_rst_i ? 1'b0 : csr_stb_o;
+
+endmodule
+"
+"`timescale 1ns / 1ps
+// Copyright (C) 2008 Schuyler Eldridge, Boston University
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+module mux(opA,opB,sum,dsp_sel,out);
+\tinput [3:0] opA,opB;
+\tinput [4:0] sum;
+\tinput [1:0] dsp_sel;
+\toutput [3:0] out;
+\t
+\treg cout;
+\t
+\talways @ (sum)
+\t\tbegin
+\t\t\tif (sum[4] == 1)
+\t\t\t\tcout <= 4'b0001;
+\t\t\telse
+\t\t\t\tcout <= 4'b0000;
+\t\tend
+\t
+\treg out;
+\t
+\talways @(dsp_sel,sum,cout,opB,opA)
+\t\tbegin
+\t\t\tif (dsp_sel == 2'b00)
+\t\t\t\tout <= sum[3:0];
+\t\t\telse if (dsp_sel == 2'b01)
+\t\t\t\tout <= cout;
+\t\t\telse if (dsp_sel == 2'b10)
+\t\t\t\tout <= opB;
+\t\t\telse if (dsp_sel == 2'b11)
+\t\t\t\tout <= opA;
+\t\tend
+
+endmodule
+"
+"////////////////////////////////////////////////////////////////////////////////\r
+// Original Author: Schuyler Eldridge\r
+// Contact Point: Schuyler Eldridge (schuyler.eldridge@gmail.com)\r
+// sign_extender.v\r
+// Created: 5.16.2012\r
+// Modified: 5.16.2012\r
+//\r
+// Generic sign extension module\r
+//\r
+// Copyright (C) 2012 Schuyler Eldridge, Boston University\r
+//\r
+// This program is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License.\r
+//\r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program. If not, see .\r
+////////////////////////////////////////////////////////////////////////////////\r
+`timescale 1ns/1ps\r
+module sign_extender\r
+ #(\r
+ parameter\r
+ INPUT_WIDTH = 8,\r
+ OUTPUT_WIDTH = 16\r
+ )\r
+ (\r
+ input [INPUT_WIDTH-1:0] original,\r
+ output reg [OUTPUT_WIDTH-1:0] sign_extended_original\r
+ );\r
+\r
+ wire [OUTPUT_WIDTH-INPUT_WIDTH-1:0] sign_extend;\r
+\r
+ generate\r
+ genvar i;\r
+ for (i = 0; i < OUTPUT_WIDTH-INPUT_WIDTH; i = i + 1) begin : gen_sign_extend\r
+ assign sign_extend[i] = (original[INPUT_WIDTH-1]) ? 1'b1 : 1'b0;\r
+ end\r
+ endgenerate\r
+\r
+ always @ * begin\r
+ sign_extended_original = {sign_extend,original};\r
+ end\r
+\r
+endmodule\r
+"
+"Require Export Sorted.
+Require Export Mergesort.
+"
+"////////////////////////////////////////////////////////////////////////////////\r
+// Original Author: Schuyler Eldridge\r
+// Contact Point: Schuyler Eldridge (schuyler.eldridge@gmail.com)\r
+// button_debounce.v\r
+// Created: 10/10/2009\r
+// Modified: 3/20/2012\r
+//\r
+// Counter based debounce circuit originally written for EC551 (back\r
+// in the day) and then modified (i.e. chagned entirely) into 3 always\r
+// block format. This debouncer generates a signal that goes high for\r
+// 1 clock cycle after the clock sees an asserted value on the button\r
+// line. This action is then disabled until the counter hits a\r
+// specified count value that is determined by the clock frequency and\r
+// desired debounce frequency. An alternative implementation would not\r
+// use a counter, but would use the shift register approach, looking\r
+// for repeated matches (say 5) on the button line.\r
+// \r
+// Copyright (C) 2012 Schuyler Eldridge, Boston University\r
+//\r
+// This program is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License.\r
+//\r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program. If not, see .\r
+////////////////////////////////////////////////////////////////////////////////\r
+`timescale 1ns / 1ps\r
+module button_debounce\r
+ (\r
+ input clk, // clock\r
+ input reset_n, // asynchronous reset \r
+ input button, // bouncy button\r
+ output reg debounce // debounced 1-cycle signal\r
+ );\r
+ \r
+ parameter\r
+ CLK_FREQUENCY = 66000000,\r
+ DEBOUNCE_HZ = 2;\r
+ // These parameters are specified such that you can choose any power\r
+ // of 2 frequency for a debouncer between 1 Hz and\r
+ // CLK_FREQUENCY. Note, that this will throw errors if you choose a\r
+ // non power of 2 frequency (i.e. count_value evaluates to some\r
+ // number / 3 which isn't interpreted as a logical right shift). I'm\r
+ // assuming this will not work for DEBOUNCE_HZ values less than 1,\r
+ // however, I'm uncertain of the value of a debouncer for fractional\r
+ // hertz button presses.\r
+ localparam\r
+ COUNT_VALUE = CLK_FREQUENCY / DEBOUNCE_HZ,\r
+ WAIT = 0,\r
+ FIRE = 1,\r
+ COUNT = 2;\r
+\r
+ reg [1:0] state, next_state;\r
+ reg [25:0] count;\r
+ \r
+ always @ (posedge clk or negedge reset_n)\r
+ state <= (!reset_n) ? WAIT : next_state;\r
+\r
+ always @ (posedge clk or negedge reset_n) begin\r
+ if (!reset_n) begin\r
+ debounce <= 0;\r
+ count <= 0;\r
+ end\r
+ else begin\r
+ debounce <= 0;\r
+ count <= 0;\r
+ case (state)\r
+ WAIT: begin\r
+ end\r
+ FIRE: begin\r
+ debounce <= 1;\r
+ end\r
+ COUNT: begin\r
+ count <= count + 1;\r
+ end\r
+ endcase \r
+ end\r
+ end\r
+\r
+ always @ * begin\r
+ case (state)\r
+ WAIT: next_state = (button) ? FIRE : state;\r
+ FIRE: next_state = COUNT;\r
+ COUNT: next_state = (count > COUNT_VALUE - 1) ? WAIT : state;\r
+ default: next_state = WAIT;\r
+ endcase\r
+ end\r
+\r
+endmodule\r
+"
+"/*
+ * PS2 Mouse Interface
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module ps2_mouse (
+ input clk, // Clock Input
+ input reset, // Reset Input
+ inout ps2_clk, // PS2 Clock, Bidirectional
+ inout ps2_dat, // PS2 Data, Bidirectional
+
+ input [7:0] the_command, // Command to send to mouse
+ input send_command, // Signal to send
+ output command_was_sent, // Signal command finished sending
+ output error_communication_timed_out,
+
+ output [7:0] received_data, // Received data
+ output received_data_en, // If 1 - new data has been received
+ output start_receiving_data,
+ output wait_for_incoming_data
+ );
+
+ // --------------------------------------------------------------------
+ // Internal wires and registers Declarations
+ // --------------------------------------------------------------------
+ wire ps2_clk_posedge; // Internal Wires
+ wire ps2_clk_negedge;
+
+ reg [7:0] idle_counter; // Internal Registers
+ reg ps2_clk_reg;
+ reg ps2_data_reg;
+ reg last_ps2_clk;
+
+ reg [2:0] ns_ps2_transceiver; // State Machine Registers
+ reg [2:0] s_ps2_transceiver;
+
+ // --------------------------------------------------------------------
+ // Constant Declarations
+ // --------------------------------------------------------------------
+ localparam PS2_STATE_0_IDLE = 3'h0, // states
+ PS2_STATE_1_DATA_IN = 3'h1,
+ PS2_STATE_2_COMMAND_OUT = 3'h2,
+ PS2_STATE_3_END_TRANSFER = 3'h3,
+ PS2_STATE_4_END_DELAYED = 3'h4;
+
+ // --------------------------------------------------------------------
+ // Finite State Machine(s)
+ // --------------------------------------------------------------------
+ always @(posedge clk) begin
+ if(reset == 1'b1) s_ps2_transceiver <= PS2_STATE_0_IDLE;
+ else s_ps2_transceiver <= ns_ps2_transceiver;
+ end
+
+ always @(*) begin
+ ns_ps2_transceiver = PS2_STATE_0_IDLE; // Defaults
+
+ case (s_ps2_transceiver)
+ PS2_STATE_0_IDLE:
+ begin
+ if((idle_counter == 8'hFF) && (send_command == 1'b1))
+ ns_ps2_transceiver = PS2_STATE_2_COMMAND_OUT;
+ else if ((ps2_data_reg == 1'b0) && (ps2_clk_posedge == 1'b1))
+ ns_ps2_transceiver = PS2_STATE_1_DATA_IN;
+ else ns_ps2_transceiver = PS2_STATE_0_IDLE;
+ end
+ PS2_STATE_1_DATA_IN:
+ begin
+ // if((received_data_en == 1'b1) && (ps2_clk_posedge == 1'b1))
+ if((received_data_en == 1'b1)) ns_ps2_transceiver = PS2_STATE_0_IDLE;
+ else ns_ps2_transceiver = PS2_STATE_1_DATA_IN;
+ end
+ PS2_STATE_2_COMMAND_OUT:
+ begin
+ if((command_was_sent == 1'b1) || (error_communication_timed_out == 1'b1))
+ ns_ps2_transceiver = PS2_STATE_3_END_TRANSFER;
+ else ns_ps2_transceiver = PS2_STATE_2_COMMAND_OUT;
+ end
+ PS2_STATE_3_END_TRANSFER:
+ begin
+ if(send_command == 1'b0) ns_ps2_transceiver = PS2_STATE_0_IDLE;
+ else if((ps2_data_reg == 1'b0) && (ps2_clk_posedge == 1'b1))
+ ns_ps2_transceiver = PS2_STATE_4_END_DELAYED;
+ else ns_ps2_transceiver = PS2_STATE_3_END_TRANSFER;
+ end
+ PS2_STATE_4_END_DELAYED:
+ begin
+ if(received_data_en == 1'b1) begin
+ if(send_command == 1'b0) ns_ps2_transceiver = PS2_STATE_0_IDLE;
+ else ns_ps2_transceiver = PS2_STATE_3_END_TRANSFER;
+ end
+ else ns_ps2_transceiver = PS2_STATE_4_END_DELAYED;
+ end
+
+ default:
+ ns_ps2_transceiver = PS2_STATE_0_IDLE;
+ endcase
+ end
+
+ // --------------------------------------------------------------------
+ // Sequential logic
+ // --------------------------------------------------------------------
+ always @(posedge clk) begin
+ if(reset == 1'b1) begin
+ last_ps2_clk <= 1'b1;
+ ps2_clk_reg <= 1'b1;
+ ps2_data_reg <= 1'b1;
+ end
+ else begin
+ last_ps2_clk <= ps2_clk_reg;
+ ps2_clk_reg <= ps2_clk;
+ ps2_data_reg <= ps2_dat;
+ end
+ end
+
+ always @(posedge clk) begin
+ if(reset == 1'b1) idle_counter <= 6'h00;
+ else if((s_ps2_transceiver == PS2_STATE_0_IDLE) && (idle_counter != 8'hFF))
+ idle_counter <= idle_counter + 6'h01;
+ else if (s_ps2_transceiver != PS2_STATE_0_IDLE)
+ idle_counter <= 6'h00;
+ end
+
+ // --------------------------------------------------------------------
+ // Combinational logic
+ // --------------------------------------------------------------------
+ assign ps2_clk_posedge = ((ps2_clk_reg == 1'b1) && (last_ps2_clk == 1'b0)) ? 1'b1 : 1'b0;
+ assign ps2_clk_negedge = ((ps2_clk_reg == 1'b0) && (last_ps2_clk == 1'b1)) ? 1'b1 : 1'b0;
+
+ assign start_receiving_data = (s_ps2_transceiver == PS2_STATE_1_DATA_IN);
+ assign wait_for_incoming_data = (s_ps2_transceiver == PS2_STATE_3_END_TRANSFER);
+
+ // --------------------------------------------------------------------
+ // Internal Modules
+ // --------------------------------------------------------------------
+ ps2_mouse_cmdout mouse_cmdout (
+ .clk (clk), // Inputs
+ .reset (reset),
+ .the_command (the_command),
+ .send_command (send_command),
+ .ps2_clk_posedge (ps2_clk_posedge),
+ .ps2_clk_negedge (ps2_clk_negedge),
+ .ps2_clk (ps2_clk), // Bidirectionals
+ .ps2_dat (ps2_dat),
+ .command_was_sent (command_was_sent), // Outputs
+ .error_communication_timed_out (error_communication_timed_out)
+ );
+
+ ps2_mouse_datain mouse_datain (
+ .clk (clk), // Inputs
+ .reset (reset),
+ .wait_for_incoming_data (wait_for_incoming_data),
+ .start_receiving_data (start_receiving_data),
+ .ps2_clk_posedge (ps2_clk_posedge),
+ .ps2_clk_negedge (ps2_clk_negedge),
+ .ps2_data (ps2_data_reg),
+ .received_data (received_data), // Outputs
+ .received_data_en (received_data_en)
+ );
+
+endmodule
+
+"
+"`timescale 1ns / 1ps
+// Copyright (C) 2008 Schuyler Eldridge, Boston University
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+module control(clk,en,dsp_sel,an);
+ input clk, en;
+ output [1:0]dsp_sel;
+ output [3:0]an;
+ wire a,b,c,d,e,f,g,h,i,j,k,l;
+
+ assign an[3] = a;
+ assign an[2] = b;
+ assign an[1] = c;
+ assign an[0] = d;
+
+ assign dsp_sel[1] = e;
+
+ assign dsp_sel[0] = i;
+
+
+ FDRSE #(
+ .INIT(1'b0) // Initial value of register (1'b0 or 1'b1)
+ ) DFF3(
+ .Q(a), // Data output
+ .C(clk), // Clock input
+ .CE(en), // Clock enable input
+ .D(d), // Data input
+ .R(1'b0), // Synchronous reset input
+ .S(1'b0) // Synchronous set input
+ );
+ FDRSE #(
+ .INIT(1'b1) // Initial value of register (1'b0 or 1'b1)
+ ) DFF2(
+ .Q(b), // Data output
+ .C(clk), // Clock input
+ .CE(en), // Clock enable input
+ .D(a), // Data input
+ .R(1'b0), // Synchronous reset input
+ .S(1'b0) // Synchronous set input
+ );
+ FDRSE #(
+ .INIT(1'b1) // Initial value of register (1'b0 or 1'b1)
+ ) DFF1(
+ .Q(c), // Data output
+ .C(clk), // Clock input
+ .CE(en), // Clock enable input
+ .D(b), // Data input
+ .R(1'b0), // Synchronous reset input
+ .S(1'b0) // Synchronous set input
+ );
+ FDRSE #(
+ .INIT(1'b1) // Initial value of register (1'b0 or 1'b1)
+ ) DFF0(
+ .Q(d), // Data output
+ .C(clk), // Clock input
+ .CE(en), // Clock enable input
+ .D(c), // Data input
+ .R(1'b0), // Synchronous reset input
+ .S(1'b0) // Synchronous set input
+ );
+
+
+ FDRSE #(
+ .INIT(1'b1) // Initial value of register (1'b0 or 1'b1)
+ ) DFF7(
+ .Q(e), // Data output
+ .C(clk), // Clock input
+ .CE(en), // Clock enable input
+ .D(h), // Data input
+ .R(1'b0), // Synchronous reset input
+ .S(1'b0) // Synchronous set input
+ );
+ FDRSE #(
+ .INIT(1'b1) // Initial value of register (1'b0 or 1'b1)
+ ) DFF6(
+ .Q(f), // Data output
+ .C(clk), // Clock input
+ .CE(en), // Clock enable input
+ .D(e), // Data input
+ .R(1'b0), // Synchronous reset input
+ .S(1'b0) // Synchronous set input
+ );
+ FDRSE #(
+ .INIT(1'b0) // Initial value of register (1'b0 or 1'b1)
+ ) DFF5(
+ .Q(g), // Data output
+ .C(clk), // Clock input
+ .CE(en), // Clock enable input
+ .D(f), // Data input
+ .R(1'b0), // Synchronous reset input
+ .S(1'b0) // Synchronous set input
+ );
+ FDRSE #(
+ .INIT(1'b0) // Initial value of register (1'b0 or 1'b1)
+ ) DFF4(
+ .Q(h), // Data output
+ .C(clk), // Clock input
+ .CE(en), // Clock enable input
+ .D(g), // Data input
+ .R(1'b0), // Synchronous reset input
+ .S(1'b0) // Synchronous set input
+ );
+
+
+ FDRSE #(
+ .INIT(1'b1) // Initial value of register (1'b0 or 1'b1)
+ ) DFF11(
+ .Q(i), // Data output
+ .C(clk), // Clock input
+ .CE(en), // Clock enable input
+ .D(l), // Data input
+ .R(1'b0), // Synchronous reset input
+ .S(1'b0) // Synchronous set input
+ );
+ FDRSE #(
+ .INIT(1'b0) // Initial value of register (1'b0 or 1'b1)
+ ) DFF10(
+ .Q(j), // Data output
+ .C(clk), // Clock input
+ .CE(en), // Clock enable input
+ .D(i), // Data input
+ .R(1'b0), // Synchronous reset input
+ .S(1'b0) // Synchronous set input
+ );
+ FDRSE #(
+ .INIT(1'b1) // Initial value of register (1'b0 or 1'b1)
+ ) DFF9(
+ .Q(k), // Data output
+ .C(clk), // Clock input
+ .CE(en), // Clock enable input
+ .D(j), // Data input
+ .R(1'b0), // Synchronous reset input
+ .S(1'b0) // Synchronous set input
+ );
+ FDRSE #(
+ .INIT(1'b0) // Initial value of register (1'b0 or 1'b1)
+ ) DFF8(
+ .Q(l), // Data output
+ .C(clk), // Clock input
+ .CE(en), // Clock enable input
+ .D(k), // Data input
+ .R(1'b0), // Synchronous reset input
+ .S(1'b0) // Synchronous set input
+ );
+endmodule
+"
+"// file: clk_divider_tb.v
+//
+// (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+
+//----------------------------------------------------------------------------
+// Clocking wizard demonstration testbench
+//----------------------------------------------------------------------------
+// This demonstration testbench instantiates the example design for the
+// clocking wizard. Input clocks are toggled, which cause the clocking
+// network to lock and the counters to increment.
+//----------------------------------------------------------------------------
+
+`timescale 1ps/1ps
+
+`define wait_lock @(posedge LOCKED)
+
+module clk_divider_tb ();
+
+ // Clock to Q delay of 100ps
+ localparam TCQ = 100;
+
+
+ // timescale is 1ps/1ps
+ localparam ONE_NS = 1000;
+ localparam PHASE_ERR_MARGIN = 100; // 100ps
+ // how many cycles to run
+ localparam COUNT_PHASE = 1024;
+ // we\'ll be using the period in many locations
+ localparam time PER1 = 10.0*ONE_NS;
+ localparam time PER1_1 = PER1/2;
+ localparam time PER1_2 = PER1 - PER1/2;
+
+ // Declare the input clock signals
+ reg CLK_IN1 = 1;
+
+ // The high bit of the sampling counter
+ wire COUNT;
+ // Status and control signals
+ reg RESET = 0;
+ wire LOCKED;
+ reg COUNTER_RESET = 0;
+wire [1:1] CLK_OUT;
+//Freq Check using the M & D values setting and actual Frequency generated
+
+
+ // Input clock generation
+ //------------------------------------
+ always begin
+ CLK_IN1 = #PER1_1 ~CLK_IN1;
+ CLK_IN1 = #PER1_2 ~CLK_IN1;
+ end
+
+ // Test sequence
+ reg [15*8-1:0] test_phase = """";
+ initial begin
+ // Set up any display statements using time to be readable
+ $timeformat(-12, 2, ""ps"", 10);
+ COUNTER_RESET = 0;
+ test_phase = ""reset"";
+ RESET = 1;
+ #(PER1*6);
+ RESET = 0;
+ test_phase = ""wait lock"";
+ `wait_lock;
+ #(PER1*6);
+ COUNTER_RESET = 1;
+ #(PER1*20)
+ COUNTER_RESET = 0;
+
+ test_phase = ""counting"";
+ #(PER1*COUNT_PHASE);
+
+ $display(""SIMULATION PASSED"");
+ $display(""SYSTEM_CLOCK_COUNTER : %0d\
+"",$time/PER1);
+ $finish;
+ end
+
+ // Instantiation of the example design containing the clock
+ // network and sampling counters
+ //---------------------------------------------------------
+ clk_divider_exdes
+ #(
+ .TCQ (TCQ)
+ ) dut
+ (// Clock in ports
+ .CLK_IN1 (CLK_IN1),
+ // Reset for logic in example design
+ .COUNTER_RESET (COUNTER_RESET),
+ .CLK_OUT (CLK_OUT),
+ // High bits of the counters
+ .COUNT (COUNT),
+ // Status and control signals
+ .RESET (RESET),
+ .LOCKED (LOCKED));
+
+// Freq Check
+
+endmodule
+"
+"// file: clk_divider_tb.v
+//
+// (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+
+//----------------------------------------------------------------------------
+// Clocking wizard demonstration testbench
+//----------------------------------------------------------------------------
+// This demonstration testbench instantiates the example design for the
+// clocking wizard. Input clocks are toggled, which cause the clocking
+// network to lock and the counters to increment.
+//----------------------------------------------------------------------------
+
+`timescale 1ps/1ps
+
+`define wait_lock @(posedge LOCKED)
+
+module clk_divider_tb ();
+
+ // Clock to Q delay of 100ps
+ localparam TCQ = 100;
+
+
+ // timescale is 1ps/1ps
+ localparam ONE_NS = 1000;
+ localparam PHASE_ERR_MARGIN = 100; // 100ps
+ // how many cycles to run
+ localparam COUNT_PHASE = 1024;
+ // we\'ll be using the period in many locations
+ localparam time PER1 = 10.0*ONE_NS;
+ localparam time PER1_1 = PER1/2;
+ localparam time PER1_2 = PER1 - PER1/2;
+
+ // Declare the input clock signals
+ reg CLK_IN1 = 1;
+
+ // The high bit of the sampling counter
+ wire COUNT;
+ // Status and control signals
+ reg RESET = 0;
+ wire LOCKED;
+ reg COUNTER_RESET = 0;
+wire [1:1] CLK_OUT;
+//Freq Check using the M & D values setting and actual Frequency generated
+
+ reg [13:0] timeout_counter = 14\'b00000000000000;
+
+ // Input clock generation
+ //------------------------------------
+ always begin
+ CLK_IN1 = #PER1_1 ~CLK_IN1;
+ CLK_IN1 = #PER1_2 ~CLK_IN1;
+ end
+
+ // Test sequence
+ reg [15*8-1:0] test_phase = """";
+ initial begin
+ // Set up any display statements using time to be readable
+ $timeformat(-12, 2, ""ps"", 10);
+ $display (""Timing checks are not valid"");
+ COUNTER_RESET = 0;
+ test_phase = ""reset"";
+ RESET = 1;
+ #(PER1*6);
+ RESET = 0;
+ test_phase = ""wait lock"";
+ `wait_lock;
+ #(PER1*6);
+ COUNTER_RESET = 1;
+ #(PER1*19.5)
+ COUNTER_RESET = 0;
+ #(PER1*1)
+ $display (""Timing checks are valid"");
+ test_phase = ""counting"";
+ #(PER1*COUNT_PHASE);
+
+ $display(""SIMULATION PASSED"");
+ $display(""SYSTEM_CLOCK_COUNTER : %0d\
+"",$time/PER1);
+ $finish;
+ end
+
+
+ always@(posedge CLK_IN1) begin
+ timeout_counter <= timeout_counter + 1\'b1;
+ if (timeout_counter == 14\'b10000000000000) begin
+ if (LOCKED != 1\'b1) begin
+ $display(""ERROR : NO LOCK signal"");
+ $display(""SYSTEM_CLOCK_COUNTER : %0d\
+"",$time/PER1);
+ $finish;
+ end
+ end
+ end
+
+ // Instantiation of the example design containing the clock
+ // network and sampling counters
+ //---------------------------------------------------------
+ clk_divider_exdes
+ dut
+ (// Clock in ports
+ .CLK_IN1 (CLK_IN1),
+ // Reset for logic in example design
+ .COUNTER_RESET (COUNTER_RESET),
+ .CLK_OUT (CLK_OUT),
+ // High bits of the counters
+ .COUNT (COUNT),
+ // Status and control signals
+ .RESET (RESET),
+ .LOCKED (LOCKED));
+
+
+// Freq Check
+
+endmodule
+"
+"// file: clk_divider.v
+//
+// (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//----------------------------------------------------------------------------
+// User entered comments
+//----------------------------------------------------------------------------
+// None
+//
+//----------------------------------------------------------------------------
+// ""Output Output Phase Duty Pk-to-Pk Phase""
+// ""Clock Freq (MHz) (degrees) Cycle (%) Jitter (ps) Error (ps)""
+//----------------------------------------------------------------------------
+// CLK_OUT1____50.000______0.000______50.0______300.000____150.000
+//
+//----------------------------------------------------------------------------
+// ""Input Clock Freq (MHz) Input Jitter (UI)""
+//----------------------------------------------------------------------------
+// __primary_________100.000____________0.010
+
+`timescale 1ps/1ps
+
+(* CORE_GENERATION_INFO = ""clk_divider,clk_wiz_v3_6,{component_name=clk_divider,use_phase_alignment=true,use_min_o_jitter=false,use_max_i_jitter=false,use_dyn_phase_shift=false,use_inclk_switchover=false,use_dyn_reconfig=false,feedback_source=FDBK_AUTO,primtype_sel=DCM_SP,num_out_clk=1,clkin1_period=10.0,clkin2_period=10.0,use_power_down=false,use_reset=true,use_locked=true,use_inclk_stopped=false,use_status=false,use_freeze=false,use_clk_valid=false,feedback_type=SINGLE,clock_mgr_type=AUTO,manual_override=false}"" *)
+module clk_divider
+ (// Clock in ports
+ input CLK_IN1,
+ // Clock out ports
+ output CLK_OUT1,
+ // Status and control signals
+ input RESET,
+ output LOCKED
+ );
+
+ // Input buffering
+ //------------------------------------
+ IBUFG clkin1_buf
+ (.O (clkin1),
+ .I (CLK_IN1));
+
+
+ // Clocking primitive
+ //------------------------------------
+
+ // Instantiation of the DCM primitive
+ // * Unused inputs are tied off
+ // * Unused outputs are labeled unused
+ wire psdone_unused;
+ wire locked_int;
+ wire [7:0] status_int;
+ wire clkfb;
+ wire clk0;
+ wire clkdv;
+
+ DCM_SP
+ #(.CLKDV_DIVIDE (2.000),
+ .CLKFX_DIVIDE (1),
+ .CLKFX_MULTIPLY (4),
+ .CLKIN_DIVIDE_BY_2 (""FALSE""),
+ .CLKIN_PERIOD (10.0),
+ .CLKOUT_PHASE_SHIFT (""NONE""),
+ .CLK_FEEDBACK (""1X""),
+ .DESKEW_ADJUST (""SYSTEM_SYNCHRONOUS""),
+ .PHASE_SHIFT (0),
+ .STARTUP_WAIT (""FALSE""))
+ dcm_sp_inst
+ // Input clock
+ (.CLKIN (clkin1),
+ .CLKFB (clkfb),
+ // Output clocks
+ .CLK0 (clk0),
+ .CLK90 (),
+ .CLK180 (),
+ .CLK270 (),
+ .CLK2X (),
+ .CLK2X180 (),
+ .CLKFX (),
+ .CLKFX180 (),
+ .CLKDV (clkdv),
+ // Ports for dynamic phase shift
+ .PSCLK (1\'b0),
+ .PSEN (1\'b0),
+ .PSINCDEC (1\'b0),
+ .PSDONE (),
+ // Other control and status signals
+ .LOCKED (locked_int),
+ .STATUS (status_int),
+
+ .RST (RESET),
+ // Unused pin- tie low
+ .DSSEN (1\'b0));
+
+ assign LOCKED = locked_int;
+
+ // Output buffering
+ //-----------------------------------
+ BUFG clkf_buf
+ (.O (clkfb),
+ .I (clk0));
+
+ BUFG clkout1_buf
+ (.O (CLK_OUT1),
+ .I (clkdv));
+
+
+
+
+endmodule
+"
+"// file: clk_divider_exdes.v
+//
+// (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+
+//----------------------------------------------------------------------------
+// Clocking wizard example design
+//----------------------------------------------------------------------------
+// This example design instantiates the created clocking network, where each
+// output clock drives a counter. The high bit of each counter is ported.
+//----------------------------------------------------------------------------
+
+`timescale 1ps/1ps
+
+module clk_divider_exdes
+ #(
+ parameter TCQ = 100
+ )
+ (// Clock in ports
+ input CLK_IN1,
+ // Reset that only drives logic in example design
+ input COUNTER_RESET,
+ output [1:1] CLK_OUT,
+ // High bits of counters driven by clocks
+ output COUNT,
+ // Status and control signals
+ input RESET,
+ output LOCKED
+ );
+
+ // Parameters for the counters
+ //-------------------------------
+ // Counter width
+ localparam C_W = 16;
+ // When the clock goes out of lock, reset the counters
+ wire reset_int = !LOCKED || RESET || COUNTER_RESET;
+
+ reg rst_sync;
+ reg rst_sync_int;
+ reg rst_sync_int1;
+ reg rst_sync_int2;
+
+
+
+ // Declare the clocks and counter
+ wire clk_int;
+ wire clk_n;
+ wire clk;
+ reg [C_W-1:0] counter;
+
+ // Instantiation of the clocking network
+ //--------------------------------------
+ clk_divider clknetwork
+ (// Clock in ports
+ .CLK_IN1 (CLK_IN1),
+ // Clock out ports
+ .CLK_OUT1 (clk_int),
+ // Status and control signals
+ .RESET (RESET),
+ .LOCKED (LOCKED));
+
+ assign clk_n = ~clk;
+
+ ODDR2 clkout_oddr
+ (.Q (CLK_OUT[1]),
+ .C0 (clk),
+ .C1 (clk_n),
+ .CE (1\'b1),
+ .D0 (1\'b1),
+ .D1 (1\'b0),
+ .R (1\'b0),
+ .S (1\'b0));
+
+ // Connect the output clocks to the design
+ //-----------------------------------------
+ assign clk = clk_int;
+
+
+ // Reset synchronizer
+ //-----------------------------------
+ always @(posedge reset_int or posedge clk) begin
+ if (reset_int) begin
+ rst_sync <= 1\'b1;
+ rst_sync_int <= 1\'b1;
+ rst_sync_int1 <= 1\'b1;
+ rst_sync_int2 <= 1\'b1;
+ end
+ else begin
+ rst_sync <= 1\'b0;
+ rst_sync_int <= rst_sync;
+ rst_sync_int1 <= rst_sync_int;
+ rst_sync_int2 <= rst_sync_int1;
+ end
+ end
+
+
+ // Output clock sampling
+ //-----------------------------------
+ always @(posedge clk or posedge rst_sync_int2) begin
+ if (rst_sync_int2) begin
+ counter <= #TCQ { C_W { 1\'b 0 } };
+ end else begin
+ counter <= #TCQ counter + 1\'b 1;
+ end
+ end
+
+ // alias the high bit to the output
+ assign COUNT = counter[C_W-1];
+
+
+
+endmodule
+"
+"////////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2004 Xilinx, Inc.
+// All Rights Reserved
+////////////////////////////////////////////////////////////////////////////////
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor: Xilinx
+// \\ \\ \\/ Version: 1.02
+// \\ \\ Filename: ROM_form.v
+// / / Date Last Modified: September 7 2004
+// /___/ /\\ Date Created: July 2003
+// \\ \\ / \\
+// \\___\\/\\___\\
+//
+//Device: \tXilinx
+//Purpose: \t
+//\tThis is the Verilog template file for the KCPSM3 assembler.
+//\tIt is used to configure a Spartan-3, Virtex-II or Virtex-IIPRO block
+//\tRAM to act as a single port program ROM.
+//
+//\tThis Verilog file is not valid as input directly into a synthesis or
+//\tsimulation tool.\tThe assembler will read this template and insert the
+//\tdata required to complete the definition of program ROM and write it out
+//\tto a new \'.v\' file associated with the name of the original \'.psm\' file
+//\tbeing assembled.
+//
+//\tThis template can be modified to define alternative memory definitions
+//\tsuch as dual port. However, you are responsible for ensuring the template
+//\tis correct as the assembler does not perform any checking of the Verilog.
+//
+//\tThe assembler identifies all text enclosed by {} characters, and replaces
+//\tthese character strings. All templates should include these {} character
+//\tstrings for the assembler to work correctly.
+//
+//\tThis template defines a block RAM configured in 1024 x 18-bit single port
+//\tmode and conneceted to act as a single port ROM.
+//
+//Reference:
+// \tNone
+//Revision History:
+// Rev 1.00 - jc - Converted to verilog, July 2003.
+// Rev 1.01 - sus - Added text to confirm to Xilinx HDL std, August 4 2004.
+// Rev 1.02 - njs - Added attributes for Synplicity August 5 2004.
+//\tRev 1.03 - sus - Added text to conform to Xilinx generated
+//\t\t\t\tHDL spec, September 7 2004
+//
+////////////////////////////////////////////////////////////////////////////////
+// Contact: e-mail picoblaze@xilinx.com
+//////////////////////////////////////////////////////////////////////////////////
+//
+// Disclaimer:
+// LIMITED WARRANTY AND DISCLAIMER. These designs are
+// provided to you ""as is"". Xilinx and its licensors make and you
+// receive no warranties or conditions, express, implied,
+// statutory or otherwise, and Xilinx specifically disclaims any
+// implied warranties of merchantability, non-infringement, or
+// fitness for a particular purpose. Xilinx does not warrant that
+// the functions contained in these designs will meet your
+// requirements, or that the operation of these designs will be
+// uninterrupted or error free, or that defects in the Designs
+// will be corrected. Furthermore, Xilinx does not warrant or
+// make any representations regarding use or the results of the
+// use of the designs in terms of correctness, accuracy,
+// reliability, or otherwise.
+//
+// LIMITATION OF LIABILITY. In no event will Xilinx or its
+// licensors be liable for any loss of data, lost profits, cost
+// or procurement of substitute goods or services, or for any
+// special, incidental, consequential, or indirect damages
+// arising from the use or operation of the designs or
+// accompanying documentation, however caused and on any theory
+// of liability. This limitation will apply even if Xilinx
+// has been advised of the possibility of such damage. This
+// limitation shall apply not-withstanding the failure of the
+// essential purpose of any limited remedies herein.
+//////////////////////////////////////////////////////////////////////////////////
+
+The next line is used to determine where the template actually starts and must exist.
+{begin template}
+////////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2004 Xilinx, Inc.
+// All Rights Reserved
+////////////////////////////////////////////////////////////////////////////////
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor: Xilinx
+// \\ \\ \\/ Version: v1.30
+// \\ \\ Application : KCPSM3
+// / / Filename: {name}.v
+// /___/ /\\
+// \\ \\ / \\
+// \\___\\/\\___\\
+//
+//Command: kcpsm3 {name}.psm
+//Device: Spartan-3, Spartan-3E, Virtex-II, and Virtex-II Pro FPGAs
+//Design Name: {name}
+//Generated {timestamp}.
+//Purpose:
+//\t{name} verilog program definition.
+//
+//Reference:
+//\tPicoBlaze 8-bit Embedded Microcontroller User Guide
+////////////////////////////////////////////////////////////////////////////////
+
+`timescale 1 ps / 1ps
+
+module {name} (address, instruction, clk);
+
+input [9:0] address;
+input clk;
+
+output [17:0] instruction;
+
+RAMB16_S18 ram_1024_x_18(
+\t.DI \t(16\'h0000),
+\t.DIP \t(2\'b00),
+\t.EN\t(1\'b1),
+\t.WE\t(1\'b0),
+\t.SSR\t(1\'b0),
+\t.CLK\t(clk),
+\t.ADDR\t(address),
+\t.DO\t(instruction[15:0]),
+\t.DOP\t(instruction[17:16]))
+/*synthesis
+init_00 = ""{INIT_00}""
+init_01 = ""{INIT_01}""
+init_02 = ""{INIT_02}""
+init_03 = ""{INIT_03}""
+init_04 = ""{INIT_04}""
+init_05 = ""{INIT_05}""
+init_06 = ""{INIT_06}""
+init_07 = ""{INIT_07}""
+init_08 = ""{INIT_08}""
+init_09 = ""{INIT_09}""
+init_0A = ""{INIT_0A}""
+init_0B = ""{INIT_0B}""
+init_0C = ""{INIT_0C}""
+init_0D = ""{INIT_0D}""
+init_0E = ""{INIT_0E}""
+init_0F = ""{INIT_0F}""
+init_10 = ""{INIT_10}""
+init_11 = ""{INIT_11}""
+init_12 = ""{INIT_12}""
+init_13 = ""{INIT_13}""
+init_14 = ""{INIT_14}""
+init_15 = ""{INIT_15}""
+init_16 = ""{INIT_16}""
+init_17 = ""{INIT_17}""
+init_18 = ""{INIT_18}""
+init_19 = ""{INIT_19}""
+init_1A = ""{INIT_1A}""
+init_1B = ""{INIT_1B}""
+init_1C = ""{INIT_1C}""
+init_1D = ""{INIT_1D}""
+init_1E = ""{INIT_1E}""
+init_1F = ""{INIT_1F}""
+init_20 = ""{INIT_20}""
+init_21 = ""{INIT_21}""
+init_22 = ""{INIT_22}""
+init_23 = ""{INIT_23}""
+init_24 = ""{INIT_24}""
+init_25 = ""{INIT_25}""
+init_26 = ""{INIT_26}""
+init_27 = ""{INIT_27}""
+init_28 = ""{INIT_28}""
+init_29 = ""{INIT_29}""
+init_2A = ""{INIT_2A}""
+init_2B = ""{INIT_2B}""
+init_2C = ""{INIT_2C}""
+init_2D = ""{INIT_2D}""
+init_2E = ""{INIT_2E}""
+init_2F = ""{INIT_2F}""
+init_30 = ""{INIT_30}""
+init_31 = ""{INIT_31}""
+init_32 = ""{INIT_32}""
+init_33 = ""{INIT_33}""
+init_34 = ""{INIT_34}""
+init_35 = ""{INIT_35}""
+init_36 = ""{INIT_36}""
+init_37 = ""{INIT_37}""
+init_38 = ""{INIT_38}""
+init_39 = ""{INIT_39}""
+init_3A = ""{INIT_3A}""
+init_3B = ""{INIT_3B}""
+init_3C = ""{INIT_3C}""
+init_3D = ""{INIT_3D}""
+init_3E = ""{INIT_3E}""
+init_3F = ""{INIT_3F}""
+initp_00 = ""{INITP_00}""
+initp_01 = ""{INITP_01}""
+initp_02 = ""{INITP_02}""
+initp_03 = ""{INITP_03}""
+initp_04 = ""{INITP_04}""
+initp_05 = ""{INITP_05}""
+initp_06 = ""{INITP_06}""
+initp_07 = ""{INITP_07}"" */;
+
+// synthesis translate_off
+// Attributes for Simulation
+defparam ram_1024_x_18.INIT_00 = 256\'h{INIT_00};
+defparam ram_1024_x_18.INIT_01 = 256\'h{INIT_01};
+defparam ram_1024_x_18.INIT_02 = 256\'h{INIT_02};
+defparam ram_1024_x_18.INIT_03 = 256\'h{INIT_03};
+defparam ram_1024_x_18.INIT_04 = 256\'h{INIT_04};
+defparam ram_1024_x_18.INIT_05 = 256\'h{INIT_05};
+defparam ram_1024_x_18.INIT_06 = 256\'h{INIT_06};
+defparam ram_1024_x_18.INIT_07 = 256\'h{INIT_07};
+defparam ram_1024_x_18.INIT_08 = 256\'h{INIT_08};
+defparam ram_1024_x_18.INIT_09 = 256\'h{INIT_09};
+defparam ram_1024_x_18.INIT_0A = 256\'h{INIT_0A};
+defparam ram_1024_x_18.INIT_0B = 256\'h{INIT_0B};
+defparam ram_1024_x_18.INIT_0C = 256\'h{INIT_0C};
+defparam ram_1024_x_18.INIT_0D = 256\'h{INIT_0D};
+defparam ram_1024_x_18.INIT_0E = 256\'h{INIT_0E};
+defparam ram_1024_x_18.INIT_0F = 256\'h{INIT_0F};
+defparam ram_1024_x_18.INIT_10 = 256\'h{INIT_10};
+defparam ram_1024_x_18.INIT_11 = 256\'h{INIT_11};
+defparam ram_1024_x_18.INIT_12 = 256\'h{INIT_12};
+defparam ram_1024_x_18.INIT_13 = 256\'h{INIT_13};
+defparam ram_1024_x_18.INIT_14 = 256\'h{INIT_14};
+defparam ram_1024_x_18.INIT_15 = 256\'h{INIT_15};
+defparam ram_1024_x_18.INIT_16 = 256\'h{INIT_16};
+defparam ram_1024_x_18.INIT_17 = 256\'h{INIT_17};
+defparam ram_1024_x_18.INIT_18 = 256\'h{INIT_18};
+defparam ram_1024_x_18.INIT_19 = 256\'h{INIT_19};
+defparam ram_1024_x_18.INIT_1A = 256\'h{INIT_1A};
+defparam ram_1024_x_18.INIT_1B = 256\'h{INIT_1B};
+defparam ram_1024_x_18.INIT_1C = 256\'h{INIT_1C};
+defparam ram_1024_x_18.INIT_1D = 256\'h{INIT_1D};
+defparam ram_1024_x_18.INIT_1E = 256\'h{INIT_1E};
+defparam ram_1024_x_18.INIT_1F = 256\'h{INIT_1F};
+defparam ram_1024_x_18.INIT_20 = 256\'h{INIT_20};
+defparam ram_1024_x_18.INIT_21 = 256\'h{INIT_21};
+defparam ram_1024_x_18.INIT_22 = 256\'h{INIT_22};
+defparam ram_1024_x_18.INIT_23 = 256\'h{INIT_23};
+defparam ram_1024_x_18.INIT_24 = 256\'h{INIT_24};
+defparam ram_1024_x_18.INIT_25 = 256\'h{INIT_25};
+defparam ram_1024_x_18.INIT_26 = 256\'h{INIT_26};
+defparam ram_1024_x_18.INIT_27 = 256\'h{INIT_27};
+defparam ram_1024_x_18.INIT_28 = 256\'h{INIT_28};
+defparam ram_1024_x_18.INIT_29 = 256\'h{INIT_29};
+defparam ram_1024_x_18.INIT_2A = 256\'h{INIT_2A};
+defparam ram_1024_x_18.INIT_2B = 256\'h{INIT_2B};
+defparam ram_1024_x_18.INIT_2C = 256\'h{INIT_2C};
+defparam ram_1024_x_18.INIT_2D = 256\'h{INIT_2D};
+defparam ram_1024_x_18.INIT_2E = 256\'h{INIT_2E};
+defparam ram_1024_x_18.INIT_2F = 256\'h{INIT_2F};
+defparam ram_1024_x_18.INIT_30 = 256\'h{INIT_30};
+defparam ram_1024_x_18.INIT_31 = 256\'h{INIT_31};
+defparam ram_1024_x_18.INIT_32 = 256\'h{INIT_32};
+defparam ram_1024_x_18.INIT_33 = 256\'h{INIT_33};
+defparam ram_1024_x_18.INIT_34 = 256\'h{INIT_34};
+defparam ram_1024_x_18.INIT_35 = 256\'h{INIT_35};
+defparam ram_1024_x_18.INIT_36 = 256\'h{INIT_36};
+defparam ram_1024_x_18.INIT_37 = 256\'h{INIT_37};
+defparam ram_1024_x_18.INIT_38 = 256\'h{INIT_38};
+defparam ram_1024_x_18.INIT_39 = 256\'h{INIT_39};
+defparam ram_1024_x_18.INIT_3A = 256\'h{INIT_3A};
+defparam ram_1024_x_18.INIT_3B = 256\'h{INIT_3B};
+defparam ram_1024_x_18.INIT_3C = 256\'h{INIT_3C};
+defparam ram_1024_x_18.INIT_3D = 256\'h{INIT_3D};
+defparam ram_1024_x_18.INIT_3E = 256\'h{INIT_3E};
+defparam ram_1024_x_18.INIT_3F = 256\'h{INIT_3F};
+defparam ram_1024_x_18.INITP_00 = 256\'h{INITP_00};
+defparam ram_1024_x_18.INITP_01 = 256\'h{INITP_01};
+defparam ram_1024_x_18.INITP_02 = 256\'h{INITP_02};
+defparam ram_1024_x_18.INITP_03 = 256\'h{INITP_03};
+defparam ram_1024_x_18.INITP_04 = 256\'h{INITP_04};
+defparam ram_1024_x_18.INITP_05 = 256\'h{INITP_05};
+defparam ram_1024_x_18.INITP_06 = 256\'h{INITP_06};
+defparam ram_1024_x_18.INITP_07 = 256\'h{INITP_07};
+
+// synthesis translate_on
+// Attributes for XST (Synplicity attributes are in-line)
+// synthesis attribute INIT_00 of ram_1024_x_18 is ""{INIT_00}""
+// synthesis attribute INIT_01 of ram_1024_x_18 is ""{INIT_01}""
+// synthesis attribute INIT_02 of ram_1024_x_18 is ""{INIT_02}""
+// synthesis attribute INIT_03 of ram_1024_x_18 is ""{INIT_03}""
+// synthesis attribute INIT_04 of ram_1024_x_18 is ""{INIT_04}""
+// synthesis attribute INIT_05 of ram_1024_x_18 is ""{INIT_05}""
+// synthesis attribute INIT_06 of ram_1024_x_18 is ""{INIT_06}""
+// synthesis attribute INIT_07 of ram_1024_x_18 is ""{INIT_07}""
+// synthesis attribute INIT_08 of ram_1024_x_18 is ""{INIT_08}""
+// synthesis attribute INIT_09 of ram_1024_x_18 is ""{INIT_09}""
+// synthesis attribute INIT_0A of ram_1024_x_18 is ""{INIT_0A}""
+// synthesis attribute INIT_0B of ram_1024_x_18 is ""{INIT_0B}""
+// synthesis attribute INIT_0C of ram_1024_x_18 is ""{INIT_0C}""
+// synthesis attribute INIT_0D of ram_1024_x_18 is ""{INIT_0D}""
+// synthesis attribute INIT_0E of ram_1024_x_18 is ""{INIT_0E}""
+// synthesis attribute INIT_0F of ram_1024_x_18 is ""{INIT_0F}""
+// synthesis attribute INIT_10 of ram_1024_x_18 is ""{INIT_10}""
+// synthesis attribute INIT_11 of ram_1024_x_18 is ""{INIT_11}""
+// synthesis attribute INIT_12 of ram_1024_x_18 is ""{INIT_12}""
+// synthesis attribute INIT_13 of ram_1024_x_18 is ""{INIT_13}""
+// synthesis attribute INIT_14 of ram_1024_x_18 is ""{INIT_14}""
+// synthesis attribute INIT_15 of ram_1024_x_18 is ""{INIT_15}""
+// synthesis attribute INIT_16 of ram_1024_x_18 is ""{INIT_16}""
+// synthesis attribute INIT_17 of ram_1024_x_18 is ""{INIT_17}""
+// synthesis attribute INIT_18 of ram_1024_x_18 is ""{INIT_18}""
+// synthesis attribute INIT_19 of ram_1024_x_18 is ""{INIT_19}""
+// synthesis attribute INIT_1A of ram_1024_x_18 is ""{INIT_1A}""
+// synthesis attribute INIT_1B of ram_1024_x_18 is ""{INIT_1B}""
+// synthesis attribute INIT_1C of ram_1024_x_18 is ""{INIT_1C}""
+// synthesis attribute INIT_1D of ram_1024_x_18 is ""{INIT_1D}""
+// synthesis attribute INIT_1E of ram_1024_x_18 is ""{INIT_1E}""
+// synthesis attribute INIT_1F of ram_1024_x_18 is ""{INIT_1F}""
+// synthesis attribute INIT_20 of ram_1024_x_18 is ""{INIT_20}""
+// synthesis attribute INIT_21 of ram_1024_x_18 is ""{INIT_21}""
+// synthesis attribute INIT_22 of ram_1024_x_18 is ""{INIT_22}""
+// synthesis attribute INIT_23 of ram_1024_x_18 is ""{INIT_23}""
+// synthesis attribute INIT_24 of ram_1024_x_18 is ""{INIT_24}""
+// synthesis attribute INIT_25 of ram_1024_x_18 is ""{INIT_25}""
+// synthesis attribute INIT_26 of ram_1024_x_18 is ""{INIT_26}""
+// synthesis attribute INIT_27 of ram_1024_x_18 is ""{INIT_27}""
+// synthesis attribute INIT_28 of ram_1024_x_18 is ""{INIT_28}""
+// synthesis attribute INIT_29 of ram_1024_x_18 is ""{INIT_29}""
+// synthesis attribute INIT_2A of ram_1024_x_18 is ""{INIT_2A}""
+// synthesis attribute INIT_2B of ram_1024_x_18 is ""{INIT_2B}""
+// synthesis attribute INIT_2C of ram_1024_x_18 is ""{INIT_2C}""
+// synthesis attribute INIT_2D of ram_1024_x_18 is ""{INIT_2D}""
+// synthesis attribute INIT_2E of ram_1024_x_18 is ""{INIT_2E}""
+// synthesis attribute INIT_2F of ram_1024_x_18 is ""{INIT_2F}""
+// synthesis attribute INIT_30 of ram_1024_x_18 is ""{INIT_30}""
+// synthesis attribute INIT_31 of ram_1024_x_18 is ""{INIT_31}""
+// synthesis attribute INIT_32 of ram_1024_x_18 is ""{INIT_32}""
+// synthesis attribute INIT_33 of ram_1024_x_18 is ""{INIT_33}""
+// synthesis attribute INIT_34 of ram_1024_x_18 is ""{INIT_34}""
+// synthesis attribute INIT_35 of ram_1024_x_18 is ""{INIT_35}""
+// synthesis attribute INIT_36 of ram_1024_x_18 is ""{INIT_36}""
+// synthesis attribute INIT_37 of ram_1024_x_18 is ""{INIT_37}""
+// synthesis attribute INIT_38 of ram_1024_x_18 is ""{INIT_38}""
+// synthesis attribute INIT_39 of ram_1024_x_18 is ""{INIT_39}""
+// synthesis attribute INIT_3A of ram_1024_x_18 is ""{INIT_3A}""
+// synthesis attribute INIT_3B of ram_1024_x_18 is ""{INIT_3B}""
+// synthesis attribute INIT_3C of ram_1024_x_18 is ""{INIT_3C}""
+// synthesis attribute INIT_3D of ram_1024_x_18 is ""{INIT_3D}""
+// synthesis attribute INIT_3E of ram_1024_x_18 is ""{INIT_3E}""
+// synthesis attribute INIT_3F of ram_1024_x_18 is ""{INIT_3F}""
+// synthesis attribute INITP_00 of ram_1024_x_18 is ""{INITP_00}""
+// synthesis attribute INITP_01 of ram_1024_x_18 is ""{INITP_01}""
+// synthesis attribute INITP_02 of ram_1024_x_18 is ""{INITP_02}""
+// synthesis attribute INITP_03 of ram_1024_x_18 is ""{INITP_03}""
+// synthesis attribute INITP_04 of ram_1024_x_18 is ""{INITP_04}""
+// synthesis attribute INITP_05 of ram_1024_x_18 is ""{INITP_05}""
+// synthesis attribute INITP_06 of ram_1024_x_18 is ""{INITP_06}""
+// synthesis attribute INITP_07 of ram_1024_x_18 is ""{INITP_07}""
+
+endmodule
+
+// END OF FILE {name}.v"
+"////////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2004 Xilinx, Inc.
+// All Rights Reserved
+////////////////////////////////////////////////////////////////////////////////
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor: Xilinx
+// \\ \\ \\/ Version: 1.02
+// \\ \\ Filename: ROM_form.v
+// / / Date Last Modified: September 7 2004
+// /___/ /\\ Date Created: July 2003
+// \\ \\ / \\
+// \\___\\/\\___\\
+//
+//Device: \tXilinx
+//Purpose: \t
+//\tThis is the Verilog template file for the KCPSM3 assembler.
+//\tIt is used to configure a Spartan-3, Virtex-II or Virtex-IIPRO block
+//\tRAM to act as a single port program ROM.
+//
+//\tThis Verilog file is not valid as input directly into a synthesis or
+//\tsimulation tool.\tThe assembler will read this template and insert the
+//\tdata required to complete the definition of program ROM and write it out
+//\tto a new \'.v\' file associated with the name of the original \'.psm\' file
+//\tbeing assembled.
+//
+//\tThis template can be modified to define alternative memory definitions
+//\tsuch as dual port. However, you are responsible for ensuring the template
+//\tis correct as the assembler does not perform any checking of the Verilog.
+//
+//\tThe assembler identifies all text enclosed by {} characters, and replaces
+//\tthese character strings. All templates should include these {} character
+//\tstrings for the assembler to work correctly.
+//
+//\tThis template defines a block RAM configured in 1024 x 18-bit single port
+//\tmode and conneceted to act as a single port ROM.
+//
+//Reference:
+// \tNone
+//Revision History:
+// Rev 1.00 - jc - Converted to verilog, July 2003.
+// Rev 1.01 - sus - Added text to confirm to Xilinx HDL std, August 4 2004.
+// Rev 1.02 - njs - Added attributes for Synplicity August 5 2004.
+//\tRev 1.03 - sus - Added text to conform to Xilinx generated
+//\t\t\t\tHDL spec, September 7 2004
+//
+////////////////////////////////////////////////////////////////////////////////
+// Contact: e-mail picoblaze@xilinx.com
+//////////////////////////////////////////////////////////////////////////////////
+//
+// Disclaimer:
+// LIMITED WARRANTY AND DISCLAIMER. These designs are
+// provided to you ""as is"". Xilinx and its licensors make and you
+// receive no warranties or conditions, express, implied,
+// statutory or otherwise, and Xilinx specifically disclaims any
+// implied warranties of merchantability, non-infringement, or
+// fitness for a particular purpose. Xilinx does not warrant that
+// the functions contained in these designs will meet your
+// requirements, or that the operation of these designs will be
+// uninterrupted or error free, or that defects in the Designs
+// will be corrected. Furthermore, Xilinx does not warrant or
+// make any representations regarding use or the results of the
+// use of the designs in terms of correctness, accuracy,
+// reliability, or otherwise.
+//
+// LIMITATION OF LIABILITY. In no event will Xilinx or its
+// licensors be liable for any loss of data, lost profits, cost
+// or procurement of substitute goods or services, or for any
+// special, incidental, consequential, or indirect damages
+// arising from the use or operation of the designs or
+// accompanying documentation, however caused and on any theory
+// of liability. This limitation will apply even if Xilinx
+// has been advised of the possibility of such damage. This
+// limitation shall apply not-withstanding the failure of the
+// essential purpose of any limited remedies herein.
+//////////////////////////////////////////////////////////////////////////////////
+
+The next line is used to determine where the template actually starts and must exist.
+{begin template}
+////////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2004 Xilinx, Inc.
+// All Rights Reserved
+////////////////////////////////////////////////////////////////////////////////
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor: Xilinx
+// \\ \\ \\/ Version: v1.30
+// \\ \\ Application : KCPSM3
+// / / Filename: {name}.v
+// /___/ /\\
+// \\ \\ / \\
+// \\___\\/\\___\\
+//
+//Command: kcpsm3 {name}.psm
+//Device: Spartan-3, Spartan-3E, Virtex-II, and Virtex-II Pro FPGAs
+//Design Name: {name}
+//Generated {timestamp}.
+//Purpose:
+//\t{name} verilog program definition.
+//
+//Reference:
+//\tPicoBlaze 8-bit Embedded Microcontroller User Guide
+////////////////////////////////////////////////////////////////////////////////
+
+`timescale 1 ps / 1ps
+
+module {name} (address, instruction, clk);
+
+input [9:0] address;
+input clk;
+
+output [17:0] instruction;
+
+RAMB16_S18 ram_1024_x_18(
+\t.DI \t(16\'h0000),
+\t.DIP \t(2\'b00),
+\t.EN\t(1\'b1),
+\t.WE\t(1\'b0),
+\t.SSR\t(1\'b0),
+\t.CLK\t(clk),
+\t.ADDR\t(address),
+\t.DO\t(instruction[15:0]),
+\t.DOP\t(instruction[17:16]))
+/*synthesis
+init_00 = ""{INIT_00}""
+init_01 = ""{INIT_01}""
+init_02 = ""{INIT_02}""
+init_03 = ""{INIT_03}""
+init_04 = ""{INIT_04}""
+init_05 = ""{INIT_05}""
+init_06 = ""{INIT_06}""
+init_07 = ""{INIT_07}""
+init_08 = ""{INIT_08}""
+init_09 = ""{INIT_09}""
+init_0A = ""{INIT_0A}""
+init_0B = ""{INIT_0B}""
+init_0C = ""{INIT_0C}""
+init_0D = ""{INIT_0D}""
+init_0E = ""{INIT_0E}""
+init_0F = ""{INIT_0F}""
+init_10 = ""{INIT_10}""
+init_11 = ""{INIT_11}""
+init_12 = ""{INIT_12}""
+init_13 = ""{INIT_13}""
+init_14 = ""{INIT_14}""
+init_15 = ""{INIT_15}""
+init_16 = ""{INIT_16}""
+init_17 = ""{INIT_17}""
+init_18 = ""{INIT_18}""
+init_19 = ""{INIT_19}""
+init_1A = ""{INIT_1A}""
+init_1B = ""{INIT_1B}""
+init_1C = ""{INIT_1C}""
+init_1D = ""{INIT_1D}""
+init_1E = ""{INIT_1E}""
+init_1F = ""{INIT_1F}""
+init_20 = ""{INIT_20}""
+init_21 = ""{INIT_21}""
+init_22 = ""{INIT_22}""
+init_23 = ""{INIT_23}""
+init_24 = ""{INIT_24}""
+init_25 = ""{INIT_25}""
+init_26 = ""{INIT_26}""
+init_27 = ""{INIT_27}""
+init_28 = ""{INIT_28}""
+init_29 = ""{INIT_29}""
+init_2A = ""{INIT_2A}""
+init_2B = ""{INIT_2B}""
+init_2C = ""{INIT_2C}""
+init_2D = ""{INIT_2D}""
+init_2E = ""{INIT_2E}""
+init_2F = ""{INIT_2F}""
+init_30 = ""{INIT_30}""
+init_31 = ""{INIT_31}""
+init_32 = ""{INIT_32}""
+init_33 = ""{INIT_33}""
+init_34 = ""{INIT_34}""
+init_35 = ""{INIT_35}""
+init_36 = ""{INIT_36}""
+init_37 = ""{INIT_37}""
+init_38 = ""{INIT_38}""
+init_39 = ""{INIT_39}""
+init_3A = ""{INIT_3A}""
+init_3B = ""{INIT_3B}""
+init_3C = ""{INIT_3C}""
+init_3D = ""{INIT_3D}""
+init_3E = ""{INIT_3E}""
+init_3F = ""{INIT_3F}""
+initp_00 = ""{INITP_00}""
+initp_01 = ""{INITP_01}""
+initp_02 = ""{INITP_02}""
+initp_03 = ""{INITP_03}""
+initp_04 = ""{INITP_04}""
+initp_05 = ""{INITP_05}""
+initp_06 = ""{INITP_06}""
+initp_07 = ""{INITP_07}"" */;
+
+// synthesis translate_off
+// Attributes for Simulation
+defparam ram_1024_x_18.INIT_00 = 256\'h{INIT_00};
+defparam ram_1024_x_18.INIT_01 = 256\'h{INIT_01};
+defparam ram_1024_x_18.INIT_02 = 256\'h{INIT_02};
+defparam ram_1024_x_18.INIT_03 = 256\'h{INIT_03};
+defparam ram_1024_x_18.INIT_04 = 256\'h{INIT_04};
+defparam ram_1024_x_18.INIT_05 = 256\'h{INIT_05};
+defparam ram_1024_x_18.INIT_06 = 256\'h{INIT_06};
+defparam ram_1024_x_18.INIT_07 = 256\'h{INIT_07};
+defparam ram_1024_x_18.INIT_08 = 256\'h{INIT_08};
+defparam ram_1024_x_18.INIT_09 = 256\'h{INIT_09};
+defparam ram_1024_x_18.INIT_0A = 256\'h{INIT_0A};
+defparam ram_1024_x_18.INIT_0B = 256\'h{INIT_0B};
+defparam ram_1024_x_18.INIT_0C = 256\'h{INIT_0C};
+defparam ram_1024_x_18.INIT_0D = 256\'h{INIT_0D};
+defparam ram_1024_x_18.INIT_0E = 256\'h{INIT_0E};
+defparam ram_1024_x_18.INIT_0F = 256\'h{INIT_0F};
+defparam ram_1024_x_18.INIT_10 = 256\'h{INIT_10};
+defparam ram_1024_x_18.INIT_11 = 256\'h{INIT_11};
+defparam ram_1024_x_18.INIT_12 = 256\'h{INIT_12};
+defparam ram_1024_x_18.INIT_13 = 256\'h{INIT_13};
+defparam ram_1024_x_18.INIT_14 = 256\'h{INIT_14};
+defparam ram_1024_x_18.INIT_15 = 256\'h{INIT_15};
+defparam ram_1024_x_18.INIT_16 = 256\'h{INIT_16};
+defparam ram_1024_x_18.INIT_17 = 256\'h{INIT_17};
+defparam ram_1024_x_18.INIT_18 = 256\'h{INIT_18};
+defparam ram_1024_x_18.INIT_19 = 256\'h{INIT_19};
+defparam ram_1024_x_18.INIT_1A = 256\'h{INIT_1A};
+defparam ram_1024_x_18.INIT_1B = 256\'h{INIT_1B};
+defparam ram_1024_x_18.INIT_1C = 256\'h{INIT_1C};
+defparam ram_1024_x_18.INIT_1D = 256\'h{INIT_1D};
+defparam ram_1024_x_18.INIT_1E = 256\'h{INIT_1E};
+defparam ram_1024_x_18.INIT_1F = 256\'h{INIT_1F};
+defparam ram_1024_x_18.INIT_20 = 256\'h{INIT_20};
+defparam ram_1024_x_18.INIT_21 = 256\'h{INIT_21};
+defparam ram_1024_x_18.INIT_22 = 256\'h{INIT_22};
+defparam ram_1024_x_18.INIT_23 = 256\'h{INIT_23};
+defparam ram_1024_x_18.INIT_24 = 256\'h{INIT_24};
+defparam ram_1024_x_18.INIT_25 = 256\'h{INIT_25};
+defparam ram_1024_x_18.INIT_26 = 256\'h{INIT_26};
+defparam ram_1024_x_18.INIT_27 = 256\'h{INIT_27};
+defparam ram_1024_x_18.INIT_28 = 256\'h{INIT_28};
+defparam ram_1024_x_18.INIT_29 = 256\'h{INIT_29};
+defparam ram_1024_x_18.INIT_2A = 256\'h{INIT_2A};
+defparam ram_1024_x_18.INIT_2B = 256\'h{INIT_2B};
+defparam ram_1024_x_18.INIT_2C = 256\'h{INIT_2C};
+defparam ram_1024_x_18.INIT_2D = 256\'h{INIT_2D};
+defparam ram_1024_x_18.INIT_2E = 256\'h{INIT_2E};
+defparam ram_1024_x_18.INIT_2F = 256\'h{INIT_2F};
+defparam ram_1024_x_18.INIT_30 = 256\'h{INIT_30};
+defparam ram_1024_x_18.INIT_31 = 256\'h{INIT_31};
+defparam ram_1024_x_18.INIT_32 = 256\'h{INIT_32};
+defparam ram_1024_x_18.INIT_33 = 256\'h{INIT_33};
+defparam ram_1024_x_18.INIT_34 = 256\'h{INIT_34};
+defparam ram_1024_x_18.INIT_35 = 256\'h{INIT_35};
+defparam ram_1024_x_18.INIT_36 = 256\'h{INIT_36};
+defparam ram_1024_x_18.INIT_37 = 256\'h{INIT_37};
+defparam ram_1024_x_18.INIT_38 = 256\'h{INIT_38};
+defparam ram_1024_x_18.INIT_39 = 256\'h{INIT_39};
+defparam ram_1024_x_18.INIT_3A = 256\'h{INIT_3A};
+defparam ram_1024_x_18.INIT_3B = 256\'h{INIT_3B};
+defparam ram_1024_x_18.INIT_3C = 256\'h{INIT_3C};
+defparam ram_1024_x_18.INIT_3D = 256\'h{INIT_3D};
+defparam ram_1024_x_18.INIT_3E = 256\'h{INIT_3E};
+defparam ram_1024_x_18.INIT_3F = 256\'h{INIT_3F};
+defparam ram_1024_x_18.INITP_00 = 256\'h{INITP_00};
+defparam ram_1024_x_18.INITP_01 = 256\'h{INITP_01};
+defparam ram_1024_x_18.INITP_02 = 256\'h{INITP_02};
+defparam ram_1024_x_18.INITP_03 = 256\'h{INITP_03};
+defparam ram_1024_x_18.INITP_04 = 256\'h{INITP_04};
+defparam ram_1024_x_18.INITP_05 = 256\'h{INITP_05};
+defparam ram_1024_x_18.INITP_06 = 256\'h{INITP_06};
+defparam ram_1024_x_18.INITP_07 = 256\'h{INITP_07};
+
+// synthesis translate_on
+// Attributes for XST (Synplicity attributes are in-line)
+// synthesis attribute INIT_00 of ram_1024_x_18 is ""{INIT_00}""
+// synthesis attribute INIT_01 of ram_1024_x_18 is ""{INIT_01}""
+// synthesis attribute INIT_02 of ram_1024_x_18 is ""{INIT_02}""
+// synthesis attribute INIT_03 of ram_1024_x_18 is ""{INIT_03}""
+// synthesis attribute INIT_04 of ram_1024_x_18 is ""{INIT_04}""
+// synthesis attribute INIT_05 of ram_1024_x_18 is ""{INIT_05}""
+// synthesis attribute INIT_06 of ram_1024_x_18 is ""{INIT_06}""
+// synthesis attribute INIT_07 of ram_1024_x_18 is ""{INIT_07}""
+// synthesis attribute INIT_08 of ram_1024_x_18 is ""{INIT_08}""
+// synthesis attribute INIT_09 of ram_1024_x_18 is ""{INIT_09}""
+// synthesis attribute INIT_0A of ram_1024_x_18 is ""{INIT_0A}""
+// synthesis attribute INIT_0B of ram_1024_x_18 is ""{INIT_0B}""
+// synthesis attribute INIT_0C of ram_1024_x_18 is ""{INIT_0C}""
+// synthesis attribute INIT_0D of ram_1024_x_18 is ""{INIT_0D}""
+// synthesis attribute INIT_0E of ram_1024_x_18 is ""{INIT_0E}""
+// synthesis attribute INIT_0F of ram_1024_x_18 is ""{INIT_0F}""
+// synthesis attribute INIT_10 of ram_1024_x_18 is ""{INIT_10}""
+// synthesis attribute INIT_11 of ram_1024_x_18 is ""{INIT_11}""
+// synthesis attribute INIT_12 of ram_1024_x_18 is ""{INIT_12}""
+// synthesis attribute INIT_13 of ram_1024_x_18 is ""{INIT_13}""
+// synthesis attribute INIT_14 of ram_1024_x_18 is ""{INIT_14}""
+// synthesis attribute INIT_15 of ram_1024_x_18 is ""{INIT_15}""
+// synthesis attribute INIT_16 of ram_1024_x_18 is ""{INIT_16}""
+// synthesis attribute INIT_17 of ram_1024_x_18 is ""{INIT_17}""
+// synthesis attribute INIT_18 of ram_1024_x_18 is ""{INIT_18}""
+// synthesis attribute INIT_19 of ram_1024_x_18 is ""{INIT_19}""
+// synthesis attribute INIT_1A of ram_1024_x_18 is ""{INIT_1A}""
+// synthesis attribute INIT_1B of ram_1024_x_18 is ""{INIT_1B}""
+// synthesis attribute INIT_1C of ram_1024_x_18 is ""{INIT_1C}""
+// synthesis attribute INIT_1D of ram_1024_x_18 is ""{INIT_1D}""
+// synthesis attribute INIT_1E of ram_1024_x_18 is ""{INIT_1E}""
+// synthesis attribute INIT_1F of ram_1024_x_18 is ""{INIT_1F}""
+// synthesis attribute INIT_20 of ram_1024_x_18 is ""{INIT_20}""
+// synthesis attribute INIT_21 of ram_1024_x_18 is ""{INIT_21}""
+// synthesis attribute INIT_22 of ram_1024_x_18 is ""{INIT_22}""
+// synthesis attribute INIT_23 of ram_1024_x_18 is ""{INIT_23}""
+// synthesis attribute INIT_24 of ram_1024_x_18 is ""{INIT_24}""
+// synthesis attribute INIT_25 of ram_1024_x_18 is ""{INIT_25}""
+// synthesis attribute INIT_26 of ram_1024_x_18 is ""{INIT_26}""
+// synthesis attribute INIT_27 of ram_1024_x_18 is ""{INIT_27}""
+// synthesis attribute INIT_28 of ram_1024_x_18 is ""{INIT_28}""
+// synthesis attribute INIT_29 of ram_1024_x_18 is ""{INIT_29}""
+// synthesis attribute INIT_2A of ram_1024_x_18 is ""{INIT_2A}""
+// synthesis attribute INIT_2B of ram_1024_x_18 is ""{INIT_2B}""
+// synthesis attribute INIT_2C of ram_1024_x_18 is ""{INIT_2C}""
+// synthesis attribute INIT_2D of ram_1024_x_18 is ""{INIT_2D}""
+// synthesis attribute INIT_2E of ram_1024_x_18 is ""{INIT_2E}""
+// synthesis attribute INIT_2F of ram_1024_x_18 is ""{INIT_2F}""
+// synthesis attribute INIT_30 of ram_1024_x_18 is ""{INIT_30}""
+// synthesis attribute INIT_31 of ram_1024_x_18 is ""{INIT_31}""
+// synthesis attribute INIT_32 of ram_1024_x_18 is ""{INIT_32}""
+// synthesis attribute INIT_33 of ram_1024_x_18 is ""{INIT_33}""
+// synthesis attribute INIT_34 of ram_1024_x_18 is ""{INIT_34}""
+// synthesis attribute INIT_35 of ram_1024_x_18 is ""{INIT_35}""
+// synthesis attribute INIT_36 of ram_1024_x_18 is ""{INIT_36}""
+// synthesis attribute INIT_37 of ram_1024_x_18 is ""{INIT_37}""
+// synthesis attribute INIT_38 of ram_1024_x_18 is ""{INIT_38}""
+// synthesis attribute INIT_39 of ram_1024_x_18 is ""{INIT_39}""
+// synthesis attribute INIT_3A of ram_1024_x_18 is ""{INIT_3A}""
+// synthesis attribute INIT_3B of ram_1024_x_18 is ""{INIT_3B}""
+// synthesis attribute INIT_3C of ram_1024_x_18 is ""{INIT_3C}""
+// synthesis attribute INIT_3D of ram_1024_x_18 is ""{INIT_3D}""
+// synthesis attribute INIT_3E of ram_1024_x_18 is ""{INIT_3E}""
+// synthesis attribute INIT_3F of ram_1024_x_18 is ""{INIT_3F}""
+// synthesis attribute INITP_00 of ram_1024_x_18 is ""{INITP_00}""
+// synthesis attribute INITP_01 of ram_1024_x_18 is ""{INITP_01}""
+// synthesis attribute INITP_02 of ram_1024_x_18 is ""{INITP_02}""
+// synthesis attribute INITP_03 of ram_1024_x_18 is ""{INITP_03}""
+// synthesis attribute INITP_04 of ram_1024_x_18 is ""{INITP_04}""
+// synthesis attribute INITP_05 of ram_1024_x_18 is ""{INITP_05}""
+// synthesis attribute INITP_06 of ram_1024_x_18 is ""{INITP_06}""
+// synthesis attribute INITP_07 of ram_1024_x_18 is ""{INITP_07}""
+
+endmodule
+
+// END OF FILE {name}.v"
+"////////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2004 Xilinx, Inc.
+// All Rights Reserved
+////////////////////////////////////////////////////////////////////////////////
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor: Xilinx
+// \\ \\ \\/ Version: 1.02
+// \\ \\ Filename: ROM_form.v
+// / / Date Last Modified: September 7 2004
+// /___/ /\\ Date Created: July 2003
+// \\ \\ / \\
+// \\___\\/\\___\\
+//
+//Device: \tXilinx
+//Purpose: \t
+//\tThis is the Verilog template file for the KCPSM3 assembler.
+//\tIt is used to configure a Spartan-3, Virtex-II or Virtex-IIPRO block
+//\tRAM to act as a single port program ROM.
+//
+//\tThis Verilog file is not valid as input directly into a synthesis or
+//\tsimulation tool.\tThe assembler will read this template and insert the
+//\tdata required to complete the definition of program ROM and write it out
+//\tto a new \'.v\' file associated with the name of the original \'.psm\' file
+//\tbeing assembled.
+//
+//\tThis template can be modified to define alternative memory definitions
+//\tsuch as dual port. However, you are responsible for ensuring the template
+//\tis correct as the assembler does not perform any checking of the Verilog.
+//
+//\tThe assembler identifies all text enclosed by {} characters, and replaces
+//\tthese character strings. All templates should include these {} character
+//\tstrings for the assembler to work correctly.
+//
+//\tThis template defines a block RAM configured in 1024 x 18-bit single port
+//\tmode and conneceted to act as a single port ROM.
+//
+//Reference:
+// \tNone
+//Revision History:
+// Rev 1.00 - jc - Converted to verilog, July 2003.
+// Rev 1.01 - sus - Added text to confirm to Xilinx HDL std, August 4 2004.
+// Rev 1.02 - njs - Added attributes for Synplicity August 5 2004.
+//\tRev 1.03 - sus - Added text to conform to Xilinx generated
+//\t\t\t\tHDL spec, September 7 2004
+//
+////////////////////////////////////////////////////////////////////////////////
+// Contact: e-mail picoblaze@xilinx.com
+//////////////////////////////////////////////////////////////////////////////////
+//
+// Disclaimer:
+// LIMITED WARRANTY AND DISCLAIMER. These designs are
+// provided to you ""as is"". Xilinx and its licensors make and you
+// receive no warranties or conditions, express, implied,
+// statutory or otherwise, and Xilinx specifically disclaims any
+// implied warranties of merchantability, non-infringement, or
+// fitness for a particular purpose. Xilinx does not warrant that
+// the functions contained in these designs will meet your
+// requirements, or that the operation of these designs will be
+// uninterrupted or error free, or that defects in the Designs
+// will be corrected. Furthermore, Xilinx does not warrant or
+// make any representations regarding use or the results of the
+// use of the designs in terms of correctness, accuracy,
+// reliability, or otherwise.
+//
+// LIMITATION OF LIABILITY. In no event will Xilinx or its
+// licensors be liable for any loss of data, lost profits, cost
+// or procurement of substitute goods or services, or for any
+// special, incidental, consequential, or indirect damages
+// arising from the use or operation of the designs or
+// accompanying documentation, however caused and on any theory
+// of liability. This limitation will apply even if Xilinx
+// has been advised of the possibility of such damage. This
+// limitation shall apply not-withstanding the failure of the
+// essential purpose of any limited remedies herein.
+//////////////////////////////////////////////////////////////////////////////////
+
+The next line is used to determine where the template actually starts and must exist.
+{begin template}
+////////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2004 Xilinx, Inc.
+// All Rights Reserved
+////////////////////////////////////////////////////////////////////////////////
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor: Xilinx
+// \\ \\ \\/ Version: v1.30
+// \\ \\ Application : KCPSM3
+// / / Filename: {name}.v
+// /___/ /\\
+// \\ \\ / \\
+// \\___\\/\\___\\
+//
+//Command: kcpsm3 {name}.psm
+//Device: Spartan-3, Spartan-3E, Virtex-II, and Virtex-II Pro FPGAs
+//Design Name: {name}
+//Generated {timestamp}.
+//Purpose:
+//\t{name} verilog program definition.
+//
+//Reference:
+//\tPicoBlaze 8-bit Embedded Microcontroller User Guide
+////////////////////////////////////////////////////////////////////////////////
+
+`timescale 1 ps / 1ps
+
+module {name} (address, instruction, clk);
+
+input [9:0] address;
+input clk;
+
+output [17:0] instruction;
+
+RAMB16_S18 ram_1024_x_18(
+\t.DI \t(16\'h0000),
+\t.DIP \t(2\'b00),
+\t.EN\t(1\'b1),
+\t.WE\t(1\'b0),
+\t.SSR\t(1\'b0),
+\t.CLK\t(clk),
+\t.ADDR\t(address),
+\t.DO\t(instruction[15:0]),
+\t.DOP\t(instruction[17:16]))
+/*synthesis
+init_00 = ""{INIT_00}""
+init_01 = ""{INIT_01}""
+init_02 = ""{INIT_02}""
+init_03 = ""{INIT_03}""
+init_04 = ""{INIT_04}""
+init_05 = ""{INIT_05}""
+init_06 = ""{INIT_06}""
+init_07 = ""{INIT_07}""
+init_08 = ""{INIT_08}""
+init_09 = ""{INIT_09}""
+init_0A = ""{INIT_0A}""
+init_0B = ""{INIT_0B}""
+init_0C = ""{INIT_0C}""
+init_0D = ""{INIT_0D}""
+init_0E = ""{INIT_0E}""
+init_0F = ""{INIT_0F}""
+init_10 = ""{INIT_10}""
+init_11 = ""{INIT_11}""
+init_12 = ""{INIT_12}""
+init_13 = ""{INIT_13}""
+init_14 = ""{INIT_14}""
+init_15 = ""{INIT_15}""
+init_16 = ""{INIT_16}""
+init_17 = ""{INIT_17}""
+init_18 = ""{INIT_18}""
+init_19 = ""{INIT_19}""
+init_1A = ""{INIT_1A}""
+init_1B = ""{INIT_1B}""
+init_1C = ""{INIT_1C}""
+init_1D = ""{INIT_1D}""
+init_1E = ""{INIT_1E}""
+init_1F = ""{INIT_1F}""
+init_20 = ""{INIT_20}""
+init_21 = ""{INIT_21}""
+init_22 = ""{INIT_22}""
+init_23 = ""{INIT_23}""
+init_24 = ""{INIT_24}""
+init_25 = ""{INIT_25}""
+init_26 = ""{INIT_26}""
+init_27 = ""{INIT_27}""
+init_28 = ""{INIT_28}""
+init_29 = ""{INIT_29}""
+init_2A = ""{INIT_2A}""
+init_2B = ""{INIT_2B}""
+init_2C = ""{INIT_2C}""
+init_2D = ""{INIT_2D}""
+init_2E = ""{INIT_2E}""
+init_2F = ""{INIT_2F}""
+init_30 = ""{INIT_30}""
+init_31 = ""{INIT_31}""
+init_32 = ""{INIT_32}""
+init_33 = ""{INIT_33}""
+init_34 = ""{INIT_34}""
+init_35 = ""{INIT_35}""
+init_36 = ""{INIT_36}""
+init_37 = ""{INIT_37}""
+init_38 = ""{INIT_38}""
+init_39 = ""{INIT_39}""
+init_3A = ""{INIT_3A}""
+init_3B = ""{INIT_3B}""
+init_3C = ""{INIT_3C}""
+init_3D = ""{INIT_3D}""
+init_3E = ""{INIT_3E}""
+init_3F = ""{INIT_3F}""
+initp_00 = ""{INITP_00}""
+initp_01 = ""{INITP_01}""
+initp_02 = ""{INITP_02}""
+initp_03 = ""{INITP_03}""
+initp_04 = ""{INITP_04}""
+initp_05 = ""{INITP_05}""
+initp_06 = ""{INITP_06}""
+initp_07 = ""{INITP_07}"" */;
+
+// synthesis translate_off
+// Attributes for Simulation
+defparam ram_1024_x_18.INIT_00 = 256\'h{INIT_00};
+defparam ram_1024_x_18.INIT_01 = 256\'h{INIT_01};
+defparam ram_1024_x_18.INIT_02 = 256\'h{INIT_02};
+defparam ram_1024_x_18.INIT_03 = 256\'h{INIT_03};
+defparam ram_1024_x_18.INIT_04 = 256\'h{INIT_04};
+defparam ram_1024_x_18.INIT_05 = 256\'h{INIT_05};
+defparam ram_1024_x_18.INIT_06 = 256\'h{INIT_06};
+defparam ram_1024_x_18.INIT_07 = 256\'h{INIT_07};
+defparam ram_1024_x_18.INIT_08 = 256\'h{INIT_08};
+defparam ram_1024_x_18.INIT_09 = 256\'h{INIT_09};
+defparam ram_1024_x_18.INIT_0A = 256\'h{INIT_0A};
+defparam ram_1024_x_18.INIT_0B = 256\'h{INIT_0B};
+defparam ram_1024_x_18.INIT_0C = 256\'h{INIT_0C};
+defparam ram_1024_x_18.INIT_0D = 256\'h{INIT_0D};
+defparam ram_1024_x_18.INIT_0E = 256\'h{INIT_0E};
+defparam ram_1024_x_18.INIT_0F = 256\'h{INIT_0F};
+defparam ram_1024_x_18.INIT_10 = 256\'h{INIT_10};
+defparam ram_1024_x_18.INIT_11 = 256\'h{INIT_11};
+defparam ram_1024_x_18.INIT_12 = 256\'h{INIT_12};
+defparam ram_1024_x_18.INIT_13 = 256\'h{INIT_13};
+defparam ram_1024_x_18.INIT_14 = 256\'h{INIT_14};
+defparam ram_1024_x_18.INIT_15 = 256\'h{INIT_15};
+defparam ram_1024_x_18.INIT_16 = 256\'h{INIT_16};
+defparam ram_1024_x_18.INIT_17 = 256\'h{INIT_17};
+defparam ram_1024_x_18.INIT_18 = 256\'h{INIT_18};
+defparam ram_1024_x_18.INIT_19 = 256\'h{INIT_19};
+defparam ram_1024_x_18.INIT_1A = 256\'h{INIT_1A};
+defparam ram_1024_x_18.INIT_1B = 256\'h{INIT_1B};
+defparam ram_1024_x_18.INIT_1C = 256\'h{INIT_1C};
+defparam ram_1024_x_18.INIT_1D = 256\'h{INIT_1D};
+defparam ram_1024_x_18.INIT_1E = 256\'h{INIT_1E};
+defparam ram_1024_x_18.INIT_1F = 256\'h{INIT_1F};
+defparam ram_1024_x_18.INIT_20 = 256\'h{INIT_20};
+defparam ram_1024_x_18.INIT_21 = 256\'h{INIT_21};
+defparam ram_1024_x_18.INIT_22 = 256\'h{INIT_22};
+defparam ram_1024_x_18.INIT_23 = 256\'h{INIT_23};
+defparam ram_1024_x_18.INIT_24 = 256\'h{INIT_24};
+defparam ram_1024_x_18.INIT_25 = 256\'h{INIT_25};
+defparam ram_1024_x_18.INIT_26 = 256\'h{INIT_26};
+defparam ram_1024_x_18.INIT_27 = 256\'h{INIT_27};
+defparam ram_1024_x_18.INIT_28 = 256\'h{INIT_28};
+defparam ram_1024_x_18.INIT_29 = 256\'h{INIT_29};
+defparam ram_1024_x_18.INIT_2A = 256\'h{INIT_2A};
+defparam ram_1024_x_18.INIT_2B = 256\'h{INIT_2B};
+defparam ram_1024_x_18.INIT_2C = 256\'h{INIT_2C};
+defparam ram_1024_x_18.INIT_2D = 256\'h{INIT_2D};
+defparam ram_1024_x_18.INIT_2E = 256\'h{INIT_2E};
+defparam ram_1024_x_18.INIT_2F = 256\'h{INIT_2F};
+defparam ram_1024_x_18.INIT_30 = 256\'h{INIT_30};
+defparam ram_1024_x_18.INIT_31 = 256\'h{INIT_31};
+defparam ram_1024_x_18.INIT_32 = 256\'h{INIT_32};
+defparam ram_1024_x_18.INIT_33 = 256\'h{INIT_33};
+defparam ram_1024_x_18.INIT_34 = 256\'h{INIT_34};
+defparam ram_1024_x_18.INIT_35 = 256\'h{INIT_35};
+defparam ram_1024_x_18.INIT_36 = 256\'h{INIT_36};
+defparam ram_1024_x_18.INIT_37 = 256\'h{INIT_37};
+defparam ram_1024_x_18.INIT_38 = 256\'h{INIT_38};
+defparam ram_1024_x_18.INIT_39 = 256\'h{INIT_39};
+defparam ram_1024_x_18.INIT_3A = 256\'h{INIT_3A};
+defparam ram_1024_x_18.INIT_3B = 256\'h{INIT_3B};
+defparam ram_1024_x_18.INIT_3C = 256\'h{INIT_3C};
+defparam ram_1024_x_18.INIT_3D = 256\'h{INIT_3D};
+defparam ram_1024_x_18.INIT_3E = 256\'h{INIT_3E};
+defparam ram_1024_x_18.INIT_3F = 256\'h{INIT_3F};
+defparam ram_1024_x_18.INITP_00 = 256\'h{INITP_00};
+defparam ram_1024_x_18.INITP_01 = 256\'h{INITP_01};
+defparam ram_1024_x_18.INITP_02 = 256\'h{INITP_02};
+defparam ram_1024_x_18.INITP_03 = 256\'h{INITP_03};
+defparam ram_1024_x_18.INITP_04 = 256\'h{INITP_04};
+defparam ram_1024_x_18.INITP_05 = 256\'h{INITP_05};
+defparam ram_1024_x_18.INITP_06 = 256\'h{INITP_06};
+defparam ram_1024_x_18.INITP_07 = 256\'h{INITP_07};
+
+// synthesis translate_on
+// Attributes for XST (Synplicity attributes are in-line)
+// synthesis attribute INIT_00 of ram_1024_x_18 is ""{INIT_00}""
+// synthesis attribute INIT_01 of ram_1024_x_18 is ""{INIT_01}""
+// synthesis attribute INIT_02 of ram_1024_x_18 is ""{INIT_02}""
+// synthesis attribute INIT_03 of ram_1024_x_18 is ""{INIT_03}""
+// synthesis attribute INIT_04 of ram_1024_x_18 is ""{INIT_04}""
+// synthesis attribute INIT_05 of ram_1024_x_18 is ""{INIT_05}""
+// synthesis attribute INIT_06 of ram_1024_x_18 is ""{INIT_06}""
+// synthesis attribute INIT_07 of ram_1024_x_18 is ""{INIT_07}""
+// synthesis attribute INIT_08 of ram_1024_x_18 is ""{INIT_08}""
+// synthesis attribute INIT_09 of ram_1024_x_18 is ""{INIT_09}""
+// synthesis attribute INIT_0A of ram_1024_x_18 is ""{INIT_0A}""
+// synthesis attribute INIT_0B of ram_1024_x_18 is ""{INIT_0B}""
+// synthesis attribute INIT_0C of ram_1024_x_18 is ""{INIT_0C}""
+// synthesis attribute INIT_0D of ram_1024_x_18 is ""{INIT_0D}""
+// synthesis attribute INIT_0E of ram_1024_x_18 is ""{INIT_0E}""
+// synthesis attribute INIT_0F of ram_1024_x_18 is ""{INIT_0F}""
+// synthesis attribute INIT_10 of ram_1024_x_18 is ""{INIT_10}""
+// synthesis attribute INIT_11 of ram_1024_x_18 is ""{INIT_11}""
+// synthesis attribute INIT_12 of ram_1024_x_18 is ""{INIT_12}""
+// synthesis attribute INIT_13 of ram_1024_x_18 is ""{INIT_13}""
+// synthesis attribute INIT_14 of ram_1024_x_18 is ""{INIT_14}""
+// synthesis attribute INIT_15 of ram_1024_x_18 is ""{INIT_15}""
+// synthesis attribute INIT_16 of ram_1024_x_18 is ""{INIT_16}""
+// synthesis attribute INIT_17 of ram_1024_x_18 is ""{INIT_17}""
+// synthesis attribute INIT_18 of ram_1024_x_18 is ""{INIT_18}""
+// synthesis attribute INIT_19 of ram_1024_x_18 is ""{INIT_19}""
+// synthesis attribute INIT_1A of ram_1024_x_18 is ""{INIT_1A}""
+// synthesis attribute INIT_1B of ram_1024_x_18 is ""{INIT_1B}""
+// synthesis attribute INIT_1C of ram_1024_x_18 is ""{INIT_1C}""
+// synthesis attribute INIT_1D of ram_1024_x_18 is ""{INIT_1D}""
+// synthesis attribute INIT_1E of ram_1024_x_18 is ""{INIT_1E}""
+// synthesis attribute INIT_1F of ram_1024_x_18 is ""{INIT_1F}""
+// synthesis attribute INIT_20 of ram_1024_x_18 is ""{INIT_20}""
+// synthesis attribute INIT_21 of ram_1024_x_18 is ""{INIT_21}""
+// synthesis attribute INIT_22 of ram_1024_x_18 is ""{INIT_22}""
+// synthesis attribute INIT_23 of ram_1024_x_18 is ""{INIT_23}""
+// synthesis attribute INIT_24 of ram_1024_x_18 is ""{INIT_24}""
+// synthesis attribute INIT_25 of ram_1024_x_18 is ""{INIT_25}""
+// synthesis attribute INIT_26 of ram_1024_x_18 is ""{INIT_26}""
+// synthesis attribute INIT_27 of ram_1024_x_18 is ""{INIT_27}""
+// synthesis attribute INIT_28 of ram_1024_x_18 is ""{INIT_28}""
+// synthesis attribute INIT_29 of ram_1024_x_18 is ""{INIT_29}""
+// synthesis attribute INIT_2A of ram_1024_x_18 is ""{INIT_2A}""
+// synthesis attribute INIT_2B of ram_1024_x_18 is ""{INIT_2B}""
+// synthesis attribute INIT_2C of ram_1024_x_18 is ""{INIT_2C}""
+// synthesis attribute INIT_2D of ram_1024_x_18 is ""{INIT_2D}""
+// synthesis attribute INIT_2E of ram_1024_x_18 is ""{INIT_2E}""
+// synthesis attribute INIT_2F of ram_1024_x_18 is ""{INIT_2F}""
+// synthesis attribute INIT_30 of ram_1024_x_18 is ""{INIT_30}""
+// synthesis attribute INIT_31 of ram_1024_x_18 is ""{INIT_31}""
+// synthesis attribute INIT_32 of ram_1024_x_18 is ""{INIT_32}""
+// synthesis attribute INIT_33 of ram_1024_x_18 is ""{INIT_33}""
+// synthesis attribute INIT_34 of ram_1024_x_18 is ""{INIT_34}""
+// synthesis attribute INIT_35 of ram_1024_x_18 is ""{INIT_35}""
+// synthesis attribute INIT_36 of ram_1024_x_18 is ""{INIT_36}""
+// synthesis attribute INIT_37 of ram_1024_x_18 is ""{INIT_37}""
+// synthesis attribute INIT_38 of ram_1024_x_18 is ""{INIT_38}""
+// synthesis attribute INIT_39 of ram_1024_x_18 is ""{INIT_39}""
+// synthesis attribute INIT_3A of ram_1024_x_18 is ""{INIT_3A}""
+// synthesis attribute INIT_3B of ram_1024_x_18 is ""{INIT_3B}""
+// synthesis attribute INIT_3C of ram_1024_x_18 is ""{INIT_3C}""
+// synthesis attribute INIT_3D of ram_1024_x_18 is ""{INIT_3D}""
+// synthesis attribute INIT_3E of ram_1024_x_18 is ""{INIT_3E}""
+// synthesis attribute INIT_3F of ram_1024_x_18 is ""{INIT_3F}""
+// synthesis attribute INITP_00 of ram_1024_x_18 is ""{INITP_00}""
+// synthesis attribute INITP_01 of ram_1024_x_18 is ""{INITP_01}""
+// synthesis attribute INITP_02 of ram_1024_x_18 is ""{INITP_02}""
+// synthesis attribute INITP_03 of ram_1024_x_18 is ""{INITP_03}""
+// synthesis attribute INITP_04 of ram_1024_x_18 is ""{INITP_04}""
+// synthesis attribute INITP_05 of ram_1024_x_18 is ""{INITP_05}""
+// synthesis attribute INITP_06 of ram_1024_x_18 is ""{INITP_06}""
+// synthesis attribute INITP_07 of ram_1024_x_18 is ""{INITP_07}""
+
+endmodule
+
+// END OF FILE {name}.v"
+"/*
+ --------------------------------------------------------------------------
+ Pegasus - Copyright (C) 2012 Gregory Matthew James.
+
+ This file is part of Pegasus.
+
+ Pegasus is free; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Pegasus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --------------------------------------------------------------------------
+*/
+
+/*
+ --------------------------------------------------------------------------
+ -- Project Code : pegasus
+ -- Module Name : peg_l2_mac_tx
+ -- Author : mammenx
+ -- Associated modules:
+ -- Function : Wrapper for L2 MAC TX.
+ --------------------------------------------------------------------------
+*/
+
+`timescale 1ns / 10ps
+
+`inlcude ""pkt_intf_defines.sv""
+
+module peg_l2_mac_tx #(
+ parameter PKT_DATA_W = 8,
+ parameter PKT_SIZE_W = 16
+)
+
+(
+
+ input clk,
+ input rst_n,
+
+ //Inputs from L2 MAC RX
+ input mac_pause_en,
+
+ //MAC Logic Link Control packet interface
+ `pkt_intf_ports_s(llc_tx_,,PKT_DATA_W),
+
+ //RS packet interface
+ pkt_intf_ports_m(rs_tx_,,PKT_DATA_W)
+);
+
+//----------------------- Global parameters Declarations ------------------
+
+
+//----------------------- Input Declarations ------------------------------
+
+
+//----------------------- Inout Declarations ------------------------------
+
+
+//----------------------- Output Declarations -----------------------------
+
+
+//----------------------- Output Register Declaration ---------------------
+
+
+//----------------------- Internal Register Declarations ------------------
+
+
+//----------------------- Internal Wire Declarations ----------------------
+
+//----------------------- Input/Output Registers --------------------------
+
+//----------------------- Start of Code -----------------------------------
+
+ peg_l2_mac_tx_framer #(
+ .PKT_DATA_W(PKT_DATA_W),
+ .PKT_SIZE_W(PKT_SIZE_W)
+ )
+ u_l2_mac_tx_framer
+ (
+
+ .clk (clk),
+ .rst_n (rst_n),
+
+ //Config interface
+ .config_l2_mac_tx_en (),
+ .config_l2_mac_tx_padding_en (),
+ .config_l2_mac_tx_fcs_en (),
+ .config_l2_mac_addr (),
+ .config_l2_mac_tx_pause_gen (),
+ .config_l2_mac_tx_pause_time (),
+
+ //Status interface
+ .l2_mac_tx_fsm_state (),
+
+ //Pause Interface from MAC RX
+ .mac_pause_en (mac_pause_en),
+
+ //MAC Logic Link Control packet interface
+ `pkt_intf_port_connect(llc_tx_,,llc_tx_,),
+
+ //RS packet interface
+ `pkt_intf_port_connect(rs_tx_,,rs_tx_,)
+
+ );
+
+
+endmodule // peg_l2_mac_tx
+
+
+/*
+ --------------------------------------------------------------------------
+
+ --
+
+
+ --
+
+[28-07-2014 04:18:29 PM][mammenx] Created basic wrapper
+
+[28-05-14 20:18:21] [mammenx] Moved log section to bottom of file
+
+ --------------------------------------------------------------------------
+*/
+"
+"/*
+ --------------------------------------------------------------------------
+ Pegasus - Copyright (C) 2012 Gregory Matthew James.
+
+ This file is part of Pegasus.
+
+ Pegasus is free; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Pegasus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --------------------------------------------------------------------------
+*/
+
+/*
+ --------------------------------------------------------------------------
+ -- Project Code : pegasus
+ -- Module Name : peg_l2_mac_rx
+ -- Author : mammenx
+ -- Associated modules:
+ -- Function : Wrapper for L2 MAC TX.
+ --------------------------------------------------------------------------
+*/
+
+`timescale 1ns / 10ps
+
+`inlcude ""pkt_intf_defines.sv""
+
+module peg_l2_mac_rx #(
+ parameter PKT_DATA_W = 8,
+ parameter PKT_SIZE_W = 16,
+ parameter NUM_FIELDS = 8,
+ parameter BFFR_SIZE = 48
+)
+
+(
+
+ input clk,
+ input rst_n,
+
+ //Outputs to MAC TX
+ output mac_pause_en,
+
+ //MAC Logic Link packet interface
+ `pkt_intf_ports_m(llc_rx_,,PKT_DATA_W),
+
+ //RS packet interface
+ `pkt_intf_ports_s(rs_rx_,,PKT_DATA_W)
+);
+
+//----------------------- Global parameters Declarations ------------------
+
+
+//----------------------- Input Declarations ------------------------------
+
+
+//----------------------- Inout Declarations ------------------------------
+
+
+//----------------------- Output Declarations -----------------------------
+
+
+//----------------------- Output Register Declaration ---------------------
+
+
+//----------------------- Internal Register Declarations ------------------
+
+
+//----------------------- Internal Wire Declarations ----------------------
+ wire [NUM_FIELDS-1:0] rx_field_valid_vec_w;
+ wire [BFFR_SIZE-1:0] rx_bffr_w;
+
+ wire fcs_calc_rst_w;
+ wire fcs_calc_en_w;
+ wire [PKT_DATA_W-1:0] fcs_calc_data_w;
+
+//----------------------- Input/Output Registers --------------------------
+
+//----------------------- Start of Code -----------------------------------
+
+ peg_l2_mac_rx_parser #(
+ .PKT_DATA_W(PKT_DATA_W),
+ .PKT_SIZE_W(PKT_SIZE_W),
+ .NUM_FIELDS(NUM_FIELDS),
+ .BFFR_SIZE(BFFR_SIZE)
+ )
+ u_l2_mac_rx_parser
+ (
+ .clk (clk),
+ .rst_n (rst_n),
+
+ //Config interface
+ .config_l2_mac_rx_en,
+ .config_l2_mac_rx_fcs_en,
+ .config_l2_mac_rx_strip_preamble_sfd,
+ .config_l2_mac_rx_strip_fcs,
+
+ //Status interface
+ .l2_mac_rx_fsm_state,
+
+ //Interface to RX Filter & Pause Gen
+ .rx_field_valid_vec (rx_field_valid_vec_w),
+ .rx_bffr (rx_bffr_w),
+
+ //Interface to FCS Calculator
+ .rx_fcs_rst (fcs_calc_rst_w),
+ .rx_fcs_calc_en (fcs_calc_en_w),
+ .rx_fcs_calc_data (fcs_calc_data_w),
+
+ //RS packet interface
+ `pkt_intf_port_connect(rs_rx_,,rs_rx_,),
+
+ //LLC packet interface
+ `pkt_intf_port_connect(llc_rx_,,llc_rx_,)
+
+ );
+
+
+ peg_l2_mac_pause_cntr #(
+ .BPCLK(PKT_DATA_W)
+ )
+ u_pause_cntr
+ (
+ .clk (clk),
+ .rst_n (rst_n),
+
+ //Config
+ .pause_en (),
+
+ //Inputs from Parser
+ .pause_time_valid (rx_field_valid_vec_w[MAC_FIDX_PAUSE_TIME]),
+ .pause_time (rx_bffr_w[15:0]),
+
+ //Pause Status
+ .pause_valid (mac_pause_en)
+
+ );
+
+
+ peg_l2_fcs_gen #(
+ .DATA_W(PKT_DATA_W),
+ .CRC_INIT_VAL(32\'d0)
+ )
+ u_l2_fcs_gen
+ (
+ .clk (clk),
+ .rst_n (rst_n),
+
+ .fcs_calc_rst (fcs_calc_rst_w),
+ .fcs_calc_valid (fcs_calc_en_w),
+ .fcs_calc_data (fcs_calc_data_w),
+
+ .fcs ()
+
+ );
+
+
+
+endmodule // peg_l2_mac_rx
+
+
+/*
+ --------------------------------------------------------------------------
+
+ --
+
+
+ --
+
+[28-07-2014 04:18:29 PM][mammenx] Created basic wrapper
+
+[28-05-14 20:18:21] [mammenx] Moved log section to bottom of file
+
+ --------------------------------------------------------------------------
+*/
+"
+"/*
+ --------------------------------------------------------------------------
+ Pegasus - Copyright (C) 2012 Gregory Matthew James.
+
+ This file is part of Pegasus.
+
+ Pegasus is free; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Pegasus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --------------------------------------------------------------------------
+*/
+
+/*
+ --------------------------------------------------------------------------
+ -- Project Code : pegasus
+ -- Module Name : pkt_ff_wptr
+ -- Author : mammenx
+ -- Associated modules:
+ -- Function : This module maintains the write pointer logic for
+ the fifo.
+ --------------------------------------------------------------------------
+*/
+
+`timescale 1ns / 10ps
+
+
+module pkt_ff_wptr #(PTR_W = 8)
+
+(
+
+ //--------------------- Misc Ports (Logic) -----------
+ clk,
+ rst_n,
+
+ valid,
+ sop,
+ eop,
+ error.
+
+ wptr
+
+ //--------------------- Interfaces --------------------
+
+
+);
+
+//----------------------- Global parameters Declarations ------------------
+
+
+//----------------------- Input Declarations ------------------------------
+ input clk;
+ input rst_n;
+
+ input valid;
+ input sop;
+ input eop;
+ input error;
+
+//----------------------- Inout Declarations ------------------------------
+
+
+//----------------------- Output Declarations -----------------------------
+ output [PTR_W-1:0] wptr;
+
+//----------------------- Output Register Declaration ---------------------
+
+
+//----------------------- Internal Register Declarations ------------------
+ reg [PTR_W-1:0] sop_ptr_f;
+
+//----------------------- Internal Wire Declarations ----------------------
+ reg wptr_rewind_n_c;
+ reg wptr_inc_en_c;
+
+//----------------------- Internal Interface Declarations -----------------
+
+
+//----------------------- FSM Declarations --------------------------------
+
+
+//----------------------- Start of Code -----------------------------------
+
+
+ always@(posedge clk, negedge rst_n)
+ begin
+ if(~rst_n)
+ begin
+ sop_ptr_f <= 0;
+ end
+ else
+ begin
+ //Record the start of packet location for future rewind
+ sop_ptr_f <= (valid & sop) ? wptr : sop_ptr_f;
+
+ end
+ end
+
+ //Reset the wptr to last SOP location
+ assign wptr_rewind_n_c = (valid & error) ? 1'b0 : rst_n;
+
+ //Logic to decide when to increment wptr
+ assign wptr_inc_en_c = valid & ~error;
+
+ //Implement wptr as a gray counter
+ gry_cntr u_wptr_gry_cntr
+ (
+
+ .clk (clk),
+ .rst_n (wptr_rewind_n_c),
+
+ .rst_val (sop_ptr_f),
+
+ .en (wptr_inc_en_c),
+ .gry_cnt (wptr),
+ .gry_cnt_nxt ()
+
+ );
+
+ defparam u_wptr_gry_cntr.WIDTH = PTR_W;
+
+
+
+endmodule // pkt_ff_wptr
+
+/*
+ --------------------------------------------------------------------------
+
+ --
+
+
+ --
+
+[28-06-2014 03:30:57 PM][mammenx] Moved to Verilog
+
+[08-06-2014 02:11:10 PM][mammenx] Modified gry_cntr reset signal
+
+[08-06-2014 02:07:20 PM][mammenx] Brought out gry_cnt_nxt port
+
+[08-06-2014 12:54:08 PM][mammenx] Initial Commit
+
+[28-05-14 20:18:21] [mammenx] Moved log section to bottom of file
+
+ --------------------------------------------------------------------------
+*/
+"
+"/*
+ --------------------------------------------------------------------------
+ Pegasus - Copyright (C) 2012 Gregory Matthew James.
+
+ This file is part of Pegasus.
+
+ Pegasus is free; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Pegasus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --------------------------------------------------------------------------
+*/
+
+/*
+ --------------------------------------------------------------------------
+ -- Project Code : pegasus
+ -- Module Name : dd_sync
+ -- Author : mammenx
+ -- Associated modules:
+ -- Function : This module synchronizes a signal (of parameterized
+ width) to the destination clock.
+ --------------------------------------------------------------------------
+*/
+
+`timescale 1ns / 10ps
+
+
+module dd_sync #(WIDTH = 1, STAGES = 2, RST_VAL = 0)
+
+(
+
+ //--------------------- Misc Ports (Logic) -----------
+ clk,
+ rst_n,
+
+ data_i,
+ data_sync_o
+
+ //--------------------- Interfaces --------------------
+
+
+);
+
+//----------------------- Global parameters Declarations ------------------
+
+
+//----------------------- Input Declarations ------------------------------
+ input clk;
+ input rst_n;
+
+ input [WIDTH-1:0] data_i;
+
+//----------------------- Inout Declarations ------------------------------
+
+
+//----------------------- Output Declarations -----------------------------
+ output [WIDTH-1:0] data_sync_o;
+
+//----------------------- Output Register Declaration ---------------------
+
+
+//----------------------- Internal Register Declarations ------------------
+ reg [WIDTH-1:0] sync_pipe_f [0:STAGES-1];
+
+//----------------------- Internal Wire Declarations ----------------------
+
+
+//----------------------- Internal Interface Declarations -----------------
+
+
+//----------------------- FSM Declarations --------------------------------
+
+
+//----------------------- Start of Code -----------------------------------
+
+ genvar i;
+
+ generate
+ for(i=0; i
+
+
+ --
+
+[28-06-2014 03:30:07 PM][mammenx] Moved to Verilog
+
+[08-06-2014 11:32:22 AM][mammenx] Corrected multi-dimension order for sync_pipe_f
+
+[08-06-2014 11:11:26 AM][mammenx] Added RST_VAL parameter
+
+[08-06-2014 11:09:00 AM][mammenx] Initial Version
+
+[28-05-14 20:18:21] [mammenx] Moved log section to bottom of file
+
+ --------------------------------------------------------------------------
+*/
+"
+"/*
+ --------------------------------------------------------------------------
+ Pegasus - Copyright (C) 2012 Gregory Matthew James.
+
+ This file is part of Pegasus.
+
+ Pegasus is free; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Pegasus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --------------------------------------------------------------------------
+*/
+
+/*
+ --------------------------------------------------------------------------
+ -- Project Code : pegasus
+ -- Module Name : pkt_ff_async
+ -- Author : mammenx
+ -- Associated modules: pkt_ff_async_mem, pkt_ff_rptr, pkt_ff_wptr
+ -- Function : The top module for pkt_ff_async.
+ --------------------------------------------------------------------------
+*/
+
+`timescale 1ns / 10ps
+
+
+module pkt_ff_async #(WIDTH = 32, DEPTH = 128, MAX_NO_PKTS=2)
+(
+
+ //--------------------- Misc Ports (Logic) -----------
+ input ingr_clk,
+ input ingr_rst_n,
+
+ input egr_clk,
+ input egr_rst_n,
+
+ //Ingress packet interface
+ input ingr_valid,
+ input ingr_sop,
+ input ingr_eop,
+ input [WIDTH-1:0] ingr_data,
+ output ingr_ready,
+ input ingr_error,
+
+ //Egress packet interface
+ output egr_valid,
+ output egr_sop,
+ output egr_eop,
+ output [WIDTH-1:0] egr_data,
+ input egr_ready,
+ output egr_error
+
+ //--------------------- Interfaces --------------------
+
+);
+
+//----------------------- Global parameters Declarations ------------------
+ localparam PTR_W = $clog2(DEPTH);
+
+//----------------------- Input Declarations ------------------------------
+
+
+//----------------------- Inout Declarations ------------------------------
+
+
+//----------------------- Output Declarations -----------------------------
+
+
+//----------------------- Output Register Declaration ---------------------
+
+
+//----------------------- Internal Register Declarations ------------------
+ reg [PTR_W-1:0] credit_cnt_ingr_f;
+ reg credit_ingr_push_f;
+ reg [PTR_W-1:0] credit_cnt_egr_f;
+
+
+//----------------------- Internal Wire Declarations ----------------------
+ wire [PTR_W-1:0] wptr_w;
+ wire [PTR_W-1:0] rptr_w;
+
+ wire data_ff_rd_en_c;
+ wire data_ff_wr_en_c;
+
+ wire credit_ff_full_w;
+ wire credit_ff_empty_w;
+ wire [PTR_W-1:0] credit_ff_rdata_w;
+ wire credit_egr_pop_c;
+
+//----------------------- Internal Interface Declarations -----------------
+
+
+//----------------------- FSM Declarations --------------------------------
+
+
+
+//----------------------- Start of Code -----------------------------------
+
+ //Generate read/write signals for data fifo
+ assign data_ff_wr_en_c = ingr_valid & ingr_ready & ~ingr_error;
+ assign data_ff_rd_en_c = egr_valid & egr_ready;
+
+ pkt_ff_wptr u_wptr
+ (
+ .clk (ingr_clk),
+ .rst_n (ingr_rst_n),
+
+ .valid (ingr_valid),
+ .sop (ingr_sop),
+ .eop (ingr_eop),
+ .error (ingr_error),
+
+ .wptr (wptr_w)
+
+ );
+ defparam u_wptr.PTR_W = PTR_W;
+
+
+ pkt_ff_rptr u_rptr
+ (
+ .clk (egr_clk),
+ .rst_n (egr_rst_n),
+
+ .rd_en (data_ff_rd_en_c),
+
+ .rptr (rptr_w)
+
+ );
+ defparam u_rptr.PTR_W = PTR_W;
+
+
+ pkt_ff_async_mem u_mem
+ (
+ .data (ingr_data),
+ .rdaddress (rptr_w),
+ .rdclock (egr_clk),
+ .wraddress (wptr_w),
+ .wrclock (ingr_clk),
+ .wren (data_ff_wr_en_c),
+ .q (egr_data)
+ );
+ defparam u_mem.DWIDTH = WIDTH;
+ defparam u_mem.DEPTH = DEPTH;
+
+
+
+ /*
+ * Credit management logic
+ */
+ always@(posedge ingr_clk, negedge ingr_rst_n)
+ begin
+ if(~ingr_rst_n)
+ begin
+ credit_cnt_ingr_f <= 0;
+ credit_ingr_push_f <= 0;
+ end
+ else
+ begin
+ if(ingr_valid & ingr_ready)
+ begin
+ if(ingr_sof)
+ begin
+ credit_cnt_ingr_f <= WIDTH;
+ end
+ else
+ begin
+ credit_cnt_ingr_f <= credit_cnt_ingr_f + WIDTH;
+ end
+ end
+ else
+ begin
+ credit_cnt_ingr_f <= credit_cnt_ingr_f;
+ end
+
+ credit_ingr_push_f <= ingr_valid & ingr_ready &
+ ingr_eof & ~ingr_error;
+ end
+ end
+
+ always@(posedge egr_clk, negedge egr_rst_n)
+ begin
+ if(~egr_rst_n)
+ begin
+ credit_cnt_egr_f <= 0;
+ end
+ else
+ begin
+ if(credit_cnt_egr_f == 0)
+ begin
+ if(~credit_ff_empty_w)
+ begin
+ credit_cnt_egr_f <= credit_ff_rdata_w;
+ end
+ end
+ else if(egr_ready)
+ begin
+ credit_cnt_egr_f <= credit_cnt_egr_f - WIDTH;
+ end
+ end
+ end
+
+ assign egr_valid = (credit_cnt_egr_f > 0) ? 1'b1 : 1'b0;
+ assign egr_sop = (credit_cnt_egr_f == credit_ff_rdata_w) ? ~credit_ff_empty_w : 1'b0;
+ assign egr_eop = (credit_cnt_egr_f <= WIDTH) ? egr_valid : 1'b0;
+ assign egr_error = 0;
+
+ assign credit_egr_pop_c = egr_eop & egr_ready;
+
+ assign ingr_ready = ~credit_ff_full_w;
+
+
+ credit_ff_async u_credit_ff
+ (
+ .aclr (~ingr_rst_n | ~egr_rst_n),
+ .data (credit_cnt_ingr_f),
+ .rdclk (egr_clk),
+ .rdreq (credit_egr_pop_c),
+ .wrclk (ingr_clk),
+ .wrreq (credit_ingr_push_f),
+ .q (credit_ff_rdata_w),
+ .rdempty (credit_ff_empty_w),
+ .wrfull (credit_ff_full_w)
+ );
+ defparam u_credit_ff.WIDTH = PTR_W;
+ defparam u_credit_ff.DEPTH = MAX_NO_PKTS;
+
+
+
+endmodule // pkt_ff_async
+
+/*
+ --------------------------------------------------------------------------
+
+ --
+
+
+ --
+
+[28-06-2014 03:30:57 PM][mammenx] Moved to Verilog
+
+[08-06-2014 04:16:44 PM][mammenx] Initial Commit
+
+[28-05-14 20:18:21] [mammenx] Moved log section to bottom of file
+
+ --------------------------------------------------------------------------
+*/
+"
+"// megafunction wizard: %FIFO%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: dcfifo
+
+// ============================================================
+// File Name: credit_ff_async.v
+// Megafunction Name(s):
+// \t\t\tdcfifo
+//
+// Simulation Library Files(s):
+// \t\t\taltera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 11.1 Build 259 01/25/2012 SP 2 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2011 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module credit_ff_async #(WIDTH=8,DEPTH=512) (
+\taclr,
+\tdata,
+\trdclk,
+\trdreq,
+\twrclk,
+\twrreq,
+\tq,
+\trdempty,
+\twrfull);
+
+\tinput\t aclr;
+\tinput\t[WIDTH-1:0] data;
+\tinput\t rdclk;
+\tinput\t rdreq;
+\tinput\t wrclk;
+\tinput\t wrreq;
+\toutput\t[WIDTH-1:0] q;
+\toutput\t rdempty;
+\toutput\t wrfull;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_off
+`endif
+\ttri0\t aclr;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_on
+`endif
+
+\twire sub_wire0;
+\twire [WIDTH-1:0] sub_wire1;
+\twire sub_wire2;
+\twire wrfull = sub_wire0;
+\twire [WIDTH-1:0] q = sub_wire1[WIDTH-1:0];
+\twire rdempty = sub_wire2;
+
+\tdcfifo\tdcfifo_component (
+\t\t\t\t.rdclk (rdclk),
+\t\t\t\t.wrclk (wrclk),
+\t\t\t\t.wrreq (wrreq),
+\t\t\t\t.aclr (aclr),
+\t\t\t\t.data (data),
+\t\t\t\t.rdreq (rdreq),
+\t\t\t\t.wrfull (sub_wire0),
+\t\t\t\t.q (sub_wire1),
+\t\t\t\t.rdempty (sub_wire2),
+\t\t\t\t.rdfull (),
+\t\t\t\t.rdusedw (),
+\t\t\t\t.wrempty (),
+\t\t\t\t.wrusedw ());
+\tdefparam
+\t\tdcfifo_component.intended_device_family = ""Cyclone II"",
+\t\tdcfifo_component.lpm_hint = ""RAM_BLOCK_TYPE=M4K"",
+\t\tdcfifo_component.lpm_numwords = DEPTH,
+\t\tdcfifo_component.lpm_showahead = ""ON"",
+\t\tdcfifo_component.lpm_type = ""dcfifo"",
+\t\tdcfifo_component.lpm_width = WIDTH,
+\t\tdcfifo_component.lpm_widthu = WIDTH+1,
+\t\tdcfifo_component.overflow_checking = ""OFF"",
+\t\tdcfifo_component.rdsync_delaypipe = 4,
+\t\tdcfifo_component.underflow_checking = ""OFF"",
+\t\tdcfifo_component.use_eab = ""ON"",
+\t\tdcfifo_component.write_aclr_synch = ""OFF"",
+\t\tdcfifo_component.wrsync_delaypipe = 4;
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: AlmostEmpty NUMERIC ""0""
+// Retrieval info: PRIVATE: AlmostEmptyThr NUMERIC ""-1""
+// Retrieval info: PRIVATE: AlmostFull NUMERIC ""0""
+// Retrieval info: PRIVATE: AlmostFullThr NUMERIC ""-1""
+// Retrieval info: PRIVATE: CLOCKS_ARE_SYNCHRONIZED NUMERIC ""0""
+// Retrieval info: PRIVATE: Clock NUMERIC ""4""
+// Retrieval info: PRIVATE: Depth NUMERIC ""512""
+// Retrieval info: PRIVATE: Empty NUMERIC ""1""
+// Retrieval info: PRIVATE: Full NUMERIC ""1""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""
+// Retrieval info: PRIVATE: LE_BasedFIFO NUMERIC ""0""
+// Retrieval info: PRIVATE: LegacyRREQ NUMERIC ""0""
+// Retrieval info: PRIVATE: MAX_DEPTH_BY_9 NUMERIC ""0""
+// Retrieval info: PRIVATE: OVERFLOW_CHECKING NUMERIC ""1""
+// Retrieval info: PRIVATE: Optimize NUMERIC ""0""
+// Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC ""2""
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING ""0""
+// Retrieval info: PRIVATE: UNDERFLOW_CHECKING NUMERIC ""1""
+// Retrieval info: PRIVATE: UsedW NUMERIC ""1""
+// Retrieval info: PRIVATE: Width NUMERIC ""8""
+// Retrieval info: PRIVATE: dc_aclr NUMERIC ""1""
+// Retrieval info: PRIVATE: diff_widths NUMERIC ""0""
+// Retrieval info: PRIVATE: msb_usedw NUMERIC ""0""
+// Retrieval info: PRIVATE: output_width NUMERIC ""8""
+// Retrieval info: PRIVATE: rsEmpty NUMERIC ""1""
+// Retrieval info: PRIVATE: rsFull NUMERIC ""0""
+// Retrieval info: PRIVATE: rsUsedW NUMERIC ""0""
+// Retrieval info: PRIVATE: sc_aclr NUMERIC ""0""
+// Retrieval info: PRIVATE: sc_sclr NUMERIC ""0""
+// Retrieval info: PRIVATE: wsEmpty NUMERIC ""0""
+// Retrieval info: PRIVATE: wsFull NUMERIC ""1""
+// Retrieval info: PRIVATE: wsUsedW NUMERIC ""0""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""
+// Retrieval info: CONSTANT: LPM_HINT STRING ""RAM_BLOCK_TYPE=M4K""
+// Retrieval info: CONSTANT: LPM_NUMWORDS NUMERIC ""512""
+// Retrieval info: CONSTANT: LPM_SHOWAHEAD STRING ""ON""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""dcfifo""
+// Retrieval info: CONSTANT: LPM_WIDTH NUMERIC ""8""
+// Retrieval info: CONSTANT: LPM_WIDTHU NUMERIC ""9""
+// Retrieval info: CONSTANT: OVERFLOW_CHECKING STRING ""OFF""
+// Retrieval info: CONSTANT: RDSYNC_DELAYPIPE NUMERIC ""4""
+// Retrieval info: CONSTANT: UNDERFLOW_CHECKING STRING ""OFF""
+// Retrieval info: CONSTANT: USE_EAB STRING ""ON""
+// Retrieval info: CONSTANT: WRITE_ACLR_SYNCH STRING ""OFF""
+// Retrieval info: CONSTANT: WRSYNC_DELAYPIPE NUMERIC ""4""
+// Retrieval info: USED_PORT: aclr 0 0 0 0 INPUT GND ""aclr""
+// Retrieval info: USED_PORT: data 0 0 8 0 INPUT NODEFVAL ""data[7..0]""
+// Retrieval info: USED_PORT: q 0 0 8 0 OUTPUT NODEFVAL ""q[7..0]""
+// Retrieval info: USED_PORT: rdclk 0 0 0 0 INPUT NODEFVAL ""rdclk""
+// Retrieval info: USED_PORT: rdempty 0 0 0 0 OUTPUT NODEFVAL ""rdempty""
+// Retrieval info: USED_PORT: rdreq 0 0 0 0 INPUT NODEFVAL ""rdreq""
+// Retrieval info: USED_PORT: wrclk 0 0 0 0 INPUT NODEFVAL ""wrclk""
+// Retrieval info: USED_PORT: wrfull 0 0 0 0 OUTPUT NODEFVAL ""wrfull""
+// Retrieval info: USED_PORT: wrreq 0 0 0 0 INPUT NODEFVAL ""wrreq""
+// Retrieval info: CONNECT: @aclr 0 0 0 0 aclr 0 0 0 0
+// Retrieval info: CONNECT: @data 0 0 8 0 data 0 0 8 0
+// Retrieval info: CONNECT: @rdclk 0 0 0 0 rdclk 0 0 0 0
+// Retrieval info: CONNECT: @rdreq 0 0 0 0 rdreq 0 0 0 0
+// Retrieval info: CONNECT: @wrclk 0 0 0 0 wrclk 0 0 0 0
+// Retrieval info: CONNECT: @wrreq 0 0 0 0 wrreq 0 0 0 0
+// Retrieval info: CONNECT: q 0 0 8 0 @q 0 0 8 0
+// Retrieval info: CONNECT: rdempty 0 0 0 0 @rdempty 0 0 0 0
+// Retrieval info: CONNECT: wrfull 0 0 0 0 @wrfull 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL credit_ff_async.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL credit_ff_async.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL credit_ff_async.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL credit_ff_async.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL credit_ff_async_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL credit_ff_async_bb.v FALSE
+// Retrieval info: LIB_FILE: altera_mf
+"
+"/*
+ --------------------------------------------------------------------------
+ Pegasus - Copyright (C) 2012 Gregory Matthew James.
+
+ This file is part of Pegasus.
+
+ Pegasus is free; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Pegasus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --------------------------------------------------------------------------
+*/
+
+/*
+ --------------------------------------------------------------------------
+ -- Project Code : pegasus
+ -- Module Name : peg_l2_fcs_gen
+ -- Author : mammenx
+ -- Associated modules:
+ -- Function : This module generates FCS from the data stream.
+ --------------------------------------------------------------------------
+*/
+
+`timescale 1ns / 10ps
+
+
+module peg_l2_fcs_gen #(
+ parameter DATA_W = 8,
+ parameter CRC_INIT_VAL = 32'd0
+)
+
+(
+ input clk,
+ input rst_n,
+
+ input fcs_calc_rst,
+ input fcs_calc_valid,
+ input [DATA_W-1:0] fcs_calc_data,
+
+ output [31:0] fcs
+
+);
+
+//----------------------- Global parameters Declarations ------------------
+
+
+//----------------------- Input Declarations ------------------------------
+
+
+//----------------------- Inout Declarations ------------------------------
+
+
+//----------------------- Output Declarations -----------------------------
+
+
+//----------------------- Output Register Declaration ---------------------
+
+
+//----------------------- Internal Register Declarations ------------------
+ reg [31:0] crc_f;
+
+ genvar i;
+
+//----------------------- Internal Wire Declarations ----------------------
+
+
+//----------------------- Input/Output Registers --------------------------
+
+//----------------------- Start of Code -----------------------------------
+
+ always@(posedge clk, negedge rst_n)
+ begin
+ if(~rst_n)
+ begin
+ crc_f <= CRC_INIT_VAL;
+ end
+ else
+ begin
+ if(fcs_calc_rst)
+ begin
+ crc_f <= CRC_INIT_VAL;
+ end
+ else if(fcs_calc_valid)
+ begin
+ crc_f <= nextCRC32_D8(fcs_calc_data,crc_f);
+ end
+ end
+ end
+
+ //FCS is bit reversed & complimented version of CRC
+ generate
+ for(i=0; i<32; i++)
+ begin
+ assign fcs[i] = ~crc_f[31-i];
+ end
+ endgenerate
+
+
+endmodule // peg_l2_fcs_gen
+
+
+/*
+ --------------------------------------------------------------------------
+
+ --
+
+
+ --
+
+[28-07-2014 04:18:29 PM][mammenx] Created basic wrapper
+
+[28-05-14 20:18:21] [mammenx] Moved log section to bottom of file
+
+ --------------------------------------------------------------------------
+*/
+"
+"// megafunction wizard: %RAM: 2-PORT%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altsyncram
+
+// ============================================================
+// File Name: pkt_ff_async_mem.v
+// Megafunction Name(s):
+// \t\t\taltsyncram
+//
+// Simulation Library Files(s):
+// \t\t\taltera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 11.1 Build 259 01/25/2012 SP 2 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2011 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module pkt_ff_async_mem #(DWIDTH=32, DEPTH=128) (
+\tdata,
+\trdaddress,
+\trdclock,
+\twraddress,
+\twrclock,
+\twren,
+\tq);
+
+ localparam AWIDTH = $clog2(DEPTH);
+
+\tinput\t[DWIDTH-1:0] data;
+\tinput\t[AWIDTH-1:0] rdaddress;
+\tinput\t rdclock;
+\tinput\t[AWIDTH-1:0] wraddress;
+\tinput\t wrclock;
+\tinput\t wren;
+\toutput\t[DWIDTH-1:0] q;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_off
+`endif
+\ttri1\t wrclock;
+\ttri0\t wren;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_on
+`endif
+
+\twire [DWIDTH-1:0] sub_wire0;
+\twire [DWIDTH-1:0] q = sub_wire0[DWIDTH-1:0];
+
+\taltsyncram\taltsyncram_component (
+\t\t\t\t.address_a (wraddress),
+\t\t\t\t.clock0 (wrclock),
+\t\t\t\t.data_a (data),
+\t\t\t\t.wren_a (wren),
+\t\t\t\t.address_b (rdaddress),
+\t\t\t\t.clock1 (rdclock),
+\t\t\t\t.q_b (sub_wire0),
+\t\t\t\t.aclr0 (1\'b0),
+\t\t\t\t.aclr1 (1\'b0),
+\t\t\t\t.addressstall_a (1\'b0),
+\t\t\t\t.addressstall_b (1\'b0),
+\t\t\t\t.byteena_a (1\'b1),
+\t\t\t\t.byteena_b (1\'b1),
+\t\t\t\t.clocken0 (1\'b1),
+\t\t\t\t.clocken1 (1\'b1),
+\t\t\t\t.clocken2 (1\'b1),
+\t\t\t\t.clocken3 (1\'b1),
+\t\t\t\t.data_b ({DWIDTH{1\'b1}}),
+\t\t\t\t.eccstatus (),
+\t\t\t\t.q_a (),
+\t\t\t\t.rden_a (1\'b1),
+\t\t\t\t.rden_b (1\'b1),
+\t\t\t\t.wren_b (1\'b0));
+\tdefparam
+\t\taltsyncram_component.address_reg_b = ""CLOCK1"",
+\t\taltsyncram_component.clock_enable_input_a = ""BYPASS"",
+\t\taltsyncram_component.clock_enable_input_b = ""BYPASS"",
+\t\taltsyncram_component.clock_enable_output_a = ""BYPASS"",
+\t\taltsyncram_component.clock_enable_output_b = ""BYPASS"",
+\t\taltsyncram_component.intended_device_family = ""Cyclone II"",
+\t\taltsyncram_component.lpm_type = ""altsyncram"",
+\t\taltsyncram_component.numwords_a = DEPTH,
+\t\taltsyncram_component.numwords_b = DEPTH,
+\t\taltsyncram_component.operation_mode = ""DUAL_PORT"",
+\t\taltsyncram_component.outdata_aclr_b = ""NONE"",
+\t\taltsyncram_component.outdata_reg_b = ""UNREGISTERED"",
+\t\taltsyncram_component.power_up_uninitialized = ""FALSE"",
+\t\taltsyncram_component.ram_block_type = ""M4K"",
+\t\taltsyncram_component.widthad_a = AWIDTH,
+\t\taltsyncram_component.widthad_b = AWIDTH,
+\t\taltsyncram_component.width_a = DWIDTH,
+\t\taltsyncram_component.width_b = DWIDTH,
+\t\taltsyncram_component.width_byteena_a = 1;
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: ADDRESSSTALL_A NUMERIC ""0""
+// Retrieval info: PRIVATE: ADDRESSSTALL_B NUMERIC ""0""
+// Retrieval info: PRIVATE: BYTEENA_ACLR_A NUMERIC ""0""
+// Retrieval info: PRIVATE: BYTEENA_ACLR_B NUMERIC ""0""
+// Retrieval info: PRIVATE: BYTE_ENABLE_A NUMERIC ""0""
+// Retrieval info: PRIVATE: BYTE_ENABLE_B NUMERIC ""0""
+// Retrieval info: PRIVATE: BYTE_SIZE NUMERIC ""8""
+// Retrieval info: PRIVATE: BlankMemory NUMERIC ""1""
+// Retrieval info: PRIVATE: CLOCK_ENABLE_INPUT_A NUMERIC ""0""
+// Retrieval info: PRIVATE: CLOCK_ENABLE_INPUT_B NUMERIC ""0""
+// Retrieval info: PRIVATE: CLOCK_ENABLE_OUTPUT_A NUMERIC ""0""
+// Retrieval info: PRIVATE: CLOCK_ENABLE_OUTPUT_B NUMERIC ""0""
+// Retrieval info: PRIVATE: CLRdata NUMERIC ""0""
+// Retrieval info: PRIVATE: CLRq NUMERIC ""0""
+// Retrieval info: PRIVATE: CLRrdaddress NUMERIC ""0""
+// Retrieval info: PRIVATE: CLRrren NUMERIC ""0""
+// Retrieval info: PRIVATE: CLRwraddress NUMERIC ""0""
+// Retrieval info: PRIVATE: CLRwren NUMERIC ""0""
+// Retrieval info: PRIVATE: Clock NUMERIC ""1""
+// Retrieval info: PRIVATE: Clock_A NUMERIC ""0""
+// Retrieval info: PRIVATE: Clock_B NUMERIC ""0""
+// Retrieval info: PRIVATE: ECC NUMERIC ""0""
+// Retrieval info: PRIVATE: ECC_PIPELINE_STAGE NUMERIC ""0""
+// Retrieval info: PRIVATE: IMPLEMENT_IN_LES NUMERIC ""0""
+// Retrieval info: PRIVATE: INDATA_ACLR_B NUMERIC ""0""
+// Retrieval info: PRIVATE: INDATA_REG_B NUMERIC ""0""
+// Retrieval info: PRIVATE: INIT_FILE_LAYOUT STRING ""PORT_B""
+// Retrieval info: PRIVATE: INIT_TO_SIM_X NUMERIC ""0""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""
+// Retrieval info: PRIVATE: JTAG_ENABLED NUMERIC ""0""
+// Retrieval info: PRIVATE: JTAG_ID STRING ""NONE""
+// Retrieval info: PRIVATE: MAXIMUM_DEPTH NUMERIC ""0""
+// Retrieval info: PRIVATE: MEMSIZE NUMERIC ""4096""
+// Retrieval info: PRIVATE: MEM_IN_BITS NUMERIC ""0""
+// Retrieval info: PRIVATE: MIFfilename STRING """"
+// Retrieval info: PRIVATE: OPERATION_MODE NUMERIC ""2""
+// Retrieval info: PRIVATE: OUTDATA_ACLR_B NUMERIC ""0""
+// Retrieval info: PRIVATE: OUTDATA_REG_B NUMERIC ""0""
+// Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC ""2""
+// Retrieval info: PRIVATE: READ_DURING_WRITE_MODE_MIXED_PORTS NUMERIC ""2""
+// Retrieval info: PRIVATE: READ_DURING_WRITE_MODE_PORT_A NUMERIC ""3""
+// Retrieval info: PRIVATE: READ_DURING_WRITE_MODE_PORT_B NUMERIC ""3""
+// Retrieval info: PRIVATE: REGdata NUMERIC ""1""
+// Retrieval info: PRIVATE: REGq NUMERIC ""1""
+// Retrieval info: PRIVATE: REGrdaddress NUMERIC ""1""
+// Retrieval info: PRIVATE: REGrren NUMERIC ""1""
+// Retrieval info: PRIVATE: REGwraddress NUMERIC ""1""
+// Retrieval info: PRIVATE: REGwren NUMERIC ""1""
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING ""0""
+// Retrieval info: PRIVATE: USE_DIFF_CLKEN NUMERIC ""0""
+// Retrieval info: PRIVATE: UseDPRAM NUMERIC ""1""
+// Retrieval info: PRIVATE: VarWidth NUMERIC ""0""
+// Retrieval info: PRIVATE: WIDTH_READ_A NUMERIC ""32""
+// Retrieval info: PRIVATE: WIDTH_READ_B NUMERIC ""32""
+// Retrieval info: PRIVATE: WIDTH_WRITE_A NUMERIC ""32""
+// Retrieval info: PRIVATE: WIDTH_WRITE_B NUMERIC ""32""
+// Retrieval info: PRIVATE: WRADDR_ACLR_B NUMERIC ""0""
+// Retrieval info: PRIVATE: WRADDR_REG_B NUMERIC ""0""
+// Retrieval info: PRIVATE: WRCTRL_ACLR_B NUMERIC ""0""
+// Retrieval info: PRIVATE: enable NUMERIC ""0""
+// Retrieval info: PRIVATE: rden NUMERIC ""0""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: ADDRESS_REG_B STRING ""CLOCK1""
+// Retrieval info: CONSTANT: CLOCK_ENABLE_INPUT_A STRING ""BYPASS""
+// Retrieval info: CONSTANT: CLOCK_ENABLE_INPUT_B STRING ""BYPASS""
+// Retrieval info: CONSTANT: CLOCK_ENABLE_OUTPUT_A STRING ""BYPASS""
+// Retrieval info: CONSTANT: CLOCK_ENABLE_OUTPUT_B STRING ""BYPASS""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""altsyncram""
+// Retrieval info: CONSTANT: NUMWORDS_A NUMERIC ""128""
+// Retrieval info: CONSTANT: NUMWORDS_B NUMERIC ""128""
+// Retrieval info: CONSTANT: OPERATION_MODE STRING ""DUAL_PORT""
+// Retrieval info: CONSTANT: OUTDATA_ACLR_B STRING ""NONE""
+// Retrieval info: CONSTANT: OUTDATA_REG_B STRING ""UNREGISTERED""
+// Retrieval info: CONSTANT: POWER_UP_UNINITIALIZED STRING ""FALSE""
+// Retrieval info: CONSTANT: RAM_BLOCK_TYPE STRING ""M4K""
+// Retrieval info: CONSTANT: WIDTHAD_A NUMERIC ""7""
+// Retrieval info: CONSTANT: WIDTHAD_B NUMERIC ""7""
+// Retrieval info: CONSTANT: WIDTH_A NUMERIC ""32""
+// Retrieval info: CONSTANT: WIDTH_B NUMERIC ""32""
+// Retrieval info: CONSTANT: WIDTH_BYTEENA_A NUMERIC ""1""
+// Retrieval info: USED_PORT: data 0 0 32 0 INPUT NODEFVAL ""data[31..0]""
+// Retrieval info: USED_PORT: q 0 0 32 0 OUTPUT NODEFVAL ""q[31..0]""
+// Retrieval info: USED_PORT: rdaddress 0 0 7 0 INPUT NODEFVAL ""rdaddress[6..0]""
+// Retrieval info: USED_PORT: rdclock 0 0 0 0 INPUT NODEFVAL ""rdclock""
+// Retrieval info: USED_PORT: wraddress 0 0 7 0 INPUT NODEFVAL ""wraddress[6..0]""
+// Retrieval info: USED_PORT: wrclock 0 0 0 0 INPUT VCC ""wrclock""
+// Retrieval info: USED_PORT: wren 0 0 0 0 INPUT GND ""wren""
+// Retrieval info: CONNECT: @address_a 0 0 7 0 wraddress 0 0 7 0
+// Retrieval info: CONNECT: @address_b 0 0 7 0 rdaddress 0 0 7 0
+// Retrieval info: CONNECT: @clock0 0 0 0 0 wrclock 0 0 0 0
+// Retrieval info: CONNECT: @clock1 0 0 0 0 rdclock 0 0 0 0
+// Retrieval info: CONNECT: @data_a 0 0 32 0 data 0 0 32 0
+// Retrieval info: CONNECT: @wren_a 0 0 0 0 wren 0 0 0 0
+// Retrieval info: CONNECT: q 0 0 32 0 @q_b 0 0 32 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL pkt_ff_async_mem.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pkt_ff_async_mem.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pkt_ff_async_mem.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pkt_ff_async_mem.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pkt_ff_async_mem_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pkt_ff_async_mem_bb.v FALSE
+// Retrieval info: LIB_FILE: altera_mf
+"
+"/*
+ --------------------------------------------------------------------------
+ Pegasus - Copyright (C) 2012 Gregory Matthew James.
+
+ This file is part of Pegasus.
+
+ Pegasus is free; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Pegasus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --------------------------------------------------------------------------
+*/
+
+/*
+ --------------------------------------------------------------------------
+ -- Project Code : pegasus
+ -- Module Name : peg_l2_mac_tx_framer
+ -- Author : mammenx
+ -- Associated modules:
+ -- Function : This module contains the logic to frame L2 MAC frames
+ for transmission. This has a 8b pipeline that is
+ intended for upto 1Gbps speeds @ 125MHz clock.
+ --------------------------------------------------------------------------
+*/
+
+`timescale 1ns / 10ps
+
+
+module peg_l2_mac_tx_framer #(
+
+ parameter PKT_DATA_W = 8,
+ parameter PKT_SIZE_W = 16
+
+)
+
+(
+
+ input clk,
+ input rst_n,
+
+ //Config interface
+ input config_l2_mac_tx_en,
+ input config_l2_mac_tx_padding_en,
+ input config_l2_mac_tx_fcs_en,
+ input [47:0] config_l2_mac_addr,
+ input config_l2_mac_tx_pause_gen,
+ input [15:0] config_l2_mac_tx_pause_time,
+
+ //Status interface
+ output [3:0] l2_mac_tx_fsm_state,
+
+ //Pause Interface from MAC RX
+ input mac_pause_en,
+
+ //MAC Logic Link Control packet interface
+ input llc_tx_valid,
+ input llc_tx_sop,
+ input llc_tx_eop,
+ input [PKT_DATA_W-1:0] llc_tx_data,
+ output llc_tx_ready,
+ input llc_tx_error,
+
+ //RS packet interface
+ output rs_tx_valid,
+ output rs_tx_sop,
+ output rs_tx_eop,
+ output [PKT_DATA_W-1:0] rs_tx_data,
+ input rs_tx_ready,
+ output rs_tx_error
+
+);
+
+//----------------------- Global parameters Declarations ------------------
+ `include ""peg_l2_params.v""
+
+ parameter PKT_SIZE_INC_VAL = PKT_DATA_W / 8;
+ parameter DATA_BFFR_SIZE = 5*8;
+
+//----------------------- Input Declarations ------------------------------
+
+
+//----------------------- Inout Declarations ------------------------------
+
+
+//----------------------- Output Declarations -----------------------------
+
+
+//----------------------- Output Register Declaration ---------------------
+ reg llc_tx_ready;
+
+//----------------------- Internal Register Declarations ------------------
+ reg [15:0] data_cntr_f;
+ reg [DATA_BFFR_SIZE-1:0] data_bffr_f;
+ reg [15:0] final_pkt_size_f;
+ reg crc_en_f;
+ reg [31:0] crc_f;
+ reg pause_frm_f;
+
+//----------------------- Internal Wire Declarations ----------------------
+ wire [15:0] data_bytes_w;
+ wire [DATA_BFFR_SIZE+PKT_DATA_W-1:0] data_bffr_w;
+ wire padding_required_c;
+ wire [PKT_DATA_W-1:0] crc_data_c;
+ wire state_change_c;
+ wire [31:0] fcs_c;
+ wire [2:0] fcs_index_c;
+
+ genvar i;
+
+//----------------------- FSM Parameters --------------------------------------
+//only for FSM state vector representation
+parameter [3:0] // synopsys enum fsm_pstate
+IDLE_S = 4\'d0,
+PREAMBLE_S = 4\'d1,
+SFD_S = 4\'d2,
+DA_S = 4\'d3,
+SA_S = 4\'d4,
+LEN_TYPE_S = 4\'d5,
+VLAN_TAG_S = 4\'d6,
+PAUSE_OPCODE_S = 4\'d7,
+PAUSE_TIME_S = 4\'d8,
+DATA_S = 4\'d9,
+PADDING_S = 4\'d10,
+FCS_S = 4\'d11;
+
+//----------------------- FSM Register Declarations ------------------
+reg [3:0] // synopsys enum fsm_pstate
+fsm_pstate, next_state;
+
+//----------------------- FSM String Declarations ------------------
+//synthesis translate_off
+reg [8*16:0] state_name;//""state name"" is user defined
+//synthesis translate_on
+
+//----------------------- FSM Debugging Logic Declarations ------------------
+//synthesis translate_off
+always @ (fsm_pstate)
+begin
+case (fsm_pstate)
+
+IDLE_S : state_name = ""IDLE_S"";
+
+PREAMBLE_S : state_name = ""PREAMBLE_S"";
+
+SFD_S : state_name = ""SFD_S"";
+
+DA_S : state_name = ""DA_S"";
+
+SA_S : state_name = ""SA_S"";
+
+LEN_TYPE_S : state_name = ""LEN_TYPE_S"";
+
+PAUSE_OPCODE_S : state_name = ""PAUSE_OPCODE_S"";
+
+PAUSE_TIME_S : state_name = ""PAUSE_TIME_S"";
+
+VLAN_TAG_S : state_name = ""VLAN_TAG_S"";
+
+DATA_S : state_name = ""DATA_S"";
+
+PADDING_S : state_name = ""PADDING_S"";
+
+FCS_S : state_name = ""FCS_S"";
+
+default : state_name = ""INVALID STATE!"";
+endcase
+end
+//synthesis translate_on
+
+//----------------------- Input/Output Registers --------------------------
+
+//----------------------- Start of Code -----------------------------------
+
+
+ /* Main FSM Logic */
+ always@(posedge clk, negedge rst_n)
+ begin
+ if(~rst_n)
+ begin
+ fsm_pstate <= IDLE_S;
+ data_cntr_f <= 0;
+ data_bffr_f <= 0;
+ final_pkt_size_f <= 0;
+ pause_frm_f <= 0;
+ end
+ else
+ begin
+ fsm_pstate <= next_state;
+
+ if(fsm_pstate == IDLE_S)
+ begin
+ pause_frm_f <= config_l2_mac_tx_en & config_l2_mac_tx_pause_gen;
+ end
+ else if(fsm_pstate == FCS_S)
+ begin
+ pause_frm_f <= 1\'b0;
+ end
+
+ if(fsm_pstate == IDLE_S)
+ begin
+ data_cntr_f <= 0;
+ end
+ else if(rs_tx_valid & rs_tx_ready)
+ begin
+ data_cntr_f <= data_cntr_f + 1\'b1;
+ end
+
+ if(rs_tx_valid & rs_tx_ready)
+ begin
+ data_bffr_f <= {data_bffr_f[DATA_BFFR_SIZE-PKT_DATA_W-1:0],rs_tx_data};
+ end
+
+ if((fsm_pstate != FCS_S) & (next_state == FCS))
+ begin
+ final_pkt_size_f <= data_cntr_f + 3\'d4;
+ end
+ end
+ end
+
+ assign data_bffr_w = {data_bffr_f,rs_tx_data};
+
+ assign data_bytes_w = data_cntr_f;
+
+ //Check if pkt has minimum size
+ assign padding_required_c = (data_bytes_w < MAC_MIN_FRM_LEN) ? (config_l2_mac_tx_padding_en | pause_frm_f) : 1\'b0;
+
+ assign state_change_c = (next_state != fsm_pstate) ? 1\'b1 : 1\'b0;
+
+ always@(*)
+ begin
+ next_state = fsm_pstate;
+ llc_tx_ready = 1\'b0;
+
+ case(fsm_pstate)
+
+ IDLE_S :
+ begin
+ if(((llc_tx_valid & llc_tx_sop) | config_l2_mac_tx_pause_gen) & config_l2_mac_tx_en)
+ begin
+ next_state = PREAMBLE_S;
+ end
+ end
+
+ PREAMBLE_S :
+ begin
+ if((llc_tx_valid | pause_frm_f) & rs_tx_ready & (data_bytes_w == (MAC_SFD_OFFSET-1)))
+ begin
+ next_state = SFD_S;
+ end
+ end
+
+ SFD_S :
+ begin
+ if((llc_tx_valid | pause_frm_f) & rs_tx_ready & (data_bytes_w == (MAC_DA_OFFSET-1)))
+ llc_tx_ready = ~pause_frm_f;
+ next_state = DA_S;
+ end
+ end
+
+ DA_S :
+ begin
+ if((llc_tx_valid | pause_frm_f) & rs_tx_ready & (data_bytes_w == (MAC_SA_OFFSET-1)))
+ begin
+ llc_tx_ready = ~pause_frm_f;
+ next_state = SA_S;
+ end
+ end
+
+ SA_S :
+ begin
+ if((llc_tx_valid | pause_frm_f) & rs_tx_ready & (data_bytes_w == (MAC_LEN_TYPE_OFFSET-1)))
+ begin
+ llc_tx_ready = ~pause_frm_f;
+ next_state = LEN_TYPE_S;
+ end
+ end
+
+ LEN_TYPE_S :
+ begin
+ if(rs_tx_ready & (data_bytes_w == (MAC_DATA_OFFSET-1)))
+ begin
+ llc_tx_ready = llc_tx_valid & ~pause_frm_f;
+
+ if(pause_frm_f)
+ begin
+ next_state = PAUSE_OPCODE_S;
+ end
+ else if(llc_tx_valid)
+ begin
+ if(data_bffr_w[15:0] == VLAN_TYPE_VALUE)
+ begin
+ next_state = VLAN_TAG_S;
+ end
+ else
+ begin
+ next_state = DATA_S;
+ end
+ end
+ end
+ end
+
+ PAUSE_OPCODE_S :
+ begin
+ if(rs_tx_ready & (data_bytes_w == MAC_PAUSE_TIME_OFFSET-1))
+ begin
+ next_state = PAUSE_TIME_S;
+ end
+ end
+
+ PAUSE_TIME_S :
+ begin
+ if(rs_tx_ready & (data_bytes_w == MAC_PAUSE_TIME_OFFSET+1))
+ begin
+ next_state = PADDING_S;
+ end
+ end
+
+ VLAN_TAG_S :
+ begin
+ if(llc_tx_valid & rs_tx_ready & (data_bytes_w == (MAC_VLAN_DATA_OFFSET-1)))
+ begin
+ llc_tx_ready = 1\'b1;
+ next_state = DATA_S;
+ end
+ end
+
+ DATA_S :
+ begin
+ if(llc_tx_valid & llc_tx_eop & rs_tx_ready)
+ begin
+ llc_tx_ready = 1\'b1;
+
+ if(padding_required_c)
+ begin
+ next_state = PADDING_S;
+ end
+ else if(config_l2_mac_tx_fcs_en)
+ begin
+ next_state = FCS_S;
+ end
+ else
+ begin
+ next_state = IDLE_S;
+ end
+ end
+ end
+
+ PADDING_S :
+ begin
+ if(~padding_required_c & rs_tx_ready)
+ begin
+ next_state = FCS_S;
+ end
+ end
+
+ FCS :
+ begin
+ if((data_bytes_w == final_pkt_size_f) & rs_tx_ready))
+ begin
+ next_state = IDLE_S;
+ end
+ end
+
+ endcase
+ end
+
+ //First 32b of CRC data input should be complimented
+ assign crc_data_c = (data_cntr_f <= 4) ? ~llc_tx_data :
+ ((fsm_pstate == PADDING_S) ? 0 : llc_tx_data);
+
+ /* FCS Calculation Logic */
+ always@(posedge clk, negedge rst_n)
+ begin
+ if(~rst_n)
+ begin
+ crc_en_f <= 0;
+ crc_f <= 0;
+ end
+ else
+ begin
+ if(next_state == FCS_S)
+ begin
+ crc_en_f <= state_change_c ? 1\'b0 : crc_en_f;
+ end
+ else if(fsm_pstate == PREAMBLE_S)
+ begin
+ crc_en_f <= state_change_c & config_l2_mac_tx_fcs_en;
+ end
+
+ if(fsm_pstate == IDLE_S)
+ begin
+ crc_f <= 0;
+ end
+ else if(crc_en_f & llc_tx_valid)
+ begin
+ crc_f <= nextCRC32_D8(crc_data_c, crc_f);
+ end
+ end
+ end
+
+ //FCS is bit reversed & complimented version of CRC
+ generate
+ for(i=0; i<32; i++)
+ begin
+ assign fcs_c[i] = ~crc_f[31-i];
+ end
+ endgenerate
+
+ assign fcs_index_c = {(final_pkt_size_f[2:0] - data_cntr_f[2:0]), {$clog2(PKT_DATA_W){1\'b0}}};
+
+ /* Data framing logic */
+ always@(posedge clk, negedge rst_n)
+ begin
+ if(~rst_n)
+ begin
+ rs_tx_valid <= 0;
+ rs_tx_sop <= 0;
+ rs_tx_eop <= 0;
+ rs_tx_data <= 0;
+ rs_tx_error <= 0;
+ end
+ else
+ begin
+ case(fsm_pstate)
+
+ IDLE_S :
+ begin
+ rs_tx_valid <= state_change_c ? 1\'b1 : 1\'b0;
+ rs_tx_sop <= state_change_c ? 1\'b1 : 1\'b0;
+ rs_tx_eop <= 0;
+ rs_tx_data <= PREAMBLE_VALUE;
+ rs_tx_error <= 0;
+ end
+
+ PREAMBLE_S :
+ begin
+ rs_tx_valid <= 1\'b1;
+ rs_tx_sop <= rs_tx_sop & ~rs_tx_ready;
+ rs_tx_eop <= 0;
+ rs_tx_data <= state_change_c ? SFD_VALUE : rs_tx_data;
+ rs_tx_error <= 0;
+ end
+
+ SFD_S,
+ SA_S,
+ DA_S,
+ LEN_TYPE_S,
+ VLAN_TAG_S :
+ begin
+ rs_tx_valid <= 1\'b1;
+ rs_tx_sop <= 0;
+ rs_tx_eop <= 0;
+
+ if(pause_frm_f)
+ begin
+ rs_tx_data <= (data_bytes_w == MAC_LEN_TYPE_OFFSET) ? CTRL_TYPE_VALUE[7:0] : CTRL_TYPE_VALUE[15:8];
+ end
+ else if(state_change_c)
+ begin
+ rs_tx_data <= llc_tx_data;
+ end
+ else
+ begin
+ rs_tx_data <= rs_tx_data;
+ end
+
+ rs_tx_error <= 0;
+ end
+
+ PAUSE_OPCODE_S :
+ begin
+ rs_tx_valid <= 1\'b1;
+ rs_tx_sop <= 0;
+ rs_tx_eop <= 1\'b0;
+ rs_tx_data <= (data_cntr_f == MAC_CTRL_OPCODE_OFFSET) ? PAUSE_CTRL_OPCODE[7:0] : PAUSE_CTRL_OPCODE[15:8];
+ rs_tx_error <= 0;
+ end
+
+ PAUSE_TIME_S :
+ begin
+ rs_tx_valid <= 1\'b1;
+ rs_tx_sop <= 0;
+ rs_tx_eop <= 1\'b0;
+ rs_tx_data <= (data_cntr_f == MAC_PAUSE_TIME_OFFSET) ?
+ config_l2_mac_tx_pause_time[7:0] :
+ config_l2_mac_tx_pause_time[15:8];
+ rs_tx_error <= 0;
+ end
+
+ DATA_S :
+ begin
+ rs_tx_valid <= 1\'b1;
+ rs_tx_sop <= 0;
+ rs_tx_eop <= (next_state == IDLE_S) 1\'b1 : 1\'b0;
+ rs_tx_data <= state_change_c ? llc_tx_data : rs_tx_data;
+ rs_tx_error <= 0;
+ end
+
+ PADDING_S :
+ begin
+ rs_tx_valid <= 1\'b1;
+ rs_tx_sop <= 0;
+ rs_tx_eop <= 0;
+ rs_tx_data <= 0;
+ rs_tx_error <= 0;
+ end
+
+ FCS :
+ begin
+ rs_tx_valid <= state_change_c ? 1\'b0 : 1\'b1;
+ rs_tx_sop <= 0;
+ rs_tx_eop <= state_change_c ? 1\'b1 : 1\'b0;
+ rs_tx_data <= fcs_c[fcs_index_c +: PKT_DATA_W];
+ rs_tx_error <= 0;
+ end
+
+ endcase
+ end
+ end
+
+endmodule // peg_l2_mac_tx_framer
+
+
+/*
+ --------------------------------------------------------------------------
+
+ --
+
+
+ --
+
+[28-07-2014 04:18:29 PM][mammenx] Created basic wrapper
+
+[28-07-2014 12:12:47 PM][mammenx] Added Pause Frame support
+
+[02-07-2014 12:52:58 AM][mammenx] Initial version
+
+[28-05-14 20:18:21] [mammenx] Moved log section to bottom of file
+
+ --------------------------------------------------------------------------
+*/
+"
+"/*
+ --------------------------------------------------------------------------
+ Pegasus - Copyright (C) 2012 Gregory Matthew James.
+
+ This file is part of Pegasus.
+
+ Pegasus is free; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Pegasus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --------------------------------------------------------------------------
+*/
+
+/*
+ --------------------------------------------------------------------------
+ -- Project Code : pegasus
+ -- Module Name : peg_l2_mac_pause_cntr
+ -- Author : mammenx
+ -- Associated modules:
+ -- Function : This block is a counter used to generate pause
+ intervals.
+ --------------------------------------------------------------------------
+*/
+
+`timescale 1ns / 10ps
+
+
+module peg_l2_mac_pause_cntr #(
+
+ parameter BPCLK = 64, //Bits per clock cycle
+ parameter MAC_SPEED = 100000000 //bps
+
+)
+
+(
+ input clk,
+ input rst_n,
+
+ //Config
+ input pause_en,
+
+ //Inputs from Parser
+ input pause_time_valid,
+ input [15:0] pause_time,
+
+ //Pause Status
+ output pause_valid
+
+);
+
+//----------------------- Global parameters Declarations ------------------
+ localparam PAUSE_SCALE_FAC = $clog(512 / BPCLK);
+ localparam CNTR_W = 16 + PAUSE_SCALE_FAC;
+
+//----------------------- Input Declarations ------------------------------
+
+
+//----------------------- Inout Declarations ------------------------------
+
+
+//----------------------- Output Declarations -----------------------------
+
+
+//----------------------- Output Register Declaration ---------------------
+
+
+//----------------------- Internal Register Declarations ------------------
+ reg [15:0] pause_time_f;
+ reg [CNTR_W-1:0] pause_cntr_f;
+
+//----------------------- Internal Wire Declarations ----------------------
+
+
+//----------------------- Input/Output Registers --------------------------
+
+//----------------------- Start of Code -----------------------------------
+
+ always@(posedge clk, negedge rst_n)
+ begin
+ if(~rst_n)
+ begin
+ pause_time_f <= 0;
+ pause_cntr_f <= 0;
+ end
+ else
+ begin
+ //Register the pause time from parser
+ pause_time_f <= pause_time_valid ? pause_time : pause_time_f;
+
+ //Counter logic
+ if(pause_valid)
+ begin
+ pause_cntr_f <= 0;
+ end
+ else if(pause_en)
+ begin
+ pause_cntr_f <= pause_cntr_f + 1'b1;
+ end
+ else
+ begin
+ pause_cntr_f <= pause_cntr_f;
+ end
+ end
+ end
+
+ //Generate status
+ assign pause_en = (pause_time_f > pause_cntr_f[CNTR_W-1:PAUSE_SCALE_FAC]) ? 1'b1 : 1'b0;
+
+endmodule // peg_l2_mac_pause_cntr
+
+
+/*
+ --------------------------------------------------------------------------
+
+ --
+
+
+ --
+
+[02-07-2014 12:52:58 AM][mammenx] Initial version
+
+[28-05-14 20:18:21] [mammenx] Moved log section to bottom of file
+
+ --------------------------------------------------------------------------
+*/
+"
+"/*
+ --------------------------------------------------------------------------
+ Pegasus - Copyright (C) 2012 Gregory Matthew James.
+
+ This file is part of Pegasus.
+
+ Pegasus is free; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Pegasus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --------------------------------------------------------------------------
+*/
+
+/*
+ --------------------------------------------------------------------------
+ -- Project Code : pegasus
+ -- Module Name : gry_cntr
+ -- Author : mammenx
+ -- Associated modules:
+ -- Function : A parameterized gray code counter.
+ --------------------------------------------------------------------------
+*/
+
+`timescale 1ns / 10ps
+
+
+module gry_cntr #(WIDTH = 8)
+
+ (
+
+ //--------------------- Misc Ports (Logic) -----------
+ clk,
+ rst_n,
+
+ rst_val,
+
+ en,
+ gry_cnt,
+ gry_cnt_nxt
+
+
+ //--------------------- Interfaces --------------------
+
+
+ );
+
+//----------------------- Global parameters Declarations ------------------
+
+
+//----------------------- Input Declarations ------------------------------
+ input clk;
+ input rst_n;
+
+ input [WIDTH-1:0] rst_val;
+
+ input en;
+
+//----------------------- Inout Declarations ------------------------------
+
+
+//----------------------- Output Declarations -----------------------------
+ output [WIDTH-1:0] gry_cnt;
+ output [WIDTH-1:0] gry_cnt_nxt;
+
+//----------------------- Output Register Declaration ---------------------
+ reg [WIDTH-1:0] gry_cnt;
+ reg [WIDTH-1:0] gry_cnt_nxt;
+
+
+//----------------------- Internal Register Declarations ------------------
+ reg [WIDTH-1:0] bin_cnt_f;
+
+//----------------------- Internal Wire Declarations ----------------------
+ reg [WIDTH-1:0] rst_val2bin_c;
+ reg [WIDTH-1:0] bin_cnt_nxt_c;
+
+ genvar i;
+
+//----------------------- Internal Interface Declarations -----------------
+
+
+//----------------------- FSM Declarations --------------------------------
+
+
+//----------------------- Start of Code -----------------------------------
+
+ //Convert to binary
+ generate
+ for(i=WIDTH-1; i>=0; i--)
+ begin : RST_VAL2BIN
+ assign rst_val2bin_c[i] = ^rst_val[WIDTH-1:i];
+ end
+ endgenerate
+
+ always@(posedge clk, negedge rst_n)
+ begin
+ if(~rst_n)
+ begin
+ bin_cnt_f <= rst_val2bin_c;
+ gry_cnt <= rst_val;
+ end
+ else
+ begin
+ bin_cnt_f <= bin_cnt_nxt_c;
+ gry_cnt <= gry_cnt_nxt;
+ end
+ end
+
+ assign bin_cnt_nxt_c = bin_cnt_f + en;
+
+ assign gry_cnt_nxt = bin_cnt_nxt_c ^ {1'b0,bin_cnt_nxt_c[WIDTH-1:1]};
+
+endmodule // gry_cntr
+
+/*
+ --------------------------------------------------------------------------
+
+ --
+
+
+ --
+
+[28-06-2014 03:30:07 PM][mammenx] Moved to Verilog
+
+[08-06-2014 02:07:20 PM][mammenx] Brought out gry_cnt_nxt port
+
+[08-06-2014 12:46:15 PM][mammenx] Modified rest load
+
+[07-06-2014 09:55:48 PM][mammenx] Initial version
+
+[28-05-14 20:18:21] [mammenx] Moved log section to bottom of file
+
+ --------------------------------------------------------------------------
+*/
+"
+"/*
+ --------------------------------------------------------------------------
+ Pegasus - Copyright (C) 2012 Gregory Matthew James.
+
+ This file is part of Pegasus.
+
+ Pegasus is free; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Pegasus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --------------------------------------------------------------------------
+*/
+
+/*
+ --------------------------------------------------------------------------
+ -- Project Code : pegasus
+ -- Package Name : peg_l2_params
+ -- Author : mammenx
+ -- Description : This file contains the different parameters
+ and definitions used in L2 block.
+ --------------------------------------------------------------------------
+*/
+
+ parameter PREAMBLE_VALUE = 8\'b01010101;
+ parameter SFD_VALUE = 8\'b11010101;
+ parameter VLAN_TYPE_VALUE = 16\'h8100;
+ parameter CTRL_TYPE_VALUE = 16\'h8808;
+ parameter PAUSE_CTRL_OPCODE = 16\'h0001;
+ parameter GLBL_MULTICAST_ADDR = 48\'h01_80_C2_00_00_01;
+
+ parameter RS_TYPE = ""RMII"";
+
+ //Byte offsets for different MAC fields
+ parameter MAC_PREAMBLE_OFFSET = 0;
+ parameter MAC_SFD_OFFSET = 7;
+ parameter MAC_DA_OFFSET = 8;
+ parameter MAC_SA_OFFSET = 14;
+ parameter MAC_LEN_TYPE_OFFSET = 20;
+ parameter MAC_CTRL_OPCODE_OFFSET= 22;
+ parameter MAC_DATA_OFFSET = 22;
+ parameter MAC_PAUSE_TIME_OFFSET = 24;
+ parameter MAC_VLAN_DATA_OFFSET = 26;
+
+ //Parameters for indexing the field buffer
+ parameter MAC_FIDX_DADDR = 0;
+ parameter MAC_FIDX_SADDR = 1;
+ parameter MAC_FIDX_LEN_TYPE = 2;
+ parameter MAC_FIDX_VLAN_TAG = 3;
+ parameter MAC_FIDX_CTRL_OPCODE = 4;
+ parameter MAC_FIDX_PAUSE_TIME = 5;
+ parameter MAC_FIDX_FCS = 6;
+
+ //Function to calculate CRC
+ function [31:0] nextCRC32_D8;
+
+ input [7:0] Data;
+ input [31:0] crc;
+ reg [7:0] d;
+ reg [31:0] c;
+ reg [31:0] newcrc;
+ begin
+ d = Data;
+ c = crc;
+
+ newcrc[0] = d[6] ^ d[0] ^ c[24] ^ c[30];
+ newcrc[1] = d[7] ^ d[6] ^ d[1] ^ d[0] ^ c[24] ^ c[25] ^ c[30] ^ c[31];
+ newcrc[2] = d[7] ^ d[6] ^ d[2] ^ d[1] ^ d[0] ^ c[24] ^ c[25] ^ c[26] ^ c[30] ^ c[31];
+ newcrc[3] = d[7] ^ d[3] ^ d[2] ^ d[1] ^ c[25] ^ c[26] ^ c[27] ^ c[31];
+ newcrc[4] = d[6] ^ d[4] ^ d[3] ^ d[2] ^ d[0] ^ c[24] ^ c[26] ^ c[27] ^ c[28] ^ c[30];
+ newcrc[5] = d[7] ^ d[6] ^ d[5] ^ d[4] ^ d[3] ^ d[1] ^ d[0] ^ c[24] ^ c[25] ^ c[27] ^ c[28] ^ c[29] ^ c[30] ^ c[31];
+ newcrc[6] = d[7] ^ d[6] ^ d[5] ^ d[4] ^ d[2] ^ d[1] ^ c[25] ^ c[26] ^ c[28] ^ c[29] ^ c[30] ^ c[31];
+ newcrc[7] = d[7] ^ d[5] ^ d[3] ^ d[2] ^ d[0] ^ c[24] ^ c[26] ^ c[27] ^ c[29] ^ c[31];
+ newcrc[8] = d[4] ^ d[3] ^ d[1] ^ d[0] ^ c[0] ^ c[24] ^ c[25] ^ c[27] ^ c[28];
+ newcrc[9] = d[5] ^ d[4] ^ d[2] ^ d[1] ^ c[1] ^ c[25] ^ c[26] ^ c[28] ^ c[29];
+ newcrc[10] = d[5] ^ d[3] ^ d[2] ^ d[0] ^ c[2] ^ c[24] ^ c[26] ^ c[27] ^ c[29];
+ newcrc[11] = d[4] ^ d[3] ^ d[1] ^ d[0] ^ c[3] ^ c[24] ^ c[25] ^ c[27] ^ c[28];
+ newcrc[12] = d[6] ^ d[5] ^ d[4] ^ d[2] ^ d[1] ^ d[0] ^ c[4] ^ c[24] ^ c[25] ^ c[26] ^ c[28] ^ c[29] ^ c[30];
+ newcrc[13] = d[7] ^ d[6] ^ d[5] ^ d[3] ^ d[2] ^ d[1] ^ c[5] ^ c[25] ^ c[26] ^ c[27] ^ c[29] ^ c[30] ^ c[31];
+ newcrc[14] = d[7] ^ d[6] ^ d[4] ^ d[3] ^ d[2] ^ c[6] ^ c[26] ^ c[27] ^ c[28] ^ c[30] ^ c[31];
+ newcrc[15] = d[7] ^ d[5] ^ d[4] ^ d[3] ^ c[7] ^ c[27] ^ c[28] ^ c[29] ^ c[31];
+ newcrc[16] = d[5] ^ d[4] ^ d[0] ^ c[8] ^ c[24] ^ c[28] ^ c[29];
+ newcrc[17] = d[6] ^ d[5] ^ d[1] ^ c[9] ^ c[25] ^ c[29] ^ c[30];
+ newcrc[18] = d[7] ^ d[6] ^ d[2] ^ c[10] ^ c[26] ^ c[30] ^ c[31];
+ newcrc[19] = d[7] ^ d[3] ^ c[11] ^ c[27] ^ c[31];
+ newcrc[20] = d[4] ^ c[12] ^ c[28];
+ newcrc[21] = d[5] ^ c[13] ^ c[29];
+ newcrc[22] = d[0] ^ c[14] ^ c[24];
+ newcrc[23] = d[6] ^ d[1] ^ d[0] ^ c[15] ^ c[24] ^ c[25] ^ c[30];
+ newcrc[24] = d[7] ^ d[2] ^ d[1] ^ c[16] ^ c[25] ^ c[26] ^ c[31];
+ newcrc[25] = d[3] ^ d[2] ^ c[17] ^ c[26] ^ c[27];
+ newcrc[26] = d[6] ^ d[4] ^ d[3] ^ d[0] ^ c[18] ^ c[24] ^ c[27] ^ c[28] ^ c[30];
+ newcrc[27] = d[7] ^ d[5] ^ d[4] ^ d[1] ^ c[19] ^ c[25] ^ c[28] ^ c[29] ^ c[31];
+ newcrc[28] = d[6] ^ d[5] ^ d[2] ^ c[20] ^ c[26] ^ c[29] ^ c[30];
+ newcrc[29] = d[7] ^ d[6] ^ d[3] ^ c[21] ^ c[27] ^ c[30] ^ c[31];
+ newcrc[30] = d[7] ^ d[4] ^ c[22] ^ c[28] ^ c[31];
+ newcrc[31] = d[5] ^ c[23] ^ c[29];
+ nextCRC32_D8 = newcrc;
+ end
+ endfunction
+
+/*
+ --------------------------------------------------------------------------
+
+ --
+
+
+ --
+
+[28-07-2014 12:12:47 PM][mammenx] Added Pause Frame support
+
+[02-07-2014 12:53:29 AM][mammenx] Added misc MAC parameters & CRC function
+
+[28-06-2014 04:43:57 PM][mammenx] Removed System Verilog
+
+[24-06-2014 08:01:48 PM][mammenx] Added CRC function
+
+[18-06-2014 08:39:55 PM][mammenx] Added VLAN Tag & MAC Header structure types
+
+[18-06-2014 07:27:24 PM][mammenx] Initial Commit
+
+ --------------------------------------------------------------------------
+*/
+"
+"/*
+ --------------------------------------------------------------------------
+ Pegasus - Copyright (C) 2012 Gregory Matthew James.
+
+ This file is part of Pegasus.
+
+ Pegasus is free; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Pegasus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --------------------------------------------------------------------------
+*/
+
+/*
+ --------------------------------------------------------------------------
+ -- Project Code : pegasus
+ -- Module Name : peg_l2_mac_rx_parser
+ -- Author : mammenx
+ -- Associated modules:
+ -- Function : This module parses an ingress packet stream to
+ extract the different fields in an L2 frame. This
+ has an 8b pipeline that is intended for upto 1Gbps
+ speeds @ 125MHz clock.
+ --------------------------------------------------------------------------
+*/
+
+`timescale 1ns / 10ps
+
+
+module peg_l2_mac_rx_parser #(
+ parameter PKT_DATA_W = 8,
+ parameter PKT_SIZE_W = 16,
+ parameter NUM_FIELDS = 8,
+ parameter BFFR_SIZE = 48
+)
+
+(
+ input clk,
+ input rst_n,
+
+ //Config interface
+ input config_l2_mac_rx_en,
+ input config_l2_mac_rx_fcs_en,
+ input config_l2_mac_rx_strip_preamble_sfd,
+ input config_l2_mac_rx_strip_fcs,
+
+ //Status interface
+ output [3:0] l2_mac_rx_fsm_state,
+
+ //Interface to RX Filter & Pause Gen
+ output [NUM_FIELDS-1:0] rx_field_valid_vec,
+ output [BFFR_SIZE-1:0] rx_bffr,
+
+ //Interface to FCS Calculator
+ output rx_fcs_rst,
+ output rx_fcs_calc_en,
+ output [PKT_DATA_W-1:0] rx_fcs_calc_data,
+
+ //RS packet interface
+ input rs_rx_valid,
+ input rs_rx_sop,
+ input rs_rx_eop,
+ input [PKT_DATA_W-1:0] rs_rx_data,
+ output rs_rx_ready,
+ input rs_rx_error,
+
+ //LLC packet interface
+ output llc_rx_valid,
+ output llc_rx_sop,
+ output llc_rx_eop,
+ output [PKT_DATA_W-1:0] llc_rx_data,
+ input llc_rx_ready,
+ output llc_rx_error
+
+);
+
+//----------------------- Global parameters Declarations ------------------
+ `include ""peg_l2_params.v""
+
+ parameter PKT_SIZE_INC_VAL = PKT_DATA_W / 8;
+
+//----------------------- Input Declarations ------------------------------
+
+
+//----------------------- Inout Declarations ------------------------------
+
+
+//----------------------- Output Declarations -----------------------------
+
+
+//----------------------- Output Register Declaration ---------------------
+ reg [NUM_FIELDS-1:0] rx_field_valid_vec;
+ reg [BFFR_SIZE-1:0] rx_bffr;
+
+ reg rx_fcs_rst;
+ reg rx_fcs_calc_en;
+
+ reg llc_rx_valid;
+ reg llc_rx_sop;
+ reg llc_rx_eop;
+
+//----------------------- Internal Register Declarations ------------------
+ reg [15:0] data_cntr_f;
+ reg vlan_frm_f;
+ reg ctrl_frm_f;
+ reg pause_frm_f;
+ reg [2:0] fcs_en_delay_vec_f;
+ reg fcs_en_nxt_c;
+ reg [2:0] llc_rx_valid_del_vec_f;
+ reg llc_rx_valid_nxt_c;
+ reg [2:0] llc_rx_sop_del_vec_f;
+ reg llc_rx_sop_nxt_c;
+
+//----------------------- Internal Wire Declarations ----------------------
+ wire rx_data_valid_c;
+ wire [15:0] data_bytes_w;
+ wire [BFFR_SIZE-1:0] bffr_nxt_w;
+
+ wire preamble_valid_c;
+ wire sfd_valid_c;
+
+
+//----------------------- FSM Parameters --------------------------------------
+//only for FSM state vector representation
+parameter [3:0] // synopsys enum fsm_pstate
+IDLE_S = 4\'d0,
+PREAMBLE_S = 4\'d1,
+SFD_S = 4\'d2,
+DA_S = 4\'d3,
+SA_S = 4\'d4,
+LEN_TYPE_S = 4\'d5,
+VLAN_TAG_S = 4\'d6,
+DATA_S = 4\'d7,
+FCS_S = 4\'d8;
+
+//----------------------- FSM Register Declarations ------------------
+reg [3:0] // synopsys enum fsm_pstate
+fsm_pstate, next_state;
+
+//----------------------- FSM String Declarations ------------------
+//synthesis translate_off
+reg [8*16:0] state_name;//""state name"" is user defined
+//synthesis translate_on
+
+//----------------------- FSM Debugging Logic Declarations ------------------
+//synthesis translate_off
+always @ (fsm_pstate)
+begin
+case (fsm_pstate)
+
+IDLE_S : state_name = ""IDLE_S"";
+
+PREAMBLE_S : state_name = ""PREAMBLE_S"";
+
+SFD_S : state_name = ""SFD_S"";
+
+DA_S : state_name = ""DA_S"";
+
+SA_S : state_name = ""SA_S"";
+
+LEN_TYPE_S : state_name = ""LEN_TYPE_S"";
+
+VLAN_TAG_S : state_name = ""VLAN_TAG_S"";
+
+DATA_S : state_name = ""DATA_S"";
+
+FCS_S : state_name = ""FCS_S"";
+
+default : state_name = ""INVALID STATE!"";
+endcase
+end
+//synthesis translate_on
+
+//----------------------- Input/Output Registers --------------------------
+
+//----------------------- Start of Code -----------------------------------
+
+ always@(posedge clk, negedge rst_n)
+ begin
+ if(~rst_n)
+ begin
+ fsm_pstate <= IDLE_S;
+ data_cntr_f <= 0;
+ vlan_frm_f <= 0;
+ ctrl_frm_f <= 0;
+ pause_frm_f <= 0;
+ fcs_en_delay_vec_f <= 0;
+ llc_rx_valid_del_vec_f <= 0;
+ llc_rx_sop_del_vec_f <= 0;
+
+ rx_fcs_rst <= 0;
+ rx_fcs_calc_en <= 0;
+
+ llc_rx_valid <= 0;
+ llc_rx_sop <= 0;
+ llc_rx_eop <= 0;
+ end
+ else
+ begin
+ fsm_pstate <= next_state;
+
+ if(fsm_pstate == IDLE_S)
+ begin
+ fcs_en_delay_vec_f <= 0;
+ llc_rx_valid_del_vec_f<= 0;
+ llc_rx_sop_del_vec_f <= 0;
+ end
+ else if(fsm_pstate == FCS_S)
+ begin
+ fcs_en_delay_vec_f <= 0;
+ llc_rx_sop_del_vec_f <= 0;
+ llc_rx_valid_del_vec_f<= {llc_rx_valid_del_vec_f[1:0],1\'b0};
+ end
+ else
+ begin
+ fcs_en_delay_vec_f <= rx_data_valid_c ? {fcs_en_delay_vec_f[1:0], fcs_en_nxt_c} : fcs_en_delay_vec_f;
+ llc_rx_valid_del_vec_f<= rx_data_valid_c ? {llc_rx_valid_del_vec_f[1:0],llc_rx_valid_nxt_c} : llc_rx_valid_del_vec_f;
+ llc_rx_sop_del_vec_f <= rx_data_valid_c ? {llc_rx_sop_del_vec_f[1:0],llc_rx_sop_nxt_c} : llc_rx_sop_del_vec_f;
+ end
+
+ rx_fcs_calc_en <= rx_data_valid_c & fcs_en_delay_vec_f[2] & (fsm_pstate != IDLE_S);
+
+ rx_fcs_rst <= (fsm_pstate == SFD_S) ? 1\'b1 : 1\'b0;
+
+ llc_rx_valid <= (fsm_pstate == FCS_S) ? llc_rx_valid_del_vec_f[2] : rx_data_valid_c & llc_rx_valid_del_vec_f[2];
+
+ llc_rx_sop <= rx_data_valid_c & llc_rx_valid_del_vec_f[2] & (fsm_pstate != IDLE_S);
+
+ if((fsm_pstate == DATA_S) & rx_data_valid_c & rs_rx_eop)
+ begin
+ llc_rx_eop <= config_l2_mac_rx_strip_fcs;
+ end
+ else if(fsm_pstate == FCS_S)
+ begin
+ llc_rx_eop <= (llc_rx_valid_del_vec_f == 3\'b100) ? 1\'b1 : 1\'b0;
+ end
+ else
+ begin
+ llc_rx_eop <= 1\'b0;
+ end
+
+ if(fsm_pstate == IDLE_S)
+ begin
+ data_cntr_f <= 0;
+ end
+ else if(rx_data_valid_c)
+ begin
+ data_cntr_f <= data_cntr_f + PKT_SIZE_INC_VAL;
+ end
+
+ if(fsm_pstate == IDLE_S)
+ begin
+ vlan_frm_f <= 0;
+ end
+ else if(data_bytes_w == MAC_DATA_OFFSET-1)
+ begin
+ vlan_frm_f <= (bffr_nxt_w[15:0] == VLAN_TYPE_VALUE) ? rx_data_valid_c : 1\'b0;
+ end
+
+ if(fsm_pstate == IDLE_S)
+ begin
+ ctrl_frm_f <= 0;
+ end
+ else if(data_bytes_w == MAC_DATA_OFFSET-1)
+ begin
+ ctrl_frm_f <= (bffr_nxt_w[15:0] == CTRL_TYPE_VALUE) ? rx_data_valid_c : 1\'b0;
+ end
+
+ if(fsm_pstate == IDLE_S)
+ begin
+ pause_frm_f <= 0;
+ end
+ else if(data_bytes_w == MAC_PAUSE_TIME_OFFSET+1)
+ begin
+ pause_frm_f <= (bffr_nxt_w[15:0] == PAUSE_CTRL_OPCODE) ? rx_data_valid_c & ctrl_frm_f : 1\'b0;
+ end
+ end
+ end
+
+ assign rx_fcs_calc_data = (data_bytes_w <= 4) ? ~rx_bffr[(2*PKT_DATA_W) +: PKT_DATA_W]
+ : rx_bffr[(2*PKT_DATA_W) +: PKT_DATA_W];
+
+ assign rx_data_valid_c = rs_rx_valid & rs_rx_ready;
+ assign rs_rx_ready = 1\'b1;
+
+ assign data_bytes_w = {{(PKT_SIZE_INC_VAL-1){1\'b0}},data_cntr_f[15:PKT_SIZE_INC_VAL-1]};
+
+ always@(*)
+ begin
+ next_state = fsm_pstate;
+ fcs_en_nxt_c = 1\'b0;
+ llc_rx_valid_nxt_c = 1\'b0;
+ llc_rx_sop_nxt_c = 1\'b0;
+
+ case(fsm_pstate)
+
+ IDLE_S :
+ begin
+ if(rx_data_valid_c & rs_rx_sop & config_l2_mac_rx_en)
+ begin
+ llc_rx_valid_nxt_c = ~config_l2_mac_rx_strip_preamble_sfd;
+ llc_rx_sop_nxt_c = ~config_l2_mac_rx_strip_preamble_sfd;
+ next_state = PREAMBLE_S;
+ end
+ end
+
+ PREAMBLE_S :
+ begin
+ llc_rx_valid_nxt_c = ~config_l2_mac_rx_strip_preamble_sfd;
+
+ if(rx_data_valid_c & (data_bytes_w == MAC_SFD_OFFSET-1))
+ begin
+ next_state = preamble_valid_c ? SFD_S : IDLE_S;
+ end
+ end
+
+ SFD_S :
+ begin
+ llc_rx_valid_nxt_c = ~config_l2_mac_rx_strip_preamble_sfd;
+
+ if(rx_data_valid_c & (data_bytes_w == MAC_SA_OFFSET-1))
+ begin
+ llc_rx_sop_nxt_c = config_l2_mac_rx_strip_preamble_sfd;
+ next_state = sfd_valid_c ? DA_S : IDLE_S;
+ end
+ end
+
+ DA_S :
+ begin
+ llc_rx_valid_nxt_c = 1\'b1;
+ fcs_en_nxt_c = config_l2_mac_rx_fcs_en;
+
+ if(rx_data_valid_c & (data_bytes_w == MAC_SA_OFFSET-1))
+ begin
+ next_state = SA_S;
+ end
+ end
+
+ SA_S :
+ begin
+ llc_rx_valid_nxt_c = 1\'b1;
+ fcs_en_nxt_c = config_l2_mac_rx_fcs_en;
+
+ if(rx_data_valid_c & (data_bytes_w == MAC_LEN_TYPE_OFFSET-1))
+ begin
+ next_state = LEN_TYPE_S;
+ end
+ end
+
+ LEN_TYPE_S :
+ begin
+ llc_rx_valid_nxt_c = 1\'b1;
+ fcs_en_nxt_c = config_l2_mac_rx_fcs_en;
+
+ if(rx_data_valid_c & (data_bytes_w == MAC_DATA_OFFSET))
+ begin
+ next_state = (bffr_nxt_w == VLAN_TYPE_VALUE) ? VLAN_TAG_S : DATA_S;
+ end
+ end
+
+ VLAN_TAG_S :
+ begin
+ llc_rx_valid_nxt_c = 1\'b1;
+ fcs_en_nxt_c = config_l2_mac_rx_fcs_en;
+
+ if(rx_data_valid_c & (data_bytes_w == MAC_VLAN_DATA_OFFSET))
+ begin
+ next_state = DATA_S;
+ end
+ end
+
+ DATA_S :
+ begin
+ llc_rx_valid_nxt_c = 1\'b1;
+ fcs_en_nxt_c = config_l2_mac_rx_fcs_en;
+
+ if(rx_data_valid_c & rs_rx_eop)
+ begin
+ next_state = config_l2_mac_rx_strip_fcs ? IDLE_S : FCS_S;
+ end
+ end
+
+ FCS_S :
+ begin
+ if(llc_rx_valid_del_vec_f == 3\'b000)
+ begin
+ next_state = IDLE_S;
+ end
+ end
+
+ endcase
+ end
+
+ assign preamble_valid_c = (bffr_nxt_w[55:0] == {7{PREAMBLE_VALUE}}) ? 1\'b1 : 1\'b0;
+ assign sfd_valid_c = (bffr_nxt_w[7:0] == SFD_VALUE) ? 1\'b1 : 1\'b0;
+
+ /* Output Buffer logic */
+ always@(posedge clk, negedge rst_n)
+ begin
+ if(~rst_n)
+ begin
+ rx_field_valid_vec <= 0;
+ rx_bffr <= 0;
+ end
+ else
+ begin
+ rx_bffr <= rx_data_valid_c ? bffr_nxt_w : rx_bffr;
+
+ rx_field_valid_vec[MAC_FIDX_DADDR] <= (data_bytes_w == MAC_SA_OFFSET-1) ? rx_data_valid_c : 1\'b0;
+ rx_field_valid_vec[MAC_FIDX_SADDR] <= (data_bytes_w == MAC_LEN_TYPE_OFFSET-1) ? rx_data_valid_c : 1\'b0;
+ rx_field_valid_vec[MAC_FIDX_LEN_TYPE] <= (data_bytes_w == MAC_DATA_OFFSET-1) ? rx_data_valid_c : 1\'b0;
+ rx_field_valid_vec[MAC_FIDX_VLAN_TAG] <= (data_bytes_w == MAC_VLAN_DATA_OFFSET-1) ? rx_data_valid_c & vlan_frm_f : 1\'b0;
+ rx_field_valid_vec[MAC_FIDX_CTRL_OPCODE] <= (data_bytes_w == MAC_PAUSE_TIME_OFFSET-1) ? rx_data_valid_c & ctrl_frm_f : 1\'b0;
+ rx_field_valid_vec[MAC_FIDX_PAUSE_TIME] <= (data_bytes_w == MAC_PAUSE_TIME_OFFSET+1) ? rx_data_valid_c & pause_frm_f : 1\'b0;
+ rx_field_valid_vec[MAC_FIDX_FCS] <= (fsm_pstate == DATA_S) ? rx_data_valid_c & rs_rx_eop : 1\'b0;
+ end
+ end
+
+ assign bffr_nxt_w = {rx_bffr[BFFR_SIZE-PKT_DATA_W-1:0],rs_rx_data};
+
+endmodule // peg_l2_mac_rx_parser
+
+
+/*
+ --------------------------------------------------------------------------
+
+ --
+
+
+ --
+
+[28-07-2014 04:18:29 PM][mammenx] Created basic wrapper
+
+[28-07-2014 12:13:48 PM][mammenx] Initial Commit
+
+[28-05-14 20:18:21] [mammenx] Moved log section to bottom of file
+
+ --------------------------------------------------------------------------
+*/
+"
+"/*
+ --------------------------------------------------------------------------
+ Pegasus - Copyright (C) 2012 Gregory Matthew James.
+
+ This file is part of Pegasus.
+
+ Pegasus is free; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Pegasus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --------------------------------------------------------------------------
+*/
+
+/*
+ --------------------------------------------------------------------------
+ -- Project Code : pegasus
+ -- Module Name : pkt_ff_rptr
+ -- Author : mammenx
+ -- Associated modules:
+ -- Function : This module maintains logic for updating the read
+ pointer.
+ --------------------------------------------------------------------------
+*/
+
+`timescale 1ns / 10ps
+
+
+module pkt_ff_rptr #(PTR_W = 8)
+(
+
+ //--------------------- Misc Ports (Logic) -----------
+ clk,
+ rst_n,
+
+ rd_en,
+
+ rptr
+
+ //--------------------- Interfaces --------------------
+
+
+);
+
+//----------------------- Global parameters Declarations ------------------
+
+
+//----------------------- Input Declarations ------------------------------
+ input clk;
+ input rst_n;
+
+ input rd_en;
+
+//----------------------- Inout Declarations ------------------------------
+
+
+//----------------------- Output Declarations -----------------------------
+ output [PTR_W-1:0] rptr;
+
+//----------------------- Output Register Declaration ---------------------
+
+
+//----------------------- Internal Register Declarations ------------------
+
+
+//----------------------- Internal Wire Declarations ----------------------
+
+
+//----------------------- Internal Interface Declarations -----------------
+
+
+//----------------------- FSM Declarations --------------------------------
+
+
+//----------------------- Start of Code -----------------------------------
+
+ //Implement rptr as a gray counter
+ gry_cntr u_rptr_gry_cntr
+ (
+
+ .clk (clk),
+ .rst_n (rst_n),
+
+ .rst_val ({PTR_W{1'b0}}),
+
+ .en (rd_en),
+ .gry_cnt (),
+ .gry_cnt_nxt (rptr)
+
+ );
+
+ defparam u_rptr_gry_cntr.WIDTH = PTR_W;
+
+
+endmodule // pkt_ff_rptr
+
+/*
+ --------------------------------------------------------------------------
+
+ --
+
+
+ --
+
+[28-06-2014 03:30:57 PM][mammenx] Moved to Verilog
+
+[08-06-2014 02:14:35 PM][mammenx] Initial Commit
+
+[28-05-14 20:18:21] [mammenx] Moved log section to bottom of file
+
+ --------------------------------------------------------------------------
+*/
+"
+"/*
+ --------------------------------------------------------------------------
+ Pegasus - Copyright (C) 2012 Gregory Matthew James.
+
+ This file is part of Pegasus.
+
+ Pegasus is free; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Pegasus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --------------------------------------------------------------------------
+*/
+
+/*
+ --------------------------------------------------------------------------
+ -- Project Code : pegasus
+ -- Module Name :
+ -- Author : mammenx
+ -- Associated modules:
+ -- Function :
+ --------------------------------------------------------------------------
+*/
+
+`timescale 1ns / 10ps
+
+
+module (
+
+ );
+
+//----------------------- Global parameters Declarations ------------------
+
+
+//----------------------- Input Declarations ------------------------------
+
+
+//----------------------- Inout Declarations ------------------------------
+
+
+//----------------------- Output Declarations -----------------------------
+
+
+//----------------------- Output Register Declaration ---------------------
+
+
+//----------------------- Internal Register Declarations ------------------
+
+
+//----------------------- Internal Wire Declarations ----------------------
+
+
+//----------------------- FSM Parameters --------------------------------------
+//only for FSM state vector representation
+parameter [?:0] // synopsys enum fsm_pstate
+IDLE = ,
+
+//----------------------- FSM Register Declarations ------------------
+reg [?:0] // synopsys enum fsm_pstate
+fsm_pstate, next_state;
+
+//----------------------- FSM String Declarations ------------------
+//synthesis translate_off
+reg [8*?:0] state_name;//""state name"" is user defined
+//synthesis translate_on
+
+//----------------------- FSM Debugging Logic Declarations ------------------
+//synthesis translate_off
+always @ (fsm_pstate)
+begin
+case (fsm_pstate)
+
+ : state_name = ""IDLE"";
+
+ : state_name = ""state2"";
+.
+.
+.
+ : state_name = ""default"";
+endcase
+end
+//synthesis translate_on
+
+//----------------------- Input/Output Registers --------------------------
+
+//----------------------- Start of Code -----------------------------------
+//code should be <=200 lines
+
+/* comments for assign statements
+*/
+
+//assign statements
+
+/* comments for combinatory logic
+ Asynchronous part of FSM
+*/
+
+
+/* comments for sequential logic
+*/
+//;
+
+endmodule //
+
+
+/*
+ --------------------------------------------------------------------------
+
+ --
+
+
+ --
+
+[28-05-14 20:18:21] [mammenx] Moved log section to bottom of file
+
+ --------------------------------------------------------------------------
+*/
+"
+"import time
+import http
+
+fn main() {
+ data := http.get('https://vlang.io/utc_now') or {
+ println('failed to fetch data from the server')
+ }
+ t := time.unix(data)
+ println(t.clean()) // 27 Jun 2019 14:32
+}"
+"/*
+Copyright (C) 2019-2021, Gisselquist Technology, LLC
+
+This program is free software (firmware): you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. (It's in the $(ROOT)/doc directory. Run make with no
+target there if the PDF file isn't present.) If not, see
+ for a copy.
+
+License: GPL, v3, as defined and found on www.gnu.org,
+http://www.gnu.org/licenses/gpl.html
+*/
+`default_nettype none
+module skidbuffer #(
+ parameter [0:0] OPT_LOWPOWER = 0,
+ parameter [0:0] OPT_OUTREG = 1,
+ parameter [0:0] OPT_PASSTHROUGH = 0,
+ parameter DW = 8
+) (
+ input wire i_clk,
+ i_reset,
+ input wire i_valid,
+ output reg o_ready,
+ input wire [DW-1:0] i_data,
+ output reg o_valid,
+ input wire i_ready,
+ output reg [DW-1:0] o_data
+);
+ reg [DW-1:0] r_data;
+ generate
+ if (OPT_PASSTHROUGH) begin : PASSTHROUGH
+ always @(*) o_ready = i_ready;
+ always @(*) o_valid = i_valid;
+ always @(*)
+ if (!i_valid && OPT_LOWPOWER) o_data = 0;
+ else o_data = i_data;
+ always @(*) r_data = 0;
+ end else begin : LOGIC
+ reg r_valid;
+ initial r_valid = 0;
+ always @(posedge i_clk)
+ if (i_reset) r_valid <= 0;
+ else if ((i_valid && o_ready) && (o_valid && !i_ready)) r_valid <= 1;
+ else if (i_ready) r_valid <= 0;
+ initial r_data = 0;
+ always @(posedge i_clk)
+ if (OPT_LOWPOWER && i_reset) r_data <= 0;
+ else if (OPT_LOWPOWER && (!o_valid || i_ready)) r_data <= 0;
+ else if ((!OPT_LOWPOWER || !OPT_OUTREG || i_valid) && o_ready) r_data <= i_data;
+ always @(*) o_ready = !r_valid;
+ if (!OPT_OUTREG) begin
+ always @(*) o_valid = !i_reset && (i_valid || r_valid);
+ always @(*)
+ if (r_valid) o_data = r_data;
+ else if (!OPT_LOWPOWER || i_valid) o_data = i_data;
+ else o_data = 0;
+ end else begin : REG_OUTPUT
+ initial o_valid = 0;
+ always @(posedge i_clk)
+ if (i_reset) o_valid <= 0;
+ else if (!o_valid || i_ready) o_valid <= (i_valid || r_valid);
+ initial o_data = 0;
+ always @(posedge i_clk)
+ if (OPT_LOWPOWER && i_reset) o_data <= 0;
+ else if (!o_valid || i_ready) begin
+ if (r_valid) o_data <= r_data;
+ else if (!OPT_LOWPOWER || i_valid) o_data <= i_data;
+ else o_data <= 0;
+ end
+ end
+ end
+ endgenerate
+`ifdef FORMAL
+`ifdef VERIFIC
+ `define FORMAL_VERIFIC
+`endif
+`endif
+`ifdef FORMAL_VERIFIC
+ property RESET_CLEARS_IVALID;
+ @(posedge i_clk) i_reset |=> !i_valid;
+ endproperty
+ property IDATA_HELD_WHEN_NOT_READY;
+ @(posedge i_clk) disable iff (i_reset) i_valid && !o_ready |=> i_valid && $stable(
+ i_data
+ );
+ endproperty
+`ifdef SKIDBUFFER
+ assume property (IDATA_HELD_WHEN_NOT_READY);
+`else
+ assert property (IDATA_HELD_WHEN_NOT_READY);
+`endif
+ generate
+ if (!OPT_PASSTHROUGH) begin
+ assert property (@(posedge i_clk) OPT_OUTREG && i_reset |=> o_ready && !o_valid);
+ assert property (@(posedge i_clk) !OPT_OUTREG && i_reset |-> !o_valid);
+ assert property (@(posedge i_clk)
+disable iff (i_reset)
+o_valid && !i_ready
+|=> (o_valid && $stable(
+ o_data
+ )));
+ assert property (@(posedge i_clk)
+disable iff (i_reset)
+(i_valid && o_ready
+&& (!OPT_OUTREG || o_valid) && !i_ready)
+|=> (!o_ready && r_data == $past(
+ i_data
+ )));
+ if (!OPT_OUTREG) begin
+ assert property (@(posedge i_clk) disable iff (i_reset) i_ready |=> (o_valid == i_valid));
+ end else begin
+ assert property (@(posedge i_clk) disable iff (i_reset) i_valid && o_ready |=> o_valid);
+ assert property (@(posedge i_clk)
+disable iff (i_reset)
+!i_valid && o_ready && i_ready |=> !o_valid);
+ end
+ assert property (@(posedge i_clk) !o_ready && i_ready |=> o_ready);
+ if (OPT_LOWPOWER) begin
+ assert property (@(posedge i_clk) (OPT_OUTREG || !i_reset) && !o_valid |-> o_data == 0);
+ assert property (@(posedge i_clk) o_ready |-> r_data == 0);
+ end
+`ifdef SKIDBUFFER
+ reg f_changed_data;
+ cover property (@(posedge i_clk)
+disable iff (i_reset)
+(!o_valid && !i_valid)
+##1 i_valid && i_ready [*3]
+##1 i_valid && !i_ready
+##1 i_valid && i_ready [*2]
+##1 i_valid && !i_ready [*2]
+##1 i_valid && i_ready [*3]
+##1 o_valid && i_ready [*0:5]
+##1 (!o_valid && !i_valid && f_changed_data));
+ initial f_changed_data = 0;
+ always @(posedge i_clk)
+ if (i_reset) f_changed_data <= 1;
+ else if (i_valid && $past(!i_valid || o_ready)) begin
+ if (i_data != $past(i_data + 1)) f_changed_data <= 0;
+ end else if (!i_valid && i_data != 0) f_changed_data <= 0;
+`endif
+ end
+ endgenerate
+`endif
+endmodule
+`ifndef YOSYS
+`default_nettype wire
+`endif
+"
+"/*
+Copyright (C) 2015-2021, Gisselquist Technology, LLC
+
+This program is free software (firmware): you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. (It's in the $(ROOT)/doc directory. Run make with no
+target there if the PDF file isn't present.) If not, see
+ for a copy.
+
+License: GPL, v3, as defined and found on www.gnu.org,
+http://www.gnu.org/licenses/gpl.html
+*/
+`default_nettype none
+module rxuart #(
+ parameter [30:0] INITIAL_SETUP = 31'd868,
+ parameter [3:0] RXU_BIT_ZERO = 4'h0,
+ RXU_BIT_ONE = 4'h1,
+ RXU_BIT_TWO = 4'h2,
+ RXU_BIT_THREE = 4'h3,
+ RXU_BIT_SEVEN = 4'h7,
+ RXU_PARITY = 4'h8,
+ RXU_STOP = 4'h9,
+ RXU_SECOND_STOP = 4'ha,
+ RXU_BREAK = 4'hd,
+ RXU_RESET_IDLE = 4'he,
+ RXU_IDLE = 4'hf
+) (
+ input wire i_clk,
+ i_reset,
+ input wire [30:0] i_setup,
+ input wire i_uart_rx,
+ output reg o_wr,
+ output reg [7:0] o_data,
+ output reg o_break,
+ output reg o_parity_err,
+ o_frame_err,
+ output wire o_ck_uart
+);
+ wire [27:0] clocks_per_baud, break_condition, half_baud;
+ wire [1:0] data_bits;
+ wire use_parity, parity_even, dblstop, fixd_parity;
+ reg [29:0] r_setup;
+ reg [3:0] state;
+ reg [27:0] baud_counter;
+ reg zero_baud_counter;
+ reg q_uart, qq_uart, ck_uart;
+ reg [27:0] chg_counter;
+ reg line_synch;
+ reg half_baud_time;
+ reg [7:0] data_reg;
+ reg calc_parity;
+ reg pre_wr;
+ assign clocks_per_baud = {4'h0, r_setup[23:0]};
+ assign data_bits = r_setup[29:28];
+ assign dblstop = r_setup[27];
+ assign use_parity = r_setup[26];
+ assign fixd_parity = r_setup[25];
+ assign parity_even = r_setup[24];
+ assign break_condition = {r_setup[23:0], 4'h0};
+ assign half_baud = {5'h00, r_setup[23:1]} - 28'h1;
+ initial q_uart = 1'b0;
+ initial qq_uart = 1'b0;
+ initial ck_uart = 1'b0;
+ always @(posedge i_clk) begin
+ q_uart <= i_uart_rx;
+ qq_uart <= q_uart;
+ ck_uart <= qq_uart;
+ end
+ assign o_ck_uart = ck_uart;
+ initial chg_counter = 28'h00;
+ always @(posedge i_clk)
+ if (i_reset) chg_counter <= 28'h00;
+ else if (qq_uart != ck_uart) chg_counter <= 28'h00;
+ else if (chg_counter < break_condition) chg_counter <= chg_counter + 1;
+ initial o_break = 1'b0;
+ always @(posedge i_clk) o_break <= ((chg_counter >= break_condition) && (~ck_uart)) ? 1'b1 : 1'b0;
+ initial line_synch = 1'b0;
+ always @(posedge i_clk) line_synch <= ((chg_counter >= break_condition) && (ck_uart));
+ initial half_baud_time = 0;
+ always @(posedge i_clk) half_baud_time <= (~ck_uart) && (chg_counter >= half_baud);
+ initial r_setup = INITIAL_SETUP[29:0];
+ always @(posedge i_clk) if (state >= RXU_RESET_IDLE) r_setup <= i_setup[29:0];
+ initial state = RXU_RESET_IDLE;
+ always @(posedge i_clk)
+ if (i_reset) state <= RXU_RESET_IDLE;
+ else if (state == RXU_RESET_IDLE) begin
+ if (line_synch) state <= RXU_IDLE;
+ else state <= RXU_RESET_IDLE;
+ end else if (o_break) begin
+ state <= RXU_BREAK;
+ end else if (state == RXU_BREAK) begin
+ if (ck_uart) state <= RXU_IDLE;
+ else state <= RXU_BREAK;
+ end else if (state == RXU_IDLE) begin
+ if ((~ck_uart) && (half_baud_time)) begin
+ case (data_bits)
+ 2'b00: state <= RXU_BIT_ZERO;
+ 2'b01: state <= RXU_BIT_ONE;
+ 2'b10: state <= RXU_BIT_TWO;
+ 2'b11: state <= RXU_BIT_THREE;
+ endcase
+ end else state <= RXU_IDLE;
+ end else if (zero_baud_counter) begin
+ if (state < RXU_BIT_SEVEN) state <= state + 1;
+ else if (state == RXU_BIT_SEVEN) state <= (use_parity) ? RXU_PARITY : RXU_STOP;
+ else if (state == RXU_PARITY) state <= RXU_STOP;
+ else if (state == RXU_STOP) begin
+ if (~ck_uart) state <= RXU_RESET_IDLE;
+ else if (dblstop) state <= RXU_SECOND_STOP;
+ else state <= RXU_IDLE;
+ end else begin
+ if (~ck_uart) state <= RXU_RESET_IDLE;
+ else state <= RXU_IDLE;
+ end
+ end
+ always @(posedge i_clk)
+ if ((zero_baud_counter) && (state != RXU_PARITY))
+ data_reg <= {ck_uart, data_reg[7:1]};
+ always @(posedge i_clk)
+ if (state == RXU_IDLE) calc_parity <= 0;
+ else if (zero_baud_counter) calc_parity <= calc_parity ^ ck_uart;
+ initial o_parity_err = 1'b0;
+ always @(posedge i_clk)
+ if ((zero_baud_counter) && (state == RXU_PARITY)) begin
+ if (fixd_parity) o_parity_err <= (ck_uart ^ parity_even);
+ else if (parity_even) o_parity_err <= (calc_parity != ck_uart);
+ else o_parity_err <= (calc_parity == ck_uart);
+ end else if (state >= RXU_BREAK) o_parity_err <= 1'b0;
+ initial o_frame_err = 1'b0;
+ always @(posedge i_clk)
+ if ((zero_baud_counter) && ((state == RXU_STOP) || (state == RXU_SECOND_STOP)))
+ o_frame_err <= (o_frame_err) || (~ck_uart);
+ else if ((zero_baud_counter) || (state >= RXU_BREAK)) o_frame_err <= 1'b0;
+ initial o_data = 8'h00;
+ initial pre_wr = 1'b0;
+ always @(posedge i_clk)
+ if (i_reset) begin
+ pre_wr <= 1'b0;
+ o_data <= 8'h00;
+ end else if ((zero_baud_counter) && (state == RXU_STOP)) begin
+ pre_wr <= 1'b1;
+ case (data_bits)
+ 2'b00: o_data <= data_reg;
+ 2'b01: o_data <= {1'b0, data_reg[7:1]};
+ 2'b10: o_data <= {2'b0, data_reg[7:2]};
+ 2'b11: o_data <= {3'b0, data_reg[7:3]};
+ endcase
+ end else if ((zero_baud_counter) || (state == RXU_IDLE)) pre_wr <= 1'b0;
+ initial o_wr = 1'b0;
+ always @(posedge i_clk)
+ if ((zero_baud_counter) || (state == RXU_IDLE)) o_wr <= (pre_wr) && (!i_reset);
+ else o_wr <= 1'b0;
+ always @(posedge i_clk)
+ if (i_reset) baud_counter <= clocks_per_baud - 28'h01;
+ else if (zero_baud_counter) baud_counter <= clocks_per_baud - 28'h01;
+ else
+ case (state)
+ RXU_RESET_IDLE: baud_counter <= clocks_per_baud - 28'h01;
+ RXU_BREAK: baud_counter <= clocks_per_baud - 28'h01;
+ RXU_IDLE: baud_counter <= clocks_per_baud - 28'h01;
+ default: baud_counter <= baud_counter - 28'h01;
+ endcase
+ initial zero_baud_counter = 1'b0;
+ always @(posedge i_clk)
+ if (state == RXU_IDLE) zero_baud_counter <= 1'b0;
+ else zero_baud_counter <= (baud_counter == 28'h01);
+endmodule
+"
+"/*
+Copyright (C) 2015-2021, Gisselquist Technology, LLC
+
+This program is free software (firmware): you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. (It's in the $(ROOT)/doc directory. Run make with no
+target there if the PDF file isn't present.) If not, see
+ for a copy.
+
+License: GPL, v3, as defined and found on www.gnu.org,
+http://www.gnu.org/licenses/gpl.html
+*/
+`default_nettype none
+module txuart #(
+ parameter [30:0] INITIAL_SETUP = 31'd868,
+ parameter [3:0] TXU_BIT_ZERO = 4'h0,
+ parameter [3:0] TXU_BIT_ONE = 4'h1,
+ parameter [3:0] TXU_BIT_TWO = 4'h2,
+ parameter [3:0] TXU_BIT_THREE = 4'h3,
+ parameter [3:0] TXU_BIT_SEVEN = 4'h7,
+ parameter [3:0] TXU_PARITY = 4'h8,
+ parameter [3:0] TXU_STOP = 4'h9,
+ parameter [3:0] TXU_SECOND_STOP = 4'ha,
+ parameter [3:0] TXU_BREAK = 4'he,
+ parameter [3:0] TXU_IDLE = 4'hf
+) (
+ input wire i_clk,
+ i_reset,
+ input wire [30:0] i_setup,
+ input wire i_break,
+ input wire i_wr,
+ input wire [7:0] i_data,
+ input wire i_cts_n,
+ output reg o_uart_tx,
+ output wire o_busy
+);
+ wire [27:0] clocks_per_baud, break_condition;
+ wire [1:0] i_data_bits, data_bits;
+ wire use_parity, parity_odd, dblstop, fixd_parity, fixdp_value, hw_flow_control, i_parity_odd;
+ reg [30:0] r_setup;
+ assign clocks_per_baud = {4'h0, r_setup[23:0]};
+ assign break_condition = {r_setup[23:0], 4'h0};
+ assign hw_flow_control = !r_setup[30];
+ assign i_data_bits = i_setup[29:28];
+ assign data_bits = r_setup[29:28];
+ assign dblstop = r_setup[27];
+ assign use_parity = r_setup[26];
+ assign fixd_parity = r_setup[25];
+ assign i_parity_odd = i_setup[24];
+ assign parity_odd = r_setup[24];
+ assign fixdp_value = r_setup[24];
+ reg [27:0] baud_counter;
+ reg [ 3:0] state;
+ reg [ 7:0] lcl_data;
+ reg calc_parity, r_busy, zero_baud_counter, last_state;
+ reg q_cts_n, qq_cts_n, ck_cts;
+ always @(posedge i_clk) {qq_cts_n, q_cts_n} <= {q_cts_n, i_cts_n};
+ always @(posedge i_clk) ck_cts <= (!qq_cts_n) || (!hw_flow_control);
+ initial r_busy = 1'b1;
+ initial state = TXU_IDLE;
+ always @(posedge i_clk)
+ if (i_reset) begin
+ r_busy <= 1'b1;
+ state <= TXU_IDLE;
+ end else if (i_break) begin
+ state <= TXU_BREAK;
+ r_busy <= 1'b1;
+ end else if (!zero_baud_counter) begin
+ r_busy <= 1'b1;
+ end else if (state == TXU_BREAK) begin
+ state <= TXU_IDLE;
+ r_busy <= !ck_cts;
+ end else if (state == TXU_IDLE) begin
+ if ((i_wr) && (!r_busy)) begin
+ r_busy <= 1'b1;
+ case (i_data_bits)
+ 2'b00: state <= TXU_BIT_ZERO;
+ 2'b01: state <= TXU_BIT_ONE;
+ 2'b10: state <= TXU_BIT_TWO;
+ 2'b11: state <= TXU_BIT_THREE;
+ endcase
+ end else begin
+ r_busy <= !ck_cts;
+ end
+ end else begin
+ r_busy <= 1'b1;
+ if (state[3] == 0) begin
+ if (state == TXU_BIT_SEVEN) state <= (use_parity) ? TXU_PARITY : TXU_STOP;
+ else state <= state + 1;
+ end else if (state == TXU_PARITY) begin
+ state <= TXU_STOP;
+ end else if (state == TXU_STOP) begin
+ if (dblstop) state <= TXU_SECOND_STOP;
+ else state <= TXU_IDLE;
+ end else begin
+ state <= TXU_IDLE;
+ end
+ end
+ assign o_busy = (r_busy);
+ initial r_setup = INITIAL_SETUP;
+ always @(posedge i_clk) if (!o_busy) r_setup <= i_setup;
+ initial lcl_data = 8'hff;
+ always @(posedge i_clk)
+ if (!r_busy) lcl_data <= i_data;
+ else if (zero_baud_counter) lcl_data <= {1'b0, lcl_data[7:1]};
+ initial o_uart_tx = 1'b1;
+ always @(posedge i_clk)
+ if (i_reset) o_uart_tx <= 1'b1;
+ else if ((i_break) || ((i_wr) && (!r_busy))) o_uart_tx <= 1'b0;
+ else if (zero_baud_counter)
+ casez (state)
+ 4'b0???: o_uart_tx <= lcl_data[0];
+ TXU_PARITY: o_uart_tx <= calc_parity;
+ default: o_uart_tx <= 1'b1;
+ endcase
+ initial calc_parity = 1'b0;
+ always @(posedge i_clk)
+ if (!o_busy) calc_parity <= i_setup[24];
+ else if (fixd_parity) calc_parity <= fixdp_value;
+ else if (zero_baud_counter) begin
+ if (state[3] == 0) calc_parity <= calc_parity ^ lcl_data[0];
+ else if (state == TXU_IDLE) calc_parity <= parity_odd;
+ end else if (!r_busy) calc_parity <= parity_odd;
+ initial zero_baud_counter = 1'b0;
+ initial baud_counter = 28'h05;
+ always @(posedge i_clk) begin
+ zero_baud_counter <= (baud_counter == 28'h01);
+ if ((i_reset) || (i_break)) begin
+ baud_counter <= break_condition;
+ zero_baud_counter <= 1'b0;
+ end else if (!zero_baud_counter) baud_counter <= baud_counter - 28'h01;
+ else if (state == TXU_BREAK) begin
+ baud_counter <= 0;
+ zero_baud_counter <= 1'b1;
+ end else if (state == TXU_IDLE) begin
+ baud_counter <= 28'h0;
+ zero_baud_counter <= 1'b1;
+ if ((i_wr) && (!r_busy)) begin
+ baud_counter <= {4'h0, i_setup[23:0]} - 28'h01;
+ zero_baud_counter <= 1'b0;
+ end
+ end else if (last_state) baud_counter <= clocks_per_baud - 28'h02;
+ else baud_counter <= clocks_per_baud - 28'h01;
+ end
+ initial last_state = 1'b0;
+ always @(posedge i_clk)
+ if (dblstop) last_state <= (state == TXU_SECOND_STOP);
+ else last_state <= (state == TXU_STOP);
+ wire unused;
+ assign unused = &{1'b0, i_parity_odd, data_bits};
+`ifdef FORMAL
+ reg fsv_parity;
+ reg [30:0] fsv_setup;
+ reg [7:0] fsv_data;
+ reg f_past_valid;
+ reg [5:0] f_five_seq;
+ reg [6:0] f_six_seq;
+ reg [7:0] f_seven_seq;
+ reg [8:0] f_eight_seq;
+ reg [2:0] f_stop_seq;
+ initial f_past_valid = 1'b0;
+ always @(posedge i_clk) f_past_valid <= 1'b1;
+ always @(posedge i_clk) if ((i_wr) && (!o_busy)) fsv_data <= i_data;
+ initial fsv_setup = INITIAL_SETUP;
+ always @(posedge i_clk) if (!o_busy) fsv_setup <= i_setup;
+ always @(*) assert (r_setup == fsv_setup);
+ always @(posedge i_clk) assert (zero_baud_counter == (baud_counter == 0));
+ always @(*) if (!o_busy) assert (zero_baud_counter);
+ /*
+*
+* Will only pass if !i_break && !i_reset, otherwise the setup can
+* change in the middle of this operation
+*
+always @(posedge i_clk)
+if ((f_past_valid)&&(!$past(i_reset))&&(!$past(i_break))
+&&(($past(o_busy))||($past(i_wr))))
+assert(baud_counter <= { fsv_setup[23:0], 4'h0 });
+*/
+ always @(posedge i_clk)
+ if ((f_past_valid) && (!$past(
+ zero_baud_counter
+ )) && (!$past(
+ i_reset
+ )) && (!$past(
+ i_break
+ ))) begin
+ assert ($stable(o_uart_tx));
+ assert ($stable(state));
+ assert ($stable(lcl_data));
+ if ((state != TXU_IDLE) && (state != TXU_BREAK)) assert ($stable(calc_parity));
+ assert (baud_counter == $past(baud_counter) - 1'b1);
+ end
+ initial f_five_seq = 0;
+ always @(posedge i_clk)
+ if ((i_reset) || (i_break)) f_five_seq = 0;
+ else if ((state == TXU_IDLE) && (i_wr) && (!o_busy) && (i_data_bits == 2'b11)) f_five_seq <= 1;
+ else if (zero_baud_counter) f_five_seq <= f_five_seq << 1;
+ always @(*)
+ if (|f_five_seq) begin
+ assert (fsv_setup[29:28] == data_bits);
+ assert (data_bits == 2'b11);
+ assert (baud_counter < fsv_setup[23:0]);
+ assert (1'b0 == |f_six_seq);
+ assert (1'b0 == |f_seven_seq);
+ assert (1'b0 == |f_eight_seq);
+ assert (r_busy);
+ assert (state > 4'h2);
+ end
+ always @(*)
+ case (f_five_seq)
+ 6'h00: begin
+ assert (1);
+ end
+ 6'h01: begin
+ assert (state == 4'h3);
+ assert (o_uart_tx == 1'b0);
+ assert (lcl_data[4:0] == fsv_data[4:0]);
+ if (!fixd_parity) assert (calc_parity == parity_odd);
+ end
+ 6'h02: begin
+ assert (state == 4'h4);
+ assert (o_uart_tx == fsv_data[0]);
+ assert (lcl_data[3:0] == fsv_data[4:1]);
+ if (!fixd_parity) assert (calc_parity == fsv_data[0] ^ parity_odd);
+ end
+ 6'h04: begin
+ assert (state == 4'h5);
+ assert (o_uart_tx == fsv_data[1]);
+ assert (lcl_data[2:0] == fsv_data[4:2]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[1:0]) ^ parity_odd);
+ end
+ 6'h08: begin
+ assert (state == 4'h6);
+ assert (o_uart_tx == fsv_data[2]);
+ assert (lcl_data[1:0] == fsv_data[4:3]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[2:0]) ^ parity_odd);
+ end
+ 6'h10: begin
+ assert (state == 4'h7);
+ assert (o_uart_tx == fsv_data[3]);
+ assert (lcl_data[0] == fsv_data[4]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[3:0]) ^ parity_odd);
+ end
+ 6'h20: begin
+ if (use_parity)
+ assert (state == 4'h8);
+ else assert (state == 4'h9);
+ assert (o_uart_tx == fsv_data[4]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[4:0]) ^ parity_odd);
+ end
+ default: begin
+ assert (0);
+ end
+ endcase
+ initial f_six_seq = 0;
+ always @(posedge i_clk)
+ if ((i_reset) || (i_break)) f_six_seq = 0;
+ else if ((state == TXU_IDLE) && (i_wr) && (!o_busy) && (i_data_bits == 2'b10)) f_six_seq <= 1;
+ else if (zero_baud_counter) f_six_seq <= f_six_seq << 1;
+ always @(*)
+ if (|f_six_seq) begin
+ assert (fsv_setup[29:28] == 2'b10);
+ assert (fsv_setup[29:28] == data_bits);
+ assert (baud_counter < fsv_setup[23:0]);
+ assert (1'b0 == |f_five_seq);
+ assert (1'b0 == |f_seven_seq);
+ assert (1'b0 == |f_eight_seq);
+ assert (r_busy);
+ assert (state > 4'h1);
+ end
+ always @(*)
+ case (f_six_seq)
+ 7'h00: begin
+ assert (1);
+ end
+ 7'h01: begin
+ assert (state == 4'h2);
+ assert (o_uart_tx == 1'b0);
+ assert (lcl_data[5:0] == fsv_data[5:0]);
+ if (!fixd_parity) assert (calc_parity == parity_odd);
+ end
+ 7'h02: begin
+ assert (state == 4'h3);
+ assert (o_uart_tx == fsv_data[0]);
+ assert (lcl_data[4:0] == fsv_data[5:1]);
+ if (!fixd_parity) assert (calc_parity == fsv_data[0] ^ parity_odd);
+ end
+ 7'h04: begin
+ assert (state == 4'h4);
+ assert (o_uart_tx == fsv_data[1]);
+ assert (lcl_data[3:0] == fsv_data[5:2]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[1:0]) ^ parity_odd);
+ end
+ 7'h08: begin
+ assert (state == 4'h5);
+ assert (o_uart_tx == fsv_data[2]);
+ assert (lcl_data[2:0] == fsv_data[5:3]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[2:0]) ^ parity_odd);
+ end
+ 7'h10: begin
+ assert (state == 4'h6);
+ assert (o_uart_tx == fsv_data[3]);
+ assert (lcl_data[1:0] == fsv_data[5:4]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[3:0]) ^ parity_odd);
+ end
+ 7'h20: begin
+ assert (state == 4'h7);
+ assert (lcl_data[0] == fsv_data[5]);
+ assert (o_uart_tx == fsv_data[4]);
+ if (!fixd_parity) assert (calc_parity == ((^fsv_data[4:0]) ^ parity_odd));
+ end
+ 7'h40: begin
+ if (use_parity)
+ assert (state == 4'h8);
+ else assert (state == 4'h9);
+ assert (o_uart_tx == fsv_data[5]);
+ if (!fixd_parity) assert (calc_parity == ((^fsv_data[5:0]) ^ parity_odd));
+ end
+ default: begin
+ if (f_past_valid) assert (0);
+ end
+ endcase
+ initial f_seven_seq = 0;
+ always @(posedge i_clk)
+ if ((i_reset) || (i_break)) f_seven_seq = 0;
+ else if ((state == TXU_IDLE) && (i_wr) && (!o_busy) && (i_data_bits == 2'b01)) f_seven_seq <= 1;
+ else if (zero_baud_counter) f_seven_seq <= f_seven_seq << 1;
+ always @(*)
+ if (|f_seven_seq) begin
+ assert (fsv_setup[29:28] == 2'b01);
+ assert (fsv_setup[29:28] == data_bits);
+ assert (baud_counter < fsv_setup[23:0]);
+ assert (1'b0 == |f_five_seq);
+ assert (1'b0 == |f_six_seq);
+ assert (1'b0 == |f_eight_seq);
+ assert (r_busy);
+ assert (state != 4'h0);
+ end
+ always @(*)
+ case (f_seven_seq)
+ 8'h00: begin
+ assert (1);
+ end
+ 8'h01: begin
+ assert (state == 4'h1);
+ assert (o_uart_tx == 1'b0);
+ assert (lcl_data[6:0] == fsv_data[6:0]);
+ if (!fixd_parity) assert (calc_parity == parity_odd);
+ end
+ 8'h02: begin
+ assert (state == 4'h2);
+ assert (o_uart_tx == fsv_data[0]);
+ assert (lcl_data[5:0] == fsv_data[6:1]);
+ if (!fixd_parity) assert (calc_parity == fsv_data[0] ^ parity_odd);
+ end
+ 8'h04: begin
+ assert (state == 4'h3);
+ assert (o_uart_tx == fsv_data[1]);
+ assert (lcl_data[4:0] == fsv_data[6:2]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[1:0]) ^ parity_odd);
+ end
+ 8'h08: begin
+ assert (state == 4'h4);
+ assert (o_uart_tx == fsv_data[2]);
+ assert (lcl_data[3:0] == fsv_data[6:3]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[2:0]) ^ parity_odd);
+ end
+ 8'h10: begin
+ assert (state == 4'h5);
+ assert (o_uart_tx == fsv_data[3]);
+ assert (lcl_data[2:0] == fsv_data[6:4]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[3:0]) ^ parity_odd);
+ end
+ 8'h20: begin
+ assert (state == 4'h6);
+ assert (o_uart_tx == fsv_data[4]);
+ assert (lcl_data[1:0] == fsv_data[6:5]);
+ if (!fixd_parity) assert (calc_parity == ((^fsv_data[4:0]) ^ parity_odd));
+ end
+ 8'h40: begin
+ assert (state == 4'h7);
+ assert (lcl_data[0] == fsv_data[6]);
+ assert (o_uart_tx == fsv_data[5]);
+ if (!fixd_parity) assert (calc_parity == ((^fsv_data[5:0]) ^ parity_odd));
+ end
+ 8'h80: begin
+ if (use_parity)
+ assert (state == 4'h8);
+ else assert (state == 4'h9);
+ assert (o_uart_tx == fsv_data[6]);
+ if (!fixd_parity) assert (calc_parity == ((^fsv_data[6:0]) ^ parity_odd));
+ end
+ default: begin
+ if (f_past_valid) assert (0);
+ end
+ endcase
+ initial f_eight_seq = 0;
+ always @(posedge i_clk)
+ if ((i_reset) || (i_break)) f_eight_seq = 0;
+ else if ((state == TXU_IDLE) && (i_wr) && (!o_busy) && (i_data_bits == 2'b00)) f_eight_seq <= 1;
+ else if (zero_baud_counter) f_eight_seq <= f_eight_seq << 1;
+ always @(*)
+ if (|f_eight_seq) begin
+ assert (fsv_setup[29:28] == 2'b00);
+ assert (fsv_setup[29:28] == data_bits);
+ assert (baud_counter < {6'h0, fsv_setup[23:0]});
+ assert (1'b0 == |f_five_seq);
+ assert (1'b0 == |f_six_seq);
+ assert (1'b0 == |f_seven_seq);
+ assert (r_busy);
+ end
+ always @(*)
+ case (f_eight_seq)
+ 9'h000: begin
+ assert (1);
+ end
+ 9'h001: begin
+ assert (state == 4'h0);
+ assert (o_uart_tx == 1'b0);
+ assert (lcl_data[7:0] == fsv_data[7:0]);
+ if (!fixd_parity) assert (calc_parity == parity_odd);
+ end
+ 9'h002: begin
+ assert (state == 4'h1);
+ assert (o_uart_tx == fsv_data[0]);
+ assert (lcl_data[6:0] == fsv_data[7:1]);
+ if (!fixd_parity) assert (calc_parity == fsv_data[0] ^ parity_odd);
+ end
+ 9'h004: begin
+ assert (state == 4'h2);
+ assert (o_uart_tx == fsv_data[1]);
+ assert (lcl_data[5:0] == fsv_data[7:2]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[1:0]) ^ parity_odd);
+ end
+ 9'h008: begin
+ assert (state == 4'h3);
+ assert (o_uart_tx == fsv_data[2]);
+ assert (lcl_data[4:0] == fsv_data[7:3]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[2:0]) ^ parity_odd);
+ end
+ 9'h010: begin
+ assert (state == 4'h4);
+ assert (o_uart_tx == fsv_data[3]);
+ assert (lcl_data[3:0] == fsv_data[7:4]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[3:0]) ^ parity_odd);
+ end
+ 9'h020: begin
+ assert (state == 4'h5);
+ assert (o_uart_tx == fsv_data[4]);
+ assert (lcl_data[2:0] == fsv_data[7:5]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[4:0]) ^ parity_odd);
+ end
+ 9'h040: begin
+ assert (state == 4'h6);
+ assert (o_uart_tx == fsv_data[5]);
+ assert (lcl_data[1:0] == fsv_data[7:6]);
+ if (!fixd_parity) assert (calc_parity == (^fsv_data[5:0]) ^ parity_odd);
+ end
+ 9'h080: begin
+ assert (state == 4'h7);
+ assert (o_uart_tx == fsv_data[6]);
+ assert (lcl_data[0] == fsv_data[7]);
+ if (!fixd_parity) assert (calc_parity == ((^fsv_data[6:0]) ^ parity_odd));
+ end
+ 9'h100: begin
+ if (use_parity)
+ assert (state == 4'h8);
+ else assert (state == 4'h9);
+ assert (o_uart_tx == fsv_data[7]);
+ if (!fixd_parity) assert (calc_parity == ((^fsv_data[7:0]) ^ parity_odd));
+ end
+ default: begin
+ if (f_past_valid) assert (0);
+ end
+ endcase
+ always @(posedge i_clk)
+ if (((|f_five_seq[5:0]) || (|f_six_seq[6:0]) || (|f_seven_seq[7:0])
+|| (|f_eight_seq[8:0]))
+&& ($past(
+ zero_baud_counter
+ )))
+ assert (baud_counter == {4'h0, fsv_setup[23:0]} - 1);
+ initial f_stop_seq = 1'b0;
+ always @(posedge i_clk)
+ if ((i_reset) || (i_break)) f_stop_seq <= 0;
+ else if (zero_baud_counter) begin
+ f_stop_seq <= 0;
+ if (f_stop_seq[0]) begin
+ if (dblstop) f_stop_seq[1] <= 1'b1;
+ else f_stop_seq[2] <= 1'b1;
+ end
+ if (f_stop_seq[1]) f_stop_seq[2] <= 1'b1;
+ if (f_eight_seq[8] | f_seven_seq[7] | f_six_seq[6] | f_five_seq[5]) begin
+ if (use_parity) f_stop_seq[0] <= 1'b1;
+ else if (dblstop) f_stop_seq[1] <= 1'b1;
+ else f_stop_seq[2] <= 1'b1;
+ end
+ end
+ always @(*)
+ if (|f_stop_seq) begin
+ assert (1'b0 == |f_five_seq[4:0]);
+ assert (1'b0 == |f_six_seq[5:0]);
+ assert (1'b0 == |f_seven_seq[6:0]);
+ assert (1'b0 == |f_eight_seq[7:0]);
+ assert (r_busy);
+ end
+ always @(*)
+ if (f_stop_seq[0]) begin
+ if (dblstop)
+ assert (state == TXU_STOP);
+ else assert (state == TXU_STOP);
+ assert (use_parity);
+ assert (o_uart_tx == fsv_parity);
+ end
+
+ always @(*)
+ if (f_stop_seq[1]) begin
+ assert (state == TXU_SECOND_STOP);
+ assert (dblstop);
+ assert (o_uart_tx);
+ end
+ always @(*)
+ if (f_stop_seq[2]) begin
+ assert (state == 4'hf);
+ assert (o_uart_tx);
+ assert (baud_counter < fsv_setup[23:0] - 1'b1);
+ end
+
+ always @(*)
+ if (fsv_setup[25]) fsv_parity <= fsv_setup[24];
+ else
+ case (fsv_setup[29:28])
+ 2'b00: fsv_parity = (^fsv_data[7:0]) ^ fsv_setup[24];
+ 2'b01: fsv_parity = (^fsv_data[6:0]) ^ fsv_setup[24];
+ 2'b10: fsv_parity = (^fsv_data[5:0]) ^ fsv_setup[24];
+ 2'b11: fsv_parity = (^fsv_data[4:0]) ^ fsv_setup[24];
+ endcase
+ reg [1:0] f_break_seq;
+ initial f_break_seq = 2'b00;
+ always @(posedge i_clk)
+ if (i_reset) f_break_seq <= 2'b00;
+ else if (i_break) f_break_seq <= 2'b01;
+ else if (!zero_baud_counter) f_break_seq <= {|f_break_seq, 1'b0};
+ else f_break_seq <= 0;
+ always @(posedge i_clk)
+ if (f_break_seq[0])
+ assert (baud_counter == {$past(fsv_setup[23:0]), 4'h0});
+ always @(posedge i_clk)
+ if ((f_past_valid) && ($past(f_break_seq[1])) && (state != TXU_BREAK)) begin
+ assert (state == TXU_IDLE);
+ assert (o_uart_tx == 1'b1);
+ end
+ always @(*)
+ if (|f_break_seq) begin
+ assert (state == TXU_BREAK);
+ assert (r_busy);
+ assert (o_uart_tx == 1'b0);
+ end
+`ifndef TXUART
+ reg [28:0] f_counter;
+ initial f_counter = 0;
+ always @(posedge i_clk)
+ if (!o_busy) f_counter <= 1'b0;
+ else f_counter <= f_counter + 1'b1;
+ always @(*)
+ if (f_five_seq[0] | f_six_seq[0] | f_seven_seq[0] | f_eight_seq[0])
+ assert (f_counter == (fsv_setup[23:0] - baud_counter - 1));
+ else if (f_five_seq[1] | f_six_seq[1] | f_seven_seq[1] | f_eight_seq[1])
+ assert (f_counter == ({4'h0, fsv_setup[23:0], 1'b0} - baud_counter - 1));
+ else if (f_five_seq[2] | f_six_seq[2] | f_seven_seq[2] | f_eight_seq[2])
+ assert(f_counter == ({4'h0, fsv_setup[23:0], 1'b0}
++{5'h0, fsv_setup[23:0]}
+- baud_counter - 1));
+ else if (f_five_seq[3] | f_six_seq[3] | f_seven_seq[3] | f_eight_seq[3])
+ assert (f_counter == ({3'h0, fsv_setup[23:0], 2'b0} - baud_counter - 1));
+ else if (f_five_seq[4] | f_six_seq[4] | f_seven_seq[4] | f_eight_seq[4])
+ assert(f_counter == ({3'h0, fsv_setup[23:0], 2'b0}
++{5'h0, fsv_setup[23:0]}
+- baud_counter - 1));
+ else if (f_five_seq[5] | f_six_seq[5] | f_seven_seq[5] | f_eight_seq[5])
+ assert(f_counter == ({3'h0, fsv_setup[23:0], 2'b0}
++{4'h0, fsv_setup[23:0], 1'b0}
+- baud_counter - 1));
+ else if (f_six_seq[6] | f_seven_seq[6] | f_eight_seq[6])
+ assert(f_counter == ({3'h0, fsv_setup[23:0], 2'b0}
++{5'h0, fsv_setup[23:0]}
++{4'h0, fsv_setup[23:0], 1'b0}
+- baud_counter - 1));
+ else if (f_seven_seq[7] | f_eight_seq[7])
+ assert (f_counter == ({2'h0, fsv_setup[23:0], 3'b0} - baud_counter - 1));
+ else if (f_eight_seq[8])
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{5'h0, fsv_setup[23:0]}
+- baud_counter - 1));
+ else if (f_stop_seq[0] || (!use_parity && f_stop_seq[1])) begin
+ case (data_bits)
+ 2'b00:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{4'h0, fsv_setup[23:0], 1'b0}
+- baud_counter - 1));
+ 2'b01:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{5'h0, fsv_setup[23:0]}
+- baud_counter - 1));
+ 2'b10:
+ assert (f_counter == ({2'h0, fsv_setup[23:0], 3'b0} - baud_counter - 1));
+ 2'b11:
+ assert(f_counter == ({3'h0, fsv_setup[23:0], 2'b0}
++{5'h0, fsv_setup[23:0]}
++{4'h0, fsv_setup[23:0], 1'b0}
+- baud_counter - 1));
+ endcase
+ end else if (!use_parity && !dblstop && f_stop_seq[2]) begin
+ case (data_bits)
+ 2'b00:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{4'h0, fsv_setup[23:0], 1'b0}
+- baud_counter - 2));
+ 2'b01:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{5'h0, fsv_setup[23:0]}
+- baud_counter - 2));
+ 2'b10:
+ assert (f_counter == ({2'h0, fsv_setup[23:0], 3'b0} - baud_counter - 2));
+ 2'b11:
+ assert(f_counter == ({3'h0, fsv_setup[23:0], 2'b0}
++{5'h0, fsv_setup[23:0]}
++{4'h0, fsv_setup[23:0], 1'b0}
+- baud_counter - 2));
+ endcase
+ end else if (f_stop_seq[1]) begin
+ assert (dblstop && use_parity);
+ case (data_bits)
+ 2'b00:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{5'h0, fsv_setup[23:0]}
++{4'h0, fsv_setup[23:0], 1'b0}
+- baud_counter - 1));
+ 2'b01:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{4'h0, fsv_setup[23:0], 1'b0}
+- baud_counter - 1));
+ 2'b10:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{5'h0, fsv_setup[23:0]}
+- baud_counter - 1));
+ 2'b11:
+ assert (f_counter == ({2'h0, fsv_setup[23:0], 3'b0} - baud_counter - 1));
+ endcase
+ end else if ((dblstop ^ use_parity) && f_stop_seq[2]) begin
+ case (data_bits)
+ 2'b00:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{5'h0, fsv_setup[23:0]}
++{4'h0, fsv_setup[23:0], 1'b0}
+- baud_counter - 2));
+ 2'b01:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{4'h0, fsv_setup[23:0], 1'b0}
+- baud_counter - 2));
+ 2'b10:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{5'h0, fsv_setup[23:0]}
+- baud_counter - 2));
+ 2'b11:
+ assert (f_counter == ({2'h0, fsv_setup[23:0], 3'b0} - baud_counter - 2));
+ endcase
+ end else if (f_stop_seq[2]) begin
+ assert (dblstop);
+ assert (use_parity);
+ case (data_bits)
+ 2'b00:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{3'h0, fsv_setup[23:0], 2'b00}
+- baud_counter - 2));
+ 2'b01:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{5'h0, fsv_setup[23:0]}
++{4'h0, fsv_setup[23:0], 1'b0}
+- baud_counter - 2));
+ 2'b10:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{4'h0, fsv_setup[23:0], 1'b0}
+- baud_counter - 2));
+ 2'b11:
+ assert(f_counter == ({2'h0, fsv_setup[23:0], 3'b0}
++{5'h0, fsv_setup[23:0]}
+- baud_counter - 2));
+ endcase
+ end
+`endif
+ always @(*) assert ((state < 4'hb) || (state >= 4'he));
+ always @(*) assume (i_setup[23:0] > 2);
+ always @(*) assert (fsv_setup[23:0] > 2);
+`endif
+endmodule
+"
+"/*
+Copyright (C) 2015-2021, Gisselquist Technology, LLC
+
+This program is free software (firmware): you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. (It's in the $(ROOT)/doc directory. Run make with no
+target there if the PDF file isn't present.) If not, see
+ for a copy.
+
+License: GPL, v3, as defined and found on www.gnu.org,
+http://www.gnu.org/licenses/gpl.html
+*/
+`default_nettype none
+module ufifo #(
+ parameter BW = 8,
+ parameter [3:0] LGFLEN = 4,
+ parameter [0:0] RXFIFO = 1'b1,
+ parameter FLEN = (1 << LGFLEN)
+) (
+ input wire i_clk,
+ i_reset,
+ input wire i_wr,
+ input wire [(BW-1):0] i_data,
+ output wire o_empty_n,
+ input wire i_rd,
+ output wire [(BW-1):0] o_data,
+ output wire [15:0] o_status,
+ output wire o_err
+);
+ reg [(BW-1):0] fifo[0:(FLEN-1)];
+ reg [(BW-1):0] r_data, last_write;
+ reg [(LGFLEN-1):0] wr_addr, rd_addr, r_next;
+ reg will_overflow, will_underflow;
+ reg osrc;
+ wire [(LGFLEN-1):0] w_waddr_plus_one, w_waddr_plus_two;
+ wire w_write, w_read;
+ reg [(LGFLEN-1):0] r_fill;
+ wire [3:0] lglen;
+ wire w_half_full;
+ reg [9:0] w_fill;
+ assign w_write = (i_wr && (!will_overflow || i_rd));
+ assign w_read = (i_rd && o_empty_n);
+ assign w_waddr_plus_two = wr_addr + 2;
+ assign w_waddr_plus_one = wr_addr + 1;
+ initial will_overflow = 1'b0;
+ always @(posedge i_clk)
+ if (i_reset) will_overflow <= 1'b0;
+ else if (i_rd) will_overflow <= (will_overflow) && (i_wr);
+ else if (w_write) will_overflow <= (will_overflow) || (w_waddr_plus_two == rd_addr);
+ else if (w_waddr_plus_one == rd_addr) will_overflow <= 1'b1;
+ initial wr_addr = 0;
+ always @(posedge i_clk)
+ if (i_reset) wr_addr <= {(LGFLEN) {1'b0}};
+ else if (w_write) wr_addr <= w_waddr_plus_one;
+ always @(posedge i_clk) if (w_write) fifo[wr_addr] <= i_data;
+ initial will_underflow = 1'b1;
+ always @(posedge i_clk)
+ if (i_reset) will_underflow <= 1'b1;
+ else if (i_wr) will_underflow <= 1'b0;
+ else if (w_read) will_underflow <= (will_underflow) || (r_next == wr_addr);
+ initial rd_addr = 0;
+ initial r_next = 1;
+ always @(posedge i_clk)
+ if (i_reset) begin
+ rd_addr <= 0;
+ r_next <= 1;
+ end else if (w_read) begin
+ rd_addr <= rd_addr + 1;
+ r_next <= rd_addr + 2;
+ end
+ always @(posedge i_clk) if (w_read) r_data <= fifo[r_next[LGFLEN-1:0]];
+ always @(posedge i_clk)
+ if (i_wr && (!o_empty_n || (w_read && r_next == wr_addr)))
+ last_write <= i_data;
+ initial osrc = 1'b0;
+ always @(posedge i_clk)
+ if (i_reset) osrc <= 1'b0;
+ else if (i_wr && (!o_empty_n || (w_read && r_next == wr_addr))) osrc <= 1'b1;
+ else if (i_rd) osrc <= 1'b0;
+ assign o_data = (osrc) ? last_write : r_data;
+ generate
+ if (RXFIFO) begin : RXFIFO_FILL
+ initial r_fill = 0;
+ always @(posedge i_clk)
+ if (i_reset) r_fill <= 0;
+ else
+ case ({
+ w_write, w_read
+ })
+ 2'b01: r_fill <= r_fill - 1'b1;
+ 2'b10: r_fill <= r_fill + 1'b1;
+ default: begin
+ end
+ endcase
+ end else begin : TXFIFO_FILL
+ initial r_fill = -1;
+ always @(posedge i_clk)
+ if (i_reset) r_fill <= -1;
+ else
+ case ({
+ w_write, w_read
+ })
+ 2'b01: r_fill <= r_fill + 1'b1;
+ 2'b10: r_fill <= r_fill - 1'b1;
+ default: begin
+ end
+ endcase
+ end
+ endgenerate
+ assign o_err = (i_wr && !w_write);
+ assign lglen = LGFLEN;
+ always @(*) begin
+ w_fill = 0;
+ w_fill[(LGFLEN-1):0] = r_fill;
+ end
+ assign w_half_full = r_fill[(LGFLEN-1)];
+ assign o_status = {lglen, w_fill, w_half_full, (RXFIFO != 0) ? !will_underflow : !will_overflow};
+ assign o_empty_n = !will_underflow;
+`ifdef FORMAL
+ reg f_past_valid;
+ initial f_past_valid = 0;
+ always @(posedge i_clk) f_past_valid <= 1;
+ reg [LGFLEN-1:0] f_fill;
+ wire [LGFLEN-1:0] f_raddr_plus_one;
+ always @(*) f_fill = wr_addr - rd_addr;
+ always @(*) assert (will_underflow == (f_fill == 0));
+ always @(*) assert (will_overflow == (&f_fill));
+ assign f_raddr_plus_one = rd_addr + 1;
+ always @(*) assert (f_raddr_plus_one == r_next);
+ always @(*)
+ if (will_underflow) begin
+ assert (!w_read);
+ assert (!osrc);
+ end
+ always @(posedge i_clk)
+ if (RXFIFO)
+ assert (r_fill == f_fill);
+ else assert (r_fill == (~f_fill));
+`ifdef UFIFO
+ (* anyconst *) reg [LGFLEN-1:0] f_const_addr;
+ (* anyconst *) reg [BW-1:0] f_const_data, f_const_second;
+ reg [LGFLEN-1:0] f_next_addr;
+ reg [1:0] f_state;
+ reg f_first_in_fifo, f_second_in_fifo;
+ reg [LGFLEN-1:0] f_distance_to_first, f_distance_to_second;
+ always @(*) begin
+ f_next_addr = f_const_addr + 1;
+ f_distance_to_first = f_const_addr - rd_addr;
+ f_distance_to_second = f_next_addr - rd_addr;
+ f_first_in_fifo = (f_distance_to_first < f_fill)
+&& !will_underflow
+&& (fifo[f_const_addr] == f_const_data);
+ f_second_in_fifo = (f_distance_to_second < f_fill)
+&& !will_underflow
+&& (fifo[f_next_addr] == f_const_second);
+ end
+ initial f_state = 2'b00;
+ always @(posedge i_clk)
+ if (i_reset) f_state <= 2'b00;
+ else
+ case (f_state)
+ 2'b00:
+ if (w_write && (wr_addr == f_const_addr) && (i_data == f_const_data)) f_state <= 2'b01;
+ 2'b01:
+ if (w_read && (rd_addr == f_const_addr)) f_state <= 2'b00;
+ else if (w_write && (wr_addr == f_next_addr))
+ f_state <= (i_data == f_const_second) ? 2'b10 : 2'b00;
+ 2'b10: if (w_read && (rd_addr == f_const_addr)) f_state <= 2'b11;
+ 2'b11: if (w_read) f_state <= 2'b00;
+ endcase
+ always @(*)
+ case (f_state)
+ 2'b00: begin
+ end
+ 2'b01: begin
+ assert (!will_underflow);
+ assert (f_first_in_fifo);
+ assert (!f_second_in_fifo);
+ assert (wr_addr == f_next_addr);
+ assert (fifo[f_const_addr] == f_const_data);
+ if (rd_addr == f_const_addr) assert (o_data == f_const_data);
+ end
+ 2'b10: begin
+ assert (f_first_in_fifo);
+ assert (f_second_in_fifo);
+ end
+ 2'b11: begin
+ assert (f_second_in_fifo);
+ assert (rd_addr == f_next_addr);
+ assert (o_data == f_const_second);
+ end
+ endcase
+`endif
+ reg cvr_filled;
+ always @(*) cover (o_empty_n);
+`ifdef UFIFO
+ always @(*) cover (o_err);
+ initial cvr_filled = 0;
+ always @(posedge i_clk)
+ if (i_reset) cvr_filled <= 0;
+ else if (&f_fill[LGFLEN-1:0]) cvr_filled <= 1;
+ always @(*) cover (cvr_filled && !o_empty_n);
+`endif
+`endif
+endmodule
+"
+"/*
+Copyright (C) 2015-2021, Gisselquist Technology, LLC
+
+This program is free software (firmware): you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. (It's in the $(ROOT)/doc directory. Run make with no
+target there if the PDF file isn't present.) If not, see
+ for a copy.
+
+License: GPL, v3, as defined and found on www.gnu.org,
+http://www.gnu.org/licenses/gpl.html
+*/
+`default_nettype none
+module rxuartlite #(
+ parameter TIMER_BITS = 10,
+`ifdef FORMAL
+ parameter [(TIMER_BITS-1):0] CLOCKS_PER_BAUD = 16,
+`else
+ parameter [(TIMER_BITS-1):0] CLOCKS_PER_BAUD = 868,
+`endif
+ parameter TB = TIMER_BITS,
+ parameter [ 3:0] RXUL_BIT_ZERO = 4'h0,
+ parameter [ 3:0] RXUL_BIT_ONE = 4'h1,
+ parameter [ 3:0] RXUL_BIT_TWO = 4'h2,
+ parameter [ 3:0] RXUL_BIT_THREE = 4'h3,
+ parameter [ 3:0] RXUL_BIT_FOUR = 4'h4,
+ parameter [ 3:0] RXUL_BIT_FIVE = 4'h5,
+ parameter [ 3:0] RXUL_BIT_SIX = 4'h6,
+ parameter [ 3:0] RXUL_BIT_SEVEN = 4'h7,
+ parameter [ 3:0] RXUL_STOP = 4'h8,
+ parameter [ 3:0] RXUL_WAIT = 4'h9,
+ parameter [ 3:0] RXUL_IDLE = 4'hf
+) (
+ input wire i_clk,
+ input wire i_uart_rx,
+ output reg o_wr,
+ output reg [7:0] o_data
+);
+ wire [(TB-1):0] half_baud;
+ reg [3:0] state;
+ assign half_baud = {1'b0, CLOCKS_PER_BAUD[(TB-1):1]};
+ reg [(TB-1):0] baud_counter;
+ reg zero_baud_counter;
+ reg q_uart, qq_uart, ck_uart;
+ reg [(TB-1):0] chg_counter;
+ reg half_baud_time;
+ reg [7:0] data_reg;
+ initial q_uart = 1'b1;
+ initial qq_uart = 1'b1;
+ initial ck_uart = 1'b1;
+ always @(posedge i_clk) {ck_uart, qq_uart, q_uart} <= {qq_uart, q_uart, i_uart_rx};
+ initial chg_counter = {(TB) {1'b1}};
+ always @(posedge i_clk)
+ if (qq_uart != ck_uart) chg_counter <= 0;
+ else if (chg_counter != {(TB) {1'b1}}) chg_counter <= chg_counter + 1;
+ initial half_baud_time = 0;
+ always @(posedge i_clk) half_baud_time <= (!ck_uart) && (chg_counter >= half_baud - 1'b1 - 1'b1);
+ initial state = RXUL_IDLE;
+ always @(posedge i_clk)
+ if (state == RXUL_IDLE) begin
+ state <= RXUL_IDLE;
+ if ((!ck_uart) && (half_baud_time)) state <= RXUL_BIT_ZERO;
+ end else if ((state >= RXUL_WAIT) && (ck_uart)) state <= RXUL_IDLE;
+ else if (zero_baud_counter) begin
+ if (state <= RXUL_STOP) state <= state + 1;
+ end
+ always @(posedge i_clk)
+ if ((zero_baud_counter) && (state != RXUL_STOP))
+ data_reg <= {qq_uart, data_reg[7:1]};
+ initial o_wr = 1'b0;
+ initial o_data = 8'h00;
+ always @(posedge i_clk)
+ if ((zero_baud_counter) && (state == RXUL_STOP) && (ck_uart)) begin
+ o_wr <= 1'b1;
+ o_data <= data_reg;
+ end else o_wr <= 1'b0;
+ initial baud_counter = 0;
+ always @(posedge i_clk)
+ if (((state == RXUL_IDLE)) && (!ck_uart) && (half_baud_time))
+ baud_counter <= CLOCKS_PER_BAUD - 1'b1;
+ else if (state == RXUL_WAIT) baud_counter <= 0;
+ else if ((zero_baud_counter) && (state < RXUL_STOP)) baud_counter <= CLOCKS_PER_BAUD - 1'b1;
+ else if (!zero_baud_counter) baud_counter <= baud_counter - 1'b1;
+ initial zero_baud_counter = 1'b1;
+ always @(posedge i_clk)
+ if ((state == RXUL_IDLE) && (!ck_uart) && (half_baud_time)) zero_baud_counter <= 1'b0;
+ else if (state == RXUL_WAIT) zero_baud_counter <= 1'b1;
+ else if ((zero_baud_counter) && (state < RXUL_STOP)) zero_baud_counter <= 1'b0;
+ else if (baud_counter == 1) zero_baud_counter <= 1'b1;
+`ifdef FORMAL
+ `define FORMAL_VERILATOR
+`else
+`ifdef VERILATOR
+ `define FORMAL_VERILATOR
+`endif
+`endif
+`ifdef FORMAL
+ `define ASSUME assume
+ `define ASSERT assert
+`ifdef VERIFIC
+ (* gclk *) wire gbl_clk;
+ global clocking @(posedge gbl_clk);
+ endclocking
+`endif
+ localparam F_CKRES = 10;
+ (* anyseq *) wire f_tx_start;
+ (* anyconst *) wire [(F_CKRES-1):0] f_tx_step;
+ reg f_tx_zclk;
+ reg [(TB-1):0] f_tx_timer;
+ wire [7:0] f_rx_newdata;
+ reg [(TB-1):0] f_tx_baud;
+ wire f_tx_zbaud;
+ wire [(TB-1):0] f_max_baud_difference;
+ reg [(TB-1):0] f_baud_difference;
+ reg [(TB+3):0] f_tx_count, f_rx_count;
+ (* anyseq *) wire [7:0] f_tx_data;
+ wire f_txclk;
+ reg [1:0] f_rx_clock;
+ reg [(F_CKRES-1):0] f_tx_clock;
+ reg f_past_valid, f_past_valid_tx;
+ reg [9:0] f_tx_reg;
+ reg f_tx_busy;
+ initial f_past_valid = 1'b0;
+ always @(posedge i_clk) f_past_valid <= 1'b1;
+ initial f_rx_clock = 3'h0;
+ always @($global_clock) f_rx_clock <= f_rx_clock + 1'b1;
+ always @(*) assume (i_clk == f_rx_clock[1]);
+ localparam [(F_CKRES-1):0] F_MIDSTEP = {2'b01, {(F_CKRES - 2) {1'b0}}};
+ localparam [(F_CKRES-1):0] F_HALFSTEP = F_MIDSTEP / 32;
+ localparam [(F_CKRES-1):0] F_MINSTEP = F_MIDSTEP - F_HALFSTEP + 1;
+ localparam [(F_CKRES-1):0] F_MAXSTEP = F_MIDSTEP + F_HALFSTEP - 1;
+ initial assert (F_MINSTEP <= F_MIDSTEP);
+ initial assert (F_MIDSTEP <= F_MAXSTEP);
+ always @(*)
+ assume ((f_tx_step == F_MINSTEP) || (f_tx_step == F_MIDSTEP) || (f_tx_step == F_MAXSTEP));
+ always @($global_clock) f_tx_clock <= f_tx_clock + f_tx_step;
+ assign f_txclk = f_tx_clock[F_CKRES-1];
+ initial f_past_valid_tx = 1'b0;
+ always @(posedge f_txclk) f_past_valid_tx <= 1'b1;
+ initial assume (i_uart_rx);
+ always @(*) if (f_tx_busy) assume (!f_tx_start);
+ initial f_tx_baud = 0;
+ always @(posedge f_txclk)
+ if ((f_tx_zbaud) && ((f_tx_busy) || (f_tx_start))) f_tx_baud <= CLOCKS_PER_BAUD - 1'b1;
+ else if (!f_tx_zbaud) f_tx_baud <= f_tx_baud - 1'b1;
+ always @(*) `ASSERT(f_tx_baud < CLOCKS_PER_BAUD);
+ always @(*) if (!f_tx_busy) `ASSERT(f_tx_baud == 0);
+ assign f_tx_zbaud = (f_tx_baud == 0);
+ initial assume (f_tx_data == 0);
+ always @(posedge f_txclk)
+ if ((!f_tx_zbaud) || (f_tx_busy) || (!f_tx_start))
+ assume (f_tx_data == $past(f_tx_data));
+ always @($global_clock)
+ if ((f_past_valid) && (!$rose(f_txclk)))
+ assume ($stable(f_tx_data));
+ else if (f_tx_busy) assume ($stable(f_tx_data));
+ always @($global_clock)
+ if ((!f_past_valid) || (!$rose(f_txclk))) begin
+ assume ($stable(f_tx_start));
+ assume ($stable(f_tx_data));
+ end
+ initial f_tx_busy = 1'b0;
+ initial f_tx_reg = 0;
+ always @(posedge f_txclk)
+ if (!f_tx_zbaud) begin
+ `ASSERT(f_tx_busy);
+ end else begin
+ f_tx_reg <= {1'b0, f_tx_reg[9:1]};
+ if (f_tx_start) f_tx_reg <= {1'b1, f_tx_data, 1'b0};
+ end
+ always @(*)
+ if (!f_tx_zbaud) f_tx_busy <= 1'b1;
+ else if (|f_tx_reg) f_tx_busy <= 1'b1;
+ else f_tx_busy <= 1'b0;
+ always @(posedge f_txclk)
+ if (f_tx_reg[9]) `ASSERT(f_tx_reg[8:0] == {f_tx_data, 1'b0});
+ else if (f_tx_reg[8]) `ASSERT(f_tx_reg[7:0] == f_tx_data[7:0]);
+ else if (f_tx_reg[7]) `ASSERT(f_tx_reg[6:0] == f_tx_data[7:1]);
+ else if (f_tx_reg[6]) `ASSERT(f_tx_reg[5:0] == f_tx_data[7:2]);
+ else if (f_tx_reg[5]) `ASSERT(f_tx_reg[4:0] == f_tx_data[7:3]);
+ else if (f_tx_reg[4]) `ASSERT(f_tx_reg[3:0] == f_tx_data[7:4]);
+ else if (f_tx_reg[3]) `ASSERT(f_tx_reg[2:0] == f_tx_data[7:5]);
+ else if (f_tx_reg[2]) `ASSERT(f_tx_reg[1:0] == f_tx_data[7:6]);
+ else if (f_tx_reg[1]) `ASSERT(f_tx_reg[0] == f_tx_data[7]);
+ initial f_tx_count = 0;
+ always @(posedge f_txclk)
+ if (!f_tx_busy) f_tx_count <= 0;
+ else f_tx_count <= f_tx_count + 1'b1;
+ always @(*)
+ if (f_tx_reg == 10'h0)
+ assume (i_uart_rx);
+ else assume (i_uart_rx == f_tx_reg[0]);
+ always @(posedge f_txclk)
+ if (!f_tx_busy) begin
+ if ((!f_past_valid_tx) || (!$past(f_tx_busy))) `ASSERT(f_tx_count == 0);
+ end else if (f_tx_reg[9]) `ASSERT(f_tx_count == CLOCKS_PER_BAUD - 1 - f_tx_baud);
+ else if (f_tx_reg[8]) `ASSERT(f_tx_count == 2 * CLOCKS_PER_BAUD - 1 - f_tx_baud);
+ else if (f_tx_reg[7]) `ASSERT(f_tx_count == 3 * CLOCKS_PER_BAUD - 1 - f_tx_baud);
+ else if (f_tx_reg[6]) `ASSERT(f_tx_count == 4 * CLOCKS_PER_BAUD - 1 - f_tx_baud);
+ else if (f_tx_reg[5]) `ASSERT(f_tx_count == 5 * CLOCKS_PER_BAUD - 1 - f_tx_baud);
+ else if (f_tx_reg[4]) `ASSERT(f_tx_count == 6 * CLOCKS_PER_BAUD - 1 - f_tx_baud);
+ else if (f_tx_reg[3]) `ASSERT(f_tx_count == 7 * CLOCKS_PER_BAUD - 1 - f_tx_baud);
+ else if (f_tx_reg[2]) `ASSERT(f_tx_count == 8 * CLOCKS_PER_BAUD - 1 - f_tx_baud);
+ else if (f_tx_reg[1]) `ASSERT(f_tx_count == 9 * CLOCKS_PER_BAUD - 1 - f_tx_baud);
+ else if (f_tx_reg[0]) `ASSERT(f_tx_count == 10 * CLOCKS_PER_BAUD - 1 - f_tx_baud);
+ else `ASSERT(f_tx_count == 11 * CLOCKS_PER_BAUD - 1 - f_tx_baud);
+ initial f_rx_count = 0;
+ always @(posedge i_clk)
+ if (state == RXUL_IDLE) f_rx_count = (!ck_uart) ? (chg_counter + 2) : 0;
+ else f_rx_count <= f_rx_count + 1'b1;
+ always @(posedge i_clk)
+ if (state == 0) `ASSERT(f_rx_count == half_baud + (CLOCKS_PER_BAUD - baud_counter));
+ else if (state == 1) `ASSERT(f_rx_count == half_baud + 2 * CLOCKS_PER_BAUD - baud_counter);
+ else if (state == 2) `ASSERT(f_rx_count == half_baud + 3 * CLOCKS_PER_BAUD - baud_counter);
+ else if (state == 3) `ASSERT(f_rx_count == half_baud + 4 * CLOCKS_PER_BAUD - baud_counter);
+ else if (state == 4) `ASSERT(f_rx_count == half_baud + 5 * CLOCKS_PER_BAUD - baud_counter);
+ else if (state == 5) `ASSERT(f_rx_count == half_baud + 6 * CLOCKS_PER_BAUD - baud_counter);
+ else if (state == 6) `ASSERT(f_rx_count == half_baud + 7 * CLOCKS_PER_BAUD - baud_counter);
+ else if (state == 7) `ASSERT(f_rx_count == half_baud + 8 * CLOCKS_PER_BAUD - baud_counter);
+ else if (state == 8)
+ `ASSERT(
+ (f_rx_count == half_baud + 9 * CLOCKS_PER_BAUD
+- baud_counter)
+||(f_rx_count == half_baud + 10 * CLOCKS_PER_BAUD
+- baud_counter));
+ always @(*)
+ `ASSERT(
+ ((!zero_baud_counter)
+&&(state == RXUL_IDLE)
+&&(baud_counter == 0))
+||((zero_baud_counter)&&(baud_counter == 0))
+||((!zero_baud_counter)&&(baud_counter != 0)));
+ always @(posedge i_clk)
+ if (!f_past_valid)
+ `ASSERT((state == RXUL_IDLE) && (baud_counter == 0) && (zero_baud_counter));
+ always @(*) begin
+ `ASSERT({ck_uart, qq_uart, q_uart, i_uart_rx} != 4'h2);
+ `ASSERT({ck_uart, qq_uart, q_uart, i_uart_rx} != 4'h4);
+ `ASSERT({ck_uart, qq_uart, q_uart, i_uart_rx} != 4'h5);
+ `ASSERT({ck_uart, qq_uart, q_uart, i_uart_rx} != 4'h6);
+ `ASSERT({ck_uart, qq_uart, q_uart, i_uart_rx} != 4'h9);
+ `ASSERT({ck_uart, qq_uart, q_uart, i_uart_rx} != 4'ha);
+ `ASSERT({ck_uart, qq_uart, q_uart, i_uart_rx} != 4'hb);
+ `ASSERT({ck_uart, qq_uart, q_uart, i_uart_rx} != 4'hd);
+ end
+ always @(posedge i_clk)
+ if ((f_past_valid) && ($past(state) >= RXUL_WAIT) && ($past(ck_uart)))
+ `ASSERT(state == RXUL_IDLE);
+ always @(posedge i_clk)
+ if ((f_past_valid) && ($past(
+ state
+ ) >= RXUL_WAIT) && (($past(
+ state
+ ) != RXUL_IDLE) || (state == RXUL_IDLE)))
+ `ASSERT(zero_baud_counter);
+ always @(posedge i_clk)
+ if ((f_past_valid) && ($past(state) == RXUL_IDLE) && (state == RXUL_IDLE)) begin
+ `ASSERT(($past(ck_uart)) || (chg_counter <= {1'b0, CLOCKS_PER_BAUD[(TB-1):1]}));
+ end
+ always @(posedge f_txclk)
+ if (!f_past_valid_tx)
+ `ASSERT((state == RXUL_IDLE) && (baud_counter == 0) && (zero_baud_counter) && (!f_tx_busy));
+ wire [(TB+3):0] f_tx_count_two_clocks_ago;
+ assign f_tx_count_two_clocks_ago = f_tx_count - 2;
+ always @(*)
+ if (f_tx_count >= f_rx_count + 2) f_baud_difference = f_tx_count_two_clocks_ago - f_rx_count;
+ else f_baud_difference = f_rx_count - f_tx_count_two_clocks_ago;
+ localparam F_SYNC_DLY = 8;
+ reg [(TB+4+F_CKRES-1):0] f_sub_baud_difference;
+ reg [F_CKRES-1:0] ck_tx_clock;
+ reg [((F_SYNC_DLY-1)*F_CKRES)-1:0] q_tx_clock;
+ reg [TB+3:0] ck_tx_count;
+ reg [(F_SYNC_DLY-1)*(TB+4)-1:0] q_tx_count;
+ initial q_tx_count = 0;
+ initial ck_tx_count = 0;
+ initial q_tx_clock = 0;
+ initial ck_tx_clock = 0;
+ always @($global_clock) {ck_tx_clock, q_tx_clock} <= {q_tx_clock, f_tx_clock};
+ always @($global_clock) {ck_tx_count, q_tx_count} <= {q_tx_count, f_tx_count};
+ reg [TB+4+F_CKRES-1:0] f_ck_tx_time, f_rx_time;
+ always @(*) f_ck_tx_time = {ck_tx_count, !ck_tx_clock[F_CKRES-1], ck_tx_clock[F_CKRES-2:0]};
+ always @(*) f_rx_time = {f_rx_count, !f_rx_clock[1], f_rx_clock[0], {(F_CKRES - 2) {1'b0}}};
+ reg [TB+4+F_CKRES-1:0] f_signed_difference;
+ always @(*) f_signed_difference = f_ck_tx_time - f_rx_time;
+ always @(*)
+ if (f_signed_difference[TB+4+F_CKRES-1]) f_sub_baud_difference = -f_signed_difference;
+ else f_sub_baud_difference = f_signed_difference;
+ always @($global_clock) if (state == RXUL_WAIT) `ASSERT((!f_tx_busy) || (f_tx_reg[9:1] == 0));
+ always @($global_clock)
+ if (state == RXUL_IDLE) begin
+ `ASSERT((!f_tx_busy) || (f_tx_reg[9]) || (f_tx_reg[9:1] == 0));
+ if (!ck_uart);
+ else `ASSERT((f_tx_reg[9:1] == 0) || (f_tx_count < (3 + CLOCKS_PER_BAUD / 2)));
+ end else if (state == 0)
+ `ASSERT(f_sub_baud_difference <= 2 * ((CLOCKS_PER_BAUD << F_CKRES) / 20));
+ else if (state == 1) `ASSERT(f_sub_baud_difference <= 3 * ((CLOCKS_PER_BAUD << F_CKRES) / 20));
+ else if (state == 2) `ASSERT(f_sub_baud_difference <= 4 * ((CLOCKS_PER_BAUD << F_CKRES) / 20));
+ else if (state == 3) `ASSERT(f_sub_baud_difference <= 5 * ((CLOCKS_PER_BAUD << F_CKRES) / 20));
+ else if (state == 4) `ASSERT(f_sub_baud_difference <= 6 * ((CLOCKS_PER_BAUD << F_CKRES) / 20));
+ else if (state == 5) `ASSERT(f_sub_baud_difference <= 7 * ((CLOCKS_PER_BAUD << F_CKRES) / 20));
+ else if (state == 6) `ASSERT(f_sub_baud_difference <= 8 * ((CLOCKS_PER_BAUD << F_CKRES) / 20));
+ else if (state == 7) `ASSERT(f_sub_baud_difference <= 9 * ((CLOCKS_PER_BAUD << F_CKRES) / 20));
+ else if (state == 8) `ASSERT(f_sub_baud_difference <= 10 * ((CLOCKS_PER_BAUD << F_CKRES) / 20));
+ always @(posedge i_clk) if (o_wr) `ASSERT(o_data == $past(f_tx_data, 4));
+ always @(posedge i_clk) begin
+ if (state == 4'h0) `ASSERT(!data_reg[7]);
+ if (state == 4'h1) `ASSERT((data_reg[7] == $past(f_tx_data[0])) && (!data_reg[6]));
+ if (state == 4'h2) `ASSERT(data_reg[7:6] == $past(f_tx_data[1:0]));
+ if (state == 4'h3) `ASSERT(data_reg[7:5] == $past(f_tx_data[2:0]));
+ if (state == 4'h4) `ASSERT(data_reg[7:4] == $past(f_tx_data[3:0]));
+ if (state == 4'h5) `ASSERT(data_reg[7:3] == $past(f_tx_data[4:0]));
+ if (state == 4'h6) `ASSERT(data_reg[7:2] == $past(f_tx_data[5:0]));
+ if (state == 4'h7) `ASSERT(data_reg[7:1] == $past(f_tx_data[6:0]));
+ if (state == 4'h8) `ASSERT(data_reg[7:0] == $past(f_tx_data[7:0]));
+ end
+ always @(posedge i_clk) cover (o_wr);
+ always @(posedge i_clk) begin
+ cover (!ck_uart);
+ cover ((f_past_valid) && ($rose(ck_uart)));
+ cover ((zero_baud_counter) && (state == RXUL_BIT_ZERO));
+ cover ((zero_baud_counter) && (state == RXUL_BIT_ONE));
+ cover ((zero_baud_counter) && (state == RXUL_BIT_TWO));
+ cover ((zero_baud_counter) && (state == RXUL_BIT_THREE));
+ cover ((zero_baud_counter) && (state == RXUL_BIT_FOUR));
+ cover ((zero_baud_counter) && (state == RXUL_BIT_FIVE));
+ cover ((zero_baud_counter) && (state == RXUL_BIT_SIX));
+ cover ((zero_baud_counter) && (state == RXUL_BIT_SEVEN));
+ cover ((zero_baud_counter) && (state == RXUL_STOP));
+ cover ((zero_baud_counter) && (state == RXUL_WAIT));
+ end
+`endif
+`ifdef FORMAL_VERILATOR
+ always @(*) assert ((state == 4'hf) || (state <= RXUL_WAIT));
+ always @(*) assert (zero_baud_counter == (baud_counter == 0) ? 1'b1 : 1'b0);
+ always @(*) assert (baud_counter <= CLOCKS_PER_BAUD - 1'b1);
+`endif
+endmodule
+"
+"/*
+Copyright (C) 2020-2021, Gisselquist Technology, LLC
+
+This program is free software (firmware): you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. (It's in the $(ROOT)/doc directory. Run make with no
+target there if the PDF file isn't present.) If not, see
+ for a copy.
+
+License: GPL, v3, as defined and found on www.gnu.org,
+http://www.gnu.org/licenses/gpl.html
+*/
+`default_nettype none
+module axiluart #(
+ parameter [30:0] INITIAL_SETUP = 31'd25,
+ parameter [3:0] LGFLEN = 4,
+ parameter [0:0] HARDWARE_FLOW_CONTROL_PRESENT = 1'b1,
+ parameter [3:0] LCLLGFLEN = (LGFLEN > 4'ha) ? 4'ha : ((LGFLEN < 4'h2) ? 4'h2 : LGFLEN),
+ parameter C_AXI_ADDR_WIDTH = 4,
+ parameter C_AXI_DATA_WIDTH = 32,
+ parameter [0:0] OPT_SKIDBUFFER = 1'b0,
+ parameter [0:0] OPT_LOWPOWER = 0,
+ parameter ADDRLSB = $clog2(C_AXI_DATA_WIDTH) - 3
+) (
+ input wire S_AXI_ACLK,
+ input wire S_AXI_ARESETN,
+ input wire S_AXI_AWVALID,
+ output wire S_AXI_AWREADY,
+ input wire [C_AXI_ADDR_WIDTH-1:0] S_AXI_AWADDR,
+ input wire [2:0] S_AXI_AWPROT,
+ input wire S_AXI_WVALID,
+ output wire S_AXI_WREADY,
+ input wire [C_AXI_DATA_WIDTH-1:0] S_AXI_WDATA,
+ input wire [C_AXI_DATA_WIDTH/8-1:0] S_AXI_WSTRB,
+ output wire S_AXI_BVALID,
+ input wire S_AXI_BREADY,
+ output wire [1:0] S_AXI_BRESP,
+ input wire S_AXI_ARVALID,
+ output wire S_AXI_ARREADY,
+ input wire [C_AXI_ADDR_WIDTH-1:0] S_AXI_ARADDR,
+ input wire [2:0] S_AXI_ARPROT,
+ output wire S_AXI_RVALID,
+ input wire S_AXI_RREADY,
+ output wire [C_AXI_DATA_WIDTH-1:0] S_AXI_RDATA,
+ output wire [1:0] S_AXI_RRESP,
+ input wire i_uart_rx,
+ output wire o_uart_tx,
+ input wire i_cts_n,
+ output reg o_rts_n,
+ output wire o_uart_rx_int,
+ output wire o_uart_tx_int,
+ output wire o_uart_rxfifo_int,
+ output wire o_uart_txfifo_int
+);
+ wire i_reset = !S_AXI_ARESETN;
+ wire axil_write_ready;
+ wire [C_AXI_ADDR_WIDTH-ADDRLSB-1:0] awskd_addr;
+ wire [C_AXI_DATA_WIDTH-1:0] wskd_data;
+ wire [C_AXI_DATA_WIDTH/8-1:0] wskd_strb;
+ reg axil_bvalid;
+ wire axil_read_ready;
+ wire [C_AXI_ADDR_WIDTH-ADDRLSB-1:0] arskd_addr;
+ reg [C_AXI_DATA_WIDTH-1:0] axil_read_data;
+ reg axil_read_valid;
+ wire tx_busy;
+ reg [30:0] uart_setup;
+ wire rx_stb, rx_break, rx_perr, rx_ferr, ck_uart;
+ wire [7:0] rx_uart_data;
+ reg rx_uart_reset;
+ wire rx_empty_n, rx_fifo_err;
+ wire [7:0] rxf_axil_data;
+ wire [15:0] rxf_status;
+ reg rxf_axil_read;
+ reg r_rx_perr, r_rx_ferr;
+ wire [(LCLLGFLEN-1):0] check_cutoff;
+ wire [31:0] axil_rx_data;
+ wire tx_empty_n, txf_err, tx_break;
+ wire [ 7:0] tx_data;
+ wire [15:0] txf_status;
+ reg txf_axil_write, tx_uart_reset;
+ reg [7:0] txf_axil_data;
+ wire [31:0] axil_tx_data;
+ wire [31:0] axil_fifo_data;
+ reg [1:0] r_axil_addr;
+ reg r_preread;
+ reg [31:0] new_setup;
+ generate
+ if (OPT_SKIDBUFFER) begin : SKIDBUFFER_WRITE
+ wire awskd_valid, wskd_valid;
+ skidbuffer #(
+ .OPT_OUTREG(0),
+ .OPT_LOWPOWER(OPT_LOWPOWER),
+ .DW(C_AXI_ADDR_WIDTH - ADDRLSB)
+ ) axilawskid (
+ .i_clk (S_AXI_ACLK),
+ .i_reset(i_reset),
+ .i_valid(S_AXI_AWVALID),
+ .o_ready(S_AXI_AWREADY),
+ .i_data (S_AXI_AWADDR[C_AXI_ADDR_WIDTH-1:ADDRLSB]),
+ .o_valid(awskd_valid),
+ .i_ready(axil_write_ready),
+ .o_data (awskd_addr)
+ );
+ skidbuffer #(
+ .OPT_OUTREG(0),
+ .OPT_LOWPOWER(OPT_LOWPOWER),
+ .DW(C_AXI_DATA_WIDTH + C_AXI_DATA_WIDTH / 8)
+ ) axilwskid (
+ .i_clk (S_AXI_ACLK),
+ .i_reset(i_reset),
+ .i_valid(S_AXI_WVALID),
+ .o_ready(S_AXI_WREADY),
+ .i_data ({S_AXI_WDATA, S_AXI_WSTRB}),
+ .o_valid(wskd_valid),
+ .i_ready(axil_write_ready),
+ .o_data ({wskd_data, wskd_strb})
+ );
+ assign axil_write_ready = awskd_valid && wskd_valid && (!S_AXI_BVALID || S_AXI_BREADY);
+ end else begin : SIMPLE_WRITES
+ reg axil_awready;
+ initial axil_awready = 1'b0;
+ always @(posedge S_AXI_ACLK)
+ if (!S_AXI_ARESETN) axil_awready <= 1'b0;
+ else
+ axil_awready <= !axil_awready
+&& (S_AXI_AWVALID && S_AXI_WVALID)
+&& (!S_AXI_BVALID || S_AXI_BREADY);
+ assign S_AXI_AWREADY = axil_awready;
+ assign S_AXI_WREADY = axil_awready;
+ assign awskd_addr = S_AXI_AWADDR[C_AXI_ADDR_WIDTH-1:ADDRLSB];
+ assign wskd_data = S_AXI_WDATA;
+ assign wskd_strb = S_AXI_WSTRB;
+ assign axil_write_ready = axil_awready;
+ end
+ endgenerate
+ initial axil_bvalid = 0;
+ always @(posedge S_AXI_ACLK)
+ if (i_reset) axil_bvalid <= 0;
+ else if (axil_write_ready) axil_bvalid <= 1;
+ else if (S_AXI_BREADY) axil_bvalid <= 0;
+ assign S_AXI_BVALID = axil_bvalid;
+ assign S_AXI_BRESP = 2'b00;
+ generate
+ if (OPT_SKIDBUFFER) begin : SKIDBUFFER_READ
+ wire arskd_valid;
+ skidbuffer #(
+ .OPT_OUTREG(0),
+ .OPT_LOWPOWER(OPT_LOWPOWER),
+ .DW(C_AXI_ADDR_WIDTH - ADDRLSB)
+ ) axilarskid (
+ .i_clk (S_AXI_ACLK),
+ .i_reset(i_reset),
+ .i_valid(S_AXI_ARVALID),
+ .o_ready(S_AXI_ARREADY),
+ .i_data (S_AXI_ARADDR[C_AXI_ADDR_WIDTH-1:ADDRLSB]),
+ .o_valid(arskd_valid),
+ .i_ready(axil_read_ready),
+ .o_data (arskd_addr)
+ );
+ assign axil_read_ready = arskd_valid && (!r_preread || !axil_read_valid || S_AXI_RREADY);
+ end else begin : SIMPLE_READS
+ reg axil_arready;
+ initial axil_arready = 1;
+ always @(posedge S_AXI_ACLK)
+ if (!S_AXI_ARESETN) axil_arready <= 1;
+ else if (S_AXI_ARVALID && S_AXI_ARREADY) axil_arready <= 0;
+ else if (S_AXI_RVALID && S_AXI_RREADY) axil_arready <= 1;
+ assign arskd_addr = S_AXI_ARADDR[C_AXI_ADDR_WIDTH-1:ADDRLSB];
+ assign S_AXI_ARREADY = axil_arready;
+ assign axil_read_ready = (S_AXI_ARVALID && S_AXI_ARREADY);
+ end
+ endgenerate
+ initial axil_read_valid = 1'b0;
+ always @(posedge S_AXI_ACLK)
+ if (i_reset) axil_read_valid <= 1'b0;
+ else if (r_preread) axil_read_valid <= 1'b1;
+ else if (S_AXI_RREADY) axil_read_valid <= 1'b0;
+ assign S_AXI_RVALID = axil_read_valid;
+ assign S_AXI_RDATA = axil_read_data;
+ assign S_AXI_RRESP = 2'b00;
+ localparam [1:0] UART_SETUP = 2'b00, UART_FIFO = 2'b01, UART_RXREG = 2'b10, UART_TXREG = 2'b11;
+ always @(*) new_setup = apply_wstrb({1'b0, uart_setup}, wskd_data, wskd_strb);
+ initial uart_setup = INITIAL_SETUP | ((HARDWARE_FLOW_CONTROL_PRESENT == 1'b0) ? 31'h40000000 : 0);
+ always @(posedge S_AXI_ACLK)
+ if ((axil_write_ready) && (awskd_addr == UART_SETUP)) begin
+ uart_setup <= new_setup[30:0];
+ if (!HARDWARE_FLOW_CONTROL_PRESENT) uart_setup[30] <= 1'b1;
+ end
+`ifdef FORMAL
+ (* anyseq *) reg w_rx_break, w_rx_perr, w_rx_ferr, w_ck_uart;
+ assign rx_break = w_rx_break;
+ assign w_rx_perr = w_rx_perr;
+ assign w_rx_ferr = w_rx_ferr;
+ assign ck_uart = w_ck_uart;
+`else
+`ifdef USE_LITE_UART
+ rxuartlite #(
+ .CLOCKS_PER_BAUD(INITIAL_SETUP[23:0])
+ ) rx (
+ S_AXI_ACLK,
+ i_uart_rx,
+ rx_stb,
+ rx_uart_data
+ );
+ assign rx_break = 1'b0;
+ assign rx_perr = 1'b0;
+ assign rx_ferr = 1'b0;
+ assign ck_uart = 1'b0;
+`else
+ rxuart #(
+ .INITIAL_SETUP(INITIAL_SETUP)
+ ) rx (
+ S_AXI_ACLK,
+ (!S_AXI_ARESETN) || (rx_uart_reset),
+ uart_setup,
+ i_uart_rx,
+ rx_stb,
+ rx_uart_data,
+ rx_break,
+ rx_perr,
+ rx_ferr,
+ ck_uart
+ );
+`endif
+`endif
+ ufifo #(
+ .LGFLEN(LCLLGFLEN),
+ .RXFIFO(1)
+ ) rxfifo (
+ S_AXI_ACLK,
+ (!S_AXI_ARESETN) || (rx_break) || (rx_uart_reset),
+ rx_stb,
+ rx_uart_data,
+ rx_empty_n,
+ rxf_axil_read,
+ rxf_axil_data,
+ rxf_status,
+ rx_fifo_err
+ );
+ assign o_uart_rxfifo_int = rxf_status[1];
+ assign o_uart_rx_int = rxf_status[0];
+ assign check_cutoff = -3;
+ always @(posedge S_AXI_ACLK)
+ o_rts_n <= ((HARDWARE_FLOW_CONTROL_PRESENT)
+&&(!uart_setup[30])
+&&(rxf_status[(LCLLGFLEN+1):2] > check_cutoff));
+ initial rxf_axil_read = 1'b0;
+ always @(posedge S_AXI_ACLK)
+ rxf_axil_read <= (axil_read_ready) && (arskd_addr[1:0] == UART_RXREG);
+ initial r_rx_perr = 1'b0;
+ initial r_rx_ferr = 1'b0;
+ always @(posedge S_AXI_ACLK)
+ if ((rx_uart_reset) || (rx_break)) begin
+ r_rx_perr <= 1'b0;
+ r_rx_ferr <= 1'b0;
+ end else if (axil_write_ready && awskd_addr == UART_RXREG && wskd_strb[1]) begin
+ r_rx_perr <= (r_rx_perr) && (!wskd_data[9]);
+ r_rx_ferr <= (r_rx_ferr) && (!wskd_data[10]);
+ end else if (rx_stb) begin
+ r_rx_perr <= (r_rx_perr) || (rx_perr);
+ r_rx_ferr <= (r_rx_ferr) || (rx_ferr);
+ end
+ initial rx_uart_reset = 1'b1;
+ always @(posedge S_AXI_ACLK)
+ if ((!S_AXI_ARESETN) || ((axil_write_ready) && (awskd_addr[1:0] == UART_SETUP) && (&wskd_strb)))
+ rx_uart_reset <= 1'b1;
+ else if (axil_write_ready && (awskd_addr[1:0] == UART_RXREG) && wskd_strb[1])
+ rx_uart_reset <= wskd_data[12];
+ else rx_uart_reset <= 1'b0;
+ assign axil_rx_data = {
+ 16'h00, 3'h0, rx_fifo_err, rx_break, rx_ferr, r_rx_perr, !rx_empty_n, rxf_axil_data
+ };
+ initial txf_axil_write = 1'b0;
+ always @(posedge S_AXI_ACLK) begin
+ txf_axil_write <= (axil_write_ready) && (awskd_addr == UART_TXREG) && wskd_strb[0];
+ txf_axil_data <= wskd_data[7:0];
+ end
+ ufifo #(
+ .LGFLEN(LGFLEN),
+ .RXFIFO(0)
+ ) txfifo (
+ S_AXI_ACLK,
+ (tx_break) || (tx_uart_reset),
+ txf_axil_write,
+ txf_axil_data,
+ tx_empty_n,
+ (!tx_busy) && (tx_empty_n),
+ tx_data,
+ txf_status,
+ txf_err
+ );
+ assign o_uart_tx_int = txf_status[0];
+ assign o_uart_txfifo_int = txf_status[1];
+`ifndef USE_LITE_UART
+ reg r_tx_break;
+ initial r_tx_break = 1'b0;
+ always @(posedge S_AXI_ACLK)
+ if (!S_AXI_ARESETN) r_tx_break <= 1'b0;
+ else if (axil_write_ready && (awskd_addr[1:0] == UART_TXREG) && wskd_strb[1])
+ r_tx_break <= wskd_data[9];
+ assign tx_break = r_tx_break;
+`else
+ assign tx_break = 1'b0;
+`endif
+ initial tx_uart_reset = 1'b1;
+ always @(posedge S_AXI_ACLK)
+ if ((!S_AXI_ARESETN) || ((axil_write_ready) && (awskd_addr == UART_SETUP)))
+ tx_uart_reset <= 1'b1;
+ else if ((axil_write_ready) && (awskd_addr[1:0] == UART_TXREG) && wskd_strb[1])
+ tx_uart_reset <= wskd_data[12];
+ else tx_uart_reset <= 1'b0;
+`ifdef FORMAL
+ (* anyseq *) reg w_uart_tx, w_tx_busy;
+ assign tx_busy = w_uart_tx;
+ assign o_uart_tx = w_uart_tx;
+`else
+`ifdef USE_LITE_UART
+ txuartlite #(
+ .CLOCKS_PER_BAUD(INITIAL_SETUP[23:0])
+ ) tx (
+ S_AXI_ACLK,
+ (tx_empty_n),
+ tx_data,
+ o_uart_tx,
+ tx_busy
+ );
+`else
+ wire cts_n;
+ assign cts_n = (HARDWARE_FLOW_CONTROL_PRESENT) && (i_cts_n);
+ txuart #(
+ .INITIAL_SETUP(INITIAL_SETUP)
+ ) tx (
+ S_AXI_ACLK,
+ 1'b0,
+ uart_setup,
+ r_tx_break,
+ (tx_empty_n),
+ tx_data,
+ cts_n,
+ o_uart_tx,
+ tx_busy
+ );
+`endif
+`endif
+ assign axil_tx_data = {
+ 16'h00,
+ i_cts_n,
+ txf_status[1:0],
+ txf_err,
+ ck_uart,
+ o_uart_tx,
+ tx_break,
+ (tx_busy | txf_status[0]),
+ (tx_busy | txf_status[0]) ? txf_axil_data : 8'b00
+ };
+ assign axil_fifo_data = {txf_status, rxf_status};
+ initial r_preread = 0;
+ always @(posedge S_AXI_ACLK)
+ if (!S_AXI_ARESETN) r_preread <= 0;
+ else if (axil_read_ready) r_preread <= 1;
+ else if (!S_AXI_RVALID || S_AXI_RREADY) r_preread <= 0;
+ always @(posedge S_AXI_ACLK) if (axil_read_ready) r_axil_addr <= arskd_addr;
+ always @(posedge S_AXI_ACLK)
+ if (!S_AXI_RVALID || S_AXI_RREADY) begin
+ casez (r_axil_addr)
+ UART_SETUP: axil_read_data <= {1'b0, uart_setup};
+ UART_FIFO: axil_read_data <= axil_fifo_data;
+ UART_RXREG: axil_read_data <= axil_rx_data;
+ UART_TXREG: axil_read_data <= axil_tx_data;
+ endcase
+ if (OPT_LOWPOWER && !r_preread) axil_read_data <= 0;
+ end
+ function [C_AXI_DATA_WIDTH-1:0] apply_wstrb;
+ input [C_AXI_DATA_WIDTH-1:0] prior_data;
+ input [C_AXI_DATA_WIDTH-1:0] new_data;
+ input [C_AXI_DATA_WIDTH/8-1:0] wstrb;
+ integer k;
+ for (k = 0; k < C_AXI_DATA_WIDTH / 8; k = k + 1) begin
+ apply_wstrb[k*8+:8] = wstrb[k] ? new_data[k*8+:8] : prior_data[k*8+:8];
+ end
+ endfunction
+ wire unused;
+ assign unused = &{ 1'b0, S_AXI_AWPROT, S_AXI_ARPROT,
+S_AXI_ARADDR[ADDRLSB-1:0],
+S_AXI_AWADDR[ADDRLSB-1:0], new_setup[31] };
+`ifdef FORMAL
+ reg f_past_valid;
+ initial f_past_valid = 0;
+ always @(posedge S_AXI_ACLK) f_past_valid <= 1;
+ localparam F_AXIL_LGDEPTH = 4;
+ wire [F_AXIL_LGDEPTH-1:0] faxil_rd_outstanding, faxil_wr_outstanding, faxil_awr_outstanding;
+ faxil_slave #(
+ .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH),
+ .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH),
+ .F_LGDEPTH(F_AXIL_LGDEPTH),
+ .F_AXI_MAXWAIT(4),
+ .F_AXI_MAXDELAY(4),
+ .F_AXI_MAXRSTALL(3),
+ .F_OPT_COVER_BURST(4)
+ ) faxil (
+ .i_clk(S_AXI_ACLK),
+ .i_axi_reset_n(S_AXI_ARESETN),
+ .i_axi_awvalid(S_AXI_AWVALID),
+ .i_axi_awready(S_AXI_AWREADY),
+ .i_axi_awaddr(S_AXI_AWADDR),
+ .i_axi_awcache(4'h0),
+ .i_axi_awprot(S_AXI_AWPROT),
+ .i_axi_wvalid(S_AXI_WVALID),
+ .i_axi_wready(S_AXI_WREADY),
+ .i_axi_wdata(S_AXI_WDATA),
+ .i_axi_wstrb(S_AXI_WSTRB),
+ .i_axi_bvalid(S_AXI_BVALID),
+ .i_axi_bready(S_AXI_BREADY),
+ .i_axi_bresp(S_AXI_BRESP),
+ .i_axi_arvalid(S_AXI_ARVALID),
+ .i_axi_arready(S_AXI_ARREADY),
+ .i_axi_araddr(S_AXI_ARADDR),
+ .i_axi_arcache(4'h0),
+ .i_axi_arprot(S_AXI_ARPROT),
+ .i_axi_rvalid(S_AXI_RVALID),
+ .i_axi_rready(S_AXI_RREADY),
+ .i_axi_rdata(S_AXI_RDATA),
+ .i_axi_rresp(S_AXI_RRESP),
+ .f_axi_rd_outstanding(faxil_rd_outstanding),
+ .f_axi_wr_outstanding(faxil_wr_outstanding),
+ .f_axi_awr_outstanding(faxil_awr_outstanding)
+ );
+ always @(*)
+ if (OPT_SKIDBUFFER) begin
+ assert (faxil_awr_outstanding == (S_AXI_BVALID ? 1 : 0) + (S_AXI_AWREADY ? 0 : 1));
+ assert (faxil_wr_outstanding == (S_AXI_BVALID ? 1 : 0) + (S_AXI_WREADY ? 0 : 1));
+ assert(faxil_rd_outstanding == (S_AXI_RVALID ? 1:0)
++ (r_preread ? 1:0) +(S_AXI_ARREADY ? 0:1));
+ end else begin
+ assert (faxil_wr_outstanding == (S_AXI_BVALID ? 1 : 0));
+ assert (faxil_awr_outstanding == faxil_wr_outstanding);
+ assert (faxil_rd_outstanding == (S_AXI_RVALID ? 1 : 0) + (r_preread ? 1 : 0));
+ assert (S_AXI_ARREADY == (!S_AXI_RVALID && !r_preread));
+ end
+`ifdef VERIFIC
+ assert property (@(posedge S_AXI_ACLK)
+disable iff (!S_AXI_ARESETN || (S_AXI_RVALID && !S_AXI_RREADY))
+S_AXI_ARVALID && S_AXI_ARREADY && S_AXI_ARADDR[3:2]== UART_SETUP
+|=> r_preread && r_axil_addr == UART_SETUP
+##1 S_AXI_RVALID && axil_read_data
+== { 1'b0, $past(
+ uart_setup
+ )});
+ assert property (@(posedge S_AXI_ACLK)
+disable iff (!S_AXI_ARESETN || (S_AXI_RVALID && !S_AXI_RREADY))
+S_AXI_ARVALID && S_AXI_ARREADY && S_AXI_ARADDR[3:2] == UART_FIFO
+|=> r_preread && r_axil_addr == UART_FIFO
+##1 S_AXI_RVALID && axil_read_data == $past(
+ axil_fifo_data
+ ));
+ assert property (@(posedge S_AXI_ACLK)
+disable iff (!S_AXI_ARESETN || (S_AXI_RVALID && !S_AXI_RREADY))
+S_AXI_ARVALID && S_AXI_ARREADY && S_AXI_ARADDR[3:2]== UART_RXREG
+|=> r_preread && r_axil_addr == UART_RXREG
+##1 S_AXI_RVALID && axil_read_data == $past(
+ axil_rx_data
+ ));
+ assert property (@(posedge S_AXI_ACLK)
+disable iff (!S_AXI_ARESETN || (S_AXI_RVALID && !S_AXI_RREADY))
+S_AXI_ARVALID && S_AXI_ARREADY && S_AXI_ARADDR[3:2]== UART_TXREG
+|=> r_preread && r_axil_addr == UART_TXREG
+##1 S_AXI_RVALID && axil_read_data == $past(
+ axil_tx_data
+ ));
+`endif
+ always @(*) if (OPT_LOWPOWER && !S_AXI_RVALID) assert (S_AXI_RDATA == 0);
+`endif
+endmodule
+"
+"import json
+
+struct User {
+\tname string
+\tage int
+mut:
+\tis_registered bool
+}
+
+fn main() {
+\ts := \'[{""name"":""Frodo"", ""age"":25}, {""name"":""Bobby"", ""age"":10}]\'
+\tusers := json.decode([]User, s) or {
+\t\teprintln(\'Failed to parse json\')
+\t\treturn
+\t}
+\tfor user in users {
+\t\tprintln(\'$user.name: $user.age\')
+\t}
+\tprintln(\'\')
+\tfor i, user in users {
+\t\tprintln(\'$i) $user.name\')
+\t\tif !user.can_register() {
+\t\t\tprintln(\'Cannot register $user.name, they are too young\')
+\t\t\tcontinue
+\t\t}
+\t\tusers[i].register() // `user` is immutable, we have to modify the array
+\t}
+\t// Let\'s encode users again just for fun
+\tprintln(\'\')
+\tprintln(json.encode(users))
+}
+
+fn (u User) can_register() bool {
+ return u.age >= 16
+}
+
+fn (u mut User) register() {
+ u.is_registered = true
+}"
+"/*
+Copyright (C) 2015-2021, Gisselquist Technology, LLC
+
+This program is free software (firmware): you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. (It's in the $(ROOT)/doc directory. Run make with no
+target there if the PDF file isn't present.) If not, see
+ for a copy.
+
+License: GPL, v3, as defined and found on www.gnu.org,
+http://www.gnu.org/licenses/gpl.html
+*/
+`default_nettype none
+module wbuart #(
+ parameter [30:0] INITIAL_SETUP = 31'd25,
+ parameter [3:0] LGFLEN = 4,
+ parameter [0:0] HARDWARE_FLOW_CONTROL_PRESENT = 1'b1,
+ parameter [3:0] LCLLGFLEN = (LGFLEN > 4'ha) ? 4'ha : ((LGFLEN < 4'h2) ? 4'h2 : LGFLEN)
+) (
+ input wire i_clk,
+ i_reset,
+ input wire i_wb_cyc,
+ input wire i_wb_stb,
+ i_wb_we,
+ input wire [1:0] i_wb_addr,
+ input wire [31:0] i_wb_data,
+ input wire [3:0] i_wb_sel,
+ output wire o_wb_stall,
+ output reg o_wb_ack,
+ output reg [31:0] o_wb_data,
+ input wire i_uart_rx,
+ output wire o_uart_tx,
+ input wire i_cts_n,
+ output reg o_rts_n,
+ output wire o_uart_rx_int,
+ o_uart_tx_int,
+ o_uart_rxfifo_int,
+ o_uart_txfifo_int
+);
+ localparam [1:0] UART_SETUP = 2'b00, UART_FIFO = 2'b01, UART_RXREG = 2'b10, UART_TXREG = 2'b11;
+ wire tx_busy;
+ reg [30:0] uart_setup;
+ wire rx_stb, rx_break, rx_perr, rx_ferr, ck_uart;
+ wire [7:0] rx_uart_data;
+ reg rx_uart_reset;
+ wire rx_empty_n, rx_fifo_err;
+ wire [7:0] rxf_wb_data;
+ wire [15:0] rxf_status;
+ reg rxf_wb_read;
+ wire [(LCLLGFLEN-1):0] check_cutoff;
+ reg r_rx_perr, r_rx_ferr;
+ wire [31:0] wb_rx_data;
+ wire tx_empty_n, txf_err, tx_break;
+ wire [ 7:0] tx_data;
+ wire [15:0] txf_status;
+ reg txf_wb_write, tx_uart_reset;
+ reg [7:0] txf_wb_data;
+ wire [31:0] wb_tx_data;
+ wire [31:0] wb_fifo_data;
+ reg [1:0] r_wb_addr;
+ reg r_wb_ack;
+ initial uart_setup = INITIAL_SETUP | ((HARDWARE_FLOW_CONTROL_PRESENT == 1'b0) ? 31'h40000000 : 0);
+ always @(posedge i_clk)
+ if ((i_wb_stb) && (i_wb_addr == UART_SETUP) && (i_wb_we)) begin
+ if (i_wb_sel[0]) uart_setup[7:0] <= i_wb_data[7:0];
+ if (i_wb_sel[1]) uart_setup[15:8] <= i_wb_data[15:8];
+ if (i_wb_sel[2]) uart_setup[23:16] <= i_wb_data[23:16];
+ if (i_wb_sel[3])
+ uart_setup[30:24] <= {
+ (i_wb_data[30]) || (!HARDWARE_FLOW_CONTROL_PRESENT), i_wb_data[29:24]
+ };
+ end
+`ifdef USE_LITE_UART
+ rxuartlite #(
+ .CLOCKS_PER_BAUD(INITIAL_SETUP[23:0])
+ ) rx (
+ i_clk,
+ i_uart_rx,
+ rx_stb,
+ rx_uart_data
+ );
+ assign rx_break = 1'b0;
+ assign rx_perr = 1'b0;
+ assign rx_ferr = 1'b0;
+ assign ck_uart = 1'b0;
+`else
+ rxuart #(
+ .INITIAL_SETUP(INITIAL_SETUP)
+ ) rx (
+ i_clk,
+ (i_reset) || (rx_uart_reset),
+ uart_setup,
+ i_uart_rx,
+ rx_stb,
+ rx_uart_data,
+ rx_break,
+ rx_perr,
+ rx_ferr,
+ ck_uart
+ );
+`endif
+ ufifo #(
+ .LGFLEN(LCLLGFLEN),
+ .RXFIFO(1)
+ ) rxfifo (
+ i_clk,
+ (i_reset) || (rx_break) || (rx_uart_reset),
+ rx_stb,
+ rx_uart_data,
+ rx_empty_n,
+ rxf_wb_read,
+ rxf_wb_data,
+ rxf_status,
+ rx_fifo_err
+ );
+ assign o_uart_rxfifo_int = rxf_status[1];
+ assign o_uart_rx_int = rxf_status[0];
+ assign check_cutoff = -3;
+ always @(posedge i_clk)
+ o_rts_n <= ((HARDWARE_FLOW_CONTROL_PRESENT)
+&&(!uart_setup[30])
+&&(rxf_status[(LCLLGFLEN+1):2] > check_cutoff));
+ initial rxf_wb_read = 1'b0;
+ always @(posedge i_clk) rxf_wb_read <= (i_wb_stb) && (i_wb_addr[1:0] == UART_RXREG) && (!i_wb_we);
+ initial r_rx_perr = 1'b0;
+ initial r_rx_ferr = 1'b0;
+ always @(posedge i_clk)
+ if ((rx_uart_reset) || (rx_break)) begin
+ r_rx_perr <= 1'b0;
+ r_rx_ferr <= 1'b0;
+ end else if ((i_wb_stb) && (i_wb_addr[1:0] == UART_RXREG) && (i_wb_we)) begin
+ if (i_wb_sel[1]) begin
+ r_rx_perr <= (r_rx_perr) && (~i_wb_data[9]);
+ r_rx_ferr <= (r_rx_ferr) && (~i_wb_data[10]);
+ end
+ end else if (rx_stb) begin
+ r_rx_perr <= (r_rx_perr) || (rx_perr);
+ r_rx_ferr <= (r_rx_ferr) || (rx_ferr);
+ end
+ initial rx_uart_reset = 1'b1;
+ always @(posedge i_clk)
+ if ((i_reset) || ((i_wb_stb) && (i_wb_addr[1:0] == UART_SETUP) && (i_wb_we)))
+ rx_uart_reset <= 1'b1;
+ else if ((i_wb_stb) && (i_wb_addr[1:0] == UART_RXREG) && (i_wb_we) && i_wb_sel[1])
+ rx_uart_reset <= i_wb_data[12];
+ else rx_uart_reset <= 1'b0;
+ assign wb_rx_data = {
+ 16'h00, 3'h0, rx_fifo_err, rx_break, rx_ferr, r_rx_perr, !rx_empty_n, rxf_wb_data
+ };
+ initial txf_wb_write = 1'b0;
+ always @(posedge i_clk) begin
+ txf_wb_write <= (i_wb_stb) && (i_wb_addr == UART_TXREG) && (i_wb_we) && (i_wb_sel[0]);
+ txf_wb_data <= i_wb_data[7:0];
+ end
+ ufifo #(
+ .LGFLEN(LGFLEN),
+ .RXFIFO(0)
+ ) txfifo (
+ i_clk,
+ (tx_break) || (tx_uart_reset),
+ txf_wb_write,
+ txf_wb_data,
+ tx_empty_n,
+ (!tx_busy) && (tx_empty_n),
+ tx_data,
+ txf_status,
+ txf_err
+ );
+ assign o_uart_tx_int = txf_status[0];
+ assign o_uart_txfifo_int = txf_status[1];
+`ifndef USE_LITE_UART
+ reg r_tx_break;
+ initial r_tx_break = 1'b0;
+ always @(posedge i_clk)
+ if (i_reset) r_tx_break <= 1'b0;
+ else if ((i_wb_stb) && (i_wb_addr[1:0] == UART_TXREG) && (i_wb_we) && (i_wb_sel[1]))
+ r_tx_break <= i_wb_data[9];
+ assign tx_break = r_tx_break;
+`else
+ assign tx_break = 1'b0;
+`endif
+ initial tx_uart_reset = 1'b1;
+ always @(posedge i_clk)
+ if ((i_reset) || ((i_wb_stb) && (i_wb_addr == UART_SETUP) && (i_wb_we))) tx_uart_reset <= 1'b1;
+ else if ((i_wb_stb) && (i_wb_addr[1:0] == UART_TXREG) && (i_wb_we) && i_wb_sel[1])
+ tx_uart_reset <= i_wb_data[12];
+ else tx_uart_reset <= 1'b0;
+`ifdef USE_LITE_UART
+ txuartlite #(
+ .CLOCKS_PER_BAUD(INITIAL_SETUP[23:0])
+ ) tx (
+ i_clk,
+ (tx_empty_n),
+ tx_data,
+ o_uart_tx,
+ tx_busy
+ );
+`else
+ wire cts_n;
+ assign cts_n = (HARDWARE_FLOW_CONTROL_PRESENT) && (i_cts_n);
+ txuart #(
+ .INITIAL_SETUP(INITIAL_SETUP)
+ ) tx (
+ i_clk,
+ 1'b0,
+ uart_setup,
+ r_tx_break,
+ (tx_empty_n),
+ tx_data,
+ cts_n,
+ o_uart_tx,
+ tx_busy
+ );
+`endif
+ assign wb_tx_data = {
+ 16'h00,
+ i_cts_n,
+ txf_status[1:0],
+ txf_err,
+ ck_uart,
+ o_uart_tx,
+ tx_break,
+ (tx_busy | txf_status[0]),
+ (tx_busy | txf_status[0]) ? txf_wb_data : 8'b00
+ };
+ assign wb_fifo_data = {txf_status, rxf_status};
+ always @(posedge i_clk) r_wb_addr <= i_wb_addr;
+ initial r_wb_ack = 1'b0;
+ always @(posedge i_clk) r_wb_ack <= i_wb_stb;
+ initial o_wb_ack = 1'b0;
+ always @(posedge i_clk) o_wb_ack <= i_wb_cyc && r_wb_ack;
+ always @(posedge i_clk)
+ casez (r_wb_addr)
+ UART_SETUP: o_wb_data <= {1'b0, uart_setup};
+ UART_FIFO: o_wb_data <= wb_fifo_data;
+ UART_RXREG: o_wb_data <= wb_rx_data;
+ UART_TXREG: o_wb_data <= wb_tx_data;
+ endcase
+ assign o_wb_stall = 1'b0;
+ wire unused;
+ assign unused = &{1'b0, i_wb_data[31]};
+endmodule
+"
+"fn main() {
+\tareas := ['game', 'web', 'tools', 'science', 'systems',
+\t 'embedded', 'GUI', 'mobile']
+\tfor area in areas {
+\t\tprintln('Hello, $area developers!')
+\t}
+}"
+"import os
+
+// Print file lines that starth with ""DEBUG:""
+fn main() {
+\t// `read_file` returns an optional (`?string`), it must be checked
+\ttext := os.read_file(\'app.log\') or {
+\t\tprintln(\'failed to read the file\')
+\t\treturn
+\t}
+\tlines := text.split_into_lines()
+\tfor line in lines {
+\t\tif line.starts_with(\'DEBUG:\') {
+\t\t\tprintln(line)
+\t\t}
+\t}
+}
+"
+"/*
+Copyright (C) 2015-2021, Gisselquist Technology, LLC
+
+This program is free software (firmware): you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. (It's in the $(ROOT)/doc directory. Run make with no
+target there if the PDF file isn't present.) If not, see
+ for a copy.
+
+License: GPL, v3, as defined and found on www.gnu.org,
+http://www.gnu.org/licenses/gpl.html
+*/
+`default_nettype none
+module txuartlite #(
+ parameter [4:0] TIMING_BITS = 5'd24,
+ parameter TB = TIMING_BITS,
+ parameter [(TB-1):0] CLOCKS_PER_BAUD = 8
+) (
+ input wire i_clk,
+ input wire i_wr,
+ input wire [7:0] i_data,
+ output reg o_uart_tx,
+ output wire o_busy
+);
+ localparam [3:0] TXUL_BIT_ZERO = 4'h0, TXUL_STOP = 4'h8, TXUL_IDLE = 4'hf;
+ reg [(TB-1):0] baud_counter;
+ reg [3:0] state;
+ reg [7:0] lcl_data;
+ reg r_busy, zero_baud_counter;
+ initial r_busy = 1'b1;
+ initial state = TXUL_IDLE;
+ always @(posedge i_clk) begin
+ if (!zero_baud_counter) r_busy <= 1'b1;
+ else if (state > TXUL_STOP) begin
+ state <= TXUL_IDLE;
+ r_busy <= 1'b0;
+ if ((i_wr) && (!r_busy)) begin
+ r_busy <= 1'b1;
+ state <= TXUL_BIT_ZERO;
+ end
+ end else begin
+ r_busy <= 1'b1;
+ if (state <= TXUL_STOP) state <= state + 1'b1;
+ else state <= TXUL_IDLE;
+ end
+ end
+ assign o_busy = (r_busy);
+ initial lcl_data = 8'hff;
+ always @(posedge i_clk)
+ if ((i_wr) && (!r_busy)) lcl_data <= i_data;
+ else if (zero_baud_counter) lcl_data <= {1'b1, lcl_data[7:1]};
+ initial o_uart_tx = 1'b1;
+ always @(posedge i_clk)
+ if ((i_wr) && (!r_busy)) o_uart_tx <= 1'b0;
+ else if (zero_baud_counter) o_uart_tx <= lcl_data[0];
+ initial zero_baud_counter = 1'b1;
+ initial baud_counter = 0;
+ always @(posedge i_clk) begin
+ zero_baud_counter <= (baud_counter == 1);
+ if (state == TXUL_IDLE) begin
+ baud_counter <= 0;
+ zero_baud_counter <= 1'b1;
+ if ((i_wr) && (!r_busy)) begin
+ baud_counter <= CLOCKS_PER_BAUD - 1'b1;
+ zero_baud_counter <= 1'b0;
+ end
+ end else if (!zero_baud_counter) baud_counter <= baud_counter - 1'b1;
+ else if (state > TXUL_STOP) begin
+ baud_counter <= 0;
+ zero_baud_counter <= 1'b1;
+ end else if (state == TXUL_STOP) baud_counter <= CLOCKS_PER_BAUD - 2;
+ else baud_counter <= CLOCKS_PER_BAUD - 1'b1;
+ end
+`ifdef FORMAL
+`ifdef TXUARTLITE
+ `define ASSUME assume
+`else
+ `define ASSUME assert
+`endif
+ reg f_past_valid, f_last_clk;
+ reg [(TB-1):0] f_baud_count;
+ reg [9:0] f_txbits;
+ reg [3:0] f_bitcount;
+ reg [7:0] f_request_tx_data;
+ wire [3:0] subcount;
+ initial f_past_valid = 1'b0;
+ always @(posedge i_clk) f_past_valid <= 1'b1;
+ initial `ASSUME(!i_wr);
+ always @(posedge i_clk)
+ if ((f_past_valid) && ($past(i_wr)) && ($past(o_busy))) begin
+ `ASSUME(i_wr == $past(i_wr));
+ `ASSUME(i_data == $past(i_data));
+ end
+ always @(posedge i_clk) assert (zero_baud_counter == (baud_counter == 0));
+ always @(posedge i_clk)
+ if ((f_past_valid) && ($past(baud_counter != 0)) && ($past(state != TXUL_IDLE)))
+ assert (baud_counter == $past(baud_counter - 1'b1));
+ always @(posedge i_clk)
+ if ((f_past_valid) && (!$past(zero_baud_counter)) && ($past(state != TXUL_IDLE)))
+ assert ($stable(o_uart_tx));
+ initial f_baud_count = 1'b0;
+ always @(posedge i_clk)
+ if (zero_baud_counter) f_baud_count <= 0;
+ else f_baud_count <= f_baud_count + 1'b1;
+ always @(posedge i_clk) assert (f_baud_count < CLOCKS_PER_BAUD);
+ always @(posedge i_clk) if (baud_counter != 0) assert (o_busy);
+ initial f_txbits = 0;
+ always @(posedge i_clk) if (zero_baud_counter) f_txbits <= {o_uart_tx, f_txbits[9:1]};
+ always @(posedge i_clk)
+ if ((f_past_valid) && (!$past(zero_baud_counter)) && (!$past(state == TXUL_IDLE)))
+ assert (state == $past(state));
+ initial f_bitcount = 0;
+ always @(posedge i_clk)
+ if ((!f_past_valid) || (!$past(f_past_valid))) f_bitcount <= 0;
+ else if ((state == TXUL_IDLE) && (zero_baud_counter)) f_bitcount <= 0;
+ else if (zero_baud_counter) f_bitcount <= f_bitcount + 1'b1;
+ always @(posedge i_clk) assert (f_bitcount <= 4'ha);
+ always @(*) if (!o_busy) assert (zero_baud_counter);
+ always @(posedge i_clk) if ((i_wr) && (!o_busy)) f_request_tx_data <= i_data;
+ assign subcount = 10 - f_bitcount;
+ always @(posedge i_clk) if (f_bitcount > 0) assert (!f_txbits[subcount]);
+ always @(posedge i_clk)
+ if (f_bitcount == 4'ha) begin
+ assert (f_txbits[8:1] == f_request_tx_data);
+ assert (f_txbits[9]);
+ end
+ always @(posedge i_clk) assert ((state <= TXUL_STOP + 1'b1) || (state == TXUL_IDLE));
+ always @(posedge i_clk)
+ if ((f_past_valid) && ($past(f_past_valid)) && ($past(o_busy)))
+ cover (!o_busy);
+`endif
+`ifdef VERIFIC_SVA
+ reg [7:0] fsv_data;
+ always @(posedge i_clk) if ((i_wr) && (!o_busy)) fsv_data <= i_data;
+ sequence BAUD_INTERVAL(CKS, DAT, SR, ST);
+ ((o_uart_tx == DAT)&&(state == ST)
+&&(lcl_data == SR)
+&&(!zero_baud_counter))[*(CKS-1)]
+##1 (o_uart_tx == DAT)&&(state == ST)
+&&(lcl_data == SR)
+&&(zero_baud_counter);
+ endsequence
+ sequence SEND(CKS, DATA);
+ BAUD_INTERVAL(
+ CKS, 1'b0, DATA, 4'h0
+ ) ##1 BAUD_INTERVAL(
+ CKS, DATA[0], {{(1) {1'b1}}, DATA[7:1]}, 4'h1
+ ) ##1 BAUD_INTERVAL(
+ CKS, DATA[1], {{(2) {1'b1}}, DATA[7:2]}, 4'h2
+ ) ##1 BAUD_INTERVAL(
+ CKS, DATA[2], {{(3) {1'b1}}, DATA[7:3]}, 4'h3
+ ) ##1 BAUD_INTERVAL(
+ CKS, DATA[3], {{(4) {1'b1}}, DATA[7:4]}, 4'h4
+ ) ##1 BAUD_INTERVAL(
+ CKS, DATA[4], {{(5) {1'b1}}, DATA[7:5]}, 4'h5
+ ) ##1 BAUD_INTERVAL(
+ CKS, DATA[5], {{(6) {1'b1}}, DATA[7:6]}, 4'h6
+ ) ##1 BAUD_INTERVAL(
+ CKS, DATA[6], {{(7) {1'b1}}, DATA[7:7]}, 4'h7
+ ) ##1 BAUD_INTERVAL(
+ CKS, DATA[7], 8'hff, 4'h8
+ ) ##1 BAUD_INTERVAL(
+ CKS - 1, 1'b1, 8'hff, 4'h9
+ );
+ endsequence
+ assert property (@(posedge i_clk) (i_wr) && (!o_busy) |=> ((o_busy) throughout SEND(
+ CLOCKS_PER_BAUD, fsv_data
+ )) ##1 (!o_busy) && (o_uart_tx) && (zero_baud_counter));
+ assume property (@(posedge i_clk) (i_wr) && (o_busy) |=> (i_wr) && ($stable(i_data)));
+ always @(*) assert ((o_busy) || (zero_baud_counter));
+ always @(*) assert (zero_baud_counter == (baud_counter == 0));
+ always @(*) assert (baud_counter < CLOCKS_PER_BAUD);
+ always @(*) assert ((state <= TXUL_STOP + 1'b1) || (state == TXUL_IDLE));
+`endif
+endmodule
+"
+"/*
+Copyright (c) 2001 Stephan Boettcher
+
+This source code is free software; you can redistribute it
+and/or modify it in source code form under the terms of the GNU
+General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+*/
+module test_lfsr;
+ reg cp;
+ reg in;
+ wire out;
+ reg reset;
+ lfsr sr (
+ cp,
+ reset,
+ in,
+ out
+ );
+ reg errors;
+ initial errors = 0;
+ integer i;
+ initial begin
+ in = 0;
+ cp = 0;
+ #2 reset = 1;
+ #2 reset = 0;
+ #1;
+ for (i = 0; i < 512; i = i + 1) #5 cp = ~cp;
+ in = 0;
+ cp = 0;
+ #2 reset = 1;
+ #2 reset = 0;
+ #1;
+ for (i = 0; i < 512; i = i + 1) #5 cp <= ~cp;
+ #5;
+ if (errors == 0) $display(""PASSED"");
+ #10 $finish;
+ end
+ reg [7:0] here;
+ reg [7:0] next;
+ reg [7:0] old_val;
+ reg [7:0] new_val;
+ always @(reset)
+ if (reset) begin
+ here = 1;
+ #1;
+ old_val = {out, sr.s};
+ if (old_val === here) begin
+ $display(""%b RESET"", old_val);
+ end else begin
+ $display(""%b RESET FAILED: expect %b"", old_val, here);
+ errors = 1;
+ end
+ end
+ always begin
+ @(posedge cp) old_val = {out, sr.s};
+ next = {here[6:0], ^(here & sr.P) ^ in};
+ @(negedge cp) new_val = {out, sr.s};
+ if (old_val != here || new_val !== next) begin
+ $display(""%b->%b FAILED: expect %b->%b"", old_val, new_val, here, next);
+ errors = 1;
+ end else begin
+ $display(""%b->%b"", old_val, new_val);
+ end
+ here = next;
+ end
+endmodule
+module lfsr (
+ clk,
+ reset,
+ in,
+ out
+);
+ parameter P = 8\'b1101_1001;
+ input clk;
+ input reset;
+ input in;
+ output out;
+ wire [6:0] s;
+ wire i = ^{P &{out, s}} ^ in;
+ jkff ff1 (
+ s[0],
+ clk,
+ i,
+ ~i,
+ reset,
+ 0
+ );
+ jkff ff2 (
+ s[1],
+ clk,
+ s[0],
+ ~s[0],
+ 0,
+ reset
+ );
+ jkff ff3 (
+ s[2],
+ clk,
+ s[1],
+ ~s[1],
+ 0,
+ reset
+ );
+ jkff ff4 (
+ s[3],
+ clk,
+ s[2],
+ ~s[2],
+ 0,
+ reset
+ );
+ jkff ff8 (
+ out,
+ clk,
+ s[6],
+ ~s[6],
+ 0,
+ reset
+ );
+ jkff ff7 (
+ s[6],
+ clk,
+ s[5],
+ ~s[5],
+ 0,
+ reset
+ );
+ jkff ff6 (
+ s[5],
+ clk,
+ s[4],
+ ~s[4],
+ 0,
+ reset
+ );
+ jkff ff5 (
+ s[4],
+ clk,
+ s[3],
+ ~s[3],
+ 0,
+ reset
+ );
+endmodule
+primitive jkff(q, cp, j, k, s, r);
+ output q;
+ input cp, j, k, s, r;
+ reg q;
+ table
+ ? ? ? (?0) 0 : ? : -;
+ ? ? ? 0 (?0) : ? : -;
+ ? * ? 0 0 : ? : -;
+ ? ? * 0 0 : ? : -;
+ ? ? ? 1 0 : ? : 1;
+ ? ? ? 0 1 : ? : 0;
+ ? ? ? x 0 : 1 : 1;
+ ? ? ? 0 x : 0 : 0;
+ (?0) ? ? 0 0 : ? : -;
+ (1x) ? ? 0 0 : ? : -;
+ (?1) 0 ? 0 0 : 0 : 0;
+ (?1) ? 0 0 0 : 1 : 1;
+ (0x) 0 ? 0 0 : 0 : 0;
+ (0x) ? 0 0 0 : 1 : 1;
+ (01) 1 ? 0 0 : 0 : 1;
+ (01) ? 1 0 0 : 1 : 0;
+ (01) 1 0 0 0 : x : 1;
+ (01) 0 1 0 0 : x : 0;
+ endtable
+endprimitive
+"
+"`timescale 1ns / 1ps
+
+module toplevel(
+ input io_J3,
+ input io_H16,
+ input io_G15,
+ output io_G16,
+ input io_F15,
+ output io_B12,
+ input io_B10,
+ output [7:0] io_led
+ );
+
+ wire [31:0] io_gpioA_read;
+ wire [31:0] io_gpioA_write;
+ wire [31:0] io_gpioA_writeEnable;
+ wire io_mainClk;
+ wire io_jtag_tck;
+
+ SB_GB mainClkBuffer (
+ .USER_SIGNAL_TO_GLOBAL_BUFFER (io_J3),
+ .GLOBAL_BUFFER_OUTPUT ( io_mainClk)
+ );
+
+ SB_GB jtagClkBuffer (
+ .USER_SIGNAL_TO_GLOBAL_BUFFER (io_H16),
+ .GLOBAL_BUFFER_OUTPUT ( io_jtag_tck)
+ );
+
+ assign io_led = io_gpioA_write[7 : 0];
+
+ Murax murax (
+ .io_asyncReset(0),
+ .io_mainClk (io_mainClk ),
+ .io_jtag_tck(io_jtag_tck),
+ .io_jtag_tdi(io_G15),
+ .io_jtag_tdo(io_G16),
+ .io_jtag_tms(io_F15),
+ .io_gpioA_read (io_gpioA_read),
+ .io_gpioA_write (io_gpioA_write),
+ .io_gpioA_writeEnable(io_gpioA_writeEnable),
+ .io_uart_txd(io_B12),
+ .io_uart_rxd(io_B10)
+ );\t\t
+endmodule"
+"module toplevel_pll(REFERENCECLK,
+ PLLOUTCORE,
+ PLLOUTGLOBAL,
+ RESET);
+
+input REFERENCECLK;
+input RESET; /* To initialize the simulation properly, the RESET signal (Active Low) must be asserted at the beginning of the simulation */
+output PLLOUTCORE;
+output PLLOUTGLOBAL;
+
+SB_PLL40_CORE toplevel_pll_inst(.REFERENCECLK(REFERENCECLK),
+ .PLLOUTCORE(PLLOUTCORE),
+ .PLLOUTGLOBAL(PLLOUTGLOBAL),
+ .EXTFEEDBACK(),
+ .DYNAMICDELAY(),
+ .RESETB(RESET),
+ .BYPASS(1\'b0),
+ .LATCHINPUTVALUE(),
+ .LOCK(),
+ .SDI(),
+ .SDO(),
+ .SCLK());
+
+//\\\\ Fin=100, Fout=12;
+defparam toplevel_pll_inst.DIVR = 4\'b0010;
+defparam toplevel_pll_inst.DIVF = 7\'b0010110;
+defparam toplevel_pll_inst.DIVQ = 3\'b110;
+defparam toplevel_pll_inst.FILTER_RANGE = 3\'b011;
+defparam toplevel_pll_inst.FEEDBACK_PATH = ""SIMPLE"";
+defparam toplevel_pll_inst.DELAY_ADJUSTMENT_MODE_FEEDBACK = ""FIXED"";
+defparam toplevel_pll_inst.FDA_FEEDBACK = 4\'b0000;
+defparam toplevel_pll_inst.DELAY_ADJUSTMENT_MODE_RELATIVE = ""FIXED"";
+defparam toplevel_pll_inst.FDA_RELATIVE = 4\'b0000;
+defparam toplevel_pll_inst.SHIFTREG_DIV_MODE = 2\'b00;
+defparam toplevel_pll_inst.PLLOUT_SELECT = ""GENCLK"";
+defparam toplevel_pll_inst.ENABLE_ICEGATE = 1\'b0;
+
+endmodule
+"
+"`timescale 1ns / 1ps
+
+module toplevel(
+ input wire clk100,
+ input wire cpu_reset,//active low
+
+ input wire tck,
+ input wire tms,
+ input wire tdi,
+ input wire trst,//ignored
+ output reg tdo,
+
+ input wire serial_rx,
+ output wire serial_tx,
+
+ input wire user_sw0,
+ input wire user_sw1,
+ input wire user_sw2,
+ input wire user_sw3,
+
+ input wire user_btn0,
+ input wire user_btn1,
+ input wire user_btn2,
+ input wire user_btn3,
+
+ output wire user_led0,
+ output wire user_led1,
+ output wire user_led2,
+ output wire user_led3
+ );
+
+ wire [31:0] io_gpioA_read;
+ wire [31:0] io_gpioA_write;
+ wire [31:0] io_gpioA_writeEnable;
+
+ wire io_asyncReset = ~cpu_reset;
+
+ assign {user_led3,user_led2,user_led1,user_led0} = io_gpioA_write[3 : 0];
+ assign io_gpioA_read[3:0] = {user_sw3,user_sw2,user_sw1,user_sw0};
+ assign io_gpioA_read[7:4] = {user_btn3,user_btn2,user_btn1,user_btn0};
+ assign io_gpioA_read[11:8] = {tck,tms,tdi,trst};
+
+ reg tesic_tck,tesic_tms,tesic_tdi;
+ wire tesic_tdo;
+ reg soc_tck,soc_tms,soc_tdi;
+ wire soc_tdo;
+
+ always @(*) begin
+ {soc_tck, soc_tms, soc_tdi } = {tck,tms,tdi};
+ tdo = soc_tdo;
+ end
+
+ Murax core (
+ .io_asyncReset(io_asyncReset),
+ .io_mainClk (clk100 ),
+ .io_jtag_tck(soc_tck),
+ .io_jtag_tdi(soc_tdi),
+ .io_jtag_tdo(soc_tdo),
+ .io_jtag_tms(soc_tms),
+ .io_gpioA_read (io_gpioA_read),
+ .io_gpioA_write (io_gpioA_write),
+ .io_gpioA_writeEnable(io_gpioA_writeEnable),
+ .io_uart_txd(serial_tx),
+ .io_uart_rxd(serial_rx)
+ );
+endmodule
+"
+"`timescale 1ns / 1ps
+
+module toplevel(
+ input CLK,
+ input BUT1,
+ input BUT2,
+ output LED1,
+ output LED2
+ );
+
+ assign LED1 = io_gpioA_write[0];
+ assign LED2 = io_gpioA_write[7];
+
+ wire [31:0] io_gpioA_read;
+ wire [31:0] io_gpioA_write;
+ wire [31:0] io_gpioA_writeEnable;
+ wire io_mainClk;
+
+ // Use PLL to downclock external clock.
+ toplevel_pll toplevel_pll_inst(.REFERENCECLK(CLK),
+ .PLLOUTCORE(io_mainClk),
+ .PLLOUTGLOBAL(),
+ .RESET(1'b1));
+
+ Murax murax (
+ .io_asyncReset(1'b0),
+ .io_mainClk (io_mainClk),
+ .io_jtag_tck(1'b0),
+ .io_jtag_tdi(1'b0),
+ .io_jtag_tdo(),
+ .io_jtag_tms(1'b0),
+ .io_gpioA_read (io_gpioA_read),
+ .io_gpioA_write (io_gpioA_write),
+ .io_gpioA_writeEnable(io_gpioA_writeEnable),
+ .io_uart_txd(),
+ .io_uart_rxd(0'b0)
+ );
+
+endmodule
+"
+"module ghrd_10m50da_top (
+ //Clock and Reset
+ input wire clk_50,
+ input wire fpga_reset_n,
+ //QSPI
+// output wire \t qspi_clk,
+// inout wire[3:0] qspi_io,
+// output wire qspi_csn,
+ //16550 UART
+ input wire\t uart_rx,
+ output wire \t\t uart_tx,
+ output wire [4:0] user_led
+);
+//Heart-beat counter
+reg [25:0] heart_beat_cnt;
+
+// SoC sub-system module
+ghrd_10m50da ghrd_10m50da_inst (
+\t\t.clk_clk (clk_50),
+\t\t.reset_reset_n (fpga_reset_n),
+//\t\t.ext_flash_flash_dataout_conduit_dataout (qspi_io),
+//\t\t.ext_flash_flash_dclk_out_conduit_dclk_out (qspi_clk),
+//\t\t.ext_flash_flash_ncs_conduit_ncs (qspi_csn),
+\t\t//16550 UART
+\t\t.a_16550_uart_0_rs_232_serial_sin (uart_rx), // a_16550_uart_0_rs_232_serial.sin
+\t\t.a_16550_uart_0_rs_232_serial_sout (uart_tx), // .sout
+\t\t.a_16550_uart_0_rs_232_serial_sout_oe () // .sout_oe
+);
+
+
+
+//Heart beat by 50MHz clock
+always @(posedge clk_50 or negedge fpga_reset_n)
+ if (!fpga_reset_n)
+ heart_beat_cnt <= 26'h0; //0x3FFFFFF
+ else
+ heart_beat_cnt <= heart_beat_cnt + 1'b1;
+
+assign user_led = {4'hf,heart_beat_cnt[25]};
+
+
+endmodule
+
+
+"
+"@00000000\r
+13 0E 10 00 B3 00 00 06 63 9C 00 08 13 0E 20 00 \r
+93 00 00 00 13 01 00 00 B3 80 20 06 63 92 00 08 \r
+13 0E 30 00 B7 00 02 01 93 80 40 30 13 01 00 00 \r
+B3 81 20 06 63 96 11 06 13 0E 40 00 37 12 06 03 \r
+13 02 C2 90 B7 00 02 01 93 80 40 30 37 01 04 02 \r
+13 01 81 60 B3 81 20 06 63 94 41 04 13 0E 50 00 \r
+37 02 00 FF 13 02 22 10 93 00 F0 FF 37 01 01 00 \r
+13 01 31 20 B3 81 20 06 63 94 41 02 13 0E 60 00 \r
+93 02 60 00 93 00 10 00 13 01 20 00 93 01 30 00 \r
+B3 80 20 06 B3 80 30 06 63 94 50 00 6F 00 00 01 \r
+37 01 10 F0 13 01 41 F2 23 20 C1 01 37 01 10 F0 \r
+13 01 01 F2 23 20 01 00 13 00 00 00 13 00 00 00 \r
+13 00 00 00 13 00 00 00 13 00 00 00 13 00 00 00 \r
+"
+"@00000000\r
+6F 00 C0 04 13 00 00 00 13 00 00 00 13 00 00 00 \r
+13 00 00 00 13 00 00 00 13 00 00 00 13 00 00 00 \r
+F3 2E 00 30 93 FE 0E 08 63 8A 0E 00 B7 2E 00 00 \r
+93 8E 0E 80 73 90 0E 30 73 00 20 30 F3 2E 10 34 \r
+93 8E 4E 00 73 90 1E 34 73 00 20 30 13 0E 10 00 \r
+37 05 00 10 93 05 40 06 13 06 50 06 93 06 60 06 \r
+23 20 D5 00 2F 26 B5 18 13 07 10 00 63 18 E6 2E \r
+03 27 05 00 63 94 E6 2E 13 0E 20 00 37 05 00 10 \r
+13 05 45 00 93 05 70 06 13 06 80 06 93 06 90 06 \r
+23 20 D5 00 2F 26 B5 18 13 07 10 00 63 10 E6 2C \r
+03 27 05 00 63 9C E6 2A 13 0E 30 00 37 05 00 10 \r
+13 05 45 00 93 05 70 06 13 06 80 06 93 06 90 06 \r
+2F 26 B5 18 13 07 10 00 63 1A E6 28 03 27 05 00 \r
+63 96 E6 28 13 0E 40 00 37 05 00 10 13 05 85 00 \r
+93 05 A0 06 13 06 B0 06 93 06 C0 06 23 20 D5 00 \r
+AF 27 05 10 2F 26 B5 18 63 92 D7 26 63 10 06 26 \r
+03 27 05 00 63 9C E5 24 13 0E 50 00 37 05 00 10 \r
+13 05 85 00 93 05 D0 06 13 06 E0 06 93 06 F0 06 \r
+23 20 D5 00 2F 26 B5 18 63 1A 06 22 03 27 05 00 \r
+63 96 E5 22 13 0E 60 00 37 05 00 10 13 05 C5 00 \r
+93 05 00 07 13 06 10 07 93 06 20 07 37 04 00 10 \r
+13 04 04 01 93 04 30 07 13 09 40 07 93 09 50 07 \r
+23 20 D5 00 23 20 34 01 AF 27 05 10 AF 2A 04 10 \r
+2F 26 B5 18 2F 29 94 18 63 92 D7 1E 63 10 06 1E \r
+03 27 05 00 63 9C E5 1C 63 9A 3A 1D 63 18 09 1C \r
+03 2A 04 00 63 94 44 1D 13 0E 70 00 37 05 00 10 \r
+13 05 45 01 93 05 80 07 13 06 90 07 93 06 A0 07 \r
+93 0E 00 01 23 20 D5 00 AF 27 05 10 2F 26 B5 18 \r
+63 9E D7 18 63 1C 06 18 03 27 05 00 63 98 E5 18 \r
+93 8E FE FF 13 05 45 00 93 85 35 00 13 06 36 00 \r
+93 86 36 00 E3 98 0E FC 13 0E 80 00 37 05 00 10 \r
+13 05 85 01 93 05 80 07 13 06 90 07 93 06 A0 07 \r
+83 27 05 00 2F 26 B5 18 13 07 10 00 63 18 E6 14 \r
+03 27 05 00 63 94 E7 14 13 0E 90 00 37 05 00 10 \r
+13 05 05 10 93 05 B0 07 13 06 C0 07 93 06 D0 07 \r
+23 20 D5 00 AF 27 05 10 73 00 00 00 2F 26 B5 18 \r
+13 07 10 00 63 1C E6 10 03 27 05 00 63 98 E6 10 \r
+13 0E A0 00 37 05 00 10 13 05 05 20 37 08 00 10 \r
+13 08 48 20 93 05 E0 07 13 06 F0 07 93 06 00 08 \r
+93 08 10 08 23 20 D5 00 23 20 18 01 AF 27 08 10 \r
+2F 26 B5 18 13 07 10 00 63 1A E6 0C 03 27 08 00 \r
+63 96 E8 0C 13 0E B0 00 37 05 00 10 13 05 05 30 \r
+93 05 20 08 13 06 30 08 93 06 40 08 23 20 D5 00 \r
+B7 1E 00 00 93 8E 0E 80 73 90 4E 30 93 0E 80 00 \r
+AF 27 05 10 73 90 0E 30 13 00 00 00 13 00 00 00 \r
+13 00 00 00 13 00 00 00 13 00 00 00 13 00 00 00 \r
+2F 26 B5 18 13 07 10 00 63 1A E6 06 03 27 05 00 \r
+63 96 E6 06 13 0E C0 00 37 05 00 10 13 05 05 40 \r
+93 05 C0 08 13 06 D0 08 93 06 E0 08 23 20 D5 00 \r
+B7 1E 00 00 93 8E 0E 80 73 90 4E 30 B7 2E 00 00 \r
+93 8E 8E 80 AF 27 05 10 73 90 0E 30 13 00 00 00 \r
+13 00 00 00 13 00 00 00 13 00 00 00 13 00 00 00 \r
+13 00 00 00 2F 26 B5 18 13 07 10 00 63 18 E6 00 \r
+03 27 05 00 63 94 E6 00 6F 00 00 01 37 01 10 F0 \r
+13 01 41 F2 23 20 C1 01 37 01 10 F0 13 01 01 F2 \r
+23 20 01 00 13 00 00 00 13 00 00 00 13 00 00 00 \r
+13 00 00 00 13 00 00 00 13 00 00 00 \r
+"
+"@00000000\r
+13 0E 10 00 F3 20 40 B0 73 21 40 B0 F3 21 40 B0 \r
+63 48 11 06 63 C6 21 06 13 0E 20 00 B7 C0 5D 00 \r
+93 80 A0 98 73 90 40 B0 73 21 40 B0 63 4A 11 04 \r
+13 0E 30 00 F3 20 50 B0 73 21 50 B0 F3 21 50 B0 \r
+63 D0 20 04 63 5E 31 02 13 0E 40 00 73 90 60 B0 \r
+F3 20 40 B0 13 01 00 10 63 F4 20 02 13 0E 50 00 \r
+F3 20 70 B0 F3 20 40 B0 37 01 00 40 13 01 01 10 \r
+B7 01 00 40 63 F6 20 00 63 E4 30 00 6F 00 00 01 \r
+37 01 10 F0 13 01 41 F2 23 20 C1 01 37 01 10 F0 \r
+13 01 01 F2 23 20 01 00 13 00 00 00 13 00 00 00 \r
+13 00 00 00 13 00 00 00 13 00 00 00 13 00 00 00 \r
+"
+"// megafunction wizard: %ROM: 1-PORT%\r
+// GENERATION: STANDARD\r
+// VERSION: WM1.0\r
+// MODULE: altsyncram \r
+\r
+// ============================================================\r
+// File Name: memory.v\r
+// Megafunction Name(s):\r
+// \t\t\taltsyncram\r
+//\r
+// Simulation Library Files(s):\r
+// \t\t\taltera_mf\r
+// ============================================================\r
+// ************************************************************\r
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!\r
+//\r
+// 13.0.1 Build 232 06/12/2013 SP 1 SJ Web Edition\r
+// ************************************************************\r
+\r
+\r
+//Copyright (C) 1991-2013 Altera Corporation\r
+//Your use of Altera Corporation\'s design tools, logic functions \r
+//and other software and tools, and its AMPP partner logic \r
+//functions, and any output files from any of the foregoing \r
+//(including device programming or simulation files), and any \r
+//associated documentation or information are expressly subject \r
+//to the terms and conditions of the Altera Program License \r
+//Subscription Agreement, Altera MegaCore Function License \r
+//Agreement, or other applicable license agreement, including, \r
+//without limitation, that your use is for the sole purpose of \r
+//programming logic devices manufactured by Altera and sold by \r
+//Altera or its authorized distributors. Please refer to the \r
+//applicable agreement for further details.\r
+\r
+\r
+// synopsys translate_off\r
+`timescale 1 ps / 1 ps\r
+// synopsys translate_on\r
+module memory (\r
+\taddress,\r
+\tclock,\r
+\tq);\r
+\r
+\tinput\t[4:0] address;\r
+\tinput\t clock;\r
+\toutput\t[8:0] q;\r
+`ifndef ALTERA_RESERVED_QIS\r
+// synopsys translate_off\r
+`endif\r
+\ttri1\t clock;\r
+`ifndef ALTERA_RESERVED_QIS\r
+// synopsys translate_on\r
+`endif\r
+\r
+\twire [8:0] sub_wire0;\r
+\twire [8:0] q = sub_wire0[8:0];\r
+\r
+\taltsyncram\taltsyncram_component (\r
+\t\t\t\t.address_a (address),\r
+\t\t\t\t.clock0 (clock),\r
+\t\t\t\t.q_a (sub_wire0),\r
+\t\t\t\t.aclr0 (1\'b0),\r
+\t\t\t\t.aclr1 (1\'b0),\r
+\t\t\t\t.address_b (1\'b1),\r
+\t\t\t\t.addressstall_a (1\'b0),\r
+\t\t\t\t.addressstall_b (1\'b0),\r
+\t\t\t\t.byteena_a (1\'b1),\r
+\t\t\t\t.byteena_b (1\'b1),\r
+\t\t\t\t.clock1 (1\'b1),\r
+\t\t\t\t.clocken0 (1\'b1),\r
+\t\t\t\t.clocken1 (1\'b1),\r
+\t\t\t\t.clocken2 (1\'b1),\r
+\t\t\t\t.clocken3 (1\'b1),\r
+\t\t\t\t.data_a ({9{1\'b1}}),\r
+\t\t\t\t.data_b (1\'b1),\r
+\t\t\t\t.eccstatus (),\r
+\t\t\t\t.q_b (),\r
+\t\t\t\t.rden_a (1\'b1),\r
+\t\t\t\t.rden_b (1\'b1),\r
+\t\t\t\t.wren_a (1\'b0),\r
+\t\t\t\t.wren_b (1\'b0));\r
+\tdefparam\r
+\t\taltsyncram_component.clock_enable_input_a = ""BYPASS"",\r
+\t\taltsyncram_component.clock_enable_output_a = ""BYPASS"",\r
+\t\taltsyncram_component.init_file = ""inst_mem.mif"",\r
+\t\taltsyncram_component.intended_device_family = ""Cyclone II"",\r
+\t\taltsyncram_component.lpm_hint = ""ENABLE_RUNTIME_MOD=NO"",\r
+\t\taltsyncram_component.lpm_type = ""altsyncram"",\r
+\t\taltsyncram_component.numwords_a = 32,\r
+\t\taltsyncram_component.operation_mode = ""ROM"",\r
+\t\taltsyncram_component.outdata_aclr_a = ""NONE"",\r
+\t\taltsyncram_component.outdata_reg_a = ""UNREGISTERED"",\r
+\t\taltsyncram_component.widthad_a = 5,\r
+\t\taltsyncram_component.width_a = 9,\r
+\t\taltsyncram_component.width_byteena_a = 1;\r
+\r
+\r
+endmodule\r
+\r
+// ============================================================\r
+// CNX file retrieval info\r
+// ============================================================\r
+// Retrieval info: PRIVATE: ADDRESSSTALL_A NUMERIC ""0""\r
+// Retrieval info: PRIVATE: AclrAddr NUMERIC ""0""\r
+// Retrieval info: PRIVATE: AclrByte NUMERIC ""0""\r
+// Retrieval info: PRIVATE: AclrOutput NUMERIC ""0""\r
+// Retrieval info: PRIVATE: BYTE_ENABLE NUMERIC ""0""\r
+// Retrieval info: PRIVATE: BYTE_SIZE NUMERIC ""9""\r
+// Retrieval info: PRIVATE: BlankMemory NUMERIC ""0""\r
+// Retrieval info: PRIVATE: CLOCK_ENABLE_INPUT_A NUMERIC ""0""\r
+// Retrieval info: PRIVATE: CLOCK_ENABLE_OUTPUT_A NUMERIC ""0""\r
+// Retrieval info: PRIVATE: Clken NUMERIC ""0""\r
+// Retrieval info: PRIVATE: IMPLEMENT_IN_LES NUMERIC ""0""\r
+// Retrieval info: PRIVATE: INIT_FILE_LAYOUT STRING ""PORT_A""\r
+// Retrieval info: PRIVATE: INIT_TO_SIM_X NUMERIC ""0""\r
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""\r
+// Retrieval info: PRIVATE: JTAG_ENABLED NUMERIC ""0""\r
+// Retrieval info: PRIVATE: JTAG_ID STRING ""NONE""\r
+// Retrieval info: PRIVATE: MAXIMUM_DEPTH NUMERIC ""0""\r
+// Retrieval info: PRIVATE: MIFfilename STRING ""inst_mem.mif""\r
+// Retrieval info: PRIVATE: NUMWORDS_A NUMERIC ""32""\r
+// Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC ""0""\r
+// Retrieval info: PRIVATE: RegAddr NUMERIC ""1""\r
+// Retrieval info: PRIVATE: RegOutput NUMERIC ""0""\r
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING ""0""\r
+// Retrieval info: PRIVATE: SingleClock NUMERIC ""1""\r
+// Retrieval info: PRIVATE: UseDQRAM NUMERIC ""0""\r
+// Retrieval info: PRIVATE: WidthAddr NUMERIC ""5""\r
+// Retrieval info: PRIVATE: WidthData NUMERIC ""9""\r
+// Retrieval info: PRIVATE: rden NUMERIC ""0""\r
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all\r
+// Retrieval info: CONSTANT: CLOCK_ENABLE_INPUT_A STRING ""BYPASS""\r
+// Retrieval info: CONSTANT: CLOCK_ENABLE_OUTPUT_A STRING ""BYPASS""\r
+// Retrieval info: CONSTANT: INIT_FILE STRING ""inst_mem.mif""\r
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""\r
+// Retrieval info: CONSTANT: LPM_HINT STRING ""ENABLE_RUNTIME_MOD=NO""\r
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""altsyncram""\r
+// Retrieval info: CONSTANT: NUMWORDS_A NUMERIC ""32""\r
+// Retrieval info: CONSTANT: OPERATION_MODE STRING ""ROM""\r
+// Retrieval info: CONSTANT: OUTDATA_ACLR_A STRING ""NONE""\r
+// Retrieval info: CONSTANT: OUTDATA_REG_A STRING ""UNREGISTERED""\r
+// Retrieval info: CONSTANT: WIDTHAD_A NUMERIC ""5""\r
+// Retrieval info: CONSTANT: WIDTH_A NUMERIC ""9""\r
+// Retrieval info: CONSTANT: WIDTH_BYTEENA_A NUMERIC ""1""\r
+// Retrieval info: USED_PORT: address 0 0 5 0 INPUT NODEFVAL ""address[4..0]""\r
+// Retrieval info: USED_PORT: clock 0 0 0 0 INPUT VCC ""clock""\r
+// Retrieval info: USED_PORT: q 0 0 9 0 OUTPUT NODEFVAL ""q[8..0]""\r
+// Retrieval info: CONNECT: @address_a 0 0 5 0 address 0 0 5 0\r
+// Retrieval info: CONNECT: @clock0 0 0 0 0 clock 0 0 0 0\r
+// Retrieval info: CONNECT: q 0 0 9 0 @q_a 0 0 9 0\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL memory.v TRUE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL memory.inc FALSE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL memory.cmp FALSE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL memory.bsf FALSE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL memory_inst.v TRUE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL memory_bb.v TRUE\r
+// Retrieval info: LIB_FILE: altera_mf\r
+"
+"/**\r
+ * Embedded Systems (EECE6017C) - Lab 3\r
+ * Simple Processor\r
+ * Author(s): Alex Stephens (AWS)\r
+ *\t \t Josh Boroff (JBB)\r
+ *\t \t Adam Wilford (AFW)\r
+ * Target FPGA: Altera Cyclone II 2C20 (EP2C20F484C7)\r
+ * Tool: Quartus II 64-bit\r
+ * Version: 13.0.1 sp1\r
+ *\r
+ * Development Log:\r
+ * Date\t\tDeveloper\tDescription\r
+ * 09 18 13 \t\t\t\tInitial development\r
+ * 09 19 13\tAWS\t\t\tAdded GPRs and associated control signals. Defined bus drivers.\r
+ */\r
+\r
+/**\r
+ * Module mem - The top level module that contains the memory, counter, and proc to do processor operations to memory\r
+ * mclock - the clock used for the memory \r
+ * pclock - the clock used for the processor\r
+ * resetn - the reset button for the systems\r
+ * run - the trigger used for running the system command\r
+ * done - the signal released when an operation has completed\r
+ * bus - the output of the bus lines \r
+ */\r
+module mem(mclock, pclock, resetn, run, done, bus);\r
+\t\r
+\tinput mclock, pclock, resetn, run;\r
+\toutput done;\r
+\toutput [8:0] bus;\r
+\t\r
+\t\r
+\twire [4:0] n;//data wire between the counter module and the memory module\r
+\twire [8:0] data;//data wire between memory and proc transfer\r
+\t\r
+\tcounter count(mclock, resetn, n);//the module for counting\r
+\t\r
+\tmemory memory_control(n, mclock, data);// the module for memory\r
+\t\r
+\tproc processor(data, resetn, pclock, run, done, bus);// the module for the processor\r
+\t\r
+endmodule\r
+"
+"/**\r
+ * Embedded Systems (EECE6017C) - Lab 3\r
+ * Simple Processor\r
+ * Author(s): Alex Stephens (AWS)\r
+ *\t \t Josh Boroff (JBB)\r
+ *\t \t Adam Wilford (AFW)\r
+ * Target FPGA: Altera Cyclone II 2C20 (EP2C20F484C7)\r
+ * Tool: Quartus II 64-bit\r
+ * Version: 13.0.1 sp1\r
+ *\r
+ */\r
+\r
+/**\r
+ * Module counter - This module is used to increment a count of 5 bits\r
+ * clock - synchronizes this counter with another system\r
+ * reset - input for when the counter should be reset to 0\r
+ * countEn - Enable counting\r
+ * load - Put the loadVal into the counter\r
+ * loadVal - Value to start the counter at\r
+ * n - The output value of the counter\r
+ */\r
+\r
+module counter(clock, reset, countEn, load, loadVal, n);\r
+\tinput clock, enable, load, reset;\r
+\tinput [8:0] loadVal;\r
+\toutput reg [8:0] n;\r
+\t\r
+\tinitial n = 9\'b000000000;\r
+\t\r
+\talways @(posedge clock or negedge reset or posedge load or posedge countEn) \r
+\tbegin\r
+\t\tif(!reset) n = 9\'b000000000;//reset to 0\r
+\t\telse if(clock) begin\r
+\t\t\tif(!load && countEn) begin\r
+\t\t\t\tn = n + 1;//increment\r
+\t\t\tend\r
+\t\t\telse if(load && !countEn) begin\r
+\t\t\t\tn = loadVal;\r
+\t\t\tend\t\r
+\t\t\telse if(load && countEn) begin\r
+\t\t\t\t$display(""Load and countEn both high! They should not both be high at the same time! Loading loadVal+1\
+"");\r
+\t\t\t\tn = loadVal + 1;\r
+\t\t\tend\r
+\t\t\telse begin\r
+\t\t\t\t// do nothing\r
+\t\t\tend\r
+\t\tend\r
+\tend\r
+endmodule"
+"/**\r
+ * Embedded Systems (EECE6017C) - Lab 3\r
+ * Simple Processor\r
+ * Author(s): Alex Stephens (AWS)\r
+ *\t \t Josh Boroff (JBB)\r
+ *\t \t Adam Wilford (AFW)\r
+ * Target FPGA: Altera Cyclone II 2C20 (EP2C20F484C7)\r
+ * Tool: Quartus II 64-bit\r
+ * Version: 13.0.1 sp1\r
+ *\r
+ * Development Log:\r
+ */\r
+\r
+/**\r
+ * Module dec3to8 - used to change the 3 bit instructions, x's, and y's into 8 bits\r
+ * W - the 3 bit input\r
+ * En - the enable\r
+ * Y - the output of the 3 bits into 8 bits\r
+ */\r
+module dec3to8(W, En, Y); //change\r
+\tinput [2:0] W;\r
+\tinput En;\r
+\toutput [0:7] Y;\r
+\treg [0:7] Y;\r
+\talways @(W or En)\r
+\tbegin\r
+\t\tif (En == 1)\r
+\t\t\tcase (W)\r
+\t\t\t\t3'b000: Y = 8'b10000000;\r
+\t\t\t\t3'b001: Y = 8'b01000000;\r
+\t\t\t\t3'b010: Y = 8'b00100000;\r
+\t\t\t\t3'b011: Y = 8'b00010000;\r
+\t\t\t\t3'b100: Y = 8'b00001000;\r
+\t\t\t\t3'b101: Y = 8'b00000100;\r
+\t\t\t\t3'b110: Y = 8'b00000010;\r
+\t\t\t\t3'b111: Y = 8'b00000001;\r
+\t\t\tendcase\r
+\t\telse\r
+\t\t\tY = 8'b00000000;\r
+\tend\r
+endmodule"
+"// megafunction wizard: %ROM: 1-PORT%VBB%\r
+// GENERATION: STANDARD\r
+// VERSION: WM1.0\r
+// MODULE: altsyncram \r
+\r
+// ============================================================\r
+// File Name: memory.v\r
+// Megafunction Name(s):\r
+// \t\t\taltsyncram\r
+//\r
+// Simulation Library Files(s):\r
+// \t\t\taltera_mf\r
+// ============================================================\r
+// ************************************************************\r
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!\r
+//\r
+// 13.0.1 Build 232 06/12/2013 SP 1 SJ Web Edition\r
+// ************************************************************\r
+\r
+//Copyright (C) 1991-2013 Altera Corporation\r
+//Your use of Altera Corporation\'s design tools, logic functions \r
+//and other software and tools, and its AMPP partner logic \r
+//functions, and any output files from any of the foregoing \r
+//(including device programming or simulation files), and any \r
+//associated documentation or information are expressly subject \r
+//to the terms and conditions of the Altera Program License \r
+//Subscription Agreement, Altera MegaCore Function License \r
+//Agreement, or other applicable license agreement, including, \r
+//without limitation, that your use is for the sole purpose of \r
+//programming logic devices manufactured by Altera and sold by \r
+//Altera or its authorized distributors. Please refer to the \r
+//applicable agreement for further details.\r
+\r
+module memory (\r
+\taddress,\r
+\tclock,\r
+\tq);\r
+\r
+\tinput\t[4:0] address;\r
+\tinput\t clock;\r
+\toutput\t[8:0] q;\r
+`ifndef ALTERA_RESERVED_QIS\r
+// synopsys translate_off\r
+`endif\r
+\ttri1\t clock;\r
+`ifndef ALTERA_RESERVED_QIS\r
+// synopsys translate_on\r
+`endif\r
+\r
+endmodule\r
+\r
+// ============================================================\r
+// CNX file retrieval info\r
+// ============================================================\r
+// Retrieval info: PRIVATE: ADDRESSSTALL_A NUMERIC ""0""\r
+// Retrieval info: PRIVATE: AclrAddr NUMERIC ""0""\r
+// Retrieval info: PRIVATE: AclrByte NUMERIC ""0""\r
+// Retrieval info: PRIVATE: AclrOutput NUMERIC ""0""\r
+// Retrieval info: PRIVATE: BYTE_ENABLE NUMERIC ""0""\r
+// Retrieval info: PRIVATE: BYTE_SIZE NUMERIC ""9""\r
+// Retrieval info: PRIVATE: BlankMemory NUMERIC ""0""\r
+// Retrieval info: PRIVATE: CLOCK_ENABLE_INPUT_A NUMERIC ""0""\r
+// Retrieval info: PRIVATE: CLOCK_ENABLE_OUTPUT_A NUMERIC ""0""\r
+// Retrieval info: PRIVATE: Clken NUMERIC ""0""\r
+// Retrieval info: PRIVATE: IMPLEMENT_IN_LES NUMERIC ""0""\r
+// Retrieval info: PRIVATE: INIT_FILE_LAYOUT STRING ""PORT_A""\r
+// Retrieval info: PRIVATE: INIT_TO_SIM_X NUMERIC ""0""\r
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""\r
+// Retrieval info: PRIVATE: JTAG_ENABLED NUMERIC ""0""\r
+// Retrieval info: PRIVATE: JTAG_ID STRING ""NONE""\r
+// Retrieval info: PRIVATE: MAXIMUM_DEPTH NUMERIC ""0""\r
+// Retrieval info: PRIVATE: MIFfilename STRING ""inst_mem.mif""\r
+// Retrieval info: PRIVATE: NUMWORDS_A NUMERIC ""32""\r
+// Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC ""0""\r
+// Retrieval info: PRIVATE: RegAddr NUMERIC ""1""\r
+// Retrieval info: PRIVATE: RegOutput NUMERIC ""0""\r
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING ""0""\r
+// Retrieval info: PRIVATE: SingleClock NUMERIC ""1""\r
+// Retrieval info: PRIVATE: UseDQRAM NUMERIC ""0""\r
+// Retrieval info: PRIVATE: WidthAddr NUMERIC ""5""\r
+// Retrieval info: PRIVATE: WidthData NUMERIC ""9""\r
+// Retrieval info: PRIVATE: rden NUMERIC ""0""\r
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all\r
+// Retrieval info: CONSTANT: CLOCK_ENABLE_INPUT_A STRING ""BYPASS""\r
+// Retrieval info: CONSTANT: CLOCK_ENABLE_OUTPUT_A STRING ""BYPASS""\r
+// Retrieval info: CONSTANT: INIT_FILE STRING ""inst_mem.mif""\r
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""\r
+// Retrieval info: CONSTANT: LPM_HINT STRING ""ENABLE_RUNTIME_MOD=NO""\r
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""altsyncram""\r
+// Retrieval info: CONSTANT: NUMWORDS_A NUMERIC ""32""\r
+// Retrieval info: CONSTANT: OPERATION_MODE STRING ""ROM""\r
+// Retrieval info: CONSTANT: OUTDATA_ACLR_A STRING ""NONE""\r
+// Retrieval info: CONSTANT: OUTDATA_REG_A STRING ""UNREGISTERED""\r
+// Retrieval info: CONSTANT: WIDTHAD_A NUMERIC ""5""\r
+// Retrieval info: CONSTANT: WIDTH_A NUMERIC ""9""\r
+// Retrieval info: CONSTANT: WIDTH_BYTEENA_A NUMERIC ""1""\r
+// Retrieval info: USED_PORT: address 0 0 5 0 INPUT NODEFVAL ""address[4..0]""\r
+// Retrieval info: USED_PORT: clock 0 0 0 0 INPUT VCC ""clock""\r
+// Retrieval info: USED_PORT: q 0 0 9 0 OUTPUT NODEFVAL ""q[8..0]""\r
+// Retrieval info: CONNECT: @address_a 0 0 5 0 address 0 0 5 0\r
+// Retrieval info: CONNECT: @clock0 0 0 0 0 clock 0 0 0 0\r
+// Retrieval info: CONNECT: q 0 0 9 0 @q_a 0 0 9 0\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL memory.v TRUE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL memory.inc FALSE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL memory.cmp FALSE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL memory.bsf FALSE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL memory_inst.v TRUE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL memory_bb.v TRUE\r
+// Retrieval info: LIB_FILE: altera_mf\r
+"
+"/**\r
+ * Embedded Systems (EECE6017C) - Lab 3\r
+ * Simple Processor\r
+ * Author(s): Alex Stephens (AWS)\r
+ *\t \t Josh Boroff (JBB)\r
+ *\t \t Adam Wilford (AFW)\r
+ * Target FPGA: Altera Cyclone II 2C20 (EP2C20F484C7)\r
+ * Tool: Quartus II 64-bit\r
+ * Version: 13.0.1 sp1\r
+ *\r
+ */\r
+\r
+/**\r
+ * Module regn - this module is used to create the registers from example code\r
+ * R - Bus wires for inputing into the reg\r
+ * Rin - the input signal to say if data needs out\r
+ * Clock - the clock for things to happen\r
+ * Q - the output of what is in the reg\r
+ */\r
+module regn(R, Rin, Clock, Q);
+parameter n = 9;
+input [n-1:0] R;
+input Rin, Clock;
+output [n-1:0] Q;
+reg [n-1:0] Q;
+always @(posedge Clock)
+\tif (Rin)
+\t\tQ <= R;
+endmodule"
+"memory\tmemory_inst (\r
+\t.address ( address_sig ),\r
+\t.clock ( clock_sig ),\r
+\t.q ( q_sig )\r
+\t);\r
+"
+"/**
+ * Embedded Systems (EECE6017C) - Lab 3
+ * Simple Processor
+ * Author(s): Alex Stephens (AWS)
+ *\t \t Josh Boroff (JBB)
+ *\t \t Adam Wilford (AFW)
+ * Target FPGA: Altera Cyclone II 2C20 (EP2C20F484C7)
+ * Tool: Quartus II 64-bit
+ * Version: 13.0.1 sp1
+ *
+ * Development Log:
+ * Date\t\tDeveloper\tDescription
+ * 09 19 13\tAWS\t\t\tInitial
+ */
+
+/**
+ * module Addsub
+ * Adds or subtracts two 9-bit inputs
+ * Sub (1-bit) [in] - When this is asserted, this module will subtract the two numbers
+ * A (9-bit, Little Endian) [in] - First operand, 2's complement signed integer
+ * B (9-bit, Little Endian) [in] - Second operand, 2's complement signed integer
+ * Out (9-bit, Little Endian) [out] - Result of operation, 2's complement signed integer
+ */
+module addsub(Sub, A, B, Out);
+\tinput [8:0] A, B;
+\tinput Sub;
+\toutput [8:0] Out;
+\t
+\tassign Out = Sub ? A - B : A + B;
+\t
+endmodule"
+"/**\r
+ * Embedded Systems (EECE6017C) - Lab 4\r
+ * Simple Processor\r
+ * Author(s): Alex Stephens (AWS)\r
+ *\t \t Josh Boroff (JBB)\r
+ *\t \t Adam Wilford (AFW)\r
+ * Target FPGA: Altera Cyclone II 2C20 (EP2C20F484C7)\r
+ * Tool: Quartus II 64-bit\r
+ * Version: 13.0.1 sp1\r
+ *\r
+ * Development Log:\r
+ * Date\t\tDeveloper\tDescription\r
+ * 09 18 13 \t\t\t\tInitial development\r
+ * 09 19 13\tAWS\t\t\tAdded GPRs and associated control signals. Defined bus drivers.\r
+ * 09 25 13\t\t\t\t\tBegan development on enhanced version on new branch\r
+ */\r
+\r
+/**\r
+ * Module proc\r
+ * Enhanced processor with a 9-bit synchronous memory interface and program counter\r
+ * DIN (9-bit, Little Endian) [in] - Data input, values from memory are read in through this port.\r
+ * Resetn (1-bit) [in] - Active low reset\r
+ * Clock (1-bit) [in] - Enable for internal registers\r
+ * Run (1-bit) [in] - While hight, this signal will allow the processor to continue execution\r
+ * Done (1-bit) [out] - This signal goes high when an instruction has completed\r
+ * DOUT (9-bit, Little Endian) [out] - Data being sent to memory\r
+ * ADDR (9-bit, Little Endian) [out] - Address to access from memory\r
+ * W (1-bit) [out] - Memory write enable\r
+ */\r
+module proc (DIN, Resetn, Clock, Run, Done, DOUT, ADDR, W);\r
+\tinput [8:0] DIN;\r
+\tinput Resetn, Clock, Run;\r
+\toutput reg Done, W;\r
+\toutput reg [8:0] DOUT, ADDR;\r
+\r
+\r
+\tparameter T0 = 3\'b000, T1 = 3\'b001, T2 = 3\'b010, T3 = 3\'b011, T4 = 3\'b100;\r
+\tparameter mv = 3\'b000, mvi = 3\'b001, add = 3\'b010, sub = 3\'b011, ld = 3\'b100, st = 3\'b101, mvnz = 3\'b110;\r
+\tparameter reg0 = 10\'b1000000000,\r
+\t\t\t\t reg1 = 10\'b0100000000,\r
+\t\t\t\t reg2 = 10\'b0010000000,\r
+\t\t\t\t reg3 = 10\'b0001000000,\r
+\t\t\t\t reg4 = 10\'b0000100000,\r
+\t\t\t\t reg5 = 10\'b0000010000,\r
+\t\t\t\t reg6 = 10\'b0000001000,\r
+\t\t\t\t reg7 = 10\'b0000000100,\r
+\t\t\t\t gout = 10\'b0000000010,\r
+\t\t\t\t dinout = 10\'b0000000001;\r
+\t\r
+\t//declare variables\r
+\treg [1:0] Tstep_Q;\r
+\treg [1:0] Tstep_D;\r
+\twire [2:0] I;\r
+\twire [0:7] regX, regY; ///<-- These are 1-hot encoding, Big Endian!!\r
+\twire [8:0] IRoutWires;\r
+\twire [8:0] GinWires, GoutWires;\r
+\twire [8:0] AoutWires;\r
+\twire GNZ;\r
+\tand(GNZ, GoutWires[0],\r
+\t\t\t\tGoutWires[1],\r
+\t\t\t\tGoutWires[2],\r
+\t\t\t\tGoutWires[3],\r
+\t\t\t\tGoutWires[4],\r
+\t\t\t\tGoutWires[5],\r
+\t\t\t\tGoutWires[6],\r
+\t\t\t\tGoutWires[7],\r
+\t\t\t\tGoutWires[8]\r
+\t);\r
+\t// Register input signals\r
+\treg [0:7] Rin;\r
+\treg [0:9] busDriver; ///< [R0out, ..., R7out, Gout, DINout]\r
+\t\r
+\t// Control Signals\r
+\treg IRin, DINout, RYout, RYin, RXout, RXin, Ain, Gin, Gout, AddSub,\r
+\t\t PCincr, ADDRin, DOUTin;\r
+ \r
+\tassign I = IRoutWires[8:6];\r
+\tdec3to8 decX (IRoutWires[5:3], 1\'b1, regX);\r
+\tdec3to8 decY (IRoutWires[2:0], 1\'b1, regY);\r
+\t\t\r
+\t// Control FSM state table change\r
+ always @(Tstep_Q, Run, Done)\r
+ begin\r
+\t\tif(Done) begin\r
+\t\t\tTstep_D <= T0;\r
+\t\tend\r
+\t\telse begin\r
+ case (Tstep_Q)\r
+ T0: // data is loaded into IR in this time step\r
+\t\t\t\tbegin\r
+\t\t\t\tif(!Run)\r
+\t\t\t\t\tTstep_D <= T0;\r
+\t\t\t\telse\r
+\t\t\t\t\tTstep_D <= T1;\r
+\t\t\t\tend\r
+ T1:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tTstep_D <= T2;\r
+\t\t\t\tend\r
+\t\t\t\tT2:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tTstep_D <= T3;\r
+\t\t\t\tend\r
+\t\t\t\tT3:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tTstep_D <= T4;\r
+\t\t\t\tend\r
+\t\t\t\tT4:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tTstep_D <=T0;\r
+\t\t\t\tend\r
+ endcase\r
+\t end\r
+ end\r
+\r
+\t// Control FSM outputs\r
+\talways @(Tstep_Q or I or regX or regY)\r
+\tbegin\r
+\t\t//: : : specify initial values\r
+\t\tIRin <= 0;\r
+\t\tDone <= 0;\r
+\t\tDINout <= 0;\r
+\t\tRYout <= 0;\r
+\t\tRYin <= 0;\r
+\t\tRXout <= 0;\r
+\t\tRXin <= 0;\r
+\t\tAin <= 0;\r
+\t\tGin <= 0;\r
+\t\tGout <= 0;\r
+\t\tAddSub <= 0;\r
+\t\t//reg IRin, DINout, RYout, RYin, RXout, RXin, Ain, Gin, Gout, AddSub;\r
+\t\tcase (Tstep_Q)\r
+\t\tT0: // store DIN in IR in time step 0\r
+\t\t\tbegin\r
+\t\t\t//IRin <= 1;\r
+\t\t\t\tPCout <= 1;\r
+\t\t\t\tADDRin <= 1;\r
+\t\t\tend\r
+\t\tT1:\r
+\t\t\tbegin\r
+\t\t\t\tIRin <=1;\r
+\t\t\t\tPCincr <=1;\r
+\t\tT2: //define signals in time step 1\r
+\t\t\tcase (I)\r
+\t\t\t\tmv: \r
+\t\t\t\tbegin\r
+\t\t\t\t\tRYout <= 1;\r
+\t\t\t\t\tRXin <= 1;\r
+\t\t\t\t\tDone <= 1;\t\t\t\r
+\t\t\t\tend\r
+\t\t\t\tmvi:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tPCout <=1;\r
+\t\t\t\t\tADDRin <=1;\r
+\t\t\t\tend\r
+\t\t\t\tadd:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tRXout <= 1;\r
+\t\t\t\t\tAin <= 1;\r
+\t\t\t\tend\r
+\t\t\t\tsub:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tRXout <= 1;\r
+\t\t\t\t\tAin <= 1;\r
+\t\t\t\tend\r
+\t\t\t\tld:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tRYout <=1;\r
+\t\t\t\t\tADDRin <=1;\r
+\t\t\t\tend\r
+\t\t\t\tst:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tRYout <=1;\r
+\t\t\t\t\tADDRin <=1;\r
+\t\t\t\tend\r
+\t\t\t\tmvnz:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tif(GNZ)\r
+\t\t\t\t\tbegin\r
+\t\t\t\t\t\tRYout <=1;\r
+\t\t\t\t\t\tADDRin <=1;\r
+\t\t\t\t\tend\r
+\t\t\t\t\telse Done <= 1;\r
+\t\t\t\tend\r
+\t\t\t\tdefault:\r
+\t\t\t\tbegin\r
+\t\t\t\tIRin <= 0;\r
+\t\t\t\tDone <= 0;\r
+\t\t\t\tDINout <= 0;\r
+\t\t\t\tRYout <= 0;\r
+\t\t\t\tRYin <= 0;\r
+\t\t\t\tRXout <= 0;\r
+\t\t\t\tRXin <= 0;\r
+\t\t\t\tAin <= 0;\r
+\t\t\t\tGin <= 0;\r
+\t\t\t\tGout <= 0;\r
+\t\t\t\tAddSub <= 0;\r
+\t\t\t\tend\r
+\t\t\tendcase\r
+\t\tT3: //define signals in time step 3\r
+\t\t\tcase (I)\r
+\t\t\t\tmvi:\r
+\t\t\t\tbegin\t\r
+\t\t\t\t\tPCincr <=1;\r
+\t\t\t\t\tDINout <=1;\r
+\t\t\t\t\tRXin <=1;\r
+\t\t\t\t\tDone <=1;\r
+\t\t\t\tadd:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tRYout <= 1;\r
+\t\t\t\t\tGin <= 1;\t\t\t\t\r
+\t\t\t\tend\r
+\t\t\t\tsub:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tRYout <= 1;\r
+\t\t\t\t\tGin <= 1;\r
+\t\t\t\t\tAddSub <= 1;\r
+\t\t\t\tend\r
+\t\t\t\tld:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tDINout <=1;\r
+\t\t\t\t\tRXin <=1;\r
+\t\t\t\t\tDone <=1;\r
+\t\t\t\tend\r
+\t\t\t\tst:\r
+\t\t\t\tbegin\t\r
+\t\t\t\t\tRXout <=1;\r
+\t\t\t\t\tDOUTin <=1;\r
+\t\t\t\t\tW_D <=1;\r
+\t\t\t\t\tDone <=1;//This may need to be in another step unsure\r
+\t\t\t\tdefault:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tIRin <= 0;\r
+\t\t\t\t\tDone <= 0;\r
+\t\t\t\t\tDINout <= 0;\r
+\t\t\t\t\tRYout <= 0;\r
+\t\t\t\t\tRYin <= 0;\r
+\t\t\t\t\tRXout <= 0;\r
+\t\t\t\t\tRXin <= 0;\r
+\t\t\t\t\tAin <= 0;\r
+\t\t\t\t\tGin <= 0;\r
+\t\t\t\t\tGout <= 0;\r
+\t\t\t\t\tAddSub <= 0;\r
+\t\t\t\tend\r
+\t\t\tendcase\r
+\t\tT4: //define signals in time step 3\r
+\t\t\tcase (I)\r
+\t\t\t\tadd:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tDone <= 1;\r
+\t\t\t\t\tGout <= 1;\r
+\t\t\t\t\tRXin <= 1;\r
+\t\t\t\tend\r
+\t\t\t\tsub:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tDone <= 1;\r
+\t\t\t\t\tRXin <= 1;\r
+\t\t\t\t\tGout <= 1;\t\t\t\t\r
+\t\t\t\tend\r
+\t\t\t\tdefault:\r
+\t\t\t\tbegin\r
+\t\t\t\t\tIRin <= 0;\r
+\t\t\t\t\tDone <= 0;\r
+\t\t\t\t\tDINout <= 0;\r
+\t\t\t\t\tRYout <= 0;\r
+\t\t\t\t\tRYin <= 0;\r
+\t\t\t\t\tRXout <= 0;\r
+\t\t\t\t\tRXin <= 0;\r
+\t\t\t\t\tAin <= 0;\r
+\t\t\t\t\tGin <= 0;\r
+\t\t\t\t\tGout <= 0;\r
+\t\t\t\t\tAddSub <= 0;\r
+\t\t\t\tend\r
+\t\t\tendcase\r
+\t\tendcase\r
+\tend\r
+\t\r
+\t// Control FSM flip-flops\r
+\talways @(posedge Clock, negedge Resetn) begin\r
+\t\tif (!Resetn) begin\r
+\t\t\t// Reset all FSM flip-flops\r
+\t\t\t/*\r
+\t\t\tbusDriver = dinout;\r
+\t\t\tDINout = 0;\r
+\t\t\tRYout = 0;\r
+\t\t\tRYin = 0;\r
+\t\t\tRXout = 0;\r
+\t\t\tRXin = 0;\r
+\t\t\tAin = 0;\r
+\t\t\tGin = 0;\r
+\t\t\tGout = 0;\r
+\t\t\tAddSub = 0;\r
+\t\t\tTstep_Q = 2\'b00;\r
+\t\t\tTstep_D = 2\'b00;\r
+\t\t\t*/\r
+\t\tend\r
+\t\telse Tstep_Q <= Tstep_D;\r
+\t\t\r
+\tend\r
+\t\r
+\t/** General Purpose Register Instantiations **/\r
+\t\r
+\t// Register outputs\r
+\twire [8:0] R0, R1, R2, R3, R4, R5, R6, R7;\r
+\t\r
+\t// General Purpose Registers\r
+\tregn reg_0(BusWires, Rin[0], Clock, R0);\r
+\r
+\tregn reg_1(BusWires, Rin[1], Clock, R1);\t\t\t\t\r
+\t\r
+\tregn reg_2(BusWires, Rin[2], Clock, R2);\r
+\t\t\t\t\r
+\tregn reg_3(BusWires, Rin[3], Clock, R3);\r
+\t\r
+\tregn reg_4(BusWires, Rin[4], Clock, R4);\r
+\t\r
+\tregn reg_5(BusWires, Rin[5], Clock, R5);\r
+\t\r
+\tregn reg_6(BusWires, Rin[6], Clock, R6);\r
+\t\r
+\tcounter reg_pc(Clock, Resetn, PCincr, Rin[7], R7);\r
+\t\r
+\t/** Register A **/\r
+\tregn reg_a(BusWires, Ain, Clock, AoutWires);\r
+\t\r
+\t/** Register G **/\r
+\r
+\tregn reg_g(GinWires, Gin, Clock, GoutWires);\r
+\t\r
+\t/** Instruction Register **/\r
+\tregn reg_ir(DIN, IRin, Clock, IRoutWires);\r
+\t\r
+\taddsub Addsub(AddSub, AoutWires, BusWires, GinWires);\r
+\t\r
+\r
+\talways @ (RXout, RYout, Gout, DINout, regX, regY)\r
+\tbegin // Check control signals and set appropriate flip-flops\r
+\t\t//RYin, RXin, Ain, Gin, AddSub;\r
+\t\t\t// Set the bus driver\r
+\t\t\tif(DINout && !(RXout || RYout || Gout)) begin\r
+\t\t\t\tbusDriver = 10\'b0000000001;\r
+\t\t\tend\r
+\t\t\telse if(RXout && !(DINout || RYout || Gout)) begin\r
+\t\t\t\tbusDriver = {regX, 1\'b0, 1\'b0};\r
+\t\t\tend\r
+\t\t\telse if(RYout && !(RXout || DINout || Gout)) begin\r
+\t\t\t\tbusDriver = {regY, 1\'b0, 1\'b0};\r
+\t\t\tend\r
+\t\t\telse if(Gout && !(RXout || RYout || DINout)) begin\r
+\t\t\t\tbusDriver = 10\'b0000000010;\r
+\t\t\tend\r
+\t\t\telse begin\r
+\t\t\t\t$display(""Ambiguous bus driver!! Setting to DINout\
+"");\r
+\t\t\t\tbusDriver = 10\'b0000000001;\r
+\t\t\tend\r
+\t\t\t\r
+\tend\r
+\t\r
+\talways @ (RXin, RYin, regX, regY)\r
+\tbegin\r
+\t\tRin = 8\'b00000000;\r
+\t\tif(RXin) begin\r
+\t\t\tRin = Rin | regX;\r
+\t\tend\r
+\t\t\r
+\t\tif(RYin) begin\r
+\t\t\tRin = Rin | regY;\r
+\t\tend\r
+\tend\r
+\t\r
+\t// Define the bus\r
+\talways @ (busDriver, R0, R1, R2, R3, R4, R5, R6, R7, GoutWires, DIN) begin\r
+\t\tcase(busDriver)\r
+\t\t\treg0: BusWires <= R0;\r
+\t\t\treg1: BusWires <= R1;\r
+\t\t\treg2: BusWires <= R2;\r
+\t\t\treg3: BusWires <= R3;\r
+\t\t\treg4: BusWires <= R4;\r
+\t\t\treg5: BusWires <= R5;\r
+\t\t\treg6: BusWires <= R6;\r
+\t\t\treg7: BusWires <= R7;\r
+\t\t\tgout: BusWires <= GoutWires;\r
+\t\t\tdinout: BusWires <= DIN;\r
+\t\t\tdefault:\r
+\t\t\tbegin\r
+\t\t\t\t$display(""Undefined bus driver!! Defaulting to DIN!!\
+"");\r
+\t\t\t\tBusWires <= DIN;\r
+\t\t\tend\r
+\t\tendcase\r
+\tend\r
+\t\r
+\r
+\t\r
+\t\r
+endmodule
+"
+"module Quadrature(clk, enc_a, enc_b, count);\r
+ input clk;\r
+ input enc_a;\r
+ input enc_b;\r
+ output count;\r
+ \r
+ reg signed [15:0] count;\r
+\r
+ wire [1:0] cur_state;\r
+ reg [1:0] last_state;\r
+\r
+ // Debounce encoder inputs\r
+ Debouncer dbc_a(clk, enc_a, cur_state[0]);\r
+ Debouncer dbc_b(clk, enc_b, cur_state[1]);\r
+\r
+\r
+ always @ (posedge clk) begin\r
+ case ({last_state, cur_state})\r
+ 4'b0001: count <= count + 1;\r
+ 4'b0111: count <= count + 1;\r
+ 4'b1110: count <= count + 1;\r
+ 4'b1000: count <= count + 1;\r
+\r
+ 4'b0010: count <= count - 1;\r
+ 4'b1011: count <= count - 1;\r
+ 4'b1101: count <= count - 1;\r
+ 4'b0100: count <= count - 1;\r
+ endcase\r
+ last_state <= cur_state;\r
+ end\r
+endmodule\r
+"
+"module Servo(clk, out, pos, enable);\r
+\tinput clk;\r
+\toutput out;\r
+\treg out;\r
+\tinput [9:0] pos;\r
+ input enable;\r
+\r
+\t// fpga4fun\r
+\tparameter ClkDiv = 31;\r
+\tparameter PulseCountSize = 11;\r
+\r
+\treg [6:0] ClkCount;\r
+\treg [PulseCountSize:0] PulseCount;\r
+\treg ClkTick;\r
+\r
+\talways @(posedge clk) begin\r
+\t\tClkTick <= (ClkCount==ClkDiv-2);\r
+\r
+\t\tif(ClkTick) \r
+\t\t\tClkCount <= 0; \r
+\t\telse \r
+\t\t\tClkCount <= ClkCount + 1;\r
+\r
+\t\tif(ClkTick) \r
+\t\t\tPulseCount <= PulseCount + 1;\r
+\t\r
+\t\tout = enable ? (PulseCount < {2'b00, pos}) : 0;\r
+ end\r
+\t// fpga4fun\r
+\r
+endmodule\r
+"
+"module Motor(clk, out, ctl, vel);\r
+\tinput clk;\r
+\toutput [1:0] out;\r
+\treg pwmout;\r
+\treg [7:0] pwmcount;\r
+\tinput [7:0] vel;\r
+\tinput [1:0] ctl;\r
+\t\r
+\talways @ (posedge clk)\r
+\tbegin\r
+\t\tpwmcount <= pwmcount + 1;\r
+\t\tif (pwmcount==0)\r
+\t\t\tpwmout = 1;\r
+\t\telse\r
+\t\tif (pwmcount==vel)\r
+\t\t\tpwmout = 0;\r
+\tend\r
+\t\r
+\t\r
+\twire fwd = (ctl==2'b01);\t\r
+\twire rev = (ctl==2'b10);\t\r
+//\twire brake = (ctl==2'b00);\r
+\r
+\tassign out[0] = fwd ? pwmout : 0;\r
+\tassign out[1] = rev ? pwmout : 0;\r
+\t\r
+endmodule\r
+"
+"`include ""Motor.v""\r
+`include ""Servo.v""\r
+`include ""Encoder.v""\r
+`include ""Debouncer.v""\r
+`include ""Quadrature.v""\r
+`include ""Pwm.v""\r
+\r
+module happyio(clk, ad, a, aout, ale, nRD, nWR, mot0, mot1, mot2, mot3, mot4, mot5, Servo, Enc, Digital, ramce);\r
+\t// clock\r
+\tinput clk;\r
+\t// AVR XMEM interface\r
+\tinput [7:0] a;\r
+\tinout [7:0] ad;\r
+\tinput ale;\r
+\tinput nRD, nWR;\r
+\t// address [0..7] output\r
+\toutput [7:0] aout;\r
+\t// IO Pins\r
+\toutput [1:0] mot0;\r
+\toutput [1:0] mot1;\r
+\toutput [1:0] mot2;\r
+\toutput [1:0] mot3;\r
+\toutput [1:0] mot4;\r
+\toutput [1:0] mot5;\r
+\tinput [3:0] Enc;\r
+\tinout [7:0] Digital;\r
+\toutput [5:0] Servo;\r
+\toutput ramce;\r
+\r
+\t\r
+\t// tri-state digital IO\r
+\treg [7:0] digitalPinMode = 8\'h00;\r
+\twire [7:0] digitalOutput;\r
+\treg [7:0] digitalPwm [7:0];\r
+\r
+\tassign Digital[0] = digitalPinMode[0] ? digitalOutput[0] : 1\'bz;\r
+\tassign Digital[1] = digitalPinMode[1] ? digitalOutput[1] : 1\'bz;\r
+\tassign Digital[2] = digitalPinMode[2] ? digitalOutput[2] : 1\'bz;\r
+\tassign Digital[3] = digitalPinMode[3] ? digitalOutput[3] : 1\'bz;\r
+\tassign Digital[4] = digitalPinMode[4] ? digitalOutput[4] : 1\'bz;\r
+\tassign Digital[5] = digitalPinMode[5] ? digitalOutput[5] : 1\'bz;\r
+\tassign Digital[6] = digitalPinMode[6] ? digitalOutput[6] : 1\'bz;\r
+\tassign Digital[7] = digitalPinMode[7] ? digitalOutput[7] : 1\'bz;\r
+\r
+\t//reg ramce;\r
+\r
+\t// internal\r
+\treg [15:0] addr;\r
+\twire\t [7:0] aout;\r
+\twire [7:0] data;\r
+\treg [7:0] dataOut;\r
+\r
+\t// registers (motors)\r
+\treg [1:0] ma1_ctl;\r
+\treg [7:0] ma1_vel;\r
+\treg [1:0] ma2_ctl;\r
+\treg [7:0] ma2_vel;\r
+\treg [1:0] mb1_ctl;\r
+\treg [7:0] mb1_vel;\r
+\treg [1:0] mb2_ctl;\r
+\treg [7:0] mb2_vel;\r
+\treg [1:0] mc1_ctl;\r
+\treg [7:0] mc1_vel;\r
+\treg [1:0] mc2_ctl;\r
+\treg [7:0] mc2_vel;\r
+\t\r
+\t// registers (encoders)\r
+\twire [15:0] enc0;\r
+\twire [15:0] enc1;\r
+\twire [15:0] enc2;\r
+\twire [15:0] enc3;\r
+\t\r
+\t// registers (servos)\r
+\treg [9:0] srv0;\r
+\treg [9:0] srv1;\r
+\treg [9:0] srv2;\r
+\treg [9:0] srv3;\r
+\treg [9:0] srv4;\r
+\treg [9:0] srv5;\r
+ reg srv0_e;\r
+ reg srv1_e;\r
+ reg srv2_e;\r
+ reg srv3_e;\r
+ reg srv4_e;\r
+ reg srv5_e;\r
+\r
+\treg [7:0] tempLo;\r
+\treg [7:0] tempHi;\r
+\r
+\t// bidirectional data bus\r
+\t assign ad = (addr[15] | nRD ) ? 8\'hzz : dataOut ;\r
+\t//assign ad = 8\'hzz;\r
+\t\r
+\t// latch the lower 8 bits of address\r
+\tassign data = ad;\r
+\talways @(negedge ale) begin\r
+\t\t\taddr[7:0] = ad[7:0];\r
+\t\t\taddr[15:8] = a[7:0];\r
+\tend\r
+\r
+\tassign aout[7:0] = addr[7:0];\r
+\r
+\t// assign ram ce\t\r
+\tassign ramce = ~addr[15];\r
+\t//always @ (addr[15] or nRD or nWR) begin\r
+\t//\tramce = ~addr[15];\r
+\t//end \r
+\r
+\t// read control\r
+\talways @ (negedge nRD)\r
+\tbegin\r
+\t\tcase (addr)\r
+\t\t\t// 0x1100 - 0x110B : motors\r
+\t\t\t16\'h1100:\tdataOut[1:0] = ma1_ctl;\r
+\t\t\t16\'h1101:\tdataOut = ma1_vel;\r
+\t\t\t16\'h1102:\tdataOut[1:0] = ma2_ctl;\r
+\t\t\t16\'h1103:\tdataOut = ma2_vel;\r
+\t\t\t16\'h1104:\tdataOut[1:0] = mb1_ctl;\r
+\t\t\t16\'h1105:\tdataOut = mb1_vel;\r
+\t\t\t16\'h1106:\tdataOut[1:0] = mb2_ctl;\r
+\t\t\t16\'h1107:\tdataOut = mb2_vel;\r
+\t\t\t16\'h1108:\tdataOut[1:0] = mc1_ctl;\r
+\t\t\t16\'h1109:\tdataOut = mc1_vel;\r
+\t\t\t16\'h110A:\tdataOut[1:0] = mc2_ctl;\r
+\t\t\t16\'h110B:\tdataOut = mc2_vel;\r
+\t\t\t// 0x110C - 0x1113 : encoders\r
+\t\t\t16\'h110C:\t{tempHi, dataOut} = enc0;\r
+\t\t\t16\'h110D:\tdataOut = tempHi;\r
+\t\t\t16\'h110E:\t{tempHi, dataOut} = enc1;\r
+\t\t\t16\'h110F:\tdataOut = tempHi;\r
+\t\t\t16\'h1110:\t{tempHi, dataOut} = enc2;\r
+\t\t\t16\'h1111:\tdataOut = tempHi;\r
+\t\t\t16\'h1112:\t{tempHi, dataOut} = enc3;\r
+\t\t\t16\'h1113:\tdataOut = tempHi;\r
+\t\t\t// 0x1120 - 0x112B : servos\r
+\t\t\t/*\r
+\t\t\t16\'h1118:\tdataOut = srv0;\r
+\t\t\t16\'h1119:\tdataOut = srv1;\r
+\t\t\t16\'h111A:\tdataOut = srv2;\r
+\t\t\t16\'h111B:\tdataOut = srv3;\r
+\t\t\t16\'h111C:\tdataOut = srv4;\r
+\t\t\t16\'h111D:\tdataOut = srv5;\r
+\t\t\t*/\r
+\t\t\t// 0x11 : digital in\r
+\t\t\t16\'h111E:\tdataOut = Digital;\r
+\t\t\t// 0x11FE : major version\r
+\t\t\t16\'h11FE:\tdataOut = 0;\r
+\t\t\t// 0x11FF : minor version\r
+\t\t\t16\'h11FF:\tdataOut = 7;\r
+\t\tendcase\r
+\tend\r
+\t\r
+\t// write control\r
+\talways @ (negedge nWR or posedge clk)\r
+\tbegin \r
+\t\tif (!nWR)\r
+\t\tcase (addr)\r
+\t\t\t// 0x1100 - 0x110B : motors\r
+\t\t\t16\'h1100:\tma1_ctl = data;\r
+\t\t\t16\'h1101:\tma1_vel = data;\r
+\t\t\t16\'h1102:\tma2_ctl = data;\r
+\t\t\t16\'h1103:\tma2_vel = data;\r
+\t\t\t16\'h1104:\tmb1_ctl = data;\r
+\t\t\t16\'h1105:\tmb1_vel = data;\r
+\t\t\t16\'h1106:\tmb2_ctl = data;\r
+\t\t\t16\'h1107:\tmb2_vel = data;\r
+\t\t\t16\'h1108:\tmc1_ctl = data;\r
+\t\t\t16\'h1109:\tmc1_vel = data;\r
+\t\t\t16\'h110A:\tmc2_ctl = data;\r
+\t\t\t16\'h110B:\tmc2_vel = data;\r
+\t\t\t// 0x110C - 0x1113 : encoders\r
+\t\t\t// ...\r
+\t\t\t// 0x1120 - 0x112B : servos\r
+\t\t\t16\'h1120:\ttempLo = data;\r
+\t\t\t16\'h1121: \tbegin\r
+\t\t\t\t\t\t\tsrv0 = {data[1:0],tempLo}; \r
+\t\t\t\t\t\t\tsrv0_e = data[7];\r
+\t\t\t\t\t\tend\r
+\t\t\t16\'h1122:\ttempLo = data;\r
+\t\t\t16\'h1123: \tbegin\r
+\t\t\t\t\t\t\tsrv1 = {data[1:0],tempLo}; \r
+\t\t\t\t\t\t\tsrv1_e = data[7];\r
+\t\t\t\t\t\tend\r
+\t\t\t16\'h1124:\ttempLo = data;\r
+\t\t\t16\'h1125: \tbegin\r
+\t\t\t\t\t\t\tsrv2 = {data[1:0],tempLo}; \r
+\t\t\t\t\t\t\tsrv2_e = data[7];\r
+\t\t\t\t\t\tend\r
+\t\t\t16\'h1126:\ttempLo = data;\r
+\t\t\t16\'h1127: \tbegin\r
+\t\t\t\t\t\t\tsrv3 = {data[1:0],tempLo}; \r
+\t\t\t\t\t\t\tsrv3_e = data[7];\r
+\t\t\t\t\t\tend\r
+\t\t\t16\'h1128:\ttempLo = data;\r
+\t\t\t16\'h1129: \tbegin\r
+\t\t\t\t\t\t\tsrv4 = {data[1:0],tempLo}; \r
+\t\t\t\t\t\t\tsrv4_e = data[7];\r
+\t\t\t\t\t\tend\r
+\t\t\t16\'h112A:\ttempLo = data;\r
+\t\t\t16\'h112B: \tbegin\r
+\t\t\t\t\t\t\tsrv5 = {data[1:0],tempLo}; \r
+\t\t\t\t\t\t\tsrv5_e = data[7];\r
+\t\t\t\t\t\tend\r
+\r
+\r
+\t\t\t// Digital I/O mode\r
+\t\t\t16\'h1130:\tdigitalPinMode = data;\r
+\r
+\t\t\t// Digital Output\r
+\t\t\t16\'h1131:\tdigitalPwm[0] = data;\r
+\t\t\t16\'h1132:\tdigitalPwm[1] = data;\r
+\t\t\t16\'h1133:\tdigitalPwm[2] = data;\r
+\t\t\t16\'h1134:\tdigitalPwm[3] = data;\r
+\t\t\t16\'h1135:\tdigitalPwm[4] = data;\r
+\t\t\t16\'h1136:\tdigitalPwm[5] = data;\r
+\t\t\t16\'h1137:\tdigitalPwm[6] = data;\r
+\t\t\t16\'h1138:\tdigitalPwm[7] = data;\r
+\t\t\t// ...\r
+\t\tendcase\r
+\tend\r
+\t\r
+\r
+\t// motor drivers\r
+\tMotor motor0(clk,mot0,ma2_ctl,ma2_vel);\r
+\tMotor motor1(clk,mot1,ma1_ctl,ma1_vel);\r
+\tMotor motor2(clk,mot2,mb2_ctl,mb2_vel);\r
+\tMotor motor3(clk,mot3,mb1_ctl,mb1_vel);\r
+\tMotor motor4(clk,mot4,mc2_ctl,mc2_vel);\r
+\tMotor motor5(clk,mot5,mc1_ctl,mc1_vel);\r
+\r
+\t// encoder drivers\r
+ `ifndef QUADRATURE\r
+\tEncoder encoder0(clk,Enc[0],enc0);\r
+\tEncoder encoder1(clk,Enc[1],enc1);\r
+\tEncoder encoder2(clk,Enc[2],enc2);\r
+\tEncoder encoder3(clk,Enc[3],enc3);\r
+ `else\r
+\tQuadrature quad0(clk,Enc[0],Enc[1], enc0);\r
+\tQuadrature quad1(clk,Enc[2],Enc[3], enc1);\r
+ `endif\r
+\r
+\t// servo drivers\r
+\tServo servo0(clk,Servo[0],srv0, srv0_e);\r
+\tServo servo1(clk,Servo[1],srv1, srv1_e);\r
+\tServo servo2(clk,Servo[2],srv2, srv2_e);\r
+\tServo servo3(clk,Servo[3],srv3, srv3_e);\r
+\tServo servo4(clk,Servo[4],srv4, srv4_e);\r
+\tServo servo5(clk,Servo[5],srv5, srv5_e);\r
+\r
+\t// digital IO\r
+\tPwm pwm0(clk, digitalOutput[0], digitalPwm[0]);\r
+\tPwm pwm1(clk, digitalOutput[1], digitalPwm[1]);\r
+\tPwm pwm2(clk, digitalOutput[2], digitalPwm[2]);\r
+\tPwm pwm3(clk, digitalOutput[3], digitalPwm[3]);\r
+\tPwm pwm4(clk, digitalOutput[4], digitalPwm[4]);\r
+\tPwm pwm5(clk, digitalOutput[5], digitalPwm[5]);\r
+\tPwm pwm6(clk, digitalOutput[6], digitalPwm[6]);\r
+\tPwm pwm7(clk, digitalOutput[7], digitalPwm[7]);\r
+\r
+endmodule\r
+"
+"module Debouncer (clk, dirty, clean);
+ input clk;
+ input dirty;
+ output reg clean;
+
+ reg [6:0] debounce;
+ reg last_dirty;
+
+ always @ (posedge clk) begin
+ if (dirty != last_dirty) begin
+ last_dirty <= dirty;
+ debounce <= 0;
+ end else if (debounce == 127) begin
+ clean <= last_dirty;
+ end else begin
+ debounce <= debounce+1;
+ end
+ end
+endmodule
+
+"
+"module Pwm(clk, out, val);\r
+\tinput clk;\r
+\toutput reg out;\r
+\treg [7:0] pwmcount = 0;\r
+\tinput [7:0] val;\r
+\t\r
+\talways @ (posedge clk) begin\r
+\t\tpwmcount <= pwmcount + 1;\r
+ if (val == 0) begin\r
+ out <= 0;\r
+ end else if (val == 255) begin\r
+ out <= 1;\r
+ end else if (pwmcount==0) begin\r
+\t\t\tout <= 1;\r
+\t\tend else if (pwmcount==val) begin\r
+\t\t\tout <= 0;\r
+ end\r
+\tend\r
+endmodule\r
+"
+"module Encoder(clk, enc, count);\r
+\tinput clk;\r
+\tinput enc;\r
+\treg enc_clean, enc_new;\r
+\treg [7:0] debounce;\r
+\toutput [15:0] count;\r
+\treg [15:0] count;\r
+\r
+\talways @ (posedge clk)\r
+ if (enc != enc_new) begin enc_new <= enc; debounce <= 0; end\r
+ else if (debounce == 127) enc_clean <= enc_new;\r
+ else debounce <= debounce+1;\r
+\r
+\talways @ (posedge enc_clean)\r
+\t\tcount <= count + 1;\r
+\t\r
+endmodule\r
+"
+"//Test Bench for Register File
+
+`define N 16
+`define K 4
+module regfile_tb;
+
+ reg clk;
+ wire [`N-1:0] a,b;
+ reg [`N-1:0] x;
+ reg [`K-1:0] sa, sb, d;
+ reg ld;
+
+
+regfile #(.n(`N), .k(`K)) r1 (clk, x, ld, d, sa, sb, a, b);
+
+initial begin
+ clk = 0;
+end
+
+initial begin
+ $monitor(""time:%t\\tld: %b\\tsa: %d\\tsb: %d\\td %d\\tx: %d\\ta: %d\\tb: %d"", $time, ld, sa, sb, d, x, a, b);
+end
+
+initial begin
+ // Load 10 into register 2
+ #0 begin
+ $display(""\
+Starting test 1"");
+ ld = 1;
+ x = 16\'d10;
+ d = 3;
+ sa = 3;
+ sb = 3;
+ end
+ // Retrieve 10 from register 2
+ #2 begin
+ $display(""Reading register"");
+ ld = 0;
+ x = 0;
+ d = 3;
+ sa = 3;//4\'b0010;
+ sb = 3;//4\'b0010;
+ end
+
+ #2 begin
+ $display(""Writing + Reading"");
+ ld = 1;
+ x = 16\'d15;
+ d = 1;
+ sa = 3;
+ sb = 3;
+ end
+
+ #2 begin
+ $display(""Reading both registers"");
+ ld = 0;
+ x = 0;
+ d = 0;
+ sa = 1;
+ sb = 3;
+ end
+ #2 begin
+ $display(""Read again"");
+ ld = 0;
+ x = 0;
+ d = 0;
+ sa = 1;
+ sb = 3;
+ end
+ #4 $finish;
+end
+
+//Simulate Clock
+always begin
+ #1 clk = !clk;
+end
+
+endmodule
+"
+"//Fibonacci Test Bench
+
+//Test Bench for Multiplier Functional Unit
+module FibonacciTB;
+
+ reg clk, reset;
+ wire [15:0] result;
+ reg [7:0] n;
+ wire ready;
+
+
+//Data containing 0
+reg [7:0] test0Data = 8\'b0;
+
+//Data containing 1
+reg [7:0] test1Data = 8\'b1;
+
+// Test regular fibonacci number
+reg [7:0] testOrdinary = 8\'d6;
+
+//Test overflow number
+reg [7:0] testOverflow = 8\'d25;
+
+defparam f1.inBits = 8;
+defparam f1.outBits = 16;
+fibonacci f1 (clk, reset, n, result, ready);
+
+initial begin
+ clk = 0;
+ reset = 0;
+end
+
+initial begin
+// $monitor(""time:%t\\treset: %b\\tready: %b\\tresult: %d\
+n: %d"",$time, reset, ready, result, n);
+end
+
+initial begin
+ #50 begin $display(""Starting test 1""); reset = 1; n = testOrdinary; end
+ #11 reset = 0;
+ #90 begin $display(""Starting test 2""); reset = 1; n = test0Data; end //Test fib(0) == 0
+ #11 reset = 0;
+ #50 begin $display(""Starting test 3""); reset = 1; n = test1Data; end //Test fib(1) == 1
+ #11 reset = 0;
+ #50 begin $display(""Starting test 4""); reset = 1; n = testOverflow; end //Test overflowing
+ #11 reset = 0;
+ #300 $finish;
+end
+
+//Simulate Clock
+always begin
+ #5 clk = !clk;
+end
+
+endmodule
+"
+"//Circuit which generates Fibonacci numbers
+
+module fibonacci (
+clk, //clock
+reset, //reset the Multiplier
+n, //Fibonacci number to calculate
+result, //result of fibonacci calculation
+ready //signals if the result is ready
+);
+
+parameter inBits = 8; //No of bits for n
+parameter outBits = 16; //No of bits of Fib number
+
+//----Input Ports---
+input clk;
+input reset;
+input [inBits-1:0] n;
+
+//---Output Ports---
+output reg [outBits-1:0] result;
+output reg ready;
+
+//---Internal Registers---
+reg [outBits-1:0] last;
+reg [inBits-1:0] no;
+reg [inBits-1:0] count;
+
+
+always @(posedge clk) begin
+ if (reset) begin
+ result <= 16\'b0;
+ last <= 16\'b0;
+ no <= n;
+ count <= 16\'b0;
+ //0th fibonacci number is 0, need to generate 1 afterwards
+ end else begin
+ if (result == 0 && !ready) begin
+ result <= 1;
+ end else if (ready) begin
+ result <= result;
+ end else begin
+ result <= result + last;
+ end
+ last <= result;
+ count <= count + 1;
+ end
+ ready <= count >= no;
+ $display(""reset %b, count %d, result %d, ready %b, no %d, last %d"",reset, count, result, ready, no, last);
+end
+
+
+endmodule
+"
+"//Multiplier Functional Unit which multiplies 2 numbers
+
+
+module multiplier (
+clk, //clock
+reset, //reset the Multiplier
+x, //First Number to be multiplied
+y, //Second Number to be multiplied
+prod, //result of multiplication
+ready //signals if the result is ready
+);
+
+parameter bits = 8;
+
+//----Input Ports---
+input clk;
+input reset;
+input [bits - 1:0] x;
+input [bits - 1:0] y;
+
+//---Output Ports--
+output reg [(bits * 2) - 1:0] prod;
+output reg ready;
+
+//--Internal Data--
+reg [7:0] rx;
+reg [15:0] ry;
+
+always @(posedge clk) begin
+ if (reset) begin
+ rx <= x;
+ ry <= 16\'b0 + y;
+ prod <= 16\'b0;
+
+ end else begin
+ rx <= rx >> 1;
+ ry <= ry << 1;
+ // If LSB of rx is 1 then ""multiply"" otherwise no change
+ if (rx & 8\'b1) begin
+ prod <= prod + ry;
+ end else begin
+ prod <= prod;
+ end
+
+ end
+ // When one result reaches 0 nothing left to multiply
+ //$display(""reset %b ready %b rx %d ry %d prod %d, x %d, y %d"", reset, ready, rx, ry, prod, x ,y);
+ ready <= !rx || !ry;
+end
+
+
+endmodule
+"
+"
+//Test Bench for Multiplier Functional Unit
+module MultiplierTB;
+
+ reg clk, reset;
+ wire [15:0] result;
+ reg [7:0] x, y;
+ wire ready;
+
+
+//Data containing 0
+reg [7:0] test0Data = 8\'b00000000;
+
+//Data containing 1
+reg [7:0] test1Data = 8\'b00000001;
+
+//Data for testing left and right multiplication with identity (1)
+//gives the data
+reg [7:0] testLeftIdentity = 8\'d67;
+reg [7:0] testRightIdentity = 8\'d96;
+
+// Data for testing multiplying by 0 on lhs and rhs still gives 0
+reg [7:0] testLHS0Data = 8\'d37;
+reg [7:0] testRHS0Data = 8\'d96;
+
+
+// Data for testing 2 regular numbers multiply correctly
+reg [7:0] testRegularData1 = 8\'d20;
+reg [7:0] testRegularData2 = 8\'d10;
+
+
+reg [7:0] test2RegularData1 = 8\'d255;
+reg [7:0] test2RegularData2= 8\'d255;
+
+
+defparam m1.bits = 8;
+multiplier m1 (clk, reset, x, y, result, ready);
+
+initial begin
+ clk = 0;
+ reset = 0;
+end
+
+initial begin
+ $monitor(""time:%t\\treset: %b\\tready: %b\\tresult: %d\
+x: %d\\ty: %d"", $time, reset, ready, result, x, y);
+end
+
+initial begin
+ #50 begin $display(""Starting test 1""); reset = 1; x = testRegularData1; y = testRegularData2; end
+ #11 reset = 0;
+ #70 begin $display(""Starting test 2""); reset = 1; x = test2RegularData1; y = test2RegularData2; end
+ #11 reset = 0;
+ #200 begin $display(""Starting test 3""); reset = 1; x = test0Data; y = test0Data; end //Test 0x0 == 0
+ #11 reset = 0;
+ #50 begin $display(""Starting test 4""); reset = 1; x = testLHS0Data; y = test0Data; end //Test x*0 == 0
+ #11 reset = 0;
+ #50 begin $display(""Starting test 5""); reset = 1; x = test0Data; y = testRHS0Data; end //Test 0*x == 0
+ #11 reset = 0;
+ #50 begin $display(""Starting test 6""); reset = 1; x = test1Data; y = testLeftIdentity; end //Test 1*x == x
+ #11 reset = 0;
+ #50 begin $display(""Starting test 7""); reset = 1;x = testRightIdentity; y = test1Data; end //Test x*1 == x
+ #11 reset = 0;
+ #80 $finish;
+end
+
+//Simulate Clock
+always begin
+ #5 clk = !clk;
+end
+
+endmodule
+"
+"//Module which prints Hello World
+module HelloWorld;
+
+initial begin
+ $display(""Hello World"");
+ $finish;
+end
+
+endmodule
+"
+"//Register File
+module regfile (
+clk, // Clock
+x, //External Input
+ld, //Whether or not to load destination register from extenral input
+d, //Destination register
+sa, //1st Source Register
+sb, // 2nd Source Register
+a, // Output a
+b // Output b
+);
+
+parameter n = 16; //n bits per register
+parameter k = 4; //2^k registers
+
+//--- Input Ports ---
+input clk;
+input [n-1:0] x;
+input ld;
+input [k-1:0] d, sa, sb;
+
+//--- Output Ports ---
+output wire [n - 1:0] a, b;
+
+
+//-- Internal Data ---
+wire [n - 1:0] a0, a1, b0, b1;
+
+wire ld0, ld1;
+
+generate
+ // Base case of 2 regfiles left
+ if (k == 1) begin
+ regfile1 #(.n(n)) rfile1A(clk, x, ld0, a0, b0);
+ regfile1 #(.n(n)) rfile1B(clk, x, ld1, a1, b1);
+ // 2^k bit regfile
+ end else begin
+ regfile #(.k(k-1), .n(n)) rFileA(clk, x, ld0, d[k-2:0], sa[k-2:0], sb[k-2:0], a0, b0);
+ regfile #(.k(k-1), .n(n)) rFileB(clk, x, ld1, d[k-2:0], sa[k-2:0], sb[k-2:0], a1, b1);
+ end
+endgenerate
+
+function [n-1:0] mux1w;
+ input v;
+ input [n-1:0]x1;
+ input [n-1:0]x2;
+ begin
+ if (v) begin
+ mux1w = x2;
+
+ end else begin
+ mux1w = x1;
+ end
+ end
+endfunction
+
+
+assign ld0 = (!d[k-1]) & ld;
+assign ld1 = d[k-1] & ld;
+assign a = mux1w(sa[k-1], a0, a1);
+assign b = mux1w(sb[k-1], b0, b1);
+
+endmodule
+
+
+
+module regfile1 (
+clk, // Clock
+x, //External Input
+ld, //Whether or not to load destination register from external input
+r, // Output a
+r // Output b
+);
+
+parameter n = 16; //n bit register
+
+//--- Inputs ---
+input clk;
+input [n - 1: 0] x;
+input ld;
+
+//--- Outputs ---
+output reg [n-1:0] r;
+
+always @(posedge clk) begin
+ if (ld) begin
+ r <= x;
+ end else begin
+ r <= r;
+ end
+end
+
+
+endmodule
+
+"
+"Require Import Bedrock EchoServerDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024 * 10.
+ Definition port : W := 8081%N.
+ Definition numWorkers : W := 10.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Require Import Bedrock WebServerDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := (1024 * 1024 * 25)%N.
+ Definition port : W := 8080%N.
+ Definition numWorkers : W := 10.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Require Import AutoSep Malloc.
+
+
+Section adt.
+ Variable P : W -> W -> HProp.
+ Variable res : nat.
+
+ Definition newS := SPEC(""extra_stack"") reserving res
+ PRE[_] mallocHeap 0
+ POST[R] P 0 R * mallocHeap 0.
+
+ Definition deleteS := SPEC(""extra_stack"", ""self"") reserving res
+ Al c,
+ PRE[V] P c (V ""self"") * mallocHeap 0
+ POST[_] mallocHeap 0.
+
+ Definition readS := SPEC(""extra_stack"", ""self"") reserving res
+ Al c,
+ PRE[V] P c (V ""self"") * mallocHeap 0
+ POST[R] [| R = c |] * P c (V ""self"") * mallocHeap 0.
+
+ Definition writeS := SPEC(""extra_stack"", ""self"", ""n"") reserving res
+ Al c,
+ PRE[V] P c (V ""self"") * mallocHeap 0
+ POST[_] P (V ""n"") (V ""self"") * mallocHeap 0.
+End adt.
+"
+"Set Implicit Arguments.
+
+Require Import StringSet.
+Module String_as_OT := StringKey.
+
+Require Import FMapAVL.
+Module Import StringMap := Make String_as_OT.
+
+Require Import OrdersAlt.
+Module String_as_OT_new := Update_OT String_as_OT.
+Require Import Equalities.
+Module String_as_UDT := Make_UDT String_as_OT.
+"
+"Require Import S.
+
+Module Make (E : S).
+
+ Definition t := list E.t.
+
+End Make."
+"Require Import Thread.
+Export Thread.
+
+Module Type S.
+ Variable globalSched : W.
+End S.
+
+Module Make(M : S).
+Import M.
+
+Module M'.
+ Definition globalSched := M.globalSched.
+
+ Open Scope Sep_scope.
+
+ Definition globalInv (_ : files) : HProp := Emp.
+End M'.
+
+Ltac unf := unfold M'.globalInv in *.
+
+Module T := Thread.Make(M').
+
+Import T.
+Export T.
+
+Ltac sep := T.sep unf.
+Ltac sep_auto := sep auto_ext.
+
+End Make.
+"
+"Set Implicit Arguments.
+
+Require Import LabelMap.
+Require Import Equalities.
+Module K := Make_UDT LabelKey.
+Module M := LabelMap.
+Require Import FMapFacts.
+Include (Properties M).
+Include (Facts M).
+Require Import FMapFacts1.
+Include (WFacts_fun K M).
+Include (UWFacts_fun K M).
+Require Import FMapFacts2.
+Include (UWFacts_fun K M)."
+"Set Implicit Arguments.
+
+Require Import String.
+
+Definition glabel := (string * string)%type.
+
+"
+"Set Implicit Arguments.
+
+Require Import StringMap.
+Module K := String_as_UDT.
+Module M := StringMap.
+Require Import FMapFacts.
+Include (Properties M).
+Include (Facts M).
+Require Import FMapFacts1.
+Include (WFacts_fun K M).
+Include (UWFacts_fun K M).
+Require Import FMapFacts2.
+Include (UWFacts_fun K M).
+"
+"Require Import Bedrock ConnectDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024 * 10.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Set Implicit Arguments.
+
+Module Type ADT.
+
+ Parameter ADTValue : Type.
+
+End ADT.
+
+
+(*
+ Record ADT :=
+ {
+ Model : Type
+ }.
+
+ Record ADTValue :=
+ {
+ Type_ : ADT;
+ Value : Model Type_
+ }.
+ *)
+
+"
+"Require Import AutoSep.
+Require Import Syntax.
+Require Import SyntaxExpr Memory IL String.
+
+Set Implicit Arguments.
+
+Coercion Const : W >-> Expr.
+Coercion Var : string >-> Expr.
+
+Infix ""+"" := (SyntaxExpr.Binop Plus) : expr_scope.
+Infix ""-"" := (SyntaxExpr.Binop Minus) : expr_scope.
+Infix ""*"" := (SyntaxExpr.Binop Times) : expr_scope.
+Infix ""="" := (SyntaxExpr.TestE IL.Eq) : expr_scope.
+Infix ""<>"" := (SyntaxExpr.TestE IL.Ne) : expr_scope.
+Infix ""<"" := (SyntaxExpr.TestE IL.Lt) : expr_scope.
+Infix ""<="" := (SyntaxExpr.TestE IL.Le) : expr_scope.
+
+Delimit Scope expr_scope with expr.
+Local Open Scope expr.
+
+Infix "";;"" := Syntax.Seq : stmt_scope.
+
+Notation ""\'skip\'"" := Syntax.Skip : stmt_scope.
+
+Notation ""\'If\' cond { trueStmt } \'else\' { falseStmt }"" := (Syntax.If cond%expr trueStmt falseStmt) : stmt_scope.
+
+Notation ""x <- e"" := (Syntax.Assign x e%expr) : stmt_scope.
+
+Delimit Scope stmt_scope with stmt.
+Local Open Scope stmt.
+
+Definition DirectCall x f args := (Syntax.Label ""_f"" f ;; Syntax.Call x ""_f"" args)%stmt.
+
+Notation ""\'DCall\' f ()"" := (DirectCall None f nil)
+ (no associativity, at level 95, f at level 0) : stmt_scope.
+
+Notation ""\'DCall\' f ( x1 , .. , xN )"" := (DirectCall None f (cons x1 (.. (cons xN nil) ..))%expr)
+ (no associativity, at level 95, f at level 0) : stmt_scope.
+
+Notation ""x <-- \'DCall\' f ()"" := (DirectCall (Some x) f nil)
+ (no associativity, at level 95, f at level 0) : stmt_scope.
+
+Notation ""x <-- \'DCall\' f ( x1 , .. , xN )"" := (DirectCall (Some x) f (cons x1 (.. (cons xN nil) ..))%expr) (no associativity, at level 95, f at level 0) : stmt_scope.
+
+Notation ""a ! b"" := (a, b) (only parsing) : stmt_scope.
+
+Local Close Scope stmt.
+Local Close Scope expr.
+"
+"Require Import StringSet.
+Import StringSet.
+
+Set Implicit Arguments.
+
+Definition union_list ls := List.fold_right union empty ls."
+"Require Import Bedrock XmlTest2Driver AMD64_gas.
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Require Import Bedrock Echo3Driver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Require Import Bedrock XmlTestDriver AMD64_gas.
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Set Implicit Arguments.
+
+Require Import GLabelKey.
+Module K := GLabel_as_UDT.
+Require Import GLabelMap.
+Module M := GLabelMap.
+Require Import FMapFacts.
+Include (Properties M).
+Include (Facts M).
+Require Import FMapFacts1.
+Include (WFacts_fun K M).
+Include (UWFacts_fun K M).
+Require Import FMapFacts2.
+Include (UWFacts_fun K M).
+"
+"Require Import Bedrock MiniMasterDriver AMD64_gas.
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Notation ""$$ x"":= (Const ($ x)) (at level 0): expr_scope.
+Notation ""## x"":= (Var x) (at level 0): expr_scope.
+Infix "".+"":= (Binop Plus) (at level 50): expr_scope.
+Infix "".-"":= (Binop Minus) (at level 50): expr_scope.
+Infix "".*"":= (Binop Times) (at level 50): expr_scope.
+Infix "".="":= (TestE Eq) (at level 50): expr_scope.
+Infix "".<>"":= (TestE Ne) (at level 50): expr_scope.
+Infix "".<"":= (TestE Lt) (at level 50): expr_scope.
+Infix "".<="":= (TestE Le) (at level 50): expr_scope.
+
+Delimit Scope expr_scope with expr.
+"
+"Require Import List.
+
+Set Implicit Arguments.
+
+Definition max_list := fold_right max.
+
+"
+"Require Import PreAutoSep.
+
+Export PreAutoSep.
+
+Require Import Bool StreamParse ArrayQuery.
+Export StreamParse ArrayQuery.
+
+Ltac vcgen_simp := cbv beta iota zeta delta [map app imps
+ LabelMap.add Entry Blocks Postcondition VerifCond
+ Straightline_ Seq_ Diverge_ Fail_ Skip_ Assert_
+ Structured.If_ Structured.While_ Goto_ Structured.Call_ IGoto
+ setArgs Programming.Reserved Programming.Formals Programming.Precondition
+ importsMap fullImports buildLocals blocks union Nplus Nsucc length N_of_nat
+ List.fold_left ascii_lt string_lt label'_lt
+ LabelKey.compare' LabelKey.compare LabelKey.eq_dec
+ LabelMap.find
+ toCmd Seq Instr Diverge Fail Skip Assert_
+ Programming.If_ Programming.While_ Goto Programming.Call_ RvImm'
+ Assign' localsInvariant
+ regInL lvalIn immInR labelIn variableSlot string_eq ascii_eq
+ andb eqb qspecOut
+ ICall_ Structured.ICall_
+ Assert_ Structured.Assert_
+ LabelMap.Raw.find LabelMap.this LabelMap.Raw.add
+ LabelMap.empty LabelMap.Raw.empty string_dec
+ Ascii.ascii_dec string_rec string_rect sumbool_rec sumbool_rect Ascii.ascii_rec Ascii.ascii_rect
+ Bool.bool_dec bool_rec bool_rect eq_rec_r eq_rec eq_rect eq_sym
+ fst snd labl
+ Ascii.N_of_ascii Ascii.N_of_digits N.compare Nmult Pos.compare Pos.compare_cont
+ Pos.mul Pos.add LabelMap.Raw.bal
+ Int.Z_as_Int.gt_le_dec Int.Z_as_Int.ge_lt_dec LabelMap.Raw.create
+ ZArith_dec.Z_gt_le_dec Int.Z_as_Int.plus Int.Z_as_Int.max LabelMap.Raw.height
+ ZArith_dec.Z_gt_dec Int.Z_as_Int._1 BinInt.Z.add Int.Z_as_Int._0 Int.Z_as_Int._2 BinInt.Z.max
+ ZArith_dec.Zcompare_rec ZArith_dec.Z_ge_lt_dec BinInt.Z.compare ZArith_dec.Zcompare_rect
+ ZArith_dec.Z_ge_dec label'_eq label'_rec label'_rect
+ COperand1 CTest COperand2 Pos.succ
+ makeVcs
+
+ Cond_ Cond
+ Lambda__ Lambda_
+
+ Wrap.Wrap
+ Parse1 ParseOne ParseOne'
+ Query ForArray
+].
+
+Ltac vcgen :=
+ structured_auto vcgen_simp;
+ autorewrite with sepFormula in *; simpl in *;
+ unfold starB, hvarB, hpropB in *; fold hprop in *; refold.
+"
+"Require Import Bedrock RosMasterDriver AMD64_gas.
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Set Implicit Arguments.
+
+Require Import StringSet.
+Import StringSet.
+Require Import FSetProperties.
+Module Import Properties := Properties StringSet.
+Import FM.
+
+Local Infix ""+"" := union.
+Local Infix ""<="" := Subset.
+
+Ltac subset_solver :=
+ repeat
+ match goal with
+ | |- ?A <= ?A => eapply subset_refl
+ | |- empty <= _ => eapply subset_empty
+ | |- _ + _ <= _ => eapply union_subset_3
+ | |- ?S <= ?A + _ =>
+ match A with
+ context [ S ] => eapply subset_trans; [ | eapply union_subset_1]
+ end
+ | |- ?S <= _ + ?B =>
+ match B with
+ context [ S ] => eapply subset_trans; [ .. | eapply union_subset_2]
+ end
+ end.
+"
+"Require Import Bedrock ListBuilderDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Require Import Bedrock ArrayTestDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m1.
+Recursive Extraction compiled.
+"
+"Set Implicit Arguments.
+
+Section Body.
+
+ Require Import AutoSep.
+ Variable vars : list string.
+
+ Variable temp_size : nat.
+
+ Variable imports : LabelMap.t assert.
+
+ Variable imports_global : importsGlobal imports.
+
+ Variable modName : string.
+
+ Require Import SemanticsExpr.
+
+ Definition stack_slot n := LvMem (Sp + (4 * n)%nat)%loc.
+ Definition vars_start := 4 * 2.
+ Definition var_slot x := LvMem (Sp + (vars_start + variablePosition vars x)%nat)%loc.
+ Definition temp_start := vars_start + 4 * length vars.
+ Definition temp_slot n := LvMem (Sp + (temp_start + 4 * n)%nat)%loc.
+ Definition frame_len := temp_start + 4 * temp_size.
+ Definition frame_len_w := natToW frame_len.
+ Definition callee_stack_start := frame_len.
+ Definition callee_stack_slot n := LvMem (Sp + (callee_stack_start + 4 * n)%nat)%loc.
+
+ Definition Seq2 := @Seq_ _ imports_global modName.
+
+ Definition Strline := Straightline_ imports modName.
+
+ Definition Skip__ := Skip_ imports modName.
+
+ Definition If__ := Structured.If_ imports_global.
+
+ Definition While__ := Structured.While_ imports_global.
+
+ Fixpoint Seq__ ls :=
+ match ls with
+ | nil => Skip__
+ | a :: ls' => Seq2 a (Seq__ ls')
+ end.
+
+ Definition SaveRv lv := Strline (IL.Assign lv (RvLval (LvReg Rv)) :: nil).
+
+ Definition CheckExtraStack (n : nat) cmd :=
+ Seq2
+ (Strline (IL.Assign Rv (stack_slot 1) :: nil))
+ (Structured.If_ imports_global n Le Rv cmd
+ (Diverge_ imports modName)).
+
+ Require SaveRet.
+ Local Open Scope nat.
+
+ Require Import ConvertLabel.
+ Import Syntax.
+ Variable loop_inv : Expr -> Stmt -> Stmt -> assert.
+ Variable after_call : option string -> Stmt -> assert.
+ Variable compile_expr : Expr -> nat -> cmd imports modName.
+ Variable compile_exprs : list Expr -> nat -> nat -> cmd imports modName.
+
+ Fixpoint cmp (s k : Stmt) : cmd imports modName :=
+ match s with
+ | Syntax.Skip =>
+ Skip__
+ | Syntax.Seq a b =>
+ Seq2 (cmp a (Syntax.Seq b k))
+ (cmp b k)
+ | Syntax.If cond t f =>
+ Seq2 (compile_expr cond 0)
+ (If__ Rv Ne (natToW 0) (cmp t k) (cmp f k))
+ | Syntax.While cond body =>
+ Seq2 (compile_expr cond 0)
+ (While__ (loop_inv cond body k) Rv Ne (natToW 0)
+ (Seq2 (cmp body (Syntax.Seq (Syntax.While cond body) k))
+ (compile_expr cond 0)))
+ | Syntax.Call var f args =>
+ let callee_frame_len := 2 + length args in
+ CheckExtraStack
+ callee_frame_len
+ (Seq__
+ (compile_exprs
+ args 0 (callee_stack_start + 8)
+ :: compile_expr f 0
+ :: Strline
+ (IL.Binop
+ (callee_stack_slot 1) (stack_slot 1) Minus callee_frame_len
+ :: IL.Binop Sp Sp Plus frame_len_w :: nil)
+ :: Structured.ICall_ imports modName Rv (after_call var k)
+ :: Strline (IL.Binop Sp Sp Minus frame_len_w :: nil)
+ :: SaveRet.compile vars var imports_global modName :: nil))
+ | Syntax.Label x lbl =>
+ Strline (IL.Assign (var_slot x) lbl :: nil)
+ | Syntax.Assign x e =>
+ Seq2 (compile_expr e 0)
+ (SaveRv (var_slot x))
+ end.
+
+End Body.
+
+Require Import ADT.
+Require Import RepInv.
+
+Module Make (Import E : ADT) (Import M : RepInv E).
+
+ Require Import Inv.
+ Module Import InvMake := Make E.
+ Import SemanticsMake.
+ Module Import InvMake2 := Make M.
+
+ Section TopSection.
+
+ Variable vars : list string.
+
+ Variable temp_size : nat.
+
+ Variable rv_postcond : W -> vals -> Prop.
+
+ Definition loop_inv cond body k : assert :=
+ let s := Syntax.Seq (Syntax.While cond body) k in
+ inv_template vars temp_size (fun rv v => rv = eval (fst v) cond) rv_postcond s.
+
+ Require Import Malloc.
+ Require Import Semantics.
+
+ Definition after_call ret k : assert :=
+ st ~> Ex fs,
+ let stn := fst st in
+ funcs_ok stn fs /\\
+ ExX, Ex vs, Ex heap1, Ex heap2, Ex temps, Ex rp, Ex e_stack, Ex ret_w, Ex ret_a,
+ let old_sp := st#Sp ^- (frame_len_w vars temp_size) in
+ ![^[is_state old_sp rp e_stack e_stack vars (vs, heap1) temps * is_heap heap2 * layout_option ret_w ret_a * mallocHeap 0] * #0] st /\\
+ let env := (ConvertLabel.from_bedrock_label_map (Labels stn), fs stn) in
+ [| let vs := upd_option vs ret st#Rv in
+ let heap12 := heap_merge heap1 heap2 in
+ let heap := heap_upd_option heap12 ret_w ret_a in
+ let v := (vs, heap) in
+ (separated heap12 ret_w ret_a -> Safe env k v) /\\
+ length temps = temp_size |] /\\
+ (rp, stn)
+ @@@ (
+ st' ~> Ex v', Ex temps',
+ ![^[is_state st'#Sp rp e_stack e_stack vars v' temps' * mallocHeap 0] * #1] st' /\\
+ [| let vs := upd_option vs ret st#Rv in
+ let heap12 := heap_merge heap1 heap2 in
+ let heap := heap_upd_option heap12 ret_w ret_a in
+ let v := (vs, heap) in
+ separated heap12 ret_w ret_a /\\
+ RunsTo env k v v' /\\
+ length temps' = temp_size /\\
+ st'#Sp = old_sp /\\
+ rv_postcond st'#Rv (fst v') |]).
+
+ Variable imports : LabelMap.t assert.
+
+ Variable imports_global : importsGlobal imports.
+
+ Variable modName : string.
+
+ Require CompileExpr.
+
+ Definition compile_expr e n := CompileExpr.compile vars temp_size imports_global modName e n.
+
+ Require CompileExprs.
+
+ Definition compile_exprs es n dst := CompileExprs.compile vars temp_size es n dst imports_global modName.
+
+ Definition compile := cmp vars temp_size imports_global loop_inv after_call compile_expr compile_exprs.
+
+ End TopSection.
+
+End Make."
+"Require Import AutoSep.
+Require Import ListFactsNew.
+
+Ltac hide_upd_sublist :=
+ repeat match goal with
+ | H : context [ upd_sublist ?L _ _ ] |- _ => set (upd_sublist L _ _) in *
+ end.
+
+"
+"Require Import Bedrock Factorial AMD64_gas.
+
+Definition compiled := moduleS factProg.
+Recursive Extraction compiled.
+"
+"Require Import Bedrock SharedListDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Set Implicit Arguments.
+
+Require Import Labels.
+Require Import GLabel.
+
+Definition to_bedrock_label (l : glabel) : label := (fst l, Global (snd l)).
+
+Coercion to_bedrock_label : glabel >-> label.
+
+Definition from_bedrock_label_map A (f : label -> A) (lbl : glabel) := f lbl.
+
+"
+"Require Import Syntax.
+
+Notation skip := Syntax.Skip.
+
+Infix "";:"" := Syntax.Seq (left associativity, at level 110).
+
+"
+"Ltac unfold_all :=
+ repeat match goal with
+ | H := _ |- _ => unfold H in *; clear H
+ end.
+
+Ltac inv_clear H :=
+ inversion H; unfold_all; subst; clear H.
+
+Ltac eapply_in_any t :=
+ match goal with
+ H : _ |- _ => eapply t in H
+ end.
+
+"
+"Require Import SyntaxExpr.
+
+(* The depth of stack actually used by compileExpr *)
+Fixpoint depth expr :=
+ match expr with
+ | Var _ => 0
+ | Const _ => 0
+ | Binop _ a b => max (depth a) (S (depth b))
+ | TestE _ a b => max (depth a) (S (depth b))
+ end.
+
+"
+"Require Import UseCellDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m1.
+Recursive Extraction compiled.
+"
+"Set Implicit Arguments.
+
+Require Import WordKey.
+Module K := W_as_UDT.
+Require Import WordMap.
+Module M := WordMap.
+Require Import FMapFacts.
+Include (Properties M).
+Include (Facts M).
+Require Import FMapFacts1.
+Include (WFacts_fun K M).
+Include (UWFacts_fun K M).
+Require Import FMapFacts2.
+Include (UWFacts_fun K M).
+"
+"Require Import SyntaxExpr SemanticsExpr.
+Require Import List.
+
+Fixpoint varsIn expr:=
+match expr with
+ | Var s => s :: nil
+ | Const w => nil
+ | SyntaxExpr.Binop op a b => varsIn a ++ varsIn b
+ | SyntaxExpr.TestE op a b => varsIn a ++ varsIn b
+end.
+
+"
+"Require Import Bedrock RtosDriver I386_gas.
+
+Module M.
+ Definition heapSize := (1024 * 1024)%N.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Require Import List.
+Require Import IL.
+Require Import ReifyExpr.
+Require Import SymIL.
+
+(* Reify the instructions *)
+Ltac collectTypes_loc isConst l Ts k :=
+ match l with
+ | Reg _ => k Ts
+ | Imm ?i => ReifyExpr.collectTypes_expr isConst i Ts k
+ | Indir _ ?i => ReifyExpr.collectTypes_expr isConst i Ts k
+ end.
+Ltac reify_loc isConst l types funcs uvars vars k :=
+ match l with
+ | Reg ?r =>
+ let res := constr:(@SymReg types r) in
+ k uvars funcs res
+ | Imm ?i =>
+ ReifyExpr.reify_expr isConst i types funcs uvars vars ltac:(fun uvars funcs i =>
+ let l := constr:(@SymImm types i) in k uvars funcs l)
+ | Indir ?r ?i =>
+ ReifyExpr.reify_expr isConst i types funcs uvars vars ltac:(fun uvars funcs i =>
+ let l := constr:(@SymIndir types r i) in k uvars funcs l)
+ end.
+
+Ltac collectTypes_lvalue isConst l Ts k :=
+ match l with
+ | LvReg _ => k Ts
+ | LvMem ?l => collectTypes_loc isConst l Ts k
+ | LvMem8 ?l => collectTypes_loc isConst l Ts k
+ end.
+
+Ltac reify_lvalue isConst l types funcs uvars vars k :=
+ match l with
+ | LvReg ?r => let l := constr:(@SymLvReg types r) in k uvars funcs l
+ | LvMem ?l =>
+ reify_loc isConst l types funcs uvars vars ltac:(fun uvars funcs l =>
+ let l := constr:(@SymLvMem types l) in k uvars funcs l)
+ | LvMem8 ?l =>
+ reify_loc isConst l types funcs uvars vars ltac:(fun uvars funcs l =>
+ let l := constr:(@SymLvMem8 types l) in k uvars funcs l)
+ end.
+
+Ltac collectTypes_rvalue isConst r Ts k :=
+ match r with
+ | RvLval ?l => collectTypes_lvalue isConst l Ts k
+ | RvImm ?i => ReifyExpr.collectTypes_expr isConst i Ts k
+ | RvLabel _ => let Ts := Reflect.cons_uniq label Ts in k Ts
+ end.
+
+Ltac reify_rvalue isConst r types funcs uvars vars k :=
+ match r with
+ | RvLval ?l =>
+ reify_lvalue isConst l types funcs uvars vars ltac:(fun uvars funcs l =>
+ let l := constr:(@SymRvLval types l) in k uvars funcs l)
+ | RvImm ?i =>
+ ReifyExpr.reify_expr isConst i types funcs uvars vars ltac:(fun uvars funcs i =>
+ let l := constr:(@SymRvImm types i) in k uvars funcs l)
+ | RvLabel ?l =>
+ let r := constr:(@SymRvLabel types l) in k uvars funcs r
+ end.
+
+Ltac collectTypes_instr isConst i Ts k :=
+ match i with
+ | Assign ?l ?r =>
+ collectTypes_lvalue isConst l Ts ltac:(fun Ts =>
+ collectTypes_rvalue isConst r Ts k)
+ | Binop ?l ?r1 _ ?r2 =>
+ collectTypes_lvalue isConst l Ts ltac:(fun Ts =>
+ collectTypes_rvalue isConst r1 Ts ltac:(fun Ts =>
+ collectTypes_rvalue isConst r2 Ts k ))
+ end.
+Ltac reify_instr isConst i types funcs uvars vars k :=
+ match i with
+ | Assign ?l ?r =>
+ reify_lvalue isConst l types funcs uvars vars ltac:(fun uvars funcs l =>
+ reify_rvalue isConst r types funcs uvars vars ltac:(fun uvars funcs r =>
+ let res := constr:(@SymAssign types l r) in k uvars funcs res))
+ | Binop ?l ?r1 ?o ?r2 =>
+ reify_lvalue isConst l types funcs uvars vars ltac:(fun uvars funcs l =>
+ reify_rvalue isConst r1 types funcs uvars vars ltac:(fun uvars funcs r1 =>
+ reify_rvalue isConst r2 types funcs uvars vars ltac:(fun uvars funcs r2 =>
+ let res := constr:(@SymBinop types l r1 o r2) in k uvars funcs res)))
+ end.
+
+Ltac collectTypes_instrs isConst is Ts k :=
+ match is with
+ | nil => k Ts
+ | ?i :: ?is =>
+ collectTypes_instr isConst i Ts ltac:(fun Ts =>
+ collectTypes_instrs isConst is Ts k)
+ end.
+Ltac reify_instrs isConst is types funcs uvars vars k :=
+ match is with
+ | nil =>
+ let is := constr:(@nil (sym_instr types)) in k uvars funcs is
+ | ?i :: ?is =>
+ reify_instr isConst i types funcs uvars vars ltac:(fun uvars funcs i =>
+ reify_instrs isConst is types funcs uvars vars ltac:(fun uvars funcs is =>
+ let res := constr:(i :: is) in k uvars funcs res))
+ end."
+"Require Import Bedrock RosMasterDriver I386_gas.
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Module Type S.
+
+ Parameter t : Type.
+
+End S."
+"Require Import FactorialRecurDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m1.
+Recursive Extraction compiled.
+"
+"(* FastString -- speedy versions of string functions from String
+
+This library defines tail-recursive, unverified versions of some of the
+functions in String. It\'s intended to be used in unverified applications
+(e.g., the Bedrock assembly generator) where speed is important. *)
+
+Require Import Ascii List.
+Require Export String.
+
+Module Import ForReverse.
+
+ Fixpoint foldString {A} (f : A -> ascii -> A) (str : string) (zero : A) : A :=
+ match str with
+ | EmptyString => zero
+ | String character str\' => foldString f str\' (f zero character)
+ end.
+
+ Definition prependReversed : string -> string -> string :=
+ foldString (fun char str => String str char).
+
+End ForReverse.
+
+Definition reverse str := prependReversed str """".
+
+Definition concat (strs : list string) : string :=
+ reverse (fold_left (fun x y => prependReversed y x) strs """"%string).
+
+Definition append x y := concat (x :: y :: nil).
+Infix ""++"" := append : string_scope.
+
+
+(* Intercalate. This implementation is direct from the Haskell base
+package. *)
+
+Module Import ForIntercalate.
+ Fixpoint prependToAll (sep : string) (xs : list string) :=
+ match xs with
+ | nil => nil
+ | x :: xs => sep :: x :: prependToAll sep xs
+ end.
+End ForIntercalate.
+
+Definition intersperse (sep : string) (xs : list string) : list string :=
+ match xs with
+ | nil => nil
+ | x :: xs => x :: prependToAll sep xs
+ end.
+
+Definition intercalate (sep : string) (xs : list string) : string :=
+ concat (intersperse sep xs).
+"
+"Require Import Bedrock CallbackDriver AMD64_gas.
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Require Import Bedrock MiniMasterDriver I386_gas.
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Set Implicit Arguments.
+
+Require Import Syntax.
+Require Import String.
+
+Record FuncCore :=
+ {
+ ArgVars : list string;
+ RetVar : string;
+ Body : Stmt
+ }.
+
+"
+"Require Import FreeVarsExpr.
+Require Import Syntax.
+Require Import StringSet.
+Require Import Option.
+Require Import Union.
+Import StringSet.
+
+Set Implicit Arguments.
+
+Local Notation e_free_vars := FreeVarsExpr.free_vars.
+
+Fixpoint free_vars (s : Syntax.Stmt) :=
+ match s with
+ | Syntax.Skip => empty
+ | Syntax.Seq a b => union (free_vars a) (free_vars b)
+ | Syntax.If cond t f => union (union (e_free_vars cond) (free_vars t)) (free_vars f)
+ | Syntax.While cond body => union (e_free_vars cond) (free_vars body)
+ | Syntax.Call var f args =>
+ union
+ (union
+ (default empty (option_map singleton var))
+ (e_free_vars f))
+ (union_list (List.map e_free_vars args))
+ | Syntax.Label x lbl => singleton x
+ | Syntax.Assign x e => union (singleton x) (e_free_vars e)
+ end.
+
+"
+"Require Export String List NArith.
+
+Require Export Heaps SepTheoryX SepIL.
+
+Require Export Nomega Word Memory IL LabelMap PropX PropXTac XCAP Structured StructuredModule Linker Programming.
+
+Require Export ILTac SymILTac Arrays Allocated.
+
+Open Scope string_scope.
+"
+"Require Import Syntax.
+Require DepthExpr.
+Require Import Max.
+
+Set Implicit Arguments.
+
+Local Notation edepth := DepthExpr.depth.
+
+Fixpoint depth statement :=
+ match statement with
+ | Syntax.Skip => 0
+ | Syntax.Seq a b => max (depth a) (depth b)
+ | Syntax.If cond t f => max (edepth cond) (max (depth t) (depth f))
+ | While cond body => max (edepth cond) (depth body)
+ | Syntax.Call _ f args => max (edepth f) (max_list 0 (List.map edepth args))
+ | Syntax.Label _ _ => 0
+ | Syntax.Assign _ e => edepth e
+ end."
+"Set Implicit Arguments.
+
+Ltac not_not :=
+ match goal with
+ | H : ~ _ |- ~ _ => unfold not; intro; contradict H
+ end.
+
+Ltac nintro := unfold not; intros.
+
+"
+"Require Import Bedrock PrintIntDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m1.
+Recursive Extraction compiled.
+"
+"Require Import Bedrock RtosDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := (1024 * 1024)%N.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m.
+Recursive Extraction compiled.
+"
+"Require Import SyntaxExpr.
+Require Import StringSet.
+Import StringSet.
+
+Set Implicit Arguments.
+
+Fixpoint free_vars expr:=
+ match expr with
+ |Var s => singleton s
+ |Const w => empty
+ |Binop op a b => union (free_vars a) (free_vars b)
+ |TestE te a b => union (free_vars a) (free_vars b)
+ end.
+
+"
+"Require Import SyntaxFunc.
+Require Import String.
+Export SyntaxFunc.
+
+Set Implicit Arguments.
+
+Record Module :=
+ {
+ Name : string;
+ Functions : list Func
+ }."
+"Require Import AutoSep Malloc.
+
+Require Import WordKey.
+
+Require Import MSetRBT.
+Module WordSet := Make W_as_OT_new.
+
+Section adt.
+ Variable P : WordSet.t -> W -> HProp.
+ Variable res : nat.
+
+ Definition newS := SPEC(""extra_stack"") reserving res
+ PRE[_] mallocHeap 0
+ POST[R] P WordSet.empty R * mallocHeap 0.
+
+ Definition deleteS := SPEC(""extra_stack"", ""self"") reserving res
+ Al s,
+ PRE[V] P s (V ""self"") * mallocHeap 0
+ POST[_] mallocHeap 0.
+
+ Definition memS := SPEC(""extra_stack"", ""self"", ""n"") reserving res
+ Al s,
+ PRE[V] P s (V ""self"") * mallocHeap 0
+ POST[R] [| R = WordSet.mem (V ""n"") s |] * P s (V ""self"") * mallocHeap 0.
+
+ Definition addS := SPEC(""extra_stack"", ""self"", ""n"") reserving res
+ Al s,
+ PRE[V] P s (V ""self"") * mallocHeap 0
+ POST[_] P (WordSet.add (V ""n"") s) (V ""self"") * mallocHeap 0.
+
+ Definition sizeS := SPEC(""extra_stack"", ""self"") reserving res
+ Al s,
+ PRE[V] P s (V ""self"") * mallocHeap 0
+ POST[R] [| R = WordSet.cardinal s |] * P s (V ""self"") * mallocHeap 0.
+End adt.
+"
+"Require Import ReturnZeroDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m1.
+Recursive Extraction compiled.
+"
+"Set Implicit Arguments.
+
+Require Import WordKey.
+
+Require Import FMapAVL.
+Module Import WordMap := Make W_as_OT.
+"
+"Set Implicit Arguments.
+
+Require Import StringSet.
+Require Import Equalities.
+Module K := Make_UDT StringKey.
+Module M := StringSet.
+Require Import FSetProperties.
+Include (Properties M).
+Require Import FSetFacts.
+Include (Facts M).
+Require Import FSetFacts1.
+Include (UWFacts_fun K M).
+"
+"Require Import String.
+
+Definition impl_module_name s := (""__impl_"" ++ s)%string."
+"Require Import Word.
+
+Definition B := word 8.
+Definition W := word 32.
+
+Section mem_ops.
+ Variable addr mem : Type.
+ Variable footprint_w : addr -> addr * addr * addr * addr.
+
+ Variable mem_get : mem -> addr -> option B.
+
+ Definition mem_get_word (implode : B * B * B * B -> W) (p : addr) (m : mem)
+ : option W :=
+ let '(a,b,c,d) := footprint_w p in
+ match mem_get m a , mem_get m b , mem_get m c , mem_get m d with
+ | Some a , Some b , Some c , Some d =>
+ Some (implode (a,b,c,d))
+ | _ , _ , _ , _ => None
+ end.
+
+ Variable mem_set : mem -> addr -> B -> option mem.
+
+ Definition mem_set_word (explode : W -> B * B * B * B) (p : addr) (v : W)
+ (m : mem) : option mem :=
+ let '(a,b,c,d) := footprint_w p in
+ let '(av,bv,cv,dv) := explode v in
+ match mem_set m d dv with
+ | Some m => match mem_set m c cv with
+ | Some m => match mem_set m b bv with
+ | Some m => mem_set m a av
+ | None => None
+ end
+ | None => None
+ end
+ | None => None
+ end.
+
+End mem_ops.
+"
+"Require Import IL Memory String.
+Require Import SyntaxExpr.
+
+Set Implicit Arguments.
+
+Fixpoint eval vs expr :=
+ match expr with
+ | Var str => vs str
+ | Const w => w
+ | Binop op a b => evalBinop op (eval vs a) (eval vs b)
+ | TestE op a b => if evalTest op (eval vs a) (eval vs b) then $1 else $0
+ end."
+"Set Implicit Arguments.
+
+Require Import GLabelKey.
+
+Require Import FMapAVL.
+Module GLabelMap := Make GLabel_as_OT."
+"Require Import Prover Env.
+Require Import ILEnv.
+Require provers.AssumptionProver.
+Require provers.ReflexivityProver.
+Require provers.WordProver.
+Require provers.ArrayBoundProver.
+
+Set Implicit Arguments.
+Set Strict Implicit.
+
+(** * The Combo Prover **)
+
+Definition comboTypes := repr_combine bedrock_types_r sep.Array.types_r.
+Definition comboFuncs types' := repr_combine (bedrock_funcs_r (repr comboTypes types'))
+ (Array.funcs_r (repr comboTypes types')).
+
+Definition ComboProver : ProverPackage :=
+{| ProverTypes := comboTypes
+ ; ProverFuncs := comboFuncs
+ ; Prover_correct := fun ts fs => composite_ProverT_correct
+ (composite_ProverT_correct (provers.AssumptionProver.assumptionProver_correct _)
+ (provers.ReflexivityProver.reflexivityProver_correct _))
+ (composite_ProverT_correct
+ (provers.WordProver.wordProver_correct (types' := repr comboTypes ts) (repr (comboFuncs ts) fs))
+ (provers.ArrayBoundProver.boundProver_correct (types' := repr comboTypes ts) (repr (comboFuncs ts) fs)))
+|}.
+"
+"Set Implicit Arguments.
+
+Definition default A def (x : option A) :=
+ match x with
+ | Some v => v
+ | None => def
+ end."
+"Require Import CountUniqueDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m1.
+Recursive Extraction compiled.
+"
+"Require Import Bedrock Echo2Driver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m1.
+Recursive Extraction compiled.
+"
+"Require Import AutoSep.
+
+Set Implicit Arguments.
+
+
+Ltac make_Himp := match goal with
+ | [ |- interp _ (![?P] _ ---> ![?Q] _)%PropX ] =>
+ let H := fresh in assert (P ===> Q); [ | rewrite sepFormula_eq in *; apply H ]
+ | [ |- himp _ ?P ?Q ] => let H := fresh in assert (H : P ===> Q); [ | apply H ]
+ end.
+"
+"Require Import FactorialDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m1.
+Recursive Extraction compiled.
+"
+"Set Implicit Arguments.
+
+Require Import Syntax.
+Require Import String.
+Require Import FuncCore.
+Export Syntax FuncCore.
+
+Record Func :=
+ {
+ Name : string;
+ Core : FuncCore
+ }.
+
+Coercion Core : Func >-> FuncCore.
+
+"
+"Require Parser.
+Require Datatypes.
+Require Analysis.
+Require Word.
+
+Require Import ExtrOcamlBasic.
+Require Import ExtrOcamlString.
+
+Extraction Language Ocaml.
+
+Extraction ""Main.ml"" Main.Make.
+Extraction ""Parser.ml"" Parser.pinstrs Datatypes.get_token.
+Extraction ""Analysis.ml"" Analysis.state Analysis.run_filter Word.wordToNat Word.natToWord.
+"
+"Require Import AutoSep Malloc.
+
+
+Section adt.
+ Variable P : list W -> W -> HProp.
+ Variable res : nat.
+
+ Definition newS := SPEC(""extra_stack"", ""len"") reserving res
+ PRE[V] [| goodSize (2 + wordToNat (V ""len"")) |] * mallocHeap 0
+ POST[R] Ex ws, P ws R * [| length ws = wordToNat (V ""len"") |] * mallocHeap 0.
+
+ Definition deleteS := SPEC(""extra_stack"", ""self"") reserving res
+ Al ws,
+ PRE[V] P ws (V ""self"") * mallocHeap 0
+ POST[_] mallocHeap 0.
+
+ Definition readS := SPEC(""extra_stack"", ""self"", ""n"") reserving res
+ Al ws,
+ PRE[V] P ws (V ""self"") * [| V ""n"" < natToW (length ws) |] * mallocHeap 0
+ POST[R] [| R = Array.sel ws (V ""n"") |] * P ws (V ""self"") * mallocHeap 0.
+
+ Definition writeS := SPEC(""extra_stack"", ""self"", ""n"", ""v"") reserving res
+ Al ws,
+ PRE[V] P ws (V ""self"") * [| V ""n"" < natToW (length ws) |] * mallocHeap 0
+ POST[_] P (Array.upd ws (V ""n"") (V ""v"")) (V ""self"") * mallocHeap 0.
+End adt.
+"
+"Require Import Bedrock AbortDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m1.
+Recursive Extraction compiled.
+"
+"Require Import Bedrock EchoDriver AMD64_gas.
+
+Module M.
+ Definition heapSize := 1024.
+End M.
+
+Module E := Make(M).
+
+Definition compiled := moduleS E.m1.
+Recursive Extraction compiled.
+"
+"Set Implicit Arguments.
+
+Require Import GoodFunction.
+
+Definition IsGoodModuleName (s : string) := prefix ""_"" s = false.
+
+Record GoodModule :=
+ {
+ Name : string;
+ GoodModuleName : IsGoodModuleName Name;
+ Functions : list GoodFunction;
+ NoDupFuncNames : NoDup (map (fun (f : GoodFunction) => SyntaxFunc.Name f) Functions)
+ }."
+"Set Implicit Arguments.
+
+Require Import ADT.
+Require Import RepInv.
+
+Module Make (Import E : ADT) (Import M : RepInv E).
+
+ Require Import PostOk.
+ Module Import PostOkMake := Make E M.
+ Require Import VerifCondOk.
+ Module Import VerifCondOkMake := Make E M.
+ Import CompileStmtSpecMake.
+ Import InvMake.
+ Import Semantics.
+ Import SemanticsMake.
+ Import InvMake2.
+
+ Section TopSection.
+
+ Require Import AutoSep.
+
+ Variable vars : list string.
+
+ Variable temp_size : nat.
+
+ Variable imports : LabelMap.t assert.
+
+ Variable imports_global : importsGlobal imports.
+
+ Variable modName : string.
+
+ Require Import Syntax.
+
+ Variable rv_postcond : W -> vals -> Prop.
+
+ Notation do_compile := (CompileStmtImplMake.compile vars temp_size rv_postcond imports_global modName).
+
+ Variable s k : Stmt.
+
+ Require Import Wrap.
+ Definition compile : cmd imports modName.
+ refine (
+ Wrap imports imports_global modName
+ (do_compile s k)
+ (fun _ => postcond vars temp_size k rv_postcond)
+ (verifCond vars temp_size s k rv_postcond)
+ _ _).
+ eapply post_ok.
+ eapply verifCond_ok.
+ Defined.
+
+ End TopSection.
+
+End Make."
+"Require Import XmlLang.
+Export XmlOutput XmlLang.
+
+
+Coercion XmlLang.Cdata : string >-> XmlLang.pat.
+Notation ""$ x"" := (XmlLang.Var x) (at level 0) : pat_scope.
+Notation ""$$ x"" := (XmlLang.TreeVar x) (at level 0) : pat_scope.
+Infix ""/"" := XmlLang.Tag : pat_scope.
+Infix ""&"" := XmlLang.Both (at level 41, right associativity) : pat_scope.
+Infix "";;"" := XmlLang.Ordered : pat_scope.
+Delimit Scope pat_scope with pat.
+Bind Scope pat_scope with pat.
+
+Coercion Const : string >-> exp.
+Notation ""$ x"" := (Input x) : exp_scope.
+Delimit Scope exp_scope with exp.
+Bind Scope exp_scope with exp.
+
+Notation ""col = e"" := ((col, e%exp) :: nil) : condition_scope.
+Infix ""&&"" := app : condition_scope.
+Delimit Scope condition_scope with condition.
+
+Coercion XCdata : string >-> xml.
+Notation ""$ x"" := (XVar x) : out_scope.
+Notation ""tab # col"" := (XColumn tab col) (at level 0) : out_scope.
+Definition xcons (x : xml) (xs : list xml) : list xml := x :: xs.
+Notation ""<*> tag > x1 , .. , xN >"" := (XTag tag (xcons x1 .. (xcons xN nil) ..))
+ (tag at level 0) : out_scope.
+Delimit Scope out_scope with out.
+Notation ""\'From\' tab \'Where\' cond \'Write\' o"" :=
+ (XSelect tab cond%condition o%out)
+ (at level 0, tab at level 0, cond at level 0, o at level 0) : out_scope.
+Notation ""\'From\' tab \'Write\' o"" :=
+ (XSelect tab nil o%out)
+ (at level 0, tab at level 0, o at level 0) : out_scope.
+Definition forJoin (o : xml) :=
+ match o with
+ | XColumn tab col => (tab, col)
+ | _ => ("""", """")
+ end.
+Notation ""\'Join\' x1 \'to\' x2 ;;; o"" :=
+ (let (tab1, col1) := forJoin x1 in
+ let (tab2, col2) := forJoin x2 in
+ XIfEqual tab1 col1 tab2 col2 o%out)
+ (at level 95, col1 at level 0, col2 at level 0, o at level 0) : out_scope.
+Bind Scope out_scope with xml.
+
+Definition econs (x : exp) (xs : list exp) : list exp := x :: xs.
+Notation ""\'Insert\' t ( e1 , .. , eN )"" := (XmlLang.Insert t (econs e1%exp .. (econs eN%exp nil) ..))
+ (at level 0, t at level 0) : action_scope.
+Notation ""\'Delete\' tab \'Where\' cond"" :=
+ (Delete tab cond%condition)
+ (at level 0, tab at level 0, cond at level 0) : action_scope.
+Notation ""\'Write\' o"" := (Output o%out) (at level 0, o at level 0) : action_scope.
+Infix "";;"" := Seq : action_scope.
+Notation ""\'IfHas\' tab \'Where\' cond \'then\' a1 \'else\' a2 \'end\'"" :=
+ (IfExists tab cond%condition a1 a2)
+ (at level 0, tab at level 0, cond at level 0, a1 at level 0, a2 at level 0) : action_scope.
+Delimit Scope action_scope with action.
+Notation ""\'From\' tab \'Where\' cond \'Do\' a"" :=
+ (XmlLang.Select tab cond%condition a%action)
+ (at level 0, tab at level 0, cond at level 0, a at level 0) : action_scope.
+Notation ""\'From\' tab \'Do\' a"" :=
+ (XmlLang.Select tab nil a%action)
+ (at level 0, tab at level 0, a at level 0) : action_scope.
+Notation ""\'Send\' x1 \'Value\' x2"" :=
+ (XmlLang.SendTo x1%out x2%out) (at level 0, x1 at level 0, x2 at level 0) : action_scope.
+Bind Scope action_scope with action.
+
+Notation ""\'Match\' p \'Do\' a \'end\'"" := (Rule p%pat a%action) : program_scope.
+Infix "";;"" := PSeq : program_scope.
+Delimit Scope program_scope with program.
+Bind Scope program_scope with program.
+
+Ltac wf\'\' :=
+ match goal with
+ | [ |- exists t, _ /\\ Name t = ?s /\\ _ ] =>
+ match goal with
+ | [ |- context[{| Name := s; Address := ?a; Schema := ?sch |}] ] =>
+ exists {| Name := s; Address := a; Schema := sch |}; simpl; intuition
+ end
+ | _ =>
+ repeat match goal with
+ | [ H : List.Exists _ _ |- _ ] => inversion H; clear H; subst
+ end; simpl in *; tauto
+ | _ => constructor
+ end.
+
+Ltac wf\' :=
+ match goal with
+ | [ |- (_ <= _)%nat ] => compute; omega
+ | [ |- (_ >= _)%N ] => discriminate
+ | [ |- (_ < _)%N ] => reflexivity
+ | [ |- NoDup _ ] => NoDup
+ | [ |- twfs _ ] => repeat constructor
+ | [ |- uf _ ] => repeat (constructor; simpl; intuition (try congruence))
+ | _ => simpl; intuition (try (congruence || reflexivity || NoDup)); repeat wf\'\'
+ end.
+
+Ltac wf := constructor; wf\'.
+"
+"// File example.v
+//
+// Below is an example of a comment that is mis-parsed by exuberant ctags.
+// It uses the multi-line comment format, i.e. /* ... */ except that in
+// this case, the character sequence immediately preceeding the closing
+// delimiter is an asterisk. (Any even number of asterisks would have the
+// same problem.
+// The line immediately afterwards is used to demonstrate the problem.
+// the module name 'wahoo' isn't recognised, because the parser mistakenly
+// thinks we are still in a multi-line comment.
+/*
+ * I am a multi-line comment
+ * I happen to end in a strange
+ * (but legal) way: **/
+module wahoo ()
+begin
+end
+"
+"/**************************************************************************
+****
+* test task one
+* the line below has 53 asteriks
+*****************************************************/
+task pass_task_1;
+begin
+end
+endtask
+
+/**************************************************************************
+****
+* test task one
+* the line below has 54 asteriks
+******************************************************/
+task fail_task_2;
+begin
+end
+endtask
+
+/**************************************************************************
+****
+* test function one
+* the line below has 53 asteriks
+*****************************************************/
+function pass_func_1;
+begin
+end
+endfunction
+
+/**************************************************************************
+****
+* test function two
+* the line below has 54 asteriks
+******************************************************/
+function fail_func_2;
+begin
+end
+endfunction
+
+/**************************************************************************
+****
+* test function one
+* the line below has 53 asteriks
+*****************************************************/
+`define pass_define_1 1'b1;
+
+/**************************************************************************
+****
+* test function two
+* the line below has 54 asteriks
+******************************************************/
+`define fail_define_2 1'b1;
+"
+"// somewhat contrived, but i came across a real-life file that caused this
+// crash.
+value=
+hello/
+world;
+"
+"/*
+ * In Verilog, the following two lines are both valid syntax:
+ *
+ * `define GUEST
+ * `define GUEST
+ *
+ * The first defines ""GUEST"" as existing, but with no assigned
+ * value. The second defines ""GUEST"" as existing with an
+ * assigned value. Ctags55 correctly handles both cases, but
+ * Ctags551 - Ctags554 only handles the `define with value
+ * correctly. Here is some test code to demonstrate this:
+ */
+`define HOSTA
+`define HOSTB
+`define HOSTC
+`define HOSTD
+
+`define GUESTA 1
+`define GUESTB 2
+`define GUESTC 3
+`define GUESTD 4
+/*
+ * Ctags55 correctly generates a tag for all `defines in the
+ * code, but Ctags554 does not generate tags for ""HOSTB""
+ * or ""HOSTD"".
+ */
+"
+"/*
+*
+**/
+module top(outsig, insig);
+output outsig;
+input insig;
+assign outsig = insig;
+endmodule
+"
+"parameter ramaddr_0 = {1'b1,9'd0};
+"
+"// Taken from http://www.europa.com/~celiac/fsm_samp.html
+
+// These are the symbolic names for states
+parameter [1:0] //synopsys enum state_info
+ S0 = 2'h0,
+ S1 = 2'h1,
+ S2 = 2'h2,
+ S3 = 2'h3;
+
+// These are the current state and next state variables
+reg [1:0] /* synopsys enum state_info */ state;
+reg [1:0] /* synopsys enum state_info */ next_state;
+
+
+// synopsys state_vector state
+
+always @ (state or y or x)
+begin
+ next_state = state;
+ case (state) // synopsys full_case parallel_case
+ S0: begin
+ if (x) begin
+ next_state = S1;
+ end
+ else begin
+
+ next_state = S2;
+ end
+ end
+ S1: begin
+ if (y) begin
+ next_state = S2;
+ end
+ else begin
+ next_state = S0;
+ end
+ end
+ S2: begin
+ if (x & y) begin
+ next_state = S3;
+ end
+ else begin
+ next_state = S0;
+ end
+ end
+ S3: begin
+ next_state = S0;
+ end
+ endcase
+end
+
+
+always @ (posedge clk or posedge reset)
+begin
+ if (reset) begin
+ state <= S0;
+ end
+ else begin
+ state <= next_state;
+ end
+end
+"
+"// http://www.eg.bucknell.edu/~cs320/1995-fall/verilog-manual.html#RTFToC33
+
+// Digital model of a traffic light
+// By Dan Hyde August 10, 1995
+module traffic;
+parameter on = 1, off = 0, red_tics = 35,
+ amber_tics = 3, green_tics = 20;
+reg clock, red, amber, green;
+
+// will stop the simulation after 1000 time units
+initial begin: stop_at
+ #1000; $stop;
+end
+
+// initialize the lights and set up monitoring of registers
+initial begin: Init
+ red = off; amber = off; green = off;
+ $display("" Time green amber red"");
+ $monitor(""%3d %b %b %b"", $time, green, amber, red);
+end
+
+// task to wait for \'tics\' positive edge clocks
+// before turning light off
+task light;
+ output color;
+ input [31:0] tics;
+ begin
+ repeat(tics) // wait to detect tics positive edges on clock
+ @(posedge clock);
+ color = off;
+ end
+endtask
+
+// waveform for clock period of 2 time units
+always begin: clock_wave
+ #1 clock = 0;
+ #1 clock = 1;
+end
+
+always begin: main_process
+ red = on;
+ light(red, red_tics); // call task to wait
+ green = on;
+ light(green, green_tics);
+ amber = on;
+ light(amber, amber_tics);
+end
+
+endmodule
+"
+"/*
+Bugs item #762027, was opened at 2003-06-27 18:32
+Message generated for change (Tracker Item Submitted) made by Item Submitter
+You can respond by visiting:
+https://sourceforge.net/tracker/?func=detail&atid=106556&aid=762027&group_id=6556
+
+Category: None
+Group: None
+Status: Open
+Resolution: None
+Priority: 5
+Submitted By: cdic (cdic)
+Assigned to: Nobody/Anonymous (nobody)
+Summary: multi-line definition w/o back-slash will be missing
+
+Initial Comment:
+There is a small bug (language verilog):
+*/
+ wire N_84, N_83; // is ok.
+
+ wire N_84,
+ N_83; // then N_83 will be missing in tags.
+/*
+Thanks for fixing it.
+
+cdic
+*/
+"
+"/**
+ * microcodeundefs.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+`undef MCROM_WIDTH
+`undef OFFSET_WIDTH
+`undef AC_SOURCE
+`undef WRITE_AC
+`undef MAR_SOURCE
+`undef WRITE_MAR
+`undef MDR_SOURCE
+`undef WRITE_MDR
+`undef ALU_OP_SELECT
+`undef PC_SOURCE
+`undef WRITE_PC
+`undef WRITE_FLAGS
+`undef ALUCTL
+`undef ROM_OFFSET_EN
+`undef OFFSET_NEXT_SEL/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * clk_gen.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 18:29:34 04/26/2015
+// Design Name:
+// Module Name: clk_gen
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module clk_gen(
+\t\tinput wire\t\t\t\tbutton,
+\t\tinput wire\t\t\t\tclk,
+\t\tinput wire\t\t\t\tres,
+\t\toutput wire\t\t\t\tclk_div
+ );
+
+\treg [3 : 0] ripple;
+\tassign clk_div = &ripple;
+\t
+\talways @(posedge clk) begin
+\t\tif(res)
+\t\t\tripple <= 4'b0;
+\t\telse begin
+\t\t\tripple[0] <= button;
+\t\t\tripple[1] <= ripple[0];
+\t\t\tripple[2] <= ripple[1];
+\t\t\tripple[3] <= ripple[2];
+\t\tend
+\tend
+endmodule
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * microcodedefs.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+`include ""aludefs.v""
+/* microcode ROM width */
+`define MCROM_WIDTH\t\t27
+`define OFFSET_WIDTH \t6 /* number of bits in microcode offset */
+/* microcode ROM word layout */
+
+`define AC_SOURCE\t\t1:0\t\t\t\t/* accumulator source */
+`define WRITE_AC\t\t2\t\t\t\t/* enable write to accumulator */
+`define MAR_SOURCE\t\t3\t\t\t\t/* memory address register source */
+`define WRITE_MAR\t\t4\t\t\t\t/* enable write to memory address register */
+`define MDR_SOURCE\t\t6:5\t\t\t\t/* memory data register source */
+`define WRITE_MDR\t\t7\t\t\t\t/* enable write to memory data register */
+`define PC_SOURCE\t\t9:8\t\t\t\t/* program counter register source */
+`define WRITE_PC\t\t10\t\t\t\t/* enable write to program counter register */
+`define WRITE_IR\t\t11\t\t\t\t/* enable write to instruction register */
+`define WRITE_FLAGS\t\t12\t\t\t\t/* enable write to flags register */
+`define WRITE_MEM\t\t13\t\t\t\t/* enable write to memory */
+`define ALU_OP_SELECT\t16:14\t\t\t/* ALU operand selection */
+`define ALUCTL\t\t(16 + `ALUCTLW):17\t/* ALU control */
+
+/* offset of next microcode address */
+`define OFFSET_NEXT\t\t(`MCROM_WIDTH - 2):(`MCROM_WIDTH - `OFFSET_WIDTH - 1)
+/* offset selection */
+`define OFFSET_NEXT_SEL\t(`MCROM_WIDTH - 1)
+
+`include ""aluundefs.v""/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * ff_d.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+module ff_d #(parameter WIDTH=8) (
+\t\tinput wire\t\t[WIDTH - 1 : 0]\tD,\t\t/* data input */
+\t\tinput wire\t\t\t\t\t\ten,\t\t/* enable */
+\t\tinput wire\t\t\t\t\t\tclk,\t/* clock */
+\t\tinput wire\t\t\t\t\t\tres,\t/* synchronous active high reset */
+\t\toutput wire\t\t[WIDTH - 1 : 0]\tQ\t\t/* output */
+ );
+\t
+\treg [WIDTH - 1 : 0] storage;
+\tassign Q = storage;
+\t
+\talways @(posedge clk) begin
+\t\tif(res)\t\t\t\t\t\t\t\t\t/* handle synchronous reset */
+\t\t\tstorage <= {WIDTH{1'b0}};
+\t\telse if(en)\t\t\t\t\t\t\t\t/* handle save data */
+\t\t\tstorage <= D;
+\tend
+endmodule
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * controller_unit_tb.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+module controller_unit_tb;
+
+\t/* input signals */
+\treg [7:0] opcode;
+\treg clk;
+\treg res;
+
+\t/* output signals */
+\twire [1:0] ac_source;
+\twire write_ac;
+\twire mar_source;
+\twire write_mar;
+\twire [1:0] mdr_source;
+\twire write_mdr;
+\twire write_flags;
+\twire [1:0] pc_source;
+\twire write_pc;
+\twire write_ir;
+\twire write_mem;
+\twire [2:0] ALU_op_select;
+\twire [2:0] ALUctl;
+
+\t/* unit under testing */
+\tcontroller_unit uut (
+\t\t\t.opcode(opcode),
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.ac_source(ac_source),
+\t\t\t.write_ac(write_ac),
+\t\t\t.mar_source(mar_source),
+\t\t\t.write_mar(write_mar),
+\t\t\t.mdr_source(mdr_source),
+\t\t\t.write_mdr(write_mdr),
+\t\t\t.write_flags(write_flags),
+\t\t\t.pc_source(pc_source),
+\t\t\t.write_pc(write_pc),
+\t\t\t.write_ir(write_ir),
+\t\t\t.write_mem(write_mem),
+\t\t\t.ALU_op_select(ALU_op_select),
+\t\t\t.ALUctl(ALUctl)
+\t\t);
+
+\tinitial begin
+\t\t/* initialize signals */
+\t\topcode = 8\'h03;
+\t\tclk = 0;
+\t\tres = 1;
+
+\t\t$dumpfile(""controller_unit.vcd"");
+\t\t$dumpvars;
+
+\t\t/* release reset */
+\t\t#100\tres = 0;
+\t\t
+\t\t/* finish simulation */
+\t\t#1000\t$finish;
+\tend
+\t
+\talways
+\t\t#50\t\tclk = ~clk;
+
+endmodule
+
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * processor.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+`include ""aludefs.v""
+module processor(
+\t\t/* inputs */
+\t\tinput wire\t\t\t\t\tclk,\t\t\t/* clock */
+\t\tinput wire\t\t\t\t\tres,\t\t\t/* reset */
+\t\tinput wire\t\t[15 : 0]\tinstruction_in,\t/* instruction word */
+\t\tinput wire\t\t[ 7 : 0]\tmdr_in,\t\t\t/* memory data input */
+\t\t/* outputs */
+\t\toutput wire\t\t[ 7 : 0]\tpc_out,\t\t\t/* program counter */
+\t\toutput wire\t\t[ 7 : 0]\tmdr_out,\t\t/* memory data output */
+\t\toutput wire\t\t[ 7 : 0]\tmar_out,\t\t/* memory address */
+\t\toutput wire\t\t\t\t\twrite_mem\t\t/* memory write enable */
+ );
+
+\t/* internal signals */
+\twire\t[15 : 0]\tinstruction;\t/* instruction register output */
+\twire\t[`FWIDTH - 1 : 0] flags;\t/* ALU flags register */
+\twire \t[ 7 : 0] \topcode,\t\t\t/* intruction opcode */
+\t\t\t\t\t\timmediate;\t\t/* instruction immediate constant */
+\twire\t[ 1 : 0]\tac_source;\t\t/* accumulator register source */
+\twire \t\t\t\twrite_ac,\t\t/* write accumulator register */
+\t\t\t\t\t\tmar_source,\t\t/* memory address register source */
+\t\t\t\t\t\twrite_mar;\t\t/* write memory address register */
+\twire\t[ 1 : 0]\tmdr_source;\t\t/* memory data register source */
+\twire\t\t\t\twrite_mdr,\t\t/* write memory data register */
+\t\t\t\t\t\twrite_flags;\t/* write flags register */
+\twire\t[ 1 : 0]\tpc_source;\t\t/* program counter register source */
+\twire\t\t\t\twrite_pc,\t\t/* write program counter register */
+\t\t\t\t\t\twrite_ir;\t\t/* write instruction register */
+\twire\t[ 2 : 0]\tALU_op_select;\t/* ALU operator select */
+\twire\t[`ALUCTLW - 1 : 0] ALUctl;\t/* ALU control signal bus */
+\t
+\t
+\tassign opcode = instruction[15 : 8];
+\tassign immediate = instruction[ 7 : 0];
+
+\t/* instruction register */
+\tff_d #(.WIDTH(16)) ir (
+\t\t\t.D(instruction_in),
+\t\t\t.en(write_ir),
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.Q(instruction)
+\t\t);
+
+\t/* control unit */
+\tcontroller_unit cr0 (
+\t\t\t/* inputs */
+\t\t\t.opcode(opcode),
+\t\t\t.flags(flags),
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t/* outputs */
+\t\t\t.ac_source(ac_source),
+\t\t\t.write_ac(write_ac),
+\t\t\t.mar_source(mar_source),
+\t\t\t.write_mar(write_mar),
+\t\t\t.mdr_source(mdr_source),
+\t\t\t.write_mdr(write_mdr),
+\t\t\t.write_flags(write_flags),
+\t\t\t.pc_source(pc_source),
+\t\t\t.write_pc(write_pc),
+\t\t\t.write_ir(write_ir),
+\t\t\t.write_mem(write_mem),
+\t\t\t.ALU_op_select(ALU_op_select),
+\t\t\t.ALUctl(ALUctl)
+\t\t);
+\t\t
+\t/* datapath */
+\tdatapath dp0 (
+\t\t\t.immediate(immediate),
+\t\t\t.mdr_in(mdr_in),
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.ac_source(ac_source),
+\t\t\t.write_ac(write_ac),
+\t\t\t.mar_source(mar_source),
+\t\t\t.write_mar(write_mar),
+\t\t\t.mdr_source(mdr_source),
+\t\t\t.write_mdr(write_mdr),
+\t\t\t.write_flags(write_flags),
+\t\t\t.pc_source(pc_source),
+\t\t\t.write_pc(write_pc),
+\t\t\t.ALU_op_select(ALU_op_select),
+\t\t\t.ALUctl(ALUctl),
+\t\t\t.mar_out(mar_out),
+\t\t\t.mdr_out(mdr_out),
+\t\t\t.pc_out(pc_out),
+\t\t\t.flags(flags)
+\t\t);
+endmodule
+`include ""aluundefs.v""
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * clock_divider.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+module clock_divider(
+\t\tinput wire\t\t\t\t\tclk,
+\t\tinput wire\t\t\t\t\tres,
+\t\tinput wire\t\t[ 1 : 0]\tprescaler,
+\t\toutput wire\t\t\t\t\tclk_out
+ );
+
+\treg \t\t\t\t\tclk_div;
+\treg [ 2**16 - 1 : 0 ]\tcounter;
+\treg [ 2**16 - 1 : 0 ]\tcounter2;
+\t
+\tassign clk_out = clk_div;
+\t
+\talways @(prescaler or clk or counter or counter2) begin
+\t\tcase(prescaler)
+\t\t\t2'b00:\tclk_div = clk;
+\t\t\t2'b01:\tclk_div = counter[0];
+\t\t\t2'b10:\tclk_div = counter[2**16 - 1];
+\t\t\t2'b11:\tclk_div = counter2[2**8 - 1];
+\t\tendcase
+\tend
+
+\talways @(posedge clk) begin
+\t\tif(res) begin
+\t\t\tcounter <= {(2**22 - 1){1'b0}};
+\t\t\tcounter2 <= {(2**22 - 1){1'b0}};
+\t\tend
+\t\telse counter <= counter + 1'b1;
+\tend
+\t
+\talways @(counter[2**16 - 1])
+\t\tcounter2 <= counter2 + 1'b1;
+\t
+
+endmodule
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * memory_decoder.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+/* memory decoder unit */
+module memory_decoder(
+\t\tinput wire\t\t[ 7 : 0]\taddress,\t\t/* address input */
+\t\tinput wire\t\t[ 7 : 0]\tdata_in,\t\t/* data input */
+\t\tinput wire\t\t[ 7 : 0]\tswitch_in,\t\t/* I/O switch input */
+\t\tinput wire\t\t\t\t\tclk,\t\t\t/* clock */
+\t\tinput wire\t\t\t\t\tres,\t\t\t/* reset */
+\t\tinput wire\t\t\t\t\twrite_enable,\t/* memory write enable */
+\t\toutput wire\t\t[ 7 : 0]\tLED_status,\t\t/* I/O LED output */
+\t\toutput wire\t\t[ 7 : 0]\tdata_out\t\t/* memory data output */
+ );
+
+\t/* internal wires and registers */
+\twire\t[ 7 : 0]\tmemory_data_out;
+\twire\t\t[ 7 : 0]\tswitch_data_out;
+\t
+\twire mem_write_enable, LED_write_enable;
+\t
+\t/* mask write to address 0xff for LED usage */
+\tassign mem_write_enable = write_enable & (~&address);
+\t/* sram block */
+\tsram sram0 (
+\t\t\t.address(address),
+\t\t\t.data_in(data_in),
+\t\t\t.clk(clk),
+\t\t\t.write_enable(mem_write_enable),
+\t\t\t.data_out(memory_data_out)
+\t\t);
+\t
+\t/* decode LED address */
+\tassign LED_write_enable = write_enable & (&address);
+\t/* LED output driver flip flop */
+\tff_d #(.WIDTH(8)) led_driver0 (
+\t\t\t.D(data_in),
+\t\t\t.en(LED_write_enable),
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.Q(LED_status)
+\t\t);
+\t
+\t/* switch input driver flip flop */
+\tff_d #(.WIDTH(8)) switch_driver0 (
+\t\t\t.D(switch_in),
+\t\t\t.en(1'b1),
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.Q(switch_data_out)
+\t\t);
+\t
+\t/* decode read address */
+\tassign data_out = (~&address) ? memory_data_out : switch_data_out;
+\t
+endmodule
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * ALU.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+`include ""aludefs.v""
+
+module ALU #(parameter WIDTH=8) (
+\t\tinput wire\t\t[WIDTH - 1 : 0] \top1,
+\t\tinput wire\t\t[WIDTH - 1 : 0] \top2,
+\t\tinput wire\t\t[`ALUCTLW - 1: 0]\tctl,
+\t\tinput wire\t\t[`FWIDTH - 1 : 0]\tflags_in,
+\t\toutput wire\t\t[WIDTH - 1 : 0] \tresult,
+\t\toutput wire\t\t[`FWIDTH - 1 : 0]\tflags_out
+ );
+\t
+\t/* internal signals */
+\treg [`FWIDTH - 1 : 0] flags;
+\treg [WIDTH - 1 : 0] alu_out;
+\twire msb1, msb2, msb3;
+\t
+\t/* ALU output */
+\tassign flags_out = flags;
+\tassign result = alu_out;
+\t
+\t/* internal wiring */
+\tassign msb1 = op1[WIDTH - 1];
+\tassign msb2 = op2[WIDTH - 1];
+\tassign msb3 = result[WIDTH - 1];
+\t
+\t/* ALU multiplexer and behaviour */
+\talways @(*) begin
+\t\tflags = {`FWIDTH{1\'b0}};
+\t\tcase(ctl)
+\t\t\t3\'b000:\tbegin\t/* add: op1 + op2 */
+\t\t\t\t\t/* sum and carry */
+\t\t\t\t\t{flags[`CARRY_FLAG], alu_out} = op1 + op2;
+\t\t\t\t\t/* overflow detect */
+\t\t\t\t\tflags[`OVERFLOW_FLAG] =\t((~msb1) & (~msb2) & msb3)
+\t\t\t\t\t\t\t\t\t\t\t| (msb1 & msb2 & (~msb3));
+\t\t\t\t\t/* negative flag */
+\t\t\t\t\tflags[`NEGATIVE_FLAG] = msb3;
+\t\t\t\tend
+\t\t\t3\'b001:\tbegin\t/* add with carry: op1 + op2 + carry_in */
+\t\t\t\t\t/* sum and carry */
+\t\t\t\t\t{flags[`CARRY_FLAG], alu_out} = op1 + op2 + flags_in[`CARRY_FLAG];
+\t\t\t\t\t/* overflow detect */
+\t\t\t\t\tflags[`OVERFLOW_FLAG] =\t((~msb1) & (~msb2) & msb3)
+\t\t\t\t\t\t\t\t\t\t\t| (msb1 & msb2 & (~msb3));
+\t\t\t\t\t/* negative flag */
+\t\t\t\t\tflags[`NEGATIVE_FLAG] = msb3;
+\t\t\t\tend
+\t\t\t3\'b010:\tbegin\t/* subtract: op2 - op1 */
+\t\t\t\t\t{flags[`CARRY_FLAG], alu_out} = op2 - op1;
+\t\t\t\t\t/* overflow detect */
+\t\t\t\t\tflags[`OVERFLOW_FLAG] =\t((~msb1) & (~msb2) & msb3)
+\t\t\t\t\t\t\t\t\t\t\t| (msb1 & msb2 & (~msb3));
+\t\t\t\t\t/* negative flag */
+\t\t\t\t\tflags[`NEGATIVE_FLAG] = msb3;
+\t\t\t\tend
+\t\t\t3\'b011:\tbegin\t/* subtract with carry */
+\t\t\t\t\t{flags[`CARRY_FLAG], alu_out} = op2 - op1 - flags_in[`CARRY_FLAG];
+\t\t\t\t\t/* overflow detect */
+\t\t\t\t\tflags[`OVERFLOW_FLAG] =\t((~msb1) & (~msb2) & msb3)
+\t\t\t\t\t\t\t\t\t\t\t| (msb1 & msb2 & (~msb3));
+\t\t\t\t\t/* negative flag */
+\t\t\t\t\tflags[`NEGATIVE_FLAG] = msb3;
+\t\t\t\tend
+\t\t\t3\'b100:\tbegin\t/* nand */
+\t\t\t\t\talu_out = ~(op1 & op2);
+\t\t\t\tend
+\t\t\t3\'b101:\tbegin\t/* nor */
+\t\t\t\t\talu_out = ~(op1 | op2);
+\t\t\t\tend
+\t\t\t3\'b110:\tbegin\t/* xor */
+\t\t\t\t\talu_out = op1 ^ op2;
+\t\t\t\tend
+\t\t\t3\'b111:\tbegin\t/* shift right arithmetic */
+\t\t\t\t\talu_out = {op1[WIDTH - 1], op1[WIDTH - 1 : 1]};
+\t\t\t\t\tflags[`CARRY_FLAG] = op1[0];
+\t\t\t\tend
+\t\t\tdefault:
+\t\t\t\talu_out = {WIDTH{1\'b0}};
+\t\tendcase
+\t\tflags[`ZERO_FLAG] = ~|alu_out;
+\tend
+\t
+endmodule
+
+`include ""aluundefs.v""
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * decoder_complex_tb.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+module decoder_complex_tb;
+\t/* inputs and control signals */
+\treg [7:0] opcode;
+\treg clk;
+
+\t/* output signal */
+\twire [5:0] rom_offset;
+
+\t/* unit under testing */
+\tdecoder_complex uut (
+\t\t\t.opcode(opcode),
+\t\t\t.rom_offset(rom_offset)
+\t\t);
+
+\tinitial begin
+\t\t/* signal initialization */
+\t\topcode = 0;
+\t\tclk = 0;
+
+\t\t/* finish simulation */
+\t\t#1000\t$finish;
+\tend
+\t
+\talways
+\t\t#50\t\tclk = ~clk;
+
+\talways @(posedge clk)
+\t\topcode = opcode + 1'b1;
+
+endmodule
+
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * datapath.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+`include ""aludefs.v""
+
+module datapath(
+\t\t/* regular inputs */
+\t\tinput wire\t\t[ 7 : 0]\t\timmediate,\t\t/* instruction predicate */
+\t\tinput wire\t\t[ 7 : 0]\t\tmdr_in,\t\t\t/* memory data register input */
+\t\t/* toplevel signals */
+\t\tinput wire\t\t\t\t\t\tclk,\t\t\t/* clock signal */
+\t\tinput wire\t\t\t\t\t\tres,\t\t\t/* reset signal */
+\t\t/* control signals */
+\t\tinput wire\t\t[ 1 : 0]\t\tac_source,\t\t/* accumulator source */
+\t\tinput wire\t\t\t\t\t\twrite_ac,\t\t/* write accumulator */
+\t\tinput wire\t\t\t\t\t\tmar_source,\t\t/* memory address register source */
+\t\tinput wire\t\t\t\t\t\twrite_mar,\t\t/* write memory address register */
+\t\tinput wire\t\t[ 1 : 0]\t\tmdr_source,\t\t/* memory data register source */
+\t\tinput wire\t\t\t\t\t\twrite_mdr,\t\t/* write memory data register */
+\t\tinput wire\t\t\t\t\t\twrite_flags,\t/* write flags register */
+\t\tinput wire\t\t[ 1 : 0]\t\tpc_source,\t\t/* program counter source */
+\t\tinput wire\t\t\t\t\t\twrite_pc,\t\t/* write program counter */
+\t\tinput wire\t\t[ 2 : 0]\t\tALU_op_select,\t/* ALU operand source */
+\t\tinput wire\t\t[`ALUCTLW - 1: 0]\tALUctl,\t\t/* ALU control signal bus */
+\t\t/* output signals */
+\t\toutput wire\t\t[ 7 : 0]\t\t\tmar_out,\t/* memory address */
+\t\toutput wire\t\t[ 7 : 0]\t\t\tmdr_out,\t/* data */
+\t\toutput wire\t\t[ 7 : 0]\t\t\tpc_out,\t\t/* program counter */
+\t\toutput wire\t\t[`FWIDTH - 1 : 0]\tflags\t\t/* ALU flags */
+ );
+\t
+\t/* internal signals */
+\twire [ 7 : 0] ALU_feedback,\t\t\t\t\t\t/* ALU output and feedback path */
+\t\t\tpc_next,\t\t\t\t\t\t\t\t/* next program counter */
+\t\t\tac_out,\t\t\t\t\t\t\t\t\t/* accumulator data output */
+\t\t\tac_in,\t\t\t\t\t\t\t\t\t/* accumulator data input */
+\t\t\talu_operand,\t\t\t\t\t\t\t/* second ALU operand */
+\t\t\tmar_data,\t\t\t\t\t\t\t\t/* memory address register data source */
+\t\t\tmdr_data;\t\t\t\t\t\t\t\t/* memory data register data source */
+\t
+\twire [`FWIDTH - 1 : 0] flags_out;\t\t\t\t/* flags */
+\t
+\t/* program counter jump select
+\t * pc_source:
+\t * 00: regular execution
+\t * 01: direct jump
+\t * 10: indirect jump
+\t * 11: jump with offset
+\t * rationale:
+\t * mechanism allows for implementation of both direct jumps
+\t * and indirect jumps.
+\t */
+\tmux4 #(.WIDTH(8)) pc_mux (
+\t\t\t.in0(pc_out + 8\'b1),
+\t\t\t.in1(immediate),
+\t\t\t.in2(ac_out),
+\t\t\t.in3(pc_out + ac_out),
+\t\t\t.sel(pc_source),
+\t\t\t.mux_out(pc_next)
+\t\t);
+
+\t/* program counter register */
+\tff_d #(.WIDTH(8)) pc (
+\t\t\t.D(pc_next),
+\t\t\t.en(write_pc),
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.Q(pc_out)
+\t\t);
+\t
+\t/* flags register
+\t * rationale:
+\t * keep ALU flags for new operations/CPU status
+\t */
+\tff_d #(.WIDTH(`FWIDTH)) flags_register (
+\t\t\t.D(flags_out),
+\t\t\t.en(write_flags),
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.Q(flags)
+\t\t);
+
+\t/* accumulator input select:
+\t * ac_source:
+\t * 00: store value in memory address register
+\t * 01: store value in memory data register
+\t * 10: store result from ALU into accumulator
+\t * 11: store immediate into accumulator
+\t * rationale:
+\t * mechanism allows for accumulator behaviour and for loading
+\t * a numeric constant into accumulator.
+\t */
+\tmux4 #(.WIDTH(8)) ac_mux (
+\t\t\t.in0(mar_out),
+\t\t\t.in1(mdr_out),
+\t\t\t.in2(ALU_feedback),
+\t\t\t.in3(immediate),
+\t\t\t.sel(ac_source),
+\t\t\t.mux_out(ac_in)
+\t\t);
+\t/* accumulator register */
+\tff_d #(.WIDTH(8)) ac (
+\t\t\t.D(ac_in),
+\t\t\t.en(write_ac),
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.Q(ac_out)
+\t\t);
+\t
+\t/* memory address register data source select
+\t * mar_source:
+\t * 1: use source from immediate constant
+\t * 0: use source from accumulator register
+\t * rationale:
+\t * allows for both direct and indirect addressing of memory data
+\t */
+\tassign mar_data = mar_source ? immediate : ac_out;
+\t
+\t/* memory address register */
+\tff_d #(.WIDTH(8)) mar (
+\t\t\t.D(mar_data),
+\t\t\t.en(write_mar),
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.Q(mar_out)
+\t\t);
+\t
+\t/* memory data register data source select
+\t * mdr_source:
+\t * 00: the constant 0
+\t * 01: memory bus value
+\t *\t10: immediate value
+\t * 11: accumulator register
+\t * rationale:
+\t * allows for both direct and indirect
+\t * addressing of memory data
+\t * allows to easily clear a memory address
+\t */
+\tmux4 #(.WIDTH(8)) mdr_mux (
+\t\t\t.in0(8\'b0),
+\t\t\t.in1(mdr_in),
+\t\t\t.in2(immediate),
+\t\t\t.in3(ac_out),
+\t\t\t.sel(mdr_source),
+\t\t\t.mux_out(mdr_data)
+\t\t);
+\t
+\t/* memory data register */
+\tff_d #(.WIDTH(8)) mdr (
+\t\t\t.D(mdr_data),
+\t\t\t.en(write_mdr),
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.Q(mdr_out)
+\t\t);
+\t
+\t/* ALU operand source select
+\t * ALU_op_select:
+\t * 000: the constant 0
+\t * 001: the constant 1
+\t * 010: the constant 2
+\t * 011: the constant -1
+\t * 100: the constant -2
+\t * 101: accumulator register
+\t * 110: immediate constant
+\t * 111: memory data register
+\t * rationale:
+\t * allows for the ease of implementation of
+\t * arithmetic/logic instructions
+\t */
+\tmux8 #(.WIDTH(8)) ALU_op_mux (
+\t\t\t.in0(8\'b0),
+\t\t\t.in1(8\'b01),
+\t\t\t.in2(8\'b10),
+\t\t\t.in3(8\'hff),
+\t\t\t.in4(8\'hfe),
+\t\t\t.in5(ac_out),
+\t\t\t.in6(immediate),
+\t\t\t.in7(mdr_out),
+\t\t\t.sel(ALU_op_select),
+\t\t\t.mux_out(alu_operand)
+\t\t);
+\t
+\t/* ALU */
+\tALU alu0 (
+\t\t\t.op1(ac_out),
+\t\t\t.op2(alu_operand),
+\t\t\t.ctl(ALUctl),
+\t\t\t.flags_in(flags),
+\t\t\t.result(ALU_feedback),
+\t\t\t.flags_out(flags_out)
+\t\t);
+endmodule
+`include ""aluundefs.v""
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * mux.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+module mux4 #(parameter WIDTH=8) (
+\t\tinput wire\t[WIDTH - 1 : 0]\t\tin0,\t\t/* multiplexer input 0 */
+\t\tinput wire\t[WIDTH - 1 : 0]\t\tin1,\t\t/* multiplexer input 1 */
+\t\tinput wire\t[WIDTH - 1 : 0]\t\tin2,\t\t/* multiplexer input 2 */
+\t\tinput wire\t[WIDTH - 1 : 0]\t\tin3,\t\t/* multiplexer input 3 */
+\t\tinput wire\t[ 1: 0]\t\t\t\tsel,\t\t/* select lines */
+\t\toutput reg\t[WIDTH - 1 : 0]\t\tmux_out\t\t/* multiplexer output */
+\t);
+\t
+\talways @(*) begin
+\t\tcase(sel)
+\t\t\t2'b00:\t\tmux_out = in0;
+\t\t\t2'b01:\t\tmux_out = in1;
+\t\t\t2'b10:\t\tmux_out = in2;
+\t\t\t2'b11:\t\tmux_out = in3;
+\t\tendcase
+\tend
+endmodule
+
+module mux8 #(parameter WIDTH=8) (
+\t\tinput wire\t[WIDTH - 1 : 0]\t\tin0,\t\t/* multiplexer input 0 */
+\t\tinput wire\t[WIDTH - 1 : 0]\t\tin1,\t\t/* multiplexer input 1 */
+\t\tinput wire\t[WIDTH - 1 : 0]\t\tin2,\t\t/* multiplexer input 2 */
+\t\tinput wire\t[WIDTH - 1 : 0]\t\tin3,\t\t/* multiplexer input 3 */
+\t\tinput wire\t[WIDTH - 1 : 0]\t\tin4,\t\t/* multiplexer input 4 */
+\t\tinput wire\t[WIDTH - 1 : 0]\t\tin5,\t\t/* multiplexer input 5 */
+\t\tinput wire\t[WIDTH - 1 : 0]\t\tin6,\t\t/* multiplexer input 6 */
+\t\tinput wire\t[WIDTH - 1 : 0]\t\tin7,\t\t/* multiplexer input 7 */
+\t\tinput wire\t[ 2: 0]\t\t\t\tsel,\t\t/* select lines */
+\t\toutput reg\t[WIDTH - 1 : 0]\t\tmux_out\t\t/* multiplexer output */
+\t);
+
+\talways @(*) begin
+\t\tcase(sel)
+\t\t\t3'b000:\t\tmux_out = in0;
+\t\t\t3'b001:\t\tmux_out = in1;
+\t\t\t3'b010:\t\tmux_out = in2;
+\t\t\t3'b011:\t\tmux_out = in3;
+\t\t\t3'b100:\t\tmux_out = in4;
+\t\t\t3'b101:\t\tmux_out = in5;
+\t\t\t3'b110:\t\tmux_out = in6;
+\t\t\t3'b111:\t\tmux_out = in7;
+\t\tendcase
+\tend
+endmodule
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * aludefs.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/* flags register width */
+`define FWIDTH\t\t\t4
+
+/* CPU flags */
+`define ZERO_FLAG\t\t0
+`define CARRY_FLAG\t\t1
+`define NEGATIVE_FLAG\t2
+`define OVERFLOW_FLAG\t3
+
+/* ALU control bus width */
+`define ALUCTLW\t\t\t3
+
+/* Microcode ROM offset width */
+`define MC_OFFSET_WIDTH\t6
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * pc_system.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+module pc_system(
+\t\tinput wire\t\t[ 7 : 0]\tswitch_in,
+\t\tinput wire\t\t\t\t\tbutton,
+\t\tinput wire\t\t\t\t\tclk,
+\t\tinput wire\t\t\t\t\tres,
+\t\toutput wire \t[ 7 : 0]\tLED_status,
+\t\toutput wire\t\t[ 3 : 0]\tanode,
+\t\toutput wire\t\t[ 6 : 0]\tcathode
+ );
+\t
+\t/* clock divider */
+\twire clk_div;
+\t
+\t/* processor signals */
+\twire [ 7 : 0] pc_out, mar_out, mdr_in, mdr_out;
+\twire [15 : 0] instruction_in;
+
+\t/* direct board clock */
+\tassign clk_div = clk;
+\t
+\t/* clock divider */
+\t/*clock_divider clk_div0 (
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.prescaler(2'b10),
+\t\t\t.clk_out(clk_div)
+\t\t);*/
+\t
+\t/* clock generator */
+\t/*clk_gen clk0(
+\t\t\t.button(button),
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.clk_div(clk_div)
+\t\t);
+\t*/
+
+\t/* debug unit
+\t * show instruction in 7-segment display
+\t */
+\tinsn_out debug_unit0 (
+\t\t\t.insn(instruction_in),
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.anode(anode),
+\t\t\t.cathode(cathode)
+\t\t);
+
+\t/* memory decoder unit */
+\tmemory_decoder md0 (
+\t\t\t.address(mar_out),
+\t\t\t.data_in(mdr_out),
+\t\t\t.switch_in(switch_in),
+\t\t\t.clk(clk_div),
+\t\t\t.res(res),
+\t\t\t.write_enable(write_mem),
+\t\t\t.LED_status(LED_status),
+\t\t\t.data_out(mdr_in)
+\t\t);
+\t
+\t/* the processor */
+\tprocessor core0 (
+\t\t\t.clk(clk_div),
+\t\t\t.res(res),
+\t\t\t.instruction_in(instruction_in),
+\t\t\t.mdr_in(mdr_in),
+\t\t\t.pc_out(pc_out),
+\t\t\t.mdr_out(mdr_out),
+\t\t\t.mar_out(mar_out),
+\t\t\t.write_mem(write_mem)
+\t\t);
+\t
+\t/* program memory subsystem */
+\tprogmem prom0 (
+\t\t\t.pc(pc_out),
+\t\t\t.instruction(instruction_in)
+\t\t);
+
+endmodule
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * insn_out.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+/* instruction output driver */
+module insn_out(
+\t\tinput wire\t\t[15 : 0]\tinsn,
+\t\tinput wire\t\t\t\t\tclk,
+\t\tinput wire\t\t\t\t\tres,
+\t\toutput wire\t\t[ 3 : 0]\tanode,
+\t\toutput wire\t\t[ 6 : 0]\tcathode
+\t);
+
+\t/* internal frequency scaler parameter */
+\tparameter MSB = 16;
+\t
+\treg [MSB : 0] counter;
+\treg [ 3 : 0] nibble;
+\t
+\t/* seven segment display driver instance */
+\tsseg_driver ssgd0 (
+\t\t\t.digit(nibble),\t\t\t\t\t/* digit to show */
+\t\t\t.sel(counter[MSB:MSB - 1]),\t\t/* digit selection */
+\t\t\t.anode(anode),\t\t\t\t\t/* decoded common anode enable */
+\t\t\t.cathode(cathode)\t\t\t\t/* decoded seven segment cathode */
+\t\t);
+\t
+\t/* internal counter */
+\talways @(posedge clk) begin
+\t\tif(res) counter <= {(MSB+1){1'b0}};
+\t\telse counter <= counter + 1'b1;
+\tend
+\t
+\t/* nibble multiplexing */
+\talways @(counter[MSB:MSB - 1] or insn) begin
+\t\tcase(counter[MSB:MSB - 1])
+\t\t\t2'b00:\tnibble = insn[ 3 : 0];
+\t\t\t2'b01:\tnibble = insn[ 7 : 4];
+\t\t\t2'b10:\tnibble = insn[11 : 8];
+\t\t\t2'b11:\tnibble = insn[15 :12];
+\t\tendcase
+\tend
+
+endmodule
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * decoder_complex.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+`include ""aludefs.v""
+
+module decoder_complex(
+\t\tinput wire\t[ 7 : 0]\t\t\t\t\topcode,\t\t\t/* opcode */
+\t\tinput wire\t[`FWIDTH - 1 : 0]\t\t\tflags,\t\t\t/* ALU flags */
+\t\toutput reg\t[`MC_OFFSET_WIDTH - 1 : 0]\top_decoder_out\t/* microcode offset */
+\t);
+
+\talways @(*) begin
+\t\tcase(opcode)
+\t\t\t/* add from immediate memory address into accumulator */
+\t\t\t8\'h00:\top_decoder_out = `MC_OFFSET_WIDTH\'h0a;
+\t\t\t/* store from accumulator into immediate address */
+\t\t\t8\'h01:\top_decoder_out = `MC_OFFSET_WIDTH\'h08;
+\t\t\t/* load from immediate address into accumulator */
+\t\t\t8\'h02:\top_decoder_out = `MC_OFFSET_WIDTH\'h04;
+\t\t\t/* absolute branch to immediate address */
+\t\t\t8\'h03:\top_decoder_out = `MC_OFFSET_WIDTH\'h0e;
+\t\t\t/* jump if negative */
+\t\t\t8\'h04:\top_decoder_out =
+\t\t\t\t\t\t\tflags[`NEGATIVE_FLAG] ?
+\t\t\t\t\t\t\t\t`MC_OFFSET_WIDTH\'h0e
+\t\t\t\t\t\t\t\t: `MC_OFFSET_WIDTH\'h0f;
+\t\t\t/* subtract from immediate memory address into accumulator */
+\t\t\t8\'h05:\top_decoder_out = `MC_OFFSET_WIDTH\'h16;
+\t\t\t/* exclusive OR from immediate memory address into accumulator */
+\t\t\t8\'h06:\top_decoder_out = `MC_OFFSET_WIDTH\'h1a;
+\t\t\t/* NOR from immediate memory address into accumulator */
+\t\t\t8\'h07:\top_decoder_out = `MC_OFFSET_WIDTH\'h1e;
+\t\t\t/* NAND from immediate memory address into accumulator */
+\t\t\t8\'h08:\top_decoder_out = `MC_OFFSET_WIDTH\'h22;
+\t\t\t/* jump if positive */
+\t\t\t8\'h09:\top_decoder_out =
+\t\t\t\t\t\t\tflags[`NEGATIVE_FLAG] ?
+\t\t\t\t\t\t\t\t`MC_OFFSET_WIDTH\'h0f
+\t\t\t\t\t\t\t\t: `MC_OFFSET_WIDTH\'h0e;
+\t\t\t/* jump if zero */
+\t\t\t8\'h0a:\top_decoder_out =
+\t\t\t\t\t\t\tflags[`ZERO_FLAG] ?
+\t\t\t\t\t\t\t\t`MC_OFFSET_WIDTH\'h0e
+\t\t\t\t\t\t\t\t: `MC_OFFSET_WIDTH\'h0f;
+\t\t\t/* add immediate into accumulator */
+\t\t\t8\'h0b:\top_decoder_out = `MC_OFFSET_WIDTH\'h26;
+\t\t\t/* accumulator arithmetic shift left */
+\t\t\t8\'h0d:\top_decoder_out = `MC_OFFSET_WIDTH\'h29;
+\t\t\t/* accumulator arithmetic shift right */
+\t\t\t8\'h0e:\top_decoder_out = `MC_OFFSET_WIDTH\'h28;
+\t\t\t/* jump if carry set */
+\t\t\t8\'h70:\top_decoder_out =
+\t\t\t\t\t\t\tflags[`CARRY_FLAG] ?
+\t\t\t\t\t\t\t\t`MC_OFFSET_WIDTH\'h0e
+\t\t\t\t\t\t\t\t: `MC_OFFSET_WIDTH\'h0f;
+\t\t\t/* jump if overflow set */
+\t\t\t8\'h71:\top_decoder_out =
+\t\t\t\t\t\t\tflags[`OVERFLOW_FLAG] ?
+\t\t\t\t\t\t\t\t`MC_OFFSET_WIDTH\'h0e
+\t\t\t\t\t\t\t\t: `MC_OFFSET_WIDTH\'h0f;
+\t\t\t/* increment accumulator */
+\t\t\t8\'h72:\top_decoder_out = `MC_OFFSET_WIDTH\'h10;
+\t\t\t/* compare with immediate constant */
+\t\t\t8\'h73:\top_decoder_out = `MC_OFFSET_WIDTH\'h11;
+\t\t\t/* compare with value at immediate address */
+\t\t\t8\'h74:\top_decoder_out = `MC_OFFSET_WIDTH\'h12;
+\t\t\t/* invert accumulator */
+\t\t\t8\'h75:\top_decoder_out = `MC_OFFSET_WIDTH\'h27;
+\t\t\t/* clear accumulator register */
+\t\t\t8\'h7e:\top_decoder_out = `MC_OFFSET_WIDTH\'h02;
+\t\t\t/* load immediate into accumulator register */
+\t\t\t8\'h7f:\top_decoder_out = `MC_OFFSET_WIDTH\'h03;
+\t\t\tdefault:op_decoder_out = {`MC_OFFSET_WIDTH{1\'b1}};
+\t\tendcase
+\tend
+endmodule
+
+`include ""aluundefs.v""
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * mcrom_tb.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+`include ""microcodedefs.v""
+
+module mcrom_tb;
+
+\t/* input and signals */
+\treg [ 5 : 0] offset;
+\treg clk;
+
+\t/* output */
+\twire [`MCROM_WIDTH - 1 : 0] mc_word;
+
+\t/* unit under testing */
+\tmicrocode_rom uut (
+\t\t\t.offset(offset),
+\t\t\t.mc_word(mc_word)
+\t\t);
+
+\tinitial begin
+\t\t/* initialize signals */
+\t\toffset = 0;
+\t\tclk = 0;
+\t\t/* end simulation after 1000 ticks */
+\t\t#1000\t$finish;
+\tend
+
+\talways
+\t\t#50\t\tclk = ~clk;
+\t
+\talways @(posedge clk)
+\t\toffset = offset + 1;
+\t\t
+endmodule
+
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * controller_unit.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+`include ""microcodedefs.v""
+`include ""aludefs.v""
+
+module controller_unit(
+\t\t/* input signals */
+\t\tinput wire\t\t[ 7 : 0]\t\t\topcode,\t\t/* opcode byte */
+\t\tinput wire\t\t[`FWIDTH - 1 : 0]\tflags,\t\t/* ALU flags */
+\t\tinput wire\t\t\t\t\t\t\tclk,\t\t/* clock signal */
+\t\tinput wire\t\t\t\t\t\t\tres,\t\t/* reset signal */
+\t\t/* output signals */
+\t\toutput wire\t\t[1 : 0]\t\t\t\tac_source,\t/* accumulator source */
+\t\toutput wire\t\t\t\t\t\t\twrite_ac,\t/* write accumulator */
+\t\toutput wire\t\t\t\t\t\t\tmar_source,\t/* memory address register source */
+\t\toutput wire\t\t\t\t\t\t\twrite_mar,\t/* write memory address register */
+\t\toutput wire\t\t[1 : 0]\t\t\t\tmdr_source,\t/* memory data register source */
+\t\toutput wire\t\t\t\t\t\t\twrite_mdr,\t/* write memory data register */
+\t\toutput wire\t\t\t\t\t\t\twrite_flags,/* write flags register */
+\t\toutput wire\t\t[ 1 : 0]\t\t\tpc_source,\t/* program counter source */
+\t\toutput wire\t\t\t\t\t\t\twrite_pc,\t/* write program counter */
+\t\toutput wire\t\t\t\t\t\t\twrite_ir,\t/* write instruction register */
+\t\toutput wire\t\t\t\t\t\t\twrite_mem,\t/* write memory */
+\t\toutput wire\t\t[ 2 : 0]\t\t\tALU_op_select,\t/* ALU operator */
+\t\toutput wire\t\t[`ALUCTLW - 1: 0]\tALUctl\t\t/* ALU control signal bus */
+ );
+
+\t/* internal signals */
+\twire [`MCROM_WIDTH - 1 : 0] mc_word;
+\twire [`OFFSET_WIDTH - 1 : 0] offset, rom_offset_next, op_decoder_out;
+\twire [ 1 : 0] offset_next_select;
+
+\t
+\t/* instance the decoder complex */
+\tdecoder_complex idec0 (
+\t\t\t.opcode(opcode),
+\t\t\t.flags(flags),
+\t\t\t.op_decoder_out(op_decoder_out)
+\t\t);
+\t
+\t/* instance the microcode rom */
+\tmicrocode_rom rom0 (
+\t\t\t.clk(clk),
+\t\t\t.offset(offset),
+\t\t\t.mc_word(mc_word)
+\t\t);
+\t
+\t/* select the next address in the microcode ROM */
+\tmux4 #(.WIDTH(`OFFSET_WIDTH)) mux0(
+\t\t\t.in0(op_decoder_out),\t\t/* decoder complex output */
+\t\t\t.in1(rom_offset_next),\t\t/* offset from ROM */
+\t\t\t.in2(`OFFSET_WIDTH\'b0),\t\t/* start of ROM */
+\t\t\t.in3(`OFFSET_WIDTH\'b0),\t\t/* start of ROM */
+\t\t\t.sel(offset_next_select),\t/* next ROM address selection */
+\t\t\t.mux_out(offset)\t\t\t/* next offset on microcode ROM */
+\t\t);
+
+\t/* control signals assignment */
+\tassign offset_next_select \t= {res, res ? 1\'b1 : mc_word[`OFFSET_NEXT_SEL]};
+\tassign rom_offset_next\t\t= mc_word[`OFFSET_NEXT];
+\tassign ac_source \t\t\t= mc_word[`AC_SOURCE];
+\tassign write_ac \t\t\t= mc_word[`WRITE_AC];
+\tassign mar_source \t\t\t= mc_word[`MAR_SOURCE];
+\tassign write_mar \t\t\t= mc_word[`WRITE_MAR];
+\tassign mdr_source \t\t\t= mc_word[`MDR_SOURCE];
+\tassign write_mdr \t\t\t= mc_word[`WRITE_MDR];
+\tassign write_flags \t\t\t= mc_word[`WRITE_FLAGS];
+\tassign pc_source \t\t\t= mc_word[`PC_SOURCE];
+\tassign write_pc \t\t\t= mc_word[`WRITE_PC];
+\tassign write_ir\t\t\t\t= mc_word[`WRITE_IR];
+\tassign write_mem\t\t\t= mc_word[`WRITE_MEM];
+\tassign ALU_op_select \t\t= mc_word[`ALU_OP_SELECT];
+\tassign ALUctl \t\t\t\t= mc_word[`ALUCTL];
+endmodule
+
+`include ""microcodeundefs.v""
+`include ""aluundefs.v""
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * aluundefs.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+/* undefines */
+`undef FWIDTH
+`undef ZERO_FLAG
+`undef CARRY_FLAG
+`undef NEGATIVE_FLAG
+`undef OVERFLOW_FLAG
+`undef ALUCTLW
+`undef MC_OFFSET_WIDTH/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * processor_tb.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+module processor_tb;
+
+\t/* inputs */
+\treg clk;
+\treg res;
+\treg [15:0] instruction_in;
+\treg [7:0] mdr_in;
+\t
+\t/* SRAM block */
+\treg [7 : 0] memory [255 : 0];
+
+\t/* outputs */
+\twire [7:0] pc_out;
+\twire [7:0] mdr_out;
+\twire [7:0] mar_out;
+\twire write_mem;
+
+\t/* unit under testing */
+\tprocessor uut (
+\t\t\t.clk(clk),
+\t\t\t.res(res),
+\t\t\t.instruction_in(instruction_in),
+\t\t\t.mdr_in(mdr_in),
+\t\t\t.pc_out(pc_out),
+\t\t\t.mdr_out(mdr_out),
+\t\t\t.mar_out(mar_out),
+\t\t\t.write_mem(write_mem)
+\t\t);
+
+\tinitial begin
+\t\t/* initialize inputs */
+\t\tclk = 0;
+\t\tres = 1;
+
+\t\t/* release reset signal */
+\t\t#100\tres = 0;
+
+\t\t/* finish simulation */
+\tend
+\t
+\t/* clock */
+\talways
+\t\t#10\t\tclk = ~clk;
+\t
+\t/* data memory subsystem emulation */
+\talways @(posedge clk) begin
+\t\tif(write_mem)
+\t\t\tmemory[mar_out] <= mdr_out;
+\t\t\tmdr_in <= memory[mar_out];
+\tend
+
+\t/* ROM subsystem emulation */
+\talways @(pc_out) begin
+\t\tcase(pc_out)
+\t\t\t8'h00:\tinstruction_in = 16'h7f00;\t/* start:\tldi 0 */
+\t\t\t8'h01:\tinstruction_in = 16'h0100;\t/* \t\t\tsto 0x00 */
+\t\t\t8'h02:\tinstruction_in = 16'h0101;\t/* \t\t\tsto 0x01 */
+\t\t\t8'h03:\tinstruction_in = 16'h7200;\t/* loop:\tinc */
+\t\t\t8'h04:\tinstruction_in = 16'h730a;\t/* \t\t\tcmpi 0x0a */
+\t\t\t8'h05:\tinstruction_in = 16'h0aff;\t/* \t\t\tjz end */
+\t\t\t8'h06:\tinstruction_in = 16'h0101;\t/* \t\t\tsto 0x01 */
+\t\t\t8'h07:\tinstruction_in = 16'h0000;\t/* \t\t\tadd 0x00 */
+\t\t\t8'h08:\tinstruction_in = 16'h0100;\t/* \t\t\tsto 0x00 */
+\t\t\t8'h09:\tinstruction_in = 16'h0201;\t/* \t\t\tlo 0x01\t*/
+\t\t\t8'h0a:\tinstruction_in = 16'h0303;\t/* \t\t\tjmp loop */
+\t\t\tdefault:
+\t\t\t\tbegin
+\t\t\t\t\tinstruction_in = 16'hffff;\t/* end: \thalt */
+\t\t\t\t\t$finish;
+\t\t\t\tend
+\t\tendcase
+\tend
+
+endmodule
+
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * progmem.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+/* program memory */
+module progmem(
+\t\tinput wire\t\t[ 7 : 0]\tpc,
+\t\toutput reg\t\t[15 : 0]\tinstruction
+ );
+
+\t/* ROM subsystem emulation */
+\talways @(pc) begin
+\t\tcase(pc)
+\t\t\t8'h00:\tinstruction = 16'h7f00;\t/* start:\tldi 0 */
+\t\t\t8'h01:\tinstruction = 16'h0100;\t/* \t\t\tsto 0x00 */
+\t\t\t8'h02:\tinstruction = 16'h0101;\t/* \t\t\tsto 0x01 */
+\t\t\t8'h03:\tinstruction = 16'h7200;\t/* loop:\tinc */
+\t\t\t8'h04:\tinstruction = 16'h74ff;\t/* \t\t\tcmp 0xff */
+\t\t\t8'h05:\tinstruction = 16'h0a0c;\t/* \t\t\tjz loop_e */
+\t\t\t8'h06:\tinstruction = 16'h0101;\t/* \t\t\tsto 0x01 */
+\t\t\t8'h07:\tinstruction = 16'h0000;\t/* \t\t\tadd 0x00 */
+\t\t\t8'h08:\tinstruction = 16'h0100;\t/* \t\t\tsto 0x00 */
+\t\t\t8'h09:\tinstruction = 16'h01ff;\t/*\t\t\tsto 0xff */
+\t\t\t8'h0a:\tinstruction = 16'h0201;\t/* \t\t\tlo 0x01\t*/
+\t\t\t8'h0b:\tinstruction = 16'h0303;\t/* \t\t\tjmp loop */
+\t\t\t8'h0c:\tinstruction = 16'h030c;\t/* self:\tjmp self */
+\t\t\tdefault:
+\t\t\t\tbegin
+\t\t\t\t\tinstruction = 16'hffff;\t/* end: \thalt */
+\t\t\t\tend
+\t\tendcase
+\tend
+
+endmodule
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * sram.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+/* Xilinx BRAM module creation */
+module sram(
+\t\tinput wire\t\t[ 7 : 0]\taddress,\t\t/* address bus */
+\t\tinput wire\t\t[ 7 : 0]\tdata_in,\t\t/* data input bus */
+\t\tinput wire\t\t\t\t\tclk,\t\t\t/* clock */
+\t\tinput wire\t\t\t\t\twrite_enable,\t/* memory write enable */
+\t\toutput reg\t\t[ 7 : 0]\tdata_out\t\t/* data output bus */
+ );
+
+\t/* 255x8 SRAM block */
+\treg [ 7 : 0] memory [255 : 0];
+\t
+\t/* Xilinx BRAM module generation */
+\talways @(posedge clk) begin
+\t\tif(write_enable)
+\t\t\tmemory[address] <= data_in;
+\t\tdata_out <= memory[address];
+\tend
+
+endmodule
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * sseg_driver.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+
+/* seven segment display driver */
+module sseg_driver(
+\t\tinput wire\t\t[ 3 : 0]\tdigit,\t\t/* digit to show */
+\t\tinput wire\t\t[ 1 : 0]\tsel,\t\t/* place to show */
+\t\toutput reg\t\t[ 3 : 0]\tanode,\t\t/* common anode enable */
+\t\toutput reg\t\t[ 6 : 0]\tcathode\t\t/* cathode enable */
+ );
+
+\t/* decode anode enable signal */
+\talways @(sel) begin
+\t\tcase(sel)
+\t\t\t2'b00:\tanode = 4'b1110;
+\t\t\t2'b01:\tanode = 4'b1101;
+\t\t\t2'b10:\tanode = 4'b1011;
+\t\t\t2'b11:\tanode = 4'b0111;
+\t\tendcase
+\tend
+\t
+\t/* decode digit into 7-segment driver output */
+\talways @(digit) begin
+\t\tcase(digit)\t\t\t/* ABCDEFG */
+\t\t\t4'h0:\tcathode = 7'b0000001;
+\t\t\t4'h1:\tcathode = 7'b1001111;
+\t\t\t4'h2:\tcathode = 7'b0010010;
+\t\t\t4'h3:\tcathode = 7'b0000110;
+\t\t\t4'h4:\tcathode = 7'b1001100;
+\t\t\t4'h5:\tcathode = 7'b0100100;
+\t\t\t4'h6:\tcathode = 7'b0100000;
+\t\t\t4'h7:\tcathode = 7'b0001111;
+\t\t\t4'h8:\tcathode = 7'b0000000;
+\t\t\t4'h9:\tcathode = 7'b0000100;
+\t\t\t4'ha:\tcathode = 7'b0001000;
+\t\t\t4'hb:\tcathode = 7'b1100000;
+\t\t\t4'hc:\tcathode = 7'b0110001;
+\t\t\t4'hd:\tcathode = 7'b1000010;
+\t\t\t4'he:\tcathode = 7'b0110000;
+\t\t\t4'hf:\tcathode = 7'b0111000;
+\t\tendcase
+\tend
+
+endmodule
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"/**
+ * microcode_rom.v - Microcoded Accumulator CPU
+ * Copyright (C) 2015 Orlando Arias, David Mascenik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+`timescale 1ns / 1ps
+`include ""microcodedefs.v""
+
+module microcode_rom(
+\t\tinput wire\t\t\t\t\t\t\t\tclk,\t\t/* clock input */
+\t\tinput wire\t\t[`OFFSET_WIDTH - 1 : 0]\toffset,\t\t/* ROM address */
+\t\toutput reg\t\t[`MCROM_WIDTH - 1 : 0]\tmc_word\t\t/* ROM word output */
+ );
+
+\talways @(posedge clk) begin
+\t\tcase(offset)
+\t\t\t/* fetch */
+\t\t\t`OFFSET_WIDTH\'h00:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000001_xxx_xxx_0_0_1_0_xx_0_xx_0_x_0_xx;
+\t\t\t/* decode */
+\t\t\t`OFFSET_WIDTH\'h01:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b0_xxxxxx_xxx_xxx_0_0_0_0_xx_0_xx_0_x_0_xx;
+\t\t\t/* clear accumulator register */
+\t\t\t`OFFSET_WIDTH\'h02:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_110_101_0_1_0_1_00_0_xx_0_x_1_10;
+\t\t\t/* load immediate into accumulator */
+\t\t\t`OFFSET_WIDTH\'h03:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_xxx_xxx_0_0_0_1_00_0_xx_0_x_1_11;
+\t\t\t/* load from immediate memory address into accumulator */
+\t\t\t`OFFSET_WIDTH\'h04:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000101_xxx_xxx_0_0_0_0_xx_0_xx_1_1_0_xx;
+\t\t\t`OFFSET_WIDTH\'h05:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000110_xxx_xxx_0_0_0_0_xx_0_xx_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h06:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000111_xxx_xxx_0_0_0_0_xx_1_01_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h07:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_xxx_xxx_0_0_0_1_00_0_xx_0_x_1_01;
+\t\t\t/* store from accumulator into immediate memory address */
+\t\t\t`OFFSET_WIDTH\'h08:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_001001_xxx_xxx_0_0_0_0_xx_1_11_1_1_0_xx;
+\t\t\t`OFFSET_WIDTH\'h09:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_xxx_xxx_1_0_0_1_00_0_xx_0_x_0_xx;
+\t\t\t/* add from immediate memory address into accumulator */
+\t\t\t`OFFSET_WIDTH\'h0a:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_001011_xxx_xxx_0_0_0_0_xx_0_xx_1_1_0_xx;
+\t\t\t`OFFSET_WIDTH\'h0b:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_001100_xxx_xxx_0_0_0_0_xx_0_xx_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h0c:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_001101_xxx_xxx_0_0_0_0_xx_1_01_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h0d:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_000_111_0_1_0_1_00_0_xx_0_x_1_10;
+\t\t\t/* absolute branch to immediate address or conditional branch taken */
+\t\t\t`OFFSET_WIDTH\'h0e:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_xxx_xxx_0_0_0_1_01_0_xx_0_x_0_xx;
+\t\t\t/* conditional branch not taken */
+\t\t\t`OFFSET_WIDTH\'h0f:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_xxx_xxx_0_0_0_1_00_0_xx_0_x_0_xx;
+\t\t\t/* increment accumulator */
+\t\t\t`OFFSET_WIDTH\'h10:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_000_001_0_1_0_1_00_0_xx_0_x_1_10;
+\t\t\t/* compare with immediate constant */
+\t\t\t`OFFSET_WIDTH\'h11:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_010_110_0_1_0_1_00_0_xx_0_x_0_xx;
+\t\t\t/* compare with value at immediate address */
+\t\t\t`OFFSET_WIDTH\'h12:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_010011_xxx_xxx_0_0_0_0_xx_0_xx_1_1_0_xx;
+\t\t\t`OFFSET_WIDTH\'h13:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_010100_xxx_xxx_0_0_0_0_xx_0_xx_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h14:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_010101_xxx_xxx_0_0_0_0_xx_1_01_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h15:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_010_111_0_1_0_1_00_0_xx_0_x_0_xx;
+\t\t\t/* subtract from immediate memory address into accumulator */
+\t\t\t`OFFSET_WIDTH\'h16:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_010111_xxx_xxx_0_0_0_0_xx_0_xx_1_1_0_xx;
+\t\t\t`OFFSET_WIDTH\'h17:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_011000_xxx_xxx_0_0_0_0_xx_0_xx_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h18:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_011001_xxx_xxx_0_0_0_0_xx_1_01_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h19:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_010_111_0_1_0_1_00_0_xx_0_x_1_10;
+\t\t\t/* exclusive OR from immediate memory address into accumulator */
+\t\t\t`OFFSET_WIDTH\'h1a:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_011011_xxx_xxx_0_0_0_0_xx_0_xx_1_1_0_xx;
+\t\t\t`OFFSET_WIDTH\'h1b:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_011100_xxx_xxx_0_0_0_0_xx_0_xx_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h1c:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_011101_xxx_xxx_0_0_0_0_xx_1_01_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h1d:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_110_111_0_1_0_1_00_0_xx_0_x_1_10;
+\t\t\t/* NOR from immediate memory address into accumulator */
+\t\t\t`OFFSET_WIDTH\'h1e:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_011111_xxx_xxx_0_0_0_0_xx_0_xx_1_1_0_xx;
+\t\t\t`OFFSET_WIDTH\'h1f:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_100000_xxx_xxx_0_0_0_0_xx_0_xx_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h20:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_100001_xxx_xxx_0_0_0_0_xx_1_01_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h21:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_101_111_0_1_0_1_00_0_xx_0_x_1_10;
+\t\t\t/* NAND from immediate memory address into accumulator */
+\t\t\t`OFFSET_WIDTH\'h22:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_100011_xxx_xxx_0_0_0_0_xx_0_xx_1_1_0_xx;
+\t\t\t`OFFSET_WIDTH\'h23:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_100100_xxx_xxx_0_0_0_0_xx_0_xx_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h24:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_100101_xxx_xxx_0_0_0_0_xx_1_01_0_x_0_xx;
+\t\t\t`OFFSET_WIDTH\'h25:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_100_111_0_1_0_1_00_0_xx_0_x_1_10;
+\t\t\t/* add immediate into accumulator */
+\t\t\t`OFFSET_WIDTH\'h26:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_000_110_0_1_0_1_00_0_xx_0_x_1_10;
+\t\t\t/* invert accumulator */
+\t\t\t`OFFSET_WIDTH\'h27:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_110_011_0_1_0_1_00_0_xx_0_x_1_10;
+\t\t\t/* shift right arithmetic accumulator */
+\t\t\t`OFFSET_WIDTH\'h28:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_111_101_0_1_0_1_00_0_xx_0_x_1_10;
+\t\t\t/* shift left arithmetic accumulator */
+\t\t\t`OFFSET_WIDTH\'h29:
+\t\t\t\tmc_word = `MCROM_WIDTH\'b1_000000_000_101_0_1_0_1_00_0_xx_0_x_1_10;
+\t\t\t/* halt condition */
+\t\t\tdefault:
+\t\t\t\tmc_word = {{(`OFFSET_WIDTH+1){1\'b1}},
+\t\t\t\t\t\t\t{(`MCROM_WIDTH - `OFFSET_WIDTH - 1){1\'b0}}};
+\t\tendcase
+\tend
+endmodule
+
+`include ""microcodeundefs.v""
+/* vim: set ts=4 tw=79 syntax=verilog */
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer cyc; initial cyc=0;
+ reg [63:0] crc;
+ reg [63:0] sum;
+
+ reg \t out1;
+ reg [4:0] out2;
+ sub sub (.in(crc[23:0]), .out1(out1), .out2(out2));
+
+ always @ (posedge clk) begin
+ //$write(""[%0t] cyc==%0d crc=%x sum=%x out=%x,%x\
+"",$time, cyc, crc, sum, out1,out2);
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= {sum[62:0], sum[63]^sum[2]^sum[0]} ^ {58\'h0,out1,out2};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h00000000_00000097;
+\t sum <= 64\'h0;
+ end
+ else if (cyc==90) begin
+\t if (sum !== 64\'hf0afc2bfa78277c5) $stop;
+ end
+ else if (cyc==91) begin
+ end
+ else if (cyc==92) begin
+ end
+ else if (cyc==93) begin
+ end
+ else if (cyc==94) begin
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module sub (/*AUTOARG*/
+ // Outputs
+ out1, out2,
+ // Inputs
+ in
+ );
+
+ input [23:0] in;
+ output reg \t out1;
+ output reg [4:0] out2;
+
+ always @* begin
+ // Test empty cases
+ casez (in[0])
+ endcase
+ casez (in)
+\t24\'b0000_0000_0000_0000_0000_0000 : {out1,out2} = {1\'b0,5\'h00};
+\t24\'b????_????_????_????_????_???1 : {out1,out2} = {1\'b1,5\'h00};
+\t24\'b????_????_????_????_????_??10 : {out1,out2} = {1\'b1,5\'h01};
+\t24\'b????_????_????_????_????_?100 : {out1,out2} = {1\'b1,5\'h02};
+\t24\'b????_????_????_????_????_1000 : {out1,out2} = {1\'b1,5\'h03};
+\t24\'b????_????_????_????_???1_0000 : {out1,out2} = {1\'b1,5\'h04};
+\t24\'b????_????_????_????_??10_0000 : {out1,out2} = {1\'b1,5\'h05};
+\t24\'b????_????_????_????_?100_0000 : {out1,out2} = {1\'b1,5\'h06};
+\t24\'b????_????_????_????_1000_0000 : {out1,out2} = {1\'b1,5\'h07};
+\t// Same pattern, but reversed to test we work OK.
+\t24\'b1000_0000_0000_0000_0000_0000 : {out1,out2} = {1\'b1,5\'h17};
+\t24\'b?100_0000_0000_0000_0000_0000 : {out1,out2} = {1\'b1,5\'h16};
+\t24\'b??10_0000_0000_0000_0000_0000 : {out1,out2} = {1\'b1,5\'h15};
+\t24\'b???1_0000_0000_0000_0000_0000 : {out1,out2} = {1\'b1,5\'h14};
+\t24\'b????_1000_0000_0000_0000_0000 : {out1,out2} = {1\'b1,5\'h13};
+\t24\'b????_?100_0000_0000_0000_0000 : {out1,out2} = {1\'b1,5\'h12};
+\t24\'b????_??10_0000_0000_0000_0000 : {out1,out2} = {1\'b1,5\'h11};
+\t24\'b????_???1_0000_0000_0000_0000 : {out1,out2} = {1\'b1,5\'h10};
+\t24\'b????_????_1000_0000_0000_0000 : {out1,out2} = {1\'b1,5\'h0f};
+\t24\'b????_????_?100_0000_0000_0000 : {out1,out2} = {1\'b1,5\'h0e};
+\t24\'b????_????_??10_0000_0000_0000 : {out1,out2} = {1\'b1,5\'h0d};
+\t24\'b????_????_???1_0000_0000_0000 : {out1,out2} = {1\'b1,5\'h0c};
+\t24\'b????_????_????_1000_0000_0000 : {out1,out2} = {1\'b1,5\'h0b};
+\t24\'b????_????_????_?100_0000_0000 : {out1,out2} = {1\'b1,5\'h0a};
+\t24\'b????_????_????_??10_0000_0000 : {out1,out2} = {1\'b1,5\'h09};
+\t24\'b????_????_????_???1_0000_0000 : {out1,out2} = {1\'b1,5\'h08};
+ endcase
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+//bug505
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ parameter WIDTH = 33;
+ localparam MAX_WIDTH = 11;
+ localparam NUM_OUT = num_out(WIDTH);
+
+ wire [NUM_OUT-1:0] z;
+
+ function integer num_out;
+ input integer width;
+ num_out = 1;
+ while ((width + num_out - 1) / num_out > MAX_WIDTH)
+ num_out = num_out * 2;
+ endfunction
+
+ initial begin
+ if (NUM_OUT != 4) $stop;
+ if ($bits(z) != 4) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+// Check that we report warnings only once on parameterized modules
+// Also check that we don't suppress warnings on the same line
+
+module t ();
+ sub #(.A(1)) sub1();
+ sub #(.A(2)) sub2();
+ sub #(.A(3)) sub3();
+endmodule
+
+module sub;
+ parameter A = 0;
+
+ reg [A:0] unus1; reg [A:0] unus2;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ function integer max2;
+ input integer x;
+ input integer y;
+ begin
+\t begin : blk
+\t automatic int temp;
+\t temp = x;
+\t end
+ end
+ max2 = ( x > y ) ? x : y;
+ endfunction
+
+ function integer max4;
+ input integer x;
+ input integer y;
+ input integer z;
+ input integer w;
+ // MAX2 is used multiple times
+ max4 = max2( max2( x, y ), max2( z, w ) );
+ endfunction
+
+ localparam MAX4 = max4( 1, 1, 0, 0 );
+
+ initial begin
+ if (MAX4 != 1) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Iztok Jeras.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // counters
+ int cnt;
+ int cnt_bit ;
+ int cnt_byte;
+ int cnt_int ;
+ int cnt_ar1d;
+ int cnt_ar2d;
+
+ // sizes
+ int siz_bit ;
+ int siz_byte;
+ int siz_int ;
+ int siz_ar1d;
+ int siz_ar2d;
+
+ // add all counters
+ assign cnt = cnt_bit + cnt_byte + cnt_int + cnt_ar1d + cnt_ar2d;
+
+ // finish report
+ always @ (posedge clk)
+ if (cnt == 5) begin
+ if (siz_bit != 1) $stop();
+ if (siz_byte != 8) $stop();
+ if (siz_int != 32) $stop();
+ if (siz_ar1d != 24) $stop();
+ if (siz_ar2d != 16) $stop();
+ end else if (cnt > 5) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ // instances with various types
+ mod_typ #(.TYP (bit )) mod_bit (clk, cnt_bit [ 1-1:0], siz_bit );
+ mod_typ #(.TYP (byte )) mod_byte (clk, cnt_byte[ 8-1:0], siz_byte);
+ mod_typ #(.TYP (int )) mod_int (clk, cnt_int [32-1:0], siz_int );
+ mod_typ #(.TYP (bit [23:0] )) mod_ar1d (clk, cnt_ar1d[24-1:0], siz_ar1d);
+ mod_typ #(.TYP (bit [3:0][3:0])) mod_ar2d (clk, cnt_ar2d[16-1:0], siz_ar2d);
+
+endmodule : t
+
+
+module mod_typ #(
+ parameter type TYP = byte
+)(
+ input logic clk,
+ output TYP cnt = 0,
+ output int siz
+);
+
+ always @ (posedge clk)
+ cnt <= cnt + 1;
+
+ assign siz = $bits (cnt);
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+// bug749
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ genvar g;
+ for (g=1; g<3; ++g) begin : gblk
+ sub2 #(.IN(g)) u ();
+ //sub #(.IN(g)) u2 ();
+ end
+
+ sub1 #(.IN(0)) u ();
+
+ always @ (posedge clk) begin
+ if (t.u.IN != 0) $stop;
+ if (t.u.FLAVOR != 1) $stop;
+ //if (t.u2.IN != 0) $stop; // This should be not found
+ if (t.gblk[1].u.IN != 1) $stop;
+ if (t.gblk[2].u.IN != 2) $stop;
+ if (t.gblk[1].u.FLAVOR != 2) $stop;
+ if (t.gblk[2].u.FLAVOR != 2) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+
+module sub1 (/*AUTOARG*/);
+ parameter [31:0] IN = 99;
+ parameter FLAVOR = 1;
+`ifdef TEST_VERBOSE
+ initial $display(""%m"");
+`endif
+endmodule
+
+module sub2 (/*AUTOARG*/);
+ parameter [31:0] IN = 99;
+ parameter FLAVOR = 2;
+`ifdef TEST_VERBOSE
+ initial $display(""%m"");
+`endif
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module x;
+
+ // verilator lint_off UNPACKED
+ typedef struct {
+ int \t a;
+ } notpacked_t;
+ // verilator lint_on UNPACKED
+
+ typedef struct packed {
+ notpacked_t b;
+ } ispacked_t;
+
+ ispacked_t p;
+
+ initial begin
+ p.b = 1;
+ if (p.b != 1) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [1:0] in = crc[1:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [1:0]\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[1:0]),
+\t // Inputs
+\t .in\t\t\t(in[1:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {62\'h0, out};
+
+ // What checksum will we end up with
+`define EXPECTED_SUM 64\'hbb2d9709592f64bd
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ in
+ );
+ input [1:0] in;
+ output reg [1:0] out;
+ always @* begin
+ // bug99: Internal Error: ../V3Ast.cpp:495: New node already linked?
+ case (in[1:0])
+\t2\'d0, 2\'d1, 2\'d2, 2\'d3: begin
+\t out = in;
+\tend
+ endcase
+ end
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ logic oe;
+
+ read r (.clk(clk), .data( ( ( oe == 1'd001 ) && implicit_write ) ) );
+ set s (.clk(clk), .enable(implicit_write));
+ read u (.clk(clk), .data(~implicit_also));
+
+endmodule
+
+module set (
+ input clk,
+ output enable
+ );
+ assign enable = 1'b0;
+endmodule
+
+module read (
+ input clk,
+ input data
+ );
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+interface pads_if();
+ modport mp_dig(
+\t\t import fIn,
+\t\t import fOut );
+
+ integer exists[8];
+ function automatic integer fIn (integer i);
+ fIn = exists[i];
+ endfunction
+ task automatic fOut (integer i);
+ exists[i] = 33;
+ endtask
+endinterface
+
+module t();
+ pads_if padsif();
+ initial begin
+ padsif.fOut(3);
+ if (padsif.fIn(3) != 33) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [7:0] operand_a = crc[7:0];
+ wire [7:0] operand_b = crc[15:8];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [6:0]\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[6:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .operand_a\t\t(operand_a[7:0]),
+\t .operand_b\t\t(operand_b[7:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {57\'h0, out};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h8a78c2ec4946ac38
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test
+ (
+ // Inputs
+ input wire \t clk,
+ input wire [7:0] operand_a, // operand a
+ input wire [7:0] operand_b, // operand b
+\t // Outputs
+ output wire [6:0] out
+ );
+
+ wire [6:0] \t clz_a;
+ wire [6:0] \t clz_b;
+
+ clz u_clz_a
+ (
+ // Inputs
+ .data_i (operand_a),
+ .out (clz_a));
+
+ clz u_clz_b
+ (
+ // Inputs
+ .data_i (operand_b),
+ .out (clz_b));
+
+ assign out = clz_a - clz_b;
+`ifdef TEST_VERBOSE
+ always @(posedge clk)
+ $display(""Out(%x) = clz_a(%x) - clz_b(%x)"", out, clz_a, clz_b);
+`endif
+
+endmodule
+
+`define def_0000_001x 8\'b0000_0010, 8\'b0000_0011
+
+`define def_0000_01xx 8\'b0000_0100, 8\'b0000_0101, 8\'b0000_0110, 8\'b0000_0111
+
+`define def_0000_10xx 8\'b0000_1000, 8\'b0000_1001, 8\'b0000_1010, 8\'b0000_1011
+`define def_0000_11xx 8\'b0000_1100, 8\'b0000_1101, 8\'b0000_1110, 8\'b0000_1111
+`define def_0000_1xxx `def_0000_10xx, `def_0000_11xx
+
+`define def_0001_00xx 8\'b0001_0000, 8\'b0001_0001, 8\'b0001_0010, 8\'b0001_0011
+`define def_0001_01xx 8\'b0001_0100, 8\'b0001_0101, 8\'b0001_0110, 8\'b0001_0111
+`define def_0001_10xx 8\'b0001_1000, 8\'b0001_1001, 8\'b0001_1010, 8\'b0001_1011
+`define def_0001_11xx 8\'b0001_1100, 8\'b0001_1101, 8\'b0001_1110, 8\'b0001_1111
+
+`define def_0010_00xx 8\'b0010_0000, 8\'b0010_0001, 8\'b0010_0010, 8\'b0010_0011
+`define def_0010_01xx 8\'b0010_0100, 8\'b0010_0101, 8\'b0010_0110, 8\'b0010_0111
+`define def_0010_10xx 8\'b0010_1000, 8\'b0010_1001, 8\'b0010_1010, 8\'b0010_1011
+`define def_0010_11xx 8\'b0010_1100, 8\'b0010_1101, 8\'b0010_1110, 8\'b0010_1111
+
+`define def_0011_00xx 8\'b0011_0000, 8\'b0011_0001, 8\'b0011_0010, 8\'b0011_0011
+`define def_0011_01xx 8\'b0011_0100, 8\'b0011_0101, 8\'b0011_0110, 8\'b0011_0111
+`define def_0011_10xx 8\'b0011_1000, 8\'b0011_1001, 8\'b0011_1010, 8\'b0011_1011
+`define def_0011_11xx 8\'b0011_1100, 8\'b0011_1101, 8\'b0011_1110, 8\'b0011_1111
+
+`define def_0100_00xx 8\'b0100_0000, 8\'b0100_0001, 8\'b0100_0010, 8\'b0100_0011
+`define def_0100_01xx 8\'b0100_0100, 8\'b0100_0101, 8\'b0100_0110, 8\'b0100_0111
+`define def_0100_10xx 8\'b0100_1000, 8\'b0100_1001, 8\'b0100_1010, 8\'b0100_1011
+`define def_0100_11xx 8\'b0100_1100, 8\'b0100_1101, 8\'b0100_1110, 8\'b0100_1111
+
+`define def_0101_00xx 8\'b0101_0000, 8\'b0101_0001, 8\'b0101_0010, 8\'b0101_0011
+`define def_0101_01xx 8\'b0101_0100, 8\'b0101_0101, 8\'b0101_0110, 8\'b0101_0111
+`define def_0101_10xx 8\'b0101_1000, 8\'b0101_1001, 8\'b0101_1010, 8\'b0101_1011
+`define def_0101_11xx 8\'b0101_1100, 8\'b0101_1101, 8\'b0101_1110, 8\'b0101_1111
+
+`define def_0110_00xx 8\'b0110_0000, 8\'b0110_0001, 8\'b0110_0010, 8\'b0110_0011
+`define def_0110_01xx 8\'b0110_0100, 8\'b0110_0101, 8\'b0110_0110, 8\'b0110_0111
+`define def_0110_10xx 8\'b0110_1000, 8\'b0110_1001, 8\'b0110_1010, 8\'b0110_1011
+`define def_0110_11xx 8\'b0110_1100, 8\'b0110_1101, 8\'b0110_1110, 8\'b0110_1111
+
+`define def_0111_00xx 8\'b0111_0000, 8\'b0111_0001, 8\'b0111_0010, 8\'b0111_0011
+`define def_0111_01xx 8\'b0111_0100, 8\'b0111_0101, 8\'b0111_0110, 8\'b0111_0111
+`define def_0111_10xx 8\'b0111_1000, 8\'b0111_1001, 8\'b0111_1010, 8\'b0111_1011
+`define def_0111_11xx 8\'b0111_1100, 8\'b0111_1101, 8\'b0111_1110, 8\'b0111_1111
+
+`define def_1000_00xx 8\'b1000_0000, 8\'b1000_0001, 8\'b1000_0010, 8\'b1000_0011
+`define def_1000_01xx 8\'b1000_0100, 8\'b1000_0101, 8\'b1000_0110, 8\'b1000_0111
+`define def_1000_10xx 8\'b1000_1000, 8\'b1000_1001, 8\'b1000_1010, 8\'b1000_1011
+`define def_1000_11xx 8\'b1000_1100, 8\'b1000_1101, 8\'b1000_1110, 8\'b1000_1111
+
+`define def_1001_00xx 8\'b1001_0000, 8\'b1001_0001, 8\'b1001_0010, 8\'b1001_0011
+`define def_1001_01xx 8\'b1001_0100, 8\'b1001_0101, 8\'b1001_0110, 8\'b1001_0111
+`define def_1001_10xx 8\'b1001_1000, 8\'b1001_1001, 8\'b1001_1010, 8\'b1001_1011
+`define def_1001_11xx 8\'b1001_1100, 8\'b1001_1101, 8\'b1001_1110, 8\'b1001_1111
+
+`define def_1010_00xx 8\'b1010_0000, 8\'b1010_0001, 8\'b1010_0010, 8\'b1010_0011
+`define def_1010_01xx 8\'b1010_0100, 8\'b1010_0101, 8\'b1010_0110, 8\'b1010_0111
+`define def_1010_10xx 8\'b1010_1000, 8\'b1010_1001, 8\'b1010_1010, 8\'b1010_1011
+`define def_1010_11xx 8\'b1010_1100, 8\'b1010_1101, 8\'b1010_1110, 8\'b1010_1111
+
+`define def_1011_00xx 8\'b1011_0000, 8\'b1011_0001, 8\'b1011_0010, 8\'b1011_0011
+`define def_1011_01xx 8\'b1011_0100, 8\'b1011_0101, 8\'b1011_0110, 8\'b1011_0111
+`define def_1011_10xx 8\'b1011_1000, 8\'b1011_1001, 8\'b1011_1010, 8\'b1011_1011
+`define def_1011_11xx 8\'b1011_1100, 8\'b1011_1101, 8\'b1011_1110, 8\'b1011_1111
+
+`define def_1100_00xx 8\'b1100_0000, 8\'b1100_0001, 8\'b1100_0010, 8\'b1100_0011
+`define def_1100_01xx 8\'b1100_0100, 8\'b1100_0101, 8\'b1100_0110, 8\'b1100_0111
+`define def_1100_10xx 8\'b1100_1000, 8\'b1100_1001, 8\'b1100_1010, 8\'b1100_1011
+`define def_1100_11xx 8\'b1100_1100, 8\'b1100_1101, 8\'b1100_1110, 8\'b1100_1111
+
+`define def_1101_00xx 8\'b1101_0000, 8\'b1101_0001, 8\'b1101_0010, 8\'b1101_0011
+`define def_1101_01xx 8\'b1101_0100, 8\'b1101_0101, 8\'b1101_0110, 8\'b1101_0111
+`define def_1101_10xx 8\'b1101_1000, 8\'b1101_1001, 8\'b1101_1010, 8\'b1101_1011
+`define def_1101_11xx 8\'b1101_1100, 8\'b1101_1101, 8\'b1101_1110, 8\'b1101_1111
+
+`define def_1110_00xx 8\'b1110_0000, 8\'b1110_0001, 8\'b1110_0010, 8\'b1110_0011
+`define def_1110_01xx 8\'b1110_0100, 8\'b1110_0101, 8\'b1110_0110, 8\'b1110_0111
+`define def_1110_10xx 8\'b1110_1000, 8\'b1110_1001, 8\'b1110_1010, 8\'b1110_1011
+`define def_1110_11xx 8\'b1110_1100, 8\'b1110_1101, 8\'b1110_1110, 8\'b1110_1111
+
+`define def_1111_00xx 8\'b1111_0000, 8\'b1111_0001, 8\'b1111_0010, 8\'b1111_0011
+`define def_1111_01xx 8\'b1111_0100, 8\'b1111_0101, 8\'b1111_0110, 8\'b1111_0111
+`define def_1111_10xx 8\'b1111_1000, 8\'b1111_1001, 8\'b1111_1010, 8\'b1111_1011
+`define def_1111_11xx 8\'b1111_1100, 8\'b1111_1101, 8\'b1111_1110, 8\'b1111_1111
+
+`define def_0001_xxxx `def_0001_00xx, `def_0001_01xx, `def_0001_10xx, `def_0001_11xx
+`define def_0010_xxxx `def_0010_00xx, `def_0010_01xx, `def_0010_10xx, `def_0010_11xx
+`define def_0011_xxxx `def_0011_00xx, `def_0011_01xx, `def_0011_10xx, `def_0011_11xx
+`define def_0100_xxxx `def_0100_00xx, `def_0100_01xx, `def_0100_10xx, `def_0100_11xx
+`define def_0101_xxxx `def_0101_00xx, `def_0101_01xx, `def_0101_10xx, `def_0101_11xx
+`define def_0110_xxxx `def_0110_00xx, `def_0110_01xx, `def_0110_10xx, `def_0110_11xx
+`define def_0111_xxxx `def_0111_00xx, `def_0111_01xx, `def_0111_10xx, `def_0111_11xx
+
+`define def_1000_xxxx `def_1000_00xx, `def_1000_01xx, `def_1000_10xx, `def_1000_11xx
+`define def_1001_xxxx `def_1001_00xx, `def_1001_01xx, `def_1001_10xx, `def_1001_11xx
+`define def_1010_xxxx `def_1010_00xx, `def_1010_01xx, `def_1010_10xx, `def_1010_11xx
+`define def_1011_xxxx `def_1011_00xx, `def_1011_01xx, `def_1011_10xx, `def_1011_11xx
+`define def_1100_xxxx `def_1100_00xx, `def_1100_01xx, `def_1100_10xx, `def_1100_11xx
+`define def_1101_xxxx `def_1101_00xx, `def_1101_01xx, `def_1101_10xx, `def_1101_11xx
+`define def_1110_xxxx `def_1110_00xx, `def_1110_01xx, `def_1110_10xx, `def_1110_11xx
+`define def_1111_xxxx `def_1111_00xx, `def_1111_01xx, `def_1111_10xx, `def_1111_11xx
+
+`define def_1xxx_xxxx `def_1000_xxxx, `def_1001_xxxx, `def_1010_xxxx, `def_1011_xxxx, \\
+ `def_1100_xxxx, `def_1101_xxxx, `def_1110_xxxx, `def_1111_xxxx
+`define def_01xx_xxxx `def_0100_xxxx, `def_0101_xxxx, `def_0110_xxxx, `def_0111_xxxx
+`define def_001x_xxxx `def_0010_xxxx, `def_0011_xxxx
+
+
+
+module clz(
+ input wire [7:0] data_i,
+ output wire [6:0] out
+);
+
+ // -----------------------------
+ // Reg declarations
+ // -----------------------------
+
+ reg [2:0] clz_byte0;
+ reg [2:0] clz_byte1;
+ reg [2:0] clz_byte2;
+ reg [2:0] clz_byte3;
+
+ always @*
+ case (data_i)
+ `def_1xxx_xxxx : clz_byte0 = 3\'b000;
+ `def_01xx_xxxx : clz_byte0 = 3\'b001;
+ `def_001x_xxxx : clz_byte0 = 3\'b010;
+ `def_0001_xxxx : clz_byte0 = 3\'b011;
+ `def_0000_1xxx : clz_byte0 = 3\'b100;
+ `def_0000_01xx : clz_byte0 = 3\'b101;
+ `def_0000_001x : clz_byte0 = 3\'b110;
+ 8\'b0000_0001 : clz_byte0 = 3\'b111;
+ 8\'b0000_0000 : clz_byte0 = 3\'b111;
+ default : clz_byte0 = 3\'bxxx;
+ endcase
+
+ always @*
+ case (data_i)
+ `def_1xxx_xxxx : clz_byte1 = 3\'b000;
+ `def_01xx_xxxx : clz_byte1 = 3\'b001;
+ `def_001x_xxxx : clz_byte1 = 3\'b010;
+ `def_0001_xxxx : clz_byte1 = 3\'b011;
+ `def_0000_1xxx : clz_byte1 = 3\'b100;
+ `def_0000_01xx : clz_byte1 = 3\'b101;
+ `def_0000_001x : clz_byte1 = 3\'b110;
+ 8\'b0000_0001 : clz_byte1 = 3\'b111;
+ 8\'b0000_0000 : clz_byte1 = 3\'b111;
+ default : clz_byte1 = 3\'bxxx;
+ endcase
+
+ always @*
+ case (data_i)
+ `def_1xxx_xxxx : clz_byte2 = 3\'b000;
+ `def_01xx_xxxx : clz_byte2 = 3\'b001;
+ `def_001x_xxxx : clz_byte2 = 3\'b010;
+ `def_0001_xxxx : clz_byte2 = 3\'b011;
+ `def_0000_1xxx : clz_byte2 = 3\'b100;
+ `def_0000_01xx : clz_byte2 = 3\'b101;
+ `def_0000_001x : clz_byte2 = 3\'b110;
+ 8\'b0000_0001 : clz_byte2 = 3\'b111;
+ 8\'b0000_0000 : clz_byte2 = 3\'b111;
+ default : clz_byte2 = 3\'bxxx;
+ endcase
+ always @*
+ case (data_i)
+ `def_1xxx_xxxx : clz_byte3 = 3\'b000;
+ `def_01xx_xxxx : clz_byte3 = 3\'b001;
+ `def_001x_xxxx : clz_byte3 = 3\'b010;
+ `def_0001_xxxx : clz_byte3 = 3\'b011;
+ `def_0000_1xxx : clz_byte3 = 3\'b100;
+ `def_0000_01xx : clz_byte3 = 3\'b101;
+ `def_0000_001x : clz_byte3 = 3\'b110;
+ 8\'b0000_0001 : clz_byte3 = 3\'b111;
+ 8\'b0000_0000 : clz_byte3 = 3\'b111;
+ default : clz_byte3 = 3\'bxxx;
+ endcase
+
+ assign out = {4\'b0000, clz_byte1};
+
+endmodule // clz
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Jeremy Bennett.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ wire [19:10] bitout;
+ wire [29:24] short_bitout;
+ wire [7:0] \tallbits;
+ wire [15:0] \ttwobits;
+
+ sub
+ i_sub1 [7:4] (.allbits (allbits),
+\t\t .twobits (twobits[15:8]),
+\t\t .bitout (bitout[17:14])),
+ i_sub2 [3:0] (.allbits (allbits),
+\t\t .twobits (twobits[7:0]),
+\t\t .bitout (bitout[13:10]));
+
+ sub
+ i_sub3 [7:4] (.allbits (allbits),
+\t\t .twobits (twobits[15:8]),
+\t\t .bitout (bitout[17:14]));
+
+ sub
+ i_sub4 [7:4] (.allbits (allbits),
+\t\t .twobits (twobits[15:8]),
+\t\t .bitout (short_bitout[27:24]));
+
+ sub
+ i_sub5 [7:0] (.allbits (allbits),
+\t\t .twobits (twobits),
+\t\t .bitout (bitout[17:10]));
+
+ sub
+ i_sub6 [7:4] (.allbits (allbits),
+\t\t .twobits (twobits[15:8]),
+\t\t .bitout ({bitout[18+:2],short_bitout[28+:2]}));
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Signals under test
+ assign allbits = crc[7:0];
+ assign twobits = crc[15:0];
+ wire [63:0] result = {48\'h0, short_bitout, bitout};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'ha1da9ff8082a4ff6
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule // t
+
+
+module sub
+ ( input wire [7:0] allbits,
+ input wire [1:0] twobits,
+ output wire bitout);
+
+ assign bitout = (^ twobits) ^ (^ allbits);
+
+endmodule // sub
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t;
+ wire d1 = 1\'b1;
+ wire d2 = 1\'b1;
+ wire d3 = 1\'b1;
+ wire o1,o2,o3;
+ add1 add1 (d1,o1);
+ add2 add2 (d2,o2);
+
+`define ls left_side
+`define rs right_side
+`define noarg na//note extra space
+`define thru(x) x
+`define thruthru `ls `rs\t// Doesn\'t expand
+`define msg(x,y) `""x: `\\`""y`\\`""`""
+`define left(m,left) m // The \'left\' as the variable name shouldn\'t match the ""left"" in the `"" string
+ initial begin
+ //$display(`msg( \\`, \\`)); // Illegal
+ $display(`msg(pre `thru(thrupre `thru(thrumid) thrupost) post,right side));
+ $display(`msg(left side,right side));
+ $display(`msg( left side , right side ));
+ $display(`msg( `ls , `rs ));
+ $display(`msg( `noarg , `rs ));
+ $display(`msg( prep ( midp1 `ls midp2 ( outp ) ) , `rs ));
+ $display(`msg(`noarg,`noarg`noarg));
+ $display(`msg( `thruthru , `thruthru )); // Results vary between simulators
+ $display(`left(`msg( left side , right side ), left_replaced));
+ //$display(`msg( `""tickquoted_left`"", `""tickquoted_right`"" )); // Syntax error
+`ifndef VCS // Sim bug - wrong number of arguments, but we\'re right
+ $display(`msg(`thru(),)); // Empty
+`endif
+ $display(`msg(`thru(left side),`thru(right side)));
+ $display(`msg( `thru( left side ) , `thru( right side ) ));
+`ifndef NC
+ $display(`""standalone`"");
+`endif
+
+`ifdef VERILATOR
+ // Illegal on some simulators, as the ""..."" crosses two lines
+`define twoline first \\
+ second
+ $display(`msg(twoline, `twoline));
+`endif
+
+ $display(""Line %0d File \\""%s\\"""",`__LINE__,`__FILE__);
+
+ //$display(`msg(left side, \\ right side \\ )); // Not sure \\{space} is legal.
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+
+`define ADD_UP(a,c) \\
+wire tmp_``a = a; \\
+wire tmp_``c = tmp_``a + 1; \\
+assign c = tmp_``c ;
+
+module add1 ( input wire d1, output wire o1);
+ `ADD_UP(d1,o1) // expansion is OK
+endmodule
+module add2 ( input wire d2, output wire o2);
+ `ADD_UP( d2 , o2 ) // expansion is bad
+endmodule
+// `ADD_UP( \\d3 , \\o3 ) // This really is illegal
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t_embed1_wrap (/*AUTOARG*/
+ // Outputs
+ bit_out, vec_out, wide_out, did_init_out,
+ // Inputs
+ clk, bit_in, vec_in, wide_in, is_ref
+ );
+
+ /*AUTOINOUTMODULE(""t_embed1_child"")*/
+ // Beginning of automatic in/out/inouts (from specific module)
+ output\t\tbit_out;
+ output [30:0]\tvec_out;
+ output [123:0]\twide_out;
+ output\t\tdid_init_out;
+ input\t\tclk;
+ input\t\tbit_in;
+ input [30:0]\t\tvec_in;
+ input [123:0]\twide_in;
+ input\t\tis_ref;
+ // End of automatics
+
+`ifdef verilator
+ // Import $t_embed_child__initial etc as a DPI function
+`endif
+
+ //TODO would like __\'s as in {PREFIX}__initial but presently illegal for users to do this
+ import ""DPI-C"" context function void t_embed_child_initial();
+ import ""DPI-C"" context function void t_embed_child_final();
+ import ""DPI-C"" context function void t_embed_child_eval();
+ import ""DPI-C"" context function void t_embed_child_io_eval
+ (
+ //TODO we support bit, but not logic
+ input bit clk,
+ input bit bit_in,
+ input bit [30:0] vec_in,
+ input bit [123:0] wide_in,
+ input bit is_ref,
+ output bit bit_out,
+ output bit [30:0] vec_out,
+ output bit [123:0] wide_out,
+ output bit did_init_out);
+
+ initial begin
+ // Load all values
+ t_embed_child_initial();
+ end
+
+ // Only if system verilog, and if a ""final"" block in the code
+ final begin
+ t_embed_child_final();
+ end
+
+ bit _temp_bit_out;
+ bit _temp_did_init_out;
+ bit [30:0] _temp_vec_out;
+ bit [123:0] _temp_wide_out;
+ always @* begin
+ t_embed_child_io_eval(
+\t\t\t clk,
+\t\t\t bit_in,
+\t\t\t vec_in,
+\t\t\t wide_in,
+\t\t\t is_ref,
+\t\t\t _temp_bit_out,
+\t\t\t _temp_vec_out,
+\t\t\t _temp_wide_out,
+\t\t\t _temp_did_init_out
+\t\t\t );
+ // TODO might eliminate these temporaries
+ bit_out = _temp_bit_out;
+ did_init_out = _temp_did_init_out;
+ end
+
+
+ // Send all variables every cycle,
+ // or have a sensitivity routine for each?
+ // How to make sure we call eval at end of variable changes?
+ // #0 (though not verilator compatible!)
+
+ // TODO for now, we know what changes when
+ always @ (posedge clk) begin
+ vec_out <= _temp_vec_out;
+ wide_out <= _temp_wide_out;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+`timescale 1 ns/ 1ns
+
+module top (/*AUTOARG*/
+ // Outputs
+ passed, out_small, out_quad, out_wide,
+ // Inputs
+ clk, fastclk, reset_l, in_small, in_quad, in_wide
+ );
+
+ output passed;
+ input clk;
+ input fastclk;
+ input reset_l;
+
+ output [1:0] out_small;
+ output [39:0] out_quad;
+ output [69:0] out_wide;
+ input [1:0] \t in_small;
+ input [39:0] in_quad;
+ input [69:0] in_wide;
+
+ wire [1:0] \t out_small = in_small | {2{reset_l}};
+ wire [39:0] \t out_quad = in_quad | {40{reset_l}};
+ wire [69:0] \t out_wide = in_wide | {70{reset_l}};
+
+ initial begin
+ $write(""Hello World!\
+"");
+ end
+
+ // Example sub module
+ t t (/*AUTOINST*/
+\t// Outputs
+\t.passed\t\t\t\t(passed),
+\t// Inputs
+\t.clk\t\t\t\t(clk),
+\t.fastclk\t\t\t(fastclk),
+\t.reset_l\t\t\t(reset_l));
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ in
+ );
+
+ input in; // inputs don\'t get flagged as undriven
+ output out; // outputs don\'t get flagged as unused
+
+ sub sub ();
+
+ // Check we don\'t warn about unused UDP signals
+ udp_mux2 udpsub (out, in, in, in);
+
+ // Check ignoreds mark as used
+ reg \t sysused;
+ initial $bboxed(sysused);
+
+ // Check file IO. The fopen is the ""driver"" all else a usage.
+ integer infile;
+ integer outfile;
+ initial begin
+ outfile = $fopen(""obj_dir/t_lint_unused_bad/open.log"", ""w"");
+ $fwrite(outfile, ""1\
+"");
+ $fclose(outfile);
+ infile = $fopen(""obj_dir/t_lint_unused_bad/open.log"", ""r"");
+ if ($fgetc(infile) != ""1"") begin end
+ end
+
+ wire _unused_ok;
+
+endmodule
+
+module sub;
+
+ wire pub /*verilator public*/; // Ignore publics
+
+ localparam THREE = 3;
+
+endmodule
+
+primitive udp_mux2 (q, a, b, s);
+ output q;
+ input a, b, s;
+ table
+ //a b s : out
+ 1 ? 0 : 1 ;
+ 0 ? 0 : 0 ;
+ ? 1 1 : 1 ;
+ ? 0 1 : 0 ;
+ 0 0 x : 0 ;
+ 1 1 x : 1 ;
+ endtable
+endprimitive
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005-2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ reg [3:0] value;
+ reg [3:0] valuex;
+
+ // verilator lint_off CASEOVERLAP
+ // verilator lint_off CASEWITHX
+ // verilator lint_off CASEX
+
+ // Note for Verilator Xs must become zeros, or the Xs may match.
+
+ initial begin
+ value = 4\'b1001;
+ valuex = 4\'b1xxx;
+ case (value)
+\t4\'b1xxx: $stop;
+\t4\'b1???: $stop;
+\t4\'b1001: ;
+\tdefault: $stop;
+ endcase
+ case (valuex)
+\t4\'b1???: $stop;
+\t4\'b1xxx: ;
+\t4\'b1001: ;
+\t4\'b1000: ; // 1xxx is mapped to this by Verilator -x-assign 0
+\tdefault: $stop;
+ endcase
+ //
+ casex (value)
+\t4\'b100x: ;
+\tdefault: $stop;
+ endcase
+ casex (value)
+\t4\'b100?: ;
+\tdefault: $stop;
+ endcase
+ casex (valuex)
+\t4\'b100x: ;
+\tdefault: $stop;
+ endcase
+ casex (valuex)
+\t4\'b100?: ;
+\tdefault: $stop;
+ endcase
+ //
+ casez (value)
+\t4\'bxxxx: $stop;
+\t4\'b100?: ;
+\tdefault: $stop;
+ endcase
+ casez (valuex)
+\t4\'b1xx?: ;
+\t4\'b100?: ; // 1xxx is mapped to this by Verilator -x-assign 0
+\tdefault: $stop;
+ endcase
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Unsupported tristate constructur error
+//
+// This is a compile only regression test of tristate handling for bug514
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Jeremy Bennett.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ wire [11:0] ck;
+
+ assign ck[1:0] = {1'bz,{1{1'b0}}};
+
+ test i_test (.clk (ck[1:0]));
+
+endmodule
+
+
+module test (clk);
+
+ output wire [1:0] clk;
+
+endmodule // test
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+
+ reg [0:0] d1;
+ reg [2:0] d3;
+ reg [7:0] d8;
+
+ wire [0:0] q1;
+ wire [2:0] q3;
+ wire [7:0] q8;
+
+ // verilator lint_off UNOPTFLAT
+ reg \t ena;
+ // verilator lint_on UNOPTFLAT
+
+ condff #(12) condff
+ (.clk(clk), .sen(1\'b0), .ena(ena),
+ .d({d8,d3,d1}),
+ .q({q8,q3,q1}));
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t //$write(""%x %x %x %x\
+"", cyc, q8, q3, q1);
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t d1 <= 1\'b1; d3<=3\'h1; d8<=8\'h11;
+\t ena <= 1\'b1;
+\t end
+\t if (cyc==2) begin
+\t d1 <= 1\'b0; d3<=3\'h2; d8<=8\'h33;
+\t ena <= 1\'b0;
+\t end
+\t if (cyc==3) begin
+\t d1 <= 1\'b1; d3<=3\'h3; d8<=8\'h44;
+\t ena <= 1\'b1;
+\t if (q8 != 8\'h11) $stop;
+\t end
+\t if (cyc==4) begin
+\t d1 <= 1\'b1; d3<=3\'h4; d8<=8\'h77;
+\t ena <= 1\'b1;
+\t if (q8 != 8\'h11) $stop;
+\t end
+\t if (cyc==5) begin
+\t d1 <= 1\'b1; d3<=3\'h0; d8<=8\'h88;
+\t ena <= 1\'b1;
+\t if (q8 != 8\'h44) $stop;
+\t end
+\t if (cyc==6) begin
+\t if (q8 != 8\'h77) $stop;
+\t end
+\t if (cyc==7) begin
+\t if (q8 != 8\'h88) $stop;
+\t end
+\t //
+\t if (cyc==20) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+
+module condff (clk, sen, ena, d, q);
+ parameter WIDTH = 1;
+ input clk;
+
+ input sen;
+ input ena;
+ input [WIDTH-1:0] d;
+ output [WIDTH-1:0] q;
+
+ condffimp #(.WIDTH(WIDTH))
+ imp (.clk(clk), .sen(sen), .ena(ena), .d(d), .q(q));
+endmodule
+
+module condffimp (clk, sen, ena, d, q);
+ parameter WIDTH = 1;
+ input clk;
+ input sen;
+ input ena;
+ input [WIDTH-1:0] d;
+ output reg [WIDTH-1:0] q;
+ wire gatedclk;
+
+ clockgate clockgate (.clk(clk), .sen(sen), .ena(ena), .gatedclk(gatedclk));
+
+ always @(posedge gatedclk) begin
+ if (gatedclk === 1\'bX) begin
+\t q <= {WIDTH{1\'bX}};
+ end
+ else begin
+\t q <= d;
+ end
+ end
+
+endmodule
+
+module clockgate (clk, sen, ena, gatedclk);
+ input\tclk;
+ input\tsen;
+ input\tena;
+ output\tgatedclk;
+
+ reg\t\tena_b;
+ wire gatedclk = clk & ena_b;
+
+ // verilator lint_off COMBDLY
+ always @(clk or ena or sen) begin
+ if (~clk) begin
+ ena_b <= ena | sen;
+ end
+ else begin
+\t if ((clk^sen)===1\'bX) ena_b <= 1\'bX;
+ end
+ end
+ // verilator lint_on COMBDLY
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t;
+ real n0; initial n0 = 0.0;
+ real n1; initial n1 = 1.0;
+ real n2; initial n2 = 0.1;
+ real n3; initial n3 = 1.2345e-15;
+ real n4; initial n4 = 2.579e+15;
+ reg [7:0] r8; initial r8 = 3;
+
+ initial begin
+ // Display formatting
+ $display(""[%0t] e=%e e1=%1e e30=%3.0e e32=%3.2e"", $time, n0,n0,n0,n0);
+ $display(""[%0t] f=%f f1=%1e f30=%3.0e f32=%3.2e"", $time, n0,n0,n0,n0);
+ $display(""[%0t] g=%g g1=%1e g30=%3.0e g32=%3.2e"", $time, n0,n0,n0,n0);
+ $display;
+ $display(""[%0t] e=%e e1=%1e e30=%3.0e e32=%3.2e"", $time, n1,n1,n1,n1);
+ $display(""[%0t] f=%f f1=%1e f30=%3.0e f32=%3.2e"", $time, n1,n1,n1,n1);
+ $display(""[%0t] g=%g g1=%1e g30=%3.0e g32=%3.2e"", $time, n1,n1,n1,n1);
+ $display;
+ $display(""[%0t] e=%e e1=%1e e30=%3.0e e32=%3.2e"", $time, n2,n2,n2,n2);
+ $display(""[%0t] f=%f f1=%1e f30=%3.0e f32=%3.2e"", $time, n2,n2,n2,n2);
+ $display(""[%0t] g=%g g1=%1e g30=%3.0e g32=%3.2e"", $time, n2,n2,n2,n2);
+ $display;
+ $display(""[%0t] e=%e e1=%1e e30=%3.0e e32=%3.2e"", $time, n3,n3,n3,n3);
+ $display(""[%0t] f=%f f1=%1e f30=%3.0e f32=%3.2e"", $time, n3,n3,n3,n3);
+ $display(""[%0t] g=%g g1=%1e g30=%3.0e g32=%3.2e"", $time, n3,n3,n3,n3);
+ $display;
+ $display(""[%0t] e=%e e1=%1e e30=%3.0e e32=%3.2e"", $time, n4,n4,n4,n4);
+ $display(""[%0t] f=%f f1=%1e f30=%3.0e f32=%3.2e"", $time, n4,n4,n4,n4);
+ $display(""[%0t] g=%g g1=%1e g30=%3.0e g32=%3.2e"", $time, n4,n4,n4,n4);
+ $display;
+ $display(""r8=%d n1=%g n2=%g"", r8, n1, n2);
+ $display(""n1=%g n2=%g r8=%d"", n1, n2, r8);
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg [31:0] in_a;
+ reg [31:0] in_b;
+
+ reg [31:0] e,f,g,h;
+
+ always @ (/*AS*/in_a) begin
+ e = in_a;
+ f = {e[15:0], e[31:16]};
+ g = {f[15:0], f[31:16]};
+ h = {g[15:0], g[31:16]};
+ end
+
+ // verilator lint_off UNOPTFLAT
+ reg [31:0] e2,f2,g2,h2;
+ always @ (/*AS*/f2) begin
+ h2 = {g2[15:0], g2[31:16]};
+ g2 = {f2[15:0], f2[31:16]};
+ end
+ always @ (/*AS*/in_a) begin
+ f2 = {e2[15:0], e2[31:16]};
+ e2 = in_a;
+ end
+ // verilator lint_on UNOPTFLAT
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t //$write(""%d %x %x\
+"", cyc, h, h2);
+\t if (h != h2) $stop;
+\t if (cyc==1) begin
+\t in_a <= 32\'h89a14fab;
+\t in_b <= 32\'h7ab512fa;
+\t end
+\t if (cyc==2) begin
+\t in_a <= 32\'hf4c11a42;
+\t in_b <= 32\'h359967c6;
+\t if (h != 32\'h4fab89a1) $stop;
+\t end
+\t if (cyc==3) begin
+\t if (h != 32\'h1a42f4c1) $stop;
+\t end
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2009 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+module t ();
+
+ // Same name w/ different args
+ import ""DPI-C"" dpii_fa_bit = function int oth_f_int1(input int i);
+ import ""DPI-C"" pure dpii_fa_bit = function int oth_f_int2(input int i, input int bad);
+
+ initial begin
+ $stop;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+// Also check that SystemC is ordering properly
+// verilator lint_on IMPERFECTSCH
+
+module t (/*AUTOARG*/
+ // Outputs
+ o1, o8, o16, o32, o64, o65, o128, o513, o1a2, o94a3, obv1, obv16,
+ // Inputs
+ clk, i1, i8, i16, i32, i64, i65, i128, i513, i1a2, i94a3, ibv1, ibv16
+ );
+
+ input clk;
+
+ input \t i1;
+ input [7:0]\t i8;
+ input [15:0]\t i16;
+ input [31:0]\t i32;
+ input [63:0]\t i64;
+ input [64:0]\t i65;
+ input [127:0] i128;
+ input [512:0] i513;
+ input \t i1a2 [1:0];
+ input [93:0] i94a3 [2:0];
+
+
+ output \t o1;
+ output [7:0] o8;
+ output [15:0] o16;
+ output [31:0] o32;
+ output [63:0] o64;
+ output [64:0] o65;
+ output [127:0] o128;
+ output [512:0] o513;
+ output\t o1a2 [1:0];
+ output [93:0] o94a3 [2:0];
+
+ input [0:0] \t ibv1 /*verilator sc_bv*/;
+ input [15:0] ibv16 /*verilator sc_bv*/;
+
+ output [0:0] obv1 /*verilator sc_bv*/;
+ output [15:0] obv16 /*verilator sc_bv*/;
+
+ always @ (posedge clk) begin
+ o1 <= i1;
+ o8 <= i8;
+ o16 <= i16;
+ o32 <= i32;
+ o64 <= i64;
+ o65 <= i65;
+ o128 <= i128;
+ o513 <= i513;
+ obv1 <= ibv1;
+ obv16 <= ibv16;
+ o1a2 <= i1a2;
+ o94a3 <= i94a3;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ wire [4:0] in = crc[4:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ logic\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(in[4:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {63\'h0, out};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h7a7bd4ee927e7cc3
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ clk, in
+ );
+
+ //bug718
+
+ input clk;
+
+ input logic [4:0] in;
+
+ output logic out;
+
+ always @(posedge clk) begin
+ out <= in inside {5\'b1_1?1?};
+ end
+
+endmodule // t"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ outc_w30, outd_w73,
+ // Inputs
+ clk, ina_w1, inb_w61
+ );
+
+ input clk;
+
+ input ina_w1;
+ input [60:0] inb_w61;
+ output [29:0] outc_w30;
+ output [72:0] outd_w73;
+
+ sub sub (
+\t // Outputs
+\t .outy_w92\t(outc_w30),\t// .large => (small)
+\t .outz_w22\t(outd_w73),\t// .small => (large)
+\t // Inputs
+\t .clk\t(clk),
+\t .inw_w31\t(ina_w1),\t// .large <= (small)
+\t .inx_w11\t(inb_w61)\t// .small <= (large)
+\t );
+
+endmodule
+
+module sub (/*AUTOARG*/
+ // Outputs
+ outy_w92, outz_w22,
+ // Inputs
+ clk, inw_w31, inx_w11
+ );
+
+ input \tclk;
+ input [30:0]\tinw_w31;
+ input [10:0]\tinx_w11;
+ output reg [91:0] outy_w92 /*verilator public*/;
+ output reg [21:0] outz_w22 /*verilator public*/;
+
+ always @(posedge clk) begin
+ outy_w92 <= {inw_w31[29:0],inw_w31[29:0],inw_w31[29:0],2'b00};
+ outz_w22 <= {inx_w11[10:0],inx_w11[10:0]};
+ end
+
+endmodule // regfile
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc = 0;
+
+ logic [1:0][27:0] ch01;
+ logic [1:0][27:0] ch02;
+ logic [1:0][27:0] ch03;
+ logic [27:0] ch04[1:0];
+
+ /* verilator lint_off WIDTH */
+ always @ (posedge clk) begin
+ // LHS is a 2D packed array, RHS is 1D packed or Const. Allowed now.
+ ch01 <= {{2{28\'d4}}};
+ ch02 <= {{2{cyc}}};
+ ch03 <= 56\'d0;
+ // LHS is 1D packed, 1D unpacked, this should never work.
+ ch04 <= 56\'d0;
+ $display(""ch01: %0x %0x"", ch01[0], ch01[1]);
+ $display(""ch01: %0x %0x"", ch02[0], ch02[1]);
+ $display(""ch01: %0x %0x"", ch03[0], ch03[1]);
+ $display(""ch01: %0x %0x"", ch04[0], ch04[1]);
+ end
+ /* verilator lint_on WIDTH */
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003-2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ reg [7:0] cyc; initial cyc=0;
+
+ reg [31:0] in;
+ wire [31:0] out;
+ t_extend_class_v sub (.in(in), .out(out));
+
+ always @ (posedge clk) begin
+ cyc <= cyc+8\'d1;
+ if (cyc == 8\'d1) begin
+\t in <= 32\'h10;
+ end
+ if (cyc == 8\'d2) begin
+\t if (out != 32\'h11) $stop;
+ end
+ if (cyc == 8\'d9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module t_extend_class_v (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ in
+ );
+
+ input [31:0] in;
+ output [31:0] out;
+
+ always @* begin
+ // When ""in"" changes, call my method
+ out = $c(""m_myobjp->my_math("",in,"")"");
+ end
+
+ `systemc_header
+#include ""t_extend_class_c.h""\t// Header for contained object
+ `systemc_interface
+ t_extend_class_c* m_myobjp;\t// Pointer to object we are embedding
+ `systemc_ctor
+ m_myobjp = new t_extend_class_c();\t// Construct contained object
+ `systemc_dtor
+ delete m_myobjp;\t// Destruct contained object
+ `verilog
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t(/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ reg \t _ranit;
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [4:0]\t\tpar1;\t\t\t// From a1 of t_param_first_a.v
+ wire [4:0]\t\tpar2;\t\t\t// From a2 of t_param_first_a.v
+ wire [4:0]\t\tpar3;\t\t\t// From a3 of t_param_first_a.v
+ wire [4:0]\t\tpar4;\t\t\t// From a4 of t_param_first_a.v
+ wire [1:0]\t\tvarwidth1;\t\t// From a1 of t_param_first_a.v
+ wire [2:0]\t\tvarwidth2;\t\t// From a2 of t_param_first_a.v
+ wire [3:0]\t\tvarwidth3;\t\t// From a3 of t_param_first_a.v
+ wire [3:0]\t\tvarwidth4;\t\t// From a4 of t_param_first_a.v
+ // End of automatics
+ /*t_param_first_a AUTO_TEMPLATE (
+\t\t .par\t\t(par@[]));
+\t\t .varwidth\t\t(varwidth@[]));
+ */
+
+ parameter XX = 2\'bXX;
+
+ parameter THREE = 3;
+
+ t_param_first_a #(1,5) a1
+ (
+ // Outputs
+ .varwidth\t\t(varwidth1[1:0]),
+ /*AUTOINST*/
+ // Outputs
+ .par\t\t\t\t(par1[4:0]));\t\t // Templated
+ t_param_first_a #(2,5) a2
+ (
+ // Outputs
+ .varwidth\t\t(varwidth2[2:0]),
+ /*AUTOINST*/
+ // Outputs
+ .par\t\t\t\t(par2[4:0]));\t\t // Templated
+ t_param_first_a #(THREE,5) a3
+ (
+ // Outputs
+ .varwidth\t\t(varwidth3[3:0]),
+ /*AUTOINST*/
+ // Outputs
+ .par\t\t\t\t(par3[4:0]));\t\t // Templated
+ t_param_first_a #(THREE,5) a4
+ (
+ // Outputs
+ .varwidth\t\t(varwidth4[3:0]),
+ /*AUTOINST*/
+ // Outputs
+ .par\t\t\t\t(par4[4:0]));\t\t // Templated
+
+ parameter THREE_BITS_WIDE = 3\'b011;
+ parameter THREE_2WIDE = 2\'b11;
+ parameter ALSO_THREE_WIDE = THREE_BITS_WIDE;
+ parameter THREEPP_32_WIDE = 2*8*2+3;
+ parameter THREEPP_3_WIDE = 3\'d4*3\'d4*3\'d2+3\'d3; // Yes folks VCS says 3 bits wide
+
+ // Width propagation doesn\'t care about LHS vs RHS
+ // But the width of a RHS/LHS on a upper node does affect lower nodes;
+ // Thus must double-descend in width analysis.
+ // VCS 7.0.1 is broken on this test!
+ parameter T10 = (3\'h7+3\'h7)+4\'h0;\t//initial if (T10!==4\'d14) $stop;
+ parameter T11 = 4\'h0+(3\'h7+3\'h7);\t//initial if (T11!==4\'d14) $stop;
+
+ // Parameters assign LHS is affectively width zero.
+ parameter T12 = THREE_2WIDE + THREE_2WIDE;\tinitial if (T12!==2\'d2) $stop;
+ parameter T13 = THREE_2WIDE + 3;\t\tinitial if (T13!==32\'d6) $stop;
+
+ // Must be careful about LSB\'s with extracts
+ parameter [39:8] T14 = 32\'h00_1234_56; initial if (T14[24:16]!==9\'h34) $stop;
+
+ //
+ parameter THREEPP_32P_WIDE = 3\'d4*3\'d4*2+3\'d3;
+ parameter THREE_32_WIDE = 3%32;
+ parameter THIRTYTWO = 2;\t// Param is 32 bits
+ parameter [40:0] WIDEPARAM = 41\'h12_3456789a;
+ parameter [40:0] WIDEPARAM2 = WIDEPARAM;
+
+ reg [7:0] eightb;
+ reg [3:0] fourb;
+ wire [7:0] eight = 8\'b00010000;
+ wire [1:0] eight2two = eight[THREE_32_WIDE+1:THREE_32_WIDE];
+ wire [2:0] threebits = ALSO_THREE_WIDE;
+
+ // surefire lint_off CWCCXX
+
+ initial _ranit = 0;
+
+ always @ (posedge clk) begin
+ if (!_ranit) begin
+\t _ranit <= 1;
+\t $write(""[%0t] t_param: Running\
+"", $time);
+\t //
+\t $write("" %d %d %d\
+"", par1,par2,par3);
+\t if (par1!==5\'d1) $stop;
+\t if (par2!==5\'d2) $stop;
+\t if (par3!==5\'d3) $stop;
+\t if (par4!==5\'d3) $stop;
+\t if (varwidth1!==2\'d2) $stop;
+\t if (varwidth2!==3\'d2) $stop;
+\t if (varwidth3!==4\'d2) $stop;
+\t if (varwidth4!==4\'d2) $stop;
+\t if (threebits !== 3\'b011) $stop;
+\t if (eight !== 8\'b00010000) $stop;
+\t if (eight2two !== 2\'b10) $stop;
+\t $write("" Params = %b %b\
+ %b %b\
+"",
+\t\tTHREEPP_32_WIDE,THREEPP_3_WIDE,
+\t\tTHIRTYTWO, THREEPP_32P_WIDE);
+\t if (THREEPP_32_WIDE !== 32\'h23) $stop;
+\t if (THREEPP_3_WIDE !== 3\'h3) $stop;
+\t if (THREEPP_32P_WIDE !== 32\'h23) $stop;
+\t if (THIRTYTWO[1:0] !== 2\'h2) $stop;
+\t if (THIRTYTWO !== 32\'h2) $stop;
+\t if (THIRTYTWO !== 2) $stop;
+\t if ((THIRTYTWO[1:0]+2\'b00) !== 2\'b10) $stop;
+\t if ({1\'b1,{THIRTYTWO[1:0]+2\'b00}} !== 3\'b110) $stop;
+\t if (XX===0 || XX===1 || XX===2 || XX===3) $stop; // Paradoxical but right, since 1\'bx!=0 && !=1
+\t //
+\t // Example of assignment LHS affecting expression widths.
+\t // verilator lint_off WIDTH
+\t // surefire lint_off ASWCMB
+\t // surefire lint_off ASWCBB
+\t eightb = (4\'d8+4\'d8)/4\'d4;\tif (eightb!==8\'d4) $stop;
+\t fourb = (4\'d8+4\'d8)/4\'d4;\tif (fourb!==4\'d0) $stop;
+\t fourb = (4\'d8+8)/4\'d4;\t\tif (fourb!==4\'d4) $stop;
+\t // verilator lint_on WIDTH
+\t // surefire lint_on ASWCMB
+\t // surefire lint_on ASWCBB
+\t //
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ value
+ );
+ input [3:0] value;
+ assign value = 4'h0;
+ sub sub (.valueSub\t(value[3:0]));
+endmodule
+
+module sub (/*AUTOARG*/
+ // Inputs
+ valueSub
+ );
+ input [3:0] valueSub;
+ assign valueSub = 4'h0;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // verilator lint_off GENCLK
+
+ reg [7:0] cyc; initial cyc=0;
+ reg [7:0] padd;
+ reg \t dsp_ph1, dsp_ph2, dsp_reset;
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [7:0]\t\tout;\t\t\t// From dspchip of t_dspchip.v
+ // End of automatics
+
+ t_dspchip dspchip (/*AUTOINST*/
+\t\t // Outputs
+\t\t .out\t\t(out[7:0]),
+\t\t // Inputs
+\t\t .dsp_ph1\t\t(dsp_ph1),
+\t\t .dsp_ph2\t\t(dsp_ph2),
+\t\t .dsp_reset\t(dsp_reset),
+\t\t .padd\t\t(padd[7:0]));
+
+ always @ (posedge clk) begin
+ $write(""cyc %d\
+"",cyc);
+ if (cyc == 8\'d0) begin
+\t cyc <= 8\'d1;
+\t dsp_reset <= 0;\t// Need a posedge
+\t padd <= 0;
+ end
+ else if (cyc == 8\'d20) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ else begin
+\t cyc <= cyc + 8\'d1;
+\t dsp_ph1 <= ((cyc&8\'d3) == 8\'d0);
+\t dsp_ph2 <= ((cyc&8\'d3) == 8\'d2);
+\t dsp_reset <= (cyc == 8\'d1);
+\t padd <= cyc;
+\t //$write(""[%0t] cyc %d %x->%x\
+"", $time, cyc, padd, out);
+\t case (cyc)
+\t default: $stop;
+\t 8\'d01: ;
+\t 8\'d02: ;
+\t 8\'d03: ;
+\t 8\'d04: ;
+\t 8\'d05: ;
+\t 8\'d06: ;
+\t 8\'d07: ;
+\t 8\'d08: ;
+\t 8\'d09: if (out!==8\'h04) $stop;
+\t 8\'d10: if (out!==8\'h04) $stop;
+\t 8\'d11: if (out!==8\'h08) $stop;
+\t 8\'d12: if (out!==8\'h08) $stop;
+\t 8\'d13: if (out!==8\'h00) $stop;
+\t 8\'d14: if (out!==8\'h00) $stop;
+\t 8\'d15: if (out!==8\'h00) $stop;
+\t 8\'d16: if (out!==8\'h00) $stop;
+\t 8\'d17: if (out!==8\'h0c) $stop;
+\t 8\'d18: if (out!==8\'h0c) $stop;
+\t 8\'d19: if (out!==8\'h10) $stop;
+\t endcase
+ end
+ end
+
+endmodule
+
+module t_dspchip (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ dsp_ph1, dsp_ph2, dsp_reset, padd
+ );
+ input dsp_ph1, dsp_ph2, dsp_reset;
+ input [7:0] padd;
+ output [7:0] out;
+
+ wire \tdsp_ph1, dsp_ph2;
+ wire [7:0] \tout;
+ wire \tpla_ph1, pla_ph2;
+ wire \tout1_r;
+ wire [7:0] \tout2_r, padd;
+ wire \tclk_en;
+
+ t_dspcore t_dspcore (/*AUTOINST*/
+\t\t\t// Outputs
+\t\t\t.out1_r\t\t(out1_r),
+\t\t\t.pla_ph1\t(pla_ph1),
+\t\t\t.pla_ph2\t(pla_ph2),
+\t\t\t// Inputs
+\t\t\t.dsp_ph1\t(dsp_ph1),
+\t\t\t.dsp_ph2\t(dsp_ph2),
+\t\t\t.dsp_reset\t(dsp_reset),
+\t\t\t.clk_en\t\t(clk_en));
+ t_dsppla t_dsppla (/*AUTOINST*/
+\t\t // Outputs
+\t\t .out2_r\t\t(out2_r[7:0]),
+\t\t // Inputs
+\t\t .pla_ph1\t\t(pla_ph1),
+\t\t .pla_ph2\t\t(pla_ph2),
+\t\t .dsp_reset\t(dsp_reset),
+\t\t .padd\t\t(padd[7:0]));
+
+ assign \tout = out1_r ? 8\'h00 : out2_r;
+ assign \tclk_en = 1\'b1;
+
+endmodule
+
+module t_dspcore (/*AUTOARG*/
+ // Outputs
+ out1_r, pla_ph1, pla_ph2,
+ // Inputs
+ dsp_ph1, dsp_ph2, dsp_reset, clk_en
+ );
+ input dsp_ph1, dsp_ph2, dsp_reset;
+ input clk_en;
+ output out1_r, pla_ph1, pla_ph2;
+
+ wire dsp_ph1, dsp_ph2, dsp_reset;
+ wire pla_ph1, pla_ph2;
+ reg \t out1_r;
+
+ always @(posedge dsp_ph1 or posedge dsp_reset) begin
+ if (dsp_reset)
+\tout1_r <= 1\'h0;
+ else
+\tout1_r <= ~out1_r;
+ end
+
+ assign pla_ph1 = dsp_ph1;
+ assign pla_ph2 = dsp_ph2 & clk_en;
+
+endmodule
+
+module t_dsppla (/*AUTOARG*/
+ // Outputs
+ out2_r,
+ // Inputs
+ pla_ph1, pla_ph2, dsp_reset, padd
+ );
+ input pla_ph1, pla_ph2, dsp_reset;
+ input [7:0] padd;
+ output [7:0] out2_r;
+
+ wire \tpla_ph1, pla_ph2, dsp_reset;
+ wire [7:0] \tpadd;
+ reg [7:0] \tout2_r;
+
+ reg [7:0] \tlatched_r;
+
+ always @(posedge pla_ph1 or posedge dsp_reset) begin
+ if (dsp_reset)
+\tlatched_r <= 8\'h00;
+ else
+\tlatched_r <= padd;
+ end
+
+ always @(posedge pla_ph2 or posedge dsp_reset) begin
+ if (dsp_reset)
+\tout2_r <= 8\'h00;
+ else
+\tout2_r <= latched_r;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t;
+
+`define DUP fred
+`define DUP barney
+
+`define DUPP paramed(x) (x)
+`define DUPP paramed(x,z) (x*z)
+
+ initial $stop; // Should have failed
+
+endmodule
+"
+"module t(y);
+ output [3:0] y;
+ // bug775
+ // verilator lint_off WIDTH
+ assign y = ((0/0) ? 1 : 2) % 0;
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // verilator lint_off GENCLK
+
+ reg [7:0] cyc; initial cyc=0;
+ reg \t genclk;
+ // verilator lint_off MULTIDRIVEN
+ reg [7:0] set_both;
+ // verilator lint_on MULTIDRIVEN
+
+ wire genthiscyc = ( (cyc % 2) == 1 );
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 8\'h1;
+ genclk <= genthiscyc;
+ set_both <= cyc;
+ $write (""SB set_both %x <= cyc %x\
+"", set_both, cyc);
+ if (genthiscyc) begin
+\t if (cyc>1 && set_both != (cyc - 8\'h1)) $stop;
+ end
+ else begin
+\t if (cyc>1 && set_both != ~(cyc - 8\'h1)) $stop;
+ end
+ if (cyc==10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+ always @ (posedge genclk) begin
+ set_both <= ~ set_both;
+ $write (""SB set_both %x <= cyc %x\
+"", set_both, ~cyc);
+ if (cyc>1 && set_both != (cyc - 8\'h1)) $stop;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg [255:0] \t\ti;
+ wire [255:0]\t\tq;
+
+ assign q = {
+\t\ti[176],i[168],i[126],i[177],i[097],i[123],i[231],i[039],
+\t\ti[156],i[026],i[001],i[052],i[005],i[240],i[157],i[048],
+\t\ti[111],i[088],i[133],i[225],i[046],i[038],i[004],i[234],
+\t\ti[115],i[008],i[069],i[099],i[137],i[130],i[255],i[122],
+\t\ti[223],i[195],i[224],i[083],i[094],i[018],i[067],i[034],
+\t\ti[221],i[105],i[104],i[107],i[053],i[066],i[020],i[174],
+\t\ti[010],i[196],i[003],i[041],i[071],i[194],i[154],i[110],
+\t\ti[186],i[210],i[040],i[044],i[243],i[236],i[239],i[183],
+\t\ti[164],i[064],i[086],i[193],i[055],i[206],i[203],i[128],
+\t\ti[190],i[233],i[023],i[022],i[135],i[108],i[061],i[139],
+\t\ti[180],i[043],i[109],i[090],i[229],i[238],i[095],i[173],
+\t\ti[208],i[054],i[025],i[024],i[148],i[079],i[246],i[142],
+\t\ti[181],i[129],i[120],i[220],i[036],i[159],i[201],i[119],
+\t\ti[216],i[152],i[175],i[138],i[242],i[143],i[101],i[035],
+\t\ti[228],i[082],i[211],i[062],i[076],i[124],i[150],i[149],
+\t\ti[235],i[227],i[250],i[134],i[068],i[032],i[060],i[144],
+\t\ti[042],i[163],i[087],i[059],i[213],i[251],i[200],i[070],
+\t\ti[145],i[204],i[249],i[191],i[127],i[247],i[106],i[017],
+\t\ti[028],i[045],i[215],i[162],i[205],i[073],i[065],i[084],
+\t\ti[153],i[158],i[085],i[197],i[212],i[114],i[096],i[118],
+\t\ti[146],i[030],i[058],i[230],i[141],i[000],i[199],i[171],
+\t\ti[182],i[185],i[021],i[016],i[033],i[237],i[015],i[112],
+\t\ti[222],i[253],i[244],i[031],i[248],i[092],i[226],i[179],
+\t\ti[189],i[056],i[132],i[116],i[072],i[184],i[027],i[002],
+\t\ti[103],i[125],i[009],i[078],i[178],i[245],i[170],i[161],
+\t\ti[102],i[047],i[192],i[012],i[057],i[207],i[187],i[151],
+\t\ti[218],i[254],i[214],i[037],i[131],i[165],i[011],i[098],
+\t\ti[169],i[209],i[167],i[202],i[100],i[172],i[147],i[013],
+\t\ti[136],i[166],i[252],i[077],i[051],i[074],i[140],i[050],
+\t\ti[217],i[198],i[081],i[091],i[075],i[121],i[188],i[219],
+\t\ti[160],i[241],i[080],i[155],i[019],i[006],i[014],i[029],
+\t\ti[089],i[049],i[113],i[232],i[007],i[117],i[063],i[093]
+\t };
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+`ifdef TEST_VERBOSE
+\t $write(""%x %x\
+"", q, i);
+`endif
+\t if (cyc==1) begin
+\t i <= 256\'hed388e646c843d35de489bab2413d77045e0eb7642b148537491f3da147e7f26;
+\t end
+\t if (cyc==2) begin
+\t i <= 256\'h0e17c88f3d5fe51a982646c8e2bd68c3e236ddfddddbdad20a48e039c9f395b8;
+\t if (q != 256\'h697bad4b0cf2d7fa4ad22809293710bb67d1eb3131e8eb2135f2c7bd820baa84) $stop;
+\t end
+\t if (cyc==3) begin
+\t if (q != 256\'h320eda5078b3e942353d16dddc8b29fd773b4fcec8323612dadfb1fa483f602c) $stop;
+\t end
+\t if (cyc==4) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+`include ""verilated.v""
+
+module t_case_write2_tasks ();
+
+ // verilator lint_off WIDTH
+ // verilator lint_off CASEINCOMPLETE
+
+ `define FD_BITS 31:0
+
+ parameter STRLEN = 78;
+ task ozonerab;
+ input [6:0] rab;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (rab[6:0])
+\t 7\'h00 : $fwrite (fd, "" 0"");
+\t 7\'h01 : $fwrite (fd, "" 1"");
+\t 7\'h02 : $fwrite (fd, "" 2"");
+\t 7\'h03 : $fwrite (fd, "" 3"");
+\t 7\'h04 : $fwrite (fd, "" 4"");
+\t 7\'h05 : $fwrite (fd, "" 5"");
+\t 7\'h06 : $fwrite (fd, "" 6"");
+\t 7\'h07 : $fwrite (fd, "" 7"");
+\t 7\'h08 : $fwrite (fd, "" 8"");
+\t 7\'h09 : $fwrite (fd, "" 9"");
+\t 7\'h0a : $fwrite (fd, "" 10"");
+\t 7\'h0b : $fwrite (fd, "" 11"");
+\t 7\'h0c : $fwrite (fd, "" 12"");
+\t 7\'h0d : $fwrite (fd, "" 13"");
+\t 7\'h0e : $fwrite (fd, "" 14"");
+\t 7\'h0f : $fwrite (fd, "" 15"");
+\t 7\'h10 : $fwrite (fd, "" 16"");
+\t 7\'h11 : $fwrite (fd, "" 17"");
+\t 7\'h12 : $fwrite (fd, "" 18"");
+\t 7\'h13 : $fwrite (fd, "" 19"");
+\t 7\'h14 : $fwrite (fd, "" 20"");
+\t 7\'h15 : $fwrite (fd, "" 21"");
+\t 7\'h16 : $fwrite (fd, "" 22"");
+\t 7\'h17 : $fwrite (fd, "" 23"");
+\t 7\'h18 : $fwrite (fd, "" 24"");
+\t 7\'h19 : $fwrite (fd, "" 25"");
+\t 7\'h1a : $fwrite (fd, "" 26"");
+\t 7\'h1b : $fwrite (fd, "" 27"");
+\t 7\'h1c : $fwrite (fd, "" 28"");
+\t 7\'h1d : $fwrite (fd, "" 29"");
+\t 7\'h1e : $fwrite (fd, "" 30"");
+\t 7\'h1f : $fwrite (fd, "" 31"");
+\t 7\'h20 : $fwrite (fd, "" 32"");
+\t 7\'h21 : $fwrite (fd, "" 33"");
+\t 7\'h22 : $fwrite (fd, "" 34"");
+\t 7\'h23 : $fwrite (fd, "" 35"");
+\t 7\'h24 : $fwrite (fd, "" 36"");
+\t 7\'h25 : $fwrite (fd, "" 37"");
+\t 7\'h26 : $fwrite (fd, "" 38"");
+\t 7\'h27 : $fwrite (fd, "" 39"");
+\t 7\'h28 : $fwrite (fd, "" 40"");
+\t 7\'h29 : $fwrite (fd, "" 41"");
+\t 7\'h2a : $fwrite (fd, "" 42"");
+\t 7\'h2b : $fwrite (fd, "" 43"");
+\t 7\'h2c : $fwrite (fd, "" 44"");
+\t 7\'h2d : $fwrite (fd, "" 45"");
+\t 7\'h2e : $fwrite (fd, "" 46"");
+\t 7\'h2f : $fwrite (fd, "" 47"");
+\t 7\'h30 : $fwrite (fd, "" 48"");
+\t 7\'h31 : $fwrite (fd, "" 49"");
+\t 7\'h32 : $fwrite (fd, "" 50"");
+\t 7\'h33 : $fwrite (fd, "" 51"");
+\t 7\'h34 : $fwrite (fd, "" 52"");
+\t 7\'h35 : $fwrite (fd, "" 53"");
+\t 7\'h36 : $fwrite (fd, "" 54"");
+\t 7\'h37 : $fwrite (fd, "" 55"");
+\t 7\'h38 : $fwrite (fd, "" 56"");
+\t 7\'h39 : $fwrite (fd, "" 57"");
+\t 7\'h3a : $fwrite (fd, "" 58"");
+\t 7\'h3b : $fwrite (fd, "" 59"");
+\t 7\'h3c : $fwrite (fd, "" 60"");
+\t 7\'h3d : $fwrite (fd, "" 61"");
+\t 7\'h3e : $fwrite (fd, "" 62"");
+\t 7\'h3f : $fwrite (fd, "" 63"");
+\t 7\'h40 : $fwrite (fd, "" 64"");
+\t 7\'h41 : $fwrite (fd, "" 65"");
+\t 7\'h42 : $fwrite (fd, "" 66"");
+\t 7\'h43 : $fwrite (fd, "" 67"");
+\t 7\'h44 : $fwrite (fd, "" 68"");
+\t 7\'h45 : $fwrite (fd, "" 69"");
+\t 7\'h46 : $fwrite (fd, "" 70"");
+\t 7\'h47 : $fwrite (fd, "" 71"");
+\t 7\'h48 : $fwrite (fd, "" 72"");
+\t 7\'h49 : $fwrite (fd, "" 73"");
+\t 7\'h4a : $fwrite (fd, "" 74"");
+\t 7\'h4b : $fwrite (fd, "" 75"");
+\t 7\'h4c : $fwrite (fd, "" 76"");
+\t 7\'h4d : $fwrite (fd, "" 77"");
+\t 7\'h4e : $fwrite (fd, "" 78"");
+\t 7\'h4f : $fwrite (fd, "" 79"");
+\t 7\'h50 : $fwrite (fd, "" 80"");
+\t 7\'h51 : $fwrite (fd, "" 81"");
+\t 7\'h52 : $fwrite (fd, "" 82"");
+\t 7\'h53 : $fwrite (fd, "" 83"");
+\t 7\'h54 : $fwrite (fd, "" 84"");
+\t 7\'h55 : $fwrite (fd, "" 85"");
+\t 7\'h56 : $fwrite (fd, "" 86"");
+\t 7\'h57 : $fwrite (fd, "" 87"");
+\t 7\'h58 : $fwrite (fd, "" 88"");
+\t 7\'h59 : $fwrite (fd, "" 89"");
+\t 7\'h5a : $fwrite (fd, "" 90"");
+\t 7\'h5b : $fwrite (fd, "" 91"");
+\t 7\'h5c : $fwrite (fd, "" 92"");
+\t 7\'h5d : $fwrite (fd, "" 93"");
+\t 7\'h5e : $fwrite (fd, "" 94"");
+\t 7\'h5f : $fwrite (fd, "" 95"");
+\t 7\'h60 : $fwrite (fd, "" 96"");
+\t 7\'h61 : $fwrite (fd, "" 97"");
+\t 7\'h62 : $fwrite (fd, "" 98"");
+\t 7\'h63 : $fwrite (fd, "" 99"");
+\t 7\'h64 : $fwrite (fd, "" 100"");
+\t 7\'h65 : $fwrite (fd, "" 101"");
+\t 7\'h66 : $fwrite (fd, "" 102"");
+\t 7\'h67 : $fwrite (fd, "" 103"");
+\t 7\'h68 : $fwrite (fd, "" 104"");
+\t 7\'h69 : $fwrite (fd, "" 105"");
+\t 7\'h6a : $fwrite (fd, "" 106"");
+\t 7\'h6b : $fwrite (fd, "" 107"");
+\t 7\'h6c : $fwrite (fd, "" 108"");
+\t 7\'h6d : $fwrite (fd, "" 109"");
+\t 7\'h6e : $fwrite (fd, "" 110"");
+\t 7\'h6f : $fwrite (fd, "" 111"");
+\t 7\'h70 : $fwrite (fd, "" 112"");
+\t 7\'h71 : $fwrite (fd, "" 113"");
+\t 7\'h72 : $fwrite (fd, "" 114"");
+\t 7\'h73 : $fwrite (fd, "" 115"");
+\t 7\'h74 : $fwrite (fd, "" 116"");
+\t 7\'h75 : $fwrite (fd, "" 117"");
+\t 7\'h76 : $fwrite (fd, "" 118"");
+\t 7\'h77 : $fwrite (fd, "" 119"");
+\t 7\'h78 : $fwrite (fd, "" 120"");
+\t 7\'h79 : $fwrite (fd, "" 121"");
+\t 7\'h7a : $fwrite (fd, "" 122"");
+\t 7\'h7b : $fwrite (fd, "" 123"");
+\t 7\'h7c : $fwrite (fd, "" 124"");
+\t 7\'h7d : $fwrite (fd, "" 125"");
+\t 7\'h7e : $fwrite (fd, "" 126"");
+\t 7\'h7f : $fwrite (fd, "" 127"");
+\t default:$fwrite (fd, "" 128"");
+\t endcase
+ end
+ endtask
+
+ task ozonerb;
+ input [5:0] rb;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (rb[5:0])
+\t 6\'h10,
+\t 6\'h17,
+\t 6\'h1e,
+\t 6\'h1f: $fwrite (fd, "" 129"");
+\t default: ozonerab({1\'b1, rb}, fd);
+\t endcase
+ end
+ endtask
+
+ task ozonef3f4_iext;
+ input [1:0] foo;
+ input [15:0] im16;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (foo)
+\t 2\'h0 :
+ begin
+\t\tskyway({4{im16[15]}}, fd);
+\t\tskyway({4{im16[15]}}, fd);
+\t\tskyway(im16[15:12], fd);
+\t\tskyway(im16[11: 8], fd);
+\t\tskyway(im16[ 7: 4], fd);
+\t\tskyway(im16[ 3:0], fd);
+\t\t$fwrite (fd, "" 130"");
+ end
+\t 2\'h1 :
+ begin
+\t\t$fwrite (fd, "" 131"");
+\t\tskyway(im16[15:12], fd);
+\t\tskyway(im16[11: 8], fd);
+\t\tskyway(im16[ 7: 4], fd);
+\t\tskyway(im16[ 3:0], fd);
+ end
+\t 2\'h2 :
+ begin
+\t\tskyway({4{im16[15]}}, fd);
+\t\tskyway({4{im16[15]}}, fd);
+\t\tskyway(im16[15:12], fd);
+\t\tskyway(im16[11: 8], fd);
+\t\tskyway(im16[ 7: 4], fd);
+\t\tskyway(im16[ 3:0], fd);
+\t\t$fwrite (fd, "" 132"");
+ end
+\t 2\'h3 :
+ begin
+\t\t$fwrite (fd, "" 133"");
+\t\tskyway(im16[15:12], fd);
+\t\tskyway(im16[11: 8], fd);
+\t\tskyway(im16[ 7: 4], fd);
+\t\tskyway(im16[ 3:0], fd);
+ end
+\t endcase
+ end
+ endtask
+
+ task skyway;
+ input [ 3:0] hex;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (hex)
+\t 4\'h0 : $fwrite (fd, "" 134"");
+\t 4\'h1 : $fwrite (fd, "" 135"");
+\t 4\'h2 : $fwrite (fd, "" 136"");
+\t 4\'h3 : $fwrite (fd, "" 137"");
+\t 4\'h4 : $fwrite (fd, "" 138"");
+\t 4\'h5 : $fwrite (fd, "" 139"");
+\t 4\'h6 : $fwrite (fd, "" 140"");
+\t 4\'h7 : $fwrite (fd, "" 141"");
+\t 4\'h8 : $fwrite (fd, "" 142"");
+\t 4\'h9 : $fwrite (fd, "" 143"");
+\t 4\'ha : $fwrite (fd, "" 144"");
+\t 4\'hb : $fwrite (fd, "" 145"");
+\t 4\'hc : $fwrite (fd, "" 146"");
+\t 4\'hd : $fwrite (fd, "" 147"");
+\t 4\'he : $fwrite (fd, "" 148"");
+\t 4\'hf : $fwrite (fd, "" 149"");
+\t endcase
+ end
+ endtask
+
+ task ozonesr;
+ input [ 15:0] foo;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (foo[11: 9])
+\t 3\'h0 : $fwrite (fd, "" 158"");
+\t 3\'h1 : $fwrite (fd, "" 159"");
+\t 3\'h2 : $fwrite (fd, "" 160"");
+\t 3\'h3 : $fwrite (fd, "" 161"");
+\t 3\'h4 : $fwrite (fd, "" 162"");
+\t 3\'h5 : $fwrite (fd, "" 163"");
+\t 3\'h6 : $fwrite (fd, "" 164"");
+\t 3\'h7 : $fwrite (fd, "" 165"");
+\t endcase
+ end
+ endtask
+
+ task ozonejk;
+ input k;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t if (k)
+\t $fwrite (fd, "" 166"");
+\t else
+\t $fwrite (fd, "" 167"");
+ end
+ endtask
+
+ task ozoneae;
+ input [ 2:0] ae;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (ae)
+\t 3\'b000 : $fwrite (fd, "" 168"");
+\t 3\'b001 : $fwrite (fd, "" 169"");
+\t 3\'b010 : $fwrite (fd, "" 170"");
+\t 3\'b011 : $fwrite (fd, "" 171"");
+\t 3\'b100 : $fwrite (fd, "" 172"");
+\t 3\'b101 : $fwrite (fd, "" 173"");
+\t 3\'b110 : $fwrite (fd, "" 174"");
+\t 3\'b111 : $fwrite (fd, "" 175"");
+\t endcase
+ end
+ endtask
+
+ task ozoneaee;
+ input [ 2:0] aee;
+ input [`FD_BITS] \tfd;
+ // verilator no_inline_task
+ begin
+\t case (aee)
+\t 3\'b001,
+\t 3\'b011,
+\t 3\'b101,
+\t 3\'b111 : $fwrite (fd, "" 176"");
+\t 3\'b000 : $fwrite (fd, "" 177"");
+\t 3\'b010 : $fwrite (fd, "" 178"");
+\t 3\'b100 : $fwrite (fd, "" 179"");
+\t 3\'b110 : $fwrite (fd, "" 180"");
+\t endcase
+ end
+ endtask
+
+ task ozoneape;
+ input [ 2:0] ape;
+ input [`FD_BITS] \tfd;
+ // verilator no_inline_task
+ begin
+\t case (ape)
+\t 3\'b001,
+\t 3\'b011,
+\t 3\'b101,
+\t 3\'b111 : $fwrite (fd, "" 181"");
+\t 3\'b000 : $fwrite (fd, "" 182"");
+\t 3\'b010 : $fwrite (fd, "" 183"");
+\t 3\'b100 : $fwrite (fd, "" 184"");
+\t 3\'b110 : $fwrite (fd, "" 185"");
+\t endcase
+ end
+ endtask
+
+ task ozonef1;
+ input [ 31:0] foo;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (foo[24:21])
+\t 4\'h0 :
+ if (foo[26])
+ $fwrite (fd, "" 186"");
+ else
+ $fwrite (fd, "" 187"");
+\t 4\'h1 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd, "" 188"");
+ 2\'b01 : $fwrite (fd, "" 189"");
+ 2\'b10 : $fwrite (fd, "" 190"");
+ 2\'b11 : $fwrite (fd, "" 191"");
+ endcase
+\t 4\'h2 : $fwrite (fd, "" 192"");
+\t 4\'h3 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd, "" 193"");
+ 2\'b01 : $fwrite (fd, "" 194"");
+ 2\'b10 : $fwrite (fd, "" 195"");
+ 2\'b11 : $fwrite (fd, "" 196"");
+ endcase
+\t 4\'h4 :
+ if (foo[26])
+ $fwrite (fd, "" 197"");
+ else
+ $fwrite (fd, "" 198"");
+\t 4\'h5 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd, "" 199"");
+ 2\'b01 : $fwrite (fd, "" 200"");
+ 2\'b10 : $fwrite (fd, "" 201"");
+ 2\'b11 : $fwrite (fd, "" 202"");
+ endcase
+\t 4\'h6 : $fwrite (fd, "" 203"");
+\t 4\'h7 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd, "" 204"");
+ 2\'b01 : $fwrite (fd, "" 205"");
+ 2\'b10 : $fwrite (fd, "" 206"");
+ 2\'b11 : $fwrite (fd, "" 207"");
+ endcase
+\t 4\'h8 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd, "" 208"");
+ 2\'b01 : $fwrite (fd, "" 209"");
+ 2\'b10 : $fwrite (fd, "" 210"");
+ 2\'b11 : $fwrite (fd, "" 211"");
+ endcase
+\t 4\'h9 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd, "" 212"");
+ 2\'b01 : $fwrite (fd, "" 213"");
+ 2\'b10 : $fwrite (fd, "" 214"");
+ 2\'b11 : $fwrite (fd, "" 215"");
+ endcase
+\t 4\'ha :
+ if (foo[25])
+ $fwrite (fd, "" 216"");
+ else
+ $fwrite (fd, "" 217"");
+\t 4\'hb :
+ if (foo[25])
+ $fwrite (fd, "" 218"");
+ else
+ $fwrite (fd, "" 219"");
+\t 4\'hc :
+ if (foo[26])
+ $fwrite (fd, "" 220"");
+ else
+ $fwrite (fd, "" 221"");
+\t 4\'hd :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd, "" 222"");
+ 2\'b01 : $fwrite (fd, "" 223"");
+ 2\'b10 : $fwrite (fd, "" 224"");
+ 2\'b11 : $fwrite (fd, "" 225"");
+ endcase
+\t 4\'he :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd, "" 226"");
+ 2\'b01 : $fwrite (fd, "" 227"");
+ 2\'b10 : $fwrite (fd, "" 228"");
+ 2\'b11 : $fwrite (fd, "" 229"");
+ endcase
+\t 4\'hf :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd, "" 230"");
+ 2\'b01 : $fwrite (fd, "" 231"");
+ 2\'b10 : $fwrite (fd, "" 232"");
+ 2\'b11 : $fwrite (fd, "" 233"");
+ endcase
+\t endcase
+ end
+ endtask
+
+ task ozonef1e;
+ input [ 31:0] foo;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (foo[27:21])
+\t 7\'h00:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 234"");
+\t\t$fwrite (fd, "" 235"");
+\t end
+\t 7\'h01:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 236"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 237"");
+\t\t$fwrite (fd, "" 238"");
+\t end
+\t 7\'h02:
+\t $fwrite (fd, "" 239"");
+\t 7\'h03:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 240"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 241"");
+\t\t$fwrite (fd, "" 242"");
+\t end
+\t 7\'h04:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 243"");
+\t\t$fwrite (fd,"" 244"");
+\t end
+\t 7\'h05:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 245"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 246"");
+\t end
+\t 7\'h06:
+\t $fwrite (fd, "" 247"");
+\t 7\'h07:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 248"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 249"");
+\t end
+\t 7\'h08:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 250"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 251"");
+\t end
+\t 7\'h09:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 252"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 253"");
+\t end
+\t 7\'h0a:
+\t begin
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 254"");
+\t end
+\t 7\'h0b:
+\t begin
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 255"");
+\t end
+\t 7\'h0c:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 256"");
+\t end
+\t 7\'h0d:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 257"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 258"");
+\t end
+\t 7\'h0e:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 259"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 260"");
+\t end
+\t 7\'h0f:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 261"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 262"");
+\t end
+\t 7\'h10:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 263"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 264"");
+\t\t$fwrite (fd, "" 265"");
+\t\t$fwrite (fd, "" 266"");
+\t end
+\t 7\'h11:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 267"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 268"");
+\t\t$fwrite (fd, "" 269"");
+\t\t$fwrite (fd, "" 270"");
+\t end
+\t 7\'h12:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 271"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 272"");
+\t\t$fwrite (fd, "" 273"");
+\t\t$fwrite (fd, "" 274"");
+\t end
+\t 7\'h13:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 275"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 276"");
+\t\t$fwrite (fd, "" 277"");
+\t\t$fwrite (fd, "" 278"");
+\t end
+\t 7\'h14:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 279"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 280"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 281"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 282"");
+\t\t$fwrite (fd, "" 283"");
+\t\t$fwrite (fd, "" 284"");
+\t end
+\t 7\'h15:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 285"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 286"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 287"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 288"");
+\t\t$fwrite (fd, "" 289"");
+\t\t$fwrite (fd, "" 290"");
+\t end
+\t 7\'h16:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 291"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 292"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 293"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 294"");
+\t\t$fwrite (fd, "" 295"");
+\t\t$fwrite (fd, "" 296"");
+\t end
+\t 7\'h17:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 297"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 298"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 299"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 300"");
+\t\t$fwrite (fd, "" 301"");
+\t\t$fwrite (fd, "" 302"");
+\t end
+\t 7\'h18:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 303"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 304"");
+\t\t$fwrite (fd, "" 305"");
+\t\t$fwrite (fd, "" 306"");
+\t end
+\t 7\'h19:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 307"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 308"");
+\t\t$fwrite (fd, "" 309"");
+\t\t$fwrite (fd, "" 310"");
+\t end
+\t 7\'h1a:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 311"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 312"");
+\t\t$fwrite (fd, "" 313"");
+\t\t$fwrite (fd, "" 314"");
+\t end
+\t 7\'h1b:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 315"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 316"");
+\t\t$fwrite (fd, "" 317"");
+\t\t$fwrite (fd, "" 318"");
+\t end
+\t 7\'h1c:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 319"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 320"");
+\t\t$fwrite (fd, "" 321"");
+\t\t$fwrite (fd, "" 322"");
+\t end
+\t 7\'h1d:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 323"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 324"");
+\t\t$fwrite (fd, "" 325"");
+\t\t$fwrite (fd, "" 326"");
+\t end
+\t 7\'h1e:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 327"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 328"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 329"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 330"");
+\t\t$fwrite (fd, "" 331"");
+\t\t$fwrite (fd, "" 332"");
+\t end
+\t 7\'h1f:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 333"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 334"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 335"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 336"");
+\t\t$fwrite (fd, "" 337"");
+\t\t$fwrite (fd, "" 338"");
+\t end
+\t 7\'h20:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 339"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 340"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 341"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 342"");
+\t\t$fwrite (fd, "" 343"");
+\t\t$fwrite (fd, "" 344"");
+\t end
+\t 7\'h21:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 345"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 346"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 347"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 348"");
+\t\t$fwrite (fd, "" 349"");
+\t\t$fwrite (fd, "" 350"");
+\t end
+\t 7\'h22:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 351"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 352"");
+\t\t$fwrite (fd, "" 353"");
+\t\t$fwrite (fd, "" 354"");
+\t end
+\t 7\'h23:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 355"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 356"");
+\t\t$fwrite (fd, "" 357"");
+\t\t$fwrite (fd, "" 358"");
+\t end
+\t 7\'h24:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 359"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 360"");
+\t\t$fwrite (fd, "" 361"");
+\t\t$fwrite (fd, "" 362"");
+\t end
+\t 7\'h25:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 363"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 364"");
+\t\t$fwrite (fd, "" 365"");
+\t\t$fwrite (fd, "" 366"");
+\t end
+\t 7\'h26:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 367"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 368"");
+\t\t$fwrite (fd, "" 369"");
+\t\t$fwrite (fd, "" 370"");
+\t end
+\t 7\'h27:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 371"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 372"");
+\t\t$fwrite (fd, "" 373"");
+\t\t$fwrite (fd, "" 374"");
+\t end
+\t 7\'h28:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 375"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 376"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 377"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 378"");
+\t\t$fwrite (fd, "" 379"");
+\t\t$fwrite (fd, "" 380"");
+\t end
+\t 7\'h29:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 381"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 382"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 383"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 384"");
+\t\t$fwrite (fd, "" 385"");
+\t\t$fwrite (fd, "" 386"");
+\t end
+\t 7\'h2a:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 387"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 388"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 389"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 390"");
+\t\t$fwrite (fd, "" 391"");
+\t\t$fwrite (fd, "" 392"");
+\t end
+\t 7\'h2b:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 393"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 394"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 395"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 396"");
+\t\t$fwrite (fd, "" 397"");
+\t\t$fwrite (fd, "" 398"");
+\t end
+\t 7\'h2c:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 399"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 400"");
+\t\t$fwrite (fd, "" 401"");
+\t\t$fwrite (fd, "" 402"");
+\t end
+\t 7\'h2d:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 403"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 404"");
+\t\t$fwrite (fd, "" 405"");
+\t\t$fwrite (fd, "" 406"");
+\t end
+\t 7\'h2e:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 407"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 408"");
+\t\t$fwrite (fd, "" 409"");
+\t\t$fwrite (fd, "" 410"");
+\t end
+\t 7\'h2f:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 411"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 412"");
+\t\t$fwrite (fd, "" 413"");
+\t\t$fwrite (fd, "" 414"");
+\t end
+\t 7\'h30:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 415"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 416"");
+\t\t$fwrite (fd, "" 417"");
+\t\t$fwrite (fd, "" 418"");
+\t end
+\t 7\'h31:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 419"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 420"");
+\t\t$fwrite (fd, "" 421"");
+\t\t$fwrite (fd, "" 422"");
+\t end
+\t 7\'h32:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 423"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 424"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 425"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 426"");
+\t\t$fwrite (fd, "" 427"");
+\t\t$fwrite (fd, "" 428"");
+\t end
+\t 7\'h33:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 429"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 430"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 431"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 432"");
+\t\t$fwrite (fd, "" 433"");
+\t\t$fwrite (fd, "" 434"");
+\t end
+\t 7\'h34:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 435"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 436"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 437"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 438"");
+\t\t$fwrite (fd, "" 439"");
+\t\t$fwrite (fd, "" 440"");
+\t end
+\t 7\'h35:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 441"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 442"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 443"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 444"");
+\t\t$fwrite (fd, "" 445"");
+\t\t$fwrite (fd, "" 446"");
+\t end
+\t 7\'h36:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 447"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 448"");
+\t\t$fwrite (fd, "" 449"");
+\t\t$fwrite (fd, "" 450"");
+\t end
+\t 7\'h37:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 451"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 452"");
+\t\t$fwrite (fd, "" 453"");
+\t\t$fwrite (fd, "" 454"");
+\t end
+\t 7\'h38:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 455"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 456"");
+\t\t$fwrite (fd, "" 457"");
+\t end
+\t 7\'h39:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 458"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 459"");
+\t\t$fwrite (fd, "" 460"");
+\t end
+\t 7\'h3a:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 461"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 462"");
+\t\t$fwrite (fd, "" 463"");
+\t end
+\t 7\'h3b:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 464"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 465"");
+\t\t$fwrite (fd, "" 466"");
+\t end
+\t 7\'h3c:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 467"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 468"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 469"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 470"");
+\t\t$fwrite (fd, "" 471"");
+\t end
+\t 7\'h3d:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 472"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 473"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 474"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 475"");
+\t\t$fwrite (fd, "" 476"");
+\t end
+\t 7\'h3e:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 477"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 478"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 479"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 480"");
+\t\t$fwrite (fd, "" 481"");
+\t end
+\t 7\'h3f:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 482"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 483"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 484"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 485"");
+\t\t$fwrite (fd, "" 486"");
+\t end
+\t 7\'h40:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 487"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 488"");
+\t\t$fwrite (fd, "" 489"");
+\t\t$fwrite (fd, "" 490"");
+\t end
+\t 7\'h41:
+\t begin
+\t\t$fwrite (fd, "" 491"");
+\t\t$fwrite (fd, "" 492"");
+\t end
+\t 7\'h42:
+\t begin
+\t\t$fwrite (fd, "" 493"");
+\t\t$fwrite (fd, "" 494"");
+\t end
+\t 7\'h43:
+\t begin
+\t\t$fwrite (fd, "" 495"");
+\t\t$fwrite (fd, "" 496"");
+\t end
+\t 7\'h44:
+\t begin
+\t\t$fwrite (fd, "" 497"");
+\t\t$fwrite (fd, "" 498"");
+\t end
+\t 7\'h45:
+\t $fwrite (fd, "" 499"");
+\t 7\'h46:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 500"");
+\t\t$fwrite (fd, "" 501"");
+\t\t$fwrite (fd, "" 502"");
+\t end
+\t 7\'h47:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 503"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 504"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 505"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 506"");
+\t\t$fwrite (fd, "" 507"");
+\t\t$fwrite (fd, "" 508"");
+\t end
+\t 7\'h48:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 509"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 510"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 511"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 512"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 513"");
+\t end
+\t 7\'h49:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 514"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 515"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 516"");
+\t end
+\t 7\'h4a:
+ $fwrite (fd,"" 517"");
+\t 7\'h4b:
+ $fwrite (fd, "" 518"");
+\t 7\'h4c:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 519"");
+\t\t$fwrite (fd, "" 520"");
+\t\t$fwrite (fd, "" 521"");
+\t end
+\t 7\'h4d:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 522"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 523"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 524"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 525"");
+\t\t$fwrite (fd, "" 526"");
+\t\t$fwrite (fd, "" 527"");
+\t end
+\t 7\'h4e:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 528"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 529"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 530"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 531"");
+\t end
+\t 7\'h4f:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 532"");
+\t end
+\t 7\'h50:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 533"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 534"");
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 535"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 536"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 537"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 538"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 539"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 540"");
+\t end
+\t 7\'h51:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 541"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 542"");
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 543"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 544"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 545"");
+\t end
+\t 7\'h52:
+\t $fwrite (fd, "" 546"");
+\t 7\'h53:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd, "" 547"");
+\t end
+\t 7\'h54:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 548"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 549"");
+\t end
+\t 7\'h55:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 550"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 551"");
+\t end
+\t 7\'h56:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 552"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 553"");
+\t\t$fwrite (fd, "" 554"");
+\t end
+\t 7\'h57:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 555"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 556"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 557"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 558"");
+\t end
+\t 7\'h58:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd, "" 559"");
+\t end
+\t 7\'h59:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 560"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 561"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 562"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 563"");
+\t end
+\t 7\'h5a:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 564"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd, "" 565"");
+\t end
+\t 7\'h5b:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 566"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd, "" 567"");
+\t end
+\t 7\'h5c:
+\t begin
+\t\t$fwrite (fd,"" 568"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 569"");
+\t\t$fwrite (fd,"" 570"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 571"");
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 572"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd, "" 573"");
+\t end
+\t 7\'h5d:
+\t begin
+\t\t$fwrite (fd,"" 574"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 575"");
+\t\t$fwrite (fd,"" 576"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 577"");
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 578"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd, "" 579"");
+\t end
+\t 7\'h5e:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 580"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd, "" 581"");
+\t end
+\t 7\'h5f:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 582"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 583"");
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 584"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 585"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 586"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 587"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 588"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 589"");
+\t end
+\t 7\'h60:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 590"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 591"");
+\t end
+\t 7\'h61:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 592"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 593"");
+\t end
+\t 7\'h62:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 594"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 595"");
+\t end
+\t 7\'h63:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 596"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 597"");
+\t end
+\t 7\'h64:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 598"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 599"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 600"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 601"");
+\t end
+\t 7\'h65:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 602"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 603"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 604"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 605"");
+\t end
+\t 7\'h66:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 606"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 607"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 608"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 609"");
+\t end
+\t 7\'h67:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 610"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 611"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 612"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 613"");
+\t end
+\t 7\'h68:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 614"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 615"");
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 616"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 617"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 618"");
+\t\tozoneape(foo[17:15], fd);
+\t end
+\t 7\'h69:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 619"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 620"");
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 621"");
+\t end
+\t 7\'h6a:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 622"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 623"");
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 624"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 625"");
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 626"");
+\t\tozoneae(foo[17:15], fd);
+\t end
+\t 7\'h6b:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 627"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 628"");
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 629"");
+\t end
+\t 7\'h6c:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 630"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 631"");
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 632"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 633"");
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 634"");
+\t\tozoneae(foo[17:15], fd);
+\t end
+\t 7\'h6d:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 635"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 636"");
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 637"");
+\t end
+\t 7\'h6e:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 638"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 639"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 640"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 641"");
+\t end
+\t 7\'h6f:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 642"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 643"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 644"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 645"");
+\t end
+\t 7\'h70:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 646"");
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 647"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 648"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd, "" 649"");
+\t end
+\t 7\'h71:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 650"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd, "" 651"");
+\t end
+\t 7\'h72:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 652"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd, "" 653"");
+\t end
+\t 7\'h73:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 654"");
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 655"");
+\t\tozoneae(foo[17:15], fd);
+\t end
+\t 7\'h74:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 656"");
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 657"");
+\t\tozoneae(foo[17:15], fd);
+\t end
+\t 7\'h75:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 658"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 659"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 660"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 661"");
+\t\t$fwrite (fd, "" 662"");
+\t\t$fwrite (fd, "" 663"");
+\t end
+\t 7\'h76:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 664"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 665"");
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 666"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 667"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 668"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 669"");
+\t end
+\t 7\'h77:
+\t begin
+\t\tozoneaee(foo[20:18], fd);
+\t\t$fwrite (fd,"" 670"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 671"");
+\t\tozoneaee(foo[17:15], fd);
+\t\t$fwrite (fd,"" 672"");
+\t\tozoneape(foo[20:18], fd);
+\t\t$fwrite (fd,"" 673"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 674"");
+\t\tozoneape(foo[17:15], fd);
+\t\t$fwrite (fd,"" 675"");
+\t end
+\t 7\'h78,
+\t 7\'h79,
+\t 7\'h7a,
+\t 7\'h7b,
+\t 7\'h7c,
+\t 7\'h7d,
+\t 7\'h7e,
+\t 7\'h7f:
+ $fwrite (fd,"" 676"");
+\t endcase
+ end
+ endtask
+
+ task ozonef2;
+ input [ 31:0] foo;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (foo[24:21])
+\t 4\'h0 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 677"");
+ 2\'b01 : $fwrite (fd,"" 678"");
+ 2\'b10 : $fwrite (fd,"" 679"");
+ 2\'b11 : $fwrite (fd,"" 680"");
+ endcase
+\t 4\'h1 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 681"");
+ 2\'b01 : $fwrite (fd,"" 682"");
+ 2\'b10 : $fwrite (fd,"" 683"");
+ 2\'b11 : $fwrite (fd,"" 684"");
+ endcase
+\t 4\'h2 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 685"");
+ 2\'b01 : $fwrite (fd,"" 686"");
+ 2\'b10 : $fwrite (fd,"" 687"");
+ 2\'b11 : $fwrite (fd,"" 688"");
+ endcase
+\t 4\'h3 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 689"");
+ 2\'b01 : $fwrite (fd,"" 690"");
+ 2\'b10 : $fwrite (fd,"" 691"");
+ 2\'b11 : $fwrite (fd,"" 692"");
+ endcase
+\t 4\'h4 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 693"");
+ 2\'b01 : $fwrite (fd,"" 694"");
+ 2\'b10 : $fwrite (fd,"" 695"");
+ 2\'b11 : $fwrite (fd,"" 696"");
+ endcase
+\t 4\'h5 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 697"");
+ 2\'b01 : $fwrite (fd,"" 698"");
+ 2\'b10 : $fwrite (fd,"" 699"");
+ 2\'b11 : $fwrite (fd,"" 700"");
+ endcase
+\t 4\'h6 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 701"");
+ 2\'b01 : $fwrite (fd,"" 702"");
+ 2\'b10 : $fwrite (fd,"" 703"");
+ 2\'b11 : $fwrite (fd,"" 704"");
+ endcase
+\t 4\'h7 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 705"");
+ 2\'b01 : $fwrite (fd,"" 706"");
+ 2\'b10 : $fwrite (fd,"" 707"");
+ 2\'b11 : $fwrite (fd,"" 708"");
+ endcase
+\t 4\'h8 :
+ if (foo[26])
+ $fwrite (fd,"" 709"");
+ else
+ $fwrite (fd,"" 710"");
+\t 4\'h9 :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 711"");
+ 2\'b01 : $fwrite (fd,"" 712"");
+ 2\'b10 : $fwrite (fd,"" 713"");
+ 2\'b11 : $fwrite (fd,"" 714"");
+ endcase
+\t 4\'ha :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 715"");
+ 2\'b01 : $fwrite (fd,"" 716"");
+ 2\'b10 : $fwrite (fd,"" 717"");
+ 2\'b11 : $fwrite (fd,"" 718"");
+ endcase
+\t 4\'hb :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 719"");
+ 2\'b01 : $fwrite (fd,"" 720"");
+ 2\'b10 : $fwrite (fd,"" 721"");
+ 2\'b11 : $fwrite (fd,"" 722"");
+ endcase
+\t 4\'hc :
+ if (foo[26])
+ $fwrite (fd,"" 723"");
+ else
+ $fwrite (fd,"" 724"");
+\t 4\'hd :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 725"");
+ 2\'b01 : $fwrite (fd,"" 726"");
+ 2\'b10 : $fwrite (fd,"" 727"");
+ 2\'b11 : $fwrite (fd,"" 728"");
+ endcase
+\t 4\'he :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 729"");
+ 2\'b01 : $fwrite (fd,"" 730"");
+ 2\'b10 : $fwrite (fd,"" 731"");
+ 2\'b11 : $fwrite (fd,"" 732"");
+ endcase
+\t 4\'hf :
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd,"" 733"");
+ 2\'b01 : $fwrite (fd,"" 734"");
+ 2\'b10 : $fwrite (fd,"" 735"");
+ 2\'b11 : $fwrite (fd,"" 736"");
+ endcase
+\t endcase
+ end
+ endtask
+
+ task ozonef2e;
+ input [ 31:0] foo;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t casez (foo[25:21])
+\t 5\'h00 :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 737"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 738"");
+\t end
+\t 5\'h01 :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 739"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 740"");
+\t end
+\t 5\'h02 :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 741"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 742"");
+\t end
+\t 5\'h03 :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 743"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 744"");
+\t end
+\t 5\'h04 :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 745"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 746"");
+\t end
+\t 5\'h05 :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 747"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 748"");
+\t end
+\t 5\'h06 :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 749"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 750"");
+\t end
+\t 5\'h07 :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 751"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 752"");
+\t end
+\t 5\'h08 :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 753"");
+\t\tif (foo[ 6])
+\t\t $fwrite (fd,"" 754"");
+\t\telse
+\t\t $fwrite (fd,"" 755"");
+\t end
+\t 5\'h09 :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 756"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 757"");
+\t end
+\t 5\'h0a :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 758"");
+\t\tozoneae(foo[17:15], fd);
+\t end
+\t 5\'h0b :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 759"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 760"");
+\t end
+\t 5\'h0c :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 761"");
+\t end
+\t 5\'h0d :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 762"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 763"");
+\t end
+\t 5\'h0e :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 764"");
+\t\tozoneae(foo[17:15], fd);
+\t end
+\t 5\'h0f :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 765"");
+\t\tozoneae(foo[17:15], fd);
+\t end
+\t 5\'h10 :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 766"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 767"");
+\t end
+\t 5\'h11 :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 768"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 769"");
+\t end
+\t 5\'h18 :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 770"");
+\t\tif (foo[ 6])
+\t\t $fwrite (fd,"" 771"");
+\t\telse
+\t\t $fwrite (fd,"" 772"");
+\t end
+\t 5\'h1a :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 773"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 774"");
+\t end
+\t 5\'h1b :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 775"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 776"");
+\t\tif (foo[ 6])
+\t\t $fwrite (fd,"" 777"");
+\t\telse
+\t\t $fwrite (fd,"" 778"");
+\t\t$fwrite (fd,"" 779"");
+\t end
+\t 5\'h1c :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 780"");
+\t end
+\t 5\'h1d :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 781"");
+\t\tif (foo[ 6])
+\t\t $fwrite (fd,"" 782"");
+\t\telse
+\t\t $fwrite (fd,"" 783"");
+\t\t$fwrite (fd,"" 784"");
+\t end
+\t 5\'h1e :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 785"");
+\t\tif (foo[ 6])
+\t\t $fwrite (fd,"" 786"");
+\t\telse
+\t\t $fwrite (fd,"" 787"");
+\t\t$fwrite (fd,"" 788"");
+\t end
+\t 5\'h1f :
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 789"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 790"");
+\t\tif (foo[ 6])
+\t\t $fwrite (fd,"" 791"");
+\t\telse
+\t\t $fwrite (fd,"" 792"");
+\t\t$fwrite (fd,"" 793"");
+\t end
+\t default :
+ $fwrite (fd,"" 794"");
+\t endcase
+ end
+ endtask
+
+ task ozonef3e;
+ input [ 31:0] foo;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (foo[25:21])
+\t 5\'h00,
+\t 5\'h01,
+\t 5\'h02:
+\t begin
+\t\t ozoneae(foo[20:18], fd);
+\t\t case (foo[22:21])
+\t\t 2\'h0: $fwrite (fd,"" 795"");
+\t\t 2\'h1: $fwrite (fd,"" 796"");
+\t\t 2\'h2: $fwrite (fd,"" 797"");
+\t\t endcase
+\t\t ozoneae(foo[17:15], fd);
+\t\t $fwrite (fd,"" 798"");
+\t\t if (foo[ 9])
+\t\t ozoneae(foo[ 8: 6], fd);
+\t\t else
+\t\t ozonef3e_te(foo[ 8: 6], fd);
+\t\t $fwrite (fd,"" 799"");
+\t end
+\t 5\'h08,
+\t 5\'h09,
+\t 5\'h0d,
+\t 5\'h0e,
+\t 5\'h0f:
+\t begin
+\t\t ozoneae(foo[20:18], fd);
+\t\t $fwrite (fd,"" 800"");
+\t\t ozoneae(foo[17:15], fd);
+\t\t case (foo[23:21])
+\t\t 3\'h0: $fwrite (fd,"" 801"");
+\t\t 3\'h1: $fwrite (fd,"" 802"");
+\t\t 3\'h5: $fwrite (fd,"" 803"");
+\t\t 3\'h6: $fwrite (fd,"" 804"");
+\t\t 3\'h7: $fwrite (fd,"" 805"");
+\t\t endcase
+\t\t if (foo[ 9])
+\t\t ozoneae(foo[ 8: 6], fd);
+\t\t else
+\t\t ozonef3e_te(foo[ 8: 6], fd);
+\t end
+\t 5\'h0a,
+\t 5\'h0b:
+\t begin
+\t\t ozoneae(foo[17:15], fd);
+\t\t if (foo[21])
+\t\t $fwrite (fd,"" 806"");
+\t\t else
+\t\t $fwrite (fd,"" 807"");
+\t\t if (foo[ 9])
+\t\t ozoneae(foo[ 8: 6], fd);
+\t\t else
+\t\t ozonef3e_te(foo[ 8: 6], fd);
+\t end
+\t 5\'h0c:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 808"");
+\t\tif (foo[ 9])
+\t\t ozoneae(foo[ 8: 6], fd);
+\t\telse
+\t\t ozonef3e_te(foo[ 8: 6], fd);
+\t\t$fwrite (fd,"" 809"");
+\t\tozoneae(foo[17:15], fd);
+\t end
+\t 5\'h10,
+\t 5\'h11,
+\t 5\'h12,
+\t 5\'h13:
+\t begin
+\t\t ozoneae(foo[20:18], fd);
+\t\t $fwrite (fd,"" 810"");
+\t\t ozoneae(foo[17:15], fd);
+\t\t case (foo[22:21])
+\t\t 2\'h0,
+\t\t 2\'h2:
+\t\t\t$fwrite (fd,"" 811"");
+\t\t 2\'h1,
+\t\t 2\'h3:
+\t\t\t$fwrite (fd,"" 812"");
+\t\t endcase
+\t\t ozoneae(foo[ 8: 6], fd);
+\t\t $fwrite (fd,"" 813"");
+\t\t ozoneae((foo[20:18]+1), fd);
+\t\t $fwrite (fd,"" 814"");
+\t\t ozoneae((foo[17:15]+1), fd);
+\t\t case (foo[22:21])
+\t\t 2\'h0,
+\t\t 2\'h3:
+\t\t\t$fwrite (fd,"" 815"");
+\t\t 2\'h1,
+\t\t 2\'h2:
+\t\t\t$fwrite (fd,"" 816"");
+\t\t endcase
+\t\t ozoneae((foo[ 8: 6]+1), fd);
+\t end
+\t 5\'h18:
+\t begin
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 817"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 818"");
+\t\tozoneae(foo[ 8: 6], fd);
+\t\t$fwrite (fd,"" 819"");
+\t\tozoneae(foo[20:18], fd);
+\t\t$fwrite (fd,"" 820"");
+\t\tozoneae(foo[17:15], fd);
+\t\t$fwrite (fd,"" 821"");
+\t\tozoneae(foo[ 8: 6], fd);
+\t end
+\t default :
+ $fwrite (fd,"" 822"");
+\t endcase
+ end
+ endtask
+ task ozonef3e_te;
+ input [ 2:0] te;
+ input [`FD_BITS] \tfd;
+ // verilator no_inline_task
+ begin
+\t case (te)
+\t 3\'b100 : $fwrite (fd, "" 823"");
+\t 3\'b101 : $fwrite (fd, "" 824"");
+\t 3\'b110 : $fwrite (fd, "" 825"");
+\t default: $fwrite (fd, "" 826"");
+\t endcase
+ end
+ endtask
+ task ozonearm;
+ input [ 2:0] ate;
+ input [`FD_BITS] \tfd;
+ // verilator no_inline_task
+ begin
+\t case (ate)
+\t 3\'b000 : $fwrite (fd, "" 827"");
+\t 3\'b001 : $fwrite (fd, "" 828"");
+\t 3\'b010 : $fwrite (fd, "" 829"");
+\t 3\'b011 : $fwrite (fd, "" 830"");
+\t 3\'b100 : $fwrite (fd, "" 831"");
+\t 3\'b101 : $fwrite (fd, "" 832"");
+\t 3\'b110 : $fwrite (fd, "" 833"");
+\t 3\'b111 : $fwrite (fd, "" 834"");
+\t endcase
+ end
+ endtask
+ task ozonebmuop;
+ input [ 4:0] f4;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (f4[ 4:0])
+\t 5\'h00,
+\t 5\'h04 :
+ $fwrite (fd, "" 835"");
+\t 5\'h01,
+\t 5\'h05 :
+ $fwrite (fd, "" 836"");
+\t 5\'h02,
+\t 5\'h06 :
+ $fwrite (fd, "" 837"");
+\t 5\'h03,
+\t 5\'h07 :
+ $fwrite (fd, "" 838"");
+\t 5\'h08,
+\t 5\'h18 :
+ $fwrite (fd, "" 839"");
+\t 5\'h09,
+\t 5\'h19 :
+ $fwrite (fd, "" 840"");
+\t 5\'h0a,
+\t 5\'h1a :
+ $fwrite (fd, "" 841"");
+\t 5\'h0b :
+ $fwrite (fd, "" 842"");
+\t 5\'h1b :
+ $fwrite (fd, "" 843"");
+\t 5\'h0c,
+\t 5\'h1c :
+ $fwrite (fd, "" 844"");
+\t 5\'h0d,
+\t 5\'h1d :
+ $fwrite (fd, "" 845"");
+\t 5\'h1e :
+ $fwrite (fd, "" 846"");
+\t endcase
+ end
+ endtask
+ task ozonef3;
+ input [ 31:0] foo;
+ input [`FD_BITS] fd;
+ reg \t\t nacho;
+ // verilator no_inline_task
+ begin : f3_body
+\t nacho = 1\'b0;
+\t case (foo[24:21])
+\t 4\'h0:
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd, "" 847"");
+ 2\'b01 : $fwrite (fd, "" 848"");
+ 2\'b10 : $fwrite (fd, "" 849"");
+ 2\'b11 : $fwrite (fd, "" 850"");
+ endcase
+\t 4\'h1:
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd, "" 851"");
+ 2\'b01 : $fwrite (fd, "" 852"");
+ 2\'b10 : $fwrite (fd, "" 853"");
+ 2\'b11 : $fwrite (fd, "" 854"");
+ endcase
+\t 4\'h2:
+ case (foo[26:25])
+ 2\'b00 : $fwrite (fd, "" 855"");
+ 2\'b01 : $fwrite (fd, "" 856"");
+ 2\'b10 : $fwrite (fd, "" 857"");
+ 2\'b11 : $fwrite (fd, "" 858"");
+ endcase
+\t 4\'h8,
+\t 4\'h9,
+\t 4\'hd,
+\t 4\'he,
+\t 4\'hf :
+ case (foo[26:25])
+\t\t 2\'b00 : $fwrite (fd, "" 859"");
+\t\t 2\'b01 : $fwrite (fd, "" 860"");
+\t\t 2\'b10 : $fwrite (fd, "" 861"");
+\t\t 2\'b11 : $fwrite (fd, "" 862"");
+ endcase
+\t 4\'ha,
+\t 4\'hb :
+ if (foo[25])
+\t\t $fwrite (fd, "" 863"");
+ else
+\t\t $fwrite (fd, "" 864"");
+\t 4\'hc :
+ if (foo[26])
+ $fwrite (fd, "" 865"");
+ else
+ $fwrite (fd, "" 866"");
+\t default :
+\t begin
+\t\t$fwrite (fd, "" 867"");
+\t\tnacho = 1\'b1;
+\t end
+\t endcase
+\t if (~nacho)
+\t begin
+\t case (foo[24:21])
+\t\t4\'h8 :
+\t\t $fwrite (fd, "" 868"");
+\t\t4\'h9 :
+\t\t $fwrite (fd, "" 869"");
+\t\t4\'ha,
+\t\t 4\'he :
+\t\t $fwrite (fd, "" 870"");
+\t\t4\'hb,
+\t\t 4\'hf :
+\t\t $fwrite (fd, "" 871"");
+\t\t4\'hd :
+\t\t $fwrite (fd, "" 872"");
+\t endcase
+\t if (foo[20])
+\t\tcase (foo[18:16])
+\t\t 3\'b000 : $fwrite (fd, "" 873"");
+\t\t 3\'b100 : $fwrite (fd, "" 874"");
+\t\t default: $fwrite (fd, "" 875"");
+\t\tendcase
+\t else
+\t\tozoneae(foo[18:16], fd);
+\t if (foo[24:21] === 4\'hc)
+\t\tif (foo[25])
+\t\t $fwrite (fd, "" 876"");
+\t\telse
+\t\t $fwrite (fd, "" 877"");
+\t case (foo[24:21])
+\t\t4\'h0,
+\t\t 4\'h1,
+\t\t 4\'h2:
+\t\t $fwrite (fd, "" 878"");
+\t endcase
+\t end
+ end
+ endtask
+ task ozonerx;
+ input [ 31:0] foo;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (foo[19:18])
+\t 2\'h0 : $fwrite (fd, "" 879"");
+\t 2\'h1 : $fwrite (fd, "" 880"");
+\t 2\'h2 : $fwrite (fd, "" 881"");
+\t 2\'h3 : $fwrite (fd, "" 882"");
+\t endcase
+\t case (foo[17:16])
+\t 2\'h1 : $fwrite (fd, "" 883"");
+\t 2\'h2 : $fwrite (fd, "" 884"");
+\t 2\'h3 : $fwrite (fd, "" 885"");
+\t endcase
+ end
+ endtask
+ task ozonerme;
+ input [ 2:0] rme;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (rme)
+\t 3\'h0 : $fwrite (fd, "" 886"");
+\t 3\'h1 : $fwrite (fd, "" 887"");
+\t 3\'h2 : $fwrite (fd, "" 888"");
+\t 3\'h3 : $fwrite (fd, "" 889"");
+\t 3\'h4 : $fwrite (fd, "" 890"");
+\t 3\'h5 : $fwrite (fd, "" 891"");
+\t 3\'h6 : $fwrite (fd, "" 892"");
+\t 3\'h7 : $fwrite (fd, "" 893"");
+\t endcase
+ end
+ endtask
+ task ozoneye;
+ input [5:0] ye;
+ input \t l;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t $fwrite (fd, "" 894"");
+\t ozonerme(ye[5:3], fd);
+\t case ({ye[ 2:0], l})
+\t 4\'h2,
+\t 4\'ha: $fwrite (fd, "" 895"");
+\t 4\'h4,
+\t 4\'hb: $fwrite (fd, "" 896"");
+\t 4\'h6,
+\t 4\'he: $fwrite (fd, "" 897"");
+\t 4\'h8,
+\t 4\'hc: $fwrite (fd, "" 898"");
+\t endcase
+ end
+ endtask
+ task ozonef1e_ye;
+ input [5:0] ye;
+ input \t l;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t $fwrite (fd, "" 899"");
+\t ozonerme(ye[5:3], fd);
+\t ozonef1e_inc_dec(ye[5:0], l , fd);
+ end
+ endtask
+ task ozonef1e_h;
+ input [ 2:0] e;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t if (e[ 2:0] <= 3\'h4)
+\t $fwrite (fd, "" 900"");
+ end
+ endtask
+ task ozonef1e_inc_dec;
+ input [5:0] ye;
+ input \t l;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case ({ye[ 2:0], l})
+\t 4\'h2,
+\t 4\'h3,
+\t 4\'ha: $fwrite (fd, "" 901"");
+\t 4\'h4,
+\t 4\'h5,
+\t 4\'hb: $fwrite (fd, "" 902"");
+\t 4\'h6,
+\t 4\'h7,
+\t 4\'he: $fwrite (fd, "" 903"");
+\t 4\'h8,
+\t 4\'h9,
+\t 4\'hc: $fwrite (fd, "" 904"");
+\t 4\'hf: $fwrite (fd, "" 905"");
+\t endcase
+ end
+ endtask
+ task ozonef1e_hl;
+ input [ 2:0] e;
+ input l;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case ({e[ 2:0], l})
+\t 4\'h0,
+\t 4\'h2,
+\t 4\'h4,
+\t 4\'h6,
+\t 4\'h8: $fwrite (fd, "" 906"");
+\t 4\'h1,
+\t 4\'h3,
+\t 4\'h5,
+\t 4\'h7,
+\t 4\'h9: $fwrite (fd, "" 907"");
+\t endcase
+ end
+ endtask
+ task ozonexe;
+ input [ 3:0] xe;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (xe[3])
+\t 1\'b0 : $fwrite (fd, "" 908"");
+\t 1\'b1 : $fwrite (fd, "" 909"");
+\t endcase
+\t case (xe[ 2:0])
+\t 3\'h1,
+\t 3\'h5: $fwrite (fd, "" 910"");
+\t 3\'h2,
+\t 3\'h6: $fwrite (fd, "" 911"");
+\t 3\'h3,
+\t 3\'h7: $fwrite (fd, "" 912"");
+\t 3\'h4: $fwrite (fd, "" 913"");
+\t endcase
+ end
+ endtask
+ task ozonerp;
+ input [ 2:0] rp;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (rp)
+\t 3\'h0 : $fwrite (fd, "" 914"");
+\t 3\'h1 : $fwrite (fd, "" 915"");
+\t 3\'h2 : $fwrite (fd, "" 916"");
+\t 3\'h3 : $fwrite (fd, "" 917"");
+\t 3\'h4 : $fwrite (fd, "" 918"");
+\t 3\'h5 : $fwrite (fd, "" 919"");
+\t 3\'h6 : $fwrite (fd, "" 920"");
+\t 3\'h7 : $fwrite (fd, "" 921"");
+\t endcase
+ end
+ endtask
+ task ozonery;
+ input [ 3:0] ry;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (ry)
+\t 4\'h0 : $fwrite (fd, "" 922"");
+\t 4\'h1 : $fwrite (fd, "" 923"");
+\t 4\'h2 : $fwrite (fd, "" 924"");
+\t 4\'h3 : $fwrite (fd, "" 925"");
+\t 4\'h4 : $fwrite (fd, "" 926"");
+\t 4\'h5 : $fwrite (fd, "" 927"");
+\t 4\'h6 : $fwrite (fd, "" 928"");
+\t 4\'h7 : $fwrite (fd, "" 929"");
+\t 4\'h8 : $fwrite (fd, "" 930"");
+\t 4\'h9 : $fwrite (fd, "" 931"");
+\t 4\'ha : $fwrite (fd, "" 932"");
+\t 4\'hb : $fwrite (fd, "" 933"");
+\t 4\'hc : $fwrite (fd, "" 934"");
+\t 4\'hd : $fwrite (fd, "" 935"");
+\t 4\'he : $fwrite (fd, "" 936"");
+\t 4\'hf : $fwrite (fd, "" 937"");
+\t endcase
+ end
+ endtask
+ task ozonearx;
+ input [ 15:0] foo;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (foo[1:0])
+\t 2\'h0 : $fwrite (fd, "" 938"");
+\t 2\'h1 : $fwrite (fd, "" 939"");
+\t 2\'h2 : $fwrite (fd, "" 940"");
+\t 2\'h3 : $fwrite (fd, "" 941"");
+\t endcase
+ end
+ endtask
+ task ozonef3f4imop;
+ input [ 4:0] f3f4iml;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t casez (f3f4iml)
+\t 5\'b000??: $fwrite (fd, "" 942"");
+\t 5\'b001??: $fwrite (fd, "" 943"");
+\t 5\'b?10??: $fwrite (fd, "" 944"");
+\t 5\'b0110?: $fwrite (fd, "" 945"");
+\t 5\'b01110: $fwrite (fd, "" 946"");
+\t 5\'b01111: $fwrite (fd, "" 947"");
+\t 5\'b10???: $fwrite (fd, "" 948"");
+\t 5\'b11100: $fwrite (fd, "" 949"");
+\t 5\'b11101: $fwrite (fd, "" 950"");
+\t 5\'b11110: $fwrite (fd, "" 951"");
+\t 5\'b11111: $fwrite (fd, "" 952"");
+\t endcase
+ end
+ endtask
+ task ozonecon;
+ input [ 4:0] con;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (con)
+\t 5\'h00 : $fwrite (fd, "" 953"");
+\t 5\'h01 : $fwrite (fd, "" 954"");
+\t 5\'h02 : $fwrite (fd, "" 955"");
+\t 5\'h03 : $fwrite (fd, "" 956"");
+\t 5\'h04 : $fwrite (fd, "" 957"");
+\t 5\'h05 : $fwrite (fd, "" 958"");
+\t 5\'h06 : $fwrite (fd, "" 959"");
+\t 5\'h07 : $fwrite (fd, "" 960"");
+\t 5\'h08 : $fwrite (fd, "" 961"");
+\t 5\'h09 : $fwrite (fd, "" 962"");
+\t 5\'h0a : $fwrite (fd, "" 963"");
+\t 5\'h0b : $fwrite (fd, "" 964"");
+\t 5\'h0c : $fwrite (fd, "" 965"");
+\t 5\'h0d : $fwrite (fd, "" 966"");
+\t 5\'h0e : $fwrite (fd, "" 967"");
+\t 5\'h0f : $fwrite (fd, "" 968"");
+\t 5\'h10 : $fwrite (fd, "" 969"");
+\t 5\'h11 : $fwrite (fd, "" 970"");
+\t 5\'h12 : $fwrite (fd, "" 971"");
+\t 5\'h13 : $fwrite (fd, "" 972"");
+\t 5\'h14 : $fwrite (fd, "" 973"");
+\t 5\'h15 : $fwrite (fd, "" 974"");
+\t 5\'h16 : $fwrite (fd, "" 975"");
+\t 5\'h17 : $fwrite (fd, "" 976"");
+\t 5\'h18 : $fwrite (fd, "" 977"");
+\t 5\'h19 : $fwrite (fd, "" 978"");
+\t 5\'h1a : $fwrite (fd, "" 979"");
+\t 5\'h1b : $fwrite (fd, "" 980"");
+\t 5\'h1c : $fwrite (fd, "" 981"");
+\t 5\'h1d : $fwrite (fd, "" 982"");
+\t 5\'h1e : $fwrite (fd, "" 983"");
+\t 5\'h1f : $fwrite (fd, "" 984"");
+\t endcase
+ end
+ endtask
+ task ozonedr;
+ input [ 15:0] foo;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (foo[ 9: 6])
+\t 4\'h0 : $fwrite (fd, "" 985"");
+\t 4\'h1 : $fwrite (fd, "" 986"");
+\t 4\'h2 : $fwrite (fd, "" 987"");
+\t 4\'h3 : $fwrite (fd, "" 988"");
+\t 4\'h4 : $fwrite (fd, "" 989"");
+\t 4\'h5 : $fwrite (fd, "" 990"");
+\t 4\'h6 : $fwrite (fd, "" 991"");
+\t 4\'h7 : $fwrite (fd, "" 992"");
+\t 4\'h8 : $fwrite (fd, "" 993"");
+\t 4\'h9 : $fwrite (fd, "" 994"");
+\t 4\'ha : $fwrite (fd, "" 995"");
+\t 4\'hb : $fwrite (fd, "" 996"");
+\t 4\'hc : $fwrite (fd, "" 997"");
+\t 4\'hd : $fwrite (fd, "" 998"");
+\t 4\'he : $fwrite (fd, "" 999"");
+\t 4\'hf : $fwrite (fd, "" 1000"");
+\t endcase
+ end
+ endtask
+ task ozoneshift;
+ input [ 15:0] foo;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (foo[ 4: 3])
+\t 2\'h0 : $fwrite (fd, "" 1001"");
+\t 2\'h1 : $fwrite (fd, "" 1002"");
+\t 2\'h2 : $fwrite (fd, "" 1003"");
+\t 2\'h3 : $fwrite (fd, "" 1004"");
+\t endcase
+ end
+ endtask
+ task ozoneacc;
+ input foo;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (foo)
+\t 2\'h0 : $fwrite (fd, "" 1005"");
+\t 2\'h1 : $fwrite (fd, "" 1006"");
+\t endcase
+ end
+ endtask
+ task ozonehl;
+ input foo;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ begin
+\t case (foo)
+\t 2\'h0 : $fwrite (fd, "" 1007"");
+\t 2\'h1 : $fwrite (fd, "" 1008"");
+\t endcase
+ end
+ endtask
+ task dude;
+ input [`FD_BITS] fd;
+ // verilator no_inline_task
+ $fwrite(fd,"" dude"");
+ endtask
+
+ task big_case;
+ input [ `FD_BITS] fd;
+ input [ 31:0] foo;
+ // verilator no_inline_task
+ begin
+\t $fwrite(fd,"" 1009"");
+\t if (&foo === 1\'bx)
+\t $fwrite(fd, "" 1010"");
+\t else
+\t casez ( {foo[31:26], foo[19:15], foo[5:0]} )
+ 17\'b00_111?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, fd);
+\t\t $fwrite (fd, "" 1011"");
+\t\t ozoneacc(~foo[26], fd);
+\t\t ozonehl(foo[20], fd);
+\t\t $fwrite (fd, "" 1012"");
+\t\t ozonerx(foo, fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1013"");
+ end
+ 17\'b01_001?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, fd);
+\t\t $fwrite (fd, "" 1014"");
+\t\t ozonerx(foo, fd);
+\t\t $fwrite (fd, "" 1015"");
+\t\t $fwrite (fd, "" 1016:%x"", foo[20]);
+\t\t ozonehl(foo[20], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1017"");
+ end
+ 17\'b10_100?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, fd);
+\t\t $fwrite (fd, "" 1018"");
+\t\t ozonerx(foo, fd);
+\t\t $fwrite (fd, "" 1019"");
+\t\t $fwrite (fd, "" 1020"");
+\t\t ozonehl(foo[20], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1021"");
+ end
+ 17\'b10_101?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, fd);
+\t\t $fwrite (fd, "" 1022"");
+\t\t if (foo[20])
+\t\t begin
+\t\t $fwrite (fd, "" 1023"");
+\t\t ozoneacc(foo[18], fd);
+\t\t $fwrite (fd, "" 1024"");
+\t\t $fwrite (fd, "" 1025"");
+\t\t if (foo[19])
+\t\t\t $fwrite (fd, "" 1026"");
+\t\t else
+\t\t\t $fwrite (fd, "" 1027"");
+\t\t end
+\t\t else
+\t\t ozonerx(foo, fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1028"");
+ end
+ 17\'b10_110?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, fd);
+\t\t $fwrite (fd, "" 1029"");
+\t\t $fwrite (fd, "" 1030"");
+\t\t ozonehl(foo[20], fd);
+\t\t $fwrite (fd, "" 1031"");
+\t\t ozonerx(foo, fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1032"");
+ end
+ 17\'b10_111?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, fd);
+\t\t $fwrite (fd, "" 1033"");
+\t\t $fwrite (fd, "" 1034"");
+\t\t ozonehl(foo[20], fd);
+\t\t $fwrite (fd, "" 1035"");
+\t\t ozonerx(foo, fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1036"");
+ end
+ 17\'b11_001?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, fd);
+\t\t $fwrite (fd, "" 1037"");
+\t\t ozonerx(foo, fd);
+\t\t $fwrite (fd, "" 1038"");
+\t\t $fwrite (fd, "" 1039"");
+\t\t ozonehl(foo[20], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1040"");
+ end
+ 17\'b11_111?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, fd);
+\t\t $fwrite (fd, "" 1041"");
+\t\t $fwrite (fd, "" 1042"");
+\t\t ozonerx(foo, fd);
+\t\t $fwrite (fd, "" 1043"");
+\t\t if (foo[20])
+\t\t $fwrite (fd, "" 1044"");
+\t\t else
+\t\t $fwrite (fd, "" 1045"");
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1046"");
+ end
+ 17\'b00_10??_?_????_?1_1111 :
+ casez (foo[11: 5])
+\t\t 7\'b??_0_010_0:
+\t\t begin
+\t\t $fwrite (fd, "" 1047"");
+\t\t ozonecon(foo[14:10], fd);
+\t\t $fwrite (fd, "" 1048"");
+\t\t ozonef1e(foo, fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1049"");
+\t\t end
+\t\t 7\'b00_?_110_?:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1050"");
+\t\t case ({foo[ 9],foo[ 5]})
+\t\t\t2\'b00:
+\t\t\t begin
+\t\t\t $fwrite (fd, "" 1051"");
+\t\t\t ozoneae(foo[14:12], fd);
+\t\t\t ozonehl(foo[ 5], fd);
+\t\t\t end
+\t\t\t2\'b01:
+\t\t\t begin
+\t\t\t $fwrite (fd, "" 1052"");
+\t\t\t ozoneae(foo[14:12], fd);
+\t\t\t ozonehl(foo[ 5], fd);
+\t\t\t end
+\t\t\t2\'b10:
+\t\t\t begin
+\t\t\t $fwrite (fd, "" 1053"");
+\t\t\t ozoneae(foo[14:12], fd);
+\t\t\t end
+\t\t\t2\'b11: $fwrite (fd, "" 1054"");
+\t\t endcase
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1055"");
+\t\t end
+\t\t 7\'b01_?_110_?:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1056"");
+\t\t case ({foo[ 9],foo[ 5]})
+\t\t\t2\'b00:
+\t\t\t begin
+\t\t\t ozoneae(foo[14:12], fd);
+\t\t\t ozonehl(foo[ 5], fd);
+\t\t\t $fwrite (fd, "" 1057"");
+\t\t\t end
+\t\t\t2\'b01:
+\t\t\t begin
+\t\t\t ozoneae(foo[14:12], fd);
+\t\t\t ozonehl(foo[ 5], fd);
+\t\t\t $fwrite (fd, "" 1058"");
+\t\t\t end
+\t\t\t2\'b10:
+\t\t\t begin
+\t\t\t ozoneae(foo[14:12], fd);
+\t\t\t $fwrite (fd, "" 1059"");
+\t\t\t end
+\t\t\t2\'b11: $fwrite (fd, "" 1060"");
+\t\t endcase
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1061"");
+\t\t end
+\t\t 7\'b10_0_110_0:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1062"");
+\t\t $fwrite (fd, "" 1063"");
+\t\t if (foo[12])
+\t\t\t$fwrite (fd, "" 1064"");
+\t\t else
+\t\t\tozonerab({4\'b1001, foo[14:12]}, fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1065"");
+\t\t end
+\t\t 7\'b10_0_110_1:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1066"");
+\t\t if (foo[12])
+\t\t\t$fwrite (fd, "" 1067"");
+\t\t else
+\t\t\tozonerab({4\'b1001, foo[14:12]}, fd);
+\t\t $fwrite (fd, "" 1068"");
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1069"");
+\t\t end
+\t\t 7\'b??_?_000_?:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1070"");
+\t\t $fwrite (fd, "" 1071"");
+\t\t ozonef1e_hl(foo[11:9],foo[ 5], fd);
+\t\t $fwrite (fd, "" 1072"");
+\t\t ozonef1e_ye(foo[14:9],foo[ 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1073"");
+\t\t end
+\t\t 7\'b??_?_100_?:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1074"");
+\t\t $fwrite (fd, "" 1075"");
+\t\t ozonef1e_hl(foo[11:9],foo[ 5], fd);
+\t\t $fwrite (fd, "" 1076"");
+\t\t ozonef1e_ye(foo[14:9],foo[ 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1077"");
+\t\t end
+\t\t 7\'b??_?_001_?:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1078"");
+\t\t ozonef1e_ye(foo[14:9],foo[ 5], fd);
+\t\t $fwrite (fd, "" 1079"");
+\t\t $fwrite (fd, "" 1080"");
+\t\t ozonef1e_hl(foo[11:9],foo[ 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1081"");
+\t\t end
+\t\t 7\'b??_?_011_?:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1082"");
+\t\t ozonef1e_ye(foo[14:9],foo[ 5], fd);
+\t\t $fwrite (fd, "" 1083"");
+\t\t $fwrite (fd, "" 1084"");
+\t\t ozonef1e_hl(foo[11:9],foo[ 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1085"");
+\t\t end
+\t\t 7\'b??_?_101_?:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1086"");
+\t\t ozonef1e_ye(foo[14:9],foo[ 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1087"");
+\t\t end
+ endcase
+ 17\'b00_10??_?_????_?0_0110 :
+ begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1088"");
+\t\t ozoneae(foo[ 8: 6], fd);
+\t\t ozonef1e_hl(foo[11:9],foo[ 5], fd);
+\t\t $fwrite (fd, "" 1089"");
+\t\t ozonef1e_ye(foo[14:9],foo[ 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1090"");
+ end
+ 17\'b00_10??_?_????_00_0111 :
+ begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1091"");
+\t\t if (foo[ 6])
+\t\t $fwrite (fd, "" 1092"");
+\t\t else
+\t\t ozonerab({4\'b1001, foo[ 8: 6]}, fd);
+\t\t $fwrite (fd, "" 1093"");
+\t\t $fwrite (fd, "" 1094"");
+\t\t ozonerme(foo[14:12], fd);
+\t\t case (foo[11: 9])
+\t\t 3\'h2,
+\t\t 3\'h5,
+\t\t 3\'h6,
+\t\t 3\'h7:
+\t\t\tozonef1e_inc_dec(foo[14:9],1\'b0, fd);
+\t\t 3\'h1,
+\t\t 3\'h3,
+\t\t 3\'h4:
+\t\t\t$fwrite (fd, "" 1095"");
+\t\t endcase
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1096"");
+ end
+ 17\'b00_10??_?_????_?0_0100 :
+ begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1097"");
+\t\t ozonef1e_ye(foo[14:9],foo[ 5], fd);
+\t\t $fwrite (fd, "" 1098"");
+\t\t ozoneae(foo[ 8: 6], fd);
+\t\t ozonef1e_hl(foo[11:9],foo[ 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1099"");
+ end
+ 17\'b00_10??_?_????_10_0111 :
+ begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1100"");
+\t\t $fwrite (fd, "" 1101"");
+\t\t ozonerme(foo[14:12], fd);
+\t\t case (foo[11: 9])
+\t\t 3\'h2,
+\t\t 3\'h5,
+\t\t 3\'h6,
+\t\t 3\'h7:
+\t\t\tozonef1e_inc_dec(foo[14:9],1\'b0, fd);
+\t\t 3\'h1,
+\t\t 3\'h3,
+\t\t 3\'h4:
+\t\t\t$fwrite (fd, "" 1102"");
+\t\t endcase
+\t\t $fwrite (fd, "" 1103"");
+\t\t if (foo[ 6])
+\t\t $fwrite (fd, "" 1104"");
+\t\t else
+\t\t ozonerab({4\'b1001, foo[ 8: 6]}, fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1105"");
+ end
+ 17\'b00_10??_?_????_?0_1110 :
+ begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1106"");
+\t\t case (foo[11:9])
+\t\t 3\'h2:
+\t\t begin
+\t\t\t $fwrite (fd, "" 1107"");
+\t\t\t if (foo[14:12] == 3\'h0)
+\t\t\t $fwrite (fd, "" 1108"");
+\t\t\t else
+\t\t\t ozonerme(foo[14:12], fd);
+\t\t\t $fwrite (fd, "" 1109"");
+\t\t end
+\t\t 3\'h6:
+\t\t begin
+\t\t\t $fwrite (fd, "" 1110"");
+\t\t\t if (foo[14:12] == 3\'h0)
+\t\t\t $fwrite (fd, "" 1111"");
+\t\t\t else
+\t\t\t ozonerme(foo[14:12], fd);
+\t\t\t $fwrite (fd, "" 1112"");
+\t\t end
+\t\t 3\'h0:
+\t\t begin
+\t\t\t $fwrite (fd, "" 1113"");
+\t\t\t if (foo[14:12] == 3\'h0)
+\t\t\t $fwrite (fd, "" 1114"");
+\t\t\t else
+\t\t\t ozonerme(foo[14:12], fd);
+\t\t\t $fwrite (fd, "" 1115"");
+\t\t\t if (foo[ 7: 5] >= 3\'h5)
+\t\t\t $fwrite (fd, "" 1116"");
+\t\t\t else
+\t\t\t ozonexe(foo[ 8: 5], fd);
+\t\t end
+\t\t 3\'h1:
+\t\t begin
+\t\t\t $fwrite (fd, "" 1117"");
+\t\t\t if (foo[14:12] == 3\'h0)
+\t\t\t $fwrite (fd, "" 1118"");
+\t\t\t else
+\t\t\t ozonerme(foo[14:12], fd);
+\t\t\t $fwrite (fd, "" 1119"");
+\t\t\t if (foo[ 7: 5] >= 3\'h5)
+\t\t\t $fwrite (fd, "" 1120"");
+\t\t\t else
+\t\t\t ozonexe(foo[ 8: 5], fd);
+\t\t end
+\t\t 3\'h4:
+\t\t begin
+\t\t\t $fwrite (fd, "" 1121"");
+\t\t\t if (foo[14:12] == 3\'h0)
+\t\t\t $fwrite (fd, "" 1122"");
+\t\t\t else
+\t\t\t ozonerme(foo[14:12], fd);
+\t\t\t $fwrite (fd, "" 1123"");
+\t\t\t if (foo[ 7: 5] >= 3\'h5)
+\t\t\t $fwrite (fd, "" 1124"");
+\t\t\t else
+\t\t\t ozonexe(foo[ 8: 5], fd);
+\t\t end
+\t\t 3\'h5:
+\t\t begin
+\t\t\t $fwrite (fd, "" 1125"");
+\t\t\t if (foo[14:12] == 3\'h0)
+\t\t\t $fwrite (fd, "" 1126"");
+\t\t\t else
+\t\t\t ozonerme(foo[14:12], fd);
+\t\t\t $fwrite (fd, "" 1127"");
+\t\t\t if (foo[ 7: 5] >= 3\'h5)
+\t\t\t $fwrite (fd, "" 1128"");
+\t\t\t else
+\t\t\t ozonexe(foo[ 8: 5], fd);
+\t\t end
+\t\t endcase
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1129"");
+ end
+ 17\'b00_10??_?_????_?0_1111 :
+ casez (foo[14: 9])
+\t\t 6\'b001_10_?:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1130"");
+\t\t $fwrite (fd, "" 1131"");
+\t\t ozonef1e_hl(foo[ 7: 5],foo[ 9], fd);
+\t\t $fwrite (fd, "" 1132"");
+\t\t ozonexe(foo[ 8: 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1133"");
+\t\t end
+\t\t 6\'b???_11_?:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1134"");
+\t\t ozoneae(foo[14:12], fd);
+\t\t ozonef1e_hl(foo[ 7: 5],foo[ 9], fd);
+\t\t $fwrite (fd, "" 1135"");
+\t\t ozonexe(foo[ 8: 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1136"");
+\t\t end
+\t\t 6\'b000_10_1,
+\t\t 6\'b010_10_1,
+\t\t 6\'b100_10_1,
+\t\t 6\'b110_10_1:
+\t\t begin
+\t\t\tozonef1e(foo, fd);
+\t\t\t$fwrite (fd, "" 1137"");
+\t\t\tozonerab({4\'b1001, foo[14:12]}, fd);
+\t\t\t$fwrite (fd, "" 1138"");
+\t\t\tif ((foo[ 7: 5] >= 3\'h1) & (foo[ 7: 5] <= 3\'h3))
+\t\t\t $fwrite (fd, "" 1139"");
+\t\t\telse
+\t\t\t ozonexe(foo[ 8: 5], fd);
+\t\t\tdude(fd);
+\t\t\t$fwrite (fd, "" 1140"");
+\t\t end
+\t\t 6\'b000_10_0,
+\t\t 6\'b010_10_0,
+\t\t 6\'b100_10_0,
+\t\t 6\'b110_10_0:
+\t\t begin
+\t\t\tozonef1e(foo, fd);
+\t\t\t$fwrite (fd, "" 1141"");
+\t\t\t$fwrite (fd, "" 1142"");
+\t\t\tozonerab({4\'b1001, foo[14:12]}, fd);
+\t\t\t$fwrite (fd, "" 1143"");
+\t\t\t$fwrite (fd, "" 1144"");
+\t\t\tozonef1e_h(foo[ 7: 5], fd);
+\t\t\t$fwrite (fd, "" 1145"");
+\t\t\tozonexe(foo[ 8: 5], fd);
+\t\t\tdude(fd);
+\t\t\t$fwrite (fd, "" 1146"");
+\t\t end
+\t\t 6\'b???_00_?:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1147"");
+\t\t if (foo[ 9])
+\t\t\tbegin
+\t\t\t $fwrite (fd, "" 1148"");
+\t\t\t ozoneae(foo[14:12], fd);
+\t\t\tend
+\t\t else
+\t\t\tbegin
+\t\t\t $fwrite (fd, "" 1149"");
+\t\t\t ozoneae(foo[14:12], fd);
+\t\t\t $fwrite (fd, "" 1150"");
+\t\t\tend
+\t\t $fwrite (fd, "" 1151"");
+\t\t $fwrite (fd, "" 1152"");
+\t\t ozonef1e_h(foo[ 7: 5], fd);
+\t\t $fwrite (fd, "" 1153"");
+\t\t ozonexe(foo[ 8: 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1154"");
+\t\t end
+\t\t 6\'b???_01_?:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1155"");
+\t\t ozoneae(foo[14:12], fd);
+\t\t if (foo[ 9])
+\t\t\t$fwrite (fd, "" 1156"");
+\t\t else
+\t\t\t$fwrite (fd, "" 1157"");
+\t\t $fwrite (fd, "" 1158"");
+\t\t $fwrite (fd, "" 1159"");
+\t\t ozonef1e_h(foo[ 7: 5], fd);
+\t\t $fwrite (fd, "" 1160"");
+\t\t ozonexe(foo[ 8: 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1161"");
+\t\t end
+\t\t 6\'b011_'b'10_0:
+\t\t begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1162"");
+\t\t case (foo[ 8: 5])
+\t\t\t4\'h0: $fwrite (fd, "" 1163"");
+\t\t\t4\'h1: $fwrite (fd, "" 1164"");
+\t\t\t4\'h2: $fwrite (fd, "" 1165"");
+\t\t\t4\'h3: $fwrite (fd, "" 1166"");
+\t\t\t4\'h4: $fwrite (fd, "" 1167"");
+\t\t\t4\'h5: $fwrite (fd, "" 1168"");
+\t\t\t4\'h8: $fwrite (fd, "" 1169"");
+\t\t\t4\'h9: $fwrite (fd, "" 1170"");
+\t\t\t4\'ha: $fwrite (fd, "" 1171"");
+\t\t\t4\'hb: $fwrite (fd, "" 1172"");
+\t\t\t4\'hc: $fwrite (fd, "" 1173"");
+\t\t\t4\'hd: $fwrite (fd, "" 1174"");
+\t\t\tdefault: $fwrite (fd, "" 1175"");
+\t\t endcase
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1176"");
+\t\t end
+\t\t default: $fwrite (fd, "" 1177"");
+ endcase
+ 17\'b00_10??_?_????_?0_110? :
+ begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1178"");
+\t\t $fwrite (fd, "" 1179"");
+\t\t ozonef1e_hl(foo[11:9], foo[0], fd);
+\t\t $fwrite (fd, "" 1180"");
+\t\t ozonef1e_ye(foo[14:9],1\'b0, fd);
+\t\t $fwrite (fd, "" 1181"");
+\t\t ozonef1e_h(foo[ 7: 5], fd);
+\t\t $fwrite (fd, "" 1182"");
+\t\t ozonexe(foo[ 8: 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1183"");
+ end
+ 17\'b00_10??_?_????_?1_110? :
+ begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1184"");
+\t\t $fwrite (fd, "" 1185"");
+\t\t ozonef1e_hl(foo[11:9],foo[0], fd);
+\t\t $fwrite (fd, "" 1186"");
+\t\t ozonef1e_ye(foo[14:9],foo[ 0], fd);
+\t\t $fwrite (fd, "" 1187"");
+\t\t $fwrite (fd, "" 1188"");
+\t\t ozonef1e_h(foo[ 7: 5], fd);
+\t\t $fwrite (fd, "" 1189"");
+\t\t ozonexe(foo[ 8: 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1190"");
+ end
+ 17\'b00_10??_?_????_?0_101? :
+ begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1191"");
+\t\t ozonef1e_ye(foo[14:9],foo[ 0], fd);
+\t\t $fwrite (fd, "" 1192"");
+\t\t $fwrite (fd, "" 1193"");
+\t\t ozonef1e_hl(foo[11:9],foo[0], fd);
+\t\t $fwrite (fd, "" 1194"");
+\t\t $fwrite (fd, "" 1195"");
+\t\t ozonef1e_h(foo[ 7: 5], fd);
+\t\t $fwrite (fd, "" 1196"");
+\t\t ozonexe(foo[ 8: 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1197"");
+ end
+ 17\'b00_10??_?_????_?0_1001 :
+ begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1198"");
+\t\t $fwrite (fd, "" 1199"");
+\t\t ozonef1e_h(foo[11:9], fd);
+\t\t $fwrite (fd, "" 1200"");
+\t\t ozonef1e_ye(foo[14:9],1\'b0, fd);
+\t\t $fwrite (fd, "" 1201"");
+\t\t case (foo[ 7: 5])
+\t\t 3\'h1,
+\t\t 3\'h2,
+\t\t 3\'h3:
+\t\t\t$fwrite (fd, "" 1202"");
+\t\t default:
+\t\t begin
+\t\t\t $fwrite (fd, "" 1203"");
+\t\t\t $fwrite (fd, "" 1204"");
+\t\t\t ozonexe(foo[ 8: 5], fd);
+\t\t end
+\t\t endcase
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1205"");
+ end
+ 17\'b00_10??_?_????_?0_0101 :
+ begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1206"");
+\t\t case (foo[11: 9])
+\t\t 3\'h1,
+\t\t 3\'h3,
+\t\t 3\'h4:
+\t\t\t$fwrite (fd, "" 1207"");
+\t\t default:
+\t\t begin
+\t\t\t ozonef1e_ye(foo[14:9],1\'b0, fd);
+\t\t\t $fwrite (fd, "" 1208"");
+\t\t\t $fwrite (fd, "" 1209"");
+\t\t end
+\t\t endcase
+\t\t $fwrite (fd, "" 1210"");
+\t\t $fwrite (fd, "" 1211"");
+\t\t ozonef1e_h(foo[ 7: 5], fd);
+\t\t $fwrite (fd, "" 1212"");
+\t\t ozonexe(foo[ 8: 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1213"");
+ end
+ 17\'b00_10??_?_????_?1_1110 :
+ begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1214"");
+\t\t ozonef1e_ye(foo[14:9],1\'b0, fd);
+\t\t $fwrite (fd, "" 1215"");
+\t\t $fwrite (fd, "" 1216"");
+\t\t ozonef1e_h(foo[11: 9], fd);
+\t\t $fwrite (fd, "" 1217"");
+\t\t $fwrite (fd, "" 1218"");
+\t\t ozonef1e_h(foo[ 7: 5], fd);
+\t\t $fwrite (fd, "" 1219"");
+\t\t ozonexe(foo[ 8: 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1220"");
+ end
+ 17\'b00_10??_?_????_?0_1000 :
+ begin
+\t\t ozonef1e(foo, fd);
+\t\t $fwrite (fd, "" 1221"");
+\t\t ozonef1e_ye(foo[14:9],1\'b0, fd);
+\t\t $fwrite (fd, "" 1222"");
+\t\t $fwrite (fd, "" 1223"");
+\t\t ozonef1e_h(foo[11: 9], fd);
+\t\t $fwrite (fd, "" 1224"");
+\t\t $fwrite (fd, "" 1225"");
+\t\t ozonef1e_h(foo[ 7: 5], fd);
+\t\t $fwrite (fd, "" 1226"");
+\t\t ozonexe(foo[ 8: 5], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1227"");
+ end
+ 17\'b10_01??_?_????_??_???? :
+ begin
+\t\t if (foo[27])
+\t\t $fwrite (fd,"" 1228"");
+\t\t else
+\t\t $fwrite (fd,"" 1229"");
+\t\t ozonecon(foo[20:16], fd);
+\t\t $fwrite (fd, "" 1230"");
+\t\t ozonef2(foo[31:0], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1231"");
+ end
+ 17\'b00_1000_?_????_01_0011 :
+ if (~|foo[ 9: 8])
+\t\t begin
+\t\t if (foo[ 7])
+\t\t $fwrite (fd,"" 1232"");
+\t\t else
+\t\t $fwrite (fd,"" 1233"");
+\t\t ozonecon(foo[14:10], fd);
+\t\t $fwrite (fd, "" 1234"");
+\t\t ozonef2e(foo[31:0], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1235"");
+\t\t end
+ else
+\t\t begin
+\t\t $fwrite (fd, "" 1236"");
+\t\t ozonecon(foo[14:10], fd);
+\t\t $fwrite (fd, "" 1237"");
+\t\t ozonef3e(foo[31:0], fd);
+\t\t dude(fd);
+\t\t $fwrite (fd, "" 1238"");
+\t\t end
+ 17\'b11_110?_1_????_??_???? :
+ begin
+\t\t ozonef3(foo[31:0], fd);
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1239"");
+ end
+ 17\'b11_110?_0_????_??_???? :
+ begin : f4_body
+\t\t casez (foo[24:20])
+\t\t 5\'b0_1110,
+\t\t 5\'b1_0???,
+\t\t 5\'b1_1111:
+\t\t\tbegin
+\t\t\t $fwrite (fd, "" 1240"");
+\t\t\tend
+\t\t 5\'b0_00??:
+\t\t begin
+\t\t\t ozoneacc(foo[26], fd);
+\t\t\t $fwrite (fd, "" 1241"");
+\t\t\t ozoneacc(foo[25], fd);
+\t\t\t ozonebmuop(foo[24:20], fd);
+\t\t\t ozoneae(foo[18:16], fd);
+\t\t\t $fwrite (fd, "" 1242"");
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1243"");
+\t\t end
+\t\t 5\'b0_01??:
+\t\t begin
+\t\t\t ozoneacc(foo[26], fd);
+\t\t\t $fwrite (fd, "" 1244"");
+\t\t\t ozoneacc(foo[25], fd);
+\t\t\t ozonebmuop(foo[24:20], fd);
+\t\t\t ozonearm(foo[18:16], fd);
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1245"");
+\t\t end
+\t\t 5\'b0_1011:
+\t\t begin
+\t\t\t ozoneacc(foo[26], fd);
+\t\t\t $fwrite (fd, "" 1246"");
+\t\t\t ozonebmuop(foo[24:20], fd);
+\t\t\t $fwrite (fd, "" 1247"");
+\t\t\t ozoneae(foo[18:16], fd);
+\t\t\t $fwrite (fd, "" 1248"");
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1249"");
+\t\t end
+\t\t 5\'b0_100?,
+\t\t 5\'b0_1010,
+\t\t 5\'b0_110? :
+\t\t\tbegin
+\t\t\t ozoneacc(foo[26], fd);
+\t\t\t $fwrite (fd, "" 1250"");
+\t\t\t ozonebmuop(foo[24:20], fd);
+\t\t\t $fwrite (fd, "" 1251"");
+\t\t\t ozoneacc(foo[25], fd);
+\t\t\t $fwrite (fd, "" 1252"");
+\t\t\t ozoneae(foo[18:16], fd);
+\t\t\t $fwrite (fd, "" 1253"");
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1254"");
+\t\t\tend
+\t\t 5\'b0_1111 :
+\t\t begin
+\t\t\t ozoneacc(foo[26], fd);
+\t\t\t $fwrite (fd, "" 1255"");
+\t\t\t ozoneacc(foo[25], fd);
+\t\t\t $fwrite (fd, "" 1256"");
+\t\t\t ozoneae(foo[18:16], fd);
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1257"");
+\t\t end
+\t\t 5\'b1_10??,
+\t\t 5\'b1_110?,
+\t\t 5\'b1_1110 :
+\t\t\tbegin
+\t\t\t ozoneacc(foo[26], fd);
+\t\t\t $fwrite (fd, "" 1258"");
+\t\t\t ozonebmuop(foo[24:20], fd);
+\t\t\t $fwrite (fd, "" 1259"");
+\t\t\t ozoneacc(foo[25], fd);
+\t\t\t $fwrite (fd, "" 1260"");
+\t\t\t ozonearm(foo[18:16], fd);
+\t\t\t $fwrite (fd, "" 1261"");
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1262"");
+\t\t\tend
+\t\t endcase
+ end
+ 17\'b11_100?_?_????_??_???? :
+ casez (foo[23:19])
+\t\t 5\'b111??,
+\t\t 5\'b0111?:
+\t\t begin
+\t\t\tozoneae(foo[26:24], fd);
+\t\t\t$fwrite (fd, "" 1263"");
+\t\t\tozonef3f4imop(foo[23:19], fd);
+\t\t\t$fwrite (fd, "" 1264"");
+\t\t\tozoneae(foo[18:16], fd);
+\t\t\t$fwrite (fd, "" 1265"");
+\t\t\tskyway(foo[15:12], fd);
+\t\t\tskyway(foo[11: 8], fd);
+\t\t\tskyway(foo[ 7: 4], fd);
+\t\t\tskyway(foo[ 3:0], fd);
+\t\t\t$fwrite (fd, "" 1266"");
+\t\t\tdude(fd);
+\t\t\t$fwrite(fd, "" 1267"");
+\t\t end
+\t\t 5\'b?0???,
+\t\t 5\'b110??:
+\t\t begin
+\t\t\tozoneae(foo[26:24], fd);
+\t\t\t$fwrite (fd, "" 1268"");
+\t\t\tif (foo[23:21] == 3\'b100)
+\t\t\t $fwrite (fd, "" 1269"");
+\t\t\tozoneae(foo[18:16], fd);
+\t\t\tif (foo[19])
+\t\t\t $fwrite (fd, "" 1270"");
+\t\t\telse
+\t\t\t $fwrite (fd, "" 1271"");
+\t\t\tozonef3f4imop(foo[23:19], fd);
+\t\t\t$fwrite (fd, "" 1272"");
+\t\t\tozonef3f4_iext(foo[20:19], foo[15:0], fd);
+\t\t\tdude(fd);
+\t\t\t$fwrite(fd, "" 1273"");
+\t\t end
+\t\t 5\'b010??,
+\t\t 5\'b0110?:
+\t\t begin
+\t\t\tozoneae(foo[18:16], fd);
+\t\t\tif (foo[19])
+\t\t\t $fwrite (fd, "" 1274"");
+\t\t\telse
+\t\t\t $fwrite (fd, "" 1275"");
+\t\t\tozonef3f4imop(foo[23:19], fd);
+\t\t\t$fwrite (fd, "" 1276"");
+\t\t\tozonef3f4_iext(foo[20:19], foo[15:0], fd);
+\t\t\tdude(fd);
+\t\t\t$fwrite(fd, "" 1277"");
+\t\t end
+ endcase
+ 17\'b00_1000_?_????_11_0011 :
+ begin
+\t\t $fwrite (fd,"" 1278"");
+\t\t ozonecon(foo[14:10], fd);
+\t\t $fwrite (fd, "" 1279"");
+\t\t casez (foo[25:21])
+\t\t 5\'b0_1110,
+\t\t 5\'b1_0???,
+\t\t 5\'b1_1111:
+\t\t\tbegin
+\t\t\t $fwrite(fd, "" 1280"");
+\t\t\tend
+\t\t 5\'b0_00??:
+\t\t begin
+\t\t\t ozoneae(foo[20:18], fd);
+\t\t\t $fwrite (fd, "" 1281"");
+\t\t\t ozoneae(foo[17:15], fd);
+\t\t\t ozonebmuop(foo[25:21], fd);
+\t\t\t ozoneae(foo[ 8: 6], fd);
+\t\t\t $fwrite (fd, "" 1282"");
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1283"");
+\t\t end
+\t\t 5\'b0_01??:
+\t\t begin
+\t\t\t ozoneae(foo[20:18], fd);
+\t\t\t $fwrite (fd, "" 1284"");
+\t\t\t ozoneae(foo[17:15], fd);
+\t\t\t ozonebmuop(foo[25:21], fd);
+\t\t\t ozonearm(foo[ 8: 6], fd);
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1285"");
+\t\t end
+\t\t 5\'b0_1011:
+\t\t begin
+\t\t\t ozoneae(foo[20:18], fd);
+\t\t\t $fwrite (fd, "" 1286"");
+\t\t\t ozonebmuop(foo[25:21], fd);
+\t\t\t $fwrite (fd, "" 1287"");
+\t\t\t ozoneae(foo[ 8: 6], fd);
+\t\t\t $fwrite (fd, "" 1288"");
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1289"");
+\t\t end
+\t\t 5\'b0_100?,
+\t\t 5\'b0_1010,
+\t\t 5\'b0_110? :
+\t\t\tbegin
+\t\t\t ozoneae(foo[20:18], fd);
+\t\t\t $fwrite (fd, "" 1290"");
+\t\t\t ozonebmuop(foo[25:21], fd);
+\t\t\t $fwrite (fd, "" 1291"");
+\t\t\t ozoneae(foo[17:15], fd);
+\t\t\t $fwrite (fd, "" 1292"");
+\t\t\t ozoneae(foo[ 8: 6], fd);
+\t\t\t $fwrite (fd, "" 1293"");
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1294"");
+\t\t\tend
+\t\t 5\'b0_1111 :
+\t\t begin
+\t\t\t ozoneae(foo[20:18], fd);
+\t\t\t $fwrite (fd, "" 1295"");
+\t\t\t ozoneae(foo[17:15], fd);
+\t\t\t $fwrite (fd, "" 1296"");
+\t\t\t ozoneae(foo[ 8: 6], fd);
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1297"");
+\t\t end
+\t\t 5\'b1_10??,
+\t\t 5\'b1_110?,
+\t\t 5\'b1_1110 :
+\t\t\tbegin
+\t\t\t ozoneae(foo[20:18], fd);
+\t\t\t $fwrite (fd, "" 1298"");
+\t\t\t ozonebmuop(foo[25:21], fd);
+\t\t\t $fwrite (fd, "" 1299"");
+\t\t\t ozoneae(foo[17:15], fd);
+\t\t\t $fwrite (fd, "" 1300"");
+\t\t\t ozonearm(foo[ 8: 6], fd);
+\t\t\t $fwrite (fd, "" 1301"");
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1302"");
+\t\t\tend
+\t\t endcase
+ end
+ 17\'b00_0010_?_????_??_???? :
+ begin
+\t\t ozonerab({1\'b0, foo[25:20]}, fd);
+\t\t $fwrite (fd, "" 1303"");
+\t\t skyway(foo[19:16], fd);
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1304"");
+ end
+ 17\'b00_01??_?_????_??_???? :
+ begin
+\t\t if (foo[27])
+\t\t begin
+\t\t $fwrite (fd, "" 1305"");
+\t\t if (foo[26])
+\t\t\t $fwrite (fd, "" 1306"");
+\t\t else
+\t\t\t $fwrite (fd, "" 1307"");
+\t\t skyway(foo[19:16], fd);
+\t\t $fwrite (fd, "" 1308"");
+\t\t ozonerab({1\'b0, foo[25:20]}, fd);
+\t\t end
+\t\t else
+\t\t begin
+\t\t ozonerab({1\'b0, foo[25:20]}, fd);
+\t\t $fwrite (fd, "" 1309"");
+\t\t if (foo[26])
+\t\t\t $fwrite (fd, "" 1310"");
+\t\t else
+\t\t\t $fwrite (fd, "" 1311"");
+\t\t skyway(foo[19:16], fd);
+\t\t $fwrite (fd, "" 1312"");
+\t\t end
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1313"");
+ end
+ 17\'b01_000?_?_????_??_???? :
+ begin
+\t\t if (foo[26])
+\t\t begin
+\t\t ozonerb(foo[25:20], fd);
+\t\t $fwrite (fd, "" 1314"");
+\t\t ozoneae(foo[18:16], fd);
+\t\t ozonehl(foo[19], fd);
+\t\t end
+\t\t else
+\t\t begin
+\t\t ozoneae(foo[18:16], fd);
+\t\t ozonehl(foo[19], fd);
+\t\t $fwrite (fd, "" 1315"");
+\t\t ozonerb(foo[25:20], fd);
+\t\t end
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1316"");
+ end
+ 17\'b01_10??_?_????_??_???? :
+ begin
+\t\t if (foo[27])
+\t\t begin
+\t\t ozonerab({1\'b0, foo[25:20]}, fd);
+\t\t $fwrite (fd, "" 1317"");
+\t\t ozonerx(foo, fd);
+\t\t end
+\t\t else
+\t\t begin
+\t\t ozonerx(foo, fd);
+\t\t $fwrite (fd, "" 1318"");
+\t\t ozonerab({1\'b0, foo[25:20]}, fd);
+\t\t end
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1319"");
+ end
+ 17\'b11_101?_?_????_??_???? :
+ begin
+\t\t ozonerab (foo[26:20], fd);
+\t\t $fwrite (fd, "" 1320"");
+\t\t skyway(foo[19:16], fd);
+\t\t skyway(foo[15:12], fd);
+\t\t skyway(foo[11: 8], fd);
+\t\t skyway(foo[ 7: 4], fd);
+\t\t skyway(foo[ 3: 0], fd);
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1321"");
+ end
+ 17\'b11_0000_?_????_??_???? :
+ begin
+\t\t casez (foo[25:23])
+\t\t 3\'b00?:
+\t\t begin
+\t\t\t ozonerab(foo[22:16], fd);
+\t\t\t $fwrite (fd, "" 1322"");
+\t\t end
+\t\t 3\'b01?:
+\t\t begin
+\t\t\t $fwrite (fd, "" 1323"");
+\t\t\t if (foo[22:16]>=7\'h60)
+\t\t\t $fwrite (fd, "" 1324"");
+\t\t\t else
+\t\t\t ozonerab(foo[22:16], fd);
+\t\t end
+\t\t 3\'b110:
+\t\t $fwrite (fd, "" 1325"");
+\t\t 3\'b10?:
+\t\t begin
+\t\t\t $fwrite (fd, "" 1326"");
+\t\t\t if (foo[22:16]>=7\'h60)
+\t\t\t $fwrite (fd, "" 1327"");
+\t\t\t else
+\t\t\t ozonerab(foo[22:16], fd);
+\t\t end
+\t\t 3\'b111:
+\t\t begin
+\t\t\t $fwrite (fd, "" 1328"");
+\t\t\t ozonerab(foo[22:16], fd);
+\t\t\t $fwrite (fd, "" 1329"");
+\t\t end
+\t\t endcase
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1330"");
+ end
+ 17\'b00_10??_?_????_?1_0000 :
+ begin
+\t\t if (foo[27])
+\t\t begin
+\t\t $fwrite (fd, "" 1331"");
+\t\t ozonerp(foo[14:12], fd);
+\t\t $fwrite (fd, "" 1332"");
+\t\t skyway(foo[19:16], fd);
+\t\t skyway({foo[15],foo[11: 9]}, fd);
+\t\t skyway(foo[ 8: 5], fd);
+\t\t $fwrite (fd, "" 1333"");
+\t\t if (foo[26:20]>=7\'h60)
+\t\t\t $fwrite (fd, "" 1334"");
+\t\t else
+\t\t\t ozonerab(foo[26:20], fd);
+\t\t end
+\t\t else
+\t\t begin
+\t\t ozonerab(foo[26:20], fd);
+\t\t $fwrite (fd, "" 1335"");
+\t\t $fwrite (fd, "" 1336"");
+\t\t ozonerp(foo[14:12], fd);
+\t\t $fwrite (fd, "" 1337"");
+\t\t skyway(foo[19:16], fd);
+\t\t skyway({foo[15],foo[11: 9]}, fd);
+\t\t skyway(foo[ 8: 5], fd);
+\t\t $fwrite (fd, "" 1338"");
+\t\t end
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1339"");
+ end
+ 17\'b00_101?_1_0000_?1_0010 :
+ if (~|foo[11: 7])
+\t\t begin
+\t\t if (foo[ 6])
+\t\t begin
+\t\t\t $fwrite (fd, "" 1340"");
+\t\t\t ozonerp(foo[14:12], fd);
+\t\t\t $fwrite (fd, "" 1341"");
+\t\t\t ozonejk(foo[ 5], fd);
+\t\t\t $fwrite (fd, "" 1342"");
+\t\t\t if (foo[26:20]>=7\'h60)
+\t\t\t $fwrite (fd, "" 1343"");
+\t\t\t else
+\t\t\t ozonerab(foo[26:20], fd);
+\t\t end
+\t\t else
+\t\t begin
+\t\t\t ozonerab(foo[26:20], fd);
+\t\t\t $fwrite (fd, "" 1344"");
+\t\t\t $fwrite (fd, "" 1345"");
+\t\t\t ozonerp(foo[14:12], fd);
+\t\t\t $fwrite (fd, "" 1346"");
+\t\t\t ozonejk(foo[ 5], fd);
+\t\t\t $fwrite (fd, "" 1347"");
+\t\t end
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1348"");
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1349"");
+ 17\'b00_100?_0_0011_?1_0101 :
+ if (~|foo[ 8: 7])
+\t\t begin
+\t\t if (foo[6])
+\t\t begin
+\t\t\t ozonerab(foo[26:20], fd);
+\t\t\t $fwrite (fd, "" 1350"");
+\t\t\t ozoneye(foo[14: 9],foo[ 5], fd);
+\t\t end
+\t\t else
+\t\t begin
+\t\t\t ozoneye(foo[14: 9],foo[ 5], fd);
+\t\t\t $fwrite (fd, "" 1351"");
+\t\t\t if (foo[26:20]>=7\'h60)
+\t\t\t $fwrite (fd, "" 1352"");
+\t\t\t else
+\t\t\t ozonerab(foo[26:20], fd);
+\t\t end
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1353"");
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1354"");
+ 17\'b00_1001_0_0000_?1_0010 :
+ if (~|foo[25:20])
+\t\t begin
+\t\t ozoneye(foo[14: 9],1\'b0, fd);
+\t\t $fwrite (fd, "" 1355"");
+\t\t ozonef1e_h(foo[11: 9], fd);
+\t\t $fwrite (fd, "" 1356"");
+\t\t ozonef1e_h(foo[ 7: 5], fd);
+\t\t $fwrite (fd, "" 1357"");
+\t\t ozonexe(foo[ 8: 5], fd);
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1358"");
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1359"");
+ 17\'b00_101?_0_????_?1_0010 :
+ if (~foo[13])
+\t\t begin
+\t\t if (foo[12])
+\t\t begin
+\t\t\t $fwrite (fd, "" 1360"");
+\t\t\t if (foo[26:20]>=7\'h60)
+\t\t\t $fwrite (fd, "" 1361"");
+\t\t\t else
+\t\t\t ozonerab(foo[26:20], fd);
+\t\t\t $fwrite (fd, "" 1362"");
+\t\t\t $fwrite (fd, "" 1363"");
+\t\t\t skyway({1\'b0,foo[18:16]}, fd);
+\t\t\t skyway({foo[15],foo[11: 9]}, fd);
+\t\t\t skyway(foo[ 8: 5], fd);
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1364"");
+\t\t end
+\t\t else
+\t\t begin
+\t\t\t ozonerab(foo[26:20], fd);
+\t\t\t $fwrite (fd, "" 1365"");
+\t\t\t $fwrite (fd, "" 1366"");
+\t\t\t skyway({1\'b0,foo[18:16]}, fd);
+\t\t\t skyway({foo[15],foo[11: 9]}, fd);
+\t\t\t skyway(foo[ 8: 5], fd);
+\t\t\t dude(fd);
+\t\t\t $fwrite(fd, "" 1367"");
+\t\t end
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1368"");
+ 17\'b01_01??_?_????_??_???? :
+ begin
+\t\t ozonerab({1\'b0,foo[27:26],foo[19:16]}, fd);
+\t\t $fwrite (fd, "" 1369"");
+\t\t ozonerab({1\'b0,foo[25:20]}, fd);
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1370"");
+ end
+ 17\'b00_100?_?_???0_11_0101 :
+ if (~foo[6])
+\t\t begin
+\t\t $fwrite (fd,"" 1371"");
+\t\t ozonecon(foo[14:10], fd);
+\t\t $fwrite (fd, "" 1372"");
+\t\t ozonerab({foo[ 9: 7],foo[19:16]}, fd);
+\t\t $fwrite (fd, "" 1373"");
+\t\t ozonerab({foo[26:20]}, fd);
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1374"");
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1375"");
+ 17\'b00_1000_?_????_?1_0010 :
+ if (~|foo[25:24])
+\t\t begin
+\t\t ozonery(foo[23:20], fd);
+\t\t $fwrite (fd, "" 1376"");
+\t\t ozonerp(foo[14:12], fd);
+\t\t $fwrite (fd, "" 1377"");
+\t\t skyway(foo[19:16], fd);
+\t\t skyway({foo[15],foo[11: 9]}, fd);
+\t\t skyway(foo[ 8: 5], fd);
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1378"");
+\t\t end
+ else if ((foo[25:24] == 2\'b10) & ~|foo[19:15] & ~|foo[11: 6])
+\t\t begin
+\t\t ozonery(foo[23:20], fd);
+\t\t $fwrite (fd, "" 1379"");
+\t\t ozonerp(foo[14:12], fd);
+\t\t $fwrite (fd, "" 1380"");
+\t\t ozonejk(foo[ 5], fd);
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1381"");
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1382"");
+ 17\'b11_01??_?_????_??_????,
+ 17\'b10_00??_?_????_??_???? :
+\t\t if (foo[30])
+\t\t $fwrite(fd, "" 1383:%x"", foo[27:16]);
+\t\t else
+\t\t $fwrite(fd, "" 1384:%x"", foo[27:16]);
+ 17\'b00_10??_?_????_01_1000 :
+ if (~foo[6])
+\t\t begin
+\t\t if (foo[7])
+\t\t $fwrite(fd, "" 1385:%x"", foo[27: 8]);
+\t\t else
+\t\t $fwrite(fd, "" 1386:%x"", foo[27: 8]);
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1387"");
+ 17\'b00_10??_?_????_11_1000 :
+ begin
+\t\t $fwrite (fd,"" 1388"");
+\t\t ozonecon(foo[14:10], fd);
+\t\t $fwrite (fd, "" 1389"");
+\t\t if (foo[15])
+\t\t $fwrite (fd, "" 1390"");
+\t\t else
+\t\t $fwrite (fd, "" 1391"");
+\t\t skyway(foo[27:24], fd);
+\t\t skyway(foo[23:20], fd);
+\t\t skyway(foo[19:16], fd);
+\t\t skyway(foo[ 9: 6], fd);
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1392"");
+ end
+ 17\'b11_0001_?_????_??_???? :
+ casez (foo[25:22])
+\t\t 4\'b01?? :
+\t\t begin
+\t\t $fwrite (fd,"" 1393"");
+\t\t ozonecon(foo[20:16], fd);
+\t\t case (foo[23:21])
+\t\t\t3\'h0 : $fwrite (fd, "" 1394"");
+\t\t\t3\'h1 : $fwrite (fd, "" 1395"");
+\t\t\t3\'h2 : $fwrite (fd, "" 1396"");
+\t\t\t3\'h3 : $fwrite (fd, "" 1397"");
+\t\t\t3\'h4 : $fwrite (fd, "" 1398"");
+\t\t\t3\'h5 : $fwrite (fd, "" 1399"");
+\t\t\t3\'h6 : $fwrite (fd, "" 1400"");
+\t\t\t3\'h7 : $fwrite (fd, "" 1401"");
+\t\t endcase
+\t\t dude(fd);
+\t\t $fwrite(fd, "" 1402"");
+\t\t end
+\t\t 4\'b0000 :
+\t\t $fwrite(fd, "" 1403:%x"", foo[21:16]);
+\t\t 4\'b0010 :
+\t\t if (~|foo[21:16])
+ $fwrite(fd, "" 1404"");
+\t\t 4\'b1010 :
+\t\t if (~|foo[21:17])
+\t\t begin
+\t\t\tif (foo[16])
+\t\t\t $fwrite(fd, "" 1405"");
+\t\t\telse
+\t\t\t $fwrite(fd, "" 1406"");
+\t\t end
+\t\t default :
+\t\t $fwrite(fd, "" 1407"");
+ endcase
+ 17\'b01_11??_?_????_??_???? :
+ if (foo[27:23] === 5\'h00)
+\t\t $fwrite(fd, "" 1408:%x"", foo[22:16]);
+ else
+\t\t $fwrite(fd, "" 1409:%x"", foo[22:16]);
+ default: $fwrite(fd, "" 1410"");
+\t endcase
+ end
+ endtask
+
+ //(query-replace-regexp ""\\\\([a-z0-9_]+\\\\) *( *\\\\([][a-z0-9_~\': ]+\\\\) *, *\\\\([][a-z0-9\'~: ]+\\\\) *, *\\\\([][a-z0-9\'~: ]+\\\\) *);"" ""$c(\\""\\\\1(\\"",\\\\2,\\"",\\"",\\\\3,\\"",\\"",\\\\4,\\"");\\"");"" nil nil nil)
+ //(query-replace-regexp ""\\\\([a-z0-9_]+\\\\) *( *\\\\([][a-z0-9_~\': ]+\\\\) *, *\\\\([][a-z0-9\'~: ]+\\\\) *);"" ""$c(\\""\\\\1(\\"",\\\\2,\\"",\\"",\\\\3,\\"");\\"");"" nil nil nil)
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t
+ (
+ input wire reset_l,
+ input wire clk
+ );
+
+ sub sub_I
+ (
+ .clk(clk),
+ .reset_l(reset_l),
+ .cpu_if_timeout(1'b0)
+ );
+endmodule
+
+module sub
+ (
+ input wire\tclk, reset_l,
+ output reg\tcpu_if_timeout
+ );
+
+ always @(posedge clk) begin
+ if (!reset_l) begin
+\t cpu_if_timeout <= 1'b0;
+ end
+ else begin
+\t cpu_if_timeout <= 1'b0;
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ reg [72:1] in;
+ initial begin
+ if (in[( (1'h0 / 1'b0) )+:71] != 71'h0) $stop;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ wire d, en, nc, pc;
+
+ // verilator lint_off IMPLICIT
+ cmos (cm0, d, nc, pc);
+ rcmos (rc0, d, nc, pc);
+
+ nmos (nm0, d, en);
+ pmos (pm0, d, en);
+ rnmos (rn0, d, en);
+ rpmos (rp0, d, en);
+
+ rtran (rt0, d);
+ tran (tr0, d);
+
+ rtranif0 (r00, d, en);
+ rtranif1 (r10, d, en);
+ tranif0 (t00, d, en);
+ tranif1 (t10, d, en);
+ // verilator lint_on IMPLICIT
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // Check empty blocks
+ task EmptyFor;
+ /* verilator public */
+ integer i;
+ begin
+ for (i = 0; i < 2; i = i+1)
+ begin
+ end
+ end
+ endtask
+
+ // Check look unroller
+ reg signed\t signed_tests_only = 1\'sb1;
+ integer \t total;
+
+ integer\t i;
+ reg [31:0] \t iu;
+ reg [31:0]\t dly_to_insure_was_unrolled [1:0];
+ reg [2:0] \t i3;
+
+ integer cyc; initial cyc=0;
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ case (cyc)
+\t1: begin
+\t // >= signed
+\t total = 0;
+\t for (i=5; i>=0; i=i-1) begin
+\t total = total - i -1;
+\t dly_to_insure_was_unrolled[i] <= i;
+\t end
+\t if (total != -21) $stop;
+\tend
+\t2: begin
+\t // > signed
+\t total = 0;
+\t for (i=5; i>0; i=i-1) begin
+\t total = total - i -1;
+\t dly_to_insure_was_unrolled[i] <= i;
+\t end
+\t if (total != -20) $stop;
+\tend
+\t3: begin
+\t // < signed
+\t total = 0;
+\t for (i=1; i<5; i=i+1) begin
+\t total = total - i -1;
+\t dly_to_insure_was_unrolled[i] <= i;
+\t end
+\t if (total != -14) $stop;
+\tend
+\t4: begin
+\t // <= signed
+\t total = 0;
+\t for (i=1; i<=5; i=i+1) begin
+\t total = total - i -1;
+\t dly_to_insure_was_unrolled[i] <= i;
+\t end
+\t if (total != -20) $stop;
+\tend
+\t// UNSIGNED
+\t5: begin
+\t // >= unsigned
+\t total = 0;
+\t for (iu=5; iu>=1; iu=iu-1) begin
+\t total = total - iu -1;
+\t dly_to_insure_was_unrolled[iu] <= iu;
+\t end
+\t if (total != -20) $stop;
+\tend
+\t6: begin
+\t // > unsigned
+\t total = 0;
+\t for (iu=5; iu>1; iu=iu-1) begin
+\t total = total - iu -1;
+\t dly_to_insure_was_unrolled[iu] <= iu;
+\t end
+\t if (total != -18) $stop;
+\tend
+\t7: begin
+\t // < unsigned
+\t total = 0;
+\t for (iu=1; iu<5; iu=iu+1) begin
+\t total = total - iu -1;
+\t dly_to_insure_was_unrolled[iu] <= iu;
+\t end
+\t if (total != -14) $stop;
+\tend
+\t8: begin
+\t // <= unsigned
+\t total = 0;
+\t for (iu=1; iu<=5; iu=iu+1) begin
+\t total = total - iu -1;
+\t dly_to_insure_was_unrolled[iu] <= iu;
+\t end
+\t if (total != -20) $stop;
+\tend
+\t//===
+\t9: begin
+\t // mostly cover a small index
+\t total = 0;
+\t for (i3=3\'d0; i3<3\'d7; i3=i3+3\'d1) begin
+\t total = total - {29\'d0,i3} -1;
+\t dly_to_insure_was_unrolled[i3[0]] <= 0;
+\t end
+\t if (total != -28) $stop;
+\tend
+\t//===
+\t10: begin
+\t // mostly cover a small index
+\t total = 0;
+\t for (i3=0; i3<3\'d7; i3=i3+3\'d1) begin
+\t total = total - {29\'d0,i3} -1;
+\t dly_to_insure_was_unrolled[i3[0]] <= 0;
+\t end
+\t if (total != -28) $stop;
+\tend
+\t//===
+\t11: begin
+\t // width violation on <, causes extend
+\t total = 0;
+\t for (i3=3\'d0; i3<7; i3=i3+1) begin
+\t total = total - {29\'d0,i3} -1;
+\t dly_to_insure_was_unrolled[i3[0]] <= 0;
+\t end
+\t if (total != -28) $stop;
+\tend
+\t//===
+\t// width violation on <, causes extend signed
+\t// Unsupported as yet
+\t//===
+\t19: begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\tend
+\tdefault: ;
+ endcase
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder
+
+`define STRINGIFY(x) `""x`""
+
+module t;
+ initial begin
+`ifdef D1A
+ if (`STRINGIFY(`D4B) !== """") $stop;
+`else
+ $write(""%%Error: Missing define\
+""); $stop;
+`endif
+
+`ifdef D2A
+ if (`STRINGIFY(`D2A) !== ""VALA"") $stop;
+`else
+ $write(""%%Error: Missing define\
+""); $stop;
+`endif
+
+`ifdef D3A
+ if (`STRINGIFY(`D4B) !== """") $stop;
+`else
+ $write(""%%Error: Missing define\
+""); $stop;
+`endif
+
+`ifdef D3B
+ if (`STRINGIFY(`D4B) !== """") $stop;
+`else
+ $write(""%%Error: Missing define\
+""); $stop;
+`endif
+
+`ifdef D4A
+ if (`STRINGIFY(`D4A) !== ""VALA"") $stop;
+`else
+ $write(""%%Error: Missing define\
+""); $stop;
+`endif
+
+`ifdef D4B
+ if (`STRINGIFY(`D4B) !== """") $stop;
+`else
+ $write(""%%Error: Missing define\
+""); $stop;
+`endif
+
+`ifdef D5A
+ if (`STRINGIFY(`D5A) !== ""VALA"") $stop;
+`else
+ $write(""%%Error: Missing define\
+""); $stop;
+`endif
+
+`ifdef D5A
+ if (`STRINGIFY(`D5B) !== ""VALB"") $stop;
+`else
+ $write(""%%Error: Missing define\
+""); $stop;
+`endif
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [3:0] l_stop = crc[3:0];
+ wire [3:0] l_break = crc[7:4];
+ wire [3:0] l_continue = crc[11:8];
+
+ /*AUTOWIRE*/
+
+ wire [15:0] out0 = Test0(l_stop, l_break, l_continue);
+ wire [15:0] out1 = Test1(l_stop, l_break, l_continue);
+ wire [15:0] out2 = Test2(l_stop, l_break, l_continue);
+ wire [15:0] out3 = Test3(l_stop, l_break, l_continue);
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {out3,out2,out1,out0};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+\t if (out0!==out1) $stop;
+\t if (out0!==out2) $stop;
+\t if (out0!==out3) $stop;
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h293e9f9798e97da0
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+ function [15:0] Test0;
+ input [3:0] loop_stop;
+ input [3:0] loop_break;
+ input [3:0] loop_continue;
+ integer \t i;
+ reg \t broken;
+
+ Test0 = 0;
+ broken = 0;
+ begin
+\t for (i=1; i<20; i=i+1) begin
+\t if (!broken) begin
+\t Test0 = Test0 + 1;
+\t if (i[3:0] != loop_continue) begin // continue
+\t\t if (i[3:0] == loop_break) begin
+\t\t broken = 1\'b1;
+\t\t end
+\t\t if (!broken) begin
+\t\t Test0 = Test0 + i[15:0];
+\t\t end
+\t end
+\t end
+\t end
+ end
+ endfunction
+
+ function [15:0] Test1;
+ input [3:0] loop_stop;
+ input [3:0] loop_break;
+ input [3:0] loop_continue;
+ integer \t i;
+
+ Test1 = 0;
+ begin : outer_block
+ for (i=1; i<20; i=i+1) begin : inner_block
+ \t Test1 = Test1 + 1;
+\t // continue, IE jump to end-of-inner_block. Must be inside inner_block.
+ if (i[3:0] == loop_continue) disable inner_block;
+\t // break, IE jump to end-of-outer_block. Must be inside outer_block.
+ \t if (i[3:0] == loop_break) disable outer_block;
+ \t Test1 = Test1 + i[15:0];
+ end : inner_block
+ end : outer_block
+ endfunction
+
+ function [15:0] Test2;
+ input [3:0] loop_stop;
+ input [3:0] loop_break;
+ input [3:0] loop_continue;
+ integer \t i;
+
+ Test2 = 0;
+ begin
+ for (i=1; i<20; i=i+1) begin
+ \t Test2 = Test2 + 1;
+ \t if (i[3:0] == loop_continue) continue;
+ \t if (i[3:0] == loop_break) break;
+ \t Test2 = Test2 + i[15:0];
+ end
+ end
+ endfunction
+
+ function [15:0] Test3;
+ input [3:0] loop_stop;
+ input [3:0] loop_break;
+ input [3:0] loop_continue;
+ integer \t i;
+
+ Test3 = 0;
+ begin
+ for (i=1; i<20; i=i+1) begin
+ \t Test3 = Test3 + 1;
+ \t if (i[3:0] == loop_continue) continue;
+\t // return, IE jump to end-of-function optionally setting return value
+ \t if (i[3:0] == loop_break) return Test3;
+ \t Test3 = Test3 + i[15:0];
+ end
+ end
+ endfunction
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ function int f( int j = 1, int s = 0 );
+ return (j<<16) | s;
+ endfunction
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
+
+ initial begin
+ `checkh( f(.j(2), .s(1))\t, 32\'h2_0001 );
+ `checkh( f(.s(1))\t\t, 32\'h1_0001 );
+ `checkh( f(, 1)\t\t, 32\'h1_0001 );
+ `checkh( f(.j(2))\t\t, 32\'h2_0000 );
+ `checkh( f(.s(1), .j(2))\t, 32\'h2_0001 );
+ `checkh( f(.s(), .j())\t, 32\'h1_0000 );
+ `checkh( f(2)\t\t, 32\'h2_0000 );
+ `checkh( f()\t\t, 32\'h1_0000 );
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Simple static elaboration case
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Todd Strader.
+
+module t (/*AUTOARG*/);
+
+ typedef struct packed {
+ logic [ 31 : 0 ] _five;
+ } five_t;
+
+ function five_t gimme_five ();
+ automatic five_t result;
+
+ result._five = 5;
+
+ return result;
+ endfunction
+
+ localparam five_t FIVE = gimme_five();
+
+ initial begin
+ if (FIVE._five != 5) begin
+ $display(""%%Error: Got 0b%b instead of 5"", FIVE._five);
+ $stop;
+ end
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+// bug475
+
+module t();
+
+ function real get_real_one;
+ input \t ignored;
+ get_real_one = 1.1;
+ endfunction
+
+ localparam R_PARAM = get_real_one(1\'b0);
+ localparam R_PARAM_2 = (R_PARAM > 0);
+
+ generate
+ initial begin
+\t if (R_PARAM != 1.1) $stop;
+\t if (R_PARAM_2 != 1\'b1) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ endgenerate
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2009 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ parameter integer BLKS = 3;
+
+ generate
+ for (genvar blkIdx=0; blkIdx < BLKS; blkIdx=blkIdx+1 ) begin : slice
+
+\t import ""DPI-C"" context function void dpi_genvarTest ();
+
+ initial begin
+\t dpi_genvarTest();
+\t $display(""slice = %0d : %m"", blkIdx);
+\t end
+ end
+ endgenerate
+
+ always @ (posedge clk) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: System Verilog test of case and if
+//
+// This code instantiates and runs a simple CPU written in System Verilog.
+//
+// This file ONLY is placed into the Public Domain, for any use, without
+// warranty.
+
+// Contributed 2012 by M W Lund, Atmel Corporation and Jeremy Bennett, Embecosm.
+
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ /*AUTOWIRE*/
+
+ // **************************************************************************
+ // Regs and Wires
+ // **************************************************************************
+
+ reg \t rst;
+ integer rst_count;
+
+
+ st3_testbench st3_testbench_i (/*AUTOINST*/
+\t\t\t\t // Inputs
+\t\t\t\t .clk\t\t\t(clk),
+\t\t\t\t .rst\t\t\t(rst));
+
+ // **************************************************************************
+ // Reset Generation
+ // **************************************************************************
+
+ initial begin
+ rst = 1\'b1;
+ rst_count = 0;
+ end
+
+ always @( posedge clk ) begin
+ if (rst_count < 2) begin
+\t rst_count++;
+ end
+ else begin
+\t rst = 1\'b0;
+ end
+ end
+
+ // **************************************************************************
+ // Closing message
+ // **************************************************************************
+
+ final begin
+ $write(""*-* All Finished *-*\
+"");
+ end
+
+endmodule
+
+
+module st3_testbench (/*AUTOARG*/
+ // Inputs
+ clk, rst
+ );
+
+ input clk;
+ input rst;
+
+ logic clk;
+ logic rst;
+ logic [8*16-1:0] wide_input_bus;
+ logic \t decrementA; // 0=Up-counting, 1=down-counting
+ logic \t dual_countA; // Advance counter by 2 steps at a time
+ logic \t cntA_en; // Enable Counter A
+ logic \t decrementB; // 0=Up-counting, 1=down-counting
+ logic \t dual_countB; // Advance counter by 2 steps at a time
+ logic \t cntB_en; // Enable counter B
+ logic [47:0] selected_out;
+ integer \t i;
+
+
+ initial begin
+ decrementA = 1\'b0;
+ dual_countA = 1\'b0;
+ cntA_en = 1\'b1;
+ decrementB = 1\'b0;
+ dual_countB = 1\'b0;
+ cntB_en = 1\'b1;
+ wide_input_bus = {8\'hf5,
+ 8\'hef,
+ 8\'hd5,
+ 8\'hc5,
+ 8\'hb5,
+ 8\'ha5,
+ 8\'h95,
+ 8\'h85,
+ 8\'ha7,
+ 8\'ha6,
+ 8\'ha5,
+ 8\'ha4,
+ 8\'ha3,
+ 8\'ha2,
+ 8\'ha1,
+ 8\'ha0};
+ i = 0;
+ end
+
+
+ simple_test_3
+ simple_test_3_i
+ (// Outputs
+\t.selected_out (selected_out[47:0]),
+\t// Inputs
+\t.wide_input_bus (wide_input_bus[8*16-1:0]),
+\t.rst (rst),
+\t.clk (clk),
+\t.decrementA (decrementA),
+\t.dual_countA (dual_countA),
+\t.cntA_en (cntA_en),
+\t.decrementB (decrementB),
+\t.dual_countB (dual_countB),
+\t.cntB_en (cntB_en));
+
+
+ // Logic to print outputs and then finish.
+ always @(posedge clk) begin
+ if (i < 50) begin
+`ifdef TEST_VERBOSE
+\t $display(""%x"", simple_test_3_i.cntA_reg ,""%x"",
+\t\t simple_test_3_i.cntB_reg ,"" "", ""%x"", selected_out);
+`endif
+\t i <= i + 1;
+ end
+ else begin
+\t $finish();
+ end
+ end // always @ (posedge clk)
+
+endmodule
+
+
+// Module testing:
+// - Unique case
+// - Priority case
+// - Unique if
+// - ++, --, =- and =+ operands.
+
+module simple_test_3
+ (input logic [8*16-1:0] wide_input_bus,
+ input logic \t rst,
+ input logic \t clk,
+ // Counter A
+ input logic \t decrementA, // 0=Up-counting, 1=down-counting
+ input logic \t dual_countA, // Advance counter by 2 steps at a time
+ input logic \t cntA_en, // Enable Counter A
+ // Counter B
+ input logic \t decrementB, // 0=Up-counting, 1=down-counting
+ input logic \t dual_countB, // Advance counter by 2 steps at a time
+ input logic \t cntB_en, // Enable counter B
+
+ // Outputs
+ output logic [47:0] selected_out);
+
+ // Declarations
+ logic [3:0] \t cntA_reg; // Registered version of cntA
+ logic [3:0] \t cntB_reg; // Registered version of cntA
+
+
+ counterA
+ counterA_inst
+ (/*AUTOINST*/
+\t// Outputs
+\t.cntA_reg\t\t\t(cntA_reg[3:0]),
+\t// Inputs
+\t.decrementA\t\t\t(decrementA),
+\t.dual_countA\t\t\t(dual_countA),
+\t.cntA_en\t\t\t(cntA_en),
+\t.clk\t\t\t\t(clk),
+\t.rst\t\t\t\t(rst));
+
+ counterB
+ counterB_inst
+ (/*AUTOINST*/
+\t// Outputs
+\t.cntB_reg\t\t\t(cntB_reg[3:0]),
+\t// Inputs
+\t.decrementB\t\t\t(decrementB),
+\t.dual_countB\t\t\t(dual_countB),
+\t.cntB_en\t\t\t(cntB_en),
+\t.clk\t\t\t\t(clk),
+\t.rst\t\t\t\t(rst));
+
+ simple_test_3a
+ sta
+ (.wide_input_bus (wide_input_bus),
+\t.selector (cntA_reg),
+\t.selected_out (selected_out[7:0]));
+
+ simple_test_3b
+ stb
+ (.wide_input_bus (wide_input_bus),
+\t.selector (cntA_reg),
+\t.selected_out (selected_out[15:8]));
+
+ simple_test_3c
+ stc
+ (.wide_input_bus (wide_input_bus),
+\t.selector (cntB_reg),
+\t.selected_out (selected_out[23:16]));
+
+ simple_test_3d
+ std
+ (.wide_input_bus (wide_input_bus),
+\t.selector (cntB_reg),
+\t.selected_out (selected_out[31:24]));
+
+ simple_test_3e
+ ste
+ (.wide_input_bus (wide_input_bus),
+\t.selector (cntB_reg),
+\t.selected_out (selected_out[39:32]));
+
+ simple_test_3f
+ stf
+ (.wide_input_bus (wide_input_bus),
+\t.selector (cntB_reg),
+\t.selected_out (selected_out[47:40]));
+
+
+endmodule // simple_test_3
+
+
+module counterA
+ (output logic [3:0] cntA_reg, // Registered version of cntA
+ input logic decrementA, // 0=Up-counting, 1=down-counting
+ input logic dual_countA, // Advance counter by 2 steps at a time
+ input logic cntA_en, // Enable Counter A
+ input logic clk, // Clock
+ input logic rst); // Synchronous reset
+
+
+
+ logic [3:0] cntA; // combinational count variable.
+
+ // Counter A
+ // Sequential part of counter CntA
+ always_ff @(posedge clk)
+ begin
+\tcntA_reg <= cntA;
+ end
+
+ // Combinational part of counter
+ // Had to be split up to test C-style update, as there are no
+ // non-blocking version like -<=
+ always_comb
+ if (rst)
+ cntA = 0;
+ else begin
+ cntA = cntA_reg; // Necessary to avoid latch
+ if (cntA_en) begin
+ if (decrementA)
+ if (dual_countA)
+ //cntA = cntA - 2;
+ cntA -= 2;
+ else
+ //cntA = cntA - 1;
+ cntA--;
+ else
+ if (dual_countA)
+ //cntA = cntA + 2;
+ cntA += 2;
+ else
+ //cntA = cntA + 1;
+ cntA++;
+ end // if (cntA_en)
+ end
+endmodule // counterA
+
+
+module counterB
+ (output logic [3:0] cntB_reg, // Registered version of cntA
+ input logic decrementB, // 0=Up-counting, 1=down-counting
+ input logic dual_countB, // Advance counter by 2 steps at a time
+ input logic cntB_en, // Enable counter B
+ input logic clk, // Clock
+ input logic rst); // Synchronous reset
+
+ // Counter B - tried to write sequential only, but ended up without
+ // SystemVerilog.
+
+ always_ff @(posedge clk) begin
+ if (rst)
+ cntB_reg <= 0;
+ else
+ if (cntB_en) begin
+ if (decrementB)
+ if (dual_countB)
+ cntB_reg <= cntB_reg - 2;
+ else
+ cntB_reg <= cntB_reg - 1;
+ // Attempts to write in SystemVerilog:
+ else
+ if (dual_countB)
+ cntB_reg <= cntB_reg + 2;
+ else
+ cntB_reg <= cntB_reg + 1;
+ // Attempts to write in SystemVerilog:
+ end
+ end // always_ff @
+endmodule
+
+
+// A multiplexor in terms of look-up
+module simple_test_3a
+ (input logic [8*16-1:0] wide_input_bus,
+ input logic [3:0] selector,
+ output logic [7:0] selected_out);
+
+
+ always_comb
+ selected_out = {wide_input_bus[selector*8+7],
+ wide_input_bus[selector*8+6],
+ wide_input_bus[selector*8+5],
+ wide_input_bus[selector*8+4],
+ wide_input_bus[selector*8+3],
+ wide_input_bus[selector*8+2],
+ wide_input_bus[selector*8+1],
+ wide_input_bus[selector*8]};
+
+endmodule // simple_test_3a
+
+
+// A multiplexer in terms of standard case
+module simple_test_3b
+ (input logic [8*16-1:0] wide_input_bus,
+ input logic [3:0] selector,
+ output logic [7:0] selected_out);
+
+
+ always_comb begin
+ case (selector)
+ 4\'h0: selected_out = wide_input_bus[ 7: 0];
+ 4\'h1: selected_out = wide_input_bus[ 15: 8];
+ 4\'h2: selected_out = wide_input_bus[ 23: 16];
+ 4\'h3: selected_out = wide_input_bus[ 31: 24];
+ 4\'h4: selected_out = wide_input_bus[ 39: 32];
+ 4\'h5: selected_out = wide_input_bus[ 47: 40];
+ 4\'h6: selected_out = wide_input_bus[ 55: 48];
+ 4\'h7: selected_out = wide_input_bus[ 63: 56];
+ 4\'h8: selected_out = wide_input_bus[ 71: 64];
+ 4\'h9: selected_out = wide_input_bus[ 79: 72];
+ 4\'ha: selected_out = wide_input_bus[ 87: 80];
+ 4\'hb: selected_out = wide_input_bus[ 95: 88];
+ 4\'hc: selected_out = wide_input_bus[103: 96];
+ 4\'hd: selected_out = wide_input_bus[111:104];
+ 4\'he: selected_out = wide_input_bus[119:112];
+ 4\'hf: selected_out = wide_input_bus[127:120];
+ endcase // case (selector)
+
+ end
+
+endmodule // simple_test_3b
+
+
+// A multiplexer in terms of unique case
+module simple_test_3c
+ (input logic [8*16-1:0] wide_input_bus,
+ input logic [3:0] selector,
+ output logic [7:0] selected_out);
+
+
+ always_comb begin
+ unique case (selector)
+ 4\'h0: selected_out = wide_input_bus[ 7: 0];
+ 4\'h1: selected_out = wide_input_bus[ 15: 8];
+ 4\'h2: selected_out = wide_input_bus[ 23: 16];
+ 4\'h3: selected_out = wide_input_bus[ 31: 24];
+ 4\'h4: selected_out = wide_input_bus[ 39: 32];
+ 4\'h5: selected_out = wide_input_bus[ 47: 40];
+ 4\'h6: selected_out = wide_input_bus[ 55: 48];
+ 4\'h7: selected_out = wide_input_bus[ 63: 56];
+ 4\'h8: selected_out = wide_input_bus[ 71: 64];
+ 4\'h9: selected_out = wide_input_bus[ 79: 72];
+ 4\'ha: selected_out = wide_input_bus[ 87: 80];
+ 4\'hb: selected_out = wide_input_bus[ 95: 88];
+ 4\'hc: selected_out = wide_input_bus[103: 96];
+ 4\'hd: selected_out = wide_input_bus[111:104];
+ 4\'he: selected_out = wide_input_bus[119:112];
+ 4\'hf: selected_out = wide_input_bus[127:120];
+ endcase // case (selector)
+
+ end
+
+endmodule // simple_test_3c
+
+
+// A multiplexer in terms of unique if
+module simple_test_3d
+ (input logic [8*16-1:0] wide_input_bus,
+ input logic [3:0] selector,
+ output logic [7:0] selected_out);
+
+
+ always_comb begin
+ unique if (selector == 4\'h0) selected_out = wide_input_bus[ 7: 0];
+ else if (selector == 4\'h1) selected_out = wide_input_bus[ 15: 8];
+ else if (selector == 4\'h2) selected_out = wide_input_bus[ 23: 16];
+ else if (selector == 4\'h3) selected_out = wide_input_bus[ 31: 24];
+ else if (selector == 4\'h4) selected_out = wide_input_bus[ 39: 32];
+ else if (selector == 4\'h5) selected_out = wide_input_bus[ 47: 40];
+ else if (selector == 4\'h6) selected_out = wide_input_bus[ 55: 48];
+ else if (selector == 4\'h7) selected_out = wide_input_bus[ 63: 56];
+ else if (selector == 4\'h8) selected_out = wide_input_bus[ 71: 64];
+ else if (selector == 4\'h9) selected_out = wide_input_bus[ 79: 72];
+ else if (selector == 4\'ha) selected_out = wide_input_bus[ 87: 80];
+ else if (selector == 4\'hb) selected_out = wide_input_bus[ 95: 88];
+ else if (selector == 4\'hc) selected_out = wide_input_bus[103: 96];
+ else if (selector == 4\'hd) selected_out = wide_input_bus[111:104];
+ else if (selector == 4\'he) selected_out = wide_input_bus[119:112];
+ else if (selector == 4\'hf) selected_out = wide_input_bus[127:120];
+ end
+
+endmodule // simple_test_3d
+
+
+// Test of priority case
+// Note: This does NOT try to implement the same function as above.
+module simple_test_3e
+ (input logic [8*16-1:0] wide_input_bus,
+ input logic [3:0] selector,
+ output logic [7:0] selected_out);
+
+
+ always_comb begin
+ priority case (1\'b1)
+ selector[0]: selected_out = wide_input_bus[ 7: 0]; // Bit 0 has highets priority
+ selector[2]: selected_out = wide_input_bus[ 39: 32]; // Note 2 higher priority than 1
+ selector[1]: selected_out = wide_input_bus[ 23: 16]; // Note 1 lower priority than 2
+ selector[3]: selected_out = wide_input_bus[ 71: 64]; // Bit 3 has lowest priority
+ default: selected_out = wide_input_bus[127:120]; // for selector = 0.
+ endcase // case (selector)
+
+ end
+
+endmodule // simple_test_3e
+
+
+// Test of ""inside""
+// Note: This does NOT try to implement the same function as above.
+// Note: Support for ""inside"" is a separate Verilator feature request, so is
+// not used inside a this version of the test.
+module simple_test_3f
+ (input logic [8*16-1:0] wide_input_bus,
+ input logic [3:0] selector,
+ output logic [7:0] selected_out);
+
+
+ always_comb begin
+/* -----\\/----- EXCLUDED -----\\/-----
+ if ( selector[3:0] inside { 4\'b?00?, 4\'b1100}) // Matching 0000, 0001, 1000, 1100, 1001
+\t// if ( selector[3:2] inside { 2\'b?0, selector[1:0]})
+ selected_out = wide_input_bus[ 7: 0];
+ else
+ -----/\\----- EXCLUDED -----/\\----- */
+ /* verilator lint_off CASEOVERLAP */
+ priority casez (selector[3:0])
+ 4\'b0?10: selected_out = wide_input_bus[ 15: 8]; // Matching 0010 and 0110
+ 4\'b0??0: selected_out = wide_input_bus[ 23: 16]; // Overlap: only 0100 remains (0000 in ""if"" above)
+ 4\'b0100: selected_out = wide_input_bus[ 31: 24]; // Overlap: Will never occur
+ default: selected_out = wide_input_bus[127:120]; // Remaining 0011,0100,0101,0111,1010,1011,1101,1110,1111
+\tendcase // case (selector)
+ /* verilator lint_on CASEOVERLAP */
+ end
+
+endmodule // simple_test_3f
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer j;
+ integer hit_count;
+ reg [63:0] cam_lookup_hit_vector;
+
+ strings strings ();
+
+ task show;
+ input [8*8-1:0] str;
+ reg [7:0] char;
+ integer \t loc;
+ begin
+\t $write(""[%0t] "",$time);
+\t strings.stringStart(8*8-1);
+\t for (char = strings.stringByte(str); !strings.isNull(char); char = strings.stringByte(str)) begin
+\t $write(""%c"",char);
+\t end
+\t $write(""\
+"");
+ end
+ endtask
+
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t show(""hello\\000xx"");
+\t end
+\t if (cyc==2) begin
+\t show(""world\\000xx"");
+\t end
+\t if (cyc==4) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+module strings;
+ // **NOT** reentrant, just a test!
+ integer index;
+ task stringStart;
+ input [31:0] bits;
+ begin
+\t index = (bits-1)/8;
+ end
+ endtask
+
+ function isNull;
+ input [7:0] chr;
+ isNull = (chr == 8\'h0);
+ endfunction
+
+ function [7:0] stringByte;
+ input [8*8-1:0] str;
+ begin
+\t if (index<=0) stringByte=8\'h0;
+\t else stringByte = str[index*8 +: 8];
+\t index = index - 1;
+ end
+ endfunction
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+
+ Testit testit (/*AUTOINST*/
+\t\t // Inputs
+\t\t .clk\t\t\t(clk));
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+ end
+ else if (cyc<10) begin
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Testit (clk);
+ input clk;
+
+ genvar igen;
+ generate
+ for (igen=0; igen<0; igen=igen+1) begin : test_gen
+\t always @ (posedge clk) begin
+\t $display(""igen1 = %d"", igen);
+\t $stop;
+\t end
+ end
+ endgenerate
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t;
+
+ // Check that the lint_on is obeyed.
+ // verilator lint_off VARHIDDEN
+ // verilator lint_on VARHIDDEN
+
+ integer top;
+
+ task x;
+ output top;
+ begin end
+ endtask
+
+ initial begin
+ begin: lower
+\t integer top;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ logic use_AnB;
+ logic [1:0] active_command [8:0];
+ logic [1:0] command_A [8:0];
+ logic [1:0] command_B [8:0];
+
+ logic [1:0] active_command2 [8:0];
+ logic [1:0] command_A2 [8:0];
+ logic [1:0] command_B2 [8:0];
+
+ logic [1:0] active_command3 [1:0][2:0][3:0];
+ logic [1:0] command_A3 [1:0][2:0][3:0];
+ logic [1:0] command_B3 [1:0][2:0][3:0];
+
+ logic [2:0] use_A4nB4;
+ logic [8:0][1:0] active_command4;
+ logic [8:0][1:0] command_A4;
+ logic [8:0][1:0] command_B4;
+
+ logic [8:0] pipe1\t [7:0];
+ logic [8:0] pipe1_input;
+
+ integer cyc;
+
+ assign active_command[8:0] = (use_AnB) ? command_A[8:0] : command_B[8:0];
+ assign active_command2 = (use_AnB) ? command_A2 : command_B2;
+ // Illegal to have [1:0][x:y] here - IEEE only allows single dimension slicing
+ assign active_command3[1:0] = (use_AnB) ? command_A3[1:0] : command_B3[1:0];
+
+ // Check we can cope with things other than packed arrays
+ assign active_command4 = (use_A4nB4[0]) ? command_A4 : command_B4;
+
+ always @ (posedge clk) begin
+ pipe1_input <= pipe1_input + 1;
+ pipe1[0] <= pipe1_input;
+ pipe1[7:1] <= pipe1[6:0];
+ end
+
+ logic [3:0][13:0] iq_read_data [15:0];
+ logic [3:0][13:0] iq_data;
+ logic [3:0] sel;
+
+ assign iq_data = iq_read_data[sel];
+
+ always @ (posedge clk) begin
+ sel = sel + 1;
+ end
+
+ initial begin
+ cyc = 0;
+ use_AnB = 0;
+ for (int i = 0; i < 7; ++i) begin
+\t command_A[i] = 2\'b00;
+\t command_B[i] = 2\'b11;
+\t command_A2[i] = 2\'b00;
+\t command_B2[i] = 2\'b11;
+\t pipe1_input = 9\'b0;
+ end
+ for (int i = 0; i < 2; ++i) begin
+\t for (int j = 0; j < 3; ++j) begin
+\t for (int k = 0; k < 4; ++k) begin
+\t command_A3[i][j][k] = 2\'b00;
+\t command_B3[i][j][k] = 2\'b11;
+\t end
+\t end
+ end
+ end
+
+ always @ (posedge clk) begin
+ use_AnB <= ~use_AnB;
+ cyc <= cyc + 1;
+ if (use_AnB) begin
+\t if (active_command[3] != 2\'b00) begin
+\t $stop;
+\t end
+\t if (active_command2[3] != 2\'b00) begin
+\t $stop;
+\t end
+\t if (active_command3[0][1][2] != 2\'b00) begin
+\t $stop;
+\t end
+ end
+ if (!use_AnB) begin
+\t if (active_command[3] != 2\'b11) begin
+\t $stop;
+\t end
+\t if (active_command2[3] != 2\'b11) begin
+\t $stop;
+\t end
+ end
+ end
+
+ logic [8:0] last_pipe;
+ always @(posedge clk) begin
+ if (cyc < 3) begin
+\t last_pipe <= pipe1[0];
+ end
+ else begin
+\t if (last_pipe + 1 != pipe1[0]) begin
+\t $stop;
+\t end
+\t else begin
+\t last_pipe <= pipe1[0];
+\t end
+ end
+ if (cyc > 10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule : t
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg [7:0] crc;
+
+ // Build up assignments
+ wire [7:0] bitrev;
+ assign bitrev[7] = crc[0];
+ assign bitrev[6] = crc[1];
+ assign bitrev[5] = crc[2];
+ assign bitrev[4] = crc[3];
+ assign bitrev[0] = crc[7];
+ assign bitrev[1] = crc[6];
+ assign bitrev[2] = crc[5];
+ assign bitrev[3] = crc[4];
+
+ // Build up always assignments
+ reg [7:0] bitrevb;
+ always @ (/*AS*/crc) begin
+ bitrevb[7] = crc[0];
+ bitrevb[6] = crc[1];
+ bitrevb[5] = crc[2];
+ bitrevb[4] = crc[3];
+ bitrevb[0] = crc[7];
+ bitrevb[1] = crc[6];
+ bitrevb[2] = crc[5];
+ bitrevb[3] = crc[4];
+ end
+
+ // Build up always assignments
+ reg [7:0] bitrevr;
+ always @ (posedge clk) begin
+ bitrevr[7] <= crc[0];
+ bitrevr[6] <= crc[1];
+ bitrevr[5] <= crc[2];
+ bitrevr[4] <= crc[3];
+ bitrevr[0] <= crc[7];
+ bitrevr[1] <= crc[6];
+ bitrevr[2] <= crc[5];
+ bitrevr[3] <= crc[4];
+ end
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc<=cyc+1;
+\t //$write(""cyc=%0d crc=%x r=%x\
+"", cyc, crc, bitrev);
+\t crc <= {crc[6:0], ~^ {crc[7],crc[5],crc[4],crc[3]}};
+\t if (cyc==1) begin
+\t crc <= 8\'hed;
+\t end
+\t if (cyc==2 && bitrev!=8\'hb7) $stop;
+\t if (cyc==3 && bitrev!=8\'h5b) $stop;
+\t if (cyc==4 && bitrev!=8\'h2d) $stop;
+\t if (cyc==5 && bitrev!=8\'h16) $stop;
+\t if (cyc==6 && bitrev!=8\'h8b) $stop;
+\t if (cyc==7 && bitrev!=8\'hc5) $stop;
+\t if (cyc==8 && bitrev!=8\'he2) $stop;
+\t if (cyc==9 && bitrev!=8\'hf1) $stop;
+\t if (bitrevb != bitrev) $stop;
+\t if (cyc==3 && bitrevr!=8\'hb7) $stop;
+\t if (cyc==4 && bitrevr!=8\'h5b) $stop;
+\t if (cyc==5 && bitrevr!=8\'h2d) $stop;
+\t if (cyc==6 && bitrevr!=8\'h16) $stop;
+\t if (cyc==7 && bitrevr!=8\'h8b) $stop;
+\t if (cyc==8 && bitrevr!=8\'hc5) $stop;
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Simple test of unoptflat
+//
+// Simple demonstration of an UNOPTFLAT combinatorial loop, using 3 bits.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Jeremy Bennett.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ wire [2:0] x;
+
+ initial begin
+ x = 3\'b000;
+ end
+
+ assign x[1:0] = { x[0], clk };
+ assign x[2:1] = { clk, x[1] };
+
+ always @(posedge clk or negedge clk) begin
+
+`ifdef TEST_VERBOSE
+ $write(""x = %x\
+"", x);
+`endif
+
+ if (x[1] != 0) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule // t
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ // surefire lint_off ASWEBB
+ // surefire lint_off ASWEMB
+ // surefire lint_off STMINI
+ // surefire lint_off CSEBEQ
+
+ input clk;
+
+ reg [7:0] a_to_clk_levm3;
+ reg [7:0] b_to_clk_levm1;
+ reg [7:0] c_com_levs10;
+ reg [7:0] d_to_clk_levm2;
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [7:0]\t\tm_from_clk_lev1_r;\t// From a of t_order_a.v
+ wire [7:0]\t\tn_from_clk_lev2;\t// From a of t_order_a.v
+ wire [7:0]\t\to_from_com_levs11;\t// From a of t_order_a.v
+ wire [7:0]\t\to_from_comandclk_levs12;// From a of t_order_a.v
+ wire [7:0]\t\to_subfrom_clk_lev2;\t// From b of t_order_b.v
+ // End of automatics
+
+ reg [7:0] cyc; initial cyc=0;
+
+ t_order_a a (
+\t\t.one\t\t\t(8\'h1),
+\t\t/*AUTOINST*/
+\t\t// Outputs
+\t\t.m_from_clk_lev1_r\t(m_from_clk_lev1_r[7:0]),
+\t\t.n_from_clk_lev2\t(n_from_clk_lev2[7:0]),
+\t\t.o_from_com_levs11\t(o_from_com_levs11[7:0]),
+\t\t.o_from_comandclk_levs12(o_from_comandclk_levs12[7:0]),
+\t\t// Inputs
+\t\t.clk\t\t\t(clk),
+\t\t.a_to_clk_levm3\t\t(a_to_clk_levm3[7:0]),
+\t\t.b_to_clk_levm1\t\t(b_to_clk_levm1[7:0]),
+\t\t.c_com_levs10\t\t(c_com_levs10[7:0]),
+\t\t.d_to_clk_levm2\t\t(d_to_clk_levm2[7:0]));
+
+ t_order_b b (
+\t\t/*AUTOINST*/
+\t\t// Outputs
+\t\t.o_subfrom_clk_lev2\t(o_subfrom_clk_lev2[7:0]),
+\t\t// Inputs
+\t\t.m_from_clk_lev1_r\t(m_from_clk_lev1_r[7:0]));
+
+ reg [7:0] o_from_com_levs12;
+ reg [7:0] o_from_com_levs13;
+ always @ (/*AS*/o_from_com_levs11) begin
+ o_from_com_levs12 = o_from_com_levs11 + 8\'h1;
+ o_from_com_levs12 = o_from_com_levs12 + 8\'h1; // Test we can add to self and optimize
+ o_from_com_levs13 = o_from_com_levs12;
+ end
+
+ reg \tsepassign_in;
+ // verilator lint_off UNOPTFLAT
+ wire [3:0] \tsepassign;
+ // verilator lint_on UNOPTFLAT
+
+ // verilator lint_off UNOPT
+ assign #0.1\tsepassign[0]\t= 0,
+ \t \tsepassign[1]\t= sepassign[2],
+ \t \tsepassign[2]\t= sepassign[3],
+ \t \tsepassign[3]\t= sepassign_in;
+ wire [7:0] \to_subfrom_clk_lev3 = o_subfrom_clk_lev2;
+ // verilator lint_on UNOPT
+
+ always @ (posedge clk) begin
+ cyc <= cyc+8\'d1;
+ sepassign_in <= 0;
+ if (cyc == 8\'d1) begin
+\t a_to_clk_levm3 <= 0;
+\t d_to_clk_levm2 <= 1;
+\t b_to_clk_levm1 <= 1;
+\t c_com_levs10 <= 2;
+\t sepassign_in <= 1;
+ end
+ if (cyc == 8\'d2) begin
+\t if (sepassign !== 4\'b1110) $stop;
+ end
+ if (cyc == 8\'d3) begin
+
+\t $display(""%d %d %d %d"",m_from_clk_lev1_r,
+\t\t n_from_clk_lev2,
+\t\t o_from_com_levs11,
+\t\t o_from_comandclk_levs12);
+
+\t if (m_from_clk_lev1_r !== 8\'h2) $stop;
+\t if (o_subfrom_clk_lev3 !== 8\'h2) $stop;
+\t if (n_from_clk_lev2 !== 8\'h2) $stop;
+\t if (o_from_com_levs11 !== 8\'h3) $stop;
+\t if (o_from_com_levs13 !== 8\'h5) $stop;
+\t if (o_from_comandclk_levs12 !== 8\'h5) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [31:0] in = crc[31:0];
+ wire \tnoswap = crc[32];
+ wire \tnibble = crc[33];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [31:0] \t\tout;\t\t\t// From test of Test.v
+ wire [31:0] \t\tswapped;\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[31:0]),
+\t .swapped\t\t\t(swapped[31:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .noswap\t\t\t(noswap),
+\t .nibble\t\t\t(nibble),
+\t .in\t\t\t(in[31:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {32\'h0, out};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t if (sum !== 64\'h89522c3f5e5ca324) $stop;
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out, swapped,
+ // Inputs
+ clk, noswap, nibble, in
+ );
+ input clk;
+
+ input noswap;
+ input nibble;
+
+ input [31:0] in;
+ output [31:0] out;
+ output [31:0] swapped;
+
+ function [7:0] EndianSwap;
+ input Nibble;
+ input [7:0] Data;
+ begin
+ EndianSwap = (Nibble ? { Data[0], Data[1], Data[2], Data[3],
+\t\t\t\t Data[4], Data[5], Data[6], Data[7] }
+ : { 4\'h0, Data[0], Data[1], Data[2], Data[3] });
+ end
+ endfunction
+
+ assign out[31:24] = (noswap ? in[31:24]
+\t\t\t: EndianSwap(nibble, in[31:24]));
+ assign out[23:16] = (noswap ? in[23:16]
+\t\t\t: EndianSwap(nibble, in[23:16]));
+ assign out[15:8] = (noswap ? in[15:8]
+\t\t\t: EndianSwap(nibble, in[15:8]));
+ assign out[7:0] = (noswap ? in[7:0]
+\t\t\t: EndianSwap(nibble, in[7:0]));
+
+ reg [31:0] swapped;
+ always @(posedge clk) begin
+ swapped[31:24] <= EndianSwap(nibble, in[31:24]);
+ swapped[23:16] <= EndianSwap(nibble, in[23:16]);
+ swapped[15:8] <= EndianSwap(nibble, in[15:8] );
+ swapped[7:0] <= EndianSwap(nibble, in[7:0] );
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// A test of the +verilog1995ext+ and +verilog2001ext+ flags.
+//
+// This source code contains constructs that are valid in Verilog 2001 and
+// SystemVerilog 2005/2009, but not in Verilog 1995. So it should fail if we
+// set the language to be 1995, but not 2001.
+//
+// Compile only test, so no need for ""All Finished"" output.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Jeremy Bennett.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ reg [1:0] \tres;
+
+ // Instantiate the test
+ test test_i (/*AUTOINST*/
+\t // Outputs
+\t .res\t\t\t(res),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(1\'b1));
+
+endmodule
+
+module test (// Outputs
+\t res,
+\t // Inputs
+\t clk,
+\t in
+ );
+ output [1:0] res;
+ input \t clk;
+ input \t in;
+
+ // This is a Verilog 2001 test
+ generate
+ genvar i;
+ for (i=0; i<2; i=i+1) begin
+\t always @(posedge clk) begin
+\t res[i:i] <= in;
+\t end
+ end
+ endgenerate
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+interface ifc;
+ integer value;
+endinterface
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+`ifdef INLINE_A //verilator inline_module
+`else //verilator no_inline_module
+`endif
+ input clk;
+ integer cyc=1;
+
+ ifc itop1a();
+ ifc itop1b();
+ ifc itop2a();
+ ifc itop2b();
+
+ wrapper c1 (.isuba(itop1a),
+\t\t.isubb(itop1b),
+\t\t.i_valuea(14),
+\t\t.i_valueb(15));
+ wrapper c2 (.isuba(itop2a),
+\t\t.isubb(itop2b),
+\t\t.i_valuea(24),
+\t\t.i_valueb(25));
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==20) begin
+\t if (itop1a.value != 14) $stop;
+\t if (itop1b.value != 15) $stop;
+\t if (itop2a.value != 24) $stop;
+\t if (itop2b.value != 25) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module wrapper
+ (
+ ifc isuba,
+ ifc isubb,
+ input integer i_valuea,
+ input integer i_valueb
+ );
+`ifdef INLINE_B //verilator inline_module
+`else //verilator no_inline_module
+`endif
+ lower subsuba (.isub(isuba), .i_value(i_valuea));
+ lower subsubb (.isub(isubb), .i_value(i_valueb));
+endmodule
+
+module lower
+ (
+ ifc isub,
+ input integer i_value
+ );
+`ifdef INLINE_C //verilator inline_module
+`else //verilator no_inline_module
+`endif
+ always @* begin
+ isub.value = i_value;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+ sub sub ();
+endmodule
+
+module sub #(parameter WIDTH=X, parameter X=WIDTH)
+ ();
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ reg [3:0] counter = 0;
+ integer l2;
+ function log2 (input [3:0] x);
+ integer log2 = (x < 2) ? 1 : (x < 4) ? 2 : (x < 8) ? 3 : 4;
+ endfunction
+ always @(posedge clk) begin
+ counter <= counter + 1;
+ l2 <= log2(counter);
+ // bug589: This failed with (%Error: Internal Error: Function not underneath a statement):
+ $display(""log2(%d) == %d"", counter, log2(counter));
+ //
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003-2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg [15:0] m_din;
+
+ // OK
+ reg [15:0] c_split_1, c_split_2, c_split_3, c_split_4, c_split_5;
+ always @ (posedge clk) begin
+ if (cyc==0) begin
+\t /*AUTORESET*/
+\t // Beginning of autoreset for uninitialized flops
+\t c_split_1 <= 16\'h0;
+\t c_split_2 <= 16\'h0;
+\t c_split_3 <= 16\'h0;
+\t c_split_4 <= 0;
+\t c_split_5 <= 0;
+\t // End of automatics
+ end
+ else begin
+\t c_split_1 <= m_din;
+\t c_split_2 <= c_split_1;
+\t c_split_3 <= c_split_2 & {16{(cyc!=0)}};
+\t if (cyc==1) begin
+\t c_split_4 <= 16\'h4;
+\t c_split_5 <= 16\'h5;
+\t end
+\t else begin
+\t c_split_4 <= c_split_3;
+\t c_split_5 <= c_split_4;
+\t end
+ end
+ end
+
+ // OK
+ reg [15:0] d_split_1, d_split_2;
+ always @ (posedge clk) begin
+ if (cyc==0) begin
+\t /*AUTORESET*/
+\t // Beginning of autoreset for uninitialized flops
+\t d_split_1 <= 16\'h0;
+\t d_split_2 <= 16\'h0;
+\t // End of automatics
+ end
+ else begin
+\t d_split_1 <= m_din;
+\t d_split_2 <= d_split_1;
+\t d_split_1 <= ~m_din;
+ end
+ end
+
+ // Not OK
+ always @ (posedge clk) begin
+ if (cyc==0) begin
+\t /*AUTORESET*/
+\t // Beginning of autoreset for uninitialized flops
+\t // End of automatics
+ end
+ else begin
+\t $write("" foo %x"", m_din);
+\t $write("" bar %x\
+"", m_din);
+ end
+ end
+
+ // Not OK
+ reg [15:0] e_split_1, e_split_2;
+ always @ (posedge clk) begin
+ if (cyc==0) begin
+\t /*AUTORESET*/
+\t // Beginning of autoreset for uninitialized flops
+\t e_split_1 = 16\'h0;
+\t e_split_2 = 16\'h0;
+\t // End of automatics
+ end
+ else begin
+\t e_split_1 = m_din;
+\t e_split_2 = e_split_1;
+ end
+ end
+
+ // Not OK
+ reg [15:0] f_split_1, f_split_2;
+ always @ (posedge clk) begin
+ if (cyc==0) begin
+\t /*AUTORESET*/
+\t // Beginning of autoreset for uninitialized flops
+\t f_split_1 = 16\'h0;
+\t f_split_2 = 16\'h0;
+\t // End of automatics
+ end
+ else begin
+\t f_split_2 = f_split_1;
+\t f_split_1 = m_din;
+ end
+ end
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t //$write("" C %d %x %x\
+"", cyc, c_split_1, c_split_2);
+\t cyc<=cyc+1;
+\t if (cyc==1) begin
+\t m_din <= 16\'hfeed;
+\t end
+\t if (cyc==3) begin
+\t end
+\t if (cyc==4) begin
+\t m_din <= 16\'he11e;
+\t if (!(d_split_1==16\'h0112 && d_split_2==16\'h0112)) $stop;
+\t if (!(e_split_1==16\'hfeed && e_split_2==16\'hfeed)) $stop;
+\t if (!(f_split_1==16\'hfeed && f_split_2==16\'hfeed)) $stop;
+\t end
+\t if (cyc==5) begin
+\t m_din <= 16\'he22e;
+\t if (!(d_split_1==16\'h0112 && d_split_2==16\'h0112)) $stop;
+\t // Two valid orderings, as we don\'t know which posedge clk gets evaled first
+\t if (!(e_split_1==16\'hfeed && e_split_2==16\'hfeed) && !(e_split_1==16\'he11e && e_split_2==16\'he11e)) $stop;
+\t if (!(f_split_1==16\'hfeed && f_split_2==16\'hfeed) && !(f_split_1==16\'he11e && f_split_2==16\'hfeed)) $stop;
+\t end
+\t if (cyc==6) begin
+\t m_din <= 16\'he33e;
+\t if (!(c_split_1==16\'he11e && c_split_2==16\'hfeed && c_split_3==16\'hfeed)) $stop;
+\t if (!(d_split_1==16\'h1ee1 && d_split_2==16\'h0112)) $stop;
+\t // Two valid orderings, as we don\'t know which posedge clk gets evaled first
+\t if (!(e_split_1==16\'he11e && e_split_2==16\'he11e) && !(e_split_1==16\'he22e && e_split_2==16\'he22e)) $stop;
+\t if (!(f_split_1==16\'he11e && f_split_2==16\'hfeed) && !(f_split_1==16\'he22e && f_split_2==16\'he11e)) $stop;
+\t end
+\t if (cyc==7) begin
+\t m_din <= 16\'he44e;
+\t if (!(c_split_1==16\'he22e && c_split_2==16\'he11e && c_split_3==16\'hfeed)) $stop;
+\t end
+\t if (cyc==8) begin
+\t m_din <= 16\'he55e;
+\t if (!(c_split_1==16\'he33e && c_split_2==16\'he22e && c_split_3==16\'he11e
+\t\t && c_split_4==16\'hfeed && c_split_5==16\'hfeed)) $stop;
+\t end
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+package pkg;
+ typedef enum bit [1:0]
+ {
+ E__NOT = 2\'b00,
+ E__VAL = 2\'b11
+ } E_t;
+endpackage
+
+module t;
+ reg [1:0] ttype;
+ reg \t m;
+
+ enum bit [1:0] { LOCAL } l;
+
+ always @ (m or 1\'b0 or LOCAL) begin
+ // Don\'t complain about constants in sensitivity lists
+ end
+
+ initial begin
+ ttype = pkg::E__NOT;
+ m = (ttype == pkg::E__VAL);
+ if (m != 1\'b0) $stop;
+
+ ttype = pkg::E__VAL;
+ m = (ttype == pkg::E__VAL);
+ if (m != 1\'b1) $stop;
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2009 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+`ifdef VCS
+ `define NO_SHORTREAL
+`endif
+`ifdef NC
+ `define NO_SHORTREAL
+`endif
+`ifdef VERILATOR // Unsupported
+ `define NO_SHORTREAL
+`endif
+
+module t (/*AUTOARG*/);
+
+ // Note these are NOT pure.
+ import ""DPI-C"" function int dpii_clear ();
+ import ""DPI-C"" function int dpii_count (input int ctr);
+ import ""DPI-C"" function bit dpii_inc0 (input int ctr);
+ import ""DPI-C"" function bit dpii_inc1 (input int ctr);
+ import ""DPI-C"" function bit dpii_incx (input int ctr, input bit value);
+
+ integer i;
+ integer j;
+ integer k;
+ bit \t b;
+ integer errors;
+
+ task check1(integer line, bit got, bit ex);
+ if (got != ex) begin
+\t $display(""%%Error: Line %0d: Bad result, got=%0d expect=%0d"",line,got,ex);
+\t errors++;
+ end
+ endtask
+ task check(integer line, int got, int ex);
+ if (got != ex) begin
+\t $display(""%%Error: Line %0d: Bad result, got=%0d expect=%0d"",line,got,ex);
+\t errors++;
+ end
+ endtask
+
+ // Test loop
+ initial begin
+ // bug963
+ dpii_clear();
+ j = 0;
+ for (i=0; i<64; i++) begin
+\t if (i[0])
+\t j = 0;
+\t else
+\t j = {31\'b0, dpii_inc1(0)};
+\t k = k + j;
+ end
+ $write(""%x\
+"",k);
+ check (`__LINE__, dpii_count(0), 32);
+
+ if (|errors) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2011 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+`define is_near_real(a,b) ($abs((a)-(b)) < (((a)/(b))*0.0001))
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer i;
+ reg [63:0] b;
+ real r, r2;
+ integer \tcyc=0;
+
+ realtime uninit;
+ initial if (uninit != 0.0) $stop;
+
+ sub_cast_bug374 sub (.cyc5(cyc[4:0]), .*);
+
+ initial begin
+ if (1_00_0.0_1 != 1000.01) $stop;
+ // rtoi truncates
+ if ($rtoi(36.7) != 36) $stop;
+ if ($rtoi(36.5) != 36) $stop;
+ if ($rtoi(36.4) != 36) $stop;
+ // casting rounds
+ if ((integer \'(36.7)) != 37) $stop;
+ if ((integer \'(36.5)) != 37) $stop;
+ if ((integer \'(36.4)) != 36) $stop;
+ // assignment rounds
+ // verilator lint_off REALCVT
+ i = 36.7; if (i != 37) $stop;
+ i = 36.5; if (i != 37) $stop;
+ i = 36.4; if (i != 36) $stop;
+ r = 10\'d38; if (r!=38.0) $stop;
+ // verilator lint_on REALCVT
+ // operators
+ if ((-(1.5)) != -1.5) $stop;
+ if ((+(1.5)) != 1.5) $stop;
+ if (((1.5)+(1.25)) != 2.75) $stop;
+ if (((1.5)-(1.25)) != 0.25) $stop;
+ if (((1.5)*(1.25)) != 1.875) $stop;
+ if (((1.5)/(1.25)) != 1.2) $stop;
+ //
+ if (((1.5)==(2)) != 1\'b0) $stop; // note 2 becomes real 2.0
+ if (((1.5)!=(2)) != 1\'b1) $stop;
+ if (((1.5)> (2)) != 1\'b0) $stop;
+ if (((1.5)>=(2)) != 1\'b0) $stop;
+ if (((1.5)< (2)) != 1\'b1) $stop;
+ if (((1.5)<=(2)) != 1\'b1) $stop;
+ if (((1.5)==(1.5)) != 1\'b1) $stop;
+ if (((1.5)!=(1.5)) != 1\'b0) $stop;
+ if (((1.5)> (1.5)) != 1\'b0) $stop;
+ if (((1.5)>=(1.5)) != 1\'b1) $stop;
+ if (((1.5)< (1.5)) != 1\'b0) $stop;
+ if (((1.5)<=(1.5)) != 1\'b1) $stop;
+ if (((1.6)==(1.5)) != 1\'b0) $stop;
+ if (((1.6)!=(1.5)) != 1\'b1) $stop;
+ if (((1.6)> (1.5)) != 1\'b1) $stop;
+ if (((1.6)>=(1.5)) != 1\'b1) $stop;
+ if (((1.6)< (1.5)) != 1\'b0) $stop;
+ if (((1.6)<=(1.5)) != 1\'b0) $stop;
+ //
+ if (((0.0)?(2.0):(1.1)) != 1.1) $stop;
+ if (((1.5)?(2.0):(1.1)) != 2.0) $stop;
+ //
+ if (!1.7) $stop;
+ if (!(!0.0)) $stop;
+ if (1.8 && 0.0) $stop;
+ if (!(1.8 || 0.0)) $stop;
+ //
+ i=0;
+ for (r=1.0; r<2.0; r=r+0.1) i++;
+ if (i!=10) $stop;
+ end
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+\t // Setup
+ end
+ else if (cyc<90) begin
+\t if ($time != {32\'h0, $rtoi($realtime)}) $stop;
+\t if ($itor(cyc) != cyc) $stop;
+\t //Unsup: if ((real `($time)) != $realtime) $stop;
+\t r = $itor(cyc*2);
+\t i = $rtoi(r);
+\t if (i!=cyc*2) $stop;
+\t //
+\t r = $itor(cyc)/1.5;
+\t b = $realtobits(r);
+\t r2 = $bitstoreal(b);
+\t if (r != r2) $stop;
+\t //
+\t // Trust the integer math as a comparison
+\t r = $itor(cyc);
+\t if ($rtoi(-r) != -cyc) $stop;
+\t if ($rtoi(+r) != cyc) $stop;
+\t if ($rtoi(r+2.0) != (cyc+2)) $stop;
+\t if ($rtoi(r-2.0) != (cyc-2)) $stop;
+\t if ($rtoi(r*2.0) != (cyc*2)) $stop;
+\t if ($rtoi(r/2.0) != (cyc/2)) $stop;
+\t r2 = (2.0/(r-60)); // When zero, result indeterminate, but no crash
+\t //
+\t r2 = $itor(cyc);
+\t case (r)
+\t (r2-1.0): $stop;
+\t r2: ;
+\t default: $stop;
+\t endcase
+\t //
+\t r = $itor(cyc);
+\t if ((r==50.0) != (cyc==50)) $stop;
+\t if ((r!=50.0) != (cyc!=50)) $stop;
+\t if ((r> 50.0) != (cyc> 50)) $stop;
+\t if ((r>=50.0) != (cyc>=50)) $stop;
+\t if ((r< 50.0) != (cyc< 50)) $stop;
+\t if ((r<=50.0) != (cyc<=50)) $stop;
+\t //
+\t if ($rtoi((r-50.0) ? 10.0 : 20.0)
+\t != (((cyc-50)!=0) ? 10 : 20)) $stop;
+\t //
+\t if ((!(r-50.0)) != (!((cyc-50) != 0))) $stop;
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module sub_cast_bug374(input clk, input [4:0] cyc5);
+ integer i;
+
+ always @(posedge clk) begin
+ i <= integer\'(cyc5);
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Aggregate outputs into a single result vector
+ //wire [31:0] \tpow32b = {24\'h0,crc[15:8]}**crc[7:0]; // Overflows
+ wire [3:0] \tpow4b = crc[7:4]**crc[3:0];
+ wire [63:0] \tresult = {60\'h0, pow4b};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h1fec4b2b71cf8024
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ passed,
+ // Inputs
+ clk, fastclk, reset_l
+ );
+
+ input clk /*verilator sc_clock*/;
+ input fastclk /*verilator sc_clock*/;
+ input reset_l;
+ output passed;
+
+ reg [31:0] count_c;
+ reg [31:0] count_f;
+
+ always @ (posedge clk) begin
+ if (!reset_l) begin
+\t /*AUTORESET*/
+\t // Beginning of autoreset for uninitialized flops
+\t count_c <= 32'h0;
+\t // End of automatics
+ end else begin
+\t count_c <= count_c + 1;
+ end
+ end
+
+ always @ (posedge fastclk) begin
+ if (!reset_l) begin
+\t /*AUTORESET*/
+\t // Beginning of autoreset for uninitialized flops
+\t count_f <= 32'h0;
+\t passed <= 1'h0;
+\t // End of automatics
+ end else begin
+\t count_f <= count_f + 1;
+\t if (count_f == 5) passed <= 1'b1;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Simple test of unoptflat
+//
+// Trigger the DETECTARRAY error on packed structure.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Jie Xu.
+
+localparam ID_MSB = 1;
+
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk,
+ res
+ );
+ input clk;
+ output [8:0][8:0] res;
+
+ logic a = 1\'b1;
+ logic [8:0] b [8:0]; // where the error is reported
+ logic [8:0][8:0] c; // where the error is reported
+
+ // following just to make c as circular
+ assign c[0] = c[0] | a << 1;
+ assign b[0] = b[0] | a << 2;
+
+ assign res[0] = c[0];
+ assign res[1] = b[0];
+
+
+ always @(posedge clk or negedge clk) begin
+
+ if (res != 0) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t;
+
+ integer p_i;
+ reg [7*8:1] p_str;
+
+ initial begin
+ if ($test$plusargs(""PLUS"")!==1) $stop;
+ if ($test$plusargs(""PLUSNOT"")!==0) $stop;
+ if ($test$plusargs(""PL"")!==1) $stop;
+ //if ($test$plusargs("""")!==1) $stop; // Simulators differ in this answer
+ if ($test$plusargs(""NOTTHERE"")!==0) $stop;
+
+ p_i = 10;
+ if ($value$plusargs(""NOTTHERE%d"", p_i)!==0) $stop;
+ if (p_i !== 10) $stop;
+
+ if ($value$plusargs(""INT=%d"", p_i)!==1) $stop;
+ if (p_i !== 32\'d1234) $stop;
+
+ if ($value$plusargs(""INT=%H"", p_i)!==1) $stop; // tests uppercase % also
+ if (p_i !== 32\'h1234) $stop;
+
+ if ($value$plusargs(""INT=%o"", p_i)!==1) $stop;
+ if (p_i !== 32\'o1234) $stop;
+
+ if ($value$plusargs(""IN%s"", p_str)!==1) $stop;
+ $display(""str=\'%s\'"",p_str);
+ if (p_str !== ""T=1234"") $stop;
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ integer \tcyc=0;
+
+ reg [7:0] crc;
+ genvar g;
+
+ wire [7:0] \tout_p1;
+ wire [15:0] \tout_p2;
+ wire [7:0] \tout_p3;
+ wire [7:0] \tout_p4;
+
+ paramed #(.WIDTH(8), .MODE(0)) p1 (.in(crc), .out(out_p1));
+ paramed #(.WIDTH(16), .MODE(1)) p2 (.in({crc,crc}), .out(out_p2));
+ paramed #(.WIDTH(8), .MODE(2)) p3 (.in(crc), .out(out_p3));
+ gencase #(.MODE(3)) \t p4 (.in(crc), .out(out_p4));
+
+ wire [7:0] \tout_ef;
+ enflop #(.WIDTH(8)) enf (.a(crc), .q(out_ef), .oe_e1(1\'b1), .clk(clk));
+
+ always @ (posedge clk) begin
+ //$write(""[%0t] cyc==%0d crc=%b %x %x %x %x %x\
+"",$time, cyc, crc, out_p1, out_p2, out_p3, out_p4, out_ef);
+ cyc <= cyc + 1;
+ crc <= {crc[6:0], ~^ {crc[7],crc[5],crc[4],crc[3]}};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 8\'hed;
+ end
+ else if (cyc==1) begin
+ end
+ else if (cyc==3) begin
+\t if (out_p1 !== 8\'h2d) $stop;
+\t if (out_p2 !== 16\'h2d2d) $stop;
+\t if (out_p3 !== 8\'h78) $stop;
+\t if (out_p4 !== 8\'h44) $stop;
+\t if (out_ef !== 8\'hda) $stop;
+ end
+ else if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module gencase (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ in
+ );
+ parameter MODE = 0;
+ input [7:0] in;
+ output [7:0] out;
+ generate // : genblk1
+ begin
+\t case (MODE)
+\t 2: mbuf mc [7:0] (.q(out[7:0]), .a({in[5:0],in[7:6]}));
+\t default: mbuf mc [7:0] (.q(out[7:0]), .a({in[3:0],in[3:0]}));
+\t endcase
+ end
+ endgenerate
+
+endmodule
+
+module paramed (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ in
+ );
+ parameter WIDTH = 1;
+ parameter MODE = 0;
+ input [WIDTH-1:0] in;
+ output [WIDTH-1:0] out;
+
+ generate
+ if (MODE==0) initial $write(""Mode=0\
+"");
+ // No else
+ endgenerate
+
+`ifndef NC // for(genvar) unsupported
+ `ifndef ATSIM // for(genvar) unsupported
+ generate
+ // Empty loop body, local genvar
+ for (genvar j=0; j<3; j=j+1) begin end
+ // Ditto to make sure j has new scope
+ for (genvar j=0; j<5; j=j+1) begin end
+ endgenerate
+ `endif
+`endif
+
+ generate
+ endgenerate
+
+ genvar \t i;
+ generate
+ if (MODE==0) begin
+\t // Flip bitorder, direct assign method
+\t for (i=0; i> ((`MUX1_SIZE*`MUX2_SIZE*j)+addr);
+\t /* verilator lint_on WIDTH */
+ end
+ end
+
+ // Run the test loop. This just increments the address
+ integer i, result;
+ always @ (posedge clk) begin
+ // initial the input data with random values
+ if (addr == 0) begin
+\t result = 1;
+\t datai = 0;
+\t for(i=0; i<`MUX1_SIZE*`MUX2_SIZE; i=i+1) begin
+\t /* verilator lint_off WIDTH */
+\t datai = (datai << `DATA_WIDTH) | ($random & {`DATA_WIDTH{1\'b1}});
+\t /* verilator lint_on WIDTH */
+\t end
+ end
+
+ addr <= addr + 1;
+ if (datao_check != datao) begin
+\t result = 0;
+\t $stop;
+ end
+
+ $write(""Addr=%d datao_check=%d datao=%d\
+"", addr, datao_check, datao);
+ // only run the first 10 addresses for now
+ if (addr > 10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module mux4096
+ (input [`DATA_WIDTH*`MUX1_SIZE*`MUX2_SIZE-1:0] datai,
+ input [`ADDR_WIDTH-1:0] addr,
+ output [`DATA_WIDTH-1:0] datao
+ );
+
+ // DATA_WIDTH instantiations of mux4096_1bit
+ mux4096_1bit mux4096_1bit[`DATA_WIDTH-1:0]
+ (.addr(addr),
+ .datai(datai),
+ .datao(datao)
+ );
+endmodule
+
+module mux4096_1bit
+ (input [`MUX1_SIZE*`MUX2_SIZE-1:0] datai,
+ input [`ADDR_WIDTH-1:0] addr,
+ output datao
+ );
+
+ // address decoding
+ wire [3:0] A = (4\'b1) << addr[1:0];
+ wire [3:0] B = (4\'b1) << addr[3:2];
+ wire [3:0] C = (4\'b1) << addr[5:4];
+ wire [3:0] D = (4\'b1) << addr[7:6];
+ wire [3:0] E = (4\'b1) << addr[9:8];
+ wire [3:0] F = (4\'b1) << addr[11:10];
+
+ wire [`MUX2_SIZE-1:0] data0;
+
+ // DATA_WIDTH*(MUX2_SIZE)*MUX1_SIZE instantiations of mux64
+ // first stage of 64:1 muxing
+ mux64 #(.MUX_SIZE(`MUX1_SIZE)) mux1[`MUX2_SIZE-1:0]
+ (.A(A),
+ .B(B),
+ .C(C),
+ .datai(datai),
+ .datao(data0));
+
+ // DATA_WIDTH*MUX2_SIZE instantiations of mux64
+ // second stage of 64:1 muxing
+ mux64 #(.MUX_SIZE(`MUX2_SIZE)) mux2
+ (.A(D),
+ .B(E),
+ .C(F),
+ .datai(data0),
+ .datao(datao));
+
+endmodule
+
+module mux64
+ #(parameter MUX_SIZE=64)
+ (input [3:0] A,
+ input [3:0] B,
+ input [3:0] C,
+ input [MUX_SIZE-1:0] datai,
+ output datao
+ );
+
+ wire [63:0] colSelA = { 16{ A[3:0] }};
+ wire [63:0] colSelB = { 4{ {4{B[3]}}, {4{B[2]}}, {4{B[1]}}, {4{B[0]}}}};
+ wire [63:0] colSelC = { {16{C[3]}}, {16{C[2]}}, {16{C[1]}}, {16{C[0]}}};
+
+ wire [MUX_SIZE-1:0] data_bus;
+
+ // Note each of these becomes a separate wire.
+ //.colSelA(colSelA[MUX_SIZE-1:0]),
+ //.colSelB(colSelB[MUX_SIZE-1:0]),
+ //.colSelC(colSelC[MUX_SIZE-1:0]),
+
+ drv drv[MUX_SIZE-1:0]
+ (.colSelA(colSelA[MUX_SIZE-1:0]),
+ .colSelB(colSelB[MUX_SIZE-1:0]),
+ .colSelC(colSelC[MUX_SIZE-1:0]),
+ .datai(datai),
+ .datao(data_bus)
+ );
+
+ assign datao = |data_bus;
+
+endmodule
+
+module drv
+ (input colSelA,
+ input colSelB,
+ input colSelC,
+ input datai,
+ output datao
+ );
+ assign datao = colSelC & colSelB & colSelA & datai;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // verilator lint_off LITENDIAN
+ wire [10:41] sel2 = crc[31:0];
+ wire [10:100] sel3 = {crc[26:0],crc};
+
+ wire\t\t out20 = sel2[{1\'b0,crc[3:0]} + 11];
+ wire [3:0] \t out21 = sel2[13 : 16];
+ wire [3:0] \t out22 = sel2[{1\'b0,crc[3:0]} + 20 +: 4];
+ wire [3:0] \t out23 = sel2[{1\'b0,crc[3:0]} + 20 -: 4];
+
+ wire\t\t out30 = sel3[{2\'b0,crc[3:0]} + 11];
+ wire [3:0] \t out31 = sel3[13 : 16];
+ wire [3:0] \t out32 = sel3[crc[5:0] + 20 +: 4];
+ wire [3:0] \t out33 = sel3[crc[5:0] + 20 -: 4];
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] \t result = {38\'h0, out20, out21, out22, out23, out30, out31, out32, out33};
+
+ reg [19:50] sel1;
+ initial begin
+ // Path clearing
+ // 122333445
+ // 826048260
+ sel1 = 32\'h12345678;
+ if (sel1 != 32\'h12345678) $stop;
+ if (sel1[47 : 50] != 4\'h8) $stop;
+ if (sel1[31 : 34] != 4\'h4) $stop;
+ if (sel1[27 +: 4] != 4\'h3) $stop; //==[27:30], in memory as [23:20]
+ if (sel1[26 -: 4] != 4\'h2) $stop; //==[23:26], in memory as [27:24]
+ end
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] sels=%x,%x,%x,%x %x,%x,%x,%x\
+"",$time, out20,out21,out22,out23, out30,out31,out32,out33);
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+`define EXPECTED_SUM 64\'h28bf65439eb12c00
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Test for using DPI as general accessors
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012.
+//
+// Contributed by Jeremy Bennett and Jie Xul
+//
+// This test exercises the use of DPI to access signals and registers in a
+// module hierarchy in a uniform fashion. See the discussion at
+//
+// http://www.veripool.org/boards/3/topics/show/752-Verilator-Command-line-specification-of-public-access-to-variables
+//
+// We need to test read and write access to:
+// - scalars
+// - vectors
+// - array elements
+// - slices of vectors or array elements
+//
+// We need to test that writing to non-writable elements generates an error.
+//
+// This Verilog would run forever. It will be stopped externally by the C++
+// instantiating program.
+
+
+// Define the width of registers and size of memory we use
+`define REG_WIDTH 8
+`define MEM_SIZE 256
+
+
+// Top module defines the accessors and instantiates a sub-module with
+// substantive content.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ `include ""t_dpi_accessors_macros_inc.vh""
+ `include ""t_dpi_accessors_inc.vh""
+
+ // Put the serious stuff in a sub-module, so we can check hierarchical
+ // access works OK.
+ test_sub i_test_sub (.clk (clk));
+
+endmodule // t
+
+
+// A sub-module with all sorts of goodies we would like to access
+
+module test_sub (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer i;\t\t// General counter
+
+ // Elements we would like to access from outside
+ reg \t a;
+ reg [`REG_WIDTH - 1:0] b;
+ reg [`REG_WIDTH - 1:0] mem [`MEM_SIZE - 1:0];
+ wire \t\t c;
+ wire [`REG_WIDTH - 1:0] d;
+ reg [`REG_WIDTH - 1:0] e;
+ reg [`REG_WIDTH - 1:0] f;
+
+ // Drive our wires from our registers
+ assign c = ~a;
+ assign d = ~b;
+
+ // Initial values for registers and array
+ initial begin
+ a = 0;
+ b = `REG_WIDTH\'h0;
+
+ for (i = 0; i < `MEM_SIZE; i++) begin
+\t mem[i] = i [`REG_WIDTH - 1:0];
+ end
+
+ e = 0;
+ f = 0;
+ end
+
+ // Wipe out one memory cell in turn on the positive clock edge, restoring
+ // the previous element. We toggle the wipeout value.
+ always @(posedge clk) begin
+ mem[b] <= {`REG_WIDTH {a}};
+ mem[b - 1] <= b - 1;
+ a <= ~a;
+ b <= b + 1;
+ end
+
+endmodule // test_sub
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+typedef struct packed {
+ bit \t b9;
+ byte\t b1;
+ bit \t b0;
+} pack_t;
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ pack_t in;
+ always @* in = crc[9:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ pack_t\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out),
+\t // Inputs
+\t .in\t\t\t(in));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {54\'h0, out};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x in=%x result=%x\
+"",$time, cyc, crc, in, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h99c434d9b08c2a8a
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (
+\t input pack_t in,
+\t output pack_t out);
+
+ always @* begin
+ out = in;
+ out.b1 = in.b1 + 1;
+ out.b0 = 1\'b1;
+ end
+endmodule
+
+// Local Variables:
+// verilog-typedef-regexp: ""_t$""
+// End:
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+interface ifc;
+ integer value;
+ modport i (output value);
+ modport o (input value);
+endinterface
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ integer cyc=1;
+
+ ifc itop1a(),
+ itop1b();
+
+ wrapper c1 (.isuba(itop1a),
+\t\t.isubb(itop1b),
+\t\t.i_valuea(14),
+\t\t.i_valueb(15));
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==20) begin
+\t if (itop1a.value != 14) $stop;
+\t if (itop1b.value != 15) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module wrapper
+ (
+ ifc.i isuba, isubb,
+ input integer i_valuea, i_valueb
+ );
+ always @* begin
+ isuba.value = i_valuea;
+ isubb.value = i_valueb;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); fail=\'1; end while(0)
+`define checkf(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=%f exp=%f\
+"", `__FILE__,`__LINE__, (gotv), (expv)); fail=\'1; end while(0)
+`ifdef VERILATOR
+ `define c(v,vs) ($c(vs)) // Don\'t constify a value
+`else
+ `define c(v,vs) (v)
+`endif
+
+ module t (/*AUTOARG*/
+ // Outputs
+ ow4_u
+ );
+
+ bit fail;
+
+ reg signed [3:0] w4_s;
+ reg signed [4:0] w5_s;
+ reg [2:0] \t w3_u;
+ reg [3:0] \t w4_u;
+ reg [4:0] \t w5_u;
+ reg [5:0] \t w6_u;
+ reg [15:0] \t w16a_u;
+ reg [15:0] \t w16_u;
+ reg [31:0] \t w32_u;
+ real \t r;
+
+ reg signed [4:0] bug754_a;
+
+ integer \t i;
+
+ //verilator lint_off WIDTH
+ wire a = (5\'b0 == (5\'sb11111 >>> 3\'d7));
+ wire b = (5\'sb11111 == (5\'sb11111 >>> 3\'d7));
+ wire c = (1\'b0+(5\'sb11111 >>> 3\'d7));
+ wire d = (1\'sb0+(5\'sb11111 >>> 3\'d7));
+ wire e = (5\'b0 == (5\'sb11111 / 5\'sd3));
+ wire f = (5\'sb0 == (5\'sb11111 / 5\'sd3));
+ wire g = (5\'b01010 == (5\'b11111 / 5\'sd3));
+ initial begin
+ // verilator lint_off STMTDLY
+ #1;
+`ifdef VCS // I-2014.03
+ `checkh({a, b, c, d, e, f, g}, 7\'b1101111);
+`else
+ `checkh({a, b, c, d, e, f, g}, 7\'b1101011);
+`endif
+
+ //======================================================================
+
+ if ((-1 >>> 3) != -1) $stop;\t// Decimals are signed
+
+ i = 3\'sb111 >>> 3;
+ `checkh(i, -1);
+ i = -1 >>> 3;
+ `checkh(i, -1);
+
+ bug754_a = -1;
+ w4_u = |0 != (bug754_a >>> 3\'d7);
+ `checkh(w4_u, 4\'b0);
+
+ // Sanity check: -1>>7 == -1
+ w5_u = (5\'sb11111 >>> 3\'d7);
+ `checkh(w5_u, 5\'b11111);
+
+ // bug756
+ w4_u = (5\'b0 == (5\'sb11111 >>> 3\'d7));
+ `checkh(w4_u, 4\'b0001);
+ w4_u = ((5\'b0 == (5\'sb11111 >>> 3\'d7))); // Exp 0 Vlt 0
+ `checkh(w4_u, 4\'b0001);
+ w4_u = ((5\'b01111 == (5\'sb11111 / 5\'sd2))); // Strength-reduces to >>>
+`ifdef VCS // I-2014.03
+ `checkh(w4_u, 4\'b0000); // Wrong, gets 5\'b0==..., unsigned does not propagate
+`else
+ `checkh(w4_u, 4\'b0001); // NC-Verilog, Modelsim, XSim, ...
+`endif
+
+ // Does == sign propagate from lhs to rhs? Yes, but not in VCS
+ w4_u = ((5\'b01010 == (5\'sb11111 / 5\'sd3))); // Exp 0 Vlt 0 // Must be signed result (-1/3) to make this result zero
+`ifdef VCS // I-2014.03
+ `checkh(w4_u, 4\'b0000); // Wrong, gets 5\'b0==..., unsigned does not propagate
+`else
+ `checkh(w4_u, 4\'b0001); // NC-Verilog, Modelsim, XSim, ...
+`endif
+
+ w4_u = (1\'b0+(5\'sb11111 >>> 3\'d7)); // Exp 00000 Vlt 000000 Actually the signedness of result does NOT matter
+ `checkh(w4_u, 4\'b0000);
+
+ w4_u = (5\'sb0 == (5\'sb11111 / 5\'sd3)); // Must be signed result (-1/3) to make this result zero
+ `checkh(w4_u, 4\'b0001);
+ // Does == width propagate from lhs to rhs? Yes
+ w4_u = (3\'b100==(3\'b111 << 2));
+ `checkh(w4_u, 4\'b0001);
+ w4_u = (4\'b100==(3\'b111 << 2));
+ `checkh(w4_u, 4\'b0000);
+ w4_u = (4\'b1100==(3\'b111 << 2));
+ `checkh(w4_u, 4\'b0001);
+
+ // Does >>> sign propagate from input same as for +? Yes
+ w4_u = (1\'b0+(5\'sb11111 >>> 3\'d7));
+ `checkh(w4_u, 4\'b0000);
+ w4_u = (1\'sb0+(5\'sb11111 >>> 3\'d7));
+ `checkh(w4_u, 4\'b1111);
+
+ // Does << width propagate from input same as for +? Yes
+ w4_u = (3\'b0+(3\'b111 << 2));
+ `checkh(w4_u, 4\'b1100); // width 4 ==\'s LHS
+ w4_u = (4\'b0+(3\'b111 << 2));
+ `checkh(w4_u, 4\'b1100);
+
+ w4_u = (5\'sb11111 == (5\'sb11111 >>> 3\'d7)); // WHAT? Signedness does propagate across ==?????
+ `checkh(w4_u, 4\'b0001);
+ w4_u = ((5\'b0 == (5\'sb11111 >>> 3\'d7)));
+ `checkh(w4_u, 4\'b0001);
+
+ // bug756
+ w5_s = -1;
+ w3_u = 7;
+ w4_u = |0 != (w5_s >>> w3_u);
+ `checkh(w4_u, 4\'b0000);
+
+ // bug763
+ w3_u = 2;
+ w4_u = (w3_u >> 2\'b11) >> 1;
+ `checkh(w4_u, 4\'b0000);
+
+ // bug766
+ w16a_u = 16\'h1234;
+ w16_u = (w16a_u >> 16) >>> 32\'h7ffffff1;
+ `checkh(w16_u, 16\'h0000);
+
+ // bug768
+ w4_s = 4\'sd4;
+ w4_u = $signed(5\'d1 > w4_s-w4_s);
+ `checkh(w4_u, 4\'b1111);
+ w4_s = `c(4,""4""); // Eval at runtime
+ w4_u = $signed(5\'d1 > w4_s-w4_s);
+ `checkh(w4_u, 4\'b1111);
+
+ // bug772
+ w4_s = w4_u << 1 <<< 0/0;
+`ifndef VERILATOR // In v4 can\'t check value as not 4-state
+ `checkh(w4_s, 4\'bxxxx);
+`endif
+
+ // bug773
+ w5_u = `c(31, 31);
+ w5_s = w5_u >> ((w5_u ? 1 : 2) << w5_u);
+ `checkh(w5_s, 5\'b0);
+
+ // bug774
+ w4_u = `c(4, 5);
+ w6_u = `c(6, 35);
+ w4_u = 64\'d0 | (w4_u << w6_u);
+ `checkh(w4_u, 0);
+
+ // bug776
+ w4_u = `c(4, 1);
+ w4_u = (w4_u >> w4_u) ^~ (w4_u >> w4_u);
+ `checkh(w4_u, 4\'b1111);
+
+ // bug828
+ // verilator lint_off WIDTH
+ w32_u = 32\'(signed\'({4\'b0001,5\'b10000}) << 3);
+ `checkh(w32_u, 32\'h0000_0180);
+ w32_u = 32\'(signed\'({4\'b0011,5\'b10000}) << 3);
+ `checkh(w32_u, 32\'h0000_0380);
+ w32_u = signed\'(32\'({4\'b0001,5\'b10000}) << 3);
+ `checkh(w32_u, 32\'h0000_0180);
+ w32_u = signed\'(32\'({4\'b0011,5\'b10000}) << 3);
+ `checkh(w32_u, 32\'h0000_0380);
+ // verilator lint_on WIDTH
+ w32_u = 32\'(signed\'({4\'b0011,5\'b10000})) << 3; // Check no width warning
+ `checkh(w32_u, 32\'h0000_0380);
+
+ if (fail) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ // bug775
+ output [3:0] ow4_u; // Must be consumed
+ assign ow4_u = ((0/0) ? 1 : 2) % 0;
+
+endmodule
+"
+"// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Lane Brooks
+
+`define WIDTH 2
+
+module top (
+ input OE1,
+ input OE2,
+ input [`WIDTH-1:0] A1,
+ input [`WIDTH-1:0] A2,
+ output [`WIDTH-1:0] Y1,
+ output [`WIDTH-1:0] Y2,
+ output [`WIDTH-1:0] Y3,
+ output [`WIDTH**2-1:0] W);
+
+ assign W[A1] = (OE2) ? A2[0] : 1'bz;
+ assign W[A2] = (OE1) ? A2[1] : 1'bz;
+
+ // have 2 different 'chips' drive the PAD to act like a bi-directional bus
+ wire [`WIDTH-1:0] PAD;
+ io_ring io_ring1 (.OE(OE1), .A(A1), .O(Y1), .PAD(PAD));
+ io_ring io_ring2 (.OE(OE2), .A(A2), .O(Y2), .PAD(PAD));
+
+ assign Y3 = PAD;
+
+ pullup p1(PAD);
+// pulldown p1(PAD);
+
+
+ wire [5:0] \t fill = { 4'b0, A1 };
+
+endmodule
+
+module io_ring (input OE, input [`WIDTH-1:0] A, output [`WIDTH-1:0] O, inout [`WIDTH-1:0] PAD);
+ io io[`WIDTH-1:0] (.OE(OE), .I(A), .O(O), .PAD(PAD));
+endmodule
+
+module io (input OE, input I, output O, inout PAD);
+ assign O = PAD;
+ assign PAD = OE ? I : 1'bz;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [31:0] Operand1 = crc[31:0];
+ wire [15:0] Operand2 = crc[47:32];
+ wire \tUnsigned = crc[48];
+ reg \t\trst;
+
+ parameter wl = 16;
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [wl-1:0]\tQuotient;\t\t// From test of Test.v
+ wire [wl-1:0]\tRemainder;\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .Quotient\t\t\t(Quotient[wl-1:0]),
+\t .Remainder\t\t(Remainder[wl-1:0]),
+\t // Inputs
+\t .Operand1\t\t\t(Operand1[wl*2-1:0]),
+\t .Operand2\t\t\t(Operand2[wl-1:0]),
+\t .clk\t\t\t(clk),
+\t .rst\t\t\t(rst),
+\t .Unsigned\t\t\t(Unsigned));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {32\'h0, Quotient, Remainder};
+
+ // What checksum will we end up with
+`define EXPECTED_SUM 64\'h98d41f89a8be5693
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x it=%x\
+"",$time, cyc, crc, result, test.Iteration);
+`endif
+ cyc <= cyc + 1;
+ if (cyc < 20 || test.Iteration==4\'d15) begin
+\t crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ end
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t rst <= 1\'b1;
+ end
+ else if (cyc<20) begin
+\t sum <= 64\'h0;
+\t rst <= 1\'b0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'h8dd70a44972ad809) $stop;
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test(clk, rst, Operand1, Operand2, Unsigned, Quotient, Remainder);
+
+ parameter wl = 16;
+
+ input [wl*2-1:0] Operand1;
+ input [wl-1:0] Operand2;
+ input clk, rst, Unsigned;
+ output [wl-1:0] Quotient, Remainder;
+
+ reg Cy, Overflow, Sign1, Sign2, Zero, Negative;
+ reg [wl-1:0] ah,al,Quotient, Remainder;
+ reg [3:0] \tIteration;
+ reg [wl-1:0] sub_quot,op;
+ reg \t\tah_ext;
+
+ reg [1:0]\ta,b,c,d,e;
+
+ always @(posedge clk) begin
+ if (!rst) begin
+\t {a,b,c,d,e} = Operand1[9:0];
+\t {a,b,c,d,e} = {e,d,c,b,a};
+\t if (a != Operand1[1:0]) $stop;
+\t if (b != Operand1[3:2]) $stop;
+\t if (c != Operand1[5:4]) $stop;
+\t if (d != Operand1[7:6]) $stop;
+\t if (e != Operand1[9:8]) $stop;
+ end
+ end
+
+ always @(posedge clk) begin
+ if (rst) begin
+\t Iteration <= 0;
+ Quotient <= 0;
+ Remainder <= 0;
+ end
+ else begin
+\t if (Iteration == 0) begin
+ {ah,al} = Operand1;
+ op = Operand2;
+ Cy = 0;
+ Overflow = 0;
+ Sign1 = (~Unsigned)&ah[wl-1];
+ Sign2 = (~Unsigned)&(ah[wl-1]^op[wl-1]);
+ if (Sign1) {ah,al} = -{ah,al};
+\t end
+`define BUG1
+`ifdef BUG1
+\t {ah_ext,ah,al} = {ah,al,Cy};
+`else
+\t ah_ext = ah[15];
+\t ah[15:1] = ah[14:0];
+\t ah[0] = al[15];
+\t al[15:1] = al[14:0];
+\t al[0] = Cy;
+`endif
+`ifdef TEST_VERBOSE
+\t $display(""%x %x %x %x %x %x %x %x %x"",
+\t\t Iteration, ah, al, Quotient, Remainder, Overflow, ah_ext, sub_quot, Cy);
+`endif
+\t {Cy,sub_quot} = (~Unsigned)&op[wl-1]? {ah_ext,ah}+op : {ah_ext,ah} - {1\'b1,op};
+\t if (Cy)
+\t begin
+ {ah_ext,ah} = {1\'b0,sub_quot};
+\t end
+\t if (Iteration != 15 )
+\t begin
+ if (ah_ext) Overflow = 1;
+\t end
+\t else
+\t begin
+ if (al[14] && ~Unsigned) Overflow = 1;
+ Quotient <= Sign2 ? -{al[14:0],Cy} : {al[14:0],Cy};
+ Remainder <= Sign1 ? -ah : ah;
+ if (Overflow)
+\t\tbegin
+\t Quotient <= Sign2 ? 16\'h8001 : {Unsigned,{15{1\'b1}}};
+\t Remainder <= Unsigned ? 16\'hffff : 16\'h8000;
+\t Zero = 1;
+\t Negative = 1;
+\t\tend
+\t end
+\t Iteration <= Iteration + 1; // Count number of times this instruction is repeated
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013.
+
+// bug648
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [7:0] datai = crc[7:0];
+ wire enable = crc[8];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ logic [7:0]\t\tdatao;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .datao\t\t\t(datao[7:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .datai\t\t\t(datai[7:0]),
+\t .enable\t\t\t(enable));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {56\'h0, datao};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h9d550d82d38926fa
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+`define FAIL 1
+
+module Nested
+ (
+ input logic \tclk,
+ input logic \tx,
+ output logic y
+ );
+ logic \t\t t;
+ always_comb t = x ^ 1\'b1;
+
+ always_ff @(posedge clk) begin
+ if (clk)
+ y <= t;
+ end
+endmodule
+
+module Test
+ (
+ input logic \t clk,
+ input logic [7:0] datai,
+ input logic \t enable,
+ output logic [7:0] datao
+ );
+
+ // verilator lint_off BLKANDNBLK
+ logic [7:0] \t datat;
+ // verilator lint_on BLKANDNBLK
+
+ for (genvar i = 0; i < 8; i++) begin
+ if (i%4 != 3) begin
+`ifndef FAIL
+ logic t;
+ always_comb begin
+\t t = datai[i] ^ 1\'b1;
+\t end
+ always_ff @(posedge clk) begin
+\t if (clk)
+ datat[i] <= t;
+\t end
+`else
+ Nested nested_i
+\t (
+\t .clk(clk),
+\t .x(datai[i]),
+\t .y(datat[i]) //<== via Vcellout wire
+\t );
+`endif
+
+ always_comb begin
+\t casez (enable)
+\t 1\'b1: datao[i] = datat[i];
+\t 1\'b0: datao[i] = \'0;
+\t default: datao[i] = \'x;
+\t endcase
+\t end
+ end
+ else begin
+ always_ff @(posedge clk) begin
+\t if (clk)
+ datat[i] <= 0; //<== assign delayed
+ end
+ always_comb begin
+\t casez (enable)
+\t 1\'b1: datao[i] = datat[i] ^ 1\'b1;
+\t 1\'b0: datao[i] = \'1;
+\t default: datao[i] = \'x;
+\t endcase
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2009 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+module t;
+
+ wire [39:0] out;
+ sub a(.value(out));
+
+ import ""DPI-C"" context function void poke_value(input int i);
+
+
+ initial begin
+ poke_value(32\'hdeadbeef);
+ if (out !== 40\'hdeadbeef) begin
+\t $display(""[%0t] %%Error: t_dpi_qw: failed"", $time);
+\t $stop;
+ end
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+module sub(value);
+ parameter WIDTH = 40;
+
+ output [WIDTH-1:0] value;
+
+ reg [WIDTH-1:0] value;
+
+ task set_value(input bit [WIDTH-1:0] v);
+ value = v;
+ endtask
+
+ export ""DPI-C"" task set_value;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg [31:0] a;
+ reg [31:0] b;
+
+ wire [2:0] bf; buf BF0 (bf[0], a[0]),
+\t\t BF1 (bf[1], a[1]),
+\t\t BF2 (bf[2], a[2]);
+
+ // verilator lint_off IMPLICIT
+ not #(0.108) NT0 (nt0, a[0]);
+ and #1 AN0 (an0, a[0], b[0]);
+ nand #(2,3) ND0 (nd0, a[0], b[0], b[1]);
+ or OR0 (or0, a[0], b[0]);
+ nor NR0 (nr0, a[0], b[0], b[2]);
+ xor (xo0, a[0], b[0]);
+ xnor (xn0, a[0], b[0], b[2]);
+ // verilator lint_on IMPLICIT
+
+ parameter BITS=32;
+ wire [BITS-1:0] ba;
+ buf BARRAY [BITS-1:0] (ba, a);
+
+`ifdef verilator
+ specify
+ specparam CDS_LIBNAME = ""foobar"";
+ (nt0 *> nt0) = (0, 0);
+ endspecify
+
+ specify
+ // delay parameters
+ specparam
+ a$A1$Y = 1.0,
+ b$A0$Z = 1.0;
+
+ // path delays
+ (A1 *> Q) = (a$A1$Y, a$A1$Y);
+ (A0 *> Q) = (b$A0$Y, a$A0$Z);
+ endspecify
+`endif
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t a <= 32\'h18f6b034;
+\t b <= 32\'h834bf892;
+\t end
+\t if (cyc==2) begin
+\t a <= 32\'h529ab56f;
+\t b <= 32\'h7835a237;
+\t if (bf !== 3\'b100) $stop;
+\t if (nt0 !== 1\'b1) $stop;
+\t if (an0 !== 1\'b0) $stop;
+\t if (nd0 !== 1\'b1) $stop;
+\t if (or0 !== 1\'b0) $stop;
+\t if (nr0 !== 1\'b1) $stop;
+\t if (xo0 !== 1\'b0) $stop;
+\t if (xn0 !== 1\'b1) $stop;
+\t if (ba != 32\'h18f6b034) $stop;
+\t end
+\t if (cyc==3) begin
+\t if (bf !== 3\'b111) $stop;
+\t if (nt0 !== 1\'b0) $stop;
+\t if (an0 !== 1\'b1) $stop;
+\t if (nd0 !== 1\'b0) $stop;
+\t if (or0 !== 1\'b1) $stop;
+\t if (nr0 !== 1\'b0) $stop;
+\t if (xo0 !== 1\'b0) $stop;
+\t if (xn0 !== 1\'b0) $stop;
+\t end
+\t if (cyc==4) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+"
+"// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Lane Brooks.
+
+module t (clk);
+ input clk;
+
+ wire A;
+
+ pullup p1(A);
+ pulldown p2(A);
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+// verilator lint_off UNUSED
+// verilator lint_off UNDRIVEN
+
+//bug858
+
+typedef struct packed {
+ logic m_1;
+ logic m_2;
+} struct_t;
+
+typedef struct packed {
+ logic [94:0] m_1;
+ logic m_2;
+} struct96_t;
+
+module t
+ (
+ input struct_t test_input,
+ input struct96_t t96
+ );
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+// bug598
+
+module t (/*AUTOARG*/
+ // Outputs
+ val,
+ // Inputs
+ clk
+ );
+
+ input \t clk;
+ output integer val;
+ integer \t dbg_addr = 0;
+
+ function func1;
+ input en;
+ input [31:0] a;
+ func1 = en && (a == 1);
+ endfunction
+
+ function func2;
+ input \t en;
+ input [31:0] a;
+ func2 = en && (a == 2);
+ endfunction
+
+ always @(posedge clk) begin
+ case( 1\'b1 )
+ // This line is OK:
+ func1(1\'b1, dbg_addr) : val = 1;
+ // This fails:
+ // %Error: Internal Error: test.v:23: ../V3Task.cpp:993: Function not underneath a statement
+ // %Error: Internal Error: See the manual and http://www.veripool.org/verilator for more assistance.
+ func2(1\'b1, dbg_addr) : val = 2;
+ default : val = 0;
+ endcase
+ //
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+`include ""verilated.v""
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg [63:0] crc;
+ `verilator_file_descriptor\t fd;
+
+ t_case_write1_tasks tasks ();
+
+ integer cyc; initial cyc=0;
+
+ always @ (posedge clk) begin
+ $fwrite(fd, ""[%0d] crc=%x "", cyc, crc);
+ tasks.big_case(fd, crc[31:0]);
+ $fwrite(fd, ""\
+"");
+ end
+
+ always @ (posedge clk) begin
+ //$write(""[%0t] cyc==%0d crc=%x\
+"",$time, cyc, crc);
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ if (cyc==1) begin
+\t crc <= 64\'h00000000_00000097;
+\t $write(""Open obj_dir/t_case_write1/t_case_write1_logger.log\
+"");
+\t fd = $fopen(""obj_dir/t_case_write1/t_case_write1_logger.log"", ""w"");
+ end
+ if (cyc==90) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+//
+// --------------------------------------------------------
+// Bug Description:
+//
+// Issue: The gated clock gclk_vld[0] toggles but dvld[0]
+// input to the flop does not propagate to the output
+// signal entry_vld[0] correctly. The value that propagates
+// is the new value of dvld[0] not the one just before the
+// posedge of gclk_vld[0].
+// --------------------------------------------------------
+
+// Define to see the bug with test failing with gated clock \'gclk_vld\'
+// Comment out the define to see the test passing with ungated clock \'clk\'
+`define GATED_CLK_TESTCASE 1
+
+// A side effect of the problem is this warning, disabled by default
+//verilator lint_on IMPERFECTSCH
+
+// Test Bench
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+
+ // Take CRC data and apply to testblock inputs
+ wire [7:0] dvld = crc[7:0];
+ wire [7:0] ff_en_e1 = crc[15:8];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [7:0]\t\tentry_vld;\t\t// From test of Test.v
+ wire [7:0]\t\tff_en_vld;\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .ff_en_vld\t\t(ff_en_vld[7:0]),
+\t .entry_vld\t\t(entry_vld[7:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .dvld\t\t\t(dvld[7:0]),
+\t .ff_en_e1\t\t\t(ff_en_e1[7:0]));
+
+ reg err_code;
+ reg ffq_clk_active;
+ reg [7:0] prv_dvld;
+
+ initial begin
+ err_code = 0;
+ ffq_clk_active = 0;
+ end
+ always @ (posedge clk) begin
+ prv_dvld = test.dvld;
+ end
+ always @ (negedge test.ff_entry_dvld_0.clk) begin
+ ffq_clk_active = 1;
+ if (test.entry_vld[0] !== prv_dvld[0]) err_code = 1;
+ end
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x "",$time, cyc, crc);
+ $display("" en=%b fen=%b d=%b ev=%b"",
+\t test.flop_en_vld[0], test.ff_en_vld[0],
+\t test.dvld[0], test.entry_vld[0]);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ if (cyc<3) begin
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x\
+"",$time, cyc, crc);
+ if (ffq_clk_active == 0) begin
+ $display (""----"");
+ $display (""%%Error: TESTCASE FAILED with no Clock arriving at FFQs"");
+ $display (""----"");
+ $stop;
+ end
+ else if (err_code) begin
+ $display (""----"");
+ $display (""%%Error: TESTCASE FAILED with invalid propagation of \'d\' to \'q\' of FFQs"");
+ $display (""----"");
+ $stop;
+ end
+ else begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+ end
+
+endmodule
+
+module llq (clk, d, q);
+ parameter WIDTH = 32;
+ input clk;
+ input [WIDTH-1:0] d;
+ output [WIDTH-1:0] q;
+
+ reg [WIDTH-1:0] qr;
+
+ /* verilator lint_off COMBDLY */
+
+ always @(clk or d)
+ if (clk == 1\'b0)
+ qr <= d;
+
+ /* verilator lint_on COMBDLY */
+
+ assign q = qr;
+endmodule
+
+module ffq (clk, d, q);
+ parameter WIDTH = 32;
+ input clk;
+ input [WIDTH-1:0] d;
+ output [WIDTH-1:0] q;
+
+ reg [WIDTH-1:0] qr;
+
+ always @(posedge clk)
+ qr <= d;
+
+ assign q = qr;
+endmodule
+
+// DUT module
+module Test (/*AUTOARG*/
+ // Outputs
+ ff_en_vld, entry_vld,
+ // Inputs
+ clk, dvld, ff_en_e1
+ );
+ input clk;
+
+ input [7:0] dvld;
+ input [7:0] ff_en_e1;
+
+ output [7:0] ff_en_vld;
+ output wire [7:0] entry_vld;
+
+ wire [7:0] gclk_vld;
+ wire [7:0] ff_en_vld /*verilator clock_enable*/;
+ reg [7:0] flop_en_vld;
+
+ always @(posedge clk) flop_en_vld <= ff_en_e1;
+
+ // clock gating
+`ifdef GATED_CLK_TESTCASE
+ assign gclk_vld = {8{clk}} & ff_en_vld;
+`else
+ assign gclk_vld = {8{clk}};
+`endif
+
+ // latch for avoiding glitch on the clock gating control
+ llq #(8) dp_ff_en_vld (.clk(clk), .d(flop_en_vld), .q(ff_en_vld));
+
+ // flops that use the gated clock signal
+ ffq #(1) ff_entry_dvld_0 (.clk(gclk_vld[0]), .d(dvld[0]), .q(entry_vld[0]));
+ ffq #(1) ff_entry_dvld_1 (.clk(gclk_vld[1]), .d(dvld[1]), .q(entry_vld[1]));
+ ffq #(1) ff_entry_dvld_2 (.clk(gclk_vld[2]), .d(dvld[2]), .q(entry_vld[2]));
+ ffq #(1) ff_entry_dvld_3 (.clk(gclk_vld[3]), .d(dvld[3]), .q(entry_vld[3]));
+ ffq #(1) ff_entry_dvld_4 (.clk(gclk_vld[4]), .d(dvld[4]), .q(entry_vld[4]));
+ ffq #(1) ff_entry_dvld_5 (.clk(gclk_vld[5]), .d(dvld[5]), .q(entry_vld[5]));
+ ffq #(1) ff_entry_dvld_6 (.clk(gclk_vld[6]), .d(dvld[6]), .q(entry_vld[6]));
+ ffq #(1) ff_entry_dvld_7 (.clk(gclk_vld[7]), .d(dvld[7]), .q(entry_vld[7]));
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t_case_huge_sub2 (/*AUTOARG*/
+ // Outputs
+ outa,
+ // Inputs
+ index
+ );
+
+ input [9:0] index;
+ output [9:0] outa;
+
+ // =============================
+ /*AUTOREG*/
+ // Beginning of automatic regs (for this module\'s undeclared outputs)
+ reg [9:0]\t\touta;
+ // End of automatics
+
+ // =============================
+ // Created from perl
+ // for $i (0..1023) { printf ""\\t10\'h%03x: begin outa = 10\'h%03x; outb = 2\'b%02b; outc = 1\'b%d; end\
+"", $i, rand(1024),rand(4),rand(2); };
+
+ always @(/*AS*/index) begin
+ case (index[7:0])
+`ifdef VERILATOR // Harder test
+\t8\'h00: begin outa = $c(""0""); end // Makes whole table non-optimizable
+`else
+\t8\'h00: begin outa = 10\'h0; end
+`endif
+\t8\'h01: begin outa = 10\'h318; end
+\t8\'h02: begin outa = 10\'h29f; end
+\t8\'h03: begin outa = 10\'h392; end
+\t8\'h04: begin outa = 10\'h1ef; end
+\t8\'h05: begin outa = 10\'h06c; end
+\t8\'h06: begin outa = 10\'h29f; end
+\t8\'h07: begin outa = 10\'h29a; end
+\t8\'h08: begin outa = 10\'h3ce; end
+\t8\'h09: begin outa = 10\'h37c; end
+\t8\'h0a: begin outa = 10\'h058; end
+\t8\'h0b: begin outa = 10\'h3b2; end
+\t8\'h0c: begin outa = 10\'h36f; end
+\t8\'h0d: begin outa = 10\'h2c5; end
+\t8\'h0e: begin outa = 10\'h23a; end
+\t8\'h0f: begin outa = 10\'h222; end
+\t8\'h10: begin outa = 10\'h328; end
+\t8\'h11: begin outa = 10\'h3c3; end
+\t8\'h12: begin outa = 10\'h12c; end
+\t8\'h13: begin outa = 10\'h1d0; end
+\t8\'h14: begin outa = 10\'h3ff; end
+\t8\'h15: begin outa = 10\'h115; end
+\t8\'h16: begin outa = 10\'h3ba; end
+\t8\'h17: begin outa = 10\'h3ba; end
+\t8\'h18: begin outa = 10\'h10d; end
+\t8\'h19: begin outa = 10\'h13b; end
+\t8\'h1a: begin outa = 10\'h0a0; end
+\t8\'h1b: begin outa = 10\'h264; end
+\t8\'h1c: begin outa = 10\'h3a2; end
+\t8\'h1d: begin outa = 10\'h07c; end
+\t8\'h1e: begin outa = 10\'h291; end
+\t8\'h1f: begin outa = 10\'h1d1; end
+\t8\'h20: begin outa = 10\'h354; end
+\t8\'h21: begin outa = 10\'h0c0; end
+\t8\'h22: begin outa = 10\'h191; end
+\t8\'h23: begin outa = 10\'h379; end
+\t8\'h24: begin outa = 10\'h073; end
+\t8\'h25: begin outa = 10\'h2fd; end
+\t8\'h26: begin outa = 10\'h2e0; end
+\t8\'h27: begin outa = 10\'h337; end
+\t8\'h28: begin outa = 10\'h2c7; end
+\t8\'h29: begin outa = 10\'h19e; end
+\t8\'h2a: begin outa = 10\'h107; end
+\t8\'h2b: begin outa = 10\'h06a; end
+\t8\'h2c: begin outa = 10\'h1c7; end
+\t8\'h2d: begin outa = 10\'h107; end
+\t8\'h2e: begin outa = 10\'h0cf; end
+\t8\'h2f: begin outa = 10\'h009; end
+\t8\'h30: begin outa = 10\'h09d; end
+\t8\'h31: begin outa = 10\'h28e; end
+\t8\'h32: begin outa = 10\'h010; end
+\t8\'h33: begin outa = 10\'h1e0; end
+\t8\'h34: begin outa = 10\'h079; end
+\t8\'h35: begin outa = 10\'h13e; end
+\t8\'h36: begin outa = 10\'h282; end
+\t8\'h37: begin outa = 10\'h21c; end
+\t8\'h38: begin outa = 10\'h148; end
+\t8\'h39: begin outa = 10\'h3c0; end
+\t8\'h3a: begin outa = 10\'h176; end
+\t8\'h3b: begin outa = 10\'h3fc; end
+\t8\'h3c: begin outa = 10\'h295; end
+\t8\'h3d: begin outa = 10\'h113; end
+\t8\'h3e: begin outa = 10\'h354; end
+\t8\'h3f: begin outa = 10\'h0db; end
+\t8\'h40: begin outa = 10\'h238; end
+\t8\'h41: begin outa = 10\'h12b; end
+\t8\'h42: begin outa = 10\'h1dc; end
+\t8\'h43: begin outa = 10\'h137; end
+\t8\'h44: begin outa = 10\'h1e2; end
+\t8\'h45: begin outa = 10\'h3d5; end
+\t8\'h46: begin outa = 10\'h30c; end
+\t8\'h47: begin outa = 10\'h298; end
+\t8\'h48: begin outa = 10\'h080; end
+\t8\'h49: begin outa = 10\'h35a; end
+\t8\'h4a: begin outa = 10\'h01b; end
+\t8\'h4b: begin outa = 10\'h0a3; end
+\t8\'h4c: begin outa = 10\'h0b3; end
+\t8\'h4d: begin outa = 10\'h17a; end
+\t8\'h4e: begin outa = 10\'h3ae; end
+\t8\'h4f: begin outa = 10\'h078; end
+\t8\'h50: begin outa = 10\'h322; end
+\t8\'h51: begin outa = 10\'h213; end
+\t8\'h52: begin outa = 10\'h11a; end
+\t8\'h53: begin outa = 10\'h1a7; end
+\t8\'h54: begin outa = 10\'h35a; end
+\t8\'h55: begin outa = 10\'h233; end
+\t8\'h56: begin outa = 10\'h01d; end
+\t8\'h57: begin outa = 10\'h2d5; end
+\t8\'h58: begin outa = 10\'h1a0; end
+\t8\'h59: begin outa = 10\'h3d0; end
+\t8\'h5a: begin outa = 10\'h181; end
+\t8\'h5b: begin outa = 10\'h219; end
+\t8\'h5c: begin outa = 10\'h26a; end
+\t8\'h5d: begin outa = 10\'h050; end
+\t8\'h5e: begin outa = 10\'h189; end
+\t8\'h5f: begin outa = 10\'h1eb; end
+\t8\'h60: begin outa = 10\'h224; end
+\t8\'h61: begin outa = 10\'h2fe; end
+\t8\'h62: begin outa = 10\'h0ae; end
+\t8\'h63: begin outa = 10\'h1cd; end
+\t8\'h64: begin outa = 10\'h273; end
+\t8\'h65: begin outa = 10\'h268; end
+\t8\'h66: begin outa = 10\'h111; end
+\t8\'h67: begin outa = 10\'h1f9; end
+\t8\'h68: begin outa = 10\'h232; end
+\t8\'h69: begin outa = 10\'h255; end
+\t8\'h6a: begin outa = 10\'h34c; end
+\t8\'h6b: begin outa = 10\'h049; end
+\t8\'h6c: begin outa = 10\'h197; end
+\t8\'h6d: begin outa = 10\'h0fe; end
+\t8\'h6e: begin outa = 10\'h253; end
+\t8\'h6f: begin outa = 10\'h2de; end
+\t8\'h70: begin outa = 10\'h13b; end
+\t8\'h71: begin outa = 10\'h040; end
+\t8\'h72: begin outa = 10\'h0b4; end
+\t8\'h73: begin outa = 10\'h233; end
+\t8\'h74: begin outa = 10\'h198; end
+\t8\'h75: begin outa = 10\'h018; end
+\t8\'h76: begin outa = 10\'h2f7; end
+\t8\'h77: begin outa = 10\'h134; end
+\t8\'h78: begin outa = 10\'h1ca; end
+\t8\'h79: begin outa = 10\'h286; end
+\t8\'h7a: begin outa = 10\'h0e6; end
+\t8\'h7b: begin outa = 10\'h064; end
+\t8\'h7c: begin outa = 10\'h257; end
+\t8\'h7d: begin outa = 10\'h31a; end
+\t8\'h7e: begin outa = 10\'h247; end
+\t8\'h7f: begin outa = 10\'h299; end
+\t8\'h80: begin outa = 10\'h02c; end
+\t8\'h81: begin outa = 10\'h2bb; end
+\t8\'h82: begin outa = 10\'h180; end
+\t8\'h83: begin outa = 10\'h245; end
+\t8\'h84: begin outa = 10\'h0da; end
+\t8\'h85: begin outa = 10\'h367; end
+\t8\'h86: begin outa = 10\'h304; end
+\t8\'h87: begin outa = 10\'h38b; end
+\t8\'h88: begin outa = 10\'h09f; end
+\t8\'h89: begin outa = 10\'h1f0; end
+\t8\'h8a: begin outa = 10\'h281; end
+\t8\'h8b: begin outa = 10\'h019; end
+\t8\'h8c: begin outa = 10\'h1f2; end
+\t8\'h8d: begin outa = 10\'h0b1; end
+\t8\'h8e: begin outa = 10\'h058; end
+\t8\'h8f: begin outa = 10\'h39b; end
+\t8\'h90: begin outa = 10\'h2ec; end
+\t8\'h91: begin outa = 10\'h250; end
+\t8\'h92: begin outa = 10\'h3f4; end
+\t8\'h93: begin outa = 10\'h057; end
+\t8\'h94: begin outa = 10\'h18f; end
+\t8\'h95: begin outa = 10\'h105; end
+\t8\'h96: begin outa = 10\'h1ae; end
+\t8\'h97: begin outa = 10\'h04e; end
+\t8\'h98: begin outa = 10\'h240; end
+\t8\'h99: begin outa = 10\'h3e4; end
+\t8\'h9a: begin outa = 10\'h3c6; end
+\t8\'h9b: begin outa = 10\'h109; end
+\t8\'h9c: begin outa = 10\'h073; end
+\t8\'h9d: begin outa = 10\'h19f; end
+\t8\'h9e: begin outa = 10\'h3b8; end
+\t8\'h9f: begin outa = 10\'h00e; end
+\t8\'ha0: begin outa = 10\'h1b3; end
+\t8\'ha1: begin outa = 10\'h2bd; end
+\t8\'ha2: begin outa = 10\'h324; end
+\t8\'ha3: begin outa = 10\'h343; end
+\t8\'ha4: begin outa = 10\'h1c9; end
+\t8\'ha5: begin outa = 10\'h185; end
+\t8\'ha6: begin outa = 10\'h37a; end
+\t8\'ha7: begin outa = 10\'h0e0; end
+\t8\'ha8: begin outa = 10\'h0a3; end
+\t8\'ha9: begin outa = 10\'h019; end
+\t8\'haa: begin outa = 10\'h099; end
+\t8\'hab: begin outa = 10\'h376; end
+\t8\'hac: begin outa = 10\'h077; end
+\t8\'had: begin outa = 10\'h2b1; end
+\t8\'hae: begin outa = 10\'h27f; end
+\t8\'haf: begin outa = 10\'h265; end
+\t8\'hb0: begin outa = 10\'h156; end
+\t8\'hb1: begin outa = 10\'h1ce; end
+\t8\'hb2: begin outa = 10\'h008; end
+\t8\'hb3: begin outa = 10\'h12e; end
+\t8\'hb4: begin outa = 10\'h199; end
+\t8\'hb5: begin outa = 10\'h330; end
+\t8\'hb6: begin outa = 10\'h1ab; end
+\t8\'hb7: begin outa = 10\'h3bd; end
+\t8\'hb8: begin outa = 10\'h0ca; end
+\t8\'hb9: begin outa = 10\'h367; end
+\t8\'hba: begin outa = 10\'h334; end
+\t8\'hbb: begin outa = 10\'h040; end
+\t8\'hbc: begin outa = 10\'h1a7; end
+\t8\'hbd: begin outa = 10\'h036; end
+\t8\'hbe: begin outa = 10\'h223; end
+\t8\'hbf: begin outa = 10\'h075; end
+\t8\'hc0: begin outa = 10\'h3c4; end
+\t8\'hc1: begin outa = 10\'h2cc; end
+\t8\'hc2: begin outa = 10\'h123; end
+\t8\'hc3: begin outa = 10\'h3fd; end
+\t8\'hc4: begin outa = 10\'h11e; end
+\t8\'hc5: begin outa = 10\'h27c; end
+\t8\'hc6: begin outa = 10\'h1e2; end
+\t8\'hc7: begin outa = 10\'h377; end
+\t8\'hc8: begin outa = 10\'h33a; end
+\t8\'hc9: begin outa = 10\'h32d; end
+\t8\'hca: begin outa = 10\'h014; end
+\t8\'hcb: begin outa = 10\'h332; end
+\t8\'hcc: begin outa = 10\'h359; end
+\t8\'hcd: begin outa = 10\'h0a4; end
+\t8\'hce: begin outa = 10\'h348; end
+\t8\'hcf: begin outa = 10\'h04b; end
+\t8\'hd0: begin outa = 10\'h147; end
+\t8\'hd1: begin outa = 10\'h026; end
+\t8\'hd2: begin outa = 10\'h103; end
+\t8\'hd3: begin outa = 10\'h106; end
+\t8\'hd4: begin outa = 10\'h35a; end
+\t8\'hd5: begin outa = 10\'h254; end
+\t8\'hd6: begin outa = 10\'h0cd; end
+\t8\'hd7: begin outa = 10\'h17c; end
+\t8\'hd8: begin outa = 10\'h37e; end
+\t8\'hd9: begin outa = 10\'h0a9; end
+\t8\'hda: begin outa = 10\'h0fe; end
+\t8\'hdb: begin outa = 10\'h3c0; end
+\t8\'hdc: begin outa = 10\'h1d9; end
+\t8\'hdd: begin outa = 10\'h10e; end
+\t8\'hde: begin outa = 10\'h394; end
+\t8\'hdf: begin outa = 10\'h316; end
+\t8\'he0: begin outa = 10\'h05b; end
+\t8\'he1: begin outa = 10\'h126; end
+\t8\'he2: begin outa = 10\'h369; end
+\t8\'he3: begin outa = 10\'h291; end
+\t8\'he4: begin outa = 10\'h2ca; end
+\t8\'he5: begin outa = 10\'h25b; end
+\t8\'he6: begin outa = 10\'h106; end
+\t8\'he7: begin outa = 10\'h172; end
+\t8\'he8: begin outa = 10\'h2f7; end
+\t8\'he9: begin outa = 10\'h2d3; end
+\t8\'hea: begin outa = 10\'h182; end
+\t8\'heb: begin outa = 10\'h327; end
+\t8\'hec: begin outa = 10\'h1d0; end
+\t8\'hed: begin outa = 10\'h204; end
+\t8\'hee: begin outa = 10\'h11f; end
+\t8\'hef: begin outa = 10\'h365; end
+\t8\'hf0: begin outa = 10\'h2c2; end
+\t8\'hf1: begin outa = 10\'h2b5; end
+\t8\'hf2: begin outa = 10\'h1f8; end
+\t8\'hf3: begin outa = 10\'h2a7; end
+\t8\'hf4: begin outa = 10\'h1be; end
+\t8\'hf5: begin outa = 10\'h25e; end
+\t8\'hf6: begin outa = 10\'h032; end
+\t8\'hf7: begin outa = 10\'h2ef; end
+\t8\'hf8: begin outa = 10\'h02f; end
+\t8\'hf9: begin outa = 10\'h201; end
+\t8\'hfa: begin outa = 10\'h054; end
+\t8\'hfb: begin outa = 10\'h013; end
+\t8\'hfc: begin outa = 10\'h249; end
+\t8\'hfd: begin outa = 10\'h09a; end
+\t8\'hfe: begin outa = 10\'h012; end
+\t8\'hff: begin outa = 10\'h114; end
+ endcase
+ end
+endmodule
+"
+"`define GOT_DEF3 1
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+`define INT_RANGE 31:0
+`define INT_RANGE 31:0\t// Duplicate identical defs are OK
+`define INT_RANGE_MAX 31
+`define VECTOR_RANGE 511:0
+
+module t (clk);
+
+ // verilator lint_off WIDTH
+
+ parameter WIDTH = 16; // Must be a power of 2
+ parameter WIDTH_LOG2 = 4; // set to log2(WIDTH)
+ parameter USE_BS = 1; // set to 1 for enable
+
+ input clk;
+
+ function [`VECTOR_RANGE] func_tree_left;
+ input [`VECTOR_RANGE] x; // x[width-1:0] is the input vector
+ reg [`VECTOR_RANGE] flip;
+ begin
+\t flip = \'d0;
+\t func_tree_left = flip;
+ end
+ endfunction
+
+ reg [WIDTH-1:0] a; // value to be shifted
+ reg [WIDTH-1:0] \ttree_left;
+ always @(a) begin : barrel_shift
+ tree_left = func_tree_left (a);
+ end // barrel_shift
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t a = 5;
+\t end
+\t if (cyc==2) begin
+\t $display (""%x\
+"",tree_left);
+\t //if (tree_left != \'d15) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+`include ""t_pp_lib_inc.vh""
+module t();
+ wire [`WIDTH-1:0] a;
+ library_cell n1(a);
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+
+ // verilator lint_off WIDTH
+
+`define INT_RANGE 31:0
+`define INT_RANGE_MAX 31
+`define VECTOR_RANGE 63:0
+
+ reg [`INT_RANGE] stashb, stasha, stashn, stashm;
+
+ function [`VECTOR_RANGE] copy_range;
+ input [`VECTOR_RANGE] y;
+ input [`INT_RANGE] b;
+ input [`INT_RANGE] a;
+
+ input [`VECTOR_RANGE] x;
+ input [`INT_RANGE] n;
+ input [`INT_RANGE] m;
+
+ begin
+\t copy_range = y;
+\t stashb = b;
+\t stasha = a;
+\t stashn = n;
+\t stashm = m;
+ end
+ endfunction
+
+ parameter DATA_SIZE = 16;
+ parameter NUM_OF_REGS = 32;
+
+ reg [NUM_OF_REGS*DATA_SIZE-1 : 0] memread_rf;
+ reg [DATA_SIZE-1:0] \t\t memread_rf_reg;
+ always @(memread_rf) begin : memread_convert
+ memread_rf_reg = copy_range(\'d0, DATA_SIZE-\'d1, DATA_SIZE-\'d1, memread_rf,
+\t\t\t\t DATA_SIZE-\'d1, DATA_SIZE-\'d1);
+ end
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t memread_rf = 512\'haa;
+\t end
+\t if (cyc==3) begin
+\t if (stashb != \'d15) $stop;
+\t if (stasha != \'d15) $stop;
+\t if (stashn != \'d15) $stop;
+\t if (stashm != \'d15) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ // verilator lint_off COMBDLY
+ // verilator lint_off UNOPT
+ // verilator lint_off UNOPTFLAT
+
+ reg \t c1_start; initial c1_start = 0;
+ wire [31:0] c1_count;
+ comb_loop c1 (.count(c1_count), .start(c1_start));
+
+ wire s2_start = (c1_count==0 && c1_start);
+ wire [31:0] s2_count;
+ seq_loop s2 (.count(s2_count), .start(s2_start));
+
+ wire c3_start = (s2_count[0]);
+ wire [31:0] c3_count;
+ comb_loop c3 (.count(c3_count), .start(c3_start));
+
+ reg [7:0] cyc; initial cyc=0;
+ always @ (posedge clk) begin
+ //$write(""[%0t] %x counts %x %x %x\
+"",$time,cyc,c1_count,s2_count,c3_count);
+ cyc <= cyc + 8\'d1;
+ case (cyc)
+\t8\'d00: begin
+\t c1_start <= 1\'b0;
+\tend
+\t8\'d01: begin
+\t c1_start <= 1\'b1;
+\tend
+\tdefault: ;
+ endcase
+ case (cyc)
+\t8\'d02: begin
+\t if (c1_count!=32\'h3) $stop;
+\t if (s2_count!=32\'h3) $stop;
+\t if (c3_count!=32\'h6) $stop;
+\tend
+\t8\'d03: begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\tend
+\tdefault: ;
+ endcase
+ end
+endmodule
+
+module comb_loop (/*AUTOARG*/
+ // Outputs
+ count,
+ // Inputs
+ start
+ );
+ input start;
+ output reg [31:0] count; initial count = 0;
+
+ reg [31:0] \t runnerm1, runner; initial runner = 0;
+
+ always @ (start) begin
+ if (start) begin
+\t runner = 3;
+ end
+ end
+
+ always @ (/*AS*/runner) begin
+ runnerm1 = runner - 32\'d1;
+ end
+
+ always @ (/*AS*/runnerm1) begin
+ if (runner > 0) begin
+\t count = count + 1;
+\t runner = runnerm1;
+\t $write (""%m count=%d runner =%x\
+"",count, runnerm1);
+ end
+ end
+
+endmodule
+
+module seq_loop (/*AUTOARG*/
+ // Outputs
+ count,
+ // Inputs
+ start
+ );
+ input start;
+ output reg [31:0] count; initial count = 0;
+
+ reg [31:0] \t runnerm1, runner; initial runner = 0;
+
+ always @ (start) begin
+ if (start) begin
+\t runner <= 3;
+ end
+ end
+
+ always @ (/*AS*/runner) begin
+ runnerm1 = runner - 32\'d1;
+ end
+
+ always @ (/*AS*/runnerm1) begin
+ if (runner > 0) begin
+\t count = count + 1;
+\t runner <= runnerm1;
+\t $write (""%m count=%d runner<=%x\
+"",count, runnerm1);
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ integer \tcyc=0;
+
+ reg [6:0] mem1d;
+ reg [6:0] mem2d [5:0];
+ reg [6:0] mem3d [4:0][5:0];
+
+ integer i,j,k;
+
+ // Four different test cases for out of bounds
+ //\t=
+ //\t<=
+ // Continuous assigns
+ //\tOutput pin interconnect (also covers cont assigns)
+ // Each with both bit selects and array selects
+
+ initial begin
+ mem1d[0] = 1\'b0;
+ i=7;
+ mem1d[i] = 1\'b1;
+ if (mem1d[0] !== 1\'b0) $stop;
+ //
+ for (i=0; i<8; i=i+1) begin
+\t for (j=0; j<8; j=j+1) begin
+\t for (k=0; k<8; k=k+1) begin
+\t mem1d[k] = k[0];
+\t mem2d[j][k] = j[0]+k[0];
+\t mem3d[i][j][k] = i[0]+j[0]+k[0];
+\t end
+\t end
+ end
+ for (i=0; i<5; i=i+1) begin
+\t for (j=0; j<6; j=j+1) begin
+\t for (k=0; k<7; k=k+1) begin
+\t if (mem1d[k] !== k[0]) $stop;
+\t if (mem2d[j][k] !== j[0]+k[0]) $stop;
+\t if (mem3d[i][j][k] !== i[0]+j[0]+k[0]) $stop;
+\t end
+\t end
+ end
+ end
+
+ integer wi;
+ wire [31:0] wd = cyc;
+ reg [31:0] reg2d[6:0];
+ always @ (posedge clk) reg2d[wi[2:0]] <= wd;
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d reg2d[%0d]=%0x wd=%0x\
+"",$time, cyc, wi[2:0], reg2d[wi[2:0]], wd);
+`endif
+ cyc <= cyc + 1;
+ if (cyc<10) begin
+\t wi <= 0;
+ end
+ else if (cyc==10) begin
+\t wi <= 1;
+ end
+ else if (cyc==11) begin
+\t if (reg2d[0] !== 10) $stop;
+\t wi <= 6;
+ end
+ else if (cyc==12) begin
+\t if (reg2d[0] !== 10) $stop;
+\t if (reg2d[1] !== 11) $stop;
+\t wi <= 7; // Will be ignored
+ end
+ else if (cyc==13) begin
+\t if (reg2d[0] !== 10) $stop;
+\t if (reg2d[1] !== 11) $stop;
+\t if (reg2d[6] !== 12) $stop;
+ end
+ else if (cyc==14) begin
+\t if (reg2d[0] !== 10) $stop;
+\t if (reg2d[1] !== 11) $stop;
+\t if (reg2d[6] !== 12) $stop;
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t ();
+
+ // This isn't a width violation, as +/- 1'b1 is a common idiom
+ // that's fairly harmless
+ wire [4:0] five = 5'd5;
+ wire [4:0] suma = five + 1'b1;
+ wire [4:0] sumb = 1'b1 + five;
+ wire [4:0] sumc = five - 1'b1;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008-2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ wire [9:0] I1 = crc[9:0];
+ wire [9:0] I2 = crc[19:10];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [9:0]\t\tS;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .S\t\t\t(S[9:0]),
+\t // Inputs
+\t .I1\t\t\t(I1[9:0]),
+\t .I2\t\t\t(I2[9:0]));
+
+ wire [63:0] result = {32\'h0, 22\'h0, S};
+
+`define EXPECTED_SUM 64\'h24c38b77b0fcc2e7
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ S,
+ // Inputs
+ I1, I2
+ );
+
+ input [9:0] I1/*verilator public*/;
+ input [9:0] I2/*verilator public*/;
+ output reg [9:0] S/*verilator public*/;
+
+ always @(I1 or I2)
+ t2(I1,I2,S);
+
+ task t1;
+ input In1,In2;
+ output Sum;
+ Sum = In1 ^ In2;
+ endtask
+
+ task t2;
+ input[9:0] In1,In2;
+ output [9:0] Sum;
+ integer \t I;
+ begin
+\t for (I=0;I<10;I=I+1)
+\t t1(In1[I],In2[I],Sum[I]);
+ end
+ endtask
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003-2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ integer \tcyc=0;
+
+ wire \tout;
+ reg \t\tin;
+
+ Genit g (.clk(clk), .value(in), .result(out));
+
+ always @ (posedge clk) begin
+ //$write(""[%0t] cyc==%0d %x %x\
+"",$time, cyc, in, out);
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+\t // Setup
+\t in <= 1\'b1;
+ end
+ else if (cyc==1) begin
+\t in <= 1\'b0;
+ end
+ else if (cyc==2) begin
+\t if (out != 1\'b1) $stop;
+ end
+ else if (cyc==3) begin
+\t if (out != 1\'b0) $stop;
+ end
+ else if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+//`define WAVES
+`ifdef WAVES
+ initial begin
+ $dumpfile(""obj_dir/t_gen_intdot/t_gen_intdot.vcd"");
+ $dumpvars(12, t);
+ end
+`endif
+
+endmodule
+
+module Generate (clk, value, result);
+ input clk;
+ input value;
+ output result;
+
+ reg Internal;
+
+ assign result = Internal ^ clk;
+
+ always @(posedge clk)
+ Internal <= #1 value;
+endmodule
+
+module Checker (clk, value);
+ input clk, value;
+
+ always @(posedge clk) begin
+ $write (""[%0t] value=%h\
+"", $time, value);
+ end
+
+endmodule
+
+module Test (clk, value, result);
+ input clk;
+ input value;
+ output result;
+
+ Generate gen (clk, value, result);
+ Checker chk (clk, gen.Internal);
+
+endmodule
+
+module Genit (clk, value, result);
+ input clk;
+ input value;
+ output result;
+
+`ifndef ATSIM // else unsupported
+ `ifndef NC // else unsupported
+ `define WITH_FOR_GENVAR
+ `endif
+`endif
+
+`define WITH_GENERATE
+`ifdef WITH_GENERATE
+ `ifndef WITH_FOR_GENVAR
+ genvar i;
+ `endif
+ generate
+ for (
+ `ifdef WITH_FOR_GENVAR
+\t genvar
+ `endif
+\t i = 0; i < 1; i = i + 1)
+\tbegin : foo
+\t Test tt (clk, value, result);
+\tend
+ endgenerate
+`else
+ Test tt (clk, value, result);
+`endif
+
+ wire Result2 = t.g.foo[0].tt.gen.Internal; // Works - Do not change!
+ always @ (posedge clk) begin
+ $write(""[%0t] Result2 = %x\
+"", $time, Result2);
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ const logic [2:0] five = 3\'d5;
+
+ always @ (posedge clk) begin
+ five = 3\'d4;
+ if (five !== 3\'d5) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+// simplistic example, should choose 1st conditional generate and assign straight through
+// the tool also compiles the special case and determines an error (replication value is 0)
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty.
+`timescale 1ns / 1ps
+
+module t(data_i, data_o, single);
+ parameter op_bits = 32;
+ input [op_bits -1:0] data_i;
+ output [31:0] data_o;
+ input single;
+
+ //simplistic example, should choose 1st conditional generate and assign straight through
+ //the tool also compiles the special case and determines an error (replication value is 0
+ generate
+ if (op_bits == 32) begin : general_case
+ assign data_o = data_i;
+\t // Test implicit signals
+\t /* verilator lint_off IMPLICIT */
+\t assign imp = single;
+\t /* verilator lint_on IMPLICIT */
+ end
+ else begin : special_case
+ assign data_o = {{(32 -op_bits){1'b0}},data_i};
+\t /* verilator lint_off IMPLICIT */
+\t assign imp = single;
+\t /* verilator lint_on IMPLICIT */
+ end
+ endgenerate
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t_inst_first_a (/*AUTOARG*/
+ // Outputs
+ o_w5, o_w5_d1r, o_w40, o_w104,
+ // Inputs
+ clk, i_w5, i_w40, i_w104
+ );
+
+ input clk;
+
+ input [4:0] \t\ti_w5;
+ output [4:0] \to_w5;
+ output [4:0] \to_w5_d1r;
+ input [39:0] \ti_w40;
+ output [39:0] \to_w40;
+ input [104:0] \ti_w104;
+ output [104:0] \to_w104;
+
+ wire [4:0] o_w5 = i_w5;
+ wire [39:0] o_w40 = i_w40;
+ wire [104:0] o_w104 = i_w104;
+
+ /*AUTOREG*/
+ // Beginning of automatic regs (for this module's undeclared outputs)
+ reg [4:0]\t\to_w5_d1r;
+ // End of automatics
+
+ always @ (posedge clk) begin
+ o_w5_d1r <= i_w5;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t;
+
+ integer i;
+
+ initial begin
+`ifndef VERILATOR
+ `ifndef VCS
+ `ifndef NC
+ $system(); // Legal per spec, but not supported everywhere and nonsensical
+ `endif
+ `endif
+`endif
+ $system(""exit 0"");
+ $system(""echo hello"");
+`ifndef VCS
+ i = $system(""exit 0"");
+ if (i!==0) $stop;
+ i = $system(""exit 10"");
+ if (i!==10) $stop;
+`endif
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+`begin_keywords ""VAMS-2.3""
+
+module t (/*autoarg*/
+ // Outputs
+ aout,
+ // Inputs
+ in
+ );
+
+ input [15:0] in;
+ output \taout;
+ wreal aout;
+
+ parameter real lsb = 1;
+ // verilator lint_off WIDTH
+ assign aout = $itor(in) * lsb;
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ tri z0;
+ tri z1;
+
+ updown #(0) updown0 (.z(z0));
+ updown #(1) updown1 (.z(z1));
+
+ always @ (posedge clk) begin
+ if (z0 !== 0) $stop;
+ if (z1 !== 1) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+module updown #(parameter UP=0)
+ (inout z);
+ generate
+ if (UP) begin
+\t t_up sub (.z);
+ end
+ else begin
+\t t_down sub (.z);
+ end
+ endgenerate
+endmodule
+
+module t_up (inout tri1 z);
+endmodule
+
+module t_down (inout tri0 z);
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg [31:0] a, b, c, d, e, f, g, h;
+
+ always @ (*) begin // Test Verilog 2001 (*)
+ // verilator lint_off COMBDLY
+ c <= a | b;
+ // verilator lint_on COMBDLY
+ end
+
+ always @ (posedge (clk)) begin // always bug 2008/4/18
+ d <= a | b;
+ end
+ always @ ((d)) begin // always bug 2008/4/18
+ e = d;
+ end
+
+ parameter CONSTANT = 1;
+ always @ (e, 1\'b0, CONSTANT) begin // not technically legal, see bug412
+ f = e;
+ end
+ always @ (1\'b0, CONSTANT, f) begin // not technically legal, see bug412
+ g = f;
+ end
+ always @ ({CONSTANT, g}) begin // bug745
+ h = g;
+ end
+ //always @ ((posedge b) or (a or b)) begin // note both illegal
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc<=cyc+1;
+\t if (cyc==1) begin
+\t a <= 32\'hfeed0000;
+\t b <= 32\'h0000face;
+\t end
+\t if (cyc==2) begin
+\t if (c != 32\'hfeedface) $stop;
+\t end
+\t if (cyc==3) begin
+\t if (h != 32\'hfeedface) $stop;
+\t end
+\t if (cyc==7) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module a();
+endmodule
+
+module test();
+ a a();
+endmodule
+
+module a();
+endmodule
+
+module b();
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ typedef struct packed {
+ logic [3:2] a;
+ logic [5:4][3:2] b;
+ } ab_t;
+ typedef ab_t [7:6] c_t; // array of structs
+ typedef struct packed {
+ c_t [17:16] d;
+ } e_t;
+
+`define checkb(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'b%x exp=\'b%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
+
+ initial begin
+ e_t e;
+ `checkh($bits(ab_t),6);
+ `checkh($bits(c_t),12);
+ `checkh($bits(e_t),24);
+ `checkh($bits(e), 24);
+ `checkh($bits(e.d[17]),12);
+ `checkh($bits(e.d[16][6]),6);
+ `checkh($bits(e.d[16][6].b[5]),2);
+ `checkh($bits(e.d[16][6].b[5][2]), 1);
+ //
+ e = 24\'b101101010111010110101010;
+ `checkb(e, 24\'b101101010111010110101010);
+ e.d[17] = 12\'b111110011011;
+ `checkb(e, 24\'b111110011011010110101010);
+ e.d[16][6] = 6\'b010101;
+ `checkb(e, 24\'b111110011011010110010101);
+ e.d[16][6].b[5] = 2\'b10;
+ `checkb(e, 24\'b111110011011010110011001);
+ e.d[16][6].b[5][2] = 1\'b1;
+ //
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t ();
+
+ // See also t_math_width
+
+ // This shows the uglyness in width warnings across param modules
+ // TODO: Would be nice to also show relevant parameter settings
+ p #(.WIDTH(4)) p4 (.in(4'd0));
+ p #(.WIDTH(5)) p5 (.in(5'd0));
+
+ //====
+ localparam [3:0]\tXS = 'hx; // User presumably intended to use 'x
+
+ //====
+ wire [4:0] c = 1'b1 << 2; // No width warning, as is common syntax
+ wire [4:0] d = (1'b1 << 2) + 5'b1; // Has warning as not obvious what expression width is
+
+ //====
+ localparam\t\tWIDTH = 6;
+ wire \t\tone_bit;
+ wire\t[2:0]\t\tshifter = 1;
+ wire [WIDTH-1:0] \tmasked = (({{(WIDTH){1'b0}}, one_bit}) << shifter);
+
+ //====
+ // We presently warn here, in theory we could detect if the number of one bit additions could overflow the LHS
+ wire \t\tone = 1;
+ wire [2:0] \t\tcnt = (one + one + one + one);
+
+endmodule
+
+module p
+ #(parameter WIDTH=64)
+ (input [WIDTH-1:0] in);
+ wire [4:0] out = in;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008-2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ reg [4*8:1] strg;
+
+ initial begin
+ strg = ""CHK"";
+ if (strg != ""CHK"") $stop;
+ if (strg == ""JOE"") $stop;
+ $write(""String = %s = %x\
+"", strg, strg);
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg [255:0] \t\ta;
+ reg [255:0] \t\tq;
+ reg [63:0] \t\tqq;
+
+ integer \t\ti;
+ always @* begin
+ for (i=0; i<256; i=i+1) begin
+\t q[255-i] = a[i];
+ end
+ q[27:16] = 12\'hfed;
+ for (i=0; i<64; i=i+1) begin
+\t qq[63-i] = a[i];
+ end
+ qq[27:16] = 12\'hfed;
+ end
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+`ifdef TEST_VERBOSE
+\t $write(""%x/%x %x\
+"", q, qq, a);
+`endif
+\t if (cyc==1) begin
+\t a = 256\'hed388e646c843d35de489bab2413d77045e0eb7642b148537491f3da147e7f26;
+\t end
+\t if (cyc==2) begin
+\t a = 256\'h0e17c88f3d5fe51a982646c8e2bd68c3e236ddfddddbdad20a48e039c9f395b8;
+\t if (q != 256\'h64fe7e285bcf892eca128d426ed707a20eebc824d5d9127bacbc21362fed1cb7) $stop;
+\t if (qq != 64\'h64fe7e285fed892e) $stop;
+\t end
+\t if (cyc==3) begin
+\t if (q != 256\'h1da9cf939c0712504b5bdbbbbfbb6c47c316bd471362641958a7fabcffede870) $stop;
+\t if (qq != 64\'h1da9cf939fed1250) $stop;
+\t end
+\t if (cyc==4) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+package defs;
+ function automatic integer max;
+ input integer a;
+ input integer b;
+ max = (a > b) ? a : b;
+ endfunction
+
+ function automatic integer log2;
+ input integer value;
+ value = value >> 1;
+ for (log2 = 0; value > 0; log2 = log2 + 1)
+ value = value >> 1;
+ endfunction
+
+ function automatic integer ceil_log2;
+ input integer value;
+ value = value - 1;
+ for (ceil_log2 = 0; value > 0; ceil_log2 = ceil_log2 + 1)
+ value = value >> 1;
+ endfunction
+endpackage
+
+module sub();
+
+ import defs::*;
+
+ parameter RAND_NUM_MAX = """";
+
+ localparam DATA_RANGE = RAND_NUM_MAX + 1;
+ localparam DATA_WIDTH = ceil_log2(DATA_RANGE);
+ localparam WIDTH = max(4, ceil_log2(DATA_RANGE + 1));
+
+endmodule
+
+module t(/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ import defs::*;
+
+ parameter WHICH = 0;
+ parameter MAX_COUNT = 10;
+
+ localparam MAX_EXPONENT = log2(MAX_COUNT);
+ localparam EXPONENT_WIDTH = ceil_log2(MAX_EXPONENT + 1);
+
+ input clk;
+
+ generate
+ if (WHICH == 1)
+\tbegin : which_true
+ sub sub_true();
+ defparam sub_true.RAND_NUM_MAX = MAX_EXPONENT;
+\tend
+ else
+\tbegin : which_false
+ sub sub_false();
+ defparam sub_false.RAND_NUM_MAX = MAX_COUNT;
+\tend
+ endgenerate
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2009 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+`ifdef VCS
+ `define NO_SHORTREAL
+`endif
+`ifdef NC
+ `define NO_SHORTREAL
+`endif
+`ifdef VERILATOR // Unsupported
+ `define NO_SHORTREAL
+`endif
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ // Allowed import return types:
+ // void, byte, shortint, int, longint, real, shortreal, chandle, and string
+ // Scalar bit and logic
+ //
+ // Allowed argument types:
+ //\t Same as above plus packed arrays
+
+ import ""DPI-C"" pure function bit dpii_f_bit (input bit i);
+ import ""DPI-C"" pure function bit [8-1:0] dpii_f_bit8 (input bit [8-1:0] i);
+ import ""DPI-C"" pure function bit [9-1:0] dpii_f_bit9 (input bit [9-1:0] i);
+ import ""DPI-C"" pure function bit [16-1:0] dpii_f_bit16 (input bit [16-1:0] i);
+ import ""DPI-C"" pure function bit [17-1:0] dpii_f_bit17 (input bit [17-1:0] i);
+ import ""DPI-C"" pure function bit [32-1:0] dpii_f_bit32 (input bit [32-1:0] i);
+ // Illegal to return > 32 bits, so we use longint
+ import ""DPI-C"" pure function longint dpii_f_bit33 (input bit [33-1:0] i);
+ import ""DPI-C"" pure function longint\t dpii_f_bit64 (input bit [64-1:0] i);
+ import ""DPI-C"" pure function int dpii_f_int (input int i);
+ import ""DPI-C"" pure function byte dpii_f_byte (input byte i);
+ import ""DPI-C"" pure function shortint dpii_f_shortint (input shortint i);
+ import ""DPI-C"" pure function longint dpii_f_longint (input longint i);
+ import ""DPI-C"" pure function chandle dpii_f_chandle (input chandle i);
+ import ""DPI-C"" pure function string dpii_f_string (input string i);
+ import ""DPI-C"" pure function real dpii_f_real (input real i);
+`ifndef NO_SHORTREAL
+ import ""DPI-C"" pure function shortreal dpii_f_shortreal(input shortreal i);
+`endif
+
+ import ""DPI-C"" pure function void dpii_v_bit (input bit i, output bit o);
+ import ""DPI-C"" pure function void dpii_v_int (input int i, output int o);
+ import ""DPI-C"" pure function void dpii_v_byte (input byte i, output byte o);
+ import ""DPI-C"" pure function void dpii_v_shortint (input shortint i, output shortint o);
+ import ""DPI-C"" pure function void dpii_v_longint (input longint i, output longint o);
+ import ""DPI-C"" pure function void dpii_v_chandle (input chandle i, output chandle o);
+ import ""DPI-C"" pure function void dpii_v_string (input string i, output string o);
+ import ""DPI-C"" pure function void dpii_v_real (input real i, output real o);
+
+ import ""DPI-C"" pure function void dpii_v_uint (input int unsigned i, output int unsigned o);
+ import ""DPI-C"" pure function void dpii_v_ushort (input shortint unsigned i, output shortint unsigned o);
+ import ""DPI-C"" pure function void dpii_v_ulong (input longint unsigned i, output longint unsigned o);
+`ifndef NO_SHORTREAL
+ import ""DPI-C"" pure function void dpii_v_shortreal(input shortreal i, output shortreal o);
+`endif
+ import ""DPI-C"" pure function void dpii_v_bit64 (input bit [64-1:0] i, output bit [64-1:0] o);
+ import ""DPI-C"" pure function void dpii_v_bit95 (input bit [95-1:0] i, output bit [95-1:0] o);
+ import ""DPI-C"" pure function void dpii_v_bit96 (input bit [96-1:0] i, output bit [96-1:0] o);
+
+ import ""DPI-C"" pure function int dpii_f_strlen (input string i);
+
+ import ""DPI-C"" function void dpii_f_void ();
+
+ // Try a task
+ import ""DPI-C"" task dpii_t_void ();
+ import ""DPI-C"" context task dpii_t_void_context ();
+
+ import ""DPI-C"" task dpii_t_int (input int i, output int o);
+
+ // Try non-pure, aliasing with name
+ import ""DPI-C"" dpii_fa_bit = function int oth_f_int1(input int i);
+ import ""DPI-C"" dpii_fa_bit = function int oth_f_int2(input int i);
+
+ bit \ti_b,\to_b;
+ bit [7:0] i_b8;
+ bit [8:0]\ti_b9;
+ bit [15:0]\ti_b16;
+ bit [16:0] i_b17;
+ bit [31:0]\ti_b32;
+ bit [32:0]\ti_b33,\to_b33;
+ bit [63:0]\ti_b64,\to_b64;
+ bit [94:0]\ti_b95,\to_b95;
+ bit [95:0]\ti_b96,\to_b96;
+
+ int\t\ti_i,\to_i;
+ byte\t\ti_y,\to_y;
+ shortint\ti_s,\to_s;
+ longint\ti_l,\to_l;
+ int unsigned\t\ti_iu,\to_iu;
+ shortint unsigned\ti_su,\to_su;
+ longint unsigned\ti_lu,\to_lu;
+ // verilator lint_off UNDRIVEN
+ chandle\ti_c,\to_c;
+ string \ti_n,\to_n;
+ // verilator lint_on UNDRIVEN
+ real \ti_d,\to_d;
+`ifndef NO_SHORTREAL
+ shortreal \ti_f,\to_f;
+`endif
+
+ bit [94:0] wide;
+
+ bit [6*8:1] string6;
+
+ initial begin
+ wide = 95\'h15caff7a73c48afee4ffcb57;
+
+ i_b = 1\'b1;
+ i_b8 = {1\'b1,wide[8-2:0]};
+ i_b9 = {1\'b1,wide[9-2:0]};
+ i_b16 = {1\'b1,wide[16-2:0]};
+ i_b17 = {1\'b1,wide[17-2:0]};
+ i_b32 = {1\'b1,wide[32-2:0]};
+ i_b33 = {1\'b1,wide[33-2:0]};
+ i_b64 = {1\'b1,wide[64-2:0]};
+ i_b95 = {1\'b1,wide[95-2:0]};
+ i_b96 = {1\'b1,wide[96-2:0]};
+
+ i_i = {1\'b1,wide[32-2:0]};
+ i_iu= {1\'b1,wide[32-2:0]};
+ i_y = {1\'b1,wide[8-2:0]};
+ i_s = {1\'b1,wide[16-2:0]};
+ i_su= {1\'b1,wide[16-2:0]};
+ i_l = {1\'b1,wide[64-2:0]};
+ i_lu= {1\'b1,wide[64-2:0]};
+ i_d = 32.1;
+`ifndef NO_SHORTREAL
+ i_f = 30.2;
+`endif
+
+ if (dpii_f_bit (i_b) !== ~i_b) $stop;
+ if (dpii_f_bit8 (i_b8) !== ~i_b8) $stop;
+ if (dpii_f_bit9 (i_b9) !== ~i_b9) $stop;
+ if (dpii_f_bit16 (i_b16) !== ~i_b16) $stop;
+ if (dpii_f_bit17 (i_b17) !== ~i_b17) $stop;
+ if (dpii_f_bit32 (i_b32) !== ~i_b32) $stop;
+
+ // These return different sizes, so we need to truncate
+ // verilator lint_off WIDTH
+ o_b33 = dpii_f_bit33 (i_b33);
+ o_b64 = dpii_f_bit64 (i_b64);
+ // verilator lint_on WIDTH
+ if (o_b33 !== ~i_b33) $stop;
+ if (o_b64 !== ~i_b64) $stop;
+
+ if (dpii_f_bit (i_b) !== ~i_b) $stop;
+ if (dpii_f_int (i_i) !== ~i_i) $stop;
+ if (dpii_f_byte (i_y) !== ~i_y) $stop;
+ if (dpii_f_shortint (i_s) !== ~i_s) $stop;
+ if (dpii_f_longint (i_l) !== ~i_l) $stop;
+ if (dpii_f_chandle (i_c) !== i_c) $stop;
+ if (dpii_f_string (i_n) != i_n) $stop;
+ if (dpii_f_real (i_d) != i_d+1.5) $stop;
+`ifndef NO_SHORTREAL
+ if (dpii_f_shortreal(i_f) != i_f+1.5) $stop;
+`endif
+
+ dpii_v_bit (i_b,o_b); if (o_b !== ~i_b) $stop;
+ dpii_v_int (i_i,o_i); if (o_i !== ~i_i) $stop;
+ dpii_v_byte (i_y,o_y); if (o_y !== ~i_y) $stop;
+ dpii_v_shortint (i_s,o_s); if (o_s !== ~i_s) $stop;
+ dpii_v_longint (i_l,o_l); if (o_l !== ~i_l) $stop;
+ dpii_v_uint (i_iu,o_iu); if (o_iu !== ~i_iu) $stop;
+ dpii_v_ushort (i_su,o_su); if (o_su !== ~i_su) $stop;
+ dpii_v_ulong (i_lu,o_lu); if (o_lu !== ~i_lu) $stop;
+ dpii_v_chandle (i_c,o_c); if (o_c !== i_c) $stop;
+ dpii_v_string (i_n,o_n); if (o_n != i_n) $stop;
+ dpii_v_real (i_d,o_d); if (o_d != i_d+1.5) $stop;
+`ifndef NO_SHORTREAL
+ dpii_v_shortreal(i_f,o_f); if (o_f != i_f+1.5) $stop;
+`endif
+ dpii_v_bit64 (i_b64,o_b64); if (o_b64 !== ~i_b64) $stop;
+ dpii_v_bit95 (i_b95,o_b95); if (o_b95 !== ~i_b95) $stop;
+ dpii_v_bit96 (i_b96,o_b96); if (o_b96 !== ~i_b96) $stop;
+
+ if (dpii_f_strlen ("""")!=0) $stop;
+ if (dpii_f_strlen (""s"")!=1) $stop;
+ if (dpii_f_strlen (""st"")!=2) $stop;
+ if (dpii_f_strlen (""str"")!=3) $stop;
+ if (dpii_f_strlen (""stri"")!=4) $stop;
+ if (dpii_f_strlen (""string_l"")!=8) $stop;
+ if (dpii_f_strlen (""string_len"")!=10) $stop;
+ string6 = ""hello6"";
+`ifdef VERILATOR
+ string6 = $c48(string6); // Don\'t optimize away - want to see the constant conversion function
+`endif
+ if (dpii_f_strlen (string6) != 6) $stop;
+
+ dpii_f_void();
+ dpii_t_void();
+ dpii_t_void_context();
+
+ i_i = 32\'h456789ab;
+ dpii_t_int (i_i,o_i); if (o_b !== ~i_b) $stop;
+
+ // Check alias
+ if (oth_f_int1(32\'d123) !== ~32\'d123) $stop;
+ if (oth_f_int2(32\'d124) !== ~32\'d124) $stop;
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ always @ (posedge clk) begin
+ i_b <= ~i_b;
+ // This once mis-threw a BLKSEQ warning
+ dpii_v_bit (i_b,o_b); if (o_b !== ~i_b) $stop;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ function int f_no_no ();
+ int st = 2; st++; return st;
+ endfunction
+ function int f_no_st ();
+ static int st = 2; st++; return st;
+ endfunction
+ function int f_no_au ();
+ automatic int st = 2; st++; return st;
+ endfunction
+
+ function static int f_st_no ();
+ int st = 2; st++; return st;
+ endfunction
+ function static int f_st_st ();
+ static int st = 2; st++; return st;
+ endfunction
+ function static int f_st_au ();
+ automatic int st = 2; st++; return st;
+ endfunction
+
+ function automatic int f_au_no ();
+ int st = 2; st++; return st;
+ endfunction
+ function automatic int f_au_st ();
+ static int st = 2; st++; return st;
+ endfunction
+ function automatic int f_au_au ();
+ automatic int st = 2; st++; return st;
+ endfunction
+
+ initial begin
+ if (f_no_no() != 3) $stop;
+ if (f_no_no() != 4) $stop;
+ if (f_no_st() != 3) $stop;
+ if (f_no_st() != 4) $stop;
+ if (f_no_au() != 3) $stop;
+ if (f_no_au() != 3) $stop;
+ //
+ if (f_st_no() != 3) $stop;
+ if (f_st_no() != 4) $stop;
+ if (f_st_st() != 3) $stop;
+ if (f_st_st() != 4) $stop;
+ if (f_st_au() != 3) $stop;
+ if (f_st_au() != 3) $stop;
+ //
+ if (f_au_no() != 3) $stop;
+ if (f_au_no() != 3) $stop;
+ if (f_au_st() != 3) $stop;
+ if (f_au_st() != 4) $stop;
+ if (f_au_au() != 3) $stop;
+ if (f_au_au() != 3) $stop;
+ //
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ reg \t toggle;
+ integer cyc; initial cyc=1;
+
+ Test suba (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle\t\t\t(toggle),
+\t .cyc\t\t\t(cyc[31:0]));
+ Test subb (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle\t\t\t(toggle),
+\t .cyc\t\t\t(cyc[31:0]));
+ Test subc (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle\t\t\t(toggle),
+\t .cyc\t\t\t(cyc[31:0]));
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t toggle <= !cyc[0];
+\t if (cyc==9) begin
+\t end
+\t if (cyc==10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+module Test
+ (
+ input clk,
+ input toggle,
+ input [31:0] cyc
+ );
+
+ // Don\'t flatten out these modules please:
+ // verilator no_inline_module
+
+ // Labeled cover
+ cyc_eq_5: cover property (@(posedge clk) cyc==5) $display(""*COVER: Cyc==5"");
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (clk);
+
+ input clk;
+
+ reg [7:0] \ta,b;
+ wire [7:0] \tz;
+
+ mytop u0 ( a, b, clk, z );
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t //$write(""%d %x\
+"", cyc, z);
+\t if (cyc==1) begin
+\t a <= 8\'h07;
+\t b <= 8\'h20;
+\t end
+\t if (cyc==2) begin
+\t a <= 8\'h8a;
+\t b <= 8\'h12;
+\t end
+\t if (cyc==3) begin
+\t if (z !== 8\'hdf) $stop;
+\t a <= 8\'h71;
+\t b <= 8\'hb2;
+\t end
+\t if (cyc==4) begin
+\t if (z !== 8\'hed) $stop;
+\t end
+\t if (cyc==5) begin
+\t if (z !== 8\'h4d) $stop;
+\t end
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule // mytop
+
+module inv(
+ input [ 7:0 ] a,
+ output [ 7:0 ] z
+ );
+ wire [7:0] \t\t z = ~a;
+endmodule
+
+
+module ftest(
+ input [ 7:0 ] a,
+ b, // Test legal syntax
+ input clk,
+ output [ 7:0 ] z
+ );
+
+ wire [7:0] \t\t zi;
+ reg [7:0] \t\t z;
+
+ inv u1 (.a(myadd(a,b)),
+\t .z(zi));
+
+
+ always @ ( posedge clk ) begin
+ z <= myadd( a, zi );
+ end
+
+ function [ 7:0 ] myadd;
+ input [7:0] ina;
+ input [7:0] inb;
+
+ begin
+ myadd = ina + inb;
+ end
+ endfunction // myadd
+
+endmodule // ftest
+
+module mytop (
+ input [ 7:0 ] a,
+ b,
+ input clk,
+ output [ 7:0 ] z
+ );
+
+ ftest u0( a, b, clk, z );
+
+endmodule // mytop
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg [125:0] a;
+ wire q;
+
+ sub sub (
+\t .q\t\t\t\t(q),
+\t .a\t\t\t\t(a),
+\t .clk\t\t\t(clk));
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t a <= 126\'b1000;
+\t end
+\t if (cyc==2) begin
+\t a <= 126\'h1001;
+\t end
+\t if (cyc==3) begin
+\t a <= 126\'h1010;
+\t end
+\t if (cyc==4) begin
+\t a <= 126\'h1111;
+\t if (q !== 1\'b0) $stop;
+\t end
+\t if (cyc==5) begin
+\t if (q !== 1\'b1) $stop;
+\t end
+\t if (cyc==6) begin
+\t if (q !== 1\'b0) $stop;
+\t end
+\t if (cyc==7) begin
+\t if (q !== 1\'b0) $stop;
+\t end
+\t if (cyc==8) begin
+\t if (q !== 1\'b0) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+module sub (
+ input clk,
+ input [125:0] a,
+ output reg q
+ );
+
+ // verilator public_module
+
+ reg [125:0] g_r;
+
+ wire [127:0] g_extend = { g_r, 1\'b1, 1\'b0 };
+
+ reg [6:0] sel;
+ wire g_sel = g_extend[sel];
+
+ always @ (posedge clk) begin
+ g_r <= a;
+ sel <= a[6:0];
+ q <= g_sel;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+ integer \tcyc=0;
+
+ // Trace would overflow at 256KB which is 256 kb dump, 16 kb in a chunk
+
+ typedef struct packed {
+ logic [1024*1024:0] d;
+ } s1_t; // 128 b
+
+ s1_t biggie;
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ biggie [ cyc +: 32 ] <= 32\'hfeedface;
+ if (cyc == 5) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0)
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+ /*AUTOWIRE*/
+
+ generate
+ for (genvar width=1; width<=16; width++) begin
+\t for (genvar amt=1; amt<=width; amt++) begin
+\t Test #(.WIDTH(width),
+\t\t .AMT(amt))
+\t test (.ins(crc[width-1:0]));
+\t end
+ end
+ endgenerate
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x\
+"",
+\t $time, cyc, crc);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h0
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Inputs
+ ins
+ );
+
+ parameter WIDTH = 1;
+ parameter AMT = 1;
+
+ input [WIDTH-1:0] ins;
+ reg [WIDTH-1:0] got;
+ reg [WIDTH-1:0] expec;
+ int \t\t istart;
+ int \t\t bitn;
+ int \t\t ostart;
+
+ always @* begin
+ got = { << AMT {ins}};
+
+ // Note always starts with right-most bit
+ expec = 0;
+ for (istart=0; istart= 0
+\t\t&& (ostart+bitn) < WIDTH
+\t\t&& (ostart+bitn) >= 0) begin
+\t expec[ostart+bitn] = ins[istart+bitn];
+\t end
+\t end
+ end
+
+`ifdef TEST_VERBOSE
+ $write(""[%0t] exp %0d\'b%b got %0d\'b%b = { << %0d { %0d\'b%b }}\
+"", $time, WIDTH, expec, WIDTH, got, AMT, WIDTH, ins);
+`endif
+ `checkh(got, expec);
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // verilator lint_off MULTIDRIVEN
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [31:0]\t\tout;\t\t\t// From test of Test.v
+ wire [15:0]\t\tout2;\t\t\t// From test of Test.v
+ // End of automatics
+ // verilator lint_on MULTIDRIVEN
+
+ Test test (
+\t .en (crc[21:20]),
+\t .a1 (crc[19:18]),
+\t .a0 (crc[17:16]),
+\t .d1 (crc[15:8]),
+\t .d0 (crc[7:0]),
+\t /*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[31:0]),
+\t .out2\t\t\t(out2[15:0]),
+\t // Inputs
+\t .clk\t\t\t(clk));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {out2, 16\'h0, out};
+
+ // Test loop
+`ifdef TEST_VERBOSE
+ always @ (negedge clk) begin
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+ end
+`endif
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+\t test.clear();
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+\t test.clear();
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'hc68a94a34ec970aa
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out, out2,
+ // Inputs
+ clk, en, a0, a1, d0, d1
+ );
+
+ input clk;
+ input [1:0] en;
+ input [1:0] a0;
+ input [1:0] a1;
+ input [7:0] d0;
+ input [7:0] d1;
+ output reg [31:0] out;
+ output reg [15:0] out2;
+
+ // verilator lint_off MULTIDRIVEN
+ reg [7:0] \t mem [4];
+ // verilator lint_on MULTIDRIVEN
+
+ task clear();
+ for (int i=0; i<4; ++i) mem[i] = 0;
+ endtask
+
+ always @(posedge clk) begin
+ if (en[0]) begin
+\t mem[a0] <= d0;
+\t out2[7:0] <= d0;
+ end
+ end
+ always @(negedge clk) begin
+ if (en[1]) begin
+\t mem[a1] <= d1;
+\t out2[15:8] <= d0;
+ end
+ end
+
+ assign out = {mem[3],mem[2],mem[1],mem[0]};
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Test of select from constant
+//
+// This tests issue 508, bit select of constant fails
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Jeremy Bennett.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // Note that if we declare ""wire [0:0] b"", this works just fine.
+ wire a;
+ wire b;
+
+ assign b = 1\'b0;
+ assign a = b[0]; // IEEE illegal can\'t extract scalar
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+ wire ok = 1'b0;
+ sub sub (.ok(ok), , .nc());
+endmodule
+
+module sub (input ok, input none, input nc, input missing);
+ initial if (ok && none && nc && missing) begin end // No unused warning
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test for short-circuiting in generate ""if""
+//
+// The given generate loops should only access valid bits of mask, since that
+// is defined by SIZE. However since the loop range is larger, this only works
+// if short-circuited evaluation of the generate loop is in place.
+
+// This file ONLY is placed into the Public Domain, for any use, without
+// warranty, 2012 by Jeremy Bennett.
+
+
+`define MAX_SIZE 4
+
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ // Set the parameters, so that we use a size less than MAX_SIZE
+ test_gen
+ #(.SIZE (2),
+ .MASK (2\'b11))
+ i_test_gen (.clk (clk));
+
+ // This is only a compilation test, but for good measure we do one clock
+ // cycle.
+ integer count;
+
+ initial begin
+ count = 0;
+ end
+
+ always @(posedge clk) begin
+ if (count == 1) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ else begin
+\t count = count + 1;
+ end
+ end
+
+endmodule // t
+
+
+module test_gen
+
+ #( parameter
+ SIZE = `MAX_SIZE,
+ MASK = `MAX_SIZE\'b0)
+
+ (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // Generate blocks that rely on short-circuiting of the logic to avoid errors.
+ generate
+ genvar g;
+
+ for (g = 0; g < `MAX_SIZE; g = g + 1) begin
+ if ((g < SIZE) && MASK[g]) begin
+\t always @(posedge clk) begin
+`ifdef TEST_VERBOSE
+\t $write (""Logical AND generate if MASK [%1d] = %d\
+"", g, MASK[g]);
+`endif
+\t if (g >= SIZE) begin
+\t\t $stop;
+\t end
+\t end
+\t end
+ end
+ endgenerate
+
+ generate
+ for (g = 0; g < `MAX_SIZE; g = g + 1) begin
+ if (!((g >= SIZE) || ~MASK[g])) begin
+\t always @(posedge clk) begin
+`ifdef TEST_VERBOSE
+\t $write (""Logical OR generate if MASK [%1d] = %d\
+"", g, MASK[g]);
+`endif
+\t if (g >= SIZE) begin
+\t\t $stop;
+\t end
+\t end
+\t end
+ end
+ endgenerate
+
+ generate
+ for (g = 0; g < `MAX_SIZE; g = g + 1) begin
+ if (!((g < SIZE) -> ~MASK[g])) begin
+\t always @(posedge clk) begin
+`ifdef TEST_VERBOSE
+\t $write (""Logical infer generate if MASK [%1d] = %d\
+"", g, MASK[g]);
+`endif
+\t if (g >= SIZE) begin
+\t\t $stop;
+\t end
+\t end
+\t end
+ end
+ endgenerate
+
+ generate
+ for (g = 0; g < `MAX_SIZE; g = g + 1) begin
+ if ( g < SIZE ? MASK[g] : 1\'b0) begin
+\t always @(posedge clk) begin
+`ifdef TEST_VERBOSE
+\t $write (""Conditional generate if MASK [%1d] = %d\
+"", g, MASK[g]);
+`endif
+\t if (g >= SIZE) begin
+\t\t $stop;
+\t end
+\t end
+\t end
+ end
+ endgenerate
+
+ // The other way round
+ generate
+ for (g = 0; g < `MAX_SIZE; g = g + 1) begin
+ if ( g >= SIZE ? 1\'b0 : MASK[g]) begin
+\t always @(posedge clk) begin
+`ifdef TEST_VERBOSE
+\t $write (""Conditional generate if MASK [%1d] = %d\
+"", g, MASK[g]);
+`endif
+\t if (g >= SIZE) begin
+\t\t $stop;
+\t end
+\t end
+\t end
+ end
+ endgenerate
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+// Very simple test for interface pathclearing
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc=1;
+
+ ifc #(2) itopa();
+ ifc #(4) itopb();
+
+ sub ca (.isub(itopa.out_modport),
+\t .clk);
+ sub cb (.isub(itopb.out_modport),
+\t .clk);
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d result=%b %b\
+"",$time, cyc, itopa.valueo, itopb.valueo);
+`endif
+ cyc <= cyc + 1;
+ itopa.valuei <= cyc[1:0];
+ itopb.valuei <= cyc[3:0];
+ if (cyc==1) begin
+\t if (itopa.WIDTH != 2) $stop;
+\t if (itopb.WIDTH != 4) $stop;
+\t if ($bits(itopa.valueo) != 2) $stop;
+\t if ($bits(itopb.valueo) != 4) $stop;
+\t if ($bits(itopa.out_modport.valueo) != 2) $stop;
+\t if ($bits(itopb.out_modport.valueo) != 4) $stop;
+ end
+ if (cyc==4) begin
+\t if (itopa.valueo != 2\'b11) $stop;
+\t if (itopb.valueo != 4\'b0011) $stop;
+ end
+ if (cyc==5) begin
+\t if (itopa.valueo != 2\'b00) $stop;
+\t if (itopb.valueo != 4\'b0100) $stop;
+ end
+ if (cyc==20) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+interface ifc
+ #(parameter WIDTH = 1);
+ // verilator lint_off MULTIDRIVEN
+ logic [WIDTH-1:0] valuei;
+ logic [WIDTH-1:0] valueo;
+ // verilator lint_on MULTIDRIVEN
+ modport out_modport (input valuei, output valueo);
+endinterface
+
+// Note not parameterized
+module sub
+ (
+ ifc.out_modport isub,
+ input clk
+ );
+ always @(posedge clk) isub.valueo <= isub.valuei + 1;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+// bug511
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ wire [7:0] au;
+ wire [7:0] as;
+
+ Test1 test1 (.au);
+ Test2 test2 (.as);
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] result=%x %x\
+"",$time, au, as);
+`endif
+ if (au != \'h12) $stop;
+ if (as != \'h02) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+module Test1 (output [7:0] au);
+ wire [7:0] \t\tb;
+ wire signed [3:0] \tc;
+
+ // verilator lint_off WIDTH
+ assign c=-1; // \'hf
+ assign b=3; // \'h3
+ assign au=b+c; // \'h12
+ // verilator lint_on WIDTH
+endmodule
+
+
+module Test2 (output [7:0] as);
+ wire signed [7:0] \tb;
+ wire signed [3:0] \tc;
+
+ // verilator lint_off WIDTH
+ assign c=-1; // \'hf
+ assign b=3; // \'h3
+ assign as=b+c; // \'h12
+ // verilator lint_on WIDTH
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=0;
+ reg [63:0] crc;
+ reg [63:0] sum;
+
+`ifdef ALLOW_UNOPT
+ /*verilator lint_off UNOPTFLAT*/
+`endif
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [31:0]\t\tb;\t\t\t// From file of file.v
+ wire [31:0]\t\tc;\t\t\t// From file of file.v
+ wire [31:0]\t\td;\t\t\t// From file of file.v
+ // End of automatics
+
+ file file (/*AUTOINST*/
+\t // Outputs
+\t .b\t\t\t(b[31:0]),
+\t .c\t\t\t(c[31:0]),
+\t .d\t\t\t(d[31:0]),
+\t // Inputs
+\t .crc\t\t\t(crc[31:0]));
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc=%0d crc=%x sum=%x b=%x d=%x\
+"",$time,cyc,crc,sum, b, d);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= {b, d}
+\t ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $write(""[%0t] cyc==%0d crc=%x %x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t if (sum !== 64\'h649ee1713d624dd9) $stop;
+\t $finish;
+ end
+ end
+
+endmodule
+
+module file (/*AUTOARG*/
+ // Outputs
+ b, c, d,
+ // Inputs
+ crc
+ );
+
+ input [31:0] crc;
+`ifdef ISOLATE
+ output reg [31:0] b /* verilator isolate_assignments*/;
+`else
+ output reg [31:0] b;
+`endif
+
+ output reg [31:0] c;
+ output reg [31:0] d;
+
+ always @* begin
+ // Note that while c and b depend on crc, b doesn\'t depend on c.
+ casez (crc[3:0])
+\t4\'b??01: begin
+\t b = {crc[15:0],get_31_16(crc)};
+\t d = c;
+\tend
+\t4\'b??00: begin
+\t b = {crc[15:0],~crc[31:16]};
+\t d = {crc[15:0],~c[31:16]};
+\tend
+\tdefault: begin
+\t set_b_d(crc, c);
+\tend
+ endcase
+ end
+
+ function [31:16] get_31_16\t/* verilator isolate_assignments*/;
+ input [31:0] t_crc\t/* verilator isolate_assignments*/;
+ get_31_16 = t_crc[31:16];
+ endfunction
+
+ task set_b_d;
+`ifdef ISOLATE
+ input [31:0] t_crc\t/* verilator isolate_assignments*/;
+ input [31:0] t_c\t\t/* verilator isolate_assignments*/;
+`else
+ input [31:0] t_crc;
+ input [31:0] t_c;
+`endif
+ begin
+\t b = {t_crc[31:16],~t_crc[23:8]};
+\t d = {t_crc[31:16], ~t_c[23:8]};
+ end
+ endtask
+
+ always @* begin
+ // Any complicated equation we can\'t optimize
+ casez (crc[3:0])
+\t4\'b00??: begin
+\t c = {b[29:0],2\'b11};
+\tend
+\t4\'b01??: begin
+\t c = {b[30:1],2\'b01};
+\tend
+\t4\'b10??: begin
+\t c = {b[31:2],2\'b10};
+\tend
+\t4\'b11??: begin
+\t c = {b[31:2],2\'b00};
+\tend
+ endcase
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ liblib_a a ();
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+// see bug 474
+package functions;
+ localparam LP_PACK = 512;
+ localparam LP_PACK_AND_MOD = 19;
+ task check_param;
+ $display(""In %m\
+""); // ""In functions::check_param""
+ if (LP_PACK_AND_MOD != 19) $stop;
+ endtask
+endpackage
+
+module t ();
+ // synthesis translate off
+ import functions::*;
+ // synthesis translate on
+ localparam LP_PACK_AND_MOD = 20;
+ initial begin
+ // verilator lint_off STMTDLY
+ #10;
+ // verilator lint_on STMTDLY
+ if (LP_PACK_AND_MOD != 20) $stop;
+ check_param();
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+
+\t\t\t\t\t\t"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ q,
+ // Inputs
+ clk, d
+ );
+ input clk;
+ input d;
+ output wire [1:0] q;
+
+ // This demonstrates how warning disables should be propagated across module boundaries.
+
+ m1 m1 (/*AUTOINST*/
+\t // Outputs
+\t .q\t\t\t\t(q[1:0]),
+\t // Inputs
+\t .clk\t\t\t\t(clk),
+\t .d\t\t\t\t(d));
+endmodule
+
+module m1
+ (
+ input clk,
+ input d,
+ output wire [1:0] q
+ );
+
+ m2 m2 (/*AUTOINST*/
+\t // Outputs
+\t .q\t\t\t\t(q[1:0]),
+\t // Inputs
+\t .clk\t\t\t\t(clk),
+\t .d\t\t\t\t(d));
+endmodule
+
+module m2
+ (
+ input clk,
+ input d,
+ // Due to bug the below disable used to be ignored.
+ // verilator lint_off UNOPT
+ output reg [1:0] q
+ // verilator lint_on UNOPT
+ );
+
+ always @* begin
+ q[1] = d;
+ end
+
+ always @* begin
+ q[0] = q[1];
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+ integer num;
+ initial begin
+ num = 0;
+
+`define EMPTY_TRUE
+`ifndef EMPTY_TRUE
+ `error ""Empty is still true""
+`endif
+
+`define A
+`ifdef A\t$display(""1A""); num = num + 1;
+ `ifdef C\t$stop;
+ `elsif A\t$display(""2A""); num = num + 1;
+ `ifdef C\t$stop;
+ `elsif B\t$stop;
+ `else\t\t$display(""3A""); num = num + 1;
+ `endif
+ `else\t\t$stop;
+ `endif
+ `elsif B\t$stop;
+ `ifdef A\t$stop;
+ `elsif A\t$stop;
+ `else
+ `endif
+`elsif C\t$stop;
+`else\t\t$stop;
+`endif
+ if (num == 3) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ else begin
+\t $write(""%%Error: Bad count: %d\
+"", num);
+\t $stop;
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+`begin_keywords ""VAMS-2.3""
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ task check (integer line, real got, real expec);
+ real delta;
+ delta = got-expec;
+ if (delta > 0.001) begin
+\t $display(""Line%d: Got %g Exp %g\
+"", line, got, expec);
+\t $stop;
+ end
+ endtask
+
+ wreal wr;
+ assign wr = 1.1;
+
+ sub sub (.*);
+
+ initial begin
+ check(`__LINE__, sqrt(2.0)\t, 1.414);
+ check(`__LINE__, pow(2.0,2.0)\t, 4.0);
+ check(`__LINE__, ln(2.0)\t\t, 0.693147);
+ check(`__LINE__, log(2.0)\t\t, 0.30103);
+ check(`__LINE__, floor(2.5)\t, 2.0);
+ check(`__LINE__, exp(2.0)\t\t, 7.38906);
+ check(`__LINE__, ceil(2.5)\t, 3.0);
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+
+module sub (
+\t input wreal wr
+\t );
+ initial begin
+ if (wr != 1.1) $stop;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Dedupe optimization test.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty.
+
+// Contributed 2012 by Varun Koyyalagunta, Centaur Technology.
+
+module t(res,d,clk,en);
+ output res;
+ input d,en,clk;
+ wire q0,q1,q2,q3;
+
+ flop_gated_latch f0(q0,d,clk,en);
+ flop_gated_latch f1(q1,d,clk,en);
+ flop_gated_flop f2(q2,d,clk,en);
+ flop_gated_flop f3(q3,d,clk,en);
+ assign res = (q0 + q1) * (q2 - q3);
+endmodule
+
+module flop_gated_latch(q,d,clk,en);
+ input d, clk, en;
+ output q;
+ wire gated_clock;
+ clock_gate_latch clock_gate(gated_clock, clk, en);
+ always @(posedge gated_clock) begin
+ q <= d;
+ end
+endmodule
+
+module flop_gated_flop(q,d,clk,en);
+ input d, clk, en;
+ output q;
+ wire gated_clock;
+ clock_gate_flop clock_gate(gated_clock, clk, en);
+ always @(posedge gated_clock) begin
+ q <= d;
+ end
+endmodule
+
+module clock_gate_latch (gated_clk, clk, clken);
+ output gated_clk;
+ input clk, clken;
+ reg clken_latched /*verilator clock_enable*/;
+ assign gated_clk = clk & clken_latched ;
+
+ wire clkb = ~clk;
+ always @(clkb or clken)
+ if(clkb) clken_latched = clken;
+
+endmodule
+
+module clock_gate_flop (gated_clk, clk, clken);
+ output gated_clk;
+ input clk, clken;
+ reg clken_r /*verilator clock_enable*/;
+ assign gated_clk = clk & clken_r ;
+
+ always @(negedge clk)
+ clken_r <= clken;
+
+endmodule
+"
+"////////////////////////////////////////////////////////////////////////////////
+// //
+// This file is placed into the Public Domain, for any use, without warranty. //
+// 2012 by Iztok Jeras //
+// //
+////////////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////////////
+// //
+// This testbench contains a bus source and a bus drain. The source creates //
+// address and data bus values, while the drain is the final destination of //
+// such pairs. All source and drain transfers are logged into memories, which //
+// are used at the end of simulation to check for data transfer correctness. //
+// Inside the RLT wrapper there is a multiplexer and a demultiplexer, they //
+// bus transfers into a 8bit data stream and back. Both stream input and //
+// output are exposed, they are connected together into a loopback. //
+// //
+// ----------- --------------------- //
+// | bso_mem | | wrap | //
+// ----------- | | //
+// ----------- | | ----------- | //
+// | bsi src | ------------> | -> | mux | -> | -> - sto //
+// ----------- | ----------- | \\ //
+// | | | loopback //
+// ----------- | ----------- | / //
+// | bso drn | <------------ | <- | demux | <- | <- - sti //
+// ----------- | | ----------- | //
+// ----------- | | //
+// | bso_mem | | | //
+// ----------- --------------------- //
+// //
+// PROTOCOL: //
+// //
+// The \'vld\' signal is driven by the source to indicate valid data is //
+// available, \'rdy\' is used by the drain to indicate is is ready to accept //
+// valid data. A data transfer only happens if both \'vld\' & \'rdy\' are active. //
+// //
+////////////////////////////////////////////////////////////////////////////////
+
+`timescale 1ns/1ps
+
+// include RTL files
+`include ""t_sv_bus_mux_demux/sv_bus_mux_demux_def.sv""
+`include ""t_sv_bus_mux_demux/sv_bus_mux_demux_demux.sv""
+`include ""t_sv_bus_mux_demux/sv_bus_mux_demux_mux.sv""
+`include ""t_sv_bus_mux_demux/sv_bus_mux_demux_wrap.sv""
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+input clk;
+
+parameter SIZ = 10;
+
+// system signals
+//logic clk = 1\'b1; // clock
+logic rst = 1\'b1; // reset
+integer rst_cnt = 0;
+
+// input bus
+logic bsi_vld; // valid (chip select)
+logic [31:0] bsi_adr; // address
+logic [31:0] bsi_dat; // data
+logic bsi_rdy; // ready (acknowledge)
+logic bsi_trn; // data transfer
+logic [31:0] bsi_mem [SIZ];
+// output stream
+logic sto_vld; // valid (chip select)
+logic [7:0] sto_bus; // data bus
+logic sto_rdy; // ready (acknowledge)
+
+// input stream
+logic sti_vld; // valid (chip select)
+logic [7:0] sti_bus; // data bus
+logic sti_rdy; // ready (acknowledge)
+// output bus
+logic bso_vld; // valid (chip select)
+logic [31:0] bso_adr; // address
+logic [31:0] bso_dat; // data
+logic bso_rdy; // ready (acknowledge)
+logic bso_trn; // data transfer
+logic [31:0] bso_mem [SIZ];
+integer bso_cnt = 0;
+
+////////////////////////////////////////////////////////////////////////////////
+// clock and reset
+////////////////////////////////////////////////////////////////////////////////
+
+// clock toggling
+//always #5 clk = ~clk;
+
+// reset is removed after a delay
+always @ (posedge clk)
+begin
+ rst_cnt <= rst_cnt + 1;
+ rst <= rst_cnt <= 3;
+end
+
+// reset is removed after a delay
+always @ (posedge clk)
+if (bso_cnt == SIZ) begin
+ if (bsi_mem === bso_mem) begin $write(""*-* All Finished *-*\
+""); $finish(); end
+ else begin $display (""FAILED""); $stop(); end
+end
+
+////////////////////////////////////////////////////////////////////////////////
+// input data generator
+////////////////////////////////////////////////////////////////////////////////
+
+// input data transfer
+assign bsi_trn = bsi_vld & bsi_rdy;
+
+// valid (for SIZ transfers)
+always @ (posedge clk, posedge rst)
+if (rst) bsi_vld = 1\'b0;
+else bsi_vld = (bsi_adr < SIZ);
+
+// address (increments every transfer)
+always @ (posedge clk, posedge rst)
+if (rst) bsi_adr <= 32\'h00000000;
+else if (bsi_trn) bsi_adr <= bsi_adr + \'d1;
+
+// data (new random value generated after every transfer)
+always @ (posedge clk, posedge rst)
+if (rst) bsi_dat <= 32\'h00000000;
+else if (bsi_trn) bsi_dat <= $random();
+
+// storing transferred data into memory for final check
+always @ (posedge clk)
+if (bsi_trn) bsi_mem [bsi_adr] <= bsi_dat;
+
+////////////////////////////////////////////////////////////////////////////////
+// RTL instance
+////////////////////////////////////////////////////////////////////////////////
+
+sv_bus_mux_demux_wrap wrap (
+ // system signals
+ .clk (clk),
+ .rst (rst),
+ // input bus
+ .bsi_vld (bsi_vld),
+ .bsi_adr (bsi_adr),
+ .bsi_dat (bsi_dat),
+ .bsi_rdy (bsi_rdy),
+ // output stream
+ .sto_vld (sto_vld),
+ .sto_bus (sto_bus),
+ .sto_rdy (sto_rdy),
+ // input stream
+ .sti_vld (sti_vld),
+ .sti_bus (sti_bus),
+ .sti_rdy (sti_rdy),
+ // output bus
+ .bso_vld (bso_vld),
+ .bso_adr (bso_adr),
+ .bso_dat (bso_dat),
+ .bso_rdy (bso_rdy)
+);
+
+// stream output from mux is looped back into stream input for demux
+assign sti_vld = sto_vld;
+assign sti_bus = sto_bus;
+assign sto_rdy = sti_rdy;
+
+////////////////////////////////////////////////////////////////////////////////
+// output data monitor
+////////////////////////////////////////////////////////////////////////////////
+
+// input data transfer
+assign bso_trn = bso_vld & bso_rdy;
+
+// output transfer counter used to end the test
+always @ (posedge clk, posedge rst)
+if (rst) bso_cnt <= 0;
+else if (bso_trn) bso_cnt <= bso_cnt + 1;
+
+// storing transferred data into memory for final check
+always @ (posedge clk)
+if (bso_trn) bso_mem [bso_adr] <= bso_dat;
+
+// every output transfer against expected value stored in memory
+always @ (posedge clk)
+if (bso_trn && (bsi_mem [bso_adr] !== bso_dat))
+$display (""@%08h i:%08h o:%08h"", bso_adr, bsi_mem [bso_adr], bso_dat);
+
+// ready is active for SIZ transfers
+always @ (posedge clk, posedge rst)
+if (rst) bso_rdy = 1\'b0;
+else bso_rdy = 1\'b1;
+
+endmodule : sv_bus_mux_demux_tb
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+// Very simple test for interface pathclearing
+
+interface ifc;
+ integer hidden_from_isub;
+ integer value;
+ modport out_modport (output value);
+endinterface
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc=1;
+
+ ifc itop();
+
+ sub c1 (.isub(itop),
+\t .i_value(4));
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==20) begin
+\t if (itop.value != 4) $stop;
+\t itop.hidden_from_isub = 20;
+\t if (itop.hidden_from_isub != 20) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module sub
+`ifdef NANSI // bug868
+ (
+ isub, i_value
+ );
+ ifc.out_modport isub; // Note parenthesis are not legal here
+ input integer i_value;
+`else
+ (
+ ifc.out_modport isub,
+ input integer i_value
+ );
+`endif
+
+ always @* begin
+ isub.value = i_value;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ x,
+ // Inputs
+ clk
+ );
+
+`ifdef ALLOW_UNOPT
+ /*verilator lint_off UNOPTFLAT*/
+`endif
+
+ input clk;
+ output x; // Avoid eliminating x
+
+ reg x;
+ always @* begin
+ x = ~x;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ reg [1:0] in;
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [1:0]\t\tout10;\t\t\t// From test of Test.v
+ wire [1:0]\t\tout32;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out32\t\t\t(out32[1:0]),
+\t .out10\t\t\t(out10[1:0]),
+\t // Inputs
+\t .in\t\t\t(in[1:0]));
+
+ // Test loop
+ always @ (posedge clk) begin
+ in <= in + 1;
+`ifdef TEST_VERBOSE
+ $write(""[%0t] in=%d out32=%d out10=%d\
+"",$time, in, out32, out10);
+`endif
+ if (in==3) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out32, out10,
+ // Inputs
+ in
+ );
+ input [1:0] in;
+ output [1:0] out32;
+ output [1:0] out10;
+
+ assign out32 = in[3:2];
+ assign out10 = in[1:0];
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Jeremy Bennett.
+
+module t (/*AUTOARG*/);
+
+ typedef enum int {
+\t\t PADTYPE_DEFAULT = 32\'d0,
+\t\t PADTYPE_GPIO,
+\t\t PADTYPE_VDD,
+\t\t PADTYPE_GND
+\t\t } t_padtype;
+
+ localparam int STR_PINID [0:15]
+\t\t = \'{
+\t\t ""DEF"", ""ERR"", ""ERR"", ""ERR"", ""ERR"", ""ERR"", ""ERR"", ""ERR"",
+\t\t ""PA0"", ""PA1"", ""PA2"", ""PA3"", ""PA4"", ""PA5"", ""PA6"", ""PA7""
+\t\t };
+
+ typedef struct packed {
+ t_padtype padtype;
+ int \t aux;
+ } t_pin_descriptor;
+
+ localparam t_pin_descriptor
+ PINOUT[ 1: 6]
+ = \'{
+\t \'{default:0, padtype:PADTYPE_GPIO, aux:1},
+\t \'{default:0, padtype:PADTYPE_GPIO},
+\t \'{default:0, padtype:PADTYPE_GPIO},
+\t \'{default:0, padtype:PADTYPE_GPIO},
+\t \'{default:0, padtype:PADTYPE_VDD},
+\t \'{default:0, padtype:PADTYPE_GND}
+\t };
+
+ localparam int PINOUT_SIZE = 6;
+ localparam int PINOUT_WA[1:PINOUT_SIZE][3]
+\t\t = \'{
+\t\t \'{0, PADTYPE_GPIO, 0},
+\t\t \'{1, PADTYPE_GPIO, 0},
+\t\t \'{2, PADTYPE_GPIO, 0},
+\t\t \'{5, PADTYPE_GPIO, 0},
+\t\t \'{6, PADTYPE_VDD, 0},
+\t\t \'{8, PADTYPE_GND , 0}
+\t\t };
+
+ const int pinout_static_const[1:PINOUT_SIZE][3]
+\t\t = \'{
+\t\t \'{0, PADTYPE_GPIO, 0},
+\t\t \'{1, PADTYPE_GPIO, 0},
+\t\t \'{2, PADTYPE_GPIO, 0},
+\t\t \'{5, PADTYPE_GPIO, 0},
+\t\t \'{6, PADTYPE_VDD, 0},
+\t\t \'{8, PADTYPE_GND , 0}
+\t\t };
+
+ // Make sure consants propagate
+ checkstr #(.PINID(STR_PINID[1]),
+\t .EXP(""ERR""))
+ substr1 ();
+ checkstr #(.PINID(STR_PINID[8]),
+\t .EXP(""PA0""))
+ substr8 ();
+
+ initial begin
+ $display(""PINID1 %s"", STR_PINID[1]);
+ $display(""PINID8 %s"", STR_PINID[8]);
+ if (STR_PINID[1] != ""ERR"") $stop;
+ if (STR_PINID[8] != ""PA0"") $stop;
+ if (pinout_static_const[1][0] != 0) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+module checkstr;
+ parameter int PINID = "" "";
+ parameter int EXP = "" "";
+ initial begin
+ $display(""PID %s EXP %s"", PINID, EXP);
+ if (EXP != ""ERR"" && EXP != ""PA0"") $stop;
+ if (PINID != EXP) $stop;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+// See bug408
+
+module top
+ (
+ output logic [1:0] q,
+ input logic [1:0] d,
+ input logic \t clk
+ );
+
+ genvar \t i;
+ assign \t q[i] = d[i];
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t;
+ reg [40:0] quad; initial quad = 41\'ha_bbbb_cccc;
+ reg [80:0] wide; initial wide = 81\'habc_1234_5678_1234_5678;
+ reg [31:0] str; initial str = ""\\000\\277\\021\
+"";
+ reg [47:0] str2; initial str2 = ""\\000what!"";
+ reg [79:0] str3; initial str3 = ""\\000hmmm!1234"";
+ reg [8:0] nine;
+
+ sub sub ();
+ sub2 sub2 ();
+
+ initial begin
+ $write(""[%0t] In %m: Hi\
+"", $time);
+ sub.write_m;
+ sub2.write_m;
+
+ // Escapes
+ $display(""[%0t] Back \\\\ Quote \\"""", $time); // Old bug when \\"" last on the line.
+
+ // Display formatting
+ nine = {3\'d0,quad[5:0]};
+ $display(""[%0t] %%X=%X %%0X=%0X %%0O=%0O %%B=%B"", $time,
+\t nine, nine, nine, nine);
+ $display(""[%0t] %%x=%x %%0x=%0x %%0o=%0o %%b=%b"", $time,
+\t nine, nine, nine, nine);
+ $display(""[%0t] %%D=%D %%d=%d %%01d=%01d %%06d=%06d %%6d=%6d"", $time,
+\t nine, nine, nine, nine, nine);
+ $display(""[%0t] %%x=%x %%0x=%0x %%o=%o %%b=%b"", $time,
+\t quad, quad, quad, quad);
+ $display(""[%0t] %%x=%x %%0x=%0x %%o=%o %%b=%b"", $time,
+\t wide, wide, wide, wide);
+ $display(""[%0t] %%t=%t %%03t=%03t %%0t=%0t"", $time,
+\t $time, $time, $time);
+ $display;
+ // Not testing %0s, it does different things in different simulators
+ $display(""[%0t] %%s=%s %%s=%s %%s=%s"", $time,
+\t str2[7:0], str2, str3);
+
+ $display(""[%0t] %s%s%s"", $time,
+\t ""hel"", ""lo, fr"", ""om a very long string. Percent %s are literally substituted in."");
+ $write(""[%0t] Embedded \\r return\
+"", $time);
+ $display(""[%0t] Embedded\\
+multiline"", $time);
+
+ // Str check
+`ifndef NC\t// NC-Verilog 5.3 chokes on this test
+ if (str !== 32\'h00_bf_11_0a) $stop;
+`endif
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+
+module sub;
+ task write_m;
+ begin
+\t $write(""[%0t] In %m\
+"", $time);
+\t begin : subblock
+\t $write(""[%0t] In %M\
+"", $time); // Uppercase %M test
+\t end
+ end
+ endtask
+endmodule
+
+module sub2;
+ // verilator no_inline_module
+ task write_m;
+ begin
+\t $write(""[%0t] In %m\
+"", $time);
+\t begin : subblock2
+\t $write(""[%0t] In %m\
+"", $time);
+\t end
+ end
+ endtask
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ priority_mask,
+ // Inputs
+ muxed_requests
+ );
+
+ parameter ARW = 7;
+
+ // verilator lint_off UNOPTFLAT
+ integer i,j;
+
+ output reg [ARW-1:0] priority_mask;
+
+ input [ARW-1:0] muxed_requests;
+
+ always @* begin
+ for (i=ARW-1;i>0;i=i-1) begin
+\t priority_mask[i]=1'b0;
+\t // vvvv=== note j=j not j=i; was bug
+\t for( j=j;j>=0;j=j-1)
+\t priority_mask[i]=priority_mask[j] | muxed_requests[j];
+ end
+ //Bit zero is always enabled
+ priority_mask[0]=1'b0;
+ end
+
+endmodule
+
+// Local Variables:
+// verilog-auto-inst-param-value: t
+// End:
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module x;
+
+ typedef struct {
+ int \t a;
+ } notpacked_t;
+
+ typedef struct packed {
+ notpacked_t b;
+ } ispacked_t;
+
+ ispacked_t p;
+
+ initial begin
+ p.b = 1;
+ if (p.b != 1) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+
+ reg [0:0] d1;
+ reg [2:0] d3;
+ reg [7:0] d8;
+
+ wire [0:0] q1;
+ wire [2:0] q3;
+ wire [7:0] q8;
+
+ // verilator lint_off UNOPTFLAT
+ reg \t ena;
+ // verilator lint_on UNOPTFLAT
+
+ condff #(12) condff
+ (.clk(clk), .sen(1\'b0), .ena(ena),
+ .d({d8,d3,d1}),
+ .q({q8,q3,q1}));
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t //$write(""%x %x %x %x\
+"", cyc, q8, q3, q1);
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t d1 <= 1\'b1; d3<=3\'h1; d8<=8\'h11;
+\t ena <= 1\'b1;
+\t end
+\t if (cyc==2) begin
+\t d1 <= 1\'b0; d3<=3\'h2; d8<=8\'h33;
+\t ena <= 1\'b0;
+\t end
+\t if (cyc==3) begin
+\t d1 <= 1\'b1; d3<=3\'h3; d8<=8\'h44;
+\t ena <= 1\'b1;
+\t if (q8 != 8\'h11) $stop;
+\t end
+\t if (cyc==4) begin
+\t d1 <= 1\'b1; d3<=3\'h4; d8<=8\'h77;
+\t ena <= 1\'b1;
+\t if (q8 != 8\'h11) $stop;
+\t end
+\t if (cyc==5) begin
+\t d1 <= 1\'b1; d3<=3\'h0; d8<=8\'h88;
+\t ena <= 1\'b1;
+\t if (q8 != 8\'h44) $stop;
+\t end
+\t if (cyc==6) begin
+\t if (q8 != 8\'h77) $stop;
+\t end
+\t if (cyc==7) begin
+\t if (q8 != 8\'h88) $stop;
+\t end
+\t //
+\t if (cyc==20) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+
+module condff (clk, sen, ena, d, q);
+ parameter WIDTH = 1;
+ input clk;
+
+ input sen;
+ input ena;
+ input [WIDTH-1:0] d;
+ output [WIDTH-1:0] q;
+
+ condffimp #(.WIDTH(WIDTH))
+ imp (.clk(clk), .sen(sen), .ena(ena), .d(d), .q(q));
+endmodule
+
+module condffimp (clk, sen, ena, d, q);
+ parameter WIDTH = 1;
+ input clk;
+ input sen;
+ input ena;
+ input [WIDTH-1:0] d;
+ output reg [WIDTH-1:0] q;
+ wire gatedclk;
+
+ clockgate clockgate (.clk(clk), .sen(sen), .ena(ena), .gatedclk(gatedclk));
+
+ always @(posedge gatedclk) begin
+ if (gatedclk === 1\'bX) begin
+\t q <= {WIDTH{1\'bX}};
+ end
+ else begin
+\t q <= d;
+ end
+ end
+
+endmodule
+
+module clockgate (clk, sen, ena, gatedclk);
+ input\tclk;
+ input\tsen;
+ input\tena;
+ output\tgatedclk;
+
+ reg\t\tena_b;
+ wire gatedclk = clk & ena_b;
+
+ // verilator lint_off COMBDLY
+ always @(clk or ena or sen) begin
+ if (~clk) begin
+ ena_b <= ena | sen;
+ end
+ else begin
+\t if ((clk^sen)===1\'bX) ena_b <= 1\'bX;
+ end
+ end
+ // verilator lint_on COMBDLY
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // verilator lint_off LITENDIAN
+ // verilator lint_off BLKANDNBLK
+ // 3 3 4
+ reg [71:0] memw [2:0][1:3][5:2];
+ reg [7:0] memn [2:0][1:3][5:2];
+ // verilator lint_on BLKANDNBLK
+
+ integer cyc; initial cyc=0;
+ reg [63:0] crc;
+ reg [71:0] wide;
+ reg [7:0] narrow;
+ reg [1:0] index0;
+ reg [1:0] index1;
+ reg [2:0] index2;
+ integer i0,i1,i2;
+
+ integer imem[2:0][1:3];
+ reg [2:0] cstyle[2];
+ // verilator lint_on LITENDIAN
+
+ initial begin
+ for (i0=0; i0<3; i0=i0+1) begin
+\t for (i1=1; i1<4; i1=i1+1) begin
+\t imem[i0[1:0]] [i1[1:0]] = i1;
+\t for (i2=2; i2<6; i2=i2+1) begin
+\t memw[i0[1:0]] [i1[1:0]] [i2[2:0]] = {56\'hfe_fee0_fee0_fee0_,4\'b0,i0[3:0],i1[3:0],i2[3:0]};
+\t memn[i0[1:0]] [i1[1:0]] [i2[2:0]] = 8\'b1000_0001;
+\t end
+\t end
+ end
+ end
+
+ reg [71:0] wread;
+ reg\t wreadb;
+
+ always @ (posedge clk) begin
+ //$write(""cyc==%0d crc=%x i[%d][%d][%d] nar=%x wide=%x\
+"",cyc, crc, index0,index1,index2, narrow, wide);
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t narrow <= 8\'h0;
+\t wide <= 72\'h0;
+\t index0 <= 2\'b0;
+\t index1 <= 2\'b0;
+\t index2 <= 3\'b0;
+ end
+ else if (cyc<90) begin
+\t index0 <= crc[1:0];
+\t index1 <= crc[3:2];
+\t index2 <= crc[6:4];
+\t crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+
+\t // We never read past bounds, or get unspecific results
+\t // We also never read lowest indexes, as writing outside of range may corrupt them
+\t if (index0>=0+1 && index0<=2 && index1>=1+1 /*&& index1<=3 CMPCONST*/ && index2>=2+1 && index2<=5) begin
+\t narrow <= ({narrow[6:0], narrow[7]^narrow[0]}
+\t\t ^ {memn[index0][index1][index2]});
+\t wread = memw[index0][index1][index2];
+\t wreadb = memw[index0][index1][index2][2];
+\t wide <= ({wide[70:0], wide[71]^wide[2]^wide[0]} ^ wread);
+\t //$write(""Get memw[%d][%d][%d] -> %x\
+"",index0,index1,index2, wread);
+\t end
+\t // We may write past bounds of memory
+\t memn[index0][index1][index2] [crc[10:8]+:3] <= crc[2:0];
+\t memn[index0][index1][index2] <= {~crc[6:0],crc[7]};
+\t memw[index0][index1][index2] <= {~crc[7:0],crc};
+\t //$write(""Set memw[%d][%d][%d] <= %x\
+"",index0,index1,index2, {~crc[7:0],crc});
+\t cstyle[cyc[0]] <= cyc[2:0];
+\t if (cyc>20) if (cstyle[~cyc[0]] != (cyc[2:0]-3\'b1)) $stop;
+ end
+ else if (cyc==90) begin
+\t memn[0][1][3] <= memn[0][1][3] ^ 8\'ha8;
+ end
+ else if (cyc==91) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x nar=%x wide=%x\
+"",$time, cyc, crc, narrow, wide);
+\t if (crc != 64\'h65e3bddcd9bc2750) $stop;
+\t if (narrow != 8\'hca) $stop;
+\t if (wide != 72\'h4edafed31ba6873f73) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003-2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ integer \tcyc=0;
+
+ reg \t\tcheck;
+ initial check = 1\'b0;
+ Genit g (.clk(clk), .check(check));
+
+ always @ (posedge clk) begin
+ //$write(""[%0t] cyc==%0d %x %x\
+"",$time, cyc, check, out);
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+\t // Setup
+\t check <= 1\'b0;
+ end
+ else if (cyc==1) begin
+\t check <= 1\'b1;
+ end
+ else if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+//`define WAVES
+`ifdef WAVES
+ initial begin
+ $dumpfile(""obj_dir/t_gen_intdot2/t_gen_intdot.vcd"");
+ $dumpvars(12, t);
+ end
+`endif
+
+endmodule
+
+module One;
+ wire one = 1\'b1;
+endmodule
+
+module Genit (
+ input clk,
+ input check);
+
+ // ARRAY
+ One cellarray1[1:0] ();\t//cellarray[0..1][0..1]
+ always @ (posedge clk) if (cellarray1[0].one !== 1\'b1) $stop;
+ always @ (posedge clk) if (cellarray1[1].one !== 1\'b1) $stop;
+
+ // IF
+ generate
+ // genblk1 refers to the if\'s name, not the ""generate"" itself.
+ if (1\'b1) // IMPLIED begin: genblk1
+\tOne ifcell1(); // genblk1.ifcell1
+ else
+\tOne ifcell1(); // genblk1.ifcell1
+ endgenerate
+ // On compliant simulators ""Implicit name"" not allowed here; IE we can\'t use ""genblk1"" etc
+`ifdef verilator
+ always @ (posedge clk) if (genblk1.ifcell1.one !== 1\'b1) $stop;
+//`else // NOT SUPPORTED accoring to spec - generic block references
+`endif
+
+ generate
+ begin : namedif2
+\t if (1\'b1)
+\t One ifcell2(); // namedif2.genblk1.ifcell2
+ end
+ endgenerate
+`ifdef verilator
+ always @ (posedge clk) if (namedif2.genblk1.ifcell2.one !== 1\'b1) $stop;
+//`else // NOT SUPPORTED accoring to spec - generic block references
+`endif
+
+ generate
+ if (1\'b1)
+\tbegin : namedif3
+\t One ifcell3(); // namedif3.ifcell3
+\tend
+ endgenerate
+ always @ (posedge clk) if (namedif3.ifcell3.one !== 1\'b1) $stop;
+
+ // CASE
+ generate
+ case (1\'b1)
+\t1\'b1 :
+\t One casecell10();\t// genblk3.casecell10
+ endcase
+ endgenerate
+`ifdef verilator
+ always @ (posedge clk) if (genblk3.casecell10.one !== 1\'b1) $stop;
+//`else // NOT SUPPORTED accoring to spec - generic block references
+`endif
+
+ generate
+ case (1\'b1)
+\t1\'b1 : begin : namedcase11
+\t One casecell11();
+\tend
+ endcase
+ endgenerate
+ always @ (posedge clk) if (namedcase11.casecell11.one !== 1\'b1) $stop;
+
+ genvar i;
+ genvar j;
+
+ // IF
+ generate
+ for (i = 0; i < 2; i = i + 1)
+\tOne cellfor20 ();\t// genblk4[0..1].cellfor20
+ endgenerate
+`ifdef verilator
+ always @ (posedge clk) if (genblk4[0].cellfor20.one !== 1\'b1) $stop;
+ always @ (posedge clk) if (genblk4[1].cellfor20.one !== 1\'b1) $stop;
+//`else // NOT SUPPORTED accoring to spec - generic block references
+`endif
+
+ // COMBO
+ generate
+ for (i = 0; i < 2; i = i + 1)
+\tbegin : namedfor21
+\t One cellfor21 ();\t// namedfor21[0..1].cellfor21
+\tend
+ endgenerate
+ always @ (posedge clk) if (namedfor21[0].cellfor21.one !== 1\'b1) $stop;
+ always @ (posedge clk) if (namedfor21[1].cellfor21.one !== 1\'b1) $stop;
+
+ generate
+ for (i = 0; i < 2; i = i + 1)
+\tbegin : namedfor30
+\t for (j = 0; j < 2; j = j + 1)
+\t begin : forb30
+\t\tif (j == 0)
+\t\t begin : forif30
+\t\t One cellfor30a (); // namedfor30[0..1].forb30[0].forif30.cellfor30a
+\t\t end
+\t\telse
+`ifdef verilator
+\t\t begin : forif30b
+`else
+\t\t begin : forif30 // forif30 seems to work on some simulators, not verilator yet
+`endif
+\t\t One cellfor30b (); // namedfor30[0..1].forb30[1].forif30.cellfor30b
+\t\t end
+\t end
+\tend
+ endgenerate
+ always @ (posedge clk) if (namedfor30[0].forb30[0].forif30.cellfor30a.one !== 1\'b1) $stop;
+ always @ (posedge clk) if (namedfor30[1].forb30[0].forif30.cellfor30a.one !== 1\'b1) $stop;
+`ifdef verilator
+ always @ (posedge clk) if (namedfor30[0].forb30[1].forif30b.cellfor30b.one !== 1\'b1) $stop;
+ always @ (posedge clk) if (namedfor30[1].forb30[1].forif30b.cellfor30b.one !== 1\'b1) $stop;
+`else
+ always @ (posedge clk) if (namedfor30[0].forb30[1].forif30.cellfor30b.one !== 1\'b1) $stop;
+ always @ (posedge clk) if (namedfor30[1].forb30[1].forif30.cellfor30b.one !== 1\'b1) $stop;
+`endif
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Test of select from constant
+//
+// This tests issue 509, bit select of constant fails
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Jeremy Bennett.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // a and b are arrays of length 1.
+ wire a[0:0]; // Array of nets
+ wire b[0:0];
+
+ assign a = 1'b0; // Only net assignment allowed
+ assign b = a[0]; // Only net assignment allowed
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+
+module t;
+ initial begin
+ // verilator lint_off FUTURE1
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ // verilator FUTURE2
+ // verilator FUTURE2 blah blah
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk, fastclk
+ );
+
+ input clk /*verilator sc_clock*/;
+ input fastclk /*verilator sc_clock*/;
+ reg \t reset_l;
+
+ int cyc;
+ initial reset_l = 0;
+ always @ (posedge clk) begin
+ if (cyc==0) reset_l <= 1\'b1;
+ else if (cyc==1) reset_l <= 1\'b0;
+ else if (cyc==10) reset_l <= 1\'b1;
+ end
+
+ t_clk t (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .fastclk\t\t\t(fastclk),
+\t .reset_l\t\t\t(reset_l));
+endmodule
+
+module t_clk (/*AUTOARG*/
+ // Inputs
+ clk, fastclk, reset_l
+ );
+
+ input clk /*verilator sc_clock*/;
+ input fastclk /*verilator sc_clock*/;
+ input reset_l;
+
+ // surefire lint_off STMINI
+ // surefire lint_off CWECSB
+ // surefire lint_off NBAJAM
+ reg \t _ranit; initial _ranit=0;
+ // surefire lint_off UDDSMX
+ reg [7:0] clk_clocks; initial clk_clocks = 0; // surefire lint_off_line WRTWRT
+ wire [7:0] clk_clocks_d1r;
+ wire [7:0] clk_clocks_d1sr;
+ wire [7:0] clk_clocks_cp2_d1r;
+ wire [7:0] clk_clocks_cp2_d1sr;
+ // verilator lint_off MULTIDRIVEN
+ reg [7:0] int_clocks; initial int_clocks = 0;
+ // verilator lint_on MULTIDRIVEN
+ reg [7:0] int_clocks_copy;
+
+ // verilator lint_off GENCLK
+ reg \t internal_clk; initial internal_clk = 0;
+ reg \t reset_int_;
+ // verilator lint_on GENCLK
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] CLK1 %x\
+"", $time, reset_l);
+`endif
+ if (!reset_l) begin
+\t clk_clocks <= 0;
+\t int_clocks <= 0;
+\t internal_clk <= 1\'b1;
+\t reset_int_ <= 0;
+ end
+ else begin
+\t internal_clk <= ~internal_clk;
+\t if (!_ranit) begin
+\t _ranit <= 1;
+`ifdef TEST_VERBOSE
+\t $write(""[%0t] t_clk: Running\
+"",$time);
+`endif
+\t reset_int_ <= 1;
+\t end
+ end
+ end
+
+ reg [7:0] sig_rst;
+ always @ (posedge clk or negedge reset_l) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] CLK2 %x sr=%x\
+"", $time, reset_l, sig_rst);
+`endif
+ if (!reset_l) begin
+\t sig_rst <= 0;
+ end
+ else begin
+\t sig_rst <= sig_rst + 1; // surefire lint_off_line ASWIBB
+ end
+ end
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] CLK3 %x cc=%x sr=%x\
+"", $time, reset_l, clk_clocks, sig_rst);
+`endif
+ if (!reset_l) begin
+\t clk_clocks <= 0;
+ end
+ else begin
+\t clk_clocks <= clk_clocks + 8\'d1;
+\t if (clk_clocks == 4) begin
+\t if (sig_rst !== 4) $stop;
+\t if (clk_clocks_d1r !== 3) $stop;
+\t if (int_clocks !== 2) $stop;
+\t if (int_clocks_copy !== 2) $stop;
+\t if (clk_clocks_d1r !== clk_clocks_cp2_d1r) $stop;
+\t if (clk_clocks_d1sr !== clk_clocks_cp2_d1sr) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+ reg [7:0] resetted;
+ always @ (posedge clk or negedge reset_int_) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] CLK4 %x\
+"", $time, reset_l);
+`endif
+ if (!reset_int_) begin
+\t resetted <= 0;
+ end
+ else begin
+\t resetted <= resetted + 8\'d1;
+ end
+ end
+
+ always @ (int_clocks) begin
+ int_clocks_copy = int_clocks;
+ end
+
+ always @ (negedge internal_clk) begin
+ int_clocks <= int_clocks + 8\'d1;
+ end
+
+ t_clk_flop flopa (.clk(clk), .clk2(fastclk), .a(clk_clocks),
+\t\t .q(clk_clocks_d1r), .q2(clk_clocks_d1sr));
+ t_clk_flop flopb (.clk(clk), .clk2(fastclk), .a(clk_clocks),
+\t\t .q(clk_clocks_cp2_d1r), .q2(clk_clocks_cp2_d1sr));
+ t_clk_two two (/*AUTOINST*/
+\t\t // Inputs
+\t\t .fastclk\t\t(fastclk),
+\t\t .reset_l\t\t(reset_l));
+
+endmodule
+
+module t_clk_flop (/*AUTOARG*/
+ // Outputs
+ q, q2,
+ // Inputs
+ clk, clk2, a
+ );
+ parameter WIDTH=8;
+ input clk;
+ input clk2;
+ input [(WIDTH-1):0] a;
+ output [(WIDTH-1):0] q;
+ output [(WIDTH-1):0] q2;
+ reg [(WIDTH-1):0] q;
+ reg [(WIDTH-1):0] q2;
+ always @ (posedge clk) q<=a;
+ always @ (posedge clk2) q2<=a;
+endmodule
+
+module t_clk_two (/*AUTOARG*/
+ // Inputs
+ fastclk, reset_l
+ );
+ input fastclk;
+ input reset_l;
+ // verilator lint_off GENCLK
+ reg clk2;
+ // verilator lint_on GENCLK
+ reg [31:0] count;
+
+ t_clk_twob tb (.*);
+
+ wire reset_h = ~reset_l;
+ always @ (posedge fastclk) begin
+ if (reset_h) clk2 <= 0;
+ else clk2 <= ~clk2;
+ end
+ always @ (posedge clk2) begin
+ if (reset_h) count <= 0;
+ else count <= count + 1;
+ end
+endmodule
+
+module t_clk_twob (/*AUTOARG*/
+ // Inputs
+ fastclk, reset_l
+ );
+ input fastclk;
+ input reset_l;
+
+ always @ (posedge fastclk) begin
+ // Extra line coverage point, just to make sure coverage
+ // hierarchy under inlining lands properly
+ if (reset_l) ;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ ign,
+ // Inputs
+ clk
+ );
+
+ input clk;
+ output [31:0] ign;
+
+ reg [31:0] \t\tright;
+ reg [31:0] \t\tleft;
+ reg [63:0] \t\tqright;
+ reg [63:0] \t\tqleft;
+ reg [31:0] \t\tamt;
+
+ assign ign = {31\'h0, clk} >>> 4\'bx; // bug760
+
+ always @* begin
+ right = 32\'h819b018a >> amt;
+ left = 32\'h819b018a << amt;
+ qright = 64\'hf784bf8f_12734089 >> amt;
+ qleft = 64\'hf784bf8f_12734089 >> amt;
+ end
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+`ifdef TEST_VERBOSE
+\t $write(""%d %x %x %x %x\
+"", cyc, left, right, qleft, qright);
+`endif
+\t if (cyc==1) begin
+\t amt <= 32\'d0;
+\t if (5\'b10110>>2 != 5\'b00101) $stop;
+\t if (5\'b10110>>>2 != 5\'b00101) $stop; // Note it cares about sign-ness
+\t if (5\'b10110<<2 != 5\'b11000) $stop;
+\t if (5\'b10110<<<2 != 5\'b11000) $stop;
+\t if (5\'sb10110>>2 != 5\'sb00101) $stop;
+\t if (5\'sb10110>>>2 != 5\'sb11101) $stop;
+\t if (5\'sb10110<<2 != 5\'sb11000) $stop;
+\t if (5\'sb10110<<<2 != 5\'sb11000) $stop;
+\t // Allow >64 bit shifts if the shift amount is a constant
+\t if ((64\'sh458c2de282e30f8b >> 68\'sh4) !== 64\'sh0458c2de282e30f8) $stop;
+\t end
+\t if (cyc==2) begin
+\t amt <= 32\'d28;
+\t if (left != 32\'h819b018a) $stop;
+\t if (right != 32\'h819b018a) $stop;
+\t if (qleft != 64\'hf784bf8f_12734089) $stop;
+\t if (qright != 64\'hf784bf8f_12734089) $stop;
+\t end
+\t if (cyc==3) begin
+\t amt <= 32\'d31;
+\t if (left != 32\'ha0000000) $stop;
+\t if (right != 32\'h8) $stop;
+\t if (qleft != 64\'h0000000f784bf8f1) $stop;
+\t if (qright != 64\'h0000000f784bf8f1) $stop;
+\t end
+\t if (cyc==4) begin
+\t amt <= 32\'d32;
+\t if (left != 32\'h0) $stop;
+\t if (right != 32\'h1) $stop;
+\t if (qleft != 64\'h00000001ef097f1e) $stop;
+\t if (qright != 64\'h00000001ef097f1e) $stop;
+\t end
+\t if (cyc==5) begin
+\t amt <= 32\'d33;
+\t if (left != 32\'h0) $stop;
+\t if (right != 32\'h0) $stop;
+\t if (qleft != 64\'h00000000f784bf8f) $stop;
+\t if (qright != 64\'h00000000f784bf8f) $stop;
+\t end
+\t if (cyc==6) begin
+\t amt <= 32\'d64;
+\t if (left != 32\'h0) $stop;
+\t if (right != 32\'h0) $stop;
+\t if (qleft != 64\'h000000007bc25fc7) $stop;
+\t if (qright != 64\'h000000007bc25fc7) $stop;
+\t end
+\t if (cyc==7) begin
+\t amt <= 32\'d128;
+\t if (left != 32\'h0) $stop;
+\t if (right != 32\'h0) $stop;
+\t if (qleft != 64\'h0) $stop;
+\t if (qright != 64\'h0) $stop;
+\t end
+\t if (cyc==8) begin
+\t if (left != 32\'h0) $stop;
+\t if (right != 32\'h0) $stop;
+\t if (qleft != 64\'h0) $stop;
+\t if (qright != 64\'h0) $stop;
+\t end
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+//bug485, but see t_gen_forif.v for an OK example.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ always_comb begin
+ integer i;
+
+ for(i=0; i<10; i++ ) begin: COMB
+ end
+
+ for(i=0; i<9; i++ ) begin: COMB
+ end
+ end
+endmodule
+"
+"// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013.
+
+module t
+ (
+ input logic \t\t\t\tclk,
+ input logic \t\t\t\tdaten,
+ input logic [8:0] \t\t\tdatval,
+ output logic signed [3:0][3:0][35:0] datao
+ );
+
+ logic signed [3:0][3:0][3:0][8:0] \tdatat;
+
+ genvar \t\t\t\ti;
+ generate
+ for (i=0; i<4; i++)begin
+\t testio dut(.clk(clk), .arr3d_in(datat[i]), .arr2d_out(datao[i]));
+ end
+ endgenerate
+
+ genvar j;
+ generate
+ for (i=0; i<4; i++) begin
+\t for (j=0; j<4; j++) begin
+\t always_comb datat[i][j][0] = daten ? 9'h0 : datval;
+\t always_comb datat[i][j][1] = daten ? 9'h1 : datval;
+\t always_comb datat[i][j][2] = daten ? 9'h2 : datval;
+\t always_comb datat[i][j][3] = daten ? 9'h3 : datval;
+\t end
+ end
+ endgenerate
+endmodule
+
+module testio
+ (
+ input \t\t\t\tclk,
+ input logic signed [3:0] [3:0] [8:0] arr3d_in,
+ output logic signed [3:0] [35:0] \tarr2d_out
+ );
+ logic signed [3:0] [35:0] \t\tar2d_out_pre;
+
+ always_comb ar2d_out_pre[0][35:0] = {arr3d_in[0][0][8:0], arr3d_in[0][1][8:0], arr3d_in[0][2][8:0], arr3d_in[0][3][8:0]};
+ always_comb ar2d_out_pre[0][35:0] = {arr3d_in[0][0][8:0], arr3d_in[0][1][8:0], arr3d_in[0][2][8:0], arr3d_in[0][3][8:0]};
+ always_comb ar2d_out_pre[0][35:0] = {arr3d_in[0][0][8:0], arr3d_in[0][1][8:0], arr3d_in[0][2][8:0], arr3d_in[0][3][8:0]};
+ always_comb ar2d_out_pre[0][35:0] = {arr3d_in[0][0][8:0], arr3d_in[0][1][8:0], arr3d_in[0][2][8:0], arr3d_in[0][3][8:0]};
+
+ always_ff @(posedge clk) begin
+ if (clk)
+\tarr2d_out <= ar2d_out_pre;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ data_out,
+ // Inputs
+ wr, wa, rst_l, rd, ra, data_in, clk
+ );
+ input clk;
+
+ /*AUTOINPUT*/
+ // Beginning of automatic inputs (from unused autoinst inputs)
+ input [31:0]\t\tdata_in;\t\t// To sub of reg_1r1w.v
+ input [7:0]\t\tra;\t\t\t// To sub of reg_1r1w.v
+ input\t\trd;\t\t\t// To sub of reg_1r1w.v
+ input\t\trst_l;\t\t\t// To sub of reg_1r1w.v
+ input [7:0]\t\twa;\t\t\t// To sub of reg_1r1w.v
+ input\t\twr;\t\t\t// To sub of reg_1r1w.v
+ // End of automatics
+ /*AUTOOUTPUT*/
+ // Beginning of automatic outputs (from unused autoinst outputs)
+ output [31:0]\tdata_out;\t\t// From sub of reg_1r1w.v
+ // End of automatics
+
+ reg_1r1w #(.WIDTH(32), .DEPTH(256), .ADRWID(8))
+ sub
+ (/*AUTOINST*/
+ // Outputs
+ .data_out\t\t\t\t(data_out[31:0]),
+ // Inputs
+ .data_in\t\t\t\t(data_in[31:0]),
+ .ra\t\t\t\t(ra[7:0]),
+ .wa\t\t\t\t(wa[7:0]),
+ .wr\t\t\t\t(wr),
+ .rd\t\t\t\t(rd),
+ .clk\t\t\t\t(clk),
+ .rst_l\t\t\t\t(rst_l));
+
+endmodule
+
+module reg_1r1w
+ #(
+ parameter WIDTH=32,
+ parameter ADRWID=10,
+ parameter DEPTH=1024,
+ parameter RST=0
+ )
+ (/*AUTOARG*/
+ // Outputs
+ data_out,
+ // Inputs
+ data_in, ra, wa, wr, rd, clk, rst_l
+ );
+
+ input [WIDTH-1:0] data_in;
+ input [ADRWID-1:0] ra;
+ input [ADRWID-1:0] wa;
+ input wr;
+ input rd;
+ input clk;
+ input rst_l;
+
+ output [WIDTH-1:0] data_out;
+
+ reg [WIDTH-1:0] array [DEPTH-1:0];
+ reg [ADRWID-1:0] ra_r, wa_r;
+ reg [WIDTH-1:0] data_in_r;
+ reg wr_r;
+ reg rd_r;
+
+ integer x;
+
+ // Message 679
+ always @(posedge clk) begin
+ int tmp = x + 1;
+ if (tmp !== x + 1) $stop;
+ end
+
+ always @(posedge clk or negedge rst_l) begin
+ if (!rst_l) begin
+\t for (x=0; x1) break;
+ end
+ while (1) begin
+\t out = out+1;
+\t if (a>1) return 2+out;
+ end
+ f_return = 0;
+ endfunction
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Wilson Snyder.
+
+module t;
+ function integer bottom_4bits;
+ input [7:0] i;
+ bottom_4bits = 0;
+ bottom_4bits[3:0] = i[3:0];
+ endfunction
+
+ function integer bottom_2_unknown;
+ input [7:0] i;
+ // bottom_4bits = 0; \'x
+ bottom_2_unknown[1:0] = i[1:0];
+ endfunction
+
+ localparam p = bottom_4bits(8\'h13);
+ localparam bu = bottom_2_unknown(8\'h13);
+
+ initial begin
+ if (p != 3) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Simple test of unoptflat
+//
+// Simple demonstration of an UNOPTFLAT combinatorial loop, using just 2 bits.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Jeremy Bennett.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ wire [1:0] x = { x[0], clk };
+
+ initial begin
+ x = 0;
+ end
+
+ always @(posedge clk or negedge clk) begin
+
+`ifdef TEST_VERBOSE
+ $write(""x = %x\
+"", x);
+`endif
+
+ if (x[1] != 0) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+module t ();
+
+ // See also t_lint_width
+
+ parameter A_ONE = \'1;
+ // verilator lint_off WIDTH
+ parameter [3:0] A_W4 = A_ONE;
+ // verilator lint_on WIDTH
+ initial begin
+ if ($bits(A_ONE) != 1 || A_ONE !== 1\'b1) $stop;
+ if ($bits(A_W4) != 4) $stop;
+ if (A_W4 != 4\'b0001) $stop;
+ end
+
+ b #(.B_WIDTH(48)) b ();
+
+ reg [4:0] c;
+ integer c_i;
+ initial begin
+ c_i = 3;
+ c = 1\'b1 << c_i; // No width warning when not embedded in expression, as is common syntax
+ if (c != 5\'b1000) $stop;
+ end
+
+ localparam D_TT = 32\'d23;
+ localparam D_SIX = 6;
+ // verilator lint_off WIDTH
+ localparam [5:0] D_SUB = D_TT - D_SIX;
+ // verilator lint_on WIDTH
+ initial begin
+ if (D_SUB != 17) $stop;
+ end
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+
+module b;
+ parameter B_WIDTH = 1;
+ localparam B_VALUE0 = {B_WIDTH{1\'b0}};
+ localparam B_VALUE1 = {B_WIDTH{1\'b1}};
+ reg [47:0] b_val;
+ initial begin
+ b_val = B_VALUE0;
+ if (b_val != 48\'b0) $stop;
+ b_val = B_VALUE1;
+ if (b_val != ~48\'b0) $stop;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test for short-circuiting in generate ""if""
+// that should not work.
+//
+// The given generate loops should attempt to access invalid bits of mask and
+// trigger errors.
+// is defined by SIZE. However since the loop range is larger, this only works
+// if short-circuited evaluation of the generate loop is in place.
+
+// This file ONLY is placed into the Public Domain, for any use, without
+// warranty, 2012 by Jeremy Bennett.
+
+
+`define MAX_SIZE 3
+
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ // Set the parameters, so that we use a size less than MAX_SIZE
+ test_gen
+ #(.SIZE (2),
+ .MASK (2\'b11))
+ i_test_gen (.clk (clk));
+
+ // This is only a compilation test, so we can immediately finish
+ always @(posedge clk) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule // t
+
+
+module test_gen
+
+ #( parameter
+ SIZE = `MAX_SIZE,
+ MASK = `MAX_SIZE\'b0)
+
+ (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // Generate blocks that all have errors in applying short-circuting to
+ // generate ""if"" conditionals.
+
+ // Attempt to access invalid bits of MASK in different ways
+ generate
+ genvar g;
+
+ for (g = 0; g < `MAX_SIZE; g = g + 1) begin
+ if ((g < (SIZE + 1)) && MASK[g]) begin
+\t always @(posedge clk) begin
+`ifdef TEST_VERBOSE
+\t $write (""Logical AND generate if MASK [%1d] = %d\
+"", g, MASK[g]);
+`endif
+\t end
+\t end
+ end
+ endgenerate
+
+ generate
+ for (g = 0; g < `MAX_SIZE; g = g + 1) begin
+ if ((g < SIZE) && MASK[g + 1]) begin
+\t always @(posedge clk) begin
+`ifdef TEST_VERBOSE
+\t $write (""Logical AND generate if MASK [%1d] = %d\
+"", g, MASK[g]);
+`endif
+\t end
+\t end
+ end
+ endgenerate
+
+ // Attempt to short-circuit bitwise AND
+ generate
+ for (g = 0; g < `MAX_SIZE; g = g + 1) begin
+ if ((g < (SIZE)) & MASK[g]) begin
+\t always @(posedge clk) begin
+`ifdef TEST_VERBOSE
+\t $write (""Bitwise AND generate if MASK [%1d] = %d\
+"", g, MASK[g]);
+`endif
+\t end
+\t end
+ end
+ endgenerate
+
+ // Attempt to short-circuit bitwise OR
+ generate
+ for (g = 0; g < `MAX_SIZE; g = g + 1) begin
+ if (!((g >= SIZE) | ~MASK[g])) begin
+\t always @(posedge clk) begin
+`ifdef TEST_VERBOSE
+\t $write (""Bitwise OR generate if MASK [%1d] = %d\
+"", g, MASK[g]);
+`endif
+\t end
+\t end
+ end
+ endgenerate
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t;
+ reg [40:0] disp; initial disp = 41\'ha_bbbb_cccc;
+ initial begin
+ // Display formatting
+ $display(""%x""); // Too few
+ $display(""%x"",disp,disp); // Too many
+ $display(""%q""); // Bad escape
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg [11:0] in_a;
+ reg [31:0] sel;
+ wire [2:0] out_x;
+
+ extractor #(4,3) extractor (
+\t\t\t // Outputs
+\t\t\t .out\t(out_x),
+\t\t\t // Inputs
+\t\t\t .in\t(in_a),
+\t\t\t .sel\t(sel));
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t //$write(""%d %x %x %x\
+"", cyc, in_a, sel, out_x);
+\t if (cyc==1) begin
+\t in_a <= 12\'b001_101_111_010;
+\t sel <= 32\'d0;
+\t end
+\t if (cyc==2) begin
+\t sel <= 32\'d1;
+\t if (out_x != 3\'b010) $stop;
+\t end
+\t if (cyc==3) begin
+\t sel <= 32\'d2;
+\t if (out_x != 3\'b111) $stop;
+\t end
+\t if (cyc==4) begin
+\t sel <= 32\'d3;
+\t if (out_x != 3\'b101) $stop;
+\t end
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+
+module extractor (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ in, sel
+ );
+ parameter IN_WIDTH=8;
+ parameter OUT_WIDTH=2;
+
+ input [IN_WIDTH*OUT_WIDTH-1:0] in;
+ output [OUT_WIDTH-1:0] out;
+ input [31:0] \t\t sel;
+
+ wire [OUT_WIDTH-1:0] out = selector(in,sel);
+
+ function [OUT_WIDTH-1:0] selector;
+ input [IN_WIDTH*OUT_WIDTH-1:0] inv;
+ input [31:0] \t\t selv;
+ integer i;
+ begin
+\t selector = 0;
+\t for (i=0; i 8\'d10 ) && ( cnt < 8\'d30 ) && ( cnt[0] == 1\'b0 );
+ assign o_addr = cnt;
+ assign o_wdata = cnt;
+
+endmodule
+
+
+// Memory Reader
+module FooRd(
+ input i_clk,
+
+ output o_wen,
+ output [7:0] o_addr,
+ output [7:0] o_wdata,
+ input [7:0] i_rdata
+ );
+
+ reg [7:0] cnt = 0;
+ reg [7:0] addr_r;
+ reg en_r;
+
+ // Count [0,200]
+ always @( posedge i_clk )
+ if ( cnt < 8\'d200 )
+ cnt <= cnt + 8\'d1;
+
+ // Read data
+ assign o_wen = 0;
+ assign o_addr = cnt - 8\'d100;
+
+ // Track issued read
+ always @( posedge i_clk )
+ begin
+ addr_r <= o_addr;
+ en_r <= ( cnt > 8\'d110 ) && ( cnt < 8\'d130 ) && ( cnt[0] == 1\'b0 );
+ end
+
+ // Display to console 100 cycles after writer
+ always @( negedge i_clk )
+ if ( en_r ) begin
+`ifdef TEST_VERBOSE
+ $display( ""MEM[%x] == %x"", addr_r, i_rdata );
+`endif
+\t if (addr_r != i_rdata) $stop;
+\tend
+
+endmodule
+
+
+// Multi-port memory abstraction
+module FooMem(
+ input [2 -1:0] iv_clk,
+ input [2 -1:0] iv_wen,
+ input [2*8-1:0] iv_addr,
+ input [2*8-1:0] iv_wdata,
+ output [2*8-1:0] ov_rdata
+ );
+
+ FooMemImpl u_impl (
+ .a_clk ( iv_clk [0*1+:1] ),
+ .a_wen ( iv_wen [0*1+:1] ),
+ .a_addr ( iv_addr [0*8+:8] ),
+ .a_wdata ( iv_wdata[0*8+:8] ),
+ .a_rdata ( ov_rdata[0*8+:8] ),
+
+ .b_clk ( iv_clk [1*1+:1] ),
+ .b_wen ( iv_wen [1*1+:1] ),
+ .b_addr ( iv_addr [1*8+:8] ),
+ .b_wdata ( iv_wdata[1*8+:8] ),
+ .b_rdata ( ov_rdata[1*8+:8] )
+ );
+
+endmodule
+
+
+// Dual-Port L1 Memory Implementation
+module FooMemImpl(
+ input a_clk,
+ input a_wen,
+ input [7:0] a_addr,
+ input [7:0] a_wdata,
+ output [7:0] a_rdata,
+
+ input b_clk,
+ input b_wen,
+ input [7:0] b_addr,
+ input [7:0] b_wdata,
+ output [7:0] b_rdata
+ );
+
+ /* verilator lint_off MULTIDRIVEN */
+ reg [7:0] mem[0:255];
+ /* verilator lint_on MULTIDRIVEN */
+
+ always @( posedge a_clk )
+ if ( a_wen )
+ mem[a_addr] <= a_wdata;
+
+ always @( posedge b_clk )
+ if ( b_wen )
+ mem[b_addr] <= b_wdata;
+
+ always @( posedge a_clk )
+ a_rdata <= mem[a_addr];
+
+ always @( posedge b_clk )
+ b_rdata <= mem[b_addr];
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [7:0] a = crc[7:0];
+ wire [7:0] b = crc[15:8];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [63:0]\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[63:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .a\t\t\t(a[7:0]),
+\t .b\t\t\t(b[7:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {out};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h0908a1f2194d24ee
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ clk, a, b
+ );
+
+ input clk;
+ input [7:0] a;
+ input [7:0] b;
+ output reg [63:0] out;
+
+ and u0[7:0] (out[7:0], a[7:0], b[7:0]);
+ and u1[7:0] (out[15:8], a[0], b[7:0]);
+ and u2[7:0] (out[23:16], a[0], b[0]);
+ nand u3[7:0] (out[31:24], a[0], b[7:0]);
+ or u4[7:0] (out[39:32], a[0], b[7:0]);
+ nor u5[7:0] (out[47:40], a[0], b[7:0]);
+ xor u6[7:0] (out[55:48], a[0], b[7:0]);
+ xnor u7[7:0] (out[63:56], a[0], b[7:0]);
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ // [16] is SV syntax for [0:15]
+ reg [7:0] memory8_16 [16];
+
+ reg \t m_we;
+ reg [3:1] m_addr;
+ reg [15:0] m_data;
+
+ always @ (posedge clk) begin
+ // Load instructions from cache
+ memory8_16[{m_addr,1\'d0}] <= 8\'hfe;
+ if (m_we) begin
+\t {memory8_16[{m_addr,1\'d1}],
+\t memory8_16[{m_addr,1\'d0}]} <= m_data;
+ end
+ end
+
+ reg [7:0] memory8_16_4;
+ reg [7:0] memory8_16_5;
+ // Test complicated sensitivity lists
+ always @ (memory8_16[4][7:1] or memory8_16[5]) begin
+ memory8_16_4 = memory8_16[4];
+ memory8_16_5 = memory8_16[5];
+ end
+
+ always @ (posedge clk) begin
+ m_we <= 0;
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t m_we <= 1\'b1;
+\t m_addr <= 3\'d2;
+\t m_data <= 16\'h55_44;
+\t end
+\t if (cyc==2) begin
+\t m_we <= 1\'b1;
+\t m_addr <= 3\'d3;
+\t m_data <= 16\'h77_66;
+\t end
+\t if (cyc==3) begin
+\t m_we <= 0;\t// Check we really don\'t write this
+\t m_addr <= 3\'d3;
+\t m_data <= 16\'h0bad;
+\t end
+\t if (cyc==5) begin
+\t if (memory8_16_4 != 8\'h44) $stop;
+\t if (memory8_16_5 != 8\'h55) $stop;
+\t if (memory8_16[6] != 8\'hfe) $stop;
+\t if (memory8_16[7] != 8\'h77) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ parameter PAR = 3;
+ input clk;
+
+`ifdef verilator
+ // Else it becomes a localparam, per IEEE 4.10.1, but we don\'t check it
+ defparam m3.FROMDEFP = 19;
+`endif
+
+ m3 #(.P3(PAR),
+\t.P2(2))
+ m3(.clk(clk));
+
+ integer cyc=1;
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==1) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module m3
+ #(
+ parameter UNCH = 99,
+ parameter P1 = 10,
+ parameter P2 = 20,
+ P3 = 30
+ )
+ (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ localparam LOC = 13;
+
+ parameter FROMDEFP = 11;
+
+ initial begin
+ $display(""%x %x %x"",P1,P2,P3);
+ end
+ always @ (posedge clk) begin
+ if (UNCH !== 99) $stop;
+ if (P1 !== 10) $stop;
+ if (P2 !== 2) $stop;
+ if (P3 !== 3) $stop;
+`ifdef verilator
+ if (FROMDEFP !== 19) $stop;
+`endif
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+//`begin_keywords ""VAMS-2.3""
+`begin_keywords ""1800+VAMS""
+
+module t (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ in
+ );
+
+ input in;
+ wreal in;
+ output out;
+ wreal out;
+
+ import ""DPI-C"" context function void dpii_call(input real in, output real out);
+
+ initial begin
+ dpii_call(in,out);
+ $finish;
+ end
+
+endmodule
+"
+"// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+`define DDIFF_BITS 9
+`define AOA_BITS 8
+`define HALF_DDIFF `DDIFF_BITS\'d256
+`define MAX_AOA `AOA_BITS\'d255
+`define BURP_DIVIDER 9\'d16
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [`DDIFF_BITS-1:0] DDIFF_B = crc[`DDIFF_BITS-1:0];
+ wire reset = (cyc<7);
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [`AOA_BITS-1:0]\tAOA_B;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .AOA_B\t\t\t(AOA_B[`AOA_BITS-1:0]),
+\t // Inputs
+\t .DDIFF_B\t\t\t(DDIFF_B[`DDIFF_BITS-1:0]),
+\t .reset\t\t\t(reset),
+\t .clk\t\t\t(clk));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {56\'h0, AOA_B};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h3a74e9d34771ad93
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ AOA_B,
+ // Inputs
+ DDIFF_B, reset, clk
+ );
+
+ input [`DDIFF_BITS-1:0] DDIFF_B;
+ input reset;
+ input clk;
+ output reg [`AOA_BITS-1:0] AOA_B;
+
+ reg [`AOA_BITS-1:0] AOA_NEXT_B;
+ reg [`AOA_BITS-1:0] tmp;
+
+ always @(posedge clk) begin
+ if (reset) begin
+\t AOA_B <= 8\'h80;
+ end
+ else begin
+\t AOA_B <= AOA_NEXT_B;
+ end
+ end
+
+ always @* begin
+ // verilator lint_off WIDTH
+ tmp = ((`HALF_DDIFF-DDIFF_B)/`BURP_DIVIDER);
+ t_aoa_update(AOA_NEXT_B, AOA_B, ((`HALF_DDIFF-DDIFF_B)/`BURP_DIVIDER));
+ // verilator lint_on WIDTH
+ end
+
+ task t_aoa_update;
+ output [`AOA_BITS-1:0] aoa_reg_next;
+ input [`AOA_BITS-1:0] aoa_reg;
+ input [`AOA_BITS-1:0] aoa_delta_update;
+ begin
+ if ((`MAX_AOA-aoa_reg) 5)
+\ta <= 17;
+
+ // single if with else
+ unique0 if (cyc < 3)
+\tb <= 17;
+ else
+\tb <= 19;
+
+ // multi if, some cases may not be true
+ unique0 if (cyc < 3)
+\tc <= 17;
+ else if (cyc > 3)
+\tc <= 19;
+
+ // multi if with else, else clause hit in some cases
+ unique0 if (cyc < 3)
+\td <= 17;
+ else if (cyc > 3)
+\td <= 19;
+ else
+\td <= 21;
+
+ // single if with else
+ unique if (cyc < 3)
+\tf <= 17;
+ else
+\tf <= 19;
+
+ // multi if
+ unique if (cyc < 3)
+\tg <= 17;
+ else if (cyc >= 3)
+\tg <= 19;
+
+ // multi if with else, else clause hit in some cases
+ unique if (cyc < 3)
+\th <= 17;
+ else if (cyc > 3)
+\th <= 19;
+ else
+\th <= 21;
+
+ //====================
+ // Negative test cases
+ //====================
+`ifdef FAILING_ASSERTION1
+ $display(""testing fail 1: %d"", cyc);
+ // multi if, multiple cases true
+ unique0 if (cyc < 3)
+\ti <= 17;
+ else if (cyc < 5)
+\ti <= 19;
+`endif
+
+`ifdef FAILING_ASSERTION2
+ // multi if, multiple cases true
+ unique if (cyc < 3)
+\tj <= 17;
+ else if (cyc < 5)
+\tj <= 19;
+`endif
+
+`ifdef FAILING_ASSERTION3
+ // multi if, no cases true
+ unique if (cyc > 1000)
+\tk <= 17;
+ else if (cyc > 2000)
+\tk <= 19;
+`endif
+
+`ifdef FAILING_ASSERTION4
+ // Single if, which is untrue sometimes.
+ // The LRM states: ""A software tool shall also issue an error if it determines that no condition\'
+ // is true, or it is possible that no condition is true, and the final if does not have a
+ // corresponding else."" In this case, the final if is the only if, but I think the clause
+ // still applies.
+ unique if (cyc > 5)
+\tl <= 17;
+`endif
+
+
+ if (cyc==10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Mike Thyer.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ int cycle=0;
+
+ // verilator lint_off UNOPTFLAT
+ reg [7:0] a_r;
+ wire [7:0] a_w;
+ reg [7:0] b_r;
+ reg [7:0] c_d_r, c_q_r;
+
+ assign a_w = a_r;
+
+ always @(*) begin
+ a_r = 0;
+ b_r = a_w; // Substituting the a_w assignment to get b_r = 0 is wrong, as a_r is not ""complete""
+ a_r = c_q_r;
+ c_d_r = c_q_r;
+ end
+
+ // stimulus + checks
+ always @(posedge clk) begin
+ cycle <= cycle+1;
+ if (cycle==0) begin
+ c_q_r <= 8\'b0;
+ end
+ else begin
+ c_q_r <= c_d_r+1;
+`ifdef TEST_VERBOSE
+ $display(""[%0t] a_r=%0d, b_r=%0d"", $time, a_r, b_r); // a_r and b_r should always be the same
+`endif
+ end
+ if (cycle >= 10) begin
+ if (b_r==9) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+ else begin
+ $stop;
+ end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Jeremy Bennett
+
+// see bug 591
+
+package pkg2;
+ parameter PARAM2 = 16;
+endpackage // pkg2
+
+package pkg1;
+ import pkg2::*;
+`ifdef T_PACKAGE_EXPORT
+ export pkg2::*; // Not supported on all simulators
+`endif
+ parameter PARAM1 = 8;
+endpackage // pkg1
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ import pkg1::*;
+
+ reg [PARAM1:0] bus1;
+ reg [PARAM2:0] bus2;
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+
+ reg\t\tnegate;
+ reg\t\tenable;
+
+ wire [31:0] datA = crc[31:0];
+ wire [31:0] datB = crc[63:32];
+
+ // Predict result
+ wire [63:0] \tmuled = (negate ? (- {32\'h0,datA} * {32\'h0,datB})
+\t\t\t : ( {32\'h0,datA} * {32\'h0,datB}));
+ reg [63:0] \tmuled_d1;
+ reg [63:0] \tmuled_d2;
+ reg [63:0] \tmuled_d3;
+ reg [63:0] \tmuled_d4;
+ reg \t\tenable_d1;
+ reg \t\tenable_d2;
+ reg \t\tenable_d3;
+ always @ (posedge clk) enable_d1 <= enable;
+ always @ (posedge clk) enable_d2 <= enable_d1;
+ always @ (posedge clk) enable_d3 <= enable_d2;
+ always @ (posedge clk) if (enable) muled_d1 <= muled;
+ always @ (posedge clk) if (enable_d1) muled_d2 <= muled_d1;
+ always @ (posedge clk) if (enable_d2) muled_d3 <= muled_d2;
+ always @ (posedge clk) if (enable_d3) muled_d4 <= muled_d3;
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [64:0]\t\tproduct_d4;\t\t// From test of t_math_synmul_mul.v
+ // End of automatics
+
+ t_math_synmul_mul test (/*AUTOINST*/
+\t\t\t // Outputs
+\t\t\t .product_d4\t\t(product_d4[64:0]),
+\t\t\t // Inputs
+\t\t\t .clk\t\t(clk),
+\t\t\t .enable\t\t(enable),
+\t\t\t .negate\t\t(negate),
+\t\t\t .datA\t\t(datA[31:0]),
+\t\t\t .datB\t\t(datB[31:0]));
+
+ integer cycs_enabled; initial cycs_enabled = 0;
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x e=%x n=%x a*b=%x synmul=%x\
+"",$time, cyc,
+\t crc, enable, negate, muled_d4, product_d4[63:0]);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ negate <= 1\'b0; // Negation not currently supported
+
+ // Always enable in low cycle counts to clear out the pipe
+ //enable <= 1\'b1; // 100% activity factor
+ enable <= (cyc<10 || cyc[4]); // 50% activity factor
+ //enable <= (cyc<10 || cyc[4]&cyc[3]); // 25% activity factor
+
+ if (enable) cycs_enabled=cycs_enabled+1;
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+ end
+ else begin
+\t if (product_d4[63:0] !== muled_d4) begin
+\t $write(""[%0t] BAD product, got=%x exp=%x\
+"",$time, product_d4[63:0], muled_d4);
+\t $stop;
+\t end
+\t if (cyc==99) begin
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t end
+`ifndef SIM_CYCLES
+ `define SIM_CYCLES 99
+`endif
+\t if (cyc==`SIM_CYCLES) begin
+\t $write(""- Cycles=%0d, Activity factor=%0d%%\
+"", cyc, ((cycs_enabled*100)/cyc));
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire bit_in = crc[0];
+ wire [30:0] vec_in = crc[31:1];
+ wire [123:0] wide_in = {crc[59:0],~crc[63:0]};
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire\t\t\texp_bit_out;\t\t// From reference of t_embed1_child.v
+ wire\t\t\texp_did_init_out;\t// From reference of t_embed1_child.v
+ wire [30:0]\t\texp_vec_out;\t\t// From reference of t_embed1_child.v
+ wire [123:0]\t\texp_wide_out;\t\t// From reference of t_embed1_child.v
+ wire\t\t\tgot_bit_out;\t\t// From test of t_embed1_wrap.v
+ wire\t\t\tgot_did_init_out;\t// From test of t_embed1_wrap.v
+ wire [30:0]\t\tgot_vec_out;\t\t// From test of t_embed1_wrap.v
+ wire [123:0]\t\tgot_wide_out;\t\t// From test of t_embed1_wrap.v
+ // End of automatics
+
+ // A non-embedded master
+
+ /* t_embed1_child AUTO_TEMPLATE(
+ .\\(.*_out\\) (exp_\\1[]),
+ .is_ref (1\'b1));
+ */
+ t_embed1_child reference
+ (/*AUTOINST*/
+ // Outputs
+ .bit_out\t\t\t\t(exp_bit_out),\t\t // Templated
+ .vec_out\t\t\t\t(exp_vec_out[30:0]),\t // Templated
+ .wide_out\t\t\t\t(exp_wide_out[123:0]),\t // Templated
+ .did_init_out\t\t\t(exp_did_init_out),\t // Templated
+ // Inputs
+ .clk\t\t\t\t(clk),
+ .bit_in\t\t\t\t(bit_in),
+ .vec_in\t\t\t\t(vec_in[30:0]),
+ .wide_in\t\t\t\t(wide_in[123:0]),
+ .is_ref\t\t\t\t(1\'b1));\t\t\t // Templated
+
+ // The embeded comparison
+
+ /* t_embed1_wrap AUTO_TEMPLATE(
+ .\\(.*_out\\) (got_\\1[]),
+ .is_ref (1\'b0));
+ */
+
+ t_embed1_wrap test
+ (/*AUTOINST*/
+ // Outputs
+ .bit_out\t\t\t\t(got_bit_out),\t\t // Templated
+ .vec_out\t\t\t\t(got_vec_out[30:0]),\t // Templated
+ .wide_out\t\t\t\t(got_wide_out[123:0]),\t // Templated
+ .did_init_out\t\t\t(got_did_init_out),\t // Templated
+ // Inputs
+ .clk\t\t\t\t(clk),
+ .bit_in\t\t\t\t(bit_in),
+ .vec_in\t\t\t\t(vec_in[30:0]),
+ .wide_in\t\t\t\t(wide_in[123:0]),
+ .is_ref\t\t\t\t(1\'b0));\t\t\t // Templated
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {60\'h0,
+\t\t\t got_wide_out !== exp_wide_out,
+\t\t\t got_vec_out !== exp_vec_out,
+\t\t\t got_bit_out !== exp_bit_out,
+\t\t\t got_did_init_out !== exp_did_init_out};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x gv=%x ev=%x\
+"",$time, cyc, crc, result,
+\t got_vec_out, exp_vec_out);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+ end
+ else if (cyc<90) begin
+\t if (result != 64\'h0) begin
+\t $display(""Bit mismatch, result=%x\
+"", result);
+\t $stop;
+\t end
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t //Child prints this: $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: System Verilog test of a complete CPU
+//
+// This code instantiates and runs a simple CPU written in System Verilog.
+//
+// This file ONLY is placed into the Public Domain, for any use, without
+// warranty.
+
+// Contributed 2012 by M W Lund, Atmel Corporation and Jeremy Bennett, Embecosm.
+
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ /*AUTOWIRE*/
+
+ // **************************************************************************
+ // Regs and Wires
+ // **************************************************************************
+
+ reg \t rst;
+ integer rst_count;
+ integer clk_count;
+
+
+ testbench testbench_i (/*AUTOINST*/
+\t\t\t // Inputs
+\t\t\t .clk\t\t\t(clk),
+\t\t\t .rst\t\t\t(rst));
+
+
+ // **************************************************************************
+ // Reset Generation
+ // **************************************************************************
+
+ initial begin
+ rst = 1\'b1;
+ rst_count = 0;
+ end
+
+ always @( posedge clk ) begin
+ if (rst_count < 2) begin
+\t rst_count++;
+ end
+ else begin
+\t rst = 1\'b0;
+ end
+ end
+
+
+ // **************************************************************************
+ // Drive simulation for 500 clock cycles
+ // **************************************************************************
+
+ initial begin
+`ifdef TEST_VERBOSE
+ $display( ""[testbench] - Start of simulation ----------------------- "" );
+`endif
+ clk_count = 0;
+ end
+
+ always @( posedge clk ) begin
+ if (90 == clk_count) begin
+\t $finish ();
+ end
+ else begin
+\t clk_count++;
+ end
+ end
+
+ final begin
+`ifdef TEST_VERBOSE
+ $display( ""[testbench] - End of simulation ------------------------- "" );
+`endif
+ $write(""*-* All Finished *-*\
+"");
+ end
+
+
+endmodule
+
+
+module testbench (/*AUTOARG*/
+ // Inputs
+ clk, rst
+ );
+
+ input clk;
+ input rst;
+
+ // **************************************************************************
+ // Local parameters
+ // **************************************************************************
+
+ localparam
+ NUMPADS = $size( pinout );
+
+
+ // **************************************************************************
+ // Regs and Wires
+ // **************************************************************************
+
+ // **** Pinout ****
+`ifdef VERILATOR // see t_tri_array
+ wire [NUMPADS:1] pad; // GPIO Pads (PORT{A,...,R}).
+`else
+ wire pad [1:NUMPADS]; // GPIO Pads (PORT{A,...,R}).
+`endif
+
+
+ // **************************************************************************
+ // Regs and Wires, Automatics
+ // **************************************************************************
+
+ /*AUTOWIRE*/
+
+
+ // **************************************************************************
+ // Includes (Testbench extensions)
+ // **************************************************************************
+
+ // N/A
+
+
+ // **************************************************************************
+ // Chip Instance
+ // **************************************************************************
+
+ chip
+ i_chip
+ (
+ /*AUTOINST*/
+\t// Inouts
+\t.pad\t\t\t\t(pad[NUMPADS:1]),
+\t// Inputs
+\t.clk\t\t\t\t(clk),
+\t.rst\t\t\t\t(rst));
+
+
+endmodule // test
+
+// Local Variables:
+// verilog-library-directories:(""."" ""t_sv_cpu_code"")
+// End:
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t;
+`define A B
+
+ // NOTDEF isn\'t defined here:
+ `NOTDEF
+
+//`include ""notfound""
+
+ initial $stop; // Should have failed
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+module t
+ (
+ input wire clk
+ );
+
+ integer cyc; initial cyc = 0;
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [15:0] in = crc[15:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [15:0]\t\touta;\t\t\t// From test of Test.v
+ wire [15:0]\t\toutb;\t\t\t// From test of Test.v
+ wire [15:0]\t\toutc;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .outa\t\t\t(outa[15:0]),
+\t .outb\t\t\t(outb[15:0]),
+\t .outc\t\t\t(outc[15:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(in[15:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {16\'h0, outa, outb, outc};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h09be74b1b0f8c35d
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ outa, outb, outc,
+ // Inputs
+ clk, in
+ );
+
+ input clk;
+ input [15:0] in;
+ output reg [15:0] outa;
+ output reg [15:0] outb;
+ output reg [15:0] outc;
+
+ parameter WIDTH = 0;
+ always @(posedge clk) begin
+ outa <= {in};
+ outb <= {{WIDTH{1\'b0}}, in};
+ outc <= {in, {WIDTH{1\'b0}}};
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ integer \tcyc=0;
+
+ genvar \tg;
+ integer \ti;
+
+ reg [31:0] v;
+
+ reg [31:0] gen_pre_PLUSPLUS = 32\'h0;
+ reg [31:0] gen_pre_MINUSMINUS = 32\'h0;
+ reg [31:0] gen_post_PLUSPLUS\t= 32\'h0;
+ reg [31:0] gen_post_MINUSMINUS = 32\'h0;
+ reg [31:0] gen_PLUSEQ = 32\'h0;
+ reg [31:0] gen_MINUSEQ = 32\'h0;
+ reg [31:0] gen_TIMESEQ = 32\'h0;
+ reg [31:0] gen_DIVEQ = 32\'h0;
+ reg [31:0] gen_MODEQ = 32\'h0;
+ reg [31:0] gen_ANDEQ = 32\'h0;
+ reg [31:0] gen_OREQ = 32\'h0;
+ reg [31:0] gen_XOREQ\t= 32\'h0;
+ reg [31:0] gen_SLEFTEQ = 32\'h0;
+ reg [31:0] gen_SRIGHTEQ = 32\'h0;
+ reg [31:0] gen_SSRIGHTEQ = 32\'h0;
+
+ generate
+ for (g=8; g<=16; ++g) always @(posedge clk) gen_pre_PLUSPLUS[g] = 1\'b1;
+ for (g=16; g>=8; --g) always @(posedge clk) gen_pre_MINUSMINUS[g] = 1\'b1;
+ for (g=8; g<=16; g++) always @(posedge clk) gen_post_PLUSPLUS[g] = 1\'b1;
+ for (g=16; g>=8; g--) always @(posedge clk) gen_post_MINUSMINUS[g] = 1\'b1;
+ for (g=8; g<=16; g+=2) always @(posedge clk) gen_PLUSEQ[g] = 1\'b1;
+ for (g=16; g>=8; g-=2) always @(posedge clk) gen_MINUSEQ[g] = 1\'b1;
+`ifndef verilator //UNSUPPORTED
+ for (g=8; g<=16; g*=2) always @(posedge clk) gen_TIMESEQ[g] = 1\'b1;
+ for (g=16; g>=8; g/=2) always @(posedge clk) gen_DIVEQ[g] = 1\'b1;
+ for (g=15; g>8; g%=8) always @(posedge clk) gen_MODEQ[g] = 1\'b1;
+ for (g=7; g>4; g&=4) always @(posedge clk) gen_ANDEQ[g] = 1\'b1;
+ for (g=1; g<=1; g|=2) always @(posedge clk) gen_OREQ[g] = 1\'b1;
+ for (g=7; g==7; g^=2) always @(posedge clk) gen_XOREQ[g] = 1\'b1;
+ for (g=8; g<=16; g<<=2) always @(posedge clk) gen_SLEFTEQ[g] = 1\'b1;
+ for (g=16; g>=8; g>>=2) always @(posedge clk) gen_SRIGHTEQ[g] = 1\'b1;
+ for (g=16; g>=8; g>>>=2) always @(posedge clk) gen_SSRIGHTEQ[g] = 1\'b1;
+`endif
+ endgenerate
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc == 3) begin
+`ifdef TEST_VERBOSE
+\t $write(""gen_pre_PLUSPLUS %b\
+"", gen_pre_PLUSPLUS);
+\t $write(""gen_pre_MINUSMINUS %b\
+"", gen_pre_MINUSMINUS);
+\t $write(""gen_post_PLUSPLUS %b\
+"", gen_post_PLUSPLUS);
+\t $write(""gen_post_MINUSMINUS %b\
+"", gen_post_MINUSMINUS);
+\t $write(""gen_PLUSEQ %b\
+"", gen_PLUSEQ);
+\t $write(""gen_MINUSEQ %b\
+"", gen_MINUSEQ);
+\t $write(""gen_TIMESEQ %b\
+"", gen_TIMESEQ);
+\t $write(""gen_DIVEQ %b\
+"", gen_DIVEQ);
+\t $write(""gen_MODEQ %b\
+"", gen_MODEQ);
+\t $write(""gen_ANDEQ %b\
+"", gen_ANDEQ);
+\t $write(""gen_OREQ %b\
+"", gen_OREQ);
+\t $write(""gen_XOREQ %b\
+"", gen_XOREQ);
+\t $write(""gen_SLEFTEQ %b\
+"", gen_SLEFTEQ);
+\t $write(""gen_SRIGHTEQ %b\
+"", gen_SRIGHTEQ);
+\t $write(""gen_SSRIGHTEQ %b\
+"", gen_SSRIGHTEQ);
+`endif
+\t if (gen_pre_PLUSPLUS\t!== 32\'b00000000000000011111111100000000) $stop;
+\t if (gen_pre_MINUSMINUS\t!== 32\'b00000000000000011111111100000000) $stop;
+\t if (gen_post_PLUSPLUS\t!== 32\'b00000000000000011111111100000000) $stop;
+\t if (gen_post_MINUSMINUS!== 32\'b00000000000000011111111100000000) $stop;
+\t if (gen_PLUSEQ\t\t!== 32\'b00000000000000010101010100000000) $stop;
+\t if (gen_MINUSEQ\t!== 32\'b00000000000000010101010100000000) $stop;
+`ifndef verilator //UNSUPPORTED
+\t if (gen_TIMESEQ\t!== 32\'b00000000000000010000000100000000) $stop;
+\t if (gen_DIVEQ\t\t!== 32\'b00000000000000010000000100000000) $stop;
+\t if (gen_MODEQ\t\t!== 32\'b00000000000000001000000000000000) $stop;
+\t if (gen_ANDEQ\t\t!== 32\'b00000000000000000000000010000000) $stop;
+\t if (gen_OREQ\t\t!== 32\'b00000000000000000000000000000010) $stop;
+\t if (gen_XOREQ\t\t!== 32\'b00000000000000000000000010000000) $stop;
+\t if (gen_SLEFTEQ\t!== 32\'b00000000000000000000000100000000) $stop;
+\t if (gen_SRIGHTEQ\t!== 32\'b00000000000000010000000000000000) $stop;
+\t if (gen_SSRIGHTEQ\t!== 32\'b00000000000000010000000000000000) $stop;
+`endif
+
+\t v=0; for (i=8; i<=16; ++i) v[i] = 1\'b1; if (v !== 32\'b00000000000000011111111100000000) $stop;
+\t v=0; for (i=16; i>=8; --i) v[i] = 1\'b1; if (v !== 32\'b00000000000000011111111100000000) $stop;
+\t v=0; for (i=8; i<=16; i++) v[i] = 1\'b1; if (v !== 32\'b00000000000000011111111100000000) $stop;
+\t v=0; for (i=16; i>=8; i--) v[i] = 1\'b1; if (v !== 32\'b00000000000000011111111100000000) $stop;
+\t v=0; for (i=8; i<=16; i+=2) v[i] = 1\'b1; if (v !== 32\'b00000000000000010101010100000000) $stop;
+\t v=0; for (i=16; i>=8; i-=2) v[i] = 1\'b1; if (v !== 32\'b00000000000000010101010100000000) $stop;
+`ifndef verilator //UNSUPPORTED
+\t v=0; for (i=8; i<=16; i*=2) v[i] = 1\'b1; if (v !== 32\'b00000000000000010000000100000000) $stop;
+\t v=0; for (i=16; i>=8; i/=2) v[i] = 1\'b1; if (v !== 32\'b00000000000000010000000100000000) $stop;
+\t v=0; for (i=15; i>8; i%=8) v[i] = 1\'b1; if (v !== 32\'b00000000000000001000000000000000) $stop;
+\t v=0; for (i=7; i>4; i&=4) v[i] = 1\'b1; if (v !== 32\'b00000000000000000000000010000000) $stop;
+\t v=0; for (i=1; i<=1; i|=2) v[i] = 1\'b1; if (v !== 32\'b00000000000000000000000000000010) $stop;
+\t v=0; for (i=7; i==7; i^=2) v[i] = 1\'b1; if (v !== 32\'b00000000000000000000000010000000) $stop;
+\t v=0; for (i=8; i<=16; i<<=2) v[i] =1\'b1; if (v !== 32\'b00000000000000000000000100000000) $stop;
+\t v=0; for (i=16; i>=8; i>>=2) v[i] =1\'b1; if (v !== 32\'b00000000000000010000000000000000) $stop;
+\t v=0; for (i=16; i>=8; i>>>=2) v[i]=1\'b1; if (v !== 32\'b00000000000000010000000000000000) $stop;
+`endif
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer cyc; initial cyc=1;
+ // verilator tracing_off
+ integer b_trace_off;
+ // verilator tracing_on
+ integer c_trace_on;
+ real\t r;
+
+ // verilator tracing_off
+ sub sub ();
+ // verilator tracing_on
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t b_trace_off <= cyc;
+\t c_trace_on <= b_trace_off;
+\t r <= r + 0.1;
+\t if (cyc==4) begin
+\t if (c_trace_on != 2) $stop;
+\t end
+\t if (cyc==10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+module sub;
+ integer inside_sub = 0;
+endmodule
+"
+"// DESCRIPTION: Verilator: Dedupe optimization test.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty.
+
+// Contributed 2012 by Varun Koyyalagunta, Centaur Technology.
+//
+// Test consists of the follow logic tree, which has many obvious
+// places for dedupe:
+/*
+ output
+ +
+ --------------/ \\--------------
+ / \\
+ + +
+ ----/ \\----- ----/ \\----
+ / + / +
+ + / \\ + / \\
+ -/ \\- a b -/ \\- a b
+ / \\ / \\
+ + + + +
+ / \\ / \\ / \\ / \\
+ a b c d a b c d
+*/
+
+module t(sum,a,b,c,d,clk);
+ output sum;
+ input a,b,c,d,clk;
+ wire left,right;
+ add add(sum,left,right,clk);
+ l l(left,a,b,c,d,clk);
+ r r(right,a,b,c,d,clk);
+endmodule
+
+module l(sum,a,b,c,d,clk);
+ output sum;
+ input a,b,c,d,clk;
+ wire left, right;
+ add add(sum,left,right,clk);
+ ll ll(left,a,b,c,d,clk);
+ lr lr(right,a,b,c,d,clk);
+endmodule
+
+module ll(sum,a,b,c,d,clk);
+ output sum;
+ input a,b,c,d,clk;
+ wire left, right;
+ add add(sum,left,right,clk);
+ lll lll(left,a,b,c,d,clk);
+ llr llr(right,a,b,c,d,clk);
+endmodule
+
+module lll(sum,a,b,c,d,clk);
+ output sum;
+ input a,b,c,d,clk;
+ add add(sum,a,b,clk);
+endmodule
+
+module llr(sum,a,b,c,d,clk);
+ output sum;
+ input a,b,c,d,clk;
+ add add(sum,c,d,clk);
+endmodule
+
+module lr(sum,a,b,c,d,clk);
+ output sum;
+ input a,b,c,d,clk;
+ add add(sum,a,b,clk);
+endmodule
+
+module r(sum,a,b,c,d,clk);
+ output sum;
+ input a,b,c,d,clk;
+ wire left, right;
+ add add(sum,left,right,clk);
+ rl rl(left,a,b,c,d,clk);
+ rr rr(right,a,b,c,d,clk);
+endmodule
+
+module rr(sum,a,b,c,d,clk);
+ output sum;
+ input a,b,c,d,clk;
+ add add(sum,a,b,clk);
+endmodule
+
+module rl(sum,a,b,c,d,clk);
+ output sum;
+ input a,b,c,d,clk;
+ wire left, right;
+ add add(sum,left,right,clk);
+ rll rll(left,a,b,c,d,clk);
+ rlr rlr(right,a,b,c,d,clk);
+endmodule
+
+module rll(sum,a,b,c,d,clk);
+ output sum;
+ input a,b,c,d,clk;
+ add2 add(sum,a,b,clk);
+endmodule
+
+module rlr(sum,a,b,c,d,clk);
+ output sum;
+ input a,b,c,d,clk;
+ add2 add(sum,c,d,clk);
+endmodule
+
+module add(sum,x,y,clk);
+ output sum;
+ input x,y,clk;
+ reg t1,t2;
+ always @(posedge clk) begin
+ sum <= x + y;
+ end
+endmodule
+
+module add2(sum,x,y,clk);
+ output sum;
+ input x,y,clk;
+ reg t1,t2;
+ always @(posedge clk) begin
+ sum <= x + y;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg \t a;\tinitial a = 1\'b1;
+ reg \t b_fc;\tinitial b_fc = 1\'b0;
+ reg \t b_pc;\tinitial b_pc = 1\'b0;
+ reg \t b_oh;\tinitial b_oh = 1\'b0;
+ reg \t b_oc;\tinitial b_oc = 1\'b0;
+ wire a_l = ~a;
+ wire b_oc_l = ~b_oc;
+
+ // Note we must insure that full, parallel, etc, only fire during
+ // edges (not mid-cycle), and must provide a way to turn them off.
+ // SystemVerilog provides: $asserton and $assertoff.
+
+ // verilator lint_off CASEINCOMPLETE
+
+ always @* begin
+ // Note not all tools support directives on casez\'s
+ case ({a,b_fc}) // synopsys full_case
+\t2\'b0_0: ;
+\t2\'b0_1: ;
+\t2\'b1_0: ;
+\t// Note no default
+ endcase
+ priority case ({a,b_fc})
+\t2\'b0_0: ;
+\t2\'b0_1: ;
+\t2\'b1_0: ;
+\t// Note no default
+ endcase
+ end
+
+ always @* begin
+ case (1\'b1) // synopsys full_case parallel_case
+\ta: ;
+\tb_pc: ;
+ endcase
+ end
+
+`ifdef NOT_YET_VERILATOR // Unsupported
+ // ambit synthesis one_hot ""a, b_oh""
+ // cadence one_cold ""a_l, b_oc_l""
+`endif
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t a <= 1\'b1;
+\t b_fc <= 1\'b0;
+\t b_pc <= 1\'b0;
+\t b_oh <= 1\'b0;
+\t b_oc <= 1\'b0;
+\t end
+\t if (cyc==2) begin
+\t a <= 1\'b0;
+\t b_fc <= 1\'b1;
+\t b_pc <= 1\'b1;
+\t b_oh <= 1\'b1;
+\t b_oc <= 1\'b1;
+\t end
+\t if (cyc==3) begin
+\t a <= 1\'b1;
+\t b_fc <= 1\'b0;
+\t b_pc <= 1\'b0;
+\t b_oh <= 1\'b0;
+\t b_oc <= 1\'b0;
+\t end
+\t if (cyc==4) begin
+`ifdef FAILING_FULL
+\t b_fc <= 1\'b1;
+`endif
+`ifdef FAILING_PARALLEL
+\t b_pc <= 1\'b1;
+`endif
+`ifdef FAILING_OH
+\t b_oh <= 1\'b1;
+`endif
+`ifdef FAILING_OC
+\t b_oc <= 1\'b1;
+`endif
+\t end
+\t if (cyc==10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (
+ input wire CLK,
+ output reg RESET
+\t );
+
+ neg neg (.clk(CLK));
+ little little (.clk(CLK));
+ glbl glbl ();
+
+ // A vector
+ logic [2:1] vec [4:3];
+
+ integer val = 0;
+ always @ (posedge CLK) begin
+ if (RESET) val <= 0;
+ else val <= val + 1;
+ vec[3] <= val[1:0];
+ vec[4] <= val[3:2];
+ end
+
+ initial RESET = 1'b1;
+ always @ (posedge CLK)
+ RESET <= glbl.GSR;
+
+endmodule
+
+module glbl();
+`ifdef PUB_FUNC
+ wire GSR;
+ task setGSR;
+ /* verilator public */
+ input value;
+ GSR = value;
+ endtask
+`else
+ wire GSR /*verilator public*/;
+`endif
+endmodule
+
+module neg (
+ input clk
+\t );
+
+ reg [0:-7] i8; initial i8 = '0;
+ reg [-1:-48] i48; initial i48 = '0;
+ reg [63:-64] i128; initial i128 = '0;
+
+ always @ (posedge clk) begin
+ i8 <= ~i8;
+ i48 <= ~i48;
+ i128 <= ~i128;
+ end
+endmodule
+
+module little (
+ input clk
+\t );
+
+ // verilator lint_off LITENDIAN
+ reg [0:7] i8; initial i8 = '0;
+ reg [1:49] i48; initial i48 = '0;
+ reg [63:190] i128; initial i128 = '0;
+ // verilator lint_on LITENDIAN
+
+ always @ (posedge clk) begin
+ i8 <= ~i8;
+ i48 <= ~i48;
+ i128 <= ~i128;
+ end
+endmodule
+"
+"//*************************************************************************
+//
+// Code available from: http://www.veripool.org/verilator
+//
+//*************************************************************************
+//
+// Copyright 2003-2015 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License.
+// Version 2.0.
+//
+// This is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+//=========================================================================
+//
+// DESCRIPTION: Verilator: Include in verilog files to hide verilator defines
+\x0c
+`ifdef _VERILATED_V_ `else
+ `define _VERILATED_V_ 1
+
+ // Hide verilator pragmas from other tools
+ `ifdef VERILATOR `else
+ `define coverage_block_off
+ `endif
+
+ // Hide file descriptor difference - deprecated - for older versions
+ `define verilator_file_descriptor integer
+
+`endif // guard
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003-2007 by Wilson Snyder.
+
+module t;
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ fastclk, clk
+ );
+
+`ifdef EDGE_DETECT_STYLE\t// Two \'common\' forms of latching, with full combo, and with pos/negedge
+ `define posstyle posedge
+ `define negstyle negedge
+`else
+ `define posstyle
+ `define negstyle
+`endif
+
+ input fastclk;
+ input clk;
+
+ reg [7:0] data;
+ reg [7:0] data_a;
+ reg [7:0] data_a_a;
+ reg [7:0] data_a_b;
+ reg [7:0] data_b;
+ reg [7:0] data_b_a;
+ reg [7:0] data_b_b;
+
+ reg [8*6-1:0] check [100:0];
+ wire [8*6-1:0] compare = {data_a,data_a_a,data_b_a,data_b,data_a_b,data_b_b};
+ initial begin
+ check[7\'d19] = {8\'h0d, 8\'h0e, 8\'h0e, 8\'h0d, 8\'h0e, 8\'h0e};
+ check[7\'d20] = {8\'h0d, 8\'h0e, 8\'h0e, 8\'h0d, 8\'h0e, 8\'h0e};
+ check[7\'d21] = {8\'h15, 8\'h16, 8\'h0e, 8\'h0d, 8\'h0e, 8\'h0e};
+ check[7\'d22] = {8\'h15, 8\'h16, 8\'h0e, 8\'h0d, 8\'h0e, 8\'h0e};
+ check[7\'d23] = {8\'h15, 8\'h16, 8\'h0e, 8\'h15, 8\'h16, 8\'h0e};
+ check[7\'d24] = {8\'h15, 8\'h16, 8\'h0e, 8\'h15, 8\'h16, 8\'h0e};
+ check[7\'d25] = {8\'h15, 8\'h16, 8\'h0e, 8\'h15, 8\'h16, 8\'h0e};
+ check[7\'d26] = {8\'h15, 8\'h16, 8\'h16, 8\'h15, 8\'h16, 8\'h0e};
+ check[7\'d27] = {8\'h15, 8\'h16, 8\'h16, 8\'h15, 8\'h16, 8\'h0e};
+ check[7\'d28] = {8\'h15, 8\'h16, 8\'h16, 8\'h15, 8\'h16, 8\'h16};
+ check[7\'d29] = {8\'h15, 8\'h16, 8\'h16, 8\'h15, 8\'h16, 8\'h16};
+ check[7\'d30] = {8\'h15, 8\'h16, 8\'h16, 8\'h15, 8\'h16, 8\'h16};
+ check[7\'d31] = {8\'h1f, 8\'h20, 8\'h16, 8\'h15, 8\'h16, 8\'h16};
+ check[7\'d32] = {8\'h1f, 8\'h20, 8\'h16, 8\'h15, 8\'h16, 8\'h16};
+ check[7\'d33] = {8\'h1f, 8\'h20, 8\'h16, 8\'h1f, 8\'h20, 8\'h16};
+ check[7\'d34] = {8\'h1f, 8\'h20, 8\'h16, 8\'h1f, 8\'h20, 8\'h16};
+ check[7\'d35] = {8\'h1f, 8\'h20, 8\'h16, 8\'h1f, 8\'h20, 8\'h16};
+ check[7\'d36] = {8\'h1f, 8\'h20, 8\'h20, 8\'h1f, 8\'h20, 8\'h16};
+ check[7\'d37] = {8\'h1f, 8\'h20, 8\'h20, 8\'h1f, 8\'h20, 8\'h16};
+ end
+
+ // verilator lint_off COMBDLY
+ always @ (`posstyle clk /*AS*/ or data) begin
+ if (clk) begin
+\t data_a <= data + 8\'d1;
+ end
+ end
+
+ always @ (`posstyle clk /*AS*/ or data_a) begin
+ if (clk) begin
+\t data_a_a <= data_a + 8\'d1;
+ end
+ end
+
+ always @ (`posstyle clk /*AS*/ or data_b) begin
+ if (clk) begin
+\t data_b_a <= data_b + 8\'d1;
+ end
+ end
+
+ always @ (`negstyle clk /*AS*/ or data or data_a) begin
+ if (~clk) begin
+\t data_b <= data + 8\'d1;
+\t data_a_b <= data_a + 8\'d1;
+\t data_b_b <= data_b + 8\'d1;
+ end
+ end
+
+ integer cyc; initial cyc=0;
+
+ always @ (posedge fastclk) begin
+ cyc <= cyc+1;
+`ifdef TEST_VERBOSE
+ $write(""%d %x %x %x %x %x %x\
+"",cyc,data_a,data_a_a,data_b_a,data_b,data_a_b,data_b_b);
+`endif
+ if (cyc>=19 && cyc<36) begin
+\t if (compare !== check[cyc]) begin
+\t $write(""[%0t] Mismatch, got=%x, exp=%x\
+"", $time, compare, check[cyc]);
+\t $stop;
+\t end
+ end
+ if (cyc == 10) begin
+\t data <= 8\'d12;
+ end
+ if (cyc == 20) begin
+\t data <= 8\'d20;
+ end
+ if (cyc == 30) begin
+\t data <= 8\'d30;
+ end
+ if (cyc == 40) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Iztok Jeras.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ localparam NO = 7; // number of access events
+
+ // packed structures
+ struct packed {
+ logic e0;
+ logic [1:0] e1;
+ logic [3:0] e2;
+ logic [7:0] e3;
+ } struct_bg; // big endian structure
+ /* verilator lint_off LITENDIAN */
+ struct packed {
+ logic e0;
+ logic [0:1] e1;
+ logic [0:3] e2;
+ logic [0:7] e3;
+ } struct_lt; // little endian structure
+ /* verilator lint_on LITENDIAN */
+
+ localparam WS = 15; // $bits(struct_bg)
+
+ integer cnt = 0;
+
+ // event counter
+ always @ (posedge clk)
+ begin
+ cnt <= cnt + 1;
+ end
+
+ // finish report
+ always @ (posedge clk)
+ if ((cnt[30:2]==(NO-1)) && (cnt[1:0]==2\'d3)) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ // big endian
+ always @ (posedge clk)
+ if (cnt[1:0]==2\'d0) begin
+ // initialize to defaults (all bits 1\'b0)
+ if (cnt[30:2]==0) struct_bg <= \'0;
+ else if (cnt[30:2]==1) struct_bg <= \'0;
+ else if (cnt[30:2]==2) struct_bg <= \'0;
+ else if (cnt[30:2]==3) struct_bg <= \'0;
+ else if (cnt[30:2]==4) struct_bg <= \'0;
+ else if (cnt[30:2]==5) struct_bg <= \'0;
+ else if (cnt[30:2]==6) struct_bg <= \'0;
+ end else if (cnt[1:0]==2\'d1) begin
+ // write data into whole or part of the array using literals
+ if (cnt[30:2]==0) begin end
+ else if (cnt[30:2]==1) struct_bg <= \'{0 ,1 , 2, 3};
+ else if (cnt[30:2]==2) struct_bg <= \'{e0:1, e1:2, e2:3, e3:4};
+ else if (cnt[30:2]==3) struct_bg <= \'{e3:6, e2:4, e1:2, e0:0};
+ // verilator lint_off WIDTH
+ else if (cnt[30:2]==4) struct_bg <= \'{default:13};
+ else if (cnt[30:2]==5) struct_bg <= \'{e2:8\'haa, default:1};
+ else if (cnt[30:2]==6) struct_bg <= \'{cnt+0 ,cnt+1 , cnt+2, cnt+3};
+ // verilator lint_on WIDTH
+ end else if (cnt[1:0]==2\'d2) begin
+ // chack array agains expected value
+ if (cnt[30:2]==0) begin if (struct_bg !== 15\'b0_00_0000_00000000) begin $display(""%b"", struct_bg); $stop(); end end
+ else if (cnt[30:2]==1) begin if (struct_bg !== 15\'b0_01_0010_00000011) begin $display(""%b"", struct_bg); $stop(); end end
+ else if (cnt[30:2]==2) begin if (struct_bg !== 15\'b1_10_0011_00000100) begin $display(""%b"", struct_bg); $stop(); end end
+ else if (cnt[30:2]==3) begin if (struct_bg !== 15\'b0_10_0100_00000110) begin $display(""%b"", struct_bg); $stop(); end end
+ else if (cnt[30:2]==4) begin if (struct_bg !== 15\'b1_01_1101_00001101) begin $display(""%b"", struct_bg); $stop(); end end
+ else if (cnt[30:2]==5) begin if (struct_bg !== 15\'b1_01_1010_00000001) begin $display(""%b"", struct_bg); $stop(); end end
+ else if (cnt[30:2]==6) begin if (struct_bg !== 15\'b1_10_1011_00011100) begin $display(""%b"", struct_bg); $stop(); end end
+ end
+
+ // little endian
+ always @ (posedge clk)
+ if (cnt[1:0]==2\'d0) begin
+ // initialize to defaults (all bits 1\'b0)
+ if (cnt[30:2]==0) struct_lt <= \'0;
+ else if (cnt[30:2]==1) struct_lt <= \'0;
+ else if (cnt[30:2]==2) struct_lt <= \'0;
+ else if (cnt[30:2]==3) struct_lt <= \'0;
+ else if (cnt[30:2]==4) struct_lt <= \'0;
+ else if (cnt[30:2]==5) struct_lt <= \'0;
+ else if (cnt[30:2]==6) struct_lt <= \'0;
+ end else if (cnt[1:0]==2\'d1) begin
+ // write data into whole or part of the array using literals
+ if (cnt[30:2]==0) begin end
+ else if (cnt[30:2]==1) struct_lt <= \'{0 ,1 , 2, 3};
+ else if (cnt[30:2]==2) struct_lt <= \'{e0:1, e1:2, e2:3, e3:4};
+ else if (cnt[30:2]==3) struct_lt <= \'{e3:6, e2:4, e1:2, e0:0};
+ // verilator lint_off WIDTH
+ else if (cnt[30:2]==4) struct_lt <= \'{default:13};
+ else if (cnt[30:2]==5) struct_lt <= \'{e2:8\'haa, default:1};
+ else if (cnt[30:2]==6) struct_lt <= \'{cnt+0 ,cnt+1 , cnt+2, cnt+3};
+ // verilator lint_on WIDTH
+ end else if (cnt[1:0]==2\'d2) begin
+ // chack array agains expected value
+ if (cnt[30:2]==0) begin if (struct_lt !== 15\'b0_00_0000_00000000) begin $display(""%b"", struct_lt); $stop(); end end
+ else if (cnt[30:2]==1) begin if (struct_lt !== 15\'b0_01_0010_00000011) begin $display(""%b"", struct_lt); $stop(); end end
+ else if (cnt[30:2]==2) begin if (struct_lt !== 15\'b1_10_0011_00000100) begin $display(""%b"", struct_lt); $stop(); end end
+ else if (cnt[30:2]==3) begin if (struct_lt !== 15\'b0_10_0100_00000110) begin $display(""%b"", struct_lt); $stop(); end end
+ else if (cnt[30:2]==4) begin if (struct_lt !== 15\'b1_01_1101_00001101) begin $display(""%b"", struct_lt); $stop(); end end
+ else if (cnt[30:2]==5) begin if (struct_lt !== 15\'b1_01_1010_00000001) begin $display(""%b"", struct_lt); $stop(); end end
+ else if (cnt[30:2]==6) begin if (struct_lt !== 15\'b1_10_1011_00011100) begin $display(""%b"", struct_lt); $stop(); end end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator:
+// Test an error where a shift amount was out of bounds and the compiler treats the
+// value as undefined (Issue #803)
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Jeff Bush.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ struct packed {
+\tlogic flag;
+\tlogic [130:0] data;
+ } foo[1];
+
+ integer cyc=0;
+
+ // Test loop
+ always @ (posedge clk) begin
+\tcyc <= cyc + 1;
+\tfoo[0].data <= 0;
+\tfoo[0].flag <= !foo[0].flag;
+\tif (cyc==10) begin
+\t if (foo[0].data != 0) begin
+\t \t$display(""bad data value %x"", foo[0].data);
+\t\t$stop;
+\t end
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\tend
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+typedef enum logic [4:0]
+ {
+ BIT0 = 5\'d0,
+ BIT1 = 5\'d1,
+ BIT2 = 5\'d2
+ } three_t;
+
+module t (/*AUTOARG*/);
+
+ localparam FIVE = 5;
+
+ enum { e0,
+\t e1,
+\t e3=3,
+\t e5=FIVE,
+\t e10_[2] = 10,
+\t e20_[5:7] = 25,
+\t e20_z,
+\t e30_[7:5] = 30,
+\t e30_z
+\t } EN;
+
+ enum {
+\t z5 = e5
+\t } ZN;
+
+ typedef enum [2:0] { ONES=~0 } three_t;
+ three_t three = ONES;
+
+ var logic [ONES:0] sized_based_on_enum;
+
+ var enum logic [3:0] { QINVALID=\'1, QSEND={2\'b0,2\'h0}, QOP={2\'b0,2\'h1}, QCL={2\'b0,2\'h2},
+\t\t\t QPR={2\'b0,2\'h3 }, QACK, QRSP } inv;
+
+ initial begin
+ if (e0 !== 0) $stop;
+ if (e1 !== 1) $stop;
+ if (e3 !== 3) $stop;
+ if (e5 !== 5) $stop;
+ if (e10_0 !== 10) $stop;
+ if (e10_1 !== 11) $stop;
+ if (e20_5 !== 25) $stop;
+ if (e20_6 !== 26) $stop;
+ if (e20_7 !== 27) $stop;
+ if (e20_z !== 28) $stop;
+ if (e30_7 !== 30) $stop;
+ if (e30_6 !== 31) $stop;
+ if (e30_5 !== 32) $stop;
+ if (e30_z !== 33) $stop;
+
+ if (z5 !== 5) $stop;
+
+ if (three != 3\'b111) $stop;
+
+ if ($bits(sized_based_on_enum) != 8) $stop;
+ if ($bits(three_t) != 3) $stop;
+
+ if (FIVE[BIT0] != 1\'b1) $stop;
+ if (FIVE[BIT1] != 1\'b0) $stop;
+ if (FIVE[BIT2] != 1\'b1) $stop;
+
+ if (QINVALID != 15) $stop;
+ if (QSEND != 0) $stop;
+ if (QOP != 1) $stop;
+ if (QCL != 2) $stop;
+ if (QPR != 3) $stop;
+ if (QACK != 4) $stop;
+ if (QRSP != 5) $stop;
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer cyc; initial cyc = 0;
+ integer a;
+ integer b;
+
+ initial begin
+ a <= 22;
+ b <= 33;
+ end
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==99) begin
+\t if (a != 22) $stop;
+\t if (b != 33) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+`include ""verilated.v""
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg [63:0] crc;
+ `verilator_file_descriptor\t fd;
+
+ t_case_write2_tasks tasks ();
+
+ integer cyc; initial cyc=0;
+
+ always @ (posedge clk) begin
+ $fwrite(fd, ""[%0d] crc=%x "", cyc, crc);
+ tasks.big_case(fd, crc[31:0]);
+ $fwrite(fd, ""\
+"");
+ end
+
+ always @ (posedge clk) begin
+ //$write(""[%0t] cyc==%0d crc=%x\
+"",$time, cyc, crc);
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ if (cyc==1) begin
+\t crc <= 64\'h00000000_00000097;
+\t $write(""Open obj_dir/t_case_write2/t_case_write2_logger.log\
+"");
+\t fd = $fopen(""obj_dir/t_case_write2/t_case_write2_logger.log"", ""w"");
+ end
+ if (cyc==90) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t
+ (
+ output wire o,
+ input wire i,
+ input wire i2
+ );
+
+ sub
+ #(, .P(2), .P(3))
+ sub (.o(o),
+\t.i(i),
+\t.i(i2),
+\t);
+
+endmodule
+
+module sub
+ #(parameter P=1)
+ (
+ output wire o,
+ input wire i
+ );
+
+ assign o = ~i;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ // verilator lint_off GENCLK
+ reg \t printclk;
+ // verilator lint_on GENCLK
+ ps ps (printclk);
+
+ reg [7:0] a;
+ wire [7:0] z;
+
+ l1 u (~a,z);
+
+ always @ (posedge clk) begin
+ printclk <= 0;
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t printclk <= 1\'b1;
+\t end
+\t if (cyc==2) begin
+\t a <= 8\'b1;
+\t end
+\t if (cyc==3) begin
+\t if (z !== 8\'hf8) $stop;
+\t //if (u.u1.u1.u1.u0.PARAM !== 1) $stop;
+\t //if (u.u1.u1.u1.u1.PARAM !== 2) $stop;
+\t //if (u.u0.u0.u0.u0.z !== 8\'hfe) $stop;
+\t //if (u.u0.u0.u0.u1.z !== 8\'hff) $stop;
+\t //if (u.u1.u1.u1.u0.z !== 8\'h00) $stop;
+\t //if (u.u1.u1.u1.u1.z !== 8\'h01) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+`ifdef USE_INLINE
+ `define INLINE_MODULE /*verilator inline_module*/
+`else
+ `define INLINE_MODULE /*verilator public_module*/
+`endif
+
+`ifdef USE_PUBLIC
+ `define PUBLIC /*verilator public*/
+`else
+ `define PUBLIC
+`endif
+
+module ps (input printclk);
+ `INLINE_MODULE
+ // Check that %m stays correct across inlines
+ always @ (posedge printclk) $write(""[%0t] %m: Clocked\
+"", $time);
+endmodule
+
+module l1 (input [7:0] a, output [7:0] z);
+ `INLINE_MODULE
+ wire [7:0] z0 `PUBLIC; wire [7:0] z1 `PUBLIC;
+ wire [7:0] z `PUBLIC; assign z = z0+z1;
+ l2 u0 (a, z0); l2 u1 (a, z1);
+endmodule
+
+module l2 (input [7:0] a, output [7:0] z);
+ `INLINE_MODULE
+ wire [7:0] z0 `PUBLIC; wire [7:0] z1 `PUBLIC;
+ wire [7:0] z `PUBLIC; assign z = z0+z1;
+ wire [7:0] a1 = a+8\'d1;
+ l3 u0 (a, z0); l3 u1 (a1, z1);
+endmodule
+
+module l3 (input [7:0] a, output [7:0] z);
+ `INLINE_MODULE
+ wire [7:0] z0 `PUBLIC; wire [7:0] z1 `PUBLIC;
+ wire [7:0] z `PUBLIC; assign z = z0+z1;
+ wire [7:0] a1 = a+8\'d1;
+ l4 u0 (a, z0); l4 u1 (a1, z1);
+endmodule
+
+module l4 (input [7:0] a, output [7:0] z);
+ `INLINE_MODULE
+ wire [7:0] z0 `PUBLIC; wire [7:0] z1 `PUBLIC;
+ wire [7:0] z `PUBLIC; assign z = z0+z1;
+ wire [7:0] a1 = a+8\'d1;
+ l5 #(1) u0 (a, z0); l5 #(2) u1 (a1, z1);
+endmodule
+
+module l5 (input [7:0] a, output [7:0] z);
+ `INLINE_MODULE
+ parameter PARAM = 5;
+ wire [7:0] z0 `PUBLIC; wire [7:0] z1 `PUBLIC;
+ wire [7:0] z `PUBLIC; assign z = a;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+// bug789 generates
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc=1;
+
+ ifc #(1) itopa();
+ ifc #(2) itopb();
+
+ sub #(1) ca (.isub(itopa),
+\t\t.i_value(4));
+ sub #(2) cb (.isub(itopb),
+\t\t.i_value(5));
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==1) begin
+\t if (itopa.MODE != 1) $stop;
+\t if (itopb.MODE != 2) $stop;
+ end
+ if (cyc==20) begin
+\t if (itopa.i != 4) $stop;
+\t if (itopb.i != 5) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module sub
+ #(parameter MODE = 0)
+ (
+ ifc isub,
+ input integer i_value
+ );
+
+ // Commercial unsupported Xmrs into scopes within interfaces
+ generate
+ always_comb isub.i = i_value;
+ endgenerate
+endmodule
+
+interface ifc;
+ parameter MODE = 0;
+ // Commercial unsupported Xmrs into scopes within interfaces
+ generate
+ integer \t i;
+ endgenerate
+endinterface
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+
+`define GOT_DEF5
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This is to test the handling of VarXRef when the referenced VAR is
+// under a generate construction.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Jie Xu and Roland Kruse.
+
+module t (/*AUTOARG*/
+\t // Inputs
+\t clk, addr, res
+\t );
+
+ input clk;
+
+ input [31:0] addr;
+ output [15:0] res;
+
+ memory i_mem(.addr(addr),.dout(res));
+
+ assign i_mem.cxrow_inst[0].cmem_xrow[0] = 16'h0;
+
+endmodule
+
+
+
+module memory(addr, dout);
+ parameter CM_XROWSIZE = 256;
+ parameter CM_NUMXROWS = 2;
+
+ input [31:0] addr;
+ output [15:0] dout;
+
+ generate
+ genvar \t g_cx;
+ for (g_cx = 0; g_cx < CM_NUMXROWS; g_cx++)
+ begin: cxrow_inst
+ reg [15:0] cmem_xrow[0:CM_XROWSIZE - 1];
+ end
+ endgenerate
+
+ assign dout = cxrow_inst[0].cmem_xrow[addr];
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ // verilator lint_off BLKANDNBLK
+ // verilator lint_off COMBDLY
+ // verilator lint_off UNOPT
+ // verilator lint_off UNOPTFLAT
+ // verilator lint_off MULTIDRIVEN
+
+ reg [31:0] \t runnerm1, runner; initial runner = 0;
+ reg [31:0] \t runcount; initial runcount = 0;
+ reg [31:0] \t clkrun; initial clkrun = 0;
+ reg [31:0] \t clkcount; initial clkcount = 0;
+ always @ (/*AS*/runner) begin
+ runnerm1 = runner - 32\'d1;
+ end
+ reg run0;
+ always @ (/*AS*/runnerm1) begin
+ if ((runner & 32\'hf)!=0) begin
+\t runcount = runcount + 1;
+\t runner = runnerm1;
+\t $write ("" seq runcount=%0d runner =%0x\
+"",runcount, runnerm1);
+ end
+ run0 = (runner[8:4]!=0 && runner[3:0]==0);
+ end
+
+ always @ (posedge run0) begin
+ // Do something that forces another combo run
+ clkcount <= clkcount + 1;
+ runner[8:4] <= runner[8:4] - 1;
+ runner[3:0] <= 3;
+ $write (""[%0t] posedge runner=%0x\
+"", $time, runner);
+ end
+
+ reg [7:0] cyc; initial cyc=0;
+ always @ (posedge clk) begin
+ $write(""[%0t] %x counts %0x %0x\
+"",$time,cyc,runcount,clkcount);
+ cyc <= cyc + 8\'d1;
+ case (cyc)
+\t8\'d00: begin
+\t runner <= 0;
+\tend
+\t8\'d01: begin
+\t runner <= 32\'h35;
+\tend
+\tdefault: ;
+ endcase
+ case (cyc)
+\t8\'d02: begin
+\t if (runcount!=32\'he) $stop;
+\t if (clkcount!=32\'h3) $stop;
+\tend
+\t8\'d03: begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\tend
+\tdefault: ;
+ endcase
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// A test case for struct signal bit selection.
+//
+// This test is to check that bit selection of multi-dimensional signal inside
+// of a packed struct works. Currently +: and -: blow up with packed structs.
+//
+// This file ONLY is placed into the Public Domain, for any use, without
+// warranty, 2013 by Jie Xu.
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
+
+module t(/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ typedef struct packed {
+ logic [15:0] channel;
+ logic [15:0] others;
+ } buss_t;
+
+ buss_t b;
+
+ reg [7:0] a;
+ reg [7:0] c;
+ reg [7:0] d;
+
+ union packed {
+ logic [31:0] [7:0] idx;
+ struct \t\t packed {
+\t logic [15:0] z, y, x;
+\t logic [25:0] [7:0] r;
+ } nam;
+ } gpr;
+
+ reg [14:0] gpr_a;
+
+ initial begin
+ b = {16\'h8765,16\'h4321};
+ a = b[19:12];\t\t\t// This works
+ c = b[8+:8];\t\t\t// This fails
+ d = b[11-:8];\t\t\t// This fails
+ `checkh(a, 8\'h54);
+ `checkh(c, 8\'h43);
+ `checkh(d, 8\'h32);
+
+ gpr = 256\'h12346789_abcdef12_3456789a_bcdef123_456789ab_cdef1234_56789abc_def12345;
+ `checkh (gpr[255:255-14], 15\'h091a);
+ gpr_a = gpr.nam.z[15:1];
+ `checkh (gpr_a, 15\'h091a);
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+ parameter ONE = 1;
+
+ wire [17:10] bitout;
+ reg [7:0] allbits;
+ reg [15:0] onebit;
+
+ sub #(1)
+ sub0 (allbits, onebit[1:0], bitout[10]),
+ sub1 (allbits, onebit[3:2], bitout[11]),
+ sub2 (allbits, onebit[5:4], bitout[12]),
+ sub3 (allbits, onebit[7:6], bitout[13]),
+ sub4 (allbits, onebit[9:8], bitout[14]),
+ sub5 (allbits, onebit[11:10], bitout[15]),
+ sub6 (allbits, onebit[13:12], bitout[16]),
+ sub7 (allbits, onebit[15:14], bitout[17]);
+
+ integer x;
+
+ always @ (posedge clk) begin
+ //$write(""%x\
+"", bitout);
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t allbits <= 8\'hac;
+\t onebit <= 16\'hc01a;
+\t end
+\t if (cyc==2) begin
+\t if (bitout !== 8\'h07) $stop;
+\t allbits <= 8\'hca;
+\t onebit <= 16\'h1f01;
+\t end
+\t if (cyc==3) begin
+\t if (bitout !== 8\'h41) $stop;
+\t if (sub0.bitout !== 1\'b1) $stop;
+\t if (sub1.bitout !== 1\'b0) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+
+`ifdef USE_INLINE
+ `define INLINE_MODULE /*verilator inline_module*/
+`else
+ `define INLINE_MODULE /*verilator public_module*/
+`endif
+
+module sub (input [7:0] allbits, input [1:0] onebit, output bitout);
+ `INLINE_MODULE
+ parameter integer P = 0;
+ initial if (P != 1) $stop;
+ wire bitout = (^ onebit) ^ (^ allbits);
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ bl, cl, bc, cc,
+ // Inputs
+ a
+ );
+
+ input logic a;
+ output logic bl;
+ output logic cl;
+ always_latch begin
+ bl <= a; // No warning
+ cl = a;
+ end
+
+ output logic bc;
+ output logic\tcc;
+ always_comb begin
+ bc <= a; // Warning
+ cc = a;
+ end
+
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Chandan Egbert.
+
+module sub();
+endmodule
+
+module t(input logic a, input logic b,
+\t output logic x, output logic y);
+
+ always_comb begin
+ integer i;
+ x = a;
+ end
+
+ sub u0();
+
+ always_comb begin
+ integer j;
+ y = b;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+package TEST_TYPES;
+ typedef struct packed {
+ logic \t stuff;
+ } a_struct_t;
+endpackage // TEST_TYPES
+
+module t(clk);
+ input clk;
+ TEST_TYPES::a_struct_t [3:0] a_out;
+ sub sub (.a_out);
+ always @ (posedge clk) begin
+ if (a_out[0] != 1\'b0) $stop;
+ if (a_out[1] != 1\'b1) $stop;
+ if (a_out[2] != 1\'b0) $stop;
+ if (a_out[3] != 1\'b1) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+
+module sub(a_out);
+ parameter n = 4;
+ output TEST_TYPES::a_struct_t [n-1:0] a_out;
+ always_comb begin
+ for (int i=0;iJo_![Cl)
+ #nj1]p,3^1~,=""E@QZB\\T)eU\\pC#C|7=\\$J$##A[@-@{Qk]
+`endprotected
+endmodule
+//""
+
+//======================================================================
+// macro call with define that has comma
+`define REG_H 6
+`define REG_L 7
+`define _H regs[`REG_H]
+`define _L regs[`REG_L]
+`define _HL {`_H, `_L}
+`define EX_WRITE(ad, da) begin addr <= (ad); wdata <= (da); wr <= 1; end
+`define EX_READ(ad) begin addr <= (ad); rd <= 1; end
+
+`EX_READ((`_HL + 1)) and `EX_WRITE((`_HL), rdata)
+`EX_READ(`_HL + 1)
+`EX_WRITE(`_HL, rdata) more
+
+//======================================================================
+// include of parameterized file
+`define INCNAME ""t_preproc_inc4.vh""
+`include `INCNAME
+`ifndef T_PREPROC_INC4
+ `error ""No Inc4""
+`endif
+`undef T_PREPROC_INC4
+
+`ifdef NOT_DEFINED_INC
+ `include NOT_DEFINED_INC
+`endif
+
+//======================================================================
+// macro call with , in {}
+
+`define xxerror(logfile, msg) $blah(logfile,msg)
+`xxerror(""ab,cd"",""e,f"");
+`xxerror(this.logfile, vec);
+`xxerror(this.logfile, vec[1,2,3]);
+`xxerror(this.logfile, {blah.name(), "" is not foo""});
+
+//======================================================================
+// pragma/default net type
+
+`pragma foo = 1
+`default_nettype none
+`default_nettype uwire
+
+//======================================================================
+// Ifdef
+
+`define EMPTY_TRUE
+`ifndef EMPTY_TRUE
+ `error ""Empty is still true""
+`endif
+Line_Preproc_Check `__LINE__
+
+//======================================================================
+// bug84
+
+`define ARGPAR(a, // Hello, comments MIGHT not be legal
+ /*more,,)cmts*/ b // But newlines ARE legal... who speced THAT?
+ ) (a,b)
+`ARGPAR(p,q)
+`ARGPAR( //Here
+\t x,
+ y //Too
+ )
+Line_Preproc_Check `__LINE__
+
+//======================================================================
+// defines split arguments
+
+`define BEGIN begin
+`define END end
+`define BEGINEND `BEGIN`END
+`define quoteit(x) `""x`""
+`BEGIN`END // 2001 spec doesn\'t require two tokens, so ""beginend"" ok
+`BEGINEND // 2001 spec doesn\'t require two tokens, so ""beginend"" ok
+`quoteit(`BEGIN`END) // No space ""beginend""
+
+//======================================================================
+// bug106
+`define \\esc`def got_escaped
+`ifdef \\esc`def
+ `\\esc`def
+`endif
+Not a \\`define
+
+//======================================================================
+// misparsed comma in submacro
+`define sb bee
+`define appease_emacs_paren_matcher (
+`define sa(l) x,y)
+`define sfoo(q,r) q--r
+`sfoo(`sa(el),`sb) submacro has comma paren
+
+//======================================================================
+// bug191
+`define bug191(bits) $display(""bits %d %d"", $bits(foo), bits);
+`bug191(10)
+
+//======================================================================
+// 1800-2009
+`define UDALL
+`ifndef PREDEF_COMMAND_LINE `error ""Test setup error, PREDEF_COMMAND_LINE pre-missing"" `endif
+`undefineall
+`ifdef UDALL `error ""undefineall failed"" `endif
+`ifndef PREDEF_COMMAND_LINE `error ""Deleted too much, no PREDEF_COMMAND_LINE"" `endif
+
+//======================================================================
+// bug202
+`define FC_INV3(out, in)\t\t\t\t\t\\
+ `ifdef DC\t\t\t\t\t\t\t\\
+ cell \\inv_``out <$typeof(out)> (.a(), .o());\t\\
+ /* multi-line comment\t\t\t\t\t\\
+\t multi-line comment */\t\t\t\t\t\\
+ `else\t\t\t\t\t\t\t\t\\
+ `ifdef MACRO_ATTRIBUTE\t\t\t\t\t\\
+ (* macro_attribute = `""INV (out``,in``)`"" *)\t\t\\
+ `endif\t\t\t\t\t\t\t\\
+ assign out = ~in ;\t\t\t\t\t\t\\
+ `endif
+
+`FC_INV3(a3,b3)
+
+`define /* multi\t\\
+\t line1*/\t\\
+ bug202( i /*multi\t\\
+\t line2*/\t\\
+ )\t\t\t\\
+ /* multi\t\t\\
+ line 3*/\t\t\\
+ def i\t\t\\
+
+`bug202(foo)
+
+//======================================================================
+
+`define CMT1 // verilator NOT IN DEFINE
+`define CMT2 /* verilator PART OF DEFINE */
+`define CMT3 /* verilator NOT PART
+\t OF DEFINE */
+`define CMT4 /* verilator PART \\
+\t OF DEFINE */
+`define CMT5 // CMT NOT \\
+ also in // BUT TEXT IS \\
+ also3 // CMT NOT
+
+1 `CMT1 (nodef)
+2 `CMT2 (hasdef)
+3 `CMT3 (nodef)
+4 `CMT4 (nodef)
+5 `CMT5 (nodef)
+`define NL HAS a NEW \\
+LINE
+`NL
+
+//======================================================================
+
+`define msg_fatal(log, msg) \\
+ do \\
+ /* synopsys translate_off */ \\
+`ifdef NEVER \\
+ `error ""WTF"" \\
+`else \\
+ if (start(`__FILE__, `__LINE__)) begin \\
+`endif \\
+\t message(msg); \\
+ end \\
+ /* synopsys translate_on */ \\
+ while(0)
+
+`define msg_scen_(cl) cl``_scen
+`define MSG_MACRO_TO_STRING(x) `""x`""
+
+EXP: clxx_scen
+`msg_scen_(clxx)
+EXP: clxx_scen
+`MSG_MACRO_TO_STRING(`msg_scen_(clxx))
+`define mf(clx) `msg_fatal(this.log, {""Blah-"", `MSG_MACRO_TO_STRING(`msg_scen_(clx)), "" end""});
+EXP: do if (start(""verilog/inc1.v"", 25)) begin message({""Blah-"", ""clx_scen"", "" end""}); end while(0);
+`mf(clx)
+
+//======================================================================
+
+`define makedefine(name) \\
+ `define def_``name This is name \\
+ `define def_``name``_2 This is name``_2 \\
+
+`makedefine(fooed)
+`ifndef def_fooed `error ""No def_fooed"" `endif
+//`ifndef def_fooed_2 `error ""No def_fooed_2"" `endif
+EXP: This is fooed
+`def_fooed
+EXP: This is fooed_2
+`def_fooed_2
+
+//======================================================================
+`define NOPARAM() np
+`NOPARAM()
+`NOPARAM( )
+//======================================================================
+// It\'s unclear if the spec allows this; is text_macro_idenitfier before or after substitution?
+`define NODS_DEFINED
+`define NODS_INDIRECT(x) x
+`ifndef `NODS_INDIRECT(NODS_DEFINED)
+ `error ""Indirect failed""
+`endif
+`ifdef `NODS_INDIRECT(NODS_UNDEFINED)
+ `error ""Indirect2 failed""
+`endif
+//======================================================================
+// Metaprogramming
+`define REPEAT_0(d)
+`define REPEAT_1(d) d
+`define REPEAT_2(d) `REPEAT_1(d)d
+`define REPEAT_3(d) `REPEAT_2(d)d
+`define REPEAT_4(d) `REPEAT_3(d)d
+
+`define CONCAT(a, b) a``b
+`define REPEATC(n, d) `CONCAT(`REPEAT_, n)(d)
+`define REPEATT(n, d) `REPEAT_``n(d)
+
+`REPEATC(3, hello3 )
+`REPEATT(4, hello4 )
+//======================================================================
+// Include from stringification
+`undef T_PREPROC_INC4
+`define NODS_CONC_VH(m) `""m.vh`""
+`include `NODS_CONC_VH(t_preproc_inc4)
+`ifndef T_PREPROC_INC4 `error_here `endif
+//======================================================================
+// Defines doing defines
+// Note the newline on the end - required to form the end of a define
+`define DEFINEIT(d) d \\
+
+`define _DEFIF_Z_0 1
+`define DEFIF_NZ(d,n) `undef d `ifndef _DEFIF_Z_``n `DEFINEIT(`define d 1) `endif
+`DEFIF_NZ(TEMP,1)
+`ifndef TEMP `error ""bad"" `endif
+`DEFIF_NZ(TEMP,0)
+`ifdef TEMP `error ""bad0"" `endif
+Line_Preproc_Check `__LINE__
+//======================================================================
+// Quoted multiline - track line numbers, and insure \\\
+ gets propagated
+`define MULQUOTE ""FOO \\
+ BAR ""
+`define MULQUOTE2(mq) `MULQUOTE mq `MULQUOTE
+Line_Preproc_Check `__LINE__
+`MULQUOTE2(""arg_line1 \\
+ arg_line2"")
+Line_Preproc_Check `__LINE__
+//======================================================================
+// bug283
+
+`define A a
+`define B b
+`define C c
+// EXP: abc
+`define C5 `A``b```C
+`C5
+`undef A
+`undef B
+`undef C
+
+`define XTYPE sonet
+`define XJOIN(__arg1, __arg2) __arg1``__arg2
+`define XACTION `XJOIN(`XTYPE, _frame)
+EXP: sonet_frame
+`XACTION
+//
+`define XFRAME frame
+`define XACTION2 `XJOIN(sonet_, `XFRAME)
+EXP: sonet_frame
+`XACTION2
+// This result varies between simulators
+`define sonet_frame other_frame
+`define XACTION3 `XTYPE``_frame
+EXP: sonet_frame
+`XACTION3
+
+// The existance of non-existance of a base define can make a difference
+`define QA_b zzz
+`define Q1 `QA``_b
+EXP: module zzz ; endmodule
+module `Q1 ; endmodule
+module `Q1 ; endmodule
+
+`define QA a
+EXP: module a_b ; endmodule
+module `Q1 ; endmodule
+module `Q1 ; endmodule
+
+//======================================================================
+// bug311
+integer/*NEED_SPACE*/foo;
+//======================================================================
+// bug441
+module t;
+ //-----
+ // case provided
+ // note this does NOT escape as suggested in the mail
+`define LEX_CAT(lexem1, lexem2) lexem1``lexem2
+`define LEX_ESC(name) \
+ame \\
+
+ initial begin : `LEX_ESC( `LEX_CAT(a[0],_assignment) ) $write(""GOT%%m=\'%m\' EXP=\'%s\'\
+"", ""t.\\\\`LEX_CAT(a[0],_assignment) ""); end
+ //-----
+ // SHOULD(simulator-dependant): Backslash doesn\'t prevent arguments from
+ // substituting and the \\ staying in the expansion
+ // Note space after name is important so when substitute it has ending whitespace
+`define ESC_CAT(name,name2) \
+ame``_assignment_``name2 \\
+
+ initial begin : `ESC_CAT( a[0],a[1] ) $write(""GOT%%m=\'%m\' EXP=\'%s\'\
+"", ""t.\\\\a[0]_assignment_a[1] ""); end
+`undef ESC_CAT
+ //-----
+`define CAT(a,b) a``b
+`define ESC(name) \\`CAT(name,suffix)
+ // RULE: Ignoring backslash does NOT allow an additional expansion level
+ // (Because ESC gets expanded then the \\ has it\'s normal escape meaning)
+ initial begin : `ESC(pp) $write(""GOT%%m=\'%m\' EXP=\'%s\'\
+"", ""t.\\\\`CAT(pp,suffix) ""); end
+`undef CAT `undef ESC
+ //-----
+`define CAT(a,b) a``b
+`define ESC(name) \
+ame \\
+
+ // Similar to above; \\ does not allow expansion after substitution
+ initial begin : `ESC( `CAT(ff,bb) ) $write(""GOT%%m=\'%m\' EXP=\'%s\'\
+"", ""t.\\\\`CAT(ff,bb) ""); end
+`undef CAT `undef ESC
+ //-----
+`define ESC(name) \
+ame \\
+
+ // MUST: Unknown macro with backslash escape stays as escaped symbol name
+ initial begin : `ESC( `zzz ) $write(""GOT%%m=\'%m\' EXP=\'%s\'\
+"", ""t.\\\\`zzz ""); end
+`undef ESC
+ //-----
+`define FOO bar
+`define ESC(name) \
+ame \\
+
+ // SHOULD(simulator-dependant): Known macro with backslash escape expands
+ initial begin : `ESC( `FOO ) $write(""GOT%%m=\'%m\' OTHER_EXP=\'%s\'\
+ OUR_EXP=\'%s\'"", ""t.bar "",""t.\\\\`FOO ""); end
+ // SHOULD(simulator-dependant): Prefix breaks the above
+ initial begin : `ESC( xx`FOO ) $write(""GOT%%m=\'%m\' EXP=\'%s\'\
+"", ""t.\\\\xx`FOO ""); end
+`undef FOO `undef ESC
+ //-----
+ // MUST: Unknown macro not under call with backslash escape doesn\'t expand
+`undef UNKNOWN
+ initial begin : \\`UNKNOWN $write(""GOT%%m=\'%m\' EXP=\'%s\'\
+"", ""t.\\\\`UNKNOWN ""); end
+ //-----
+ // MUST: Unknown macro not under call doesn\'t expand
+`define DEF_NO_EXPAND error_dont_expand
+ initial begin : \\`DEF_NO_EXPAND $write(""GOT%%m=\'%m\' EXP=\'%s\'\
+"", ""t.\\\\`DEF_NO_EXPAND ""); end
+`undef DEF_NO_EXPAND
+ //-----
+ // bug441 derivative
+ // SHOULD(simulator-dependant): Quotes doesn\'t prevent arguments from expanding (like backslashes above)
+`define STR(name) ""foo name baz""
+ initial $write(""GOT=\'%s\' EXP=\'%s\'\
+"", `STR(bar), ""foo bar baz"");
+`undef STR
+ //-----
+ // RULE: Because there are quotes after substituting STR, the `A does NOT expand
+`define STR(name) ""foo name baz""
+`define A(name) boo name hiss
+ initial $write(""GOT=\'%s\' EXP=\'%s\'\
+"", `STR(`A(bar)), ""foo `A(bar) baz"");
+`undef A `undef STR
+ //----
+ // bug845
+`define SLASHED ""1//2.3""
+ initial $write(""Slashed=`%s\'\
+"", `SLASHED);
+ //----
+ // bug915
+`define BUG915(a,b,c) \\
+ $display(""%s%s"",a,`""b``c``\
+`"")
+ initial `BUG915(""a1"",b2,c3);
+endmodule
+//======================================================================
+// IEEE mandated predefines
+`undefineall // undefineall should have no effect on these
+predef `SV_COV_START 0
+predef `SV_COV_STOP 1
+predef `SV_COV_RESET 2
+predef `SV_COV_CHECK 3
+predef `SV_COV_MODULE 10
+predef `SV_COV_HIER 11
+predef `SV_COV_ASSERTION 20
+predef `SV_COV_FSM_STATE 21
+predef `SV_COV_STATEMENT 22
+predef `SV_COV_TOGGLE 23
+predef `SV_COV_OVERFLOW -2
+predef `SV_COV_ERROR -1
+predef `SV_COV_NOCOV 0
+predef `SV_COV_OK 1
+predef `SV_COV_PARTIAL 2
+//======================================================================
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+
+ parameter CNT = 10;
+
+ wire [31:0] \tw [CNT:0];
+
+ generate
+ for (genvar g=0; g10 && cyc<90) begin
+\t sum <= {sum[30:0],sum[31]} ^ {out1, out0};
+ end
+ else if (cyc==99) begin
+\t if (sum !== 32\'he8bbd130) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module fifo (/*AUTOARG*/
+ // Outputs
+ out0, out1,
+ // Inputs
+ clk, wr0a, wr0b, wr1a, wr1b, inData
+ );
+
+ input clk;
+ input \t wr0a;
+ input \t wr0b;
+ input \t wr1a;
+ input \t wr1b;
+ input [15:0] inData;
+
+ output [15:0] out0;
+ output [15:0] out1;
+
+ reg [15:0] \t mem [1:0];
+ reg [15:0] \t memtemp2 [1:0];
+ reg [15:0] \t memtemp3 [1:0];
+
+ assign \t out0 = {mem[0] ^ memtemp2[0]};
+ assign \t out1 = {mem[1] ^ memtemp3[1]};
+
+ always @(posedge clk) begin
+ // These mem assignments must be done in order after processing
+ if (wr0a) begin
+\t memtemp2[0] <= inData;
+\t mem[0] <= inData;
+ end
+ if (wr0b) begin
+\t memtemp3[0] <= inData;
+\t mem[0] <= ~inData;
+ end
+ if (wr1a) begin
+\t memtemp3[1] <= inData;
+\t mem[1] <= inData;
+ end
+ if (wr1b) begin
+\t memtemp2[1] <= inData;
+\t mem[1] <= ~inData;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t_order_a (/*AUTOARG*/
+ // Outputs
+ m_from_clk_lev1_r, n_from_clk_lev2, o_from_com_levs11, o_from_comandclk_levs12,
+ // Inputs
+ clk, a_to_clk_levm3, b_to_clk_levm1, c_com_levs10, d_to_clk_levm2, one
+ );
+
+ input clk;
+ input [7:0] a_to_clk_levm3;
+ input [7:0] b_to_clk_levm1;
+ input [7:0] c_com_levs10;
+ input [7:0] d_to_clk_levm2;
+ input [7:0] one;
+ output [7:0] m_from_clk_lev1_r;
+ output [7:0] n_from_clk_lev2;
+ output [7:0] o_from_com_levs11;
+ output [7:0] o_from_comandclk_levs12;
+
+ /*AUTOREG*/
+ // Beginning of automatic regs (for this module's undeclared outputs)
+ reg [7:0]\t\tm_from_clk_lev1_r;
+ // End of automatics
+
+ // surefire lint_off ASWEBB
+ // surefire lint_off ASWEMB
+
+ wire [7:0] a_to_clk_levm1;
+ wire [7:0] a_to_clk_levm2;
+ wire [7:0] c_com_levs11;
+ reg [7:0] o_from_comandclk_levs12;
+ wire [7:0] n_from_clk_lev2;
+ wire [7:0] n_from_clk_lev3;
+
+ assign a_to_clk_levm1 = a_to_clk_levm2 + d_to_clk_levm2;
+ assign a_to_clk_levm2 = a_to_clk_levm3 + 0;
+
+ always @ (posedge clk) begin
+ m_from_clk_lev1_r <= a_to_clk_levm1 + b_to_clk_levm1;
+ end
+
+ assign c_com_levs11 = c_com_levs10 + one;
+ always @ (/*AS*/c_com_levs11 or n_from_clk_lev3) o_from_comandclk_levs12 = c_com_levs11 + n_from_clk_lev3;
+ assign n_from_clk_lev2 = m_from_clk_lev1_r;
+ assign n_from_clk_lev3 = n_from_clk_lev2;
+ wire [7:0] o_from_com_levs11 = c_com_levs10 + 1;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+typedef struct packed {
+ logic [1:0] b1;
+ logic [1:0] b2;
+ logic [1:0] b3;
+ logic [1:0] b4;
+} t__aa_bbbbbbb_ccccc_dddddd_eee;
+
+typedef struct packed {
+ logic [31:0] a;
+ union packed {
+ logic [7:0] fbyte;
+ t__aa_bbbbbbb_ccccc_dddddd_eee pairs;
+ } b1;
+ logic [23:0] b2;
+ logic [7:0] c1;
+ logic [23:0] c2;
+ logic [31:0] d;
+} t__aa_bbbbbbb_ccccc_dddddd;
+
+typedef struct packed {
+ logic [31:0] a;
+ logic [31:0] b;
+ logic [31:0] c;
+\tlogic [31:0] d;
+} t__aa_bbbbbbb_ccccc_eee;
+
+typedef union packed {
+ t__aa_bbbbbbb_ccccc_dddddd dddddd;
+ t__aa_bbbbbbb_ccccc_eee eee;
+} t__aa_bbbbbbb_ccccc;
+
+
+module t (
+ input t__aa_bbbbbbb_ccccc xxxxxxx_yyyyy_zzzz,
+ output logic [15:0] datao_pre
+);
+ always_comb datao_pre = { xxxxxxx_yyyyy_zzzz.dddddd.b1.fbyte, xxxxxxx_yyyyy_zzzz.dddddd.c1 };
+
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+typedef reg [2:0] threeansi_t;
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ typedef reg [2:0] three_t;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [2:0] in = crc[2:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ threeansi_t\t\touta;\t\t\t// From testa of TestAnsi.v
+ three_t\t\toutna;\t\t\t// From test of TestNonAnsi.v
+ // End of automatics
+
+ TestNonAnsi test (// Outputs
+\t\t .out\t\t(outna),
+\t\t /*AUTOINST*/
+\t\t // Inputs
+\t\t .clk\t\t(clk),
+\t\t .in\t\t(in));
+
+ TestAnsi testa (// Outputs
+\t\t .out\t\t\t(outa),
+\t\t /*AUTOINST*/
+\t\t // Inputs
+\t\t .clk\t\t\t(clk),
+\t\t .in\t\t\t(in));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {57\'h0, outna, 1\'b0, outa};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h018decfea0a8828a
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module TestNonAnsi (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ clk, in
+ );
+ typedef reg [2:0] three_t;
+
+ input clk;
+ input three_t in;
+ output three_t out;
+
+ always @(posedge clk) begin
+ out <= ~in;
+ end
+endmodule
+
+module TestAnsi (
+\t input clk,
+\t input threeansi_t in,
+\t output threeansi_t out
+\t );
+ always @(posedge clk) begin
+ out <= ~in;
+ end
+endmodule
+
+// Local Variables:
+// verilog-typedef-regexp: ""_t$""
+// End:
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Jonathon Donaldson.
+
+module t_bitsel_enum
+ (
+ output out0,
+ output out1
+ );
+
+ localparam [6:0] CNST_VAL = 7\'h22;
+
+ enum logic [6:0] {
+\t\t ENUM_VAL = 7\'h33
+\t\t } MyEnum;
+
+ assign out0 = CNST_VAL[0];
+ // Not supported by NC-verilog nor VCS, but other simulators do
+ assign out1 = ENUM_VAL[0]; // named values of an enumeration should act like constants so this should work just like the line above works
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg [63:0] d;
+ reg [31:0] c;
+
+ wire [31:0] q = crc (d, c);
+ reg [31:0] q_r;
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t q_r <= q;
+\t c <= q;
+ d <= {d[62:0], ^d[63:48]};
+\t //$write(""%d crc(%x,%x)=%x\
+"", cyc, d, c, q);
+\t if (cyc==1) begin
+\t // Assign inputs randomly
+\t q_r <= 32\'h12345678;
+\t c <= 32\'h12345678;
+\t d <= 64\'hffffffff_ffffffff;
+\t end
+\t if (cyc==2) begin
+\t d <= 64\'hffffffff_ffffffff;
+\t end
+\t if (cyc==3) begin
+\t d <= 64\'hffffffff_ffffffff;
+\t end
+\t if (cyc==4) begin
+\t d <= 64\'h50183721_81a04b1a;
+\t end
+\t if (cyc==5) begin
+\t end
+\t if (cyc==9) begin
+\t if (q !== 32\'h38295e96) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+ function [31:0] crc;
+ input [63:0] di;
+ input [31:0] ci;
+ reg [63:0] drev;
+ begin
+\t drev = reverse(di);
+\t crc = newcrc(drev, ci);
+ end
+ endfunction
+
+ function [63:0] reverse;
+ input [63:0] di;
+ integer \t i;
+ begin
+ reverse = 64\'b0;
+ for (i=0; i<64; i=i+1) reverse[i] = di[63-i];
+ end
+ endfunction
+
+ function [31:0] newcrc;
+ input [63:0] D;
+ input [31:0] C;
+ reg [31:0] N;
+ reg [31:0] DT;
+ begin
+\t N = 32\'b0;
+\t // Note this isn\'t a real CRC code; it\'s been munged for privacy
+ N[0] = D[59]^D[53]^D[52]^D[49]^D[44]^D[41]^D[40]^D[39]^D[37]^D[32]^D[29]^D[26]^D[22]^D[21]^D[20]^D[16]^D[15]^D[14]^D[9]^D[7]^D[0]
+ ^C[29]^C[27]^C[24]^C[23]^C[22]^C[21]^C[19]^C[15]^C[13]^C[10]^C[8]^C[3]^C[1];
+ N[1] = D[61]^D[57]^D[51]^D[47]^D[43]^D[37]^D[35]^D[32]^D[28]^D[24]^D[22]^D[21]^D[20]^D[16]^D[12]^D[11]^D[10]^D[8]^D[7]^D[6]^D[1]^D[0]
+ ^C[30]^C[27]^C[26]^C[20]^C[16]^C[14]^C[13]^C[11]^C[10]^C[8]^C[5]^C[0];
+ N[2] = D[63]^D[62]^D[61]^D[60]^D[55]^D[54]^D[52]^D[44]^D[43]^D[42]^D[37]^D[34]^D[33]^D[29]^D[28]^D[25]^D[24]^D[23]^D[22]^D[18]^D[16]^D[15]^D[13]^D[12]^D[11]
+ ^C[31]^C[30]^C[27]^C[22]^C[21]^C[18]^C[15]^C[12]^C[11]^C[10]^C[7];
+ N[3] = D[62]^D[54]^D[50]^D[47]^D[46]^D[38]^D[36]^D[35]^D[34]^D[33]^D[32]^D[30]^D[27]^D[25]^D[21]^D[20]^D[19]^D[17]^D[15]^D[11]^D[8]^D[5]^D[3]^D[1]^D[0]
+ ^C[28]^C[25]^C[24]^C[13]^C[11]^C[9]^C[8]^C[7]^C[3]^C[1];
+ N[4] = D[57]^D[54]^D[53]^D[52]^D[45]^D[44]^D[43]^D[39]^D[37]^D[34]^D[33]^D[32]^D[31]^D[28]^D[24]^D[23]^D[20]^D[19]^D[15]^D[14]^D[10]^D[6]^D[1]^D[0]
+ ^C[30]^C[24]^C[20]^C[16]^C[14]^C[11]^C[8]^C[7]^C[6]^C[5]^C[2];
+ N[5] = D[58]^D[57]^D[50]^D[49]^D[48]^D[47]^D[43]^D[39]^D[29]^D[26]^D[23]^D[22]^D[20]^D[18]^D[14]^D[10]^D[9]^D[6]^D[5]^D[4]^D[1]
+ ^C[27]^C[24]^C[20]^C[19]^C[18]^C[14]^C[13]^C[12]^C[11]^C[8]^C[7]^C[1];
+ N[6] = D[63]^D[62]^D[61]^D[57]^D[51]^D[50]^D[47]^D[38]^D[37]^D[34]^D[30]^D[28]^D[27]^D[25]^D[21]^D[16]^D[15]^D[10]^D[9]^D[6]^D[5]^D[2]^D[1]
+ ^C[31]^C[27]^C[25]^C[16]^C[13]^C[9]^C[8]^C[7]^C[0];
+ N[7] = ^D[62]^D[61]^D[59]^D[54]^D[52]^D[51]^D[49]^D[46]^D[45]^D[42]^D[41]^D[38]^D[35]^D[29]^D[26]^D[24]^D[15]^D[12]^D[11]^D[9]^D[2]^D[0]
+ ^C[28]^C[27]^C[26]^C[20]^C[19]^C[18]^C[15]^C[12]^C[7]^C[4];
+ N[8] = D[62]^D[61]^D[60]^D[59]^D[52]^D[50]^D[48]^D[47]^D[46]^D[45]^D[44]^D[42]^D[41]^D[40]^D[30]^D[24]^D[23]^D[22]^D[19]^D[17]^D[11]^D[10]^D[7]^D[6]^D[2]
+ ^C[31]^C[29]^C[27]^C[22]^C[21]^C[19]^C[17]^C[11]^C[9]^C[7]^C[6];
+ N[9] = D[62]^D[59]^D[58]^D[57]^D[54]^D[51]^D[50]^D[43]^D[41]^D[39]^D[28]^D[25]^D[24]^D[23]^D[22]^D[21]^D[18]^D[16]^D[15]^D[7]
+ ^C[30]^C[29]^C[27]^C[25]^C[23]^C[22]^C[13]^C[12]^C[7]^C[6]^C[5]^C[1];
+ N[10] = D[61]^D[60]^D[58]^D[56]^D[54]^D[53]^D[51]^D[48]^D[46]^D[43]^D[42]^D[38]^D[37]^D[35]^D[33]^D[31]^D[30]^D[27]^D[26]^D[24]^D[19]^D[10]^D[8]^D[6]^D[1]
+ ^C[31]^C[30]^C[26]^C[25]^C[24]^C[21]^C[16]^C[12]^C[3]^C[2];
+ N[11] = D[59]^D[57]^D[56]^D[50]^D[49]^D[48]^D[47]^D[46]^D[45]^D[42]^D[41]^D[40]^D[33]^D[32]^D[30]^D[25]^D[21]^D[15]^D[14]^D[13]^D[12]^D[11]^D[5]^D[1]
+ ^C[27]^C[25]^C[24]^C[21]^C[16]^C[12]^C[7]^C[3]^C[2]^C[1];
+ N[12] = D[62]^D[61]^D[59]^D[58]^D[56]^D[55]^D[53]^D[48]^D[47]^D[44]^D[43]^D[35]^D[31]^D[30]^D[28]^D[24]^D[23]^D[21]^D[14]^D[5]^D[2]
+ ^C[28]^C[26]^C[25]^C[23]^C[22]^C[18]^C[16]^C[15]^C[6];
+ N[13] = D[63]^D[60]^D[58]^D[57]^D[55]^D[54]^D[53]^D[51]^D[47]^D[45]^D[42]^D[41]^D[38]^D[28]^D[26]^D[25]^D[22]^D[20]^D[18]^D[17]^D[15]^D[13]^D[12]^D[11]
+ ^C[29]^C[28]^C[25]^C[22]^C[19]^C[17]^C[16]^C[15]^C[14]^C[12]^C[10]^C[9];
+ N[14] = D[58]^D[56]^D[55]^D[52]^D[47]^D[43]^D[41]^D[40]^D[39]^D[38]^D[30]^D[26]^D[25]^D[22]^D[19]^D[17]^D[13]^D[11]^D[10]^D[9]^D[8]^D[3]^D[2]^D[0]
+ ^C[31]^C[28]^C[20]^C[18]^C[17]^C[16]^C[15]^C[13]^C[11]^C[4]^C[2]^C[1];
+ N[15] = D[63]^D[62]^D[61]^D[59]^D[58]^D[48]^D[47]^D[43]^D[42]^D[35]^D[28]^D[26]^D[25]^D[24]^D[23]^D[22]^D[21]^D[20]^D[19]^D[17]^D[11]^D[7]^D[2]
+ ^C[30]^C[29]^C[27]^C[24]^C[20]^C[17]^C[16]^C[15]^C[11]^C[9]^C[5];
+ N[16] = D[60]^D[57]^D[49]^D[46]^D[45]^D[43]^D[39]^D[36]^D[32]^D[30]^D[29]^D[28]^D[27]^D[26]^D[23]^D[20]^D[19]^D[17]^D[11]^D[8]^D[5]^D[1]
+ ^C[28]^C[26]^C[23]^C[22]^C[18]^C[16]^C[13]^C[12]^C[10]^C[9]^C[6];
+ N[17] = D[63]^D[62]^D[61]^D[60]^D[58]^D[54]^D[53]^D[51]^D[48]^D[42]^D[41]^D[37]^D[36]^D[34]^D[28]^D[27]^D[26]^D[24]^D[13]^D[12]^D[9]^D[7]^D[4]^D[0]
+ ^C[31]^C[30]^C[27]^C[23]^C[20]^C[17]^C[14]^C[9]^C[6]^C[4]^C[3]^C[0];
+ N[18] = D[63]^D[61]^D[59]^D[56]^D[52]^D[50]^D[47]^D[42]^D[37]^D[35]^D[34]^D[31]^D[30]^D[29]^D[22]^D[19]^D[17]^D[16]^D[11]^D[9]^D[8]^D[7]
+ ^C[26]^C[22]^C[20]^C[19]^C[16]^C[11]^C[8]^C[6]^C[5]^C[0];
+ N[19] = D[62]^D[60]^D[52]^D[49]^D[44]^D[43]^D[42]^D[37]^D[33]^D[32]^D[29]^D[26]^D[19]^D[17]^D[16]^D[12]^D[10]^D[7]^D[6]^D[4]^D[3]^D[2]
+ ^C[30]^C[29]^C[26]^C[25]^C[22]^C[19]^C[14]^C[7]^C[6]^C[5]^C[2]^C[0];
+ N[20] = D[63]^D[58]^D[54]^D[48]^D[47]^D[40]^D[39]^D[35]^D[34]^D[32]^D[31]^D[28]^D[27]^D[25]^D[18]^D[12]^D[9]^D[7]^D[5]^D[4]^D[3]^D[2]^D[1]
+ ^C[31]^C[29]^C[28]^C[25]^C[19]^C[18]^C[17]^C[15]^C[10]^C[9]^C[6]^C[4];
+ N[21] = D[61]^D[59]^D[57]^D[56]^D[53]^D[48]^D[44]^D[43]^D[41]^D[35]^D[29]^D[26]^D[25]^D[20]^D[18]^D[17]^D[16]^D[12]^D[9]^D[6]^D[5]^D[3]^D[1]
+ ^C[30]^C[27]^C[24]^C[23]^C[22]^C[21]^C[20]^C[13]^C[9]^C[3]^C[2];
+ N[22] = D[63]^D[62]^D[60]^D[57]^D[53]^D[51]^D[45]^D[44]^D[42]^D[34]^D[33]^D[27]^D[20]^D[19]^D[18]^D[15]^D[10]^D[9]^D[8]^D[4]^D[3]
+ ^C[24]^C[23]^C[18]^C[17]^C[16]^C[14]^C[12]^C[11]^C[10]^C[9]^C[6]^C[5];
+ N[23] = D[58]^D[56]^D[54]^D[51]^D[47]^D[43]^D[42]^D[40]^D[37]^D[36]^D[33]^D[25]^D[23]^D[20]^D[18]^D[16]^D[15]^D[12]^D[10]^D[8]^D[7]^D[5]^D[3]
+ ^C[31]^C[27]^C[26]^C[23]^C[21]^C[18]^C[15]^C[11]^C[10]^C[8]^C[7]^C[1];
+ N[24] = D[60]^D[59]^D[52]^D[50]^D[48]^D[44]^D[39]^D[36]^D[35]^D[31]^D[30]^D[28]^D[27]^D[23]^D[22]^D[21]^D[19]^D[14]^D[13]^D[12]^D[9]^D[4]^D[1]^D[0]
+ ^C[27]^C[25]^C[23]^C[21]^C[17]^C[11]^C[10]^C[4]^C[0];
+ N[25] = D[61]^D[60]^D[56]^D[54]^D[51]^D[46]^D[43]^D[41]^D[40]^D[38]^D[37]^D[36]^D[29]^D[28]^D[27]^D[22]^D[17]^D[15]^D[10]^D[7]^D[4]^D[2]
+ ^C[29]^C[28]^C[26]^C[23]^C[18]^C[14]^C[13]^C[12]^C[11]^C[9]^C[8]^C[6];
+ N[26] = D[63]^D[62]^D[58]^D[55]^D[54]^D[52]^D[50]^D[39]^D[37]^D[36]^D[35]^D[33]^D[31]^D[29]^D[27]^D[18]^D[14]^D[10]^D[3]^D[2]^D[0]
+ ^C[31]^C[27]^C[26]^C[25]^C[24]^C[21]^C[13]^C[12]^C[10]^C[1];
+ N[27] = D[62]^D[60]^D[58]^D[56]^D[55]^D[54]^D[51]^D[44]^D[41]^D[36]^D[34]^D[32]^D[31]^D[29]^D[28]^D[27]^D[23]^D[17]^D[12]^D[11]^D[8]^D[6]^D[4]^D[2]
+ ^C[31]^C[30]^C[28]^C[27]^C[23]^C[19]^C[17]^C[16]^C[14]^C[12]^C[11]^C[10]^C[3];
+ N[28] = D[57]^D[54]^D[53]^D[51]^D[50]^D[48]^D[40]^D[38]^D[34]^D[33]^D[31]^D[30]^D[29]^D[27]^D[23]^D[21]^D[14]^D[9]^D[7]^D[6]^D[5]^D[4]^D[0]
+ ^C[31]^C[30]^C[26]^C[24]^C[15]^C[14]^C[13]^C[7]^C[6]^C[4]^C[3]^C[0];
+ N[29] = D[62]^D[60]^D[55]^D[46]^D[45]^D[44]^D[43]^D[41]^D[40]^D[35]^D[33]^D[32]^D[30]^D[28]^D[25]^D[23]^D[22]^D[13]^D[8]^D[7]^D[6]^D[5]^D[4]^D[3]^D[1]^D[0]
+ ^C[31]^C[28]^C[27]^C[18]^C[11]^C[8]^C[6]^C[4]^C[2]^C[1]^C[0];
+ N[30] = D[63]^D[62]^D[59]^D[58]^D[55]^D[52]^D[47]^D[44]^D[36]^D[35]^D[34]^D[31]^D[29]^D[22]^D[21]^D[20]^D[19]^D[15]^D[14]^D[10]^D[6]^D[3]^D[2]^D[0]
+ ^C[28]^C[25]^C[24]^C[22]^C[20]^C[15]^C[14]^C[12]^C[10]^C[9]^C[4]^C[0];
+ N[31] = D[61]^D[58]^D[56]^D[55]^D[54]^D[52]^D[51]^D[50]^D[49]^D[42]^D[38]^D[37]^D[36]^D[34]^D[31]^D[30]^D[27]^D[26]^D[23]^D[22]^D[21]^D[19]^D[18]^D[12]^D[0]
+ ^C[28]^C[26]^C[24]^C[21]^C[17]^C[16]^C[14]^C[13]^C[10]^C[8]^C[2];
+\t newcrc = N;
+ end
+ endfunction
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg b;
+
+ wire vconst1 = 1\'b0;
+ wire vconst2 = !(vconst1);
+ wire vconst3 = !vconst2;
+ wire vconst = vconst3;
+
+ wire qa;
+ wire qb;
+ wire qc;
+ wire qd;
+ wire qe;
+ ta ta (.b(b), .vconst(vconst), .q(qa));
+ tb tb (.clk(clk), .vconst(vconst), .q(qb));
+ tc tc (.b(b), .vconst(vconst), .q(qc));
+ td td (.b(b), .vconst(vconst), .q(qd));
+ te te (.clk(clk), .b(b), .vconst(vconst), .q(qe));
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $display(""%b"",{qa,qb,qc,qd,qe});
+`endif
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t b <= 1\'b1;
+\t end
+\t if (cyc==2) begin
+\t if (qa!=1\'b1) $stop;
+\t if (qb!=1\'b0) $stop;
+\t if (qd!=1\'b0) $stop;
+\t b <= 1\'b0;
+\t end
+\t if (cyc==3) begin
+\t if (qa!=1\'b0) $stop;
+\t if (qb!=1\'b0) $stop;
+\t if (qd!=1\'b0) $stop;
+\t if (qe!=1\'b0) $stop;
+\t b <= 1\'b1;
+\t end
+\t if (cyc==4) begin
+\t if (qa!=1\'b1) $stop;
+\t if (qb!=1\'b0) $stop;
+\t if (qd!=1\'b0) $stop;
+\t if (qe!=1\'b1) $stop;
+\t b <= 1\'b0;
+\t end
+\t if (cyc==5) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+
+module ta (
+\t input vconst,
+\t input b,
+\t output reg q);
+
+ always @ (/*AS*/b or vconst) begin
+ q = vconst | b;
+ end
+endmodule
+
+module tb (
+\t input vconst,
+\t input clk,
+\t output reg q);
+
+ always @ (posedge clk) begin
+ q <= vconst;
+ end
+endmodule
+
+module tc (
+\t input vconst,
+\t input b,
+\t output reg q);
+ always @ (posedge vconst) begin
+ q <= b;
+ $stop;
+ end
+endmodule
+
+module td (
+\t input vconst,
+\t input b,
+\t output reg q);
+
+ always @ (/*AS*/vconst) begin
+ q = vconst;
+ end
+endmodule
+
+module te (
+\t input clk,
+\t input vconst,
+\t input b,
+\t output reg q);
+ reg \t\t qmid;
+ always @ (posedge vconst or posedge clk) begin
+ qmid <= b;
+ end
+ always @ (posedge clk or posedge vconst) begin
+ q <= qmid;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ initial begin
+ func(0, 1'b1);
+ end
+
+ function automatic int func
+ (
+ input int a,
+ output bit b );
+ return 0;
+ endfunction
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg [83:4] \t\tfrom;
+ reg [83:4] \t\tto;
+ reg [6:0] \t\tbitn;
+ reg [3:0] \t\tnibblep;
+ reg [3:0] \t\tnibblem;
+
+ reg [7:0] cyc; initial cyc=0;
+
+ always @* begin
+ nibblep = from[bitn +: 4];
+ nibblem = from[bitn -: 4];
+ to = from;
+ to[bitn +: 4] = cyc[3:0];
+ to[bitn -: 4] = cyc[3:0];
+ end
+
+ always @ (posedge clk) begin
+ //$write(""[%0t] cyc==%d nibblep==%b nibblem==%b to^from==%x\
+"",$time, cyc, nibblep, nibblem, from^to);
+ cyc <= cyc + 8\'d1;
+ case (cyc)
+\t8\'d00: begin from<=80\'h7bea9d779b67e48f67da; bitn<=7\'d7; end
+\t8\'d01: begin from<=80\'hefddce326b11ca5dc448; bitn<=7\'d8; end
+\t8\'d02: begin from<=80\'h3f99c5f34168401e210d; bitn<=7\'d4; end // truncate -:
+\t8\'d03: begin from<=80\'hc90635f0a7757614ce3f; bitn<=7\'d79; end
+\t8\'d04: begin from<=80\'hc761feca3820331370ec; bitn<=7\'d83; end // truncate +:
+\t8\'d05: begin from<=80\'hd6e36077bf28244f84b5; bitn<=7\'d6; end // half trunc
+\t8\'d06: begin from<=80\'h90118c5d3d285a1f3252; bitn<=7\'d81; end // half trunc
+\t8\'d07: begin from<=80\'h38305da3d46b5859fe16; bitn<=7\'d67; end
+\t8\'d08: begin from<=80\'h4b9ade23a8f5cc5b3111; bitn<=7\'d127; end // truncate
+\t8\'d09: begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\tend
+\tdefault: ;
+ endcase
+ case (cyc)
+\t8\'d00: ;
+\t8\'d01: begin if ((nibblep & 4\'b1111)!==4\'b1011) $stop; if ((nibblem & 4\'b1111)!==4\'b1010) $stop; end
+\t8\'d02: begin if ((nibblep & 4\'b1111)!==4\'b0100) $stop; if ((nibblem & 4\'b1111)!==4\'b0100) $stop; end
+\t8\'d03: begin if ((nibblep & 4\'b1111)!==4\'b1101) $stop; if ((nibblem & 4\'b0000)!==4\'b0000) $stop; end
+\t8\'d04: begin if ((nibblep & 4\'b1111)!==4\'b1001) $stop; if ((nibblem & 4\'b1111)!==4\'b1001) $stop; end
+\t8\'d05: begin if ((nibblep & 4\'b0000)!==4\'b0000) $stop; if ((nibblem & 4\'b1111)!==4\'b1100) $stop; end
+\t8\'d06: begin if ((nibblep & 4\'b1111)!==4\'b1101) $stop; if ((nibblem & 4\'b0000)!==4\'b0000) $stop; end
+\t8\'d07: begin if ((nibblep & 4\'b0000)!==4\'b0000) $stop; if ((nibblem & 4\'b1111)!==4\'b0100) $stop; end
+\t8\'d08: begin if ((nibblep & 4\'b1111)!==4\'b0000) $stop; if ((nibblem & 4\'b1111)!==4\'b0101) $stop; end
+\t8\'d09: begin if ((nibblep & 4\'b0000)!==4\'b0000) $stop; if ((nibblem & 4\'b0000)!==4\'b0000) $stop; end
+\tdefault: $stop;
+ endcase
+ case (cyc)
+\t8\'d00: ;
+\t8\'d01: begin if ((to^from)!==80\'h0000000000000000005b) $stop; end
+\t8\'d02: begin if ((to^from)!==80\'h0000000000000000006c) $stop; end
+\t8\'d03: begin if ((to^from)!==80\'h0000000000000000000e) $stop; end
+\t8\'d04: begin if ((to^from)!==80\'h6d000000000000000000) $stop; end
+\t8\'d05: begin if (((to^from)&~80\'hf)!==80\'h90000000000000000000) $stop; end // Exceed bounds, verilator may write index 0
+\t8\'d06: begin if (((to^from)&~80\'hf)!==80\'h00000000000000000020) $stop; end // Exceed bounds, verilator may write index 0
+\t8\'d07: begin if (((to^from)&~80\'hf)!==80\'h4c000000000000000000) $stop; end
+\t8\'d08: begin if ((to^from)!==80\'h0004d000000000000000) $stop; end
+\t8\'d09: begin if (((to^from)&~80\'hf)!==80\'h00000000000000000000) $stop; end
+\tdefault: $stop;
+ endcase
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2009 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+module t;
+
+ export ""DPI-C"" task dpix_twice;
+ export ""DPI-C"" dpix_t_int_renamed = task dpix_twice;
+ task dpix_twice(input int i, output int o); o = ~i; endtask
+
+ initial begin
+ $stop;
+ end
+endmodule
+"
+"// DESCRIPTION::Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+module t;
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
+
+ typedef enum logic [1:0]
+\t\t{ ZERO = 2\'d0,
+\t\t ONE = 2\'d1,
+\t\t TWO = 2\'d2,
+\t\t THREE = 2\'d3,
+\t\t XXX = 2\'dx
+\t\t } num_t;
+
+ function automatic logic is_odd;
+ input \ten;
+ input \tnum_t number;
+ case (en)
+\t1\'b1: begin
+\t unique if (number inside {ONE, THREE})
+\t is_odd = 1\'b1;
+\t else if (number inside {ZERO, TWO})
+\t is_odd = 1\'b0;
+\t else
+\t is_odd = 1\'bx;
+\tend
+\t1\'b0: is_odd = 1\'bx;
+\tdefault: is_odd = 1\'bx;
+ endcase
+ endfunction
+
+ initial begin
+ `checkh ((4\'d4 inside {4\'d1,4\'d5}), 1\'b0);
+ `checkh ((4\'d4 inside {4\'d1,4\'d4}), 1\'b1);
+ //
+ `checkh ((4\'b1011 inside {4\'b1001}), 1\'b0);
+ `checkh ((4\'b1011 inside {4\'b1xx1}), 1\'b1); // Uses ==?
+ `checkh ((4\'b1001 inside {4\'b1xx1}), 1\'b1); // Uses ==?
+ `checkh ((4\'b1001 inside {4\'b1??1}), 1\'b1);
+`ifndef VERILATOR
+ `checkh ((4\'b1z11 inside {4\'b11?1, 4\'b1011}),1\'bx);
+`endif
+ // Range
+ `checkh ((4\'d4 inside {[4\'d5:4\'d3], [4\'d10:4\'d8]}), 1\'b0); // If left of colon < never matches
+ `checkh ((4\'d3 inside {[4\'d1:4\'d2], [4\'d3:4\'d5]}), 1\'b1);
+ `checkh ((4\'d4 inside {[4\'d1:4\'d2], [4\'d3:4\'d5]}), 1\'b1);
+ `checkh ((4\'d5 inside {[4\'d1:4\'d2], [4\'d3:4\'d5]}), 1\'b1);
+ //
+ // Unsupported $ bound
+ //
+ // Unsupported if unpacked array, elements tranversed
+ //int unpackedarray [$] = \'{8,9};
+ //( expr inside {2, 3, unpackedarray}) // { 2,3,8,9}
+ //
+ `checkh (is_odd(1\'b1, ZERO), 1\'d0);
+ `checkh (is_odd(1\'b1, ONE), 1\'d1);
+ `checkh (is_odd(1\'b1, TWO), 1\'d0);
+ `checkh (is_odd(1\'b1, THREE),1\'d1);
+`ifndef VERILATOR
+ `checkh (is_odd(1\'b1, XXX), 1\'dx);
+`endif
+ //
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+//===========================================================================
+// Includes
+
+
+example line 10;
+example line 11;
+
+`include ""t_pipe_filter_inc.vh""
+// Twice to check caching of includes
+`include ""t_pipe_filter_inc.vh""
+
+example line 15;
+example line 16;
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// A test case for parameterized module.
+//
+// When a module is instantiatied with parameter, there will be two modules in
+// the tree and eventually one will be removed after param and deadifyModules.
+//
+// This test is to check that the removal of dead module will not cause
+// compilation error. Possible error was/is seen as:
+//
+// pure virtual method called
+// terminate called without an active exception
+// %Error: Verilator aborted. Consider trying --debug --gdbbt
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Jie Xu.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ wire [71:0] ctrl;
+ wire [7:0] cl; // this line is added
+
+ memory #(.words(72)) i_memory (.clk (clk));
+
+ assign ctrl = i_memory.mem[0];
+ assign cl = i_memory.mem[0][7:0]; // and this line
+endmodule
+
+
+// memory module, which is used with parameter
+module memory (clk);
+ input clk;
+
+ parameter words = 16384, bits = 72;
+
+ reg [bits-1 :0] mem[words-1 : 0];
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Varun Koyyalagunta.
+
+typedef struct packed {
+ logic p;
+} s_data;
+
+module m1 (output s_data data[1:0]);
+ assign data[0].p = 0;
+ assign data[1].p = 0;
+endmodule
+
+module top (output s_data data[2:0]);
+ m1 m1_inst (.data(data[1:0]));
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t;
+ reg [2:0] value;
+ reg [31:0] rglobal;
+ reg [31:0] vec [1:0];
+ reg [31:0] n;
+
+ initial begin
+ rglobal = 1;
+ value = 2;
+ if (add(value) != 3\'d3) $stop;
+ if (rglobal != 2) $stop;
+ if (add(add(3\'d1)) != 3\'d3) $stop;
+ if (rglobal != 4) $stop;
+ if (munge4(4\'b0010) != 4\'b1011) $stop;
+ if (toint(2) != 3) $stop;
+ if (rglobal != 5) $stop;
+ setit;
+ incr(rglobal,rglobal,32\'h10);
+ if (rglobal != 32\'h17) $stop;
+ nop(32\'h11);
+ empty;
+ empty();
+
+ rglobal = 32\'h00000001;
+ flipupperbit(rglobal,4\'d4);
+ flipupperbit(rglobal,4\'d12);
+ if (rglobal !== 32\'h10100001) $stop;
+
+ if (nil_func(32\'h12,32\'h12) != 32\'h24) $stop;
+ nil_task(32\'h012,32\'h112,rglobal);
+ if (rglobal !== 32\'h124) $stop;
+
+ vec[0] = 32\'h333;
+ vec[1] = 32\'habc;
+ incr(vec[1],vec[0],vec[1]);
+ if (vec[0] != 32\'h333) $stop;
+ if (vec[1] != 32\'hdef) $stop;
+
+ // verilator lint_off SELRANGE
+ incr(vec[2],vec[0],vec[2]); // Reading/Writing past end of vector!
+ // verilator lint_on SELRANGE
+
+ n=1;
+ nil();
+ if (n !== 10) $stop;
+
+ // Functions called as tasks
+ rglobal = 32\'h4;
+ if (inc_and_return(32\'h2) != 32\'h6) $stop;
+ if (rglobal !== 32\'h6) $stop;
+ rglobal = 32\'h6;
+ inc_and_return(32\'h3);
+ if (rglobal !== 32\'h9) $stop;
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ function [2:0] add;
+ input [2:0] fromv;
+ begin
+\t add = fromv + 3\'d1;
+\t begin : named
+\t reg [31:0] flocal;
+\t flocal = 1;
+\t rglobal = rglobal + flocal;
+\t end : named\t// SystemVerilog end labels
+ end
+ endfunction
+
+ function [3:0] munge4;
+ input [3:0] fromv; // Different fromv than the \'fromv\' signal above
+ reg one;
+ begin : named
+\t reg [1:0] flocal;
+\t // Function calling a function
+\t one = 1\'b1;
+\t munge4 = {one, add(fromv[2:0])};
+ end
+ endfunction
+
+ task setit;
+ reg [31:0] temp;
+ begin
+\t temp = rglobal + 32\'h1;
+\t rglobal = temp + 32\'h1;
+ end
+ endtask
+
+ task incr (
+\t // Check a V2K style input/output list
+ output [31:0] z,
+ input [31:0] a, inc
+\t );
+ z = a + inc;
+ endtask
+
+ task nop;
+ input [31:0] a;
+ begin
+ end
+ endtask
+
+ task empty;
+ endtask
+
+ task flipupperbit;
+ inout [31:0] vector;
+ input [3:0] bitnum;
+ reg [4:0] bitnum2;
+ begin
+\t bitnum2 = {1\'b1, bitnum};\t// A little math to test constant propagation
+\t vector[bitnum2] = vector[bitnum2] ^ 1\'b1;
+ end
+ endtask
+
+ task nil_task;
+ input [31:0] a;
+ input [31:0] b;
+ output [31:0] q;
+ // verilator no_inline_task
+ q = nil_func(a, b);
+ endtask
+
+ function void nil;
+ n = 10;
+ endfunction
+
+ function [31:0] nil_func;
+ input [31:0] fa;
+ input [31:0] fb;
+ // verilator no_inline_task
+ nil_func = fa + fb;
+ endfunction
+
+ function integer toint;
+ input integer fa;
+ toint = fa + 32\'h1;
+ endfunction
+
+ function [31:0] inc_and_return;
+ input [31:0] inc;
+ rglobal = rglobal + inc;
+ return rglobal;
+ endfunction
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t;
+ subok subok (.a(1'b1), .b(1'b0));
+ sub sub (.a(1'b1), .b(1'b0));
+endmodule
+
+module subok (input a,b);
+endmodule
+
+module sub (a);
+ input a, b;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+module t (clk, Rand);
+ input clk;
+ output reg [31:0] Rand;
+
+`ifdef verilator
+ `systemc_interface
+ unsigned int QxRandTbl (unsigned int tbl, unsigned int idx) { return 0xfeed0fad; }
+ `verilog
+`endif
+
+ function [31:0] QxRand32;
+ /* verilator public */
+ input [7:0] tbl;
+ input [7:0] idx;
+ begin
+`ifdef verilator
+\t QxRand32 = $c (""QxRandTbl("",tbl,"","",idx,"")"");
+`else
+\t QxRand32 = 32\'hfeed0fad;
+`endif
+ end
+ endfunction
+
+ always @(posedge clk) begin
+ Rand <= #1 QxRand32 (8\'h0, 8\'h7);
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003-2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ /*verilator public_module*/
+
+ input clk;
+ // No verilator_public needed, because it\'s outside the """" in the $c statement
+ reg [7:0] cyc; initial cyc=0;
+ reg \t c_worked;
+ reg [8:0] c_wider;
+
+ wire one = 1\'b1;
+
+ always @ (posedge clk) begin
+ cyc <= cyc+8\'d1;
+
+ // coverage testing
+ if (one) begin end
+ if (!one) begin end
+ if (cyc[0]) begin end if (!cyc[0]) begin end // multiple on a line
+
+ if (cyc == 8\'d1) begin
+\t c_worked <= 0;
+ end
+ if (cyc == 8\'d2) begin
+`ifdef VERILATOR
+\t $c(""VL_PRINTF(\\""Calling $c, calling $c...\\\
+\\"");"");
+\t $c(""VL_PRINTF(\\""Cyc=%d\\\
+\\"","",cyc,"");"");
+\t c_worked <= $c(""my_function()"");
+\t c_wider <= $c9(""0x10"");
+`else
+\t c_worked <= 1\'b1;
+\t c_wider <= 9\'h10;
+`endif
+ end
+ if (cyc == 8\'d3) begin
+\t if (c_worked !== 1\'b1) $stop;
+\t if (c_wider !== 9\'h10) $stop;
+\t $finish;
+ end
+ end
+
+`ifdef verilator
+ `systemc_header
+#define DID_INT_HEADER 1
+ `systemc_interface
+#ifndef DID_INT_HEADER
+#error ""`systemc_header didn\'t work""
+#endif
+ bool m_did_ctor;
+ vluint32_t my_function() {
+ if (!m_did_ctor) vl_fatal(__FILE__,__LINE__,__FILE__,""`systemc_ctor didn\'t work"");
+ return 1;
+ }
+ `systemc_imp_header
+#define DID_IMP_HEADER 1
+ `systemc_implementation
+#ifndef DID_IMP_HEADER
+#error ""`systemc_imp_header didn\'t work""
+#endif
+ `systemc_ctor
+ m_did_ctor = 1;
+ `systemc_dtor
+ printf(""In systemc_dtor\
+"");
+ printf(""*-* All Finished *-*\
+"");
+ `verilog
+
+// Test verilator comment after a endif
+`endif // verilator
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg [31:0] wr_data;
+ reg \t wr_en;
+ wire [31:0] rd_data;
+ wire [1:0] rd_guards;
+ wire [1:0] rd_guardsok;
+
+ regfile regfile (/*AUTOINST*/
+\t\t // Outputs
+\t\t .rd_data\t\t(rd_data[31:0]),
+\t\t .rd_guards\t\t(rd_guards[1:0]),
+\t\t .rd_guardsok\t(rd_guardsok[1:0]),
+\t\t // Inputs
+\t\t .wr_data\t\t(wr_data[31:0]),
+\t\t .wr_en\t\t(wr_en),
+\t\t .clk\t\t(clk));
+
+ initial wr_en = 0;
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t if (!rd_guards[0]) $stop;
+\t if (!rd_guardsok[0]) $stop;
+\t wr_en <= 1\'b1;
+\t wr_data <= 32\'hfeedf;
+\t end
+\t if (cyc==2) begin
+\t wr_en <= 0;
+\t end
+\t if (cyc==3) begin
+\t wr_en <= 0;
+\t if (rd_data != 32\'hfeedf) $stop;
+\t if (rd_guards != 2\'b11) $stop;
+\t if (rd_guardsok != 2\'b11) $stop;
+\t end
+\t if (cyc==4) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+module regfile (
+\t\tinput [31:0] wr_data,
+\t\tinput wr_en,
+\t\toutput reg [31:0] \trd_data,
+\t\toutput [1:0] rd_guards /*verilator public*/,
+\t\toutput [1:0] rd_guardsok /*verilator public*/,
+\t\tinput clk
+\t\t);
+
+ always @(posedge clk) begin
+ if (wr_en)
+\tbegin
+ rd_data <= wr_data;
+\tend
+ end
+
+ // this initial statement will induce correct initialize behavior
+ // initial rd_guards= { 2\'b11 };
+
+ assign rd_guards= {
+\t\t rd_data[0],
+\t\t 1\'b1
+\t\t };
+
+ assign rd_guardsok[0] = 1\'b1;
+ assign rd_guardsok[1] = rd_data[0];
+
+endmodule // regfile
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module a_top;
+ a a ();
+ initial begin
+ $write(""Bad top modules\
+"");
+ $stop;
+ end
+endmodule
+
+module a;
+ b b ();
+ c c ();
+ d d ();
+endmodule
+
+module b;
+endmodule
+
+module c;
+endmodule
+
+module d;
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+// verilator lint_off SYMRSVDWORD
+
+module t (/*AUTOARG*/
+ // Inputs
+ bool
+ );
+
+ input bool;\t// BAD
+
+ reg vector;\t// OK, as not public
+ reg switch /*verilator public*/;\t// Bad
+
+ typedef struct packed {
+ logic [31:0] vector;\t// OK, as not public
+ } test;
+ test t;
+
+ // global is a 1800-2009 reserved word, but we allow it when possible.
+ reg global;
+
+ initial begin
+ t.vector = 1;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ logic [2:0] [1:0] in;
+ always @* in = crc[5:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ logic [1:0] [1:0]\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out/*[1:0][1:0]*/),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(in/*[2:0][1:0]*/));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {60\'h0, out[1],out[0]};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'hdc21e42d85441511
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ clk, in
+ );
+
+ //bug717
+
+ input clk;
+ input logic [2:0][1:0] in;
+
+ output logic [1:0][1:0] out;
+
+ always @(posedge clk) begin
+ out <= in[2 -: 2];
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// IEEE 1800-2009 requires that any local definitions take precedence over
+// definitions in wildcard imported packages (section 26.3). Thus the code
+// below is valid SystemVerilog.
+//
+// This file ONLY is placed into the Public Domain, for any use, without
+// warranty, 2013 by Jie Xu
+
+package defs;
+ parameter NUMBER = 8;
+ localparam NUM = NUMBER;
+endpackage
+
+
+module t(/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ import defs::*;
+
+ // This also fails if we use localparam
+ parameter NUM = 32;
+
+ // Check we have the right definition
+ always @(posedge clk) begin
+ if (NUM == 32) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ else begin
+\t $stop;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+`include ""verilated.v""
+
+module t;
+ `verilator_file_descriptor file;
+
+ integer\tchars;
+ reg [1*8:1]\tletterl;
+ reg [8*8:1]\tletterq;
+ reg [16*8:1]\tletterw;
+ reg [16*8:1]\tletterz;
+ real\t\tr;
+ string\ts;
+
+ reg [7:0] \tv_a,v_b,v_c,v_d;
+ reg [31:0] \tv_worda;
+ reg [31:0] \tv_wordb;
+
+`ifdef TEST_VERBOSE
+ `define verbose 1\'b1
+`else
+ `define verbose 1\'b0
+`endif
+
+ initial begin
+ // Display formatting
+`ifdef verilator
+ if (file != 0) $stop;
+ $fwrite(file, ""Never printed, file closed\
+"");
+ if (!$feof(file)) $stop;
+`endif
+
+`ifdef AUTOFLUSH
+ // The ""w"" is required so we get a FD not a MFD
+ file = $fopen(""obj_dir/t_sys_file_autoflush/t_sys_file_autoflush.log"",""w"");
+`else
+ // The ""w"" is required so we get a FD not a MFD
+ file = $fopen(""obj_dir/t_sys_file_basic/t_sys_file_basic_test.log"",""w"");
+`endif
+ if ($feof(file)) $stop;
+
+ $fdisplay(file, ""[%0t] hello v=%x"", $time, 32\'h12345667);
+ $fwrite(file, ""[%0t] %s\
+"", $time, ""Hello2"");
+ $fflush(file);
+
+ $fclose(file);
+`ifdef verilator
+ if (file != 0) $stop(1); // Also test arguments to stop
+ $fwrite(file, ""Never printed, file closed\
+"");
+`endif
+
+ begin
+\t // Check for opening errors
+\t // The ""r"" is required so we get a FD not a MFD
+\t file = $fopen(""obj_dir/t_sys_file_basic/DOES_NOT_EXIST"",""r"");
+\t if (|file) $stop;\t// Should not exist, IE must return 0
+ end
+
+ begin
+\t // Check quadword access; a little strange, but it\'s legal to open "".""
+\t file = $fopen(""."",""r"");
+\t $fclose(file);
+ end
+
+ begin
+\t // Check read functions w/string
+\t s = ""t/t_sys_file_basic_input.dat"";
+\t file = $fopen(s,""r"");
+\t if ($feof(file)) $stop;
+\t $fclose(file);
+ end
+
+ begin
+\t // Check read functions
+\t file = $fopen(""t/t_sys_file_basic_input.dat"",""r"");
+\t if ($feof(file)) $stop;
+
+\t // $fgetc
+\t if ($fgetc(file) != ""h"") $stop;
+\t if ($fgetc(file) != ""i"") $stop;
+\t if ($fgetc(file) != ""\
+"") $stop;
+
+\t // $fgets
+\t chars = $fgets(letterl, file);
+\t if (`verbose) $write(""c=%0d l=%s\
+"", chars, letterl);
+\t if (chars != 1) $stop;
+\t if (letterl != ""l"") $stop;
+
+\t chars = $fgets(letterq, file);
+\t if (`verbose) $write(""c=%0d q=%x=%s"", chars, letterq, letterq); // Output includes newline
+\t if (chars != 5) $stop;
+\t if (letterq != ""\\0\\0\\0quad\
+"") $stop;
+
+\t letterw = ""5432109876543210"";
+\t chars = $fgets(letterw, file);
+\t if (`verbose) $write(""c=%0d w=%s"", chars, letterw); // Output includes newline
+\t if (chars != 10) $stop;
+\t if (letterw != ""\\0\\0\\0\\0\\0\\0widestuff\
+"") $stop;
+
+\t // $sscanf
+\t if ($sscanf(""x"","""")!=0) $stop;
+\t if ($sscanf(""z"",""z"")!=0) $stop;
+
+\t chars = $sscanf(""blabcdefghijklmnop"",
+\t\t\t ""%s"", letterq);
+\t if (`verbose) $write(""c=%0d sa=%s\
+"", chars, letterq);
+\t if (chars != 1) $stop;
+\t if (letterq != ""ijklmnop"") $stop;
+
+\t chars = $sscanf(""xa=1f xb=12898971238912389712783490823_237904689_02348923"",
+\t\t\t ""xa=%x xb=%x"", letterq, letterw);
+\t if (`verbose) $write(""c=%0d xa=%x xb=%x\
+"", chars, letterq, letterw);
+\t if (chars != 2) $stop;
+\t if (letterq != 64\'h1f) $stop;
+\t if (letterw != 128\'h38971278349082323790468902348923) $stop;
+
+\t chars = $sscanf(""ba=10 bb=110100101010010101012 note_the_two "",
+\t\t\t ""ba=%b bb=%b%s"", letterq, letterw, letterz);
+\t if (`verbose) $write(""c=%0d xa=%x xb=%x z=%0s\
+"", chars, letterq, letterw, letterz);
+\t if (chars != 3) $stop;
+\t if (letterq != 64\'h2) $stop;
+\t if (letterw != 128\'hd2a55) $stop;
+\t if (letterz != {""\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0"",""2""}) $stop;
+
+\t chars = $sscanf(""oa=23 ob=125634123615234123681236"",
+\t\t\t ""oa=%o ob=%o"", letterq, letterw);
+\t if (`verbose) $write(""c=%0d oa=%x ob=%x\
+"", chars, letterq, letterw);
+\t if (chars != 2) $stop;
+\t if (letterq != 64\'h13) $stop;
+\t if (letterw != 128\'h55ce14f1a9c29e) $stop;
+
+\t chars = $sscanf(""r=0.1 d=-236123"",
+\t\t\t ""r=%g d=%d"", r, letterq);
+\t if (`verbose) $write(""c=%0d d=%d\
+"", chars, letterq);
+\t if (chars != 2) $stop;
+\t if (r != 0.1) $stop;
+\t if (letterq != 64\'hfffffffffffc65a5) $stop;
+
+\t s = ""r=0.2 d=-236124"";
+\t chars = $sscanf(s, ""r=%g d=%d"", r, letterq);
+\t if (`verbose) $write(""c=%0d d=%d\
+"", chars, letterq);
+\t if (chars != 2) $stop;
+\t if (r != 0.2) $stop;
+\t if (letterq != 64\'hfffffffffffc65a4) $stop;
+
+\t // $fscanf
+\t if ($fscanf(file,"""")!=0) $stop;
+
+\t if (!sync(""*"")) $stop;
+\t chars = $fscanf(file, ""xa=%x xb=%x"", letterq, letterw);
+\t if (`verbose) $write(""c=%0d xa=%0x xb=%0x\
+"", chars, letterq, letterw);
+\t if (chars != 2) $stop;
+\t if (letterq != 64\'h1f) $stop;
+\t if (letterw != 128\'h23790468902348923) $stop;
+
+\t if (!sync(""\
+"")) $stop;
+\t if (!sync(""*"")) $stop;
+\t chars = $fscanf(file, ""ba=%b bb=%b %s"", letterq, letterw, letterz);
+\t if (`verbose) $write(""c=%0d ba=%0x bb=%0x z=%0s\
+"", chars, letterq, letterw, letterz);
+\t if (chars != 3) $stop;
+\t if (letterq != 64\'h2) $stop;
+\t if (letterw != 128\'hd2a55) $stop;
+\t if (letterz != ""\\0\\0\\0\\0note_the_two"") $stop;
+
+\t if (!sync(""\
+"")) $stop;
+\t if (!sync(""*"")) $stop;
+\t chars = $fscanf(file, ""oa=%o ob=%o"", letterq, letterw);
+\t if (`verbose) $write(""c=%0d oa=%0x ob=%0x\
+"", chars, letterq, letterw);
+\t if (chars != 2) $stop;
+\t if (letterq != 64\'h13) $stop;
+\t if (letterw != 128\'h1573) $stop;
+
+\t if (!sync(""\
+"")) $stop;
+\t if (!sync(""*"")) $stop;
+\t chars = $fscanf(file, ""d=%d"", letterq);
+\t if (`verbose) $write(""c=%0d d=%0x\
+"", chars, letterq);
+\t if (chars != 1) $stop;
+\t if (letterq != 64\'hfffffffffffc65a5) $stop;
+
+\t if (!sync(""\
+"")) $stop;
+\t if (!sync(""*"")) $stop;
+\t chars = $fscanf(file, ""%c%s"", letterl, letterw);
+\t if (`verbose) $write(""c=%0d q=%c s=%s\
+"", chars, letterl, letterw);
+\t if (chars != 2) $stop;
+\t if (letterl != ""f"") $stop;
+\t if (letterw != ""\\0\\0\\0\\0\\0redfishblah"") $stop;
+
+\t chars = $fscanf(file, ""%c"", letterl);
+\t if (`verbose) $write(""c=%0d l=%x\
+"", chars, letterl);
+\t if (chars != 1) $stop;
+\t if (letterl != ""\
+"") $stop;
+
+\t // msg1229
+\t v_a = $fgetc(file);
+\t v_b = $fgetc(file);
+\t v_c = $fgetc(file);
+\t v_d = $fgetc(file);
+\t v_worda = { v_d, v_c, v_b, v_a };
+\t if (v_worda != ""4321"") $stop;
+
+\t v_wordb[7:0] = $fgetc(file);
+\t v_wordb[15:8] = $fgetc(file);
+\t v_wordb[23:16] = $fgetc(file);
+\t v_wordb[31:24] = $fgetc(file);
+\t if (v_wordb != ""9876"") $stop;
+
+\t if ($fgetc(file) != ""\
+"") $stop;
+
+\t $fclose(file);
+ end
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish(0); // Test arguments to finish
+ end
+
+ function sync;
+ input [7:0] cexp;
+ reg [7:0] cgot;
+ begin
+\t cgot = $fgetc(file);
+\t if (`verbose) $write(""sync=%x=\'%c\'\
+"", cgot,cgot);
+\t sync = (cgot == cexp);
+ end
+ endfunction
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+bit global_bit;
+
+module t (clk);
+ input clk;
+ integer \tcyc=0;
+
+ typedef struct packed {
+ bit\tb1;
+ bit\tb0;
+ } strp_t;
+
+ typedef struct packed {
+ strp_t\tx1;
+ strp_t\tx0;
+ } strp_strp_t;
+
+ typedef union packed {
+ strp_t\tx1;
+ strp_t\tx0;
+ } unip_strp_t;
+
+ typedef bit [2:1] arrp_t;
+ typedef arrp_t [4:3] arrp_arrp_t;
+
+ typedef strp_t [4:3] arrp_strp_t;
+
+ typedef bit arru_t [2:1];
+ typedef arru_t arru_arru_t [4:3];
+ typedef arrp_t arru_arrp_t [4:3];
+ typedef strp_t arru_strp_t [4:3];
+
+ strp_t \tv_strp;
+ strp_strp_t\tv_strp_strp;
+ unip_strp_t\tv_unip_strp;
+ arrp_t\tv_arrp;
+ arrp_arrp_t\tv_arrp_arrp;
+ arrp_strp_t\tv_arrp_strp;
+ arru_t\tv_arru;
+ arru_arru_t\tv_arru_arru;
+ arru_arrp_t\tv_arru_arrp;
+ arru_strp_t\tv_arru_strp;
+
+ real v_real;
+ real v_arr_real [2];
+ string\tv_string;
+
+ typedef struct packed {
+ logic [31:0] data;
+ } str32_t;
+ str32_t [1:0] v_str32x2; // If no --trace-struct, this packed array is traced as 63:0
+ initial v_str32x2[0] = 32\'hff;
+ initial v_str32x2[1] = 0;
+
+ p #(.PARAM(2)) p2 ();
+ p #(.PARAM(3)) p3 ();
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ v_strp <= ~v_strp;
+ v_strp_strp <= ~v_strp_strp;
+ v_unip_strp <= ~v_unip_strp;
+ v_arrp_strp <= ~v_arrp_strp;
+ v_arrp <= ~v_arrp;
+ v_arrp_arrp <= ~v_arrp_arrp;
+ v_real <= v_real + 0.1;
+ v_string <= ""foo"";
+ v_arr_real[0] <= v_arr_real[0] + 0.2;
+ v_arr_real[1] <= v_arr_real[1] + 0.3;
+ for (integer b=3; b<=4; b++) begin
+\t v_arru[b] <= ~v_arru[b];
+\t v_arru_strp[b] <= ~v_arru_strp[b];
+\t v_arru_arrp[b] <= ~v_arru_arrp[b];
+\t for (integer a=3; a<=4; a++) begin
+\t v_arru_arru[a][b] = ~v_arru_arru[a][b];
+\t end
+ end
+ v_str32x2[0] <= v_str32x2[0] - 1;
+ v_str32x2[1] <= v_str32x2[1] + 1;
+ if (cyc == 5) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module p;
+ parameter PARAM = 1;
+ initial global_bit = 1;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Iztok Jeras.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ parameter SIZE = 8;
+
+ integer cnt = 0;
+
+ logic [SIZE-1:0] vld_for;
+ logic vld_if = 1\'b0;
+ logic vld_else = 1\'b0;
+
+ genvar i;
+
+ // event counter
+ always @ (posedge clk) begin
+ cnt <= cnt + 1;
+ end
+
+ // finish report
+ always @ (posedge clk)
+ if (cnt==SIZE) begin : if_cnt_finish
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end : if_cnt_finish_bad
+
+ generate
+ for (i=0; i0) begin : generate_if_if
+ always @ (posedge clk)
+ vld_if <= 1\'b1;
+ end : generate_if_if_bad
+ else begin : generate_if_else
+ always @ (posedge clk)
+ vld_else <= 1\'b1;
+ end : generate_if_else_bad
+ endgenerate
+
+endmodule : t_bad
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ parameter\tUNSIZED = 10;
+
+ integer cyc=1;
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==1) begin
+\t if ({UNSIZED,UNSIZED+1} != {32\'d10, 32\'d11}) $stop;
+\t if ({2{UNSIZED}} != {32\'d10, 32\'d10}) $stop;
+ end
+ if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Mahesh Kumashikar
+
+module t_math_synmul_mul ( /*AUTOARG*/
+ // Outputs
+ product_d4,
+ // Inputs
+ clk, enable, negate, datA, datB
+ );
+ input clk;
+ input enable;
+ input negate;
+
+ input [31:0] datA;
+ input [31:0] datB;
+
+ // verilator lint_off UNOPTFLAT
+
+ output reg [64:0] product_d4;
+
+ reg [33:0] datA_d1r;
+ reg [33:0] datB_d1r;
+
+ always @ (posedge clk) begin
+ if (enable) begin
+\t datA_d1r <= {2\'b0,datA};
+\t datB_d1r <= {2\'b0,datB};
+\t // The extra multiplier bits were for signed, for this
+\t // test we\'ve ripped that out
+\t if (negate) $stop;
+ end
+ end
+
+ reg en_d1;
+ reg en_d2;
+ reg en_d3;
+ always @ (posedge clk) begin
+ en_d1 <= enable;
+ en_d2 <= en_d1;
+ en_d3 <= en_d2;
+ end
+
+ wire [63:0] prod_d3;
+
+ smmultiplier_34_34 mul (.OPA(datA_d1r),
+\t\t\t .OPB(datB_d1r),
+\t\t\t .RESULT(prod_d3),
+\t\t\t /*AUTOINST*/
+\t\t\t // Inputs
+\t\t\t .clk\t\t\t(clk),
+\t\t\t .en_d1\t\t(en_d1),
+\t\t\t .en_d2\t\t(en_d2));
+
+ always @ (posedge clk) begin
+ if (en_d3) begin
+\t product_d4 <= {1\'b0,prod_d3};
+ end
+ end
+
+endmodule
+
+// The below was originally generated by the ""Synthesizable Arithmetic Module Generator""
+// at http://modgen.fysel.ntnu.no/~pihl/iwlas98/ then cleaned up by hand.
+// Unfortunately the generator no longer appears available. Please contact
+// us if you know otherwise.
+
+module smmultiplier_34_34
+ (
+ input clk,
+ input en_d1,
+ input en_d2,
+
+ input [33:0] OPA,
+ input [33:0] OPB,
+ output [63:0] RESULT
+ );
+
+ wire [628:0] PPBIT;
+ wire [66:0] INT_CARRY;
+ wire [66:0] INT_SUM;
+ smboothcoder_34_34 db (.OPA(OPA[33:0]), .OPB(OPB[33:0]), .SUMMAND(PPBIT[628:0]) );
+ smwallace_34_34 dw (.SUMMAND(PPBIT[628:0]), .CARRY(INT_CARRY[66:1]), .SUM(INT_SUM[66:0]),
+\t\t /*AUTOINST*/
+\t\t // Inputs
+\t\t .clk\t\t(clk),
+\t\t .en_d1\t\t(en_d1),
+\t\t .en_d2\t\t(en_d2));
+ assign INT_CARRY[0] = 1\'b0;
+ smdblcadder_128_128 dd (.OPA(INT_SUM[63:0]), .OPB(INT_CARRY[63:0]), .CIN (1\'b0), .SUM(RESULT));
+endmodule
+
+module smdblcadder_128_128 ( OPA, OPB, CIN, SUM );
+ input [63:0] OPA;
+ input [63:0] OPB;
+ input CIN;
+ output [63:0] SUM;
+ wire [63:0] INTPROP;
+ wire [63:0] INTGEN;
+ wire [0:0] PBIT;
+ wire [63:0] CARRY;
+ smprestage_128 dp (OPA[63:0], OPB[63:0], CIN, INTPROP, INTGEN );
+ smdblctree_128 dd (INTPROP[63:0], INTGEN[63:0], CARRY[63:0], PBIT );
+ smxorstage_128 dx (OPA[63:0], OPB[63:0], PBIT[0], CARRY[63:0], SUM );
+endmodule
+
+module smdblctree_128 ( PIN, GIN, GOUT, POUT );
+ input [63:0] PIN;
+ input [63:0] GIN;
+ output [63:0] GOUT;
+ output [0:0] POUT;
+ wire [63:0] INTPROP_0;
+ wire [63:0] INTGEN_0;
+ wire [63:0] INTPROP_1;
+ wire [63:0] INTGEN_1;
+ wire [63:0] INTPROP_2;
+ wire [63:0] INTGEN_2;
+ wire [63:0] INTPROP_3;
+ wire [63:0] INTGEN_3;
+ wire [63:0] INTPROP_4;
+ wire [63:0] INTGEN_4;
+ wire [63:0] INTPROP_5;
+ wire [63:0] INTGEN_5;
+ smdblc_0_128 ddb0 (.PIN(PIN), .GIN(GIN), .POUT(INTPROP_0), .GOUT(INTGEN_0) );
+ smdblc_1_128 ddb1 (.PIN(INTPROP_0), .GIN(INTGEN_0), .POUT(INTPROP_1), .GOUT(INTGEN_1) );
+ smdblc_2_128 ddb2 (.PIN(INTPROP_1), .GIN(INTGEN_1), .POUT(INTPROP_2), .GOUT(INTGEN_2) );
+ smdblc_3_128 ddb3 (.PIN(INTPROP_2), .GIN(INTGEN_2), .POUT(INTPROP_3), .GOUT(INTGEN_3) );
+ smdblc_4_128 ddb4 (.PIN(INTPROP_3), .GIN(INTGEN_3), .POUT(INTPROP_4), .GOUT(INTGEN_4) );
+ smdblc_5_128 ddb5 (.PIN(INTPROP_4), .GIN(INTGEN_4), .POUT(INTPROP_5), .GOUT(INTGEN_5) );
+ smdblc_6_128 ddb6 (.PIN(INTPROP_5), .GIN(INTGEN_5), .POUT(POUT), .GOUT(GOUT) );
+endmodule
+
+module smwallace_34_34
+ (
+ input clk,
+ input en_d1,
+ input en_d2,
+
+ input [628:0] SUMMAND,
+ output [65:0] CARRY,
+ output [66:0] SUM
+ );
+
+ wire [628:0] LATCHED_PP;
+ wire [551:0] INT_CARRY;
+ wire [687:0] INT_SUM;
+ smffa dla0 (.D(SUMMAND[0]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[0]) );
+ smffa dla1 (.D(SUMMAND[1]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[1]) );
+ smhalfadder dha0 (.DATA_A (LATCHED_PP[0]), .DATA_B (LATCHED_PP[1]), .SAVE (INT_SUM[0]), .CARRY (INT_CARRY[0]) );
+ smffb dla2 (.D(INT_SUM[0]), .clk(clk), .en_d2(en_d2), .Q(SUM[0]) );
+ smffb dla3 (.D(INT_CARRY[0]), .clk(clk), .en_d2(en_d2), .Q(CARRY[0]) );
+ smffa dla4 (.D(SUMMAND[2]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[2]) );
+ assign INT_SUM[1] = LATCHED_PP[2];
+ assign CARRY[1] = 1\'b0;
+ smffb dla5 (.D(INT_SUM[1]), .clk(clk), .en_d2(en_d2), .Q(SUM[1]) );
+ smffa dla6 (.D(SUMMAND[3]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[3]) );
+ smffa dla7 (.D(SUMMAND[4]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[4]) );
+ smffa dla8 (.D(SUMMAND[5]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[5]) );
+ smfulladder dfa0 (.DATA_A (LATCHED_PP[3]), .DATA_B (LATCHED_PP[4]), .DATA_C (LATCHED_PP[5]), .SAVE (INT_SUM[2]), .CARRY (INT_CARRY[1]) );
+ smffb dla9 (.D(INT_SUM[2]), .clk(clk), .en_d2(en_d2), .Q(SUM[2]) );
+ smffb dla10 (.D(INT_CARRY[1]), .clk(clk), .en_d2(en_d2), .Q(CARRY[2]) );
+ smffa dla11 (.D(SUMMAND[6]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[6]) );
+ smffa dla12 (.D(SUMMAND[7]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[7]) );
+ smhalfadder dha1 (.DATA_A (LATCHED_PP[6]), .DATA_B (LATCHED_PP[7]), .SAVE (INT_SUM[3]), .CARRY (INT_CARRY[2]) );
+ smffb dla13 (.D(INT_SUM[3]), .clk(clk), .en_d2(en_d2), .Q(SUM[3]) );
+ smffb dla14 (.D(INT_CARRY[2]), .clk(clk), .en_d2(en_d2), .Q(CARRY[3]) );
+ smffa dla15 (.D(SUMMAND[8]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[8]) );
+ smffa dla16 (.D(SUMMAND[9]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[9]) );
+ smffa dla17 (.D(SUMMAND[10]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[10]) );
+ smfulladder dfa1 (.DATA_A (LATCHED_PP[8]), .DATA_B (LATCHED_PP[9]), .DATA_C (LATCHED_PP[10]), .SAVE (INT_SUM[4]), .CARRY (INT_CARRY[4]) );
+ smffa dla18 (.D(SUMMAND[11]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[11]) );
+ assign INT_SUM[5] = LATCHED_PP[11];
+ smhalfadder dha2 (.DATA_A (INT_SUM[4]), .DATA_B (INT_SUM[5]), .SAVE (INT_SUM[6]), .CARRY (INT_CARRY[3]) );
+ smffb dla19 (.D(INT_SUM[6]), .clk(clk), .en_d2(en_d2), .Q(SUM[4]) );
+ smffb dla20 (.D(INT_CARRY[3]), .clk(clk), .en_d2(en_d2), .Q(CARRY[4]) );
+ smffa dla21 (.D(SUMMAND[12]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[12]) );
+ smffa dla22 (.D(SUMMAND[13]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[13]) );
+ smffa dla23 (.D(SUMMAND[14]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[14]) );
+ smfulladder dfa2 (.DATA_A (LATCHED_PP[12]), .DATA_B (LATCHED_PP[13]), .DATA_C (LATCHED_PP[14]), .SAVE (INT_SUM[7]), .CARRY (INT_CARRY[6]) );
+ smhalfadder dha3 (.DATA_A (INT_SUM[7]), .DATA_B (INT_CARRY[4]), .SAVE (INT_SUM[8]), .CARRY (INT_CARRY[5]) );
+ smffb dla24 (.D(INT_SUM[8]), .clk(clk), .en_d2(en_d2), .Q(SUM[5]) );
+ smffb dla25 (.D(INT_CARRY[5]), .clk(clk), .en_d2(en_d2), .Q(CARRY[5]) );
+ smffa dla26 (.D(SUMMAND[15]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[15]) );
+ smffa dla27 (.D(SUMMAND[16]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[16]) );
+ smffa dla28 (.D(SUMMAND[17]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[17]) );
+ smfulladder dfa3 (.DATA_A (LATCHED_PP[15]), .DATA_B (LATCHED_PP[16]), .DATA_C (LATCHED_PP[17]), .SAVE (INT_SUM[9]), .CARRY (INT_CARRY[8]) );
+ smffa dla29 (.D(SUMMAND[18]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[18]) );
+ smffa dla30 (.D(SUMMAND[19]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[19]) );
+ smhalfadder dha4 (.DATA_A (LATCHED_PP[18]), .DATA_B (LATCHED_PP[19]), .SAVE (INT_SUM[10]), .CARRY (INT_CARRY[9]) );
+ smfulladder dfa4 (.DATA_A (INT_SUM[9]), .DATA_B (INT_SUM[10]), .DATA_C (INT_CARRY[6]), .SAVE (INT_SUM[11]), .CARRY (INT_CARRY[7]) );
+ smffb dla31 (.D(INT_SUM[11]), .clk(clk), .en_d2(en_d2), .Q(SUM[6]) );
+ smffb dla32 (.D(INT_CARRY[7]), .clk(clk), .en_d2(en_d2), .Q(CARRY[6]) );
+ smffa dla33 (.D(SUMMAND[20]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[20]) );
+ smffa dla34 (.D(SUMMAND[21]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[21]) );
+ smffa dla35 (.D(SUMMAND[22]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[22]) );
+ smfulladder dfa5 (.DATA_A (LATCHED_PP[20]), .DATA_B (LATCHED_PP[21]), .DATA_C (LATCHED_PP[22]), .SAVE (INT_SUM[12]), .CARRY (INT_CARRY[11]) );
+ smffa dla36 (.D(SUMMAND[23]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[23]) );
+ assign INT_SUM[13] = LATCHED_PP[23];
+ smfulladder dfa6 (.DATA_A (INT_SUM[12]), .DATA_B (INT_SUM[13]), .DATA_C (INT_CARRY[8]), .SAVE (INT_SUM[14]), .CARRY (INT_CARRY[12]) );
+ assign INT_SUM[15] = INT_CARRY[9];
+ smhalfadder dha5 (.DATA_A (INT_SUM[14]), .DATA_B (INT_SUM[15]), .SAVE (INT_SUM[16]), .CARRY (INT_CARRY[10]) );
+ smffb dla37 (.D(INT_SUM[16]), .clk(clk), .en_d2(en_d2), .Q(SUM[7]) );
+ smffb dla38 (.D(INT_CARRY[10]), .clk(clk), .en_d2(en_d2), .Q(CARRY[7]) );
+ smffa dla39 (.D(SUMMAND[24]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[24]) );
+ smffa dla40 (.D(SUMMAND[25]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[25]) );
+ smffa dla41 (.D(SUMMAND[26]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[26]) );
+ smfulladder dfa7 (.DATA_A (LATCHED_PP[24]), .DATA_B (LATCHED_PP[25]), .DATA_C (LATCHED_PP[26]), .SAVE (INT_SUM[17]), .CARRY (INT_CARRY[14]) );
+ smffa dla42 (.D(SUMMAND[27]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[27]) );
+ smffa dla43 (.D(SUMMAND[28]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[28]) );
+ smffa dla44 (.D(SUMMAND[29]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[29]) );
+ smfulladder dfa8 (.DATA_A (LATCHED_PP[27]), .DATA_B (LATCHED_PP[28]), .DATA_C (LATCHED_PP[29]), .SAVE (INT_SUM[18]), .CARRY (INT_CARRY[15]) );
+ smfulladder dfa9 (.DATA_A (INT_SUM[17]), .DATA_B (INT_SUM[18]), .DATA_C (INT_CARRY[11]), .SAVE (INT_SUM[19]), .CARRY (INT_CARRY[16]) );
+ smhalfadder dha6 (.DATA_A (INT_SUM[19]), .DATA_B (INT_CARRY[12]), .SAVE (INT_SUM[20]), .CARRY (INT_CARRY[13]) );
+ smffb dla45 (.D(INT_SUM[20]), .clk(clk), .en_d2(en_d2), .Q(SUM[8]) );
+ smffb dla46 (.D(INT_CARRY[13]), .clk(clk), .en_d2(en_d2), .Q(CARRY[8]) );
+ smffa dla47 (.D(SUMMAND[30]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[30]) );
+ smffa dla48 (.D(SUMMAND[31]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[31]) );
+ smffa dla49 (.D(SUMMAND[32]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[32]) );
+ smfulladder dfa10 (.DATA_A (LATCHED_PP[30]), .DATA_B (LATCHED_PP[31]), .DATA_C (LATCHED_PP[32]), .SAVE (INT_SUM[21]), .CARRY (INT_CARRY[18]) );
+ smffa dla50 (.D(SUMMAND[33]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[33]) );
+ smffa dla51 (.D(SUMMAND[34]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[34]) );
+ smhalfadder dha7 (.DATA_A (LATCHED_PP[33]), .DATA_B (LATCHED_PP[34]), .SAVE (INT_SUM[22]), .CARRY (INT_CARRY[19]) );
+ smfulladder dfa11 (.DATA_A (INT_SUM[21]), .DATA_B (INT_SUM[22]), .DATA_C (INT_CARRY[14]), .SAVE (INT_SUM[23]), .CARRY (INT_CARRY[20]) );
+ assign INT_SUM[24] = INT_CARRY[15];
+ smfulladder dfa12 (.DATA_A (INT_SUM[23]), .DATA_B (INT_SUM[24]), .DATA_C (INT_CARRY[16]), .SAVE (INT_SUM[25]), .CARRY (INT_CARRY[17]) );
+ smffb dla52 (.D(INT_SUM[25]), .clk(clk), .en_d2(en_d2), .Q(SUM[9]) );
+ smffb dla53 (.D(INT_CARRY[17]), .clk(clk), .en_d2(en_d2), .Q(CARRY[9]) );
+ smffa dla54 (.D(SUMMAND[35]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[35]) );
+ smffa dla55 (.D(SUMMAND[36]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[36]) );
+ smffa dla56 (.D(SUMMAND[37]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[37]) );
+ smfulladder dfa13 (.DATA_A (LATCHED_PP[35]), .DATA_B (LATCHED_PP[36]), .DATA_C (LATCHED_PP[37]), .SAVE (INT_SUM[26]), .CARRY (INT_CARRY[22]) );
+ smffa dla57 (.D(SUMMAND[38]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[38]) );
+ smffa dla58 (.D(SUMMAND[39]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[39]) );
+ smffa dla59 (.D(SUMMAND[40]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[40]) );
+ smfulladder dfa14 (.DATA_A (LATCHED_PP[38]), .DATA_B (LATCHED_PP[39]), .DATA_C (LATCHED_PP[40]), .SAVE (INT_SUM[27]), .CARRY (INT_CARRY[23]) );
+ smffa dla60 (.D(SUMMAND[41]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[41]) );
+ assign INT_SUM[28] = LATCHED_PP[41];
+ smfulladder dfa15 (.DATA_A (INT_SUM[26]), .DATA_B (INT_SUM[27]), .DATA_C (INT_SUM[28]), .SAVE (INT_SUM[29]), .CARRY (INT_CARRY[24]) );
+ smhalfadder dha8 (.DATA_A (INT_CARRY[18]), .DATA_B (INT_CARRY[19]), .SAVE (INT_SUM[30]), .CARRY (INT_CARRY[25]) );
+ smfulladder dfa16 (.DATA_A (INT_SUM[29]), .DATA_B (INT_SUM[30]), .DATA_C (INT_CARRY[20]), .SAVE (INT_SUM[31]), .CARRY (INT_CARRY[21]) );
+ smffb dla61 (.D(INT_SUM[31]), .clk(clk), .en_d2(en_d2), .Q(SUM[10]) );
+ smffb dla62 (.D(INT_CARRY[21]), .clk(clk), .en_d2(en_d2), .Q(CARRY[10]) );
+ smffa dla63 (.D(SUMMAND[42]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[42]) );
+ smffa dla64 (.D(SUMMAND[43]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[43]) );
+ smffa dla65 (.D(SUMMAND[44]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[44]) );
+ smfulladder dfa17 (.DATA_A (LATCHED_PP[42]), .DATA_B (LATCHED_PP[43]), .DATA_C (LATCHED_PP[44]), .SAVE (INT_SUM[32]), .CARRY (INT_CARRY[27]) );
+ smffa dla66 (.D(SUMMAND[45]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[45]) );
+ smffa dla67 (.D(SUMMAND[46]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[46]) );
+ smffa dla68 (.D(SUMMAND[47]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[47]) );
+ smfulladder dfa18 (.DATA_A (LATCHED_PP[45]), .DATA_B (LATCHED_PP[46]), .DATA_C (LATCHED_PP[47]), .SAVE (INT_SUM[33]), .CARRY (INT_CARRY[28]) );
+ smfulladder dfa19 (.DATA_A (INT_SUM[32]), .DATA_B (INT_SUM[33]), .DATA_C (INT_CARRY[22]), .SAVE (INT_SUM[34]), .CARRY (INT_CARRY[29]) );
+ assign INT_SUM[35] = INT_CARRY[23];
+ smfulladder dfa20 (.DATA_A (INT_SUM[34]), .DATA_B (INT_SUM[35]), .DATA_C (INT_CARRY[24]), .SAVE (INT_SUM[36]), .CARRY (INT_CARRY[30]) );
+ assign INT_SUM[37] = INT_CARRY[25];
+ smhalfadder dha9 (.DATA_A (INT_SUM[36]), .DATA_B (INT_SUM[37]), .SAVE (INT_SUM[38]), .CARRY (INT_CARRY[26]) );
+ smffb dla69 (.D(INT_SUM[38]), .clk(clk), .en_d2(en_d2), .Q(SUM[11]) );
+ smffb dla70 (.D(INT_CARRY[26]), .clk(clk), .en_d2(en_d2), .Q(CARRY[11]) );
+ smffa dla71 (.D(SUMMAND[48]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[48]) );
+ smffa dla72 (.D(SUMMAND[49]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[49]) );
+ smffa dla73 (.D(SUMMAND[50]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[50]) );
+ smfulladder dfa21 (.DATA_A (LATCHED_PP[48]), .DATA_B (LATCHED_PP[49]), .DATA_C (LATCHED_PP[50]), .SAVE (INT_SUM[39]), .CARRY (INT_CARRY[32]) );
+ smffa dla74 (.D(SUMMAND[51]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[51]) );
+ smffa dla75 (.D(SUMMAND[52]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[52]) );
+ smffa dla76 (.D(SUMMAND[53]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[53]) );
+ smfulladder dfa22 (.DATA_A (LATCHED_PP[51]), .DATA_B (LATCHED_PP[52]), .DATA_C (LATCHED_PP[53]), .SAVE (INT_SUM[40]), .CARRY (INT_CARRY[33]) );
+ smffa dla77 (.D(SUMMAND[54]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[54]) );
+ assign INT_SUM[41] = LATCHED_PP[54];
+ smffa dla78 (.D(SUMMAND[55]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[55]) );
+ assign INT_SUM[42] = LATCHED_PP[55];
+ smfulladder dfa23 (.DATA_A (INT_SUM[39]), .DATA_B (INT_SUM[40]), .DATA_C (INT_SUM[41]), .SAVE (INT_SUM[43]), .CARRY (INT_CARRY[34]) );
+ smfulladder dfa24 (.DATA_A (INT_SUM[42]), .DATA_B (INT_CARRY[27]), .DATA_C (INT_CARRY[28]), .SAVE (INT_SUM[44]), .CARRY (INT_CARRY[35]) );
+ smfulladder dfa25 (.DATA_A (INT_SUM[43]), .DATA_B (INT_SUM[44]), .DATA_C (INT_CARRY[29]), .SAVE (INT_SUM[45]), .CARRY (INT_CARRY[36]) );
+ smhalfadder dha10 (.DATA_A (INT_SUM[45]), .DATA_B (INT_CARRY[30]), .SAVE (INT_SUM[46]), .CARRY (INT_CARRY[31]) );
+ smffb dla79 (.D(INT_SUM[46]), .clk(clk), .en_d2(en_d2), .Q(SUM[12]) );
+ smffb dla80 (.D(INT_CARRY[31]), .clk(clk), .en_d2(en_d2), .Q(CARRY[12]) );
+ smffa dla81 (.D(SUMMAND[56]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[56]) );
+ smffa dla82 (.D(SUMMAND[57]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[57]) );
+ smffa dla83 (.D(SUMMAND[58]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[58]) );
+ smfulladder dfa26 (.DATA_A (LATCHED_PP[56]), .DATA_B (LATCHED_PP[57]), .DATA_C (LATCHED_PP[58]), .SAVE (INT_SUM[47]), .CARRY (INT_CARRY[38]) );
+ smffa dla84 (.D(SUMMAND[59]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[59]) );
+ smffa dla85 (.D(SUMMAND[60]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[60]) );
+ smffa dla86 (.D(SUMMAND[61]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[61]) );
+ smfulladder dfa27 (.DATA_A (LATCHED_PP[59]), .DATA_B (LATCHED_PP[60]), .DATA_C (LATCHED_PP[61]), .SAVE (INT_SUM[48]), .CARRY (INT_CARRY[39]) );
+ smffa dla87 (.D(SUMMAND[62]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[62]) );
+ assign INT_SUM[49] = LATCHED_PP[62];
+ smfulladder dfa28 (.DATA_A (INT_SUM[47]), .DATA_B (INT_SUM[48]), .DATA_C (INT_SUM[49]), .SAVE (INT_SUM[50]), .CARRY (INT_CARRY[40]) );
+ smhalfadder dha11 (.DATA_A (INT_CARRY[32]), .DATA_B (INT_CARRY[33]), .SAVE (INT_SUM[51]), .CARRY (INT_CARRY[41]) );
+ smfulladder dfa29 (.DATA_A (INT_SUM[50]), .DATA_B (INT_SUM[51]), .DATA_C (INT_CARRY[34]), .SAVE (INT_SUM[52]), .CARRY (INT_CARRY[42]) );
+ assign INT_SUM[53] = INT_CARRY[35];
+ smfulladder dfa30 (.DATA_A (INT_SUM[52]), .DATA_B (INT_SUM[53]), .DATA_C (INT_CARRY[36]), .SAVE (INT_SUM[54]), .CARRY (INT_CARRY[37]) );
+ smffb dla88 (.D(INT_SUM[54]), .clk(clk), .en_d2(en_d2), .Q(SUM[13]) );
+ smffb dla89 (.D(INT_CARRY[37]), .clk(clk), .en_d2(en_d2), .Q(CARRY[13]) );
+ smffa dla90 (.D(SUMMAND[63]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[63]) );
+ smffa dla91 (.D(SUMMAND[64]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[64]) );
+ smffa dla92 (.D(SUMMAND[65]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[65]) );
+ smfulladder dfa31 (.DATA_A (LATCHED_PP[63]), .DATA_B (LATCHED_PP[64]), .DATA_C (LATCHED_PP[65]), .SAVE (INT_SUM[55]), .CARRY (INT_CARRY[44]) );
+ smffa dla93 (.D(SUMMAND[66]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[66]) );
+ smffa dla94 (.D(SUMMAND[67]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[67]) );
+ smffa dla95 (.D(SUMMAND[68]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[68]) );
+ smfulladder dfa32 (.DATA_A (LATCHED_PP[66]), .DATA_B (LATCHED_PP[67]), .DATA_C (LATCHED_PP[68]), .SAVE (INT_SUM[56]), .CARRY (INT_CARRY[45]) );
+ smffa dla96 (.D(SUMMAND[69]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[69]) );
+ smffa dla97 (.D(SUMMAND[70]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[70]) );
+ smffa dla98 (.D(SUMMAND[71]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[71]) );
+ smfulladder dfa33 (.DATA_A (LATCHED_PP[69]), .DATA_B (LATCHED_PP[70]), .DATA_C (LATCHED_PP[71]), .SAVE (INT_SUM[57]), .CARRY (INT_CARRY[46]) );
+ smfulladder dfa34 (.DATA_A (INT_SUM[55]), .DATA_B (INT_SUM[56]), .DATA_C (INT_SUM[57]), .SAVE (INT_SUM[58]), .CARRY (INT_CARRY[47]) );
+ smhalfadder dha12 (.DATA_A (INT_CARRY[38]), .DATA_B (INT_CARRY[39]), .SAVE (INT_SUM[59]), .CARRY (INT_CARRY[48]) );
+ smfulladder dfa35 (.DATA_A (INT_SUM[58]), .DATA_B (INT_SUM[59]), .DATA_C (INT_CARRY[40]), .SAVE (INT_SUM[60]), .CARRY (INT_CARRY[49]) );
+ assign INT_SUM[61] = INT_CARRY[41];
+ smfulladder dfa36 (.DATA_A (INT_SUM[60]), .DATA_B (INT_SUM[61]), .DATA_C (INT_CARRY[42]), .SAVE (INT_SUM[62]), .CARRY (INT_CARRY[43]) );
+ smffb dla99 (.D(INT_SUM[62]), .clk(clk), .en_d2(en_d2), .Q(SUM[14]) );
+ smffb dla100 (.D(INT_CARRY[43]), .clk(clk), .en_d2(en_d2), .Q(CARRY[14]) );
+ smffa dla101 (.D(SUMMAND[72]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[72]) );
+ smffa dla102 (.D(SUMMAND[73]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[73]) );
+ smffa dla103 (.D(SUMMAND[74]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[74]) );
+ smfulladder dfa37 (.DATA_A (LATCHED_PP[72]), .DATA_B (LATCHED_PP[73]), .DATA_C (LATCHED_PP[74]), .SAVE (INT_SUM[63]), .CARRY (INT_CARRY[51]) );
+ smffa dla104 (.D(SUMMAND[75]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[75]) );
+ smffa dla105 (.D(SUMMAND[76]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[76]) );
+ smffa dla106 (.D(SUMMAND[77]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[77]) );
+ smfulladder dfa38 (.DATA_A (LATCHED_PP[75]), .DATA_B (LATCHED_PP[76]), .DATA_C (LATCHED_PP[77]), .SAVE (INT_SUM[64]), .CARRY (INT_CARRY[52]) );
+ smffa dla107 (.D(SUMMAND[78]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[78]) );
+ smffa dla108 (.D(SUMMAND[79]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[79]) );
+ smhalfadder dha13 (.DATA_A (LATCHED_PP[78]), .DATA_B (LATCHED_PP[79]), .SAVE (INT_SUM[65]), .CARRY (INT_CARRY[53]) );
+ smfulladder dfa39 (.DATA_A (INT_SUM[63]), .DATA_B (INT_SUM[64]), .DATA_C (INT_SUM[65]), .SAVE (INT_SUM[66]), .CARRY (INT_CARRY[54]) );
+ smfulladder dfa40 (.DATA_A (INT_CARRY[44]), .DATA_B (INT_CARRY[45]), .DATA_C (INT_CARRY[46]), .SAVE (INT_SUM[67]), .CARRY (INT_CARRY[55]) );
+ smfulladder dfa41 (.DATA_A (INT_SUM[66]), .DATA_B (INT_SUM[67]), .DATA_C (INT_CARRY[47]), .SAVE (INT_SUM[68]), .CARRY (INT_CARRY[56]) );
+ assign INT_SUM[69] = INT_CARRY[48];
+ smfulladder dfa42 (.DATA_A (INT_SUM[68]), .DATA_B (INT_SUM[69]), .DATA_C (INT_CARRY[49]), .SAVE (INT_SUM[70]), .CARRY (INT_CARRY[50]) );
+ smffb dla109 (.D(INT_SUM[70]), .clk(clk), .en_d2(en_d2), .Q(SUM[15]) );
+ smffb dla110 (.D(INT_CARRY[50]), .clk(clk), .en_d2(en_d2), .Q(CARRY[15]) );
+ smffa dla111 (.D(SUMMAND[80]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[80]) );
+ smffa dla112 (.D(SUMMAND[81]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[81]) );
+ smffa dla113 (.D(SUMMAND[82]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[82]) );
+ smfulladder dfa43 (.DATA_A (LATCHED_PP[80]), .DATA_B (LATCHED_PP[81]), .DATA_C (LATCHED_PP[82]), .SAVE (INT_SUM[71]), .CARRY (INT_CARRY[58]) );
+ smffa dla114 (.D(SUMMAND[83]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[83]) );
+ smffa dla115 (.D(SUMMAND[84]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[84]) );
+ smffa dla116 (.D(SUMMAND[85]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[85]) );
+ smfulladder dfa44 (.DATA_A (LATCHED_PP[83]), .DATA_B (LATCHED_PP[84]), .DATA_C (LATCHED_PP[85]), .SAVE (INT_SUM[72]), .CARRY (INT_CARRY[59]) );
+ smffa dla117 (.D(SUMMAND[86]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[86]) );
+ smffa dla118 (.D(SUMMAND[87]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[87]) );
+ smffa dla119 (.D(SUMMAND[88]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[88]) );
+ smfulladder dfa45 (.DATA_A (LATCHED_PP[86]), .DATA_B (LATCHED_PP[87]), .DATA_C (LATCHED_PP[88]), .SAVE (INT_SUM[73]), .CARRY (INT_CARRY[60]) );
+ smffa dla120 (.D(SUMMAND[89]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[89]) );
+ assign INT_SUM[74] = LATCHED_PP[89];
+ smfulladder dfa46 (.DATA_A (INT_SUM[71]), .DATA_B (INT_SUM[72]), .DATA_C (INT_SUM[73]), .SAVE (INT_SUM[75]), .CARRY (INT_CARRY[61]) );
+ smfulladder dfa47 (.DATA_A (INT_SUM[74]), .DATA_B (INT_CARRY[51]), .DATA_C (INT_CARRY[52]), .SAVE (INT_SUM[76]), .CARRY (INT_CARRY[62]) );
+ assign INT_SUM[77] = INT_CARRY[53];
+ smfulladder dfa48 (.DATA_A (INT_SUM[75]), .DATA_B (INT_SUM[76]), .DATA_C (INT_SUM[77]), .SAVE (INT_SUM[78]), .CARRY (INT_CARRY[63]) );
+ smhalfadder dha14 (.DATA_A (INT_CARRY[54]), .DATA_B (INT_CARRY[55]), .SAVE (INT_SUM[79]), .CARRY (INT_CARRY[64]) );
+ smfulladder dfa49 (.DATA_A (INT_SUM[78]), .DATA_B (INT_SUM[79]), .DATA_C (INT_CARRY[56]), .SAVE (INT_SUM[80]), .CARRY (INT_CARRY[57]) );
+ smffb dla121 (.D(INT_SUM[80]), .clk(clk), .en_d2(en_d2), .Q(SUM[16]) );
+ smffb dla122 (.D(INT_CARRY[57]), .clk(clk), .en_d2(en_d2), .Q(CARRY[16]) );
+ smffa dla123 (.D(SUMMAND[90]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[90]) );
+ smffa dla124 (.D(SUMMAND[91]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[91]) );
+ smffa dla125 (.D(SUMMAND[92]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[92]) );
+ smfulladder dfa50 (.DATA_A (LATCHED_PP[90]), .DATA_B (LATCHED_PP[91]), .DATA_C (LATCHED_PP[92]), .SAVE (INT_SUM[81]), .CARRY (INT_CARRY[66]) );
+ smffa dla126 (.D(SUMMAND[93]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[93]) );
+ smffa dla127 (.D(SUMMAND[94]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[94]) );
+ smffa dla128 (.D(SUMMAND[95]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[95]) );
+ smfulladder dfa51 (.DATA_A (LATCHED_PP[93]), .DATA_B (LATCHED_PP[94]), .DATA_C (LATCHED_PP[95]), .SAVE (INT_SUM[82]), .CARRY (INT_CARRY[67]) );
+ smffa dla129 (.D(SUMMAND[96]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[96]) );
+ smffa dla130 (.D(SUMMAND[97]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[97]) );
+ smffa dla131 (.D(SUMMAND[98]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[98]) );
+ smfulladder dfa52 (.DATA_A (LATCHED_PP[96]), .DATA_B (LATCHED_PP[97]), .DATA_C (LATCHED_PP[98]), .SAVE (INT_SUM[83]), .CARRY (INT_CARRY[68]) );
+ smfulladder dfa53 (.DATA_A (INT_SUM[81]), .DATA_B (INT_SUM[82]), .DATA_C (INT_SUM[83]), .SAVE (INT_SUM[84]), .CARRY (INT_CARRY[69]) );
+ smfulladder dfa54 (.DATA_A (INT_CARRY[58]), .DATA_B (INT_CARRY[59]), .DATA_C (INT_CARRY[60]), .SAVE (INT_SUM[85]), .CARRY (INT_CARRY[70]) );
+ smfulladder dfa55 (.DATA_A (INT_SUM[84]), .DATA_B (INT_SUM[85]), .DATA_C (INT_CARRY[61]), .SAVE (INT_SUM[86]), .CARRY (INT_CARRY[71]) );
+ assign INT_SUM[87] = INT_CARRY[62];
+ smfulladder dfa56 (.DATA_A (INT_SUM[86]), .DATA_B (INT_SUM[87]), .DATA_C (INT_CARRY[63]), .SAVE (INT_SUM[88]), .CARRY (INT_CARRY[72]) );
+ assign INT_SUM[89] = INT_CARRY[64];
+ smhalfadder dha15 (.DATA_A (INT_SUM[88]), .DATA_B (INT_SUM[89]), .SAVE (INT_SUM[90]), .CARRY (INT_CARRY[65]) );
+ smffb dla132 (.D(INT_SUM[90]), .clk(clk), .en_d2(en_d2), .Q(SUM[17]) );
+ smffb dla133 (.D(INT_CARRY[65]), .clk(clk), .en_d2(en_d2), .Q(CARRY[17]) );
+ smffa dla134 (.D(SUMMAND[99]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[99]) );
+ smffa dla135 (.D(SUMMAND[100]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[100]) );
+ smffa dla136 (.D(SUMMAND[101]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[101]) );
+ smfulladder dfa57 (.DATA_A (LATCHED_PP[99]), .DATA_B (LATCHED_PP[100]), .DATA_C (LATCHED_PP[101]), .SAVE (INT_SUM[91]), .CARRY (INT_CARRY[74]) );
+ smffa dla137 (.D(SUMMAND[102]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[102]) );
+ smffa dla138 (.D(SUMMAND[103]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[103]) );
+ smffa dla139 (.D(SUMMAND[104]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[104]) );
+ smfulladder dfa58 (.DATA_A (LATCHED_PP[102]), .DATA_B (LATCHED_PP[103]), .DATA_C (LATCHED_PP[104]), .SAVE (INT_SUM[92]), .CARRY (INT_CARRY[75]) );
+ smffa dla140 (.D(SUMMAND[105]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[105]) );
+ smffa dla141 (.D(SUMMAND[106]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[106]) );
+ smffa dla142 (.D(SUMMAND[107]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[107]) );
+ smfulladder dfa59 (.DATA_A (LATCHED_PP[105]), .DATA_B (LATCHED_PP[106]), .DATA_C (LATCHED_PP[107]), .SAVE (INT_SUM[93]), .CARRY (INT_CARRY[76]) );
+ smffa dla143 (.D(SUMMAND[108]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[108]) );
+ assign INT_SUM[94] = LATCHED_PP[108];
+ smffa dla144 (.D(SUMMAND[109]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[109]) );
+ assign INT_SUM[95] = LATCHED_PP[109];
+ smfulladder dfa60 (.DATA_A (INT_SUM[91]), .DATA_B (INT_SUM[92]), .DATA_C (INT_SUM[93]), .SAVE (INT_SUM[96]), .CARRY (INT_CARRY[77]) );
+ smfulladder dfa61 (.DATA_A (INT_SUM[94]), .DATA_B (INT_SUM[95]), .DATA_C (INT_CARRY[66]), .SAVE (INT_SUM[97]), .CARRY (INT_CARRY[78]) );
+ assign INT_SUM[98] = INT_CARRY[67];
+ assign INT_SUM[99] = INT_CARRY[68];
+ smfulladder dfa62 (.DATA_A (INT_SUM[96]), .DATA_B (INT_SUM[97]), .DATA_C (INT_SUM[98]), .SAVE (INT_SUM[100]), .CARRY (INT_CARRY[79]) );
+ smfulladder dfa63 (.DATA_A (INT_SUM[99]), .DATA_B (INT_CARRY[69]), .DATA_C (INT_CARRY[70]), .SAVE (INT_SUM[101]), .CARRY (INT_CARRY[80]) );
+ smfulladder dfa64 (.DATA_A (INT_SUM[100]), .DATA_B (INT_SUM[101]), .DATA_C (INT_CARRY[71]), .SAVE (INT_SUM[102]), .CARRY (INT_CARRY[81]) );
+ smhalfadder dha16 (.DATA_A (INT_SUM[102]), .DATA_B (INT_CARRY[72]), .SAVE (INT_SUM[103]), .CARRY (INT_CARRY[73]) );
+ smffb dla145 (.D(INT_SUM[103]), .clk(clk), .en_d2(en_d2), .Q(SUM[18]) );
+ smffb dla146 (.D(INT_CARRY[73]), .clk(clk), .en_d2(en_d2), .Q(CARRY[18]) );
+ smffa dla147 (.D(SUMMAND[110]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[110]) );
+ smffa dla148 (.D(SUMMAND[111]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[111]) );
+ smffa dla149 (.D(SUMMAND[112]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[112]) );
+ smfulladder dfa65 (.DATA_A (LATCHED_PP[110]), .DATA_B (LATCHED_PP[111]), .DATA_C (LATCHED_PP[112]), .SAVE (INT_SUM[104]), .CARRY (INT_CARRY[83]) );
+ smffa dla150 (.D(SUMMAND[113]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[113]) );
+ smffa dla151 (.D(SUMMAND[114]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[114]) );
+ smffa dla152 (.D(SUMMAND[115]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[115]) );
+ smfulladder dfa66 (.DATA_A (LATCHED_PP[113]), .DATA_B (LATCHED_PP[114]), .DATA_C (LATCHED_PP[115]), .SAVE (INT_SUM[105]), .CARRY (INT_CARRY[84]) );
+ smffa dla153 (.D(SUMMAND[116]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[116]) );
+ smffa dla154 (.D(SUMMAND[117]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[117]) );
+ smffa dla155 (.D(SUMMAND[118]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[118]) );
+ smfulladder dfa67 (.DATA_A (LATCHED_PP[116]), .DATA_B (LATCHED_PP[117]), .DATA_C (LATCHED_PP[118]), .SAVE (INT_SUM[106]), .CARRY (INT_CARRY[85]) );
+ smffa dla156 (.D(SUMMAND[119]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[119]) );
+ assign INT_SUM[107] = LATCHED_PP[119];
+ smfulladder dfa68 (.DATA_A (INT_SUM[104]), .DATA_B (INT_SUM[105]), .DATA_C (INT_SUM[106]), .SAVE (INT_SUM[108]), .CARRY (INT_CARRY[86]) );
+ smfulladder dfa69 (.DATA_A (INT_SUM[107]), .DATA_B (INT_CARRY[74]), .DATA_C (INT_CARRY[75]), .SAVE (INT_SUM[109]), .CARRY (INT_CARRY[87]) );
+ assign INT_SUM[110] = INT_CARRY[76];
+ smfulladder dfa70 (.DATA_A (INT_SUM[108]), .DATA_B (INT_SUM[109]), .DATA_C (INT_SUM[110]), .SAVE (INT_SUM[111]), .CARRY (INT_CARRY[88]) );
+ smhalfadder dha17 (.DATA_A (INT_CARRY[77]), .DATA_B (INT_CARRY[78]), .SAVE (INT_SUM[112]), .CARRY (INT_CARRY[89]) );
+ smfulladder dfa71 (.DATA_A (INT_SUM[111]), .DATA_B (INT_SUM[112]), .DATA_C (INT_CARRY[79]), .SAVE (INT_SUM[113]), .CARRY (INT_CARRY[90]) );
+ assign INT_SUM[114] = INT_CARRY[80];
+ smfulladder dfa72 (.DATA_A (INT_SUM[113]), .DATA_B (INT_SUM[114]), .DATA_C (INT_CARRY[81]), .SAVE (INT_SUM[115]), .CARRY (INT_CARRY[82]) );
+ smffb dla157 (.D(INT_SUM[115]), .clk(clk), .en_d2(en_d2), .Q(SUM[19]) );
+ smffb dla158 (.D(INT_CARRY[82]), .clk(clk), .en_d2(en_d2), .Q(CARRY[19]) );
+ smffa dla159 (.D(SUMMAND[120]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[120]) );
+ smffa dla160 (.D(SUMMAND[121]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[121]) );
+ smffa dla161 (.D(SUMMAND[122]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[122]) );
+ smfulladder dfa73 (.DATA_A (LATCHED_PP[120]), .DATA_B (LATCHED_PP[121]), .DATA_C (LATCHED_PP[122]), .SAVE (INT_SUM[116]), .CARRY (INT_CARRY[92]) );
+ smffa dla162 (.D(SUMMAND[123]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[123]) );
+ smffa dla163 (.D(SUMMAND[124]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[124]) );
+ smffa dla164 (.D(SUMMAND[125]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[125]) );
+ smfulladder dfa74 (.DATA_A (LATCHED_PP[123]), .DATA_B (LATCHED_PP[124]), .DATA_C (LATCHED_PP[125]), .SAVE (INT_SUM[117]), .CARRY (INT_CARRY[93]) );
+ smffa dla165 (.D(SUMMAND[126]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[126]) );
+ smffa dla166 (.D(SUMMAND[127]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[127]) );
+ smffa dla167 (.D(SUMMAND[128]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[128]) );
+ smfulladder dfa75 (.DATA_A (LATCHED_PP[126]), .DATA_B (LATCHED_PP[127]), .DATA_C (LATCHED_PP[128]), .SAVE (INT_SUM[118]), .CARRY (INT_CARRY[94]) );
+ smffa dla168 (.D(SUMMAND[129]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[129]) );
+ smffa dla169 (.D(SUMMAND[130]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[130]) );
+ smffa dla170 (.D(SUMMAND[131]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[131]) );
+ smfulladder dfa76 (.DATA_A (LATCHED_PP[129]), .DATA_B (LATCHED_PP[130]), .DATA_C (LATCHED_PP[131]), .SAVE (INT_SUM[119]), .CARRY (INT_CARRY[95]) );
+ smfulladder dfa77 (.DATA_A (INT_SUM[116]), .DATA_B (INT_SUM[117]), .DATA_C (INT_SUM[118]), .SAVE (INT_SUM[120]), .CARRY (INT_CARRY[96]) );
+ smfulladder dfa78 (.DATA_A (INT_SUM[119]), .DATA_B (INT_CARRY[83]), .DATA_C (INT_CARRY[84]), .SAVE (INT_SUM[121]), .CARRY (INT_CARRY[97]) );
+ assign INT_SUM[122] = INT_CARRY[85];
+ smfulladder dfa79 (.DATA_A (INT_SUM[120]), .DATA_B (INT_SUM[121]), .DATA_C (INT_SUM[122]), .SAVE (INT_SUM[123]), .CARRY (INT_CARRY[98]) );
+ smhalfadder dha18 (.DATA_A (INT_CARRY[86]), .DATA_B (INT_CARRY[87]), .SAVE (INT_SUM[124]), .CARRY (INT_CARRY[99]) );
+ smfulladder dfa80 (.DATA_A (INT_SUM[123]), .DATA_B (INT_SUM[124]), .DATA_C (INT_CARRY[88]), .SAVE (INT_SUM[125]), .CARRY (INT_CARRY[100]) );
+ assign INT_SUM[126] = INT_CARRY[89];
+ smfulladder dfa81 (.DATA_A (INT_SUM[125]), .DATA_B (INT_SUM[126]), .DATA_C (INT_CARRY[90]), .SAVE (INT_SUM[127]), .CARRY (INT_CARRY[91]) );
+ smffb dla171 (.D(INT_SUM[127]), .clk(clk), .en_d2(en_d2), .Q(SUM[20]) );
+ smffb dla172 (.D(INT_CARRY[91]), .clk(clk), .en_d2(en_d2), .Q(CARRY[20]) );
+ smffa dla173 (.D(SUMMAND[132]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[132]) );
+ smffa dla174 (.D(SUMMAND[133]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[133]) );
+ smffa dla175 (.D(SUMMAND[134]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[134]) );
+ smfulladder dfa82 (.DATA_A (LATCHED_PP[132]), .DATA_B (LATCHED_PP[133]), .DATA_C (LATCHED_PP[134]), .SAVE (INT_SUM[128]), .CARRY (INT_CARRY[102]) );
+ smffa dla176 (.D(SUMMAND[135]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[135]) );
+ smffa dla177 (.D(SUMMAND[136]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[136]) );
+ smffa dla178 (.D(SUMMAND[137]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[137]) );
+ smfulladder dfa83 (.DATA_A (LATCHED_PP[135]), .DATA_B (LATCHED_PP[136]), .DATA_C (LATCHED_PP[137]), .SAVE (INT_SUM[129]), .CARRY (INT_CARRY[103]) );
+ smffa dla179 (.D(SUMMAND[138]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[138]) );
+ smffa dla180 (.D(SUMMAND[139]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[139]) );
+ smffa dla181 (.D(SUMMAND[140]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[140]) );
+ smfulladder dfa84 (.DATA_A (LATCHED_PP[138]), .DATA_B (LATCHED_PP[139]), .DATA_C (LATCHED_PP[140]), .SAVE (INT_SUM[130]), .CARRY (INT_CARRY[104]) );
+ smffa dla182 (.D(SUMMAND[141]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[141]) );
+ assign INT_SUM[131] = LATCHED_PP[141];
+ smffa dla183 (.D(SUMMAND[142]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[142]) );
+ assign INT_SUM[132] = LATCHED_PP[142];
+ smfulladder dfa85 (.DATA_A (INT_SUM[128]), .DATA_B (INT_SUM[129]), .DATA_C (INT_SUM[130]), .SAVE (INT_SUM[133]), .CARRY (INT_CARRY[105]) );
+ smfulladder dfa86 (.DATA_A (INT_SUM[131]), .DATA_B (INT_SUM[132]), .DATA_C (INT_CARRY[92]), .SAVE (INT_SUM[134]), .CARRY (INT_CARRY[106]) );
+ smfulladder dfa87 (.DATA_A (INT_CARRY[93]), .DATA_B (INT_CARRY[94]), .DATA_C (INT_CARRY[95]), .SAVE (INT_SUM[135]), .CARRY (INT_CARRY[107]) );
+ smfulladder dfa88 (.DATA_A (INT_SUM[133]), .DATA_B (INT_SUM[134]), .DATA_C (INT_SUM[135]), .SAVE (INT_SUM[136]), .CARRY (INT_CARRY[108]) );
+ smhalfadder dha19 (.DATA_A (INT_CARRY[96]), .DATA_B (INT_CARRY[97]), .SAVE (INT_SUM[137]), .CARRY (INT_CARRY[109]) );
+ smfulladder dfa89 (.DATA_A (INT_SUM[136]), .DATA_B (INT_SUM[137]), .DATA_C (INT_CARRY[98]), .SAVE (INT_SUM[138]), .CARRY (INT_CARRY[110]) );
+ assign INT_SUM[139] = INT_CARRY[99];
+ smfulladder dfa90 (.DATA_A (INT_SUM[138]), .DATA_B (INT_SUM[139]), .DATA_C (INT_CARRY[100]), .SAVE (INT_SUM[140]), .CARRY (INT_CARRY[101]) );
+ smffb dla184 (.D(INT_SUM[140]), .clk(clk), .en_d2(en_d2), .Q(SUM[21]) );
+ smffb dla185 (.D(INT_CARRY[101]), .clk(clk), .en_d2(en_d2), .Q(CARRY[21]) );
+ smffa dla186 (.D(SUMMAND[143]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[143]) );
+ smffa dla187 (.D(SUMMAND[144]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[144]) );
+ smffa dla188 (.D(SUMMAND[145]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[145]) );
+ smfulladder dfa91 (.DATA_A (LATCHED_PP[143]), .DATA_B (LATCHED_PP[144]), .DATA_C (LATCHED_PP[145]), .SAVE (INT_SUM[141]), .CARRY (INT_CARRY[112]) );
+ smffa dla189 (.D(SUMMAND[146]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[146]) );
+ smffa dla190 (.D(SUMMAND[147]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[147]) );
+ smffa dla191 (.D(SUMMAND[148]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[148]) );
+ smfulladder dfa92 (.DATA_A (LATCHED_PP[146]), .DATA_B (LATCHED_PP[147]), .DATA_C (LATCHED_PP[148]), .SAVE (INT_SUM[142]), .CARRY (INT_CARRY[113]) );
+ smffa dla192 (.D(SUMMAND[149]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[149]) );
+ smffa dla193 (.D(SUMMAND[150]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[150]) );
+ smffa dla194 (.D(SUMMAND[151]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[151]) );
+ smfulladder dfa93 (.DATA_A (LATCHED_PP[149]), .DATA_B (LATCHED_PP[150]), .DATA_C (LATCHED_PP[151]), .SAVE (INT_SUM[143]), .CARRY (INT_CARRY[114]) );
+ smffa dla195 (.D(SUMMAND[152]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[152]) );
+ smffa dla196 (.D(SUMMAND[153]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[153]) );
+ smffa dla197 (.D(SUMMAND[154]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[154]) );
+ smfulladder dfa94 (.DATA_A (LATCHED_PP[152]), .DATA_B (LATCHED_PP[153]), .DATA_C (LATCHED_PP[154]), .SAVE (INT_SUM[144]), .CARRY (INT_CARRY[115]) );
+ smffa dla198 (.D(SUMMAND[155]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[155]) );
+ assign INT_SUM[145] = LATCHED_PP[155];
+ smfulladder dfa95 (.DATA_A (INT_SUM[141]), .DATA_B (INT_SUM[142]), .DATA_C (INT_SUM[143]), .SAVE (INT_SUM[146]), .CARRY (INT_CARRY[116]) );
+ smfulladder dfa96 (.DATA_A (INT_SUM[144]), .DATA_B (INT_SUM[145]), .DATA_C (INT_CARRY[102]), .SAVE (INT_SUM[147]), .CARRY (INT_CARRY[117]) );
+ smhalfadder dha20 (.DATA_A (INT_CARRY[103]), .DATA_B (INT_CARRY[104]), .SAVE (INT_SUM[148]), .CARRY (INT_CARRY[118]) );
+ smfulladder dfa97 (.DATA_A (INT_SUM[146]), .DATA_B (INT_SUM[147]), .DATA_C (INT_SUM[148]), .SAVE (INT_SUM[149]), .CARRY (INT_CARRY[119]) );
+ smfulladder dfa98 (.DATA_A (INT_CARRY[105]), .DATA_B (INT_CARRY[106]), .DATA_C (INT_CARRY[107]), .SAVE (INT_SUM[150]), .CARRY (INT_CARRY[120]) );
+ smfulladder dfa99 (.DATA_A (INT_SUM[149]), .DATA_B (INT_SUM[150]), .DATA_C (INT_CARRY[108]), .SAVE (INT_SUM[151]), .CARRY (INT_CARRY[121]) );
+ assign INT_SUM[152] = INT_CARRY[109];
+ smfulladder dfa100 (.DATA_A (INT_SUM[151]), .DATA_B (INT_SUM[152]), .DATA_C (INT_CARRY[110]), .SAVE (INT_SUM[153]), .CARRY (INT_CARRY[111]) );
+ smffb dla199 (.D(INT_SUM[153]), .clk(clk), .en_d2(en_d2), .Q(SUM[22]) );
+ smffb dla200 (.D(INT_CARRY[111]), .clk(clk), .en_d2(en_d2), .Q(CARRY[22]) );
+ smffa dla201 (.D(SUMMAND[156]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[156]) );
+ smffa dla202 (.D(SUMMAND[157]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[157]) );
+ smffa dla203 (.D(SUMMAND[158]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[158]) );
+ smfulladder dfa101 (.DATA_A (LATCHED_PP[156]), .DATA_B (LATCHED_PP[157]), .DATA_C (LATCHED_PP[158]), .SAVE (INT_SUM[154]), .CARRY (INT_CARRY[123]) );
+ smffa dla204 (.D(SUMMAND[159]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[159]) );
+ smffa dla205 (.D(SUMMAND[160]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[160]) );
+ smffa dla206 (.D(SUMMAND[161]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[161]) );
+ smfulladder dfa102 (.DATA_A (LATCHED_PP[159]), .DATA_B (LATCHED_PP[160]), .DATA_C (LATCHED_PP[161]), .SAVE (INT_SUM[155]), .CARRY (INT_CARRY[124]) );
+ smffa dla207 (.D(SUMMAND[162]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[162]) );
+ smffa dla208 (.D(SUMMAND[163]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[163]) );
+ smffa dla209 (.D(SUMMAND[164]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[164]) );
+ smfulladder dfa103 (.DATA_A (LATCHED_PP[162]), .DATA_B (LATCHED_PP[163]), .DATA_C (LATCHED_PP[164]), .SAVE (INT_SUM[156]), .CARRY (INT_CARRY[125]) );
+ smffa dla210 (.D(SUMMAND[165]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[165]) );
+ smffa dla211 (.D(SUMMAND[166]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[166]) );
+ smffa dla212 (.D(SUMMAND[167]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[167]) );
+ smfulladder dfa104 (.DATA_A (LATCHED_PP[165]), .DATA_B (LATCHED_PP[166]), .DATA_C (LATCHED_PP[167]), .SAVE (INT_SUM[157]), .CARRY (INT_CARRY[126]) );
+ smfulladder dfa105 (.DATA_A (INT_SUM[154]), .DATA_B (INT_SUM[155]), .DATA_C (INT_SUM[156]), .SAVE (INT_SUM[158]), .CARRY (INT_CARRY[127]) );
+ smfulladder dfa106 (.DATA_A (INT_SUM[157]), .DATA_B (INT_CARRY[112]), .DATA_C (INT_CARRY[113]), .SAVE (INT_SUM[159]), .CARRY (INT_CARRY[128]) );
+ smhalfadder dha21 (.DATA_A (INT_CARRY[114]), .DATA_B (INT_CARRY[115]), .SAVE (INT_SUM[160]), .CARRY (INT_CARRY[129]) );
+ smfulladder dfa107 (.DATA_A (INT_SUM[158]), .DATA_B (INT_SUM[159]), .DATA_C (INT_SUM[160]), .SAVE (INT_SUM[161]), .CARRY (INT_CARRY[130]) );
+ smfulladder dfa108 (.DATA_A (INT_CARRY[116]), .DATA_B (INT_CARRY[117]), .DATA_C (INT_CARRY[118]), .SAVE (INT_SUM[162]), .CARRY (INT_CARRY[131]) );
+ smfulladder dfa109 (.DATA_A (INT_SUM[161]), .DATA_B (INT_SUM[162]), .DATA_C (INT_CARRY[119]), .SAVE (INT_SUM[163]), .CARRY (INT_CARRY[132]) );
+ assign INT_SUM[164] = INT_CARRY[120];
+ smfulladder dfa110 (.DATA_A (INT_SUM[163]), .DATA_B (INT_SUM[164]), .DATA_C (INT_CARRY[121]), .SAVE (INT_SUM[165]), .CARRY (INT_CARRY[122]) );
+ smffb dla213 (.D(INT_SUM[165]), .clk(clk), .en_d2(en_d2), .Q(SUM[23]) );
+ smffb dla214 (.D(INT_CARRY[122]), .clk(clk), .en_d2(en_d2), .Q(CARRY[23]) );
+ smffa dla215 (.D(SUMMAND[168]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[168]) );
+ smffa dla216 (.D(SUMMAND[169]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[169]) );
+ smffa dla217 (.D(SUMMAND[170]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[170]) );
+ smfulladder dfa111 (.DATA_A (LATCHED_PP[168]), .DATA_B (LATCHED_PP[169]), .DATA_C (LATCHED_PP[170]), .SAVE (INT_SUM[166]), .CARRY (INT_CARRY[134]) );
+ smffa dla218 (.D(SUMMAND[171]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[171]) );
+ smffa dla219 (.D(SUMMAND[172]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[172]) );
+ smffa dla220 (.D(SUMMAND[173]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[173]) );
+ smfulladder dfa112 (.DATA_A (LATCHED_PP[171]), .DATA_B (LATCHED_PP[172]), .DATA_C (LATCHED_PP[173]), .SAVE (INT_SUM[167]), .CARRY (INT_CARRY[135]) );
+ smffa dla221 (.D(SUMMAND[174]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[174]) );
+ smffa dla222 (.D(SUMMAND[175]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[175]) );
+ smffa dla223 (.D(SUMMAND[176]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[176]) );
+ smfulladder dfa113 (.DATA_A (LATCHED_PP[174]), .DATA_B (LATCHED_PP[175]), .DATA_C (LATCHED_PP[176]), .SAVE (INT_SUM[168]), .CARRY (INT_CARRY[136]) );
+ smffa dla224 (.D(SUMMAND[177]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[177]) );
+ smffa dla225 (.D(SUMMAND[178]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[178]) );
+ smffa dla226 (.D(SUMMAND[179]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[179]) );
+ smfulladder dfa114 (.DATA_A (LATCHED_PP[177]), .DATA_B (LATCHED_PP[178]), .DATA_C (LATCHED_PP[179]), .SAVE (INT_SUM[169]), .CARRY (INT_CARRY[137]) );
+ smffa dla227 (.D(SUMMAND[180]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[180]) );
+ smffa dla228 (.D(SUMMAND[181]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[181]) );
+ smhalfadder dha22 (.DATA_A (LATCHED_PP[180]), .DATA_B (LATCHED_PP[181]), .SAVE (INT_SUM[170]), .CARRY (INT_CARRY[138]) );
+ smfulladder dfa115 (.DATA_A (INT_SUM[166]), .DATA_B (INT_SUM[167]), .DATA_C (INT_SUM[168]), .SAVE (INT_SUM[171]), .CARRY (INT_CARRY[139]) );
+ smfulladder dfa116 (.DATA_A (INT_SUM[169]), .DATA_B (INT_SUM[170]), .DATA_C (INT_CARRY[123]), .SAVE (INT_SUM[172]), .CARRY (INT_CARRY[140]) );
+ smfulladder dfa117 (.DATA_A (INT_CARRY[124]), .DATA_B (INT_CARRY[125]), .DATA_C (INT_CARRY[126]), .SAVE (INT_SUM[173]), .CARRY (INT_CARRY[141]) );
+ smfulladder dfa118 (.DATA_A (INT_SUM[171]), .DATA_B (INT_SUM[172]), .DATA_C (INT_SUM[173]), .SAVE (INT_SUM[174]), .CARRY (INT_CARRY[142]) );
+ smfulladder dfa119 (.DATA_A (INT_CARRY[127]), .DATA_B (INT_CARRY[128]), .DATA_C (INT_CARRY[129]), .SAVE (INT_SUM[175]), .CARRY (INT_CARRY[143]) );
+ smfulladder dfa120 (.DATA_A (INT_SUM[174]), .DATA_B (INT_SUM[175]), .DATA_C (INT_CARRY[130]), .SAVE (INT_SUM[176]), .CARRY (INT_CARRY[144]) );
+ assign INT_SUM[177] = INT_CARRY[131];
+ smfulladder dfa121 (.DATA_A (INT_SUM[176]), .DATA_B (INT_SUM[177]), .DATA_C (INT_CARRY[132]), .SAVE (INT_SUM[178]), .CARRY (INT_CARRY[133]) );
+ smffb dla229 (.D(INT_SUM[178]), .clk(clk), .en_d2(en_d2), .Q(SUM[24]) );
+ smffb dla230 (.D(INT_CARRY[133]), .clk(clk), .en_d2(en_d2), .Q(CARRY[24]) );
+ smffa dla231 (.D(SUMMAND[182]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[182]) );
+ smffa dla232 (.D(SUMMAND[183]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[183]) );
+ smffa dla233 (.D(SUMMAND[184]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[184]) );
+ smfulladder dfa122 (.DATA_A (LATCHED_PP[182]), .DATA_B (LATCHED_PP[183]), .DATA_C (LATCHED_PP[184]), .SAVE (INT_SUM[179]), .CARRY (INT_CARRY[146]) );
+ smffa dla234 (.D(SUMMAND[185]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[185]) );
+ smffa dla235 (.D(SUMMAND[186]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[186]) );
+ smffa dla236 (.D(SUMMAND[187]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[187]) );
+ smfulladder dfa123 (.DATA_A (LATCHED_PP[185]), .DATA_B (LATCHED_PP[186]), .DATA_C (LATCHED_PP[187]), .SAVE (INT_SUM[180]), .CARRY (INT_CARRY[147]) );
+ smffa dla237 (.D(SUMMAND[188]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[188]) );
+ smffa dla238 (.D(SUMMAND[189]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[189]) );
+ smffa dla239 (.D(SUMMAND[190]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[190]) );
+ smfulladder dfa124 (.DATA_A (LATCHED_PP[188]), .DATA_B (LATCHED_PP[189]), .DATA_C (LATCHED_PP[190]), .SAVE (INT_SUM[181]), .CARRY (INT_CARRY[148]) );
+ smffa dla240 (.D(SUMMAND[191]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[191]) );
+ smffa dla241 (.D(SUMMAND[192]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[192]) );
+ smffa dla242 (.D(SUMMAND[193]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[193]) );
+ smfulladder dfa125 (.DATA_A (LATCHED_PP[191]), .DATA_B (LATCHED_PP[192]), .DATA_C (LATCHED_PP[193]), .SAVE (INT_SUM[182]), .CARRY (INT_CARRY[149]) );
+ smffa dla243 (.D(SUMMAND[194]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[194]) );
+ assign INT_SUM[183] = LATCHED_PP[194];
+ smfulladder dfa126 (.DATA_A (INT_SUM[179]), .DATA_B (INT_SUM[180]), .DATA_C (INT_SUM[181]), .SAVE (INT_SUM[184]), .CARRY (INT_CARRY[150]) );
+ smfulladder dfa127 (.DATA_A (INT_SUM[182]), .DATA_B (INT_SUM[183]), .DATA_C (INT_CARRY[134]), .SAVE (INT_SUM[185]), .CARRY (INT_CARRY[151]) );
+ smfulladder dfa128 (.DATA_A (INT_CARRY[135]), .DATA_B (INT_CARRY[136]), .DATA_C (INT_CARRY[137]), .SAVE (INT_SUM[186]), .CARRY (INT_CARRY[152]) );
+ assign INT_SUM[187] = INT_CARRY[138];
+ smfulladder dfa129 (.DATA_A (INT_SUM[184]), .DATA_B (INT_SUM[185]), .DATA_C (INT_SUM[186]), .SAVE (INT_SUM[188]), .CARRY (INT_CARRY[153]) );
+ smfulladder dfa130 (.DATA_A (INT_SUM[187]), .DATA_B (INT_CARRY[139]), .DATA_C (INT_CARRY[140]), .SAVE (INT_SUM[189]), .CARRY (INT_CARRY[154]) );
+ assign INT_SUM[190] = INT_CARRY[141];
+ smfulladder dfa131 (.DATA_A (INT_SUM[188]), .DATA_B (INT_SUM[189]), .DATA_C (INT_SUM[190]), .SAVE (INT_SUM[191]), .CARRY (INT_CARRY[155]) );
+ smhalfadder dha23 (.DATA_A (INT_CARRY[142]), .DATA_B (INT_CARRY[143]), .SAVE (INT_SUM[192]), .CARRY (INT_CARRY[156]) );
+ smfulladder dfa132 (.DATA_A (INT_SUM[191]), .DATA_B (INT_SUM[192]), .DATA_C (INT_CARRY[144]), .SAVE (INT_SUM[193]), .CARRY (INT_CARRY[145]) );
+ smffb dla244 (.D(INT_SUM[193]), .clk(clk), .en_d2(en_d2), .Q(SUM[25]) );
+ smffb dla245 (.D(INT_CARRY[145]), .clk(clk), .en_d2(en_d2), .Q(CARRY[25]) );
+ smffa dla246 (.D(SUMMAND[195]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[195]) );
+ smffa dla247 (.D(SUMMAND[196]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[196]) );
+ smffa dla248 (.D(SUMMAND[197]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[197]) );
+ smfulladder dfa133 (.DATA_A (LATCHED_PP[195]), .DATA_B (LATCHED_PP[196]), .DATA_C (LATCHED_PP[197]), .SAVE (INT_SUM[194]), .CARRY (INT_CARRY[158]) );
+ smffa dla249 (.D(SUMMAND[198]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[198]) );
+ smffa dla250 (.D(SUMMAND[199]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[199]) );
+ smffa dla251 (.D(SUMMAND[200]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[200]) );
+ smfulladder dfa134 (.DATA_A (LATCHED_PP[198]), .DATA_B (LATCHED_PP[199]), .DATA_C (LATCHED_PP[200]), .SAVE (INT_SUM[195]), .CARRY (INT_CARRY[159]) );
+ smffa dla252 (.D(SUMMAND[201]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[201]) );
+ smffa dla253 (.D(SUMMAND[202]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[202]) );
+ smffa dla254 (.D(SUMMAND[203]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[203]) );
+ smfulladder dfa135 (.DATA_A (LATCHED_PP[201]), .DATA_B (LATCHED_PP[202]), .DATA_C (LATCHED_PP[203]), .SAVE (INT_SUM[196]), .CARRY (INT_CARRY[160]) );
+ smffa dla255 (.D(SUMMAND[204]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[204]) );
+ smffa dla256 (.D(SUMMAND[205]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[205]) );
+ smffa dla257 (.D(SUMMAND[206]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[206]) );
+ smfulladder dfa136 (.DATA_A (LATCHED_PP[204]), .DATA_B (LATCHED_PP[205]), .DATA_C (LATCHED_PP[206]), .SAVE (INT_SUM[197]), .CARRY (INT_CARRY[161]) );
+ smffa dla258 (.D(SUMMAND[207]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[207]) );
+ smffa dla259 (.D(SUMMAND[208]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[208]) );
+ smffa dla260 (.D(SUMMAND[209]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[209]) );
+ smfulladder dfa137 (.DATA_A (LATCHED_PP[207]), .DATA_B (LATCHED_PP[208]), .DATA_C (LATCHED_PP[209]), .SAVE (INT_SUM[198]), .CARRY (INT_CARRY[162]) );
+ smfulladder dfa138 (.DATA_A (INT_SUM[194]), .DATA_B (INT_SUM[195]), .DATA_C (INT_SUM[196]), .SAVE (INT_SUM[199]), .CARRY (INT_CARRY[163]) );
+ smfulladder dfa139 (.DATA_A (INT_SUM[197]), .DATA_B (INT_SUM[198]), .DATA_C (INT_CARRY[146]), .SAVE (INT_SUM[200]), .CARRY (INT_CARRY[164]) );
+ smfulladder dfa140 (.DATA_A (INT_CARRY[147]), .DATA_B (INT_CARRY[148]), .DATA_C (INT_CARRY[149]), .SAVE (INT_SUM[201]), .CARRY (INT_CARRY[165]) );
+ smfulladder dfa141 (.DATA_A (INT_SUM[199]), .DATA_B (INT_SUM[200]), .DATA_C (INT_SUM[201]), .SAVE (INT_SUM[202]), .CARRY (INT_CARRY[166]) );
+ smfulladder dfa142 (.DATA_A (INT_CARRY[150]), .DATA_B (INT_CARRY[151]), .DATA_C (INT_CARRY[152]), .SAVE (INT_SUM[203]), .CARRY (INT_CARRY[167]) );
+ smfulladder dfa143 (.DATA_A (INT_SUM[202]), .DATA_B (INT_SUM[203]), .DATA_C (INT_CARRY[153]), .SAVE (INT_SUM[204]), .CARRY (INT_CARRY[168]) );
+ assign INT_SUM[205] = INT_CARRY[154];
+ smfulladder dfa144 (.DATA_A (INT_SUM[204]), .DATA_B (INT_SUM[205]), .DATA_C (INT_CARRY[155]), .SAVE (INT_SUM[206]), .CARRY (INT_CARRY[169]) );
+ assign INT_SUM[207] = INT_CARRY[156];
+ smhalfadder dha24 (.DATA_A (INT_SUM[206]), .DATA_B (INT_SUM[207]), .SAVE (INT_SUM[208]), .CARRY (INT_CARRY[157]) );
+ smffb dla261 (.D(INT_SUM[208]), .clk(clk), .en_d2(en_d2), .Q(SUM[26]) );
+ smffb dla262 (.D(INT_CARRY[157]), .clk(clk), .en_d2(en_d2), .Q(CARRY[26]) );
+ smffa dla263 (.D(SUMMAND[210]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[210]) );
+ smffa dla264 (.D(SUMMAND[211]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[211]) );
+ smffa dla265 (.D(SUMMAND[212]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[212]) );
+ smfulladder dfa145 (.DATA_A (LATCHED_PP[210]), .DATA_B (LATCHED_PP[211]), .DATA_C (LATCHED_PP[212]), .SAVE (INT_SUM[209]), .CARRY (INT_CARRY[171]) );
+ smffa dla266 (.D(SUMMAND[213]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[213]) );
+ smffa dla267 (.D(SUMMAND[214]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[214]) );
+ smffa dla268 (.D(SUMMAND[215]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[215]) );
+ smfulladder dfa146 (.DATA_A (LATCHED_PP[213]), .DATA_B (LATCHED_PP[214]), .DATA_C (LATCHED_PP[215]), .SAVE (INT_SUM[210]), .CARRY (INT_CARRY[172]) );
+ smffa dla269 (.D(SUMMAND[216]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[216]) );
+ smffa dla270 (.D(SUMMAND[217]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[217]) );
+ smffa dla271 (.D(SUMMAND[218]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[218]) );
+ smfulladder dfa147 (.DATA_A (LATCHED_PP[216]), .DATA_B (LATCHED_PP[217]), .DATA_C (LATCHED_PP[218]), .SAVE (INT_SUM[211]), .CARRY (INT_CARRY[173]) );
+ smffa dla272 (.D(SUMMAND[219]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[219]) );
+ smffa dla273 (.D(SUMMAND[220]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[220]) );
+ smffa dla274 (.D(SUMMAND[221]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[221]) );
+ smfulladder dfa148 (.DATA_A (LATCHED_PP[219]), .DATA_B (LATCHED_PP[220]), .DATA_C (LATCHED_PP[221]), .SAVE (INT_SUM[212]), .CARRY (INT_CARRY[174]) );
+ smffa dla275 (.D(SUMMAND[222]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[222]) );
+ smffa dla276 (.D(SUMMAND[223]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[223]) );
+ smhalfadder dha25 (.DATA_A (LATCHED_PP[222]), .DATA_B (LATCHED_PP[223]), .SAVE (INT_SUM[213]), .CARRY (INT_CARRY[175]) );
+ smfulladder dfa149 (.DATA_A (INT_SUM[209]), .DATA_B (INT_SUM[210]), .DATA_C (INT_SUM[211]), .SAVE (INT_SUM[214]), .CARRY (INT_CARRY[176]) );
+ smfulladder dfa150 (.DATA_A (INT_SUM[212]), .DATA_B (INT_SUM[213]), .DATA_C (INT_CARRY[158]), .SAVE (INT_SUM[215]), .CARRY (INT_CARRY[177]) );
+ smfulladder dfa151 (.DATA_A (INT_CARRY[159]), .DATA_B (INT_CARRY[160]), .DATA_C (INT_CARRY[161]), .SAVE (INT_SUM[216]), .CARRY (INT_CARRY[178]) );
+ assign INT_SUM[217] = INT_CARRY[162];
+ smfulladder dfa152 (.DATA_A (INT_SUM[214]), .DATA_B (INT_SUM[215]), .DATA_C (INT_SUM[216]), .SAVE (INT_SUM[218]), .CARRY (INT_CARRY[179]) );
+ smfulladder dfa153 (.DATA_A (INT_SUM[217]), .DATA_B (INT_CARRY[163]), .DATA_C (INT_CARRY[164]), .SAVE (INT_SUM[219]), .CARRY (INT_CARRY[180]) );
+ assign INT_SUM[220] = INT_CARRY[165];
+ smfulladder dfa154 (.DATA_A (INT_SUM[218]), .DATA_B (INT_SUM[219]), .DATA_C (INT_SUM[220]), .SAVE (INT_SUM[221]), .CARRY (INT_CARRY[181]) );
+ assign INT_SUM[222] = INT_CARRY[166];
+ assign INT_SUM[223] = INT_CARRY[167];
+ smfulladder dfa155 (.DATA_A (INT_SUM[221]), .DATA_B (INT_SUM[222]), .DATA_C (INT_SUM[223]), .SAVE (INT_SUM[224]), .CARRY (INT_CARRY[182]) );
+ assign INT_SUM[225] = INT_CARRY[168];
+ smfulladder dfa156 (.DATA_A (INT_SUM[224]), .DATA_B (INT_SUM[225]), .DATA_C (INT_CARRY[169]), .SAVE (INT_SUM[226]), .CARRY (INT_CARRY[170]) );
+ smffb dla277 (.D(INT_SUM[226]), .clk(clk), .en_d2(en_d2), .Q(SUM[27]) );
+ smffb dla278 (.D(INT_CARRY[170]), .clk(clk), .en_d2(en_d2), .Q(CARRY[27]) );
+ smffa dla279 (.D(SUMMAND[224]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[224]) );
+ smffa dla280 (.D(SUMMAND[225]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[225]) );
+ smffa dla281 (.D(SUMMAND[226]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[226]) );
+ smfulladder dfa157 (.DATA_A (LATCHED_PP[224]), .DATA_B (LATCHED_PP[225]), .DATA_C (LATCHED_PP[226]), .SAVE (INT_SUM[227]), .CARRY (INT_CARRY[184]) );
+ smffa dla282 (.D(SUMMAND[227]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[227]) );
+ smffa dla283 (.D(SUMMAND[228]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[228]) );
+ smffa dla284 (.D(SUMMAND[229]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[229]) );
+ smfulladder dfa158 (.DATA_A (LATCHED_PP[227]), .DATA_B (LATCHED_PP[228]), .DATA_C (LATCHED_PP[229]), .SAVE (INT_SUM[228]), .CARRY (INT_CARRY[185]) );
+ smffa dla285 (.D(SUMMAND[230]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[230]) );
+ smffa dla286 (.D(SUMMAND['b'231]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[231]) );
+ smffa dla287 (.D(SUMMAND[232]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[232]) );
+ smfulladder dfa159 (.DATA_A (LATCHED_PP[230]), .DATA_B (LATCHED_PP[231]), .DATA_C (LATCHED_PP[232]), .SAVE (INT_SUM[229]), .CARRY (INT_CARRY[186]) );
+ smffa dla288 (.D(SUMMAND[233]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[233]) );
+ smffa dla289 (.D(SUMMAND[234]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[234]) );
+ smffa dla290 (.D(SUMMAND[235]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[235]) );
+ smfulladder dfa160 (.DATA_A (LATCHED_PP[233]), .DATA_B (LATCHED_PP[234]), .DATA_C (LATCHED_PP[235]), .SAVE (INT_SUM[230]), .CARRY (INT_CARRY[187]) );
+ smffa dla291 (.D(SUMMAND[236]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[236]) );
+ smffa dla292 (.D(SUMMAND[237]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[237]) );
+ smffa dla293 (.D(SUMMAND[238]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[238]) );
+ smfulladder dfa161 (.DATA_A (LATCHED_PP[236]), .DATA_B (LATCHED_PP[237]), .DATA_C (LATCHED_PP[238]), .SAVE (INT_SUM[231]), .CARRY (INT_CARRY[188]) );
+ smffa dla294 (.D(SUMMAND[239]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[239]) );
+ assign INT_SUM[232] = LATCHED_PP[239];
+ smfulladder dfa162 (.DATA_A (INT_SUM[227]), .DATA_B (INT_SUM[228]), .DATA_C (INT_SUM[229]), .SAVE (INT_SUM[233]), .CARRY (INT_CARRY[189]) );
+ smfulladder dfa163 (.DATA_A (INT_SUM[230]), .DATA_B (INT_SUM[231]), .DATA_C (INT_SUM[232]), .SAVE (INT_SUM[234]), .CARRY (INT_CARRY[190]) );
+ smfulladder dfa164 (.DATA_A (INT_CARRY[171]), .DATA_B (INT_CARRY[172]), .DATA_C (INT_CARRY[173]), .SAVE (INT_SUM[235]), .CARRY (INT_CARRY[191]) );
+ assign INT_SUM[236] = INT_CARRY[174];
+ assign INT_SUM[237] = INT_CARRY[175];
+ smfulladder dfa165 (.DATA_A (INT_SUM[233]), .DATA_B (INT_SUM[234]), .DATA_C (INT_SUM[235]), .SAVE (INT_SUM[238]), .CARRY (INT_CARRY[192]) );
+ smfulladder dfa166 (.DATA_A (INT_SUM[236]), .DATA_B (INT_SUM[237]), .DATA_C (INT_CARRY[176]), .SAVE (INT_SUM[239]), .CARRY (INT_CARRY[193]) );
+ assign INT_SUM[240] = INT_CARRY[177];
+ assign INT_SUM[241] = INT_CARRY[178];
+ smfulladder dfa167 (.DATA_A (INT_SUM[238]), .DATA_B (INT_SUM[239]), .DATA_C (INT_SUM[240]), .SAVE (INT_SUM[242]), .CARRY (INT_CARRY[194]) );
+ smfulladder dfa168 (.DATA_A (INT_SUM[241]), .DATA_B (INT_CARRY[179]), .DATA_C (INT_CARRY[180]), .SAVE (INT_SUM[243]), .CARRY (INT_CARRY[195]) );
+ smfulladder dfa169 (.DATA_A (INT_SUM[242]), .DATA_B (INT_SUM[243]), .DATA_C (INT_CARRY[181]), .SAVE (INT_SUM[244]), .CARRY (INT_CARRY[196]) );
+ smhalfadder dha26 (.DATA_A (INT_SUM[244]), .DATA_B (INT_CARRY[182]), .SAVE (INT_SUM[245]), .CARRY (INT_CARRY[183]) );
+ smffb dla295 (.D(INT_SUM[245]), .clk(clk), .en_d2(en_d2), .Q(SUM[28]) );
+ smffb dla296 (.D(INT_CARRY[183]), .clk(clk), .en_d2(en_d2), .Q(CARRY[28]) );
+ smffa dla297 (.D(SUMMAND[240]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[240]) );
+ smffa dla298 (.D(SUMMAND[241]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[241]) );
+ smffa dla299 (.D(SUMMAND[242]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[242]) );
+ smfulladder dfa170 (.DATA_A (LATCHED_PP[240]), .DATA_B (LATCHED_PP[241]), .DATA_C (LATCHED_PP[242]), .SAVE (INT_SUM[246]), .CARRY (INT_CARRY[198]) );
+ smffa dla300 (.D(SUMMAND[243]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[243]) );
+ smffa dla301 (.D(SUMMAND[244]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[244]) );
+ smffa dla302 (.D(SUMMAND[245]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[245]) );
+ smfulladder dfa171 (.DATA_A (LATCHED_PP[243]), .DATA_B (LATCHED_PP[244]), .DATA_C (LATCHED_PP[245]), .SAVE (INT_SUM[247]), .CARRY (INT_CARRY[199]) );
+ smffa dla303 (.D(SUMMAND[246]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[246]) );
+ smffa dla304 (.D(SUMMAND[247]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[247]) );
+ smffa dla305 (.D(SUMMAND[248]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[248]) );
+ smfulladder dfa172 (.DATA_A (LATCHED_PP[246]), .DATA_B (LATCHED_PP[247]), .DATA_C (LATCHED_PP[248]), .SAVE (INT_SUM[248]), .CARRY (INT_CARRY[200]) );
+ smffa dla306 (.D(SUMMAND[249]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[249]) );
+ smffa dla307 (.D(SUMMAND[250]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[250]) );
+ smffa dla308 (.D(SUMMAND[251]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[251]) );
+ smfulladder dfa173 (.DATA_A (LATCHED_PP[249]), .DATA_B (LATCHED_PP[250]), .DATA_C (LATCHED_PP[251]), .SAVE (INT_SUM[249]), .CARRY (INT_CARRY[201]) );
+ smffa dla309 (.D(SUMMAND[252]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[252]) );
+ smffa dla310 (.D(SUMMAND[253]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[253]) );
+ smffa dla311 (.D(SUMMAND[254]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[254]) );
+ smfulladder dfa174 (.DATA_A (LATCHED_PP[252]), .DATA_B (LATCHED_PP[253]), .DATA_C (LATCHED_PP[254]), .SAVE (INT_SUM[250]), .CARRY (INT_CARRY[202]) );
+ smfulladder dfa175 (.DATA_A (INT_SUM[246]), .DATA_B (INT_SUM[247]), .DATA_C (INT_SUM[248]), .SAVE (INT_SUM[251]), .CARRY (INT_CARRY[203]) );
+ smfulladder dfa176 (.DATA_A (INT_SUM[249]), .DATA_B (INT_SUM[250]), .DATA_C (INT_CARRY[184]), .SAVE (INT_SUM[252]), .CARRY (INT_CARRY[204]) );
+ smfulladder dfa177 (.DATA_A (INT_CARRY[185]), .DATA_B (INT_CARRY[186]), .DATA_C (INT_CARRY[187]), .SAVE (INT_SUM[253]), .CARRY (INT_CARRY[205]) );
+ assign INT_SUM[254] = INT_CARRY[188];
+ smfulladder dfa178 (.DATA_A (INT_SUM[251]), .DATA_B (INT_SUM[252]), .DATA_C (INT_SUM[253]), .SAVE (INT_SUM[255]), .CARRY (INT_CARRY[206]) );
+ smfulladder dfa179 (.DATA_A (INT_SUM[254]), .DATA_B (INT_CARRY[189]), .DATA_C (INT_CARRY[190]), .SAVE (INT_SUM[256]), .CARRY (INT_CARRY[207]) );
+ assign INT_SUM[257] = INT_CARRY[191];
+ smfulladder dfa180 (.DATA_A (INT_SUM[255]), .DATA_B (INT_SUM[256]), .DATA_C (INT_SUM[257]), .SAVE (INT_SUM[258]), .CARRY (INT_CARRY[208]) );
+ smhalfadder dha27 (.DATA_A (INT_CARRY[192]), .DATA_B (INT_CARRY[193]), .SAVE (INT_SUM[259]), .CARRY (INT_CARRY[209]) );
+ smfulladder dfa181 (.DATA_A (INT_SUM[258]), .DATA_B (INT_SUM[259]), .DATA_C (INT_CARRY[194]), .SAVE (INT_SUM[260]), .CARRY (INT_CARRY[210]) );
+ assign INT_SUM[261] = INT_CARRY[195];
+ smfulladder dfa182 (.DATA_A (INT_SUM[260]), .DATA_B (INT_SUM[261]), .DATA_C (INT_CARRY[196]), .SAVE (INT_SUM[262]), .CARRY (INT_CARRY[197]) );
+ smffb dla312 (.D(INT_SUM[262]), .clk(clk), .en_d2(en_d2), .Q(SUM[29]) );
+ smffb dla313 (.D(INT_CARRY[197]), .clk(clk), .en_d2(en_d2), .Q(CARRY[29]) );
+ smffa dla314 (.D(SUMMAND[255]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[255]) );
+ smffa dla315 (.D(SUMMAND[256]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[256]) );
+ smffa dla316 (.D(SUMMAND[257]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[257]) );
+ smfulladder dfa183 (.DATA_A (LATCHED_PP[255]), .DATA_B (LATCHED_PP[256]), .DATA_C (LATCHED_PP[257]), .SAVE (INT_SUM[263]), .CARRY (INT_CARRY[212]) );
+ smffa dla317 (.D(SUMMAND[258]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[258]) );
+ smffa dla318 (.D(SUMMAND[259]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[259]) );
+ smffa dla319 (.D(SUMMAND[260]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[260]) );
+ smfulladder dfa184 (.DATA_A (LATCHED_PP[258]), .DATA_B (LATCHED_PP[259]), .DATA_C (LATCHED_PP[260]), .SAVE (INT_SUM[264]), .CARRY (INT_CARRY[213]) );
+ smffa dla320 (.D(SUMMAND[261]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[261]) );
+ smffa dla321 (.D(SUMMAND[262]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[262]) );
+ smffa dla322 (.D(SUMMAND[263]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[263]) );
+ smfulladder dfa185 (.DATA_A (LATCHED_PP[261]), .DATA_B (LATCHED_PP[262]), .DATA_C (LATCHED_PP[263]), .SAVE (INT_SUM[265]), .CARRY (INT_CARRY[214]) );
+ smffa dla323 (.D(SUMMAND[264]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[264]) );
+ smffa dla324 (.D(SUMMAND[265]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[265]) );
+ smffa dla325 (.D(SUMMAND[266]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[266]) );
+ smfulladder dfa186 (.DATA_A (LATCHED_PP[264]), .DATA_B (LATCHED_PP[265]), .DATA_C (LATCHED_PP[266]), .SAVE (INT_SUM[266]), .CARRY (INT_CARRY[215]) );
+ smffa dla326 (.D(SUMMAND[267]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[267]) );
+ smffa dla327 (.D(SUMMAND[268]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[268]) );
+ smffa dla328 (.D(SUMMAND[269]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[269]) );
+ smfulladder dfa187 (.DATA_A (LATCHED_PP[267]), .DATA_B (LATCHED_PP[268]), .DATA_C (LATCHED_PP[269]), .SAVE (INT_SUM[267]), .CARRY (INT_CARRY[216]) );
+ smffa dla329 (.D(SUMMAND[270]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[270]) );
+ assign INT_SUM[268] = LATCHED_PP[270];
+ smffa dla330 (.D(SUMMAND[271]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[271]) );
+ assign INT_SUM[269] = LATCHED_PP[271];
+ smfulladder dfa188 (.DATA_A (INT_SUM[263]), .DATA_B (INT_SUM[264]), .DATA_C (INT_SUM[265]), .SAVE (INT_SUM[270]), .CARRY (INT_CARRY[217]) );
+ smfulladder dfa189 (.DATA_A (INT_SUM[266]), .DATA_B (INT_SUM[267]), .DATA_C (INT_SUM[268]), .SAVE (INT_SUM[271]), .CARRY (INT_CARRY[218]) );
+ smfulladder dfa190 (.DATA_A (INT_SUM[269]), .DATA_B (INT_CARRY[198]), .DATA_C (INT_CARRY[199]), .SAVE (INT_SUM[272]), .CARRY (INT_CARRY[219]) );
+ smfulladder dfa191 (.DATA_A (INT_CARRY[200]), .DATA_B (INT_CARRY[201]), .DATA_C (INT_CARRY[202]), .SAVE (INT_SUM[273]), .CARRY (INT_CARRY[220]) );
+ smfulladder dfa192 (.DATA_A (INT_SUM[270]), .DATA_B (INT_SUM[271]), .DATA_C (INT_SUM[272]), .SAVE (INT_SUM[274]), .CARRY (INT_CARRY[221]) );
+ smfulladder dfa193 (.DATA_A (INT_SUM[273]), .DATA_B (INT_CARRY[203]), .DATA_C (INT_CARRY[204]), .SAVE (INT_SUM[275]), .CARRY (INT_CARRY[222]) );
+ assign INT_SUM[276] = INT_CARRY[205];
+ smfulladder dfa194 (.DATA_A (INT_SUM[274]), .DATA_B (INT_SUM[275]), .DATA_C (INT_SUM[276]), .SAVE (INT_SUM[277]), .CARRY (INT_CARRY[223]) );
+ smhalfadder dha28 (.DATA_A (INT_CARRY[206]), .DATA_B (INT_CARRY[207]), .SAVE (INT_SUM[278]), .CARRY (INT_CARRY[224]) );
+ smfulladder dfa195 (.DATA_A (INT_SUM[277]), .DATA_B (INT_SUM[278]), .DATA_C (INT_CARRY[208]), .SAVE (INT_SUM[279]), .CARRY (INT_CARRY[225]) );
+ assign INT_SUM[280] = INT_CARRY[209];
+ smfulladder dfa196 (.DATA_A (INT_SUM[279]), .DATA_B (INT_SUM[280]), .DATA_C (INT_CARRY[210]), .SAVE (INT_SUM[281]), .CARRY (INT_CARRY[211]) );
+ smffb dla331 (.D(INT_SUM[281]), .clk(clk), .en_d2(en_d2), .Q(SUM[30]) );
+ smffb dla332 (.D(INT_CARRY[211]), .clk(clk), .en_d2(en_d2), .Q(CARRY[30]) );
+ smffa dla333 (.D(SUMMAND[272]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[272]) );
+ smffa dla334 (.D(SUMMAND[273]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[273]) );
+ smffa dla335 (.D(SUMMAND[274]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[274]) );
+ smfulladder dfa197 (.DATA_A (LATCHED_PP[272]), .DATA_B (LATCHED_PP[273]), .DATA_C (LATCHED_PP[274]), .SAVE (INT_SUM[282]), .CARRY (INT_CARRY[227]) );
+ smffa dla336 (.D(SUMMAND[275]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[275]) );
+ smffa dla337 (.D(SUMMAND[276]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[276]) );
+ smffa dla338 (.D(SUMMAND[277]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[277]) );
+ smfulladder dfa198 (.DATA_A (LATCHED_PP[275]), .DATA_B (LATCHED_PP[276]), .DATA_C (LATCHED_PP[277]), .SAVE (INT_SUM[283]), .CARRY (INT_CARRY[228]) );
+ smffa dla339 (.D(SUMMAND[278]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[278]) );
+ smffa dla340 (.D(SUMMAND[279]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[279]) );
+ smffa dla341 (.D(SUMMAND[280]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[280]) );
+ smfulladder dfa199 (.DATA_A (LATCHED_PP[278]), .DATA_B (LATCHED_PP[279]), .DATA_C (LATCHED_PP[280]), .SAVE (INT_SUM[284]), .CARRY (INT_CARRY[229]) );
+ smffa dla342 (.D(SUMMAND[281]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[281]) );
+ smffa dla343 (.D(SUMMAND[282]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[282]) );
+ smffa dla344 (.D(SUMMAND[283]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[283]) );
+ smfulladder dfa200 (.DATA_A (LATCHED_PP[281]), .DATA_B (LATCHED_PP[282]), .DATA_C (LATCHED_PP[283]), .SAVE (INT_SUM[285]), .CARRY (INT_CARRY[230]) );
+ smffa dla345 (.D(SUMMAND[284]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[284]) );
+ smffa dla346 (.D(SUMMAND[285]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[285]) );
+ smffa dla347 (.D(SUMMAND[286]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[286]) );
+ smfulladder dfa201 (.DATA_A (LATCHED_PP[284]), .DATA_B (LATCHED_PP[285]), .DATA_C (LATCHED_PP[286]), .SAVE (INT_SUM[286]), .CARRY (INT_CARRY[231]) );
+ smffa dla348 (.D(SUMMAND[287]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[287]) );
+ assign INT_SUM[287] = LATCHED_PP[287];
+ smfulladder dfa202 (.DATA_A (INT_SUM[282]), .DATA_B (INT_SUM[283]), .DATA_C (INT_SUM[284]), .SAVE (INT_SUM[288]), .CARRY (INT_CARRY[232]) );
+ smfulladder dfa203 (.DATA_A (INT_SUM[285]), .DATA_B (INT_SUM[286]), .DATA_C (INT_SUM[287]), .SAVE (INT_SUM[289]), .CARRY (INT_CARRY[233]) );
+ smfulladder dfa204 (.DATA_A (INT_CARRY[212]), .DATA_B (INT_CARRY[213]), .DATA_C (INT_CARRY[214]), .SAVE (INT_SUM[290]), .CARRY (INT_CARRY[234]) );
+ assign INT_SUM[291] = INT_CARRY[215];
+ assign INT_SUM[292] = INT_CARRY[216];
+ smfulladder dfa205 (.DATA_A (INT_SUM[288]), .DATA_B (INT_SUM[289]), .DATA_C (INT_SUM[290]), .SAVE (INT_SUM[293]), .CARRY (INT_CARRY[235]) );
+ smfulladder dfa206 (.DATA_A (INT_SUM[291]), .DATA_B (INT_SUM[292]), .DATA_C (INT_CARRY[217]), .SAVE (INT_SUM[294]), .CARRY (INT_CARRY[236]) );
+ smfulladder dfa207 (.DATA_A (INT_CARRY[218]), .DATA_B (INT_CARRY[219]), .DATA_C (INT_CARRY[220]), .SAVE (INT_SUM[295]), .CARRY (INT_CARRY[237]) );
+ smfulladder dfa208 (.DATA_A (INT_SUM[293]), .DATA_B (INT_SUM[294]), .DATA_C (INT_SUM[295]), .SAVE (INT_SUM[296]), .CARRY (INT_CARRY[238]) );
+ smhalfadder dha29 (.DATA_A (INT_CARRY[221]), .DATA_B (INT_CARRY[222]), .SAVE (INT_SUM[297]), .CARRY (INT_CARRY[239]) );
+ smfulladder dfa209 (.DATA_A (INT_SUM[296]), .DATA_B (INT_SUM[297]), .DATA_C (INT_CARRY[223]), .SAVE (INT_SUM[298]), .CARRY (INT_CARRY[240]) );
+ assign INT_SUM[299] = INT_CARRY[224];
+ smfulladder dfa210 (.DATA_A (INT_SUM[298]), .DATA_B (INT_SUM[299]), .DATA_C (INT_CARRY[225]), .SAVE (INT_SUM[300]), .CARRY (INT_CARRY[226]) );
+ smffb dla349 (.D(INT_SUM[300]), .clk(clk), .en_d2(en_d2), .Q(SUM[31]) );
+ smffb dla350 (.D(INT_CARRY[226]), .clk(clk), .en_d2(en_d2), .Q(CARRY[31]) );
+ smffa dla351 (.D(SUMMAND[288]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[288]) );
+ smffa dla352 (.D(SUMMAND[289]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[289]) );
+ smffa dla353 (.D(SUMMAND[290]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[290]) );
+ smfulladder dfa211 (.DATA_A (LATCHED_PP[288]), .DATA_B (LATCHED_PP[289]), .DATA_C (LATCHED_PP[290]), .SAVE (INT_SUM[301]), .CARRY (INT_CARRY[242]) );
+ smffa dla354 (.D(SUMMAND[291]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[291]) );
+ smffa dla355 (.D(SUMMAND[292]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[292]) );
+ smffa dla356 (.D(SUMMAND[293]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[293]) );
+ smfulladder dfa212 (.DATA_A (LATCHED_PP[291]), .DATA_B (LATCHED_PP[292]), .DATA_C (LATCHED_PP[293]), .SAVE (INT_SUM[302]), .CARRY (INT_CARRY[243]) );
+ smffa dla357 (.D(SUMMAND[294]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[294]) );
+ smffa dla358 (.D(SUMMAND[295]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[295]) );
+ smffa dla359 (.D(SUMMAND[296]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[296]) );
+ smfulladder dfa213 (.DATA_A (LATCHED_PP[294]), .DATA_B (LATCHED_PP[295]), .DATA_C (LATCHED_PP[296]), .SAVE (INT_SUM[303]), .CARRY (INT_CARRY[244]) );
+ smffa dla360 (.D(SUMMAND[297]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[297]) );
+ smffa dla361 (.D(SUMMAND[298]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[298]) );
+ smffa dla362 (.D(SUMMAND[299]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[299]) );
+ smfulladder dfa214 (.DATA_A (LATCHED_PP[297]), .DATA_B (LATCHED_PP[298]), .DATA_C (LATCHED_PP[299]), .SAVE (INT_SUM[304]), .CARRY (INT_CARRY[245]) );
+ smffa dla363 (.D(SUMMAND[300]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[300]) );
+ smffa dla364 (.D(SUMMAND[301]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[301]) );
+ smffa dla365 (.D(SUMMAND[302]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[302]) );
+ smfulladder dfa215 (.DATA_A (LATCHED_PP[300]), .DATA_B (LATCHED_PP[301]), .DATA_C (LATCHED_PP[302]), .SAVE (INT_SUM[305]), .CARRY (INT_CARRY[246]) );
+ smffa dla366 (.D(SUMMAND[303]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[303]) );
+ smffa dla367 (.D(SUMMAND[304]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[304]) );
+ smffa dla368 (.D(SUMMAND[305]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[305]) );
+ smfulladder dfa216 (.DATA_A (LATCHED_PP[303]), .DATA_B (LATCHED_PP[304]), .DATA_C (LATCHED_PP[305]), .SAVE (INT_SUM[306]), .CARRY (INT_CARRY[247]) );
+ smfulladder dfa217 (.DATA_A (INT_SUM[301]), .DATA_B (INT_SUM[302]), .DATA_C (INT_SUM[303]), .SAVE (INT_SUM[307]), .CARRY (INT_CARRY[248]) );
+ smfulladder dfa218 (.DATA_A (INT_SUM[304]), .DATA_B (INT_SUM[305]), .DATA_C (INT_SUM[306]), .SAVE (INT_SUM[308]), .CARRY (INT_CARRY[249]) );
+ smfulladder dfa219 (.DATA_A (INT_CARRY[227]), .DATA_B (INT_CARRY[228]), .DATA_C (INT_CARRY[229]), .SAVE (INT_SUM[309]), .CARRY (INT_CARRY[250]) );
+ smhalfadder dha30 (.DATA_A (INT_CARRY[230]), .DATA_B (INT_CARRY[231]), .SAVE (INT_SUM[310]), .CARRY (INT_CARRY[251]) );
+ smfulladder dfa220 (.DATA_A (INT_SUM[307]), .DATA_B (INT_SUM[308]), .DATA_C (INT_SUM[309]), .SAVE (INT_SUM[311]), .CARRY (INT_CARRY[252]) );
+ smfulladder dfa221 (.DATA_A (INT_SUM[310]), .DATA_B (INT_CARRY[232]), .DATA_C (INT_CARRY[233]), .SAVE (INT_SUM[312]), .CARRY (INT_CARRY[253]) );
+ assign INT_SUM[313] = INT_CARRY[234];
+ smfulladder dfa222 (.DATA_A (INT_SUM[311]), .DATA_B (INT_SUM[312]), .DATA_C (INT_SUM[313]), .SAVE (INT_SUM[314]), .CARRY (INT_CARRY[254]) );
+ smfulladder dfa223 (.DATA_A (INT_CARRY[235]), .DATA_B (INT_CARRY[236]), .DATA_C (INT_CARRY[237]), .SAVE (INT_SUM[315]), .CARRY (INT_CARRY[255]) );
+ smfulladder dfa224 (.DATA_A (INT_SUM[314]), .DATA_B (INT_SUM[315]), .DATA_C (INT_CARRY[238]), .SAVE (INT_SUM[316]), .CARRY (INT_CARRY[256]) );
+ assign INT_SUM[317] = INT_CARRY[239];
+ smfulladder dfa225 (.DATA_A (INT_SUM[316]), .DATA_B (INT_SUM[317]), .DATA_C (INT_CARRY[240]), .SAVE (INT_SUM[318]), .CARRY (INT_CARRY[241]) );
+ smffb dla369 (.D(INT_SUM[318]), .clk(clk), .en_d2(en_d2), .Q(SUM[32]) );
+ smffb dla370 (.D(INT_CARRY[241]), .clk(clk), .en_d2(en_d2), .Q(CARRY[32]) );
+ smffa dla371 (.D(SUMMAND[306]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[306]) );
+ smffa dla372 (.D(SUMMAND[307]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[307]) );
+ smffa dla373 (.D(SUMMAND[308]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[308]) );
+ smfulladder dfa226 (.DATA_A (LATCHED_PP[306]), .DATA_B (LATCHED_PP[307]), .DATA_C (LATCHED_PP[308]), .SAVE (INT_SUM[319]), .CARRY (INT_CARRY[258]) );
+ smffa dla374 (.D(SUMMAND[309]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[309]) );
+ smffa dla375 (.D(SUMMAND[310]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[310]) );
+ smffa dla376 (.D(SUMMAND[311]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[311]) );
+ smfulladder dfa227 (.DATA_A (LATCHED_PP[309]), .DATA_B (LATCHED_PP[310]), .DATA_C (LATCHED_PP[311]), .SAVE (INT_SUM[320]), .CARRY (INT_CARRY[259]) );
+ smffa dla377 (.D(SUMMAND[312]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[312]) );
+ smffa dla378 (.D(SUMMAND[313]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[313]) );
+ smffa dla379 (.D(SUMMAND[314]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[314]) );
+ smfulladder dfa228 (.DATA_A (LATCHED_PP[312]), .DATA_B (LATCHED_PP[313]), .DATA_C (LATCHED_PP[314]), .SAVE (INT_SUM[321]), .CARRY (INT_CARRY[260]) );
+ smffa dla380 (.D(SUMMAND[315]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[315]) );
+ smffa dla381 (.D(SUMMAND[316]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[316]) );
+ smffa dla382 (.D(SUMMAND[317]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[317]) );
+ smfulladder dfa229 (.DATA_A (LATCHED_PP[315]), .DATA_B (LATCHED_PP[316]), .DATA_C (LATCHED_PP[317]), .SAVE (INT_SUM[322]), .CARRY (INT_CARRY[261]) );
+ smffa dla383 (.D(SUMMAND[318]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[318]) );
+ smffa dla384 (.D(SUMMAND[319]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[319]) );
+ smffa dla385 (.D(SUMMAND[320]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[320]) );
+ smfulladder dfa230 (.DATA_A (LATCHED_PP[318]), .DATA_B (LATCHED_PP[319]), .DATA_C (LATCHED_PP[320]), .SAVE (INT_SUM[323]), .CARRY (INT_CARRY[262]) );
+ smffa dla386 (.D(SUMMAND[321]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[321]) );
+ assign INT_SUM[324] = LATCHED_PP[321];
+ smffa dla387 (.D(SUMMAND[322]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[322]) );
+ assign INT_SUM[325] = LATCHED_PP[322];
+ smfulladder dfa231 (.DATA_A (INT_SUM[319]), .DATA_B (INT_SUM[320]), .DATA_C (INT_SUM[321]), .SAVE (INT_SUM[326]), .CARRY (INT_CARRY[263]) );
+ smfulladder dfa232 (.DATA_A (INT_SUM[322]), .DATA_B (INT_SUM[323]), .DATA_C (INT_SUM[324]), .SAVE (INT_SUM[327]), .CARRY (INT_CARRY[264]) );
+ smfulladder dfa233 (.DATA_A (INT_SUM[325]), .DATA_B (INT_CARRY[242]), .DATA_C (INT_CARRY[243]), .SAVE (INT_SUM[328]), .CARRY (INT_CARRY[265]) );
+ smfulladder dfa234 (.DATA_A (INT_CARRY[244]), .DATA_B (INT_CARRY[245]), .DATA_C (INT_CARRY[246]), .SAVE (INT_SUM[329]), .CARRY (INT_CARRY[266]) );
+ assign INT_SUM[330] = INT_CARRY[247];
+ smfulladder dfa235 (.DATA_A (INT_SUM[326]), .DATA_B (INT_SUM[327]), .DATA_C (INT_SUM[328]), .SAVE (INT_SUM[331]), .CARRY (INT_CARRY[267]) );
+ smfulladder dfa236 (.DATA_A (INT_SUM[329]), .DATA_B (INT_SUM[330]), .DATA_C (INT_CARRY[248]), .SAVE (INT_SUM[332]), .CARRY (INT_CARRY[268]) );
+ smfulladder dfa237 (.DATA_A (INT_CARRY[249]), .DATA_B (INT_CARRY[250]), .DATA_C (INT_CARRY[251]), .SAVE (INT_SUM[333]), .CARRY (INT_CARRY[269]) );
+ smfulladder dfa238 (.DATA_A (INT_SUM[331]), .DATA_B (INT_SUM[332]), .DATA_C (INT_SUM[333]), .SAVE (INT_SUM[334]), .CARRY (INT_CARRY[270]) );
+ smhalfadder dha31 (.DATA_A (INT_CARRY[252]), .DATA_B (INT_CARRY[253]), .SAVE (INT_SUM[335]), .CARRY (INT_CARRY[271]) );
+ smfulladder dfa239 (.DATA_A (INT_SUM[334]), .DATA_B (INT_SUM[335]), .DATA_C (INT_CARRY[254]), .SAVE (INT_SUM[336]), .CARRY (INT_CARRY[272]) );
+ assign INT_SUM[337] = INT_CARRY[255];
+ smfulladder dfa240 (.DATA_A (INT_SUM[336]), .DATA_B (INT_SUM[337]), .DATA_C (INT_CARRY[256]), .SAVE (INT_SUM[338]), .CARRY (INT_CARRY[257]) );
+ smffb dla388 (.D(INT_SUM[338]), .clk(clk), .en_d2(en_d2), .Q(SUM[33]) );
+ smffb dla389 (.D(INT_CARRY[257]), .clk(clk), .en_d2(en_d2), .Q(CARRY[33]) );
+ smffa dla390 (.D(SUMMAND[323]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[323]) );
+ smffa dla391 (.D(SUMMAND[324]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[324]) );
+ smffa dla392 (.D(SUMMAND[325]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[325]) );
+ smfulladder dfa241 (.DATA_A (LATCHED_PP[323]), .DATA_B (LATCHED_PP[324]), .DATA_C (LATCHED_PP[325]), .SAVE (INT_SUM[339]), .CARRY (INT_CARRY[274]) );
+ smffa dla393 (.D(SUMMAND[326]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[326]) );
+ smffa dla394 (.D(SUMMAND[327]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[327]) );
+ smffa dla395 (.D(SUMMAND[328]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[328]) );
+ smfulladder dfa242 (.DATA_A (LATCHED_PP[326]), .DATA_B (LATCHED_PP[327]), .DATA_C (LATCHED_PP[328]), .SAVE (INT_SUM[340]), .CARRY (INT_CARRY[275]) );
+ smffa dla396 (.D(SUMMAND[329]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[329]) );
+ smffa dla397 (.D(SUMMAND[330]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[330]) );
+ smffa dla398 (.D(SUMMAND[331]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[331]) );
+ smfulladder dfa243 (.DATA_A (LATCHED_PP[329]), .DATA_B (LATCHED_PP[330]), .DATA_C (LATCHED_PP[331]), .SAVE (INT_SUM[341]), .CARRY (INT_CARRY[276]) );
+ smffa dla399 (.D(SUMMAND[332]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[332]) );
+ smffa dla400 (.D(SUMMAND[333]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[333]) );
+ smffa dla401 (.D(SUMMAND[334]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[334]) );
+ smfulladder dfa244 (.DATA_A (LATCHED_PP[332]), .DATA_B (LATCHED_PP[333]), .DATA_C (LATCHED_PP[334]), .SAVE (INT_SUM[342]), .CARRY (INT_CARRY[277]) );
+ smffa dla402 (.D(SUMMAND[335]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[335]) );
+ smffa dla403 (.D(SUMMAND[336]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[336]) );
+ smffa dla404 (.D(SUMMAND[337]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[337]) );
+ smfulladder dfa245 (.DATA_A (LATCHED_PP[335]), .DATA_B (LATCHED_PP[336]), .DATA_C (LATCHED_PP[337]), .SAVE (INT_SUM[343]), .CARRY (INT_CARRY[278]) );
+ smffa dla405 (.D(SUMMAND[338]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[338]) );
+ smffa dla406 (.D(SUMMAND[339]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[339]) );
+ smffa dla407 (.D(SUMMAND[340]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[340]) );
+ smfulladder dfa246 (.DATA_A (LATCHED_PP[338]), .DATA_B (LATCHED_PP[339]), .DATA_C (LATCHED_PP[340]), .SAVE (INT_SUM[344]), .CARRY (INT_CARRY[279]) );
+ smfulladder dfa247 (.DATA_A (INT_SUM[339]), .DATA_B (INT_SUM[340]), .DATA_C (INT_SUM[341]), .SAVE (INT_SUM[345]), .CARRY (INT_CARRY[280]) );
+ smfulladder dfa248 (.DATA_A (INT_SUM[342]), .DATA_B (INT_SUM[343]), .DATA_C (INT_SUM[344]), .SAVE (INT_SUM[346]), .CARRY (INT_CARRY[281]) );
+ smfulladder dfa249 (.DATA_A (INT_CARRY[258]), .DATA_B (INT_CARRY[259]), .DATA_C (INT_CARRY[260]), .SAVE (INT_SUM[347]), .CARRY (INT_CARRY[282]) );
+ assign INT_SUM[348] = INT_CARRY[261];
+ assign INT_SUM[349] = INT_CARRY[262];
+ smfulladder dfa250 (.DATA_A (INT_SUM[345]), .DATA_B (INT_SUM[346]), .DATA_C (INT_SUM[347]), .SAVE (INT_SUM[350]), .CARRY (INT_CARRY[283]) );
+ smfulladder dfa251 (.DATA_A (INT_SUM[348]), .DATA_B (INT_SUM[349]), .DATA_C (INT_CARRY[263]), .SAVE (INT_SUM[351]), .CARRY (INT_CARRY[284]) );
+ smfulladder dfa252 (.DATA_A (INT_CARRY[264]), .DATA_B (INT_CARRY[265]), .DATA_C (INT_CARRY[266]), .SAVE (INT_SUM[352]), .CARRY (INT_CARRY[285]) );
+ smfulladder dfa253 (.DATA_A (INT_SUM[350]), .DATA_B (INT_SUM[351]), .DATA_C (INT_SUM[352]), .SAVE (INT_SUM[353]), .CARRY (INT_CARRY[286]) );
+ smfulladder dfa254 (.DATA_A (INT_CARRY[267]), .DATA_B (INT_CARRY[268]), .DATA_C (INT_CARRY[269]), .SAVE (INT_SUM[354]), .CARRY (INT_CARRY[287]) );
+ smfulladder dfa255 (.DATA_A (INT_SUM[353]), .DATA_B (INT_SUM[354]), .DATA_C (INT_CARRY[270]), .SAVE (INT_SUM[355]), .CARRY (INT_CARRY[288]) );
+ assign INT_SUM[356] = INT_CARRY[271];
+ smfulladder dfa256 (.DATA_A (INT_SUM[355]), .DATA_B (INT_SUM[356]), .DATA_C (INT_CARRY[272]), .SAVE (INT_SUM[357]), .CARRY (INT_CARRY[273]) );
+ smffb dla408 (.D(INT_SUM[357]), .clk(clk), .en_d2(en_d2), .Q(SUM[34]) );
+ smffb dla409 (.D(INT_CARRY[273]), .clk(clk), .en_d2(en_d2), .Q(CARRY[34]) );
+ smffa dla410 (.D(SUMMAND[341]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[341]) );
+ smffa dla411 (.D(SUMMAND[342]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[342]) );
+ smffa dla412 (.D(SUMMAND[343]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[343]) );
+ smfulladder dfa257 (.DATA_A (LATCHED_PP[341]), .DATA_B (LATCHED_PP[342]), .DATA_C (LATCHED_PP[343]), .SAVE (INT_SUM[358]), .CARRY (INT_CARRY[290]) );
+ smffa dla413 (.D(SUMMAND[344]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[344]) );
+ smffa dla414 (.D(SUMMAND[345]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[345]) );
+ smffa dla415 (.D(SUMMAND[346]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[346]) );
+ smfulladder dfa258 (.DATA_A (LATCHED_PP[344]), .DATA_B (LATCHED_PP[345]), .DATA_C (LATCHED_PP[346]), .SAVE (INT_SUM[359]), .CARRY (INT_CARRY[291]) );
+ smffa dla416 (.D(SUMMAND[347]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[347]) );
+ smffa dla417 (.D(SUMMAND[348]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[348]) );
+ smffa dla418 (.D(SUMMAND[349]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[349]) );
+ smfulladder dfa259 (.DATA_A (LATCHED_PP[347]), .DATA_B (LATCHED_PP[348]), .DATA_C (LATCHED_PP[349]), .SAVE (INT_SUM[360]), .CARRY (INT_CARRY[292]) );
+ smffa dla419 (.D(SUMMAND[350]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[350]) );
+ smffa dla420 (.D(SUMMAND[351]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[351]) );
+ smffa dla421 (.D(SUMMAND[352]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[352]) );
+ smfulladder dfa260 (.DATA_A (LATCHED_PP[350]), .DATA_B (LATCHED_PP[351]), .DATA_C (LATCHED_PP[352]), .SAVE (INT_SUM[361]), .CARRY (INT_CARRY[293]) );
+ smffa dla422 (.D(SUMMAND[353]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[353]) );
+ smffa dla423 (.D(SUMMAND[354]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[354]) );
+ smffa dla424 (.D(SUMMAND[355]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[355]) );
+ smfulladder dfa261 (.DATA_A (LATCHED_PP[353]), .DATA_B (LATCHED_PP[354]), .DATA_C (LATCHED_PP[355]), .SAVE (INT_SUM[362]), .CARRY (INT_CARRY[294]) );
+ smffa dla425 (.D(SUMMAND[356]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[356]) );
+ smffa dla426 (.D(SUMMAND[357]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[357]) );
+ smhalfadder dha32 (.DATA_A (LATCHED_PP[356]), .DATA_B (LATCHED_PP[357]), .SAVE (INT_SUM[363]), .CARRY (INT_CARRY[295]) );
+ smfulladder dfa262 (.DATA_A (INT_SUM[358]), .DATA_B (INT_SUM[359]), .DATA_C (INT_SUM[360]), .SAVE (INT_SUM[364]), .CARRY (INT_CARRY[296]) );
+ smfulladder dfa263 (.DATA_A (INT_SUM[361]), .DATA_B (INT_SUM[362]), .DATA_C (INT_SUM[363]), .SAVE (INT_SUM[365]), .CARRY (INT_CARRY[297]) );
+ smfulladder dfa264 (.DATA_A (INT_CARRY[274]), .DATA_B (INT_CARRY[275]), .DATA_C (INT_CARRY[276]), .SAVE (INT_SUM[366]), .CARRY (INT_CARRY[298]) );
+ smfulladder dfa265 (.DATA_A (INT_CARRY[277]), .DATA_B (INT_CARRY[278]), .DATA_C (INT_CARRY[279]), .SAVE (INT_SUM[367]), .CARRY (INT_CARRY[299]) );
+ smfulladder dfa266 (.DATA_A (INT_SUM[364]), .DATA_B (INT_SUM[365]), .DATA_C (INT_SUM[366]), .SAVE (INT_SUM[368]), .CARRY (INT_CARRY[300]) );
+ smfulladder dfa267 (.DATA_A (INT_SUM[367]), .DATA_B (INT_CARRY[280]), .DATA_C (INT_CARRY[281]), .SAVE (INT_SUM[369]), .CARRY (INT_CARRY[301]) );
+ assign INT_SUM[370] = INT_CARRY[282];
+ smfulladder dfa268 (.DATA_A (INT_SUM[368]), .DATA_B (INT_SUM[369]), .DATA_C (INT_SUM[370]), .SAVE (INT_SUM[371]), .CARRY (INT_CARRY[302]) );
+ smfulladder dfa269 (.DATA_A (INT_CARRY[283]), .DATA_B (INT_CARRY[284]), .DATA_C (INT_CARRY[285]), .SAVE (INT_SUM[372]), .CARRY (INT_CARRY[303]) );
+ smfulladder dfa270 (.DATA_A (INT_SUM[371]), .DATA_B (INT_SUM[372]), .DATA_C (INT_CARRY[286]), .SAVE (INT_SUM[373]), .CARRY (INT_CARRY[304]) );
+ assign INT_SUM[374] = INT_CARRY[287];
+ smfulladder dfa271 (.DATA_A (INT_SUM[373]), .DATA_B (INT_SUM[374]), .DATA_C (INT_CARRY[288]), .SAVE (INT_SUM[375]), .CARRY (INT_CARRY[289]) );
+ smffb dla427 (.D(INT_SUM[375]), .clk(clk), .en_d2(en_d2), .Q(SUM[35]) );
+ smffb dla428 (.D(INT_CARRY[289]), .clk(clk), .en_d2(en_d2), .Q(CARRY[35]) );
+ smffa dla429 (.D(SUMMAND[358]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[358]) );
+ smffa dla430 (.D(SUMMAND[359]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[359]) );
+ smffa dla431 (.D(SUMMAND[360]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[360]) );
+ smfulladder dfa272 (.DATA_A (LATCHED_PP[358]), .DATA_B (LATCHED_PP[359]), .DATA_C (LATCHED_PP[360]), .SAVE (INT_SUM[376]), .CARRY (INT_CARRY[306]) );
+ smffa dla432 (.D(SUMMAND[361]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[361]) );
+ smffa dla433 (.D(SUMMAND[362]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[362]) );
+ smffa dla434 (.D(SUMMAND[363]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[363]) );
+ smfulladder dfa273 (.DATA_A (LATCHED_PP[361]), .DATA_B (LATCHED_PP[362]), .DATA_C (LATCHED_PP[363]), .SAVE (INT_SUM[377]), .CARRY (INT_CARRY[307]) );
+ smffa dla435 (.D(SUMMAND[364]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[364]) );
+ smffa dla436 (.D(SUMMAND[365]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[365]) );
+ smffa dla437 (.D(SUMMAND[366]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[366]) );
+ smfulladder dfa274 (.DATA_A (LATCHED_PP[364]), .DATA_B (LATCHED_PP[365]), .DATA_C (LATCHED_PP[366]), .SAVE (INT_SUM[378]), .CARRY (INT_CARRY[308]) );
+ smffa dla438 (.D(SUMMAND[367]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[367]) );
+ smffa dla439 (.D(SUMMAND[368]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[368]) );
+ smffa dla440 (.D(SUMMAND[369]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[369]) );
+ smfulladder dfa275 (.DATA_A (LATCHED_PP[367]), .DATA_B (LATCHED_PP[368]), .DATA_C (LATCHED_PP[369]), .SAVE (INT_SUM[379]), .CARRY (INT_CARRY[309]) );
+ smffa dla441 (.D(SUMMAND[370]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[370]) );
+ smffa dla442 (.D(SUMMAND[371]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[371]) );
+ smffa dla443 (.D(SUMMAND[372]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[372]) );
+ smfulladder dfa276 (.DATA_A (LATCHED_PP[370]), .DATA_B (LATCHED_PP[371]), .DATA_C (LATCHED_PP[372]), .SAVE (INT_SUM[380]), .CARRY (INT_CARRY[310]) );
+ smffa dla444 (.D(SUMMAND[373]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[373]) );
+ assign INT_SUM[381] = LATCHED_PP[373];
+ smfulladder dfa277 (.DATA_A (INT_SUM[376]), .DATA_B (INT_SUM[377]), .DATA_C (INT_SUM[378]), .SAVE (INT_SUM[382]), .CARRY (INT_CARRY[311]) );
+ smfulladder dfa278 (.DATA_A (INT_SUM[379]), .DATA_B (INT_SUM[380]), .DATA_C (INT_SUM[381]), .SAVE (INT_SUM[383]), .CARRY (INT_CARRY[312]) );
+ smfulladder dfa279 (.DATA_A (INT_CARRY[290]), .DATA_B (INT_CARRY[291]), .DATA_C (INT_CARRY[292]), .SAVE (INT_SUM[384]), .CARRY (INT_CARRY[313]) );
+ smfulladder dfa280 (.DATA_A (INT_CARRY[293]), .DATA_B (INT_CARRY[294]), .DATA_C (INT_CARRY[295]), .SAVE (INT_SUM[385]), .CARRY (INT_CARRY[314]) );
+ smfulladder dfa281 (.DATA_A (INT_SUM[382]), .DATA_B (INT_SUM[383]), .DATA_C (INT_SUM[384]), .SAVE (INT_SUM[386]), .CARRY (INT_CARRY[315]) );
+ smfulladder dfa282 (.DATA_A (INT_SUM[385]), .DATA_B (INT_CARRY[296]), .DATA_C (INT_CARRY[297]), .SAVE (INT_SUM[387]), .CARRY (INT_CARRY[316]) );
+ assign INT_SUM[388] = INT_CARRY[298];
+ assign INT_SUM[389] = INT_CARRY[299];
+ smfulladder dfa283 (.DATA_A (INT_SUM[386]), .DATA_B (INT_SUM[387]), .DATA_C (INT_SUM[388]), .SAVE (INT_SUM[390]), .CARRY (INT_CARRY[317]) );
+ smfulladder dfa284 (.DATA_A (INT_SUM[389]), .DATA_B (INT_CARRY[300]), .DATA_C (INT_CARRY[301]), .SAVE (INT_SUM[391]), .CARRY (INT_CARRY[318]) );
+ smfulladder dfa285 (.DATA_A (INT_SUM[390]), .DATA_B (INT_SUM[391]), .DATA_C (INT_CARRY[302]), .SAVE (INT_SUM[392]), .CARRY (INT_CARRY[319]) );
+ assign INT_SUM[393] = INT_CARRY[303];
+ smfulladder dfa286 (.DATA_A (INT_SUM[392]), .DATA_B (INT_SUM[393]), .DATA_C (INT_CARRY[304]), .SAVE (INT_SUM[394]), .CARRY (INT_CARRY[305]) );
+ smffb dla445 (.D(INT_SUM[394]), .clk(clk), .en_d2(en_d2), .Q(SUM[36]) );
+ smffb dla446 (.D(INT_CARRY[305]), .clk(clk), .en_d2(en_d2), .Q(CARRY[36]) );
+ smffa dla447 (.D(SUMMAND[374]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[374]) );
+ smffa dla448 (.D(SUMMAND[375]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[375]) );
+ smffa dla449 (.D(SUMMAND[376]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[376]) );
+ smfulladder dfa287 (.DATA_A (LATCHED_PP[374]), .DATA_B (LATCHED_PP[375]), .DATA_C (LATCHED_PP[376]), .SAVE (INT_SUM[395]), .CARRY (INT_CARRY[321]) );
+ smffa dla450 (.D(SUMMAND[377]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[377]) );
+ smffa dla451 (.D(SUMMAND[378]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[378]) );
+ smffa dla452 (.D(SUMMAND[379]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[379]) );
+ smfulladder dfa288 (.DATA_A (LATCHED_PP[377]), .DATA_B (LATCHED_PP[378]), .DATA_C (LATCHED_PP[379]), .SAVE (INT_SUM[396]), .CARRY (INT_CARRY[322]) );
+ smffa dla453 (.D(SUMMAND[380]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[380]) );
+ smffa dla454 (.D(SUMMAND[381]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[381]) );
+ smffa dla455 (.D(SUMMAND[382]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[382]) );
+ smfulladder dfa289 (.DATA_A (LATCHED_PP[380]), .DATA_B (LATCHED_PP[381]), .DATA_C (LATCHED_PP[382]), .SAVE (INT_SUM[397]), .CARRY (INT_CARRY[323]) );
+ smffa dla456 (.D(SUMMAND[383]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[383]) );
+ smffa dla457 (.D(SUMMAND[384]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[384]) );
+ smffa dla458 (.D(SUMMAND[385]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[385]) );
+ smfulladder dfa290 (.DATA_A (LATCHED_PP[383]), .DATA_B (LATCHED_PP[384]), .DATA_C (LATCHED_PP[385]), .SAVE (INT_SUM[398]), .CARRY (INT_CARRY[324]) );
+ smffa dla459 (.D(SUMMAND[386]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[386]) );
+ smffa dla460 (.D(SUMMAND[387]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[387]) );
+ smffa dla461 (.D(SUMMAND[388]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[388]) );
+ smfulladder dfa291 (.DATA_A (LATCHED_PP[386]), .DATA_B (LATCHED_PP[387]), .DATA_C (LATCHED_PP[388]), .SAVE (INT_SUM[399]), .CARRY (INT_CARRY[325]) );
+ smffa dla462 (.D(SUMMAND[389]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[389]) );
+ assign INT_SUM[400] = LATCHED_PP[389];
+ smfulladder dfa292 (.DATA_A (INT_SUM[395]), .DATA_B (INT_SUM[396]), .DATA_C (INT_SUM[397]), .SAVE (INT_SUM[401]), .CARRY (INT_CARRY[326]) );
+ smfulladder dfa293 (.DATA_A (INT_SUM[398]), .DATA_B (INT_SUM[399]), .DATA_C (INT_SUM[400]), .SAVE (INT_SUM[402]), .CARRY (INT_CARRY[327]) );
+ smfulladder dfa294 (.DATA_A (INT_CARRY[306]), .DATA_B (INT_CARRY[307]), .DATA_C (INT_CARRY[308]), .SAVE (INT_SUM[403]), .CARRY (INT_CARRY[328]) );
+ assign INT_SUM[404] = INT_CARRY[309];
+ assign INT_SUM[405] = INT_CARRY[310];
+ smfulladder dfa295 (.DATA_A (INT_SUM[401]), .DATA_B (INT_SUM[402]), .DATA_C (INT_SUM[403]), .SAVE (INT_SUM[406]), .CARRY (INT_CARRY[329]) );
+ smfulladder dfa296 (.DATA_A (INT_SUM[404]), .DATA_B (INT_SUM[405]), .DATA_C (INT_CARRY[311]), .SAVE (INT_SUM[407]), .CARRY (INT_CARRY[330]) );
+ smfulladder dfa297 (.DATA_A (INT_CARRY[312]), .DATA_B (INT_CARRY[313]), .DATA_C (INT_CARRY[314]), .SAVE (INT_SUM[408]), .CARRY (INT_CARRY[331]) );
+ smfulladder dfa298 (.DATA_A (INT_SUM[406]), .DATA_B (INT_SUM[407]), .DATA_C (INT_SUM[408]), .SAVE (INT_SUM[409]), .CARRY (INT_CARRY[332]) );
+ smhalfadder dha33 (.DATA_A (INT_CARRY[315]), .DATA_B (INT_CARRY[316]), .SAVE (INT_SUM[410]), .CARRY (INT_CARRY[333]) );
+ smfulladder dfa299 (.DATA_A (INT_SUM[409]), .DATA_B (INT_SUM[410]), .DATA_C (INT_CARRY[317]), .SAVE (INT_SUM[411]), .CARRY (INT_CARRY[334]) );
+ assign INT_SUM[412] = INT_CARRY[318];
+ smfulladder dfa300 (.DATA_A (INT_SUM[411]), .DATA_B (INT_SUM[412]), .DATA_C (INT_CARRY[319]), .SAVE (INT_SUM[413]), .CARRY (INT_CARRY[320]) );
+ smffb dla463 (.D(INT_SUM[413]), .clk(clk), .en_d2(en_d2), .Q(SUM[37]) );
+ smffb dla464 (.D(INT_CARRY[320]), .clk(clk), .en_d2(en_d2), .Q(CARRY[37]) );
+ smffa dla465 (.D(SUMMAND[390]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[390]) );
+ smffa dla466 (.D(SUMMAND[391]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[391]) );
+ smffa dla467 (.D(SUMMAND[392]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[392]) );
+ smfulladder dfa301 (.DATA_A (LATCHED_PP[390]), .DATA_B (LATCHED_PP[391]), .DATA_C (LATCHED_PP[392]), .SAVE (INT_SUM[414]), .CARRY (INT_CARRY[336]) );
+ smffa dla468 (.D(SUMMAND[393]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[393]) );
+ smffa dla469 (.D(SUMMAND[394]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[394]) );
+ smffa dla470 (.D(SUMMAND[395]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[395]) );
+ smfulladder dfa302 (.DATA_A (LATCHED_PP[393]), .DATA_B (LATCHED_PP[394]), .DATA_C (LATCHED_PP[395]), .SAVE (INT_SUM[415]), .CARRY (INT_CARRY[337]) );
+ smffa dla471 (.D(SUMMAND[396]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[396]) );
+ smffa dla472 (.D(SUMMAND[397]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[397]) );
+ smffa dla473 (.D(SUMMAND[398]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[398]) );
+ smfulladder dfa303 (.DATA_A (LATCHED_PP[396]), .DATA_B (LATCHED_PP[397]), .DATA_C (LATCHED_PP[398]), .SAVE (INT_SUM[416]), .CARRY (INT_CARRY[338]) );
+ smffa dla474 (.D(SUMMAND[399]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[399]) );
+ smffa dla475 (.D(SUMMAND[400]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[400]) );
+ smffa dla476 (.D(SUMMAND[401]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[401]) );
+ smfulladder dfa304 (.DATA_A (LATCHED_PP[399]), .DATA_B (LATCHED_PP[400]), .DATA_C (LATCHED_PP[401]), .SAVE (INT_SUM[417]), .CARRY (INT_CARRY[339]) );
+ smffa dla477 (.D(SUMMAND[402]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[402]) );
+ smffa dla478 (.D(SUMMAND[403]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[403]) );
+ smffa dla479 (.D(SUMMAND[404]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[404]) );
+ smfulladder dfa305 (.DATA_A (LATCHED_PP[402]), .DATA_B (LATCHED_PP[403]), .DATA_C (LATCHED_PP[404]), .SAVE (INT_SUM[418]), .CARRY (INT_CARRY[340]) );
+ smfulladder dfa306 (.DATA_A (INT_SUM[414]), .DATA_B (INT_SUM[415]), .DATA_C (INT_SUM[416]), .SAVE (INT_SUM[419]), .CARRY (INT_CARRY[341]) );
+ smfulladder dfa307 (.DATA_A (INT_SUM[417]), .DATA_B (INT_SUM[418]), .DATA_C (INT_CARRY[321]), .SAVE (INT_SUM[420]), .CARRY (INT_CARRY[342]) );
+ smfulladder dfa308 (.DATA_A (INT_CARRY[322]), .DATA_B (INT_CARRY[323]), .DATA_C (INT_CARRY[324]), .SAVE (INT_SUM[421]), .CARRY (INT_CARRY[343]) );
+ assign INT_SUM[422] = INT_CARRY[325];
+ smfulladder dfa309 (.DATA_A (INT_SUM[419]), .DATA_B (INT_SUM[420]), .DATA_C (INT_SUM[421]), .SAVE (INT_SUM[423]), .CARRY (INT_CARRY[344]) );
+ smfulladder dfa310 (.DATA_A (INT_SUM[422]), .DATA_B (INT_CARRY[326]), .DATA_C (INT_CARRY[327]), .SAVE (INT_SUM[424]), .CARRY (INT_CARRY[345]) );
+ assign INT_SUM[425] = INT_CARRY[328];
+ smfulladder dfa311 (.DATA_A (INT_SUM[423]), .DATA_B (INT_SUM[424]), .DATA_C (INT_SUM[425]), .SAVE (INT_SUM[426]), .CARRY (INT_CARRY[346]) );
+ smfulladder dfa312 (.DATA_A (INT_CARRY[329]), .DATA_B (INT_CARRY[330]), .DATA_C (INT_CARRY[331]), .SAVE (INT_SUM[427]), .CARRY (INT_CARRY[347]) );
+ smfulladder dfa313 (.DATA_A (INT_SUM[426]), .DATA_B (INT_SUM[427]), .DATA_C (INT_CARRY[332]), .SAVE (INT_SUM[428]), .CARRY (INT_CARRY[348]) );
+ assign INT_SUM[429] = INT_CARRY[333];
+ smfulladder dfa314 (.DATA_A (INT_SUM[428]), .DATA_B (INT_SUM[429]), .DATA_C (INT_CARRY[334]), .SAVE (INT_SUM[430]), .CARRY (INT_CARRY[335]) );
+ smffb dla480 (.D(INT_SUM[430]), .clk(clk), .en_d2(en_d2), .Q(SUM[38]) );
+ smffb dla481 (.D(INT_CARRY[335]), .clk(clk), .en_d2(en_d2), .Q(CARRY[38]) );
+ smffa dla482 (.D(SUMMAND[405]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[405]) );
+ smffa dla483 (.D(SUMMAND[406]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[406]) );
+ smffa dla484 (.D(SUMMAND[407]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[407]) );
+ smfulladder dfa315 (.DATA_A (LATCHED_PP[405]), .DATA_B (LATCHED_PP[406]), .DATA_C (LATCHED_PP[407]), .SAVE (INT_SUM[431]), .CARRY (INT_CARRY[350]) );
+ smffa dla485 (.D(SUMMAND[408]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[408]) );
+ smffa dla486 (.D(SUMMAND[409]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[409]) );
+ smffa dla487 (.D(SUMMAND[410]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[410]) );
+ smfulladder dfa316 (.DATA_A (LATCHED_PP[408]), .DATA_B (LATCHED_PP[409]), .DATA_C (LATCHED_PP[410]), .SAVE (INT_SUM[432]), .CARRY (INT_CARRY[351]) );
+ smffa dla488 (.D(SUMMAND[411]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[411]) );
+ smffa dla489 (.D(SUMMAND[412]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[412]) );
+ smffa dla490 (.D(SUMMAND[413]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[413]) );
+ smfulladder dfa317 (.DATA_A (LATCHED_PP[411]), .DATA_B (LATCHED_PP[412]), .DATA_C (LATCHED_PP[413]), .SAVE (INT_SUM[433]), .CARRY (INT_CARRY[352]) );
+ smffa dla491 (.D(SUMMAND[414]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[414]) );
+ smffa dla492 (.D(SUMMAND[415]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[415]) );
+ smffa dla493 (.D(SUMMAND[416]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[416]) );
+ smfulladder dfa318 (.DATA_A (LATCHED_PP[414]), .DATA_B (LATCHED_PP[415]), .DATA_C (LATCHED_PP[416]), .SAVE (INT_SUM[434]), .CARRY (INT_CARRY[353]) );
+ smffa dla494 (.D(SUMMAND[417]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[417]) );
+ smffa dla495 (.D(SUMMAND[418]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[418]) );
+ smffa dla496 (.D(SUMMAND[419]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[419]) );
+ smfulladder dfa319 (.DATA_A (LATCHED_PP[417]), .DATA_B (LATCHED_PP[418]), .DATA_C (LATCHED_PP[419]), .SAVE (INT_SUM[435]), .CARRY (INT_CARRY[354]) );
+ smfulladder dfa320 (.DATA_A (INT_SUM[431]), .DATA_B (INT_SUM[432]), .DATA_C (INT_SUM[433]), .SAVE (INT_SUM[436]), .CARRY (INT_CARRY[355]) );
+ smfulladder dfa321 (.DATA_A (INT_SUM[434]), .DATA_B (INT_SUM[435]), .DATA_C (INT_CARRY[336]), .SAVE (INT_SUM[437]), .CARRY (INT_CARRY[356]) );
+ smfulladder dfa322 (.DATA_A (INT_CARRY[337]), .DATA_B (INT_CARRY[338]), .DATA_C (INT_CARRY[339]), .SAVE (INT_SUM[438]), .CARRY (INT_CARRY[357]) );
+ assign INT_SUM[439] = INT_CARRY[340];
+ smfulladder dfa323 (.DATA_A (INT_SUM[436]), .DATA_B (INT_SUM[437]), .DATA_C (INT_SUM[438]), .SAVE (INT_SUM[440]), .CARRY (INT_CARRY[358]) );
+ smfulladder dfa324 (.DATA_A (INT_SUM[439]), .DATA_B (INT_CARRY[341]), .DATA_C (INT_CARRY[342]), .SAVE (INT_SUM[441]), .CARRY (INT_CARRY[359]) );
+ assign INT_SUM[442] = INT_CARRY[343];
+ smfulladder dfa325 (.DATA_A (INT_SUM[440]), .DATA_B (INT_SUM[441]), .DATA_C (INT_SUM[442]), .SAVE (INT_SUM[443]), .CARRY (INT_CARRY[360]) );
+ smhalfadder dha34 (.DATA_A (INT_CARRY[344]), .DATA_B (INT_CARRY[345]), .SAVE (INT_SUM[444]), .CARRY (INT_CARRY[361]) );
+ smfulladder dfa326 (.DATA_A (INT_SUM[443]), .DATA_B (INT_SUM[444]), .DATA_C (INT_CARRY[346]), .SAVE (INT_SUM[445]), .CARRY (INT_CARRY[362]) );
+ assign INT_SUM[446] = INT_CARRY[347];
+ smfulladder dfa327 (.DATA_A (INT_SUM[445]), .DATA_B (INT_SUM[446]), .DATA_C (INT_CARRY[348]), .SAVE (INT_SUM[447]), .CARRY (INT_CARRY[349]) );
+ smffb dla497 (.D(INT_SUM[447]), .clk(clk), .en_d2(en_d2), .Q(SUM[39]) );
+ smffb dla498 (.D(INT_CARRY[349]), .clk(clk), .en_d2(en_d2), .Q(CARRY[39]) );
+ smffa dla499 (.D(SUMMAND[420]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[420]) );
+ smffa dla500 (.D(SUMMAND[421]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[421]) );
+ smffa dla501 (.D(SUMMAND[422]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[422]) );
+ smfulladder dfa328 (.DATA_A (LATCHED_PP[420]), .DATA_B (LATCHED_PP[421]), .DATA_C (LATCHED_PP[422]), .SAVE (INT_SUM[448]), .CARRY (INT_CARRY[364]) );
+ smffa dla502 (.D(SUMMAND[423]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[423]) );
+ smffa dla503 (.D(SUMMAND[424]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[424]) );
+ smffa dla504 (.D(SUMMAND[425]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[425]) );
+ smfulladder dfa329 (.DATA_A (LATCHED_PP[423]), .DATA_B (LATCHED_PP[424]), .DATA_C (LATCHED_PP[425]), .SAVE (INT_SUM[449]), .CARRY (INT_CARRY[365]) );
+ smffa dla505 (.D(SUMMAND[426]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[426]) );
+ smffa dla506 (.D(SUMMAND[427]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[427]) );
+ smffa dla507 (.D(SUMMAND[428]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[428]) );
+ smfulladder dfa330 (.DATA_A (LATCHED_PP[426]), .DATA_B (LATCHED_PP[427]), .DATA_C (LATCHED_PP[428]), .SAVE (INT_SUM[450]), .CARRY (INT_CARRY[366]) );
+ smffa dla508 (.D(SUMMAND[429]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[429]) );
+ smffa dla509 (.D(SUMMAND[430]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[430]) );
+ smffa dla510 (.D(SUMMAND[431]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[431]) );
+ smfulladder dfa331 (.DATA_A (LATCHED_PP[429]), .DATA_B (LATCHED_PP[430]), .DATA_C (LATCHED_PP[431]), .SAVE (INT_SUM[451]), .CARRY (INT_CARRY[367]) );
+ smffa dla511 (.D(SUMMAND[432]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[432]) );
+ smffa dla512 (.D(SUMMAND[433]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[433]) );
+ smhalfadder dha35 (.DATA_A (LATCHED_PP[432]), .DATA_B (LATCHED_PP[433]), .SAVE (INT_SUM[452]), .CARRY (INT_CARRY[368]) );
+ smfulladder dfa332 (.DATA_A (INT_SUM[448]), .DATA_B (INT_SUM[449]), .DATA_C (INT_SUM[450]), .SAVE (INT_SUM[453]), .CARRY (INT_CARRY[369]) );
+ smfulladder dfa333 (.DATA_A (INT_SUM[451]), .DATA_B (INT_SUM[452]), .DATA_C (INT_CARRY[350]), .SAVE (INT_SUM[454]), .CARRY (INT_CARRY[370]) );
+ smfulladder dfa334 (.DATA_A (INT_CARRY[351]), .DATA_B (INT_CARRY[352]), .DATA_C (INT_CARRY[353]), .SAVE (INT_SUM[455]), .CARRY (INT_CARRY[371]) );
+ assign INT_SUM[456] = INT_CARRY[354];
+ smfulladder dfa335 (.DATA_A (INT_SUM[453]), .DATA_B (INT_SUM[454]), .DATA_C (INT_SUM[455]), .SAVE (INT_SUM[457]), .CARRY (INT_CARRY[372]) );
+ smfulladder dfa336 (.DATA_A (INT_SUM[456]), .DATA_B (INT_CARRY[355]), .DATA_C (INT_CARRY[356]), .SAVE (INT_SUM[458]), .CARRY (INT_CARRY[373]) );
+ assign INT_SUM[459] = INT_CARRY[357];
+ smfulladder dfa337 (.DATA_A (INT_SUM[457]), .DATA_B (INT_SUM[458]), .DATA_C (INT_SUM[459]), .SAVE (INT_SUM[460]), .CARRY (INT_CARRY[374]) );
+ smhalfadder dha36 (.DATA_A (INT_CARRY[358]), .DATA_B (INT_CARRY[359]), .SAVE (INT_SUM[461]), .CARRY (INT_CARRY[375]) );
+ smfulladder dfa338 (.DATA_A (INT_SUM[460]), .DATA_B (INT_SUM[461]), .DATA_C (INT_CARRY[360]), .SAVE (INT_SUM[462]), .CARRY (INT_CARRY[376]) );
+ assign INT_SUM[463] = INT_CARRY[361];
+ smfulladder dfa339 (.DATA_A (INT_SUM[462]), .DATA_B (INT_SUM[463]), .DATA_C (INT_CARRY[362]), .SAVE (INT_SUM[464]), .CARRY (INT_CARRY[363]) );
+ smffb dla513 (.D(INT_SUM[464]), .clk(clk), .en_d2(en_d2), .Q(SUM[40]) );
+ smffb dla514 (.D(INT_CARRY[363]), .clk(clk), .en_d2(en_d2), .Q(CARRY[40]) );
+ smffa dla515 (.D(SUMMAND[434]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[434]) );
+ smffa dla516 (.D(SUMMAND[435]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[435]) );
+ smffa dla517 (.D(SUMMAND[436]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[436]) );
+ smfulladder dfa340 (.DATA_A (LATCHED_PP[434]), .DATA_B (LATCHED_PP[435]), .DATA_C (LATCHED_PP[436]), .SAVE (INT_SUM[465]), .CARRY (INT_CARRY[378]) );
+ smffa dla518 (.D(SUMMAND[437]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[437]) );
+ smffa dla519 (.D(SUMMAND[438]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[438]) );
+ smffa dla520 (.D(SUMMAND[439]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[439]) );
+ smfulladder dfa341 (.DATA_A (LATCHED_PP[437]), .DATA_B (LATCHED_PP[438]), .DATA_C (LATCHED_PP[439]), .SAVE (INT_SUM[466]), .CARRY (INT_CARRY[379]) );
+ smffa dla521 (.D(SUMMAND[440]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[440]) );
+ smffa dla522 (.D(SUMMAND[441]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[441]) );
+ smffa dla523 (.D(SUMMAND[442]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[442]) );
+ smfulladder dfa342 (.DATA_A (LATCHED_PP[440]), .DATA_B (LATCHED_PP[441]), .DATA_C (LATCHED_PP[442]), .SAVE (INT_SUM[467]), .CARRY (INT_CARRY[380]) );
+ smffa dla524 (.D(SUMMAND[443]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[443]) );
+ smffa dla525 (.D(SUMMAND[444]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[444]) );
+ smffa dla526 (.D(SUMMAND[445]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[445]) );
+ smfulladder dfa343 (.DATA_A (LATCHED_PP[443]), .DATA_B (LATCHED_PP[444]), .DATA_C (LATCHED_PP[445]), .SAVE (INT_SUM[468]), .CARRY (INT_CARRY[381]) );
+ smffa dla527 (.D(SUMMAND[446]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[446]) );
+ smffa dla528 (.D(SUMMAND[447]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[447]) );
+ smhalfadder dha37 (.DATA_A (LATCHED_PP[446]), .DATA_B (LATCHED_PP[447]), .SAVE (INT_SUM[469]), .CARRY (INT_CARRY[382]) );
+ smfulladder dfa344 (.DATA_A (INT_SUM[465]), .DATA_B (INT_SUM[466]), .DATA_C (INT_SUM[467]), .SAVE (INT_SUM[470]), .CARRY (INT_CARRY[383]) );
+ smfulladder dfa345 (.DATA_A (INT_SUM[468]), .DATA_B (INT_SUM[469]), .DATA_C (INT_CARRY[364]), .SAVE (INT_SUM[471]), .CARRY (INT_CARRY[384]) );
+ smfulladder dfa346 (.DATA_A (INT_CARRY[365]), .DATA_B (INT_CARRY[366]), .DATA_C (INT_CARRY[367]), .SAVE (INT_SUM[472]), .CARRY (INT_CARRY[385]) );
+ assign INT_SUM[473] = INT_CARRY[368];
+ smfulladder dfa347 (.DATA_A (INT_SUM[470]), .DATA_B (INT_SUM[471]), .DATA_C (INT_SUM[472]), .SAVE (INT_SUM[474]), .CARRY (INT_CARRY[386]) );
+ smfulladder dfa348 (.DATA_A (INT_SUM[473]), .DATA_B (INT_CARRY[369]), .DATA_C (INT_CARRY[370]), .SAVE (INT_SUM[475]), .CARRY (INT_CARRY[387]) );
+ assign INT_SUM[476] = INT_CARRY[371];
+ smfulladder dfa349 (.DATA_A (INT_SUM[474]), .DATA_B (INT_SUM[475]), .DATA_C (INT_SUM[476]), .SAVE (INT_SUM[477]), .CARRY (INT_CARRY[388]) );
+ smhalfadder dha38 (.DATA_A (INT_CARRY[372]), .DATA_B (INT_CARRY[373]), .SAVE (INT_SUM[478]), .CARRY (INT_CARRY[389]) );
+ smfulladder dfa350 (.DATA_A (INT_SUM[477]), .DATA_B (INT_SUM[478]), .DATA_C (INT_CARRY[374]), .SAVE (INT_SUM[479]), .CARRY (INT_CARRY[390]) );
+ assign INT_SUM[480] = INT_CARRY[375];
+ smfulladder dfa351 (.DATA_A (INT_SUM[479]), .DATA_B (INT_SUM[480]), .DATA_C (INT_CARRY[376]), .SAVE (INT_SUM[481]), .CARRY (INT_CARRY[377]) );
+ smffb dla529 (.D(INT_SUM[481]), .clk(clk), .en_d2(en_d2), .Q(SUM[41]) );
+ smffb dla530 (.D(INT_CARRY[377]), .clk(clk), .en_d2(en_d2), .Q(CARRY[41]) );
+ smffa dla531 (.D(SUMMAND[448]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[448]) );
+ smffa dla532 (.D(SUMMAND[449]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[449]) );
+ smffa dla533 (.D(SUMMAND[450]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[450]) );
+ smfulladder dfa352 (.DATA_A (LATCHED_PP[448]), .DATA_B (LATCHED_PP[449]), .DATA_C (LATCHED_PP[450]), .SAVE (INT_SUM[482]), .CARRY (INT_CARRY[392]) );
+ smffa dla534 (.D(SUMMAND[451]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[451]) );
+ smffa dla535 (.D(SUMMAND[452]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[452]) );
+ smffa dla536 (.D(SUMMAND[453]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[453]) );
+ smfulladder dfa353 (.DATA_A (LATCHED_PP[451]), .DATA_B (LATCHED_PP[452]), .DATA_C (LATCHED_PP[453]), .SAVE (INT_SUM[483]), .CARRY (INT_CARRY[393]) );
+ smffa dla537 (.D(SUMMAND[454]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[454]) );
+ smffa dla538 (.D(SUMMAND[455]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[455]) );
+ smffa dla539 (.D(SUMMAND[456]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[456]) );
+ smfulladder dfa354 (.DATA_A (LATCHED_PP[454]), .DATA_B (LATCHED_PP[455]), .DATA_C (LATCHED_PP[456]), .SAVE (INT_SUM[484]), .CARRY (INT_CARRY[394]) );
+ smffa dla540 (.D(SUMMAND[457]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[457]) );
+ smffa dla541 (.D(SUMMAND[458]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[458]) );
+ smffa dla542 (.D(SUMMAND[459]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[459]) );
+ smfulladder dfa355 (.DATA_A (LATCHED_PP[457]), .DATA_B (LATCHED_PP[458]), .DATA_C (LATCHED_PP[459]), .SAVE (INT_SUM[485]), .CARRY (INT_CARRY[395]) );
+ smffa dla543 (.D(SUMMAND[460]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[460]) );
+ assign INT_SUM[486] = LATCHED_PP[460];
+ smfulladder dfa356 (.DATA_A (INT_SUM[482]), .DATA_B (INT_SUM[483]), .DATA_C (INT_SUM[484]), .SAVE (INT_SUM[487]), .CARRY (INT_CARRY[396]) );
+ smfulladder dfa357 (.DATA_A (INT_SUM[485]), .DATA_B (INT_SUM[486]), .DATA_C (INT_CARRY[378]), .SAVE (INT_SUM[488]), .CARRY (INT_CARRY[397]) );
+ smfulladder dfa358 (.DATA_A (INT_CARRY[379]), .DATA_B (INT_CARRY[380]), .DATA_C (INT_CARRY[381]), .SAVE (INT_SUM[489]), .CARRY (INT_CARRY[398]) );
+ assign INT_SUM[490] = INT_CARRY[382];
+ smfulladder dfa359 (.DATA_A (INT_SUM[487]), .DATA_B (INT_SUM[488]), .DATA_C (INT_SUM[489]), .SAVE (INT_SUM[491]), .CARRY (INT_CARRY[399]) );
+ smfulladder dfa360 (.DATA_A (INT_SUM[490]), .DATA_B (INT_CARRY[383]), .DATA_C (INT_CARRY[384]), .SAVE (INT_SUM[492]), .CARRY (INT_CARRY[400]) );
+ assign INT_SUM[493] = INT_CARRY[385];
+ smfulladder dfa361 (.DATA_A (INT_SUM[491]), .DATA_B (INT_SUM[492]), .DATA_C (INT_SUM[493]), .SAVE (INT_SUM[494]), .CARRY (INT_CARRY[401]) );
+ smhalfadder dha39 (.DATA_A (INT_CARRY[386]), .DATA_B (INT_CARRY[387]), .SAVE (INT_SUM[495]), .CARRY (INT_CARRY[402]) );
+ smfulladder dfa362 (.DATA_A (INT_SUM[494]), .DATA_B (INT_SUM[495]), .DATA_C (INT_CARRY[388]), .SAVE (INT_SUM[496]), .CARRY (INT_CARRY[403]) );
+ assign INT_SUM[497] = INT_CARRY[389];
+ smfulladder dfa363 (.DATA_A (INT_SUM[496]), .DATA_B (INT_SUM[497]), .DATA_C (INT_CARRY[390]), .SAVE (INT_SUM[498]), .CARRY (INT_CARRY[391]) );
+ smffb dla544 (.D(INT_SUM[498]), .clk(clk), .en_d2(en_d2), .Q(SUM[42]) );
+ smffb dla545 (.D(INT_CARRY[391]), .clk(clk), .en_d2(en_d2), .Q(CARRY[42]) );
+ smffa dla546 (.D(SUMMAND[461]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[461]) );
+ smffa dla547 (.D(SUMMAND[462]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[462]) );
+ smffa dla548 (.D(SUMMAND[463]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[463]) );
+ smfulladder dfa364 (.DATA_A (LATCHED_PP[461]), .DATA_B (LATCHED_PP[462]), .DATA_C (LATCHED_PP[463]), .SAVE (INT_SUM[499]), .CARRY (INT_CARRY[405]) );
+ smffa dla549 (.D(SUMMAND[464]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[464]) );
+ smffa dla550 (.D(SUMMAND[465]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[465]) );
+ smffa dla551 (.D(SUMMAND[466]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[466]) );
+ smfulladder dfa365 (.DATA_A (LATCHED_PP[464]), .DATA_B (LATCHED_PP[465]), .DATA_C (LATCHED_PP[466]), .SAVE (INT_SUM[500]), .CARRY (INT_CARRY[406]) );
+ smffa dla552 (.D(SUMMAND[467]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[467]) );
+ smffa dla553 (.D(SUMMAND[468]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[468]) );
+ smffa dla554 (.D(SUMMAND[469]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[469]) );
+ smfulladder dfa366 (.DATA_A (LATCHED_PP[467]), .DATA_B (LATCHED_PP[468]), .DATA_C (LATCHED_PP[469]), .SAVE (INT_SUM[501]), .CARRY (INT_CARRY[407]) );
+ smffa dla555 (.D(SUMMAND[470]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[470]) );
+ smffa dla556 (.D(SUMMAND[471]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[471]) );
+ smffa dla557 (.D(SUMMAND[472]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[472]) );
+ smfulladder dfa367 (.DATA_A (LATCHED_PP[470]), .DATA_B (LATCHED_PP[471]), .DATA_C (LATCHED_PP[472]), .SAVE (INT_SUM[502]), .CARRY (INT_CARRY[408]) );
+ smffa dla558 (.D(SUMMAND[473]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[473]) );
+ smfulladder dfa368 (.DATA_A (LATCHED_PP[473]), .DATA_B (INT_CARRY[392]), .DATA_C (INT_CARRY[393]), .SAVE (INT_SUM[503]), .CARRY (INT_CARRY[409]) );
+ assign INT_SUM[504] = INT_CARRY[394];
+ assign INT_SUM[505] = INT_CARRY[395];
+ smfulladder dfa369 (.DATA_A (INT_SUM[499]), .DATA_B (INT_SUM[500]), .DATA_C (INT_SUM[501]), .SAVE (INT_SUM[506]), .CARRY (INT_CARRY[410]) );
+ smfulladder dfa370 (.DATA_A (INT_SUM[502]), .DATA_B (INT_SUM[503]), .DATA_C (INT_SUM[504]), .SAVE (INT_SUM[507]), .CARRY (INT_CARRY[411]) );
+ smfulladder dfa371 (.DATA_A (INT_SUM[505]), .DATA_B (INT_CARRY[396]), .DATA_C (INT_CARRY[397]), .SAVE (INT_SUM[508]), .CARRY (INT_CARRY[412]) );
+ assign INT_SUM[509] = INT_CARRY[398];
+ smfulladder dfa372 (.DATA_A (INT_SUM[506]), .DATA_B (INT_SUM[507]), .DATA_C (INT_SUM[508]), .SAVE (INT_SUM[510]), .CARRY (INT_CARRY[413]) );
+ smfulladder dfa373 (.DATA_A (INT_SUM[509]), .DATA_B (INT_CARRY[399]), .DATA_C (INT_CARRY[400]), .SAVE (INT_SUM[511]), .CARRY (INT_CARRY[414]) );
+ smfulladder dfa374 (.DATA_A (INT_SUM[510]), .DATA_B (INT_SUM[511]), .DATA_C (INT_CARRY[401]), .SAVE (INT_SUM[512]), .CARRY (INT_CARRY[415]) );
+ assign INT_SUM[513] = INT_CARRY[402];
+ smfulladder dfa375 (.DATA_A (INT_SUM[512]), .DATA_B (INT_SUM[513]), .DATA_C (INT_CARRY[403]), .SAVE (INT_SUM[514]), .CARRY (INT_CARRY[404]) );
+ smffb dla559 (.D(INT_SUM[514]), .clk(clk), .en_d2(en_d2), .Q(SUM[43]) );
+ smffb dla560 (.D(INT_CARRY[404]), .clk(clk), .en_d2(en_d2), .Q(CARRY[43]) );
+ smffa dla561 (.D(SUMMAND[474]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[474]) );
+ smffa dla562 (.D(SUMMAND[475]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[475]) );
+ smffa dla563 (.D(SUMMAND[476]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[476]) );
+ smfulladder dfa376 (.DATA_A (LATCHED_PP[474]), .DATA_B (LATCHED_PP[475]), .DATA_C (LATCHED_PP[476]), .SAVE (INT_SUM[515]), .CARRY (INT_CARRY[417]) );
+ smffa dla564 (.D(SUMMAND[477]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[477]) );
+ smffa dla565 (.D(SUMMAND[478]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[478]) );
+ smffa dla566 (.D(SUMMAND[479]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[479]) );
+ smfulladder dfa377 (.DATA_A (LATCHED_PP[477]), .DATA_B (LATCHED_PP[478]), .DATA_C (LATCHED_PP[479]), .SAVE (INT_SUM[516]), .CARRY (INT_CARRY[418]) );
+ smffa dla567 (.D(SUMMAND[480]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[480]) );
+ smffa dla568 (.D(SUMMAND[481]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[481]) );
+ smffa dla569 (.D(SUMMAND[482]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[482]) );
+ smfulladder dfa378 (.DATA_A (LATCHED_PP[480]), .DATA_B (LATCHED_PP[481]), .DATA_C (LATCHED_PP[482]), .SAVE (INT_SUM[517]), .CARRY (INT_CARRY[419]) );
+ smffa dla570 (.D(SUMMAND[483]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[483]) );
+ smffa dla571 (.D(SUMMAND[484]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[484]) );
+ smffa dla572 (.D(SUMMAND[485]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[485]) );
+ smfulladder dfa379 (.DATA_A (LATCHED_PP[483]), .DATA_B (LATCHED_PP[484]), .DATA_C (LATCHED_PP[485]), .SAVE (INT_SUM[518]), .CARRY (INT_CARRY[420]) );
+ smfulladder dfa380 (.DATA_A (INT_SUM[515]), .DATA_B (INT_SUM[516]), .DATA_C (INT_SUM[517]), .SAVE (INT_SUM[519]), .CARRY (INT_CARRY[421]) );
+ smfulladder dfa381 (.DATA_A (INT_SUM[518]), .DATA_B (INT_CARRY[405]), .DATA_C (INT_CARRY[406]), .SAVE (INT_SUM[520]), .CARRY (INT_CARRY[422]) );
+ smfulladder dfa382 (.DATA_A (INT_CARRY[407]), .DATA_B (INT_CARRY[408]), .DATA_C (INT_CARRY[409]), .SAVE (INT_SUM[521]), .CARRY (INT_CARRY[423]) );
+ smfulladder dfa383 (.DATA_A (INT_SUM[519]), .DATA_B (INT_SUM[520]), .DATA_C (INT_SUM[521]), .SAVE (INT_SUM[522]), .CARRY (INT_CARRY[424]) );
+ smfulladder dfa384 (.DATA_A (INT_CARRY[410]), .DATA_B (INT_CARRY[411]), .DATA_C (INT_CARRY[412]), .SAVE (INT_SUM[523]), .CARRY (INT_CARRY[425]) );
+ smfulladder dfa385 (.DATA_A (INT_SUM[522]), .DATA_B (INT_SUM[523]), .DATA_C (INT_CARRY[413]), .SAVE (INT_SUM[524]), .CARRY (INT_CARRY[426]) );
+ assign INT_SUM[525] = INT_CARRY[414];
+ smfulladder dfa386 (.DATA_A (INT_SUM[524]), .DATA_B (INT_SUM[525]), .DATA_C (INT_CARRY[415]), .SAVE (INT_SUM[526]), .CARRY (INT_CARRY[416]) );
+ smffb dla573 (.D(INT_SUM[526]), .clk(clk), .en_d2(en_d2), .Q(SUM[44]) );
+ smffb dla574 (.D(INT_CARRY[416]), .clk(clk), .en_d2(en_d2), .Q(CARRY[44]) );
+ smffa dla575 (.D(SUMMAND[486]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[486]) );
+ smffa dla576 (.D(SUMMAND[487]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[487]) );
+ smffa dla577 (.D(SUMMAND[488]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[488]) );
+ smfulladder dfa387 (.DATA_A (LATCHED_PP[486]), .DATA_B (LATCHED_PP[487]), .DATA_C (LATCHED_PP[488]), .SAVE (INT_SUM[527]), .CARRY (INT_CARRY[428]) );
+ smffa dla578 (.D(SUMMAND[489]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[489]) );
+ smffa dla579 (.D(SUMMAND[490]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[490]) );
+ smffa dla580 (.D(SUMMAND[491]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[491]) );
+ smfulladder dfa388 (.DATA_A (LATCHED_PP[489]), .DATA_B (LATCHED_PP[490]), .DATA_C (LATCHED_PP[491]), .SAVE (INT_SUM[528]), .CARRY (INT_CARRY[429]) );
+ smffa dla581 (.D(SUMMAND[492]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[492]) );
+ smffa dla582 (.D(SUMMAND[493]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[493]) );
+ smffa dla583 (.D(SUMMAND[494]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[494]) );
+ smfulladder dfa389 (.DATA_A (LATCHED_PP[492]), .DATA_B (LATCHED_PP[493]), .DATA_C (LATCHED_PP[494]), .SAVE (INT_SUM[529]), .CARRY (INT_CARRY[430]) );
+ smffa dla584 (.D(SUMMAND[495]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[495]) );
+ smffa dla585 (.D(SUMMAND[496]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[496]) );
+ smffa dla586 (.D(SUMMAND[497]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[497]) );
+ smfulladder dfa390 (.DATA_A (LATCHED_PP[495]), .DATA_B (LATCHED_PP[496]), .DATA_C (LATCHED_PP[497]), .SAVE (INT_SUM[530]), .CARRY (INT_CARRY[431]) );
+ smfulladder dfa391 (.DATA_A (INT_SUM[527]), .DATA_B (INT_SUM[528]), .DATA_C (INT_SUM[529]), .SAVE (INT_SUM[531]), .CARRY (INT_CARRY[432]) );
+ smfulladder dfa392 (.DATA_A (INT_SUM[530]), .DATA_B (INT_CARRY[417]), .DATA_C (INT_CARRY[418]), .SAVE (INT_SUM[532]), .CARRY (INT_CARRY[433]) );
+ smhalfadder dha40 (.DATA_A (INT_CARRY[419]), .DATA_B (INT_CARRY[420]), .SAVE (INT_SUM[533]), .CARRY (INT_CARRY[434]) );
+ smfulladder dfa393 (.DATA_A (INT_SUM[531]), .DATA_B (INT_SUM[532]), .DATA_C (INT_SUM[533]), .SAVE (INT_SUM[534]), .CARRY (INT_CARRY[435]) );
+ smfulladder dfa394 (.DATA_A (INT_CARRY[421]), .DATA_B (INT_CARRY[422]), .DATA_C (INT_CARRY[423]), .SAVE (INT_SUM[535]), .CARRY (INT_CARRY[436]) );
+ smfulladder dfa395 (.DATA_A (INT_SUM[534]), .DATA_B (INT_SUM[535]), .DATA_C (INT_CARRY[424]), .SAVE (INT_SUM[536]), .CARRY (INT_CARRY[437]) );
+ assign INT_SUM[537] = INT_CARRY[425];
+ smfulladder dfa396 (.DATA_A (INT_SUM[536]), .DATA_B (INT_SUM[537]), .DATA_C (INT_CARRY[426]), .SAVE (INT_SUM[538]), .CARRY (INT_CARRY[427]) );
+ smffb dla587 (.D(INT_SUM[538]), .clk(clk), .en_d2(en_d2), .Q(SUM[45]) );
+ smffb dla588 (.D(INT_CARRY[427]), .clk(clk), .en_d2(en_d2), .Q(CARRY[45]) );
+ smffa dla589 (.D(SUMMAND[498]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[498]) );
+ smffa dla590 (.D(SUMMAND[499]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[499]) );
+ smffa dla591 (.D(SUMMAND[500]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[500]) );
+ smfulladder dfa39'b'7 (.DATA_A (LATCHED_PP[498]), .DATA_B (LATCHED_PP[499]), .DATA_C (LATCHED_PP[500]), .SAVE (INT_SUM[539]), .CARRY (INT_CARRY[439]) );
+ smffa dla592 (.D(SUMMAND[501]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[501]) );
+ smffa dla593 (.D(SUMMAND[502]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[502]) );
+ smffa dla594 (.D(SUMMAND[503]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[503]) );
+ smfulladder dfa398 (.DATA_A (LATCHED_PP[501]), .DATA_B (LATCHED_PP[502]), .DATA_C (LATCHED_PP[503]), .SAVE (INT_SUM[540]), .CARRY (INT_CARRY[440]) );
+ smffa dla595 (.D(SUMMAND[504]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[504]) );
+ smffa dla596 (.D(SUMMAND[505]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[505]) );
+ smffa dla597 (.D(SUMMAND[506]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[506]) );
+ smfulladder dfa399 (.DATA_A (LATCHED_PP[504]), .DATA_B (LATCHED_PP[505]), .DATA_C (LATCHED_PP[506]), .SAVE (INT_SUM[541]), .CARRY (INT_CARRY[441]) );
+ smffa dla598 (.D(SUMMAND[507]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[507]) );
+ assign INT_SUM[542] = LATCHED_PP[507];
+ smffa dla599 (.D(SUMMAND[508]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[508]) );
+ assign INT_SUM[543] = LATCHED_PP[508];
+ smfulladder dfa400 (.DATA_A (INT_SUM[539]), .DATA_B (INT_SUM[540]), .DATA_C (INT_SUM[541]), .SAVE (INT_SUM[544]), .CARRY (INT_CARRY[442]) );
+ smfulladder dfa401 (.DATA_A (INT_SUM[542]), .DATA_B (INT_SUM[543]), .DATA_C (INT_CARRY[428]), .SAVE (INT_SUM[545]), .CARRY (INT_CARRY[443]) );
+ smfulladder dfa402 (.DATA_A (INT_CARRY[429]), .DATA_B (INT_CARRY[430]), .DATA_C (INT_CARRY[431]), .SAVE (INT_SUM[546]), .CARRY (INT_CARRY[444]) );
+ smfulladder dfa403 (.DATA_A (INT_SUM[544]), .DATA_B (INT_SUM[545]), .DATA_C (INT_SUM[546]), .SAVE (INT_SUM[547]), .CARRY (INT_CARRY[445]) );
+ smfulladder dfa404 (.DATA_A (INT_CARRY[432]), .DATA_B (INT_CARRY[433]), .DATA_C (INT_CARRY[434]), .SAVE (INT_SUM[548]), .CARRY (INT_CARRY[446]) );
+ smfulladder dfa405 (.DATA_A (INT_SUM[547]), .DATA_B (INT_SUM[548]), .DATA_C (INT_CARRY[435]), .SAVE (INT_SUM[549]), .CARRY (INT_CARRY[447]) );
+ assign INT_SUM[550] = INT_CARRY[436];
+ smfulladder dfa406 (.DATA_A (INT_SUM[549]), .DATA_B (INT_SUM[550]), .DATA_C (INT_CARRY[437]), .SAVE (INT_SUM[551]), .CARRY (INT_CARRY[438]) );
+ smffb dla600 (.D(INT_SUM[551]), .clk(clk), .en_d2(en_d2), .Q(SUM[46]) );
+ smffb dla601 (.D(INT_CARRY[438]), .clk(clk), .en_d2(en_d2), .Q(CARRY[46]) );
+ smffa dla602 (.D(SUMMAND[509]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[509]) );
+ smffa dla603 (.D(SUMMAND[510]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[510]) );
+ smffa dla604 (.D(SUMMAND[511]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[511]) );
+ smfulladder dfa407 (.DATA_A (LATCHED_PP[509]), .DATA_B (LATCHED_PP[510]), .DATA_C (LATCHED_PP[511]), .SAVE (INT_SUM[552]), .CARRY (INT_CARRY[449]) );
+ smffa dla605 (.D(SUMMAND[512]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[512]) );
+ smffa dla606 (.D(SUMMAND[513]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[513]) );
+ smffa dla607 (.D(SUMMAND[514]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[514]) );
+ smfulladder dfa408 (.DATA_A (LATCHED_PP[512]), .DATA_B (LATCHED_PP[513]), .DATA_C (LATCHED_PP[514]), .SAVE (INT_SUM[553]), .CARRY (INT_CARRY[450]) );
+ smffa dla608 (.D(SUMMAND[515]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[515]) );
+ smffa dla609 (.D(SUMMAND[516]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[516]) );
+ smffa dla610 (.D(SUMMAND[517]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[517]) );
+ smfulladder dfa409 (.DATA_A (LATCHED_PP[515]), .DATA_B (LATCHED_PP[516]), .DATA_C (LATCHED_PP[517]), .SAVE (INT_SUM[554]), .CARRY (INT_CARRY[451]) );
+ smffa dla611 (.D(SUMMAND[518]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[518]) );
+ smffa dla612 (.D(SUMMAND[519]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[519]) );
+ smhalfadder dha41 (.DATA_A (LATCHED_PP[518]), .DATA_B (LATCHED_PP[519]), .SAVE (INT_SUM[555]), .CARRY (INT_CARRY[452]) );
+ smfulladder dfa410 (.DATA_A (INT_SUM[552]), .DATA_B (INT_SUM[553]), .DATA_C (INT_SUM[554]), .SAVE (INT_SUM[556]), .CARRY (INT_CARRY[453]) );
+ smfulladder dfa411 (.DATA_A (INT_SUM[555]), .DATA_B (INT_CARRY[439]), .DATA_C (INT_CARRY[440]), .SAVE (INT_SUM[557]), .CARRY (INT_CARRY[454]) );
+ assign INT_SUM[558] = INT_CARRY[441];
+ smfulladder dfa412 (.DATA_A (INT_SUM[556]), .DATA_B (INT_SUM[557]), .DATA_C (INT_SUM[558]), .SAVE (INT_SUM[559]), .CARRY (INT_CARRY[455]) );
+ smfulladder dfa413 (.DATA_A (INT_CARRY[442]), .DATA_B (INT_CARRY[443]), .DATA_C (INT_CARRY[444]), .SAVE (INT_SUM[560]), .CARRY (INT_CARRY[456]) );
+ smfulladder dfa414 (.DATA_A (INT_SUM[559]), .DATA_B (INT_SUM[560]), .DATA_C (INT_CARRY[445]), .SAVE (INT_SUM[561]), .CARRY (INT_CARRY[457]) );
+ assign INT_SUM[562] = INT_CARRY[446];
+ smfulladder dfa415 (.DATA_A (INT_SUM[561]), .DATA_B (INT_SUM[562]), .DATA_C (INT_CARRY[447]), .SAVE (INT_SUM[563]), .CARRY (INT_CARRY[448]) );
+ smffb dla613 (.D(INT_SUM[563]), .clk(clk), .en_d2(en_d2), .Q(SUM[47]) );
+ smffb dla614 (.D(INT_CARRY[448]), .clk(clk), .en_d2(en_d2), .Q(CARRY[47]) );
+ smffa dla615 (.D(SUMMAND[520]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[520]) );
+ smffa dla616 (.D(SUMMAND[521]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[521]) );
+ smffa dla617 (.D(SUMMAND[522]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[522]) );
+ smfulladder dfa416 (.DATA_A (LATCHED_PP[520]), .DATA_B (LATCHED_PP[521]), .DATA_C (LATCHED_PP[522]), .SAVE (INT_SUM[564]), .CARRY (INT_CARRY[459]) );
+ smffa dla618 (.D(SUMMAND[523]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[523]) );
+ smffa dla619 (.D(SUMMAND[524]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[524]) );
+ smffa dla620 (.D(SUMMAND[525]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[525]) );
+ smfulladder dfa417 (.DATA_A (LATCHED_PP[523]), .DATA_B (LATCHED_PP[524]), .DATA_C (LATCHED_PP[525]), .SAVE (INT_SUM[565]), .CARRY (INT_CARRY[460]) );
+ smffa dla621 (.D(SUMMAND[526]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[526]) );
+ smffa dla622 (.D(SUMMAND[527]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[527]) );
+ smffa dla623 (.D(SUMMAND[528]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[528]) );
+ smfulladder dfa418 (.DATA_A (LATCHED_PP[526]), .DATA_B (LATCHED_PP[527]), .DATA_C (LATCHED_PP[528]), .SAVE (INT_SUM[566]), .CARRY (INT_CARRY[461]) );
+ smffa dla624 (.D(SUMMAND[529]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[529]) );
+ assign INT_SUM[567] = LATCHED_PP[529];
+ smfulladder dfa419 (.DATA_A (INT_SUM[564]), .DATA_B (INT_SUM[565]), .DATA_C (INT_SUM[566]), .SAVE (INT_SUM[568]), .CARRY (INT_CARRY[462]) );
+ smfulladder dfa420 (.DATA_A (INT_SUM[567]), .DATA_B (INT_CARRY[449]), .DATA_C (INT_CARRY[450]), .SAVE (INT_SUM[569]), .CARRY (INT_CARRY[463]) );
+ assign INT_SUM[570] = INT_CARRY[451];
+ assign INT_SUM[571] = INT_CARRY[452];
+ smfulladder dfa421 (.DATA_A (INT_SUM[568]), .DATA_B (INT_SUM[569]), .DATA_C (INT_SUM[570]), .SAVE (INT_SUM[572]), .CARRY (INT_CARRY[464]) );
+ smfulladder dfa422 (.DATA_A (INT_SUM[571]), .DATA_B (INT_CARRY[453]), .DATA_C (INT_CARRY[454]), .SAVE (INT_SUM[573]), .CARRY (INT_CARRY[465]) );
+ smfulladder dfa423 (.DATA_A (INT_SUM[572]), .DATA_B (INT_SUM[573]), .DATA_C (INT_CARRY[455]), .SAVE (INT_SUM[574]), .CARRY (INT_CARRY[466]) );
+ assign INT_SUM[575] = INT_CARRY[456];
+ smfulladder dfa424 (.DATA_A (INT_SUM[574]), .DATA_B (INT_SUM[575]), .DATA_C (INT_CARRY[457]), .SAVE (INT_SUM[576]), .CARRY (INT_CARRY[458]) );
+ smffb dla625 (.D(INT_SUM[576]), .clk(clk), .en_d2(en_d2), .Q(SUM[48]) );
+ smffb dla626 (.D(INT_CARRY[458]), .clk(clk), .en_d2(en_d2), .Q(CARRY[48]) );
+ smffa dla627 (.D(SUMMAND[530]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[530]) );
+ smffa dla628 (.D(SUMMAND[531]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[531]) );
+ smffa dla629 (.D(SUMMAND[532]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[532]) );
+ smfulladder dfa425 (.DATA_A (LATCHED_PP[530]), .DATA_B (LATCHED_PP[531]), .DATA_C (LATCHED_PP[532]), .SAVE (INT_SUM[577]), .CARRY (INT_CARRY[468]) );
+ smffa dla630 (.D(SUMMAND[533]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[533]) );
+ smffa dla631 (.D(SUMMAND[534]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[534]) );
+ smffa dla632 (.D(SUMMAND[535]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[535]) );
+ smfulladder dfa426 (.DATA_A (LATCHED_PP[533]), .DATA_B (LATCHED_PP[534]), .DATA_C (LATCHED_PP[535]), .SAVE (INT_SUM[578]), .CARRY (INT_CARRY[469]) );
+ smffa dla633 (.D(SUMMAND[536]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[536]) );
+ smffa dla634 (.D(SUMMAND[537]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[537]) );
+ smffa dla635 (.D(SUMMAND[538]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[538]) );
+ smfulladder dfa427 (.DATA_A (LATCHED_PP[536]), .DATA_B (LATCHED_PP[537]), .DATA_C (LATCHED_PP[538]), .SAVE (INT_SUM[579]), .CARRY (INT_CARRY[470]) );
+ smffa dla636 (.D(SUMMAND[539]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[539]) );
+ assign INT_SUM[580] = LATCHED_PP[539];
+ smfulladder dfa428 (.DATA_A (INT_SUM[577]), .DATA_B (INT_SUM[578]), .DATA_C (INT_SUM[579]), .SAVE (INT_SUM[581]), .CARRY (INT_CARRY[471]) );
+ smfulladder dfa429 (.DATA_A (INT_SUM[580]), .DATA_B (INT_CARRY[459]), .DATA_C (INT_CARRY[460]), .SAVE (INT_SUM[582]), .CARRY (INT_CARRY[472]) );
+ assign INT_SUM[583] = INT_CARRY[461];
+ smfulladder dfa430 (.DATA_A (INT_SUM[581]), .DATA_B (INT_SUM[582]), .DATA_C (INT_SUM[583]), .SAVE (INT_SUM[584]), .CARRY (INT_CARRY[473]) );
+ smhalfadder dha42 (.DATA_A (INT_CARRY[462]), .DATA_B (INT_CARRY[463]), .SAVE (INT_SUM[585]), .CARRY (INT_CARRY[474]) );
+ smfulladder dfa431 (.DATA_A (INT_SUM[584]), .DATA_B (INT_SUM[585]), .DATA_C (INT_CARRY[464]), .SAVE (INT_SUM[586]), .CARRY (INT_CARRY[475]) );
+ assign INT_SUM[587] = INT_CARRY[465];
+ smfulladder dfa432 (.DATA_A (INT_SUM[586]), .DATA_B (INT_SUM[587]), .DATA_C (INT_CARRY[466]), .SAVE (INT_SUM[588]), .CARRY (INT_CARRY[467]) );
+ smffb dla637 (.D(INT_SUM[588]), .clk(clk), .en_d2(en_d2), .Q(SUM[49]) );
+ smffb dla638 (.D(INT_CARRY[467]), .clk(clk), .en_d2(en_d2), .Q(CARRY[49]) );
+ smffa dla639 (.D(SUMMAND[540]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[540]) );
+ smffa dla640 (.D(SUMMAND[541]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[541]) );
+ smffa dla641 (.D(SUMMAND[542]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[542]) );
+ smfulladder dfa433 (.DATA_A (LATCHED_PP[540]), .DATA_B (LATCHED_PP[541]), .DATA_C (LATCHED_PP[542]), .SAVE (INT_SUM[589]), .CARRY (INT_CARRY[477]) );
+ smffa dla642 (.D(SUMMAND[543]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[543]) );
+ smffa dla643 (.D(SUMMAND[544]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[544]) );
+ smffa dla644 (.D(SUMMAND[545]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[545]) );
+ smfulladder dfa434 (.DATA_A (LATCHED_PP[543]), .DATA_B (LATCHED_PP[544]), .DATA_C (LATCHED_PP[545]), .SAVE (INT_SUM[590]), .CARRY (INT_CARRY[478]) );
+ smffa dla645 (.D(SUMMAND[546]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[546]) );
+ smffa dla646 (.D(SUMMAND[547]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[547]) );
+ smffa dla647 (.D(SUMMAND[548]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[548]) );
+ smfulladder dfa435 (.DATA_A (LATCHED_PP[546]), .DATA_B (LATCHED_PP[547]), .DATA_C (LATCHED_PP[548]), .SAVE (INT_SUM[591]), .CARRY (INT_CARRY[479]) );
+ smfulladder dfa436 (.DATA_A (INT_SUM[589]), .DATA_B (INT_SUM[590]), .DATA_C (INT_SUM[591]), .SAVE (INT_SUM[592]), .CARRY (INT_CARRY[480]) );
+ smfulladder dfa437 (.DATA_A (INT_CARRY[468]), .DATA_B (INT_CARRY[469]), .DATA_C (INT_CARRY[470]), .SAVE (INT_SUM[593]), .CARRY (INT_CARRY[481]) );
+ smfulladder dfa438 (.DATA_A (INT_SUM[592]), .DATA_B (INT_SUM[593]), .DATA_C (INT_CARRY[471]), .SAVE (INT_SUM[594]), .CARRY (INT_CARRY[482]) );
+ assign INT_SUM[595] = INT_CARRY[472];
+ smfulladder dfa439 (.DATA_A (INT_SUM[594]), .DATA_B (INT_SUM[595]), .DATA_C (INT_CARRY[473]), .SAVE (INT_SUM[596]), .CARRY (INT_CARRY[483]) );
+ assign INT_SUM[597] = INT_CARRY[474];
+ smfulladder dfa440 (.DATA_A (INT_SUM[596]), .DATA_B (INT_SUM[597]), .DATA_C (INT_CARRY[475]), .SAVE (INT_SUM[598]), .CARRY (INT_CARRY[476]) );
+ smffb dla648 (.D(INT_SUM[598]), .clk(clk), .en_d2(en_d2), .Q(SUM[50]) );
+ smffb dla649 (.D(INT_CARRY[476]), .clk(clk), .en_d2(en_d2), .Q(CARRY[50]) );
+ smffa dla650 (.D(SUMMAND[549]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[549]) );
+ smffa dla651 (.D(SUMMAND[550]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[550]) );
+ smffa dla652 (.D(SUMMAND[551]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[551]) );
+ smfulladder dfa441 (.DATA_A (LATCHED_PP[549]), .DATA_B (LATCHED_PP[550]), .DATA_C (LATCHED_PP[551]), .SAVE (INT_SUM[599]), .CARRY (INT_CARRY[485]) );
+ smffa dla653 (.D(SUMMAND[552]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[552]) );
+ smffa dla654 (.D(SUMMAND[553]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[553]) );
+ smffa dla655 (.D(SUMMAND[554]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[554]) );
+ smfulladder dfa442 (.DATA_A (LATCHED_PP[552]), .DATA_B (LATCHED_PP[553]), .DATA_C (LATCHED_PP[554]), .SAVE (INT_SUM[600]), .CARRY (INT_CARRY[486]) );
+ smffa dla656 (.D(SUMMAND[555]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[555]) );
+ smffa dla657 (.D(SUMMAND[556]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[556]) );
+ smffa dla658 (.D(SUMMAND[557]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[557]) );
+ smfulladder dfa443 (.DATA_A (LATCHED_PP[555]), .DATA_B (LATCHED_PP[556]), .DATA_C (LATCHED_PP[557]), .SAVE (INT_SUM[601]), .CARRY (INT_CARRY[487]) );
+ smfulladder dfa444 (.DATA_A (INT_SUM[599]), .DATA_B (INT_SUM[600]), .DATA_C (INT_SUM[601]), .SAVE (INT_SUM[602]), .CARRY (INT_CARRY[488]) );
+ smfulladder dfa445 (.DATA_A (INT_CARRY[477]), .DATA_B (INT_CARRY[478]), .DATA_C (INT_CARRY[479]), .SAVE (INT_SUM[603]), .CARRY (INT_CARRY[489]) );
+ smfulladder dfa446 (.DATA_A (INT_SUM[602]), .DATA_B (INT_SUM[603]), .DATA_C (INT_CARRY[480]), .SAVE (INT_SUM[604]), .CARRY (INT_CARRY[490]) );
+ assign INT_SUM[605] = INT_CARRY[481];
+ smfulladder dfa447 (.DATA_A (INT_SUM[604]), .DATA_B (INT_SUM[605]), .DATA_C (INT_CARRY[482]), .SAVE (INT_SUM[606]), .CARRY (INT_CARRY[491]) );
+ smhalfadder dha43 (.DATA_A (INT_SUM[606]), .DATA_B (INT_CARRY[483]), .SAVE (INT_SUM[607]), .CARRY (INT_CARRY[484]) );
+ smffb dla659 (.D(INT_SUM[607]), .clk(clk), .en_d2(en_d2), .Q(SUM[51]) );
+ smffb dla660 (.D(INT_CARRY[484]), .clk(clk), .en_d2(en_d2), .Q(CARRY[51]) );
+ smffa dla661 (.D(SUMMAND[558]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[558]) );
+ smffa dla662 (.D(SUMMAND[559]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[559]) );
+ smffa dla663 (.D(SUMMAND[560]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[560]) );
+ smfulladder dfa448 (.DATA_A (LATCHED_PP[558]), .DATA_B (LATCHED_PP[559]), .DATA_C (LATCHED_PP[560]), .SAVE (INT_SUM[608]), .CARRY (INT_CARRY[493]) );
+ smffa dla664 (.D(SUMMAND[561]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[561]) );
+ smffa dla665 (.D(SUMMAND[562]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[562]) );
+ smffa dla666 (.D(SUMMAND[563]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[563]) );
+ smfulladder dfa449 (.DATA_A (LATCHED_PP[561]), .DATA_B (LATCHED_PP[562]), .DATA_C (LATCHED_PP[563]), .SAVE (INT_SUM[609]), .CARRY (INT_CARRY[494]) );
+ smffa dla667 (.D(SUMMAND[564]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[564]) );
+ smffa dla668 (.D(SUMMAND[565]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[565]) );
+ smfulladder dfa450 (.DATA_A (LATCHED_PP[564]), .DATA_B (LATCHED_PP[565]), .DATA_C (INT_CARRY[485]), .SAVE (INT_SUM[610]), .CARRY (INT_CARRY[495]) );
+ smhalfadder dha44 (.DATA_A (INT_CARRY[486]), .DATA_B (INT_CARRY[487]), .SAVE (INT_SUM[611]), .CARRY (INT_CARRY[496]) );
+ smfulladder dfa451 (.DATA_A (INT_SUM[608]), .DATA_B (INT_SUM[609]), .DATA_C (INT_SUM[610]), .SAVE (INT_SUM[612]), .CARRY (INT_CARRY[497]) );
+ smfulladder dfa452 (.DATA_A (INT_SUM[611]), .DATA_B (INT_CARRY[488]), .DATA_C (INT_CARRY[489]), .SAVE (INT_SUM[613]), .CARRY (INT_CARRY[498]) );
+ smfulladder dfa453 (.DATA_A (INT_SUM[612]), .DATA_B (INT_SUM[613]), .DATA_C (INT_CARRY[490]), .SAVE (INT_SUM[614]), .CARRY (INT_CARRY[499]) );
+ smhalfadder dha45 (.DATA_A (INT_SUM[614]), .DATA_B (INT_CARRY[491]), .SAVE (INT_SUM[615]), .CARRY (INT_CARRY[492]) );
+ smffb dla669 (.D(INT_SUM[615]), .clk(clk), .en_d2(en_d2), .Q(SUM[52]) );
+ smffb dla670 (.D(INT_CARRY[492]), .clk(clk), .en_d2(en_d2), .Q(CARRY[52]) );
+ smffa dla671 (.D(SUMMAND[566]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[566]) );
+ smffa dla672 (.D(SUMMAND[567]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[567]) );
+ smffa dla673 (.D(SUMMAND[568]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[568]) );
+ smfulladder dfa454 (.DATA_A (LATCHED_PP[566]), .DATA_B (LATCHED_PP[567]), .DATA_C (LATCHED_PP[568]), .SAVE (INT_SUM[616]), .CARRY (INT_CARRY[501]) );
+ smffa dla674 (.D(SUMMAND[569]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[569]) );
+ smffa dla675 (.D(SUMMAND[570]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[570]) );
+ smffa dla676 (.D(SUMMAND[571]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[571]) );
+ smfulladder dfa455 (.DATA_A (LATCHED_PP[569]), .DATA_B (LATCHED_PP[570]), .DATA_C (LATCHED_PP[571]), .SAVE (INT_SUM[617]), .CARRY (INT_CARRY[502]) );
+ smffa dla677 (.D(SUMMAND[572]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[572]) );
+ assign INT_SUM[618] = LATCHED_PP[572];
+ smffa dla678 (.D(SUMMAND[573]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[573]) );
+ assign INT_SUM[619] = LATCHED_PP[573];
+ smfulladder dfa456 (.DATA_A (INT_SUM[616]), .DATA_B (INT_SUM[617]), .DATA_C (INT_SUM[618]), .SAVE (INT_SUM[620]), .CARRY (INT_CARRY[503]) );
+ assign INT_SUM[621] = INT_SUM[619];
+ smfulladder dfa457 (.DATA_A (INT_SUM[620]), .DATA_B (INT_SUM[621]), .DATA_C (INT_CARRY[493]), .SAVE (INT_SUM[622]), .CARRY (INT_CARRY[504]) );
+ smfulladder dfa458 (.DATA_A (INT_CARRY[494]), .DATA_B (INT_CARRY[495]), .DATA_C (INT_CARRY[496]), .SAVE (INT_SUM[623]), .CARRY (INT_CARRY[505]) );
+ smfulladder dfa459 (.DATA_A (INT_SUM[622]), .DATA_B (INT_SUM[623]), .DATA_C (INT_CARRY[497]), .SAVE (INT_SUM[624]), .CARRY (INT_CARRY[506]) );
+ assign INT_SUM[625] = INT_CARRY[498];
+ smfulladder dfa460 (.DATA_A (INT_SUM[624]), .DATA_B (INT_SUM[625]), .DATA_C (INT_CARRY[499]), .SAVE (INT_SUM[626]), .CARRY (INT_CARRY[500]) );
+ smffb dla679 (.D(INT_SUM[626]), .clk(clk), .en_d2(en_d2), .Q(SUM[53]) );
+ smffb dla680 (.D(INT_CARRY[500]), .clk(clk), .en_d2(en_d2), .Q(CARRY[53]) );
+ smffa dla681 (.D(SUMMAND[574]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[574]) );
+ smffa dla682 (.D(SUMMAND[575]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[575]) );
+ smffa dla683 (.D(SUMMAND[576]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[576]) );
+ smfulladder dfa461 (.DATA_A (LATCHED_PP[574]), .DATA_B (LATCHED_PP[575]), .DATA_C (LATCHED_PP[576]), .SAVE (INT_SUM[627]), .CARRY (INT_CARRY[508]) );
+ smffa dla684 (.D(SUMMAND[577]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[577]) );
+ smffa dla685 (.D(SUMMAND[578]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[578]) );
+ smffa dla686 (.D(SUMMAND[579]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[579]) );
+ smfulladder dfa462 (.DATA_A (LATCHED_PP[577]), .DATA_B (LATCHED_PP[578]), .DATA_C (LATCHED_PP[579]), .SAVE (INT_SUM[628]), .CARRY (INT_CARRY[509]) );
+ smffa dla687 (.D(SUMMAND[580]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[580]) );
+ smfulladder dfa463 (.DATA_A (LATCHED_PP[580]), .DATA_B (INT_CARRY[501]), .DATA_C (INT_CARRY[502]), .SAVE (INT_SUM[629]), .CARRY (INT_CARRY[510]) );
+ smfulladder dfa464 (.DATA_A (INT_SUM[627]), .DATA_B (INT_SUM[628]), .DATA_C (INT_SUM[629]), .SAVE (INT_SUM[630]), .CARRY (INT_CARRY[511]) );
+ assign INT_SUM[631] = INT_CARRY[503];
+ smfulladder dfa465 (.DATA_A (INT_SUM[630]), .DATA_B (INT_SUM[631]), .DATA_C (INT_CARRY[504]), .SAVE (INT_SUM[632]), .CARRY (INT_CARRY[512]) );
+ assign INT_SUM[633] = INT_CARRY[505];
+ smfulladder dfa466 (.DATA_A (INT_SUM[632]), .DATA_B (INT_SUM[633]), .DATA_C (INT_CARRY[506]), .SAVE (INT_SUM[634]), .CARRY (INT_CARRY[507]) );
+ smffb dla688 (.D(INT_SUM[634]), .clk(clk), .en_d2(en_d2), .Q(SUM[54]) );
+ smffb dla689 (.D(INT_CARRY[507]), .clk(clk), .en_d2(en_d2), .Q(CARRY[54]) );
+ smffa dla690 (.D(SUMMAND[581]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[581]) );
+ smffa dla691 (.D(SUMMAND[582]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[582]) );
+ smffa dla692 (.D(SUMMAND[583]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[583]) );
+ smfulladder dfa467 (.DATA_A (LATCHED_PP[581]), .DATA_B (LATCHED_PP[582]), .DATA_C (LATCHED_PP[583]), .SAVE (INT_SUM[635]), .CARRY (INT_CARRY[514]) );
+ smffa dla693 (.D(SUMMAND[584]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[584]) );
+ smffa dla694 (.D(SUMMAND[585]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[585]) );
+ smffa dla695 (.D(SUMMAND[586]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[586]) );
+ smfulladder dfa468 (.DATA_A (LATCHED_PP[584]), .DATA_B (LATCHED_PP[585]), .DATA_C (LATCHED_PP[586]), .SAVE (INT_SUM[636]), .CARRY (INT_CARRY[515]) );
+ smffa dla696 (.D(SUMMAND[587]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[587]) );
+ assign INT_SUM[637] = LATCHED_PP[587];
+ smfulladder dfa469 (.DATA_A (INT_SUM[635]), .DATA_B (INT_SUM[636]), .DATA_C (INT_SUM[637]), .SAVE (INT_SUM[638]), .CARRY (INT_CARRY[516]) );
+ smfulladder dfa470 (.DATA_A (INT_CARRY[508]), .DATA_B (INT_CARRY[509]), .DATA_C (INT_CARRY[510]), .SAVE (INT_SUM[639]), .CARRY (INT_CARRY[517]) );
+ smfulladder dfa471 (.DATA_A (INT_SUM[638]), .DATA_B (INT_SUM[639]), .DATA_C (INT_CARRY[511]), .SAVE (INT_SUM[640]), .CARRY (INT_CARRY[518]) );
+ smhalfadder dha46 (.DATA_A (INT_SUM[640]), .DATA_B (INT_CARRY[512]), .SAVE (INT_SUM[641]), .CARRY (INT_CARRY[513]) );
+ smffb dla697 (.D(INT_SUM[641]), .clk(clk), .en_d2(en_d2), .Q(SUM[55]) );
+ smffb dla698 (.D(INT_CARRY[513]), .clk(clk), .en_d2(en_d2), .Q(CARRY[55]) );
+ smffa dla699 (.D(SUMMAND[588]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[588]) );
+ smffa dla700 (.D(SUMMAND[589]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[589]) );
+ smffa dla701 (.D(SUMMAND[590]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[590]) );
+ smfulladder dfa472 (.DATA_A (LATCHED_PP[588]), .DATA_B (LATCHED_PP[589]), .DATA_C (LATCHED_PP[590]), .SAVE (INT_SUM[642]), .CARRY (INT_CARRY[520]) );
+ smffa dla702 (.D(SUMMAND[591]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[591]) );
+ smffa dla703 (.D(SUMMAND[592]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[592]) );
+ smffa dla704 (.D(SUMMAND[593]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[593]) );
+ smfulladder dfa473 (.DATA_A (LATCHED_PP[591]), .DATA_B (LATCHED_PP[592]), .DATA_C (LATCHED_PP[593]), .SAVE (INT_SUM[643]), .CARRY (INT_CARRY[521]) );
+ smfulladder dfa474 (.DATA_A (INT_SUM[642]), .DATA_B (INT_SUM[643]), .DATA_C (INT_CARRY[514]), .SAVE (INT_SUM[644]), .CARRY (INT_CARRY[522]) );
+ assign INT_SUM[645] = INT_CARRY[515];
+ smfulladder dfa475 (.DATA_A (INT_SUM[644]), .DATA_B (INT_SUM[645]), .DATA_C (INT_CARRY[516]), .SAVE (INT_SUM[646]), .CARRY (INT_CARRY[523]) );
+ assign INT_SUM[647] = INT_CARRY[517];
+ smfulladder dfa476 (.DATA_A (INT_SUM[646]), .DATA_B (INT_SUM[647]), .DATA_C (INT_CARRY[518]), .SAVE (INT_SUM[648]), .CARRY (INT_CARRY[519]) );
+ smffb dla705 (.D(INT_SUM[648]), .clk(clk), .en_d2(en_d2), .Q(SUM[56]) );
+ smffb dla706 (.D(INT_CARRY[519]), .clk(clk), .en_d2(en_d2), .Q(CARRY[56]) );
+ smffa dla707 (.D(SUMMAND[594]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[594]) );
+ smffa dla708 (.D(SUMMAND[595]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[595]) );
+ smffa dla709 (.D(SUMMAND[596]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[596]) );
+ smfulladder dfa477 (.DATA_A (LATCHED_PP[594]), .DATA_B (LATCHED_PP[595]), .DATA_C (LATCHED_PP[596]), .SAVE (INT_SUM[649]), .CARRY (INT_CARRY[525]) );
+ smffa dla710 (.D(SUMMAND[597]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[597]) );
+ smffa dla711 (.D(SUMMAND[598]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[598]) );
+ smffa dla712 (.D(SUMMAND[599]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[599]) );
+ smfulladder dfa478 (.DATA_A (LATCHED_PP[597]), .DATA_B (LATCHED_PP[598]), .DATA_C (LATCHED_PP[599]), .SAVE (INT_SUM[650]), .CARRY (INT_CARRY[526]) );
+ smfulladder dfa479 (.DATA_A (INT_SUM[649]), .DATA_B (INT_SUM[650]), .DATA_C (INT_CARRY[520]), .SAVE (INT_SUM[651]), .CARRY (INT_CARRY[527]) );
+ assign INT_SUM[652] = INT_CARRY[521];
+ smfulladder dfa480 (.DATA_A (INT_SUM[651]), .DATA_B (INT_SUM[652]), .DATA_C (INT_CARRY[522]), .SAVE (INT_SUM[653]), .CARRY (INT_CARRY[528]) );
+ smhalfadder dha47 (.DATA_A (INT_SUM[653]), .DATA_B (INT_CARRY[523]), .SAVE (INT_SUM[654]), .CARRY (INT_CARRY[524]) );
+ smffb dla713 (.D(INT_SUM[654]), .clk(clk), .en_d2(en_d2), .Q(SUM[57]) );
+ smffb dla714 (.D(INT_CARRY[524]), .clk(clk), .en_d2(en_d2), .Q(CARRY[57]) );
+ smffa dla715 (.D(SUMMAND[600]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[600]) );
+ smffa dla716 (.D(SUMMAND[601]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[601]) );
+ smffa dla717 (.D(SUMMAND[602]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[602]) );
+ smfulladder dfa481 (.DATA_A (LATCHED_PP[600]), .DATA_B (LATCHED_PP[601]), .DATA_C (LATCHED_PP[602]), .SAVE (INT_SUM[655]), .CARRY (INT_CARRY[530]) );
+ smffa dla718 (.D(SUMMAND[603]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[603]) );
+ smffa dla719 (.D(SUMMAND[604]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[604]) );
+ smhalfadder dha48 (.DATA_A (LATCHED_PP[603]), .DATA_B (LATCHED_PP[604]), .SAVE (INT_SUM[656]), .CARRY (INT_CARRY[531]) );
+ smfulladder dfa482 (.DATA_A (INT_SUM[655]), .DATA_B (INT_SUM[656]), .DATA_C (INT_CARRY[525]), .SAVE (INT_SUM[657]), .CARRY (INT_CARRY[532]) );
+ assign INT_SUM[658] = INT_CARRY[526];
+ smfulladder dfa483 (.DATA_A (INT_SUM[657]), .DATA_B (INT_SUM[658]), .DATA_C (INT_CARRY[527]), .SAVE (INT_SUM[659]), .CARRY (INT_CARRY[533]) );
+ smhalfadder dha49 (.DATA_A (INT_SUM[659]), .DATA_B (INT_CARRY[528]), .SAVE (INT_SUM[660]), .CARRY (INT_CARRY[529]) );
+ smffb dla720 (.D(INT_SUM[660]), .clk(clk), .en_d2(en_d2), .Q(SUM[58]) );
+ smffb dla721 (.D(INT_CARRY[529]), .clk(clk), .en_d2(en_d2), .Q(CARRY[58]) );
+ smffa dla722 (.D(SUMMAND[605]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[605]) );
+ smffa dla723 (.D(SUMMAND[606]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[606]) );
+ smffa dla724 (.D(SUMMAND[607]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[607]) );
+ smfulladder dfa484 (.DATA_A (LATCHED_PP[605]), .DATA_B (LATCHED_PP[606]), .DATA_C (LATCHED_PP[607]), .SAVE (INT_SUM[661]), .CARRY (INT_CARRY[535]) );
+ smffa dla725 (.D(SUMMAND[608]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[608]) );
+ smffa dla726 (.D(SUMMAND[609]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[609]) );
+ smhalfadder dha50 (.DATA_A (LATCHED_PP[608]), .DATA_B (LATCHED_PP[609]), .SAVE (INT_SUM[662]), .CARRY (INT_CARRY[536]) );
+ smfulladder dfa485 (.DATA_A (INT_SUM[661]), .DATA_B (INT_SUM[662]), .DATA_C (INT_CARRY[530]), .SAVE (INT_SUM[663]), .CARRY (INT_CARRY[537]) );
+ assign INT_SUM[664] = INT_CARRY[531];
+ smfulladder dfa486 (.DATA_A (INT_SUM[663]), .DATA_B (INT_SUM[664]), .DATA_C (INT_CARRY[532]), .SAVE (INT_SUM[665]), .CARRY (INT_CARRY[538]) );
+ smhalfadder dha51 (.DATA_A (INT_SUM[665]), .DATA_B (INT_CARRY[533]), .SAVE (INT_SUM[666]), .CARRY (INT_CARRY[534]) );
+ smffb dla727 (.D(INT_SUM[666]), .clk(clk), .en_d2(en_d2), .Q(SUM[59]) );
+ smffb dla728 (.D(INT_CARRY[534]), .clk(clk), .en_d2(en_d2), .Q(CARRY[59]) );
+ smffa dla729 (.D(SUMMAND[610]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[610]) );
+ smffa dla730 (.D(SUMMAND[611]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[611]) );
+ smffa dla731 (.D(SUMMAND[612]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[612]) );
+ smfulladder dfa487 (.DATA_A (LATCHED_PP[610]), .DATA_B (LATCHED_PP[611]), .DATA_C (LATCHED_PP[612]), .SAVE (INT_SUM[667]), .CARRY (INT_CARRY[540]) );
+ smffa dla732 (.D(SUMMAND[613]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[613]) );
+ smfulladder dfa488 (.DATA_A (LATCHED_PP[613]), .DATA_B (INT_CARRY[535]), .DATA_C (INT_CARRY[536]), .SAVE (INT_SUM[668]), .CARRY (INT_CARRY[541]) );
+ smfulladder dfa489 (.DATA_A (INT_SUM[667]), .DATA_B (INT_SUM[668]), .DATA_C (INT_CARRY[537]), .SAVE (INT_SUM[669]), .CARRY (INT_CARRY[542]) );
+ smhalfadder dha52 (.DATA_A (INT_SUM[669]), .DATA_B (INT_CARRY[538]), .SAVE (INT_SUM[670]), .CARRY (INT_CARRY[539]) );
+ smffb dla733 (.D(INT_SUM[670]), .clk(clk), .en_d2(en_d2), .Q(SUM[60]) );
+ smffb dla734 (.D(INT_CARRY[539]), .clk(clk), .en_d2(en_d2), .Q(CARRY[60]) );
+ smffa dla735 (.D(SUMMAND[614]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[614]) );
+ smffa dla736 (.D(SUMMAND[615]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[615]) );
+ smffa dla737 (.D(SUMMAND[616]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[616]) );
+ smfulladder dfa490 (.DATA_A (LATCHED_PP[614]), .DATA_B (LATCHED_PP[615]), .DATA_C (LATCHED_PP[616]), .SAVE (INT_SUM[671]), .CARRY (INT_CARRY[544]) );
+ smffa dla738 (.D(SUMMAND[617]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[617]) );
+ assign INT_SUM[672] = LATCHED_PP[617];
+ smfulladder dfa491 (.DATA_A (INT_SUM[671]), .DATA_B (INT_SUM[672]), .DATA_C (INT_CARRY[540]), .SAVE (INT_SUM[673]), .CARRY (INT_CARRY[545]) );
+ assign INT_SUM[674] = INT_CARRY[541];
+ smfulladder dfa492 (.DATA_A (INT_SUM[673]), .DATA_B (INT_SUM[674]), .DATA_C (INT_CARRY[542]), .SAVE (INT_SUM[675]), .CARRY (INT_CARRY[543]) );
+ smffb dla739 (.D(INT_SUM[675]), .clk(clk), .en_d2(en_d2), .Q(SUM[61]) );
+ smffb dla740 (.D(INT_CARRY[543]), .clk(clk), .en_d2(en_d2), .Q(CARRY[61]) );
+ smffa dla741 (.D(SUMMAND[618]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[618]) );
+ smffa dla742 (.D(SUMMAND[619]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[619]) );
+ smffa dla743 (.D(SUMMAND[620]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[620]) );
+ smfulladder dfa493 (.DATA_A (LATCHED_PP[618]), .DATA_B (LATCHED_PP[619]), .DATA_C (LATCHED_PP[620]), .SAVE (INT_SUM[676]), .CARRY (INT_CARRY[547]) );
+ assign INT_SUM[677] = INT_SUM[676];
+ assign INT_SUM[678] = INT_CARRY[544];
+ smfulladder dfa494 (.DATA_A (INT_SUM[677]), .DATA_B (INT_SUM[678]), .DATA_C (INT_CARRY[545]), .SAVE (INT_SUM[679]), .CARRY (INT_CARRY[546]) );
+ smffb dla744 (.D(INT_SUM[679]), .clk(clk), .en_d2(en_d2), .Q(SUM[62]) );
+ smffb dla745 (.D(INT_CARRY[546]), .clk(clk), .en_d2(en_d2), .Q(CARRY[62]) );
+ smffa dla746 (.D(SUMMAND[621]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[621]) );
+ smffa dla747 (.D(SUMMAND[622]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[622]) );
+ smffa dla748 (.D(SUMMAND[623]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[623]) );
+ smfulladder dfa495 (.DATA_A (LATCHED_PP[621]), .DATA_B (LATCHED_PP[622]), .DATA_C (LATCHED_PP[623]), .SAVE (INT_SUM[680]), .CARRY (INT_CARRY[549]) );
+ assign INT_SUM[681] = INT_CARRY[547];
+ smhalfadder dha53 (.DATA_A (INT_SUM[680]), .DATA_B (INT_SUM[681]), .SAVE (INT_SUM[682]), .CARRY (INT_CARRY[548]) );
+ smffb dla749 (.D(INT_SUM[682]), .clk(clk), .en_d2(en_d2), .Q(SUM[63]) );
+ smffb dla750 (.D(INT_CARRY[548]), .clk(clk), .en_d2(en_d2), .Q(CARRY[63]) );
+ smffa dla751 (.D(SUMMAND[624]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[624]) );
+ assign INT_SUM[683] = LATCHED_PP[624];
+ smffa dla752 (.D(SUMMAND[625]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[625]) );
+ assign INT_SUM[684] = LATCHED_PP[625];
+ smfulladder dfa496 (.DATA_A (INT_SUM[683]), .DATA_B (INT_SUM[684]), .DATA_C (INT_CARRY[549]), .SAVE (INT_SUM[685]), .CARRY (INT_CARRY[550]) );
+ smffb dla753 (.D(INT_SUM[685]), .clk(clk), .en_d2(en_d2), .Q(SUM[64]) );
+ smffb dla754 (.D(INT_CARRY[550]), .clk(clk), .en_d2(en_d2), .Q(CARRY[64]) );
+ smffa dla755 (.D(SUMMAND[626]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[626]) );
+ smffa dla756 (.D(SUMMAND[627]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[627]) );
+ smhalfadder dha54 (.DATA_A (LATCHED_PP[626]), .DATA_B (LATCHED_PP[627]), .SAVE (INT_SUM[686]), .CARRY (INT_CARRY[551]) );
+ smffb dla757 (.D(INT_SUM[686]), .clk(clk), .en_d2(en_d2), .Q(SUM[65]) );
+ smffb dla758 (.D(INT_CARRY[551]), .clk(clk), .en_d2(en_d2), .Q(CARRY[65]) );
+ smffa dla759 (.D(SUMMAND[628]), .clk(clk), .en_d1(en_d1), .Q(LATCHED_PP[628]) );
+ assign INT_SUM[687] = LATCHED_PP[628];
+ smffb dla760 (.D(INT_SUM[687]), .clk(clk), .en_d2(en_d2), .Q(SUM[66]) );
+endmodule
+
+module smprestage_128 ( A, B, CIN, POUT, GOUT );
+ input [63:0] A;
+ input [63:0] B;
+ input CIN;
+ output [63:0] POUT;
+ output [63:0] GOUT;
+ smblock0 d10 (A[0], B[0], POUT[0], GOUT[1] );
+ smblock0 d11 (A[1], B[1], POUT[1], GOUT[2] );
+ smblock0 d12 (A[2], B[2], POUT[2], GOUT[3] );
+ smblock0 d13 (A[3], B[3], POUT[3], GOUT[4] );
+ smblock0 d14 (A[4], B[4], POUT[4], GOUT[5] );
+ smblock0 d15 (A[5], B[5], POUT[5], GOUT[6] );
+ smblock0 d16 (A[6], B[6], POUT[6], GOUT[7] );
+ smblock0 d17 (A[7], B[7], POUT[7], GOUT[8] );
+ smblock0 d18 (A[8], B[8], POUT[8], GOUT[9] );
+ smblock0 d19 (A[9], B[9], POUT[9], GOUT[10] );
+ smblock0 d110 (A[10], B[10], POUT[10], GOUT[11] );
+ smblock0 d111 (A[11], B[11], POUT[11], GOUT[12] );
+ smblock0 d112 (A[12], B[12], POUT[12], GOUT[13] );
+ smblock0 d113 (A[13], B[13], POUT[13], GOUT[14] );
+ smblock0 d114 (A[14], B[14], POUT[14], GOUT[15] );
+ smblock0 d115 (A[15], B[15], POUT[15], GOUT[16] );
+ smblock0 d116 (A[16], B[16], POUT[16], GOUT[17] );
+ smblock0 d117 (A[17], B[17], POUT[17], GOUT[18] );
+ smblock0 d118 (A[18], B[18], POUT[18], GOUT[19] );
+ smblock0 d119 (A[19], B[19], POUT[19], GOUT[20] );
+ smblock0 d120 (A[20], B[20], POUT[20], GOUT[21] );
+ smblock0 d121 (A[21], B[21], POUT[21], GOUT[22] );
+ smblock0 d122 (A[22], B[22], POUT[22], GOUT[23] );
+ smblock0 d123 (A[23], B[23], POUT[23], GOUT[24] );
+ smblock0 d124 (A[24], B[24], POUT[24], GOUT[25] );
+ smblock0 d125 (A[25], B[25], POUT[25], GOUT[26] );
+ smblock0 d126 (A[26], B[26], POUT[26], GOUT[27] );
+ smblock0 d127 (A[27], B[27], POUT[27], GOUT[28] );
+ smblock0 d128 (A[28], B[28], POUT[28], GOUT[29] );
+ smblock0 d129 (A[29], B[29], POUT[29], GOUT[30] );
+ smblock0 d130 (A[30], B[30], POUT[30], GOUT[31] );
+ smblock0 d131 (A[31], B[31], POUT[31], GOUT[32] );
+ smblock0 d132 (A[32], B[32], POUT[32], GOUT[33] );
+ smblock0 d133 (A[33], B[33], POUT[33], GOUT[34] );
+ smblock0 d134 (A[34], B[34], POUT[34], GOUT[35] );
+ smblock0 d135 (A[35], B[35], POUT[35], GOUT[36] );
+ smblock0 d136 (A[36], B[36], POUT[36], GOUT[37] );
+ smblock0 d137 (A[37], B[37], POUT[37], GOUT[38] );
+ smblock0 d138 (A[38], B[38], POUT[38], GOUT[39] );
+ smblock0 d139 (A[39], B[39], POUT[39], GOUT[40] );
+ smblock0 d140 (A[40], B[40], POUT[40], GOUT[41] );
+ smblock0 d141 (A[41], B[41], POUT[41], GOUT[42] );
+ smblock0 d142 (A[42], B[42], POUT[42], GOUT[43] );
+ smblock0 d143 (A[43], B[43], POUT[43], GOUT[44] );
+ smblock0 d144 (A[44], B[44], POUT[44], GOUT[45] );
+ smblock0 d145 (A[45], B[45], POUT[45], GOUT[46] );
+ smblock0 d146 (A[46], B[46], POUT[46], GOUT[47] );
+ smblock0 d147 (A[47], B[47], POUT[47], GOUT[48] );
+ smblock0 d148 (A[48], B[48], POUT[48], GOUT[49] );
+ smblock0 d149 (A[49], B[49], POUT[49], GOUT[50] );
+ smblock0 d150 (A[50], B[50], POUT[50], GOUT[51] );
+ smblock0 d151 (A[51], B[51], POUT[51], GOUT[52] );
+ smblock0 d152 (A[52], B[52], POUT[52], GOUT[53] );
+ smblock0 d153 (A[53], B[53], POUT[53], GOUT[54] );
+ smblock0 d154 (A[54], B[54], POUT[54], GOUT[55] );
+ smblock0 d155 (A[55], B[55], POUT[55], GOUT[56] );
+ smblock0 d156 (A[56], B[56], POUT[56], GOUT[57] );
+ smblock0 d157 (A[57], B[57], POUT[57], GOUT[58] );
+ smblock0 d158 (A[58], B[58], POUT[58], GOUT[59] );
+ smblock0 d159 (A[59], B[59], POUT[59], GOUT[60] );
+ smblock0 d160 (A[60], B[60], POUT[60], GOUT[61] );
+ smblock0 d161 (A[61], B[61], POUT[61], GOUT[62] );
+ smblock0 d162 (A[62], B[62], POUT[62], GOUT[63] );
+ sminvblock d2 (CIN, GOUT[0] );
+endmodule
+
+module smdblc_0_128 ( PIN, GIN, POUT, GOUT );
+ input [63:0] PIN;
+ input [63:0] GIN;
+ output [63:0] POUT;
+ output [63:0] GOUT;
+ sminvblock d10 (GIN[0], GOUT[0] );
+ smblock1a d21 (PIN[0], GIN[0], GIN[1], GOUT[1] );
+ smblock1 d32 (PIN[0], PIN[1], GIN[1], GIN[2], POUT[0], GOUT[2] );
+ smblock1 d33 (PIN[1], PIN[2], GIN[2], GIN[3], POUT[1], GOUT[3] );
+ smblock1 d34 (PIN[2], PIN[3], GIN[3], GIN[4], POUT[2], GOUT[4] );
+ smblock1 d35 (PIN[3], PIN[4], GIN[4], GIN[5], POUT[3], GOUT[5] );
+ smblock1 d36 (PIN[4], PIN[5], GIN[5], GIN[6], POUT[4], GOUT[6] );
+ smblock1 d37 (PIN[5], PIN[6], GIN[6], GIN[7], POUT[5], GOUT[7] );
+ smblock1 d38 (PIN[6], PIN[7], GIN[7], GIN[8], POUT[6], GOUT[8] );
+ smblock1 d39 (PIN[7], PIN[8], GIN[8], GIN[9], POUT[7], GOUT[9] );
+ smblock1 d310 (PIN[8], PIN[9], GIN[9], GIN[10], POUT[8], GOUT[10] );
+ smblock1 d311 (PIN[9], PIN[10], GIN[10], GIN[11], POUT[9], GOUT[11] );
+ smblock1 d312 (PIN[10], PIN[11], GIN[11], GIN[12], POUT[10], GOUT[12] );
+ smblock1 d313 (PIN[11], PIN[12], GIN[12], GIN[13], POUT[11], GOUT[13] );
+ smblock1 d314 (PIN[12], PIN[13], GIN[13], GIN[14], POUT[12], GOUT[14] );
+ smblock1 d315 (PIN[13], PIN[14], GIN[14], GIN[15], POUT[13], GOUT[15] );
+ smblock1 d316 (PIN[14], PIN[15], GIN[15], GIN[16], POUT[14], GOUT[16] );
+ smblock1 d317 (PIN[15], PIN[16], GIN[16], GIN[17], POUT[15], GOUT[17] );
+ smblock1 d318 (PIN[16], PIN[17], GIN[17], GIN[18], POUT[16], GOUT[18] );
+ smblock1 d319 (PIN[17], PIN[18], GIN[18], GIN[19], POUT[17], GOUT[19] );
+ smblock1 d320 (PIN[18], PIN[19], GIN[19], GIN[20], POUT[18], GOUT[20] );
+ smblock1 d321 (PIN[19], PIN[20], GIN[20], GIN[21], POUT[19], GOUT[21] );
+ smblock1 d322 (PIN[20], PIN[21], GIN[21], GIN[22], POUT[20], GOUT[22] );
+ smblock1 d323 (PIN[21], PIN[22], GIN[22], GIN[23], POUT[21], GOUT[23] );
+ smblock1 d324 (PIN[22], PIN[23], GIN[23], GIN[24], POUT[22], GOUT[24] );
+ smblock1 d325 (PIN[23], PIN[24], GIN[24], GIN[25], POUT[23], GOUT[25] );
+ smblock1 d326 (PIN[24], PIN[25], GIN[25], GIN[26], POUT[24], GOUT[26] );
+ smblock1 d327 (PIN[25], PIN[26], GIN[26], GIN[27], POUT[25], GOUT[27] );
+ smblock1 d328 (PIN[26], PIN[27], GIN[27], GIN[28], POUT[26], GOUT[28] );
+ smblock1 d329 (PIN[27], PIN[28], GIN[28], GIN[29], POUT[27], GOUT[29] );
+ smblock1 d330 (PIN[28], PIN[29], GIN[29], GIN[30], POUT[28], GOUT[30] );
+ smblock1 d331 (PIN[29], PIN[30], GIN[30], GIN[31], POUT[29], GOUT[31] );
+ smblock1 d332 (PIN[30], PIN[31], GIN[31], GIN[32], POUT[30], GOUT[32] );
+ smblock1 d333 (PIN[31], PIN[32], GIN[32], GIN[33], POUT[31], GOUT[33] );
+ smblock1 d334 (PIN[32], PIN[33], GIN[33], GIN[34], POUT[32], GOUT[34] );
+ smblock1 d335 (PIN[33], PIN[34], GIN[34], GIN[35], POUT[33], GOUT[35] );
+ smblock1 d336 (PIN[34], PIN[35], GIN[35], GIN[36], POUT[34], GOUT[36] );
+ smblock1 d337 (PIN[35], PIN[36], GIN[36], GIN[37], POUT[35], GOUT[37] );
+ smblock1 d338 (PIN[36], PIN[37], GIN[37], GIN[38], POUT[36], GOUT[38] );
+ smblock1 d339 (PIN[37], PIN[38], GIN[38], GIN[39], POUT[37], GOUT[39] );
+ smblock1 d340 (PIN[38], PIN[39], GIN[39], GIN[40], POUT[38], GOUT[40] );
+ smblock1 d341 (PIN[39], PIN[40], GIN[40], GIN[41], POUT[39], GOUT[41] );
+ smblock1 d342 (PIN[40], PIN[41], GIN[41], GIN[42], POUT[40], GOUT[42] );
+ smblock1 d343 (PIN[41], PIN[42], GIN[42], GIN[43], POUT[41], GOUT[43] );
+ smblock1 d344 (PIN[42], PIN[43], GIN[43], GIN[44], POUT[42], GOUT[44] );
+ smblock1 d345 (PIN[43], PIN[44], GIN[44], GIN[45], POUT[43], GOUT[45] );
+ smblock1 d346 (PIN[44], PIN[45], GIN[45], GIN[46], POUT[44], GOUT[46] );
+ smblock1 d347 (PIN[45], PIN[46], GIN[46], GIN[47], POUT[45], GOUT[47] );
+ smblock1 d348 (PIN[46], PIN[47], GIN[47], GIN[48], POUT[46], GOUT[48] );
+ smblock1 d349 (PIN[47], PIN[48], GIN[48], GIN[49], POUT[47], GOUT[49] );
+ smblock1 d350 (PIN[48], PIN[49], GIN[49], GIN[50], POUT[48], GOUT[50] );
+ smblock1 d351 (PIN[49], PIN[50], GIN[50], GIN[51], POUT[49], GOUT[51] );
+ smblock1 d352 (PIN[50], PIN[51], GIN[51], GIN[52], POUT[50], GOUT[52] );
+ smblock1 d353 (PIN[51], PIN[52], GIN[52], GIN[53], POUT[51], GOUT[53] );
+ smblock1 d354 (PIN[52], PIN[53], GIN[53], GIN[54], POUT[52], GOUT[54] );
+ smblock1 d355 (PIN[53], PIN[54], GIN[54], GIN[55], POUT[53], GOUT[55] );
+ smblock1 d356 (PIN[54], PIN[55], GIN[55], GIN[56], POUT[54], GOUT[56] );
+ smblock1 d357 (PIN[55], PIN[56], GIN[56], GIN[57], POUT[55], GOUT[57] );
+ smblock1 d358 (PIN[56], PIN[57], GIN[57], GIN[58], POUT[56], GOUT[58] );
+ smblock1 d359 (PIN[57], PIN[58], GIN[58], GIN[59], POUT[57], GOUT[59] );
+ smblock1 d360 (PIN[58], PIN[59], GIN[59], GIN[60], POUT[58], GOUT[60] );
+ smblock1 d361 (PIN[59], PIN[60], GIN[60], GIN[61], POUT[59], GOUT[61] );
+ smblock1 d362 (PIN[60], PIN[61], GIN[61], GIN[62], POUT[60], GOUT[62] );
+ smblock1 d363 (PIN[61], PIN[62], GIN[62], GIN[63], POUT[61], GOUT[63] );
+endmodule
+
+module smdblc_1_128 ( PIN, GIN, POUT, GOUT );
+ input [63:0] PIN;
+ input [63:0] GIN;
+ output [63:0] POUT;
+ output [63:0] GOUT;
+ sminvblock d10 (GIN[0], GOUT[0] );
+ sminvblock d11 (GIN[1], GOUT[1] );
+ smblock2a d22 (PIN[0], GIN[0], GIN[2], GOUT[2] );
+ smblock2a d23 (PIN[1], GIN[1], GIN[3], GOUT[3] );
+ smblock2 d34 (PIN[0], PIN[2], GIN[2], GIN[4], POUT[0], GOUT[4] );
+ smblock2 d35 (PIN[1], PIN[3], GIN[3], GIN[5], POUT[1], GOUT[5] );
+ smblock2 d36 (PIN[2], PIN[4], GIN[4], GIN[6], POUT[2], GOUT[6] );
+ smblock2 d37 (PIN[3], PIN[5], GIN[5], GIN[7], POUT[3], GOUT[7] );
+ smblock2 d38 (PIN[4], PIN[6], GIN[6], GIN[8], POUT[4], GOUT[8] );
+ smblock2 d39 (PIN[5], PIN[7], GIN[7], GIN[9], POUT[5], GOUT[9] );
+ smblock2 d310 (PIN[6], PIN[8], GIN[8], GIN[10], POUT[6], GOUT[10] );
+ smblock2 d311 (PIN[7], PIN[9], GIN[9], GIN[11], POUT[7], GOUT[11] );
+ smblock2 d312 (PIN[8], PIN[10], GIN[10], GIN[12], POUT[8], GOUT[12] );
+ smblock2 d313 (PIN[9], PIN[11], GIN[11], GIN[13], POUT[9], GOUT[13] );
+ smblock2 d314 (PIN[10], PIN[12], GIN[12], GIN[14], POUT[10], GOUT[14] );
+ smblock2 d315 (PIN[11], PIN[13], GIN[13], GIN[15], POUT[11], GOUT[15] );
+ smblock2 d316 (PIN[12], PIN[14], GIN[14], GIN[16], POUT[12], GOUT[16] );
+ smblock2 d317 (PIN[13], PIN[15], GIN[15], GIN[17], POUT[13], GOUT[17] );
+ smblock2 d318 (PIN[14], PIN[16], GIN[16], GIN[18], POUT[14], GOUT[18] );
+ smblock2 d319 (PIN[15], PIN[17], GIN[17], GIN[19], POUT[15], GOUT[19] );
+ smblock2 d320 (PIN[16], PIN[18], GIN[18], GIN[20], POUT[16], GOUT[20] );
+ smblock2 d321 (PIN[17], PIN[19], GIN[19], GIN[21], POUT[17], GOUT[21] );
+ smblock2 d322 (PIN[18], PIN[20], GIN[20], GIN[22], POUT[18], GOUT[22] );
+ smblock2 d323 (PIN[19], PIN[21], GIN[21], GIN[23], POUT[19], GOUT[23] );
+ smblock2 d324 (PIN[20], PIN[22], GIN[22], GIN[24], POUT[20], GOUT[24] );
+ smblock2 d325 (PIN[21], PIN[23], GIN[23], GIN[25], POUT[21], GOUT[25] );
+ smblock2 d326 (PIN[22], PIN[24], GIN[24], GIN[26], POUT[22], GOUT[26] );
+ smblock2 d327 (PIN[23], PIN[25], GIN[25], GIN[27], POUT[23], GOUT[27] );
+ smblock2 d328 (PIN[24], PIN[26], GIN[26], GIN[28], POUT[24], GOUT[28] );
+ smblock2 d329 (PIN[25], PIN[27], GIN[27], GIN[29], POUT[25], GOUT[29] );
+ smblock2 d330 (PIN[26], PIN[28], GIN[28], GIN[30], POUT[26], GOUT[30] );
+ smblock2 d331 (PIN[27], PIN[29], GIN[29], GIN[31], POUT[27], GOUT[31] );
+ smblock2 d332 (PIN[28], PIN[30], GIN[30], GIN[32], POUT[28], GOUT[32] );
+ smblock2 d333 (PIN[29], PIN[31], GIN[31], GIN[33], POUT[29], GOUT[33] );
+ smblock2 d334 (PIN[30], PIN[32], GIN[32], GIN[34], POUT[30], GOUT[34] );
+ smblock2 d335 (PIN[31], PIN[33], GIN[33], GIN[35], POUT[31], GOUT[35] );
+ smblock2 d336 (PIN[32], PIN[34], GIN[34], GIN[36], POUT[32], GOUT[36] );
+ smblock2 d337 (PIN[33], PIN[35], GIN[35], GIN[37], POUT[33], GOUT[37] );
+ smblock2 d338 (PIN[34], PIN[36], GIN[36], GIN[38], POUT[34], GOUT[38] );
+ smblock2 d339 (PIN[35], PIN[37], GIN[37], GIN[39], POUT[35], GOUT[39] );
+ smblock2 d340 (PIN[36], PIN[38], GIN[38], GIN[40], POUT[36], GOUT[40] );
+ smblock2 d341 (PIN[37], PIN[39], GIN[39], GIN[41], POUT[37], GOUT[41] );
+ smblock2 d342 (PIN[38], PIN[40], GIN[40], GIN[42], POUT[38], GOUT[42] );
+ smblock2 d343 (PIN[39], PIN[41], GIN[41], GIN[43], POUT[39], GOUT[43] );
+ smblock2 d344 (PIN[40], PIN[42], GIN[42], GIN[44], POUT[40], GOUT[44] );
+ smblock2 d345 (PIN[41], PIN[43], GIN[43], GIN[45], POUT[41], GOUT[45] );
+ smblock2 d346 (PIN[42], PIN[44], GIN[44], GIN[46], POUT[42], GOUT[46] );
+ smblock2 d347 (PIN[43], PIN[45], GIN[45], GIN[47], POUT[43], GOUT[47] );
+ smblock2 d348 (PIN[44], PIN[46], GIN[46], GIN[48], POUT[44], GOUT[48] );
+ smblock2 d349 (PIN[45], PIN[47], GIN[47], GIN[49], POUT[45], GOUT[49] );
+ smblock2 d350 (PIN[46], PIN[48], GIN[48], GIN[50], POUT[46], GOUT[50] );
+ smblock2 d351 (PIN[47], PIN[49], GIN[49], GIN[51], POUT[47], GOUT[51] );
+ smblock2 d352 (PIN[48], PIN[50], GIN[50], GIN[52], POUT[48], GOUT[52] );
+ smblock2 d353 (PIN[49], PIN[51], GIN[51], GIN[53], POUT[49], GOUT[53] );
+ smblock2 d354 (PIN[50], PIN[52], GIN[52], GIN[54], POUT[50], GOUT[54] );
+ smblock2 d355 (PIN[51], PIN[53], GIN[53], GIN[55], POUT[51], GOUT[55] );
+ smblock2 d356 (PIN[52], PIN[54], GIN[54], GIN[56], POUT[52], GOUT[56] );
+ smblock2 d357 (PIN[53], PIN[55], GIN[55], GIN[57], POUT[53], GOUT[57] );
+ smblock2 d358 (PIN[54], PIN[56], GIN[56], GIN[58], POUT[54], GOUT[58] );
+ smblock2 d359 (PIN[55], PIN[57], GIN[57], GIN[59], POUT[55], GOUT[59] );
+ smblock2 d360 (PIN[56], PIN[58], GIN[58], GIN[60], POUT[56], GOUT[60] );
+ smblock2 d361 (PIN[57], PIN[59], GIN[59], GIN[61], POUT[57], GOUT[61] );
+ smblock2 d362 (PIN[58], PIN[60], GIN[60], GIN[62], POUT[58], GOUT[62] );
+ smblock2 d363 (PIN[59], PIN[61], GIN[61], GIN[63], POUT[59], GOUT[63] );
+endmodule
+
+module smdblc_2_128 ( PIN, GIN, POUT, GOUT );
+ input [63:0] PIN;
+ input [63:0] GIN;
+ output [63:0] POUT;
+ output [63:0] GOUT;
+ sminvblock d10 (GIN[0], GOUT[0] );
+ sminvblock d11 (GIN[1], GOUT[1] );
+ sminvblock d12 (GIN[2], GOUT[2] );
+ sminvblock d13 (GIN[3], GOUT[3] );
+ smblock1a d24 (PIN[0], GIN[0], GIN[4], GOUT[4] );
+ smblock1a d25 (PIN[1], GIN[1], GIN[5], GOUT[5] );
+ smblock1a d26 (PIN[2], GIN[2], GIN[6], GOUT[6] );
+ smblock1a d27 (PIN[3], GIN[3], GIN[7], GOUT[7] );
+ smblock1 d38 (PIN[0], PIN[4], GIN[4], GIN[8], POUT[0], GOUT[8] );
+ smblock1 d39 (PIN[1], PIN[5], GIN[5], GIN[9], POUT[1], GOUT[9] );
+ smblock1 d310 (PIN[2], PIN[6], GIN[6], GIN[10], POUT[2], GOUT[10] );
+ smblock1 d311 (PIN[3], PIN[7], GIN[7], GIN[11], POUT[3], GOUT[11] );
+ smblock1 d312 (PIN[4], PIN[8], GIN[8], GIN[12], POUT[4], GOUT[12] );
+ smblock1 d313 (PIN[5], PIN[9], GIN[9], GIN[13], POUT[5], GOUT[13] );
+ smblock1 d314 (PIN[6], PIN[10], GIN[10], GIN[14], POUT[6], GOUT[14] );
+ smblock1 d315 (PIN[7], PIN[11], GIN[11], GIN[15], POUT[7], GOUT[15] );
+ smblock1 d316 (PIN[8], PIN[12], GIN[12], GIN[16], POUT[8], GOUT[16] );
+ smblock1 d317 (PIN[9], PIN[13], GIN[13], GIN[17], POUT[9], GOUT[17] );
+ smblock1 d318 (PIN[10], PIN[14], GIN[14], GIN[18], POUT[10], GOUT[18] );
+ smblock1 d319 (PIN[11], PIN[15], GIN[15], GIN[19], POUT[11], GOUT[19] );
+ smblock1 d320 (PIN[12], PIN[16], GIN[16], GIN[20], POUT[12], GOUT[20] );
+ smblock1 d321 (PIN[13], PIN[17], GIN[17], GIN[21], POUT[13], GOUT[21] );
+ smblock1 d322 (PIN[14], PIN[18], GIN[18], GIN[22], POUT[14], GOUT[22] );
+ smblock1 d323 (PIN[15], PIN[19], GIN[19], GIN[23], POUT[15], GOUT[23] );
+ smblock1 d324 (PIN[16], PIN[20], GIN[20], GIN[24], POUT[16], GOUT[24] );
+ smblock1 d325 (PIN[17], PIN[21], GIN[21], GIN[25], POUT[17], GOUT[25] );
+ smblock1 d326 (PIN[18], PIN[22], GIN[22], GIN[26], POUT[18], GOUT[26] );
+ smblock1 d327 (PIN[19], PIN[23], GIN[23], GIN[27], POUT[19], GOUT[27] );
+ smblock1 d328 (PIN[20], PIN[24], GIN[24], GIN[28], POUT[20], GOUT[28] );
+ smblock1 d329 (PIN[21], PIN[25], GIN[25], GIN[29], POUT[21], GOUT[29] );
+ smblock1 d330 (PIN[22], PIN[26], GIN[26], GIN[30], POUT[22], GOUT[30] );
+ smblock1 d331 (PIN[23], PIN[27], GIN[27], GIN[31], POUT[23], GOUT[31] );
+ smblock1 d332 (PIN[24], PIN[28], GIN[28], GIN[32], POUT[24], GOUT[32] );
+ smblock1 d333 (PIN[25], PIN[29], GIN[29], GIN[33], POUT[25], GOUT[33] );
+ smblock1 d334 (PIN[26], PIN[30], GIN[30], GIN[34], POUT[26], GOUT[34] );
+ smblock1 d335 (PIN[27], PIN[31], GIN[31], GIN[35], POUT[27], GOUT[35] );
+ smblock1 d336 (PIN[28], PIN[32], GIN[32], GIN[36], POUT[28], GOUT[36] );
+ smblock1 d337 (PIN[29], PIN[33], GIN[33], GIN[37], POUT[29], GOUT[37] );
+ smblock1 d338 (PIN[30], PIN[34], GIN[34], GIN[38], POUT[30], GOUT[38] );
+ smblock1 d339 (PIN[31], PIN[35], GIN[35], GIN[39], POUT[31], GOUT[39] );
+ smblock1 d340 (PIN[32], PIN[36], GIN[36], GIN[40], POUT[32], GOUT[40] );
+ smblock1 d341 (PIN[33], PIN[37], GIN[37], GIN[41], POUT[33], GOUT[41] );
+ smblock1 d342 (PIN[34], PIN[38], GIN[38], GIN[42], POUT[34], GOUT[42] );
+ smblock1 d343 (PIN[35], PIN[39], GIN[39], GIN[43], POUT[35], GOUT[43] );
+ smblock1 d344 (PIN[36], PIN[40], GIN[40], GIN[44], POUT[36], GOUT[44] );
+ smblock1 d345 (PIN[37], PIN[41], GIN[41], GIN[45], POUT[37], GOUT[45] );
+ smblock1 d346 (PIN[38], PIN[42], GIN[42], GIN[46], POUT[38], GOUT[46] );
+ smblock1 d347 (PIN[39], PIN[43], GIN[43], GIN[47], POUT[39], GOUT[47] );
+ smblock1 d348 (PIN[40], PIN[44], GIN[44], GIN[48], POUT[40], GOUT[48] );
+ smblock1 d349 (PIN[41], PIN[45], GIN[45], GIN[49], POUT[41], GOUT[49] );
+ smblock1 d350 (PIN[42], PIN[46], GIN[46], GIN[50], POUT[42], GOUT[50] );
+ smblock1 d351 (PIN[43], PIN[47], GIN[47], GIN[51], POUT[43], GOUT[51] );
+ smblock1 d352 (PIN[44], PIN[48], GIN[48], GIN[52], POUT[44], GOUT[52] );
+ smblock1 d353 (PIN[45], PIN[49], GIN[49], GIN[53], POUT[45], GOUT[53] );
+ smblock1 d354 (PIN[46], PIN[50], GIN[50], GIN[54], POUT[46], GOUT[54] );
+ smblock1 d355 (PIN[47], PIN[51], GIN[51], GIN[55], POUT[47], GOUT[55] );
+ smblock1 d356 (PIN[48], PIN[52], GIN[52], GIN[56], POUT[48], GOUT[56] );
+ smblock1 d357 (PIN[49], PIN[53], GIN[53], GIN[57], POUT[49], GOUT[57] );
+ smblock1 d358 (PIN[50], PIN[54], GIN[54], GIN[58], POUT[50], GOUT[58] );
+ smblock1 d359 (PIN[51], PIN[55], GIN[55], GIN[59], POUT[51], GOUT[59] );
+ smblock1 d360 (PIN[52], PIN[56], GIN[56], GIN[60], POUT[52], GOUT[60] );
+ smblock1 d361 (PIN[53], PIN[57], GIN[57], GIN[61], POUT[53], GOUT[61] );
+ smblock1 d362 (PIN[54], PIN[58], GIN[58], GIN[62], POUT[54], GOUT[62] );
+ smblock1 d363 (PIN[55], PIN[59], GIN[59], GIN[63], POUT[55], GOUT[63] );
+endmodule
+
+module smdblc_3_128 ( PIN, GIN, POUT, GOUT );
+ input [63:0] PIN;
+ input [63:0] GIN;
+ output [63:0] POUT;
+ output [63:0] GOUT;
+ sminvblock d10 (GIN[0], GOUT[0] );
+ sminvblock d11 (GIN[1], GOUT[1] );
+ sminvblock d12 (GIN[2], GOUT[2] );
+ sminvblock d13 (GIN[3], GOUT[3] );
+ sminvblock d14 (GIN[4], GOUT[4] );
+ sminvblock d15 (GIN[5], GOUT[5] );
+ sminvblock d16 (GIN[6], GOUT[6] );
+ sminvblock d17 (GIN[7], GOUT[7] );
+ smblock2a d28 (PIN[0], GIN[0], GIN[8], GOUT[8] );
+ smblock2a d29 (PIN[1], GIN[1], GIN[9], GOUT[9] );
+ smblock2a d210 (PIN[2], GIN[2], GIN[10], GOUT[10] );
+ smblock2a d211 (PIN[3], GIN[3], GIN[11], GOUT[11] );
+ smblock2a d212 (PIN[4], GIN[4], GIN[12], GOUT[12] );
+ smblock2a d213 (PIN[5], GIN[5], GIN[13], GOUT[13] );
+ smblock2a d214 (PIN[6], GIN[6], GIN[14], GOUT[14] );
+ smblock2a d215 (PIN[7], GIN[7], GIN[15], GOUT[15] );
+ smblock2 d316 (PIN[0], PIN[8], GIN[8], GIN[16], POUT[0], GOUT[16] );
+ smblock2 d317 (PIN[1], PIN[9], GIN[9], GIN[17], POUT[1], GOUT[17] );
+ smblock2 d318 (PIN[2], PIN[10], GIN[10], GIN[18], POUT[2], GOUT[18] );
+ smblock2 d319 (PIN[3], PIN[11], GIN[11], GIN[19], POUT[3], GOUT[19] );
+ smblock2 d320 (PIN[4], PIN[12], GIN[12], GIN[20], POUT[4], GOUT[20] );
+ smblock2 d321 (PIN[5], PIN[13], GIN[13], GIN[21], POUT[5], GOUT[21] );
+ smblock2 d322 (PIN[6], PIN[14], GIN[14], GIN[22], POUT[6], GOUT[22] );
+ smblock2 d323 (PIN[7], PIN[15], GIN[15], GIN[23], POUT[7], GOUT[23] );
+ smblock2 d324 (PIN[8], PIN[16], GIN[16], GIN[24], POUT[8], GOUT[24] );
+ smblock2 d325 (PIN[9], PIN[17], GIN[17], GIN[25], POUT[9], GOUT[25] );
+ smblock2 d326 (PIN[10], PIN[18], GIN[18], GIN[26], POUT[10], GOUT[26] );
+ smblock2 d327 (PIN[11], PIN[19], GIN[19], GIN[27], POUT[11], GOUT[27] );
+ smblock2 d328 (PIN[12], PIN[20], GIN[20], GIN[28], POUT[12], GOUT[28] );
+ smblock2 d329 (PIN[13], PIN[21], GIN[21], GIN[29], POUT[13], GOUT[29] );
+ smblock2 d330 (PIN['b""14], PIN[22], GIN[22], GIN[30], POUT[14], GOUT[30] );
+ smblock2 d331 (PIN[15], PIN[23], GIN[23], GIN[31], POUT[15], GOUT[31] );
+ smblock2 d332 (PIN[16], PIN[24], GIN[24], GIN[32], POUT[16], GOUT[32] );
+ smblock2 d333 (PIN[17], PIN[25], GIN[25], GIN[33], POUT[17], GOUT[33] );
+ smblock2 d334 (PIN[18], PIN[26], GIN[26], GIN[34], POUT[18], GOUT[34] );
+ smblock2 d335 (PIN[19], PIN[27], GIN[27], GIN[35], POUT[19], GOUT[35] );
+ smblock2 d336 (PIN[20], PIN[28], GIN[28], GIN[36], POUT[20], GOUT[36] );
+ smblock2 d337 (PIN[21], PIN[29], GIN[29], GIN[37], POUT[21], GOUT[37] );
+ smblock2 d338 (PIN[22], PIN[30], GIN[30], GIN[38], POUT[22], GOUT[38] );
+ smblock2 d339 (PIN[23], PIN[31], GIN[31], GIN[39], POUT[23], GOUT[39] );
+ smblock2 d340 (PIN[24], PIN[32], GIN[32], GIN[40], POUT[24], GOUT[40] );
+ smblock2 d341 (PIN[25], PIN[33], GIN[33], GIN[41], POUT[25], GOUT[41] );
+ smblock2 d342 (PIN[26], PIN[34], GIN[34], GIN[42], POUT[26], GOUT[42] );
+ smblock2 d343 (PIN[27], PIN[35], GIN[35], GIN[43], POUT[27], GOUT[43] );
+ smblock2 d344 (PIN[28], PIN[36], GIN[36], GIN[44], POUT[28], GOUT[44] );
+ smblock2 d345 (PIN[29], PIN[37], GIN[37], GIN[45], POUT[29], GOUT[45] );
+ smblock2 d346 (PIN[30], PIN[38], GIN[38], GIN[46], POUT[30], GOUT[46] );
+ smblock2 d347 (PIN[31], PIN[39], GIN[39], GIN[47], POUT[31], GOUT[47] );
+ smblock2 d348 (PIN[32], PIN[40], GIN[40], GIN[48], POUT[32], GOUT[48] );
+ smblock2 d349 (PIN[33], PIN[41], GIN[41], GIN[49], POUT[33], GOUT[49] );
+ smblock2 d350 (PIN[34], PIN[42], GIN[42], GIN[50], POUT[34], GOUT[50] );
+ smblock2 d351 (PIN[35], PIN[43], GIN[43], GIN[51], POUT[35], GOUT[51] );
+ smblock2 d352 (PIN[36], PIN[44], GIN[44], GIN[52], POUT[36], GOUT[52] );
+ smblock2 d353 (PIN[37], PIN[45], GIN[45], GIN[53], POUT[37], GOUT[53] );
+ smblock2 d354 (PIN[38], PIN[46], GIN[46], GIN[54], POUT[38], GOUT[54] );
+ smblock2 d355 (PIN[39], PIN[47], GIN[47], GIN[55], POUT[39], GOUT[55] );
+ smblock2 d356 (PIN[40], PIN[48], GIN[48], GIN[56], POUT[40], GOUT[56] );
+ smblock2 d357 (PIN[41], PIN[49], GIN[49], GIN[57], POUT[41], GOUT[57] );
+ smblock2 d358 (PIN[42], PIN[50], GIN[50], GIN[58], POUT[42], GOUT[58] );
+ smblock2 d359 (PIN[43], PIN[51], GIN[51], GIN[59], POUT[43], GOUT[59] );
+ smblock2 d360 (PIN[44], PIN[52], GIN[52], GIN[60], POUT[44], GOUT[60] );
+ smblock2 d361 (PIN[45], PIN[53], GIN[53], GIN[61], POUT[45], GOUT[61] );
+ smblock2 d362 (PIN[46], PIN[54], GIN[54], GIN[62], POUT[46], GOUT[62] );
+ smblock2 d363 (PIN[47], PIN[55], GIN[55], GIN[63], POUT[47], GOUT[63] );
+endmodule
+
+module smdblc_4_128 ( PIN, GIN, POUT, GOUT );
+ input [63:0] PIN;
+ input [63:0] GIN;
+ output [63:0] POUT;
+ output [63:0] GOUT;
+ sminvblock d10 (GIN[0], GOUT[0] );
+ sminvblock d11 (GIN[1], GOUT[1] );
+ sminvblock d12 (GIN[2], GOUT[2] );
+ sminvblock d13 (GIN[3], GOUT[3] );
+ sminvblock d14 (GIN[4], GOUT[4] );
+ sminvblock d15 (GIN[5], GOUT[5] );
+ sminvblock d16 (GIN[6], GOUT[6] );
+ sminvblock d17 (GIN[7], GOUT[7] );
+ sminvblock d18 (GIN[8], GOUT[8] );
+ sminvblock d19 (GIN[9], GOUT[9] );
+ sminvblock d110 (GIN[10], GOUT[10] );
+ sminvblock d111 (GIN[11], GOUT[11] );
+ sminvblock d112 (GIN[12], GOUT[12] );
+ sminvblock d113 (GIN[13], GOUT[13] );
+ sminvblock d114 (GIN[14], GOUT[14] );
+ sminvblock d115 (GIN[15], GOUT[15] );
+ smblock1a d216 (PIN[0], GIN[0], GIN[16], GOUT[16] );
+ smblock1a d217 (PIN[1], GIN[1], GIN[17], GOUT[17] );
+ smblock1a d218 (PIN[2], GIN[2], GIN[18], GOUT[18] );
+ smblock1a d219 (PIN[3], GIN[3], GIN[19], GOUT[19] );
+ smblock1a d220 (PIN[4], GIN[4], GIN[20], GOUT[20] );
+ smblock1a d221 (PIN[5], GIN[5], GIN[21], GOUT[21] );
+ smblock1a d222 (PIN[6], GIN[6], GIN[22], GOUT[22] );
+ smblock1a d223 (PIN[7], GIN[7], GIN[23], GOUT[23] );
+ smblock1a d224 (PIN[8], GIN[8], GIN[24], GOUT[24] );
+ smblock1a d225 (PIN[9], GIN[9], GIN[25], GOUT[25] );
+ smblock1a d226 (PIN[10], GIN[10], GIN[26], GOUT[26] );
+ smblock1a d227 (PIN[11], GIN[11], GIN[27], GOUT[27] );
+ smblock1a d228 (PIN[12], GIN[12], GIN[28], GOUT[28] );
+ smblock1a d229 (PIN[13], GIN[13], GIN[29], GOUT[29] );
+ smblock1a d230 (PIN[14], GIN[14], GIN[30], GOUT[30] );
+ smblock1a d231 (PIN[15], GIN[15], GIN[31], GOUT[31] );
+ smblock1 d332 (PIN[0], PIN[16], GIN[16], GIN[32], POUT[0], GOUT[32] );
+ smblock1 d333 (PIN[1], PIN[17], GIN[17], GIN[33], POUT[1], GOUT[33] );
+ smblock1 d334 (PIN[2], PIN[18], GIN[18], GIN[34], POUT[2], GOUT[34] );
+ smblock1 d335 (PIN[3], PIN[19], GIN[19], GIN[35], POUT[3], GOUT[35] );
+ smblock1 d336 (PIN[4], PIN[20], GIN[20], GIN[36], POUT[4], GOUT[36] );
+ smblock1 d337 (PIN[5], PIN[21], GIN[21], GIN[37], POUT[5], GOUT[37] );
+ smblock1 d338 (PIN[6], PIN[22], GIN[22], GIN[38], POUT[6], GOUT[38] );
+ smblock1 d339 (PIN[7], PIN[23], GIN[23], GIN[39], POUT[7], GOUT[39] );
+ smblock1 d340 (PIN[8], PIN[24], GIN[24], GIN[40], POUT[8], GOUT[40] );
+ smblock1 d341 (PIN[9], PIN[25], GIN[25], GIN[41], POUT[9], GOUT[41] );
+ smblock1 d342 (PIN[10], PIN[26], GIN[26], GIN[42], POUT[10], GOUT[42] );
+ smblock1 d343 (PIN[11], PIN[27], GIN[27], GIN[43], POUT[11], GOUT[43] );
+ smblock1 d344 (PIN[12], PIN[28], GIN[28], GIN[44], POUT[12], GOUT[44] );
+ smblock1 d345 (PIN[13], PIN[29], GIN[29], GIN[45], POUT[13], GOUT[45] );
+ smblock1 d346 (PIN[14], PIN[30], GIN[30], GIN[46], POUT[14], GOUT[46] );
+ smblock1 d347 (PIN[15], PIN[31], GIN[31], GIN[47], POUT[15], GOUT[47] );
+ smblock1 d348 (PIN[16], PIN[32], GIN[32], GIN[48], POUT[16], GOUT[48] );
+ smblock1 d349 (PIN[17], PIN[33], GIN[33], GIN[49], POUT[17], GOUT[49] );
+ smblock1 d350 (PIN[18], PIN[34], GIN[34], GIN[50], POUT[18], GOUT[50] );
+ smblock1 d351 (PIN[19], PIN[35], GIN[35], GIN[51], POUT[19], GOUT[51] );
+ smblock1 d352 (PIN[20], PIN[36], GIN[36], GIN[52], POUT[20], GOUT[52] );
+ smblock1 d353 (PIN[21], PIN[37], GIN[37], GIN[53], POUT[21], GOUT[53] );
+ smblock1 d354 (PIN[22], PIN[38], GIN[38], GIN[54], POUT[22], GOUT[54] );
+ smblock1 d355 (PIN[23], PIN[39], GIN[39], GIN[55], POUT[23], GOUT[55] );
+ smblock1 d356 (PIN[24], PIN[40], GIN[40], GIN[56], POUT[24], GOUT[56] );
+ smblock1 d357 (PIN[25], PIN[41], GIN[41], GIN[57], POUT[25], GOUT[57] );
+ smblock1 d358 (PIN[26], PIN[42], GIN[42], GIN[58], POUT[26], GOUT[58] );
+ smblock1 d359 (PIN[27], PIN[43], GIN[43], GIN[59], POUT[27], GOUT[59] );
+ smblock1 d360 (PIN[28], PIN[44], GIN[44], GIN[60], POUT[28], GOUT[60] );
+ smblock1 d361 (PIN[29], PIN[45], GIN[45], GIN[61], POUT[29], GOUT[61] );
+ smblock1 d362 (PIN[30], PIN[46], GIN[46], GIN[62], POUT[30], GOUT[62] );
+ smblock1 d363 (PIN[31], PIN[47], GIN[47], GIN[63], POUT[31], GOUT[63] );
+endmodule
+
+module smxorstage_128 ( A, B, PBIT, CARRY, SUM );
+ input [63:0] A;
+ input [63:0] B;
+ input PBIT;
+ input [63:0] CARRY;
+ output [63:0] SUM;
+ smxxor1 d20 (A[0], B[0], CARRY[0], SUM[0] );
+ smxxor1 d21 (A[1], B[1], CARRY[1], SUM[1] );
+ smxxor1 d22 (A[2], B[2], CARRY[2], SUM[2] );
+ smxxor1 d23 (A[3], B[3], CARRY[3], SUM[3] );
+ smxxor1 d24 (A[4], B[4], CARRY[4], SUM[4] );
+ smxxor1 d25 (A[5], B[5], CARRY[5], SUM[5] );
+ smxxor1 d26 (A[6], B[6], CARRY[6], SUM[6] );
+ smxxor1 d27 (A[7], B[7], CARRY[7], SUM[7] );
+ smxxor1 d28 (A[8], B[8], CARRY[8], SUM[8] );
+ smxxor1 d29 (A[9], B[9], CARRY[9], SUM[9] );
+ smxxor1 d210 (A[10], B[10], CARRY[10], SUM[10] );
+ smxxor1 d211 (A[11], B[11], CARRY[11], SUM[11] );
+ smxxor1 d212 (A[12], B[12], CARRY[12], SUM[12] );
+ smxxor1 d213 (A[13], B[13], CARRY[13], SUM[13] );
+ smxxor1 d214 (A[14], B[14], CARRY[14], SUM[14] );
+ smxxor1 d215 (A[15], B[15], CARRY[15], SUM[15] );
+ smxxor1 d216 (A[16], B[16], CARRY[16], SUM[16] );
+ smxxor1 d217 (A[17], B[17], CARRY[17], SUM[17] );
+ smxxor1 d218 (A[18], B[18], CARRY[18], SUM[18] );
+ smxxor1 d219 (A[19], B[19], CARRY[19], SUM[19] );
+ smxxor1 d220 (A[20], B[20], CARRY[20], SUM[20] );
+ smxxor1 d221 (A[21], B[21], CARRY[21], SUM[21] );
+ smxxor1 d222 (A[22], B[22], CARRY[22], SUM[22] );
+ smxxor1 d223 (A[23], B[23], CARRY[23], SUM[23] );
+ smxxor1 d224 (A[24], B[24], CARRY[24], SUM[24] );
+ smxxor1 d225 (A[25], B[25], CARRY[25], SUM[25] );
+ smxxor1 d226 (A[26], B[26], CARRY[26], SUM[26] );
+ smxxor1 d227 (A[27], B[27], CARRY[27], SUM[27] );
+ smxxor1 d228 (A[28], B[28], CARRY[28], SUM[28] );
+ smxxor1 d229 (A[29], B[29], CARRY[29], SUM[29] );
+ smxxor1 d230 (A[30], B[30], CARRY[30], SUM[30] );
+ smxxor1 d231 (A[31], B[31], CARRY[31], SUM[31] );
+ smxxor1 d232 (A[32], B[32], CARRY[32], SUM[32] );
+ smxxor1 d233 (A[33], B[33], CARRY[33], SUM[33] );
+ smxxor1 d234 (A[34], B[34], CARRY[34], SUM[34] );
+ smxxor1 d235 (A[35], B[35], CARRY[35], SUM[35] );
+ smxxor1 d236 (A[36], B[36], CARRY[36], SUM[36] );
+ smxxor1 d237 (A[37], B[37], CARRY[37], SUM[37] );
+ smxxor1 d238 (A[38], B[38], CARRY[38], SUM[38] );
+ smxxor1 d239 (A[39], B[39], CARRY[39], SUM[39] );
+ smxxor1 d240 (A[40], B[40], CARRY[40], SUM[40] );
+ smxxor1 d241 (A[41], B[41], CARRY[41], SUM[41] );
+ smxxor1 d242 (A[42], B[42], CARRY[42], SUM[42] );
+ smxxor1 d243 (A[43], B[43], CARRY[43], SUM[43] );
+ smxxor1 d244 (A[44], B[44], CARRY[44], SUM[44] );
+ smxxor1 d245 (A[45], B[45], CARRY[45], SUM[45] );
+ smxxor1 d246 (A[46], B[46], CARRY[46], SUM[46] );
+ smxxor1 d247 (A[47], B[47], CARRY[47], SUM[47] );
+ smxxor1 d248 (A[48], B[48], CARRY[48], SUM[48] );
+ smxxor1 d249 (A[49], B[49], CARRY[49], SUM[49] );
+ smxxor1 d250 (A[50], B[50], CARRY[50], SUM[50] );
+ smxxor1 d251 (A[51], B[51], CARRY[51], SUM[51] );
+ smxxor1 d252 (A[52], B[52], CARRY[52], SUM[52] );
+ smxxor1 d253 (A[53], B[53], CARRY[53], SUM[53] );
+ smxxor1 d254 (A[54], B[54], CARRY[54], SUM[54] );
+ smxxor1 d255 (A[55], B[55], CARRY[55], SUM[55] );
+ smxxor1 d256 (A[56], B[56], CARRY[56], SUM[56] );
+ smxxor1 d257 (A[57], B[57], CARRY[57], SUM[57] );
+ smxxor1 d258 (A[58], B[58], CARRY[58], SUM[58] );
+ smxxor1 d259 (A[59], B[59], CARRY[59], SUM[59] );
+ smxxor1 d260 (A[60], B[60], CARRY[60], SUM[60] );
+ smxxor1 d261 (A[61], B[61], CARRY[61], SUM[61] );
+ smxxor1 d262 (A[62], B[62], CARRY[62], SUM[62] );
+ smxxor1 d263 (A[63], B[63], CARRY[63], SUM[63] );
+endmodule
+
+module smdblc_5_128 ( PIN, GIN, POUT, GOUT );
+ input [63:0] PIN;
+ input [63:0] GIN;
+ output [63:0] POUT;
+ output [63:0] GOUT;
+ sminvblock d10 (GIN[0], GOUT[0] );
+ sminvblock d11 (GIN[1], GOUT[1] );
+ sminvblock d12 (GIN[2], GOUT[2] );
+ sminvblock d13 (GIN[3], GOUT[3] );
+ sminvblock d14 (GIN[4], GOUT[4] );
+ sminvblock d15 (GIN[5], GOUT[5] );
+ sminvblock d16 (GIN[6], GOUT[6] );
+ sminvblock d17 (GIN[7], GOUT[7] );
+ sminvblock d18 (GIN[8], GOUT[8] );
+ sminvblock d19 (GIN[9], GOUT[9] );
+ sminvblock d110 (GIN[10], GOUT[10] );
+ sminvblock d111 (GIN[11], GOUT[11] );
+ sminvblock d112 (GIN[12], GOUT[12] );
+ sminvblock d113 (GIN[13], GOUT[13] );
+ sminvblock d114 (GIN[14], GOUT[14] );
+ sminvblock d115 (GIN[15], GOUT[15] );
+ sminvblock d116 (GIN[16], GOUT[16] );
+ sminvblock d117 (GIN[17], GOUT[17] );
+ sminvblock d118 (GIN[18], GOUT[18] );
+ sminvblock d119 (GIN[19], GOUT[19] );
+ sminvblock d120 (GIN[20], GOUT[20] );
+ sminvblock d121 (GIN[21], GOUT[21] );
+ sminvblock d122 (GIN[22], GOUT[22] );
+ sminvblock d123 (GIN[23], GOUT[23] );
+ sminvblock d124 (GIN[24], GOUT[24] );
+ sminvblock d125 (GIN[25], GOUT[25] );
+ sminvblock d126 (GIN[26], GOUT[26] );
+ sminvblock d127 (GIN[27], GOUT[27] );
+ sminvblock d128 (GIN[28], GOUT[28] );
+ sminvblock d129 (GIN[29], GOUT[29] );
+ sminvblock d130 (GIN[30], GOUT[30] );
+ sminvblock d131 (GIN[31], GOUT[31] );
+ smblock2a d232 (PIN[0], GIN[0], GIN[32], GOUT[32] );
+ smblock2a d233 (PIN[1], GIN[1], GIN[33], GOUT[33] );
+ smblock2a d234 (PIN[2], GIN[2], GIN[34], GOUT[34] );
+ smblock2a d235 (PIN[3], GIN[3], GIN[35], GOUT[35] );
+ smblock2a d236 (PIN[4], GIN[4], GIN[36], GOUT[36] );
+ smblock2a d237 (PIN[5], GIN[5], GIN[37], GOUT[37] );
+ smblock2a d238 (PIN[6], GIN[6], GIN[38], GOUT[38] );
+ smblock2a d239 (PIN[7], GIN[7], GIN[39], GOUT[39] );
+ smblock2a d240 (PIN[8], GIN[8], GIN[40], GOUT[40] );
+ smblock2a d241 (PIN[9], GIN[9], GIN[41], GOUT[41] );
+ smblock2a d242 (PIN[10], GIN[10], GIN[42], GOUT[42] );
+ smblock2a d243 (PIN[11], GIN[11], GIN[43], GOUT[43] );
+ smblock2a d244 (PIN[12], GIN[12], GIN[44], GOUT[44] );
+ smblock2a d245 (PIN[13], GIN[13], GIN[45], GOUT[45] );
+ smblock2a d246 (PIN[14], GIN[14], GIN[46], GOUT[46] );
+ smblock2a d247 (PIN[15], GIN[15], GIN[47], GOUT[47] );
+ smblock2a d248 (PIN[16], GIN[16], GIN[48], GOUT[48] );
+ smblock2a d249 (PIN[17], GIN[17], GIN[49], GOUT[49] );
+ smblock2a d250 (PIN[18], GIN[18], GIN[50], GOUT[50] );
+ smblock2a d251 (PIN[19], GIN[19], GIN[51], GOUT[51] );
+ smblock2a d252 (PIN[20], GIN[20], GIN[52], GOUT[52] );
+ smblock2a d253 (PIN[21], GIN[21], GIN[53], GOUT[53] );
+ smblock2a d254 (PIN[22], GIN[22], GIN[54], GOUT[54] );
+ smblock2a d255 (PIN[23], GIN[23], GIN[55], GOUT[55] );
+ smblock2a d256 (PIN[24], GIN[24], GIN[56], GOUT[56] );
+ smblock2a d257 (PIN[25], GIN[25], GIN[57], GOUT[57] );
+ smblock2a d258 (PIN[26], GIN[26], GIN[58], GOUT[58] );
+ smblock2a d259 (PIN[27], GIN[27], GIN[59], GOUT[59] );
+ smblock2a d260 (PIN[28], GIN[28], GIN[60], GOUT[60] );
+ smblock2a d261 (PIN[29], GIN[29], GIN[61], GOUT[61] );
+ smblock2a d262 (PIN[30], GIN[30], GIN[62], GOUT[62] );
+ smblock2a d263 (PIN[31], GIN[31], GIN[63], GOUT[63] );
+endmodule
+
+module smdblc_6_128 ( PIN, GIN, POUT, GOUT );
+ input [63:0] PIN;
+ input [63:0] GIN;
+ output [0:0] POUT;
+ output [63:0] GOUT;
+ assign GOUT[63:0] = GIN[63:0];
+endmodule
+
+module smboothcoder_34_34 ( OPA, OPB, SUMMAND );
+ input [33:0] OPA;
+ input [33:0] OPB;
+ output [628:0] SUMMAND;
+ wire [33:0] OPA_;
+ wire [67:0] INT_MULTIPLIER;
+ wire LOGIC_ONE, LOGIC_ZERO;
+ assign LOGIC_ONE = 1'b1;
+ assign LOGIC_ZERO = 1'b0;
+ smdecoder dDEC0 (.INA (LOGIC_ZERO), .INB (OPB[0]), .INC (OPB[1]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]) );
+ assign OPA_ = ~ OPA;
+ smpp_low dPPL0 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[0]) );
+ smr_gate dRGATE0 (.INA (LOGIC_ZERO), .INB (OPB[0]), .INC (OPB[1]), .PPBIT (SUMMAND[1]) );
+ smpp_middle dPPM0 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[2]) );
+ smpp_middle dPPM1 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[3]) );
+ smpp_middle dPPM2 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[6]) );
+ smpp_middle dPPM3 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[8]) );
+ smpp_middle dPPM4 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[12]) );
+ smpp_middle dPPM5 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[15]) );
+ smpp_middle dPPM6 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[20]) );
+ smpp_middle dPPM7 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[24]) );
+ smpp_middle dPPM8 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[30]) );
+ smpp_middle dPPM9 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[35]) );
+ smpp_middle dPPM10 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[42]) );
+ smpp_middle dPPM11 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[48]) );
+ smpp_middle dPPM12 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[56]) );
+ smpp_middle dPPM13 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[63]) );
+ smpp_middle dPPM14 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[72]) );
+ smpp_middle dPPM15 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[80]) );
+ smpp_middle dPPM16 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[90]) );
+ smpp_middle dPPM17 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[99]) );
+ smpp_middle dPPM18 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[110]) );
+ smpp_middle dPPM19 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[120]) );
+ smpp_middle dPPM20 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[132]) );
+ smpp_middle dPPM21 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[143]) );
+ smpp_middle dPPM22 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[156]) );
+ smpp_middle dPPM23 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[168]) );
+ smpp_middle dPPM24 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[182]) );
+ smpp_middle dPPM25 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[195]) );
+ smpp_middle dPPM26 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[210]) );
+ smpp_middle dPPM27 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[224]) );
+ smpp_middle dPPM28 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[240]) );
+ smpp_middle dPPM29 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[255]) );
+ smpp_middle dPPM30 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[272]) );
+ smpp_middle dPPM31 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[288]) );
+ smpp_middle dPPM32 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[306]) );
+ smpp_high dPPH0 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[0]), .TWONEG (INT_MULTIPLIER[1]), .ONEPOS (INT_MULTIPLIER[2]), .ONENEG (INT_MULTIPLIER[3]), .PPBIT (SUMMAND[323]) );
+ assign SUMMAND[324] = 1'b1;
+ smdecoder dDEC1 (.INA (OPB[1]), .INB (OPB[2]), .INC (OPB[3]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]) );
+ smpp_low dPPL1 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[4]) );
+ smr_gate dRGATE1 (.INA (OPB[1]), .INB (OPB[2]), .INC (OPB[3]), .PPBIT (SUMMAND[5]) );
+ smpp_middle dPPM33 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[7]) );
+ smpp_middle dPPM34 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[9]) );
+ smpp_middle dPPM35 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[13]) );
+ smpp_middle dPPM36 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[16]) );
+ smpp_middle dPPM37 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[21]) );
+ smpp_middle dPPM38 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[25]) );
+ smpp_middle dPPM39 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[31]) );
+ smpp_middle dPPM40 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[36]) );
+ smpp_middle dPPM41 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[43]) );
+ smpp_middle dPPM42 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[49]) );
+ smpp_middle dPPM43 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[57]) );
+ smpp_middle dPPM44 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[64]) );
+ smpp_middle dPPM45 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[73]) );
+ smpp_middle dPPM46 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[81]) );
+ smpp_middle dPPM47 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[91]) );
+ smpp_middle dPPM48 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[100]) );
+ smpp_middle dPPM49 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[111]) );
+ smpp_middle dPPM50 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[121]) );
+ smpp_middle dPPM51 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[133]) );
+ smpp_middle dPPM52 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[144]) );
+ smpp_middle dPPM53 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[157]) );
+ smpp_middle dPPM54 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[169]) );
+ smpp_middle dPPM55 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[183]) );
+ smpp_middle dPPM56 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[196]) );
+ smpp_middle dPPM57 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[211]) );
+ smpp_middle dPPM58 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[225]) );
+ smpp_middle dPPM59 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[241]) );
+ smpp_middle dPPM60 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[256]) );
+ smpp_middle dPPM61 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[273]) );
+ smpp_middle dPPM62 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[289]) );
+ smpp_middle dPPM63 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[307]) );
+ smpp_middle dPPM64 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[325]) );
+ smpp_middle dPPM65 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[341]) );
+ assign SUMMAND[342] = LOGIC_ONE;
+ smpp_high dPPH1 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[4]), .TWONEG (INT_MULTIPLIER[5]), .ONEPOS (INT_MULTIPLIER[6]), .ONENEG (INT_MULTIPLIER[7]), .PPBIT (SUMMAND[358]) );
+ smdecoder dDEC2 (.INA (OPB[3]), .INB (OPB[4]), .INC (OPB[5]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]) );
+ smpp_low dPPL2 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[10]) );
+ smr_gate dRGATE2 (.INA (OPB[3]), .INB (OPB[4]), .INC (OPB[5]), .PPBIT (SUMMAND[11]) );
+ smpp_middle dPPM66 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[14]) );
+ smpp_middle dPPM67 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[17]) );
+ smpp_middle dPPM68 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[22]) );
+ smpp_middle dPPM69 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[26]) );
+ smpp_middle dPPM70 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[32]) );
+ smpp_middle dPPM71 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[37]) );
+ smpp_middle dPPM72 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[44]) );
+ smpp_middle dPPM73 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[50]) );
+ smpp_middle dPPM74 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[58]) );
+ smpp_middle dPPM75 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[65]) );
+ smpp_middle dPPM76 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[74]) );
+ smpp_middle dPPM77 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[82]) );
+ smpp_middle dPPM78 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[92]) );
+ smpp_middle dPPM79 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[101]) );
+ smpp_middle dPPM80 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[112]) );
+ smpp_middle dPPM81 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[122]) );
+ smpp_middle dPPM82 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[134]) );
+ smpp_middle dPPM83 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[145]) );
+ smpp_middle dPPM84 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[158]) );
+ smpp_middle dPPM85 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[170]) );
+ smpp_middle dPPM86 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[184]) );
+ smpp_middle dPPM87 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[197]) );
+ smpp_middle dPPM88 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[212]) );
+ smpp_middle dPPM89 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[226]) );
+ smpp_middle dPPM90 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[242]) );
+ smpp_middle dPPM91 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[257]) );
+ smpp_middle dPPM92 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[274]) );
+ smpp_middle dPPM93 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[290]) );
+ smpp_middle dPPM94 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[308]) );
+ smpp_middle dPPM95 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[326]) );
+ smpp_middle dPPM96 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[343]) );
+ smpp_middle dPPM97 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[359]) );
+ smpp_middle dPPM98 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[374]) );
+ assign SUMMAND[375] = LOGIC_ONE;
+ smpp_high dPPH2 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[8]), .TWONEG (INT_MULTIPLIER[9]), .ONEPOS (INT_MULTIPLIER[10]), .ONENEG (INT_MULTIPLIER[11]), .PPBIT (SUMMAND[390]) );
+ smdecoder dDEC3 (.INA (OPB[5]), .INB (OPB[6]), .INC (OPB[7]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]) );
+ smpp_low dPPL3 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[18]) );
+ smr_gate dRGATE3 (.INA (OPB[5]), .INB (OPB[6]), .INC (OPB[7]), .PPBIT (SUMMAND[19]) );
+ smpp_middle dPPM99 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[23]) );
+ smpp_middle dPPM100 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[27]) );
+ smpp_middle dPPM101 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[33]) );
+ smpp_middle dPPM102 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[38]) );
+ smpp_middle dPPM103 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[45]) );
+ smpp_middle dPPM104 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[51]) );
+ smpp_middle dPPM105 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[59]) );
+ smpp_middle dPPM106 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[66]) );
+ smpp_middle dPPM107 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[75]) );
+ smpp_middle dPPM108 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[83]) );
+ smpp_middle dPPM109 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[93]) );
+ smpp_middle dPPM110 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[102]) );
+ smpp_middle dPPM111 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[113]) );
+ smpp_middle dPPM112 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[123]) );
+ smpp_middle dPPM113 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[135]) );
+ smpp_middle dPPM114 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[146]) );
+ smpp_middle dPPM115 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[159]) );
+ smpp_middle dPPM116 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[171]) );
+ smpp_middle dPPM117 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[185]) );
+ smpp_middle dPPM118 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[198]) );
+ smpp_middle dPPM119 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[213]) );
+ smpp_middle dPPM120 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[227]) );
+ smpp_middle dPPM121 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[243]) );
+ smpp_middle dPPM122 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[258]) );
+ smpp_middle dPPM123 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[275]) );
+ smpp_middle dPPM124 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[291]) );
+ smpp_middle dPPM125 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[309]) );
+ smpp_middle dPPM126 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[327]) );
+ smpp_middle dPPM127 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[344]) );
+ smpp_middle dPPM128 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[360]) );
+ smpp_middle dPPM129 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[376]) );
+ smpp_middle dPPM130 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[391]) );
+ smpp_middle dPPM131 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[405]) );
+ assign SUMMAND[406] = LOGIC_ONE;
+ smpp_high dPPH3 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[12]), .TWONEG (INT_MULTIPLIER[13]), .ONEPOS (INT_MULTIPLIER[14]), .ONENEG (INT_MULTIPLIER[15]), .PPBIT (SUMMAND[420]) );
+ smdecoder dDEC4 (.INA (OPB[7]), .INB (OPB[8]), .INC (OPB[9]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]) );
+ smpp_low dPPL4 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[28]) );
+ smr_gate dRGATE4 (.INA (OPB[7]), .INB (OPB[8]), .INC (OPB[9]), .PPBIT (SUMMAND[29]) );
+ smpp_middle dPPM132 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[34]) );
+ smpp_middle dPPM133 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[39]) );
+ smpp_middle dPPM134 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[46]) );
+ smpp_middle dPPM135 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[52]) );
+ smpp_middle dPPM136 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[60]) );
+ smpp_middle dPPM137 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[67]) );
+ smpp_middle dPPM138 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[76]) );
+ smpp_middle dPPM139 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[84]) );
+ smpp_middle dPPM140 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[94]) );
+ smpp_middle dPPM141 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[103]) );
+ smpp_middle dPPM142 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[114]) );
+ smpp_middle dPPM143 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[124]) );
+ smpp_middle dPPM144 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[136]) );
+ smpp_middle dPPM145 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[147]) );
+ smpp_middle dPPM146 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[160]) );
+ smpp_middle dPPM147 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[172]) );
+ smpp_middle dPPM148 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[186]) );
+ smpp_middle dPPM149 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[199]) );
+ smpp_middle dPPM150 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[214]) );
+ smpp_middle dPPM151 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[228]) );
+ smpp_middle dPPM152 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[244]) );
+ smpp_middle dPPM153 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[259]) );
+ smpp_middle dPPM154 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[276]) );
+ smpp_middle dPPM155 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[292]) );
+ smpp_middle dPPM156 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[310]) );
+ smpp_middle dPPM157 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[328]) );
+ smpp_middle dPPM158 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[345]) );
+ smpp_middle dPPM159 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[361]) );
+ smpp_middle dPPM160 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[377]) );
+ smpp_middle dPPM161 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[392]) );
+ smpp_middle dPPM162 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[407]) );
+ smpp_middle dPPM163 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[421]) );
+ smpp_middle dPPM164 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[434]) );
+ assign SUMMAND[435] = LOGIC_ONE;
+ smpp_high dPPH4 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[16]), .TWONEG (INT_MULTIPLIER[17]), .ONEPOS (INT_MULTIPLIER[18]), .ONENEG (INT_MULTIPLIER[19]), .PPBIT (SUMMAND[448]) );
+ smdecoder dDEC5 (.INA (OPB[9]), .INB (OPB[10]), .INC (OPB[11]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]) );
+ smpp_low dPPL5 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[40]) );
+ smr_gate dRGATE5 (.INA (OPB[9]), .INB (OPB[10]), .INC (OPB[11]), .PPBIT (SUMMAND[41]) );
+ smpp_middle dPPM165 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[47]) );
+ smpp_middle dPPM166 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[53]) );
+ smpp_middle dPPM167 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[61]) );
+ smpp_middle dPPM168 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[68]) );
+ smpp_middle dPPM169 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[77]) );
+ smpp_middle dPPM170 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[85]) );
+ smpp_middle dPPM171 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[95]) );
+ smpp_middle dPPM172 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[104]) );
+ smpp_middle dPPM173 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[115]) );
+ smpp_middle dPPM174 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[125]) );
+ smpp_middle dPPM175 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[137]) );
+ smpp_middle dPPM176 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[148]) );
+ smpp_middle dPPM177 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[161]) );
+ smpp_middle dPPM178 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[173]) );
+ smpp_middle dPPM179 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[187]) );
+ smpp_middle dPPM180 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[200]) );
+ smpp_middle dPPM181 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[215]) );
+ smpp_middle dPPM182 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[229]) );
+ smpp_middle dPPM183 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[245]) );
+ smpp_middle dPPM184 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[260]) );
+ smpp_middle dPPM185 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[277]) );
+ smpp_middle dPPM186 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[293]) );
+ smpp_middle dPPM187 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[311]) );
+ smpp_middle dPPM188 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[329]) );
+ smpp_middle dPPM189 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[346]) );
+ smpp_middle dPPM190 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[362]) );
+ smpp_middle dPPM191 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[378]) );
+ smpp_middle dPPM192 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[393]) );
+ smpp_middle dPPM193 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[408]) );
+ smpp_middle dPPM194 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[422]) );
+ smpp_middle dPPM195 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[436]) );
+ smpp_middle dPPM196 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[449]) );
+ smpp_middle dPPM197 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[461]) );
+ assign SUMMAND[462] = LOGIC_ONE;
+ smpp_high dPPH5 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[20]), .TWONEG (INT_MULTIPLIER[21]), .ONEPOS (INT_MULTIPLIER[22]), .ONENEG (INT_MULTIPLIER[23]), .PPBIT (SUMMAND[474]) );
+ smdecoder dDEC6 (.INA (OPB[11]), .INB (OPB[12]), .INC (OPB[13]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]) );
+ smpp_low dPPL6 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[54]) );
+ smr_gate dRGATE6 (.INA (OPB[11]), .INB (OPB[12]), .INC (OPB[13]), .PPBIT (SUMMAND[55]) );
+ smpp_middle dPPM198 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[62]) );
+ smpp_middle dPPM199 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[69]) );
+ smpp_middle dPPM200 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[78]) );
+ smpp_middle dPPM201 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[86]) );
+ smpp_middle dPPM202 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[96]) );
+ smpp_middle dPPM203 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[105]) );
+ smpp_middle dPPM204 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[116]) );
+ smpp_middle dPPM205 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[126]) );
+ smpp_middle dPPM206 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[138]) );
+ smpp_middle dPPM207 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[149]) );
+ smpp_middle dPPM208 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[162]) );
+ smpp_middle dPPM209 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[174]) );
+ smpp_middle dPPM210 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[188]) );
+ smpp_middle dPPM211 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[201]) );
+ smpp_middle dPPM212 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[216]) );
+ smpp_middle dPPM213 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[230]) );
+ smpp_middle dPPM214 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[246]) );
+ smpp_middle dPPM215 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[261]) );
+ smpp_middle dPPM216 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[278]) );
+ smpp_middle dPPM217 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[294]) );
+ smpp_middle dPPM218 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[312]) );
+ smpp_middle dPPM219 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[330]) );
+ smpp_middle dPPM220 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[347]) );
+ smpp_middle dPPM221 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[363]) );
+ smpp_middle dPPM222 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[379]) );
+ smpp_middle dPPM223 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[394]) );
+ smpp_middle dPPM224 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[409]) );
+ smpp_middle dPPM225 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[423]) );
+ smpp_middle dPPM226 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[437]) );
+ smpp_middle dPPM227 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[450]) );
+ smpp_middle dPPM228 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[463]) );
+ smpp_middle dPPM229 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[475]) );
+ smpp_middle dPPM230 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[486]) );
+ assign SUMMAND[487] = LOGIC_ONE;
+ smpp_high dPPH6 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[24]), .TWONEG (INT_MULTIPLIER[25]), .ONEPOS (INT_MULTIPLIER[26]), .ONENEG (INT_MULTIPLIER[27]), .PPBIT (SUMMAND[498]) );
+ smdecoder dDEC7 (.INA (OPB[13]), .INB (OPB[14]), .INC (OPB[15]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]) );
+ smpp_low dPPL7 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[70]) );
+ smr_gate dRGATE7 (.INA (OPB[13]), .INB (OPB[14]), .INC (OPB[15]), .PPBIT (SUMMAND[71]) );
+ smpp_middle dPPM231 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[79]) );
+ smpp_middle dPPM232 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[87]) );
+ smpp_middle dPPM233 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[97]) );
+ smpp_middle dPPM234 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[106]) );
+ smpp_middle dPPM235 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[117]) );
+ smpp_middle dPPM236 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[127]) );
+ smpp_middle dPPM237 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[139]) );
+ smpp_middle dPPM238 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[150]) );
+ smpp_middle dPPM239 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[163]) );
+ smpp_middle dPPM240 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[175]) );
+ smpp_middle dPPM241 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[189]) );
+ smpp_middle dPPM242 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[202]) );
+ smpp_middle dPPM243 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[217]) );
+ smpp_middle dPPM244 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[231]) );
+ smpp_middle dPPM245 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[247]) );
+ smpp_middle dPPM246 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[262]) );
+ smpp_middle dPPM247 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[279]) );
+ smpp_middle dPPM248 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[295]) );
+ smpp_middle dPPM249 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[313]) );
+ smpp_middle dPPM250 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[331]) );
+ smpp_middle dPPM251 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[348]) );
+ smpp_middle dPPM252 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[364]) );
+ smpp_middle dPPM253 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[380]) );
+ smpp_middle dPPM254 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[395]) );
+ smpp_middle dPPM255 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[410]) );
+ smpp_middle dPPM256 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[424]) );
+ smpp_middle dPPM257 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[438]) );
+ smpp_middle dPPM258 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[451]) );
+ smpp_middle dPPM259 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[464]) );
+ smpp_middle dPPM260 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[476]) );
+ smpp_middle dPPM261 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[488]) );
+ smpp_middle dPPM262 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[499]) );
+ smpp_middle dPPM263 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[509]) );
+ assign SUMMAND[510] = LOGIC_ONE;
+ smpp_high dPPH7 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[28]), .TWONEG (INT_MULTIPLIER[29]), .ONEPOS (INT_MULTIPLIER[30]), .ONENEG (INT_MULTIPLIER[31]), .PPBIT (SUMMAND[520]) );
+ smdecoder dDEC8 (.INA (OPB[15]), .INB (OPB[16]), .INC (OPB[17]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]) );
+ smpp_low dPPL8 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[88]) );
+ smr_gate dRGATE8 (.INA (OPB[15]), .INB (OPB[16]), .INC (OPB[17]), .PPBIT (SUMMAND[89]) );
+ smpp_middle dPPM264 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[98]) );
+ smpp_middle dPPM265 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[107]) );
+ smpp_middle dPPM266 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[118]) );
+ smpp_middle dPPM267 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[128]) );
+ smpp_middle dPPM268 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[140]) );
+ smpp_middle dPPM269 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[151]) );
+ smpp_middle dPPM270 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[164]) );
+ smpp_middle dPPM271 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[176]) );
+ smpp_middle dPPM272 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[190]) );
+ smpp_middle dPPM273 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[203]) );
+ smpp_middle dPPM274 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[218]) );
+ smpp_middle dPPM275 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[232]) );
+ smpp_middle dPPM276 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[248]) );
+ smpp_middle dPPM277 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[263]) );
+ smpp_middle dPPM278 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[280]) );
+ smpp_middle dPPM279 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[296]) );
+ smpp_middle dPPM280 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[314]) );
+ smpp_middle dPPM281 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[332]) );
+ smpp_middle dPPM282 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[349]) );
+ smpp_middle dPPM283 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[365]) );
+ smpp_middle dPPM284 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[381]) );
+ smpp_middle dPPM285 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[396]) );
+ smpp_middle dPPM286 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[411]) );
+ smpp_middle dPPM287 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[425]) );
+ smpp_middle dPPM288 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[439]) );
+ smpp_middle dPPM289 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[452]) );
+ smpp_middle dPPM290 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[465]) );
+ smpp_middle dPPM291 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[477]) );
+ smpp_middle dPPM292 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[489]) );
+ smpp_middle dPPM293 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[500]) );
+ smpp_middle dPPM294 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[511]) );
+ smpp_middle dPPM295 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[521]) );
+ smpp_middle dPPM296 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[530]) );
+ assign SUMMAND[531] = LOGIC_ONE;
+ smpp_high dPPH8 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[32]), .TWONEG (INT_MULTIPLIER[33]), .ONEPOS (INT_MULTIPLIER[34]), .ONENEG (INT_MULTIPLIER[35]), .PPBIT (SUMMAND[540]) );
+ smdecoder dDEC9 (.INA (OPB[17]), .INB (OPB[18]), .INC (OPB[19]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]) );
+ smpp_low dPPL9 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[108]) );
+ smr_gate dRGATE9 (.INA (OPB[17]), .INB (OPB[18]), .INC (OPB[19]), .PPBIT (SUMMAND[109]) );
+ smpp_middle dPPM297 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[119]) );
+ smpp_middle dPPM298 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[129]) );
+ smpp_middle dPPM299 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[141]) );
+ smpp_middle dPPM300 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[152]) );
+ smpp_middle dPPM301 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[165]) );
+ smpp_middle dPPM302 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[177]) );
+ smpp_middle dPPM303 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[191]) );
+ smpp_middle dPPM304 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[204]) );
+ smpp_middle dPPM305 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[219]) );
+ smpp_middle dPPM306 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[233]) );
+ smpp_middle dPPM307 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[249]) );
+ smpp_middle dPPM308 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[264]) );
+ smpp_middle dPPM309 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[281]) );
+ smpp_middle dPPM310 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[297]) );
+ smpp_middle dPPM311 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[315]) );
+ smpp_middle dPPM312 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[333]) );
+ smpp_middle dPPM313 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[350]) );
+ smpp_middle dPPM314 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[366]) );
+ smpp_middle dPPM315 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[382]) );
+ smpp_middle dPPM316 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[397]) );
+ smpp_middle dPPM317 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[412]) );
+ smpp_middle dPPM318 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[426]) );
+ smpp_middle dPPM319 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[440]) );
+ smpp_middle dPPM320 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[453]) );
+ smpp_middle dPPM321 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[466]) );
+ smpp_middle dPPM322 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[478]) );
+ smpp_middle dPPM323 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[490]) );
+ smpp_middle dPPM324 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[501]) );
+ smpp_middle dPPM325 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[512]) );
+ smpp_middle dPPM326 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[522]) );
+ smpp_middle dPPM327 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[532]) );
+ smpp_middle dPPM328 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[541]) );
+ smpp_middle dPPM329 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[549]) );
+ assign SUMMAND[550] = LOGIC_ONE;
+ smpp_high dPPH9 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[36]), .TWONEG (INT_MULTIPLIER[37]), .ONEPOS (INT_MULTIPLIER[38]), .ONENEG (INT_MULTIPLIER[39]), .PPBIT (SUMMAND[558]) );
+ smdecoder dDEC10 (.INA (OPB[19]), .INB (OPB[20]), .INC (OPB[21]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]) );
+ smpp_low dPPL10 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[130]) );
+ smr_gate dRGATE10 (.INA (OPB[19]), .INB (OPB[20]), .INC (OPB[21]), .PPBIT (SUMMAND[131]) );
+ smpp_middle dPPM330 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[142]) );
+ smpp_middle dPPM331 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[153]) );
+ smpp_middle dPPM332 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[166]) );
+ smpp_middle dPPM333 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[178]) );
+ smpp_middle dPPM334 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[192]) );
+ smpp_middle dPPM335 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[205]) );
+ smpp_middle dPPM336 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[220]) );
+ smpp_middle dPPM337 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[234]) );
+ smpp_middle dPPM338 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[250]) );
+ smpp_middle dPPM339 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[265]) );
+ smpp_middle dPPM340 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[282]) );
+ smpp_middle dPPM341 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[298]) );
+ smpp_middle dPPM342 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[316]) );
+ smpp_middle dPPM343 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[334]) );
+ smpp_middle dPPM344 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[351]) );
+ smpp_middle dPPM345 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[367]) );
+ smpp_middle dPPM346 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[383]) );
+ smpp_middle dPPM347 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[398]) );
+ smpp_middle dPPM348 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[413]) );
+ smpp_middle dPPM349 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[427]) );
+ smpp_middle dPPM350 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[441]) );
+ smpp_middle dPPM351 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[454]) );
+ smpp_middle dPPM352 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[467]) );
+ smpp_middle dPPM353 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[479]) );
+ smpp_middle dPPM354 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[491]) );
+ smpp_middle dPPM355 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[502]) );
+ smpp_middle dPPM356 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[513]) );
+ smpp_middle dPPM357 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[523]) );
+ smpp_middle dPPM358 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[533]) );
+ smpp_middle dPPM359 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[542]) );
+ smpp_middle dPPM360 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[551]) );
+ smpp_middle dPPM361 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[559]) );
+ smpp_middle dPPM362 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[566]) );
+ assign SUMMAND[567] = LOGIC_ONE;
+ smpp_high dPPH10 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[40]), .TWONEG (INT_MULTIPLIER[41]), .ONEPOS (INT_MULTIPLIER[42]), .ONENEG (INT_MULTIPLIER[43]), .PPBIT (SUMMAND[574]) );
+ smdecoder dDEC11 (.INA (OPB[21]), .INB (OPB[22]), .INC (OPB[23]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]) );
+ smpp_low dPPL11 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[154]) );
+ smr_gate dRGATE11 (.INA (OPB[21]), .INB (OPB[22]), .INC (OPB[23]), .PPBIT (SUMMAND[155]) );
+ smpp_middle dPPM363 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[167]) );
+ smpp_middle dPPM364 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[179]) );
+ smpp_middle dPPM365 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[193]) );
+ smpp_middle dPPM366 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[206]) );
+ smpp_middle dPPM367 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[221]) );
+ smpp_middle dPPM368 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[235]) );
+ smpp_middle dPPM369 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[251]) );
+ smpp_middle dPPM370 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[266]) );
+ smpp_middle dPPM371 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[283]) );
+ smpp_middle dPPM372 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[299]) );
+ smpp_middle dPPM373 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[317]) );
+ smpp_middle dPPM374 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[335]) );
+ smpp_middle dPPM375 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[352]) );
+ smpp_middle dPPM376 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[368]) );
+ smpp_middle dPPM377 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[384]) );
+ smpp_middle dPPM378 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[399]) );
+ smpp_middle dPPM379 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[414]) );
+ smpp_middle dPPM380 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[428]) );
+ smpp_middle dPPM381 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[442]) );
+ smpp_middle dPPM382 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[455]) );
+ smpp_middle dPPM383 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[468]) );
+ smpp_middle dPPM384 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[480]) );
+ smpp_middle dPPM385 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[492]) );
+ smpp_middle dPPM386 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[503]) );
+ smpp_middle dPPM387 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[514]) );
+ smpp_middle dPPM388 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[524]) );
+ smpp_middle dPPM389 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[534]) );
+ smpp_middle dPPM390 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[543]) );
+ smpp_middle dPPM391 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[552]) );
+ smpp_middle dPPM392 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[560]) );
+ smpp_middle dPPM393 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[568]) );
+ smpp_middle dPPM394 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[575]) );
+ smpp_middle dPPM395 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[581]) );
+ assign SUMMAND[582] = LOGIC_ONE;
+ smpp_high dPPH11 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[44]), .TWONEG (INT_MULTIPLIER[45]), .ONEPOS (INT_MULTIPLIER[46]), .ONENEG (INT_MULTIPLIER[47]), .PPBIT (SUMMAND[588]) );
+ smdecoder dDEC12 (.INA (OPB[23]), .INB (OPB[24]), .INC (OPB[25]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]) );
+ smpp_low dPPL12 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[180]) );
+ smr_gate dRGATE12 (.INA (OPB[23]), .INB (OPB[24]), .INC (OPB[25]), .PPBIT (SUMMAND[181]) );
+ smpp_middle dPPM3""b'96 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[194]) );
+ smpp_middle dPPM397 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[207]) );
+ smpp_middle dPPM398 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[222]) );
+ smpp_middle dPPM399 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[236]) );
+ smpp_middle dPPM400 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[252]) );
+ smpp_middle dPPM401 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[267]) );
+ smpp_middle dPPM402 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[284]) );
+ smpp_middle dPPM403 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[300]) );
+ smpp_middle dPPM404 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[318]) );
+ smpp_middle dPPM405 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[336]) );
+ smpp_middle dPPM406 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[353]) );
+ smpp_middle dPPM407 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[369]) );
+ smpp_middle dPPM408 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[385]) );
+ smpp_middle dPPM409 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[400]) );
+ smpp_middle dPPM410 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[415]) );
+ smpp_middle dPPM411 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[429]) );
+ smpp_middle dPPM412 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[443]) );
+ smpp_middle dPPM413 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[456]) );
+ smpp_middle dPPM414 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[469]) );
+ smpp_middle dPPM415 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[481]) );
+ smpp_middle dPPM416 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[493]) );
+ smpp_middle dPPM417 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[504]) );
+ smpp_middle dPPM418 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[515]) );
+ smpp_middle dPPM419 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[525]) );
+ smpp_middle dPPM420 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[535]) );
+ smpp_middle dPPM421 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[544]) );
+ smpp_middle dPPM422 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[553]) );
+ smpp_middle dPPM423 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[561]) );
+ smpp_middle dPPM424 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[569]) );
+ smpp_middle dPPM425 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[576]) );
+ smpp_middle dPPM426 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[583]) );
+ smpp_middle dPPM427 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[589]) );
+ smpp_middle dPPM428 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[594]) );
+ assign SUMMAND[595] = LOGIC_ONE;
+ smpp_high dPPH12 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[48]), .TWONEG (INT_MULTIPLIER[49]), .ONEPOS (INT_MULTIPLIER[50]), .ONENEG (INT_MULTIPLIER[51]), .PPBIT (SUMMAND[600]) );
+ smdecoder dDEC13 (.INA (OPB[25]), .INB (OPB[26]), .INC (OPB[27]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]) );
+ smpp_low dPPL13 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[208]) );
+ smr_gate dRGATE13 (.INA (OPB[25]), .INB (OPB[26]), .INC (OPB[27]), .PPBIT (SUMMAND[209]) );
+ smpp_middle dPPM429 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[223]) );
+ smpp_middle dPPM430 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[237]) );
+ smpp_middle dPPM431 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[253]) );
+ smpp_middle dPPM432 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[268]) );
+ smpp_middle dPPM433 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[285]) );
+ smpp_middle dPPM434 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[301]) );
+ smpp_middle dPPM435 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[319]) );
+ smpp_middle dPPM436 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[337]) );
+ smpp_middle dPPM437 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[354]) );
+ smpp_middle dPPM438 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[370]) );
+ smpp_middle dPPM439 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[386]) );
+ smpp_middle dPPM440 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[401]) );
+ smpp_middle dPPM441 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[416]) );
+ smpp_middle dPPM442 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[430]) );
+ smpp_middle dPPM443 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[444]) );
+ smpp_middle dPPM444 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[457]) );
+ smpp_middle dPPM445 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[470]) );
+ smpp_middle dPPM446 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[482]) );
+ smpp_middle dPPM447 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[494]) );
+ smpp_middle dPPM448 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[505]) );
+ smpp_middle dPPM449 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[516]) );
+ smpp_middle dPPM450 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[526]) );
+ smpp_middle dPPM451 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[536]) );
+ smpp_middle dPPM452 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[545]) );
+ smpp_middle dPPM453 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[554]) );
+ smpp_middle dPPM454 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[562]) );
+ smpp_middle dPPM455 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[570]) );
+ smpp_middle dPPM456 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[577]) );
+ smpp_middle dPPM457 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[584]) );
+ smpp_middle dPPM458 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[590]) );
+ smpp_middle dPPM459 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[596]) );
+ smpp_middle dPPM460 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[601]) );
+ smpp_middle dPPM461 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[605]) );
+ assign SUMMAND[606] = LOGIC_ONE;
+ smpp_high dPPH13 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[52]), .TWONEG (INT_MULTIPLIER[53]), .ONEPOS (INT_MULTIPLIER[54]), .ONENEG (INT_MULTIPLIER[55]), .PPBIT (SUMMAND[610]) );
+ smdecoder dDEC14 (.INA (OPB[27]), .INB (OPB[28]), .INC (OPB[29]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]) );
+ smpp_low dPPL14 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[238]) );
+ smr_gate dRGATE14 (.INA (OPB[27]), .INB (OPB[28]), .INC (OPB[29]), .PPBIT (SUMMAND[239]) );
+ smpp_middle dPPM462 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[254]) );
+ smpp_middle dPPM463 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[269]) );
+ smpp_middle dPPM464 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[286]) );
+ smpp_middle dPPM465 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[302]) );
+ smpp_middle dPPM466 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[320]) );
+ smpp_middle dPPM467 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[338]) );
+ smpp_middle dPPM468 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[355]) );
+ smpp_middle dPPM469 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[371]) );
+ smpp_middle dPPM470 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[387]) );
+ smpp_middle dPPM471 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[402]) );
+ smpp_middle dPPM472 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[417]) );
+ smpp_middle dPPM473 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[431]) );
+ smpp_middle dPPM474 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[445]) );
+ smpp_middle dPPM475 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[458]) );
+ smpp_middle dPPM476 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[471]) );
+ smpp_middle dPPM477 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[483]) );
+ smpp_middle dPPM478 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[495]) );
+ smpp_middle dPPM479 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[506]) );
+ smpp_middle dPPM480 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[517]) );
+ smpp_middle dPPM481 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[527]) );
+ smpp_middle dPPM482 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[537]) );
+ smpp_middle dPPM483 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[546]) );
+ smpp_middle dPPM484 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[555]) );
+ smpp_middle dPPM485 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[563]) );
+ smpp_middle dPPM486 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[571]) );
+ smpp_middle dPPM487 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[578]) );
+ smpp_middle dPPM488 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[585]) );
+ smpp_middle dPPM489 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[591]) );
+ smpp_middle dPPM490 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[597]) );
+ smpp_middle dPPM491 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[602]) );
+ smpp_middle dPPM492 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[607]) );
+ smpp_middle dPPM493 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[611]) );
+ smpp_middle dPPM494 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[614]) );
+ assign SUMMAND[615] = LOGIC_ONE;
+ smpp_high dPPH14 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[56]), .TWONEG (INT_MULTIPLIER[57]), .ONEPOS (INT_MULTIPLIER[58]), .ONENEG (INT_MULTIPLIER[59]), .PPBIT (SUMMAND[618]) );
+ smdecoder dDEC15 (.INA (OPB[29]), .INB (OPB[30]), .INC (OPB[31]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]) );
+ smpp_low dPPL15 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[270]) );
+ smr_gate dRGATE15 (.INA (OPB[29]), .INB (OPB[30]), .INC (OPB[31]), .PPBIT (SUMMAND[271]) );
+ smpp_middle dPPM495 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[287]) );
+ smpp_middle dPPM496 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[303]) );
+ smpp_middle dPPM497 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[321]) );
+ smpp_middle dPPM498 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[339]) );
+ smpp_middle dPPM499 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[356]) );
+ smpp_middle dPPM500 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[372]) );
+ smpp_middle dPPM501 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[388]) );
+ smpp_middle dPPM502 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[403]) );
+ smpp_middle dPPM503 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[418]) );
+ smpp_middle dPPM504 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[432]) );
+ smpp_middle dPPM505 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[446]) );
+ smpp_middle dPPM506 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[459]) );
+ smpp_middle dPPM507 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[472]) );
+ smpp_middle dPPM508 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[484]) );
+ smpp_middle dPPM509 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[496]) );
+ smpp_middle dPPM510 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[507]) );
+ smpp_middle dPPM511 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[518]) );
+ smpp_middle dPPM512 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[528]) );
+ smpp_middle dPPM513 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[538]) );
+ smpp_middle dPPM514 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[547]) );
+ smpp_middle dPPM515 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[556]) );
+ smpp_middle dPPM516 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[564]) );
+ smpp_middle dPPM517 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[572]) );
+ smpp_middle dPPM518 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[579]) );
+ smpp_middle dPPM519 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[586]) );
+ smpp_middle dPPM520 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[592]) );
+ smpp_middle dPPM521 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[598]) );
+ smpp_middle dPPM522 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[603]) );
+ smpp_middle dPPM523 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[608]) );
+ smpp_middle dPPM524 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[612]) );
+ smpp_middle dPPM525 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[616]) );
+ smpp_middle dPPM526 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[619]) );
+ smpp_middle dPPM527 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[621]) );
+ assign SUMMAND[622] = LOGIC_ONE;
+ smpp_high dPPH15 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[60]), .TWONEG (INT_MULTIPLIER[61]), .ONEPOS (INT_MULTIPLIER[62]), .ONENEG (INT_MULTIPLIER[63]), .PPBIT (SUMMAND[624]) );
+ smdecoder dDEC16 (.INA (OPB[31]), .INB (OPB[32]), .INC (OPB[33]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]) );
+ smpp_low dPPL16 (.INA (OPA[0]), .INB (OPA_[0]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[304]) );
+ smr_gate dRGATE16 (.INA (OPB[31]), .INB (OPB[32]), .INC (OPB[33]), .PPBIT (SUMMAND[305]) );
+ smpp_middle dPPM528 (.INA (OPA[0]), .INB (OPA_[0]), .INC (OPA[1]), .IND (OPA_[1]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[322]) );
+ smpp_middle dPPM529 (.INA (OPA[1]), .INB (OPA_[1]), .INC (OPA[2]), .IND (OPA_[2]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[340]) );
+ smpp_middle dPPM530 (.INA (OPA[2]), .INB (OPA_[2]), .INC (OPA[3]), .IND (OPA_[3]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[357]) );
+ smpp_middle dPPM531 (.INA (OPA[3]), .INB (OPA_[3]), .INC (OPA[4]), .IND (OPA_[4]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[373]) );
+ smpp_middle dPPM532 (.INA (OPA[4]), .INB (OPA_[4]), .INC (OPA[5]), .IND (OPA_[5]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[389]) );
+ smpp_middle dPPM533 (.INA (OPA[5]), .INB (OPA_[5]), .INC (OPA[6]), .IND (OPA_[6]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[404]) );
+ smpp_middle dPPM534 (.INA (OPA[6]), .INB (OPA_[6]), .INC (OPA[7]), .IND (OPA_[7]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[419]) );
+ smpp_middle dPPM535 (.INA (OPA[7]), .INB (OPA_[7]), .INC (OPA[8]), .IND (OPA_[8]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[433]) );
+ smpp_middle dPPM536 (.INA (OPA[8]), .INB (OPA_[8]), .INC (OPA[9]), .IND (OPA_[9]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[447]) );
+ smpp_middle dPPM537 (.INA (OPA[9]), .INB (OPA_[9]), .INC (OPA[10]), .IND (OPA_[10]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[460]) );
+ smpp_middle dPPM538 (.INA (OPA[10]), .INB (OPA_[10]), .INC (OPA[11]), .IND (OPA_[11]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[473]) );
+ smpp_middle dPPM539 (.INA (OPA[11]), .INB (OPA_[11]), .INC (OPA[12]), .IND (OPA_[12]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[485]) );
+ smpp_middle dPPM540 (.INA (OPA[12]), .INB (OPA_[12]), .INC (OPA[13]), .IND (OPA_[13]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[497]) );
+ smpp_middle dPPM541 (.INA (OPA[13]), .INB (OPA_[13]), .INC (OPA[14]), .IND (OPA_[14]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[508]) );
+ smpp_middle dPPM542 (.INA (OPA[14]), .INB (OPA_[14]), .INC (OPA[15]), .IND (OPA_[15]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[519]) );
+ smpp_middle dPPM543 (.INA (OPA[15]), .INB (OPA_[15]), .INC (OPA[16]), .IND (OPA_[16]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[529]) );
+ smpp_middle dPPM544 (.INA (OPA[16]), .INB (OPA_[16]), .INC (OPA[17]), .IND (OPA_[17]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[539]) );
+ smpp_middle dPPM545 (.INA (OPA[17]), .INB (OPA_[17]), .INC (OPA[18]), .IND (OPA_[18]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[548]) );
+ smpp_middle dPPM546 (.INA (OPA[18]), .INB (OPA_[18]), .INC (OPA[19]), .IND (OPA_[19]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[557]) );
+ smpp_middle dPPM547 (.INA (OPA[19]), .INB (OPA_[19]), .INC (OPA[20]), .IND (OPA_[20]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[565]) );
+ smpp_middle dPPM548 (.INA (OPA[20]), .INB (OPA_[20]), .INC (OPA[21]), .IND (OPA_[21]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[573]) );
+ smpp_middle dPPM549 (.INA (OPA[21]), .INB (OPA_[21]), .INC (OPA[22]), .IND (OPA_[22]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[580]) );
+ smpp_middle dPPM550 (.INA (OPA[22]), .INB (OPA_[22]), .INC (OPA[23]), .IND (OPA_[23]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[587]) );
+ smpp_middle dPPM551 (.INA (OPA[23]), .INB (OPA_[23]), .INC (OPA[24]), .IND (OPA_[24]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[593]) );
+ smpp_middle dPPM552 (.INA (OPA[24]), .INB (OPA_[24]), .INC (OPA[25]), .IND (OPA_[25]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[599]) );
+ smpp_middle dPPM553 (.INA (OPA[25]), .INB (OPA_[25]), .INC (OPA[26]), .IND (OPA_[26]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[604]) );
+ smpp_middle dPPM554 (.INA (OPA[26]), .INB (OPA_[26]), .INC (OPA[27]), .IND (OPA_[27]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[609]) );
+ smpp_middle dPPM555 (.INA (OPA[27]), .INB (OPA_[27]), .INC (OPA[28]), .IND (OPA_[28]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[613]) );
+ smpp_middle dPPM556 (.INA (OPA[28]), .INB (OPA_[28]), .INC (OPA[29]), .IND (OPA_[29]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[617]) );
+ smpp_middle dPPM557 (.INA (OPA[29]), .INB (OPA_[29]), .INC (OPA[30]), .IND (OPA_[30]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[620]) );
+ smpp_middle dPPM558 (.INA (OPA[30]), .INB (OPA_[30]), .INC (OPA[31]), .IND (OPA_[31]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[623]) );
+ smpp_middle dPPM559 (.INA (OPA[31]), .INB (OPA_[31]), .INC (OPA[32]), .IND (OPA_[32]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[625]) );
+ smpp_middle dPPM560 (.INA (OPA[32]), .INB (OPA_[32]), .INC (OPA[33]), .IND (OPA_[33]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[626]) );
+ assign SUMMAND[627] = LOGIC_ONE;
+ smpp_high dPPH16 (.INA (OPA[33]), .INB (OPA_[33]), .TWOPOS (INT_MULTIPLIER[64]), .TWONEG (INT_MULTIPLIER[65]), .ONEPOS (INT_MULTIPLIER[66]), .ONENEG (INT_MULTIPLIER[67]), .PPBIT (SUMMAND[628]) );
+endmodule
+
+// Simple cells
+
+module smpp_low ( ONEPOS, ONENEG, TWONEG, INA, INB, PPBIT );
+ input ONEPOS;
+ input ONENEG;
+ input TWONEG;
+ input INA;
+ input INB;
+ output PPBIT;
+ assign PPBIT = (ONEPOS & INA) | (ONENEG & INB) | TWONEG;
+endmodule
+
+module smpp_middle ( ONEPOS, ONENEG, TWOPOS, TWONEG, INA, INB, INC, IND, PPBIT );
+ input ONEPOS;
+ input ONENEG;
+ input TWOPOS;
+ input TWONEG;
+ input INA;
+ input INB;
+ input INC;
+ input IND;
+ output PPBIT;
+ assign PPBIT = ~ (( ~ (INA & TWOPOS)) & ( ~ (INB & TWONEG)) & ( ~ (INC & ONEPOS)) & ( ~ (IND & ONENEG)));
+endmodule
+
+module smpp_high ( ONEPOS, ONENEG, TWOPOS, TWONEG, INA, INB, PPBIT );
+ input ONEPOS;
+ input ONENEG;
+ input TWOPOS;
+ input TWONEG;
+ input INA;
+ input INB;
+ output PPBIT;
+ assign PPBIT = ~ ((INA & ONEPOS) | (INB & ONENEG) | (INA & TWOPOS) | (INB & TWONEG));
+endmodule
+
+module smr_gate ( INA, INB, INC, PPBIT );
+ input INA;
+ input INB;
+ input INC;
+ output PPBIT;
+ assign PPBIT = ( ~ (INA & INB)) & INC;
+endmodule
+
+module smdecoder ( INA, INB, INC, TWOPOS, TWONEG, ONEPOS, ONENEG );
+ input INA;
+ input INB;
+ input INC;
+ output TWOPOS;
+ output TWONEG;
+ output ONEPOS;
+ output ONENEG;
+ assign TWOPOS = ~ ( ~ (INA & INB & ( ~ INC)));
+ assign TWONEG = ~ ( ~ (( ~ INA) & ( ~ INB) & INC));
+ assign ONEPOS = (( ~ INA) & INB & ( ~ INC)) | (( ~ INC) & ( ~ INB) & INA);
+ assign ONENEG = (INA & ( ~ INB) & INC) | (INC & INB & ( ~ INA));
+endmodule
+
+module smfulladder ( DATA_A, DATA_B, DATA_C, SAVE, CARRY );
+ input DATA_A;
+ input DATA_B;
+ input DATA_C;
+ output SAVE;
+ output CARRY;
+ wire TMP;
+ assign TMP = DATA_A ^ DATA_B;
+ assign SAVE = TMP ^ DATA_C;
+ assign CARRY = ~ (( ~ (TMP & DATA_C)) & ( ~ (DATA_A & DATA_B)));
+endmodule
+
+module smhalfadder ( DATA_A, DATA_B, SAVE, CARRY );
+ input DATA_A;
+ input DATA_B;
+ output SAVE;
+ output CARRY;
+ assign SAVE = DATA_A ^ DATA_B;
+ assign CARRY = DATA_A & DATA_B;
+endmodule
+
+module smffa
+ (
+ input clk,
+ input en_d1,
+ input D,
+ output reg Q
+ );
+ always @ (posedge clk) begin
+ \tQ <= D;
+ end
+endmodule
+
+module smffb
+ (
+ input clk,
+ input en_d2,
+ input D,
+ output reg Q
+ );
+ always @ (posedge clk) begin
+ \tQ <= D;
+ end
+endmodule
+
+module sminvblock ( GIN, GOUT );
+ input GIN;
+ output GOUT;
+ assign GOUT = ~ GIN;
+endmodule
+
+module smxxor1 ( A, B, GIN, SUM );
+ input A;
+ input B;
+ input GIN;
+ output SUM;
+ assign SUM = ( ~ (A ^ B)) ^ GIN;
+endmodule
+
+module smblock0 ( A, B, POUT, GOUT );
+ input A;
+ input B;
+ output POUT;
+ output GOUT;
+ assign POUT = ~ (A | B);
+ assign GOUT = ~ (A & B);
+endmodule
+
+module smblock1 ( PIN1, PIN2, GIN1, GIN2, POUT, GOUT );
+ input PIN1;
+ input PIN2;
+ input GIN1;
+ input GIN2;
+ output POUT;
+ output GOUT;
+ assign POUT = ~ (PIN1 | PIN2);
+ assign GOUT = ~ (GIN2 & (PIN2 | GIN1));
+endmodule
+
+module smblock2 ( PIN1, PIN2, GIN1, GIN2, POUT, GOUT );
+ input PIN1;
+ input PIN2;
+ input GIN1;
+ input GIN2;
+ output POUT;
+ output GOUT;
+ assign POUT = ~ (PIN1 & PIN2);
+ assign GOUT = ~ (GIN2 | (PIN2 & GIN1));
+endmodule
+
+module smblock1a ( PIN2, GIN1, GIN2, GOUT );
+ input PIN2;
+ input GIN1;
+ input GIN2;
+ output GOUT;
+ assign GOUT = ~ (GIN2 & (PIN2 | GIN1));
+endmodule
+
+module smblock2a ( PIN2, GIN1, GIN2, GOUT );
+ input PIN2;
+ input GIN1;
+ input GIN2;
+ output GOUT;
+ assign GOUT = ~ (GIN2 | (PIN2 & GIN1));
+endmodule
+
+// Local Variables:
+// compile-command: ""vlint --brief --nowarn=MULTMF,MODLNM t_math_wallace_mul.v""
+// End:
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2010 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+module t ();
+
+`ifndef VERILATOR
+ `error ""Only Verilator supports PLI-ish DPI calls and sformat conversion.""
+`endif
+
+ import ""DPI-C"" context dpii_display_call
+ = function void \\$dpii_display (input string formatted /*verilator sformat*/ );
+
+ integer a;
+
+ initial begin
+ // Check variable width constant string conversions
+ $dpii_display("""");
+ $dpii_display(""c"");
+ $dpii_display(""co"");
+ $dpii_display(""cons"");
+ $dpii_display(""constant"");
+ $dpii_display(""constant_value"");
+
+ a = $c(""10""); // Don\'t optimize away ""a""
+ $display (""one10=%x "",a); // Check single arg
+ $dpii_display(""one10=%x "",a);
+ $display (""Mod=%m 16=%d 10=%x "",a,a); // Check multiarg
+ $dpii_display(""Mod=%m 16=%d 10=%x "",a,a);
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0)
+
+module t (/*AUTOARG*/);
+
+ // verilator lint_off WIDTH
+ wire [1:0] bug729_au = ~0;
+ wire signed [1:0] bug729_as = ~0;
+ wire [2:0] \t bug729_b = ~0;
+ // the $signed output is unsigned because the input is unsigned; the signedness does not change.
+ wire [0:0] \t bug729_yuu = $signed(2\'b11) == 3\'b111; //1\'b0
+ wire [0:0] \t bug729_ysu = $signed(2\'sb11) == 3\'b111; //1\'b0
+ wire [0:0] \t bug729_yus = $signed(2\'b11) == 3\'sb111; //1\'b1
+ wire [0:0] \t bug729_yss = $signed(2\'sb11) == 3\'sb111; //1\'b1
+ wire [0:0] \t bug729_zuu = 2\'sb11 == 3\'b111; //1\'b0
+ wire [0:0] \t bug729_zsu = 2\'sb11 == 3\'b111; //1\'b0
+ wire [0:0] \t bug729_zus = 2\'sb11 == 3\'sb111; //1\'b1
+ wire [0:0] \t bug729_zss = 2\'sb11 == 3\'sb111; //1\'b1
+
+ wire [3:0] \t bug733_a = 4\'b0010;
+ wire [3:0] \t bug733_yu = $signed(|bug733_a); // 4\'b1111 note | is always unsigned
+ wire signed [3:0] bug733_ys = $signed(|bug733_a); // 4\'b1111
+
+ wire [3:0] \t bug733_zu = $signed(2\'b11); // 4\'b1111
+ wire signed [3:0] bug733_zs = $signed(2\'sb11); // 4\'b1111
+
+ // When RHS of assignment is fewer bits than lhs, RHS sign or zero extends based on RHS\'s sign
+
+ wire [3:0] \t bug733_qu = 2\'sb11; // 4\'b1111
+ wire signed [3:0] bug733_qs = 2\'sb11; // 4\'b1111
+ reg signed [32:0] bug349_s;
+ reg signed [32:0] bug349_u;
+
+ wire signed [1:0] sb11 = 2\'sb11;
+
+ wire [3:0] \t subout_u;
+ sub sub (.a(2\'sb11), .z(subout_u));
+ initial `checkh(subout_u, 4\'b1111);
+
+ wire [5:0] \t cond_a = 1\'b1 ? 3\'sb111 : 5\'sb11111;
+ initial `checkh(cond_a, 6\'b111111);
+ wire [5:0] \t cond_b = 1\'b0 ? 3\'sb111 : 5\'sb11111;
+ initial `checkh(cond_b, 6\'b111111);
+
+ initial begin
+ // verilator lint_on WIDTH
+ `checkh(bug729_yuu, 1\'b0);
+ `checkh(bug729_ysu, 1\'b0);
+ `checkh(bug729_yus, 1\'b1);
+ `checkh(bug729_yss, 1\'b1);
+
+ `checkh(bug729_zuu, 1\'b0);
+ `checkh(bug729_zsu, 1\'b0);
+ `checkh(bug729_zus, 1\'b1);
+ `checkh(bug729_zss, 1\'b1);
+
+ `checkh(bug733_yu, 4\'b1111);
+ `checkh(bug733_ys, 4\'b1111);
+
+ `checkh(bug733_zu, 4\'b1111);
+ `checkh(bug733_zs, 4\'b1111);
+
+ `checkh(bug733_qu, 4\'b1111);
+ `checkh(bug733_qs, 4\'b1111);
+
+ // verilator lint_off WIDTH
+ bug349_s = 4\'sb1111;
+ `checkh(bug349_s, 33\'h1ffffffff);
+ bug349_u = 4\'sb1111;
+ `checkh(bug349_u, 33\'h1ffffffff);
+
+ bug349_s = 4\'sb1111 - 1\'b1;
+ `checkh(bug349_s,33\'he);
+
+ bug349_s = 4\'sb1111 - 5\'b00001;
+ `checkh(bug349_s,33\'he);
+
+ case (2\'sb11)
+\t4\'b1111: ;
+\tdefault: $stop;
+ endcase
+
+ case (sb11)
+\t4\'b1111: ;
+\tdefault: $stop;
+ endcase
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+
+module sub (input [3:0] a,
+\t output [3:0] z);
+ assign z = a;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg \t toggle;
+
+ integer cyc; initial cyc=1;
+ wire [7:0] cyc_copy = cyc[7:0];
+
+ always @ (negedge clk) begin
+ AssertionFalse1: assert (cyc<100);
+ assert (!(cyc==5) || toggle);
+ // FIX cover {cyc==3 || cyc==4};
+ // FIX cover {cyc==9} report ""DefaultClock,expect=1"";
+ // FIX cover {(cyc==5)->toggle} report ""ToggleLogIf,expect=1"";
+ end
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t toggle <= !cyc[0];
+ if (cyc==7) assert (cyc[0] == cyc[1]); // bug743
+\t if (cyc==9) begin
+`ifdef FAILING_ASSERTIONS
+\t assert (0) else $info;
+\t assert (0) else $info(""Info message"");
+\t assert (0) else $info(""Info message, cyc=%d"", cyc);
+\t InWarningBlock: assert (0) else $warning(""Warning.... 1.0=%f 2.0=%f"", 1.0, 2.0);
+\t InErrorBlock: assert (0) else $error(""Error...."");
+\t assert (0) else $fatal(1,""Fatal...."");
+`endif
+\t end
+\t if (cyc==10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire\t\t\tRBL2;\t\t\t// From t of Test.v
+ // End of automatics
+
+ wire \t\tRWL1 = crc[2];
+ wire \t\tRWL2 = crc[3];
+
+ Test t (/*AUTOINST*/
+\t // Outputs
+\t .RBL2\t\t\t(RBL2),
+\t // Inputs
+\t .RWL1\t\t\t(RWL1),
+\t .RWL2\t\t\t(RWL2));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {63\'h0, RBL2};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'hb6d6b86aa20a882a
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (
+ output RBL2,
+ input RWL1, RWL2);
+
+ // verilator lint_off IMPLICIT
+ not I1 (RWL2_n, RWL2);
+ bufif1 I2 (RBL2, n3, 1\'b1);
+ Mxor I3 (n3, RWL1, RWL2_n);
+ // verilator lint_on IMPLICIT
+
+endmodule
+
+module Mxor (output out, input a, b);
+ assign out = (a ^ b);
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Iztok Jeras.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ logic [1:0] [3:0] [3:0] array_simp; // big endian array
+
+ logic [3:0] \t\t array_oned;
+
+ initial begin
+ array_oned = \'{2:1\'b1, 0:1\'b1, default:1\'b0};
+ if (array_oned != 4\'b0101) $stop;
+
+ array_simp[0] = \'{ 4\'d3, 4\'d2, 4\'d1, 4\'d0};
+ if (array_simp[0] !== 16\'h3210) $stop;
+
+ // verilator lint_off WIDTH
+ array_simp[0] = \'{ 3 ,2 ,1, 0 };
+ // verilator lint_on WIDTH
+ if (array_simp[0] !== 16\'h3210) $stop;
+
+ // Doesn\'t seem to work for unpacked arrays in other simulators
+ //if (array_simp[0] !== 16\'h3210) $stop;
+ //array_simp[0] = \'{ 1:4\'d3, default:13};
+ //if (array_simp[0] !== 16\'hDD3D) $stop;
+
+ array_simp = \'{ \'{ 4\'d3, 4\'d2, 4\'d1, 4\'d0 }, \'{ 4\'d1, 4\'d2, 4\'d3, 4\'d4 }};
+ if (array_simp !== 32\'h3210_1234) $stop;
+
+ // IEEE says \'{} allowed only on assignments, not !=, ==.
+
+ // Doesn\'t seem to work for unpacked arrays in other simulators
+ array_simp = \'{2{ \'{4\'d3, 4\'d2, 4\'d1, 4\'d0 } }};
+ if (array_simp !== 32\'h3210_3210) $stop;
+
+ array_simp = \'{2{ \'{4{ 4\'d3 }} }};
+ if (array_simp !== 32\'h3333_3333) $stop;
+
+ // Not legal in other simulators - replication doesn\'t match
+ // However IEEE suggests this is legal.
+ //array_simp = \'{2{ \'{2{ 4\'d3, 4\'d2 }} }}; // Note it\'s not \'{3,2}
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ //====================
+
+ // parameters for array sizes
+ localparam WA = 4; // address dimension size
+ localparam WB = 4; // bit dimension size
+
+ localparam NO = 11; // number of access events
+
+ // 2D packed arrays
+ logic [WA-1:0] [WB-1:0] array_bg; // big endian array
+ /* verilator lint_off LITENDIAN */
+ logic [0:WA-1] [0:WB-1] array_lt; // little endian array
+ /* verilator lint_on LITENDIAN */
+
+ integer cnt = 0;
+
+ // event counter
+ always @ (posedge clk) begin
+ cnt <= cnt + 1;
+ end
+
+ // finish report
+ always @ (posedge clk)
+ if ((cnt[30:2]==(NO-1)) && (cnt[1:0]==2\'d3)) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ // big endian
+ always @ (posedge clk)
+ if (cnt[1:0]==2\'d0) begin
+ // initialize to defaults (all bits 1\'b0)
+ if (cnt[30:2]== 0) array_bg <= \'0;
+ else if (cnt[30:2]== 1) array_bg <= \'0;
+ else if (cnt[30:2]== 2) array_bg <= \'0;
+ else if (cnt[30:2]== 3) array_bg <= \'0;
+ else if (cnt[30:2]== 4) array_bg <= \'0;
+ else if (cnt[30:2]== 5) array_bg <= \'0;
+ else if (cnt[30:2]== 6) array_bg <= \'0;
+ else if (cnt[30:2]== 7) array_bg <= \'0;
+ else if (cnt[30:2]== 8) array_bg <= \'0;
+ else if (cnt[30:2]== 9) array_bg <= \'0;
+ else if (cnt[30:2]==10) array_bg <= \'0;
+ end else if (cnt[1:0]==2\'d1) begin
+ // write data into whole or part of the array using literals
+ if (cnt[30:2]== 0) begin end
+ else if (cnt[30:2]== 1) array_bg <= \'{ 3 ,2 ,1, 0 };
+ else if (cnt[30:2]== 2) array_bg <= \'{default:13};
+ else if (cnt[30:2]== 3) array_bg <= \'{0:4, 1:5, 2:6, 3:7};
+ else if (cnt[30:2]== 4) array_bg <= \'{2:15, default:13};
+ else if (cnt[30:2]== 5) array_bg <= \'{WA { {WB/2 {2\'b10}} }};
+ else if (cnt[30:2]== 6) array_bg <= \'{cnt[3:0]+0, cnt[3:0]+1, cnt[3:0]+2, cnt[3:0]+3};
+ end else if (cnt[1:0]==2\'d2) begin
+ // chack array agains expected value
+ if (cnt[30:2]== 0) begin if (array_bg !== 16\'b0000000000000000) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]== 1) begin if (array_bg !== 16\'b0011001000010000) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]== 2) begin if (array_bg !== 16\'b1101110111011101) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]== 3) begin if (array_bg !== 16\'b0111011001010100) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]== 4) begin if (array_bg !== 16\'b1101111111011101) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]== 5) begin if (array_bg !== 16\'b1010101010101010) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]== 6) begin if (array_bg !== 16\'b1001101010111100) begin $display(""%b"", array_bg); $stop(); end end
+ end
+
+ // little endian
+ always @ (posedge clk)
+ if (cnt[1:0]==2\'d0) begin
+ // initialize to defaults (all bits 1\'b0)
+ if (cnt[30:2]== 0) array_lt <= \'0;
+ else if (cnt[30:2]== 1) array_lt <= \'0;
+ else if (cnt[30:2]== 2) array_lt <= \'0;
+ else if (cnt[30:2]== 3) array_lt <= \'0;
+ else if (cnt[30:2]== 4) array_lt <= \'0;
+ else if (cnt[30:2]== 5) array_lt <= \'0;
+ else if (cnt[30:2]== 6) array_lt <= \'0;
+ else if (cnt[30:2]== 7) array_lt <= \'0;
+ else if (cnt[30:2]== 8) array_lt <= \'0;
+ else if (cnt[30:2]== 9) array_lt <= \'0;
+ else if (cnt[30:2]==10) array_lt <= \'0;
+ end else if (cnt[1:0]==2\'d1) begin
+ // write data into whole or part of the array using literals
+ if (cnt[30:2]== 0) begin end
+ else if (cnt[30:2]== 1) array_lt <= \'{ 3 ,2 ,1, 0 };
+ else if (cnt[30:2]== 2) array_lt <= \'{default:13};
+ else if (cnt[30:2]== 3) array_lt <= \'{3:4, 2:5, 1:6, 0:7};
+ else if (cnt[30:2]== 4) array_lt <= \'{1:15, default:13};
+ else if (cnt[30:2]== 5) array_lt <= \'{WA { {WB/2 {2\'b10}} }};
+ else if (cnt[30:2]==10) array_lt <= \'{cnt[3:0]+0, cnt[3:0]+1, cnt[3:0]+2, cnt[3:0]+3};
+ end else if (cnt[1:0]==2\'d2) begin
+ // chack array agains expected value
+ if (cnt[30:2]== 0) begin if (array_lt !== 16\'b0000000000000000) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]== 1) begin if (array_lt !== 16\'b0011001000010000) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]== 2) begin if (array_lt !== 16\'b1101110111011101) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]== 3) begin if (array_lt !== 16\'b0111011001010100) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]== 4) begin if (array_lt !== 16\'b1101111111011101) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]== 5) begin if (array_lt !== 16\'b1010101010101010) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]==10) begin if (array_lt !== 16\'b1001101010111100) begin $display(""%b"", array_lt); $stop(); end end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This test demonstrates an issue with sign extension.
+// Assigning to localparms larger than 32 bits broke in 3.862
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Mike Thyer.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+
+ localparam [ 0:0] one1_lp = 1;
+ localparam [ 1:0] one2_lp = 1;
+ localparam [ 2:0] one3_lp = 1;
+ localparam [ 3:0] one4_lp = 1;
+ localparam [ 4:0] one5_lp = 1;
+ localparam [ 5:0] one6_lp = 1;
+ localparam [ 6:0] one7_lp = 1;
+ localparam [ 7:0] one8_lp = 1;
+ localparam [ 8:0] one9_lp = 1;
+ localparam [ 9:0] one10_lp = 1;
+ localparam [19:0] one20_lp = 1;
+ localparam [29:0] one30_lp = 1;
+ localparam [30:0] one31_lp = 1;
+ localparam [31:0] one32_lp = 1;
+ localparam [32:0] one33_lp = 1;
+ localparam [33:0] one34_lp = 1;
+ localparam [34:0] one35_lp = 1;
+ localparam [35:0] one36_lp = 1;
+ localparam [36:0] one37_lp = 1;
+ localparam [37:0] one38_lp = 1;
+ localparam [38:0] one39_lp = 1;
+ localparam [39:0] one40_lp = 1;
+ localparam [49:0] one50_lp = 1;
+ localparam [59:0] one60_lp = 1;
+ localparam [60:0] one61_lp = 1;
+ localparam [61:0] one62_lp = 1;
+ localparam [62:0] one63_lp = 1;
+ localparam [63:0] one64_lp = 1;
+ localparam [64:0] one65_lp = 1;
+ localparam [65:0] one66_lp = 1;
+ localparam [66:0] one67_lp = 1;
+ localparam [67:0] one68_lp = 1;
+ localparam [68:0] one69_lp = 1;
+ localparam [69:0] one70_lp = 1;
+
+ bit all_ok = 1;
+
+ initial begin
+`ifdef TEST_VERBOSE
+ $display(""one1_lp : %x %d"", one1_lp, one1_lp==1);
+ $display(""one2_lp : %x %d"", one2_lp, one2_lp==1);
+ $display(""one3_lp : %x %d"", one3_lp, one3_lp==1);
+ $display(""one4_lp : %x %d"", one4_lp, one4_lp==1);
+ $display(""one5_lp : %x %d"", one5_lp, one5_lp==1);
+ $display(""one6_lp : %x %d"", one6_lp, one6_lp==1);
+ $display(""one7_lp : %x %d"", one7_lp, one7_lp==1);
+ $display(""one8_lp : %x %d"", one8_lp, one8_lp==1);
+ $display(""one9_lp : %x %d"", one9_lp, one9_lp==1);
+ $display(""one10_lp: %x %d"", one10_lp, one10_lp==1);
+ $display(""one20_lp: %x %d"", one20_lp, one20_lp==1);
+ $display(""one30_lp: %x %d"", one30_lp, one30_lp==1);
+ $display(""one31_lp: %x %d"", one31_lp, one31_lp==1);
+ $display(""one32_lp: %x %d"", one32_lp, one32_lp==1);
+ $display(""one33_lp: %x %d"", one33_lp, one33_lp==1);
+ $display(""one34_lp: %x %d"", one34_lp, one34_lp==1);
+ $display(""one35_lp: %x %d"", one35_lp, one35_lp==1);
+ $display(""one36_lp: %x %d"", one36_lp, one36_lp==1);
+ $display(""one37_lp: %x %d"", one37_lp, one37_lp==1);
+ $display(""one38_lp: %x %d"", one38_lp, one38_lp==1);
+ $display(""one39_lp: %x %d"", one39_lp, one39_lp==1);
+ $display(""one40_lp: %x %d"", one40_lp, one40_lp==1);
+ $display(""one50_lp: %x %d"", one50_lp, one50_lp==1);
+ $display(""one60_lp: %x %d"", one60_lp, one60_lp==1);
+ $display(""one61_lp: %x %d"", one61_lp, one61_lp==1);
+ $display(""one62_lp: %x %d"", one62_lp, one62_lp==1);
+ $display(""one63_lp: %x %d"", one63_lp, one63_lp==1);
+ $display(""one64_lp: %x %d"", one64_lp, one64_lp==1);
+ $display(""one65_lp: %x %d"", one65_lp, one65_lp==1);
+ $display(""one66_lp: %x %d"", one66_lp, one66_lp==1);
+ $display(""one67_lp: %x %d"", one67_lp, one67_lp==1);
+ $display(""one68_lp: %x %d"", one68_lp, one68_lp==1);
+ $display(""one69_lp: %x %d"", one69_lp, one69_lp==1);
+ $display(""one70_lp: %x %d"", one70_lp, one70_lp==1);
+`endif
+
+ all_ok &= one1_lp == 1;
+ all_ok &= one2_lp == 1;
+ all_ok &= one3_lp == 1;
+ all_ok &= one4_lp == 1;
+ all_ok &= one5_lp == 1;
+ all_ok &= one6_lp == 1;
+ all_ok &= one7_lp == 1;
+ all_ok &= one8_lp == 1;
+ all_ok &= one9_lp == 1;
+ all_ok &= one10_lp == 1;
+ all_ok &= one20_lp == 1;
+ all_ok &= one30_lp == 1;
+ all_ok &= one31_lp == 1;
+ all_ok &= one32_lp == 1;
+ all_ok &= one33_lp == 1;
+ all_ok &= one34_lp == 1;
+ all_ok &= one35_lp == 1;
+ all_ok &= one36_lp == 1;
+ all_ok &= one37_lp == 1;
+ all_ok &= one38_lp == 1;
+ all_ok &= one39_lp == 1;
+ all_ok &= one40_lp == 1;
+ all_ok &= one50_lp == 1;
+ all_ok &= one60_lp == 1;
+ all_ok &= one61_lp == 1;
+ all_ok &= one62_lp == 1;
+ all_ok &= one63_lp == 1;
+ all_ok &= one64_lp == 1;
+ all_ok &= one65_lp == 1;
+ all_ok &= one66_lp == 1;
+ all_ok &= one67_lp == 1;
+ all_ok &= one68_lp == 1;
+ all_ok &= one69_lp == 1;
+ all_ok &= one70_lp == 1;
+
+ if (!all_ok) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+
+ end
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (a,z);
+ input a;
+ output z;
+
+ assign imp_warn = 1'b1;
+ // verilator lint_off IMPLICIT
+ assign imp_ok = 1'b1;
+
+`default_nettype none
+ assign imp_err = 1'b1;
+
+`default_nettype wire
+ assign imp_ok2 = 1'b1;
+
+`default_nettype none
+`resetall
+ assign imp_ok3 = 1'b1;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ // See also t_preproc_kwd.v
+
+ integer bit; initial bit = 1;
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer _mode;
+
+ reg\t _guard1;
+ reg [127:0] r_wide0;
+ reg \t _guard2;
+ wire [63:0] r_wide1;
+ reg \t _guard3;
+ reg \t _guard4;
+ reg \t _guard5;
+ reg \t _guard6;
+
+ assign r_wide1 = r_wide0[127:64];
+
+ // surefire lint_off STMINI
+ initial _mode = 0;
+
+ always @ (posedge clk) begin
+ if (_mode==0) begin
+\t $write(""[%0t] t_equal: Running\
+"", $time);
+\t _guard1 <= 0;
+ \t _guard2 <= 0;
+ \t _guard3 <= 0;
+ \t _guard4 <= 0;
+ \t _guard5 <= 0;
+ \t _guard6 <= 0;
+
+\t _mode<=1;
+\t r_wide0 <= {32\'h aa111111,32\'hbb222222,32\'hcc333333,32\'hdd444444};
+ end
+ else if (_mode==1) begin
+\t _mode<=2;
+\t //
+\t if (5\'d10 != 5\'b1010) $stop;
+\t if (5\'d10 != 5\'d10) $stop;
+\t if (5\'d10 != 5\'ha) $stop;
+\t if (5\'d10 != 5\'o12) $stop;
+\t if (5\'d10 != 5\'B 1010) $stop;
+\t if (5\'d10 != 5\'D10) $stop;
+\t if (5\'d10 != 5\'H a) $stop;
+\t if (5\'d10 != 5 \'O 12) $stop;
+\t //
+\t if (r_wide0 !== {32\'haa111111,32\'hbb222222,32\'hcc333333,32\'hdd444444}) $stop;
+\t if (r_wide1 !== {32\'haa111111,32\'hbb222222}) $stop;
+\t if (|{_guard1,_guard2,_guard3,_guard4,_guard5,_guard6}) begin
+\t $write(""Guard error %x %x %x %x %x\
+"",_guard1,_guard2,_guard3,_guard4,_guard5);
+\t $stop;
+\t end
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ q,
+ // Inputs
+ clk, d
+ );
+ input clk;
+ input [3:0] d;
+ output wire [3:0] q;
+
+ logic [3:0] \t between;
+
+ mod1 cell1 (.q(between),
+\t /*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .d\t\t\t(d[3:0]));
+
+ mod2 cell2 (.d(between),
+\t /*AUTOINST*/
+\t // Outputs
+\t .q\t\t\t(q[3:0]),
+\t // Inputs
+\t .clk\t\t\t(clk));
+
+endmodule
+
+module mod1
+ (
+ input clk,
+ input [3:0] d,
+ output logic [3:0] q
+ );
+ always @(posedge clk)
+ q <= d;
+
+endmodule
+
+module mod2
+ (
+ input clk,
+ input [3:0] d,
+ output wire [3:0] q
+ );
+
+ assign q = d;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Jeremy Bennett
+
+// see bug 591
+
+package pkg2;
+ parameter PARAM2 = 16;
+endpackage // pkg2
+
+package pkg1;
+ import pkg2::*;
+ parameter PARAM1 = 8;
+endpackage // pkg1
+
+module t
+ import pkg1::*; // Test SV 2012 import format
+ (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ reg [PARAM1:0] bus1;
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module init;
+
+ task t1;
+ reg \t\t ba,bb,bc,bd,be,bf,bg,bh,bi,bj,bk,bl,bm,bn,bo,bp,bq,br,bs,bt,bu,bv,bw,bx,by,bz;
+ reg \t\t ca,cb,cc,cd,ce,cf,cg,ch,ci,cj,ck,cl,cm,cn,co,cp,cq,cr,cs,ct,cu,cv,cw,cx,cy,cz;
+ reg \t\t da,db,dc,dd,de,df,dg,dh,di,dj,dk,dl,dm,dn, dp,dq,dr,ds,dt,du,dv,dw,dx,dy,dz;
+ begin : READER
+ $display (""Time: %0t Instance: %m"", $time);
+ end
+ endtask
+
+ task t2;
+ reg \t\t ba,bb,bc,bd,be,bf,bg,bh,bi,bj,bk,bl,bm,bn,bo,bp,bq,br,bs,bt,bu,bv,bw,bx,by,bz;
+ begin : READER
+ $display (""Time: %0t Instance: %m"", $time);
+ end
+ endtask
+endmodule
+
+module test();
+ init u_ram1();
+ init u_ram2();
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// The code as shown makes a really big file name with Verilator.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Todd Strader.
+
+`define LONG_NAME_MOD modlongnameiuqyrewewriqyewroiquyweriuqyewriuyewrioryqoiewyriuewyrqrqioeyriuqyewriuqyeworqiurewyqoiuewyrqiuewoyewriuoeyqiuewryqiuewyroiqyewiuryqeiuwryuqiyreoiqyewiuryqewiruyqiuewyroiuqyewroiuyqewoiryqiewuyrqiuewyroqiyewriuqyewrewqroiuyqiuewyriuqyewroiqyewroiquewyriuqyewroiqewyriuqewyroiqyewroiyewoiuryqoiewyriuqyewiuryqoierwyqoiuewyrewoiuyqroiewuryewurqyoiweyrqiuewyreqwroiyweroiuyqweoiuryqiuewyroiuqyroie
+`define LONG_NAME_SUB sublongnameiuqyrewewriqyewroiquyweriuqyewriuyewrioryqoiewyriuewyrqrqioeyriuqyewriuqyeworqiurewyqoiuewyrqiuewoyewriuoeyqiuewryqiuewyroiqyewiuryqeiuwryuqiyreoiqyewiuryqewiruyqiuewyroiuqyewroiuyqewoiryqiewuyrqiuewyroqiyewriuqyewrewqroiuyqiuewyriuqyewroiqyewroiquewyriuqyewroiqewyriuqewyroiqyewroiyewoiuryqoiewyriuqyewiuryqoierwyqoiuewyrewoiuyqroiewuryewurqyoiweyrqiuewyreqwroiyweroiuyqweoiuryqiuewyroiuqyroie
+`define LONG_NAME_VAR varlongnameiuqyrewewriqyewroiquyweriuqyewriuyewrioryqoiewyriuewyrqrqioeyriuqyewriuqyeworqiurewyqoiuewyrqiuewoyewriuoeyqiuewryqiuewyroiqyewiuryqeiuwryuqiyreoiqyewiuryqewiruyqiuewyroiuqyewroiuyqewoiryqiewuyrqiuewyroqiyewriuqyewrewqroiuyqiuewyriuqyewroiqyewroiquewyriuqyewroiqewyriuqewyroiqyewroiyewoiuryqoiewyriuqyewiuryqoierwyqoiuewyrewoiuyqroiewuryewurqyoiweyrqiuewyreqwroiyweroiuyqweoiuryqiuewyroiuqyroie
+
+module t ();
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ logic `LONG_NAME_VAR;
+
+ `LONG_NAME_MOD
+ `LONG_NAME_SUB
+ ();
+
+endmodule
+
+module `LONG_NAME_MOD ();
+ // Force Verilator to make a new class
+ logic a1 /* verilator public */;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // verilator lint_off WIDTH
+
+ //============================================================
+
+ reg bad;
+ initial begin
+ bad=0;
+ c96(96\'h0_0000_0000_0000_0000,\t96\'h8_8888_8888_8888_8888,\t96\'h0_0000_0000_0000_0000,\t96\'h0);
+ c96(96\'h8_8888_8888_8888_8888,\t96\'h0_0000_0000_0000_0000,\t96\'h0_0000_0000_0000_0000,\t96\'h0);
+ c96(96\'h8_8888_8888_8888_8888,\t96\'h0_0000_0000_0000_0002,\t96\'h4_4444_4444_4444_4444,\t96\'h0);
+ c96(96\'h8_8888_8888_8888_8888,\t96\'h0_2000_0000_0000_0000,\t96\'h0_0000_0000_0000_0044,\t96\'h0_0888_8888_8888_8888);
+ c96(96\'h8_8888_8888_8888_8888,\t96\'h8_8888_8888_8888_8888,\t96\'h0_0000_0000_0000_0001,\t96\'h0);
+ c96(96\'h8_8888_8888_8888_8888,\t96\'h8_8888_8888_8888_8889,\t96\'h0_0000_0000_0000_0000,\t96\'h8_8888_8888_8888_8888);
+ c96(96\'h1_0000_0000_8eba_434a,\t96\'h0_0000_0000_0000_0001,\t96\'h1_0000_0000_8eba_434a,\t96\'h0);
+
+ c96(96\'h0003,\t\t\t96\'h0002,\t\t\t96\'h0001,\t\t\t96\'h0001);
+ c96(96\'h0003,\t\t\t96\'h0003,\t\t\t96\'h0001,\t\t\t96\'h0000);
+ c96(96\'h0003,\t\t\t96\'h0004,\t\t\t96\'h0000,\t\t\t96\'h0003);
+ c96(96\'h0000,\t\t\t96\'hffff,\t\t\t96\'h0000,\t\t\t96\'h0000);
+ c96(96\'hffff,\t\t\t96\'h0001,\t\t\t96\'hffff,\t\t\t96\'h0000);
+ c96(96\'hffff,\t\t\t96\'hffff,\t\t\t96\'h0001,\t\t\t96\'h0000);
+ c96(96\'hffff,\t\t\t96\'h0003,\t\t\t96\'h5555,\t\t\t96\'h0000);
+ c96(96\'hffff_ffff,\t\t96\'h0001,\t\t\t96\'hffff_ffff,\t\t\t96\'h0000);
+ c96(96\'hffff_ffff,\t\t96\'hffff,\t\t\t96\'h0001_0001,\t\t\t96\'h0000);
+ c96(96\'hfffe_ffff,\t\t96\'hffff,\t\t\t96\'h0000_ffff,\t\t\t96\'hfffe);
+ c96(96\'h1234_5678,\t\t96\'h9abc,\t\t\t96\'h0000_1e1e,\t\t\t96\'h2c70);
+ c96(96\'h0000_0000,\t\t96\'h0001_0000,\t\t\t96\'h0000,\t\t\t96\'h0000_0000);
+ c96(96\'h0007_0000,\t\t96\'h0003_0000,\t\t\t96\'h0002,\t\t\t96\'h0001_0000);
+ c96(96\'h0007_0005,\t\t96\'h0003_0000,\t\t\t96\'h0002,\t\t\t96\'h0001_0005);
+ c96(96\'h0006_0000,\t\t96\'h0002_0000,\t\t\t96\'h0003,\t\t\t96\'h0000_0000);
+ c96(96\'h8000_0001,\t\t96\'h4000_7000,\t\t\t96\'h0001,\t\t\t96\'h3fff_9001);
+ c96(96\'hbcde_789a,\t\t96\'hbcde_789a,\t\t\t96\'h0001,\t\t\t96\'h0000_0000);
+ c96(96\'hbcde_789b,\t\t96\'hbcde_789a,\t\t\t96\'h0001,\t\t\t96\'h0000_0001);
+ c96(96\'hbcde_7899,\t\t96\'hbcde_789a,\t\t\t96\'h0000,\t\t\t96\'hbcde_7899);
+ c96(96\'hffff_ffff,\t\t96\'hffff_ffff,\t\t\t96\'h0001,\t\t\t96\'h0000_0000);
+ c96(96\'hffff_ffff,\t\t96\'h0001_0000,\t\t\t96\'hffff,\t\t\t96\'h0000_ffff);
+ c96(96\'h0123_4567_89ab,\t\t96\'h0001_0000,\t\t\t96\'h0123_4567,\t\t\t96\'h0000_89ab);
+ c96(96\'h8000_fffe_0000,\t\t96\'h8000_ffff,\t\t\t96\'h0000_ffff,\t\t\t96\'h7fff_ffff);
+ c96(96\'h8000_0000_0003,\t\t96\'h2000_0000_0001,\t\t96\'h0003,\t\t\t96\'h2000_0000_0000);
+
+ c96(96\'hffff_ffff_0000_0000,\t96\'h0001_0000_0000,\t\t96\'hffff_ffff,\t\t\t96\'h0000_0000_0000);
+ c96(96\'hffff_ffff_0000_0000,\t96\'hffff_0000_0000,\t\t96\'h0001_0001,\t\t\t96\'h0000_0000_0000);
+ c96(96\'hfffe_ffff_0000_0000,\t96\'hffff_0000_0000,\t\t96\'h0000_ffff,\t\t\t96\'hfffe_0000_0000);
+ c96(96\'h1234_5678_0000_0000,\t96\'h9abc_0000_0000,\t\t96\'h0000_1e1e,\t\t\t96\'h2c70_0000_0000);
+
+ c96(96\'h0000_0000_0000_0000,\t96\'h0001_0000_0000_0000,\t96\'h0000,\t\t\t96\'h0000_0000_0000_0000);
+ c96(96\'h0007_0000_0000_0000,\t96\'h0003_0000_0000_0000,\t96\'h0002,\t\t\t96\'h0001_0000_0000_0000);
+ c96(96\'h0007_0005_0000_0000,\t96\'h0003_0000_0000_0000,\t96\'h0002,\t\t\t96\'h0001_0005_0000_0000);
+ c96(96\'h0006_0000_0000_0000,\t96\'h0002_0000_0000_0000,\t96\'h0003,\t\t\t96\'h0000_0000_0000_0000);
+ c96(96\'h8000_0001_0000_0000,\t96\'h4000_7000_0000_0000,\t96\'h0001,\t\t\t96\'h3fff_9001_0000_0000);
+ c96(96\'hbcde_789a_0000_0000,\t96\'hbcde_789a_0000_0000,\t96\'h0001,\t\t\t96\'h0000_0000_0000_0000);
+ c96(96\'hbcde_789b_0000_0000,\t96\'hbcde_789a_0000_0000,\t96\'h0001,\t\t\t96\'h0000_0001_0000_0000);
+ c96(96\'hbcde_7899_0000_0000,\t96\'hbcde_789a_0000_0000,\t96\'h0000,\t\t\t96\'hbcde_7899_0000_0000);
+ c96(96\'hffff_ffff_0000_0000,\t96\'hffff_ffff_0000_0000,\t96\'h0001,\t\t\t96\'h0000_0000_0000_0000);
+ c96(96\'hffff_ffff_0000_0000,\t96\'h0001_0000_0000_0000,\t96\'hffff,\t\t\t96\'h0000_ffff_0000_0000);
+ c96(96\'h7fff_8000_0000_0000,\t96\'h8000_0000_0001,\t\t96\'h0000_fffe,\t\t\t96\'h7fff_ffff_0002);
+ c96(96\'h8000_0000_fffe_0000,\t96\'h8000_0000_ffff,\t\t96\'h0000_ffff,\t\t\t96\'h7fff_ffff_ffff);
+ c96(96\'h0008_8888_8888_8888_8888,\t96\'h0002_0000_0000_0000,\t96\'h0004_4444,\t\t\t96\'h0000_8888_8888_8888);
+
+ if (bad) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ task c96;
+ input [95:0] u;
+ input [95:0] v;
+ input [95:0] expq;
+ input [95:0] expr;
+ c96u( u, v, expq, expr);
+ c96s( u, v, expq, expr);
+ c96s(-u, v,-expq,-expr);
+ c96s( u,-v,-expq, expr);
+ c96s(-u,-v, expq,-expr);
+ endtask
+
+ task c96u;
+ input [95:0] u;
+ input [95:0] v;
+ input [95:0] expq;
+ input [95:0] expr;
+ reg [95:0] gotq;
+ reg [95:0] gotr;
+ gotq = u/v;
+ gotr = u%v;
+ if (gotq != expq && v!=0) begin
+\t bad = 1;
+ end
+ if (gotr != expr && v!=0) begin
+\t bad = 1;
+ end
+ if (bad
+`ifdef TEST_VERBOSE
+\t || 1
+`endif
+\t ) begin
+\t $write("" %x /u %x = got %x exp %x %% got %x exp %x"", u,v,gotq,expq,gotr,expr);
+\t // Test for v=0 to prevent Xs causing grief
+\t if (gotq != expq && v!=0) $write("" BADQ"");
+\t if (gotr != expr && v!=0) $write("" BADR"");
+\t $write(""\
+"");
+ end
+ endtask
+
+ task c96s;
+ input signed [95:0] u;
+ input signed [95:0] v;
+ input signed [95:0] expq;
+ input signed [95:0] expr;
+ reg signed [95:0] gotq;
+ reg signed [95:0] gotr;
+ gotq = u/v;
+ gotr = u%v;
+ if (gotq != expq && v!=0) begin
+\t bad = 1;
+ end
+ if (gotr != expr && v!=0) begin
+\t bad = 1;
+ end
+ if (bad
+`ifdef TEST_VERBOSE
+\t || 1
+`endif
+\t ) begin
+\t $write("" %x /s %x = got %x exp %x %% got %x exp %x"", u,v,gotq,expq,gotr,expr);
+\t // Test for v=0 to prevent Xs causing grief
+\t if (gotq != expq && v!=0) $write("" BADQ"");
+\t if (gotr != expr && v!=0) $write("" BADR"");
+\t $write(""\
+"");
+ end
+ endtask
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+
+ reg [63:0] inwide;
+ reg [39:0] addr;
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write (""%x %x\
+"", cyc, addr);
+`endif
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t addr <= 40\'h12_3456_7890;
+\t end
+\t if (cyc==2) begin
+\t if (addr !== 40\'h1234567890) $stop;
+\t addr[31:0] <= 32\'habcd_efaa;
+\t end
+\t if (cyc==3) begin
+\t if (addr !== 40\'h12abcdefaa) $stop;
+\t addr[39:32] <= 8\'h44;
+\t inwide <= 64\'hffeeddcc_11334466;
+\t end
+\t if (cyc==4) begin
+\t if (addr !== 40\'h44abcdefaa) $stop;
+\t addr[31:0] <= inwide[31:0];
+\t end
+\t if (cyc==5) begin
+\t if (addr !== 40\'h4411334466) $stop;
+\t $display (""Flip [%x]\
+"", inwide[3:0]);
+\t addr[{2\'b0,inwide[3:0]}] <= ! addr[{2\'b0,inwide[3:0]}];
+\t end
+\t if (cyc==6) begin
+\t if (addr !== 40\'h4411334426) $stop;
+\t end
+\t if (cyc==10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t_order_b (/*AUTOARG*/
+ // Outputs
+ o_subfrom_clk_lev2,
+ // Inputs
+ m_from_clk_lev1_r
+ );
+
+ input [7:0] m_from_clk_lev1_r;
+ output [7:0] o_subfrom_clk_lev2;
+
+ wire [7:0] o_subfrom_clk_lev2 = m_from_clk_lev1_r;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This test examines Verilator against paramter definition with functions.
+// Particularly the function takes in argument which is multi-dimentional.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Roland Kruse and Jie Xu.
+
+module test#(
+ parameter size = 4,
+ parameter p = sum({32'h1,32'h2,32'h3,32'h4}, size))
+
+ (input clk,
+ input logic sel,
+ output [p:0] res);
+
+ logic [p:0] cc = 'h45;
+
+ assign res = sel ? cc : {(p+1){1'b1}};
+
+ function integer sum;
+ input [3:0][31:0] values;
+ input int size;
+
+ sum = 0;
+
+ begin
+ for (int i = 0; i < size; i ++)
+ sum += values[i];
+ end
+ endfunction
+
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t;
+
+ function int\tint123(); int123 = 32\'h123; endfunction
+
+ function bit f_bit ; input bit i; f_bit = ~i; endfunction
+ function int f_int ; input int i; f_int = ~i; endfunction
+ function byte f_byte ; input byte i; f_byte = ~i; endfunction
+ function shortint f_shortint; input shortint i; f_shortint = ~i; endfunction
+ function longint f_longint ; input longint i; f_longint = ~i; endfunction
+ function chandle f_chandle ; input chandle i; f_chandle = i; endfunction
+
+ // Note there\'s no ""input"" here vvvv, it\'s the default
+ function bit g_bit (bit i); g_bit = ~i; endfunction
+ function int g_int (int i); g_int = ~i; endfunction
+ function byte g_byte (byte i); g_byte = ~i; endfunction
+ function shortint g_shortint(shortint i); g_shortint = ~i; endfunction
+ function longint g_longint (longint i); g_longint = ~i; endfunction
+ function chandle g_chandle (chandle i); g_chandle = i; endfunction
+
+ chandle c;
+
+ initial begin
+
+ if (int123() !== 32\'h123) $stop;
+
+ if (f_bit(1\'h1) !== 1\'h0) $stop;
+ if (f_bit(1\'h0) !== 1\'h1) $stop;
+ if (f_int(32\'h1) !== 32\'hfffffffe) $stop;
+ if (f_byte(8\'h1) !== 8\'hfe) $stop;
+ if (f_shortint(16\'h1) !== 16\'hfffe) $stop;
+ if (f_longint(64\'h1) !== 64\'hfffffffffffffffe) $stop;
+ if (f_chandle(c) !== c) $stop;
+
+ if (g_bit(1\'h1) !== 1\'h0) $stop;
+ if (g_bit(1\'h0) !== 1\'h1) $stop;
+ if (g_int(32\'h1) !== 32\'hfffffffe) $stop;
+ if (g_byte(8\'h1) !== 8\'hfe) $stop;
+ if (g_shortint(16\'h1) !== 16\'hfffe) $stop;
+ if (g_longint(64\'h1) !== 64\'hfffffffffffffffe) $stop;
+ if (g_chandle(c) !== c) $stop;
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ enum integer {
+
+\t EP_State_IDLE \t\t,
+\t EP_State_CMDSHIFT0 \t,
+\t EP_State_CMDSHIFT13 \t,
+\t EP_State_CMDSHIFT14 \t,
+\t EP_State_CMDSHIFT15 \t,
+\t EP_State_CMDSHIFT16 \t,
+\t EP_State_DWAIT \t\t,
+\t EP_State_DSHIFT0 \t,
+\t EP_State_DSHIFT1 \t,
+\t EP_State_DSHIFT15 \t} m_state_xr, m_state2_xr;
+
+ // Beginning of automatic ASCII enum decoding
+ reg [79:0]\t\tm_stateAscii_xr;\t// Decode of m_state_xr
+ always @(m_state_xr) begin
+ case ({m_state_xr})
+\tEP_State_IDLE: m_stateAscii_xr = ""idle "";
+\tEP_State_CMDSHIFT0: m_stateAscii_xr = ""cmdshift0 "";
+\tEP_State_CMDSHIFT13: m_stateAscii_xr = ""cmdshift13"";
+\tEP_State_CMDSHIFT14: m_stateAscii_xr = ""cmdshift14"";
+\tEP_State_CMDSHIFT15: m_stateAscii_xr = ""cmdshift15"";
+\tEP_State_CMDSHIFT16: m_stateAscii_xr = ""cmdshift16"";
+\tEP_State_DWAIT: m_stateAscii_xr = ""dwait "";
+\tEP_State_DSHIFT0: m_stateAscii_xr = ""dshift0 "";
+\tEP_State_DSHIFT1: m_stateAscii_xr = ""dshift1 "";
+\tEP_State_DSHIFT15: m_stateAscii_xr = ""dshift15 "";
+\tdefault: m_stateAscii_xr = ""%Error "";
+ endcase
+ end
+ // End of automatics
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t //$write(""%d %x %x %x\
+"", cyc, data, wrapcheck_a, wrapcheck_b);
+\t if (cyc==1) begin
+\t m_state_xr <= EP_State_IDLE;
+\t m_state2_xr <= EP_State_IDLE;
+\t end
+\t if (cyc==2) begin
+\t if (m_stateAscii_xr != ""idle "") $stop;
+\t m_state_xr <= EP_State_CMDSHIFT13;
+\t if (m_state2_xr != EP_State_IDLE) $stop;
+\t m_state2_xr <= EP_State_CMDSHIFT13;
+\t end
+\t if (cyc==3) begin
+\t if (m_stateAscii_xr != ""cmdshift13"") $stop;
+\t m_state_xr <= EP_State_CMDSHIFT16;
+\t if (m_state2_xr != EP_State_CMDSHIFT13) $stop;
+\t m_state2_xr <= EP_State_CMDSHIFT16;
+\t end
+\t if (cyc==4) begin
+\t if (m_stateAscii_xr != ""cmdshift16"") $stop;
+\t m_state_xr <= EP_State_DWAIT;
+\t if (m_state2_xr != EP_State_CMDSHIFT16) $stop;
+\t m_state2_xr <= EP_State_DWAIT;
+\t end
+\t if (cyc==9) begin
+\t if (m_stateAscii_xr != ""dwait "") $stop;
+\t if (m_state2_xr != EP_State_DWAIT) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t;
+
+ reg [3:0] out;
+ reg [38:0] in;
+ initial begin
+ in = 39\'h0;
+ out = MUX (in);
+ $write(""bad widths %x"", out);
+ end
+
+ function [31:0] MUX;
+ input [39:0] XX ;
+ begin
+ MUX = XX[39:8];
+ end
+ endfunction
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t;
+ initial begin
+ if (add(3'd1) != 0) $stop; // Too few args
+ if (add(3'd1, 3'd2, 3'd3) != 0) $stop;\t// Too many args
+ x; // Too few args
+ if (hasout(3'd1) != 0) $stop; // outputs
+ //
+ f(.j(1), .no_such(2)); // Name mismatch
+ f(.dup(1), .dup(3)); // Duplicate
+ f(1,2,3); // Too many
+ end
+
+ function [2:0] add;
+ input [2:0] from1;
+ input [2:0] from2;
+ begin
+\t add = from1 + from2;
+ end
+ endfunction
+
+ task x;
+ output y;
+ begin end
+ endtask
+
+ function hasout;
+ output [2:0] illegal_output;
+ hasout = 0;
+ endfunction
+
+ function int f( int j = 1, int dup = 0 );
+ return (j<<16) | dup;
+ endfunction
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Duraid Madina.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ parameter logic [1:0] t0 [ 2][ 2] = \'{\'{2\'d0, 2\'d1}, \'{2\'d2, 2\'d3}};
+ parameter logic [1:0] t1 [0:1][0:1] = \'{\'{2\'d0, 2\'d1}, \'{2\'d2, 2\'d3}};
+ parameter logic [1:0] t2 [1:0][1:0] = \'{\'{2\'d3, 2\'d2}, \'{2\'d1, 2\'d0}};
+
+ always @ (posedge clk) begin
+ if (t0[0][0] != t1[0][0]) $stop;
+ if (t0[0][1] != t1[0][1]) $stop;
+ if (t0[1][0] != t1[1][0]) $stop;
+ if (t0[1][1] != t1[1][1]) $stop;
+ if (t0[0][0] != t2[0][0]) $stop;
+ if (t0[0][1] != t2[0][1]) $stop;
+ if (t0[1][0] != t2[1][0]) $stop;
+ if (t0[1][1] != t2[1][1]) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: System Verilog test of enumerated type methods
+//
+// This code exercises the various enumeration methods
+//
+// This file ONLY is placed into the Public Domain, for any use, without
+// warranty.
+
+// Contributed 2012 by M W Lund, Atmel Corporation and Jeremy Bennett, Embecosm.
+
+
+
+// **** Pin Identifiers ****
+typedef enum int
+{
+ PINID_A0 = 32\'d0, // MUST BE ZERO!
+ // - Standard Ports -
+ PINID_A1, PINID_A2, PINID_A3, PINID_A4, PINID_A5, PINID_A6, PINID_A7,
+ PINID_B0, PINID_B1, PINID_B2, PINID_B3, PINID_B4, PINID_B5, PINID_B6, PINID_B7,
+ PINID_C0, PINID_C1, PINID_C2, PINID_C3, PINID_C4, PINID_C5, PINID_C6, PINID_C7,
+ PINID_D0, PINID_D1, PINID_D2, PINID_D3, PINID_D4, PINID_D5, PINID_D6, PINID_D7,
+ PINID_E0, PINID_E1, PINID_E2, PINID_E3, PINID_E4, PINID_E5, PINID_E6, PINID_E7,
+ PINID_F0, PINID_F1, PINID_F2, PINID_F3, PINID_F4, PINID_F5, PINID_F6, PINID_F7,
+ PINID_G0, PINID_G1, PINID_G2, PINID_G3, PINID_G4, PINID_G5, PINID_G6, PINID_G7,
+ PINID_H0, PINID_H1, PINID_H2, PINID_H3, PINID_H4, PINID_H5, PINID_H6, PINID_H7,
+// PINID_I0, PINID_I1, PINID_I2, PINID_I3, PINID_I4, PINID_I5, PINID_I6, PINID_I7,-> DO NOT USE!!!! I == 1
+ PINID_J0, PINID_J1, PINID_J2, PINID_J3, PINID_J4, PINID_J5, PINID_J6, PINID_J7,
+ PINID_K0, PINID_K1, PINID_K2, PINID_K3, PINID_K4, PINID_K5, PINID_K6, PINID_K7,
+ PINID_L0, PINID_L1, PINID_L2, PINID_L3, PINID_L4, PINID_L5, PINID_L6, PINID_L7,
+ PINID_M0, PINID_M1, PINID_M2, PINID_M3, PINID_M4, PINID_M5, PINID_M6, PINID_M7,
+ PINID_N0, PINID_N1, PINID_N2, PINID_N3, PINID_N4, PINID_N5, PINID_N6, PINID_N7,
+// PINID_O0, PINID_O1, PINID_O2, PINID_O3, PINID_O4, PINID_O5, PINID_O6, PINID_O7,-> DO NOT USE!!!! O == 0
+ PINID_P0, PINID_P1, PINID_P2, PINID_P3, PINID_P4, PINID_P5, PINID_P6, PINID_P7,
+ PINID_Q0, PINID_Q1, PINID_Q2, PINID_Q3, PINID_Q4, PINID_Q5, PINID_Q6, PINID_Q7,
+ PINID_R0, PINID_R1, PINID_R2, PINID_R3, PINID_R4, PINID_R5, PINID_R6, PINID_R7,
+ // - AUX Port (Custom) -
+ PINID_X0, PINID_X1, PINID_X2, PINID_X3, PINID_X4, PINID_X5, PINID_X6, PINID_X7,
+ // - PDI Port -
+ PINID_D2W_DAT, PINID_D2W_CLK,
+ // - Power Pins -
+ PINID_VDD0, PINID_VDD1, PINID_VDD2, PINID_VDD3,
+ PINID_GND0, PINID_GND1, PINID_GND2, PINID_GND3,
+ // - Maximum number of pins -
+ PINID_MAX
+ } t_pinid;
+
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ wire a = clk;
+ wire b = 1\'b0;
+ reg c;
+
+ test test_i (/*AUTOINST*/
+\t\t// Inputs
+\t\t.clk\t\t\t(clk));
+
+ // This is a compile time only test. Immediately finish
+ always @(posedge clk) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+
+module test (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ // Use the enumeration size to initialize a dynamic array
+ t_pinid e;
+ int \t myarray1 [] = new [e.num];
+
+ always @(posedge clk) begin
+
+`ifdef TEST_VERBOSE
+ $write (""Enumeration has %d members\
+"", e.num);
+`endif
+
+ e = e.first;
+
+ forever begin
+\t myarray1[e] <= e.prev;
+
+`ifdef TEST_VERBOSE
+\t $write (""myarray1[%d] (enum %s) = %d\
+"", e, e.name, myarray1[e]);
+`endif
+
+\t if (e == e.last) begin
+\t break;
+\t end
+\t else begin
+\t e = e.next;
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ typedef struct packed {
+ union packed {
+\t logic \t ua;
+\t logic \t ub;
+ } u;
+ logic b;
+ } str_t;
+
+ reg \t toggle; initial toggle=\'0;
+
+ str_t stoggle; initial stoggle=\'0;
+
+ const reg aconst = \'0;
+
+ reg [1:0][1:0] ptoggle; initial ptoggle=0;
+
+ integer cyc; initial cyc=1;
+ wire [7:0] cyc_copy = cyc[7:0];
+ wire toggle_up;
+
+ alpha a1 (/*AUTOINST*/
+\t // Outputs
+\t .toggle_up\t\t\t(toggle_up),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle\t\t\t(toggle),
+\t .cyc_copy\t\t\t(cyc_copy[7:0]));
+ alpha a2 (/*AUTOINST*/
+\t // Outputs
+\t .toggle_up\t\t\t(toggle_up),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle\t\t\t(toggle),
+\t .cyc_copy\t\t\t(cyc_copy[7:0]));
+
+ beta b1 (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle_up\t\t\t(toggle_up));
+
+ off o1 (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle\t\t\t(toggle));
+
+ reg [1:0] memory[121:110];
+
+ reg [1023:0] largeish;
+ // CHECK_COVER_MISSING(-1)
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t memory[cyc + \'d100] <= memory[cyc + \'d100] + 2\'b1;
+\t toggle <= \'0;
+\t stoggle.u <= toggle;
+\t stoggle.b <= toggle;
+\t ptoggle[0][0] <= toggle;
+\t if (cyc==3) begin
+\t toggle <= \'1;
+\t end
+\t if (cyc==4) begin
+\t toggle <= \'0;
+\t end
+\t else if (cyc==10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+module alpha (/*AUTOARG*/
+ // Outputs
+ toggle_up,
+ // Inputs
+ clk, toggle, cyc_copy
+ );
+
+ // t.a1 and t.a2 collapse to a count of 2
+
+ input clk;
+
+ input toggle;
+ // CHECK_COVER(-1,""top.v.a*"",4)
+ // 2 edges * (t.a1 and t.a2)
+
+ input [7:0] cyc_copy;
+ // CHECK_COVER(-1,""top.v.a*"",""cyc_copy[0]"",22)
+ // CHECK_COVER(-2,""top.v.a*"",""cyc_copy[1]"",10)
+ // CHECK_COVER(-3,""top.v.a*"",""cyc_copy[2]"",4)
+ // CHECK_COVER(-4,""top.v.a*"",""cyc_copy[3]"",2)
+ // CHECK_COVER(-5,""top.v.a*"",""cyc_copy[4]"",0)
+ // CHECK_COVER(-6,""top.v.a*"",""cyc_copy[5]"",0)
+ // CHECK_COVER(-7,""top.v.a*"",""cyc_copy[6]"",0)
+ // CHECK_COVER(-8,""top.v.a*"",""cyc_copy[7]"",0)
+
+ reg \t toggle_internal;
+ // CHECK_COVER(-1,""top.v.a*"",4)
+ // 2 edges * (t.a1 and t.a2)
+
+ output reg toggle_up;
+ // CHECK_COVER(-1,""top.v.a*"",4)
+ // 2 edges * (t.a1 and t.a2)
+
+ always @ (posedge clk) begin
+ toggle_internal <= toggle;
+ toggle_up <= toggle;
+ end
+endmodule
+
+module beta (/*AUTOARG*/
+ // Inputs
+ clk, toggle_up
+ );
+
+ input clk;
+
+ input toggle_up;
+ // CHECK_COVER(-1,""top.v.b1"",""toggle_up"",2)
+
+ /* verilator public_module */
+
+ always @ (posedge clk) begin
+ if (0 && toggle_up) begin end
+ end
+endmodule
+
+module off (/*AUTOARG*/
+ // Inputs
+ clk, toggle
+ );
+
+ // verilator coverage_off
+ input clk;
+ // CHECK_COVER_MISSING(-1)
+
+ // verilator coverage_on
+ input toggle;
+ // CHECK_COVER(-1,""top.v.o1"",""toggle"",2)
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Simple test of unoptflat
+//
+// Demonstration of an UNOPTFLAT combinatorial loop using 3 bits and looping
+// through 2 sub-modules.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Jeremy Bennett.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ wire [2:0] x;
+
+ initial begin
+ x = 3\'b000;
+ end
+
+ test1 test1i ( .clk (clk),
+\t\t .xvecin (x[1:0]),
+\t\t .xvecout (x[2:1]));
+
+ test2 test2i ( .clk (clk),
+\t\t .xvecin (x[2:1]),
+\t\t .xvecout (x[1:0]));
+
+ always @(posedge clk or negedge clk) begin
+
+`ifdef TEST_VERBOSE
+ $write(""x = %x\
+"", x);
+`endif
+
+ if (x[1] != 0) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule // t
+
+
+module test1
+ (/*AUTOARG*/
+ // Inputs
+ clk,
+ xvecin,
+ // Outputs
+ xvecout
+ );
+
+ input clk;
+ input wire [1:0] xvecin;
+
+ output wire [1:0] xvecout;
+
+ assign xvecout = {xvecin[0], clk};
+
+endmodule // test
+
+
+module test2
+ (/*AUTOARG*/
+ // Inputs
+ clk,
+ xvecin,
+ // Outputs
+ xvecout
+ );
+
+ input clk;
+ input wire [1:0] xvecin;
+
+ output wire [1:0] xvecout;
+
+ assign xvecout = {clk, xvecin[1]};
+
+endmodule // test
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg \t toggle; initial toggle=0;
+
+ integer cyc; initial cyc=1;
+ wire [7:0] cyc_copy = cyc[7:0];
+
+ alpha a1 (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle\t\t\t(toggle));
+ alpha a2 (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle\t\t\t(toggle));
+ beta b1 (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle\t\t\t(toggle));
+ beta b2 (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle\t\t\t(toggle));
+ tsk t1 (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle\t\t\t(toggle));
+ off o1 (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle\t\t\t(toggle));
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t toggle <= \'0;
+\t if (cyc==3) begin
+\t toggle <= \'1;
+\t end
+\t else if (cyc==5) begin
+`ifdef VERILATOR
+\t $c(""call_task();"");
+`else
+\t call_task();
+`endif
+\t end
+\t else if (cyc==10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+ task call_task;
+ /* verilator public */
+ t1.center_task(1\'b1);
+ endtask
+
+endmodule
+
+module alpha (/*AUTOARG*/
+ // Inputs
+ clk, toggle
+ );
+ input clk;
+ input toggle;
+ always @ (posedge clk) begin
+ if (toggle) begin
+\t // CHECK_COVER(-1,""top.v.a*"",2)
+\t // t.a1 and t.a2 collapse to a count of 2
+ end
+ if (toggle) begin
+\t // CHECK_COVER_MISSING(-1)
+\t // This doesn\'t even get added
+\t // verilator coverage_block_off
+\t $write("""");
+ end
+ end
+endmodule
+
+module beta (/*AUTOARG*/
+ // Inputs
+ clk, toggle
+ );
+ input clk;
+ input toggle;
+
+ /* verilator public_module */
+
+ always @ (posedge clk) begin
+ if (0) begin
+\t // CHECK_COVER(-1,""top.v.b*"",0)
+\t // Make sure that we don\'t optimize away zero buckets
+ end
+ if (toggle) begin
+\t // CHECK_COVER(-1,""top.v.b*"",2)
+\t // t.b1 and t.b2 collapse to a count of 2
+ end
+ if (toggle) begin
+\t // CHECK_COVER_MISSING(-1)
+\t // This doesn\'t
+\t // verilator coverage_block_off
+\t $write("""");
+ end
+ end
+endmodule
+
+module tsk (/*AUTOARG*/
+ // Inputs
+ clk, toggle
+ );
+ input clk;
+ input toggle;
+
+ /* verilator public_module */
+
+ always @ (posedge clk) begin
+ center_task(1\'b0);
+ end
+
+ task center_task;
+ input external;
+ begin
+\t if (toggle) begin
+\t // CHECK_COVER(-1,""top.v.t1"",1)
+\t end
+\t if (external) begin
+\t // CHECK_COVER(-1,""top.v.t1"",1)
+\t $write(""[%0t] Got external pulse\
+"", $time);
+\t end
+ end
+ endtask
+
+endmodule
+
+module off (/*AUTOARG*/
+ // Inputs
+ clk, toggle
+ );
+ input clk;
+ input toggle;
+
+ // verilator coverage_off
+ always @ (posedge clk) begin
+ if (toggle) begin
+\t // CHECK_COVER_MISSING(-1)
+\t // because under coverage_module_off
+ end
+ end
+ // verilator coverage_on
+ always @ (posedge clk) begin
+ if (toggle) begin
+\t // CHECK_COVER(-1,""top.v.o1"",1)
+\t // because under coverage_module_off
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005-2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ parameter [200:0] TOO_SMALL = 94'd123456789012345678901234567890; // One to many digits
+
+ parameter [200:0] SMALLH = 8'habc; // One to many digits
+ parameter [200:0] SMALLO = 6'o1234; // One to many digits
+ parameter [200:0] SMALLB = 3'b1111; // One to many digits
+
+ // We'll allow this though; no reason to be cruel
+ parameter [200:0] OKH = 8'h000000001;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg [2:0] index_a;
+ reg [2:0] index_b;
+
+ prover #(4) p4 (/*AUTOINST*/
+\t\t // Inputs
+\t\t .clk\t\t(clk),
+\t\t .index_a\t\t(index_a),
+\t\t .index_b\t\t(index_b));
+ prover #(32) p32 (/*AUTOINST*/
+\t\t // Inputs
+\t\t .clk\t\t(clk),
+\t\t .index_a\t\t(index_a),
+\t\t .index_b\t\t(index_b));
+ prover #(63) p63 (/*AUTOINST*/
+\t\t // Inputs
+\t\t .clk\t\t(clk),
+\t\t .index_a\t\t(index_a),
+\t\t .index_b\t\t(index_b));
+ prover #(64) p64 (/*AUTOINST*/
+\t\t // Inputs
+\t\t .clk\t\t(clk),
+\t\t .index_a\t\t(index_a),
+\t\t .index_b\t\t(index_b));
+ prover #(72) p72 (/*AUTOINST*/
+\t\t // Inputs
+\t\t .clk\t\t(clk),
+\t\t .index_a\t\t(index_a),
+\t\t .index_b\t\t(index_b));
+ prover #(126) p126 (/*AUTOINST*/
+\t\t // Inputs
+\t\t .clk\t\t(clk),
+\t\t .index_a\t\t(index_a),
+\t\t .index_b\t\t(index_b));
+ prover #(128) p128 (/*AUTOINST*/
+\t\t // Inputs
+\t\t .clk\t\t(clk),
+\t\t .index_a\t\t(index_a),
+\t\t .index_b\t\t(index_b));
+
+ integer cyc; initial cyc=0;
+ initial index_a = 3\'b0;
+ initial index_b = 3\'b0;
+ always @* begin
+ index_a = cyc[2:0]; if (index_a>3\'d4) index_a=3\'d4;
+ index_b = cyc[5:3]; if (index_b>3\'d4) index_b=3\'d4;
+ end
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+
+module prover (
+ input clk,
+ input [2:0] index_a,
+ input [2:0] index_b
+ );
+
+ parameter WIDTH = 4;
+
+
+ reg signed [WIDTH-1:0] as;
+ reg signed [WIDTH-1:0] bs;
+ wire [WIDTH-1:0] \t b = bs;
+
+ always @* begin
+ casez (index_a)
+\t 3\'d0: as = {(WIDTH){1\'d0}}; // 0
+\t 3\'d1: as = {{(WIDTH-1){1\'d0}}, 1\'b1}; // 1
+\t 3\'d2: as = {1\'b0, {(WIDTH-1){1\'d0}}}; // 127 or equiv
+\t 3\'d3: as = {(WIDTH){1\'d1}}; // -1
+\t 3\'d4: as = {1\'b1, {(WIDTH-1){1\'d0}}}; // -128 or equiv
+\t default: $stop;
+ endcase
+ casez (index_b)
+\t 3\'d0: bs = {(WIDTH){1\'d0}}; // 0
+\t 3\'d1: bs = {{(WIDTH-1){1\'d0}}, 1\'b1}; // 1
+\t 3\'d2: bs = {1\'b0, {(WIDTH-1){1\'d0}}}; // 127 or equiv
+\t 3\'d3: bs = {(WIDTH){1\'d1}}; // -1
+\t 3\'d4: bs = {1\'b1, {(WIDTH-1){1\'d0}}}; // -128 or equiv
+\t default: $stop;
+ endcase
+ end
+
+ reg [7:0] results[4:0][4:0];
+
+ wire gt = as>b;
+ wire gts = as>bs;
+ wire gte = as>=b;
+ wire gtes = as>=bs;
+ wire lt = as2) begin
+`ifdef TEST_VERBOSE
+\t $write(""results[%d][%d] = 8\'b%b_%b_%b_%b_%b_%b_%b_%b;\
+"",
+ \t\tindex_a, index_b,
+ \t\tgt, gts, gte, gtes, lt, lts, lte, ltes);
+`endif
+\t exp = results[index_a][index_b];
+\t got = {gt, gts, gte, gtes, lt, lts, lte, ltes};
+\t if (exp !== got) begin
+\t $display(""%%Error: bad comparison width=%0d: %d/%d got=%b exp=%b"", WIDTH, index_a,index_b,got, exp);
+\t $stop;
+\t end
+ end
+ end
+
+ // Result table
+ initial begin
+ // Indexes: 0, 1, -1, 127, -128
+ // Gt Gts Gte Gtes Lt Lts Lte Ltes
+ results[0][0] = 8\'b0_0_1_1_0_0_1_1;
+ results[0][1] = 8\'b0_0_0_0_1_1_1_1;
+ results[0][2] = 8\'b0_0_1_1_0_0_1_1;
+ results[0][3] = 8\'b0_1_0_1_1_0_1_0;
+ results[0][4] = 8\'b0_1_0_1_1_0_1_0;
+ results[1][0] = 8\'b1_1_1_1_0_0_0_0;
+ results[1][1] = 8\'b0_0_1_1_0_0_1_1;
+ results[1][2] = 8\'b1_1_1_1_0_0_0_0;
+ results[1][3] = 8\'b0_1_0_1_1_0_1_0;
+ results[1][4] = 8\'b0_1_0_1_1_0_1_0;
+ results[2][0] = 8\'b0_0_1_1_0_0_1_1;
+ results[2][1] = 8\'b0_0_0_0_1_1_1_1;
+ results[2][2] = 8\'b0_0_1_1_0_0_1_1;
+ results[2][3] = 8\'b0_1_0_1_1_0_1_0;
+ results[2][4] = 8\'b0_1_0_1_1_0_1_0;
+ results[3][0] = 8\'b1_0_1_0_0_1_0_1;
+ results[3][1] = 8\'b1_0_1_0_0_1_0_1;
+ results[3][2] = 8\'b1_0_1_0_0_1_0_1;
+ results[3][3] = 8\'b0_0_1_1_0_0_1_1;
+ results[3][4] = 8\'b1_1_1_1_0_0_0_0;
+ results[4][0] = 8\'b1_0_1_0_0_1_0_1;
+ results[4][1] = 8\'b1_0_1_0_0_1_0_1;
+ results[4][2] = 8\'b1_0_1_0_0_1_0_1;
+ results[4][3] = 8\'b0_0_0_0_1_1_1_1;
+ results[4][4] = 8\'b0_0_1_1_0_0_1_1;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ rst_sync_l, rst_both_l, rst_async_l, d, clk
+ );
+ /*AUTOINPUT*/
+ // Beginning of automatic inputs (from unused autoinst inputs)
+ input\t\tclk;\t\t\t// To sub1 of sub1.v, ...
+ input\t\td;\t\t\t// To sub1 of sub1.v, ...
+ input\t\trst_async_l;\t\t// To sub2 of sub2.v
+ input\t\trst_both_l;\t\t// To sub1 of sub1.v, ...
+ input\t\trst_sync_l;\t\t// To sub1 of sub1.v
+ // End of automatics
+
+ sub1 sub1 (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .rst_both_l\t\t(rst_both_l),
+\t .rst_sync_l\t\t(rst_sync_l),
+\t .d\t\t\t(d));
+ sub2 sub2 (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .rst_both_l\t\t(rst_both_l),
+\t .rst_async_l\t\t(rst_async_l),
+\t .d\t\t\t(d));
+endmodule
+
+module sub1 (/*AUTOARG*/
+ // Inputs
+ clk, rst_both_l, rst_sync_l, d
+ );
+
+ input clk;
+ input rst_both_l;
+ input rst_sync_l;
+ //input rst_async_l;
+ input d;
+ reg q1;
+ reg q2;
+
+ always @(posedge clk) begin
+ if (~rst_sync_l) begin
+\t /*AUTORESET*/
+\t // Beginning of autoreset for uninitialized flops
+\t q1 <= 1'h0;
+\t // End of automatics
+ end else begin
+\t q1 <= d;
+ end
+ end
+
+ always @(posedge clk) begin
+ q2 <= (~rst_both_l) ? 1'b0 : d;
+ if (0 && q1 && q2) ;
+ end
+
+endmodule
+
+module sub2 (/*AUTOARG*/
+ // Inputs
+ clk, rst_both_l, rst_async_l, d
+ );
+
+ input clk;
+ input rst_both_l;
+ //input rst_sync_l;
+ input rst_async_l;
+ input d;
+ reg \t q1;
+ reg \t q2;
+ reg \t q3;
+
+ always @(posedge clk or negedge rst_async_l) begin
+ if (~rst_async_l) begin
+\t /*AUTORESET*/
+\t // Beginning of autoreset for uninitialized flops
+\t q1 <= 1'h0;
+\t // End of automatics
+ end else begin
+\t q1 <= d;
+ end
+ end
+
+ always @(posedge clk or negedge rst_both_l) begin
+ q2 <= (~rst_both_l) ? 1'b0 : d;
+ end
+ // Make there be more async uses than sync uses
+ always @(posedge clk or negedge rst_both_l) begin
+ q3 <= (~rst_both_l) ? 1'b0 : d;
+ if (0 && q1 && q2 && q3) ;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t;
+
+ integer v = 19;
+
+ initial begin
+ if (v==1) begin end
+ else if (v==2) begin end
+ else if (v==3) begin end
+ else if (v==4) begin end
+ else if (v==5) begin end
+ else if (v==6) begin end
+ else if (v==7) begin end
+ else if (v==8) begin end
+ else if (v==9) begin end
+ else if (v==10) begin end
+ else if (v==11) begin end // Warn about this one
+ else if (v==12) begin end
+ end
+
+ initial begin
+ unique0 if (v==1) begin end
+ else if (v==2) begin end
+ else if (v==3) begin end
+ else if (v==4) begin end
+ else if (v==5) begin end
+ else if (v==6) begin end
+ else if (v==7) begin end
+ else if (v==8) begin end
+ else if (v==9) begin end
+ else if (v==10) begin end
+ else if (v==11) begin end // Warn about this one
+ else if (v==12) begin end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+// see bug491
+
+package functions;
+ function real abs (real num);
+ abs = (num <0) ? -num : num;
+ endfunction
+ function real neg (real num);
+ return -abs(num); // Check package funcs can call package funcs
+ endfunction
+endpackage
+
+module t ();
+ import functions::*;
+ localparam P = 1;
+ generate
+ if (P == 1) begin
+\t initial begin
+\t if (abs(-2.1) != 2.1) $stop;
+\t if (abs(2.2) != 2.2) $stop;
+\t if (neg(-2.1) != -2.1) $stop;
+\t if (neg(2.2) != -2.2) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ endgenerate
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t;
+ reg a;
+ initial begin
+ $unknown_sys_task_call_to_be_bbox(""blah"");
+ $unkown_sys_task_call_noarg;
+ a = $unknown_sys_func_call(23);
+ a = $unknown_sys_func_call_noarg;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+interface counter_if;
+ logic [3:0] value;
+ logic reset;
+ modport counter_mp (input reset, output value);
+ modport core_mp (output reset, input value);
+endinterface
+
+// Check can have inst module before top module
+module counter_ansi
+ (
+ input clkm,
+ counter_if c_data,
+ input logic [3:0] i_value
+ );
+
+ always @ (posedge clkm) begin
+ c_data.value <= c_data.reset ? i_value : c_data.value + 1;
+ end
+endmodule : counter_ansi
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc=1;
+
+ counter_if c1_data();
+ counter_if c2_data();
+ counter_if c3_data();
+ counter_if c4_data();
+
+ counter_ansi c1 (.clkm(clk),
+\t\t .c_data(c1_data.counter_mp),
+\t\t .i_value(4\'h1));
+`ifdef VERILATOR counter_ansi `else counter_nansi `endif
+ /**/ c2 (.clkm(clk),
+\t\t .c_data(c2_data.counter_mp),
+\t\t .i_value(4\'h2));
+ counter_ansi_m c3 (.clkm(clk),
+\t\t .c_data(c3_data),
+\t\t .i_value(4\'h3));
+`ifdef VERILATOR counter_ansi_m `else counter_nansi_m `endif
+ /**/ c4 (.clkm(clk),
+\t\t .c_data(c4_data),
+\t\t .i_value(4\'h4));
+
+ initial begin
+ c1_data.value = 4\'h4;
+ c2_data.value = 4\'h5;
+ c3_data.value = 4\'h6;
+ c4_data.value = 4\'h7;
+ end
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc<2) begin
+\t c1_data.reset <= 1;
+\t c2_data.reset <= 1;
+\t c3_data.reset <= 1;
+\t c4_data.reset <= 1;
+ end
+ if (cyc==2) begin
+\t c1_data.reset <= 0;
+\t c2_data.reset <= 0;
+\t c3_data.reset <= 0;
+\t c4_data.reset <= 0;
+ end
+ if (cyc==20) begin
+\t $write(""[%0t] cyc%0d: c1 %0x %0x c2 %0x %0x c3 %0x %0x c4 %0x %0x\
+"", $time, cyc,
+\t\tc1_data.value, c1_data.reset,
+\t\tc2_data.value, c2_data.reset,
+\t\tc3_data.value, c3_data.reset,
+\t\tc4_data.value, c4_data.reset);
+\t if (c1_data.value != 2) $stop;
+\t if (c2_data.value != 3) $stop;
+\t if (c3_data.value != 4) $stop;
+\t if (c4_data.value != 5) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+`ifndef VERILATOR
+// non-ansi modports not seen in the wild yet. Verilog-Perl needs parser improvement too.
+module counter_nansi
+ (clkm, c_data, i_value);
+
+ input clkm;
+ counter_if c_data;
+ input logic [3:0] i_value;
+
+ always @ (posedge clkm) begin
+ c_data.value <= c_data.reset ? i_value : c_data.value + 1;
+ end
+endmodule : counter_nansi
+`endif
+
+module counter_ansi_m
+ (
+ input clkm,
+ counter_if.counter_mp c_data,
+ input logic [3:0] i_value
+ );
+
+ always @ (posedge clkm) begin
+ c_data.value <= c_data.reset ? i_value : c_data.value + 1;
+ end
+endmodule : counter_ansi_m
+
+`ifndef VERILATOR
+// non-ansi modports not seen in the wild yet. Verilog-Perl needs parser improvement too.
+module counter_nansi_m
+ (clkm, c_data, i_value);
+
+ input clkm;
+ counter_if.counter_mp c_data;
+ input logic [3:0] i_value;
+
+ always @ (posedge clkm) begin
+ c_data.value <= c_data.reset ? i_value : c_data.value + 1;
+ end
+endmodule : counter_nansi_m
+`endif
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ // verilator lint_off WIDTH
+ reg [6:0] myreg1;
+
+ initial begin
+ myreg1 = # 100 7\'d0;
+ myreg1 = # 100 \'b0; // [#] [100] [\'b0]
+ myreg1 = #100\'b0; // [#] [100] [\'b0]
+ myreg1 = 100\'b0;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [19:0] in = crc[19:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [19:0]\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[19:0]),
+\t // Inputs
+\t .in\t\t\t(in[19:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {44\'h0, out};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'hdb7bc61592f31b99
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+typedef struct packed {
+ logic [7:0] cn;
+ logic vbfval;
+ logic vabval;
+} rel_t;
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ in
+ );
+
+ input [19:0] in;
+ output [19:0] out;
+
+ rel_t [1:0] i; // From ifb0 of ifb.v, ...
+ rel_t [1:0] o; // From ifb0 of ifb.v, ...
+
+ assign i = in;
+ assign out = o;
+
+ sub sub
+ (
+ .i (i[1:0]),
+ .o (o[1:0]));
+endmodule
+
+module sub (/*AUTOARG*/
+ // Outputs
+ o,
+ // Inputs
+ i
+ );
+
+ input rel_t [1:0] i;
+ output rel_t [1:0] o;
+ assign o = i;
+endmodule
+
+// Local Variables:
+// verilog-typedef-regexp: ""_t$""
+// End:
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+// bug474
+package verb_pkg;
+ typedef enum int {VERB_I,
+\t\t VERB_W} Verb_t;
+ Verb_t verb = VERB_I;
+ string message = "" "";
+endpackage
+
+module t;
+ import verb_pkg::*;
+
+ string message = ""*x*"";
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ out, out2,
+ // Inputs
+ clk, a0, d0, d1
+ );
+
+ input clk;
+ input [1:0] a0;
+ input [7:0] d0;
+ input [7:0] d1;
+ output reg [31:0] out;
+ output reg [15:0] out2;
+
+ reg [7:0] \t mem [4];
+
+ always @(posedge clk) begin
+ mem[a0] <= d0;
+ end
+ always @(negedge clk) begin
+ mem[a0] <= d1;
+ end
+ assign out = {mem[3],mem[2],mem[1],mem[0]};
+
+ always @(posedge clk) begin
+ out2[7:0] <= d0;
+ end
+ always @(negedge clk) begin
+ out2[15:8] <= d0;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ integer \tcyc=0;
+
+ localparam N = 31;
+
+ wire [31:0] \tvec;
+
+ generate
+ genvar g; // bug461
+ begin : topgen
+\t for (g=0; g 0.000001) begin
+\t $display(""%%Error: Line %0d: Bad result, got=%0.99g expect=%0.99g"",line,got,ex);
+\t $stop;
+\t end
+ end
+ endtask
+
+ initial begin
+ // Check constant propagation
+ // Note $abs is not defined in SystemVerilog (as of 2012)
+ check(`__LINE__, $ceil(-1.2),\t-1);
+ check(`__LINE__, $ceil(1.2),\t2);
+ check(`__LINE__, $exp(1.2),\t3.3201169227365472380597566370852291584014892578125);
+ check(`__LINE__, $exp(0.0),\t1);
+ check(`__LINE__, $exp(-1.2),\t0.301194211912202136627314530414878390729427337646484375);
+ check(`__LINE__, $floor(-1.2),\t-2);
+ check(`__LINE__, $floor(1.2),\t1);
+ check(`__LINE__, $ln(1.2),\t0.1823215567939545922460098381634452380239963531494140625);
+ //check(`__LINE__, $ln(0),\t0);\t// Bad value
+ //check(`__LINE__, $ln(-1.2),\t0);\t// Bad value
+ check(`__LINE__, $log10(1.2),\t0.07918124604762481755226843915806966833770275115966796875);
+ //check(`__LINE__, $log10(0),\t0);\t// Bad value
+ //check(`__LINE__, $log10(-1.2),\t0);
+ check(`__LINE__, $pow(2.3,1.2),\t2.71689843249914897427288451581262052059173583984375);
+ check(`__LINE__, $pow(2.3,-1.2),\t0.368066758785732861536388327294844202697277069091796875);
+ //check(`__LINE__, $pow(-2.3,1.2),0);\t// Bad value
+ check(`__LINE__, $sqrt(1.2),\t1.095445115010332148841598609578795731067657470703125);
+ //check(`__LINE__, $sqrt(-1.2),\t0);\t// Bad value
+ check(`__LINE__, ((1.5)**(1.25)), 1.660023);
+`ifndef VERILATOR
+ check(`__LINE__, $acos (0.2),\t1.369438406);\t// Arg1 is -1..1
+ check(`__LINE__, $acosh(1.2),\t0.622362503);
+ check(`__LINE__, $asin (0.2),\t0.201357920);\t// Arg1 is -1..1
+ check(`__LINE__, $asinh(1.2),\t1.015973134);
+ check(`__LINE__, $atan (0.2),\t0.197395559);
+ check(`__LINE__, $atan2(0.2,2.3),\t0.086738338);\t// Arg1 is -1..1
+ check(`__LINE__, $atanh(0.2),\t0.202732554);\t// Arg1 is -1..1
+ check(`__LINE__, $cos (1.2),\t0.362357754);
+ check(`__LINE__, $cosh (1.2),\t1.810655567);
+ check(`__LINE__, $hypot(1.2,2.3),\t2.594224354);
+ check(`__LINE__, $sin (1.2),\t0.932039085);
+ check(`__LINE__, $sinh (1.2),\t1.509461355);
+ check(`__LINE__, $tan (1.2),\t2.572151622);
+ check(`__LINE__, $tanh (1.2),\t0.833654607);
+`endif
+ end
+
+ real sum_ceil;
+ real sum_exp;
+ real sum_floor;
+ real sum_ln;
+ real sum_log10;
+ real sum_pow1;
+ real sum_pow2;
+ real sum_sqrt;
+
+ real sum_acos;
+ real sum_acosh;
+ real sum_asin;
+ real sum_asinh;
+ real sum_atan;
+ real sum_atan2;
+ real sum_atanh;
+ real sum_cos ;
+ real sum_cosh;
+ real sum_hypot;
+ real sum_sin;
+ real sum_sinh;
+ real sum_tan;
+ real sum_tanh;
+
+ // Test loop
+ always @ (posedge clk) begin
+ r = $itor(cyc)/10.0 - 5.0; // Crosses 0
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d r=%g s_ln=%0.12g\
+"",$time, cyc, r, sum_ln);
+`endif
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+ end
+ else if (cyc<90) begin
+\t // Setup
+\t sum_ceil\t+= 1.0+$ceil(r);
+\t sum_exp\t+= 1.0+$exp(r);
+\t sum_floor\t+= 1.0+$floor(r);
+\t if (r > 0.0) sum_ln += 1.0+$ln(r);
+\t if (r > 0.0) sum_log10 += 1.0+$log10(r);
+\t // Pow requires if arg1<0 then arg1 integral
+\t sum_pow1 += 1.0+$pow(2.3,r);
+\t if (r >= 0.0) sum_pow2 += 1.0+$pow(r,2.3);
+\t if (r >= 0.0) sum_sqrt += 1.0+$sqrt(r);
+
+`ifndef VERILATOR
+\t if (r>=-1.0 && r<=1.0) sum_acos += 1.0+$acos (r);
+\t if (r>=1.0) sum_acosh += 1.0+$acosh(r);
+\t if (r>=-1.0 && r<=1.0) sum_asin += 1.0+$asin (r);
+\t sum_asinh += 1.0+$asinh(r);
+\t sum_atan += 1.0+$atan (r);
+\t if (r>=-1.0 && r<=1.0) sum_atan2 += 1.0+$atan2(r,2.3);
+\t if (r>=-1.0 && r<=1.0) sum_atanh += 1.0+$atanh(r);
+\t sum_cos += 1.0+$cos (r);
+\t sum_cosh += 1.0+$cosh (r);
+\t sum_hypot += 1.0+$hypot(r,2.3);
+\t sum_sin += 1.0+$sin (r);
+\t sum_sinh += 1.0+$sinh (r);
+\t sum_tan += 1.0+$tan (r);
+\t sum_tanh += 1.0+$tanh (r);
+`endif
+ end
+ else if (cyc==99) begin
+\t check (`__LINE__, sum_ceil,\t85);
+\t check (`__LINE__, sum_exp,\t608.06652950);
+\t check (`__LINE__, sum_floor,\t4);
+\t check (`__LINE__, sum_ln,\t55.830941633);
+\t check (`__LINE__, sum_log10,\t46.309585076);
+\t check (`__LINE__, sum_pow1,\t410.98798177);
+\t check (`__LINE__, sum_pow2,\t321.94765689);
+\t check (`__LINE__, sum_sqrt,\t92.269677253);
+`ifndef VERILATOR
+\t check (`__LINE__, sum_acos,\t53.986722862);
+\t check (`__LINE__, sum_acosh,\t72.685208498);
+\t check (`__LINE__, sum_asin,\t21);
+\t check (`__LINE__, sum_asinh,\t67.034973416);
+\t check (`__LINE__, sum_atan,\t75.511045389);
+\t check (`__LINE__, sum_atan2,\t21);
+\t check (`__LINE__, sum_atanh,\t0);
+\t check (`__LINE__, sum_cos,\t72.042023124);
+\t check (`__LINE__, sum_cosh,\t1054.0178222);
+\t check (`__LINE__, sum_hypot,\t388.92858406);
+\t check (`__LINE__, sum_sin,\t98.264184989);
+\t check (`__LINE__, sum_sinh,\t0);
+\t check (`__LINE__, sum_tan,\t1.7007946043);
+\t check (`__LINE__, sum_tanh,\t79.003199681);
+`endif
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Iztok Jeras.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
+
+ // parameters for array sizes
+ localparam WA = 4;
+ localparam WB = 6;
+ localparam WC = 8;
+
+ // 2D packed arrays
+ logic [WA+1:2] [WB+1:2] [WC+1:2] array_bg; // big endian array
+ /* verilator lint_off LITENDIAN */
+ logic [2:WA+1] [2:WB+1] [2:WC+1] array_lt; // little endian array
+ /* verilator lint_on LITENDIAN */
+
+ logic [1:0] array_unpk [3:2][1:0];
+
+ integer cnt = 0;
+ integer slc = 0; // slice type
+ integer dim = 0; // dimension
+ integer wdt = 0; // width
+
+ initial begin
+ `checkh($dimensions (array_unpk), 3);
+`ifndef VCS
+ `checkh($unpacked_dimensions (array_unpk), 2); // IEEE 2009
+`endif
+ `checkh($bits (array_unpk), 2*2*2);
+ `checkh($low (array_unpk), 2);
+ `checkh($high (array_unpk), 3);
+ `checkh($left (array_unpk), 3);
+ `checkh($right(array_unpk), 2);
+ `checkh($increment(array_unpk), 1);
+ `checkh($size (array_unpk), 2);
+ end
+
+ // event counter
+ always @ (posedge clk) begin
+ cnt <= cnt + 1;
+ end
+
+ // finish report
+ always @ (posedge clk)
+ if ( (cnt[30:4]==3) && (cnt[3:2]==2\'d3) && (cnt[1:0]==2\'d3) ) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ integer slc_next;
+
+ // calculation of dimention sizes
+ always @ (posedge clk) begin
+ // slicing type counter
+ case (cnt[3:2])
+ 2\'d0 : begin slc_next = 0; end // full array
+ 2\'d1 : begin slc_next = 1; end // single array element
+ 2\'d2 : begin slc_next = 2; end // half array
+ default: begin slc_next = 0; end
+ endcase
+ slc <= slc_next;
+ // dimension counter
+ case (cnt[1:0])
+ 2\'d0 : begin dim <= 1; wdt <= (slc_next==1) ? WA/2 : (slc_next==2) ? WA/2 : WA; end
+ 2\'d1 : begin dim <= 2; wdt <= WB; end
+ 2\'d2 : begin dim <= 3; wdt <= WC; end
+ default: begin dim <= 0; wdt <= 0; end
+ endcase
+ end
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""cnt[30:4]=%0d slc=%0d dim=%0d wdt=%0d\
+"", cnt[30:4], slc, dim, wdt);
+`endif
+ if (cnt[30:4]==1) begin
+\t // big endian
+\t if (slc==0) begin
+ // full array
+ `checkh($dimensions (array_bg), 3);
+ `checkh($bits (array_bg), WA*WB*WC);
+ if ((dim>=1)&&(dim<=3)) begin
+ `checkh($left (array_bg, dim), wdt+1);
+ `checkh($right (array_bg, dim), 2 );
+ `checkh($low (array_bg, dim), 2 );
+ `checkh($high (array_bg, dim), wdt+1);
+ `checkh($increment (array_bg, dim), 1 );
+ `checkh($size (array_bg, dim), wdt );
+ end
+\t end else if (slc==1) begin
+ // single array element
+ `checkh($dimensions (array_bg[2]), 2);
+ `checkh($bits (array_bg[2]), WB*WC);
+ if ((dim>=2)&&(dim<=3)) begin
+ `checkh($left (array_bg[2], dim-1), wdt+1);
+ `checkh($right (array_bg[2], dim-1), 2 );
+ `checkh($low (array_bg[2], dim-1), 2 );
+ `checkh($high (array_bg[2], dim-1), wdt+1);
+ `checkh($increment (array_bg[2], dim-1), 1 );
+ `checkh($size (array_bg[2], dim-1), wdt );
+ end
+`ifndef VERILATOR // Unsupported slices don\'t maintain size correctly
+\t end else if (slc==2) begin
+ // half array
+ `checkh($dimensions (array_bg[WA/2+1:2]), 3);
+ `checkh($bits (array_bg[WA/2+1:2]), WA/2*WB*WC);
+ if ((dim>=1)&&(dim<=3)) begin
+ `checkh($left (array_bg[WA/2+1:2], dim), wdt+1);
+ `checkh($right (array_bg[WA/2+1:2], dim), 2 );
+ `checkh($low (array_bg[WA/2+1:2], dim), 2 );
+ `checkh($high (array_bg[WA/2+1:2], dim), wdt+1);
+ `checkh($increment (array_bg[WA/2+1:2], dim), 1 );
+ `checkh($size (array_bg[WA/2+1:2], dim), wdt);
+ end
+`endif
+\t end
+ end else if (cnt[30:4]==2) begin
+\t // little endian
+\t if (slc==0) begin
+ // full array
+ `checkh($dimensions (array_lt), 3);
+ `checkh($bits (array_lt), WA*WB*WC);
+ if ((dim>=1)&&(dim<=3)) begin
+ `checkh($left (array_lt, dim), 2 );
+ `checkh($right (array_lt, dim), wdt+1);
+ `checkh($low (array_lt, dim), 2 );
+ `checkh($high (array_lt, dim), wdt+1);
+ `checkh($increment (array_lt, dim), -1 );
+ `checkh($size (array_lt, dim), wdt );
+ end
+\t end else if (slc==1) begin
+ // single array element
+ `checkh($dimensions (array_lt[2]), 2);
+ `checkh($bits (array_lt[2]), WB*WC);
+ if ((dim>=2)&&(dim<=3)) begin
+ `checkh($left (array_lt[2], dim-1), 2 );
+ `checkh($right (array_lt[2], dim-1), wdt+1);
+ `checkh($low (array_lt[2], dim-1), 2 );
+ `checkh($high (array_lt[2], dim-1), wdt+1);
+ `checkh($increment (array_lt[2], dim-1), -1 );
+ `checkh($size (array_lt[2], dim-1), wdt );
+ end
+`ifndef VERILATOR // Unsupported slices don\'t maintain size correctly
+\t end else if (slc==2) begin
+ // half array
+ `checkh($dimensions (array_lt[2:WA/2+1]), 3);
+ `checkh($bits (array_lt[2:WA/2+1]), WA/2*WB*WC);
+ if ((dim>=1)&&(dim<=3)) begin
+ `checkh($left (array_lt[2:WA/2+1], dim), 2 );
+ `checkh($right (array_lt[2:WA/2+1], dim), wdt+1);
+ `checkh($low (array_lt[2:WA/2+1], dim), 2 );
+ `checkh($high (array_lt[2:WA/2+1], dim), wdt+1);
+ `checkh($increment (array_lt[2:WA/2+1], dim), -1 );
+ `checkh($size (array_lt[2:WA/2+1], dim), wdt );
+ end
+`endif
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005-2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ parameter P = 32'b1000;
+
+ generate
+ case (P)
+\t32'b0: initial begin end
+\t32'b1xxx: initial begin end
+\tdefault: initial begin end
+ endcase
+ endgenerate
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003-2007 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+
+ reg [43:0] mi;
+ reg [3:0] sel2;
+ reg [0:22] backwd;
+
+ always @ (posedge clk) begin
+ mi = 44\'h123;
+ sel2 = mi[1:4];
+ $write (""Bad select %x\
+"", sel2);
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ integer j;
+ reg [63:0] cam_lookup_hit_vector;
+
+ integer hit_count;
+ always @(/*AUTOSENSE*/cam_lookup_hit_vector) begin
+ hit_count = 0;
+ for (j=0; j < 64; j=j+1) begin
+\t hit_count = hit_count + {31\'h0, cam_lookup_hit_vector[j]};
+ end
+ end
+
+ integer hit_count2;
+ always @(/*AUTOSENSE*/cam_lookup_hit_vector) begin
+ hit_count2 = 0;
+ for (j=63; j >= 0; j=j-1) begin
+\t hit_count2 = hit_count2 + {31\'h0, cam_lookup_hit_vector[j]};
+ end
+ end
+
+ integer hit_count3;
+ always @(/*AUTOSENSE*/cam_lookup_hit_vector) begin
+ hit_count3 = 0;
+ for (j=63; j > 0; j=j-1) begin
+\t if (cam_lookup_hit_vector[j]) hit_count3 = hit_count3 + 32\'d1;
+ end
+ end
+
+ reg [127:0] wide_for_index;
+ reg [31:0] wide_for_count;
+ always @(/*AUTOSENSE*/cam_lookup_hit_vector) begin
+ wide_for_count = 0;
+ for (wide_for_index = 128\'hff_00000000_00000000;
+\t wide_for_index < 128\'hff_00000000_00000100;
+\t wide_for_index = wide_for_index + 2) begin
+\t wide_for_count = wide_for_count+32\'h1;
+ end
+ end
+
+ // While loop
+ integer w;
+ initial begin
+ while (w<10) w=w+1;
+ if (w!=10) $stop;
+ while (w<20) begin w=w+2; end
+ while (w<20) begin w=w+99999; end // NEVER
+ if (w!=20) $stop;
+ end
+
+ // Do-While loop
+ integer dw;
+ initial begin
+ do dw=dw+1; while (dw<10);
+ if (dw!=10) $stop;
+ do dw=dw+2; while (dw<20);
+ if (dw!=20) $stop;
+ do dw=dw+5; while (dw<20); // Once
+ if (dw!=25) $stop;
+ end
+
+ always @ (posedge clk) begin
+ cam_lookup_hit_vector <= 0;
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t cam_lookup_hit_vector <= 64\'h00010000_00010000;
+\t end
+\t if (cyc==2) begin
+\t if (hit_count != 32\'d2) $stop;
+\t if (hit_count2 != 32\'d2) $stop;
+\t if (hit_count3 != 32\'d2) $stop;
+\t cam_lookup_hit_vector <= 64\'h01010010_00010001;
+\t end
+\t if (cyc==3) begin
+\t if (hit_count != 32\'d5) $stop;
+\t if (hit_count2 != 32\'d5) $stop;
+\t if (hit_count3 != 32\'d4) $stop;
+\t if (wide_for_count != 32\'h80) $stop;
+\t end
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ parameter PAR = 3;
+
+ input clk;
+ integer cyc=1;
+
+ reg [31:0] dly0;
+ wire [31:0] dly1;
+ wire [31:0] dly2 = dly1 + 32\'h1;
+
+ assign #(1.2000000000000000) dly1 = dly0 + 32\'h1;
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==1) begin
+\t dly0 <= #0 32\'h11;
+ end
+ else if (cyc==2) begin
+\t dly0 <= #0.12 dly0 + 32\'h12;
+ end
+ else if (cyc==3) begin
+\t if (dly0 !== 32\'h23) $stop;
+\t if (dly2 !== 32\'h25) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t #100 $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t_param_first_b (/*AUTOARG*/
+ // Outputs
+ par, varwidth
+ );
+
+ parameter X = 1;
+ parameter FIVE = 0; // Overridden
+ parameter TWO = 2;
+
+ output [4:0] \tpar;
+ output [X:0] \tvarwidth;
+
+ wire [4:0]\tpar = X;
+ wire [X:0] \tvarwidth = (FIVE==5)?TWO:0;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t ();
+
+ reg [3:0] four;
+ reg [4:0] five;
+
+ // verilator lint_save
+
+ // verilator lint_off WIDTH
+ initial four = 64'h1;
+
+ // verilator lint_restore
+
+ initial five = 64'h1;
+
+ initial $stop;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+program t;
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endprogram
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ parameter PAR = 3;
+ input clk;
+
+ m3 m3_inst (.clk(clk));
+ defparam m3_inst.FROMDEFP = 19;
+ defparam m3_inst.P2 = 2;
+ //defparam m3_inst.P3 = PAR;
+ defparam m3_inst.P3 = 3;
+
+ integer cyc=1;
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==1) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+ end
+
+endmodule
+
+module m3
+ (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ localparam LOC = 13;
+
+ parameter UNCH = 99;
+ parameter P1 = 10;
+ parameter P2 = 20;
+ parameter P3 = 30;
+
+ parameter FROMDEFP = 11;
+
+ initial begin
+ $display(""%x %x %x"",P1,P2,P3);
+ end
+ always @ (posedge clk) begin
+ if (UNCH !== 99) $stop;
+ if (P1 !== 10) $stop;
+ if (P2 !== 2) $stop;
+ if (P3 !== 3) $stop;
+ if (FROMDEFP !== 19) $stop;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t;
+
+ // width warnings off due to command line
+ wire A = 15'd1234;
+
+ // width warnings off due to command line + manual switch
+ // verilator lint_off WIDTH
+ wire B = 15'd1234;
+
+ // this turnon does nothing as off on command line
+ // verilator lint_on WIDTH
+ wire C = 15'd1234;
+
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+`include ""verilated.v""
+
+module t;
+ `verilator_file_descriptor infile, outfile;
+ integer count, a;
+
+ initial begin
+ infile = $fopen(""t/t_sys_file_scan_input.dat"", ""r"");
+ outfile = $fopen(""obj_dir/t_sys_file_scan/t_sys_file_scan_test.log"", ""w"");
+
+ count = 1234;
+`ifdef TEST_VERBOSE
+ $display(""-count == %0d, infile %d, outfile %d"", count, infile, outfile);
+`endif
+ count = $fscanf(infile, ""%d\
+"", a);
+`ifdef TEST_VERBOSE
+ // Ifdefing this out gave bug248
+ $display(""-count == %0d, infile %d, outfile %d"", count, infile, outfile);
+`endif
+ if (count == 0) $stop;
+ $fwrite(outfile, ""# a\
+"");
+ $fwrite(outfile, ""%d\
+"", a);
+ $fclose(infile);
+ $fclose(outfile);
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish(0); // Test arguments to finish
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ reg \t toggle;
+ integer cyc; initial cyc=1;
+
+ Test test (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .toggle\t\t\t(toggle),
+\t .cyc\t\t\t(cyc[31:0]));
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t toggle <= !cyc[0];
+\t if (cyc==9) begin
+\t end
+\t if (cyc==10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+module Test
+ (
+ input clk,
+ input toggle,
+ input [31:0] cyc
+ );
+
+ // Simple cover
+ cover property (@(posedge clk) cyc==3);
+
+ // With statement, in generate
+ generate if (1) begin
+ cover property (@(posedge clk) cyc==4) $display(""*COVER: Cyc==4"");
+ end
+ endgenerate
+
+ // Labeled cover
+ cyc_eq_5:
+ cover property (@(posedge clk) cyc==5) $display(""*COVER: Cyc==5"");
+
+ // Using default clock
+ default clocking @(posedge clk); endclocking
+ cover property (cyc==6) $display(""*COVER: Cyc==6"");
+
+ // Disable statement
+ // Note () after disable are required
+ cover property (@(posedge clk) disable iff (toggle) cyc==8)
+ $display(""*COVER: Cyc==8"");
+ cover property (@(posedge clk) disable iff (!toggle) cyc==8)
+ $stop;
+
+ //============================================================
+ // Using a macro and generate
+ wire reset = (cyc < 2);
+
+`define covclk(eqn) cover property (@(posedge clk) disable iff (reset) (eqn))
+
+ genvar i;
+ generate
+ for (i=0; i<32; i=i+1)
+\tbegin: cycval
+\t CycCover_i: `covclk( cyc[i] );
+\tend
+ endgenerate
+
+`ifndef verilator // Unsupported
+ //============================================================
+ // Using a more complicated property
+ property C1;
+ @(posedge clk)
+\tdisable iff (!toggle)
+\tcyc==5;
+ endproperty
+ cover property (C1) $display(""*COVER: Cyc==5"");
+
+ // Using covergroup
+ // Note a covergroup is really inheritance of a special system ""covergroup"" class.
+ covergroup counter1 @ (posedge cyc);
+ // Automatic methods: stop(), start(), sample(), set_inst_name()
+
+ // Each bin value must be <= 32 bits. Strange.
+ cyc_value : coverpoint cyc {
+\t}
+
+ cyc_bined : coverpoint cyc {
+\t bins zero = {0};
+\t bins low = {1,5};
+\t // Note 5 is also in the bin above. Only the first bin matching is counted.
+\t bins mid = {[5:$]};
+\t // illegal_bins\t// Has precidence over ""first matching bin"", creates assertion
+\t // ignore_bins\t\t// Not counted, and not part of total
+ }
+ toggle : coverpoint (toggle) {
+\t bins off = {0};
+\t bins on = {1};
+ }
+ cyc5 : coverpoint (cyc==5) {
+\t bins five = {1};
+ }
+
+ // option.at_least = {number};\t// Default 1 - Hits to be considered covered
+ // option.auto_bin_max = {number}; // Default 64
+ // option.comment = {string}
+ // option.goal = {number};\t// Default 90%
+ // option.name = {string}
+ // option.per_instance = 1;\t// Default 0 - each instance separately counted (cadence default is 1)
+ // option.weight = {number};\t// Default 1
+
+ // CROSS
+ value_and_toggle: // else default is ___X__
+\tcross cyc_value, toggle;
+ endgroup
+ counter1 c1 = new();
+`endif
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ reg [7:0] cyc; initial cyc=0;
+ reg \t set_in_task;
+
+ always @ (posedge clk) begin
+ if (cyc == 8\'d0) begin
+\t cyc <= 8\'d1;
+\t set_in_task <= 0;
+ end
+ if (cyc == 8\'d1) begin
+\t cyc <= 8\'h2;
+\t ttask;
+ end
+ if (cyc == 8\'d2) begin
+\t if (!set_in_task) $stop;
+\t cyc <= 8\'hf;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+ task ttask;
+ begin
+\t set_in_task <= 1\'b1;
+ end
+ endtask
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ integer cyc; initial cyc=1;
+
+ // verilator lint_off UNOPT
+ // verilator lint_off UNOPTFLAT
+ reg [31:0] runner; initial runner = 5;
+ reg [31:0] runnerm1;
+ reg [59:0] runnerq;
+ reg [89:0] runnerw;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+`ifdef verilator
+\t if (runner != 0) $stop; // Initial settlement failed
+`endif
+\t end
+\t if (cyc==2) begin
+\t runner = 20;
+\t runnerq = 60\'h0;
+\t runnerw = 90\'h0;
+\t end
+\t if (cyc==3) begin
+\t if (runner != 0) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+ // This forms a ""loop"" where we keep going through the always till runner=0
+ // This isn\'t ""regular"" beh code, but insures our change detection is working properly
+ always @ (/*AS*/runner) begin
+ runnerm1 = runner - 32\'d1;
+ end
+
+ always @ (/*AS*/runnerm1) begin
+ if (runner > 0) begin
+\t runner = runnerm1;
+\t runnerq = runnerq - 60\'d1;
+\t runnerw = runnerw - 90\'d1;
+\t $write (""[%0t] runner=%d\
+"", $time, runner);
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ bool
+ );
+
+ input bool;\t// BAD
+
+ reg vector;\t// OK, as not public
+ reg switch /*verilator public*/;\t// Bad
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg [9:0] index;
+ wire [7:0] index0 = index[7:0] + 8\'h0;
+ wire [7:0] index1 = index[7:0] + 8\'h1;
+ wire [7:0] index2 = index[7:0] + 8\'h2;
+ wire [7:0] index3 = index[7:0] + 8\'h3;
+ wire [7:0] index4 = index[7:0] + 8\'h4;
+ wire [7:0] index5 = index[7:0] + 8\'h5;
+ wire [7:0] index6 = index[7:0] + 8\'h6;
+ wire [7:0] index7 = index[7:0] + 8\'h7;
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [9:0]\t\touta0;\t\t\t// From s0 of t_case_huge_sub.v
+ wire [9:0]\t\touta1;\t\t\t// From s1 of t_case_huge_sub.v
+ wire [9:0]\t\touta2;\t\t\t// From s2 of t_case_huge_sub.v
+ wire [9:0]\t\touta3;\t\t\t// From s3 of t_case_huge_sub.v
+ wire [9:0]\t\touta4;\t\t\t// From s4 of t_case_huge_sub.v
+ wire [9:0]\t\touta5;\t\t\t// From s5 of t_case_huge_sub.v
+ wire [9:0]\t\touta6;\t\t\t// From s6 of t_case_huge_sub.v
+ wire [9:0]\t\touta7;\t\t\t// From s7 of t_case_huge_sub.v
+ wire [1:0]\t\toutb0;\t\t\t// From s0 of t_case_huge_sub.v
+ wire [1:0]\t\toutb1;\t\t\t// From s1 of t_case_huge_sub.v
+ wire [1:0]\t\toutb2;\t\t\t// From s2 of t_case_huge_sub.v
+ wire [1:0]\t\toutb3;\t\t\t// From s3 of t_case_huge_sub.v
+ wire [1:0]\t\toutb4;\t\t\t// From s4 of t_case_huge_sub.v
+ wire [1:0]\t\toutb5;\t\t\t// From s5 of t_case_huge_sub.v
+ wire [1:0]\t\toutb6;\t\t\t// From s6 of t_case_huge_sub.v
+ wire [1:0]\t\toutb7;\t\t\t// From s7 of t_case_huge_sub.v
+ wire\t\t\toutc0;\t\t\t// From s0 of t_case_huge_sub.v
+ wire\t\t\toutc1;\t\t\t// From s1 of t_case_huge_sub.v
+ wire\t\t\toutc2;\t\t\t// From s2 of t_case_huge_sub.v
+ wire\t\t\toutc3;\t\t\t// From s3 of t_case_huge_sub.v
+ wire\t\t\toutc4;\t\t\t// From s4 of t_case_huge_sub.v
+ wire\t\t\toutc5;\t\t\t// From s5 of t_case_huge_sub.v
+ wire\t\t\toutc6;\t\t\t// From s6 of t_case_huge_sub.v
+ wire\t\t\toutc7;\t\t\t// From s7 of t_case_huge_sub.v
+ wire [9:0]\t\toutq;\t\t\t// From q of t_case_huge_sub4.v
+ wire [3:0]\t\toutr;\t\t\t// From sub3 of t_case_huge_sub3.v
+ wire [9:0]\t\toutsmall;\t\t// From sub2 of t_case_huge_sub2.v
+ // End of automatics
+
+ t_case_huge_sub2 sub2 (
+\t\t\t // Outputs
+\t\t\t .outa\t\t(outsmall[9:0]),
+\t\t\t /*AUTOINST*/
+\t\t\t // Inputs
+\t\t\t .index\t(index[9:0]));
+
+ t_case_huge_sub3 sub3 (/*AUTOINST*/
+\t\t\t // Outputs
+\t\t\t .outr\t\t(outr[3:0]),
+\t\t\t // Inputs
+\t\t\t .clk\t\t(clk),
+\t\t\t .index\t(index[9:0]));
+
+ /* t_case_huge_sub AUTO_TEMPLATE (
+\t\t .outa\t\t(outa@[]),
+\t\t .outb\t\t(outb@[]),
+\t\t .outc\t\t(outc@[]),
+\t\t .index\t\t(index@[]));
+ */
+
+ t_case_huge_sub s0 (/*AUTOINST*/
+\t\t // Outputs
+\t\t .outa\t\t(outa0[9:0]),\t\t // Templated
+\t\t .outb\t\t(outb0[1:0]),\t\t // Templated
+\t\t .outc\t\t(outc0),\t\t // Templated
+\t\t // Inputs
+\t\t .index\t\t(index0[7:0]));\t\t // Templated
+ t_case_huge_sub s1 (/*AUTOINST*/
+\t\t // Outputs
+\t\t .outa\t\t(outa1[9:0]),\t\t // Templated
+\t\t .outb\t\t(outb1[1:0]),\t\t // Templated
+\t\t .outc\t\t(outc1),\t\t // Templated
+\t\t // Inputs
+\t\t .index\t\t(index1[7:0]));\t\t // Templated
+ t_case_huge_sub s2 (/*AUTOINST*/
+\t\t // Outputs
+\t\t .outa\t\t(outa2[9:0]),\t\t // Templated
+\t\t .outb\t\t(outb2[1:0]),\t\t // Templated
+\t\t .outc\t\t(outc2),\t\t // Templated
+\t\t // Inputs
+\t\t .index\t\t(index2[7:0]));\t\t // Templated
+ t_case_huge_sub s3 (/*AUTOINST*/
+\t\t // Outputs
+\t\t .outa\t\t(outa3[9:0]),\t\t // Templated
+\t\t .outb\t\t(outb3[1:0]),\t\t // Templated
+\t\t .outc\t\t(outc3),\t\t // Templated
+\t\t // Inputs
+\t\t .index\t\t(index3[7:0]));\t\t // Templated
+ t_case_huge_sub s4 (/*AUTOINST*/
+\t\t // Outputs
+\t\t .outa\t\t(outa4[9:0]),\t\t // Templated
+\t\t .outb\t\t(outb4[1:0]),\t\t // Templated
+\t\t .outc\t\t(outc4),\t\t // Templated
+\t\t // Inputs
+\t\t .index\t\t(index4[7:0]));\t\t // Templated
+ t_case_huge_sub s5 (/*AUTOINST*/
+\t\t // Outputs
+\t\t .outa\t\t(outa5[9:0]),\t\t // Templated
+\t\t .outb\t\t(outb5[1:0]),\t\t // Templated
+\t\t .outc\t\t(outc5),\t\t // Templated
+\t\t // Inputs
+\t\t .index\t\t(index5[7:0]));\t\t // Templated
+ t_case_huge_sub s6 (/*AUTOINST*/
+\t\t // Outputs
+\t\t .outa\t\t(outa6[9:0]),\t\t // Templated
+\t\t .outb\t\t(outb6[1:0]),\t\t // Templated
+\t\t .outc\t\t(outc6),\t\t // Templated
+\t\t // Inputs
+\t\t .index\t\t(index6[7:0]));\t\t // Templated
+ t_case_huge_sub s7 (/*AUTOINST*/
+\t\t // Outputs
+\t\t .outa\t\t(outa7[9:0]),\t\t // Templated
+\t\t .outb\t\t(outb7[1:0]),\t\t // Templated
+\t\t .outc\t\t(outc7),\t\t // Templated
+\t\t // Inputs
+\t\t .index\t\t(index7[7:0]));\t\t // Templated
+
+ t_case_huge_sub4 q (/*AUTOINST*/
+\t\t // Outputs
+\t\t .outq\t\t(outq[9:0]),
+\t\t // Inputs
+\t\t .index\t\t(index[7:0]));
+
+
+ integer cyc; initial cyc=1;
+ initial index = 10\'h0;
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t //$write(""%x: %x\
+"",cyc,outr);
+\t //$write(""%x: %x %x %x %x\
+"", cyc, outa1,outb1,outc1,index1);
+\t if (cyc==1) begin
+\t index <= 10\'h236;
+\t end
+\t if (cyc==2) begin
+\t index <= 10\'h022;
+\t if (outsmall != 10\'h282) $stop;
+\t if (outr != 4\'b0) $stop;
+\t if ({outa0,outb0,outc0}!={10\'h282,2\'d3,1\'b0}) $stop;
+\t if ({outa1,outb1,outc1}!={10\'h21c,2\'d3,1\'b1}) $stop;
+\t if ({outa2,outb2,outc2}!={10\'h148,2\'d0,1\'b1}) $stop;
+\t if ({outa3,outb3,outc3}!={10\'h3c0,2\'d2,1\'b0}) $stop;
+\t if ({outa4,outb4,outc4}!={10\'h176,2\'d1,1\'b1}) $stop;
+\t if ({outa5,outb5,outc5}!={10\'h3fc,2\'d2,1\'b1}) $stop;
+\t if ({outa6,outb6,outc6}!={10\'h295,2\'d3,1\'b1}) $stop;
+\t if ({outa7,outb7,outc7}!={10\'h113,2\'d2,1\'b1}) $stop;
+\t if (outq != 10\'h001) $stop;
+\t end
+\t if (cyc==3) begin
+\t index <= 10\'h165;
+\t if (outsmall != 10\'h191) $stop;
+\t if (outr != 4\'h5) $stop;
+\t if ({outa1,outb1,outc1}!={10\'h379,2\'d1,1\'b0}) $stop;
+\t if ({outa2,outb2,outc2}!={10\'h073,2\'d0,1\'b0}) $stop;
+\t if ({outa3,outb3,outc3}!={10\'h2fd,2\'d3,1\'b1}) $stop;
+\t if ({outa4,outb4,outc4}!={10\'h2e0,2\'d3,1\'b1}) $stop;
+\t if ({outa5,outb5,outc5}!={10\'h337,2\'d1,1\'b1}) $stop;
+\t if ({outa6,outb6,outc6}!={10\'h2c7,2\'d3,1\'b1}) $stop;
+\t if ({outa7,outb7,outc7}!={10\'h19e,2\'d3,1\'b0}) $stop;
+\t if (outq != 10\'h001) $stop;
+\t end
+\t if (cyc==4) begin
+\t index <= 10\'h201;
+\t if (outsmall != 10\'h268) $stop;
+\t if (outr != 4\'h2) $stop;
+\t if ({outa1,outb1,outc1}!={10\'h111,2\'d1,1\'b0}) $stop;
+\t if ({outa2,outb2,outc2}!={10\'h1f9,2\'d0,1\'b0}) $stop;
+\t if ({outa3,outb3,outc3}!={10\'h232,2\'d0,1\'b1}) $stop;
+\t if ({outa4,outb4,outc4}!={10\'h255,2\'d3,1\'b0}) $stop;
+\t if ({outa5,outb5,outc5}!={10\'h34c,2\'d1,1\'b1}) $stop;
+\t if ({outa6,outb6,outc6}!={10\'h049,2\'d1,1\'b1}) $stop;
+\t if ({outa7,outb7,outc7}!={10\'h197,2\'d3,1\'b0}) $stop;
+\t if (outq != 10\'h001) $stop;
+\t end
+\t if (cyc==5) begin
+\t index <= 10\'h3ff;
+\t if (outr != 4\'hd) $stop;
+\t if (outq != 10\'h001) $stop;
+\t end
+\t if (cyc==6) begin
+\t index <= 10\'h0;
+\t if (outr != 4\'hd) $stop;
+\t if (outq != 10\'h114) $stop;
+\t end
+\t if (cyc==7) begin
+\t if (outr != 4\'h4) $stop;
+\t end
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t;
+
+ reg [175:0] hex [15:0];
+
+ initial begin
+ $readmemb(""t/t_sys_readmem_bad_digit.mem"", hex);
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); fail=\'1; end while(0)
+`define checkf(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=%f exp=%f\
+"", `__FILE__,`__LINE__, (gotv), (expv)); fail=\'1; end while(0)
+
+module t (/*AUTOARG*/);
+
+ bit fail;
+
+ localparam signed [3:0] bug737_p1 = 4\'b1000;
+
+ wire [3:0] bug737_a = 4\'b1010;
+ reg [5:0] bug737_y;
+ reg signed [3:0] w4_s;
+ reg signed [4:0] w5_s;
+ reg [3:0] w4_u;
+ reg [4:0] w5_u;
+ reg signed [8:0] w9_s;
+ real r;
+ initial begin
+ // verilator lint_off WIDTH
+ bug737_y = bug737_a + (bug737_p1 + 4\'sb0);
+ `checkh(bug737_y, 6\'b010010); //bug737
+
+ // 6u +[6u] 4s +[6s] 6s
+ bug737_y = 6\'b001010 + (4\'sb1000 + 6\'sb0);
+ `checkh(bug737_y, 6\'b010010); //bug737, getx 000010
+
+ // 6u +[6u] 4s +[6s] 6s
+ bug737_y = 6\'b001010 + (4\'b1000 + 6\'sb0);
+ `checkh(bug737_y, 6\'b010010); //ok
+
+ bug737_y = 6\'b001010 + (6\'sb111000 + 6\'sb0);
+ `checkh(bug737_y, 6\'b000010); //ok
+
+ // v--- sign extends to 6-bits
+ bug737_y = 6\'sb001010 + (4\'sb1000 + 6\'sb0);
+ `checkh(bug737_y, 6\'b000010); //ok
+
+ // From t_math_signed_3
+ w4_s = 4\'sb1111 - 1\'b1;
+ `checkh(w4_s,33\'he);
+
+ w4_s = 4\'sb1111 - 5\'b00001;
+ `checkh(w4_s,33\'he);
+
+ w4_s = 4\'sb1111 - 1\'sb1;
+ `checkh(w4_s,4\'h0);
+ w5_s = 4\'sb1111 - 1\'sb1;
+ `checkh(w5_s,4\'h0);
+
+ w4_s = 4\'sb1111 - 4\'sb1111;
+ `checkh(w4_s,4\'h0);
+ w5_s = 4\'sb1111 - 4\'sb1111;
+ `checkh(w5_s,5\'h0);
+
+ // The assign LHS being signed or unsigned does not matter per IEEE
+ // The upper add being signed DOES matter propagating to lower
+ w4_s = 4\'sb1111 - (1\'sb1 + 4\'b0); //1\'sb1 not extended as unsigned add
+ `checkh(w4_s,4\'he);
+ w4_s = 4\'sb1111 - (1\'sb1 + 4\'sb0); //1\'sb1 does sign extend
+ `checkh(w4_s,4\'h0);
+ w4_s = 4\'b1111 - (1\'sb1 + 4\'sb0); //1\'sb1 does *NOT* sign extend
+ `checkh(w4_s,4\'he); // BUG, Verilator says \'h0
+
+ w5_u = 4\'b1111 + 4\'b0001; // Extends to 5 bits due to LHS
+ `checkh(w5_u, 5\'b10000);
+ w4_u = 4\'b1111 + 4\'b0001; // Normal case
+ `checkh(w4_u, 4\'b0000);
+
+ // Another example of promotion, the add is 4 bits wide
+ w4_u = 3\'b111 + 3\'b010;
+ `checkh(w4_u, 4\'b1001);
+ //
+ w4_u = 3\'sb111 * 3\'sb001; // Signed output, LHS does not matter
+ `checkh(w4_u, 4\'sb1111);
+ w4_s = 3\'sb111 * 3\'sb001; // Signed output
+ `checkh(w4_s, 4\'sb1111);
+ w4_s = 3\'b111 * 3\'sb001; // Unsigned output
+ `checkh(w4_s, 4\'b0111);
+
+ // Conditionals get width from parent; are assignment-like
+ w4_u = 1\'b0 ? 4\'b0 : (2\'b01+2\'b11);
+ `checkh(w4_u, 4\'b0100);
+ w4_u = 1\'b0 ? 4\'b0 : (6\'b001000+6\'b001000);
+ `checkh(w4_u, 4\'b0000);
+
+ // If RHS is larger, that larger size is used
+ w4_u = 5\'b10000 / 5\'b00100;
+ `checkh(w4_u, 4\'b0100);
+
+ // bug754
+ w5_u = 4\'sb0010 << -2\'sd1; // << 3
+`ifdef VCS
+ `checkh(w5_u, 5\'b00000); // VCS E-2014.03 bug
+`else
+ `checkh(w5_u, 5\'b10000); // VCS E-2014.03 bug
+`endif
+ w5_u = 4\'sb1000 << 0; // Sign extends
+ `checkh(w5_u, 5\'b11000);
+
+ // Reals do not propagate to children
+ r = 1.0 + ( 1 + (1 / 2));
+ `checkf(r, 2.0);
+
+ // Self determined sign extension
+ r = $itor(3\'sb111);
+ `checkf(r, -1.0);
+
+ // If any part of case is real, all is real
+ case (22)
+\t22.0: ;
+\t22.1: $stop;
+\tdefault: $stop;
+ endcase
+
+ // bug759
+ w5_u = { -4\'sd7 };
+ `checkh(w5_u, 5\'b01001);
+ w5_u = {2{ -2\'sd1 }};
+ `checkh(w5_u, 5\'b01111);
+ // Don\'t break concats....
+ w5_u = {{0{1\'b1}}, -4\'sd7 };
+ `checkh(w5_u, 5\'b01001);
+ w9_s = { -4\'sd7, -4\'sd7 };
+ `checkh(w9_s, 9\'b010011001);
+ {w5_u, {w4_u}} = 9\'b10101_1100;
+ `checkh(w5_u, 5\'b10101);
+ `checkh(w4_u, 4\'b1100);
+ {w4_u} = 4\'b1011;
+ `checkh(w4_u, 4\'b1011);
+
+ if (fail) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+//bug456
+
+typedef logic signed [34:0] rc_t;
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [34:0] rc = crc[34:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ logic\t\to;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .o\t\t\t(o),
+\t // Inputs
+\t .rc\t\t\t(rc),
+\t .clk\t\t\t(clk));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {63\'h0, o};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h7211d24a17b25ec9
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test( output logic o,
+ input \t rc_t rc,
+ input logic clk);
+
+ localparam RATIO = 2;
+
+ rc_t rc_d[RATIO:1];
+
+ always_ff @(posedge clk) begin
+ integer k;
+
+ rc_d[1] <= rc;
+
+ for( k=2; k> 33 {in}};
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Alex Solomatnikov.
+
+//bug595
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ logic [6-1:0] foo; initial foo = 20;
+
+ dut #(.W(6)) udut(.clk(clk),
+ .foo(foo-16));
+endmodule
+
+module dut
+ #(parameter W = 1)
+ (input logic clk,
+ input logic [W-1:0] foo);
+
+ genvar i;
+ generate
+ for (i = 0; i < W; i++) begin
+ suba ua(.clk(clk), .foo(foo[i]));
+ end
+ endgenerate
+endmodule
+
+module suba
+ (input logic clk,
+ input logic foo);
+
+ always @(posedge clk) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+`ifdef verilator
+ `define CLOG2 $clog2
+`else
+ `define CLOG2 clog2_emulate
+`endif
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Need temp wires as function has different width rules than $clog2
+ wire [127:0] pows = 128\'h1<> 1);
+ end
+ endfunction
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+`ifdef INLINE_A //verilator inline_module
+`else //verilator no_inline_module
+`endif
+
+ bmod bsub3 (.clk, .n(3));
+ bmod bsub2 (.clk, .n(2));
+ bmod bsub1 (.clk, .n(1));
+ bmod bsub0 (.clk, .n(0));
+endmodule
+
+module bmod
+ (input clk,
+ input [31:0] n);
+
+`ifdef INLINE_B //verilator inline_module
+`else //verilator no_inline_module
+`endif
+
+ cmod csub (.clk, .n);
+
+endmodule
+
+module cmod
+ (input clk, input [31:0] n);
+
+`ifdef INLINE_C //verilator inline_module
+`else //verilator no_inline_module
+`endif
+
+ reg [31:0] clocal;
+ always @ (posedge clk) clocal <= n;
+
+ dmod dsub (.clk, .n);
+endmodule
+
+module dmod (input clk, input [31:0] n);
+
+`ifdef INLINE_D //verilator inline_module
+`else //verilator no_inline_module
+`endif
+
+ reg [31:0] dlocal;
+ always @ (posedge clk) dlocal <= n;
+
+ int \t cyc;
+ always @(posedge clk) begin
+ cyc <= cyc+1;
+ end
+ always @(posedge clk) begin
+ if (cyc>10) begin
+`ifdef TEST_VERBOSE $display(""%m: csub.clocal=%0d dlocal=%0d"", csub.clocal, dlocal); `endif
+\t if (csub.clocal !== n) $stop;
+\t if (dlocal !== n) $stop;
+ end
+ if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Non-cutable edge in loop
+//
+// This code (stripped down from a much larger application) has a loop between
+// the use of ready in the first two always blocks. However it should
+// trivially trigger the $write on the first clk posedge.
+//
+// This is a regression test against issue 513.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Jeremy Bennett.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ reg \t ready;
+
+ initial begin
+ ready = 1\'b0;
+ end
+
+ always @(posedge ready) begin
+ if ((ready === 1\'b1)) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+ always @(posedge ready) begin
+ if ((ready === 1\'b0)) begin
+ ready = 1\'b1 ;
+ end
+ end
+
+ always @(posedge clk) begin
+ ready = 1\'b1;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator Test: Top level main for invoking model
+//
+// Copyright 2003-2015 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+module sim_main;
+ /*verilator public_module*/
+
+ reg clk;
+ reg check;
+ wire done;
+
+ vgen vgen (/*AUTOINST*/
+\t // Outputs
+\t .done\t\t\t(done),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .check\t\t\t(check));
+
+ integer i;
+
+ initial begin
+ check = 1'b0;
+ clk = 1'b0;
+ for (i=0; i<10*vgen.CYCLES; i=i+1) begin
+\t #5;
+\t clk = ~clk;
+\t #5;
+\t clk = ~clk;
+ end
+ check = 1'b1;
+ for (i=0; i<10; i=i+1) begin
+\t #5;
+\t clk = ~clk;
+\t #5;
+\t clk = ~clk;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t;
+
+`define UDALL
+`ifndef PREDEF_COMMAND_LINE `error ""Test setup error, PREDEF_COMMAND_LINE pre-missing"" `endif
+
+`undefineall
+
+`ifdef UDALL `error ""undefineall failed"" `endif
+`ifndef PREDEF_COMMAND_LINE `error ""Deleted too much, no PREDEF_COMMAND_LINE"" `endif
+
+ initial begin
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ typedef struct packed { bit m; } struct_t;
+ struct_t s;
+
+ initial begin
+ s.nfmember = 0; // Member not found
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Glen Gibb.
+
+//module t;
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+
+ // The \'initial\' code block below tests compilation-time
+ // evaluation/optimization of the stream operator. All occurences of the stream
+ // operator within this block are replaced prior to generation of C code.
+ logic [3:0] dout;
+ logic [31:0] dout32;
+ logic [10:0] dout11;
+
+ initial begin
+
+ // Stream operator: <<
+ // Location: rhs of assignment
+ //
+ // Test slice sizes from 1 - 5
+ dout = { << {4\'b0001}}; if (dout != 4\'b1000) $stop;
+ dout = { << 2 {4\'b0001}}; if (dout != 4\'b0100) $stop;
+ dout = { << 3 {4\'b0001}}; if (dout != 4\'b0010) $stop;
+ dout = { << 4 {4\'b0001}}; if (dout != 4\'b0001) $stop;
+ dout = { << 5 {4\'b0001}}; if (dout != 4\'b0001) $stop;
+
+ // Stream operator: >>
+ // Location: rhs of assignment
+ //
+ // Right-streaming operator on RHS does not reorder bits
+ dout = { >> {4\'b0001}}; if (dout != 4\'b0001) $stop;
+ dout = { >> 2 {4\'b0001}}; if (dout != 4\'b0001) $stop;
+ dout = { >> 3 {4\'b0001}}; if (dout != 4\'b0001) $stop;
+ dout = { >> 4 {4\'b0001}}; if (dout != 4\'b0001) $stop;
+ dout = { >> 5 {4\'b0001}}; if (dout != 4\'b0001) $stop;
+
+ // Stream operator: <<
+ // Location: lhs of assignment
+ { << {dout}} = 4\'b0001; if (dout != 4\'b1000) $stop;
+ { << 2 {dout}} = 4\'b0001; if (dout != 4\'b0100) $stop;
+ { << 3 {dout}} = 4\'b0001; if (dout != 4\'b0010) $stop;
+ { << 4 {dout}} = 4\'b0001; if (dout != 4\'b0001) $stop;
+ { << 5 {dout}} = 4\'b0001; if (dout != 4\'b0001) $stop;
+
+ // Stream operator: >>
+ // Location: lhs of assignment
+ { >> {dout}} = 4\'b0001; if (dout != 4\'b0001) $stop;
+ { >> 2 {dout}} = 4\'b0001; if (dout != 4\'b0001) $stop;
+ { >> 3 {dout}} = 4\'b0001; if (dout != 4\'b0001) $stop;
+ { >> 4 {dout}} = 4\'b0001; if (dout != 4\'b0001) $stop;
+ { >> 5 {dout}} = 4\'b0001; if (dout != 4\'b0001) $stop;
+
+ // Stream operator: <<
+ // Location: lhs of assignment
+ // RHS is *wider* than LHS
+ /* verilator lint_off WIDTH */
+ { << {dout}} = 5\'b00001; if (dout != 4\'b1000) $stop;
+ { << 2 {dout}} = 5\'b00001; if (dout != 4\'b0100) $stop;
+ { << 3 {dout}} = 5\'b00001; if (dout != 4\'b0010) $stop;
+ { << 4 {dout}} = 5\'b00001; if (dout != 4\'b0001) $stop;
+ { << 5 {dout}} = 5\'b01101; if (dout != 4\'b0110) $stop;
+ /* verilator lint_on WIDTH */
+
+ // Stream operator: >>
+ // Location: lhs of assignment
+ // RHS is *wider* than LHS
+ /* verilator lint_off WIDTH */
+ { >> {dout}} = 5\'b01101; if (dout != 4\'b0110) $stop;
+ { >> 2 {dout}} = 5\'b01101; if (dout != 4\'b0110) $stop;
+ { >> 3 {dout}} = 5\'b01101; if (dout != 4\'b0110) $stop;
+ { >> 4 {dout}} = 5\'b01101; if (dout != 4\'b0110) $stop;
+ { >> 5 {dout}} = 5\'b01101; if (dout != 4\'b0110) $stop;
+ /* verilator lint_on WIDTH */
+
+ // Stream operator: <<
+ // Location: both sides of assignment
+ { << {dout}} = { << {4\'b0001}}; if (dout != 4\'b0001) $stop;
+ { << 2 {dout}} = { << 2 {4\'b0001}}; if (dout != 4\'b0001) $stop;
+ { << 3 {dout}} = { << 3 {4\'b0001}}; if (dout != 4\'b0100) $stop;
+ { << 4 {dout}} = { << 4 {4\'b0001}}; if (dout != 4\'b0001) $stop;
+ { << 5 {dout}} = { << 5 {4\'b0001}}; if (dout != 4\'b0001) $stop;
+
+ // Stream operator: <<
+ // Location: as an operand within a statement
+ //
+ // Test slice sizes from 1 - 5
+ if (4\'({ << {4\'b0001}}) != 4\'b1000) $stop;
+ if (4\'({ << 2 {4\'b0001}}) != 4\'b0100) $stop;
+ if (4\'({ << 3 {4\'b0001}}) != 4\'b0010) $stop;
+ if (4\'({ << 4 {4\'b0001}}) != 4\'b0001) $stop;
+ if (4\'({ << 5 {4\'b0001}}) != 4\'b0001) $stop;
+
+ // case\t\t\t\t\t
+ dout32 = { << 3 { 32\'b11010111000010100100010010010111 }}; if (dout32 != 32\'he92910eb) $stop;
+ dout11 = { << 4 { 11\'b10010010111 }}; if (dout11 != 11\'h3cc) $stop;
+ end
+
+
+ // The two always blocks below test run-time evaluation of the stream
+ // operator in generated C code.
+ //
+ // Various stream operators are optimized away. Here\'s a brief summary:
+ //
+ // Stream op on RHS of assign
+ // --------------------------
+ // X = { << a { Y } } --- C function evaluates stream operator
+ // -- if log2(a) == int --> ""fast"" eval func
+ // -- if log2(a) != int --> ""slow"" eval func
+ // X = { >> a { Y } } --- stream operator is optimized away
+ //
+ // Stream op on LHS of assign
+ // --------------------------
+ // Note: if Y.width() > X.width, then the MSBs of Y are used, not the LSBs!
+ // { << a { X } } = Y --- stream operator is moved to RHS, eval as above
+ // { >> a { X } } = Y --- stream operator is optimized away
+
+ logic [31:0] din_i;
+ logic [63:0] din_q;
+ logic [95:0] din_w;
+
+ // Stream op on RHS, left-stream operator
+ logic [31:0] dout_rhs_ls_i;
+ logic [63:0] dout_rhs_ls_q;
+ logic [95:0] dout_rhs_ls_w;
+
+ // Stream op on RHS, right-stream operator
+ logic [31:0] dout_rhs_rs_i;
+ logic [63:0] dout_rhs_rs_q;
+ logic [95:0] dout_rhs_rs_w;
+
+ // Stream op on both sides, left-stream operator
+ logic [31:0] dout_bhs_ls_i;
+ logic [63:0] dout_bhs_ls_q;
+ logic [95:0] dout_bhs_ls_w;
+
+ // Stream op on both sides, right-stream operator
+ logic [31:0] dout_bhs_rs_i;
+ logic [63:0] dout_bhs_rs_q;
+ logic [95:0] dout_bhs_rs_w;
+
+ // Stream operator on LHS (with concatenation on LHS)
+ logic [3:0] din_lhs;
+ logic [1:0] dout_lhs_ls_a, dout_lhs_ls_b;
+ logic [1:0] dout_lhs_rs_a, dout_lhs_rs_b;
+
+ // Addition operator on LHS, right-shift tests:
+ // Testing various shift sizes to exercise fast + slow funcs
+ logic [22:0] dout_rhs_ls_i_23_3;
+ logic [22:0] dout_rhs_ls_i_23_4;
+
+ logic [36:0] dout_rhs_ls_q_37_3;
+ logic [36:0] dout_rhs_ls_q_37_4;
+
+ always @*
+ begin
+ // Stream operator: <<
+ // Location: rhs of assignment
+ //
+ // Test each data type (I, Q, W)
+ dout_rhs_ls_i = { << {din_i}};
+ dout_rhs_ls_q = { << {din_q}};
+ dout_rhs_ls_w = { << {din_w}};
+
+ // Stream operator: >>
+ // Location: rhs of assignment
+ dout_rhs_rs_i = { >> {din_i}};
+ dout_rhs_rs_q = { >> {din_q}};
+ dout_rhs_rs_w = { >> {din_w}};
+
+ // Stream operator: <<
+ // Location: lhs of assignment
+ { << 2 {dout_lhs_ls_a, dout_lhs_ls_b}} = din_lhs;
+
+ // Stream operator: >>
+ // Location: lhs of assignment
+ { >> 2 {dout_lhs_rs_a, dout_lhs_rs_b}} = din_lhs;
+
+ // Stream operator: <<
+ // Location: both sides of assignment
+ { << 5 {dout_bhs_ls_i}} = { << 5 {din_i}};
+ { << 5 {dout_bhs_ls_q}} = { << 5 {din_q}};
+ { << 5 {dout_bhs_ls_w}} = { << 5 {din_w}};
+
+ // Stream operator: >>
+ // Location: both sides of assignment
+ { >> 5 {dout_bhs_rs_i}} = { >> 5 {din_i}};
+ { >> 5 {dout_bhs_rs_q}} = { >> 5 {din_q}};
+ { >> 5 {dout_bhs_rs_w}} = { >> 5 {din_w}};
+
+ // Stream operator: <<
+ // Location: both sides of assignment
+ { << 5 {dout_bhs_ls_i}} = { << 5 {din_i}};
+ { << 5 {dout_bhs_ls_q}} = { << 5 {din_q}};
+ { << 5 {dout_bhs_ls_w}} = { << 5 {din_w}};
+
+ // Stream operator: <<
+ // Location: rhs of assignment
+ //
+ // Verify both fast and slow paths (fast: sliceSize = power of 2)
+ dout_rhs_ls_i_23_3 = { << 3 {din_i[22:0]}}; // SLOW
+ dout_rhs_ls_i_23_4 = { << 4 {din_i[22:0]}}; // FAST
+
+ dout_rhs_ls_q_37_3 = { << 3 {din_q[36:0]}}; // SLOW
+ dout_rhs_ls_q_37_4 = { << 4 {din_q[36:0]}}; // FAST
+ end
+
+ always @(posedge clk)
+ begin
+ if (cyc != 0) begin
+ cyc <= cyc + 1;
+
+ if (cyc == 1) begin
+ din_i <= 32\'h_00_00_00_01;
+ din_q <= 64\'h_00_00_00_00_00_00_00_01;
+ din_w <= 96\'h_00_00_00_00_00_00_00_00_00_00_00_01;
+
+ din_lhs <= 4\'b_00_01;
+ end
+ if (cyc == 2) begin
+ din_i <= 32\'h_04_03_02_01;
+ din_q <= 64\'h_08_07_06_05_04_03_02_01;
+ din_w <= 96\'h_0c_0b_0a_09_08_07_06_05_04_03_02_01;
+
+ din_lhs <= 4\'b_01_11;
+
+\t if (dout_rhs_ls_i != 32\'h_80_00_00_00) $stop;
+\t if (dout_rhs_ls_q != 64\'h_80_00_00_00_00_00_00_00) $stop;
+\t if (dout_rhs_ls_w != 96\'h_80_00_00_00_00_00_00_00_00_00_00_00) $stop;
+
+ if (dout_rhs_rs_i != 32\'h_00_00_00_01) $stop;
+ if (dout_rhs_rs_q != 64\'h_00_00_00_00_00_00_00_01) $stop;
+ if (dout_rhs_rs_w != 96\'h_00_00_00_00_00_00_00_00_00_00_00_01) $stop;
+
+\t if (dout_lhs_ls_a != 2\'b_01) $stop;
+\t if (dout_lhs_ls_b != 2\'b_00) $stop;
+
+\t if (dout_lhs_rs_a != 2\'b_00) $stop;
+\t if (dout_lhs_rs_b != 2\'b_01) $stop;
+
+\t if (dout_bhs_rs_i != 32\'h_00_00_00_01) $stop;
+\t if (dout_bhs_rs_q != 64\'h_00_00_00_00_00_00_00_01) $stop;
+\t if (dout_bhs_rs_w != 96\'h_00_00_00_00_00_00_00_00_00_00_00_01) $stop;
+
+\t if (dout_bhs_ls_i != 32\'h_00_00_00_10) $stop;
+\t if (dout_bhs_ls_q != 64\'h_00_00_00_00_00_00_01_00) $stop;
+\t if (dout_bhs_ls_w != 96\'h_00_00_00_00_00_00_00_00_00_00_00_04) $stop;
+
+\t if (dout_rhs_ls_i_23_3 != 23\'h_10_00_00) $stop;
+\t if (dout_rhs_ls_i_23_4 != 23\'h_08_00_00) $stop;
+
+\t if (dout_rhs_ls_q_37_3 != 37\'h_04_00_00_00_00) $stop;
+\t if (dout_rhs_ls_q_37_4 != 37\'h_02_00_00_00_00) $stop;
+ end
+ if (cyc == 3) begin
+\t // The values below test the strange shift-merge done at the end of
+\t // the fast stream operators.
+\t // All-1s in the bits being streamed should end up as all-1s.
+\t din_i <= 32\'h_00_7f_ff_ff;
+\t din_q <= 64\'h_00_00_00_1f_ff_ff_ff_ff;
+
+\t if (dout_rhs_ls_i != 32\'h_80_40_c0_20) $stop;
+\t if (dout_rhs_ls_q != 64\'h_80_40_c0_20_a0_60_e0_10) $stop;
+\t if (dout_rhs_ls_w != 96\'h_80_40_c0_20_a0_60_e0_10_90_50_d0_30) $stop;
+
+ if (dout_rhs_rs_i != 32\'h_04_03_02_01) $stop;
+ if (dout_rhs_rs_q != 64\'h_08_07_06_05_04_03_02_01) $stop;
+ if (dout_rhs_rs_w != 96\'h_0c_0b_0a_09_08_07_06_05_04_03_02_01) $stop;
+
+\t if (dout_bhs_ls_i != 32\'h_40_30_00_18) $stop;
+\t if (dout_bhs_ls_q != 64\'h_06_00_c1_81_41_00_c1_80) $stop;
+\t if (dout_bhs_ls_w != 96\'h_30_2c_28_20_01_1c_1a_04_14_0c_00_06) $stop;
+
+\t if (dout_bhs_rs_i != 32\'h_04_03_02_01) $stop;
+\t if (dout_bhs_rs_q != 64\'h_08_07_06_05_04_03_02_01) $stop;
+\t if (dout_bhs_rs_w != 96\'h_0c_0b_0a_09_08_07_06_05_04_03_02_01) $stop;
+
+\t if (dout_lhs_ls_a != 2\'b_11) $stop;
+\t if (dout_lhs_ls_b != 2\'b_01) $stop;
+
+\t if (dout_lhs_rs_a != 2\'b_01) $stop;
+\t if (dout_lhs_rs_b != 2\'b_11) $stop;
+
+\t if (dout_rhs_ls_i_23_3 != 23\'h_10_08_c0) $stop;
+\t if (dout_rhs_ls_i_23_4 != 23\'h_08_10_18) $stop;
+
+\t if (dout_rhs_ls_q_37_3 != 37\'h_04_02_30_10_44) $stop;
+\t if (dout_rhs_ls_q_37_4 != 37\'h_02_04_06_08_0a) $stop;
+ end
+\t if (cyc == 4) begin
+\t if (dout_rhs_ls_i_23_3 != 23\'h_7f_ff_ff) $stop;
+\t if (dout_rhs_ls_i_23_4 != 23\'h_7f_ff_ff) $stop;
+
+\t if (dout_rhs_ls_q_37_3 != 37\'h_1f_ff_ff_ff_ff) $stop;
+\t if (dout_rhs_ls_q_37_4 != 37\'h_1f_ff_ff_ff_ff) $stop;
+\t end
+ if (cyc == 9) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+//bug 762
+module t(a0, y);
+ input [3:0] a0;
+ output [44:0] y;
+
+ assign y[40] = 0;
+ assign y[30] = 0;
+ // verilator lint_off UNOPTFLAT
+ assign { y[44:41], y[39:31], y[29:0] } = { 6'b000000, a0, 7'b0000000, y[40], y[30], y[30], y[30], y[30], 21'b000000000000000000000 };
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2012 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+module t (/*AUTOARG*/);
+
+`define ASSERT(x) initial if (!(x)) $stop
+ // See IEEE 6.20.2 on value parameters
+
+ localparam unsigned [63:0] UNSIGNED =64\'h99934567_89abcdef;
+ localparam signed [63:0] SIGNED =64\'sh99934567_89abcdef;
+ localparam real REAL=1.234;
+ `ASSERT(UNSIGNED > 0);
+ `ASSERT(SIGNED < 0);
+
+ // bullet 1
+ localparam A1_WIDE = UNSIGNED;
+ `ASSERT($bits(A1_WIDE)==64);
+
+ localparam A2_REAL = REAL;
+ `ASSERT(A2_REAL == 1.234);
+
+ localparam A3_SIGNED = SIGNED;
+ `ASSERT($bits(A3_SIGNED)==64 && A3_SIGNED < 0);
+
+ localparam A4_EXPR = (2\'b01 + 2\'b10);
+ `ASSERT($bits(A4_EXPR)==2 && A4_EXPR==2\'b11);
+
+ // bullet 2
+ localparam [63:0] B_UNSIGNED = SIGNED;
+ `ASSERT($bits(B_UNSIGNED)==64 && B_UNSIGNED > 0);
+
+ // bullet 3
+ localparam signed C_SIGNED = UNSIGNED;
+ `ASSERT($bits(C_SIGNED)==64 && C_SIGNED < 0);
+
+ localparam unsigned C_UNSIGNED = SIGNED;
+ `ASSERT($bits(C_UNSIGNED)==64 && C_UNSIGNED > 0);
+
+ // bullet 4
+ // verilator lint_off WIDTH
+ localparam signed [59:0] D_SIGNED = UNSIGNED;
+ `ASSERT($bits(D_SIGNED)==60 && D_SIGNED < 0);
+ // verilator lint_on WIDTH
+
+ // verilator lint_off WIDTH
+ localparam unsigned [59:0] D_UNSIGNED = SIGNED;
+ `ASSERT($bits(D_UNSIGNED)==60 && D_UNSIGNED > 0);
+ // verilator lint_on WIDTH
+
+ // bullet 6
+ localparam UNSIZED = 23;
+ `ASSERT($bits(UNSIZED)>=32);
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // Some inputs we\'ll set to random values
+ reg [6:0] addr;
+ reg [6:0] e0;
+ reg [5:0] e1;
+ reg [5:0] e2;
+
+ wire [7:0] data;
+ reg [2:0] wrapcheck_a;
+ reg [2:0] wrapcheck_b;
+
+ test test (/*AUTOINST*/
+\t // Outputs
+\t .data\t\t\t(data[7:0]),
+\t // Inputs
+\t .addr\t\t\t(addr[6:0]),
+\t .e0\t\t\t(e0[6:0]),
+\t .e1\t\t\t(e1[5:0]),
+\t .e2\t\t\t(e2[5:0]));
+
+ always @(/*AS*/addr) begin
+ case(addr[2:0])
+\t3\'d0+3\'d0: wrapcheck_a = 3\'h0;
+\t3\'d0+3\'d1: wrapcheck_a = 3\'h1;
+\t3\'d0+3\'d2: wrapcheck_a = 3\'h2;
+\t3\'d0+3\'d3: wrapcheck_a = 3\'h3;
+\tdefault: wrapcheck_a = 3\'h4;
+ endcase
+
+ case(addr[2:0])
+\t3\'d0+0: wrapcheck_b = 3\'h0;
+\t3\'d1+1: wrapcheck_b = 3\'h1;
+\t3\'d2+2: wrapcheck_b = 3\'h2;
+\t3\'d3+3: wrapcheck_b = 3\'h3;
+\tdefault: wrapcheck_b = 3\'h4;
+ endcase
+ end
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t //$write(""%d %x %x %x\
+"", cyc, data, wrapcheck_a, wrapcheck_b);
+\t if (cyc==1) begin
+\t addr <= 7\'h28;
+\t e0 <= 7\'h11;
+\t e1 <= 6\'h02;
+\t e2 <= 6\'h03;
+\t end
+\t if (cyc==2) begin
+\t addr <= 7\'h2b;
+\t if (data != 8\'h11) $stop;
+\t end
+\t if (cyc==3) begin
+\t addr <= 7\'h2c;
+\t if (data != 8\'h03) $stop;
+\t if (wrapcheck_a != 3\'h3) $stop;
+\t if (wrapcheck_b != 3\'h4) $stop;
+\t end
+\t if (cyc==4) begin
+\t addr <= 7\'h0;
+\t if (data != 8\'h00) $stop;
+\t if (wrapcheck_a != 3\'h4) $stop;
+\t if (wrapcheck_b != 3\'h2) $stop;
+\t end
+\t if (cyc==5) begin
+\t if (data != 8\'h00) $stop;
+\t end
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+/* verilator lint_off WIDTH */
+`define AI 7\'h28
+
+module test (/*AUTOARG*/
+ // Outputs
+ data,
+ // Inputs
+ addr, e0, e1, e2
+ );
+
+ output [7:0]\tdata;
+
+ input [6:0] \taddr;
+ input [6:0] \te0;
+ input [5:0] \te1, e2;
+
+ reg [7:0] \tdata;
+
+ always @(/*AS*/addr or e0 or e1 or e2)
+ begin
+ \tcase (addr)
+\t `AI: data = {e0[6], 1\'b0, e0[5:0]};
+\t `AI+1: data = e1;
+\t `AI+2,
+\t `AI+3: data = e2;
+\t default: data = 0;
+ \tendcase
+ end
+
+endmodule
+
+// Local Variables:
+// eval:(verilog-read-defines)
+// verilog-auto-sense-defines-constant: t
+// End:
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ integer\tv;
+
+ reg \ti;
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire\t\t\toa;\t\t\t// From a of a.v
+ wire\t\t\toz;\t\t\t// From z of z.v
+ // End of automatics
+
+ a a (.*);
+ z z (.*);
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d i=%x oa=%x oz=%x\
+"",$time, cyc, i, oa, oz);
+`endif
+ cyc <= cyc + 1;
+ i <= cyc[0];
+ if (cyc==0) begin
+\t v = 3;
+\t if (v !== 3) $stop;
+\t if (assignin(v) !== 2) $stop;
+\t if (v !== 3) $stop; // Make sure V didn\'t get changed
+ end
+ else if (cyc<10) begin
+\t if (cyc==11 && oz!==1\'b0) $stop;
+\t if (cyc==12 && oz!==1\'b1) $stop;
+\t if (cyc==12 && oa!==1\'b1) $stop;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+ function integer assignin(input integer i);
+ i = 2;
+ assignin = i;
+ endfunction
+
+endmodule
+
+module a (input i, output oa);
+ // verilator lint_off ASSIGNIN
+ assign i = 1\'b1;
+ assign oa = i;
+endmodule
+
+module z (input i, output oz);
+ assign oz = i;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ parameter DW = 4;
+ wire [3:0] drv_a = crc[3:0];
+ wire [3:0] drv_b = crc[7:4];
+ wire [3:0] drv_e = crc[19:16];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [DW-1:0]\tdrv;\t\t\t// To/From test1 of Test1.v
+ wire [DW-1:0]\tdrv2;\t\t\t// From test2 of Test2.v
+ // End of automatics
+
+ Test1 test1 (/*AUTOINST*/
+\t\t// Inouts
+\t\t.drv\t\t\t(drv[DW-1:0]),
+\t\t// Inputs
+\t\t.drv_a\t\t\t(drv_a[DW-1:0]),
+\t\t.drv_b\t\t\t(drv_b[DW-1:0]),
+\t\t.drv_e\t\t\t(drv_e[DW-1:0]));
+ Test2 test2 (/*AUTOINST*/
+\t\t// Outputs
+\t\t.drv2\t\t\t(drv2[DW-1:0]),
+\t\t// Inputs
+\t\t.drv_a\t\t\t(drv_a[DW-1:0]),
+\t\t.drv_b\t\t\t(drv_b[DW-1:0]),
+\t\t.drv_e\t\t\t(drv_e[DW-1:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {60\'h0, drv};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x drv=%x %x (%b??%b:%b)\
+"",$time, cyc, crc, drv, drv2, drv_e,drv_a,drv_b);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+\t if (drv2 != drv) $stop;
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'hd95d216c5a2945d0
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test1 #(
+ parameter DW = 4
+)(
+ input wire [DW-1:0] drv_a,
+ input wire [DW-1:0] drv_b,
+ input wire [DW-1:0] drv_e,
+ inout wire [DW-1:0] drv
+);
+
+ wire drv_0, drv_1, drv_2, drv_3;
+ bufif1 bufa0 (drv_0, drv_a[0], drv_e[0]);
+ bufif1 bufb0 (drv_0, drv_b[0], ~drv_e[0]);
+ bufif1 bufa1 (drv_1, drv_a[1], drv_e[1]);
+ bufif1 bufb1 (drv_1, drv_b[1], ~drv_e[1]);
+ bufif1 bufa2 (drv_2, drv_a[2], drv_e[2]);
+ bufif1 bufb2 (drv_2, drv_b[2], ~drv_e[2]);
+ bufif1 bufa3 (drv_3, drv_a[3], drv_e[3]);
+ bufif1 bufb3 (drv_3, drv_b[3], ~drv_e[3]);
+ assign drv = {drv_3,drv_2,drv_1,drv_0};
+
+endmodule
+
+module Test2 #(
+ parameter DW = 4
+)(
+ input wire [DW-1:0] drv_a,
+ input wire [DW-1:0] drv_b,
+ input wire [DW-1:0] drv_e,
+ inout wire [DW-1:0] drv2
+);
+
+ wire [DW-1:0] drv_all;
+ bufif1 bufa [DW-1:0] (drv_all, drv_a, drv_e);
+ // Below ~= bufif1 bufb [DW-1:0] (drv_all, drv_b, ~drv_e);
+ bufif1 bufb [DW-1:0] ({drv_all[3], drv_all[2], drv_all[1], drv_all[0]},
+\t\t\t {drv_b[3], drv_b[2], drv_b[1], drv_b[0]},
+\t\t\t {~drv_e[3], ~drv_e[2], ~drv_e[1], ~drv_e[0]});
+ assign drv2 = drv_all;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] crc;
+ reg [63:0] sum;
+
+ wire [3:0] Value = crc[3:0];
+
+ wire [3:0] Result;
+ wire [3:0] Result2;
+
+ Testit testit (/*AUTOINST*/
+\t\t // Outputs
+\t\t .Result\t\t(Result[3:0]),
+\t\t .Result2\t\t(Result2[3:0]),
+\t\t // Inputs
+\t\t .clk\t\t\t(clk),
+\t\t .Value\t\t(Value[3:0]));
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x %x %x %x\
+"",$time, cyc, crc, Result, Result2);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= {56\'h0, Result, Result2}
+\t ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $write(""[%0t] cyc==%0d crc=%x %x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t if (sum !== 64\'h4af37965592f64f9) $stop;
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (clk, Value, Result);
+ input clk;
+ input Value;
+ output Result;
+
+ reg Internal;
+
+ assign Result = Internal ^ clk;
+
+ always @(posedge clk)
+ Internal <= #1 Value;
+endmodule
+
+module Test_wrap1 (clk, Value, Result);
+ input clk;
+ input Value;
+ output Result;
+
+ Test t (clk, Value, Result);
+endmodule
+
+module Test_wrap2 (clk, Value, Result);
+ input clk;
+ input Value;
+ output Result;
+
+ Test t (clk, Value, Result);
+endmodule
+
+module Testit (clk, Value, Result, Result2);
+ input clk;
+ input [3:0] Value;
+ output [3:0] Result;
+ output [3:0] Result2;
+
+ genvar i;
+ generate
+ for (i = 0; i < 4; i = i + 1)
+\tbegin : a
+\t if ((i == 0) || (i == 2)) begin : gblk
+\t Test_wrap1 test (clk, Value[i] , Result[i]);
+\t end
+\t else begin : gblk
+\t Test_wrap2 test (clk, Value[i], Result[i]);
+\t end
+\tend
+ endgenerate
+
+ assign Result2[0] = a[0].gblk.test.t.Internal;
+ assign Result2[1] = a[1].gblk.test.t.Internal;
+ assign Result2[2] = a[2].gblk.test.t.Internal;
+ assign Result2[3] = a[3].gblk.test.t.Internal;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ logic [7:0] arr [7:0];
+ logic [7:0] arri [7:0];
+
+ has_array am1 (.clk(clk), .arri(arr), .arro(arri));
+
+ integer cyc; initial cyc = 0;
+
+ initial begin
+ for (int i = 0; i < 8; i++) begin
+\t arr[i] = 0;
+ end
+ end
+
+ always @(posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc == 5 && arri[1] != 8) begin
+ $stop;
+ end
+ for (int i = 0; i < 7; ++i) begin
+\t arr[i+1] <= arr[i];
+ end
+ arr[0] <= arr[0] + 1;
+ end
+
+endmodule : t
+
+module has_array (
+ input clk,
+ input logic [7:0] arri [7:0],
+ output logic [7:0] arro [7:0]
+ );
+
+ integer cyc; initial cyc = 0;
+
+ always @(posedge clk) begin
+ cyc <= cyc + 1;
+ if (arri[0] == 10 && cyc == 10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+ always @(posedge clk) begin
+ for (integer i = 0; i < 7; ++i) begin
+\t arro[i+1] <= arro[i];
+ end
+ arro[0] = arro[0] + 2;
+ end
+
+endmodule : has_array
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Jonathon Donaldson.
+
+package my_funcs;
+ function automatic int simple_func (input int value);
+ begin
+\t simple_func = value;
+ end
+ endfunction
+endpackage
+
+package my_module_types;
+ import my_funcs::*;
+
+ localparam MY_PARAM = 3;
+ localparam MY_PARAM2 /*verilator public*/ = simple_func(12);
+endpackage
+
+module t
+ import my_module_types::*;
+ (
+ input \t\t\ti_clk,
+ input [MY_PARAM-1:0] \ti_d,
+ output logic [MY_PARAM-1:0] o_q
+ );
+
+ always_ff @(posedge i_clk)
+ o_q <= i_d;
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003-2007 by Wilson Snyder.
+
+`define zednkw 200
+
+module BreadAddrDP (zfghtn, cjtmau, vipmpg, knquim, kqxkkr);
+input zfghtn;
+input [4:0] cjtmau;
+input vipmpg;
+input [7:0] knquim;
+input [7:0] kqxkkr;
+
+reg covfok;
+
+reg [15:0] xwieqw;
+reg [2:0] ofnjjt;
+
+reg [37:0] hdsejo[1:0];
+
+reg wxxzgd, tceppr, ratebp, fjizkr, iwwrnq;
+reg vrqrih, ryyjxy;
+reg fgzsox;
+
+wire xdjikl = ~wxxzgd & ~tceppr & ~ratebp & fjizkr;
+wire iytyol = ~wxxzgd & ~tceppr & ratebp & ~fjizkr & ~xwieqw[10];
+wire dywooz = ~wxxzgd & ~tceppr & ratebp & ~fjizkr & xwieqw[10];
+wire qnpfus = ~wxxzgd & ~tceppr & ratebp & fjizkr;
+wire fqlkrg = ~wxxzgd & tceppr & ~ratebp & ~fjizkr;
+
+wire ktsveg = hdsejo[0][6] | (hdsejo[0][37:34] == 4'h1);
+wire smxixw = vrqrih | (ryyjxy & ktsveg);
+
+wire [7:0] grvsrs, kyxrft, uxhkka;
+
+wire [7:0] eianuv = 8'h01 << ofnjjt;
+wire [7:0] jvpnxn = {8{qnpfus}} & eianuv;
+wire [7:0] zlnzlj = {8{fqlkrg}} & eianuv;
+wire [7:0] nahzat = {8{iytyol}} & eianuv;
+
+genvar i;
+generate
+ for (i=0;i<8;i=i+1)
+ begin : dnlpyw
+ DecCountReg4 bzpytc (zfghtn, fgzsox, zlnzlj[i],
+ \t\t\t knquim[3:0], covfok, grvsrs[i]);
+ DecCountReg4 oghukp (zfghtn, fgzsox, zlnzlj[i],
+ \t\t\t knquim[7:4], covfok, kyxrft[i]);
+ DecCountReg4 ttvjoo (zfghtn, fgzsox, nahzat[i],
+\t\t\t kqxkkr[3:0], covfok, uxhkka[i]);
+ end
+endgenerate
+
+endmodule
+
+module DecCountReg4 (clk, fgzsox, fckiyr, uezcjy, covfok, juvlsh);
+input clk, fgzsox, fckiyr, covfok;
+input [3:0] uezcjy;
+output juvlsh;
+
+task Xinit;
+begin
+`ifdef TEST_HARNESS
+ khgawe = 1'b0;
+`endif
+end
+endtask
+function X;
+input vrdejo;
+begin
+`ifdef TEST_HARNESS
+ if ((vrdejo & ~vrdejo) !== 1'h0) khgawe = 1'b1;
+`endif
+ X = vrdejo;
+end
+endfunction
+task Xcheck;
+input vzpwwy;
+begin
+end
+endtask
+
+reg [3:0] udbvtl;
+
+assign juvlsh = |udbvtl;
+wire [3:0] mppedc = {4{fgzsox}} & (fckiyr ? uezcjy : (udbvtl - 4'h1));
+
+wire qqibou = ((juvlsh | fckiyr) & covfok) | ~fgzsox;
+
+always @(posedge clk)
+begin
+ Xinit;
+ if (X(qqibou))
+ udbvtl\t<= #`zednkw mppedc;
+
+ Xcheck(fgzsox);
+end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ initial begin
+ if (task_as_func(1'b0)) $stop;
+ end
+
+ task task_as_func;
+ input ign;
+ endtask
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+
+module t;
+ Test0 t0 (.val0(\'0));
+ Test1 t1 (.val1(\'0));
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+
+package params;
+ parameter P = 7;
+endpackage
+
+module Test0 (val0);
+ parameter Z = 1;
+ input [Z : 0] val0;
+endmodule
+
+module Test1 (val1);
+ input logic [params::P : 0] val1;\t// Fully qualified parameter
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg [41:0] \t\taaa;
+ wire [41:0] \t\tbbb;
+
+ // verilator public_module
+ wire [41:0] \t\tz_0;
+ wire [41:0] \t\tz_1;
+
+ wide w_0(
+\t .xxx( { {40{1\'b0}},2\'b11 } ),
+\t .yyy( aaa[1:0] ),
+\t .zzz( z_0 )
+\t );
+
+ wide w_1(
+\t .xxx( aaa ),
+\t .yyy( 2\'b10 ),
+\t .zzz( z_1 )
+\t );
+
+ assign bbb= z_0 + z_1;
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t aaa <= 42\'b01;
+\t end
+\t if (cyc==2) begin
+\t aaa <= 42\'b10;
+\t if (z_0 != 42\'h4) $stop;
+\t if (z_1 != 42\'h3) $stop;
+\t end
+\t if (cyc==3) begin
+\t if (z_0 != 42\'h5) $stop;
+\t if (z_1 != 42\'h4) $stop;
+\t end
+\t if (cyc==4) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+module wide (
+\tinput [41:0]\t\txxx,
+\tinput [1:0]\t\t\tyyy,
+\toutput [41:0]\t\tzzz
+\t);
+ // verilator public_module
+
+ assign zzz = xxx+ { {40{1\'b0}},yyy };
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t_case_huge_sub4 (/*AUTOARG*/
+ // Outputs
+ outq,
+ // Inputs
+ index
+ );
+
+ input [7:0] index;
+ output [9:0] outq;
+
+ // =============================
+ /*AUTOREG*/
+ // Beginning of automatic regs (for this module's undeclared outputs)
+ reg [9:0]\t\toutq;
+ // End of automatics
+
+ // =============================
+ always @(/*AS*/index) begin
+ case (index)
+\t// default below: no change
+\t8'h00: begin outq = 10'h001; end
+\t8'he0: begin outq = 10'h05b; end
+\t8'he1: begin outq = 10'h126; end
+\t8'he2: begin outq = 10'h369; end
+\t8'he3: begin outq = 10'h291; end
+\t8'he4: begin outq = 10'h2ca; end
+\t8'he5: begin outq = 10'h25b; end
+\t8'he6: begin outq = 10'h106; end
+\t8'he7: begin outq = 10'h172; end
+\t8'he8: begin outq = 10'h2f7; end
+\t8'he9: begin outq = 10'h2d3; end
+\t8'hea: begin outq = 10'h182; end
+\t8'heb: begin outq = 10'h327; end
+\t8'hec: begin outq = 10'h1d0; end
+\t8'hed: begin outq = 10'h204; end
+\t8'hee: begin outq = 10'h11f; end
+\t8'hef: begin outq = 10'h365; end
+\t8'hf0: begin outq = 10'h2c2; end
+\t8'hf1: begin outq = 10'h2b5; end
+\t8'hf2: begin outq = 10'h1f8; end
+\t8'hf3: begin outq = 10'h2a7; end
+\t8'hf4: begin outq = 10'h1be; end
+\t8'hf5: begin outq = 10'h25e; end
+\t8'hf6: begin outq = 10'h032; end
+\t8'hf7: begin outq = 10'h2ef; end
+\t8'hf8: begin outq = 10'h02f; end
+\t8'hf9: begin outq = 10'h201; end
+\t8'hfa: begin outq = 10'h054; end
+\t8'hfb: begin outq = 10'h013; end
+\t8'hfc: begin outq = 10'h249; end
+\t8'hfd: begin outq = 10'h09a; end
+\t8'hfe: begin outq = 10'h012; end
+\t8'hff: begin outq = 10'h114; end
+\tdefault: ; // No change
+ endcase
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+
+`include ""t_flag_f_tsub_inc.v""
+
+module t;
+ initial begin
+`ifndef GOT_DEF1
+ $write(""%%Error: NO GOT_DEF1\
+""); $stop;
+`endif
+`ifndef GOT_DEF2
+ $write(""%%Error: NO GOT_DEF2\
+""); $stop;
+`endif
+`ifndef GOT_DEF3
+ $write(""%%Error: NO GOT_DEF3\
+""); $stop;
+`endif
+`ifndef GOT_DEF4
+ $write(""%%Error: NO GOT_DEF4\
+""); $stop;
+`endif
+`ifndef GOT_DEF5
+ $write(""%%Error: NO GOT_DEF5\
+""); $stop;
+`endif
+`ifndef GOT_DEF6
+ $write(""%%Error: NO GOT_DEF6\
+""); $stop;
+`endif
+`ifdef NON_DEF
+ $write(""%%Error: NON_DEF\
+""); $stop;
+`endif
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg [15:0] m_din;
+
+ // OK
+ reg [15:0] a_split_1, a_split_2;
+ always @ (/*AS*/m_din) begin
+ a_split_1 = m_din;
+ a_split_2 = m_din;
+ end
+
+ // OK
+ reg [15:0] b_split_1, b_split_2;
+ always @ (/*AS*/m_din) begin
+ b_split_1 = m_din;
+ b_split_2 = b_split_1;
+ end
+
+ // Not OK
+ reg [15:0] c_split_1, c_split_2;
+ always @ (/*AS*/m_din) begin
+ c_split_1 = m_din;
+ c_split_2 = c_split_1;
+ c_split_1 = ~m_din;
+ end
+
+ // OK
+ reg [15:0] d_split_1, d_split_2;
+ always @ (posedge clk) begin
+ d_split_1 <= m_din;
+ d_split_2 <= d_split_1;
+ d_split_1 <= ~m_din;
+ end
+
+ // Not OK
+ always @ (posedge clk) begin
+ $write("" foo %x"", m_din);
+ $write("" bar %x\
+"", m_din);
+ end
+
+ // Not OK
+ reg [15:0] e_split_1, e_split_2;
+ always @ (posedge clk) begin
+ e_split_1 = m_din;
+ e_split_2 = e_split_1;
+ end
+
+ // Not OK
+ reg [15:0] f_split_1, f_split_2;
+ always @ (posedge clk) begin
+ f_split_2 = f_split_1;
+ f_split_1 = m_din;
+ end
+
+ // Not Ok
+ reg [15:0] l_split_1, l_split_2;
+ always @ (posedge clk) begin
+ l_split_2 <= l_split_1;
+ l_split_1 <= l_split_2 | m_din;
+ end
+
+ // OK
+ reg [15:0] z_split_1, z_split_2;
+ always @ (posedge clk) begin
+ z_split_1 <= 0;
+ z_split_1 <= ~m_din;
+ end
+ always @ (posedge clk) begin
+ z_split_2 <= 0;
+ z_split_2 <= z_split_1;
+ end
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc<=cyc+1;
+\t if (cyc==1) begin
+\t m_din <= 16\'hfeed;
+\t end
+\t if (cyc==3) begin
+\t end
+\t if (cyc==4) begin
+\t m_din <= 16\'he11e;
+\t //$write("" A %x %x\
+"", a_split_1, a_split_2);
+\t if (!(a_split_1==16\'hfeed && a_split_2==16\'hfeed)) $stop;
+\t if (!(b_split_1==16\'hfeed && b_split_2==16\'hfeed)) $stop;
+\t if (!(c_split_1==16\'h0112 && c_split_2==16\'hfeed)) $stop;
+\t if (!(d_split_1==16\'h0112 && d_split_2==16\'h0112)) $stop;
+\t if (!(e_split_1==16\'hfeed && e_split_2==16\'hfeed)) $stop;
+\t if (!(f_split_1==16\'hfeed && f_split_2==16\'hfeed)) $stop;
+\t if (!(z_split_1==16\'h0112 && z_split_2==16\'h0112)) $stop;
+\t end
+\t if (cyc==5) begin
+\t m_din <= 16\'he22e;
+\t if (!(a_split_1==16\'he11e && a_split_2==16\'he11e)) $stop;
+\t if (!(b_split_1==16\'he11e && b_split_2==16\'he11e)) $stop;
+\t if (!(c_split_1==16\'h1ee1 && c_split_2==16\'he11e)) $stop;
+\t if (!(d_split_1==16\'h0112 && d_split_2==16\'h0112)) $stop;
+\t if (!(z_split_1==16\'h0112 && z_split_2==16\'h0112)) $stop;
+\t // Two valid orderings, as we don\'t know which posedge clk gets evaled first
+\t if (!(e_split_1==16\'hfeed && e_split_2==16\'hfeed) && !(e_split_1==16\'he11e && e_split_2==16\'he11e)) $stop;
+\t if (!(f_split_1==16\'hfeed && f_split_2==16\'hfeed) && !(f_split_1==16\'he11e && f_split_2==16\'hfeed)) $stop;
+\t end
+\t if (cyc==6) begin
+\t m_din <= 16\'he33e;
+\t if (!(a_split_1==16\'he22e && a_split_2==16\'he22e)) $stop;
+\t if (!(b_split_1==16\'he22e && b_split_2==16\'he22e)) $stop;
+\t if (!(c_split_1==16\'h1dd1 && c_split_2==16\'he22e)) $stop;
+\t if (!(d_split_1==16\'h1ee1 && d_split_2==16\'h0112)) $stop;
+\t if (!(z_split_1==16\'h1ee1 && d_split_2==16\'h0112)) $stop;
+\t // Two valid orderings, as we don\'t know which posedge clk gets evaled first
+\t if (!(e_split_1==16\'he11e && e_split_2==16\'he11e) && !(e_split_1==16\'he22e && e_split_2==16\'he22e)) $stop;
+\t if (!(f_split_1==16\'he11e && f_split_2==16\'hfeed) && !(f_split_1==16\'he22e && f_split_2==16\'he11e)) $stop;
+\t end
+\t if (cyc==7) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t
+ (
+ input wire i,
+ input wire i2 = i // BAD
+ );
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// We see Verilator assumes a 1-bit parameter is a scalar rather than a 1-bit
+// long vector. This causes the following code to fail.
+//
+// Other event drive simulators accept this.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Jeremy Bennett.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ // At this point it is ambiguous whether a is scalar or vector
+ parameter a = 1\'b0;
+ wire b = a[0];
+ // Note however b[0] is illegal.
+
+ always @(posedge clk) begin
+ if (b == 1\'b0) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ else begin
+\t $stop;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t ();
+
+ parameter MSG_PORT_WIDTH = 4350;
+ localparam PAYLOAD_MAX_BITS = 4352;
+
+ reg [MSG_PORT_WIDTH-1:0] \tmsg;
+
+ initial begin
+ // Operator TASKREF \'func\' expects 4352 bits on the Function Argument, but Function Argument\'s VARREF \'msg\' generates 4350 bits.
+ // verilator lint_off WIDTH
+ func(msg);
+ // verilator lint_on WIDTH
+ if (msg !== {MSG_PORT_WIDTH{1\'b1}}) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ function integer func (output bit [PAYLOAD_MAX_BITS-1:0] data);
+ /*verilator no_inline_task*/
+ data = {PAYLOAD_MAX_BITS{1\'b1}};
+ return (1);
+ endfunction
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+//
+// Example module to create problem.
+//
+// generate a 64 bit value with bits
+// [HighMaskSel_Bot : LowMaskSel_Bot ] = 1
+// [HighMaskSel_Top+32: LowMaskSel_Top+32] = 1
+// all other bits zero.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=0;
+ reg [7:0] crc;
+ reg [63:0] sum;
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [63:0]\t\tHighLogicImm;\t\t// From example of example.v
+ wire [63:0]\t\tLogicImm;\t\t// From example of example.v
+ wire [63:0]\t\tLowLogicImm;\t\t// From example of example.v
+ // End of automatics
+
+ wire [5:0] LowMaskSel_Top = crc[5:0];
+ wire [5:0] LowMaskSel_Bot = crc[5:0];
+ wire [5:0] HighMaskSel_Top = crc[5:0]+{4\'b0,crc[7:6]};
+ wire [5:0] HighMaskSel_Bot = crc[5:0]+{4\'b0,crc[7:6]};
+
+ example example (/*AUTOINST*/
+\t\t // Outputs
+\t\t .LogicImm\t\t(LogicImm[63:0]),
+\t\t .LowLogicImm\t(LowLogicImm[63:0]),
+\t\t .HighLogicImm\t(HighLogicImm[63:0]),
+\t\t // Inputs
+\t\t .LowMaskSel_Top\t(LowMaskSel_Top[5:0]),
+\t\t .HighMaskSel_Top\t(HighMaskSel_Top[5:0]),
+\t\t .LowMaskSel_Bot\t(LowMaskSel_Bot[5:0]),
+\t\t .HighMaskSel_Bot\t(HighMaskSel_Bot[5:0]));
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ crc <= {crc[6:0], ~^ {crc[7],crc[5],crc[4],crc[3]}};
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%b %d.%d,%d.%d -> %x.%x -> %x\
+"",$time, cyc, crc,
+\t LowMaskSel_Top, HighMaskSel_Top, LowMaskSel_Bot, HighMaskSel_Bot,
+\t LowLogicImm, HighLogicImm, LogicImm);
+`endif
+ if (cyc==0) begin
+\t // Single case
+\t crc <= 8\'h0;
+\t sum <= 64\'h0;
+ end
+ else if (cyc==1) begin
+\t // Setup
+\t crc <= 8\'hed;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+\t sum <= {sum[62:0],sum[63]} ^ LogicImm;
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%b %x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 8\'b00111000) $stop;
+\t if (sum !== 64\'h58743ffa61e41075) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module example (/*AUTOARG*/
+ // Outputs
+ LogicImm, LowLogicImm, HighLogicImm,
+ // Inputs
+ LowMaskSel_Top, HighMaskSel_Top, LowMaskSel_Bot, HighMaskSel_Bot
+ );
+
+ input [5:0] LowMaskSel_Top, HighMaskSel_Top;
+ input [5:0] \t LowMaskSel_Bot, HighMaskSel_Bot;
+ output [63:0] LogicImm;
+
+ output [63:0] \t LowLogicImm, HighLogicImm;
+
+
+ wire [63:0] \t LowLogicImm, HighLogicImm;
+
+ /* verilator lint_off UNSIGNED */
+ /* verilator lint_off CMPCONST */
+ genvar \t i;
+ generate
+ for (i=0;i<64;i=i+1) begin : MaskVal
+\t if (i >= 32) begin
+\t assign LowLogicImm[i] = (LowMaskSel_Top <= i[5:0]);
+\t assign HighLogicImm[i] = (HighMaskSel_Top >= i[5:0]);
+\t end
+\t else begin
+\t assign LowLogicImm[i] = (LowMaskSel_Bot <= i[5:0]);
+\t assign HighLogicImm[i] = (HighMaskSel_Bot >= i[5:0]);
+\t end
+ end
+ endgenerate
+ /* verilator lint_on UNSIGNED */
+ /* verilator lint_on CMPCONST */
+
+ assign LogicImm = LowLogicImm & HighLogicImm;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); fail=1; end while(0)
+
+module t (/*AUTOARG*/);
+
+ bit fail;
+
+ // IEEE says for ** the size is L(i). Thus Icarus Verilog is wrong in sizing some of the below.
+
+ initial begin
+ // NC=67b6cfc1b29a21 VCS=c1b29a20(wrong) IV=67b6cfc1b29a21 Verilator=67b6cfc1b29a21
+ $display(""15 ** 14 = %0x expect 67b6cfc1b29a21"", 64\'b1111 ** 64\'b1110);
+ // NC=1 VCS=0 IV=0 Verilator=1 (wrong,fixed)
+ $display(""15 **-4\'sd2 = %0x expect 0 (per IEEE negative power)"", ((-4\'d1 ** -4\'sd2)));
+ // NC=1 VCS=0 IV=67b6cfc1b29a21(wrong) Verilator=1
+ $display(""15 ** 14 = %0x expect 1 (LSB 4-bits of 67b6cfc1b29a21)"", ((-4\'d1 ** -4\'d2)));
+ // NC=1 VCS=0 IV=67b6cfc1b29a21(wrong) Verilator=1
+ $display(""15 ** 14 = %0x expect 1 (LSB 4-bits of 67b6cfc1b29a21)"", ((4\'d15 ** 4\'d14)));
+ // NC=8765432187654321 VCS=8765432187654000(wrong) IV=8765432187654321 Verilator=8765432187654321
+ $display(""64\'big ** 1 = %0x expect %0x"", 64\'h8765432187654321 ** 1, 64\'h8765432187654321);
+ $display(""\
+"");
+
+ `checkh( (64\'b1111 ** 64\'b1110),\t64\'h67b6cfc1b29a21);
+ `checkh( (-4\'d1 ** -4\'sd2),\t4\'h0); //bug730
+ `checkh( (-4\'d1 ** -4\'d2),\t\t4\'h1);
+ `checkh( (4\'d15 ** 4\'d14),\t\t4\'h1);
+ `checkh( (64\'h8765432187654321 ** 4\'h1), 64\'h8765432187654321);
+
+ `checkh((-8\'sh3 ** 8\'h3) , 8\'he5 ); // a**b (-27)
+ `checkh((-8\'sh1 ** 8\'h2) , 8\'h1\t ); // -1^odd=-1, -1^even=1
+ `checkh((-8\'sh1 ** 8\'h3) , 8\'hff ); // -1^odd=-1, -1^even=1
+ `checkh(( 8\'h0 ** 8\'h3) , 8\'h0\t ); // 0
+ `checkh(( 8\'h1 ** 8\'h3) , 8\'h1\t ); // 1
+ `checkh(( 8\'h3 ** 8\'h3) , 8\'h1b ); // a**b (27)
+ `checkh(( 8\'sh3 ** 8\'h3) , 8\'h1b ); // a**b (27)
+ `checkh(( 8\'h6 ** 8\'h3) , 8\'hd8 ); // a**b (216)
+ `checkh(( 8\'sh6 ** 8\'h3) , 8\'hd8 ); // a**b (216)
+
+ `checkh((-8\'sh3 ** 8\'sh3), 8\'he5 ); // a**b
+ `checkh((-8\'sh1 ** 8\'sh2), 8\'h1\t ); // -1^odd=-1, -1^even=1
+ `checkh((-8\'sh1 ** 8\'sh3), 8\'hff ); // -1^odd=-1, -1^even=1
+ `checkh(( 8\'h0 ** 8\'sh3), 8\'h0\t ); // 0
+ `checkh(( 8\'h1 ** 8\'sh3), 8\'h1\t ); // 1
+ `checkh(( 8\'h3 ** 8\'sh3), 8\'h1b ); // a**b (27)
+ `checkh(( 8\'sh3 ** 8\'sh3), 8\'h1b ); // a**b (27)
+ `checkh(( 8\'h6 ** 8\'sh3), 8\'hd8 ); // a**b (216)
+ `checkh(( 8\'sh6 ** 8\'sh3), 8\'hd8 ); // a**b (216)
+
+ `checkh((-8\'sh3 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+ `checkh((-8\'sh1 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+ `checkh((-8\'sh1 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+ `checkh(( 8\'h0 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+ `checkh(( 8\'h1 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+ `checkh(( 8\'h3 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+ `checkh(( 8\'sh3 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+
+ `checkh((-8\'sh3 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+ `checkh((-8\'sh1 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+ `checkh((-8\'sh1 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+ `checkh(( 8\'h0 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+ `checkh(( 8\'h1 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+ `checkh(( 8\'h3 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+ `checkh(( 8\'sh3 ** -8\'sh0), 8\'h1 ); // a**0 always 1
+
+ `checkh((-8\'sh3 ** -8\'sh3), 8\'h0 ); // 0 (a<-1) // NCVERILOG bug
+ `checkh((-8\'sh1 ** -8\'sh2), 8\'h1 ); // -1^odd=-1, -1^even=1
+ `checkh((-8\'sh1 ** -8\'sh3), 8\'hff); // -1^odd=-1, -1^even=1
+// `checkh(( 8\'h0 ** -8\'sh3), 8\'hx ); // x // NCVERILOG bug
+ `checkh(( 8\'h1 ** -8\'sh3), 8\'h1 ); // 1**b always 1
+ `checkh(( 8\'h3 ** -8\'sh3), 8\'h0 ); // 0 // NCVERILOG bug
+ `checkh(( 8\'sh3 ** -8\'sh3), 8\'h0 ); // 0 // NCVERILOG bug
+
+
+ if (fail) $stop;
+ else $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOINST*/);
+
+ Test #(
+ .BIT_WIDTH (72),
+ .BYTE_WIDTH (9)
+ )
+
+ u_test_inst();
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+module Test ();
+
+ parameter BIT_WIDTH = """";
+ parameter BYTE_WIDTH = """";
+
+ localparam BYTES = BIT_WIDTH / BYTE_WIDTH;
+
+ wire [BYTES - 1:0] i;
+ wire [BYTES - 1:0] o;
+
+ genvar g;
+ generate
+ for (g = 0; g < BYTES; g = g + 1) begin: gen
+ assign o[g] = (i[g] !== 1\'b0);
+ end
+ endgenerate
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ // Width error below
+ wire [3:0] foo = 6'h2e;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+
+ integer cyc; initial cyc=0;
+
+ always @(posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc == 1) begin
+\t ReadContDisps;
+ end
+ else if (cyc == 5) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+`ifndef verilator
+ DispContDisps;
+`endif
+ end
+
+ task ReadContDisps;
+ begin
+\t $display(""%m: Here: %d"", cyc);
+ end
+ endtask
+
+ integer dindex;
+
+ task DispContDisps;
+ /* verilator public */
+ begin
+\t if (cyc >= 2) begin
+ if ( cyc >= 4 ) begin
+\t dindex = dindex + 2; //*** Error line
+\t $display(""%m: DIndex increment %d"", cyc);
+`ifdef VERILATOR
+\t $c(""VL_PRINTF(\\""Hello1?\\\
+\\"");"");
+`endif
+ end
+`ifdef VERILATOR
+\t $c(""VL_PRINTF(\\""Hello2?\\\
+\\"");"");
+\t $c(""VL_PRINTF(\\""Hello3?\\\
+\\"");"");
+`endif
+\t end
+ end
+ endtask
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ wire [15:-16] sel2 = crc[31:0];
+ wire [80:-10] sel3 = {crc[26:0],crc};
+
+ wire [3:0] \t out21 = sel2[-3 : -6];
+ wire [3:0] \t out22 = sel2[{1\'b0,crc[3:0]} - 16 +: 4];
+ wire [3:0] \t out23 = sel2[{1\'b0,crc[3:0]} - 10 -: 4];
+
+ wire [3:0] \t out31 = sel3[-3 : -6];
+ wire [3:0] \t out32 = sel3[crc[5:0] - 6 +: 4];
+ wire [3:0] \t out33 = sel3[crc[5:0] - 6 -: 4];
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {40\'h0, out21, out22, out23, out31, out32, out33};
+
+ reg [15:-16] sel1;
+ initial begin
+ // Path clearing
+ sel1 = 32\'h12345678;
+ if (sel1 != 32\'h12345678) $stop;
+ if (sel1[-13 : -16] != 4\'h8) $stop;
+ if (sel1[3:0] != 4\'h4) $stop;
+ if (sel1[4 +: 4] != 4\'h3) $stop;
+ if (sel1[11 -: 4] != 4\'h2) $stop;
+ end
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] sels=%x,%x,%x %x,%x,%x\
+"",$time, out21,out22,out23, out31,out32,out33);
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+`define EXPECTED_SUM 64\'hba7fe1e7ac128362
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk, fastclk
+ );
+
+ input clk;
+ input fastclk;
+
+ genvar unused;
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire\t\t\to_com;\t\t\t// From b of t_inst_first_b.v
+ wire\t\t\to_seq_d1r;\t\t// From b of t_inst_first_b.v
+ // End of automatics
+
+ integer _mode; // initial _mode=0
+ reg na,nb,nc,nd,ne;
+ wire ma,mb,mc,md,me;
+ wire da,db,dc,dd,de;
+ reg\t[7:0] wa,wb,wc,wd,we;
+ wire\t[7:0] qa,qb,qc,qd,qe;
+
+ wire\t[5:0] ra;
+ wire\t[4:0] rb;
+ wire\t[29:0] rc;
+ wire\t[63:0] rd;
+ reg\t [5:0] sa;
+ reg\t [4:0] sb;
+ reg\t [29:0] sc;
+ reg\t [63:0] sd;
+
+ reg \t\t_guard1; initial _guard1=0;
+ wire [104:0] r_wide = {ra,rb,rc,rd};
+ reg \t\t_guard2; initial _guard2=0;
+ wire [98:0] \tr_wide0 = {rb,rc,rd};
+ reg \t\t_guard3; initial _guard3=0;
+ wire [93:0] \tr_wide1 = {rc,rd};
+ reg \t\t_guard4; initial _guard4=0;
+ wire [63:0] \tr_wide2 = {rd};
+ reg \t\t_guard5; initial _guard5=0;
+ wire [168:0] r_wide3 = {ra,rb,rc,rd,rd};
+ reg [127:0]\t_guard6; initial _guard6=0;
+
+ t_inst_first_a a (
+\t .clk\t\t(clk),
+\t // Outputs
+\t .o_w5\t\t({ma,mb,mc,md,me}),
+\t .o_w5_d1r\t({da,db,dc,dd,de}),
+\t .o_w40\t\t({qa,qb,qc,qd,qe}),
+\t .o_w104\t\t({ra,rb,rc,rd}),
+\t // Inputs
+\t .i_w5\t\t({na,nb,nc,nd,ne}),
+\t .i_w40\t\t({wa,wb,wc,wd,we}),
+\t .i_w104\t\t({sa,sb,sc,sd})
+\t );
+
+ reg \t\ti_seq;
+ reg\t\ti_com;
+ wire [15:14] o2_comhigh;
+
+ t_inst_first_b b (
+\t .o2_com\t\t\t(o2_comhigh),
+\t .i2_com\t\t\t({i_com,~i_com}),
+\t .wide_for_trace\t\t(128\'h1234_5678_aaaa_bbbb_cccc_dddd),
+\t .wide_for_trace_2\t(_guard6 + 128\'h1234_5678_aaaa_bbbb_cccc_dddd),
+\t /*AUTOINST*/
+\t\t // Outputs
+\t\t .o_seq_d1r\t\t(o_seq_d1r),
+\t\t .o_com\t\t(o_com),
+\t\t // Inputs
+\t\t .clk\t\t(clk),
+\t\t .i_seq\t\t(i_seq),
+\t\t .i_com\t\t(i_com));
+
+ // surefire lint_off STMINI
+ initial _mode = 0;
+
+ always @ (posedge fastclk) begin
+ if (_mode==1) begin
+\t if (o_com !== ~i_com) $stop;
+\t if (o2_comhigh !== {~i_com,i_com}) $stop;
+ end
+ end
+
+ always @ (posedge clk) begin
+ //$write(""[%0t] t_inst: MODE = %0x NA=%x MA=%x DA=%x\
+"", $time, _mode,
+ //\t {na,nb,nc,nd,ne}, {ma,mb,mc,md,me}, {da,db,dc,dd,de});
+ $write(""[%0t] t_inst: MODE = %0x IS=%x OS=%x\
+"", $time, _mode, i_seq, o_seq_d1r);
+ if (_mode==0) begin
+\t $write(""[%0t] t_inst: Running\
+"", $time);
+\t _mode<=1;
+\t {na,nb,nc,nd,ne} <= 5\'b10110;
+\t {wa,wb,wc,wd,we} <= {8\'ha, 8\'hb, 8\'hc, 8\'hd, 8\'he};
+\t {sa,sb,sc,sd} <= {6\'hf, 5\'h3, 30\'h12345, 32\'h0abc_abcd, 32\'h7654_3210};
+\t //
+\t i_seq <= 1\'b1;
+\t i_com <= 1\'b1;
+ end
+ else if (_mode==1) begin
+\t _mode<=2;
+\t if ({ma,mb,mc,md,me} !== 5\'b10110) $stop;
+\t if ({qa,qb,qc,qd,qe} !== {8\'ha,8\'hb,8\'hc,8\'hd,8\'he}) $stop;
+\t if ({sa,sb,sc,sd} !== {6\'hf, 5\'h3, 30\'h12345, 32\'h0abc_abcd, 32\'h7654_3210}) $stop;
+ end
+ else if (_mode==2) begin
+\t _mode<=3;
+\t if ({da,db,dc,dd,de} !== 5\'b10110) $stop;
+\t if (o_seq_d1r !== ~i_seq) $stop;
+\t //
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ if (|{_guard1,_guard2,_guard3,_guard4,_guard5,_guard6}) begin
+\t $write(""Guard error %x %x %x %x %x\
+"",_guard1,_guard2,_guard3,_guard4,_guard5);
+\t $stop;
+ end
+ end
+
+ // surefire lint_off UDDSDN
+ wire _unused_ok = |{1\'b1, r_wide0, r_wide1,r_wide2,r_wide3,r_wide};
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+
+ reg [2:0] a;
+ reg [2:0] b;
+ reg q;
+
+ f6 f6 (/*AUTOINST*/
+\t // Outputs
+\t .q\t\t\t\t(q),
+\t // Inputs
+\t .a\t\t\t\t(a[2:0]),
+\t .b\t\t\t\t(b[2:0]),
+\t .clk\t\t\t\t(clk));
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t a <= 3\'b000;
+\t b <= 3\'b100;
+\t end
+\t if (cyc==2) begin
+\t a <= 3\'b011;
+\t b <= 3\'b001;
+\t if (q != 1\'b0) $stop;
+\t end
+\t if (cyc==3) begin
+\t a <= 3\'b011;
+\t b <= 3\'b011;
+\t if (q != 1\'b0) $stop;
+\t end
+\t if (cyc==9) begin
+\t if (q != 1\'b1) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+module f6 (a, b, clk, q);
+ input [2:0] a;
+ input [2:0] \tb;
+ input \tclk;
+ output \tq;
+ reg \t\tout;
+
+ function func6;
+ reg \tresult;
+ input [5:0] src;
+ begin
+\t if (src[5:0] == 6\'b011011) begin
+\t result = 1\'b1;
+\t end
+\t else begin
+\t result = 1\'b0;
+\t end
+\t func6 = result;
+ end
+ endfunction
+
+ wire [5:0] w6 = {a, b};
+ always @(posedge clk) begin
+ out <= func6(w6);
+ end
+
+ assign q = out;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t_embed1_child (/*AUTOARG*/
+ // Outputs
+ bit_out, vec_out, wide_out, did_init_out,
+ // Inputs
+ clk, bit_in, vec_in, wide_in, is_ref
+ );
+
+ input clk;
+ input bit_in;
+ output bit_out;
+ input [30:0] vec_in;
+ output [30:0] vec_out;
+ input [123:0] wide_in;
+ output [123:0] wide_out;
+ output \t did_init_out;
+
+ input \t is_ref;
+
+ reg did_init; initial did_init = 0;
+ initial begin
+ did_init = 1;
+ end
+
+ reg did_final; initial did_final = 0;
+ final begin
+ did_final = 1;
+ if (!is_ref) $write(""*-* All Finished *-*\
+"");
+ //$finish is in parent
+ end
+
+ // Note async use!
+ wire bit_out = bit_in;
+ wire did_init_out = did_init;
+
+ always @ (posedge clk) begin
+ vec_out <= vec_in;
+ wide_out <= wide_in;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+
+`define GOT_DEF6
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005-2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ value
+ );
+
+ input [3:0] value;
+ always @ (/*AS*/value) begin
+ casex (value)
+\tdefault: $stop;
+ endcase
+ case (value)
+\t4'b0000: $stop;
+\t4'b1xxx: $stop;
+\tdefault: $stop;
+ endcase
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// A test of the export parameter used with modport
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Jeremy Bennett.
+
+interface test_if;
+
+ // Pre-declare function
+ extern function myfunc (input logic val);
+
+ // Interface variable
+ logic \tdata;
+
+ // Modport
+ modport mp_e(
+ export myfunc,
+\t output data
+\t );
+
+ // Modport
+ modport mp_i(
+ import myfunc,
+\t output data
+\t );
+
+endinterface // test_if
+
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ test_if i ();
+
+ testmod_callee testmod_callee_i (.ie (i.mp_e));
+ testmod_caller testmod_caller_i (.clk (clk),
+\t\t\t\t .ii (i.mp_i));
+endmodule
+
+
+module testmod_callee
+ (
+ test_if.mp_e ie
+ );
+
+ function automatic logic ie.myfunc (input logic val);
+ begin
+\t myfunc = (val == 1\'b0);
+ end
+ endfunction
+endmodule // testmod_caller
+
+
+module testmod_caller
+ (
+ input clk,
+ test_if.mp_i ii
+ );
+
+ always @(posedge clk) begin
+ ii.data = 1\'b0;
+ if (ii.myfunc (1\'b0)) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ else begin
+\t $stop;
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Iztok Jeras.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // packed structures
+ struct packed {
+ logic e0;
+ logic [1:0] e1;
+ logic [3:0] e2;
+ logic [7:0] e3;
+ } struct_bg; // big endian structure
+ /* verilator lint_off LITENDIAN */
+ struct packed {
+ logic e0;
+ logic [0:1] e1;
+ logic [0:3] e2;
+ logic [0:7] e3;
+ } struct_lt; // little endian structure
+ /* verilator lint_on LITENDIAN */
+
+ integer cnt = 0;
+
+ // event counter
+ always @ (posedge clk)
+ begin
+ cnt <= cnt + 1;
+ end
+
+ // finish report
+ always @ (posedge clk)
+ if (cnt==2) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ always @ (posedge clk)
+ if (cnt==1) begin
+ // big endian
+ if ($bits (struct_bg ) != 15) $stop;
+ if ($bits (struct_bg.e0) != 1) $stop;
+ if ($bits (struct_bg.e1) != 2) $stop;
+ if ($bits (struct_bg.e2) != 4) $stop;
+ if ($bits (struct_bg.e3) != 8) $stop;
+ if ($increment (struct_bg, 1) != 1) $stop;
+ // little endian
+ if ($bits (struct_lt ) != 15) $stop;
+ if ($bits (struct_lt.e0) != 1) $stop;
+ if ($bits (struct_lt.e1) != 2) $stop;
+ if ($bits (struct_lt.e2) != 4) $stop;
+ if ($bits (struct_lt.e3) != 8) $stop;
+ if ($increment (struct_lt, 1) != 1) $stop; // Structure itself always big numbered
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t;
+
+ integer varfirst;
+ sub varfirst (); // Error: Cell hits var
+ task varfirst; begin end endtask // Error: Task hits var
+
+ sub cellfirst ();
+ integer cellfirst; // Error: Var hits cell
+ task cellfirst; begin end endtask // Error: Task hits cell
+
+ task taskfirst; begin end endtask
+ integer taskfirst; // Error: Var hits task
+ sub taskfirst (); // Error: Cell hits task
+
+endmodule
+
+module sub;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+
+ reg [43:0] mi;
+ reg [5:0] index;
+ integer indexi;
+ reg\t read;
+
+ initial begin
+ // Static
+ mi = 44\'b01010101010101010101010101010101010101010101;
+ if (mi[0] !== 1\'b1) $stop;
+ if (mi[1 -: 2] !== 2\'b01) $stop;
+`ifdef VERILATOR
+ // verilator lint_off SELRANGE
+ if (mi[-1] !== 1\'bx && mi[-1] !== 1\'b0) $stop;
+ if (mi[0 -: 2] !== 2\'b1x && 1\'b0) $stop;
+ if (mi[-1 -: 2] !== 2\'bxx && 1\'b0) $stop;
+ // verilator lint_on SELRANGE
+`else
+ if (mi[-1] !== 1\'bx) $stop;
+ if (mi[0 -: 2] !== 2\'b1x) $stop;
+ if (mi[-1 -: 2] !== 2\'bxx) $stop;
+`endif
+ end
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t mi = 44\'h123;
+\t end
+\t if (cyc==2) begin
+\t index = 6\'d43;
+\t indexi = 43;
+\t end
+\t if (cyc==3) begin
+\t read = mi[index];
+\t if (read!==1\'b0) $stop;
+\t read = mi[indexi];
+\t if (read!==1\'b0) $stop;
+\t end
+\t if (cyc==4) begin
+\t index = 6\'d44;
+\t indexi = 44;
+\t end
+\t if (cyc==5) begin
+\t read = mi[index];
+\t $display(""-Illegal read value: %x"",read);
+\t //if (read!==1\'b1 && read!==1\'bx) $stop;
+\t read = mi[indexi];
+\t $display(""-Illegal read value: %x"",read);
+\t //if (read!==1\'b1 && read!==1\'bx) $stop;
+\t end
+\t if (cyc==6) begin
+\t indexi = -1;
+\t end
+\t if (cyc==7) begin
+\t read = mi[indexi];
+\t $display(""-Illegal read value: %x"",read);
+\t //if (read!==1\'b1 && read!==1\'bx) $stop;
+\t end
+\t if (cyc==10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire input_signal = crc[0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire\t\t\toutput_signal;\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .output_signal\t\t(output_signal),
+\t // Inputs
+\t .input_signal\t\t(input_signal));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {63\'h0, output_signal};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= \'0;
+ end
+ else if (cyc<10) begin
+\t sum <= \'0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h765b2e12b25ec97b
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (
+ input input_signal,
+ output output_signal
+ );
+
+ // bug872
+
+ // verilator lint_off UNOPTFLAT
+ wire some_signal[1:0][1:0];
+ assign some_signal[0][0] = input_signal;
+ assign some_signal[0][1] = some_signal[0][0];
+ assign some_signal[1][0] = some_signal[0][1];
+ assign some_signal[1][1] = some_signal[1][0];
+ assign output_signal = some_signal[1][1];
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ q0, q1, q2, q3, q4, q5, q6a, q6b,
+ // Inputs
+ clk, d, rst0_n
+ );
+ input clk;
+ input d;
+
+ // OK -- from primary
+ input rst0_n;
+ output wire q0;
+ Flop flop0 (.q(q0), .rst_n(rst0_n), .clk(clk), .d(d));
+
+ // OK -- from flop
+ reg \t rst1_n;
+ always @ (posedge clk) rst1_n <= rst0_n;
+ output wire q1;
+ Flop flop1 (.q(q1), .rst_n(rst1_n), .clk(clk), .d(d));
+
+ // Bad - logic
+ wire rst2_bad_n = rst0_n | rst1_n;
+ output wire q2;
+ Flop flop2 (.q(q2), .rst_n(rst2_bad_n), .clk(clk), .d(d));
+
+ // Bad - logic in submodule
+ wire rst3_bad_n;
+ Sub sub (.z(rst3_bad_n), .a(rst0_n), .b(rst1_n));
+ output wire q3;
+ Flop flop3 (.q(q3), .rst_n(rst3_bad_n), .clk(clk), .d(d));
+
+ // OK - bit selection
+ reg [3:0] rst4_n;
+ always @ (posedge clk) rst4_n <= {4{rst0_n}};
+ output wire q4;
+ Flop flop4 (.q(q4), .rst_n(rst4_n[1]), .clk(clk), .d(d));
+
+ // Bad - logic, but waived
+ // verilator lint_off CDCRSTLOGIC
+ wire rst5_waive_n = rst0_n & rst1_n;
+ // verilator lint_on CDCRSTLOGIC
+ output wire q5;
+ Flop flop5 (.q(q5), .rst_n(rst5_waive_n), .clk(clk), .d(d));
+
+ // Bad - for graph test - logic feeds two signals, three destinations
+ wire rst6_bad_n = rst0_n ^ rst1_n;
+ wire rst6a_bad_n = rst6_bad_n ^ $c1(""0""); // $c prevents optimization
+ wire rst6b_bad_n = rst6_bad_n ^ $c1(""1"");
+ output wire q6a;
+ output wire q6b;
+ Flop flop6a (.q(q6a), .rst_n(rst6a_bad_n), .clk(clk), .d(d));
+ Flop flop6v (.q(q6b), .rst_n(rst6b_bad_n), .clk(clk), .d(d));
+
+ initial begin
+ $display(""%%Error: Not a runnable test"");
+ $stop;
+ end
+
+endmodule
+
+module Flop (
+\t input clk,
+\t input d,
+\t input rst_n,
+\t output q);
+
+ always @ (posedge clk or negedge rst_n) begin
+ if (!rst_n) q <= 1\'b0;
+ else q <= d;
+ end
+endmodule
+
+module Sub (input a, b,
+\t output z);
+ wire \t z = a|b;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Jie Xu.
+//
+// The test was added together with the concat optimization.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg [31:0] in_a;
+ reg [31:0] in_b;
+ reg [31:0] in_c;
+ reg [31:0] in_d;
+ reg [31:0] in_e;
+ reg [15:0] in_f;
+ wire [31:0] in_g;
+
+ assign in_g = in_a << 4;
+
+ reg [31:0] out_x;
+ reg [31:0] out_y;
+ reg [31:0] out_z;
+ reg [31:0] out_o;
+ reg [31:0] out_p;
+ reg [31:0] out_q;
+
+ assign out_x = {in_a[31:16] & in_f, in_a[15:0] & in_f};
+ assign out_y = {in_a[31:18] & in_b[31:18], in_a[17:0] & in_b[17:0]};
+ assign out_z = {in_c[31:14] & in_d[31:14] & in_e[31:14], in_c[13:0] & in_d[13:0] & in_e[13:0]};
+ assign out_o = out_z | out_y;
+ assign out_p = {in_a[31:16] & in_f | in_e[31:16], in_a[15:0] & in_f | in_e[15:0]};
+ assign out_q = {{in_a[31:25] ^ in_g[31:25], in_a[24:16] ^ in_g[24:16]}, {in_a[15:5] ^ in_g[15:5], in_a[4:0] ^ in_g[4:0]}};
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+ in_a <= cyc;
+ in_b <= cyc + 1;
+ in_c <= cyc + 3;
+ in_d <= cyc + 8;
+ in_e <= cyc;
+ in_f <= cyc[15:0];
+
+ if (out_x != (in_a & {2{in_f}}))
+ $stop;
+ if (out_y != (in_a&in_b))
+ $stop;
+ if (out_z != (in_e&in_d&in_c))
+ $stop;
+ if (out_o != (((in_a&in_b)|(in_c&in_e&in_d))))
+ $stop;
+ if (out_p != (in_a & {2{in_f}} | in_e))
+ $stop;
+ if (out_q != (in_a ^ in_g))
+ $stop;
+
+\t if (cyc==100) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer cyc; initial cyc=0;
+ reg [63:0] crc;
+ reg [63:0] sum;
+
+ wire [31:0] out1;
+ wire [31:0] out2;
+ sub sub (.in1(crc[15:0]), .in2(crc[31:16]), .out1(out1), .out2);
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x sum=%x out=%x %x\
+"",$time, cyc, crc, sum, out1, out2);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= {sum[62:0], sum[63]^sum[2]^sum[0]} ^ {out2,out1};
+ if (cyc==1) begin
+\t // Setup
+\t crc <= 64\'h00000000_00000097;
+\t sum <= 64\'h0;
+ end
+ else if (cyc==90) begin
+\t if (sum !== 64\'he396068aba3898a2) $stop;
+ end
+ else if (cyc==91) begin
+ end
+ else if (cyc==92) begin
+ end
+ else if (cyc==93) begin
+ end
+ else if (cyc==94) begin
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module sub (/*AUTOARG*/
+ // Outputs
+ out1, out2,
+ // Inputs
+ in1, in2
+ );
+
+ input [15:0] in1;
+ input [15:0] in2;
+ output reg signed [31:0] out1;
+ output reg unsigned [31:0] out2;
+
+ always @* begin
+ // verilator lint_off WIDTH
+ out1 = $signed(in1) * $signed(in2);
+ out2 = $unsigned(in1) * $unsigned(in2);
+ // verilator lint_on WIDTH
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+package p3;
+ typedef enum logic [2:0] {
+ ZERO = 3\'b0,
+ ONE = 3\'b1 } e3_t /*verilator public*/;
+endpackage
+
+package p62;
+ typedef enum logic [62:0] {
+ ZERO = \'0,
+ ALLONE = \'1 } e62_t /*verilator public*/;
+endpackage
+
+module t (/*AUTOARG*/);
+
+ enum integer {
+\t\t EI_A,
+\t\t EI_B,
+\t\t EI_C
+\t\t } m_state;
+
+ initial begin
+ m_state = EI_A;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+"
+"// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Lane Brooks
+
+module t (/*AUTOARG*/
+ // Outputs
+ o3, o34, o345,
+ // Inputs
+ i3, i34, i345
+ );
+ input [15:0] i3;
+ output wire [15:0] o3;
+ input [15:0] i34 [3:0];
+ output wire [15:0] o34 [3:0];
+ input [15:0] i345 [3:0][4:0];
+ output wire [15:0] o345 [3:0][4:0];
+
+ sub sub (.*);
+endmodule
+
+module sub (/*AUTOARG*/
+ // Outputs
+ o3, o34, o345,
+ // Inputs
+ i3, i34, i345
+ );
+ input [15:0] i3;
+ output wire [15:0] o3;
+ input [15:0] i34 [3:0];
+ output wire [15:0] o34 [3:0];
+ input [15:0] i345 [3:0][4:0];
+ output wire [15:0] o345 [3:0][4:0];
+
+ assign o3 = i3;
+ assign o34 = i34;
+ assign o345 = i345;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ const logic [2:0] five = 3\'d5;
+
+ const logic unsigned [31:0] var_const = 22;
+ logic [7:0] res_const;
+ assign res_const = var_const[7:0]; // bug693
+
+ always @ (posedge clk) begin
+ if (five !== 3\'d5) $stop;
+ if (res_const !== 8\'d22) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION:tor:ilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ wire [31:0] o;
+ wire [31:0] oe;
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .o\t\t\t(o[31:0]),
+\t .oe\t\t\t(oe[31:0]));
+
+ // Test loop
+ always @ (posedge clk) begin
+ if (o !== 32\'h00000001) $stop;
+ if (oe !== 32\'h00000001) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+module subimp(o,oe);
+ output [31:0] o;
+ assign o = 32\'h12345679;
+ output [31:0] oe;
+ assign oe = 32\'hab345679;
+endmodule
+
+module Test(o,oe);
+ output [31:0] o;
+ output [31:0] oe;
+ wire [31:0] \t xe;
+ assign xe[31:1] = 0;
+ // verilator lint_off IMPLICIT
+ // verilator lint_off WIDTH
+ subimp subimp(x,\t // x is implicit and one bit
+\t\t xe[0]); // xe explicit one bit
+ assign o = x;
+ assign oe = xe;
+ // verilator lint_on WIDTH
+ // verilator lint_on IMPLICIT
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+//
+// This is a copy of t_param.v with the parentheses around the module parameters
+// removed.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ parameter PAR = 3;
+
+ m1 #PAR m1();
+ m3 #PAR m3();
+ mnooverride #10 mno();
+
+ input clk;
+ integer cyc=1;
+ reg [4:0] bitsel;
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+\t bitsel = 0;
+\t if (PAR[bitsel]!==1\'b1) $stop;
+\t bitsel = 1;
+\t if (PAR[bitsel]!==1\'b1) $stop;
+\t bitsel = 2;
+\t if (PAR[bitsel]!==1\'b0) $stop;
+ end
+ if (cyc==1) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module m1;
+ localparam PAR1MINUS1 = PAR1DUP-2-1;
+ localparam PAR1DUP = PAR1+2; // Check we propagate parameters properly
+ parameter PAR1 = 0;
+ m2 #PAR1MINUS1 m2 ();
+endmodule
+
+module m2;
+ parameter PAR2 = 10;
+ initial begin
+ $display(""%x"",PAR2);
+ if (PAR2 !== 2) $stop;
+ end
+endmodule
+
+module m3;
+ localparam LOC = 13;
+ parameter PAR = 10;
+ initial begin
+ $display(""%x %x"",LOC,PAR);
+ if (LOC !== 13) $stop;
+ if (PAR !== 3) $stop;
+ end
+endmodule
+
+module mnooverride;
+ localparam LOC = 13;
+ parameter PAR = 10;
+ initial begin
+ $display(""%x %x"",LOC,PAR);
+ if (LOC !== 13) $stop;
+ if (PAR !== 10) $stop;
+ end
+endmodule
+"
+"// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Lane Brooks
+
+module top (input SEL, input[1:0] A, output W, output X, output Y, output Z);
+ mux mux2 (.A(A), .SEL(SEL), .Z(W));
+
+ pass mux1 (.A(A), .SEL(SEL), .Z(X));
+
+ tbuf mux0[1:0] (.A(A), .OE({SEL,!SEL}), .Z(Y));
+
+ assign Z = ( SEL) ? A[1] : 1\'bz;
+ tbuf tbuf (.A(A[0]), .OE(!SEL), .Z(Z));
+endmodule
+
+module pass (input[1:0] A, input SEL, output Z);
+ tbuf tbuf1 (.A(A[1]), .OE(SEL), .Z(Z));
+ tbuf tbuf0 (.A(A[0]), .OE(!SEL),.Z(Z));
+endmodule
+
+module tbuf (input A, input OE, output Z);
+`ifdef T_BUFIF0
+ bufif0 (Z, A, !OE);
+`elsif T_BUFIF1
+ bufif1 (Z, A, OE);
+`elsif T_NOTIF0
+ notif0 (Z, !A, !OE);
+`elsif T_NOTIF1
+ notif1 (Z, !A, OE);
+`elsif T_PMOS
+ pmos (Z, A, !OE);
+`elsif T_NMOS
+ nmos (Z, A, OE);
+`elsif T_COND
+ assign Z = (OE) ? A : 1\'bz;
+`else
+ `error ""Unknown test name""
+`endif
+endmodule
+
+module mux (input[1:0] A, input SEL, output Z);
+ assign Z = (SEL) ? A[1] : 1\'bz;
+ assign Z = (!SEL)? A[0] : 1\'bz;
+ assign Z = 1\'bz;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+// bug291
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer out18;
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire\t\t\tout1;\t\t\t// From test of Test.v
+ wire\t\t\tout19;\t\t\t// From test of Test.v
+ wire\t\t\tout1b;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out1\t\t\t(out1),
+\t .out18\t\t\t(out18),
+\t .out1b\t\t\t(out1b),
+\t .out19\t\t\t(out19));
+
+ // Test loop
+ always @ (posedge clk) begin
+ if (out1 !== 1\'b1) $stop;
+ if (out18 !== 32\'h18) $stop;
+ if (out1b !== 1\'b1) $stop;
+ if (out19 !== 1\'b1) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+module Test (
+\t output wire out1 = 1\'b1,
+\t output integer out18 = 32\'h18,
+\t output var out1b = 1\'b1,
+\t output var logic out19 = 1\'b1
+\t );
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+`include ""verilated.v""
+
+module t_case_write1_tasks ();
+
+ // verilator lint_off WIDTH
+ // verilator lint_off CASEINCOMPLETE
+
+ parameter STRLEN = 78;
+ task ozonerab;
+ input [6:0] rab;
+ inout [STRLEN*8:1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (rab[6:0])
+\t 7\'h00 : foobar = {foobar, "" 0""};
+\t 7\'h01 : foobar = {foobar, "" 1""};
+\t 7\'h02 : foobar = {foobar, "" 2""};
+\t 7\'h03 : foobar = {foobar, "" 3""};
+\t 7\'h04 : foobar = {foobar, "" 4""};
+\t 7\'h05 : foobar = {foobar, "" 5""};
+\t 7\'h06 : foobar = {foobar, "" 6""};
+\t 7\'h07 : foobar = {foobar, "" 7""};
+\t 7\'h08 : foobar = {foobar, "" 8""};
+\t 7\'h09 : foobar = {foobar, "" 9""};
+\t 7\'h0a : foobar = {foobar, "" 10""};
+\t 7\'h0b : foobar = {foobar, "" 11""};
+\t 7\'h0c : foobar = {foobar, "" 12""};
+\t 7\'h0d : foobar = {foobar, "" 13""};
+\t 7\'h0e : foobar = {foobar, "" 14""};
+\t 7\'h0f : foobar = {foobar, "" 15""};
+\t 7\'h10 : foobar = {foobar, "" 16""};
+\t 7\'h11 : foobar = {foobar, "" 17""};
+\t 7\'h12 : foobar = {foobar, "" 18""};
+\t 7\'h13 : foobar = {foobar, "" 19""};
+\t 7\'h14 : foobar = {foobar, "" 20""};
+\t 7\'h15 : foobar = {foobar, "" 21""};
+\t 7\'h16 : foobar = {foobar, "" 22""};
+\t 7\'h17 : foobar = {foobar, "" 23""};
+\t 7\'h18 : foobar = {foobar, "" 24""};
+\t 7\'h19 : foobar = {foobar, "" 25""};
+\t 7\'h1a : foobar = {foobar, "" 26""};
+\t 7\'h1b : foobar = {foobar, "" 27""};
+\t 7\'h1c : foobar = {foobar, "" 28""};
+\t 7\'h1d : foobar = {foobar, "" 29""};
+\t 7\'h1e : foobar = {foobar, "" 30""};
+\t 7\'h1f : foobar = {foobar, "" 31""};
+\t 7\'h20 : foobar = {foobar, "" 32""};
+\t 7\'h21 : foobar = {foobar, "" 33""};
+\t 7\'h22 : foobar = {foobar, "" 34""};
+\t 7\'h23 : foobar = {foobar, "" 35""};
+\t 7\'h24 : foobar = {foobar, "" 36""};
+\t 7\'h25 : foobar = {foobar, "" 37""};
+\t 7\'h26 : foobar = {foobar, "" 38""};
+\t 7\'h27 : foobar = {foobar, "" 39""};
+\t 7\'h28 : foobar = {foobar, "" 40""};
+\t 7\'h29 : foobar = {foobar, "" 41""};
+\t 7\'h2a : foobar = {foobar, "" 42""};
+\t 7\'h2b : foobar = {foobar, "" 43""};
+\t 7\'h2c : foobar = {foobar, "" 44""};
+\t 7\'h2d : foobar = {foobar, "" 45""};
+\t 7\'h2e : foobar = {foobar, "" 46""};
+\t 7\'h2f : foobar = {foobar, "" 47""};
+\t 7\'h30 : foobar = {foobar, "" 48""};
+\t 7\'h31 : foobar = {foobar, "" 49""};
+\t 7\'h32 : foobar = {foobar, "" 50""};
+\t 7\'h33 : foobar = {foobar, "" 51""};
+\t 7\'h34 : foobar = {foobar, "" 52""};
+\t 7\'h35 : foobar = {foobar, "" 53""};
+\t 7\'h36 : foobar = {foobar, "" 54""};
+\t 7\'h37 : foobar = {foobar, "" 55""};
+\t 7\'h38 : foobar = {foobar, "" 56""};
+\t 7\'h39 : foobar = {foobar, "" 57""};
+\t 7\'h3a : foobar = {foobar, "" 58""};
+\t 7\'h3b : foobar = {foobar, "" 59""};
+\t 7\'h3c : foobar = {foobar, "" 60""};
+\t 7\'h3d : foobar = {foobar, "" 61""};
+\t 7\'h3e : foobar = {foobar, "" 62""};
+\t 7\'h3f : foobar = {foobar, "" 63""};
+\t 7\'h40 : foobar = {foobar, "" 64""};
+\t 7\'h41 : foobar = {foobar, "" 65""};
+\t 7\'h42 : foobar = {foobar, "" 66""};
+\t 7\'h43 : foobar = {foobar, "" 67""};
+\t 7\'h44 : foobar = {foobar, "" 68""};
+\t 7\'h45 : foobar = {foobar, "" 69""};
+\t 7\'h46 : foobar = {foobar, "" 70""};
+\t 7\'h47 : foobar = {foobar, "" 71""};
+\t 7\'h48 : foobar = {foobar, "" 72""};
+\t 7\'h49 : foobar = {foobar, "" 73""};
+\t 7\'h4a : foobar = {foobar, "" 74""};
+\t 7\'h4b : foobar = {foobar, "" 75""};
+\t 7\'h4c : foobar = {foobar, "" 76""};
+\t 7\'h4d : foobar = {foobar, "" 77""};
+\t 7\'h4e : foobar = {foobar, "" 78""};
+\t 7\'h4f : foobar = {foobar, "" 79""};
+\t 7\'h50 : foobar = {foobar, "" 80""};
+\t 7\'h51 : foobar = {foobar, "" 81""};
+\t 7\'h52 : foobar = {foobar, "" 82""};
+\t 7\'h53 : foobar = {foobar, "" 83""};
+\t 7\'h54 : foobar = {foobar, "" 84""};
+\t 7\'h55 : foobar = {foobar, "" 85""};
+\t 7\'h56 : foobar = {foobar, "" 86""};
+\t 7\'h57 : foobar = {foobar, "" 87""};
+\t 7\'h58 : foobar = {foobar, "" 88""};
+\t 7\'h59 : foobar = {foobar, "" 89""};
+\t 7\'h5a : foobar = {foobar, "" 90""};
+\t 7\'h5b : foobar = {foobar, "" 91""};
+\t 7\'h5c : foobar = {foobar, "" 92""};
+\t 7\'h5d : foobar = {foobar, "" 93""};
+\t 7\'h5e : foobar = {foobar, "" 94""};
+\t 7\'h5f : foobar = {foobar, "" 95""};
+\t 7\'h60 : foobar = {foobar, "" 96""};
+\t 7\'h61 : foobar = {foobar, "" 97""};
+\t 7\'h62 : foobar = {foobar, "" 98""};
+\t 7\'h63 : foobar = {foobar, "" 99""};
+\t 7\'h64 : foobar = {foobar, "" 100""};
+\t 7\'h65 : foobar = {foobar, "" 101""};
+\t 7\'h66 : foobar = {foobar, "" 102""};
+\t 7\'h67 : foobar = {foobar, "" 103""};
+\t 7\'h68 : foobar = {foobar, "" 104""};
+\t 7\'h69 : foobar = {foobar, "" 105""};
+\t 7\'h6a : foobar = {foobar, "" 106""};
+\t 7\'h6b : foobar = {foobar, "" 107""};
+\t 7\'h6c : foobar = {foobar, "" 108""};
+\t 7\'h6d : foobar = {foobar, "" 109""};
+\t 7\'h6e : foobar = {foobar, "" 110""};
+\t 7\'h6f : foobar = {foobar, "" 111""};
+\t 7\'h70 : foobar = {foobar, "" 112""};
+\t 7\'h71 : foobar = {foobar, "" 113""};
+\t 7\'h72 : foobar = {foobar, "" 114""};
+\t 7\'h73 : foobar = {foobar, "" 115""};
+\t 7\'h74 : foobar = {foobar, "" 116""};
+\t 7\'h75 : foobar = {foobar, "" 117""};
+\t 7\'h76 : foobar = {foobar, "" 118""};
+\t 7\'h77 : foobar = {foobar, "" 119""};
+\t 7\'h78 : foobar = {foobar, "" 120""};
+\t 7\'h79 : foobar = {foobar, "" 121""};
+\t 7\'h7a : foobar = {foobar, "" 122""};
+\t 7\'h7b : foobar = {foobar, "" 123""};
+\t 7\'h7c : foobar = {foobar, "" 124""};
+\t 7\'h7d : foobar = {foobar, "" 125""};
+\t 7\'h7e : foobar = {foobar, "" 126""};
+\t 7\'h7f : foobar = {foobar, "" 127""};
+\t default:foobar = {foobar, "" 128""};
+\t endcase
+ end
+
+ endtask
+
+ task ozonerb;
+ input [5:0] rb;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (rb[5:0])
+\t 6\'h10,
+\t 6\'h17,
+\t 6\'h1e,
+\t 6\'h1f: foobar = {foobar, "" 129""};
+\t default: ozonerab({1\'b1, rb}, foobar);
+\t endcase
+ end
+ endtask
+
+ task ozonef3f4_iext;
+ input [1:0] foo;
+ input [15:0] im16;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (foo)
+\t 2\'h0 :
+ begin
+\t\tskyway({4{im16[15]}}, foobar);
+\t\tskyway({4{im16[15]}}, foobar);
+\t\tskyway(im16[15:12], foobar);
+\t\tskyway(im16[11: 8], foobar);
+\t\tskyway(im16[ 7: 4], foobar);
+\t\tskyway(im16[ 3:0], foobar);
+\t\tfoobar = {foobar, "" 130""};
+ end
+\t 2\'h1 :
+ begin
+\t\tfoobar = {foobar, "" 131""};
+\t\tskyway(im16[15:12], foobar);
+\t\tskyway(im16[11: 8], foobar);
+\t\tskyway(im16[ 7: 4], foobar);
+\t\tskyway(im16[ 3:0], foobar);
+ end
+\t 2\'h2 :
+ begin
+\t\tskyway({4{im16[15]}}, foobar);
+\t\tskyway({4{im16[15]}}, foobar);
+\t\tskyway(im16[15:12], foobar);
+\t\tskyway(im16[11: 8], foobar);
+\t\tskyway(im16[ 7: 4], foobar);
+\t\tskyway(im16[ 3:0], foobar);
+\t\tfoobar = {foobar, "" 132""};
+ end
+\t 2\'h3 :
+ begin
+\t\tfoobar = {foobar, "" 133""};
+\t\tskyway(im16[15:12], foobar);
+\t\tskyway(im16[11: 8], foobar);
+\t\tskyway(im16[ 7: 4], foobar);
+\t\tskyway(im16[ 3:0], foobar);
+ end
+\t endcase
+ end
+ endtask
+
+ task skyway;
+ input [ 3:0] hex;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (hex)
+\t 4\'h0 : foobar = {foobar, "" 134""};
+\t 4\'h1 : foobar = {foobar, "" 135""};
+\t 4\'h2 : foobar = {foobar, "" 136""};
+\t 4\'h3 : foobar = {foobar, "" 137""};
+\t 4\'h4 : foobar = {foobar, "" 138""};
+\t 4\'h5 : foobar = {foobar, "" 139""};
+\t 4\'h6 : foobar = {foobar, "" 140""};
+\t 4\'h7 : foobar = {foobar, "" 141""};
+\t 4\'h8 : foobar = {foobar, "" 142""};
+\t 4\'h9 : foobar = {foobar, "" 143""};
+\t 4\'ha : foobar = {foobar, "" 144""};
+\t 4\'hb : foobar = {foobar, "" 145""};
+\t 4\'hc : foobar = {foobar, "" 146""};
+\t 4\'hd : foobar = {foobar, "" 147""};
+\t 4\'he : foobar = {foobar, "" 148""};
+\t 4\'hf : foobar = {foobar, "" 149""};
+\t endcase
+ end
+ endtask
+
+ task ozonesr;
+ input [ 15:0] foo;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (foo[11: 9])
+\t 3\'h0 : foobar = {foobar, "" 158""};
+\t 3\'h1 : foobar = {foobar, "" 159""};
+\t 3\'h2 : foobar = {foobar, "" 160""};
+\t 3\'h3 : foobar = {foobar, "" 161""};
+\t 3\'h4 : foobar = {foobar, "" 162""};
+\t 3\'h5 : foobar = {foobar, "" 163""};
+\t 3\'h6 : foobar = {foobar, "" 164""};
+\t 3\'h7 : foobar = {foobar, "" 165""};
+\t endcase
+ end
+ endtask
+
+ task ozonejk;
+ input k;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t if (k)
+\t foobar = {foobar, "" 166""};
+\t else
+\t foobar = {foobar, "" 167""};
+ end
+ endtask
+
+ task ozoneae;
+ input [ 2:0] ae;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (ae)
+\t 3\'b000 : foobar = {foobar, "" 168""};
+\t 3\'b001 : foobar = {foobar, "" 169""};
+\t 3\'b010 : foobar = {foobar, "" 170""};
+\t 3\'b011 : foobar = {foobar, "" 171""};
+\t 3\'b100 : foobar = {foobar, "" 172""};
+\t 3\'b101 : foobar = {foobar, "" 173""};
+\t 3\'b110 : foobar = {foobar, "" 174""};
+\t 3\'b111 : foobar = {foobar, "" 175""};
+\t endcase
+ end
+ endtask
+
+ task ozoneaee;
+ input [ 2:0] aee;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (aee)
+\t 3\'b001,
+\t 3\'b011,
+\t 3\'b101,
+\t 3\'b111 : foobar = {foobar, "" 176""};
+\t 3\'b000 : foobar = {foobar, "" 177""};
+\t 3\'b010 : foobar = {foobar, "" 178""};
+\t 3\'b100 : foobar = {foobar, "" 179""};
+\t 3\'b110 : foobar = {foobar, "" 180""};
+\t endcase
+ end
+ endtask
+
+ task ozoneape;
+ input [ 2:0] ape;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (ape)
+\t 3\'b001,
+\t 3\'b011,
+\t 3\'b101,
+\t 3\'b111 : foobar = {foobar, "" 181""};
+\t 3\'b000 : foobar = {foobar, "" 182""};
+\t 3\'b010 : foobar = {foobar, "" 183""};
+\t 3\'b100 : foobar = {foobar, "" 184""};
+\t 3\'b110 : foobar = {foobar, "" 185""};
+\t endcase
+ end
+ endtask
+
+ task ozonef1;
+ input [ 31:0] foo;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (foo[24:21])
+\t 4\'h0 :
+ if (foo[26])
+ foobar = {foobar, "" 186""};
+ else
+ foobar = {foobar, "" 187""};
+\t 4\'h1 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar, "" 188""};
+ 2\'b01 : foobar = {foobar, "" 189""};
+ 2\'b10 : foobar = {foobar, "" 190""};
+ 2\'b11 : foobar = {foobar, "" 191""};
+ endcase
+\t 4\'h2 : foobar = {foobar, "" 192""};
+\t 4\'h3 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar, "" 193""};
+ 2\'b01 : foobar = {foobar, "" 194""};
+ 2\'b10 : foobar = {foobar, "" 195""};
+ 2\'b11 : foobar = {foobar, "" 196""};
+ endcase
+\t 4\'h4 :
+ if (foo[26])
+ foobar = {foobar, "" 197""};
+ else
+ foobar = {foobar, "" 198""};
+\t 4\'h5 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar, "" 199""};
+ 2\'b01 : foobar = {foobar, "" 200""};
+ 2\'b10 : foobar = {foobar, "" 201""};
+ 2\'b11 : foobar = {foobar, "" 202""};
+ endcase
+\t 4\'h6 : foobar = {foobar, "" 203""};
+\t 4\'h7 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar, "" 204""};
+ 2\'b01 : foobar = {foobar, "" 205""};
+ 2\'b10 : foobar = {foobar, "" 206""};
+ 2\'b11 : foobar = {foobar, "" 207""};
+ endcase
+\t 4\'h8 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar, "" 208""};
+ 2\'b01 : foobar = {foobar, "" 209""};
+ 2\'b10 : foobar = {foobar, "" 210""};
+ 2\'b11 : foobar = {foobar, "" 211""};
+ endcase
+\t 4\'h9 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar, "" 212""};
+ 2\'b01 : foobar = {foobar, "" 213""};
+ 2\'b10 : foobar = {foobar, "" 214""};
+ 2\'b11 : foobar = {foobar, "" 215""};
+ endcase
+\t 4\'ha :
+ if (foo[25])
+ foobar = {foobar, "" 216""};
+ else
+ foobar = {foobar, "" 217""};
+\t 4\'hb :
+ if (foo[25])
+ foobar = {foobar, "" 218""};
+ else
+ foobar = {foobar, "" 219""};
+\t 4\'hc :
+ if (foo[26])
+ foobar = {foobar, "" 220""};
+ else
+ foobar = {foobar, "" 221""};
+\t 4\'hd :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar, "" 222""};
+ 2\'b01 : foobar = {foobar, "" 223""};
+ 2\'b10 : foobar = {foobar, "" 224""};
+ 2\'b11 : foobar = {foobar, "" 225""};
+ endcase
+\t 4\'he :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar, "" 226""};
+ 2\'b01 : foobar = {foobar, "" 227""};
+ 2\'b10 : foobar = {foobar, "" 228""};
+ 2\'b11 : foobar = {foobar, "" 229""};
+ endcase
+\t 4\'hf :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar, "" 230""};
+ 2\'b01 : foobar = {foobar, "" 231""};
+ 2\'b10 : foobar = {foobar, "" 232""};
+ 2\'b11 : foobar = {foobar, "" 233""};
+ endcase
+\t endcase
+ end
+ endtask
+
+ task ozonef1e;
+ input [ 31:0] foo;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (foo[27:21])
+\t 7\'h00:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 234""};
+\t\tfoobar = {foobar, "" 235""};
+\t end
+\t 7\'h01:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 236""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 237""};
+\t\tfoobar = {foobar, "" 238""};
+\t end
+\t 7\'h02:
+\t foobar = {foobar, "" 239""};
+\t 7\'h03:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 240""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 241""};
+\t\tfoobar = {foobar, "" 242""};
+\t end
+\t 7\'h04:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 243""};
+\t\tfoobar = {foobar,"" 244""};
+\t end
+\t 7\'h05:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 245""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 246""};
+\t end
+\t 7\'h06:
+\t foobar = {foobar, "" 247""};
+\t 7\'h07:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 248""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 249""};
+\t end
+\t 7\'h08:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 250""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 251""};
+\t end
+\t 7\'h09:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 252""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 253""};
+\t end
+\t 7\'h0a:
+\t begin
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 254""};
+\t end
+\t 7\'h0b:
+\t begin
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 255""};
+\t end
+\t 7\'h0c:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 256""};
+\t end
+\t 7\'h0d:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 257""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 258""};
+\t end
+\t 7\'h0e:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 259""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 260""};
+\t end
+\t 7\'h0f:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 261""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 262""};
+\t end
+\t 7\'h10:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 263""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 264""};
+\t\tfoobar = {foobar, "" 265""};
+\t\tfoobar = {foobar, "" 266""};
+\t end
+\t 7\'h11:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 267""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 268""};
+\t\tfoobar = {foobar, "" 269""};
+\t\tfoobar = {foobar, "" 270""};
+\t end
+\t 7\'h12:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 271""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 272""};
+\t\tfoobar = {foobar, "" 273""};
+\t\tfoobar = {foobar, "" 274""};
+\t end
+\t 7\'h13:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 275""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 276""};
+\t\tfoobar = {foobar, "" 277""};
+\t\tfoobar = {foobar, "" 278""};
+\t end
+\t 7\'h14:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 279""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 280""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 281""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 282""};
+\t\tfoobar = {foobar, "" 283""};
+\t\tfoobar = {foobar, "" 284""};
+\t end
+\t 7\'h15:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 285""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 286""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 287""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 288""};
+\t\tfoobar = {foobar, "" 289""};
+\t\tfoobar = {foobar, "" 290""};
+\t end
+\t 7\'h16:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 291""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 292""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 293""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 294""};
+\t\tfoobar = {foobar, "" 295""};
+\t\tfoobar = {foobar, "" 296""};
+\t end
+\t 7\'h17:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 297""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 298""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 299""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 300""};
+\t\tfoobar = {foobar, "" 301""};
+\t\tfoobar = {foobar, "" 302""};
+\t end
+\t 7\'h18:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 303""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 304""};
+\t\tfoobar = {foobar, "" 305""};
+\t\tfoobar = {foobar, "" 306""};
+\t end
+\t 7\'h19:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 307""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 308""};
+\t\tfoobar = {foobar, "" 309""};
+\t\tfoobar = {foobar, "" 310""};
+\t end
+\t 7\'h1a:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 311""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 312""};
+\t\tfoobar = {foobar, "" 313""};
+\t\tfoobar = {foobar, "" 314""};
+\t end
+\t 7\'h1b:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 315""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 316""};
+\t\tfoobar = {foobar, "" 317""};
+\t\tfoobar = {foobar, "" 318""};
+\t end
+\t 7\'h1c:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 319""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 320""};
+\t\tfoobar = {foobar, "" 321""};
+\t\tfoobar = {foobar, "" 322""};
+\t end
+\t 7\'h1d:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 323""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 324""};
+\t\tfoobar = {foobar, "" 325""};
+\t\tfoobar = {foobar, "" 326""};
+\t end
+\t 7\'h1e:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 327""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 328""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 329""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 330""};
+\t\tfoobar = {foobar, "" 331""};
+\t\tfoobar = {foobar, "" 332""};
+\t end
+\t 7\'h1f:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 333""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 334""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 335""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 336""};
+\t\tfoobar = {foobar, "" 337""};
+\t\tfoobar = {foobar, "" 338""};
+\t end
+\t 7\'h20:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 339""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 340""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 341""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 342""};
+\t\tfoobar = {foobar, "" 343""};
+\t\tfoobar = {foobar, "" 344""};
+\t end
+\t 7\'h21:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 345""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 346""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 347""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 348""};
+\t\tfoobar = {foobar, "" 349""};
+\t\tfoobar = {foobar, "" 350""};
+\t end
+\t 7\'h22:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 351""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 352""};
+\t\tfoobar = {foobar, "" 353""};
+\t\tfoobar = {foobar, "" 354""};
+\t end
+\t 7\'h23:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 355""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 356""};
+\t\tfoobar = {foobar, "" 357""};
+\t\tfoobar = {foobar, "" 358""};
+\t end
+\t 7\'h24:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 359""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 360""};
+\t\tfoobar = {foobar, "" 361""};
+\t\tfoobar = {foobar, "" 362""};
+\t end
+\t 7\'h25:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 363""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 364""};
+\t\tfoobar = {foobar, "" 365""};
+\t\tfoobar = {foobar, "" 366""};
+\t end
+\t 7\'h26:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 367""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 368""};
+\t\tfoobar = {foobar, "" 369""};
+\t\tfoobar = {foobar, "" 370""};
+\t end
+\t 7\'h27:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 371""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 372""};
+\t\tfoobar = {foobar, "" 373""};
+\t\tfoobar = {foobar, "" 374""};
+\t end
+\t 7\'h28:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 375""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 376""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 377""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 378""};
+\t\tfoobar = {foobar, "" 379""};
+\t\tfoobar = {foobar, "" 380""};
+\t end
+\t 7\'h29:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 381""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 382""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 383""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 384""};
+\t\tfoobar = {foobar, "" 385""};
+\t\tfoobar = {foobar, "" 386""};
+\t end
+\t 7\'h2a:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 387""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 388""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 389""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 390""};
+\t\tfoobar = {foobar, "" 391""};
+\t\tfoobar = {foobar, "" 392""};
+\t end
+\t 7\'h2b:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 393""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 394""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 395""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 396""};
+\t\tfoobar = {foobar, "" 397""};
+\t\tfoobar = {foobar, "" 398""};
+\t end
+\t 7\'h2c:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 399""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 400""};
+\t\tfoobar = {foobar, "" 401""};
+\t\tfoobar = {foobar, "" 402""};
+\t end
+\t 7\'h2d:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 403""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 404""};
+\t\tfoobar = {foobar, "" 405""};
+\t\tfoobar = {foobar, "" 406""};
+\t end
+\t 7\'h2e:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 407""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 408""};
+\t\tfoobar = {foobar, "" 409""};
+\t\tfoobar = {foobar, "" 410""};
+\t end
+\t 7\'h2f:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 411""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 412""};
+\t\tfoobar = {foobar, "" 413""};
+\t\tfoobar = {foobar, "" 414""};
+\t end
+\t 7\'h30:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 415""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 416""};
+\t\tfoobar = {foobar, "" 417""};
+\t\tfoobar = {foobar, "" 418""};
+\t end
+\t 7\'h31:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 419""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 420""};
+\t\tfoobar = {foobar, "" 421""};
+\t\tfoobar = {foobar, "" 422""};
+\t end
+\t 7\'h32:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 423""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 424""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 425""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 426""};
+\t\tfoobar = {foobar, "" 427""};
+\t\tfoobar = {foobar, "" 428""};
+\t end
+\t 7\'h33:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 429""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 430""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 431""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 432""};
+\t\tfoobar = {foobar, "" 433""};
+\t\tfoobar = {foobar, "" 434""};
+\t end
+\t 7\'h34:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 435""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 436""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 437""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 438""};
+\t\tfoobar = {foobar, "" 439""};
+\t\tfoobar = {foobar, "" 440""};
+\t end
+\t 7\'h35:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 441""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 442""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 443""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 444""};
+\t\tfoobar = {foobar, "" 445""};
+\t\tfoobar = {foobar, "" 446""};
+\t end
+\t 7\'h36:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 447""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 448""};
+\t\tfoobar = {foobar, "" 449""};
+\t\tfoobar = {foobar, "" 450""};
+\t end
+\t 7\'h37:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 451""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 452""};
+\t\tfoobar = {foobar, "" 453""};
+\t\tfoobar = {foobar, "" 454""};
+\t end
+\t 7\'h38:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 455""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 456""};
+\t\tfoobar = {foobar, "" 457""};
+\t end
+\t 7\'h39:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 458""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 459""};
+\t\tfoobar = {foobar, "" 460""};
+\t end
+\t 7\'h3a:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 461""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 462""};
+\t\tfoobar = {foobar, "" 463""};
+\t end
+\t 7\'h3b:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 464""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 465""};
+\t\tfoobar = {foobar, "" 466""};
+\t end
+\t 7\'h3c:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 467""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 468""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 469""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 470""};
+\t\tfoobar = {foobar, "" 471""};
+\t end
+\t 7\'h3d:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 472""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 473""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 474""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 475""};
+\t\tfoobar = {foobar, "" 476""};
+\t end
+\t 7\'h3e:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 477""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 478""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 479""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 480""};
+\t\tfoobar = {foobar, "" 481""};
+\t end
+\t 7\'h3f:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 482""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 483""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 484""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 485""};
+\t\tfoobar = {foobar, "" 486""};
+\t end
+\t 7\'h40:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 487""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 488""};
+\t\tfoobar = {foobar, "" 489""};
+\t\tfoobar = {foobar, "" 490""};
+\t end
+\t 7\'h41:
+\t begin
+\t\tfoobar = {foobar, "" 491""};
+\t\tfoobar = {foobar, "" 492""};
+\t end
+\t 7\'h42:
+\t begin
+\t\tfoobar = {foobar, "" 493""};
+\t\tfoobar = {foobar, "" 494""};
+\t end
+\t 7\'h43:
+\t begin
+\t\tfoobar = {foobar, "" 495""};
+\t\tfoobar = {foobar, "" 496""};
+\t end
+\t 7\'h44:
+\t begin
+\t\tfoobar = {foobar, "" 497""};
+\t\tfoobar = {foobar, "" 498""};
+\t end
+\t 7\'h45:
+\t foobar = {foobar, "" 499""};
+\t 7\'h46:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 500""};
+\t\tfoobar = {foobar, "" 501""};
+\t\tfoobar = {foobar, "" 502""};
+\t end
+\t 7\'h47:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 503""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 504""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 505""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 506""};
+\t\tfoobar = {foobar, "" 507""};
+\t\tfoobar = {foobar, "" 508""};
+\t end
+\t 7\'h48:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 509""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 510""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 511""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 512""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 513""};
+\t end
+\t 7\'h49:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 514""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 515""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 516""};
+\t end
+\t 7\'h4a:
+ foobar = {foobar,"" 517""};
+\t 7\'h4b:
+ foobar = {foobar, "" 518""};
+\t 7\'h4c:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 519""};
+\t\tfoobar = {foobar, "" 520""};
+\t\tfoobar = {foobar, "" 521""};
+\t end
+\t 7\'h4d:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 522""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 523""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 524""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 525""};
+\t\tfoobar = {foobar, "" 526""};
+\t\tfoobar = {foobar, "" 527""};
+\t end
+\t 7\'h4e:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 528""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 529""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 530""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 531""};
+\t end
+\t 7\'h4f:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 532""};
+\t end
+\t 7\'h50:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 533""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 534""};
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 535""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 536""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 537""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 538""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 539""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 540""};
+\t end
+\t 7\'h51:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 541""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 542""};
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 543""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 544""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 545""};
+\t end
+\t 7\'h52:
+\t foobar = {foobar, "" 546""};
+\t 7\'h53:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar, "" 547""};
+\t end
+\t 7\'h54:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 548""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 549""};
+\t end
+\t 7\'h55:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 550""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 551""};
+\t end
+\t 7\'h56:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 552""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 553""};
+\t\tfoobar = {foobar, "" 554""};
+\t end
+\t 7\'h57:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 555""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 556""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 557""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 558""};
+\t end
+\t 7\'h58:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar, "" 559""};
+\t end
+\t 7\'h59:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 560""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 561""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 562""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 563""};
+\t end
+\t 7\'h5a:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 564""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar, "" 565""};
+\t end
+\t 7\'h5b:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 566""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar, "" 567""};
+\t end
+\t 7\'h5c:
+\t begin
+\t\tfoobar = {foobar,"" 568""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 569""};
+\t\tfoobar = {foobar,"" 570""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 571""};
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 572""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar, "" 573""};
+\t end
+\t 7\'h5d:
+\t begin
+\t\tfoobar = {foobar,"" 574""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 575""};
+\t\tfoobar = {foobar,"" 576""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 577""};
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 578""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar, "" 579""};
+\t end
+\t 7\'h5e:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 580""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar, "" 581""};
+\t end
+\t 7\'h5f:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 582""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 583""};
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 584""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 585""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 586""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 587""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 588""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 589""};
+\t end
+\t 7\'h60:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 590""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 591""};
+\t end
+\t 7\'h61:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 592""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 593""};
+\t end
+\t 7\'h62:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 594""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 595""};
+\t end
+\t 7\'h63:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 596""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 597""};
+\t end
+\t 7\'h64:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 598""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 599""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 600""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 601""};
+\t end
+\t 7\'h65:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 602""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 603""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 604""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 605""};
+\t end
+\t 7\'h66:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 606""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 607""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 608""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 609""};
+\t end
+\t 7\'h67:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 610""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 611""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 612""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 613""};
+\t end
+\t 7\'h68:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 614""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 615""};
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 616""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 617""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 618""};
+\t\tozoneape(foo[17:15], foobar);
+\t end
+\t 7\'h69:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 619""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 620""};
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 621""};
+\t end
+\t 7\'h6a:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 622""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 623""};
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 624""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 625""};
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 626""};
+\t\tozoneae(foo[17:15], foobar);
+\t end
+\t 7\'h6b:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 627""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 628""};
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 629""};
+\t end
+\t 7\'h6c:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 630""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 631""};
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 632""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 633""};
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 634""};
+\t\tozoneae(foo[17:15], foobar);
+\t end
+\t 7\'h6d:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 635""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 636""};
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 637""};
+\t end
+\t 7\'h6e:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 638""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 639""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 640""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 641""};
+\t end
+\t 7\'h6f:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 642""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 643""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 644""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 645""};
+\t end
+\t 7\'h70:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 646""};
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 647""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 648""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar, "" 649""};
+\t end
+\t 7\'h71:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 650""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar, "" 651""};
+\t end
+\t 7\'h72:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 652""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar, "" 653""};
+\t end
+\t 7\'h73:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 654""};
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 655""};
+\t\tozoneae(foo[17:15], foobar);
+\t end
+\t 7\'h74:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 656""};
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 657""};
+\t\tozoneae(foo[17:15], foobar);
+\t end
+\t 7\'h75:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 658""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 659""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 660""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 661""};
+\t\tfoobar = {foobar, "" 662""};
+\t\tfoobar = {foobar, "" 663""};
+\t end
+\t 7\'h76:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 664""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 665""};
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 666""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 667""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 668""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 669""};
+\t end
+\t 7\'h77:
+\t begin
+\t\tozoneaee(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 670""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 671""};
+\t\tozoneaee(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 672""};
+\t\tozoneape(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 673""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 674""};
+\t\tozoneape(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 675""};
+\t end
+\t 7\'h78,
+\t 7\'h79,
+\t 7\'h7a,
+\t 7\'h7b,
+\t 7\'h7c,
+\t 7\'h7d,
+\t 7\'h7e,
+\t 7\'h7f:
+ foobar = {foobar,"" 676""};
+\t endcase
+ end
+ endtask
+
+ task ozonef2;
+ input [ 31:0] foo;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (foo[24:21])
+\t 4\'h0 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 677""};
+ 2\'b01 : foobar = {foobar,"" 678""};
+ 2\'b10 : foobar = {foobar,"" 679""};
+ 2\'b11 : foobar = {foobar,"" 680""};
+ endcase
+\t 4\'h1 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 681""};
+ 2\'b01 : foobar = {foobar,"" 682""};
+ 2\'b10 : foobar = {foobar,"" 683""};
+ 2\'b11 : foobar = {foobar,"" 684""};
+ endcase
+\t 4\'h2 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 685""};
+ 2\'b01 : foobar = {foobar,"" 686""};
+ 2\'b10 : foobar = {foobar,"" 687""};
+ 2\'b11 : foobar = {foobar,"" 688""};
+ endcase
+\t 4\'h3 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 689""};
+ 2\'b01 : foobar = {foobar,"" 690""};
+ 2\'b10 : foobar = {foobar,"" 691""};
+ 2\'b11 : foobar = {foobar,"" 692""};
+ endcase
+\t 4\'h4 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 693""};
+ 2\'b01 : foobar = {foobar,"" 694""};
+ 2\'b10 : foobar = {foobar,"" 695""};
+ 2\'b11 : foobar = {foobar,"" 696""};
+ endcase
+\t 4\'h5 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 697""};
+ 2\'b01 : foobar = {foobar,"" 698""};
+ 2\'b10 : foobar = {foobar,"" 699""};
+ 2\'b11 : foobar = {foobar,"" 700""};
+ endcase
+\t 4\'h6 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 701""};
+ 2\'b01 : foobar = {foobar,"" 702""};
+ 2\'b10 : foobar = {foobar,"" 703""};
+ 2\'b11 : foobar = {foobar,"" 704""};
+ endcase
+\t 4\'h7 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 705""};
+ 2\'b01 : foobar = {foobar,"" 706""};
+ 2\'b10 : foobar = {foobar,"" 707""};
+ 2\'b11 : foobar = {foobar,"" 708""};
+ endcase
+\t 4\'h8 :
+ if (foo[26])
+ foobar = {foobar,"" 709""};
+ else
+ foobar = {foobar,"" 710""};
+\t 4\'h9 :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 711""};
+ 2\'b01 : foobar = {foobar,"" 712""};
+ 2\'b10 : foobar = {foobar,"" 713""};
+ 2\'b11 : foobar = {foobar,"" 714""};
+ endcase
+\t 4\'ha :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 715""};
+ 2\'b01 : foobar = {foobar,"" 716""};
+ 2\'b10 : foobar = {foobar,"" 717""};
+ 2\'b11 : foobar = {foobar,"" 718""};
+ endcase
+\t 4\'hb :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 719""};
+ 2\'b01 : foobar = {foobar,"" 720""};
+ 2\'b10 : foobar = {foobar,"" 721""};
+ 2\'b11 : foobar = {foobar,"" 722""};
+ endcase
+\t 4\'hc :
+ if (foo[26])
+ foobar = {foobar,"" 723""};
+ else
+ foobar = {foobar,"" 724""};
+\t 4\'hd :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 725""};
+ 2\'b01 : foobar = {foobar,"" 726""};
+ 2\'b10 : foobar = {foobar,"" 727""};
+ 2\'b11 : foobar = {foobar,"" 728""};
+ endcase
+\t 4\'he :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 729""};
+ 2\'b01 : foobar = {foobar,"" 730""};
+ 2\'b10 : foobar = {foobar,"" 731""};
+ 2\'b11 : foobar = {foobar,"" 732""};
+ endcase
+\t 4\'hf :
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar,"" 733""};
+ 2\'b01 : foobar = {foobar,"" 734""};
+ 2\'b10 : foobar = {foobar,"" 735""};
+ 2\'b11 : foobar = {foobar,"" 736""};
+ endcase
+\t endcase
+ end
+ endtask
+
+ task ozonef2e;
+ input [ 31:0] foo;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t casez (foo[25:21])
+\t 5\'h00 :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 737""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 738""};
+\t end
+\t 5\'h01 :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 739""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 740""};
+\t end
+\t 5\'h02 :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 741""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 742""};
+\t end
+\t 5\'h03 :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 743""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 744""};
+\t end
+\t 5\'h04 :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 745""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 746""};
+\t end
+\t 5\'h05 :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 747""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 748""};
+\t end
+\t 5\'h06 :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 749""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 750""};
+\t end
+\t 5\'h07 :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 751""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 752""};
+\t end
+\t 5\'h08 :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 753""};
+\t\tif (foo[ 6])
+\t\t foobar = {foobar,"" 754""};
+\t\telse
+\t\t foobar = {foobar,"" 755""};
+\t end
+\t 5\'h09 :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 756""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 757""};
+\t end
+\t 5\'h0a :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 758""};
+\t\tozoneae(foo[17:15], foobar);
+\t end
+\t 5\'h0b :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 759""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 760""};
+\t end
+\t 5\'h0c :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 761""};
+\t end
+\t 5\'h0d :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 762""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 763""};
+\t end
+\t 5\'h0e :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 764""};
+\t\tozoneae(foo[17:15], foobar);
+\t end
+\t 5\'h0f :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 765""};
+\t\tozoneae(foo[17:15], foobar);
+\t end
+\t 5\'h10 :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 766""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 767""};
+\t end
+\t 5\'h11 :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 768""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 769""};
+\t end
+\t 5\'h18 :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 770""};
+\t\tif (foo[ 6])
+\t\t foobar = {foobar,"" 771""};
+\t\telse
+\t\t foobar = {foobar,"" 772""};
+\t end
+\t 5\'h1a :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 773""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 774""};
+\t end
+\t 5\'h1b :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 775""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 776""};
+\t\tif (foo[ 6])
+\t\t foobar = {foobar,"" 777""};
+\t\telse
+\t\t foobar = {foobar,"" 778""};
+\t\tfoobar = {foobar,"" 779""};
+\t end
+\t 5\'h1c :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 780""};
+\t end
+\t 5\'h1d :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 781""};
+\t\tif (foo[ 6])
+\t\t foobar = {foobar,"" 782""};
+\t\telse
+\t\t foobar = {foobar,"" 783""};
+\t\tfoobar = {foobar,"" 784""};
+\t end
+\t 5\'h1e :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 785""};
+\t\tif (foo[ 6])
+\t\t foobar = {foobar,"" 786""};
+\t\telse
+\t\t foobar = {foobar,"" 787""};
+\t\tfoobar = {foobar,"" 788""};
+\t end
+\t 5\'h1f :
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 789""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 790""};
+\t\tif (foo[ 6])
+\t\t foobar = {foobar,"" 791""};
+\t\telse
+\t\t foobar = {foobar,"" 792""};
+\t\tfoobar = {foobar,"" 793""};
+\t end
+\t default :
+ foobar = {foobar,"" 794""};
+\t endcase
+ end
+ endtask
+
+ task ozonef3e;
+ input [ 31:0] foo;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (foo[25:21])
+\t 5\'h00,
+\t 5\'h01,
+\t 5\'h02:
+\t begin
+\t\t ozoneae(foo[20:18], foobar);
+\t\t case (foo[22:21])
+\t\t 2\'h0: foobar = {foobar,"" 795""};
+\t\t 2\'h1: foobar = {foobar,"" 796""};
+\t\t 2\'h2: foobar = {foobar,"" 797""};
+\t\t endcase
+\t\t ozoneae(foo[17:15], foobar);
+\t\t foobar = {foobar,"" 798""};
+\t\t if (foo[ 9])
+\t\t ozoneae(foo[ 8: 6], foobar);
+\t\t else
+\t\t ozonef3e_te(foo[ 8: 6], foobar);
+\t\t foobar = {foobar,"" 799""};
+\t end
+\t 5\'h08,
+\t 5\'h09,
+\t 5\'h0d,
+\t 5\'h0e,
+\t 5\'h0f:
+\t begin
+\t\t ozoneae(foo[20:18], foobar);
+\t\t foobar = {foobar,"" 800""};
+\t\t ozoneae(foo[17:15], foobar);
+\t\t case (foo[23:21])
+\t\t 3\'h0: foobar = {foobar,"" 801""};
+\t\t 3\'h1: foobar = {foobar,"" 802""};
+\t\t 3\'h5: foobar = {foobar,"" 803""};
+\t\t 3\'h6: foobar = {foobar,"" 804""};
+\t\t 3\'h7: foobar = {foobar,"" 805""};
+\t\t endcase
+\t\t if (foo[ 9])
+\t\t ozoneae(foo[ 8: 6], foobar);
+\t\t else
+\t\t ozonef3e_te(foo[ 8: 6], foobar);
+\t end
+\t 5\'h0a,
+\t 5\'h0b:
+\t begin
+\t\t ozoneae(foo[17:15], foobar);
+\t\t if (foo[21])
+\t\t foobar = {foobar,"" 806""};
+\t\t else
+\t\t foobar = {foobar,"" 807""};
+\t\t if (foo[ 9])
+\t\t ozoneae(foo[ 8: 6], foobar);
+\t\t else
+\t\t ozonef3e_te(foo[ 8: 6], foobar);
+\t end
+\t 5\'h0c:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 808""};
+\t\tif (foo[ 9])
+\t\t ozoneae(foo[ 8: 6], foobar);
+\t\telse
+\t\t ozonef3e_te(foo[ 8: 6], foobar);
+\t\tfoobar = {foobar,"" 809""};
+\t\tozoneae(foo[17:15], foobar);
+\t end
+\t 5\'h10,
+\t 5\'h11,
+\t 5\'h12,
+\t 5\'h13:
+\t begin
+\t\t ozoneae(foo[20:18], foobar);
+\t\t foobar = {foobar,"" 810""};
+\t\t ozoneae(foo[17:15], foobar);
+\t\t case (foo[22:21])
+\t\t 2\'h0,
+\t\t 2\'h2:
+\t\t\tfoobar = {foobar,"" 811""};
+\t\t 2\'h1,
+\t\t 2\'h3:
+\t\t\tfoobar = {foobar,"" 812""};
+\t\t endcase
+\t\t ozoneae(foo[ 8: 6], foobar);
+\t\t foobar = {foobar,"" 813""};
+\t\t ozoneae((foo[20:18]+1), foobar);
+\t\t foobar = {foobar,"" 814""};
+\t\t ozoneae((foo[17:15]+1), foobar);
+\t\t case (foo[22:21])
+\t\t 2\'h0,
+\t\t 2\'h3:
+\t\t\tfoobar = {foobar,"" 815""};
+\t\t 2\'h1,
+\t\t 2\'h2:
+\t\t\tfoobar = {foobar,"" 816""};
+\t\t endcase
+\t\t ozoneae((foo[ 8: 6]+1), foobar);
+\t end
+\t 5\'h18:
+\t begin
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 817""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 818""};
+\t\tozoneae(foo[ 8: 6], foobar);
+\t\tfoobar = {foobar,"" 819""};
+\t\tozoneae(foo[20:18], foobar);
+\t\tfoobar = {foobar,"" 820""};
+\t\tozoneae(foo[17:15], foobar);
+\t\tfoobar = {foobar,"" 821""};
+\t\tozoneae(foo[ 8: 6], foobar);
+\t end
+\t default :
+ foobar = {foobar,"" 822""};
+\t endcase
+ end
+ endtask
+ task ozonef3e_te;
+ input [ 2:0] te;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (te)
+\t 3\'b100 : foobar = {foobar, "" 823""};
+\t 3\'b101 : foobar = {foobar, "" 824""};
+\t 3\'b110 : foobar = {foobar, "" 825""};
+\t default: foobar = {foobar, "" 826""};
+\t endcase
+ end
+ endtask
+ task ozonearm;
+ input [ 2:0] ate;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (ate)
+\t 3\'b000 : foobar = {foobar, "" 827""};
+\t 3\'b001 : foobar = {foobar, "" 828""};
+\t 3\'b010 : foobar = {foobar, "" 829""};
+\t 3\'b011 : foobar = {foobar, "" 830""};
+\t 3\'b100 : foobar = {foobar, "" 831""};
+\t 3\'b101 : foobar = {foobar, "" 832""};
+\t 3\'b110 : foobar = {foobar, "" 833""};
+\t 3\'b111 : foobar = {foobar, "" 834""};
+\t endcase
+ end
+ endtask
+ task ozonebmuop;
+ input [ 4:0] f4;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (f4[ 4:0])
+\t 5\'h00,
+\t 5\'h04 :
+ foobar = {foobar, "" 835""};
+\t 5\'h01,
+\t 5\'h05 :
+ foobar = {foobar, "" 836""};
+\t 5\'h02,
+\t 5\'h06 :
+ foobar = {foobar, "" 837""};
+\t 5\'h03,
+\t 5\'h07 :
+ foobar = {foobar, "" 838""};
+\t 5\'h08,
+\t 5\'h18 :
+ foobar = {foobar, "" 839""};
+\t 5\'h09,
+\t 5\'h19 :
+ foobar = {foobar, "" 840""};
+\t 5\'h0a,
+\t 5\'h1a :
+ foobar = {foobar, "" 841""};
+\t 5\'h0b :
+ foobar = {foobar, "" 842""};
+\t 5\'h1b :
+ foobar = {foobar, "" 843""};
+\t 5\'h0c,
+\t 5\'h1c :
+ foobar = {foobar, "" 844""};
+\t 5\'h0d,
+\t 5\'h1d :
+ foobar = {foobar, "" 845""};
+\t 5\'h1e :
+ foobar = {foobar, "" 846""};
+\t endcase
+ end
+ endtask
+ task ozonef3;
+ input [ 31:0] foo;
+ inout [STRLEN*8: 1] foobar;
+ reg \t\t nacho;
+ // verilator no_inline_task
+ begin : f3_body
+\t nacho = 1\'b0;
+\t case (foo[24:21])
+\t 4\'h0:
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar, "" 847""};
+ 2\'b01 : foobar = {foobar, "" 848""};
+ 2\'b10 : foobar = {foobar, "" 849""};
+ 2\'b11 : foobar = {foobar, "" 850""};
+ endcase
+\t 4\'h1:
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar, "" 851""};
+ 2\'b01 : foobar = {foobar, "" 852""};
+ 2\'b10 : foobar = {foobar, "" 853""};
+ 2\'b11 : foobar = {foobar, "" 854""};
+ endcase
+\t 4\'h2:
+ case (foo[26:25])
+ 2\'b00 : foobar = {foobar, "" 855""};
+ 2\'b01 : foobar = {foobar, "" 856""};
+ 2\'b10 : foobar = {foobar, "" 857""};
+ 2\'b11 : foobar = {foobar, "" 858""};
+ endcase
+\t 4\'h8,
+\t 4\'h9,
+\t 4\'hd,
+\t 4\'he,
+\t 4\'hf :
+ case (foo[26:25])
+\t\t 2\'b00 : foobar = {foobar, "" 859""};
+\t\t 2\'b01 : foobar = {foobar, "" 860""};
+\t\t 2\'b10 : foobar = {foobar, "" 861""};
+\t\t 2\'b11 : foobar = {foobar, "" 862""};
+ endcase
+\t 4\'ha,
+\t 4\'hb :
+ if (foo[25])
+\t\t foobar = {foobar, "" 863""};
+ else
+\t\t foobar = {foobar, "" 864""};
+\t 4\'hc :
+ if (foo[26])
+ foobar = {foobar, "" 865""};
+ else
+ foobar = {foobar, "" 866""};
+\t default :
+\t begin
+\t\tfoobar = {foobar, "" 867""};
+\t\tnacho = 1\'b1;
+\t end
+\t endcase
+\t if (~nacho)
+\t begin
+\t case (foo[24:21])
+\t\t4\'h8 :
+\t\t foobar = {foobar, "" 868""};
+\t\t4\'h9 :
+\t\t foobar = {foobar, "" 869""};
+\t\t4\'ha,
+\t\t 4\'he :
+\t\t foobar = {foobar, "" 870""};
+\t\t4\'hb,
+\t\t 4\'hf :
+\t\t foobar = {foobar, "" 871""};
+\t\t4\'hd :
+\t\t foobar = {foobar, "" 872""};
+\t endcase
+\t if (foo[20])
+\t\tcase (foo[18:16])
+\t\t 3\'b000 : foobar = {foobar, "" 873""};
+\t\t 3\'b100 : foobar = {foobar, "" 874""};
+\t\t default: foobar = {foobar, "" 875""};
+\t\tendcase
+\t else
+\t\tozoneae(foo[18:16], foobar);
+\t if (foo[24:21] === 4\'hc)
+\t\tif (foo[25])
+\t\t foobar = {foobar, "" 876""};
+\t\telse
+\t\t foobar = {foobar, "" 877""};
+\t case (foo[24:21])
+\t\t4\'h0,
+\t\t 4\'h1,
+\t\t 4\'h2:
+\t\t foobar = {foobar, "" 878""};
+\t endcase
+\t end
+ end
+ endtask
+ task ozonerx;
+ input [ 31:0] foo;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (foo[19:18])
+\t 2\'h0 : foobar = {foobar, "" 879""};
+\t 2\'h1 : foobar = {foobar, "" 880""};
+\t 2\'h2 : foobar = {foobar, "" 881""};
+\t 2\'h3 : foobar = {foobar, "" 882""};
+\t endcase
+\t case (foo[17:16])
+\t 2\'h1 : foobar = {foobar, "" 883""};
+\t 2\'h2 : foobar = {foobar, "" 884""};
+\t 2\'h3 : foobar = {foobar, "" 885""};
+\t endcase
+ end
+ endtask
+ task ozonerme;
+ input [ 2:0] rme;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (rme)
+\t 3\'h0 : foobar = {foobar, "" 886""};
+\t 3\'h1 : foobar = {foobar, "" 887""};
+\t 3\'h2 : foobar = {foobar, "" 888""};
+\t 3\'h3 : foobar = {foobar, "" 889""};
+\t 3\'h4 : foobar = {foobar, "" 890""};
+\t 3\'h5 : foobar = {foobar, "" 891""};
+\t 3\'h6 : foobar = {foobar, "" 892""};
+\t 3\'h7 : foobar = {foobar, "" 893""};
+\t endcase
+ end
+ endtask
+ task ozoneye;
+ input [5:0] ye;
+ input \t l;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t foobar = {foobar, "" 894""};
+\t ozonerme(ye[5:3],foobar);
+\t case ({ye[ 2:0], l})
+\t 4\'h2,
+\t 4\'ha: foobar = {foobar, "" 895""};
+\t 4\'h4,
+\t 4\'hb: foobar = {foobar, "" 896""};
+\t 4\'h6,
+\t 4\'he: foobar = {foobar, "" 897""};
+\t 4\'h8,
+\t 4\'hc: foobar = {foobar, "" 898""};
+\t endcase
+ end
+ endtask
+ task ozonef1e_ye;
+ input [5:0] ye;
+ input \t l;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t foobar = {foobar, "" 899""};
+\t ozonerme(ye[5:3],foobar);
+\t ozonef1e_inc_dec(ye[5:0], l ,foobar);
+ end
+ endtask
+ task ozonef1e_h;
+ input [ 2:0] e;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t if (e[ 2:0] <= 3\'h4)
+\t foobar = {foobar, "" 900""};
+ end
+ endtask
+ task ozonef1e_inc_dec;
+ input [5:0] ye;
+ input \t l;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case ({ye[ 2:0], l})
+\t 4\'h2,
+\t 4\'h3,
+\t 4\'ha: foobar = {foobar, "" 901""};
+\t 4\'h4,
+\t 4\'h5,
+\t 4\'hb: foobar = {foobar, "" 902""};
+\t 4\'h6,
+\t 4\'h7,
+\t 4\'he: foobar = {foobar, "" 903""};
+\t 4\'h8,
+\t 4\'h9,
+\t 4\'hc: foobar = {foobar, "" 904""};
+\t 4\'hf: foobar = {foobar, "" 905""};
+\t endcase
+ end
+ endtask
+ task ozonef1e_hl;
+ input [ 2:0] e;
+ input l;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case ({e[ 2:0], l})
+\t 4\'h0,
+\t 4\'h2,
+\t 4\'h4,
+\t 4\'h6,
+\t 4\'h8: foobar = {foobar, "" 906""};
+\t 4\'h1,
+\t 4\'h3,
+\t 4\'h5,
+\t 4\'h7,
+\t 4\'h9: foobar = {foobar, "" 907""};
+\t endcase
+ end
+ endtask
+ task ozonexe;
+ input [ 3:0] xe;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (xe[3])
+\t 1\'b0 : foobar = {foobar, "" 908""};
+\t 1\'b1 : foobar = {foobar, "" 909""};
+\t endcase
+\t case (xe[ 2:0])
+\t 3\'h1,
+\t 3\'h5: foobar = {foobar, "" 910""};
+\t 3\'h2,
+\t 3\'h6: foobar = {foobar, "" 911""};
+\t 3\'h3,
+\t 3\'h7: foobar = {foobar, "" 912""};
+\t 3\'h4: foobar = {foobar, "" 913""};
+\t endcase
+ end
+ endtask
+ task ozonerp;
+ input [ 2:0] rp;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (rp)
+\t 3\'h0 : foobar = {foobar, "" 914""};
+\t 3\'h1 : foobar = {foobar, "" 915""};
+\t 3\'h2 : foobar = {foobar, "" 916""};
+\t 3\'h3 : foobar = {foobar, "" 917""};
+\t 3\'h4 : foobar = {foobar, "" 918""};
+\t 3\'h5 : foobar = {foobar, "" 919""};
+\t 3\'h6 : foobar = {foobar, "" 920""};
+\t 3\'h7 : foobar = {foobar, "" 921""};
+\t endcase
+ end
+ endtask
+ task ozonery;
+ input [ 3:0] ry;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (ry)
+\t 4\'h0 : foobar = {foobar, "" 922""};
+\t 4\'h1 : foobar = {foobar, "" 923""};
+\t 4\'h2 : foobar = {foobar, "" 924""};
+\t 4\'h3 : foobar = {foobar, "" 925""};
+\t 4\'h4 : foobar = {foobar, "" 926""};
+\t 4\'h5 : foobar = {foobar, "" 927""};
+\t 4\'h6 : foobar = {foobar, "" 928""};
+\t 4\'h7 : foobar = {foobar, "" 929""};
+\t 4\'h8 : foobar = {foobar, "" 930""};
+\t 4\'h9 : foobar = {foobar, "" 931""};
+\t 4\'ha : foobar = {foobar, "" 932""};
+\t 4\'hb : foobar = {foobar, "" 933""};
+\t 4\'hc : foobar = {foobar, "" 934""};
+\t 4\'hd : foobar = {foobar, "" 935""};
+\t 4\'he : foobar = {foobar, "" 936""};
+\t 4\'hf : foobar = {foobar, "" 937""};
+\t endcase
+ end
+ endtask
+ task ozonearx;
+ input [ 15:0] foo;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (foo[1:0])
+\t 2\'h0 : foobar = {foobar, "" 938""};
+\t 2\'h1 : foobar = {foobar, "" 939""};
+\t 2\'h2 : foobar = {foobar, "" 940""};
+\t 2\'h3 : foobar = {foobar, "" 941""};
+\t endcase
+ end
+ endtask
+ task ozonef3f4imop;
+ input [ 4:0] f3f4iml;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t casez (f3f4iml)
+\t 5\'b000??: foobar = {foobar, "" 942""};
+\t 5\'b001??: foobar = {foobar, "" 943""};
+\t 5\'b?10??: foobar = {foobar, "" 944""};
+\t 5\'b0110?: foobar = {foobar, "" 945""};
+\t 5\'b01110: foobar = {foobar, "" 946""};
+\t 5\'b01111: foobar = {foobar, "" 947""};
+\t 5\'b10???: foobar = {foobar, "" 948""};
+\t 5\'b11100: foobar = {foobar, "" 949""};
+\t 5\'b11101: foobar = {foobar, "" 950""};
+\t 5\'b11110: foobar = {foobar, "" 951""};
+\t 5\'b11111: foobar = {foobar, "" 952""};
+\t endcase
+ end
+ endtask
+ task ozonecon;
+ input [ 4:0] con;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (con)
+\t 5\'h00 : foobar = {foobar, "" 953""};
+\t 5\'h01 : foobar = {foobar, "" 954""};
+\t 5\'h02 : foobar = {foobar, "" 955""};
+\t 5\'h03 : foobar = {foobar, "" 956""};
+\t 5\'h04 : foobar = {foobar, "" 957""};
+\t 5\'h05 : foobar = {foobar, "" 958""};
+\t 5\'h06 : foobar = {foobar, "" 959""};
+\t 5\'h07 : foobar = {foobar, "" 960""};
+\t 5\'h08 : foobar = {foobar, "" 961""};
+\t 5\'h09 : foobar = {foobar, "" 962""};
+\t 5\'h0a : foobar = {foobar, "" 963""};
+\t 5\'h0b : foobar = {foobar, "" 964""};
+\t 5\'h0c : foobar = {foobar, "" 965""};
+\t 5\'h0d : foobar = {foobar, "" 966""};
+\t 5\'h0e : foobar = {foobar, "" 967""};
+\t 5\'h0f : foobar = {foobar, "" 968""};
+\t 5\'h10 : foobar = {foobar, "" 969""};
+\t 5\'h11 : foobar = {foobar, "" 970""};
+\t 5\'h12 : foobar = {foobar, "" 971""};
+\t 5\'h13 : foobar = {foobar, "" 972""};
+\t 5\'h14 : foobar = {foobar, "" 973""};
+\t 5\'h15 : foobar = {foobar, "" 974""};
+\t 5\'h16 : foobar = {foobar, "" 975""};
+\t 5\'h17 : foobar = {foobar, "" 976""};
+\t 5\'h18 : foobar = {foobar, "" 977""};
+\t 5\'h19 : foobar = {foobar, "" 978""};
+\t 5\'h1a : foobar = {foobar, "" 979""};
+\t 5\'h1b : foobar = {foobar, "" 980""};
+\t 5\'h1c : foobar = {foobar, "" 981""};
+\t 5\'h1d : foobar = {foobar, "" 982""};
+\t 5\'h1e : foobar = {foobar, "" 983""};
+\t 5\'h1f : foobar = {foobar, "" 984""};
+\t endcase
+ end
+ endtask
+ task ozonedr;
+ input [ 15:0] foo;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (foo[ 9: 6])
+\t 4\'h0 : foobar = {foobar, "" 985""};
+\t 4\'h1 : foobar = {foobar, "" 986""};
+\t 4\'h2 : foobar = {foobar, "" 987""};
+\t 4\'h3 : foobar = {foobar, "" 988""};
+\t 4\'h4 : foobar = {foobar, "" 989""};
+\t 4\'h5 : foobar = {foobar, "" 990""};
+\t 4\'h6 : foobar = {foobar, "" 991""};
+\t 4\'h7 : foobar = {foobar, "" 992""};
+\t 4\'h8 : foobar = {foobar, "" 993""};
+\t 4\'h9 : foobar = {foobar, "" 994""};
+\t 4\'ha : foobar = {foobar, "" 995""};
+\t 4\'hb : foobar = {foobar, "" 996""};
+\t 4\'hc : foobar = {foobar, "" 997""};
+\t 4\'hd : foobar = {foobar, "" 998""};
+\t 4\'he : foobar = {foobar, "" 999""};
+\t 4\'hf : foobar = {foobar, "" 1000""};
+\t endcase
+ end
+ endtask
+ task ozoneshift;
+ input [ 15:0] foo;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (foo[ 4: 3])
+\t 2\'h0 : foobar = {foobar, "" 1001""};
+\t 2\'h1 : foobar = {foobar, "" 1002""};
+\t 2\'h2 : foobar = {foobar, "" 1003""};
+\t 2\'h3 : foobar = {foobar, "" 1004""};
+\t endcase
+ end
+ endtask
+ task ozoneacc;
+ input foo;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (foo)
+\t 2\'h0 : foobar = {foobar, "" 1005""};
+\t 2\'h1 : foobar = {foobar, "" 1006""};
+\t endcase
+ end
+ endtask
+ task ozonehl;
+ input foo;
+ inout [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t case (foo)
+\t 2\'h0 : foobar = {foobar, "" 1007""};
+\t 2\'h1 : foobar = {foobar, "" 1008""};
+\t endcase
+ end
+ endtask
+ task dude;
+ inout [STRLEN*8: 1] foobar;
+ reg [ 7:0] \t temp;
+ integer \t\t i;
+ reg \t\t nacho;
+ // verilator no_inline_task
+ begin : justify_block
+\t nacho = 1\'b0;
+\t for (i=STRLEN-1; i>1; i=i-1)
+\t begin
+\t temp = foobar>>((STRLEN-1)*8);
+\t if (temp || nacho)
+\t\tnacho = 1\'b1;
+\t else
+\t\tbegin
+\t\t foobar = foobar<<8;
+\t\t foobar[8:1] = 32;
+\t\tend
+\t end
+ end
+ endtask
+
+ task big_case;
+ input [ 31:0] fd;
+ input [ 31:0] foo;
+ reg [STRLEN*8: 1] foobar;
+ // verilator no_inline_task
+ begin
+\t foobar = "" 1009"";
+\t if (&foo === 1\'bx)
+\t $fwrite(fd, "" 1010"");
+\t else
+\t casez ( {foo[31:26], foo[19:15], foo[5:0]} )
+ 17\'b00_111?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, foobar);
+\t\t foobar = {foobar, "" 1011""};
+\t\t ozoneacc(~foo[26], foobar);
+\t\t ozonehl(foo[20], foobar);
+\t\t foobar = {foobar, "" 1012""};
+\t\t ozonerx(foo, foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1013:%s"", foobar);
+ end
+ 17\'b01_001?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, foobar);
+\t\t foobar = {foobar, "" 1014""};
+\t\t ozonerx(foo, foobar);
+\t\t foobar = {foobar, "" 1015""};
+\t\t foobar = {foobar, "" 1016""};
+\t\t ozonehl(foo[20], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1017:%s"", foobar);
+ end
+ 17\'b10_100?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, foobar);
+\t\t foobar = {foobar, "" 1018""};
+\t\t ozonerx(foo, foobar);
+\t\t foobar = {foobar, "" 1019""};
+\t\t foobar = {foobar, "" 1020""};
+\t\t ozonehl(foo[20], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1021:%s"", foobar);
+ end
+ 17\'b10_101?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, foobar);
+\t\t foobar = {foobar, "" 1022""};
+\t\t if (foo[20])
+\t\t begin
+\t\t foobar = {foobar, "" 1023""};
+\t\t ozoneacc(foo[18], foobar);
+\t\t foobar = {foobar, "" 1024""};
+\t\t foobar = {foobar, "" 1025""};
+\t\t if (foo[19])
+\t\t\t foobar = {foobar, "" 1026""};
+\t\t else
+\t\t\t foobar = {foobar, "" 1027""};
+\t\t end
+\t\t else
+\t\t ozonerx(foo, foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1028:%s"", foobar);
+ end
+ 17\'b10_110?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, foobar);
+\t\t foobar = {foobar, "" 1029""};
+\t\t foobar = {foobar, "" 1030""};
+\t\t ozonehl(foo[20], foobar);
+\t\t foobar = {foobar, "" 1031""};
+\t\t ozonerx(foo, foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1032:%s"", foobar);
+ end
+ 17\'b10_111?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, foobar);
+\t\t foobar = {foobar, "" 1033""};
+\t\t foobar = {foobar, "" 1034""};
+\t\t ozonehl(foo[20], foobar);
+\t\t foobar = {foobar, "" 1035""};
+\t\t ozonerx(foo, foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1036:%s"", foobar);
+ end
+ 17\'b11_001?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, foobar);
+\t\t foobar = {foobar, "" 1037""};
+\t\t ozonerx(foo, foobar);
+\t\t foobar = {foobar, "" 1038""};
+\t\t foobar = {foobar, "" 1039""};
+\t\t ozonehl(foo[20], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1040:%s"", foobar);
+ end
+ 17\'b11_111?_?_????_??_???? :
+ begin
+\t\t ozonef1(foo, foobar);
+\t\t foobar = {foobar, "" 1041""};
+\t\t foobar = {foobar, "" 1042""};
+\t\t ozonerx(foo, foobar);
+\t\t foobar = {foobar, "" 1043""};
+\t\t if (foo[20])
+\t\t foobar = {foobar, "" 1044""};
+\t\t else
+\t\t foobar = {foobar, "" 1045""};
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1046:%s"", foobar);
+ end
+ 17\'b00_10??_?_????_?1_1111 :
+ casez (foo[11: 5])
+\t\t 7\'b??_0_010_0:
+\t\t begin
+\t\t foobar = "" 1047"";
+\t\t ozonecon(foo[14:10], foobar);
+\t\t foobar = {foobar, "" 1048""};
+\t\t ozonef1e(foo, foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1049:%s"", foobar);
+\t\t end
+\t\t 7\'b00_?_110_?:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1050""};
+\t\t case ({foo[ 9],foo[ 5]})
+\t\t\t2\'b00:
+\t\t\t begin
+\t\t\t foobar = {foobar, "" 1051""};
+\t\t\t ozoneae(foo[14:12], foobar);
+\t\t\t ozonehl(foo[ 5], foobar);
+\t\t\t end
+\t\t\t2\'b01:
+\t\t\t begin
+\t\t\t foobar = {foobar, "" 1052""};
+\t\t\t ozoneae(foo[14:12], foobar);
+\t\t\t ozonehl(foo[ 5], foobar);
+\t\t\t end
+\t\t\t2\'b10:
+\t\t\t begin
+\t\t\t foobar = {foobar, "" 1053""};
+\t\t\t ozoneae(foo[14:12], foobar);
+\t\t\t end
+\t\t\t2\'b11: foobar = {foobar, "" 1054""};
+\t\t endcase
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1055:%s"", foobar);
+\t\t end
+\t\t 7\'b01_?_110_?:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1056""};
+\t\t case ({foo[ 9],foo[ 5]})
+\t\t\t2\'b00:
+\t\t\t begin
+\t\t\t ozoneae(foo[14:12], foobar);
+\t\t\t ozonehl(foo[ 5], foobar);
+\t\t\t foobar = {foobar, "" 1057""};
+\t\t\t end
+\t\t\t2\'b01:
+\t\t\t begin
+\t\t\t ozoneae(foo[14:12], foobar);
+\t\t\t ozonehl(foo[ 5], foobar);
+\t\t\t foobar = {foobar, "" 1058""};
+\t\t\t end
+\t\t\t2\'b10:
+\t\t\t begin
+\t\t\t ozoneae(foo[14:12], foobar);
+\t\t\t foobar = {foobar, "" 1059""};
+\t\t\t end
+\t\t\t2\'b11: foobar = {foobar, "" 1060""};
+\t\t endcase
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1061:%s"", foobar);
+\t\t end
+\t\t 7\'b10_0_110_0:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1062""};
+\t\t foobar = {foobar, "" 1063""};
+\t\t if (foo[12])
+\t\t\tfoobar = {foobar, "" 1064""};
+\t\t else
+\t\t\tozonerab({4\'b1001, foo[14:12]}, foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1065:%s"", foobar);
+\t\t end
+\t\t 7\'b10_0_110_1:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1066""};
+\t\t if (foo[12])
+\t\t\tfoobar = {foobar, "" 1067""};
+\t\t else
+\t\t\tozonerab({4\'b1001, foo[14:12]}, foobar);
+\t\t foobar = {foobar, "" 1068""};
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1069:%s"", foobar);
+\t\t end
+\t\t 7\'b??_?_000_?:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1070""};
+\t\t foobar = {foobar, "" 1071""};
+\t\t ozonef1e_hl(foo[11:9],foo[ 5],foobar);
+\t\t foobar = {foobar, "" 1072""};
+\t\t ozonef1e_ye(foo[14:9],foo[ 5],foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1073:%s"", foobar);
+\t\t end
+\t\t 7\'b??_?_100_?:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1074""};
+\t\t foobar = {foobar, "" 1075""};
+\t\t ozonef1e_hl(foo[11:9],foo[ 5],foobar);
+\t\t foobar = {foobar, "" 1076""};
+\t\t ozonef1e_ye(foo[14:9],foo[ 5],foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1077:%s"", foobar);
+\t\t end
+\t\t 7\'b??_?_001_?:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1078""};
+\t\t ozonef1e_ye(foo[14:9],foo[ 5],foobar);
+\t\t foobar = {foobar, "" 1079""};
+\t\t foobar = {foobar, "" 1080""};
+\t\t ozonef1e_hl(foo[11:9],foo[ 5],foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1081:%s"", foobar);
+\t\t end
+\t\t 7\'b??_?_011_?:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1082""};
+\t\t ozonef1e_ye(foo[14:9],foo[ 5],foobar);
+\t\t foobar = {foobar, "" 1083""};
+\t\t foobar = {foobar, "" 1084""};
+\t\t ozonef1e_hl(foo[11:9],foo[ 5],foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1085:%s"", foobar);
+\t\t end
+\t\t 7\'b??_?_101_?:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1086""};
+\t\t ozonef1e_ye(foo[14:9],foo[ 5],foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1087:%s"", foobar);
+\t\t end
+ endcase
+ 17\'b00_10??_?_????_?0_0110 :
+ begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1088""};
+\t\t ozoneae(foo[ 8: 6], foobar);
+\t\t ozonef1e_hl(foo[11:9],foo[ 5],foobar);
+\t\t foobar = {foobar, "" 1089""};
+\t\t ozonef1e_ye(foo[14:9],foo[ 5],foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1090:%s"", foobar);
+ end
+ 17\'b00_10??_?_????_00_0111 :
+ begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1091""};
+\t\t if (foo[ 6])
+\t\t foobar = {foobar, "" 1092""};
+\t\t else
+\t\t ozonerab({4\'b1001, foo[ 8: 6]}, foobar);
+\t\t foobar = {foobar, "" 1093""};
+\t\t foobar = {foobar, "" 1094""};
+\t\t ozonerme(foo[14:12],foobar);
+\t\t case (foo[11: 9])
+\t\t 3\'h2,
+\t\t 3\'h5,
+\t\t 3\'h6,
+\t\t 3\'h7:
+\t\t\tozonef1e_inc_dec(foo[14:9],1\'b0,foobar);
+\t\t 3\'h1,
+\t\t 3\'h3,
+\t\t 3\'h4:
+\t\t\tfoobar = {foobar, "" 1095""};
+\t\t endcase
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1096:%s"", foobar);
+ end
+ 17\'b00_10??_?_????_?0_0100 :
+ begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1097""};
+\t\t ozonef1e_ye(foo[14:9],foo[ 5],foobar);
+\t\t foobar = {foobar, "" 1098""};
+\t\t ozoneae(foo[ 8: 6], foobar);
+\t\t ozonef1e_hl(foo[11:9],foo[ 5],foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1099:%s"", foobar);
+ end
+ 17\'b00_10??_?_????_10_0111 :
+ begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1100""};
+\t\t foobar = {foobar, "" 1101""};
+\t\t ozonerme(foo[14:12],foobar);
+\t\t case (foo[11: 9])
+\t\t 3\'h2,
+\t\t 3\'h5,
+\t\t 3\'h6,
+\t\t 3\'h7:
+\t\t\tozonef1e_inc_dec(foo[14:9],1\'b0,foobar);
+\t\t 3\'h1,
+\t\t 3\'h3,
+\t\t 3\'h4:
+\t\t\tfoobar = {foobar, "" 1102""};
+\t\t endcase
+\t\t foobar = {foobar, "" 1103""};
+\t\t if (foo[ 6])
+\t\t foobar = {foobar, "" 1104""};
+\t\t else
+\t\t ozonerab({4\'b1001, foo[ 8: 6]}, foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1105:%s"", foobar);
+ end
+ 17\'b00_10??_?_????_?0_1110 :
+ begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1106""};
+\t\t case (foo[11:9])
+\t\t 3\'h2:
+\t\t begin
+\t\t\t foobar = {foobar, "" 1107""};
+\t\t\t if (foo[14:12] == 3\'h0)
+\t\t\t foobar = {foobar, "" 1108""};
+\t\t\t else
+\t\t\t ozonerme(foo[14:12],foobar);
+\t\t\t foobar = {foobar, "" 1109""};
+\t\t end
+\t\t 3\'h6:
+\t\t begin
+\t\t\t foobar = {foobar, "" 1110""};
+\t\t\t if (foo[14:12] == 3\'h0)
+\t\t\t foobar = {foobar, "" 1111""};
+\t\t\t else
+\t\t\t ozonerme(foo[14:12],foobar);
+\t\t\t foobar = {foobar, "" 1112""};
+\t\t end
+\t\t 3\'h0:
+\t\t begin
+\t\t\t foobar = {foobar, "" 1113""};
+\t\t\t if (foo[14:12] == 3\'h0)
+\t\t\t foobar = {foobar, "" 1114""};
+\t\t\t else
+\t\t\t ozonerme(foo[14:12],foobar);
+\t\t\t foobar = {foobar, "" 1115""};
+\t\t\t if (foo[ 7: 5] >= 3\'h5)
+\t\t\t foobar = {foobar, "" 1116""};
+\t\t\t else
+\t\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t end
+\t\t 3\'h1:
+\t\t begin
+\t\t\t foobar = {foobar, "" 1117""};
+\t\t\t if (foo[14:12] == 3\'h0)
+\t\t\t foobar = {foobar, "" 1118""};
+\t\t\t else
+\t\t\t ozonerme(foo[14:12],foobar);
+\t\t\t foobar = {foobar, "" 1119""};
+\t\t\t if (foo[ 7: 5] >= 3\'h5)
+\t\t\t foobar = {foobar, "" 1120""};
+\t\t\t else
+\t\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t end
+\t\t 3\'h4:
+\t\t begin
+\t\t\t foobar = {foobar, "" 1121""};
+\t\t\t if (foo[14:12] == 3\'h0)
+\t\t\t foobar = {foobar, "" 1122""};
+\t\t\t else
+\t\t\t ozonerme(foo[14:12],foobar);
+\t\t\t foobar = {foobar, "" 1123""};
+\t\t\t if (foo[ 7: 5] >= 3\'h5)
+\t\t\t foobar = {foobar, "" 1124""};
+\t\t\t else
+\t\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t end
+\t\t 3\'h5:
+\t\t begin
+\t\t\t foobar = {foobar, "" 1125""};
+\t\t\t if (foo[14:12] == 3\'h0)
+\t\t\t foobar = {foobar, "" 1126""};
+\t\t\t else
+\t\t\t ozonerme(foo[14:12],foobar);
+\t\t\t foobar = {foobar, "" 1127""};
+\t\t\t if (foo[ 7: 5] >= 3\'h5)
+\t\t\t foobar = {foobar, "" 1128""};
+\t\t\t else
+\t\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t end
+\t\t endcase
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1129:%s"", foobar);
+ end
+ 17\'b00_10??_?_????_?0_1111 :
+ casez (foo[14: 9])
+\t\t 6\'b001_10_?:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1130""};
+\t\t foobar = {foobar, "" 1131""};
+\t\t ozonef1e_hl(foo[ 7: 5],foo[ 9],foobar);
+\t\t foobar = {foobar, "" 1132""};
+\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 113'b'3:%s"", foobar);
+\t\t end
+\t\t 6\'b???_11_?:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1134""};
+\t\t ozoneae(foo[14:12], foobar);
+\t\t ozonef1e_hl(foo[ 7: 5],foo[ 9],foobar);
+\t\t foobar = {foobar, "" 1135""};
+\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1136:%s"", foobar);
+\t\t end
+\t\t 6\'b000_10_1,
+\t\t 6\'b010_10_1,
+\t\t 6\'b100_10_1,
+\t\t 6\'b110_10_1:
+\t\t begin
+\t\t\tozonef1e(foo, foobar);
+\t\t\tfoobar = {foobar, "" 1137""};
+\t\t\tozonerab({4\'b1001, foo[14:12]}, foobar);
+\t\t\tfoobar = {foobar, "" 1138""};
+\t\t\tif ((foo[ 7: 5] >= 3\'h1) & (foo[ 7: 5] <= 3\'h3))
+\t\t\t foobar = {foobar, "" 1139""};
+\t\t\telse
+\t\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t\tdude(foobar);
+\t\t\t$fwrite (fd, "" 1140:%s"", foobar);
+\t\t end
+\t\t 6\'b000_10_0,
+\t\t 6\'b010_10_0,
+\t\t 6\'b100_10_0,
+\t\t 6\'b110_10_0:
+\t\t begin
+\t\t\tozonef1e(foo, foobar);
+\t\t\tfoobar = {foobar, "" 1141""};
+\t\t\tfoobar = {foobar, "" 1142""};
+\t\t\tozonerab({4\'b1001, foo[14:12]}, foobar);
+\t\t\tfoobar = {foobar, "" 1143""};
+\t\t\tfoobar = {foobar, "" 1144""};
+\t\t\tozonef1e_h(foo[ 7: 5],foobar);
+\t\t\tfoobar = {foobar, "" 1145""};
+\t\t\tozonexe(foo[ 8: 5], foobar);
+\t\t\tdude(foobar);
+\t\t\t$fwrite (fd, "" 1146:%s"", foobar);
+\t\t end
+\t\t 6\'b???_00_?:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1147""};
+\t\t if (foo[ 9])
+\t\t\tbegin
+\t\t\t foobar = {foobar, "" 1148""};
+\t\t\t ozoneae(foo[14:12], foobar);
+\t\t\tend
+\t\t else
+\t\t\tbegin
+\t\t\t foobar = {foobar, "" 1149""};
+\t\t\t ozoneae(foo[14:12], foobar);
+\t\t\t foobar = {foobar, "" 1150""};
+\t\t\tend
+\t\t foobar = {foobar, "" 1151""};
+\t\t foobar = {foobar, "" 1152""};
+\t\t ozonef1e_h(foo[ 7: 5],foobar);
+\t\t foobar = {foobar, "" 1153""};
+\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1154:%s"", foobar);
+\t\t end
+\t\t 6\'b???_01_?:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1155""};
+\t\t ozoneae(foo[14:12], foobar);
+\t\t if (foo[ 9])
+\t\t\tfoobar = {foobar, "" 1156""};
+\t\t else
+\t\t\tfoobar = {foobar, "" 1157""};
+\t\t foobar = {foobar, "" 1158""};
+\t\t foobar = {foobar, "" 1159""};
+\t\t ozonef1e_h(foo[ 7: 5],foobar);
+\t\t foobar = {foobar, "" 1160""};
+\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1161:%s"", foobar);
+\t\t end
+\t\t 6\'b011_10_0:
+\t\t begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1162""};
+\t\t case (foo[ 8: 5])
+\t\t\t4\'h0: foobar = {foobar, "" 1163""};
+\t\t\t4\'h1: foobar = {foobar, "" 1164""};
+\t\t\t4\'h2: foobar = {foobar, "" 1165""};
+\t\t\t4\'h3: foobar = {foobar, "" 1166""};
+\t\t\t4\'h4: foobar = {foobar, "" 1167""};
+\t\t\t4\'h5: foobar = {foobar, "" 1168""};
+\t\t\t4\'h8: foobar = {foobar, "" 1169""};
+\t\t\t4\'h9: foobar = {foobar, "" 1170""};
+\t\t\t4\'ha: foobar = {foobar, "" 1171""};
+\t\t\t4\'hb: foobar = {foobar, "" 1172""};
+\t\t\t4\'hc: foobar = {foobar, "" 1173""};
+\t\t\t4\'hd: foobar = {foobar, "" 1174""};
+\t\t\tdefault: foobar = {foobar, "" 1175""};
+\t\t endcase
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1176:%s"", foobar);
+\t\t end
+\t\t default: foobar = {foobar, "" 1177""};
+ endcase
+ 17\'b00_10??_?_????_?0_110? :
+ begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1178""};
+\t\t foobar = {foobar, "" 1179""};
+\t\t ozonef1e_hl(foo[11:9], foo[0], foobar);
+\t\t foobar = {foobar, "" 1180""};
+\t\t ozonef1e_ye(foo[14:9],1\'b0,foobar);
+\t\t foobar = {foobar, "" 1181""};
+\t\t ozonef1e_h(foo[ 7: 5],foobar);
+\t\t foobar = {foobar, "" 1182""};
+\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1183:%s"", foobar);
+ end
+ 17\'b00_10??_?_????_?1_110? :
+ begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1184""};
+\t\t foobar = {foobar, "" 1185""};
+\t\t ozonef1e_hl(foo[11:9],foo[0],foobar);
+\t\t foobar = {foobar, "" 1186""};
+\t\t ozonef1e_ye(foo[14:9],foo[ 0],foobar);
+\t\t foobar = {foobar, "" 1187""};
+\t\t foobar = {foobar, "" 1188""};
+\t\t ozonef1e_h(foo[ 7: 5],foobar);
+\t\t foobar = {foobar, "" 1189""};
+\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1190:%s"", foobar);
+ end
+ 17\'b00_10??_?_????_?0_101? :
+ begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1191""};
+\t\t ozonef1e_ye(foo[14:9],foo[ 0],foobar);
+\t\t foobar = {foobar, "" 1192""};
+\t\t foobar = {foobar, "" 1193""};
+\t\t ozonef1e_hl(foo[11:9],foo[0],foobar);
+\t\t foobar = {foobar, "" 1194""};
+\t\t foobar = {foobar, "" 1195""};
+\t\t ozonef1e_h(foo[ 7: 5],foobar);
+\t\t foobar = {foobar, "" 1196""};
+\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1197:%s"", foobar);
+ end
+ 17\'b00_10??_?_????_?0_1001 :
+ begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1198""};
+\t\t foobar = {foobar, "" 1199""};
+\t\t ozonef1e_h(foo[11:9],foobar);
+\t\t foobar = {foobar, "" 1200""};
+\t\t ozonef1e_ye(foo[14:9],1\'b0,foobar);
+\t\t foobar = {foobar, "" 1201""};
+\t\t case (foo[ 7: 5])
+\t\t 3\'h1,
+\t\t 3\'h2,
+\t\t 3\'h3:
+\t\t\tfoobar = {foobar, "" 1202""};
+\t\t default:
+\t\t begin
+\t\t\t foobar = {foobar, "" 1203""};
+\t\t\t foobar = {foobar, "" 1204""};
+\t\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t end
+\t\t endcase
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1205:%s"", foobar);
+ end
+ 17\'b00_10??_?_????_?0_0101 :
+ begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1206""};
+\t\t case (foo[11: 9])
+\t\t 3\'h1,
+\t\t 3\'h3,
+\t\t 3\'h4:
+\t\t\tfoobar = {foobar, "" 1207""};
+\t\t default:
+\t\t begin
+\t\t\t ozonef1e_ye(foo[14:9],1\'b0,foobar);
+\t\t\t foobar = {foobar, "" 1208""};
+\t\t\t foobar = {foobar, "" 1209""};
+\t\t end
+\t\t endcase
+\t\t foobar = {foobar, "" 1210""};
+\t\t foobar = {foobar, "" 1211""};
+\t\t ozonef1e_h(foo[ 7: 5],foobar);
+\t\t foobar = {foobar, "" 1212""};
+\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1213:%s"", foobar);
+ end
+ 17\'b00_10??_?_????_?1_1110 :
+ begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1214""};
+\t\t ozonef1e_ye(foo[14:9],1\'b0,foobar);
+\t\t foobar = {foobar, "" 1215""};
+\t\t foobar = {foobar, "" 1216""};
+\t\t ozonef1e_h(foo[11: 9],foobar);
+\t\t foobar = {foobar, "" 1217""};
+\t\t foobar = {foobar, "" 1218""};
+\t\t ozonef1e_h(foo[ 7: 5],foobar);
+\t\t foobar = {foobar, "" 1219""};
+\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1220:%s"", foobar);
+ end
+ 17\'b00_10??_?_????_?0_1000 :
+ begin
+\t\t ozonef1e(foo, foobar);
+\t\t foobar = {foobar, "" 1221""};
+\t\t ozonef1e_ye(foo[14:9],1\'b0,foobar);
+\t\t foobar = {foobar, "" 1222""};
+\t\t foobar = {foobar, "" 1223""};
+\t\t ozonef1e_h(foo[11: 9],foobar);
+\t\t foobar = {foobar, "" 1224""};
+\t\t foobar = {foobar, "" 1225""};
+\t\t ozonef1e_h(foo[ 7: 5],foobar);
+\t\t foobar = {foobar, "" 1226""};
+\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1227:%s"", foobar);
+ end
+ 17\'b10_01??_?_????_??_???? :
+ begin
+\t\t if (foo[27])
+\t\t foobar = "" 1228"";
+\t\t else
+\t\t foobar = "" 1229"";
+\t\t ozonecon(foo[20:16], foobar);
+\t\t foobar = {foobar, "" 1230""};
+\t\t ozonef2(foo[31:0], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1231:%s"", foobar);
+ end
+ 17\'b00_1000_?_????_01_0011 :
+ if (~|foo[ 9: 8])
+\t\t begin
+\t\t if (foo[ 7])
+\t\t foobar = "" 1232"";
+\t\t else
+\t\t foobar = "" 1233"";
+\t\t ozonecon(foo[14:10], foobar);
+\t\t foobar = {foobar, "" 1234""};
+\t\t ozonef2e(foo[31:0], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1235:%s"", foobar);
+\t\t end
+ else
+\t\t begin
+\t\t foobar = "" 1236"";
+\t\t ozonecon(foo[14:10], foobar);
+\t\t foobar = {foobar, "" 1237""};
+\t\t ozonef3e(foo[31:0], foobar);
+\t\t dude(foobar);
+\t\t $fwrite (fd, "" 1238:%s"", foobar);
+\t\t end
+ 17\'b11_110?_1_????_??_???? :
+ begin
+\t\t ozonef3(foo[31:0], foobar);
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1239:%s"", foobar);
+ end
+ 17\'b11_110?_0_????_??_???? :
+ begin : f4_body
+\t\t casez (foo[24:20])
+\t\t 5\'b0_1110,
+\t\t 5\'b1_0???,
+\t\t 5\'b1_1111:
+\t\t\tbegin
+\t\t\t $fwrite (fd, "" 1240"");
+\t\t\tend
+\t\t 5\'b0_00??:
+\t\t begin
+\t\t\t ozoneacc(foo[26], foobar);
+\t\t\t foobar = {foobar, "" 1241""};
+\t\t\t ozoneacc(foo[25], foobar);
+\t\t\t ozonebmuop(foo[24:20], foobar);
+\t\t\t ozoneae(foo[18:16], foobar);
+\t\t\t foobar = {foobar, "" 1242""};
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1243:%s"", foobar);
+\t\t end
+\t\t 5\'b0_01??:
+\t\t begin
+\t\t\t ozoneacc(foo[26], foobar);
+\t\t\t foobar = {foobar, "" 1244""};
+\t\t\t ozoneacc(foo[25], foobar);
+\t\t\t ozonebmuop(foo[24:20], foobar);
+\t\t\t ozonearm(foo[18:16], foobar);
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1245:%s"", foobar);
+\t\t end
+\t\t 5\'b0_1011:
+\t\t begin
+\t\t\t ozoneacc(foo[26], foobar);
+\t\t\t foobar = {foobar, "" 1246""};
+\t\t\t ozonebmuop(foo[24:20], foobar);
+\t\t\t foobar = {foobar, "" 1247""};
+\t\t\t ozoneae(foo[18:16], foobar);
+\t\t\t foobar = {foobar, "" 1248""};
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1249:%s"", foobar);
+\t\t end
+\t\t 5\'b0_100?,
+\t\t 5\'b0_1010,
+\t\t 5\'b0_110? :
+\t\t\tbegin
+\t\t\t ozoneacc(foo[26], foobar);
+\t\t\t foobar = {foobar, "" 1250""};
+\t\t\t ozonebmuop(foo[24:20], foobar);
+\t\t\t foobar = {foobar, "" 1251""};
+\t\t\t ozoneacc(foo[25], foobar);
+\t\t\t foobar = {foobar, "" 1252""};
+\t\t\t ozoneae(foo[18:16], foobar);
+\t\t\t foobar = {foobar, "" 1253""};
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1254:%s"", foobar);
+\t\t\tend
+\t\t 5\'b0_1111 :
+\t\t begin
+\t\t\t ozoneacc(foo[26], foobar);
+\t\t\t foobar = {foobar, "" 1255""};
+\t\t\t ozoneacc(foo[25], foobar);
+\t\t\t foobar = {foobar, "" 1256""};
+\t\t\t ozoneae(foo[18:16], foobar);
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1257:%s"", foobar);
+\t\t end
+\t\t 5\'b1_10??,
+\t\t 5\'b1_110?,
+\t\t 5\'b1_1110 :
+\t\t\tbegin
+\t\t\t ozoneacc(foo[26], foobar);
+\t\t\t foobar = {foobar, "" 1258""};
+\t\t\t ozonebmuop(foo[24:20], foobar);
+\t\t\t foobar = {foobar, "" 1259""};
+\t\t\t ozoneacc(foo[25], foobar);
+\t\t\t foobar = {foobar, "" 1260""};
+\t\t\t ozonearm(foo[18:16], foobar);
+\t\t\t foobar = {foobar, "" 1261""};
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1262:%s"", foobar);
+\t\t\tend
+\t\t endcase
+ end
+ 17\'b11_100?_?_????_??_???? :
+ casez (foo[23:19])
+\t\t 5\'b111??,
+\t\t 5\'b0111?:
+\t\t begin
+\t\t\tozoneae(foo[26:24], foobar);
+\t\t\tfoobar = {foobar, "" 1263""};
+\t\t\tozonef3f4imop(foo[23:19], foobar);
+\t\t\tfoobar = {foobar, "" 1264""};
+\t\t\tozoneae(foo[18:16], foobar);
+\t\t\tfoobar = {foobar, "" 1265""};
+\t\t\tskyway(foo[15:12], foobar);
+\t\t\tskyway(foo[11: 8], foobar);
+\t\t\tskyway(foo[ 7: 4], foobar);
+\t\t\tskyway(foo[ 3:0], foobar);
+\t\t\tfoobar = {foobar, "" 1266""};
+\t\t\tdude(foobar);
+\t\t\t$fwrite(fd, "" 1267:%s"", foobar);
+\t\t end
+\t\t 5\'b?0???,
+\t\t 5\'b110??:
+\t\t begin
+\t\t\tozoneae(foo[26:24], foobar);
+\t\t\tfoobar = {foobar, "" 1268""};
+\t\t\tif (foo[23:21] == 3\'b100)
+\t\t\t foobar = {foobar, "" 1269""};
+\t\t\tozoneae(foo[18:16], foobar);
+\t\t\tif (foo[19])
+\t\t\t foobar = {foobar, "" 1270""};
+\t\t\telse
+\t\t\t foobar = {foobar, "" 1271""};
+\t\t\tozonef3f4imop(foo[23:19], foobar);
+\t\t\tfoobar = {foobar, "" 1272""};
+\t\t\tozonef3f4_iext(foo[20:19], foo[15:0], foobar);
+\t\t\tdude(foobar);
+\t\t\t$fwrite(fd, "" 1273:%s"", foobar);
+\t\t end
+\t\t 5\'b010??,
+\t\t 5\'b0110?:
+\t\t begin
+\t\t\tozoneae(foo[18:16], foobar);
+\t\t\tif (foo[19])
+\t\t\t foobar = {foobar, "" 1274""};
+\t\t\telse
+\t\t\t foobar = {foobar, "" 1275""};
+\t\t\tozonef3f4imop(foo[23:19], foobar);
+\t\t\tfoobar = {foobar, "" 1276""};
+\t\t\tozonef3f4_iext(foo[20:19], foo[15:0], foobar);
+\t\t\tdude(foobar);
+\t\t\t$fwrite(fd, "" 1277:%s"", foobar);
+\t\t end
+ endcase
+ 17\'b00_1000_?_????_11_0011 :
+ begin
+\t\t foobar = "" 1278"";
+\t\t ozonecon(foo[14:10], foobar);
+\t\t foobar = {foobar, "" 1279""};
+\t\t casez (foo[25:21])
+\t\t 5\'b0_1110,
+\t\t 5\'b1_0???,
+\t\t 5\'b1_1111:
+\t\t\tbegin
+\t\t\t $fwrite(fd, "" 1280"");
+\t\t\tend
+\t\t 5\'b0_00??:
+\t\t begin
+\t\t\t ozoneae(foo[20:18], foobar);
+\t\t\t foobar = {foobar, "" 1281""};
+\t\t\t ozoneae(foo[17:15], foobar);
+\t\t\t ozonebmuop(foo[25:21], foobar);
+\t\t\t ozoneae(foo[ 8: 6], foobar);
+\t\t\t foobar = {foobar, "" 1282""};
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1283:%s"", foobar);
+\t\t end
+\t\t 5\'b0_01??:
+\t\t begin
+\t\t\t ozoneae(foo[20:18], foobar);
+\t\t\t foobar = {foobar, "" 1284""};
+\t\t\t ozoneae(foo[17:15], foobar);
+\t\t\t ozonebmuop(foo[25:21], foobar);
+\t\t\t ozonearm(foo[ 8: 6], foobar);
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1285:%s"", foobar);
+\t\t end
+\t\t 5\'b0_1011:
+\t\t begin
+\t\t\t ozoneae(foo[20:18], foobar);
+\t\t\t foobar = {foobar, "" 1286""};
+\t\t\t ozonebmuop(foo[25:21], foobar);
+\t\t\t foobar = {foobar, "" 1287""};
+\t\t\t ozoneae(foo[ 8: 6], foobar);
+\t\t\t foobar = {foobar, "" 1288""};
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1289:%s"", foobar);
+\t\t end
+\t\t 5\'b0_100?,
+\t\t 5\'b0_1010,
+\t\t 5\'b0_110? :
+\t\t\tbegin
+\t\t\t ozoneae(foo[20:18], foobar);
+\t\t\t foobar = {foobar, "" 1290""};
+\t\t\t ozonebmuop(foo[25:21], foobar);
+\t\t\t foobar = {foobar, "" 1291""};
+\t\t\t ozoneae(foo[17:15], foobar);
+\t\t\t foobar = {foobar, "" 1292""};
+\t\t\t ozoneae(foo[ 8: 6], foobar);
+\t\t\t foobar = {foobar, "" 1293""};
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1294:%s"", foobar);
+\t\t\tend
+\t\t 5\'b0_1111 :
+\t\t begin
+\t\t\t ozoneae(foo[20:18], foobar);
+\t\t\t foobar = {foobar, "" 1295""};
+\t\t\t ozoneae(foo[17:15], foobar);
+\t\t\t foobar = {foobar, "" 1296""};
+\t\t\t ozoneae(foo[ 8: 6], foobar);
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1297:%s"", foobar);
+\t\t end
+\t\t 5\'b1_10??,
+\t\t 5\'b1_110?,
+\t\t 5\'b1_1110 :
+\t\t\tbegin
+\t\t\t ozoneae(foo[20:18], foobar);
+\t\t\t foobar = {foobar, "" 1298""};
+\t\t\t ozonebmuop(foo[25:21], foobar);
+\t\t\t foobar = {foobar, "" 1299""};
+\t\t\t ozoneae(foo[17:15], foobar);
+\t\t\t foobar = {foobar, "" 1300""};
+\t\t\t ozonearm(foo[ 8: 6], foobar);
+\t\t\t foobar = {foobar, "" 1301""};
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1302:%s"", foobar);
+\t\t\tend
+\t\t endcase
+ end
+ 17\'b00_0010_?_????_??_???? :
+ begin
+\t\t $fwrite(fd, "" 1304a:%x;%x"", foobar, foo[25:20]);
+\t\t ozonerab({1\'b0, foo[25:20]}, foobar);
+\t\t $fwrite(fd, "" 1304b:%x"", foobar);
+\t\t foobar = {foobar, "" 1303""};
+\t\t $fwrite(fd, "" 1304c:%x;%x"", foobar, foo[19:16]);
+\t\t skyway(foo[19:16], foobar);
+\t\t $fwrite(fd, "" 1304d:%x"", foobar);
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1304e:%x"", foobar);
+\t\t $fwrite(fd, "" 1304:%s"", foobar);
+ end
+ 17\'b00_01??_?_????_??_???? :
+ begin
+\t\t if (foo[27])
+\t\t begin
+\t\t foobar = {foobar, "" 1305""};
+\t\t if (foo[26])
+\t\t\t foobar = {foobar, "" 1306""};
+\t\t else
+\t\t\t foobar = {foobar, "" 1307""};
+\t\t skyway(foo[19:16], foobar);
+\t\t foobar = {foobar, "" 1308""};
+\t\t ozonerab({1\'b0, foo[25:20]}, foobar);
+\t\t end
+\t\t else
+\t\t begin
+\t\t ozonerab({1\'b0, foo[25:20]}, foobar);
+\t\t foobar = {foobar, "" 1309""};
+\t\t if (foo[26])
+\t\t\t foobar = {foobar, "" 1310""};
+\t\t else
+\t\t\t foobar = {foobar, "" 1311""};
+\t\t skyway(foo[19:16], foobar);
+\t\t foobar = {foobar, "" 1312""};
+\t\t end
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1313:%s"", foobar);
+ end
+ 17\'b01_000?_?_????_??_???? :
+ begin
+\t\t if (foo[26])
+\t\t begin
+\t\t ozonerb(foo[25:20], foobar);
+\t\t foobar = {foobar, "" 1314""};
+\t\t ozoneae(foo[18:16], foobar);
+\t\t ozonehl(foo[19], foobar);
+\t\t end
+\t\t else
+\t\t begin
+\t\t ozoneae(foo[18:16], foobar);
+\t\t ozonehl(foo[19], foobar);
+\t\t foobar = {foobar, "" 1315""};
+\t\t ozonerb(foo[25:20], foobar);
+\t\t end
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1316:%s"", foobar);
+ end
+ 17\'b01_10??_?_????_??_???? :
+ begin
+\t\t if (foo[27])
+\t\t begin
+\t\t ozonerab({1\'b0, foo[25:20]}, foobar);
+\t\t foobar = {foobar, "" 1317""};
+\t\t ozonerx(foo, foobar);
+\t\t end
+\t\t else
+\t\t begin
+\t\t ozonerx(foo, foobar);
+\t\t foobar = {foobar, "" 1318""};
+\t\t ozonerab({1\'b0, foo[25:20]}, foobar);
+\t\t end
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1319:%s"", foobar);
+ end
+ 17\'b11_101?_?_????_??_???? :
+ begin
+\t\t ozonerab (foo[26:20], foobar);
+\t\t foobar = {foobar, "" 1320""};
+\t\t skyway(foo[19:16], foobar);
+\t\t skyway(foo[15:12], foobar);
+\t\t skyway(foo[11: 8], foobar);
+\t\t skyway(foo[ 7: 4], foobar);
+\t\t skyway(foo[ 3: 0], foobar);
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1321:%s"", foobar);
+ end
+ 17\'b11_0000_?_????_??_???? :
+ begin
+\t\t casez (foo[25:23])
+\t\t 3\'b00?:
+\t\t begin
+\t\t\t ozonerab(foo[22:16], foobar);
+\t\t\t foobar = {foobar, "" 1322""};
+\t\t end
+\t\t 3\'b01?:
+\t\t begin
+\t\t\t foobar = {foobar, "" 1323""};
+\t\t\t if (foo[22:16]>=7\'h60)
+\t\t\t foobar = {foobar, "" 1324""};
+\t\t\t else
+\t\t\t ozonerab(foo[22:16], foobar);
+\t\t end
+\t\t 3\'b110:
+\t\t foobar = {foobar, "" 1325""};
+\t\t 3\'b10?:
+\t\t begin
+\t\t\t foobar = {foobar, "" 1326""};
+\t\t\t if (foo[22:16]>=7\'h60)
+\t\t\t foobar = {foobar, "" 1327""};
+\t\t\t else
+\t\t\t ozonerab(foo[22:16], foobar);
+\t\t end
+\t\t 3\'b111:
+\t\t begin
+\t\t\t foobar = {foobar, "" 1328""};
+\t\t\t ozonerab(foo[22:16], foobar);
+\t\t\t foobar = {foobar, "" 1329""};
+\t\t end
+\t\t endcase
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1330:%s"", foobar);
+ end
+ 17\'b00_10??_?_????_?1_0000 :
+ begin
+\t\t if (foo[27])
+\t\t begin
+\t\t foobar = {foobar, "" 1331""};
+\t\t ozonerp(foo[14:12], foobar);
+\t\t foobar = {foobar, "" 1332""};
+\t\t skyway(foo[19:16], foobar);
+\t\t skyway({foo[15],foo[11: 9]}, foobar);
+\t\t skyway(foo[ 8: 5], foobar);
+\t\t foobar = {foobar, "" 1333""};
+\t\t if (foo[26:20]>=7\'h60)
+\t\t\t foobar = {foobar, "" 1334""};
+\t\t else
+\t\t\t ozonerab(foo[26:20], foobar);
+\t\t end
+\t\t else
+\t\t begin
+\t\t ozonerab(foo[26:20], foobar);
+\t\t foobar = {foobar, "" 1335""};
+\t\t foobar = {foobar, "" 1336""};
+\t\t ozonerp(foo[14:12], foobar);
+\t\t foobar = {foobar, "" 1337""};
+\t\t skyway(foo[19:16], foobar);
+\t\t skyway({foo[15],foo[11: 9]}, foobar);
+\t\t skyway(foo[ 8: 5], foobar);
+\t\t foobar = {foobar, "" 1338""};
+\t\t end
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1339:%s"", foobar);
+ end
+ 17\'b00_101?_1_0000_?1_0010 :
+ if (~|foo[11: 7])
+\t\t begin
+\t\t if (foo[ 6])
+\t\t begin
+\t\t\t foobar = {foobar, "" 1340""};
+\t\t\t ozonerp(foo[14:12], foobar);
+\t\t\t foobar = {foobar, "" 1341""};
+\t\t\t ozonejk(foo[ 5], foobar);
+\t\t\t foobar = {foobar, "" 1342""};
+\t\t\t if (foo[26:20]>=7\'h60)
+\t\t\t foobar = {foobar, "" 1343""};
+\t\t\t else
+\t\t\t ozonerab(foo[26:20], foobar);
+\t\t end
+\t\t else
+\t\t begin
+\t\t\t ozonerab(foo[26:20], foobar);
+\t\t\t foobar = {foobar, "" 1344""};
+\t\t\t foobar = {foobar, "" 1345""};
+\t\t\t ozonerp(foo[14:12], foobar);
+\t\t\t foobar = {foobar, "" 1346""};
+\t\t\t ozonejk(foo[ 5], foobar);
+\t\t\t foobar = {foobar, "" 1347""};
+\t\t end
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1348:%s"", foobar);
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1349"");
+ 17\'b00_100?_0_0011_?1_0101 :
+ if (~|foo[ 8: 7])
+\t\t begin
+\t\t if (foo[6])
+\t\t begin
+\t\t\t ozonerab(foo[26:20], foobar);
+\t\t\t foobar = {foobar, "" 1350""};
+\t\t\t ozoneye(foo[14: 9],foo[ 5], foobar);
+\t\t end
+\t\t else
+\t\t begin
+\t\t\t ozoneye(foo[14: 9],foo[ 5], foobar);
+\t\t\t foobar = {foobar, "" 1351""};
+\t\t\t if (foo[26:20]>=7\'h60)
+\t\t\t foobar = {foobar, "" 1352""};
+\t\t\t else
+\t\t\t ozonerab(foo[26:20], foobar);
+\t\t end
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1353:%s"", foobar);
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1354"");
+ 17\'b00_1001_0_0000_?1_0010 :
+ if (~|foo[25:20])
+\t\t begin
+\t\t ozoneye(foo[14: 9],1\'b0, foobar);
+\t\t foobar = {foobar, "" 1355""};
+\t\t ozonef1e_h(foo[11: 9],foobar);
+\t\t foobar = {foobar, "" 1356""};
+\t\t ozonef1e_h(foo[ 7: 5],foobar);
+\t\t foobar = {foobar, "" 1357""};
+\t\t ozonexe(foo[ 8: 5], foobar);
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1358:%s"", foobar);
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1359"");
+ 17\'b00_101?_0_????_?1_0010 :
+ if (~foo[13])
+\t\t begin
+\t\t if (foo[12])
+\t\t begin
+\t\t\t foobar = {foobar, "" 1360""};
+\t\t\t if (foo[26:20]>=7\'h60)
+\t\t\t foobar = {foobar, "" 1361""};
+\t\t\t else
+\t\t\t ozonerab(foo[26:20], foobar);
+\t\t\t foobar = {foobar, "" 1362""};
+\t\t\t foobar = {foobar, "" 1363""};
+\t\t\t skyway({1\'b0,foo[18:16]}, foobar);
+\t\t\t skyway({foo[15],foo[11: 9]}, foobar);
+\t\t\t skyway(foo[ 8: 5], foobar);
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1364:%s"", foobar);
+\t\t end
+\t\t else
+\t\t begin
+\t\t\t ozonerab(foo[26:20], foobar);
+\t\t\t foobar = {foobar, "" 1365""};
+\t\t\t foobar = {foobar, "" 1366""};
+\t\t\t skyway({1\'b0,foo[18:16]}, foobar);
+\t\t\t skyway({foo[15],foo[11: 9]}, foobar);
+\t\t\t skyway(foo[ 8: 5], foobar);
+\t\t\t dude(foobar);
+\t\t\t $fwrite(fd, "" 1367:%s"", foobar);
+\t\t end
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1368"");
+ 17\'b01_01??_?_????_??_???? :
+ begin
+\t\t ozonerab({1\'b0,foo[27:26],foo[19:16]}, foobar);
+\t\t foobar = {foobar, "" 1369""};
+\t\t ozonerab({1\'b0,foo[25:20]}, foobar);
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1370:%s"", foobar);
+ end
+ 17\'b00_100?_?_???0_11_0101 :
+ if (~foo[6])
+\t\t begin
+\t\t foobar = "" 1371"";
+\t\t ozonecon(foo[14:10], foobar);
+\t\t foobar = {foobar, "" 1372""};
+\t\t ozonerab({foo[ 9: 7],foo[19:16]}, foobar);
+\t\t foobar = {foobar, "" 1373""};
+\t\t ozonerab({foo[26:20]}, foobar);
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1374:%s"", foobar);
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1375"");
+ 17\'b00_1000_?_????_?1_0010 :
+ if (~|foo[25:24])
+\t\t begin
+\t\t ozonery(foo[23:20], foobar);
+\t\t foobar = {foobar, "" 1376""};
+\t\t ozonerp(foo[14:12], foobar);
+\t\t foobar = {foobar, "" 1377""};
+\t\t skyway(foo[19:16], foobar);
+\t\t skyway({foo[15],foo[11: 9]}, foobar);
+\t\t skyway(foo[ 8: 5], foobar);
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1378:%s"", foobar);
+\t\t end
+ else if ((foo[25:24] == 2\'b10) & ~|foo[19:15] & ~|foo[11: 6])
+\t\t begin
+\t\t ozonery(foo[23:20], foobar);
+\t\t foobar = {foobar, "" 1379""};
+\t\t ozonerp(foo[14:12], foobar);
+\t\t foobar = {foobar, "" 1380""};
+\t\t ozonejk(foo[ 5], foobar);
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1381:%s"", foobar);
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1382"");
+ 17\'b11_01??_?_????_??_????,
+ 17\'b10_00??_?_????_??_???? :
+\t\t if (foo[30])
+\t\t $fwrite(fd, "" 1383:%s"", foo[27:16]);
+\t\t else
+\t\t $fwrite(fd, "" 1384:%s"", foo[27:16]);
+ 17\'b00_10??_?_????_01_1000 :
+ if (~foo[6])
+\t\t begin
+\t\t if (foo[7])
+\t\t $fwrite(fd, "" 1385:%s"", foo[27: 8]);
+\t\t else
+\t\t $fwrite(fd, "" 1386:%s"", foo[27: 8]);
+\t\t end
+ else
+\t\t $fwrite(fd, "" 1387"");
+ 17\'b00_10??_?_????_11_1000 :
+ begin
+\t\t foobar = "" 1388"";
+\t\t ozonecon(foo[14:10], foobar);
+\t\t foobar = {foobar, "" 1389""};
+\t\t if (foo[15])
+\t\t foobar = {foobar, "" 1390""};
+\t\t else
+\t\t foobar = {foobar, "" 1391""};
+\t\t skyway(foo[27:24], foobar);
+\t\t skyway(foo[23:20], foobar);
+\t\t skyway(foo[19:16], foobar);
+\t\t skyway(foo[ 9: 6], foobar);
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1392:%s"", foobar);
+ end
+ 17\'b11_0001_?_????_??_???? :
+ casez (foo[25:22])
+\t\t 4\'b01?? :
+\t\t begin
+\t\t foobar = "" 1393"";
+\t\t ozonecon(foo[20:16], foobar);
+\t\t case (foo[23:21])
+\t\t\t3\'h0 : foobar = {foobar, "" 1394""};
+\t\t\t3\'h1 : foobar = {foobar, "" 1395""};
+\t\t\t3\'h2 : foobar = {foobar, "" 1396""};
+\t\t\t3\'h3 : foobar = {foobar, "" 1397""};
+\t\t\t3\'h4 : foobar = {foobar, "" 1398""};
+\t\t\t3\'h5 : foobar = {foobar, "" 1399""};
+\t\t\t3\'h6 : foobar = {foobar, "" 1400""};
+\t\t\t3\'h7 : foobar = {foobar, "" 1401""};
+\t\t endcase
+\t\t dude(foobar);
+\t\t $fwrite(fd, "" 1402:%s"", foobar);
+\t\t end
+\t\t 4\'b0000 :
+\t\t $fwrite(fd, "" 1403:%s"", foo[21:16]);
+\t\t 4\'b0010 :
+\t\t if (~|foo[21:16])
+ $fwrite(fd, "" 1404"");
+\t\t 4\'b1010 :
+\t\t if (~|foo[21:17])
+\t\t begin
+\t\t\tif (foo[16])
+\t\t\t $fwrite(fd, "" 1405"");
+\t\t\telse
+\t\t\t $fwrite(fd, "" 1406"");
+\t\t end
+\t\t default :
+\t\t $fwrite(fd, "" 1407"");
+ endcase
+ 17\'b01_11??_?_????_??_???? :
+ if (foo[27:23] === 5\'h00)
+\t\t $fwrite(fd, "" 1408:%s"", foo[22:16]);
+ else
+\t\t $fwrite(fd, "" 1409:%s"", foo[22:16]);
+ default: $fwrite(fd, "" 1410"");
+\t endcase
+ end
+ endtask
+
+ //(query-replace-regexp ""\\\\([a-z0-9_]+\\\\) *( *\\\\([][a-z0-9_~\': ]+\\\\) *, *\\\\([][a-z0-9\'~: ]+\\\\) *, *\\\\([][a-z0-9\'~: ]+\\\\) *);"" ""$c(\\""\\\\1(\\"",\\\\2,\\"",\\"",\\\\3,\\"",\\"",\\\\4,\\"");\\"");"" nil nil nil)
+ //(query-replace-regexp ""\\\\([a-z0-9_]+\\\\) *( *\\\\([][a-z0-9_~\': ]+\\\\) *, *\\\\([][a-z0-9\'~: ]+\\\\) *);"" ""$c(\\""\\\\1(\\"",\\\\2,\\"",\\"",\\\\3,\\"");\\"");"" nil nil nil)
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ integer i;
+ integer a_var;
+
+ sub sub ();
+
+ initial begin
+ nf = 0; // z not found
+ sub.subsubz.inss = 0; // subsub not found
+ i = nofunc(); // nofunc not found
+ notask(); // notask not found
+ a_var();\t// Calling variable as task
+ $finish;
+ end
+endmodule
+
+module sub;
+ subsub subsub ();
+endmodule
+
+module subsub;
+ integer inss;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+//See bug289
+
+`include ""t_preproc_inc_inc_bad.vh""
+
+module t;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+ reg dimn;
+ reg [1:0] dim0;
+ reg [1:0] dim1 [1:0];
+ reg [1:0] dim2 [1:0][1:0];
+ reg\t dim0nv[1:0];
+
+ initial begin
+ dimn[1:0] = 0;\t\t// Bad: Not ranged
+ dim0[1][1] = 0;\t\t// Bad: Not arrayed
+ dim1[1][1][1] = 0;\t// Bad: Not arrayed to right depth
+ dim2[1][1][1] = 0;\t// OK
+ dim2[0 +: 1][1] = 0;\t// Bad: Range on non-bits
+ dim2[1 : 0][1] = 0;\t// Bad: Range on non-bits
+ dim2[1][1:0] = 0;\t\t// Bad: Bitsel too soon
+ dim0nv[1:0] = 0;\t\t// Bad: Not vectored
+ dim0nv[1][1] = 0;\t\t// Bad: Not arrayed to right depth
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ wire [1:0] \ta = crc[1 +: 2];
+ wire [1:0] \tb = crc[3 +: 2];
+ wire [1:0] \tc = crc[5 +: 2];
+ wire [1:0] \td = crc[7 +: 2];
+ wire [1:0] \te = crc[9 +: 2];
+ wire [1:0] \tf = crc[11+: 2];
+ wire [1:0] \tg = crc[13+: 2];
+
+ //\tleft\t() [] :: .
+ //\tunary\t+ - ! ~ & ~& | ~| ^ ~^ ^~ ++ -- (unary)
+ //\tleft\t**
+ //\tleft\t* / %
+ //\tleft\t+ - (binary)
+ //\tleft\t<< >> <<< >>>
+ //\tleft\t< <= > >= inside dist
+ //\tleft\t== != === !== ==? !=?
+ //\tleft\t& (binary)
+ //\tleft\t^ ~^ ^~ (binary)
+ //\tleft\t| (binary)
+ //\tleft\t&&
+ //\tleft\t||
+ //\tleft\t? :
+ //\tright\t->
+ //\tnone\t= += -= *= /= %= &= ^= |= <<= >>= <<<= >>>= := :/ <=
+ //\t\t{} {{}} concatenation
+
+ wire [1:0] \tbnz = (b==2\'b0) ? 2\'b11 : b;
+ wire [1:0] \tcnz = (c==2\'b0) ? 2\'b11 : c;
+ wire [1:0] \tdnz = (d==2\'b0) ? 2\'b11 : d;
+ wire [1:0] \tenz = (e==2\'b0) ? 2\'b11 : e;
+
+ // verilator lint_off WIDTH
+ // Do a few in each group
+ wire [1:0] o1 = ~ a; // Can\'t get more than one reduction to parse
+ wire [1:0] o2 = ^ b; // Can\'t get more than one reduction to parse
+ wire [1:0] o3 = a ** b ** c; // Some simulators botch this
+
+ wire [1:0] o4 = a * b / cnz % dnz * enz;
+ wire [1:0] o5 = a + b - c + d;
+ wire [1:0] o6 = a << b >> c <<< d >>> e <<< f;
+ wire [1:0] o7 = a < b <= c;
+ wire [1:0] o8 = a == b != c === d == e;
+ wire [1:0] o9 = a & b & c;
+ wire [1:0] o10 = a ^ b ~^ c ^~ d ^ a;
+ wire [1:0] o11 = a | b | c;
+ wire [1:0] o12 = a && b && c;
+ wire [1:0] o13 = a || b || c;
+ wire [1:0] o14 = a ? b ? c : d : e;
+ wire [1:0] o15 = a ? b : c ? d : e;
+
+ // Now cross each pair of groups
+ wire [1:0] x1 = ~ a ** ~ b ** ~c; // Some simulators botch this
+ wire [1:0] x2 = a ** b * c ** d; // Some simulators botch this
+ wire [1:0] x3 = a + b * c + d;
+ wire [1:0] x4 = a + b << c + d;
+ wire [1:0] x5 = a == b << c == d;
+ wire [1:0] x6 = a & b << c & d;
+ wire [1:0] x7 = a ^ b & c ^ d;
+ wire [1:0] x8 = a | b ^ c | d;
+ wire [1:0] x9 = a && b | c && d;
+ wire [1:0] x10 = a || b && c || d;
+ wire [1:0] x11 = a ? b || c : d ? e : f;
+
+ // verilator lint_on WIDTH
+
+ function [1:0] pow (input [1:0] x, input [1:0] y);
+ casez ({x,y})
+\t4\'b00_??: pow = 2\'b00;
+\t4\'b01_00: pow = 2\'b01;
+\t4\'b01_01: pow = 2\'b01;
+\t4\'b01_10: pow = 2\'b01;
+\t4\'b01_11: pow = 2\'b01;
+\t4\'b10_00: pow = 2\'b01;
+\t4\'b10_01: pow = 2\'b10;
+\t4\'b10_10: pow = 2\'b00;
+\t4\'b10_11: pow = 2\'b00;
+\t4\'b11_00: pow = 2\'b01;
+\t4\'b11_01: pow = 2\'b11;
+\t4\'b11_10: pow = 2\'b01;
+\t4\'b11_11: pow = 2\'b11;
+ endcase
+ endfunction
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {12\'h0,
+\t\t\t x11,x10,x9,x8,x7,x6,x5,x4,x3,x2,x1,
+\t\t\t o15,o14,o13,o12,o11,o10,o9,o8,o7,o6,o5,o4,o3,o2,o1};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x "",$time, cyc, crc, result);
+ $write("" %b"",o1);
+ $write("" %b"",o2);
+ $write("" %b"",o3);
+ $write("" %b"",o4);
+ $write("" %b"",o5);
+ $write("" %b"",o6);
+ $write("" %b"",o7);
+ $write("" %b"",o8);
+ $write("" %b"",o9);
+ $write("" %b"",o10);
+ $write("" %b"",o11);
+ $write("" %b"",o12);
+ $write("" %b"",o13);
+ $write("" %b"",o14);
+ $write("" %b"",o15);
+ // Now cross each pair of groups
+ $write("" %b"",x1);
+ $write("" %b"",x2);
+ $write("" %b"",x3);
+ $write("" %b"",x4);
+ $write("" %b"",x5);
+ $write("" %b"",x6);
+ $write("" %b"",x7);
+ $write("" %b"",x8);
+ $write("" %b"",x9);
+ $write("" %b"",x10);
+ $write("" %b"",x11);
+ $write(""\
+"");
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h2756ea365ec7520e
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2009 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+module t ();
+
+ sub a (.inst(1));
+ sub b (.inst(2));
+
+ initial begin
+ a.test1;
+ b.test1;
+ a.test2;
+ b.test2;
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+module sub (input integer inst);
+
+ import ""DPI-C"" context function int dpic_line();
+ import ""DPI-C"" context function int dpic_save(int value);
+ import ""DPI-C"" context function int dpic_restore();
+ import ""DPI-C"" context function int unsigned dpic_getcontext();
+
+ int result;
+
+ task test1;
+ // Check line numbering
+`ifndef verilator // Not all sims support SV2009 `__LINE__, and some that do fail the specific-line test
+ result = dpic_line(); if (!result) $stop;
+`else
+ result = dpic_line(); if (result !== `__LINE__) $stop;
+ //
+ result = dpic_line(); if (result !== `__LINE__) $stop;
+`endif
+
+ // Check save-restore
+ result = dpic_save(23+inst);
+ if (result==0) $stop;
+ endtask
+
+ task test2;
+ if (dpic_restore() != 23+inst) $stop;
+ endtask
+
+ int unsigned cntxt1;
+ int unsigned cntxt2;
+
+ initial begin
+ cntxt1 = dpic_getcontext();
+ begin : caller_context
+ // call from a different scope - should still get the context of the function declaration
+ cntxt2 = dpic_getcontext();
+ end
+ // svContext should be the context of the function declaration, not the context of the function call
+ if (cntxt1 != cntxt2) $stop;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// A test of the +1364-1995ext+ and +systemverilogext+ flags.
+//
+// This source code contains constructs that are valid in SystemVerilog 2009
+// but not in Verilog 1995. So it should fail if we set the language to be
+// Verilog 1995, but not SystemVerilog 2009.
+//
+// Compile only test, so no need for ""All Finished"" output.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Jeremy Bennett.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ reg [1:0] \tres;
+
+
+ // Instantiate the test
+ test test_i (/*AUTOINST*/
+\t // Outputs
+\t .res\t\t\t(res),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(1\'b1));
+
+endmodule
+
+module test (// Outputs
+\t res,
+\t // Inputs
+\t clk,
+\t in
+ );
+ output [1:0] res;
+ input \t clk;
+ input \t in;
+
+ // This is a SystemVerilog 2009 only test
+ generate
+ genvar i;
+ for (i=0; i<2; i=i+1) begin
+\t always @(posedge clk) begin
+\t unique0 case (i)
+\t\t 0: res[0:0] <= in;
+\t\t 1: res[1:1] <= in;
+\t\t endcase
+\t end
+ end
+ endgenerate
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer cyc; initial cyc=0;
+ reg [63:0] crc;
+ reg [63:0] sum;
+
+ reg \t out1;
+ sub sub (.in(crc[23:0]), .out1(out1));
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x sum=%x out=%x\
+"",$time, cyc, crc, sum, out1);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= {sum[62:0], sum[63]^sum[2]^sum[0]} ^ {63\'h0,out1};
+ if (cyc==1) begin
+\t // Setup
+\t crc <= 64\'h00000000_00000097;
+\t sum <= 64\'h0;
+ end
+ else if (cyc==90) begin
+\t if (sum !== 64\'h2e5cb972eb02b8a0) $stop;
+ end
+ else if (cyc==91) begin
+ end
+ else if (cyc==92) begin
+ end
+ else if (cyc==93) begin
+ end
+ else if (cyc==94) begin
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module sub (/*AUTOARG*/
+ // Outputs
+ out1,
+ // Inputs
+ in
+ );
+
+ input [23:0] in;
+ output reg [0:0] out1; // Note this tests a vector of 1 bit, which is different from a non-arrayed signal
+
+ parameter [1023:0] RANDOM = 1024\'b101011010100011011100111101001000000101000001111111111100110000110011011010110011101000100110000110101111101000111100100010111001001110001010101000111000100010000010011100001100011110110110000101100011111000110111110010110011000011111111010101110001101010010001111110111100000110111101100110101110001110110000010000110101110111001111001100001101110001011100111001001110101001010000110101010100101111000010000010110100101110100110000110110101000100011101111100011000110011001100010010011001101100100101110010100110101001110011111110010000111001111000010001101100101101110111110001000010110010011100101001011111110011010110111110000110010011110001110110011010011010110011011111001110100010110100011100001011000101111000010011111010111001110110011101110101011111001100011000101000001000100111110010100111011101010101011001101000100000101111110010011010011010001111010001110000110010100011110110011001010000011001010010110111101010010011111111010001000101100010100100010011001100110000111111000001000000001001111101110000100101;
+
+ always @* begin
+ casez (in[17:16])
+\t2\'b00: casez (in[2:0])
+\t\t 3\'h0:\tout1[0] = in[0]^RANDOM[0];
+\t\t 3\'h1:\tout1[0] = in[0]^RANDOM[1];
+\t\t 3\'h2:\tout1[0] = in[0]^RANDOM[2];
+\t\t 3\'h3:\tout1[0] = in[0]^RANDOM[3];
+\t\t 3\'h4:\tout1[0] = in[0]^RANDOM[4];
+\t\t 3\'h5:\tout1[0] = in[0]^RANDOM[5];
+\t\t 3\'h6:\tout1[0] = in[0]^RANDOM[6];
+\t\t 3\'h7:\tout1[0] = in[0]^RANDOM[7];
+\t endcase
+\t2\'b01: casez (in[2:0])
+\t\t 3\'h0:\tout1[0] = RANDOM[10];
+\t\t 3\'h1:\tout1[0] = RANDOM[11];
+\t\t 3\'h2:\tout1[0] = RANDOM[12];
+\t\t 3\'h3:\tout1[0] = RANDOM[13];
+\t\t 3\'h4:\tout1[0] = RANDOM[14];
+\t\t 3\'h5:\tout1[0] = RANDOM[15];
+\t\t 3\'h6:\tout1[0] = RANDOM[16];
+\t\t 3\'h7:\tout1[0] = RANDOM[17];
+\t endcase
+\t2\'b1?: casez (in[4])
+\t\t 1\'b1: casez (in[2:0])
+\t\t\t 3\'h0:\tout1[0] = RANDOM[20];
+\t\t\t 3\'h1:\tout1[0] = RANDOM[21];
+\t\t\t 3\'h2:\tout1[0] = RANDOM[22];
+\t\t\t 3\'h3:\tout1[0] = RANDOM[23];
+\t\t\t 3\'h4:\tout1[0] = RANDOM[24];
+\t\t\t 3\'h5:\tout1[0] = RANDOM[25];
+\t\t\t 3\'h6:\tout1[0] = RANDOM[26];
+\t\t\t 3\'h7:\tout1[0] = RANDOM[27];
+\t\t endcase
+\t\t 1\'b0: casez (in[2:0])
+\t\t\t 3\'h0:\tout1[0] = RANDOM[30];
+\t\t\t 3\'h1:\tout1[0] = RANDOM[31];
+\t\t\t 3\'h2:\tout1[0] = RANDOM[32];
+\t\t\t 3\'h3:\tout1[0] = RANDOM[33];
+\t\t\t 3\'h4:\tout1[0] = RANDOM[34];
+\t\t\t 3\'h5:\tout1[0] = RANDOM[35];
+\t\t\t 3\'h6:\tout1[0] = RANDOM[36];
+\t\t\t 3\'h7:\tout1[0] = RANDOM[37];
+\t\t endcase
+\t endcase
+ endcase
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ // verilator lint_off GENCLK
+ reg \t gendlyclk_r;
+ reg [31:0] gendlydata_r;
+ reg [31:0] dlydata_gr;
+
+ reg \t genblkclk;
+ reg [31:0] genblkdata;
+ reg [31:0] blkdata_gr;
+
+ wire [31:0] constwire = 32\'h11;
+ reg [31:0] initwire;
+
+ integer i;
+ initial begin
+ for (i=0; i<10000; i=i+1) begin
+\t initwire = 32\'h2200;
+ end
+ end
+
+ wire [31:0] either = gendlydata_r | dlydata_gr | blkdata_gr | initwire | constwire;
+ wire [31:0] either_unused = gendlydata_r | dlydata_gr | blkdata_gr | initwire | constwire;
+
+ always @ (posedge clk) begin
+ gendlydata_r <= 32\'h0011_0000;
+ gendlyclk_r <= 0;
+ // surefire lint_off SEQASS
+ genblkclk = 0;
+ genblkdata = 0;
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==2) begin
+\t gendlyclk_r <= 1;
+\t gendlydata_r <= 32\'h00540000;
+\t genblkclk = 1;
+\t genblkdata = 32\'hace;
+\t $write(""[%0t] Send pulse\
+"", $time);
+\t end
+\t if (cyc==3) begin
+\t genblkdata = 32\'hdce;
+\t gendlydata_r <= 32\'h00ff0000;
+\t if (either != 32\'h87542211) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ // surefire lint_on SEQASS
+ end
+
+ always @ (posedge gendlyclk_r) begin
+ if ($time>0) begin\t// Hack, don\'t split the block
+\t $write(""[%0t] Got gendlyclk_r, d=%x b=%x\
+"", $time, gendlydata_r, genblkdata);
+\t dlydata_gr <= 32\'h80000000;
+\t // Delayed activity list will already be completed for gendlydata
+\t // because genclk is from a delayed assignment.
+\t // Thus we get the NEW not old value of gendlydata_r
+\t if (gendlydata_r != 32\'h00540000) $stop;
+\t if (genblkdata != 32\'hace) $stop;
+ end
+ end
+
+ always @ (posedge genblkclk) begin
+ if ($time>0) begin\t// Hack, don\'t split the block
+\t $write(""[%0t] Got genblkclk, d=%x b=%x\
+"", $time, gendlydata_r, genblkdata);
+\t blkdata_gr <= 32\'h07000000;
+\t // Clock from non-delayed assignment, we get old value of gendlydata_r
+`ifdef verilator `else\t// V3.2 races... technically legal
+\t if (gendlydata_r != 32\'h00110000) $stop;
+`endif
+\t if (genblkdata != 32\'hace) $stop;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module sub;
+ integer i;
+ initial begin
+ i = 23.2;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ wire [3:0] drv_a = crc[3:0];
+ wire [3:0] drv_b = crc[7:4];
+ wire [3:0] drv_e = crc[19:16];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [8:0]\t\tmatch1;\t\t\t// From test1 of Test1.v
+ wire [8:0]\t\tmatch2;\t\t\t// From test2 of Test2.v
+ // End of automatics
+
+ Test1 test1 (/*AUTOINST*/
+\t\t// Outputs
+\t\t.match1\t\t\t(match1[8:0]),
+\t\t// Inputs
+\t\t.drv_a\t\t\t(drv_a[3:0]),
+\t\t.drv_e\t\t\t(drv_e[3:0]));
+ Test2 test2 (/*AUTOINST*/
+\t\t// Outputs
+\t\t.match2\t\t\t(match2[8:0]),
+\t\t// Inputs
+\t\t.drv_a\t\t\t(drv_a[3:0]),
+\t\t.drv_e\t\t\t(drv_e[3:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] \t\tresult = {39\'h0, match2, 7\'h0, match1};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x m1=%x m2=%x (%b??%b:%b)\
+"",$time, cyc, crc, match1, match2, drv_e,drv_a,drv_b);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'hc0c4a2b9aea7c4b4
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test1
+ (
+ input wire [3:0] drv_a,
+ input wire [3:0] drv_e,
+ output wire [8:0] match1
+ );
+
+ wire [2:1] drv_all;
+ bufif1 bufa [2:1] (drv_all, drv_a[2:1], drv_e[2:1]);
+
+`ifdef VERILATOR
+ // At present Verilator only allows comparisons with Zs
+ assign match1[0] = (drv_a[2:1]== 2\'b00 && drv_e[2:1]==2\'b11);
+ assign match1[1] = (drv_a[2:1]== 2\'b01 && drv_e[2:1]==2\'b11);
+ assign match1[2] = (drv_a[2:1]== 2\'b10 && drv_e[2:1]==2\'b11);
+ assign match1[3] = (drv_a[2:1]== 2\'b11 && drv_e[2:1]==2\'b11);
+`else
+ assign match1[0] = drv_all === 2\'b00;
+ assign match1[1] = drv_all === 2\'b01;
+ assign match1[2] = drv_all === 2\'b10;
+ assign match1[3] = drv_all === 2\'b11;
+`endif
+ assign match1[4] = drv_all === 2\'bz0;
+ assign match1[5] = drv_all === 2\'bz1;
+ assign match1[6] = drv_all === 2\'bzz;
+ assign match1[7] = drv_all === 2\'b0z;
+ assign match1[8] = drv_all === 2\'b1z;
+endmodule
+
+module Test2
+ (
+ input wire [3:0] drv_a,
+ input wire [3:0] drv_e,
+ output wire [8:0] match2
+ );
+
+ wire [2:1] drv_all;
+ bufif1 bufa [2:1] (drv_all, drv_a[2:1], drv_e[2:1]);
+
+`ifdef VERILATOR
+ assign match2[0] = (drv_all !== 2\'b00 || drv_e[2:1]!=2\'b11);
+ assign match2[1] = (drv_all !== 2\'b01 || drv_e[2:1]!=2\'b11);
+ assign match2[2] = (drv_all !== 2\'b10 || drv_e[2:1]!=2\'b11);
+ assign match2[3] = (drv_all !== 2\'b11 || drv_e[2:1]!=2\'b11);
+`else
+ assign match2[0] = drv_all !== 2\'b00;
+ assign match2[1] = drv_all !== 2\'b01;
+ assign match2[2] = drv_all !== 2\'b10;
+ assign match2[3] = drv_all !== 2\'b11;
+`endif
+ assign match2[4] = drv_all !== 2\'bz0;
+ assign match2[5] = drv_all !== 2\'bz1;
+ assign match2[6] = drv_all !== 2\'bzz;
+ assign match2[7] = drv_all !== 2\'b0z;
+ assign match2[8] = drv_all !== 2\'b1z;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg [63:0] rf;
+ reg [63:0] rf2;
+ reg [63:0] biu;
+ reg\t okidoki;
+
+ always @* begin
+ rf[63:32] = biu[63:32] & {32{okidoki}};
+ rf[31:0] = {32{okidoki}};
+ rf2 = rf;
+ rf2[31:0] = ~{32{okidoki}};
+ end
+
+ reg [31:0] src1, src0, sr, mask;
+ wire [31:0] dualasr
+\t = ((| src1[31:4])
+\t\t ? {{16{src0[31]}}, {16{src0[15]}}}
+\t\t : ( ( sr & {2{mask[31:16]}})
+\t\t | ( {{16{src0[31]}}, {16{src0[15]}}}
+\t\t\t & {2{~mask[31:16]}})));
+
+ wire [31:0] sl_mask
+\t = (32\'hffffffff << src1[4:0]);
+
+ wire [31:0] sr_mask
+\t = {sl_mask[0], sl_mask[1],
+\t\t sl_mask[2], sl_mask[3], sl_mask[4],
+ sl_mask[5], sl_mask[6], sl_mask[7],
+\t\t sl_mask[8], sl_mask[9],
+ sl_mask[10], sl_mask[11],
+\t\t sl_mask[12], sl_mask[13], sl_mask[14],
+ sl_mask[15], sl_mask[16],
+\t\t sl_mask[17], sl_mask[18], sl_mask[19],
+ sl_mask[20], sl_mask[21],
+\t\t sl_mask[22], sl_mask[23], sl_mask[24],
+ sl_mask[25], sl_mask[26],
+\t\t sl_mask[27], sl_mask[28], sl_mask[29],
+ sl_mask[30], sl_mask[31]};
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+`ifdef TEST_VERBOSE
+\t $write(""%x %x %x %x %x\
+"", rf, rf2, dualasr, sl_mask, sr_mask);
+`endif
+\t if (cyc==1) begin
+\t biu <= 64\'h12451282_abadee00;
+\t okidoki <= 1\'b0;
+\t src1 <= 32\'h00000001;
+\t src0 <= 32\'h9a4f1235;
+\t sr <= 32\'h0f19f567;
+\t mask <= 32\'h7af07ab4;
+\t end
+\t if (cyc==2) begin
+\t biu <= 64\'h12453382_abad8801;
+\t okidoki <= 1\'b1;
+\t if (rf != 64\'h0) $stop;
+\t if (rf2 != 64\'h00000000ffffffff) $stop;
+\t src1 <= 32\'h0010000f;
+\t src0 <= 32\'h028aa336;
+\t sr <= 32\'h42ad0377;
+\t mask <= 32\'h1ab3b906;
+\t if (dualasr != 32\'h8f1f7060) $stop;
+\t if (sl_mask != 32\'hfffffffe) $stop;
+\t if (sr_mask != 32\'h7fffffff) $stop;
+\t end
+\t if (cyc==3) begin
+\t biu <= 64\'h12422382_77ad8802;
+\t okidoki <= 1\'b1;
+\t if (rf != 64\'h12453382ffffffff) $stop;
+\t if (rf2 != 64\'h1245338200000000) $stop;
+\t src1 <= 32\'h0000000f;
+\t src0 <= 32\'h5c158f71;
+\t sr <= 32\'h7076c40a;
+\t mask <= 32\'h33eb3d44;
+\t if (dualasr != 32\'h0000ffff) $stop;
+\t if (sl_mask != 32\'hffff8000) $stop;
+\t if (sr_mask != 32\'h0001ffff) $stop;
+\t end
+\t if (cyc==4) begin
+\t if (rf != 64\'h12422382ffffffff) $stop;
+\t if (rf2 != 64\'h1242238200000000) $stop;
+\t if (dualasr != 32\'h3062cc1e) $stop;
+\t if (sl_mask != 32\'hffff8000) $stop;
+\t if (sr_mask != 32\'h0001ffff) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire \tpick1 = crc[0];
+ wire [13:0][1:0] data1 = crc[27+1:1];
+ wire [3:0][2:0][1:0] data2 = crc[23+29:29];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ logic [15:0] [1:0]\tdatao;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .datao\t\t\t(datao/*[15:0][1:0]*/),
+\t // Inputs
+\t .pick1\t\t\t(pick1),
+\t .data1\t\t\t(data1/*[13:0][1:0]*/),
+\t .data2\t\t\t(data2/*[2:0][3:0][1:0]*/));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {32\'h0, datao};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h3ff4bf0e6407b281
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test
+ (
+ input logic \t\t\t pick1,
+ input logic [13:0] [1:0] \t data1, // 14 x 2 = 28 bits
+ input logic [ 3:0] [2:0] [1:0] data2, // 4 x 3 x 2 = 24 bits
+ output logic [15:0] [1:0] \t datao // 16 x 2 = 32 bits
+ );
+ // verilator lint_off WIDTH
+ always_comb datao[13: 0] // 28 bits
+ = (pick1)
+ ? {data1} // 28 bits
+ : {\'0, data2}; // 25-28 bits, perhaps not legal as \'0 is unsized
+ // verilator lint_on WIDTH
+ always_comb datao[15:14] = \'0;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [2:0]\t\tq;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (
+\t // Outputs
+\t .q\t\t\t(q[2:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .reset_l\t\t\t(crc[0]),
+\t .enable\t\t\t(crc[2]),
+\t .q_var0\t\t\t(crc[19:10]),
+\t .q_var2\t\t\t(crc[29:20]),
+\t .q_var4\t\t\t(crc[39:30]),
+\t .q_var6\t\t\t(crc[49:40])
+\t /*AUTOINST*/);
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {61\'h0,q};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+`define EXPECTED_SUM 64\'h58b162c58d6e35ba
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+
+module Test
+ (
+ input clk,
+ input reset_l,
+ input enable,
+
+ input [ 9:0] q_var0,
+ input [ 9:0] q_var2,
+ input [ 9:0] q_var4,
+ input [ 9:0] q_var6,
+
+ output reg [2:0] q
+ );
+
+ reg [7:0] \t p1_r [6:0];
+
+ always @(posedge clk) begin
+ if (!reset_l) begin
+ p1_r[0] <= \'b0;
+ p1_r[1] <= \'b0;
+ p1_r[2] <= \'b0;
+ p1_r[3] <= \'b0;
+ p1_r[4] <= \'b0;
+ p1_r[5] <= \'b0;
+ p1_r[6] <= \'b0;
+ end
+ else if (enable) begin : pass1
+ match(q_var0, q_var2, q_var4, q_var6);
+ end
+ end
+
+ // verilator lint_off WIDTH
+ always @(posedge clk) begin : l
+ reg [10:0] bd;
+ reg [3:0] idx;
+
+ q = 0;
+ bd = 0;
+ for (idx=0; idx<7; idx=idx+1) begin
+\t q = idx+1;
+\t bd = bd + p1_r[idx];
+ end
+ end
+
+
+ task match;
+ input [9:0] p0, p1, p2, p3;
+ reg [9:0] p[3:0];
+ begin
+\t p[0] = p0;
+\t p[1] = p1;
+\t p[2] = p2;
+\t p[3] = p3;
+\t p1_r[0] = p[0];
+\t p1_r[1] = p[1];
+ end
+ endtask
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2009 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+module t ();
+
+ // Can\'t handle logic (yet?)
+ import ""DPI-C"" dpii_fa_bit = function int oth_f_int1(input logic [2:0] i);
+
+ initial begin
+ $stop;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ reg \t _ranit;
+
+ `include ""t_initial_inc.vh""
+
+ // surefire lint_off STMINI
+ initial assign user_loaded_value = 1;
+
+ initial _ranit = 0;
+
+ always @ (posedge clk) begin
+ if (!_ranit) begin
+\t _ranit <= 1;
+
+\t // Test $time
+\t // surefire lint_off CWECBB
+\t if ($time<20) $write(""time<20\
+"");
+\t // surefire lint_on CWECBB
+
+\t // Test $write
+\t $write (""[%0t] %m: User loaded "", $time);
+\t $display (""%b"", user_loaded_value);
+\t if (user_loaded_value!=1) $stop;
+
+\t // Test $c
+`ifdef VERILATOR
+\t $c (""VL_PRINTF(\\""Hi From C++\\\
+\\"");"");
+`endif
+\t user_loaded_value <= 2;
+
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// A test of the +verilog2001ext+ and +verilog2005ext+ flags.
+//
+// This source code uses the uwire declaration, which is only valid in Verilog
+// 2005.
+//
+// Compile only test, so no need for ""All Finished"" output.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Jeremy Bennett.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ uwire w;\t\t\t// Only in Verilog 2005
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+// Very simple test for interface pathclearing
+
+`ifdef VCS
+ `define UNSUPPORTED_MOD_IN_GENS
+`endif
+`ifdef VERILATOR
+ `define UNSUPPORTED_MOD_IN_GENS
+`endif
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc=1;
+
+ ifc #(1) itopa();
+ ifc #(2) itopb();
+
+ sub #(1) ca (.isub(itopa),
+\t\t.i_value(4));
+ sub #(2) cb (.isub(itopb),
+\t\t.i_value(5));
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==1) begin
+\t if (itopa.MODE != 1) $stop;
+\t if (itopb.MODE != 2) $stop;
+ end
+ if (cyc==20) begin
+\t if (itopa.get_value() != 4) $stop;
+\t if (itopb.get_value() != 5) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module sub
+ #(parameter MODE = 0)
+ (
+ ifc.out_modport isub,
+ input integer i_value
+ );
+
+`ifdef UNSUPPORTED_MOD_IN_GENS
+ always @* isub.value = i_value;
+`else
+ generate if (MODE == 1) begin
+ always @* isub.valuea = i_value;
+ end
+ else if (MODE == 2) begin
+ always @* isub.valueb = i_value;
+ end
+ endgenerate
+`endif
+
+endmodule
+
+interface ifc;
+ parameter MODE = 0;
+ // Modports under generates not supported by all commercial simulators
+`ifdef UNSUPPORTED_MOD_IN_GENS
+ integer value;
+ modport out_modport (output value);
+ function integer get_value(); return value; endfunction
+`else
+ generate if (MODE == 0) begin
+ integer valuea;
+ modport out_modport (output valuea);
+ function integer get_valuea(); return valuea; endfunction
+ end
+ else begin
+ integer valueb;
+ modport out_modport (output valueb);
+ function integer get_valueb(); return valueb; endfunction
+ end
+ endgenerate
+`endif
+endinterface
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ fastclk
+ );
+ input fastclk;
+
+ t_netlist tnetlist
+ (.also_fastclk\t(fastclk),
+ /*AUTOINST*/
+ // Inputs
+ .fastclk\t\t\t\t(fastclk));
+
+endmodule
+
+module t_netlist (/*AUTOARG*/
+ // Inputs
+ fastclk, also_fastclk
+ );
+
+ // surefire lint_off ASWEMB
+
+ input fastclk;
+ input also_fastclk;
+ integer _mode; initial _mode = 0;
+
+ // This entire module should optimize to nearly nothing...
+
+ // verilator lint_off UNOPTFLAT
+ reg [4:0] a,a2,b,c,d,e;
+ // verilator lint_on UNOPTFLAT
+
+ initial a=5\'d1;
+
+ always @ (posedge fastclk) begin
+ b <= a+5\'d1;
+ c <= b+5\'d1; // Better for ordering if this moves before previous statement
+ end
+
+ // verilator lint_off UNOPT
+ always @ (d or /*AS*/a or c) begin
+ e = d+5\'d1;
+ a2 = a+5\'d1; // This can be pulled out of the middle of the always
+ d = c+5\'d1; // Better for ordering if this moves before previous statement
+ end
+ // verilator lint_on UNOPT
+
+ always @ (posedge also_fastclk) begin
+ if (_mode==5) begin
+\t if (a2 != 5\'d2) $stop;
+\t if (e != 5\'d5) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ _mode <= _mode + 1;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t;
+ reg do;
+ mod mod (.do(bar));
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [33:0] in = crc[33:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [31:0]\t\tcode;\t\t\t// From test of Test.v
+ wire [4:0]\t\tlen;\t\t\t// From test of Test.v
+ wire\t\t\tnext;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .next\t\t\t(next),
+\t .code\t\t\t(code[31:0]),
+\t .len\t\t\t(len[4:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(in[33:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {26\'h0, next, len, code};
+
+ // What checksum will we end up with
+`define EXPECTED_SUM 64\'h5537fa30d49bf865
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ next, code, len,
+ // Inputs
+ clk, in
+ );
+
+ input clk;
+ input [33:0] in;
+ output \t next;
+ output [31:0] code;
+ output [4:0]\t len;
+
+ /*AUTOREG*/
+ // Beginning of automatic regs (for this module\'s undeclared outputs)
+ reg [31:0]\t\tcode;
+ reg [4:0]\t\tlen;
+ reg\t\t\tnext;
+ // End of automatics
+
+/*
+#!/usr/bin/perl -w
+srand(5);
+my @used;
+pat:
+ for (my $pat=0; 1; ) {
+ last if $pat > 196;
+ my $len = int($pat / (6 + $pat/50)) + 4; $len=20 if $len>20;
+ my ($try, $val, $mask);
+ try:
+ for ($try=0; ; $try++) {
+\tnext pat if $try>50;
+\t$val = 0;
+\tfor (my $bit=23; $bit>(23-$len); $bit--) {
+\t my $b = int(rand()*2);
+\t $val |= (1<<$bit) if $b;
+\t}
+\t$mask = (1<<(23-$len+1))-1;
+\tfor (my $testval = $val; $testval <= ($val + $mask); $testval ++) {
+\t next try if $used[$testval];
+\t}
+\tlast;
+ }
+ my $bits = """";
+ my $val2 = 0;
+ for (my $bit=23; $bit>(23-$len); $bit--) {
+\tmy $b = ($val & (1<<$bit));
+\t$bits .= $b?\'1\':\'0\';
+ }
+ for (my $testval = $val; $testval <= ($val + $mask); $testval++) {
+\t$used[$testval]= 1; #printf ""U%08x\
+"", $testval;
+ }
+ if ($try<90) {
+\tprintf +("" 24\'b%s: {next, len, code} = {in[%02d], 5\'d%02d, 32\'d%03d};\
+""
+\t\t ,$bits.(""?""x(24-$len)), 31-$len, $len, $pat);
+\t$pat++;
+ }
+}
+*/
+
+ always @* begin
+ next = 1\'b0;
+ code = 32\'d0;
+ len = 5\'b11111;
+ casez (in[31:8])
+\t24\'b1010????????????????????: {next, len, code} = {in[27], 5\'d04, 32\'d000};
+\t24\'b1100????????????????????: {next, len, code} = {in[27], 5\'d04, 32\'d001};
+\t24\'b0110????????????????????: {next, len, code} = {in[27], 5\'d04, 32\'d002};
+\t24\'b1001????????????????????: {next, len, code} = {in[27], 5\'d04, 32\'d003};
+\t24\'b1101????????????????????: {next, len, code} = {in[27], 5\'d04, 32\'d004};
+\t24\'b0011????????????????????: {next, len, code} = {in[27], 5\'d04, 32\'d005};
+\t24\'b0001????????????????????: {next, len, code} = {in[27], 5\'d04, 32\'d006};
+\t24\'b10001???????????????????: {next, len, code} = {in[26], 5\'d05, 32\'d007};
+\t24\'b01110???????????????????: {next, len, code} = {in[26], 5\'d05, 32\'d008};
+\t24\'b01000???????????????????: {next, len, code} = {in[26], 5\'d05, 32\'d009};
+\t24\'b00001???????????????????: {next, len, code} = {in[26], 5\'d05, 32\'d010};
+\t24\'b11100???????????????????: {next, len, code} = {in[26], 5\'d05, 32\'d011};
+\t24\'b01011???????????????????: {next, len, code} = {in[26], 5\'d05, 32\'d012};
+\t24\'b100001??????????????????: {next, len, code} = {in[25], 5\'d06, 32\'d013};
+\t24\'b111110??????????????????: {next, len, code} = {in[25], 5\'d06, 32\'d014};
+\t24\'b010010??????????????????: {next, len, code} = {in[25], 5\'d06, 32\'d015};
+\t24\'b001011??????????????????: {next, len, code} = {in[25], 5\'d06, 32\'d016};
+\t24\'b101110??????????????????: {next, len, code} = {in[25], 5\'d06, 32\'d017};
+\t24\'b111011??????????????????: {next, len, code} = {in[25], 5\'d06, 32\'d018};
+\t24\'b0111101?????????????????: {next, len, code} = {in[24], 5\'d07, 32\'d020};
+\t24\'b0010100?????????????????: {next, len, code} = {in[24], 5\'d07, 32\'d021};
+\t24\'b0111111?????????????????: {next, len, code} = {in[24], 5\'d07, 32\'d022};
+\t24\'b1011010?????????????????: {next, len, code} = {in[24], 5\'d07, 32\'d023};
+\t24\'b1000000?????????????????: {next, len, code} = {in[24], 5\'d07, 32\'d024};
+\t24\'b1011111?????????????????: {next, len, code} = {in[24], 5\'d07, 32\'d025};
+\t24\'b1110100?????????????????: {next, len, code} = {in[24], 5\'d07, 32\'d026};
+\t24\'b01111100????????????????: {next, len, code} = {in[23], 5\'d08, 32\'d027};
+\t24\'b00000110????????????????: {next, len, code} = {in[23], 5\'d08, 32\'d028};
+\t24\'b00000101????????????????: {next, len, code} = {in[23], 5\'d08, 32\'d029};
+\t24\'b01001100????????????????: {next, len, code} = {in[23], 5\'d08, 32\'d030};
+\t24\'b10110110????????????????: {next, len, code} = {in[23], 5\'d08, 32\'d031};
+\t24\'b00100110????????????????: {next, len, code} = {in[23], 5\'d08, 32\'d032};
+\t24\'b11110010????????????????: {next, len, code} = {in[23], 5\'d08, 32\'d033};
+\t24\'b010011101???????????????: {next, len, code} = {in[22], 5\'d09, 32\'d034};
+\t24\'b001000000???????????????: {next, len, code} = {in[22], 5\'d09, 32\'d035};
+\t24\'b010101111???????????????: {next, len, code} = {in[22], 5\'d09, 32\'d036};
+\t24\'b010101010???????????????: {next, len, code} = {in[22], 5\'d09, 32\'d037};
+\t24\'b010011011???????????????: {next, len, code} = {in[22], 5\'d09, 32\'d038};
+\t24\'b010100011???????????????: {next, len, code} = {in[22], 5\'d09, 32\'d039};
+\t24\'b010101000???????????????: {next, len, code} = {in[22], 5\'d09, 32\'d040};
+\t24\'b1111010101??????????????: {next, len, code} = {in[21], 5\'d10, 32\'d041};
+\t24\'b0010001000??????????????: {next, len, code} = {in[21], 5\'d10, 32\'d042};
+\t24\'b0101001101??????????????: {next, len, code} = {in[21], 5\'d10, 32\'d043};
+\t24\'b0010010100??????????????: {next, len, code} = {in[21], 5\'d10, 32\'d044};
+\t24\'b1011001110??????????????: {next, len, code} = {in[21], 5\'d10, 32\'d045};
+\t24\'b1111000011??????????????: {next, len, code} = {in[21], 5\'d10, 32\'d046};
+\t24\'b0101000000??????????????: {next, len, code} = {in[21], 5\'d10, 32\'d047};
+\t24\'b1111110000??????????????: {next, len, code} = {in[21], 5\'d10, 32\'d048};
+\t24\'b10110111010?????????????: {next, len, code} = {in[20], 5\'d11, 32\'d049};
+\t24\'b11110000011?????????????: {next, len, code} = {in[20], 5\'d11, 32\'d050};
+\t24\'b01001111011?????????????: {next, len, code} = {in[20], 5\'d11, 32\'d051};
+\t24\'b00101011011?????????????: {next, len, code} = {in[20], 5\'d11, 32\'d052};
+\t24\'b01010010100?????????????: {next, len, code} = {in[20], 5\'d11, 32\'d053};
+\t24\'b11110111100?????????????: {next, len, code} = {in[20], 5\'d11, 32\'d054};
+\t24\'b00100111001?????????????: {next, len, code} = {in[20], 5\'d11, 32\'d055};
+\t24\'b10110001010?????????????: {next, len, code} = {in[20], 5\'d11, 32\'d056};
+\t24\'b10000010000?????????????: {next, len, code} = {in[20], 5\'d11, 32\'d057};
+\t24\'b111111101100????????????: {next, len, code} = {in[19], 5\'d12, 32\'d058};
+\t24\'b100000111110????????????: {next, len, code} = {in[19], 5\'d12, 32\'d059};
+\t24\'b100000110010????????????: {next, len, code} = {in[19], 5\'d12, 32\'d060};
+\t24\'b100000111001????????????: {next, len, code} = {in[19], 5\'d12, 32\'d061};
+\t24\'b010100101111????????????: {next, len, code} = {in[19], 5\'d12, 32\'d062};
+\t24\'b001000001100????????????: {next, len, code} = {in[19], 5\'d12, 32\'d063};
+\t24\'b000001111111????????????: {next, len, code} = {in[19], 5\'d12, 32\'d064};
+\t24\'b011111010100????????????: {next, len, code} = {in[19], 5\'d12, 32\'d065};
+\t24\'b1110101111101???????????: {next, len, code} = {in[18], 5\'d13, 32\'d066};
+\t24\'b0100110101110???????????: {next, len, code} = {in[18], 5\'d13, 32\'d067};
+\t24\'b1111111011011???????????: {next, len, code} = {in[18], 5\'d13, 32\'d068};
+\t24\'b0101011011001???????????: {next, len, code} = {in[18], 5\'d13, 32\'d069};
+\t24\'b0010000101100???????????: {next, len, code} = {in[18], 5\'d13, 32\'d070};
+\t24\'b1111111101101???????????: {next, len, code} = {in[18], 5\'d13, 32\'d071};
+\t24\'b1011110010110???????????: {next, len, code} = {in[18], 5\'d13, 32\'d072};
+\t24\'b0101010111010???????????: {next, len, code} = {in[18], 5\'d13, 32\'d073};
+\t24\'b1111011010010???????????: {next, len, code} = {in[18], 5\'d13, 32\'d074};
+\t24\'b01010100100011??????????: {next, len, code} = {in[17], 5\'d14, 32\'d075};
+\t24\'b10110000110010??????????: {next, len, code} = {in[17], 5\'d14, 32\'d076};
+\t24\'b10111101001111??????????: {next, len, code} = {in[17], 5\'d14, 32\'d077};
+\t24\'b10110000010101??????????: {next, len, code} = {in[17], 5\'d14, 32\'d078};
+\t24\'b00101011001111??????????: {next, len, code} = {in[17], 5\'d14, 32\'d079};
+\t24\'b00100000101100??????????: {next, len, code} = {in[17], 5\'d14, 32\'d080};
+\t24\'b11111110010111??????????: {next, len, code} = {in[17], 5\'d14, 32\'d081};
+\t24\'b10110010100000??????????: {next, len, code} = {in[17], 5\'d14, 32\'d082};
+\t24\'b11101011101000??????????: {next, len, code} = {in[17], 5\'d14, 32\'d083};
+\t24\'b01010000011111??????????: {next, len, code} = {in[17], 5\'d14, 32\'d084};
+\t24\'b101111011001011?????????: {next, len, code} = {in[16], 5\'d15, 32\'d085};
+\t24\'b101111010001100?????????: {next, len, code} = {in[16], 5\'d15, 32\'d086};
+\t24\'b100000111100111?????????: {next, len, code} = {in[16], 5\'d15, 32\'d087};
+\t24\'b001010101011000?????????: {next, len, code} = {in[16], 5\'d15, 32\'d088};
+\t24\'b111111100100001?????????: {next, len, code} = {in[16], 5\'d15, 32\'d089};
+\t24\'b001001011000010?????????: {next, len, code} = {in[16], 5\'d15, 32\'d090};
+\t24\'b011110011001011?????????: {next, len, code} = {in[16], 5\'d15, 32\'d091};
+\t24\'b111111111111010?????????: {next, len, code} = {in[16], 5\'d15, 32\'d092};
+\t24\'b101111001010011?????????: {next, len, code} = {in[16], 5\'d15, 32\'d093};
+\t24\'b100000110000111?????????: {next, len, code} = {in[16], 5\'d15, 32\'d094};
+\t24\'b0010010000000101????????: {next, len, code} = {in[15], 5\'d16, 32\'d095};
+\t24\'b0010010010101001????????: {next, len, code} = {in[15], 5\'d16, 32\'d096};
+\t24\'b1111011010110010????????: {next, len, code} = {in[15], 5\'d16, 32\'d097};
+\t24\'b0010010001100100????????: {next, len, code} = {in[15], 5\'d16, 32\'d098};
+\t24\'b0101011101110100????????: {next, len, code} = {in[15], 5\'d16, 32\'d099};
+\t24\'b0101011010001111????????: {next, len, code} = {in[15], 5\'d16, 32\'d100};
+\t24\'b0010000110011111????????: {next, len, code} = {in[15], 5\'d16, 32\'d101};
+\t24\'b0101010010000101????????: {next, len, code} = {in[15], 5\'d16, 32\'d102};
+\t24\'b1110101011000000????????: {next, len, code} = {in[15], 5\'d16, 32\'d103};
+\t24\'b1111000000110010????????: {next, len, code} = {in[15], 5\'d16, 32\'d104};
+\t24\'b0111100010001101????????: {next, len, code} = {in[15], 5\'d16, 32\'d105};
+\t24\'b00100010110001100???????: {next, len, code} = {in[14], 5\'d17, 32\'d106};
+\t24\'b00100010101101010???????: {next, len, code} = {in[14], 5\'d17, 32\'d107};
+\t24\'b11111110111100000???????: {next, len, code} = {in[14], 5\'d17, 32\'d108};
+\t24\'b00100000111010000???????: {next, len, code} = {in[14], 5\'d17, 32\'d109};
+\t24\'b00100111011101001???????: {next, len, code} = {in[14], 5\'d17, 32\'d110};
+\t24\'b11111110111000011???????: {next, len, code} = {in[14], 5\'d17, 32\'d111};
+\t24\'b11110001101000100???????: {next, len, code} = {in[14], 5\'d17, 32\'d112};
+\t24\'b11101011101011101???????: {next, len, code} = {in[14], 5\'d17, 32\'d113};
+\t24\'b01010000100101011???????: {next, len, code} = {in[14], 5\'d17, 32\'d114};
+\t24\'b00100100110011001???????: {next, len, code} = {in[14], 5\'d17, 32\'d115};
+\t24\'b01001110010101000???????: {next, len, code} = {in[14], 5\'d17, 32\'d116};
+\t24\'b010011110101001000??????: {next, len, code} = {in[13], 5\'d18, 32\'d117};
+\t24\'b111010101110010010??????: {next, len, code} = {in[13], 5\'d18, 32\'d118};
+\t24\'b001001001001111000??????: {next, len, code} = {in[13], 5\'d18, 32\'d119};
+\t24\'b101111000110111101??????: {next, len, code} = {in[13], 5\'d18, 32\'d120};
+\t24\'b101101111010101001??????: {next, len, code} = {in[13], 5\'d18, 32\'d121};
+\t24\'b111101110010111110??????: {next, len, code} = {in[13], 5\'d18, 32\'d122};
+\t24\'b010100100011010000??????: {next, len, code} = {in[13], 5\'d18, 32\'d123};
+\t24\'b001001001111011001??????: {next, len, code} = {in[13], 5\'d18, 32\'d124};
+\t24\'b010100110010001001??????: {next, len, code} = {in[13], 5\'d18, 32\'d125};
+\t24\'b111010110000111000??????: {next, len, code} = {in[13], 5\'d18, 32\'d126};
+\t24\'b111010110011000101??????: {next, len, code} = {in[13], 5\'d18, 32\'d127};
+\t24\'b010100001000111001??????: {next, len, code} = {in[13], 5\'d18, 32\'d128};
+\t24\'b1000001011000110100?????: {next, len, code} = {in[12], 5\'d19, 32\'d129};
+\t24\'b0010010111001110110?????: {next, len, code} = {in[12], 5\'d19, 32\'d130};
+\t24\'b0101011001000001101?????: {next, len, code} = {in[12], 5\'d19, 32\'d131};
+\t24\'b0101000010010101011?????: {next, len, code} = {in[12], 5\'d19, 32\'d132};
+\t24\'b1111011111101001101?????: {next, len, code} = {in[12], 5\'d19, 32\'d133};
+\t24\'b1011001000101010110?????: {next, len, code} = {in[12], 5\'d19, 32\'d134};
+\t24\'b1011000001000100001?????: {next, len, code} = {in[12], 5\'d19, 32\'d135};
+\t24\'b1110101100010011001?????: {next, len, code} = {in[12], 5\'d19, 32\'d136};
+\t24\'b0010010111010111110?????: {next, len, code} = {in[12], 5\'d19, 32\'d137};
+\t24\'b0010010001100111100?????: {next, len, code} = {in[12], 5\'d19, 32\'d138};
+\t24\'b1011001011100000101?????: {next, len, code} = {in[12], 5\'d19, 32\'d139};
+\t24\'b1011000100010100101?????: {next, len, code} = {in[12], 5\'d19, 32\'d140};
+\t24\'b1111111001000111011?????: {next, len, code} = {in[12], 5\'d19, 32\'d141};
+\t24\'b00100010111101101101????: {next, len, code} = {in[11], 5\'d20, 32\'d142};
+\t24\'b10000010101010101101????: {next, len, code} = {in[11], 5\'d20, 32\'d143};
+\t24\'b10110010100101001101????: {next, len, code} = {in[11], 5\'d20, 32\'d144};
+\t24\'b01010110111100010000????: {next, len, code} = {in[11], 5\'d20, 32\'d145};
+\t24\'b10110111110011001001????: {next, len, code} = {in[11], 5\'d20, 32\'d146};
+\t24\'b11111101101100100101????: {next, len, code} = {in[11], 5\'d20, 32\'d147};
+\t24\'b10110000010100100001????: {next, len, code} = {in[11], 5\'d20, 32\'d148};
+\t24\'b10110010011010110110????: {next, len, code} = {in[11], 5\'d20, 32\'d149};
+\t24\'b01111001010000011000????: {next, len, code} = {in[11], 5\'d20, 32\'d150};
+\t24\'b11110110001011011011????: {next, len, code} = {in[11], 5\'d20, 32\'d151};
+\t24\'b01010000100100001011????: {next, len, code} = {in[11], 5\'d20, 32\'d152};
+\t24\'b10110001100101110111????: {next, len, code} = {in[11], 5\'d20, 32\'d153};
+\t24\'b10111100110111101000????: {next, len, code} = {in[11], 5\'d20, 32\'d154};
+\t24\'b01010001010111010000????: {next, len, code} = {in[11], 5\'d20, 32\'d155};
+\t24\'b01010100111110001110????: {next, len, code} = {in[11], 5\'d20, 32\'d156};
+\t24\'b11111110011001100111????: {next, len, code} = {in[11], 5\'d20, 32\'d157};
+\t24\'b11110111111101010001????: {next, len, code} = {in[11], 5\'d20, 32\'d158};
+\t24\'b10110000010111100000????: {next, len, code} = {in[11], 5\'d20, 32\'d159};
+\t24\'b01001111100001000101????: {next, len, code} = {in[11], 5\'d20, 32\'d160};
+\t24\'b01010010000111010110????: {next, len, code} = {in[11], 5\'d20, 32\'d161};
+\t24\'b11101010101011101111????: {next, len, code} = {in[11], 5\'d20, 32\'d162};
+\t24\'b11111110010011100011????: {next, len, code} = {in[11], 5\'d20, 32\'d163};
+\t24\'b01010111001111101111????: {next, len, code} = {in[11], 5\'d20, 32\'d164};
+\t24\'b10110001111111111101????: {next, len, code} = {in[11], 5\'d20, 32\'d165};
+\t24\'b10110001001100110000????: {next, len, code} = {in[11], 5\'d20, 32\'d166};
+\t24\'b11110100011000111101????: {next, len, code} = {in[11], 5\'d20, 32\'d167};
+\t24\'b00101011101110100011????: {next, len, code} = {in[11], 5\'d20, 32\'d168};
+\t24\'b01010000011011111110????: {next, len, code} = {in[11], 5\'d20, 32\'d169};
+\t24\'b00000111000010000010????: {next, len, code} = {in[11], 5\'d20, 32\'d170};
+\t24\'b00101010000011001000????: {next, len, code} = {in[11], 5\'d20, 32\'d171};
+\t24\'b01001110010100101110????: {next, len, code} = {in[11], 5\'d20, 32\'d172};
+\t24\'b11110000000010000000????: {next, len, code} = {in[11], 5\'d20, 32\'d173};
+\t24\'b01001101011001111001????: {next, len, code} = {in[11], 5\'d20, 32\'d174};
+\t24\'b11110111000111010101????: {next, len, code} = {in[11], 5\'d20, 32\'d175};
+\t24\'b01111001101001110110????: {next, len, code} = {in[11], 5\'d20, 32\'d176};
+\t24\'b11110000101011101111????: {next, len, code} = {in[11], 5\'d20, 32\'d177};
+\t24\'b00100100100110101010????: {next, len, code} = {in[11], 5\'d20, 32\'d178};
+\t24\'b11110001011011000011????: {next, len, code} = {in[11], 5\'d20, 32\'d179};
+\t24\'b01010111001000110011????: {next, len, code} = {in[11], 5\'d20, 32\'d180};
+\t24\'b01111000000100010101????: {next, len, code} = {in[11], 5\'d20, 32\'d181};
+\t24\'b00100101101011001101????: {next, len, code} = {in[11], 5\'d20, 32\'d182};
+\t24\'b10110010110000111001????: {next, len, code} = {in[11], 5\'d20, 32\'d183};
+\t24\'b10110000101010000011????: {next, len, code} = {in[11], 5\'d20, 32\'d184};
+\t24\'b00100100111110001101????: {next, len, code} = {in[11], 5\'d20, 32\'d185};
+\t24\'b01111001101001101011????: {next, len, code} = {in[11], 5\'d20, 32\'d186};
+\t24\'b01010001000000010001????: {next, len, code} = {in[11], 5\'d20, 32\'d187};
+\t24\'b11110101111111101110????: {next, len, code} = {in[11], 5\'d20, 32\'d188};
+\t24\'b10000010111110110011????: {next, len, code} = {in[11], 5\'d20, 32\'d189};
+\t24\'b00000100011110100111????: {next, len, code} = {in[11], 5\'d20, 32\'d190};
+\t24\'b11111101001111101100????: {next, len, code} = {in[11], 5\'d20, 32\'d191};
+\t24\'b00101011100011110000????: {next, len, code} = {in[11], 5\'d20, 32\'d192};
+\t24\'b00100100111001011001????: {next, len, code} = {in[11], 5\'d20, 32\'d193};
+\t24\'b10000010101000000100????: {next, len, code} = {in[11], 5\'d20, 32\'d194};
+\t24\'b11110001001000111100????: {next, len, code} = {in[11], 5\'d20, 32\'d195};
+\t24\'b10111100011010011001????: {next, len, code} = {in[11], 5\'d20, 32\'d196};
+\t24\'b000000??????????????????: begin
+\t casez (in[33:32])
+\t 2\'b1?: {next, len, code} = {1\'b0, 5\'d18, 32\'d197};
+\t 2\'b01: {next, len, code} = {1\'b0, 5\'d19, 32\'d198};
+\t 2\'b00: {next, len, code} = {1\'b0, 5\'d19, 32\'d199};
+\t default: ;
+\t endcase
+\tend
+\tdefault: ;
+ endcase
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+ parameter ONE = 1;
+
+ wire [17:10] bitout;
+ reg [7:0] allbits;
+ reg [15:0] onebit;
+
+ sub sub [7:0] (allbits, onebit, bitout);
+
+ integer x;
+
+ always @ (posedge clk) begin
+ //$write(""%x\
+"", bitout);
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t allbits <= 8\'hac;
+\t onebit <= 16\'hc01a;
+\t end
+\t if (cyc==2) begin
+\t if (bitout !== 8\'h07) $stop;
+\t allbits <= 8\'hca;
+\t onebit <= 16\'h1f01;
+\t end
+\t if (cyc==3) begin
+\t if (bitout !== 8\'h41) $stop;
+\t if (sub[0].bitout !== 1\'b1) $stop;
+\t if (sub[1].bitout !== 1\'b0) $stop;
+`ifndef verilator // Hacky array subscripting
+\t if (sub[ONE].bitout !== 1\'b0) $stop;
+`endif
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+
+`ifdef USE_INLINE
+ `define INLINE_MODULE /*verilator inline_module*/
+`else
+ `define INLINE_MODULE /*verilator public_module*/
+`endif
+
+module sub (input [7:0] allbits, input [1:0] onebit, output bitout);
+ `INLINE_MODULE
+ wire bitout = (^ onebit) ^ (^ allbits);
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [7:0] \tsel = crc[7:0];
+ wire [255+3:0] in = {crc[2:0],crc,crc,crc,crc};
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [3:0]\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ /* Test AUTO_TEMPLATE (
+ .i\\([0-9]+\\)\t(in[\\1 +:4]),
+ ); */
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[3:0]),
+\t // Inputs
+\t .sel\t\t\t(sel[7:0]),
+\t .i0\t\t\t(in[0 +:4]),\t\t // Templated
+\t .i1\t\t\t(in[1 +:4]),\t\t // Templated
+\t .i2\t\t\t(in[2 +:4]),\t\t // Templated
+\t .i3\t\t\t(in[3 +:4]),\t\t // Templated
+\t .i4\t\t\t(in[4 +:4]),\t\t // Templated
+\t .i5\t\t\t(in[5 +:4]),\t\t // Templated
+\t .i6\t\t\t(in[6 +:4]),\t\t // Templated
+\t .i7\t\t\t(in[7 +:4]),\t\t // Templated
+\t .i8\t\t\t(in[8 +:4]),\t\t // Templated
+\t .i9\t\t\t(in[9 +:4]),\t\t // Templated
+\t .i10\t\t\t(in[10 +:4]),\t\t // Templated
+\t .i11\t\t\t(in[11 +:4]),\t\t // Templated
+\t .i12\t\t\t(in[12 +:4]),\t\t // Templated
+\t .i13\t\t\t(in[13 +:4]),\t\t // Templated
+\t .i14\t\t\t(in[14 +:4]),\t\t // Templated
+\t .i15\t\t\t(in[15 +:4]),\t\t // Templated
+\t .i16\t\t\t(in[16 +:4]),\t\t // Templated
+\t .i17\t\t\t(in[17 +:4]),\t\t // Templated
+\t .i18\t\t\t(in[18 +:4]),\t\t // Templated
+\t .i19\t\t\t(in[19 +:4]),\t\t // Templated
+\t .i20\t\t\t(in[20 +:4]),\t\t // Templated
+\t .i21\t\t\t(in[21 +:4]),\t\t // Templated
+\t .i22\t\t\t(in[22 +:4]),\t\t // Templated
+\t .i23\t\t\t(in[23 +:4]),\t\t // Templated
+\t .i24\t\t\t(in[24 +:4]),\t\t // Templated
+\t .i25\t\t\t(in[25 +:4]),\t\t // Templated
+\t .i26\t\t\t(in[26 +:4]),\t\t // Templated
+\t .i27\t\t\t(in[27 +:4]),\t\t // Templated
+\t .i28\t\t\t(in[28 +:4]),\t\t // Templated
+\t .i29\t\t\t(in[29 +:4]),\t\t // Templated
+\t .i30\t\t\t(in[30 +:4]),\t\t // Templated
+\t .i31\t\t\t(in[31 +:4]),\t\t // Templated
+\t .i32\t\t\t(in[32 +:4]),\t\t // Templated
+\t .i33\t\t\t(in[33 +:4]),\t\t // Templated
+\t .i34\t\t\t(in[34 +:4]),\t\t // Templated
+\t .i35\t\t\t(in[35 +:4]),\t\t // Templated
+\t .i36\t\t\t(in[36 +:4]),\t\t // Templated
+\t .i37\t\t\t(in[37 +:4]),\t\t // Templated
+\t .i38\t\t\t(in[38 +:4]),\t\t // Templated
+\t .i39\t\t\t(in[39 +:4]),\t\t // Templated
+\t .i40\t\t\t(in[40 +:4]),\t\t // Templated
+\t .i41\t\t\t(in[41 +:4]),\t\t // Templated
+\t .i42\t\t\t(in[42 +:4]),\t\t // Templated
+\t .i43\t\t\t(in[43 +:4]),\t\t // Templated
+\t .i44\t\t\t(in[44 +:4]),\t\t // Templated
+\t .i45\t\t\t(in[45 +:4]),\t\t // Templated
+\t .i46\t\t\t(in[46 +:4]),\t\t // Templated
+\t .i47\t\t\t(in[47 +:4]),\t\t // Templated
+\t .i48\t\t\t(in[48 +:4]),\t\t // Templated
+\t .i49\t\t\t(in[49 +:4]),\t\t // Templated
+\t .i50\t\t\t(in[50 +:4]),\t\t // Templated
+\t .i51\t\t\t(in[51 +:4]),\t\t // Templated
+\t .i52\t\t\t(in[52 +:4]),\t\t // Templated
+\t .i53\t\t\t(in[53 +:4]),\t\t // Templated
+\t .i54\t\t\t(in[54 +:4]),\t\t // Templated
+\t .i55\t\t\t(in[55 +:4]),\t\t // Templated
+\t .i56\t\t\t(in[56 +:4]),\t\t // Templated
+\t .i57\t\t\t(in[57 +:4]),\t\t // Templated
+\t .i58\t\t\t(in[58 +:4]),\t\t // Templated
+\t .i59\t\t\t(in[59 +:4]),\t\t // Templated
+\t .i60\t\t\t(in[60 +:4]),\t\t // Templated
+\t .i61\t\t\t(in[61 +:4]),\t\t // Templated
+\t .i62\t\t\t(in[62 +:4]),\t\t // Templated
+\t .i63\t\t\t(in[63 +:4]),\t\t // Templated
+\t .i64\t\t\t(in[64 +:4]),\t\t // Templated
+\t .i65\t\t\t(in[65 +:4]),\t\t // Templated
+\t .i66\t\t\t(in[66 +:4]),\t\t // Templated
+\t .i67\t\t\t(in[67 +:4]),\t\t // Templated
+\t .i68\t\t\t(in[68 +:4]),\t\t // Templated
+\t .i69\t\t\t(in[69 +:4]),\t\t // Templated
+\t .i70\t\t\t(in[70 +:4]),\t\t // Templated
+\t .i71\t\t\t(in[71 +:4]),\t\t // Templated
+\t .i72\t\t\t(in[72 +:4]),\t\t // Templated
+\t .i73\t\t\t(in[73 +:4]),\t\t // Templated
+\t .i74\t\t\t(in[74 +:4]),\t\t // Templated
+\t .i75\t\t\t(in[75 +:4]),\t\t // Templated
+\t .i76\t\t\t(in[76 +:4]),\t\t // Templated
+\t .i77\t\t\t(in[77 +:4]),\t\t // Templated
+\t .i78\t\t\t(in[78 +:4]),\t\t // Templated
+\t .i79\t\t\t(in[79 +:4]),\t\t // Templated
+\t .i80\t\t\t(in[80 +:4]),\t\t // Templated
+\t .i81\t\t\t(in[81 +:4]),\t\t // Templated
+\t .i82\t\t\t(in[82 +:4]),\t\t // Templated
+\t .i83\t\t\t(in[83 +:4]),\t\t // Templated
+\t .i84\t\t\t(in[84 +:4]),\t\t // Templated
+\t .i85\t\t\t(in[85 +:4]),\t\t // Templated
+\t .i86\t\t\t(in[86 +:4]),\t\t // Templated
+\t .i87\t\t\t(in[87 +:4]),\t\t // Templated
+\t .i88\t\t\t(in[88 +:4]),\t\t // Templated
+\t .i89\t\t\t(in[89 +:4]),\t\t // Templated
+\t .i90\t\t\t(in[90 +:4]),\t\t // Templated
+\t .i91\t\t\t(in[91 +:4]),\t\t // Templated
+\t .i92\t\t\t(in[92 +:4]),\t\t // Templated
+\t .i93\t\t\t(in[93 +:4]),\t\t // Templated
+\t .i94\t\t\t(in[94 +:4]),\t\t // Templated
+\t .i95\t\t\t(in[95 +:4]),\t\t // Templated
+\t .i96\t\t\t(in[96 +:4]),\t\t // Templated
+\t .i97\t\t\t(in[97 +:4]),\t\t // Templated
+\t .i98\t\t\t(in[98 +:4]),\t\t // Templated
+\t .i99\t\t\t(in[99 +:4]),\t\t // Templated
+\t .i100\t\t\t(in[100 +:4]),\t\t // Templated
+\t .i101\t\t\t(in[101 +:4]),\t\t // Templated
+\t .i102\t\t\t(in[102 +:4]),\t\t // Templated
+\t .i103\t\t\t(in[103 +:4]),\t\t // Templated
+\t .i104\t\t\t(in[104 +:4]),\t\t // Templated
+\t .i105\t\t\t(in[105 +:4]),\t\t // Templated
+\t .i106\t\t\t(in[106 +:4]),\t\t // Templated
+\t .i107\t\t\t(in[107 +:4]),\t\t // Templated
+\t .i108\t\t\t(in[108 +:4]),\t\t // Templated
+\t .i109\t\t\t(in[109 +:4]),\t\t // Templated
+\t .i110\t\t\t(in[110 +:4]),\t\t // Templated
+\t .i111\t\t\t(in[111 +:4]),\t\t // Templated
+\t .i112\t\t\t(in[112 +:4]),\t\t // Templated
+\t .i113\t\t\t(in[113 +:4]),\t\t // Templated
+\t .i114\t\t\t(in[114 +:4]),\t\t // Templated
+\t .i115\t\t\t(in[115 +:4]),\t\t // Templated
+\t .i116\t\t\t(in[116 +:4]),\t\t // Templated
+\t .i117\t\t\t(in[117 +:4]),\t\t // Templated
+\t .i118\t\t\t(in[118 +:4]),\t\t // Templated
+\t .i119\t\t\t(in[119 +:4]),\t\t // Templated
+\t .i120\t\t\t(in[120 +:4]),\t\t // Templated
+\t .i121\t\t\t(in[121 +:4]),\t\t // Templated
+\t .i122\t\t\t(in[122 +:4]),\t\t // Templated
+\t .i123\t\t\t(in[123 +:4]),\t\t // Templated
+\t .i124\t\t\t(in[124 +:4]),\t\t // Templated
+\t .i125\t\t\t(in[125 +:4]),\t\t // Templated
+\t .i126\t\t\t(in[126 +:4]),\t\t // Templated
+\t .i127\t\t\t(in[127 +:4]),\t\t // Templated
+\t .i128\t\t\t(in[128 +:4]),\t\t // Templated
+\t .i129\t\t\t(in[129 +:4]),\t\t // Templated
+\t .i130\t\t\t(in[130 +:4]),\t\t // Templated
+\t .i131\t\t\t(in[131 +:4]),\t\t // Templated
+\t .i132\t\t\t(in[132 +:4]),\t\t // Templated
+\t .i133\t\t\t(in[133 +:4]),\t\t // Templated
+\t .i134\t\t\t(in[134 +:4]),\t\t // Templated
+\t .i135\t\t\t(in[135 +:4]),\t\t // Templated
+\t .i136\t\t\t(in[136 +:4]),\t\t // Templated
+\t .i137\t\t\t(in[137 +:4]),\t\t // Templated
+\t .i138\t\t\t(in[138 +:4]),\t\t // Templated
+\t .i139\t\t\t(in[139 +:4]),\t\t // Templated
+\t .i140\t\t\t(in[140 +:4]),\t\t // Templated
+\t .i141\t\t\t(in[141 +:4]),\t\t // Templated
+\t .i142\t\t\t(in[142 +:4]),\t\t // Templated
+\t .i143\t\t\t(in[143 +:4]),\t\t // Templated
+\t .i144\t\t\t(in[144 +:4]),\t\t // Templated
+\t .i145\t\t\t(in[145 +:4]),\t\t // Templated
+\t .i146\t\t\t(in[146 +:4]),\t\t // Templated
+\t .i147\t\t\t(in[147 +:4]),\t\t // Templated
+\t .i148\t\t\t(in[148 +:4]),\t\t // Templated
+\t .i149\t\t\t(in[149 +:4]),\t\t // Templated
+\t .i150\t\t\t(in[150 +:4]),\t\t // Templated
+\t .i151\t\t\t(in[151 +:4]),\t\t // Templated
+\t .i152\t\t\t(in[152 +:4]),\t\t // Templated
+\t .i153\t\t\t(in[153 +:4]),\t\t // Templated
+\t .i154\t\t\t(in[154 +:4]),\t\t // Templated
+\t .i155\t\t\t(in[155 +:4]),\t\t // Templated
+\t .i156\t\t\t(in[156 +:4]),\t\t // Templated
+\t .i157\t\t\t(in[157 +:4]),\t\t // Templated
+\t .i158\t\t\t(in[158 +:4]),\t\t // Templated
+\t .i159\t\t\t(in[159 +:4]),\t\t // Templated
+\t .i160\t\t\t(in[160 +:4]),\t\t // Templated
+\t .i161\t\t\t(in[161 +:4]),\t\t // Templated
+\t .i162\t\t\t(in[162 +:4]),\t\t // Templated
+\t .i163\t\t\t(in[163 +:4]),\t\t // Templated
+\t .i164\t\t\t(in[164 +:4]),\t\t // Templated
+\t .i165\t\t\t(in[165 +:4]),\t\t // Templated
+\t .i166\t\t\t(in[166 +:4]),\t\t // Templated
+\t .i167\t\t\t(in[167 +:4]),\t\t // Templated
+\t .i168\t\t\t(in[168 +:4]),\t\t // Templated
+\t .i169\t\t\t(in[169 +:4]),\t\t // Templated
+\t .i170\t\t\t(in[170 +:4]),\t\t // Templated
+\t .i171\t\t\t(in[171 +:4]),\t\t // Templated
+\t .i172\t\t\t(in[172 +:4]),\t\t // Templated
+\t .i173\t\t\t(in[173 +:4]),\t\t // Templated
+\t .i174\t\t\t(in[174 +:4]),\t\t // Templated
+\t .i175\t\t\t(in[175 +:4]),\t\t // Templated
+\t .i176\t\t\t(in[176 +:4]),\t\t // Templated
+\t .i177\t\t\t(in[177 +:4]),\t\t // Templated
+\t .i178\t\t\t(in[178 +:4]),\t\t // Templated
+\t .i179\t\t\t(in[179 +:4]),\t\t // Templated
+\t .i180\t\t\t(in[180 +:4]),\t\t // Templated
+\t .i181\t\t\t(in[181 +:4]),\t\t // Templated
+\t .i182\t\t\t(in[182 +:4]),\t\t // Templated
+\t .i183\t\t\t(in[183 +:4]),\t\t // Templated
+\t .i184\t\t\t(in[184 +:4]),\t\t // Templated
+\t .i185\t\t\t(in[185 +:4]),\t\t // Templated
+\t .i186\t\t\t(in[186 +:4]),\t\t // Templated
+\t .i187\t\t\t(in[187 +:4]),\t\t // Templated
+\t .i188\t\t\t(in[188 +:4]),\t\t // Templated
+\t .i189\t\t\t(in[189 +:4]),\t\t // Templated
+\t .i190\t\t\t(in[190 +:4]),\t\t // Templated
+\t .i191\t\t\t(in[191 +:4]),\t\t // Templated
+\t .i192\t\t\t(in[192 +:4]),\t\t // Templated
+\t .i193\t\t\t(in[193 +:4]),\t\t // Templated
+\t .i194\t\t\t(in[194 +:4]),\t\t // Templated
+\t .i195\t\t\t(in[195 +:4]),\t\t // Templated
+\t .i196\t\t\t(in[196 +:4]),\t\t // Templated
+\t .i197\t\t\t(in[197 +:4]),\t\t // Templated
+\t .i198\t\t\t(in[198 +:4]),\t\t // Templated
+\t .i199\t\t\t(in[199 +:4]),\t\t // Templated
+\t .i200\t\t\t(in[200 +:4]),\t\t // Templated
+\t .i201\t\t\t(in[201 +:4]),\t\t // Templated
+\t .i202\t\t\t(in[202 +:4]),\t\t // Templated
+\t .i203\t\t\t(in[203 +:4]),\t\t // Templated
+\t .i204\t\t\t(in[204 +:4]),\t\t // Templated
+\t .i205\t\t\t(in[205 +:4]),\t\t // Templated
+\t .i206\t\t\t(in[206 +:4]),\t\t // Templated
+\t .i207\t\t\t(in[207 +:4]),\t\t // Templated
+\t .i208\t\t\t(in[208 +:4]),\t\t // Templated
+\t .i209\t\t\t(in[209 +:4]),\t\t // Templated
+\t .i210\t\t\t(in[210 +:4]),\t\t // Templated
+\t .i211\t\t\t(in[211 +:4]),\t\t // Templated
+\t .i212\t\t\t(in[212 +:4]),\t\t // Templated
+\t .i213\t\t\t(in[213 +:4]),\t\t // Templated
+\t .i214\t\t\t(in[214 +:4]),\t\t // Templated
+\t .i215\t\t\t(in[215 +:4]),\t\t // Templated
+\t .i216\t\t\t(in[216 +:4]),\t\t // Templated
+\t .i217\t\t\t(in[217 +:4]),\t\t // Templated
+\t .i218\t\t\t(in[218 +:4]),\t\t // Templated
+\t .i219\t\t\t(in[219 +:4]),\t\t // Templated
+\t .i220\t\t\t(in[220 +:4]),\t\t // Templated
+\t .i221\t\t\t(in[221 +:4]),\t\t // Templated
+\t .i222\t\t\t(in[222 +:4]),\t\t // Templated
+\t .i223\t\t\t(in[223 +:4]),\t\t // Templated
+\t .i224\t\t\t(in[224 +:4]),\t\t // Templated
+\t .i225\t\t\t(in[225 +:4]),\t\t // Templated
+\t .i226\t\t\t(in[226 +:4]),\t\t // Templated
+\t .i227\t\t\t(in[227 +:4]),\t\t // Templated
+\t .i228\t\t\t(in[228 +:4]),\t\t // Templated
+\t .i229\t\t\t(in[229 +:4]),\t\t // Templated
+\t .i230\t\t\t(in[230 +:4]),\t\t // Templated
+\t .i231\t\t\t(in[231 +:4]),\t\t // Templated
+\t .i232\t\t\t(in[232 +:4]),\t\t // Templated
+\t .i233\t\t\t(in[233 +:4]),\t\t // Templated
+\t .i234\t\t\t(in[234 +:4]),\t\t // Templated
+\t .i235\t\t\t(in[235 +:4]),\t\t // Templated
+\t .i236\t\t\t(in[236 +:4]),\t\t // Templated
+\t .i237\t\t\t(in[237 +:4]),\t\t // Templated
+\t .i238\t\t\t(in[238 +:4]),\t\t // Templated
+\t .i239\t\t\t(in[239 +:4]),\t\t // Templated
+\t .i240\t\t\t(in[240 +:4]),\t\t // Templated
+\t .i241\t\t\t(in[241 +:4]),\t\t // Templated
+\t .i242\t\t\t(in[242 +:4]),\t\t // Templated
+\t .i243\t\t\t(in[243 +:4]),\t\t // Templated
+\t .i244\t\t\t(in[244 +:4]),\t\t // Templated
+\t .i245\t\t\t(in[245 +:4]),\t\t // Templated
+\t .i246\t\t\t(in[246 +:4]),\t\t // Templated
+\t .i247\t\t\t(in[247 +:4]),\t\t // Templated
+\t .i248\t\t\t(in[248 +:4]),\t\t // Templated
+\t .i249\t\t\t(in[249 +:4]),\t\t // Templated
+\t .i250\t\t\t(in[250 +:4]),\t\t // Templated
+\t .i251\t\t\t(in[251 +:4]),\t\t // Templated
+\t .i252\t\t\t(in[252 +:4]),\t\t // Templated
+\t .i253\t\t\t(in[253 +:4]),\t\t // Templated
+\t .i254\t\t\t(in[254 +:4]),\t\t // Templated
+\t .i255\t\t\t(in[255 +:4]));\t\t // Templated
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {60\'h0, out};
+
+ // What checksum will we end up with
+`define EXPECTED_SUM 64\'h36f3051d15caf07a
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test
+ ( output wire [3:0] out,
+
+ input [7:0] sel,
+
+ input [3:0] i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16,
+ i17, i18, i19, i20, i21, i22, i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33,
+ i34, i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, i45, i46, i47, i48, i49, i50,
+ i51, i52, i53, i54, i55, i56, i57, i58, i59, i60, i61, i62, i63, i64, i65, i66, i67,
+ i68, i69, i70, i71, i72, i73, i74, i75, i76, i77, i78, i79, i80, i81, i82, i83, i84,
+ i85, i86, i87, i88, i89, i90, i91, i92, i93, i94, i95, i96, i97, i98, i99, i100, i101,
+ i102, i103, i104, i105, i106, i107, i108, i109, i110, i111, i112, i113, i114, i115,
+ i116, i117, i118, i119, i120, i121, i122, i123, i124, i125, i126, i127, i128, i129,
+ i130, i131, i132, i133, i134, i135, i136, i137, i138, i139, i140, i141, i142, i143,
+ i144, i145, i146, i147, i148, i149, i150, i151, i152, i153, i154, i155, i156, i157,
+ i158, i159, i160, i161, i162, i163, i164, i165, i166, i167, i168, i169, i170, i171,
+ i172, i173, i174, i175, i176, i177, i178, i179, i180, i181, i182, i183, i184, i185,
+ i186, i187, i188, i189, i190, i191, i192, i193, i194, i195, i196, i197, i198, i199,
+ i200, i201, i202, i203, i204, i205, i206, i207, i208, i209, i210, i211, i212, i213,
+ i214, i215, i216, i217, i218, i219, i220, i221, i222, i223, i224, i225, i226, i227,
+ i228, i229, i230, i231, i232, i233, i234, i235, i236, i237, i238, i239, i240, i241,
+ i242, i243, i244, i245, i246, i247, i248, i249, i250, i251, i252, i253, i254, i255
+ );
+
+ assign out
+ = (sel==8\'h00) ? i0 : (sel==8\'h01) ? i1 : (sel==8\'h02) ? i2 : (sel==8\'h03) ? i3
+ : (sel==8\'h04) ? i4 : (sel==8\'h05) ? i5 : (sel==8\'h06) ? i6 : (sel==8\'h07) ? i7
+ : (sel==8\'h08) ? i8 : (sel==8\'h09) ? i9 : (sel==8\'h0a) ? i10 : (sel==8\'h0b) ? i11
+ : (sel==8\'h0c) ? i12 : (sel==8\'h0d) ? i13 : (sel==8\'h0e) ? i14 : (sel==8\'h0f) ? i15
+ : (sel==8\'h10) ? i16 : (sel==8\'h11) ? i17 : (sel==8\'h12) ? i18 : (sel==8\'h13) ? i19
+ : (sel==8\'h14) ? i20 : (sel==8\'h15) ? i21 : (sel==8\'h16) ? i22 : (sel==8\'h17) ? i23
+ : (sel==8\'h18) ? i24 : (sel==8\'h19) ? i25 : (sel==8\'h1a) ? i26 : (sel==8\'h1b) ? i27
+ : (sel==8\'h1c) ? i28 : (sel==8\'h1d) ? i29 : (sel==8\'h1e) ? i30 : (sel==8\'h1f) ? i31
+ : (sel==8\'h20) ? i32 : (sel==8\'h21) ? i33 : (sel==8\'h22) ? i34 : (sel==8\'h23) ? i35
+ : (sel==8\'h24) ? i36 : (sel==8\'h25) ? i37 : (sel==8\'h26) ? i38 : (sel==8\'h27) ? i39
+ : (sel==8\'h28) ? i40 : (sel==8\'h29) ? i41 : (sel==8\'h2a) ? i42 : (sel==8\'h2b) ? i43
+ : (sel==8\'h2c) ? i44 : (sel==8\'h2d) ? i45 : (sel==8\'h2e) ? i46 : (sel==8\'h2f) ? i47
+ : (sel==8\'h30) ? i48 : (sel==8\'h31) ? i49 : (sel==8\'h32) ? i50 : (sel==8\'h33) ? i51
+ : (sel==8\'h34) ? i52 : (sel==8\'h35) ? i53 : (sel==8\'h36) ? i54 : (sel==8\'h37) ? i55
+ : (sel==8\'h38) ? i56 : (sel==8\'h39) ? i57 : (sel==8\'h3a) ? i58 : (sel==8\'h3b) ? i59
+ : (sel==8\'h3c) ? i60 : (sel==8\'h3d) ? i61 : (sel==8\'h3e) ? i62 : (sel==8\'h3f) ? i63
+ : (sel==8\'h40) ? i64 : (sel==8\'h41) ? i65 : (sel==8\'h42) ? i66 : (sel==8\'h43) ? i67
+ : (sel==8\'h44) ? i68 : (sel==8\'h45) ? i69 : (sel==8\'h46) ? i70 : (sel==8\'h47) ? i71
+ : (sel==8\'h48) ? i72 : (sel==8\'h49) ? i73 : (sel==8\'h4a) ? i74 : (sel==8\'h4b) ? i75
+ : (sel==8\'h4c) ? i76 : (sel==8\'h4d) ? i77 : (sel==8\'h4e) ? i78 : (sel==8\'h4f) ? i79
+ : (sel==8\'h50) ? i80 : (sel==8\'h51) ? i81 : (sel==8\'h52) ? i82 : (sel==8\'h53) ? i83
+ : (sel==8\'h54) ? i84 : (sel==8\'h55) ? i85 : (sel==8\'h56) ? i86 : (sel==8\'h57) ? i87
+ : (sel==8\'h58) ? i88 : (sel==8\'h59) ? i89 : (sel==8\'h5a) ? i90 : (sel==8\'h5b) ? i91
+ : (sel==8\'h5c) ? i92 : (sel==8\'h5d) ? i93 : (sel==8\'h5e) ? i94 : (sel==8\'h5f) ? i95
+ : (sel==8\'h60) ? i96 : (sel==8\'h61) ? i97 : (sel==8\'h62) ? i98 : (sel==8\'h63) ? i99
+ : (sel==8\'h64) ? i100 : (sel==8\'h65) ? i101 : (sel==8\'h66) ? i102 : (sel==8\'h67) ? i103
+ : (sel==8\'h68) ? i104 : (sel==8\'h69) ? i105 : (sel==8\'h6a) ? i106 : (sel==8\'h6b) ? i107
+ : (sel==8\'h6c) ? i108 : (sel==8\'h6d) ? i109 : (sel==8\'h6e) ? i110 : (sel==8\'h6f) ? i111
+ : (sel==8\'h70) ? i112 : (sel==8\'h71) ? i113 : (sel==8\'h72) ? i114 : (sel==8\'h73) ? i115
+ : (sel==8\'h74) ? i116 : (sel==8\'h75) ? i117 : (sel==8\'h76) ? i118 : (sel==8\'h77) ? i119
+ : (sel==8\'h78) ? i120 : (sel==8\'h79) ? i121 : (sel==8\'h7a) ? i122 : (sel==8\'h7b) ? i123
+ : (sel==8\'h7c) ? i124 : (sel==8\'h7d) ? i125 : (sel==8\'h7e) ? i126 : (sel==8\'h7f) ? i127
+ : (sel==8\'h80) ? i128 : (sel==8\'h81) ? i129 : (sel==8\'h82) ? i130 : (sel==8\'h83) ? i131
+ : (sel==8\'h84) ? i132 : (sel==8\'h85) ? i133 : (sel==8\'h86) ? i134 : (sel==8\'h87) ? i135
+ : (sel==8\'h88) ? i136 : (sel==8\'h89) ? i137 : (sel==8\'h8a) ? i138 : (sel==8\'h8b) ? i139
+ : (sel==8\'h8c) ? i140 : (sel==8\'h8d) ? i141 : (sel==8\'h8e) ? i142 : (sel==8\'h8f) ? i143
+ : (sel==8\'h90) ? i144 : (sel==8\'h91) ? i145 : (sel==8\'h92) ? i146 : (sel==8\'h93) ? i147
+ : (sel==8\'h94) ? i148 : (sel==8\'h95) ? i149 : (sel==8\'h96) ? i150 : (sel==8\'h98) ? i151
+ : (sel==8\'h99) ? i152 : (sel==8\'h9a) ? i153 : (sel==8\'h9b) ? i154 : (sel==8\'h9c) ? i155
+ : (sel==8\'h9d) ? i156 : (sel==8\'h9e) ? i157 : (sel==8\'h9f) ? i158 : (sel==8\'ha0) ? i159
+ : (sel==8\'ha1) ? i160 : (sel==8\'ha2) ? i161 : (sel==8\'ha3) ? i162 : (sel==8\'ha4) ? i163
+ : (sel==8\'ha5) ? i164 : (sel==8\'ha6) ? i165 : (sel==8\'ha7) ? i166 : (sel==8\'ha8) ? i167
+ : (sel==8\'ha9) ? i168 : (sel==8\'haa) ? i169 : (sel==8\'hab) ? i170 : (sel==8\'hac) ? i171
+ : (sel==8\'had) ? i172 : (sel==8\'hae) ? i173 : (sel==8\'haf) ? i174 : (sel==8\'hb0) ? i175
+ : (sel==8\'hb1) ? i176 : (sel==8\'hb2) ? i177 : (sel==8\'hb3) ? i178 : (sel==8\'hb4) ? i179
+ : (sel==8\'hb5) ? i180 : (sel==8\'hb6) ? i181 : (sel==8\'hb7) ? i182 : (sel==8\'hb8) ? i183
+ : (sel==8\'hb9) ? i184 : (sel==8\'hba) ? i185 : (sel==8\'hbb) ? i186 : (sel==8\'hbc) ? i187
+ : (sel==8\'hbd) ? i188 : (sel==8\'hbe) ? i189 : (sel==8\'hbf) ? i190 : (sel==8\'hc0) ? i191
+ : (sel==8\'hc1) ? i192 : (sel==8\'hc2) ? i193 : (sel==8\'hc3) ? i194 : (sel==8\'hc4) ? i195
+ : (sel==8\'hc5) ? i196 : (sel==8\'hc6) ? i197 : (sel==8\'hc7) ? i198 : (sel==8\'hc8) ? i199
+ : (sel==8\'hc9) ? i200 : (sel==8\'hca) ? i201 : (sel==8\'hcb) ? i202 : (sel==8\'hcc) ? i203
+ : (sel==8\'hcd) ? i204 : (sel==8\'hce) ? i205 : (sel==8\'hcf) ? i206 : (sel==8\'hd0) ? i207
+ : (sel==8\'hd1) ? i208 : (sel==8\'hd2) ? i209 : (sel==8\'hd3) ? i210 : (sel==8\'hd4) ? i211
+ : (sel==8\'hd5) ? i212 : (sel==8\'hd6) ? i213 : (sel==8\'hd7) ? i214 : (sel==8\'hd8) ? i215
+ : (sel==8\'hd9) ? i216 : (sel==8\'hda) ? i217 : (sel==8\'hdb) ? i218 : (sel==8\'hdc) ? i219
+ : (sel==8\'hdd) ? i220 : (sel==8\'hde) ? i221 : (sel==8\'hdf) ? i222 : (sel==8\'he0) ? i223
+ : (sel==8\'he1) ? i224 : (sel==8\'he2) ? i225 : (sel==8\'he3) ? i226 : (sel==8\'he4) ? i227
+ : (sel==8\'he5) ? i228 : (sel==8\'he6) ? i229 : (sel==8\'he7) ? i230 : (sel==8\'he8) ? i231
+ : (sel==8\'he9) ? i232 : (sel==8\'hea) ? i233 : (sel==8\'heb) ? i234 : (sel==8\'hec) ? i235
+ : (sel==8\'hed) ? i236 : (sel==8\'hee) ? i237 : (sel==8\'hef) ? i238 : (sel==8\'hf0) ? i239
+ : (sel==8\'hf1) ? i240 : (sel==8\'hf2) ? i241 : (sel==8\'hf3) ? i242 : (sel==8\'hf4) ? i243
+ : (sel==8\'hf5) ? i244 : (sel==8\'hf6) ? i245 : (sel==8\'hf7) ? i246 : (sel==8\'hf8) ? i247
+ : (sel==8\'hf9) ? i248 : (sel==8\'hfa) ? i249 : (sel==8\'hfb) ? i250 : (sel==8\'hfc) ? i251
+ : (sel==8\'hfd) ? i252 : (sel==8\'hfe) ? i253 : (sel==8\'hff) ? i254 : i255;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+//
+// bug445
+
+`define WIDTH 12
+`define SEL_NUM_BITS `WIDTH-`SEL_NUM_BITS +: `SEL_NUM_BITS
+`define SEL_BITS `WIDTH-`SEL_NUM_BITS +: `SEL_NUM_BITS
+`define ADDR_BITS 0 +: `WIDTH-`SEL_NUM_BITS
+
+typedef logic [`SEL_NUM_BITS-1:0] d_t;
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+module t (b);
+ output reg [31:0] b;
+ initial begin
+ b = 22;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// A test of the import parameter used with modport
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Jeremy Bennett.
+
+interface test_if;
+
+ // Interface variable
+ logic \tdata;
+
+ // Modport
+ modport mp(
+ import myfunc,
+\t output data
+\t );
+
+ function automatic logic myfunc (input logic val);
+ begin
+\t myfunc = (val == 1\'b0);
+ end
+ endfunction
+
+endinterface // test_if
+
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ test_if i ();
+
+ testmod testmod_i (.clk (clk),
+\t\t .i (i.mp));
+
+endmodule
+
+
+module testmod
+ (
+ input clk,
+ test_if.mp i
+ );
+
+ always @(posedge clk) begin
+ i.data = 1\'b0;
+ if (i.myfunc (1\'b0)) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ else begin
+\t $stop;
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Jie Xu.
+
+//bug692
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input wire clk;
+
+ wire [31:0] \t result;
+ test_if #(.id(3)) s();
+ sub_test U_SUB_TEST(s.a.b, result); // the line causing error
+endmodule : t
+
+// ---------------------------------------------------------------------------
+
+module sub_test
+ (
+ input [31:0] b,
+ output [31:0] c
+ );
+ assign c = b;
+endmodule
+
+// ---------------------------------------------------------------------------
+
+interface test_if
+ #(parameter id = 0)
+ ();
+
+ typedef struct packed {
+ logic \t a;
+ logic [31:0] b;
+ } aType;
+
+ aType a;
+
+ typedef struct packed {
+ logic \t c;
+ logic [31:0] d;
+ } bType;
+
+ bType b;
+
+ modport master (input a, output b);
+
+endinterface
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer _mode; initial _mode=0;
+ reg [7:0] a;
+ reg [7:0] b;
+ reg [7:0] c;
+
+ reg [7:0] mode_d1r;
+ reg [7:0] mode_d2r;
+ reg [7:0] mode_d3r;
+
+ // surefire lint_off ITENST
+ // surefire lint_off STMINI
+ // surefire lint_off NBAJAM
+
+ always @ (posedge clk) begin\t// filp-flops with asynchronous reset
+ if (0) begin
+\t _mode <= 0;
+ end
+ else begin
+\t _mode <= _mode + 1;
+\t if (_mode==0) begin
+\t $write(""[%0t] t_blocking: Running\
+"", $time);
+\t a <= 8\'d0;
+\t b <= 8\'d0;
+\t c <= 8\'d0;
+\t end
+\t else if (_mode==1) begin
+\t if (a !== 8\'d0) $stop;
+\t if (b !== 8\'d0) $stop;
+\t if (c !== 8\'d0) $stop;
+\t a <= b;
+\t b <= 8\'d1;
+\t c <= b;
+\t if (a !== 8\'d0) $stop;
+\t if (b !== 8\'d0) $stop;
+\t if (c !== 8\'d0) $stop;
+\t end
+\t else if (_mode==2) begin
+\t if (a !== 8\'d0) $stop;
+\t if (b !== 8\'d1) $stop;
+\t if (c !== 8\'d0) $stop;
+\t a <= b;
+\t b <= 8\'d2;
+\t c <= b;
+\t if (a !== 8\'d0) $stop;
+\t if (b !== 8\'d1) $stop;
+\t if (c !== 8\'d0) $stop;
+\t end
+\t else if (_mode==3) begin
+\t if (a !== 8\'d1) $stop;
+\t if (b !== 8\'d2) $stop;
+\t if (c !== 8\'d1) $stop;
+\t end
+\t else if (_mode==4) begin
+\t if (mode_d3r != 8\'d1) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+ always @ (posedge clk) begin
+ mode_d3r <= mode_d2r;
+ mode_d2r <= mode_d1r;
+ mode_d1r <= _mode[7:0];
+ end
+
+ reg [14:10] bits;
+ // surefire lint_off SEQASS
+ always @ (posedge clk) begin
+ if (_mode==1) begin
+\t bits[14:13] <= 2\'b11;
+\t bits[12] <= 1\'b1;
+ end
+ if (_mode==2) begin
+\t bits[11:10] <= 2\'b10;
+\t bits[13] <= 0;
+ end
+ if (_mode==3) begin
+\t if (bits !== 5\'b10110) $stop;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+// bug420
+typedef logic [7-1:0] wb_ind_t;
+typedef logic [7-1:0] id_t;
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [31:0] in = crc[31:0];
+
+ /*AUTOWIRE*/
+
+ wire [6:0] out = line_wb_ind( in[6:0] );
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {57\'h0, out};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'hc918fa0aa882a206
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+ function wb_ind_t line_wb_ind( id_t id );
+ if( id[$bits(id_t)-1] == 0 )
+ return {2\'b00, id[$bits(wb_ind_t)-3:0]};
+ else
+ return {2\'b01, id[$bits(wb_ind_t)-3:0]};
+ endfunction // line_wb_ind
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003-2008 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+
+ integer cyc; initial cyc=1;
+ integer sum;
+ integer cpre;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cpre = cyc;
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t if (mlog2(32\'d0) != 32\'d0) $stop;
+\t if (mlog2(32\'d1) != 32\'d0) $stop;
+\t if (mlog2(32\'d3) != 32\'d2) $stop;
+\t sum <= 32\'d0;
+\t end
+\t else if (cyc<90) begin
+\t // (cyc) so if we trash the variable things will get upset.
+\t sum <= mlog2(cyc) + sum * 32\'d42;
+\t if (cpre != cyc) $stop;
+\t end
+\t else if (cyc==90) begin
+\t if (sum !== 32\'h0f12bb51) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+ function integer mlog2;
+ input [31:0] value;
+ integer \t i;
+ begin
+\t if(value < 32\'d1) begin
+ mlog2 = 0;
+\t end
+\t else begin
+ value = value - 32\'d1;
+ mlog2 = 0;
+ for(i=0;i<32;i=i+1) begin
+ if(value > 32\'d0) begin
+ mlog2 = mlog2 + 1;
+ end
+ value = value >> 1;
+ end
+\t end
+ end
+ endfunction
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005-2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ value
+ );
+
+ input [3:0] value;
+ always @ (/*AS*/value) begin
+ casez (value)
+\t4'b0000: $stop;
+\t4'b1xxx: $stop;
+\tdefault: $stop;
+ endcase
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003-2007 by Wilson Snyder.
+
+module t(/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ // surefire lint_off NBAJAM
+
+ input clk;
+ reg [7:0] _ranit;
+
+ reg [2:0] a;
+ reg [7:0] vvector;
+ reg [7:0] vvector_flip;
+
+ // surefire lint_off STMINI
+ initial _ranit = 0;
+
+ always @ (posedge clk) begin
+ a <= a + 3\'d1;
+ vvector[a] <= 1\'b1;\t// This should use ""old"" value for a
+ vvector_flip[~a] <= 1\'b1;\t// This should use ""old"" value for a
+ //
+ //========
+ if (_ranit==8\'d0) begin
+\t _ranit <= 8\'d1;
+\t $write(""[%0t] t_select_index: Running\
+"", $time);
+\t vvector <= 0;
+\t vvector_flip <= 0;
+\t a <= 3\'b1;
+ end
+ else _ranit <= _ranit + 8\'d1;
+ //
+ if (_ranit==8\'d3) begin
+\t $write(""%x %x\
+"",vvector,vvector_flip);
+\t if (vvector !== 8\'b0000110) $stop;
+\t if (vvector_flip !== 8\'b0110_0000) $stop;
+\t //
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ state,
+ // Inputs
+ clk
+ );
+ input clk;
+
+ // Gave ""Internal Error: V3Broken.cpp:: Broken link in node""
+ output [1:0] state;
+ reg [1:0] \tstate = 2\'b11;
+ always @ (posedge clk) begin
+ state <= state;
+ end
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Chandan Egbert.
+
+// See bug569
+
+module t();
+`ifdef T_FUNC_V_NOINL
+ // verilator no_inline_module
+`endif
+ level1 ul1();
+ initial ul1.doit(4\'b0);
+endmodule
+
+module level1();
+`ifdef T_FUNC_V_NOINL
+ // verilator no_inline_module
+`endif
+ level2 ul2();
+
+ task doit(input logic [3:0] v);
+ ul2.mem = v;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ endtask
+endmodule
+
+module level2();
+`ifdef T_FUNC_V_NOINL
+ // verilator no_inline_module
+`endif
+ logic [3:0] mem;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [31:0] in = crc[31:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [31:0]\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[31:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(in[31:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {32\'h0, out};
+
+ // What checksum will we end up with
+`define EXPECTED_SUM 64\'h966e272fd829e672
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ clk, in
+ );
+
+ input clk;
+ input [31:0] in;
+ output [31:0] out;
+
+ /*AUTOREG*/
+ // Beginning of automatic regs (for this module\'s undeclared outputs)
+ reg [31:0]\t\tout;
+ // End of automatics
+
+`ifdef verilator
+ `define dontOptimize $c1(""1"")
+`else
+ `define dontOptimize 1\'b1
+`endif
+
+ always @(posedge clk) begin
+ out <= in;
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+ if (`dontOptimize) if (`dontOptimize) if (`dontOptimize) if (`dontOptimize)
+\tif (in[0])
+\t out <= ~in;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [31:0] in = crc[31:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [31:0] \t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ // Async clears must not race with clocks if we want repeatable results
+ reg \t\tset_l = in[20];
+ reg \t\tclr_l = in[21];
+ always @ (negedge clk) begin
+ set_l <= in[20];
+ clr_l <= in[21];
+ end
+
+ //====== Mux
+ wire [1:0] \t\tqm;
+ // delay z a b sel
+ udp_mux2 #(0.1) m0 (qm[0], in[0], in[2], in[4]);
+ udp_mux2 #0.1 m1 (qm[1], in[1], in[3], in[4]);
+
+`define verilatorxx
+`ifdef verilatorxx
+ reg [1:0] \t\tql;
+ reg [1:0] \t\tqd;
+
+ // No sequential tables, yet
+// always @* begin
+// if (!clk) ql = in[13:12];
+// end
+ always @(posedge clk or negedge set_l or negedge clr_l) begin
+ if (!set_l) qd <= ~2\'b0;
+ else if (!clr_l) qd <= 2\'b0;
+ else qd <= in[17:16];
+ end
+`else
+ //====== Latch
+// wire [1:0] \t\tql;
+// // q clk d
+// udp_latch l0 (ql[0], !in[8], in[12]);
+// udp_latch l1 (ql[1], !in[8], in[13]);
+
+ //====== DFF
+ wire [1:0] \t\tqd;
+ //always @* $display(""UL q=%b c=%b d=%b"", ql[1:0], in[8], in[13:12]);
+ // q clk d set_l clr_l
+ udp_dff d0 (qd[0], in[8], in[16], set_l, clr_l);
+ udp_dff d2 (qd[1], in[8], in[17], set_l, clr_l);
+`endif
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {52\'h0, 2\'b0,qd, 4\'b0, 2\'b0,qm};
+// wire [63:0] result = {52\'h0, 2\'b0,qd, 2\'b0,ql, 2\'b0,qm};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+\t // Note not all simulators agree about the latch result. Maybe have a race?
+`define EXPECTED_SUM 64\'hb73acf228acaeaa3
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+primitive udp_mux2 (z, a, b, sel);
+ output z;
+ input a, b, sel;
+ table
+ //a b s o
+ ? 1 1 : 1 ;
+ ? 0 1 : 0 ;
+ 1 ? 0 : 1 ;
+ 0 ? 0 : 0 ;
+ 1 1 x : 1 ;
+ 0 0 x : 0 ;
+ endtable
+endprimitive
+
+primitive udp_latch (q, clk, d);
+ output q; reg q;
+ input clk, d;
+ table
+ //clk d q q\'
+ 0 1 : ? : 1;
+ 0 0 : ? : 0;
+ 1 ? : ? : -;
+ endtable
+endprimitive
+
+primitive udp_dff (q, clk, d, set_l, clr_l);
+ output q;
+ input clk, d, set_l, clr_l;
+ reg q;
+ table
+ //ck d s c : q : q\'
+ r 0 1 ? : ? : 0 ;
+ r 1 ? 1 : ? : 1 ;
+ * 1 ? 1 : 1 : 1 ;
+ * 0 1 ? : 0 : 0 ;
+ f ? ? ? : ? : - ;
+ b * ? ? : ? : - ;
+ ? ? 0 ? : ? : 1 ;
+ b ? * 1 : 1 : 1 ;
+ x 1 * 1 : 1 : 1 ;
+ ? ? 1 0 : ? : 0 ;
+ b ? 1 * : 0 : 0 ;
+ x 0 1 * : 0 : 0 ;
+ endtable
+endprimitive
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [31:0]\t\tO_out;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .O_out\t\t\t(O_out[31:0]));
+
+ initial begin
+ if (O_out != 32\'h4) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+module Test
+ (
+ output [31:0] O_out
+ );
+
+ test
+ #(
+ .pFOO(5),
+ .pBAR(2)
+ ) U_test
+ (
+\t.O_out(O_out)
+\t);
+endmodule
+
+module test
+ #(parameter pFOO = 7,
+ parameter pBAR = 3,
+ parameter pBAZ = ceiling(pFOO, pBAR)
+ )
+ (
+ output [31:0] O_out
+ );
+
+ assign O_out = pBAZ;
+
+ function integer ceiling;
+ input [31:0] x, y;
+ ceiling = ((x%y == 0) ? x/y : (x/y)+1) + 1;
+ endfunction
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+ reg \t check; initial check = 1\'b0;
+
+ // verilator lint_off WIDTH
+
+ //============================================================
+
+ reg [ 1:0] W0095; //=3
+ reg [ 58:0] W0101; //=0000000FFFFFFFF
+ always @(posedge clk) begin
+ if (cyc==1) begin
+\t W0095 = ((2\'h3));
+\t W0101 = ({27\'h0,({16{(W0095)}})});
+ end
+ end
+ always @(posedge clk) begin
+ if (cyc==2) begin
+\t if ((W0101) != (59\'h0FFFFFFFF)) if (check) $stop;
+ end
+ end
+
+ //============================================================
+
+ reg [ 0:0] W1243; //=1
+ always @(posedge clk) begin
+ if (cyc==1) begin
+ W1243 = ((1\'h1));
+ end
+ end
+ always @(posedge clk) begin
+ if (cyc==2) begin
+\t // Width violation, but still...
+\t if (((-W1243) < 32\'h01) != (1\'h0)) if (check) $stop;
+\t if (({32{W1243}} < 32\'h01) != (1\'h0)) if (check) $stop;
+ end
+ end
+
+ //============================================================
+
+ reg [ 0:0] W0344; //=0
+ always @(posedge clk) begin
+ if (cyc==1) begin
+\t W0344 = 1\'b0;
+ end
+ end
+ always @(posedge clk) begin
+ if (cyc==2) begin
+\t if ((W0344) != (1\'h0)) if (check) $stop;
+\t if (({116{(((- 95\'h7FFFFFFFFFFFFFFFFFFFFFFF) ^ 95\'h7FFFFFFFFFFFFFFFFFFFFFFF ) == ({94\'h0,W0344}))}})) if (check) $stop;
+ end
+ end
+
+ //============================================================
+
+ reg [ 63:0] W0372; //=FFFFFFFFFFFFFFFF
+ reg [118:0] \t W0420; //=7FFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+ reg [115:0] \t W0421; //=00000000000000000000000000000
+ always @(posedge clk) begin
+ if (cyc==1) begin
+\t W0372 = ({64{((1\'h1))}});
+\t W0421 = 116\'h0;
+\t W0420 = ({119{((W0372) <= (W0372))}});
+ end
+ end
+ always @(posedge clk) begin
+ if (cyc==2) begin
+\t if ((W0420[(- (W0421[115:110]))]) != (1\'h1)) if (check) $stop;
+ end
+ end
+
+ //============================================================
+
+ // gcc_2_96_bug
+ reg [ 31:0] W0161; //=FFFFFFFF
+ reg [ 62:0] \t W0217; //=0000000000000000
+ reg [ 53:0] \t W0219; //=00000000000000
+ always @(posedge clk) begin
+ if (cyc==1) begin
+\t W0161 = 32\'hFFFFFFFF;
+\t W0217 = 63\'h0;
+\t W0219 = 54\'h0;
+ end
+ end
+ always @(posedge clk) begin
+ if (cyc==2) begin
+\t if ((W0161) != (32\'hFFFFFFFF)) if (check) $stop;
+\t if (((- (W0161)) & ((W0217[62:31]) & ({25\'h0,(W0219[53:47])}))) != (32\'h00000000)) if (check) $stop;
+ end
+ end
+
+ //============================================================
+
+ reg [119:0] W0592; //=000000000000000000000000000000
+ reg [ 7:0] \t W0593; //=70
+ always @(posedge clk) begin
+ if (cyc==1) begin
+\t W0593 = (((8\'h90)) * ((8\'hFF)));
+ W0592 = 120\'h000000000000000000000000000000;
+ end
+ end
+ always @(posedge clk) begin
+ if (cyc==2) begin
+\tif (((W0592[119:9]) >> ((W0593))) != (111\'h0000000000000000000000000000)) if (check) $stop;
+ end
+ end
+
+ //============================================================
+
+ reg [127:0] WA1063 ; //=00000000000000000000000000000001
+ reg [ 34:0] \t WA1064 /*verilator public*/; //=7FFFFFFFF
+ reg [ 62:0] \t WA1065 ; //=0000000000000000
+ reg [ 89:0] \t WA1066 /*verilator public*/; //=00000000000000000000001
+ reg [ 34:0] \t WA1067 ; //=7FFFFFFFF
+ reg [111:0]\t WA1068;
+
+ always @(check) begin
+ WA1067 = (~ (35\'h0));
+ WA1066 = (90\'h00000000000000000000001);
+ WA1065 = (WA1066[89:27]);
+ WA1064 = (WA1067);
+ WA1063 = (~ ((~ (128\'hffffffffffffffffffffffffffffffff)) ^ (~ (128\'h00000000000000000000000000000001))));
+ end
+ always @(posedge clk) begin
+ if (cyc==2) begin
+\t if ((WA1063[(WA1064[(WA1065[((5\'h04) | (5\'h0))+:4])+:3])+:112]) != 112\'h0) if (check) $stop;
+ end
+ end
+
+ //============================================================
+
+ reg [127:0] WB1063 ; //=00000000000000000000000000000001
+ reg [ 34:0] \t WB1064 /*verilator public*/; //=7FFFFFFFF
+ reg [ 62:0] \t WB1065 ; //=0000000000000000
+ reg [ 89:0] \t WB1066 /*verilator public*/; //=00000000000000000000001
+ reg [ 34:0] \t WB1067 ; //=7FFFFFFFF
+ reg [111:0]\t WB1068;
+
+ always @(posedge clk) begin
+ if (cyc==1) begin
+\t WB1067 = (~ (35\'h0));
+\t WB1066 = (90\'h00000000000000000000001);
+ end
+ if (cyc==2) WB1065 <= (WB1066[89:27]);
+ if (cyc==3) WB1064 <= (WB1067);
+ if (cyc==4) WB1063 <= (~ ((~ (128\'hffffffffffffffffffffffffffffffff)) ^ (~ (128\'h00000000000000000000000000000001))));
+ if (cyc==5) WB1068 <= (WB1063[(WB1064[(WB1065[((5\'h04) | (5\'h0))+:4])+:3])+:112]);
+ end
+ always @(posedge clk) begin
+ if (cyc==9) begin
+\t if (WB1068 != 112\'h0) if (check) $stop;
+\t if ((WB1063[(WB1064[(WB1065[((5\'h04) | (5\'h0))+:4])+:3])+:112]) != 112\'h0) if (check) $stop;
+ end
+ end
+
+ //============================================================
+
+ reg signed [ 60:0] WC0064 ; //=1FFFFFFFFFFFFFFF
+ reg signed [ 6:0] WC0065 ; //=00
+ reg signed [ 62:0] WC0067 /*verilator public*/; //=33250A3BFFFFFFFF
+
+ always @(check) begin
+ WC0064 = 61\'sh1FFFFFFFFFFFFFFF;
+ WC0065 = 7\'sh0;
+ if (((WC0064) >>> (WC0065)) != 61\'sh1fffffffffffffff) if (check) $stop;
+ end
+
+ //============================================================
+
+ reg signed [ 76:0] W0234 ; //=00000000000000000000
+ reg signed [ 7:0] W0235 /*verilator public*/; //=B6
+ always @(check) begin
+ W0235 = 8\'shb6;
+ W0234 = ((77\'sh0001ffffffffffffffff) >>> (W0235));
+ if ((W0234) != 77\'sh0) if (check) $stop;
+ end
+
+ //============================================================
+
+ reg signed [ 30:0] W0146 ; //=00000001
+ always @(check) begin : Block71
+ W0146 = (31\'sh00000001);
+ if ((W0146 >>> 6\'sh3f) != 31\'sh0) if (check) $stop;
+ end
+
+ //============================================================
+
+ reg signed [ 54:0] W0857 /*verilator public*/; //=7FFFFFFFFFFFFF
+
+ always @(check) begin : Block405
+ W0857 = 55\'sh7fffffffffffff;
+ if ((63\'sh7fffffffffffffff >>> (W0857[54:54] ? 7\'sh56 : 7\'sh7f)) != 63\'sh7fffffffffffffff) if (check) $stop;
+ end
+
+ //============================================================
+
+ always @(posedge clk) begin
+ if ((((122\'sh3ffffffffffffffd3e48e0900000001 >>> 8\'shff) >>> 8\'b1) ) != 122\'sh3ffffffffffffffffffffffffffffff) if (check) $stop;
+ if (((95\'sh7fff_ffff_ffffffff_ffffffff < 95\'sh4a76_3d8b_0f4e3995_1146e342) != 1\'h0)) if (check) $stop;
+ end
+
+ //============================================================
+
+ reg signed [ 82:0] W0226 ; //=47A4301EE3FB4133EE3DA
+
+ always @* begin : Block144
+ W0226 = 83\'sh47A4301EE3FB4133EE3DA;
+ if ((W0226 >>> 8\'sh1a) != 83\'sh7ffffff1e90c07b8fed04) if (check) $stop;
+ end
+
+ //============================================================
+
+ reg signed [ 68:0] W0792 /*verilator public*/; //=169351569551247E0C
+ reg signed [ 68:0] W0793 ; //=1FFFFFFFFF4EB1A91A
+
+ always @(posedge clk) begin
+ W0793 <= 69\'sh1f_ffffffff_4eb1a91a;
+ W0792 <= (W0793 * 69\'sh1F_0E989F3E_F15F509E);
+ if (W0792 != 69\'sh16_93515695_51247E0C) if (check) $stop;
+ end
+
+ //============================================================
+
+ reg signed [ 2:0] DW0515 /*verilator public*/; //=7
+
+ always @(posedge clk) begin
+ DW0515 <= 3\'sh7;
+ if ($signed({62\'h0,DW0515[1\'h1]}) != 63\'sh0000000000000001) if (check) $stop;
+ end
+
+ //============================================================
+
+ reg signed [ 62:0] W0753 ; //=004E20004ED93E26
+ reg [ 2:0] W0772 /*verilator public*/; //=7
+
+ always @(posedge clk) begin
+ W0753 <= 63\'sh004E20004ED93E26; //(63\'sh7fffffffffffffff + (63\'sh464eac8c4ed93e27 & (63\'sh08cf6243ffffffff)));
+ W0772 <= 3\'h7;
+ if ((W0772[(W0753 < 63\'sh0876c66a7e29fabf)]) != 1\'h1) if (check) $stop;
+ if ((W0772[(63\'sh004E20004ED93E26 < 63\'sh0876c66a7e29fabf)]) != 1\'h1) if (check) $stop;
+ end
+
+ //============================================================
+
+ reg [ 98:0] W1027 ; //=7FFFFFFFFFFFFFFFFFFFFFFFF
+ always @(posedge clk) begin
+ W1027 <= ~99\'h0;
+ // verilator lint_off CMPCONST
+ if (((1\'sb1 < (95\'sh7fffffffffffffffffffffff >= 95\'sh09deb904ffffffffe062d44c))) != 1\'h0) if (check) $stop;
+ // verilator lint_on CMPCONST
+ end
+
+ //============================================================
+
+ reg signed [ 5:0] W123_is_3f ; //=3F
+
+ always @(posedge clk) begin
+ W123_is_3f <= 6\'sh3f;
+ end
+ always @(posedge clk) begin
+ if (((~ ((32\'sh088d1bcb) <<< W123_is_3f)) >>> 6\'sh3f) != 32\'shffffffff) if (check) $stop;
+ end
+
+ //============================================================
+
+ reg signed [105: 0] W0032 /*verilator public*/; //=106\'h3ff0000000100000000bd597bb1
+ always @(check) begin : Block237
+ W0032 = 106\'sh3ff0000000100000000bd597bb1;
+ if ((106\'sh1ca0000000000000000b96b8dc2 / 106\'sh3ff0000000100000000bd597bb1) != 106\'sh3fffffffffffffffffffffffe36) if (check) $stop;
+ if ((106\'sh1ca0000000000000000b96b8dc2 / W0032) != 106\'sh3fffffffffffffffffffffffe36) if (check) $stop;
+ end
+
+ //============================================================
+
+ reg signed [ 83: 0] W0024 ; //=84\'h0000000000000e1fe9094
+ reg signed [ 83: 0] W0025 ; //=84\'h0f66afffffffe308b3d7c
+ always @(posedge clk) begin
+ W0024 <= 84\'h0000000000000e1fe9094;
+ W0025 <= 84\'h0f66afffffffe308b3d7c;
+ if ((W0024 % W0025) != 84\'sh0000000000000e1fe9094) if (check) $stop;
+ end
+
+ //============================================================
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==18) begin
+\t check <= 1\'b1;
+\t end
+\t if (cyc==20) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+ reg \t\trst_n;
+
+ // Take CRC data and apply to testblock inputs
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [2:0]\t\tpos1;\t\t\t// From test of Test.v
+ wire [2:0]\t\tpos2;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (
+\t // Outputs
+\t .pos1\t\t\t(pos1[2:0]),
+\t .pos2\t\t\t(pos2[2:0]),
+\t /*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .rst_n\t\t\t(rst_n));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {61\'h0, pos1};
+
+ // What checksum will we end up with
+`define EXPECTED_SUM 64\'h039ea4d039c2e70b
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ rst_n <= ~1\'b0;
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t rst_n <= ~1\'b1;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+\t rst_n <= ~1\'b1;
+ end
+ else if (cyc<90) begin
+\t if (pos1 !== pos2) $stop;
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test
+ #(parameter SAMPLE_WIDTH = 5 )
+ (
+`ifdef verilator // Some simulators don\'t support clog2
+ output reg [$clog2(SAMPLE_WIDTH)-1:0] pos1,
+`else
+ output reg [log2(SAMPLE_WIDTH-1)-1:0] pos1,
+`endif
+ output reg [log2(SAMPLE_WIDTH-1)-1:0] pos2,
+ // System
+ input \tclk,
+ input \trst_n
+ );
+
+ function integer log2(input integer arg);
+ begin
+\t for(log2=0; arg>0; log2=log2+1)
+\t arg = (arg >> 1);
+ end
+ endfunction
+
+ always @ (posedge clk or negedge rst_n)
+ if (!rst_n) begin
+\tpos1 <= 0;
+\tpos2 <= 0;
+ end
+ else begin
+\tpos1 <= pos1 + 1;
+\tpos2 <= pos2 + 1;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t;
+ reg signed [20:0] longp; initial longp = 21\'shbbccc;
+ reg signed [20:0] longn; initial longn = 21\'shbbccc; initial longn[20]=1\'b1;
+ reg signed [40:0] quadp; initial quadp = 41\'sh1_bbbb_cccc;
+ reg signed [40:0] quadn; initial quadn = 41\'sh1_bbbb_cccc; initial quadn[40]=1\'b1;
+ reg signed [80:0] widep; initial widep = 81\'shbc_1234_5678_1234_5678;
+ reg signed [80:0] widen; initial widen = 81\'shbc_1234_5678_1234_5678; initial widen[40]=1\'b1;
+
+ initial begin
+ // Display formatting
+ $display(""[%0t] lp %%x=%x %%x=%x %%o=%o %%b=%b %%0d=%0d %%d=%d"", $time,
+\t longp, longp, longp, longp, longp, longp);
+ $display(""[%0t] ln %%x=%x %%x=%x %%o=%o %%b=%b %%0d=%0d %%d=%d"", $time,
+\t longn, longn, longn, longn, longn, longn);
+ $display(""[%0t] qp %%x=%x %%x=%x %%o=%o %%b=%b %%0d=%0d %%d=%d"", $time,
+\t quadp, quadp, quadp, quadp, quadp, quadp);
+ $display(""[%0t] qn %%x=%x %%x=%x %%o=%o %%b=%b %%0d=%0d %%d=%d"", $time,
+\t quadn, quadn, quadn, quadn, quadn, quadn);
+ $display(""[%0t] wp %%x=%x %%x=%x %%o=%o %%b=%b"", $time,
+\t widep, widep, widep, widep);
+ $display(""[%0t] wn %%x=%x %%x=%x %%o=%o %%b=%b"", $time,
+\t widen, widen, widen, widen);
+ $display;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t;
+ parameter [ BMSB : BLSB ] B = A[23:20]; // 3
+ parameter A = 32\'h12345678;
+ parameter BLSB = A[16+:4]; // 4
+ parameter BMSB = A[7:4]; // 7
+
+ initial begin
+ if (B !== 4\'h3) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg [127:0] \t\ti;
+ wire [127:0]\t\tq1;
+ wire [127:0]\t\tq32;
+ wire [127:0]\t\tq64;
+ wire [63:0]\t\tq64_low;
+
+ assign q1 = {
+ i[24*4], i[25*4], i[26*4], i[27*4], i[28*4], i[29*4], i[30*4], i[31*4],
+ i[16*4], i[17*4], i[18*4], i[19*4], i[20*4], i[21*4], i[22*4], i[23*4],
+ i[8*4], i[9*4], i[10*4], i[11*4], i[12*4], i[13*4], i[14*4], i[15*4],
+ i[0*4], i[1*4], i[2*4], i[3*4], i[4*4], i[5*4], i[6*4], i[7*4],
+
+ i[24*4+1], i[25*4+1], i[26*4+1], i[27*4+1], i[28*4+1], i[29*4+1], i[30*4+1], i[31*4+1],
+ i[16*4+1], i[17*4+1], i[18*4+1], i[19*4+1], i[20*4+1], i[21*4+1], i[22*4+1], i[23*4+1],
+ i[8*4+1], i[9*4+1], i[10*4+1], i[11*4+1], i[12*4+1], i[13*4+1], i[14*4+1], i[15*4+1],
+ i[0*4+1], i[1*4+1], i[2*4+1], i[3*4+1], i[4*4+1], i[5*4+1], i[6*4+1], i[7*4+1],
+
+ i[24*4+2], i[25*4+2], i[26*4+2], i[27*4+2], i[28*4+2], i[29*4+2], i[30*4+2], i[31*4+2],
+ i[16*4+2], i[17*4+2], i[18*4+2], i[19*4+2], i[20*4+2], i[21*4+2], i[22*4+2], i[23*4+2],
+ i[8*4+2], i[9*4+2], i[10*4+2], i[11*4+2], i[12*4+2], i[13*4+2], i[14*4+2], i[15*4+2],
+ i[0*4+2], i[1*4+2], i[2*4+2], i[3*4+2], i[4*4+2], i[5*4+2], i[6*4+2], i[7*4+2],
+
+ i[24*4+3], i[25*4+3], i[26*4+3], i[27*4+3], i[28*4+3], i[29*4+3], i[30*4+3], i[31*4+3],
+ i[16*4+3], i[17*4+3], i[18*4+3], i[19*4+3], i[20*4+3], i[21*4+3], i[22*4+3], i[23*4+3],
+ i[8*4+3], i[9*4+3], i[10*4+3], i[11*4+3], i[12*4+3], i[13*4+3], i[14*4+3], i[15*4+3],
+ i[0*4+3], i[1*4+3], i[2*4+3], i[3*4+3], i[4*4+3], i[5*4+3], i[6*4+3], i[7*4+3]};
+
+ assign q64[127:64] = {
+ i[24*4], i[25*4], i[26*4], i[27*4], i[28*4], i[29*4], i[30*4], i[31*4],
+ i[16*4], i[17*4], i[18*4], i[19*4], i[20*4], i[21*4], i[22*4], i[23*4],
+ i[8*4], i[9*4], i[10*4], i[11*4], i[12*4], i[13*4], i[14*4], i[15*4],
+ i[0*4], i[1*4], i[2*4], i[3*4], i[4*4], i[5*4], i[6*4], i[7*4],
+
+ i[24*4+1], i[25*4+1], i[26*4+1], i[27*4+1], i[28*4+1], i[29*4+1], i[30*4+1], i[31*4+1],
+ i[16*4+1], i[17*4+1], i[18*4+1], i[19*4+1], i[20*4+1], i[21*4+1], i[22*4+1], i[23*4+1],
+ i[8*4+1], i[9*4+1], i[10*4+1], i[11*4+1], i[12*4+1], i[13*4+1], i[14*4+1], i[15*4+1],
+ i[0*4+1], i[1*4+1], i[2*4+1], i[3*4+1], i[4*4+1], i[5*4+1], i[6*4+1], i[7*4+1]};
+ assign q64[63:0] = {
+ i[24*4+2], i[25*4+2], i[26*4+2], i[27*4+2], i[28*4+2], i[29*4+2], i[30*4+2], i[31*4+2],
+ i[16*4+2], i[17*4+2], i[18*4+2], i[19*4+2], i[20*4+2], i[21*4+2], i[22*4+2], i[23*4+2],
+ i[8*4+2], i[9*4+2], i[10*4+2], i[11*4+2], i[12*4+2], i[13*4+2], i[14*4+2], i[15*4+2],
+ i[0*4+2], i[1*4+2], i[2*4+2], i[3*4+2], i[4*4+2], i[5*4+2], i[6*4+2], i[7*4+2],
+
+ i[24*4+3], i[25*4+3], i[26*4+3], i[27*4+3], i[28*4+3], i[29*4+3], i[30*4+3], i[31*4+3],
+ i[16*4+3], i[17*4+3], i[18*4+3], i[19*4+3], i[20*4+3], i[21*4+3], i[22*4+3], i[23*4+3],
+ i[8*4+3], i[9*4+3], i[10*4+3], i[11*4+3], i[12*4+3], i[13*4+3], i[14*4+3], i[15*4+3],
+ i[0*4+3], i[1*4+3], i[2*4+3], i[3*4+3], i[4*4+3], i[5*4+3], i[6*4+3], i[7*4+3]};
+
+ assign q64_low = {
+ i[24*4+2], i[25*4+2], i[26*4+2], i[27*4+2], i[28*4+2], i[29*4+2], i[30*4+2], i[31*4+2],
+ i[16*4+2], i[17*4+2], i[18*4+2], i[19*4+2], i[20*4+2], i[21*4+2], i[22*4+2], i[23*4+2],
+ i[8*4+2], i[9*4+2], i[10*4+2], i[11*4+2], i[12*4+2], i[13*4+2], i[14*4+2], i[15*4+2],
+ i[0*4+2], i[1*4+2], i[2*4+2], i[3*4+2], i[4*4+2], i[5*4+2], i[6*4+2], i[7*4+2],
+
+ i[24*4+3], i[25*4+3], i[26*4+3], i[27*4+3], i[28*4+3], i[29*4+3], i[30*4+3], i[31*4+3],
+ i[16*4+3], i[17*4+3], i[18*4+3], i[19*4+3], i[20*4+3], i[21*4+3], i[22*4+3], i[23*4+3],
+ i[8*4+3], i[9*4+3], i[10*4+3], i[11*4+3], i[12*4+3], i[13*4+3], i[14*4+3], i[15*4+3],
+ i[0*4+3], i[1*4+3], i[2*4+3], i[3*4+3], i[4*4+3], i[5*4+3], i[6*4+3], i[7*4+3]};
+
+ assign q32[127:96] = {
+ i[24*4], i[25*4], i[26*4], i[27*4], i[28*4], i[29*4], i[30*4], i[31*4],
+ i[16*4], i[17*4], i[18*4], i[19*4], i[20*4], i[21*4], i[22*4], i[23*4],
+ i[8*4], i[9*4], i[10*4], i[11*4], i[12*4], i[13*4], i[14*4], i[15*4],
+ i[0*4], i[1*4], i[2*4], i[3*4], i[4*4], i[5*4], i[6*4], i[7*4]};
+ assign q32[95:64] = {
+ i[24*4+1], i[25*4+1], i[26*4+1], i[27*4+1], i[28*4+1], i[29*4+1], i[30*4+1], i[31*4+1],
+ i[16*4+1], i[17*4+1], i[18*4+1], i[19*4+1], i[20*4+1], i[21*4+1], i[22*4+1], i[23*4+1],
+ i[8*4+1], i[9*4+1], i[10*4+1], i[11*4+1], i[12*4+1], i[13*4+1], i[14*4+1], i[15*4+1],
+ i[0*4+1], i[1*4+1], i[2*4+1], i[3*4+1], i[4*4+1], i[5*4+1], i[6*4+1], i[7*4+1]};
+ assign q32[63:32] = {
+ i[24*4+2], i[25*4+2], i[26*4+2], i[27*4+2], i[28*4+2], i[29*4+2], i[30*4+2], i[31*4+2],
+ i[16*4+2], i[17*4+2], i[18*4+2], i[19*4+2], i[20*4+2], i[21*4+2], i[22*4+2], i[23*4+2],
+ i[8*4+2], i[9*4+2], i[10*4+2], i[11*4+2], i[12*4+2], i[13*4+2], i[14*4+2], i[15*4+2],
+ i[0*4+2], i[1*4+2], i[2*4+2], i[3*4+2], i[4*4+2], i[5*4+2], i[6*4+2], i[7*4+2]};
+ assign q32[31:0] = {
+ i[24*4+3], i[25*4+3], i[26*4+3], i[27*4+3], i[28*4+3], i[29*4+3], i[30*4+3], i[31*4+3],
+ i[16*4+3], i[17*4+3], i[18*4+3], i[19*4+3], i[20*4+3], i[21*4+3], i[22*4+3], i[23*4+3],
+ i[8*4+3], i[9*4+3], i[10*4+3], i[11*4+3], i[12*4+3], i[13*4+3], i[14*4+3], i[15*4+3],
+ i[0*4+3], i[1*4+3], i[2*4+3], i[3*4+3], i[4*4+3], i[5*4+3], i[6*4+3], i[7*4+3]};
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+`ifdef TEST_VERBOSE
+\t $write(""%x %x\
+"", q1, i);
+`endif
+\t if (cyc==1) begin
+\t i <= 128\'hed388e646c843d35de489bab2413d770;
+\t end
+\t if (cyc==2) begin
+\t i <= 128\'h0e17c88f3d5fe51a982646c8e2bd68c3;
+\t if (q1 != 128\'h06f0b17c6551e269e3ab07723b26fb10) $stop;
+\t if (q1 != q32) $stop;
+\t if (q1 != q64) $stop;
+\t if (q1[63:0] != q64_low) $stop;
+\t end
+\t if (cyc==3) begin
+\t i <= 128\'he236ddfddddbdad20a48e039c9f395b8;
+\t if (q1 != 128\'h8c6f018c8a992c979a3e7859f29ac36d) $stop;
+\t if (q1 != q32) $stop;
+\t if (q1 != q64) $stop;
+\t if (q1[63:0] != q64_low) $stop;
+\t end
+\t if (cyc==4) begin
+\t i <= 128\'h45e0eb7642b148537491f3da147e7f26;
+\t if (q1 != 128\'hf45fc07e4fa8524cf9571425f17f9ad7) $stop;
+\t if (q1 != q32) $stop;
+\t if (q1 != q64) $stop;
+\t if (q1[63:0] != q64_low) $stop;
+\t end
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+`undefineall
+
+// Definitions as speced
+// Note there are trailing spaces, which spec doesn\'t show properly
+`define D(x,y) initial $display(""start"", x , y, ""end"");
+\'`D( ""msg1"" , ""msg2"" )\'
+\'initial $display(""start"", ""msg1"" , ""msg2"" , ""end"");\'
+\'`D( "" msg1"", )\'
+\'initial $display(""start"", "" msg1"" , , ""end"");\'
+\'`D(, ""msg2 "")\'
+\'initial $display(""start"", , ""msg2 "", ""end"");\'
+\'`D(,)\'
+\'initial $display(""start"", , , ""end"");\'
+\'`D( , )\'
+\'initial $display(""start"", , , ""end"");\'
+//`D(""msg1"") // ILLEGAL: only one argument
+//`D() // ILLEGAL: only one empty argument
+//`D(,,) // ILLEGAL: more actual than formal arguments
+
+// Defaults:
+`define MACRO1(a=5,b=""B"",c) $display(a,,b,,c);
+\'`MACRO1 ( , 2, 3 )\'
+\'$display(5,,2,,3);\'
+\'`MACRO1 ( 1 , , 3 )\'
+\'$display(1 ,,""B"",,3 );\'
+\'`MACRO1 ( , 2, )\'
+\'$display(5,,2,,);\'
+//`MACRO1 ( 1 ) // ILLEGAL: b and c omitted, no default for c
+
+`define MACRO2(a=5, b, c=""C"") $display(a,,b,,c);
+\'`MACRO2 (1, , 3)\'
+\'$display(5,,,,""C"");\'
+\'`MACRO2 (, 2, )\'
+\'$display(5,,2,,""C"");\'
+\'`MACRO2 (, 2)\'
+\'$display(5,,2,,""C"");\'
+
+`define MACRO3(a=5, b=0, c=""C"") $display(a,,b,,c);
+\'`MACRO3 ( 1 )\'
+\'$display(1 ,,0,,""C"");\'
+\'`MACRO3 ( )\'
+\'$display(5,,0,,""C"");\'
+//`MACRO3 // ILLEGAL: parentheses required
+
+`define DTOP(a,b) a + b
+\'`DTOP( `DTOP(b,1), `DTOP(42,a) )\'
+\'b + 1 + 42 + a\'
+
+// Local tests
+`define MACROQUOTE(a=""==)"",b=""(((("",c=() ) \'a b c\'
+`MACROQUOTE();
+\'""==)"" ""(((("" () \';
+
+// Also check our line counting doesn\'t go bad
+`define MACROPAREN(a=(6),
+\t\t b=(eq=al),
+\t\t c) \'a b c\'
+`MACROPAREN(
+
+
+
+\t ,,
+
+
+\t ZOT)
+HERE-`__LINE__ - Line71
+
+//======================================================================
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg [31:0] narrow;
+ reg [63:0] quad;
+ reg [127:0] wide;
+
+ integer cyc; initial cyc=0;
+ reg [7:0] crc;
+ reg [6:0] index;
+
+ always @ (posedge clk) begin
+ //$write(""[%0t] cyc==%0d crc=%b n=%x\
+"",$time, cyc, crc, narrow);
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+\t // Setup
+\t narrow <= 32\'h0;
+\t quad <= 64\'h0;
+\t wide <= 128\'h0;
+\t crc <= 8\'hed;
+\t index <= 7\'h0;
+ end
+ else if (cyc<90) begin
+\t index <= index + 7\'h2;
+\t crc <= {crc[6:0], ~^ {crc[7],crc[5],crc[4],crc[3]}};
+\t // verilator lint_off WIDTH
+\t if (index < 9\'d20) narrow[index +: 3] <= crc[2:0];
+\t if (index < 9\'d60) quad [index +: 3] <= crc[2:0];
+\t if (index < 9\'d120) wide [index +: 3] <= crc[2:0];
+\t //
+\t narrow[index[3:0]] <= ~narrow[index[3:0]];
+\t quad [~index[3:0]]<= ~quad [~index[3:0]];
+\t wide [~index[3:0]] <= ~wide [~index[3:0]];
+\t // verilator lint_on WIDTH
+ end
+ else if (cyc==90) begin
+\t wide[12 +: 4] <=4\'h6;\tquad[12 +: 4] <=4\'h6;\tnarrow[12 +: 4] <=4\'h6;
+\t wide[42 +: 4] <=4\'h6;\tquad[42 +: 4] <=4\'h6;
+\t wide[82 +: 4] <=4\'h6;
+ end
+ else if (cyc==91) begin
+\t wide[0] <=1\'b1;\tquad[0] <=1\'b1;\t\tnarrow[0] <=1\'b1;
+\t wide[41] <=1\'b1;\tquad[41] <=1\'b1;
+\t wide[81] <=1\'b1;
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%b n=%x q=%x w=%x\
+"",$time, cyc, crc, narrow, quad, wide);
+\t if (crc != 8\'b01111001) $stop;
+\t if (narrow != 32\'h001661c7) $stop;
+\t if (quad != 64\'h16d49b6f64266039) $stop;
+\t if (wide != 128\'h012fd26d265b266ff6d49b6f64266039) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t;
+ reg [175:0] hex [15:0];
+
+ initial begin
+ $readmemh(""t/t_sys_readmem_bad_addr.mem"", hex);
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+
+// bug477
+
+module t (
+ input rst_n,
+ input clk,
+ output out
+ );
+
+ submod #(.STAGES(5)) u2(.*);
+
+endmodule
+
+module submod (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ rst_n, clk
+ );
+
+ parameter STAGES = 4;
+
+ input rst_n;
+ input clk;
+ output out;
+
+ reg [STAGES-1:0] r_rst;
+
+ generate
+ // for i=0..5 (5+1-1)
+ for (genvar i=0; i= 0 ) begin
+ if ( ABS(last - period) > cmp ) begin
+\t range_chk = 1;
+ end
+ end
+ endfunction
+
+ function integer ceil;
+ input num;
+ real num;
+ if (num > $rtoi(num))
+\tceil = $rtoi(num) + 1;
+ else
+\t// verilator lint_off REALCVT
+\tceil = num;
+\t// verilator lint_on REALCVT
+ endfunction
+
+ initial begin
+ if (range_chk(-1.1, 2.2, 3.3) != 1\'b0) $stop;
+ if (range_chk(1.1, 2.2, 0.3) != 1\'b1) $stop;
+ if (range_chk(1.1, 2.2, 2.3) != 1\'b0) $stop;
+ if (range_chk(2.2, 1.1, 0.3) != 1\'b1) $stop;
+ if (range_chk(2.2, 1.1, 2.3) != 1\'b0) $stop;
+ if (ceil(-2.1) != -2) $stop;
+ if (ceil(2.1) != 3) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ //bug765; disappears if add this wire
+ //wire [7:0] a = (crc[7] ? {7\'b0,crc[0]} : crc[7:0]); // favor low values
+ wire [7:0] a = crc[7:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [15:0]\t\ty;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .y\t\t\t(y[15:0]),
+\t // Inputs
+\t .a\t\t\t(a[7:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {48\'h0, y};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h0
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ y,
+ // Inputs
+ a
+ );
+ input signed [7:0] a;
+ output [15:0] y;
+ // verilator lint_off WIDTH
+ assign y = ~66\'d0 <<< {4{a}};
+ // verilator lint_on WIDTH
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2010 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+`ifdef USE_VPI_NOT_DPI
+//We call it via $c so we can verify DPI isn\'t required - see bug572
+`else
+import ""DPI-C"" context function integer mon_check();
+`endif
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+`ifdef VERILATOR
+`systemc_header
+extern ""C"" int mon_check();
+`verilog
+`endif
+
+ input clk;
+
+ reg [31:0] mem0 [16:1] /*verilator public_flat_rw @(posedge clk) */;
+ integer \t i, status;
+
+ // Test loop
+ initial begin
+`ifdef VERILATOR
+ status = $c32(""mon_check()"");
+`endif
+`ifdef iverilog
+ status = $mon_check();
+`endif
+`ifndef USE_VPI_NOT_DPI
+ status = mon_check();
+`endif
+ if (status!=0) begin
+\t $write(""%%Error: t_vpi_var.cpp:%0d: C Test failed\
+"", status);
+\t $stop;
+ end
+ for (i = 16; i > 0; i--)
+\tif (mem0[i] !== i) begin
+ $write(""%%Error: %d : GOT = %d EXP = %d\
+"", i, mem0[i], i);
+\t status = 1;
+ end
+ if (status!=0) begin
+\t $write(""%%Error: t_vpi_var.cpp:%0d: C Test failed\
+"", status);
+\t $stop;
+ end
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule : t
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+
+module t;
+ // Test turning on and off a message on the same line; only middle reg shouldn\'t warn
+ reg [0:1] show1; /*verilator lint_off LITENDIAN*/ reg [0:2] ign2; /*verilator lint_on LITENDIAN*/ reg [0:3] show3;
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Test of select from constant
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t ();
+
+ sub #(.Z(0)) sub1 ();
+ sub #(.Z(1)) sub2 ();
+ sub #(.Z(2)) sub3 ();
+
+endmodule
+
+module sub;
+ parameter Z = 0;
+ wire [1:0] a = 2'b11;
+ wire [0:0] b = a;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Peter Debacker.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ reg [10:0] in;
+ reg signed[7:0] min;
+ reg signed[7:0] max;
+ wire signed[7:0] filtered_data;
+ reg signed[7:0] delay_minmax[31:0];
+ integer k;
+
+ initial begin
+ in = 11\'b10000001000;
+ for(k=0;k<32;k=k+1)
+ delay_minmax[k] = 0;
+ end
+
+ assign filtered_data = $signed(in[10:3]);
+
+ always @(posedge clk) begin
+ in = in + 8;
+`ifdef TEST_VERBOSE
+ $write(""filtered_data: %d\
+"", filtered_data);
+`endif
+ // delay line shift
+ for (k=31;k>0;k=k-1) begin
+\t delay_minmax[k] = delay_minmax[k-1];
+ end
+ delay_minmax[0] = filtered_data;
+`ifdef TEST_VERBOSE
+ $write(""delay_minmax[0] = %d\
+"", delay_minmax[0]);
+ $write(""delay_minmax[31] = %d\
+"", delay_minmax[31]);
+`endif
+ // find min and max
+ min = 127;
+ max = -128;
+`ifdef TEST_VERBOSE
+ $write(""max init: %d\
+"", max);
+ $write(""min init: %d\
+"", min);
+`endif
+ for(k=0;k<32;k=k+1) begin
+\t if ((delay_minmax[k]) > $signed(max))
+\t max = delay_minmax[k];
+\t if ((delay_minmax[k]) < $signed(min))
+\t min = delay_minmax[k];
+ end
+`ifdef TEST_VERBOSE
+ $write(""max: %d\
+"", max);
+ $write(""min: %d\
+"", min);
+`endif
+ if (min == 127) begin
+\t $stop;
+ end
+ else if (filtered_data >= -61) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Test of gated clock detection
+//
+// The code as shown generates a result by a delayed assignment from PC. The
+// creation of the result is from a clock gated from the clock that sets
+// PC. Howevever since they are essentially the same clock, the result should
+// be delayed by one cycle.
+//
+// Standard Verilator treats them as different clocks, so the result stays in
+// step with the PC. An event drive simulator always allows the clock to win.
+//
+// The problem is caused by the extra loop added by Verilator to the
+// evaluation of all internally generated clocks (effectively removed by
+// marking the clock enable).
+//
+// This test is added to facilitate experiments with solutions.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Jeremy Bennett .
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ reg gated_clk_en = 1\'b0 ;
+ reg [1:0] pc = 2\'b0;
+ reg [1:0] res = 2\'b0;
+
+ wire gated_clk = gated_clk_en & clk;
+
+ always @(posedge clk) begin
+ pc <= pc + 1;
+ gated_clk_en <= 1\'b1;
+ end
+
+ always @(posedge gated_clk) begin
+ res <= pc;
+ end
+
+ always @(posedge clk) begin
+ if (pc == 2\'b11) begin
+\t // Correct behaviour is that res should be lagging pc in the count
+\t // by one cycle
+\t if (res == 2\'b10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+\t else begin
+\t $stop;
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Alex Solomatnikov.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ logic [6-1:0] foo[4-1:0];
+
+ //initial $display(""%m: %p\
+"", foo);
+ //initial $display(""%m: %p\
+"", foo[3:0]); // VCS not supported %p with slice
+ //logic [6-1:0] foo2[4-1:0][5:6];
+ //initial $display(""%m: %p\
+"", foo2[3:0][5:6]); // This is not legal
+
+ dut #(.W(6),
+ .D(4)) udut(.clk(clk),
+ .foo(foo[4-1:0]));
+endmodule
+
+module dut
+ #(parameter W = 1,
+ parameter D = 1)
+ (input logic clk,
+ input logic [W-1:0] foo[D-1:0]);
+
+ genvar i, j;
+ generate
+ for (j = 0; j < D; j++) begin
+ for (i = 0; i < W; i++) begin
+ suba ua(.clk(clk), .foo(foo[j][i]));
+ end
+ end
+ endgenerate
+endmodule
+
+module suba
+ (input logic clk,
+ input logic foo);
+
+ always @(posedge clk) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t_case_huge_sub3 (/*AUTOARG*/
+ // Outputs
+ outr,
+ // Inputs
+ clk, index
+ );
+
+ input clk;
+ input [9:0] index;
+ output [3:0] outr;
+
+ // =============================
+ /*AUTOREG*/
+ // Beginning of automatic regs (for this module\'s undeclared outputs)
+ reg [3:0]\t\toutr;
+ // End of automatics
+
+ // =============================
+ // Created from perl
+ //for $i (0..255) { $r=rand(4); printf ""\\t8\'h%02x: begin outr <= outr^index[8:5]^4\'h%01x; end\
+"", $i,
+ //rand(256); };
+
+ // Reset cheating
+ initial outr = 4\'b0;
+
+ always @(posedge clk) begin
+ case (index[7:0])
+\t8\'h00: begin outr <= 4\'h0; end
+\t8\'h01: begin /*No Change*/ end
+\t8\'h02: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'h03: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h04: begin outr <= outr^index[8:5]^4\'hd; end
+\t8\'h05: begin outr <= outr^index[8:5]^4\'h1; end
+\t8\'h06: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'h07: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'h08: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'h09: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h0a: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'h0b: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'h0c: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'h0d: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'h0e: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'h0f: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'h10: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'h11: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'h12: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'h13: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'h14: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'h15: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'h16: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h17: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'h18: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'h19: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'h1a: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'h1b: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h1c: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'h1d: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'h1e: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'h1f: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h20: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'h21: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'h22: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'h23: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'h24: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'h25: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'h26: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h27: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'h28: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'h29: begin outr <= outr^index[8:5]^4\'h8; end
+\t8\'h2a: begin outr <= outr^index[8:5]^4\'h1; end
+\t8\'h2b: begin outr <= outr^index[8:5]^4\'h8; end
+\t8\'h2c: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h2d: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h2e: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'h2f: begin outr <= outr^index[8:5]^4\'h8; end
+\t8\'h30: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'h31: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h32: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'h33: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'h34: begin outr <= outr^index[8:5]^4\'h1; end
+\t8\'h35: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'h36: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h37: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'h38: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h39: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'h3a: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h3b: begin outr <= outr^index[8:5]^4\'h1; end
+\t8\'h3c: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'h3d: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'h3e: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'h3f: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'h40: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h41: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'h42: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'h43: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h44: begin outr <= outr^index[8:5]^4\'h8; end
+\t8\'h45: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'h46: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'h47: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'h48: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h49: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h4a: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'h4b: begin outr <= outr^index[8:5]^4\'hd; end
+\t8\'h4c: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'h4d: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'h4e: begin outr <= outr^index[8:5]^4\'hd; end
+\t8\'h4f: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h50: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'h51: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'h52: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'h53: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'h54: begin outr <= outr^index[8:5]^4\'h1; end
+\t8\'h55: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'h56: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'h57: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'h58: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'h59: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h5a: begin outr <= outr^index[8:5]^4\'hc; end
+\t8\'h5b: begin outr <= outr^index[8:5]^4\'hd; end
+\t8\'h5c: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'h5d: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'h5e: begin outr <= outr^index[8:5]^4\'hd; end
+\t8\'h5f: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h60: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h61: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'h62: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'h63: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'h64: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'h65: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h66: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'h67: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'h68: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h69: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h6a: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'h6b: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'h6c: begin outr <= outr^index[8:5]^4\'h8; end
+\t8\'h6d: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'h6e: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h6f: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'h70: begin outr <= outr^index[8:5]^4\'hc; end
+\t8\'h71: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'h72: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'h73: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'h74: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h75: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'h76: begin outr <= outr^index[8:5]^4\'h1; end
+\t8\'h77: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'h78: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'h79: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h7a: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'h7b: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'h7c: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'h7d: begin outr <= outr^index[8:5]^4\'hc; end
+\t8\'h7e: begin outr <= outr^index[8:5]^4\'hc; end
+\t8\'h7f: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'h80: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'h81: begin outr <= outr^index[8:5]^4\'hd; end
+\t8\'h82: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'h83: begin outr <= outr^index[8:5]^4\'hc; end
+\t8\'h84: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'h85: begin outr <= outr^index[8:5]^4\'h8; end
+\t8\'h86: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'h87: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'h88: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'h89: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'h8a: begin outr <= outr^index[8:5]^4\'h1; end
+\t8\'h8b: begin outr <= outr^index[8:5]^4\'h1; end
+\t8\'h8c: begin outr <= outr^index[8:5]^4\'hc; end
+\t8\'h8d: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'h8e: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'h8f: begin outr <= outr^index[8:5]^4\'hd; end
+\t8\'h90: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'h91: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'h92: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h93: begin outr <= outr^index[8:5]^4\'hc; end
+\t8\'h94: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'h95: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'h96: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'h97: begin outr <= outr^index[8:5]^4\'hc; end
+\t8\'h98: begin outr <= outr^index[8:5]^4\'hc; end
+\t8\'h99: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'h9a: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'h9b: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'h9c: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'h9d: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'h9e: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'h9f: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'ha0: begin outr <= outr^index[8:5]^4\'hc; end
+\t8\'ha1: begin outr <= outr^index[8:5]^4\'hc; end
+\t8\'ha2: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'ha3: begin outr <= outr^index[8:5]^4\'h1; end
+\t8\'ha4: begin outr <= outr^index[8:5]^4\'hd; end
+\t8\'ha5: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'ha6: begin outr <= outr^index[8:5]^4\'hc; end
+\t8\'ha7: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'ha8: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'ha9: begin outr <= outr^index[8:5]^4\'hd; end
+\t8\'haa: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'hab: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'hac: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'had: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'hae: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'haf: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'hb0: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'hb1: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'hb2: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'hb3: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'hb4: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'hb5: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'hb6: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'hb7: begin outr <= outr^index[8:5]^4\'h8; end
+\t8\'hb8: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'hb9: begin outr <= outr^index[8:5]^4\'hd; end
+\t8\'hba: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'hbb: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'hbc: begin outr <= outr^index[8:5]^4\'hd; end
+\t8\'hbd: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'hbe: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'hbf: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'hc0: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'hc1: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'hc2: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'hc3: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'hc4: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'hc5: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'hc6: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'hc7: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'hc8: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'hc9: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'hca: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'hcb: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'hcc: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'hcd: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'hce: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'hcf: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'hd0: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'hd1: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'hd2: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'hd3: begin outr <= outr^index[8:5]^4\'h8; end
+\t8\'hd4: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'hd5: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'hd6: begin outr <= outr^index[8:5]^4\'hb; end
+\t8\'hd7: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'hd8: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'hd9: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'hda: begin outr <= outr^index[8:5]^4\'h8; end
+\t8\'hdb: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'hdc: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'hdd: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'hde: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'hdf: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'he0: begin outr <= outr^index[8:5]^4\'h7; end
+\t8\'he1: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'he2: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'he3: begin outr <= outr^index[8:5]^4\'h3; end
+\t8\'he4: begin outr <= outr^index[8:5]^4\'h2; end
+\t8\'he5: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'he6: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'he7: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'he8: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'he9: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'hea: begin outr <= outr^index[8:5]^4\'hc; end
+\t8\'heb: begin outr <= outr^index[8:5]^4\'hd; end
+\t8\'hec: begin outr <= outr^index[8:5]^4\'h1; end
+\t8\'hed: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'hee: begin outr <= outr^index[8:5]^4\'h9; end
+\t8\'hef: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'hf0: begin outr <= outr^index[8:5]^4\'hd; end
+\t8\'hf1: begin outr <= outr^index[8:5]^4\'hf; end
+\t8\'hf2: begin outr <= outr^index[8:5]^4\'h4; end
+\t8\'hf3: begin outr <= outr^index[8:5]^4\'ha; end
+\t8\'hf4: begin outr <= outr^index[8:5]^4\'h8; end
+\t8\'hf5: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'hf6: begin outr <= outr^index[8:5]^4\'he; end
+\t8\'hf7: begin outr <= outr^index[8:5]^4\'h1; end
+\t8\'hf8: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'hf9: begin outr <= outr^index[8:5]^4\'h0; end
+\t8\'hfa: begin outr <= outr^index[8:5]^4\'h5; end
+\t8\'hfb: begin outr <= outr^index[8:5]^4\'h1; end
+\t8\'hfc: begin outr <= outr^index[8:5]^4\'h8; end
+\t8\'hfd: begin outr <= outr^index[8:5]^4\'h6; end
+\t8\'hfe: begin outr <= outr^index[8:5]^4\'h1; end
+\tdefault: begin outr <= outr^index[8:5]^4\'h6; end
+ endcase
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ /* verilator lint_off WIDTH */
+
+ input clk;
+
+ integer cyc; initial cyc = 0;
+ logic [31:0] arr_c; initial arr_c = 0;
+ logic [7:0] [3:0] arr;
+
+ logic [31:0] arr2_c; initial arr2_c = 0;
+ logic [7:0] [3:0] arr2;
+ assign arr2_c = arr2;
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ arr_c <= arr_c + 1;
+ arr2 <= arr2 + 1;
+`ifdef TEST_VERBOSE
+ $write(""cyc%0d c:%0x a0:%0x a1:%0x a2:%0x a3:%0x\
+"", cyc, arr_c, arr[0], arr[1], arr[2], arr[3]);
+`endif
+ if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+ /* verilator lint_on WIDTH */
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Jonathon Donaldson.
+
+module t
+ (
+ input \ti_clk,
+ input [6:0] \ti_input,
+ output logic o_output
+ );
+
+ always_ff @(posedge i_clk)
+ // verilator lint_off CASEINCOMPLETE
+ case (i_input)
+ 7\'(92+2),
+ 7\'(92+3): o_output <= 1\'b1;
+ endcase
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2009 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+module t ();
+
+ import ""DPI-C"" function int dpii_string(input string DSM_NAME);
+
+ generate
+ begin : DSM
+\t string SOME_STRING;
+ end
+ endgenerate
+
+ initial begin
+ $sformat(DSM.SOME_STRING, ""%m"");
+ if (dpii_string(DSM.SOME_STRING) != 5) $stop;
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2010 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+`ifdef VERILATOR
+//We call it via $c so we can verify DPI isn\'t required - see bug572
+`else
+import ""DPI-C"" context function integer mon_check();
+`endif
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+`ifdef VERILATOR
+`systemc_header
+extern ""C"" int mon_check();
+`verilog
+`endif
+
+ input clk;
+
+ reg\t\tonebit\t\t/*verilator public_flat_rw @(posedge clk) */;
+
+ integer \t status;
+
+ // Test loop
+ initial begin
+`ifdef VERILATOR
+ status = $c32(""mon_check()"");
+`else
+ status = mon_check();
+`endif
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule : t
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+//
+// Example module to create problem.
+//
+// generate a 64 bit value with bits
+// [HighMaskSel_Bot : LowMaskSel_Bot ] = 1
+// [HighMaskSel_Top+32: LowMaskSel_Top+32] = 1
+// all other bits zero.
+
+module t_math_imm2 (/*AUTOARG*/
+ // Outputs
+ LogicImm, LowLogicImm, HighLogicImm,
+ // Inputs
+ LowMaskSel_Top, HighMaskSel_Top, LowMaskSel_Bot, HighMaskSel_Bot
+ );
+ input [4:0] LowMaskSel_Top, HighMaskSel_Top;
+ input [4:0] \t LowMaskSel_Bot, HighMaskSel_Bot;
+ output [63:0] LogicImm;
+
+ output [63:0] LowLogicImm, HighLogicImm;
+
+ /* verilator lint_off UNSIGNED */
+ /* verilator lint_off CMPCONST */
+ genvar \t i;
+ generate
+ for (i=0;i<64;i=i+1) begin : MaskVal
+\t if (i >= 32) begin
+\t assign LowLogicImm[i] = (LowMaskSel_Top <= i[4:0]);
+\t assign HighLogicImm[i] = (HighMaskSel_Top >= i[4:0]);
+\t end
+\t else begin
+\t assign LowLogicImm[i] = (LowMaskSel_Bot <= i[4:0]);
+\t assign HighLogicImm[i] = (HighMaskSel_Bot >= i[4:0]);
+\t end
+ end
+ endgenerate
+
+ assign LogicImm = LowLogicImm & HighLogicImm;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t;
+
+ reg [31:0] lastrand;
+ reg [31:0] thisrand;
+
+ integer same = 0;
+ integer i;
+
+`define TRIES 20
+
+ initial begin
+ // There\'s a 1^32 chance of the numbers being the same twice,
+ // so we\'ll allow one failure
+ lastrand = $random;
+ for (i=0; i<`TRIES; i=i+1) begin
+\t thisrand = $random;
+`ifdef TEST_VERBOSE
+\t $write(""Random = %x\
+"", thisrand);
+`endif
+\t if (thisrand == lastrand) same=same+1;
+\t lastrand = thisrand;
+ end
+ if (same > 1) begin
+\t $write(""%%Error: Too many similar numbers: %d\
+"", same);
+\t $stop;
+ end
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t;
+ integer i;
+ generate
+ for (i=0; i<3; i=i+1) begin\t// Bad: i is not a genvar
+ end
+ endgenerate
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t;
+
+ reg [175:0] hex [15:0];
+
+ initial begin
+ $readmemh(""t/t_sys_readmem_bad_NOTFOUND.mem"", hex);
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+module t ();
+ initial begin
+ $stop;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Clifford Wolf.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+
+ wire [31:0] y;
+ reg \t a;
+ test004 sub (/*AUTOINST*/
+\t\t// Outputs
+\t\t.y\t\t\t(y[31:0]),
+\t\t// Inputs
+\t\t.a\t\t\t(a));
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d a=%x y=%x\
+"",$time, cyc, a, y);
+`endif
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+\t a <= 0;
+ end
+ else if (cyc==1) begin
+\t a <= 1;
+\t if (y != 32\'h0) $stop;
+ end
+ else if (cyc==2) begin
+\t if (y != 32\'h010000ff) $stop;
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module test004(a, y);
+ input a;
+ output [31:0] y;
+
+ wire [7:0] y0;
+ wire [7:0] y1;
+ wire [7:0] y2;
+ wire [7:0] y3;
+ assign y = {y0,y1,y2,y3};
+
+ localparam [7:0] v0 = +8\'sd1 ** -8\'sd2; //\'h01
+ localparam [7:0] v1 = +8\'sd2 ** -8\'sd2; //\'h00
+ localparam [7:0] v2 = -8\'sd2 ** -8\'sd3; //\'h00
+ localparam [7:0] v3 = -8\'sd1 ** -8\'sd3; //\'hff
+ localparam [7:0] zero = 0;
+
+ initial $display(""v0=%x v1=%x v2=%x v3=%x"", v0,v1,v2,v3);
+
+ assign y0 = a ? v0 : zero;
+ assign y1 = a ? v1 : zero;
+ assign y2 = a ? v2 : zero;
+ assign y3 = a ? v3 : zero;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t;
+
+ reg [175:0] hex [15:0];
+
+ integer i;
+
+ initial begin
+ $readmemh(""t/t_sys_readmem_bad_end.mem"", hex, 0, 15);
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ tri \t pad_io_h;
+ tri \t pad_io_l;
+
+ sub sub (.*);
+
+endmodule
+
+
+module sub (/*AUTOARG*/
+ // Inouts
+ pad_io_h, pad_io_l
+ );
+
+ parameter USE = 1'b1;
+ parameter DIFFERENTIAL = 1'b1;
+ parameter BIDIR = 1'b1;
+
+ inout pad_io_h;
+ inout pad_io_l;
+
+ wire [31:0] dqs_out_dtap_delay;
+
+ generate
+ if (USE) begin: output_strobe
+ wire aligned_os_oe;
+ wire aligned_strobe;
+
+ if (BIDIR) begin
+ reg sig_h_r = 1'b0;
+ reg sig_l_r = 1'b0;
+ always @* begin
+ sig_h_r = ~aligned_os_oe ? aligned_strobe : 1'bz;
+ if (DIFFERENTIAL)
+ sig_l_r = ~aligned_os_oe ? ~aligned_strobe : 1'bz;
+ end
+ assign pad_io_h = sig_h_r;
+ if (DIFFERENTIAL)
+ assign pad_io_l = sig_l_r;
+ end
+ end
+ endgenerate
+
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ parameter PAR = 3;
+ input clk;
+
+ defparam i.L00 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L01 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L02 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L03 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L04 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L05 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L06 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L07 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L08 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L09 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L0A = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L0B = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L0C = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L0D = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L0E = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L0F = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L10 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L11 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L12 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L13 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L14 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L15 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L16 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L17 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L18 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L19 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L1A = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L1B = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L1C = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L1D = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L1E = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L1F = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L20 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L21 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L22 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L23 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L24 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L25 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L26 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L27 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L28 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L29 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L2A = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L2B = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L2C = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L2D = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L2E = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L2F = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L30 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L31 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L32 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L33 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L34 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L35 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L36 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L37 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L38 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L39 = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L3A = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L3B = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L3C = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L3D = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L3E = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.L3F = 256\'h000012300000000000000000000000000000000000000000000000000000cdef;
+ defparam i.A0 = ""HELLO_WORLD_BOY_THIS_IS_LONG"";
+ defparam i.A1 = ""HELLO_WORLD_BOY_THIS_IS_LONG"";
+ defparam i.A2 = ""HELLO_WORLD_BOY_THIS_IS_LONG"";
+
+ i i (.clk(clk));
+
+ integer cyc=1;
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==1) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module i
+ (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ // verilator public_module
+
+ input clk;
+
+ parameter [255:0] L00 = 256\'h0;
+ parameter [255:0] L01 = 256\'h0;
+ parameter [255:0] L02 = 256\'h0;
+ parameter [255:0] L03 = 256\'h0;
+ parameter [255:0] L04 = 256\'h0;
+ parameter [255:0] L05 = 256\'h0;
+ parameter [255:0] L06 = 256\'h0;
+ parameter [255:0] L07 = 256\'h0;
+ parameter [255:0] L08 = 256\'h0;
+ parameter [255:0] L09 = 256\'h0;
+ parameter [255:0] L0A = 256\'h0;
+ parameter [255:0] L0B = 256\'h0;
+ parameter [255:0] L0C = 256\'h0;
+ parameter [255:0] L0D = 256\'h0;
+ parameter [255:0] L0E = 256\'h0;
+ parameter [255:0] L0F = 256\'h0;
+ parameter [255:0] L10 = 256\'h0;
+ parameter [255:0] L11 = 256\'h0;
+ parameter [255:0] L12 = 256\'h0;
+ parameter [255:0] L13 = 256\'h0;
+ parameter [255:0] L14 = 256\'h0;
+ parameter [255:0] L15 = 256\'h0;
+ parameter [255:0] L16 = 256\'h0;
+ parameter [255:0] L17 = 256\'h0;
+ parameter [255:0] L18 = 256\'h0;
+ parameter [255:0] L19 = 256\'h0;
+ parameter [255:0] L1A = 256\'h0;
+ parameter [255:0] L1B = 256\'h0;
+ parameter [255:0] L1C = 256\'h0;
+ parameter [255:0] L1D = 256\'h0;
+ parameter [255:0] L1E = 256\'h0;
+ parameter [255:0] L1F = 256\'h0;
+ parameter [255:0] L20 = 256\'h0;
+ parameter [255:0] L21 = 256\'h0;
+ parameter [255:0] L22 = 256\'h0;
+ parameter [255:0] L23 = 256\'h0;
+ parameter [255:0] L24 = 256\'h0;
+ parameter [255:0] L25 = 256\'h0;
+ parameter [255:0] L26 = 256\'h0;
+ parameter [255:0] L27 = 256\'h0;
+ parameter [255:0] L28 = 256\'h0;
+ parameter [255:0] L29 = 256\'h0;
+ parameter [255:0] L2A = 256\'h0;
+ parameter [255:0] L2B = 256\'h0;
+ parameter [255:0] L2C = 256\'h0;
+ parameter [255:0] L2D = 256\'h0;
+ parameter [255:0] L2E = 256\'h0;
+ parameter [255:0] L2F = 256\'h0;
+ parameter [255:0] L30 = 256\'h0;
+ parameter [255:0] L31 = 256\'h0;
+ parameter [255:0] L32 = 256\'h0;
+ parameter [255:0] L33 = 256\'h0;
+ parameter [255:0] L34 = 256\'h0;
+ parameter [255:0] L35 = 256\'h0;
+ parameter [255:0] L36 = 256\'h0;
+ parameter [255:0] L37 = 256\'h0;
+ parameter [255:0] L38 = 256\'h0;
+ parameter [255:0] L39 = 256\'h0;
+ parameter [255:0] L3A = 256\'h0;
+ parameter [255:0] L3B = 256\'h0;
+ parameter [255:0] L3C = 256\'h0;
+ parameter [255:0] L3D = 256\'h0;
+ parameter [255:0] L3E = 256\'h0;
+ parameter [255:0] L3F = 256\'h0;
+ parameter [255:0] A0 = 256\'h0;
+ parameter [255:0] A1 = 256\'h0;
+ parameter [255:0] A2 = 256\'h0;
+
+ always @ (posedge clk) begin
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [31:0] in = crc[31:0];
+
+ localparam WIDTH = 31;
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [WIDTH-1:0]\tb;\t\t\t// From test of Test.v
+ wire [WIDTH-1:0]\tc;\t\t\t// From test of Test.v
+ // End of automatics
+ reg \t\t\trst_l;
+
+ Test #(.WIDTH(WIDTH))
+ test (/*AUTOINST*/
+\t // Outputs
+\t .b\t\t\t\t(b[WIDTH-1:0]),
+\t .c\t\t\t\t(c[WIDTH-1:0]),
+\t // Inputs
+\t .clk\t\t\t\t(clk),
+\t .rst_l\t\t\t\t(rst_l),
+\t .in\t\t\t\t(in[WIDTH-1:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {1\'h0, c, 1\'b0, b};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+\t rst_l <= ~1\'b1;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+\t rst_l <= ~1\'b1;
+\t // Hold reset while summing
+ end
+ else if (cyc<20) begin
+\t rst_l <= ~1\'b0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'hbcfcebdb75ec9d32
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ b, c,
+ // Inputs
+ clk, rst_l, in
+ );
+
+ parameter WIDTH = 5;
+
+ input clk;
+ input \t\t rst_l;
+
+ input [WIDTH-1:0] \t in;
+ output wire [WIDTH-1:0] \tb;
+ output wire [WIDTH-1:0] \tc;
+
+ dff # ( .WIDTH\t(WIDTH),
+\t .RESET\t(\'0), // Although this is a single bit, the parameter must be the specified type
+\t .RESET_WIDTH (1) )
+ sub1
+ ( .clk(clk), .rst_l(rst_l), .q(b), .d(in) );
+
+ dff # ( .WIDTH\t(WIDTH),
+\t .RESET\t({ 1\'b1, {(WIDTH-1){1\'b0}} }),
+\t .RESET_WIDTH (WIDTH))
+ sub2
+ ( .clk(clk), .rst_l(rst_l), .q(c), .d(in) );
+
+endmodule
+
+module dff (/*AUTOARG*/
+ // Outputs
+ q,
+ // Inputs
+ clk, rst_l, d
+ );
+
+ parameter WIDTH = 1;
+ parameter RESET = {WIDTH{1\'b0}};
+ parameter RESET_WIDTH = WIDTH;
+
+ input clk;
+ input rst_l;
+ input [WIDTH-1:0] d;
+ output reg [WIDTH-1:0] q;
+
+ always_ff @(posedge clk or negedge rst_l) begin
+ if ($bits(RESET) != RESET_WIDTH) $stop;
+ // verilator lint_off WIDTH
+ if (~rst_l) q <= RESET;
+ // verilator lint_on WIDTH
+ else q <= d;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t;
+ // verilator lint_off PINMISSING
+`ifdef T_GEN_MISSING_BAD
+ foobar #(.FOO_TYPE(1)) foobar; // This means we should instatiate missing module
+`elsif T_GEN_MISSING
+ foobar #(.FOO_TYPE(0)) foobar; // This means we should instatiate foo0
+`else
+ `error ""Bad Test""
+`endif
+endmodule
+
+
+module foobar
+ #( parameter
+ FOO_START = 0,
+ FOO_NUM = 2,
+ FOO_TYPE = 1
+ )
+ (
+ input wire[FOO_NUM-1:0] foo,
+ output wire[FOO_NUM-1:0] bar);
+
+
+ generate
+ begin: g
+ genvar j;
+ for (j = FOO_START; j < FOO_NUM+FOO_START; j = j + 1)
+ begin: foo_inst;
+ if (FOO_TYPE == 0)
+ begin: foo_0
+ // instatiate foo0
+ foo0 i_foo(.x(foo[j]), .y(bar[j]));
+ end
+ if (FOO_TYPE == 1)
+ begin: foo_1
+ // instatiate foo1
+ foo_not_needed i_foo(.x(foo[j]), .y(bar[j]));
+ end
+ end
+ end
+ endgenerate
+endmodule
+
+
+
+module foo0(input wire x, output wire y);
+
+ assign y = ~x;
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ reg [2:0] in;
+
+
+ wire a,y,y_fixed;
+ wire b = in[0];
+ wire en = in[1];
+
+
+ pullup(a);
+
+ ChildA childa ( .A(a), .B(b), .en(en), .Y(y),.Yfix(y_fixed) );
+
+ initial in=0;
+ initial en=0;
+
+ // Test loop
+ always @ (posedge clk) begin
+
+
+ in <= in + 1;
+
+ $display ( ""a %d b %d en %d y %d yfix: %d)"" , a, b, en, y, y_fixed);
+ if (en) begin
+ // driving b
+ // a should be b
+ // y and yfix should also be b
+ if (a!=b || y != b || y_fixed != b) begin
+ $display ( ""Expected a %d y %b yfix %b"" , a, y, y_fixed);
+ $stop;
+ end
+
+ end else begin
+ // not driving b
+ // a should be 1 (pullup)
+ // y and yfix shold be 1
+ if (a!=1 || y != 1 || y_fixed != 1) begin
+ $display( ""Expected a,y,yfix == 1"");
+ $stop;
+ end
+ end
+
+ if (in==3) begin
+\t $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+ end
+endmodule
+
+module ChildA(inout A, input B, input en, output Y, output Yfix);
+
+ // workaround
+ wire a_in = A;
+
+ ChildB childB(.A(A), .Y(Y));
+ assign A = en ? B : 1\'bz;
+
+
+ ChildB childBfix(.A(a_in),.Y(Yfix));
+
+
+endmodule
+
+module ChildB(input A, output Y);
+ assign Y = A;
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Test:
+ tri \tt;
+ bufif1 (t, crc[1], cyc[1:0]==2\'b00);
+ bufif1 (t, crc[2], cyc[1:0]==2\'b10);
+
+ tri0 t0;
+ bufif1 (t0, crc[1], cyc[1:0]==2\'b00);
+ bufif1 (t0, crc[2], cyc[1:0]==2\'b10);
+
+ tri1 t1;
+ bufif1 (t1, crc[1], cyc[1:0]==2\'b00);
+ bufif1 (t1, crc[2], cyc[1:0]==2\'b10);
+
+ tri \tt2;
+ t_tri2 t_tri2 (.t2, .d(crc[1]), .oe(cyc[1:0]==2\'b00));
+ bufif1 (t2, crc[2], cyc[1:0]==2\'b10);
+
+ tri \tt3;
+ t_tri3 t_tri3 (.t3, .d(crc[1]), .oe(cyc[1:0]==2\'b00));
+ bufif1 (t3, crc[2], cyc[1:0]==2\'b10);
+
+ wire [63:0] \tresult = {51\'h0, t3, 3\'h0,t2, 3\'h0,t1, 3\'h0,t0};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h04f91df71371e950
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module t_tri2 (/*AUTOARG*/
+ // Outputs
+ t2,
+ // Inputs
+ d, oe
+ );
+ output t2;
+ input d;
+ input oe;
+ tri1 t2;
+ bufif1 (t2, d, oe);
+endmodule
+
+module t_tri3 (/*AUTOARG*/
+ // Outputs
+ t3,
+ // Inputs
+ d, oe
+ );
+ output tri1 t3;
+ input d;
+ input oe;
+ bufif1 (t3, d, oe);
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Jie Xu.
+
+module t
+ (
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc = 0;
+
+ reg a;
+ reg b;
+ reg z;
+ sub_t sub_t_i (z, a, b);
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ a <= cyc[0];
+ b <= cyc[1];
+
+ if (cyc > 10) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+ end
+endmodule
+
+primitive CINV (a, b);
+output b;
+input a;
+assign b = ~a;
+endprimitive
+
+
+module sub_t (z, x, y);
+input x, y;
+output z;
+
+assign z = x & y;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Use this file as a template for submitting bugs, etc.
+// This module takes a single clock input, and should either
+//\t$write(""*-* All Finished *-*\
+"");
+//\t$finish;
+// on success, or $stop.
+//
+// The code as shown applies a random vector to the Test
+// module, then calculates a CRC on the Test module\'s outputs.
+//
+// **If you do not wish for your code to be released to the public
+// please note it here, otherwise:**
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by ____YOUR_NAME_HERE____.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [31:0] in = crc[31:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [31:0] \t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[31:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(in[31:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {32\'h0, out};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= \'0;
+ end
+ else if (cyc<10) begin
+\t sum <= \'0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h4afe43fb79d7b71e
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ clk, in
+ );
+
+ // Replace this module with the device under test.
+ //
+ // Change the code in the t module to apply values to the inputs and
+ // merge the output values into the result vector.
+
+ input clk;
+ input [31:0] in;
+ output reg [31:0] out;
+
+ always @(posedge clk) begin
+ out <= in;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+// Very simple test for interface pathclearing
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc=1;
+
+ ifc #(2) itopa();
+ ifc #(4) itopb();
+
+ sub ca (.isub(itopa),
+\t .clk);
+ sub cb (.isub(itopb),
+\t .clk);
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d result=%b %b\
+"",$time, cyc, itopa.valueo, itopb.valueo);
+`endif
+ cyc <= cyc + 1;
+ itopa.valuei <= cyc[1:0];
+ itopb.valuei <= cyc[3:0];
+ if (cyc==1) begin
+\t if (itopa.WIDTH != 2) $stop;
+\t if (itopb.WIDTH != 4) $stop;
+\t if ($bits(itopa.valueo) != 2) $stop;
+\t if ($bits(itopb.valueo) != 4) $stop;
+\t if ($bits(itopa.out_modport.valueo) != 2) $stop;
+\t if ($bits(itopb.out_modport.valueo) != 4) $stop;
+ end
+ if (cyc==4) begin
+\t if (itopa.valueo != 2\'b11) $stop;
+\t if (itopb.valueo != 4\'b0011) $stop;
+ end
+ if (cyc==5) begin
+\t if (itopa.valueo != 2\'b00) $stop;
+\t if (itopb.valueo != 4\'b0100) $stop;
+ end
+ if (cyc==20) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+interface ifc
+ #(parameter WIDTH = 1);
+ // verilator lint_off MULTIDRIVEN
+ logic [WIDTH-1:0] valuei;
+ logic [WIDTH-1:0] valueo;
+ // verilator lint_on MULTIDRIVEN
+ modport out_modport (input valuei, output valueo);
+endinterface
+
+// Note not parameterized
+module sub
+ (
+ ifc.out_modport isub,
+ input clk
+ );
+ always @(posedge clk) isub.valueo <= isub.valuei + 1;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+program t;
+ parameter SIZE = 5;
+
+ typedef reg [SIZE-1:0] vec_t ;
+ vec_t a; initial a =0;
+
+ typedef bit [SIZE-1:0] vec_bit_t ;
+ vec_bit_t b; initial b =0;
+
+ typedef int array [3];
+ typedef array array2 [2];
+ array2 ar [1];
+
+ // Define before use
+ // Not sure how well supported this is elsewhere
+ //UNSUP typedef preuse;
+ //UNSUP preuse p;
+ //UNSUP typedef int preuse;
+
+//reg [SIZE-1:0] a; initial a =0;
+//reg [SIZE-1:0] b; initial b =0;
+
+ initial begin
+ typedef logic [3:0][7:0] instr_mem_t;
+ instr_mem_t a;
+ a[0] = 8\'h12;
+ if (a[0] != 8\'h12) $stop;
+ end
+
+ integer j;
+ initial begin
+ for (j=0;j<=(1<0) begin : generate_if_if
+ always @ (posedge clk)
+ vld_if <= 1\'b1;
+ end : generate_if_if
+ else begin : generate_if_else
+ always @ (posedge clk)
+ vld_else <= 1\'b1;
+ end : generate_if_else
+ endgenerate
+
+endmodule : t
+"
+"// DESCRIPTION: Verilator: System Verilog test of array querying functions.
+//
+// This code instantiates a module that calls the various array querying
+// functions.
+//
+// This file ONLY is placed into the Public Domain, for any use, without
+// warranty.
+
+// Contributed 2012 by Jeremy Bennett, Embecosm.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ wire a = clk;
+ wire b = 1\'b0;
+ reg c;
+
+ array_test array_test_i (/*AUTOINST*/
+\t\t\t // Inputs
+\t\t\t .clk\t\t(clk));
+
+endmodule
+
+
+// Check the array sizing functions work correctly.
+module array_test
+
+ #( parameter
+ LEFT = 5,
+ RIGHT = 55)
+
+ (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // verilator lint_off LITENDIAN
+ reg [7:0] a [LEFT:RIGHT];
+ // verilator lint_on LITENDIAN
+
+ integer l;
+ integer r;
+ integer s;
+
+ always @(posedge clk) begin
+ l = $left (a);
+ r = $right (a);
+ s = $size (a);
+
+`ifdef TEST_VERBOSE
+ $write (""$left (a) = %d, $right (a) = %d, $size (a) = %d\
+"", l, r, s);
+`endif
+
+ if ((l != LEFT) || (r != RIGHT) || (s != (RIGHT - LEFT + 1))) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t;
+
+ //Several simulators don\'t support this.
+ //typedef struct pack2;\t// Forward declaration
+
+ typedef struct packed { // [3:0]
+ bit\tb3;
+ bit\tb2;
+ bit\tb1;
+ bit\tb0;
+ } b4_t;
+
+ typedef struct packed { // [3:0]
+ b4_t\tx1;
+ b4_t\tx0;
+ } b4x2_t;
+
+ typedef union packed { // [3:0]
+ bit [3:0]\tquad0;
+ b4_t\tquad1;
+ } q4_t;
+
+ typedef struct packed { // [5:0]
+ bit\tmsb;
+ q4_t\tfour;
+ bit\tlsb;
+ } pack2_t;
+
+ typedef union packed { // [5:0]
+ pack2_t\tpack2;
+ bit [6:1] pvec;
+ // Vector not allowed in packed structure, per spec:
+ // bit\tvec[6];
+ // bit \tvec2d[2][3];
+ } pack3_t;
+
+ const b4_t b4_const_a = \'{1\'b1, 1\'b0, 1\'b0, 1\'b1};
+
+ // Cast to a pattern - note bits are tagged out of order
+ const b4_t b4_const_b = b4_t\'{ b1 : 1\'b0, b0 : 1\'b1, b3 : 1\'b1, b2 : 1\'b0 };
+
+ wire b4_t b4_wire;
+ assign b4_wire = \'{1\'b1, 1\'b0, 1\'b1, 1\'b0};
+
+ pack2_t arr[2];
+
+ initial begin
+ pack3_t tsu;
+ tsu = 6\'b110110;
+ // 543210
+ if (tsu!=6\'b110110) $stop;
+ if (tsu[5:4]!=2\'b11) $stop;
+ if (tsu[5:4] == tsu[1:0]) $stop; // Not a good extraction test if LSB subtraction doesn\'t matter
+ if (tsu.pvec!=6\'b110110) $stop;
+ if (tsu.pvec[6:5]!=2\'b11) $stop;
+ if (tsu.pack2[5:1] != 5\'b11011) $stop;
+ if (tsu.pack2.msb != 1\'b1) $stop;
+ if (tsu.pack2.lsb != 1\'b0) $stop;
+ if (tsu.pack2.four.quad0 != 4\'b1011) $stop;
+ if (tsu.pack2.four.quad1.b0 != 1\'b1) $stop;
+ if (tsu.pack2.four.quad1.b1 != 1\'b1) $stop;
+ if (tsu.pack2.four.quad1.b2 != 1\'b0) $stop;
+ if (tsu.pack2.four.quad1.b3 != 1\'b1) $stop;
+ //
+ tsu = 1\'b0 ? \'0 : \'{pvec: 6\'b101011};
+ if (tsu!=6\'b101011) $stop;
+ //
+ arr[0] = 6\'b101010;
+ arr[1] = 6\'b010101;
+ if (arr[0].four !== 4\'b0101) $stop;
+ if (arr[1].four !== 4\'b1010) $stop;
+ //
+ // Initialization
+ begin
+\t b4_t q = \'{1\'b1, 1\'b1, 1\'b0, 1\'b0};
+\t if (q != 4\'b1100) $stop;
+ end
+ begin
+\t b4_t q = \'{3{1\'b1}, 1\'b0};
+\t if (q != 4\'b1110) $stop;
+ end
+ begin
+\t b4_t q = \'{4{1\'b1}};\t// Repeats the {}
+\t if (q != 4\'b1111) $stop;
+ end
+ begin
+\t b4x2_t m = \'{4\'b1001, \'{1\'b1, 1\'b0, 1\'b1, 1\'b1}};
+\t if (m != 8\'b10011011) $stop;
+ end
+ begin
+\t b4_t q = \'{default:1\'b1};
+\t if (q != 4\'b1111) $stop;
+ end
+ begin
+\t b4_t q = \'{b0:1\'b1, b2:1\'b1, b3:1\'b1, b1:1\'b0};
+\t if (q != 4\'b1101) $stop;
+ end
+ begin
+\t b4_t q = \'{b2:1\'b0, default:1\'b1};
+\t if (q != 4\'b1011) $stop;
+ end
+
+ if (b4_const_a != 4\'b1001) $stop;
+ if (b4_const_b != 4\'b1001) $stop;
+ if (b4_wire != 4\'b1010) $stop;
+ if (pat(4\'b1100, 4\'b1100)) $stop;
+ if (pat(\'{1\'b1, 1\'b0, 1\'b1, 1\'b1}, 4\'b1011)) $stop;
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ function pat(b4_t in, logic [3:0] cmp);
+ if (in !== cmp) $stop;
+ pat = 1\'b0;
+ endfunction
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module a;
+ c c ();
+ initial begin
+ $write(""Bad top modules\
+"");
+ $stop;
+ end
+endmodule
+
+module b;
+ d d ();
+endmodule
+
+module c;
+ initial begin
+ $write(""Bad top modules\
+"");
+ $stop;
+ end
+endmodule
+
+module d;
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [31:0] in = crc[31:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [71:0]\t\tmuxed;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .muxed\t\t\t(muxed[71:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(in[31:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {muxed[63:0]};
+
+ wire [5:0] width_check = cyc[5:0] + 1;
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h20050a66e7b253d1
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ muxed,
+ // Inputs
+ clk, in
+ );
+ input clk;
+ input [31:0] in;
+ output [71:0] muxed;
+
+ wire [71:0] \t a = {in[7:0],~in[31:0],in[31:0]};
+ wire [71:0] \t b = {~in[7:0],in[31:0],~in[31:0]};
+
+ /*AUTOWIRE*/
+ Muxer muxer (
+\t\t.sa\t(0),
+\t\t.sb\t(in[0]),
+\t\t/*AUTOINST*/
+\t\t// Outputs
+\t\t.muxed\t\t\t(muxed[71:0]),
+\t\t// Inputs
+\t\t.a\t\t\t(a[71:0]),
+\t\t.b\t\t\t(b[71:0]));
+endmodule
+
+module Muxer (/*AUTOARG*/
+ // Outputs
+ muxed,
+ // Inputs
+ sa, sb, a, b
+ );
+ input \t sa;
+ input \t sb;
+
+ output wire [71:0] \t muxed;
+ input [71:0] a;
+ input [71:0] b;
+
+ // Constification wasn\'t sizing with inlining and gave
+ // unsized error on below
+ // v
+ assign\tmuxed = (({72{sa}} & a)
+\t\t\t | ({72{sb}} & b));
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t;
+
+ // Speced ignored: system calls. I think this is nasty, so we error instead.
+
+ // Speced Illegal: inout/output/ref not allowed
+ localparam B1 = f_bad_output(1,2);
+ function integer f_bad_output(input [31:0] a, output [31:0] o);
+ f_bad_output = 0;
+ endfunction
+
+ // Speced Illegal: void
+
+ // Speced Illegal: dotted
+ localparam EIGHT = 8;
+ localparam B2 = f_bad_dotted(2);
+ function integer f_bad_dotted(input [31:0] a);
+ f_bad_dotted = t.EIGHT;
+ endfunction
+
+ // Speced Illegal: ref to non-local var
+ integer modvar;
+ localparam B3 = f_bad_nonparam(3);
+ function integer f_bad_nonparam(input [31:0] a);
+ f_bad_nonparam = modvar;
+ endfunction
+
+ // Speced Illegal: needs constant function itself
+
+ // Our own - infinite loop
+ localparam B4 = f_bad_infinite(3);
+ function integer f_bad_infinite(input [31:0] a);
+ while (1) begin
+\t f_bad_infinite = 0;
+ end
+ endfunction
+
+ // Our own - stop
+ localparam BSTOP = f_bad_stop(3);
+ function integer f_bad_stop(input [31:0] a);
+ $stop;
+ endfunction
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t;
+ t_lint_declfilename sub ();
+endmodule
+
+module t_lint_declfilename;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t;
+
+ integer p_i;
+
+ initial begin
+ // BAD: Missing argument
+ if ($value$plusargs(""NOTTHERE"", p_i)!==0) $stop;
+
+ // BAD: Bad letter
+ if ($value$plusargs(""INT=%z"", p_i)!==0) $stop;
+
+ // BAD: Multi letter
+ if ($value$plusargs(""INT=%x%x"", p_i)!==0) $stop;
+
+ $stop;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module library_cell(a);
+ input [`WIDTH-1:0] a;
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2009 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+module t ();
+
+ // Can\'t handle logic (yet?)
+ import ""DPI-C"" function int \\badly.named (int i);
+
+ initial begin
+ $stop;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use.
+
+// bug541
+module t(clk,odata);
+ input clk;
+ output [7:0] odata;
+ paramtest_DFFRE #(1) dffre0(clk,odata[7]);
+ paramtest_WRAP #(7) dffe0(clk,odata[6:0]);
+endmodule
+
+module paramtest_WRAP(clk,q);
+ parameter W=1;
+ input clk;
+ output [W-1:0] q;
+ paramtest_DFFRE #(W) dffre0(clk,q);
+endmodule
+
+module paramtest_DFFRE(clk,q);
+ parameter W=1;
+ parameter [W-1:0] INIT={W{1'b0}};
+ input clk;
+ output [W-1:0] q;
+ reg [W-1:0] \t q;
+ always @(posedge clk) begin
+ q <= INIT;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ wire [7:0] bitout;
+ reg [7:0] allbits;
+ reg [7:0] onebit;
+ reg [8:0] onebitbad; // Wrongly sized
+
+ sub sub [7:0] (allbits, onebitbad, bitout);
+
+ // This is ok.
+ wire [9:8] b;
+ wire [1:0] c;
+ sub sub2 [9:8] (allbits,b,c);
+
+endmodule
+
+module sub (input [7:0] allbits, input onebit, output bitout);
+ wire bitout = onebit ^ (^ allbits);
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg [255:0] \t\ta;
+ reg [60:0] \t\tdivisor;
+ reg [60:0] \t\tqq;
+ reg [60:0] \t\trq;
+ reg signed [60:0] \tqqs;
+ reg signed [60:0] \trqs;
+
+ always @* begin
+ qq = a[60:0] / divisor;
+ rq = a[60:0] % divisor;
+ qqs = $signed(a[60:0]) / $signed(divisor);
+ rqs = $signed(a[60:0]) % $signed(divisor);
+ end
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t //$write(""%d: %x %x %x %x\
+"", cyc, qq, rq, qqs, rqs);
+\t if (cyc==1) begin
+\t a <= 256\'hed388e646c843d35de489bab2413d77045e0eb7642b148537491f3da147e7f26;
+\t divisor <= 61\'h12371;
+\t a[60] <= 1\'b0; divisor[60] <= 1\'b0; // Unsigned
+\t end
+\t if (cyc==2) begin
+\t a <= 256\'h0e17c88f3d5fe51a982646c8e2bd68c3e236ddfddddbdad20a48e039c9f395b8;
+\t divisor <= 61\'h1238123771;
+\t a[60] <= 1\'b0; divisor[60] <= 1\'b0; // Unsigned
+\t if (qq!==61\'h00000403ad81c0da) $stop;
+\t if (rq!==61\'h00000000000090ec) $stop;
+\t if (qqs!==61\'h00000403ad81c0da) $stop;
+\t if (rqs!==61\'h00000000000090ec) $stop;
+\t end
+\t if (cyc==3) begin
+\t a <= 256\'h0e17c88f00d5fe51a982646c8002bd68c3e236ddfd00ddbdad20a48e00f395b8;
+\t divisor <= 61\'hf1b;
+\t a[60] <= 1\'b1; divisor[60] <= 1\'b0; // Signed
+\t if (qq!==61\'h000000000090832e) $stop;
+\t if (rq!==61\'h0000000334becc6a) $stop;
+\t if (qqs!==61\'h000000000090832e) $stop;
+\t if (rqs!==61\'h0000000334becc6a) $stop;
+\t end
+\t if (cyc==4) begin
+\t a[60] <= 1\'b0; divisor[60] <= 1\'b1; // Signed
+\t if (qq!==61\'h0001eda37cca1be8) $stop;
+\t if (rq!==61\'h0000000000000c40) $stop;
+\t if (qqs!==61\'h1fffcf5187c76510) $stop;
+\t if (rqs!==61\'h1ffffffffffffd08) $stop;
+\t end
+\t if (cyc==5) begin
+\t a[60] <= 1\'b1; divisor[60] <= 1\'b1; // Signed
+\t if (qq!==61\'h0000000000000000) $stop;
+\t if (rq!==61\'h0d20a48e00f395b8) $stop;
+\t if (qqs!==61\'h0000000000000000) $stop;
+\t if (rqs!==61\'h0d20a48e00f395b8) $stop;
+\t end
+\t if (cyc==6) begin
+\t if (qq!==61\'h0000000000000001) $stop;
+\t if (rq!==61\'h0d20a48e00f3869d) $stop;
+\t if (qqs!==61\'h0000000000000000) $stop;
+\t if (rqs!==61\'h1d20a48e00f395b8) $stop;
+\t end
+\t // Div by zero
+\t if (cyc==9) begin
+\t divisor <= 61\'d0;
+\t end
+\t if (cyc==10) begin
+`ifdef verilator
+\t if (qq !== {61{1\'b0}}) $stop;
+\t if (rq !== {61{1\'b0}}) $stop;
+`else
+\t if (qq !== {61{1\'bx}}) $stop;
+\t if (rq !== {61{1\'bx}}) $stop;
+`endif
+\t if ({16{1\'bx}} !== 16\'d1/16\'d0) $stop; // No div by zero errors
+\t if ({16{1\'bx}} !== 16\'d1%16\'d0) $stop; // No div by zero errors
+\t end
+\t if (cyc==19) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005-2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ parameter [200:0] MIXED = 32'dx_1;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test for generate IF constants
+//
+// The given generate loop should have a constant expression as argument. This
+// test checks it really does evaluate as constant.
+
+// This file ONLY is placed into the Public Domain, for any use, without
+// warranty, 2012 by Jeremy Bennett.
+
+
+`define MAX_SIZE 4
+
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ // Set the parameters, so that we use a size less than MAX_SIZE
+ test_gen
+ #(.SIZE (2),
+ .MASK (4\'b1111))
+ i_test_gen (.clk (clk));
+
+ // This is only a compilation test, but for good measure we do one clock
+ // cycle.
+ integer count;
+
+ initial begin
+ count = 0;
+ end
+
+ always @(posedge clk) begin
+ if (count == 1) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ else begin
+\t count = count + 1;
+ end
+ end
+
+endmodule // t
+
+
+module test_gen
+
+ #( parameter
+ SIZE = `MAX_SIZE,
+ MASK = `MAX_SIZE\'b0)
+
+ (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // Generate blocks that rely on short-circuiting of the logic to avoid
+ // errors.
+ generate
+ if ((SIZE < 8\'h04) && MASK[0]) begin
+\t always @(posedge clk) begin
+`ifdef TEST_VERBOSE
+\t $write (""Generate IF MASK[0] = %d\
+"", MASK[0]);
+`endif
+\t end
+ end
+ endgenerate
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg [39:0] con1,con2, con3;
+ reg [31:0] w32;
+ reg [31:0] v32 [2];
+
+ // surefire lint_off UDDSCN
+ reg [200:0] conw3, conw4;
+ // surefire lint_on UDDSCN
+
+ reg [16*8-1:0] con__ascii;
+
+ reg [31:0] win;
+ // Test casting is proper on narrow->wide->narrow conversions
+ // verilator lint_off WIDTH
+ wire [49:0] \t wider = ({18\'h0, win} | (1\'b1<<32)) - 50\'h111;
+ wire [31:0] \t wider2 = ({win} | (1\'b1<<32)) - 50\'d111;
+ // verilator lint_on WIDTH
+ wire [31:0] \t narrow = wider[31:0];
+ wire [31:0] \t narrow2 = wider2[31:0];
+
+ // surefire lint_off ASWEMB
+ // surefire lint_off ASWCMB
+ // surefire lint_off CWECBB
+ // surefire lint_off CWECSB
+
+ // surefire lint_off STMINI
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t $write(""[%0t] t_const: Running\
+"",$time);
+
+\t con1 = 4_0\'h1000_0010;\t// Odd but legal _ in width
+\t con2 = 40\'h10_0000_0010;
+\t con3 = con1 + 40\'h10_1100_0101;
+\t if (con1[31:0]!== 32\'h1000_0010 || con1[39:32]!==0) $stop;
+\t $display(""%x %x %x\
+"", con2, con2[31:0], con2[39:32]);
+\t if (con2[31:0]!== 32\'h10 || con2[39:32]!==8\'h10) $stop;
+\t if (con3[31:0]!==32\'h2100_0111 || con3[39:32]!==8\'h10) $stop;
+
+\t // verilator lint_off WIDTH
+\t con1 = 10\'h10 + 40\'h80_1100_0131;
+\t // verilator lint_on WIDTH
+\t con2 = 40\'h80_0000_0000 + 40\'h13_7543_0107;
+\t if (con1[31:0]!== 32\'h1100_0141 || con1[39:32]!==8\'h80) $stop;
+\t if (con2[31:0]!== 32\'h7543_0107 || con2[39:32]!==8\'h93) $stop;
+
+\t // verilator lint_off WIDTH
+ conw3 = 94\'h000a_5010_4020_3030_2040_1050;
+\t // verilator lint_on WIDTH
+\t if (conw3[31:00]!== 32\'h2040_1050 ||
+\t\tconw3[63:32]!== 32\'h4020_3030 ||
+\t\tconw3[95:64]!== 32\'h000a_5010 ||
+\t\tconw3[128:96]!==33\'h0) $stop;
+\t $display(""%x... %x\
+"", conw3[15:0], ~| conw3[15:0]);
+\t if ((~| conw3[15:0]) !== 1\'h0) $stop;
+\t if ((~& conw3[15:0]) !== 1\'h1) $stop;
+
+\t // verilator lint_off WIDTH
+ conw4 = 112\'h7010_602a_5030_4040_3050_2060_1070;
+\t // verilator lint_on WIDTH
+\t if (conw4[31:00]!== 32\'h2060_1070 ||
+\t\tconw4[63:32]!== 32\'h4040_3050 ||
+\t\tconw4[95:64]!== 32\'h602a_5030 ||
+\t\tconw4[127:96]!==32\'h7010) $stop;
+ // conw4 = 144\'h7000_7000_7010_602a_5030_4040_3050_2060_1070;
+
+\t w32 = 12;
+\t win <= 12;
+\t if ((32\'hffff0000 >> w32) != 32\'h 000ffff0) $stop;
+
+\t con__ascii = ""abcdefghijklmnop"";
+\t if ( con__ascii !== {""abcd"",""efgh"",""ijkl"",""mnop""}) $stop;
+\t con__ascii = ""abcdefghijklm"";
+\t if ( con__ascii !== {24\'h0,""a"",""bcde"",""fghi"",""jklm""}) $stop;
+
+\t if ( 3\'dx !== 3\'hx) $stop;
+
+\t // Wide decimal
+\t if ( 94\'d12345678901234567890123456789 != 94\'h27e41b3246bec9b16e398115) $stop;
+\t if (-94\'sd123456789012345678901234567 != 94\'h3f99e1020ea70d57d360b479) $stop;
+
+\t // Increments
+\t w32 = 12; w32++; if (w32 != 13) $stop;
+\t w32 = 12; ++w32; if (w32 != 13) $stop;
+\t w32 = 12; w32--; if (w32 != 11) $stop;
+\t w32 = 12; --w32; if (w32 != 11) $stop;
+\t w32 = 12; w32 += 2; if (w32 != 14) $stop;
+\t w32 = 12; w32 -= 2; if (w32 != 10) $stop;
+\t w32 = 12; w32 *= 2; if (w32 != 24) $stop;
+\t w32 = 12; w32 /= 2; if (w32 != 6) $stop;
+\t w32 = 12; w32 &= 6; if (w32 != 4) $stop;
+\t w32 = 12; w32 |= 15; if (w32 != 15) $stop;
+\t w32 = 12; w32 ^= 15; if (w32 != 3) $stop;
+\t w32 = 12; w32 >>= 1; if (w32 != 6) $stop;
+\t w32 = 12; w32 <<= 1; if (w32 != 24) $stop;
+
+\t // Increments
+\t v32[1] = 12; v32[1]++; if (v32[1] != 13) $stop;
+\t v32[1] = 12; ++v32[1]; if (v32[1] != 13) $stop;
+\t v32[1] = 12; v32[1]--; if (v32[1] != 11) $stop;
+\t v32[1] = 12; --v32[1]; if (v32[1] != 11) $stop;
+\t v32[1] = 12; v32[1] += 2; if (v32[1] != 14) $stop;
+\t v32[1] = 12; v32[1] -= 2; if (v32[1] != 10) $stop;
+\t v32[1] = 12; v32[1] *= 2; if (v32[1] != 24) $stop;
+\t v32[1] = 12; v32[1] /= 2; if (v32[1] != 6) $stop;
+\t v32[1] = 12; v32[1] &= 6; if (v32[1] != 4) $stop;
+\t v32[1] = 12; v32[1] |= 15; if (v32[1] != 15) $stop;
+\t v32[1] = 12; v32[1] ^= 15; if (v32[1] != 3) $stop;
+\t v32[1] = 12; v32[1] >>= 1; if (v32[1] != 6) $stop;
+\t v32[1] = 12; v32[1] <<= 1; if (v32[1] != 24) $stop;
+\t end
+\t if (cyc==2) begin
+\t win <= 32\'h123123;
+\t if (narrow !== 32\'hfffffefb) $stop;
+\t if (narrow2 !== 32\'hffffff9d) $stop;
+\t end
+\t if (cyc==3) begin
+\t if (narrow !== 32\'h00123012) $stop;
+\t if (narrow2 !== 32\'h001230b4) $stop;
+\t end
+\t if (cyc==10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+interface ifc;
+ integer ok;
+ integer bad;
+ modport out_modport (output ok);
+endinterface
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc=1;
+
+ ifc itop();
+
+ counter_ansi c1 (.isub(itop),
+\t\t .i_value(4'h4));
+
+endmodule
+
+module counter_ansi
+ (
+ ifc.out_modport isub,
+ input logic [3:0] i_value
+ );
+
+ always @* begin
+ isub.ok = i_value;
+ isub.bad = i_value; // Illegal access
+ end
+endmodule
+"
+"module t (/*AUTOARG*/
+ // Inputs
+ clk, reset_l
+ );
+
+ input\tclk;
+ input\treset_l;
+
+ reg \t\tinmod;
+
+ generate
+ if (1) begin
+\t // Traces as genblk1.ingen
+\t integer ingen;
+\t initial $display(""ingen: {mod}.genblk1 %m"");
+ end
+ endgenerate
+
+ integer \t rawmod;
+
+ initial begin
+ begin
+\t integer upa;
+\t begin : d3nameda
+\t // %m=\'.d3nameda\' var=_unnamed#.d3nameda.b1
+\t integer d3a;
+\t $display(""d3a: {mod}.d3nameda %m"");
+\t end
+ end
+ end
+ initial begin
+ integer b2;
+ $display(""b2: {mod} %m"");
+ begin : b3named
+\t integer b3n;
+\t $display(""b3n: {mod}.b3named: %m"");
+ end
+ if (1) begin
+\t integer b3;
+\t $display(""b3: {mod} %m"");
+\t if (1) begin
+\t begin
+\t begin
+\t\t begin
+\t\t integer b4;
+\t\t $display(""b4: {mod} %m"");
+\t\t end
+\t end
+\t end
+\t end
+\t else begin
+\t integer b4;
+\t $display(""bb %m"");
+\t end
+ end
+ else begin
+\t integer b4;
+\t $display(""b4 %m"");
+ end
+ tsk;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ task tsk;
+ integer t1;
+ $display(""t1 {mod}.tsk %m"");
+ begin
+\t integer t2;
+\t $display(""t2 {mod}.tsk %m"");
+ end
+ endtask
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+
+
+ reg [31:0] r32;
+ wire [3:0] w4;
+ wire [4:0] w5;
+
+ assign w4 = NUMONES_8 ( r32[7:0] );
+ assign w5 = NUMONES_16( r32[15:0] );
+
+ function [3:0] NUMONES_8;
+ input [7:0] i8;
+ reg [7:0] i8;
+ begin
+ NUMONES_8 = 4\'b1;
+ end
+ endfunction // NUMONES_8
+
+ function [4:0] NUMONES_16;
+ input [15:0] i16;
+ reg [15:0] i16;
+ begin
+ NUMONES_16 = ( NUMONES_8( i16[7:0] ) + NUMONES_8( i16[15:8] ));
+ end
+ endfunction
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t r32 <= 32\'h12345678;
+\t end
+\t if (cyc==2) begin
+\t if (w4 !== 1) $stop;
+\t if (w5 !== 2) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+// Try inline config
+`ifdef verilator
+ `verilator_config
+ lint_off -msg CASEX -file ""t/t_vlt_warn.v""
+ `verilog
+`endif
+
+
+
+
+
+module t;
+ reg width_warn_var_line18 = 2\'b11; // Width warning - must be line 18
+ reg width_warn2_var_line19 = 2\'b11; // Width warning - must be line 19
+ reg width_warn3_var_line20 = 2\'b11; // Width warning - must be line 20
+
+ initial begin
+ casex (1\'b1)
+\t1\'b0: $stop;
+ endcase
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [4095:0] crc;
+
+ // Test loop
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ crc <= {crc[4094:0], crc[63]^crc[2]^crc[0]}; // not a good crc :)
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 4096\'h9f51804b5275c7b6ab9907144a58649bb778f9718062fa5c336fcc9edcad7cf17aad0a656244017bb21d9f97f7c0c147b6fa7488bb9d5bb8d3635b20fba1deab597121c502b21f49b18da998852d29a6b2b649315a3323a31e7e5f41e9bbb7e44046467438f37694857b963250bdb137a922cfce2af1defd1f93db5aa167f316d751bb274bda96fdee5e2c6eb21886633246b165341f0594c27697b06b62b1ad05ebe3c08909a54272de651296dcdd3d1774fc432d22210d8f6afa50b02cf23336f8cc3a0a2ebfd1a3a60366a1b66ef346e0379116d68caa01279ac2772d1f3cd76d2cbbc68ada6f83ec2441b2679b405486df8aa734ea1729b40c3f82210e8e42823eb3fd6ca77ee19f285741c4e8bac1ab7855c3138e84b6da1d897bbe37faf2d0256ad2f7ff9e704a63d824c1e97bddce990cae1578f9537ae2328d0afd69ffb317cbcf859696736e45e5c628b44727557c535a7d02c07907f2dccd6a21ca9ae9e1dbb1a135a8ebc2e0aa8c7329b898d02896273defe21beaa348e11165b71c48cf1c09714942a5a2ddc2adcb6e42c0f630117ee21205677d5128e8efc18c9a6f82a8475541fd722cca2dd829b7e78fef89dbeab63ab7b849910eb4fe675656c4b42b9452c81a4ca6296190a81dc63e6adfaa31995d7dfe3438ee9df66488d6cf569380569ffe6e5ea313d23af6ff08d979af29374ee9aff1fa143df238a1;
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x%x%x%x\
+"",$time, cyc, crc[4095:3072], crc[2071:2048], crc[2047:1024], crc[1023:0]);
+\t $write(""[%0t] cyc==%0d crc=%b%b%b%b\
+"",$time, cyc, crc[4095:3072], crc[2071:2048], crc[2047:1024], crc[1023:0]);
+\t //Unsupported: $write(""[%0t] cyc==%0d crc=%x\
+"",$time, cyc, crc);
+\t if (crc != 4096\'h2961926edde3e5c6018be970cdbf327b72b5f3c5eab42995891005eec8767e5fdf03051edbe9d222ee756ee34d8d6c83ee877aad65c487140ac87d26c636a66214b4a69acad924c568cc8e8c79f97d07a6eedf91011919d0e3cdda5215ee58c942f6c4dea48b3f38abc77bf47e4f6d6a859fcc5b5d46ec9d2f6a5bf7b978b1bac862198cc91ac594d07c165309da5ec1ad8ac6b417af8f0224269509cb79944a5b7374f45dd3f10cb48884363dabe942c0b3c8ccdbe330e828baff468e980d9a86d9bbcd1b80de445b5a32a8049e6b09dcb47cf35db4b2ef1a2b69be0fb09106c99e6d01521b7e2a9cd3a85ca6d030fe08843a390a08facff5b29dfb867ca15d0713a2eb06ade1570c4e3a12db687625eef8dfebcb4095ab4bdffe79c1298f609307a5ef773a6432b855e3e54deb88ca342bf5a7fecc5f2f3e165a59cdb9179718a2d11c9d55f14d69f40b01e41fcb7335a8872a6ba7876ec684d6a3af0b82aa31cca6e26340a2589cf7bf886faa8d23844596dc71233c7025c5250a968b770ab72db90b03d8c045fb8848159df544a3a3bf063269be0aa11d5507f5c8b328b760a6df9e3fbe276faad8eadee126443ad3f99d595b12d0ae514b20693298a58642a07718f9ab7ea8c66575f7f8d0e3ba77d992235b3d5a4e015a7ff9b97a8c4f48ebdbfc2365e6bca4dd3ba6bfc7e850f7c8e2842c717a1d85a977a033f564fc
+\t ) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ parameter PAR = 3;
+
+ wire [31:0] o1a,o1b;
+
+ m1 #(0) m1a(.o(o1a));
+ m1 #(1) m1b(.o(o1b));
+
+ always @ (posedge clk) begin
+ if (o1a != 8) $stop;
+ if (o1b != 4) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+
+module m1 (output wire [31:0] o);
+ parameter W = 0;
+ generate
+ if (W == 0) begin
+ m2 m2 (.o(o));
+\t defparam m2.PAR2 = 8;
+ end
+ else begin
+ m2 m2 (.o(o));
+\t defparam m2.PAR2 = 4;
+ end
+ endgenerate
+endmodule
+
+module m2 (output wire [31:0] o);
+ parameter PAR2 = 10;
+ assign o = PAR2;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2009 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+module t;
+
+ sub a (.inst(1));
+ sub b (.inst(2));
+
+ // Returns integer line number, or -1 for all ok
+ import ""DPI-C"" context function int dpix_run_tests();
+
+ export ""DPI-C"" task dpix_t_int;
+ task dpix_t_int(input int i, output int o); o = ~i; endtask
+
+ export ""DPI-C"" dpix_t_renamed = task dpix_t_ren;
+ task dpix_t_ren(input int i, output int o); o = i+2; endtask
+
+ export ""DPI-C"" function dpix_int123;
+ function int\tdpix_int123(); dpix_int123 = 32\'h123; endfunction
+
+ export ""DPI-C"" function dpix_f_bit;
+ export ""DPI-C"" function dpix_f_bit15;
+ export ""DPI-C"" function dpix_f_int;
+ export ""DPI-C"" function dpix_f_byte;
+ export ""DPI-C"" function dpix_f_shortint;
+ export ""DPI-C"" function dpix_f_longint;
+ export ""DPI-C"" function dpix_f_chandle;
+
+ function bit\t\tdpix_f_bit (bit\t i); dpix_f_bit = ~i; endfunction
+ function bit [14:0]\tdpix_f_bit15 (bit [14:0] i); dpix_f_bit15 = ~i; endfunction
+ function int\t\tdpix_f_int (int\t i); dpix_f_int = ~i; endfunction
+ function byte\tdpix_f_byte (byte\t i); dpix_f_byte = ~i; endfunction
+ function shortint\tdpix_f_shortint(shortint i); dpix_f_shortint = ~i; endfunction
+ function longint\tdpix_f_longint (longint\t i); dpix_f_longint = ~i; endfunction
+ function chandle\tdpix_f_chandle (chandle\t i); dpix_f_chandle = i; endfunction
+
+ export ""DPI-C"" task dpix_t_bit95;
+ task dpix_t_bit95(input bit [94:0] i, output bit [94:0] o); o = ~i; endtask
+ export ""DPI-C"" task dpix_t_bit96;
+ task dpix_t_bit96(input bit [95:0] i, output bit [95:0] o); o = ~i; endtask
+
+ int lineno;
+
+ initial begin
+ lineno = dpix_run_tests();
+ if (lineno != -1) begin
+\t $display(""[%0t] %%Error: t_dpix_ort_c.c:%0d: dpix_run_tests returned an error"", $time, lineno);
+\t $stop;
+ end
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+module sub (input int inst);
+
+ export ""DPI-C"" function dpix_sub_inst;
+
+ function int\tdpix_sub_inst (int i); dpix_sub_inst = inst + i; endfunction
+
+endmodule
+"
+"// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Lane Brooks
+
+module top (input A, input OE, output X, output Y, output Z);
+
+ pullup p1(Z);
+ assign Z = OE ? A : 1'bz;
+
+ pulldown p2(Y);
+ assign Y = OE ? A : 1'bz;
+
+ pass pass(.A(A), .OE(OE), .X(X));
+ pullup_module p(X);
+endmodule
+
+module pass (input A, input OE, inout X);
+ io io(.A(A), .OE(OE), .X(X));
+endmodule
+
+module io (input A, input OE, inout X);
+ assign X = (OE) ? A : 1'bz;
+endmodule
+
+module pullup_module (output X);
+ pullup p1(X);
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t // New number format
+\t if (\'0 !== {66{1\'b0}}) $stop;
+\t if (\'1 !== {66{1\'b1}}) $stop;
+\t if (\'x !== {66{1\'bx}}) $stop;
+\t if (\'z !== {66{1\'bz}}) $stop;
+`ifndef NC\t// NC-Verilog 5.50-s09 chokes on this test
+\t if (""\\v"" != 8\'d11) $stop;
+\t if (""\\f"" != 8\'d12) $stop;
+\t if (""\\a"" != 8\'d7) $stop;
+\t if (""\\x9a"" != 8\'h9a) $stop;
+\t if (""\\xf1"" != 8\'hf1) $stop;
+`endif
+\t end
+\t if (cyc==8) begin
+\t end
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Ed Lander.
+
+// verilator lint_off WIDTH
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ reg [7:0] p1;
+ reg [7:0] \t p2;
+ reg [7:0] \t p3;
+
+ initial begin
+ p1 = 8\'h01;
+ p2 = 8\'h02;
+ p3 = 8\'h03;
+ end
+
+ parameter int param1 = 8\'h11;
+ parameter int param2 = 8\'h12;
+ parameter int param3 = 8\'h13;
+
+ targetmod i_targetmod (/*AUTOINST*/
+\t\t\t // Inputs
+\t\t\t .clk\t\t\t(clk));
+
+ //Binding i_targetmod to mycheck --instantiates i_mycheck inside i_targetmod
+ //param1 not over-riden (as mycheck)\t\t\t(=> 0x31)
+ //param2 explicitly bound to targetmod value\t(=> 0x22)
+ //param3 explicitly bound to top value\t\t\t(=> 0x13)
+ //p1 implictly bound (.*), takes value from targetmod\t(=> 0x04)
+ //p2 explictly bound to targetmod\t\t\t\t\t\t(=> 0x05)
+ //p3 explictly bound to top\t\t\t\t\t\t\t\t(=> 0x03)
+
+ // Alternative unsupported form is i_targetmod
+ bind targetmod mycheck
+ #(
+ .param2(param2),
+ .param3(param3)
+ )
+ i_mycheck (.p2(p2), .p3(p3), .*);
+
+endmodule
+
+module targetmod (input clk);
+ reg\t[7:0] p1;
+ reg [7:0] p2;
+ reg [7:0] p3;
+
+ parameter int param1 = 8\'h21;
+ parameter int param2 = 8\'h22;
+ parameter int param3 = 8\'h23;
+
+ initial begin
+ p1 = 8\'h04;
+ p2 = 8\'h05;
+ p3 = 8\'h06;
+ end
+endmodule
+
+module mycheck (/*AUTOARG*/
+ // Inputs
+ clk, p1, p2, p3
+ );
+
+ input clk;
+ input [7:0] p1;
+ input [7:0] p2;
+ input [7:0] p3;
+
+ parameter int param1 = 8\'h31;
+ parameter int param2 = 8\'h32;
+ parameter int param3 = 8\'h33;
+
+ always @ (posedge clk) begin
+ `checkh(param1,8\'h31);
+ `checkh(param2,8\'h22);
+ `checkh(param3,8\'h23);
+ `checkh(p1,8\'h04);
+ `checkh(p2,8\'h05);
+ `checkh(p3,8\'h06);
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
+`define checks(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\\""%s\\"" exp=\\""%s\\""\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+
+ reg [4*8:1] \tvstr;
+ const string s = ""a""; // Check static assignment
+ string \ts2;
+ string \ts3;
+ reg\t\teq;
+
+ // Operators == != < <= > >= {a,b} {a{b}} a[b]
+ // a.len, a.putc, a.getc, a.toupper, a.tolower, a.compare, a.icompare, a.substr
+ // a.atoi, a.atohex, a.atooct, a.atobin, a.atoreal,
+ // a.itoa, a.hextoa, a.octoa, a.bintoa, a.realtoa
+
+ initial begin
+ $sformat(vstr, ""s=%s"", s);
+ `checks(vstr, ""s=a"");
+ `checks(s, ""a"");
+ `checks({s,s,s}, ""aaa"");
+ `checks({4{s}}, ""aaaa"");
+ // Constification
+ `checkh(s == ""a"", 1\'b1);
+ `checkh(s == ""b"", 1\'b0);
+ `checkh(s != ""a"", 1\'b0);
+ `checkh(s != ""b"", 1\'b1);
+ `checkh(s > "" "", 1\'b1);
+ `checkh(s > ""a"", 1\'b0);
+ `checkh(s >= ""a"", 1\'b1);
+ `checkh(s >= ""b"", 1\'b0);
+ `checkh(s < ""a"", 1\'b0);
+ `checkh(s < ""b"", 1\'b1);
+ `checkh(s <= "" "", 1\'b0);
+ `checkh(s <= ""a"", 1\'b1);
+ end
+
+ // Test loop
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+\t // Setup
+\t s2 = ""c0"";
+ end
+ else if (cyc==1) begin
+\t $sformat(vstr, ""s2%s"", s2);
+\t `checks(vstr, ""s2c0"");
+ end
+ else if (cyc==2) begin
+\t s3 = s2;
+\t $sformat(vstr, ""s2%s"", s3);
+\t `checks(vstr, ""s2c0"");
+ end
+ else if (cyc==3) begin
+\t s2 = ""a"";
+\t s3 = ""b"";
+ end
+ else if (cyc==4) begin
+\t `checks({s2,s3}, ""ab"");
+\t `checks({3{s3}}, ""bbb"");
+\t `checkh(s == ""a"", 1\'b1);
+\t `checkh(s == ""b"", 1\'b0);
+\t `checkh(s != ""a"", 1\'b0);
+\t `checkh(s != ""b"", 1\'b1);
+\t `checkh(s > "" "", 1\'b1);
+\t `checkh(s > ""a"", 1\'b0);
+\t `checkh(s >= ""a"", 1\'b1);
+\t `checkh(s >= ""b"", 1\'b0);
+\t `checkh(s < ""a"", 1\'b0);
+\t `checkh(s < ""b"", 1\'b1);
+\t `checkh(s <= "" "", 1\'b0);
+\t `checkh(s <= ""a"", 1\'b1);
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc = 0;
+
+ covlabel:
+ cover property (@(posedge clk) cyc==5);
+ covlabel: // Error: Duplicate block_identifier
+ cover property (@(posedge clk) cyc==5);
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+`include ""/dev/null""
+
+module t;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2010 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+`ifdef USE_VPI_NOT_DPI
+//We call it via $c so we can verify DPI isn\'t required - see bug572
+`else
+import ""DPI-C"" context function integer mon_check();
+`endif
+
+module t (/*AUTOARG*/
+ // Inputs
+ input clk \t/*verilator public_flat_rd\t\t */,
+
+ // test ports
+ input [15:0] \ttestin \t/*verilator public_flat_rd\t\t */,
+ output [23:0] \ttestout \t/*verilator public_flat_rw @(posedge clk) */
+
+ );
+
+`ifdef VERILATOR
+`systemc_header
+extern ""C"" int mon_check();
+`verilog
+`endif
+
+ reg\t\tonebit\t\t/*verilator public_flat_rw @(posedge clk) */;
+ reg [2:1]\ttwoone\t\t/*verilator public_flat_rw @(posedge clk) */;
+ reg \tonetwo [1:2]\t/*verilator public_flat_rw @(posedge clk) */;
+ reg [2:1] \tfourthreetwoone[4:3] /*verilator public_flat_rw @(posedge clk) */;
+
+ integer status;
+
+`ifdef iverilog
+ // stop icarus optimizing signals away
+ wire \tredundant = onebit | onetwo[1] | twoone | fourthreetwoone[3];
+`endif
+
+ wire subin /*verilator public_flat_rd*/;
+ wire subout /*verilator public_flat_rd*/;
+ sub sub(.*);
+
+ // Test loop
+ initial begin
+`ifdef VERILATOR
+ status = $c32(""mon_check()"");
+`endif
+`ifdef iverilog
+ status = $mon_check();
+`endif
+`ifndef USE_VPI_NOT_DPI
+ status = mon_check();
+`endif
+ if (status!=0) begin
+\t $write(""%%Error: t_vpi_var.cpp:%0d: C Test failed\
+"", status);
+\t $stop;
+ end
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule : t
+
+module sub (
+ input subin /*verilator public_flat_rd*/,
+ output subout /*verilator public_flat_rd*/
+);
+endmodule : sub
+"
+"// DESCRIPTION: Verilator: Test generate index usage.
+//
+// The code illustrates a problem in Verilator\'s handling of constant
+// expressions inside generate indexes.
+//
+// This is a regression test against issue 517.
+//
+// **If you do not wish for your code to be released to the public
+// please note it here, otherwise:**
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Jeremy Bennett.
+
+
+`define START 8
+`define SIZE 4
+`define END (`START + `SIZE)
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ reg [`END-1:0] y;
+ wire [`END-1:0] x;
+
+ foo foo_i (.y (y),
+\t .x (x),
+\t .clk (clk));
+
+ always @(posedge clk) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule // t
+
+
+module foo(output wire [`END-1:0] y,
+\t input wire [`END-1:0] x,
+\t input wire \t\t clk);
+
+ function peek_bar;
+ peek_bar = bar_inst[`START].i_bar.r; // this is ok
+ peek_bar = bar_inst[`START + 1].i_bar.r; // this fails, should not.
+ endfunction
+
+ genvar g;
+ generate
+ for (g = `START; g < `END; g = g + 1) begin: bar_inst
+ bar i_bar(.x (x[g]),
+\t\t .y (y[g]),
+\t\t .clk (clk));
+ end
+ endgenerate
+
+endmodule : foo
+
+
+module bar(output wire y,
+\t input wire x,
+\t input wire clk);
+
+ reg r = 0;
+ assign y = r;
+
+ always @(posedge clk) begin
+ r = x ? ~x : y;
+ end
+
+endmodule : bar
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Iztok Jeras.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ // parameters for array sizes
+ localparam WA = 8; // address dimension size
+ localparam WB = 8; // bit dimension size
+
+ localparam NO = 10; // number of access events
+
+ // 2D packed arrays
+ logic [WA-1:0] [WB-1:0] array_bg; // big endian array
+ /* verilator lint_off LITENDIAN */
+ logic [0:WA-1] [0:WB-1] array_lt; // little endian array
+ /* verilator lint_on LITENDIAN */
+
+ integer cnt = 0;
+
+ // msg926
+ logic [3:0][31:0] packedArray;
+ initial packedArray <= \'0;
+
+ // event counter
+ always @ (posedge clk) begin
+ cnt <= cnt + 1;
+ end
+
+ // finish report
+ always @ (posedge clk)
+ if ((cnt[30:2]==NO) && (cnt[1:0]==2\'d0)) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ // big endian
+ always @ (posedge clk)
+ if (cnt[1:0]==2\'d0) begin
+ // initialize to defaaults (all bits to 0)
+ if (cnt[30:2]==0) array_bg <= \'0;
+ else if (cnt[30:2]==1) array_bg <= \'0;
+ else if (cnt[30:2]==2) array_bg <= \'0;
+ else if (cnt[30:2]==3) array_bg <= \'0;
+ else if (cnt[30:2]==4) array_bg <= \'0;
+ else if (cnt[30:2]==5) array_bg <= \'0;
+ else if (cnt[30:2]==6) array_bg <= \'0;
+ else if (cnt[30:2]==7) array_bg <= \'0;
+ else if (cnt[30:2]==8) array_bg <= \'0;
+ else if (cnt[30:2]==9) array_bg <= \'0;
+ end else if (cnt[1:0]==2\'d1) begin
+ // write value to array
+ if (cnt[30:2]==0) begin end
+ else if (cnt[30:2]==1) array_bg <= {WA *WB +0{1\'b1}};
+ else if (cnt[30:2]==2) array_bg [WA/2-1:0 ] <= {WA/2*WB +0{1\'b1}};
+ else if (cnt[30:2]==3) array_bg [WA -1:WA/2] <= {WA/2*WB +0{1\'b1}};
+ else if (cnt[30:2]==4) array_bg [ 0 ] <= {1 *WB +0{1\'b1}};
+ else if (cnt[30:2]==5) array_bg [WA -1 ] <= {1 *WB +0{1\'b1}};
+ else if (cnt[30:2]==6) array_bg [ 0 ][WB/2-1:0 ] <= {1 *WB/2+0{1\'b1}};
+ else if (cnt[30:2]==7) array_bg [WA -1 ][WB -1:WB/2] <= {1 *WB/2+0{1\'b1}};
+ else if (cnt[30:2]==8) array_bg [ 0 ][ 0 ] <= {1 *1 +0{1\'b1}};
+ else if (cnt[30:2]==9) array_bg [WA -1 ][WB -1 ] <= {1 *1 +0{1\'b1}};
+ end else if (cnt[1:0]==2\'d2) begin
+ // check array value
+ if (cnt[30:2]==0) begin if (array_bg !== 64\'b0000000000000000000000000000000000000000000000000000000000000000) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]==1) begin if (array_bg !== 64\'b1111111111111111111111111111111111111111111111111111111111111111) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]==2) begin if (array_bg !== 64\'b0000000000000000000000000000000011111111111111111111111111111111) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]==3) begin if (array_bg !== 64\'b1111111111111111111111111111111100000000000000000000000000000000) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]==4) begin if (array_bg !== 64\'b0000000000000000000000000000000000000000000000000000000011111111) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]==5) begin if (array_bg !== 64\'b1111111100000000000000000000000000000000000000000000000000000000) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]==6) begin if (array_bg !== 64\'b0000000000000000000000000000000000000000000000000000000000001111) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]==7) begin if (array_bg !== 64\'b1111000000000000000000000000000000000000000000000000000000000000) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]==8) begin if (array_bg !== 64\'b0000000000000000000000000000000000000000000000000000000000000001) begin $display(""%b"", array_bg); $stop(); end end
+ else if (cnt[30:2]==9) begin if (array_bg !== 64\'b1000000000000000000000000000000000000000000000000000000000000000) begin $display(""%b"", array_bg); $stop(); end end
+ end else if (cnt[1:0]==2\'d3) begin
+ // read value from array (not a very good test for now)
+ if (cnt[30:2]==0) begin if (array_bg !== {WA *WB {1\'b0}}) $stop(); end
+ else if (cnt[30:2]==1) begin if (array_bg !== {WA *WB +0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==2) begin if (array_bg [WA/2-1:0 ] !== {WA/2*WB +0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==3) begin if (array_bg [WA -1:WA/2] !== {WA/2*WB +0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==4) begin if (array_bg [ 0 ] !== {1 *WB +0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==5) begin if (array_bg [WA -1 ] !== {1 *WB +0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==6) begin if (array_bg [ 0 ][WB/2-1:0 ] !== {1 *WB/2+0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==7) begin if (array_bg [WA -1 ][WB -1:WB/2] !== {1 *WB/2+0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==8) begin if (array_bg [ 0 ][ 0 ] !== {1 *1 +0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==9) begin if (array_bg [WA -1 ][WB -1 ] !== {1 *1 +0{1\'b1}}) $stop(); end
+ end
+
+ // little endian
+ always @ (posedge clk)
+ if (cnt[1:0]==2\'d0) begin
+ // initialize to defaaults (all bits to 0)
+ if (cnt[30:2]==0) array_lt <= \'0;
+ else if (cnt[30:2]==1) array_lt <= \'0;
+ else if (cnt[30:2]==2) array_lt <= \'0;
+ else if (cnt[30:2]==3) array_lt <= \'0;
+ else if (cnt[30:2]==4) array_lt <= \'0;
+ else if (cnt[30:2]==5) array_lt <= \'0;
+ else if (cnt[30:2]==6) array_lt <= \'0;
+ else if (cnt[30:2]==7) array_lt <= \'0;
+ else if (cnt[30:2]==8) array_lt <= \'0;
+ else if (cnt[30:2]==9) array_lt <= \'0;
+ end else if (cnt[1:0]==2\'d1) begin
+ // write value to array
+ if (cnt[30:2]==0) begin end
+ else if (cnt[30:2]==1) array_lt <= {WA *WB +0{1\'b1}};
+ else if (cnt[30:2]==2) array_lt [0 :WA/2-1] <= {WA/2*WB +0{1\'b1}};
+ else if (cnt[30:2]==3) array_lt [WA/2:WA -1] <= {WA/2*WB +0{1\'b1}};
+ else if (cnt[30:2]==4) array_lt [0 ] <= {1 *WB +0{1\'b1}};
+ else if (cnt[30:2]==5) array_lt [ WA -1] <= {1 *WB +0{1\'b1}};
+ else if (cnt[30:2]==6) array_lt [0 ][0 :WB/2-1] <= {1 *WB/2+0{1\'b1}};
+ else if (cnt[30:2]==7) array_lt [ WA -1][WB/2:WB -1] <= {1 *WB/2+0{1\'b1}};
+ else if (cnt[30:2]==8) array_lt [0 ][0 ] <= {1 *1 +0{1\'b1}};
+ else if (cnt[30:2]==9) array_lt [ WA -1][ WB -1] <= {1 *1 +0{1\'b1}};
+ end else if (cnt[1:0]==2\'d2) begin
+ // check array value
+ if (cnt[30:2]==0) begin if (array_lt !== 64\'b0000000000000000000000000000000000000000000000000000000000000000) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]==1) begin if (array_lt !== 64\'b1111111111111111111111111111111111111111111111111111111111111111) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]==2) begin if (array_lt !== 64\'b1111111111111111111111111111111100000000000000000000000000000000) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]==3) begin if (array_lt !== 64\'b0000000000000000000000000000000011111111111111111111111111111111) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]==4) begin if (array_lt !== 64\'b1111111100000000000000000000000000000000000000000000000000000000) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]==5) begin if (array_lt !== 64\'b0000000000000000000000000000000000000000000000000000000011111111) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]==6) begin if (array_lt !== 64\'b1111000000000000000000000000000000000000000000000000000000000000) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]==7) begin if (array_lt !== 64\'b0000000000000000000000000000000000000000000000000000000000001111) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]==8) begin if (array_lt !== 64\'b1000000000000000000000000000000000000000000000000000000000000000) begin $display(""%b"", array_lt); $stop(); end end
+ else if (cnt[30:2]==9) begin if (array_lt !== 64\'b0000000000000000000000000000000000000000000000000000000000000001) begin $display(""%b"", array_lt); $stop(); end end
+ end else if (cnt[1:0]==2\'d3) begin
+ // read value from array (not a very good test for now)
+ if (cnt[30:2]==0) begin if (array_lt !== {WA *WB {1\'b0}}) $stop(); end
+ else if (cnt[30:2]==1) begin if (array_lt !== {WA *WB +0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==2) begin if (array_lt [0 :WA/2-1] !== {WA/2*WB +0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==3) begin if (array_lt [WA/2:WA -1] !== {WA/2*WB +0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==4) begin if (array_lt [0 ] !== {1 *WB +0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==5) begin if (array_lt [ WA -1] !== {1 *WB +0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==6) begin if (array_lt [0 ][0 :WB/2-1] !== {1 *WB/2+0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==7) begin if (array_lt [ WA -1][WB/2:WB -1] !== {1 *WB/2+0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==8) begin if (array_lt [0 ][0 ] !== {1 *1 +0{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==9) begin if (array_lt [ WA -1][ WB -1] !== {1 *1 +0{1\'b1}}) $stop(); end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ value
+ );
+ input [3:0] value;
+ always @ (/*AS*/value) begin
+ case (value)
+\tdefault: $stop;
+\t4'd0000: $stop;
+\tdefault: $stop;
+ endcase
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2009 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+`ifdef VCS
+ `define NO_SHORTREAL
+`endif
+`ifdef NC
+ `define NO_SHORTREAL
+`endif
+`ifdef VERILATOR // Unsupported
+ `define NO_SHORTREAL
+`endif
+
+module t (/*AUTOARG*/);
+
+ // Note these are NOT pure.
+ import ""DPI-C"" function int dpii_clear ();
+ import ""DPI-C"" function int dpii_count (input int ctr);
+ import ""DPI-C"" function bit dpii_inc0 (input int ctr);
+ import ""DPI-C"" function bit dpii_inc1 (input int ctr);
+ import ""DPI-C"" function bit dpii_incx (input int ctr, input bit value);
+
+ integer i;
+ integer j;
+ bit \t b;
+ integer errors;
+
+ task check1(integer line, bit got, bit ex);
+ if (got != ex) begin
+\t $display(""%%Error: Line %0d: Bad result, got=%0d expect=%0d"",line,got,ex);
+\t errors++;
+ end
+ endtask
+ task check(integer line, int got, int ex);
+ if (got != ex) begin
+\t $display(""%%Error: Line %0d: Bad result, got=%0d expect=%0d"",line,got,ex);
+\t errors++;
+ end
+ endtask
+
+ // Test loop
+ initial begin
+ // Spec says && || -> and ?: short circuit, no others do.
+ // Check both constant & non constants.
+ dpii_clear();
+ check1(`__LINE__, (1\'b0 && dpii_inc0(0)), 1\'b0);
+ check1(`__LINE__, (1\'b1 && dpii_inc0(1)), 1\'b0);
+ check1(`__LINE__, (dpii_inc0(2) && dpii_inc0(3)), 1\'b0);
+ check1(`__LINE__, (dpii_inc1(4) && dpii_inc0(5)), 1\'b0);
+ check1(`__LINE__, (dpii_inc0(6) && dpii_inc1(7)), 1\'b0);
+ check1(`__LINE__, (!(dpii_inc1(8) && dpii_inc1(9))), 1\'b0);
+ check (`__LINE__, dpii_count(0), 0);
+ check (`__LINE__, dpii_count(1), 1);
+ check (`__LINE__, dpii_count(2), 1);
+ check (`__LINE__, dpii_count(3), 0);
+ check (`__LINE__, dpii_count(4), 1);
+ check (`__LINE__, dpii_count(5), 1);
+ check (`__LINE__, dpii_count(6), 1);
+ check (`__LINE__, dpii_count(7), 0);
+ check (`__LINE__, dpii_count(8), 1);
+ check (`__LINE__, dpii_count(9), 1);
+ //
+ dpii_clear();
+ check1(`__LINE__, (1\'b0 & dpii_inc0(0)), 1\'b0);
+ check1(`__LINE__, (1\'b1 & dpii_inc0(1)), 1\'b0);
+ check1(`__LINE__, (dpii_inc0(2) & dpii_inc0(3)), 1\'b0);
+ check1(`__LINE__, (dpii_inc1(4) & dpii_inc0(5)), 1\'b0);
+ check1(`__LINE__, (dpii_inc0(6) & dpii_inc1(7)), 1\'b0);
+ check1(`__LINE__, (!(dpii_inc1(8) & dpii_inc1(9))), 1\'b0);
+ check (`__LINE__, dpii_count(0), 1);
+ check (`__LINE__, dpii_count(1), 1);
+ check (`__LINE__, dpii_count(2), 1);
+ check (`__LINE__, dpii_count(3), 1);
+ check (`__LINE__, dpii_count(4), 1);
+ check (`__LINE__, dpii_count(5), 1);
+ check (`__LINE__, dpii_count(6), 1);
+ check (`__LINE__, dpii_count(7), 1);
+ check (`__LINE__, dpii_count(8), 1);
+ check (`__LINE__, dpii_count(9), 1);
+ //
+ dpii_clear();
+ check1(`__LINE__, (1\'b0 || dpii_inc0(0)), 1\'b0);
+ check1(`__LINE__, (1\'b1 || dpii_inc0(1)), 1\'b1);
+ check1(`__LINE__, (dpii_inc0(2) || dpii_inc0(3)), 1\'b0);
+ check1(`__LINE__, (dpii_inc1(4) || dpii_inc0(5)), 1\'b1);
+ check1(`__LINE__, (dpii_inc0(6) || dpii_inc1(7)), 1\'b1);
+ check1(`__LINE__, (!(dpii_inc1(8) || dpii_inc1(9))), 1\'b0);
+ check (`__LINE__, dpii_count(0), 1);
+ check (`__LINE__, dpii_count(1), 0);
+ check (`__LINE__, dpii_count(2), 1);
+ check (`__LINE__, dpii_count(3), 1);
+ check (`__LINE__, dpii_count(4), 1);
+ check (`__LINE__, dpii_count(5), 0);
+ check (`__LINE__, dpii_count(6), 1);
+ check (`__LINE__, dpii_count(7), 1);
+ check (`__LINE__, dpii_count(8), 1);
+ check (`__LINE__, dpii_count(9), 0);
+ //
+ dpii_clear();
+ check1(`__LINE__, (1\'b0 | dpii_inc0(0)), 1\'b0);
+ check1(`__LINE__, (1\'b1 | dpii_inc0(1)), 1\'b1);
+ check1(`__LINE__, (dpii_inc0(2) | dpii_inc0(3)), 1\'b0);
+ check1(`__LINE__, (dpii_inc1(4) | dpii_inc0(5)), 1\'b1);
+ check1(`__LINE__, (dpii_inc0(6) | dpii_inc1(7)), 1\'b1);
+ check1(`__LINE__, (!(dpii_inc1(8) | dpii_inc1(9))), 1\'b0);
+ check (`__LINE__, dpii_count(0), 1);
+ check (`__LINE__, dpii_count(1), 1);
+ check (`__LINE__, dpii_count(2), 1);
+ check (`__LINE__, dpii_count(3), 1);
+ check (`__LINE__, dpii_count(4), 1);
+ check (`__LINE__, dpii_count(5), 1);
+ check (`__LINE__, dpii_count(6), 1);
+ check (`__LINE__, dpii_count(7), 1);
+ check (`__LINE__, dpii_count(8), 1);
+ check (`__LINE__, dpii_count(9), 1);
+ //
+ dpii_clear();
+ check1(`__LINE__, (1\'b0 -> dpii_inc0(0)), 1\'b1);
+ check1(`__LINE__, (1\'b1 -> dpii_inc0(1)), 1\'b0);
+ check1(`__LINE__, (dpii_inc0(2) -> dpii_inc0(3)), 1\'b1);
+ check1(`__LINE__, (dpii_inc1(4) -> dpii_inc0(5)), 1\'b0);
+ check1(`__LINE__, (dpii_inc0(6) -> dpii_inc1(7)), 1\'b1);
+ check1(`__LINE__, (!(dpii_inc1(8) -> dpii_inc1(9))), 1\'b0);
+ check (`__LINE__, dpii_count(0), 0);
+ check (`__LINE__, dpii_count(1), 1);
+ check (`__LINE__, dpii_count(2), 1);
+ check (`__LINE__, dpii_count(3), 0);
+ check (`__LINE__, dpii_count(4), 1);
+ check (`__LINE__, dpii_count(5), 1);
+ check (`__LINE__, dpii_count(6), 1);
+ check (`__LINE__, dpii_count(7), 0);
+ check (`__LINE__, dpii_count(8), 1);
+ check (`__LINE__, dpii_count(9), 1);
+ //
+ dpii_clear();
+ check1(`__LINE__, (1\'b0 ? dpii_inc0(0) : dpii_inc0(1)), 1\'b0);
+ check1(`__LINE__, (1\'b1 ? dpii_inc0(2) : dpii_inc0(3)), 1\'b0);
+ check1(`__LINE__, (dpii_inc0(4) ? dpii_inc0(5) : dpii_inc0(6)), 1\'b0);
+ check1(`__LINE__, (dpii_inc1(7) ? dpii_inc0(8) : dpii_inc0(9)), 1\'b0);
+ check (`__LINE__, dpii_count(0), 0);
+ check (`__LINE__, dpii_count(1), 1);
+ check (`__LINE__, dpii_count(2), 1);
+ check (`__LINE__, dpii_count(3), 0);
+ check (`__LINE__, dpii_count(4), 1);
+ check (`__LINE__, dpii_count(5), 0);
+ check (`__LINE__, dpii_count(6), 1);
+ check (`__LINE__, dpii_count(7), 1);
+ check (`__LINE__, dpii_count(8), 1);
+ check (`__LINE__, dpii_count(9), 0);
+ //
+ dpii_clear();
+ check1(`__LINE__, (1\'b0 * dpii_inc0(0)), 1\'b0);
+ check1(`__LINE__, (1\'b1 * dpii_inc0(1)), 1\'b0);
+ check1(`__LINE__, (dpii_inc0(2) * dpii_inc0(3)), 1\'b0);
+ check1(`__LINE__, (dpii_inc1(4) * dpii_inc0(5)), 1\'b0);
+ check1(`__LINE__, (dpii_inc0(6) * dpii_inc1(7)), 1\'b0);
+ check1(`__LINE__, (!(dpii_inc1(8) * dpii_inc1(9))), 1\'b0);
+ check (`__LINE__, dpii_count(0), 1);
+ check (`__LINE__, dpii_count(1), 1);
+ check (`__LINE__, dpii_count(2), 1);
+ check (`__LINE__, dpii_count(3), 1);
+ check (`__LINE__, dpii_count(4), 1);
+ check (`__LINE__, dpii_count(5), 1);
+ check (`__LINE__, dpii_count(6), 1);
+ check (`__LINE__, dpii_count(7), 1);
+ check (`__LINE__, dpii_count(8), 1);
+ check (`__LINE__, dpii_count(9), 1);
+ //
+ dpii_clear();
+ check1(`__LINE__, (1\'b0 + dpii_inc0(0)), 1\'b0);
+ check1(`__LINE__, (1\'b1 + dpii_inc0(1)), 1\'b1);
+ check1(`__LINE__, (dpii_inc0(2) + dpii_inc0(3)), 1\'b0);
+ check1(`__LINE__, (dpii_inc1(4) + dpii_inc0(5)), 1\'b1);
+ check1(`__LINE__, (dpii_inc0(6) + dpii_inc1(7)), 1\'b1);
+ check1(`__LINE__, (dpii_inc1(8) + dpii_inc1(9)), 1\'b0);
+ check (`__LINE__, dpii_count(0), 1);
+ check (`__LINE__, dpii_count(1), 1);
+ check (`__LINE__, dpii_count(2), 1);
+ check (`__LINE__, dpii_count(3), 1);
+ check (`__LINE__, dpii_count(4), 1);
+ check (`__LINE__, dpii_count(5), 1);
+ check (`__LINE__, dpii_count(6), 1);
+ check (`__LINE__, dpii_count(7), 1);
+ check (`__LINE__, dpii_count(8), 1);
+ check (`__LINE__, dpii_count(9), 1);
+ //
+ // Something a lot more complicated
+ dpii_clear();
+ for (i=0; i<64; i++) begin
+\t b = ( ((dpii_incx(0,i[0])
+\t\t && (dpii_incx(1,i[1])
+\t\t || dpii_incx(2,i[2])
+\t\t | dpii_incx(3,i[3]))) // | not ||
+\t\t|| dpii_incx(4,i[4]))
+\t -> dpii_incx(5,i[5]));
+ end
+ check (`__LINE__, dpii_count(0), 64);
+ check (`__LINE__, dpii_count(1), 32);
+ check (`__LINE__, dpii_count(2), 16);
+ check (`__LINE__, dpii_count(3), 16);
+ check (`__LINE__, dpii_count(4), 36);
+ check (`__LINE__, dpii_count(5), 46);
+
+ if (|errors) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ parameter PAR = 3;
+
+ m1 #(PAR) m1();
+ m3 #(PAR) m3();
+ mnooverride #(10) mno();
+
+ input clk;
+ integer cyc=1;
+ reg [4:0] bitsel;
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+\t bitsel = 0;
+\t if (PAR[bitsel]!==1\'b1) $stop;
+\t bitsel = 1;
+\t if (PAR[bitsel]!==1\'b1) $stop;
+\t bitsel = 2;
+\t if (PAR[bitsel]!==1\'b0) $stop;
+ end
+ if (cyc==1) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module m1;
+ localparam PAR1MINUS1 = PAR1DUP-2-1;
+ localparam PAR1DUP = PAR1+2; // Check we propagate parameters properly
+ parameter PAR1 = 0;
+ m2 #(PAR1MINUS1) m2 ();
+
+ // Packed arrays
+ localparam [1:0][3:0] PACKED_PARAM = { 4\'h3, 4\'h6 };
+ initial if (PACKED_PARAM != 8\'h36) $stop;
+endmodule
+
+// bug 810
+module m2 #(/*parameter*/ integer PAR2 = 10);
+ initial begin
+ $display(""%x"",PAR2);
+ if (PAR2 !== 2) $stop;
+ end
+endmodule
+
+module m3;
+ localparam LOC = 13;
+ parameter PAR = 10;
+ initial begin
+ $display(""%x %x"",LOC,PAR);
+ if (LOC !== 13) $stop;
+ if (PAR !== 3) $stop;
+ end
+endmodule
+
+module mnooverride;
+ localparam LOC = 13;
+ parameter PAR = 10;
+ initial begin
+ $display(""%x %x"",LOC,PAR);
+ if (LOC !== 13) $stop;
+ if (PAR !== 10) $stop;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ /*verilator no_inline_module*/ // So we\'ll get hiearachy we can test
+ input clk;
+
+ sub sub (/*AUTOINST*/
+\t // Inputs
+\t .clk\t\t\t(clk));
+endmodule
+
+module sub (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ /*verilator no_inline_module*/ // So we\'ll get hiearachy we can test
+
+ integer \tcyc=0;
+
+ reg [127:0] \tsave128;
+ reg [47:0] \tsave48;
+ reg [1:0] \tsave2;
+ reg [255:0] \tcycdone; // Make sure each cycle executes exactly once
+ reg [31:0]\tvec[2:1][2:1];
+ real\t\tr;
+ string\ts,s2;
+
+ string \tsi;
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d\
+"",$time, cyc);
+`endif
+ si = ""siimmed"";
+ cyc <= cyc + 1;
+ if (cycdone[cyc[7:0]]) $stop;
+ cycdone[cyc[7:0]] <= \'1;
+ if (cyc==0) begin
+\t // Setup
+\t save128 <= 128\'hc77bb9b3784ea0914afe43fb79d7b71e;
+\t save48 <= 48\'h4afe43fb79d7;
+\t save2 <= 2\'b10;
+\t vec[1][1] <= 32\'h0101;
+\t vec[1][2] <= 32\'h0102;
+\t vec[2][1] <= 32\'h0201;
+\t vec[2][2] <= 32\'h0202;
+\t r <= 1.234;
+\t s <= ""hello"";
+ end
+ if (cyc==1) begin
+\t if ($test$plusargs(""save_restore"")!=0) begin
+\t // Don\'t allow the restored model to run from time 0, it must run from a restore
+\t $write(""%%Error: didn\'t really restore\
+"");
+\t $stop;
+\t end
+ end
+ else if (cyc==99) begin
+\t if (save128 !== 128\'hc77bb9b3784ea0914afe43fb79d7b71e) $stop;
+\t if (save48 !== 48\'h4afe43fb79d7) $stop;
+\t if (save2 !== 2\'b10) $stop;
+\t if (cycdone !== {{(256-99){1\'b0}}, {99{1\'b1}}}) $stop;
+\t if (vec[1][1] !== 32\'h0101) $stop;
+\t if (vec[1][2] !== 32\'h0102) $stop;
+\t if (vec[2][1] !== 32\'h0201) $stop;
+\t if (vec[2][2] !== 32\'h0202) $stop;
+\t if (r != 1.234) $stop;
+\t $display(""%s"",s);
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ sub sub ();
+
+endmodule
+
+module sub;
+
+ wire pub /*verilator public*/; // Ignore publics
+
+ wire [5:0] assunu1 = 0; // Assigned but unused
+
+ wire [3:0] assunub2 = 0; // Assigned but bit 2 unused
+
+ wire [15:10] udrb2; // [14:13,11] is undriven
+ assign udrb2[15] = 0;
+ assign udrb2[12] = 0;
+ assign udrb2[10] = 0;
+
+ wire unu3; // Totally unused
+
+ wire [3:0] mixed; // [3] unused & undr, [2] unused, [1] undr, [0] ok
+ assign mixed[2] = 0;
+ assign mixed[0] = 0;
+
+ localparam THREE = 3;
+
+ initial begin
+ if (0 && assunu1[0] != 0 && udrb2 != 0) begin end
+ if (0 && assunub2[THREE] && assunub2[1:0]!=0) begin end
+ if (0 && mixed[1:0] != 0) begin end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module liblib_a (/*AUTOARG*/);
+ liblib_b b ();
+endmodule
+
+module liblib_b (/*AUTOARG*/);
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+
+module liblib_c (/*AUTOARG*/);
+ // Unused
+ initial $stop;
+ liblib_d d ();
+endmodule
+
+module liblib_d (/*AUTOARG*/);
+ // Unused
+ initial $stop;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [2:0] in = (crc[1:0]==0 ? 3\'d0
+\t\t : crc[1:0]==0 ? 3\'d1
+\t\t : crc[1:0]==0 ? 3\'d2 : 3\'d4);
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [31:0]\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[31:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(in[2:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {32\'h0, out};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h704ca23e2a83e1c5
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ clk, in
+ );
+
+ // Replace this module with the device under test.
+ //
+ // Change the code in the t module to apply values to the inputs and
+ // merge the output values into the result vector.
+
+ input clk;
+ input [2:0] in;
+ output reg [31:0] out;
+
+ localparam ST_0 = 0;
+ localparam ST_1 = 1;
+ localparam ST_2 = 2;
+
+ always @(posedge clk) begin
+ case (1\'b1) // synopsys parallel_case
+\tin[ST_0]: out <= 32\'h1234;
+\tin[ST_1]: out <= 32\'h4356;
+\tin[ST_2]: out <= 32\'h9874;
+\tdefault: out <= 32\'h1;
+ endcase
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ logic use_AnB;
+
+ logic [1:0] active_command [8:0];
+ logic [1:0] command_A [8:0];
+ logic [1:0] command_B [8:0];
+
+ logic [1:0] active_command2 [8:0];
+ logic [1:0] command_A2 [7:0];
+ logic [1:0] command_B2 [8:0];
+
+ logic [1:0] active_command3 [1:0][2:0][3:0];
+ logic [1:0] command_A3 [1:0][2:0][3:0];
+ logic [1:0] command_B3 [1:0][2:0][3:0];
+
+ logic [1:0] active_command4 [8:0];
+ logic [1:0] command_A4 [7:0];
+
+ logic [1:0] active_command5 [8:0];
+ logic [1:0] command_A5 [7:0];
+
+ // Single dimension assign
+ assign active_command[3:0] = (use_AnB) ? command_A[7:0] : command_B[7:0];
+ // Assignment of entire arrays
+ assign active_command2 = (use_AnB) ? command_A2 : command_B2;
+ // Multi-dimension assign
+ assign active_command3[1:0][2:0][3:0] = (use_AnB) ? command_A3[1:0][2:0][3:0] : command_B3[1:0][1:0][3:0];
+
+ // Supported: Delayed assigment with RHS Var == LHS Var
+ logic [7:0] arrd [7:0];
+ always_ff @(posedge clk) arrd[7:4] <= arrd[3:0];
+
+ // Unsupported: Non-delayed assigment with RHS Var == LHS Var
+ logic [7:0] arr [7:0];
+ assign arr[7:4] = arr[3:0];
+
+ // Delayed assign
+ always @(posedge clk) begin
+ active_command4[7:0] <= command_A4[8:0];
+ end
+
+ // Combinational assign
+ always_comb begin
+ active_command5[8:0] = command_A5[7:0];
+ end
+
+endmodule : t
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+`define CHECK text \\
+ multiline
+
+Hello in t_preproc_psl.v
+
+`ifdef NEVER
+ not
+`else
+ yes
+`endif
+
+Multi `CHECK line
+
+// Did we end up right?
+Line: `__LINE__
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+`define RegDel\t1
+
+module t_mem_slot (Clk, SlotIdx, BitToChange, BitVal, SlotToReturn, OutputVal);
+
+ input Clk;
+ input [1:0] SlotIdx;
+ input BitToChange;
+ input BitVal;
+ input [1:0] SlotToReturn;
+ output [1:0] OutputVal;
+
+ reg [1:0] Array[2:0];
+
+ always @(posedge Clk)
+ begin
+ Array[SlotIdx][BitToChange] <= #`RegDel BitVal;
+
+ OutputVal = Array[SlotToReturn];
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ // verilator lint_off MULTIDRIVEN
+
+ ma ma0 ();
+
+ global_mod #(32\'hf00d) global_cell ();
+ global_mod #(32\'hf22d) global_cell2 ();
+
+ input clk;
+ integer cyc=1;
+
+ function [31:0] getName; input fake; getName = ""t ""; endfunction
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==2) begin
+\t if (global_cell. getGlob(1\'b0) !== 32\'hf00d) $stop;
+\t if (global_cell2.getGlob(1\'b0) !== 32\'hf22d) $stop;
+ end
+ if (cyc==3) begin
+\t if (ma0. getName(1\'b0) !== ""ma "") $stop;
+\t if (ma0.mb0. getName(1\'b0) !== ""mb "") $stop;
+\t if (ma0.mb0.mc0.getName(1\'b0) !== ""mc "") $stop;
+ end
+ if (cyc==4) begin
+\t if (ma0.mb0. getP2(1\'b0) !== 32\'h0) $stop;
+\t if (ma0.mb0.mc0.getP3(1\'b0) !== 32\'h0) $stop;
+\t if (ma0.mb0.mc1.getP3(1\'b0) !== 32\'h1) $stop;
+ end
+ if (cyc==5) begin
+\t ma0. checkName(ma0. getName(1\'b0));
+\t ma0.mb0. checkName(ma0.mb0. getName(1\'b0));
+\t ma0.mb0.mc0.checkName(ma0.mb0.mc0.getName(1\'b0));
+ end
+ if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+`ifdef USE_INLINE_MID
+ `define INLINE_MODULE /*verilator inline_module*/
+ `define INLINE_MID_MODULE /*verilator no_inline_module*/
+`else
+ `ifdef USE_INLINE
+ `define INLINE_MODULE /*verilator inline_module*/
+ `define INLINE_MID_MODULE /*verilator inline_module*/
+ `else
+ `define INLINE_MODULE /*verilator public_module*/
+ `define INLINE_MID_MODULE /*verilator public_module*/
+ `endif
+`endif
+
+module global_mod;
+ `INLINE_MODULE
+ parameter INITVAL = 0;
+ integer globali;
+
+ initial globali = INITVAL;
+ function [31:0] getName; input fake; getName = ""gmod""; endfunction
+ function [31:0] getGlob; input fake; getGlob = globali; endfunction
+endmodule
+
+module ma ();
+ `INLINE_MODULE
+
+ mb #(0) mb0 ();
+ reg [31:0] gName; initial gName = ""ma "";
+ function [31:0] getName; input fake; getName = ""ma ""; endfunction
+ task checkName; input [31:0] name; if (name !== ""ma "") $stop; endtask
+
+ initial begin
+ if (ma.getName(1\'b0) !== ""ma "") $stop;
+ if (mb0.getName(1\'b0) !== ""mb "") $stop;
+ if (mb0.mc0.getName(1\'b0) !== ""mc "") $stop;
+ end
+endmodule
+
+module mb ();
+ `INLINE_MID_MODULE
+ parameter P2 = 0;
+
+ mc #(P2,0) mc0 ();
+ mc #(P2,1) mc1 ();
+ global_mod #(32\'hf33d) global_cell2 ();
+
+ reg [31:0] gName; initial gName = ""mb "";
+ function [31:0] getName; input fake; getName = ""mb ""; endfunction
+ function [31:0] getP2 ; input fake; getP2 = P2; endfunction
+ task checkName; input [31:0] name; if (name !== ""mb "") $stop; endtask
+
+ initial begin
+`ifndef verilator #1; `endif
+ if (ma. getName(1\'b0) !== ""ma "") $stop;
+ if ( getName(1\'b0) !== ""mb "") $stop;
+ if (mc1.getName(1\'b0) !== ""mc "") $stop;
+
+ ma. checkName (ma. gName);
+ /**/checkName ( gName);
+ mc1.checkName (mc1.gName);
+ ma. checkName (ma. getName(1\'b0));
+ /**/checkName ( getName(1\'b0));
+ mc1.checkName (mc1.getName(1\'b0));
+ end
+endmodule
+
+module mc ();
+ `INLINE_MODULE
+ parameter P2 = 0;
+ parameter P3 = 0;
+
+ reg [31:0] gName; initial gName = ""mc "";
+ function [31:0] getName; input fake; getName = ""mc ""; endfunction
+ function [31:0] getP3 ; input fake; getP3 = P3; endfunction
+ task checkName; input [31:0] name; if (name !== ""mc "") $stop; endtask
+
+ initial begin
+`ifndef verilator #1; `endif
+ if (ma.getName(1\'b0) !== ""ma "") $stop;
+ if (mb.getName(1\'b0) !== ""mb "") $stop;
+ if (mc.getName(1\'b0) !== ""mc "") $stop;
+ ma.checkName (ma.gName);
+ mb.checkName (mb.gName);
+ mc.checkName (mc.gName);
+ ma.checkName (ma.getName(1\'b0));
+ mb.checkName (mb.getName(1\'b0));
+ mc.checkName (mc.getName(1\'b0));
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ wire b;
+ reg \t reset;
+ integer \tcyc=0;
+
+ Testit testit (/*AUTOINST*/
+\t\t // Outputs
+\t\t .b\t\t\t(b),
+\t\t // Inputs
+\t\t .clk\t\t\t(clk),
+\t\t .reset\t\t(reset));
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+\t reset <= 1\'b0;
+ end
+ else if (cyc<10) begin
+\t reset <= 1\'b1;
+ end
+ else if (cyc<90) begin
+\t reset <= 1\'b0;
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Testit (clk, reset, b);
+ input clk;
+ input \t\t reset;
+ output \t\t b;
+
+ wire [0:0] \t\t c;
+ wire \t\t my_sig;
+ wire [0:0] \t\t d;
+
+ genvar \t\t i;
+ generate
+ for(i = 0; i >= 0; i = i-1) begin: fnxtclk1
+\t fnxtclk fnxtclk1
+\t (.u(c[i]),
+\t .reset(reset),
+\t .clk(clk),
+\t .w(d[i]) );
+ end
+ endgenerate
+
+ assign b = d[0];
+ assign c[0] = my_sig;
+ assign my_sig = 1\'b1;
+
+endmodule
+
+module fnxtclk (u, reset, clk, w );
+ input u;
+ input \t\t reset;
+ input \t\t clk;
+ output reg \t\t w;
+
+ always @ (posedge clk or posedge reset) begin
+ if (reset == 1\'b1) begin
+ w <= 1\'b0;
+ end
+ else begin
+ w <= u;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ // Width error below
+ wire [3:0] foo = 6'h2e;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2010 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+import ""DPI-C"" pure function void dpii_a_library();
+import ""DPI-C"" pure function void dpii_c_library();
+import ""DPI-C"" pure function void dpii_so_library();
+
+module t ();
+ initial begin
+ dpii_a_library(); // From .a file
+ dpii_c_library(); // From .cpp file
+ dpii_so_library(); // From .so file
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+`ifdef verilator // Otherwise need it in every module, including test, but that\'ll make a mess
+ timeunit 1ns;
+ timeprecision 1ns;
+`endif
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ supply0 [1:0] low;
+ supply1 [1:0] high;
+
+ reg [7:0] isizedwire;
+ reg ionewire;
+
+ wire oonewire;
+ wire [7:0]\t\tosizedreg;\t\t// From sub of t_inst_v2k_sub.v
+
+ t_inst sub
+ (
+ .osizedreg,
+ .oonewire,
+ // Inputs
+ .isizedwire\t\t\t(isizedwire[7:0]),
+ .*
+ //.ionewire\t\t\t(ionewire)
+ );
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t ionewire <= 1\'b1;
+\t isizedwire <= 8\'d8;
+\t end
+\t if (cyc==2) begin
+\t if (low != 2\'b00) $stop;
+\t if (high != 2\'b11) $stop;
+\t if (oonewire !== 1\'b1) $stop;
+\t if (isizedwire !== 8\'d8) $stop;
+\t end
+\t if (cyc==3) begin
+\t ionewire <= 1\'b0;
+\t isizedwire <= 8\'d7;
+\t end
+\t if (cyc==4) begin
+\t if (oonewire !== 1\'b0) $stop;
+\t if (isizedwire !== 8\'d7) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+
+module t_inst
+ (
+ output reg [7:0] osizedreg,
+ output wire oonewire /*verilator public*/,
+ input [7:0] isizedwire,
+ input wire ionewire
+ );
+
+ assign oonewire = ionewire;
+
+ always @* begin
+ osizedreg = isizedwire;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+// This test demonstrates how not only parameters but the type of a parent
+// interface could propagate down to child modules, changing their data type
+// determinations. Note presently unsupported in all commercial simulators.
+
+interface ifc;
+ parameter MODE = 0;
+ generate
+ // Note block must be named per SystemVerilog 2005
+ if (MODE==1) begin : g
+\t integer value;
+ end
+ else if (MODE==2) begin : g
+\t real value;
+ end
+ endgenerate
+endinterface
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc=1;
+
+ ifc #(1) itop1a();
+ ifc #(1) itop1b();
+ ifc #(2) itop2a();
+ ifc #(2) itop2b();
+
+ wrapper c1 (.isuba(itop1a),
+\t\t.isubb(itop1b),
+\t\t.i_valuea(14.1),
+\t\t.i_valueb(15.2));
+ wrapper c2 (.isuba(itop2a),
+\t\t.isubb(itop2b),
+\t\t.i_valuea(24.3),
+\t\t.i_valueb(25.4));
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==20) begin
+\t if (itop1a.g.value != 14) $stop;
+\t if (itop1b.g.value != 15) $stop;
+\t if (itop2a.g.value != 24) $stop;
+\t if (itop2b.g.value != 25) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module wrapper
+ (
+ ifc isuba,
+ ifc isubb,
+ input real i_valuea,
+ input real i_valueb
+ );
+ lower subsuba (.isub(isuba), .i_value(i_valuea));
+ lower subsubb (.isub(isubb), .i_value(i_valueb));
+endmodule
+
+module lower
+ (
+ ifc isub,
+ input real i_value
+ );
+ always @* begin
+`error Commercial sims choke on cross ref here
+ isub.g.value = i_value;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
+`define checkr(gotv,expv) do if ((gotv) != (expv)) begin $write(""%%Error: %s:%0d: got=%g exp=%g\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
+
+ // IEEE: integer_atom_type
+ wire byte\tw_byte;
+ wire shortint w_shortint;
+ wire int\tw_int;
+ wire longint\tw_longint;
+ wire integer\tw_integer;
+
+ // IEEE: integer_atom_type
+ wire bit\tw_bit;
+ wire logic\tw_logic;
+
+ wire bit [1:0] \tw_bit2;
+ wire logic [1:0]\tw_logic2;
+
+ // IEEE: non_integer_type
+ //UNSUP shortreal\tw_shortreal;
+ wire real\t\tw_real;
+
+ assign w_byte = 8\'h12;
+ assign w_shortint = 16\'h1234;
+ assign w_int = -123456;
+ assign w_longint = -1234567;
+ assign w_integer = -123456;
+
+ assign w_bit = 1\'b1;
+ assign w_logic = 1\'b1;
+
+ assign w_bit2 = 2\'b10;
+ assign w_logic2 = 2\'b10;
+
+ assign w_real = 3.14;
+
+ always @ (posedge clk) begin
+ `checkh(w_byte, 8\'h12);
+ `checkh(w_shortint, 16\'h1234);
+ `checkh(w_int, -123456);
+ `checkh(w_longint, -1234567);
+ `checkh(w_integer, -123456);
+ `checkh(w_bit, 1\'b1);
+ `checkh(w_logic, 1\'b1);
+ `checkh(w_bit2, 2\'b10);
+ `checkh(w_logic2, 2\'b10);
+ `checkr(w_real, 3.14);
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module a;
+ a2 a2 (.tmp(1\'b0));
+ initial begin
+ $write(""Bad top modules\
+"");
+ $stop;
+ end
+endmodule
+
+module a2 (input tmp);
+ l3 l3 (.tmp(tmp));
+endmodule
+
+module b;
+ l3 l3 (.tmp(1\'b1));
+endmodule
+
+module l3 (input tmp);
+ initial begin
+ if (tmp) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: SystemVerilog interface test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Iztok Jeras.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ logic rst = 1\'b1; // reset
+ integer rst_cnt = 0;
+
+ // reset is removed after a delay
+ always @ (posedge clk)
+ begin
+ rst_cnt <= rst_cnt + 1;
+ rst <= rst_cnt <= 3;
+ end
+
+ // counters
+ int cnt;
+ int cnt_src;
+ int cnt_drn;
+
+ // add all counters
+ assign cnt = cnt_src + cnt_drn + inf.cnt;
+
+ // finish report
+ always @ (posedge clk)
+ if (cnt == 3*16) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ // interface instance
+ handshake inf (
+ .clk (clk),
+ .rst (rst)
+ );
+
+ // source instance
+ source #(
+ .RW (8),
+ .RP (8\'b11100001)
+ ) source (
+ .clk (clk),
+ .rst (rst),
+ .inf (inf),
+ .cnt (cnt_src)
+ );
+
+ // drain instance
+ drain #(
+ .RW (8),
+ .RP (8\'b11010100)
+ ) drain (
+ .clk (clk),
+ .rst (rst),
+ .inf (inf),
+ .cnt (cnt_drn)
+ );
+
+endmodule : t
+
+
+// interface definition
+interface handshake #(
+ parameter int unsigned WC = 32
+)(
+ input logic clk,
+ input logic rst
+);
+
+ // modport signals
+ logic req; // request
+ logic grt; // grant
+ logic inc; // increment
+
+ // local signals
+ integer cnt; // counter
+
+ // source
+ modport src (
+ output req,
+ input grt
+ );
+
+ // drain
+ modport drn (
+ input req,
+ output grt
+ );
+
+ // incremet condition
+ assign inc = req & grt;
+
+ // local logic (counter)
+ always @ (posedge clk, posedge rst)
+ if (rst) cnt <= \'0;
+ else cnt <= cnt + {31\'h0, inc};
+
+endinterface : handshake
+
+
+// source module
+module source #(
+ // random generator parameters
+ parameter int unsigned RW=1, // LFSR width
+ parameter bit [RW-1:0] RP=\'0, // LFSR polinom
+ parameter bit [RW-1:0] RR=\'1 // LFSR reset state
+)(
+ input logic clk,
+ input logic rst,
+ handshake.src inf,
+ output integer cnt
+);
+
+ // LFSR
+ logic [RW-1:0] rnd;
+
+ // LFSR in Galois form
+ always @ (posedge clk, posedge rst)
+ if (rst) rnd <= RR;
+ else rnd <= {rnd[0], rnd[RW-1:1]} ^ ({RW{rnd[0]}} & RP);
+
+ // counter
+ always @ (posedge clk, posedge rst)
+ if (rst) cnt <= 32\'d0;
+ else cnt <= cnt + {31\'d0, (inf.req & inf.grt)};
+
+ // request signal
+ assign inf.req = rnd[0];
+
+endmodule : source
+
+
+// drain module
+module drain #(
+ // random generator parameters
+ parameter int unsigned RW=1, // LFSR width
+ parameter bit [RW-1:0] RP=\'0, // LFSR polinom
+ parameter bit [RW-1:0] RR=\'1 // LFSR reset state
+)(
+ input logic clk,
+ input logic rst,
+ handshake.drn inf,
+ output integer cnt
+);
+
+ // LFSR
+ logic [RW-1:0] rnd;
+
+ // LFSR in Galois form
+ always @ (posedge clk, posedge rst)
+ if (rst) rnd <= RR;
+ else rnd <= {rnd[0], rnd[RW-1:1]} ^ ({RW{rnd[0]}} & RP);
+
+ // counter
+ always @ (posedge clk, posedge rst)
+ if (rst) cnt <= 32\'d0;
+ else cnt <= cnt + {31\'d0, (inf.req & inf.grt)};
+
+ // grant signal
+ assign inf.grt = rnd[0];
+
+endmodule : drain
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk, fastclk
+ );
+
+ input clk;
+ input fastclk;\t// surefire lint_off_line UDDIXN
+
+ integer _mode; initial _mode=0;
+
+ reg [31:0] ord1; initial ord1 = 32\'h1111;
+ wire [31:0] ord2;
+ reg [31:0] ord3;
+ wire [31:0] ord4;
+ wire [31:0] ord5;
+ wire [31:0] ord6;
+ wire [31:0] ord7;
+
+ // verilator lint_off UNOPT
+ t_chg_a a (
+\t .a(ord1), .a_p1(ord2),
+\t .b(ord4), .b_p1(ord5),
+\t .c(ord3), .c_p1(ord4),
+\t .d(ord6), .d_p1(ord7)
+\t );
+
+ // surefire lint_off ASWEMB
+ assign ord6 = ord5 + 1;
+ // verilator lint_on UNOPT
+
+ always @ (/*AS*/ord2) ord3 = ord2 + 1;
+
+ always @ (fastclk) begin // surefire lint_off_line ALWLTR ALWMTR
+ if (_mode==1) begin
+\t //$write(""[%0t] t_chg: %d: Values: %x %x %x %x %x %x %x\
+"",$time,fastclk,ord1,ord2,ord3,ord4,ord5,ord6,ord7);
+\t //if (ord2 == 2 && ord7 != 7) $stop;
+ end
+ end
+
+ always @ (posedge clk) begin
+ if (_mode==0) begin
+\t $write(""[%0t] t_chg: Running\
+"", $time);
+\t _mode<=1;
+\t ord1 <= 1;
+ end
+ else if (_mode==1) begin
+\t _mode<=2;
+\t if (ord7 !== 7) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module t_chg_a (/*AUTOARG*/
+ // Outputs
+ a_p1, b_p1, c_p1, d_p1,
+ // Inputs
+ a, b, c, d
+ );
+ input [31:0] a; output [31:0] a_p1; wire [31:0] a_p1 = a + 1;
+ input [31:0] b; output [31:0] b_p1; wire [31:0] b_p1 = b + 1;
+ input [31:0] c; output [31:0] c_p1; wire [31:0] c_p1 = c + 1;
+ input [31:0] d; output [31:0] d_p1; wire [31:0] d_p1 = d + 1;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+//
+// bug354
+
+typedef logic [5:0] data_t;
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire \trst;
+ data_t \tiii_in = crc[5:0];
+ data_t \tjjj_in = crc[11:6];
+ data_t\tiii_out;
+ data_t\tjjj_out;
+ logic [1:0]\tctl0 = crc[63:62];
+
+ aaa aaa (.*);
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {64\'h0};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+\t rst <= 1\'b0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+\t rst <= 1\'b1;
+ end
+ else if (cyc<90) begin
+\t rst <= 1\'b0;
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h4afe43fb79d7b71e
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module bbb
+ (
+ output data_t ggg_out[1:0],
+ input data_t ggg_in [1:0],
+ input [1:0] [1:0] ctl,
+
+ input logic clk,
+ input logic rst
+ );
+
+ genvar \t i;
+
+ generate
+ for (i=0; i<2; i++) begin: PPP
+\t always_ff @(posedge clk) begin
+\t if (rst) begin
+\t ggg_out[i] <= 6\'b0;
+\t end
+\t else begin
+\t if (ctl[i][0]) begin
+\t\t if (ctl[i][1]) begin
+\t\t ggg_out[i] <= ~ggg_in[i];
+\t\t end else begin
+\t\t ggg_out[i] <= ggg_in[i];
+\t\t end
+\t end
+\t end
+\t end
+ end
+ endgenerate
+
+endmodule
+
+module aaa
+ (
+ input data_t iii_in,
+ input data_t jjj_in,
+ input [1:0] ctl0,
+ output data_t iii_out,
+ output data_t jjj_out,
+ input logic clk,
+ input logic rst
+ );
+
+ // Below is a bug; {} concat isn\'t used to make arrays
+ bbb bbb (
+\t .ggg_in ({jjj_in, iii_in}),
+\t .ggg_out ({jjj_out, iii_out}),
+\t .ctl\t ({{1\'b1,ctl0[1]}, {1\'b0,ctl0[0]}}),
+ .*);
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ integer cyc; initial cyc=1;
+
+ // verilator lint_off UNOPT
+ // verilator lint_off UNOPTFLAT
+ // verilator lint_off MULTIDRIVEN
+ // verilator lint_off BLKANDNBLK
+
+ reg [31:0] comcnt;
+ reg [31:0] dlycnt; initial dlycnt=0;
+ reg [31:0] lastdlycnt; initial lastdlycnt = 0;
+
+ reg [31:0] comrun; initial comrun = 0;
+ reg [31:0] comrunm1;
+ reg [31:0] dlyrun; initial dlyrun = 0;
+ reg [31:0] dlyrunm1;
+ always @ (posedge clk) begin
+ $write(""[%0t] cyc %d\
+"",$time,cyc);
+ cyc <= cyc + 1;
+ if (cyc==2) begin
+\t // Test # of iters
+\t lastdlycnt = 0;
+\t comcnt = 0;
+\t dlycnt <= 0;
+ end
+ if (cyc==3) begin
+\t dlyrun <= 5;
+\t dlycnt <= 0;
+ end
+ if (cyc==4) begin
+\t comrun = 4;
+ end
+ end
+ always @ (negedge clk) begin
+ if (cyc==5) begin
+\t $display(""%d %d\
+"", dlycnt, comcnt);
+\t if (dlycnt != 32\'d5) $stop;
+\t if (comcnt != 32\'d19) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+ // This forms a ""loop"" where we keep going through the always till comrun=0
+ reg runclk; initial runclk = 1\'b0;
+ always @ (/*AS*/comrunm1 or dlycnt) begin
+ if (lastdlycnt != dlycnt) begin
+\t comrun = 3;
+\t $write (""[%0t] comrun=%0d start\
+"", $time, comrun);
+ end
+ else if (comrun > 0) begin
+\t comrun = comrunm1;
+\t if (comrunm1==1) begin
+\t runclk = 1;
+\t $write (""[%0t] comrun=%0d [trigger clk]\
+"", $time, comrun);
+\t end
+\t else $write (""[%0t] comrun=%0d\
+"", $time, comrun);
+ end
+ lastdlycnt = dlycnt;
+ end
+
+ always @ (/*AS*/comrun) begin
+ if (comrun!=0) begin
+\t comrunm1 = comrun - 32\'d1;
+\t comcnt = comcnt + 32\'d1;
+\t $write(""[%0t] comcnt=%0d\
+"",$time,comcnt);
+ end
+ end
+
+ // This forms a ""loop"" where we keep going through the always till dlyrun=0
+ reg runclkrst;
+ always @ (posedge runclk) begin
+ runclkrst <= 1;
+ $write (""[%0t] runclk\
+"", $time);
+ if (dlyrun > 0) begin
+\t dlyrun <= dlyrun - 32\'d1;
+\t dlycnt <= dlycnt + 32\'d1;
+\t $write (""[%0t] dlyrun<=%0d\
+"", $time, dlyrun-32\'d1);
+ end
+ end
+
+ always @* begin
+ if (runclkrst) begin
+\t $write (""[%0t] runclk reset\
+"", $time);
+\t runclkrst = 0;
+\t runclk = 0;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+
+ reg [63:0]\ttime64;
+
+
+ // Test loop
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+ end
+ else if (cyc<10) begin
+ end
+ else if (cyc<90) begin
+\t time64 = $time;
+\t if ($stime != time64[31:0]) $stop;
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer cyc; initial cyc=0;
+ reg [63:0] crc;
+
+ wire [65:0]\t\toutData;\t\t// From fifo of fifo.v
+ wire [15:0] \t\tinData = crc[15:0];
+ wire [1:0] \t\tinWordPtr = crc[17:16];
+ wire\t\t\twrEn = crc[20];
+ wire [1:0] \t\twrPtr = crc[33:32];
+ wire [1:0] \t\trdPtr = crc[34:33];
+
+ fifo fifo (
+\t // Outputs
+\t .outData\t\t\t(outData[65:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .inWordPtr\t\t(inWordPtr[1:0]),
+\t .inData\t\t\t(inData[15:0]),
+\t .rdPtr\t\t\t(rdPtr),
+\t .wrPtr\t\t\t(wrPtr),
+\t .wrEn\t\t\t(wrEn));
+
+ always @ (posedge clk) begin
+ //$write(""[%0t] cyc==%0d crc=%b q=%x\
+"",$time, cyc, crc, outData);
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc==90) begin
+\t if (outData[63:0] != 64\'hd9bcbc276f0984ea) $stop;
+ end
+ else if (cyc==91) begin
+\t if (outData[63:0] != 64\'hef77cd9b13a866f0) $stop;
+ end
+ else if (cyc==92) begin
+\t if (outData[63:0] != 64\'h2750cd9b13a866f0) $stop;
+ end
+ else if (cyc==93) begin
+\t if (outData[63:0] != 64\'h4ea0bc276f0984ea) $stop;
+ end
+ else if (cyc==94) begin
+\t if (outData[63:0] != 64\'h9d41bc276f0984ea) $stop;
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module fifo (/*AUTOARG*/
+ // Outputs
+ outData,
+ // Inputs
+ clk, inWordPtr, inData, wrPtr, rdPtr, wrEn
+ );
+
+ parameter fifoDepthLog2 = 1;
+ parameter fifoDepth = 1<>>i;
+\t //$write ("" %x >>> %d == %x\
+"",data,i,srs);
+\t for (b=0; b<80; b=b+1) begin
+\t\t if (srs[b] != (b==(75-i) || b==(10-i))) $stop;
+\t end
+\t end
+\t end
+\t if (cyc==10) begin
+\t data <= 80\'h0;
+\t data[79] <= 1\'b1;
+\t data[10] <= 1\'b1;
+\t end
+\t if (cyc==12) begin
+\t for (i=0; i<85; i=i+1) begin
+\t srs = data>>>i;
+\t //$write ("" %x >>> %d == %x\
+"",data,i,srs);
+\t for (b=0; b<80; b=b+1) begin
+\t\t if (srs[b] != (b>=(79-i) || b==(10-i))) $stop;
+\t end
+\t end
+\t end
+\t if (cyc==20) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t_inst_first_b (/*AUTOARG*/
+ // Outputs
+ o_seq_d1r, o_com, o2_com,
+ // Inputs
+ clk, i_seq, i_com, i2_com, wide_for_trace, wide_for_trace_2
+ );
+ // verilator inline_module
+
+ input clk;
+
+ input \ti_seq;
+ output\to_seq_d1r;
+ input \ti_com;
+ output\to_com;
+ input [1:0] \ti2_com;
+ output [1:0]\to2_com;
+ input [127:0] wide_for_trace;
+ input [127:0] wide_for_trace_2;
+
+ /*AUTOREG*/
+ // Beginning of automatic regs (for this module's undeclared outputs)
+ // End of automatics
+
+ reg \t\t\to_seq_d1r;
+ always @ (posedge clk) begin
+ o_seq_d1r <= ~i_seq;
+ end
+
+ wire [1:0] o2_com = ~i2_com;
+ wire o_com = ~i_com;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+interface ifc;
+ logic [3:0] value;
+ logic reset;
+ modport counter_mp (input reset, output value);
+ modport core_mp (output reset, input value);
+endinterface
+
+module t
+ (// Inputs
+ input clk,
+ ifc.counter_mp c_data
+ );
+
+ integer cyc=1;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ reg \t _ranit;
+
+ reg \t rnd;
+ reg [2:0] a;
+ reg [2:0] b;
+ reg [31:0] wide;
+
+ // surefire lint_off STMINI
+ initial _ranit = 0;
+
+ wire sigone1 = 1\'b1;
+ wire sigone2 = 1\'b1;
+ reg \t ok;
+
+ parameter [1:0] twounkn = 2\'b?; // This gets extended to 2\'b??
+
+ // Large case statements should be well optimizable.
+ reg [2:0] \t anot;
+ always @ (/*AS*/a) begin
+ casez (a)
+\tdefault: anot = 3\'b001;
+\t3\'d0: anot = 3\'b111;
+\t3\'d1: anot = 3\'b110;
+\t3\'d2: anot = 3\'b101;
+\t3\'d3: anot = 3\'b101;
+\t3\'d4: anot = 3\'b011;
+\t3\'d5: anot = 3\'b010;
+\t3\'d6: anot = 3\'b001;\t// Same so folds with 7
+ endcase
+ end
+
+ always @ (posedge clk) begin
+ if (!_ranit) begin
+\t _ranit <= 1;
+\t rnd <= 1;
+\t $write(""[%0t] t_case: Running\
+"", $time);
+\t //
+\t a = 3\'b101;
+\t b = 3\'b111;
+\t // verilator lint_off CASEX
+\t casex (a)
+\t default: $stop;
+\t 3\'bx1x: $stop;
+\t 3\'b100: $stop;
+\t 3\'bx01: ;
+\t endcase
+\t casez (a)
+\t default: $stop;
+\t 3\'b?1?: $stop;
+\t 3\'b100: $stop;
+\t 3\'b?01: ;
+\t endcase
+\t casez (a)
+\t default: $stop;
+\t {1\'b0, twounkn}: $stop;
+\t {1\'b1, twounkn}: ;
+\t endcase
+\t casez (b)
+\t default: $stop;
+\t {1\'b0, twounkn}: $stop;
+\t {1\'b1, twounkn}: ;
+//\t {1\'b0, 2\'b??}: $stop;
+//\t {1\'b1, 2\'b??}: ;
+\t endcase
+\t case(a[0])
+\t default: ;
+\t endcase
+\t casex(a)
+\t default: ;
+\t 3\'b?0?: ;
+\t endcase
+\t // verilator lint_off CASEX
+\t //This is illegal, the default occurs before the statements.
+\t //case(a[0])
+\t // default: $stop;
+\t // 1\'b1: ;
+\t //endcase
+\t //
+\t wide = 32\'h12345678;
+\t casez (wide)
+\t default: $stop;
+\t 32\'h12345677,
+\t 32\'h12345678,
+\t 32\'h12345679: ;
+\t endcase
+\t //
+\t ok = 0;
+\t casez ({sigone1,sigone2})
+\t //2\'b10, 2\'b01, 2\'bXX: ;\t// verilator bails at this since in 2 state it can be true...
+\t 2\'b10, 2\'b01: ;
+\t 2\'b00: ;
+\t default: ok=1\'b1;
+\t endcase
+ if (ok !== 1\'b1) $stop;
+\t //
+
+\t if (rnd) begin
+\t $write("""");
+\t end
+\t //
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+ // Check parameters in case statements
+ parameter ALU_DO_REGISTER\t\t= 3\'h1; // input selected by reg addr.
+ parameter DSP_REGISTER_V\t\t= 6\'h03;
+
+ reg [2:0] alu_ctl_2s;\t// Delayed version of alu_ctl
+ reg [5:0] reg_addr_2s;\t// Delayed version of reg_addr
+ reg [7:0] ir_slave_2s;\t// Instruction Register delayed 2 phases
+ reg [15:10] f_tmp_2s;\t// Delayed copy of F
+ reg \t p00_2s;
+
+ initial begin
+ alu_ctl_2s = 3\'h1;
+ reg_addr_2s = 6\'h3;
+ ir_slave_2s= 0;
+ f_tmp_2s= 0;
+ casex ({alu_ctl_2s,reg_addr_2s,
+\t ir_slave_2s[7],ir_slave_2s[5:4],ir_slave_2s[1:0],
+\t f_tmp_2s[11:10]})
+\tdefault: p00_2s = 1\'b0;
+\t{ALU_DO_REGISTER,DSP_REGISTER_V,1\'bx,2\'bx,2\'bx,2\'bx}: p00_2s = 1\'b1;
+ endcase
+ if (1\'b0) $display (""%x %x %x %x"", alu_ctl_2s, ir_slave_2s, f_tmp_2s, p00_2s); //Prevent unused
+ //
+ case ({1\'b1, 1\'b1})
+\tdefault: $stop;
+\t{1\'b1, p00_2s}: ;
+ endcase
+ end
+
+ // Check wide overlapping cases
+ // surefire lint_off CSEOVR
+ parameter ANY_STATE = 7\'h??;
+ reg [19:0] foo;
+ initial begin
+ foo = {1\'b0,1\'b0,1\'b0,1\'b0,1\'b0,7\'h04,8\'b0};
+ casez (foo)
+\tdefault: $stop;
+\t{1\'b1,1\'b?,1\'b?,1\'b?,1\'b?,ANY_STATE,8\'b?}: $stop;
+\t{1\'b?,1\'b1,1\'b?,1\'b?,1\'b?,7\'h00,8\'b?}: $stop;
+\t{1\'b?,1\'b?,1\'b1,1\'b?,1\'b?,7\'h00,8\'b?}: $stop;
+\t{1\'b?,1\'b?,1\'b?,1\'b1,1\'b?,7\'h00,8\'b?}: $stop;
+\t{1\'b?,1\'b?,1\'b?,1\'b?,1\'b?,7\'h04,8\'b?}: ;
+\t{1\'b?,1\'b?,1\'b?,1\'b?,1\'b?,7\'h06,8\'hdf}: $stop;
+\t{1\'b?,1\'b?,1\'b?,1\'b?,1\'b?,7\'h06,8\'h00}: $stop;
+ endcase
+ end
+ initial begin
+ foo = 20\'b1010;
+ casex (foo[3:0])
+\tdefault: $stop;
+\t4\'b0xxx,
+\t4\'b100x,
+\t4\'b11xx: $stop;
+\t4\'b1010: ;
+ endcase
+ end
+ initial begin
+ foo = 20\'b1010;
+ ok = 1\'b0;
+ // Test of RANGE(CONCAT reductions...
+ casex ({foo[3:2],foo[1:0],foo[3]})
+\t5\'bxx10x: begin ok=1\'b0; foo=20\'d1; ok=1\'b1; end // Check multiple expressions
+\t5\'bxx00x: $stop;
+\t5\'bxx01x: $stop;
+\t5\'bxx11x: $stop;
+ endcase
+ if (!ok) $stop;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ reg [2*32-1:0] w2; initial w2 = {2 {32\'h12345678}};
+ reg [9*32-1:0] w9; initial w9 = {9 {32\'h12345678}};
+ reg [10*32-1:0] w10; initial w10 = {10{32\'h12345678}};
+ reg [11*32-1:0] w11; initial w11 = {11{32\'h12345678}};
+ reg [15*32-1:0] w15; initial w15 = {15{32\'h12345678}};
+ reg [31*32-1:0] w31; initial w31 = {31{32\'h12345678}};
+ reg [47*32-1:0] w47; initial w47 = {47{32\'h12345678}};
+ reg [63*32-1:0] w63; initial w63 = {63{32\'h12345678}};
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = (w2[63:0]
+\t\t\t ^ w9[64:1]
+\t\t\t ^ w10[65:2]
+\t\t\t ^ w11[66:3]
+\t\t\t ^ w15[67:4]
+\t\t\t ^ w31[68:5]
+\t\t\t ^ w47[69:6]
+\t\t\t ^ w63[70:7]);
+
+ // What checksum will we end up with
+`define EXPECTED_SUM 64\'h184cb39122d8c6e3
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+\t w2 <= w2 >> 1;
+\t w9 <= w9 >> 1;
+\t w10 <= w10 >> 1;
+\t w11 <= w11 >> 1;
+\t w15 <= w15 >> 1;
+\t w31 <= w31 >> 1;
+\t w47 <= w47 >> 1;
+\t w63 <= w63 >> 1;
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+
+ reg [43:0] \tmi;
+ wire [31:0] \tmo;
+ muxtop um ( mi, mo);
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t mi <= 44\'h1234567890;
+\t end
+\t if (cyc==3) begin
+\t if (mo !== 32\'h12345678) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+module muxtop (
+ input [ 43:0 ] i,
+ output reg [ 31:0 ] o
+ );
+
+ always @ ( i[43:0] ) // Verify we ignore ranges on always statement sense lists
+ o = MUX( i[39:0] );
+
+ function [31:0] MUX;
+ input [39:0] XX ;
+ begin
+ MUX = XX[39:8];
+ end
+ endfunction
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Iztok Jeras.
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0)
+
+ module t (/*AUTOARG*/);
+
+ // signed source
+ logic signed [8-1:0] src;
+
+ // destination structure
+ struct packed {
+ logic signed [16-1:0] s;
+ logic unsigned [16-1:0] u;
+ } dst;
+
+ initial begin
+ // bug882
+ // verilator lint_off WIDTH
+ src = 8\'sh05;
+ dst = \'{s: src, u: src};
+ `checkh (dst.s, 16\'h0005);
+ `checkh (dst.u, 16\'h0005);
+
+ src = 8\'shf5;
+ dst = \'{s: src, u: src};
+ `checkh (dst.s, 16\'hfff5);
+ `checkh (dst.u, 16\'hfff5);
+ // verilator lint_on WIDTH
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty.
+`timescale 1ns / 1ps
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer cyc; initial cyc=0;
+ reg [63:0] crc;
+ reg [31:0] sum;
+
+ wire [8:0]\t\tOutput;
+ wire [8:0] \t\tInput = crc[8:0];
+
+ assigns assigns (/*AUTOINST*/
+\t\t // Outputs
+\t\t .Output\t\t(Output[8:0]),
+\t\t // Inputs
+\t\t .Input\t\t(Input[8:0]));
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x q=%x\
+"",$time, cyc, crc, sum);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 32\'h0;
+ end
+ else if (cyc>10 && cyc<90) begin
+\t sum <= {sum[30:0],sum[31]} ^ {23\'h0, crc[8:0]};
+ end
+ else if (cyc==99) begin
+\t if (sum !== 32\'he8bbd130) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module assigns(Input, Output);
+ input [8:0] Input;
+ output [8:0] Output;
+
+ genvar \ti;
+ generate
+ for (i = 0; i < 8; i = i + 1) begin : ap
+\t assign Output[(i>0) ? i-1 : 8] = Input[(i>0) ? i-1 : 8];
+ end
+ endgenerate
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+/* Acceptable answer 1
+created tag with scope = top.t.tag
+created tag with scope = top.t.b.gen[0].tag
+created tag with scope = top.t.b.gen[1].tag
+mod a has scope = top.t
+mod a has tag = top.t.tag
+mod b has scope = top.t.b
+mod b has tag = top.t.tag
+mod c has scope = top.t.b.gen[0].c
+mod c has tag = top.t.b.gen[0].tag
+mod c has scope = top.t.b.gen[1].c
+mod c has tag = top.t.b.gen[1].tag
+*/
+/* Acceptable answer 2
+created tag with scope = top.t.tag
+created tag with scope = top.t.b.gen[0].tag
+created tag with scope = top.t.b.gen[1].tag
+mod a has scope = top.t
+mod a has tag = top.t.tag
+mod b has scope = top.t.b
+mod b has tag = top.t.tag
+mod c has scope = top.t.b.gen[0].c
+mod c has tag = top.t.tag
+mod c has scope = top.t.b.gen[1].c
+mod c has tag = top.t.tag
+*/
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ integer \tcyc=0;
+
+ tag tag ();
+ b b ();
+
+ always @ (t.cyc) begin
+ if (t.cyc == 2) $display(""mod a has scope = %m"");
+ if (t.cyc == 2) $display(""mod a has tag = %0s"", tag.scope);
+ end
+
+ always @(posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module b ();
+ genvar g;
+ generate
+ for (g=0; g<2; g++) begin : gen
+\t tag tag ();
+\t c c ();
+ end
+ endgenerate
+ always @ (t.cyc) begin
+ if (t.cyc == 3) $display(""mod b has scope = %m"");
+ if (t.cyc == 3) $display(""mod b has tag = %0s"", tag.scope);
+ end
+endmodule
+
+module c ();
+ always @ (t.cyc) begin
+ if (t.cyc == 4) $display(""mod c has scope = %m"");
+ if (t.cyc == 4) $display(""mod c has tag = %0s"", tag.scope);
+ end
+endmodule
+
+module tag ();
+ bit [100*8-1:0] scope;
+ initial begin
+ $sformat(scope,""%m"");
+ $display(""created tag with scope = %0s"",scope);
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+`include ""verilated.v""
+
+module t;
+
+ // Note $sscanf already tested elsewhere
+
+ reg [3:0] n;
+ reg [63:0] q;
+ reg [16*8:1] wide;
+
+ reg [8:1] \tchar;
+ reg [48*8:1] str;
+ reg [48*8:1] str2;
+
+ real \tr;
+
+ initial begin
+ n = 4\'b1100;
+ q = 64\'h1234_5678_abcd_0123;
+ wide = ""hello-there12345"";
+ $sformat(str, ""n=%b q=%d w=%s"", n, q, wide);
+`ifdef TEST_VERBOSE $display(""str=%0s"",str); `endif
+ if (str !== ""n=1100 q= 1311768467750060323 w=hello-there12345"") $stop;
+
+ q = {q[62:0],1\'b1};
+ $swrite(str2, ""n=%b q=%d w=%s"", n, q, wide);
+`ifdef TEST_VERBOSE $display(""str2=%0s"",str2); `endif
+ if (str2 !== ""n=1100 q= 2623536935500120647 w=hello-there12345"") $stop;
+
+ $swrite(str2, ""e=%e"", r);
+ $swrite(str2, ""e=%f"", r);
+ $swrite(str2, ""e=%g"", r);
+
+ r = 0.01;
+ $swrite(str2, ""e=%e f=%f g=%g"", r, r, r);
+`ifdef TEST_VERBOSE $display(""str2=%0s"",str2); `endif
+ if (str2 !== ""e=1.000000e-02 f=0.010000 g=0.01"") $stop;
+
+ $swrite(str2, ""mod=%m"");
+`ifdef TEST_VERBOSE $display(""str2=%0s"",str2); `endif
+`ifdef verilator
+ if (str2 !== ""mod=top.v"") $stop;
+`else
+ if (str2 !== ""mod=top.t"") $stop;
+`endif
+
+ $sformat(char,""%s"",""c"");
+ if (char != ""c"") $stop;
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ parameter [31:0]\tTWENTY4 = 24;
+ parameter [31:0]\tPA = TWENTY4/8;
+ parameter [1:0]\tVALUE = 2\'b10;
+ parameter [5:0]\tREPL = {PA{VALUE}};
+ parameter [7:0]\tCONC = {REPL,VALUE};
+
+ parameter \t\tDBITS = 32;
+ parameter \t\tINIT_BYTE = 8\'h1F;
+ parameter \t\tDWORDS_LOG2 = 7;
+ parameter \t\tDWORDS = (1<= 10 && cyc < 14) begin
+\t sum <= sum + arr[cyc-10];
+
+\t sum_w <= sum_w + arr_w[cyc-10];
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d sum=%x\
+"",$time, cyc, sum);
+\t if (sum != 8\'h55) $stop;
+\t if (sum != sum_w) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+ // Test ordering of packed dimensions
+ logic [31:0] data_out;
+ logic [31:0] data_out2;
+ logic [0:0] [2:0] [31:0] data_in;
+ logic [31:0] data_in2 [0:0] [2:0];
+ assign data_out = data_in[0][0] + data_in[0][1] + data_in[0][2];
+ assign data_out2 = data_in2[0][0] + data_in2[0][1] + data_in2[0][2];
+
+ logic [31:0] last_data_out;
+ always @ (posedge clk) begin
+ if (cyc <= 2) begin
+\t data_in[0][0] <= 0;
+\t data_in[0][1] <= 0;
+\t data_in[0][2] <= 0;
+\t data_in2[0][0] <= 0;
+\t data_in2[0][1] <= 0;
+\t data_in2[0][2] <= 0;
+ end
+ else if (cyc > 2 && cyc < 99) begin
+\t data_in[0][0] <= data_in[0][0] + 1;
+\t data_in[0][1] <= data_in[0][1] + 1;
+\t data_in[0][2] <= data_in[0][2] + 1;
+\t data_in2[0][0] <= data_in2[0][0] + 1;
+\t data_in2[0][1] <= data_in2[0][1] + 1;
+\t data_in2[0][2] <= data_in2[0][2] + 1;
+\t last_data_out <= data_out;
+`ifdef TEST_VERBOSE
+\t $write(""data_out %0x %0x\
+"", data_out, last_data_out);
+`endif
+\t if (cyc > 4 && data_out != last_data_out + 3) $stop;
+\t if (cyc > 4 && data_out != data_out2) $stop;
+ end
+ end
+
+ // Test for mixed implicit/explicit dimensions and all implicit packed
+ bit [3:0][7:0][1:0] vld [1:0][1:0];
+ bit [3:0][7:0][1:0] vld2;
+
+ // There are specific nodes for Or, Xor, Xnor and And
+ logic vld_or;
+ logic vld2_or;
+ assign vld_or = |vld[0][0];
+ assign vld2_or = |vld2;
+
+ logic vld_xor;
+ logic vld2_xor;
+ assign vld_xor = ^vld[0][0];
+ assign vld2_xor = ^vld2;
+
+ logic vld_xnor;
+ logic vld2_xnor;
+ assign vld_xnor = ~^vld[0][0];
+ assign vld2_xnor = ~^vld2;
+
+ logic vld_and;
+ logic vld2_and;
+ assign vld_and = &vld[0][0];
+ assign vld2_and = &vld2;
+
+ // Bit reductions should be cloned, other unary operations should clone the
+ // entire assign.
+ bit [3:0][7:0][1:0] not_lhs;
+ bit [3:0][7:0][1:0] not_rhs;
+ assign not_lhs = ~not_rhs;
+
+ // Test an AstNodeUniop that shouldn\'t be expanded
+ bit [3:0][7:0][1:0] vld2_inv;
+ assign vld2_inv = ~vld2;
+
+ initial begin
+ for (int i=0; i<4; i=i+2) begin
+ for (int j=0; j<8; j=j+2) begin
+\t vld[0][0][i][j] = 2\'b00;
+\t vld[0][0][i+1][j+1] = 2\'b00;
+\t vld2[i][j] = 2\'b00;
+\t vld2[i+1][j+1] = 2\'b00;
+\t not_rhs[i][j] = i[1:0];
+\t not_rhs[i+1][j+1] = i[1:0];
+\t end
+ end
+ end
+
+
+ logic [3:0] expect_cyc; initial expect_cyc = \'d15;
+
+ always @(posedge clk) begin
+ expect_cyc <= expect_cyc + 1;
+ for (int i=0; i<4; i=i+1) begin
+ for (int j=0; j<8; j=j+1) begin
+\t vld[0][0][i][j] <= vld[0][0][i][j] + 1;
+\t vld2[i][j] <= vld2[i][j] + 1;
+\t if (not_rhs[i][j] != ~not_lhs[i][j]) $stop;
+\t not_rhs[i][j] <= not_rhs[i][j] + 1;
+\t end
+ end
+ if (cyc % 8 == 0) begin
+\t vld[0][0][0][0] <= vld[0][0][0][0] - 1;
+\t vld2[0][0] <= vld2[0][0] - 1;
+ end
+ if (expect_cyc < 8 && !vld_xor) $stop;
+ else if (expect_cyc > 7 && vld_xor) $stop;
+
+ if (expect_cyc < 8 && vld_xnor) $stop;
+ else if (expect_cyc > 7 && !vld_xnor) $stop;
+
+ if (expect_cyc == 15 && vld_or) $stop;
+ else if (expect_cyc == 11 && vld_or) $stop;
+ else if (expect_cyc != 15 && expect_cyc != 11 && !vld_or) $stop;
+
+ if (expect_cyc == 10 && !vld_and) $stop;
+ else if (expect_cyc == 14 && !vld_and) $stop;
+ else if (expect_cyc != 10 && expect_cyc != 14 && vld_and) $stop;
+
+ if (vld_xor != vld2_xor) $stop;
+ if (vld_xnor != vld2_xnor) $stop;
+ if (vld_or != vld2_or) $stop;
+ if (vld_and != vld2_and) $stop;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ by_width #(1) w1 (.clk(clk));
+ by_width #(31) w31 (.clk(clk));
+ by_width #(32) w32 (.clk(clk));
+ by_width #(33) w33 (.clk(clk));
+ by_width #(63) w63 (.clk(clk));
+ by_width #(64) w64 (.clk(clk));
+ by_width #(65) w65 (.clk(clk));
+ by_width #(95) w95 (.clk(clk));
+ by_width #(96) w96 (.clk(clk));
+ by_width #(97) w97 (.clk(clk));
+
+ reg \t signed [15:0] a;
+ reg \t signed [4:0] b;
+
+ reg \t signed [15:0] sr,srs,sl,sls;
+
+ reg \t[15:0] b_s;
+ reg \t[15:0] b_us;
+
+ task check_s(input signed [7:0] i, input [7:0] expval);
+ //$display(""check_s %x\
+"", i);
+ if (i !== expval) $stop;
+ endtask
+ task check_us(input signed [7:0] i, input [7:0] expval);
+ //$display(""check_us %x\
+"", i);
+ if (i !== expval) $stop;
+ endtask
+
+ always @* begin
+ sr = a>>b;
+ srs = copy_signed(a)>>>b;
+ sl = a<>>4;\t\t// Signed
+ b_us = b[4:0]>>>4;\t// Unsigned, due to extract
+ check_s ( 3\'b111, 8\'h07);
+ check_s (3\'sb111, 8\'hff);
+ check_us( 3\'b111, 8\'h07);
+ check_us(3\'sb111, 8\'hff); // Note we sign extend ignoring function\'s input requirements
+ // verilator lint_on WIDTH
+ end
+
+ reg signed [32:0] bug349;
+
+ initial
+ begin
+ end
+ integer i;
+ initial begin
+ if ((-1 >>> 3) != -1) $stop;\t// Decimals are signed
+ // verilator lint_off WIDTH
+ if ((3\'b111 >>> 3) != 0) $stop;\t// Based numbers are unsigned
+ if ((3\'sb111 >>> 3) != -1) $stop;\t// Signed based numbers
+ // verilator lint_on WIDTH
+ if ( (3\'sb000 > 3\'sb000)) $stop;
+ if (!(3\'sb000 > 3\'sb111)) $stop;
+ if ( (3\'sb111 > 3\'sb000)) $stop;
+ if ( (3\'sb000 < 3\'sb000)) $stop;
+ if ( (3\'sb000 < 3\'sb111)) $stop;
+ if (!(3\'sb111 < 3\'sb000)) $stop;
+ if (!(3\'sb000 >= 3\'sb000)) $stop;
+ if (!(3\'sb000 >= 3\'sb111)) $stop;
+ if ( (3\'sb111 >= 3\'sb000)) $stop;
+ if (!(3\'sb000 <= 3\'sb000)) $stop;
+ if ( (3\'sb000 <= 3\'sb111)) $stop;
+ if (!(3\'sb111 <= 3\'sb000)) $stop;
+ // When we multiply overflow, the sign bit stays correct.
+ if ( (4\'sd2*4\'sd8) != 4\'d0) $stop;
+ // From the spec:
+ // verilator lint_off WIDTH
+ i = -12 /3; if (i !== 32\'hfffffffc) $stop;
+ i = -\'d12 /3; if (i !== 32\'h55555551) $stop;
+ i = -\'sd12 /3; if (i !== 32\'hfffffffc) $stop;
+ i = -4\'sd12 /3; if (i !== 32\'h00000001) $stop;
+ // verilator lint_on WIDTH
+
+ // verilator lint_off WIDTH
+ bug349 = 4\'sb1111 - 1\'b1;
+ if (bug349 != 32\'he) $stop;
+ end
+
+ function signed [15:0] copy_signed;
+ input [15:0] ai;
+ copy_signed = ai;
+ endfunction
+
+ integer cyc; initial cyc=0;
+ wire [31:0] ucyc = cyc;
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+`ifdef TEST_VERBOSE
+ $write(""%x %x %x %x %x %x %x\
+"", cyc, sr,srs,sl,sls, b_s,b_us);
+`endif
+ case (cyc)
+\t0: begin
+\t a <= 16\'sh8b1b; b <= 5\'sh1f; // -1
+\tend
+\t1: begin
+\t // Check spaces in constants
+\t a <= 16 \'sh 8b1b; b <= 5\'sh01; // -1
+\tend
+\t2: begin
+\t a <= 16\'sh8b1b; b <= 5\'sh1e; // shift AMOUNT is really unsigned
+\t if (ucyc / 1 != 32\'d2) $stop;
+\t if (ucyc / 2 != 32\'d1) $stop;
+\t if (ucyc * 1 != 32\'d2) $stop;
+\t if (ucyc * 2 != 32\'d4) $stop;
+\t if (ucyc * 3 != 32\'d6) $stop;
+\t if (cyc * 32\'sd1 != 32\'sd2) $stop;
+\t if (cyc * 32\'sd2 != 32\'sd4) $stop;
+\t if (cyc * 32\'sd3 != 32\'sd6) $stop;
+\tend
+\t3: begin
+\t a <= 16\'sh0048; b <= 5\'sh1f;
+\t if (ucyc * 1 != 32\'d3) $stop;
+\t if (ucyc * 2 != 32\'d6) $stop;
+\t if (ucyc * 3 != 32\'d9) $stop;
+\t if (ucyc * 4 != 32\'d12) $stop;
+\t if (cyc * 32\'sd1 != 32\'sd3) $stop;
+\t if (cyc * 32\'sd2 != 32\'sd6) $stop;
+\t if (cyc * 32\'sd3 != 32\'sd9) $stop;
+\tend
+\t4: begin
+\t a <= 16\'sh4154; b <= 5\'sh02;
+\tend
+\t5: begin
+\t a <= 16\'shc3e8; b <= 5\'sh12;
+\tend
+\t6: begin
+\t a <= 16\'sh488b; b <= 5\'sh02;
+\tend
+\t9: begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\tend
+\tdefault: ;
+ endcase
+ case (cyc)
+\t0: ;
+\t1: if ({sr,srs,sl,sls,b_s,b_us}!==96\'sh0000_ffff_0000_0000_ffff_0001) $stop;
+\t2: if ({sr,srs,sl,sls,b_s,b_us}!==96\'sh458d_c58d_1636_1636_0000_0000) $stop;
+\t3: if ({sr,srs,sl,sls,b_s,b_us}!==96\'sh0000_ffff_0000_0000_ffff_0001) $stop;
+\t4: if ({sr,srs,sl,sls,b_s,b_us}!==96\'sh0000_0000_0000_0000_ffff_0001) $stop;
+\t5: if ({sr,srs,sl,sls,b_s,b_us}!==96\'sh1055_1055_0550_0550_0000_0000) $stop;
+\t6: if ({sr,srs,sl,sls,b_s,b_us}!==96\'sh0000_ffff_0000_0000_ffff_0001) $stop;
+\t7: if ({sr,srs,sl,sls,b_s,b_us}!==96\'sh1222_1222_222c_222c_0000_0000) $stop;
+\t8: ;
+\t9: ;
+ endcase
+ end
+endmodule
+
+
+module by_width (
+\t\t input clk
+\t\t );
+ parameter \t WIDTH=1;
+
+ reg signed \t i1;
+ reg signed [62:0] i63;
+ reg signed [64:0] i65;
+
+ // verilator lint_off WIDTH
+ wire signed [WIDTH-1:0] i1extp /*verilator public*/ = i1;
+ wire signed [WIDTH-1:0] i1ext = i1;
+ wire signed [WIDTH-1:0] i63ext = i63;
+ wire signed [WIDTH-1:0] i65ext = i65;
+ // verilator lint_on WIDTH
+
+ integer cyc; initial cyc=0;
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ i1 <= cyc[0];
+ i63 <= {63{cyc[0]}};
+ i65 <= {65{cyc[0]}};
+ case (cyc)
+\t1: begin
+\t if (i1extp != {WIDTH{1\'b0}}) $stop;
+\t if (i1ext != {WIDTH{1\'b0}}) $stop;
+\t if (i63ext != {WIDTH{1\'b0}}) $stop;
+\t if (i65ext != {WIDTH{1\'b0}}) $stop;
+\tend
+\t2: begin
+\t if (i1extp != {WIDTH{1\'b1}}) $stop;
+\t if (i1ext != {WIDTH{1\'b1}}) $stop;
+\t if (i63ext != {WIDTH{1\'b1}}) $stop;
+\t if (i65ext != {WIDTH{1\'b1}}) $stop;
+\tend
+\tdefault: ;
+ endcase
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer _mode;\tinitial _mode = 0;
+
+ // verilator lint_off LITENDIAN
+ reg [7:0] mem_narrow [0:31]; //surefire lint_off_line RD_WRT WRTWRT NBAJAM
+ reg [77:0] mem_wide [1024:0]; //surefire lint_off_line RD_WRT WRTWRT NBAJAM
+ reg [7:0] mem_dly_narrow [0:1]; //surefire lint_off_line RD_WRT WRTWRT NBAJAM
+ reg [77:0] mem_dly_wide [1:0]; //surefire lint_off_line RD_WRT WRTWRT NBAJAM
+ reg [34:0] vec_wide;
+ // verilator lint_on LITENDIAN
+
+ reg [31:0] wrd0 [15:0];
+ wire [3:0] sel = 4\'h3;
+ wire [31:0] selout = wrd0[sel];
+
+ // Must take LSBs into account in bit extract widths.
+ wire [15:14] sixt = 2\'b10; // surefire lint_off_line ASWCBB
+ wire [16:14] sixt2 = 3\'b110; // surefire lint_off_line ASWCBB
+ wire [3:0] \tsixfrom = 13;
+ wire [4:0] \tsixfrom2 = 16;
+ wire \tsixtext = sixt[sixfrom];
+ wire \tsixtext2 = sixt2[sixfrom2];
+
+ // Non-power of 2 memory overwriting checks
+ reg [2:0] \tnp2_mem [5:0] /*verilator public*/;
+ reg [2:0] \tnp2_guard [7:6] /*verilator public*/;
+
+ integer \t i;
+
+ always @ (posedge clk) begin
+ if (_mode!=0) begin
+\t wrd0[0] = 32\'h1;
+\t //
+\t for (i=0; i<32; i=i+1) begin //surefire lint_off_line STMFOR
+\t mem_narrow[i] = i[7:0];
+\t mem_wide[i] = {i[7:0],70\'hfeed};
+\t end
+\t //
+\t for (i=0; i<32; i=i+1) begin //surefire lint_off_line STMFOR
+\t if (mem_narrow[i] !== i[7:0]) $stop;
+\t if (mem_wide[i] !== {i[7:0],70\'hfeed}) $stop;
+\t end
+\t //
+\t vec_wide <= 0;
+\t //
+\t np2_guard[6] = 0;
+\t np2_guard[7] = 0;
+\t //
+\t $write(""selout %b %b %b\
+"", selout, sixtext, sixtext2);
+ end
+ if (_mode == 1) begin
+\t _mode <= 2;
+\t //
+\t i=0;
+\t mem_dly_narrow[0] <= ~i[7:0];
+\t mem_dly_wide[0] <= {~i[7:0],70\'hface};
+\t i=1;
+\t mem_dly_narrow[i] <= ~i[7:0];
+\t mem_dly_wide[i] <= {~i[7:0],70\'hface};
+\t //
+\t for (i=0; i<16; i=i+1) begin //surefire lint_off_line STMFOR
+\t // verilator lint_off width
+\t np2_mem[i] = i[2:0]; // surefire lint_off_line ASWSBB
+\t // verilator lint_on width
+\t if (np2_guard[6]!=0 || np2_guard[7]!=0) $stop;
+\t end
+\t // verilator lint_off SELRANGE
+\t if (np2_mem[6] !== np2_mem[7]) begin
+\t $write(""Mem[6]!=Mem[7] during randomize...\
+"");
+\t //$stop; // Random value, so this can happen
+\t end
+\t // verilator lint_on SELRANGE
+\t //if (np2_mem[8] !== np2_mem[9]) $stop; // Enhancement: Illegal indexes, make sure map to X\'s
+\t //
+\t vec_wide[32:31] <= 2\'b11;
+\t vec_wide[34] <= 1\'b1;
+\t $display(""%x"",vec_wide);
+ end
+ if (_mode == 2) begin
+\t _mode <= 3;
+\t //
+\t for (i=0; i<2; i=i+1) begin //surefire lint_off_line STMFOR
+\t if (mem_dly_narrow[i] !== ~i[7:0]) $stop;
+\t if (mem_dly_wide[i] !== {~i[7:0],70\'hface}) $stop;
+\t end
+\t //
+\t //$write (""VW %x %x\
+"", vec_wide[34:32], vec_wide[31:0]);
+\t if (vec_wide != {4\'b101_1,31\'d0}) $stop;
+\t //
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ _mode <= _mode + 1;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2010 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer cyc=0;
+
+ wire monclk = ~clk;
+
+ int \t in;
+ int \t fr_a;
+ int \t fr_b;
+ int \t fr_chk;
+ sub sub (.*);
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d in=%x fr_a=%x b=%x fr_chk=%x\
+"",$time, cyc, in, fr_a, fr_b, fr_chk);
+`endif
+ cyc <= cyc + 1;
+ in <= {in[30:0], in[31]^in[2]^in[0]};
+ if (cyc==0) begin
+\t // Setup
+\t in <= 32\'hd70a4497;
+ end
+ else if (cyc<3) begin
+ end
+ else if (cyc<10) begin
+\t if (fr_chk != fr_a) $stop;
+\t if (fr_chk != fr_b) $stop;
+ end
+ else if (cyc==10) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+
+ always @(posedge t.monclk) begin
+ mon_eval();
+ end
+
+endmodule
+
+import ""DPI-C"" context function void mon_scope_name (input string formatted /*verilator sformat*/ );
+import ""DPI-C"" context function void mon_register_b(string name, int isOut);
+import ""DPI-C"" context function void mon_register_done();
+import ""DPI-C"" context function void mon_eval();
+
+module sub (/*AUTOARG*/
+ // Outputs
+ fr_a, fr_b, fr_chk,
+ // Inputs
+ in
+ );
+
+`systemc_imp_header
+ void mon_class_name(const char* namep);
+ void mon_register_a(const char* namep, void* sigp, bool isOut);
+`verilog
+
+ input int in /*verilator public_flat_rd*/;
+ output int fr_a /*verilator public_flat_rw @(posedge t.monclk)*/;
+ output int fr_b /*verilator public_flat_rw @(posedge t.monclk)*/;
+ output int fr_chk;
+
+ always @* fr_chk = in + 1;
+
+ initial begin
+ // Test the naming
+ $c(""mon_class_name(name());"");
+ mon_scope_name(""%m"");
+ // Scheme A - pass pointer directly
+ $c(""mon_register_a(\\""in\\"",&"",in,"",false);"");
+ $c(""mon_register_a(\\""fr_a\\"",&"",fr_a,"",true);"");
+ // Scheme B - use VPIish callbacks to see what signals exist
+ mon_register_b(""in"", 0);
+ mon_register_b(""fr_b"", 1);
+ mon_register_done();
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Jie Xu.
+//
+
+// change these two parameters to see the speed differences
+`define DATA_WIDTH 8
+`define REP_COUNT4 `DATA_WIDTH/4
+`define REP_COUNT2 `DATA_WIDTH/2
+
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ reg [3:0] count4 = 0;
+ reg [1:0] count2 = 0;
+
+ reg [`DATA_WIDTH-1:0] a = {`REP_COUNT4{4\'b0000}};
+ reg [`DATA_WIDTH-1:0] b = {`REP_COUNT4{4\'b1111}};
+ reg [`DATA_WIDTH-1:0] c = {`REP_COUNT4{4\'b1111}};
+ reg [`DATA_WIDTH-1:0] d = {`REP_COUNT4{4\'b1111}};
+ reg [`DATA_WIDTH-1:0] res1;
+ reg [`DATA_WIDTH-1:0] res2;
+ reg [`DATA_WIDTH-1:0] res3;
+ reg [`DATA_WIDTH-1:0] res4;
+
+ drv1 t_drv1 [`DATA_WIDTH-1:0] (.colSelA(a), .datao(res1));
+ drv2 t_drv2 [`DATA_WIDTH-1:0] (.colSelA(a), .colSelB(b), .datao(res2));
+ drv3 t_drv3 [`DATA_WIDTH-1:0] (.colSelA(a), .colSelB(b), .colSelC(c), .datao(res3));
+ drv4 t_drv4 [`DATA_WIDTH-1:0] (.colSelA(a), .colSelB(b), .colSelC(c), .colSelD(d), .datao(res4));
+
+ always@(posedge clk)
+ begin
+ count2 <= count2 + 1;
+ count4 <= count4 + 1;
+ a <= {`REP_COUNT4{count4}};
+ b <= {`REP_COUNT4{count4}};
+ c <= {`REP_COUNT2{count2}};
+ d <= {`REP_COUNT2{count2}};
+
+ if (res1 != (a)) begin
+ $stop;
+ end
+ if (res2 != (a&b)) begin
+ $stop;
+ end
+ if (res3 != (a&b&c)) begin
+ $stop;
+ end
+ if (res4 != (a&b&c&d)) begin
+ $stop;
+ end
+
+ if (count4 > 10) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+ end
+endmodule
+
+
+module drv1
+ (input colSelA,
+ output datao
+ );
+ assign datao = colSelA;
+endmodule
+
+module drv2
+ (input colSelA,
+ input colSelB,
+ output datao
+ );
+ assign datao = colSelB & colSelA;
+endmodule
+
+module drv3
+ (input colSelA,
+ input colSelB,
+ input colSelC,
+ output datao
+ );
+ assign datao = colSelB & colSelA & colSelC;
+
+endmodule
+
+module drv4
+ (input colSelA,
+ input colSelB,
+ input colSelC,
+ input colSelD,
+ output datao
+ );
+ assign datao = colSelB & colSelA & colSelC & colSelD;
+
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer cyc; initial cyc=0;
+ reg [63:0] crc;
+ reg [63:0] sum;
+
+ reg \t out1;
+ reg [4:0] out2;
+ sub sub (.in(crc[23:0]), .out1(out1), .out2(out2));
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x sum=%x in[3:0]=%x out=%x,%x\
+"",$time, cyc, crc, sum, crc[3:0], out1,out2);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= {sum[62:0], sum[63]^sum[2]^sum[0]} ^ {58\'h0,out1,out2};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h00000000_00000097;
+\t sum <= 64\'h0;
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+`define EXPECTED_SUM 64\'h10204fa5567c8a4b
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module sub (/*AUTOARG*/
+ // Outputs
+ out1, out2,
+ // Inputs
+ in
+ );
+
+ input [23:0] in;
+ output reg \t out1;
+ output reg [4:0] out2;
+
+ always @* begin
+ case (in[3:0]) inside
+\tdefault: {out1,out2} = {1\'b0,5\'h0F}; // Note not last item
+\t4\'h1, 4\'h2, 4\'h3: {out1,out2} = {1\'b1,5\'h01};
+\t4\'h4: {out1,out2} = {1\'b1,5\'h04};
+\t[4\'h6:4\'h5]: {out1,out2} = {1\'b1,5\'h05}; // order backwards, will not match
+\t4\'b100?:/*8,9*/ {out1,out2} = {1\'b1,5\'h08};
+\t[4\'hc:4\'hf]: {out1,out2} = {1\'b1,5\'h0C};
+ endcase
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+ wire ok = 1'b0;
+ // verilator lint_off PINNOCONNECT
+ // verilator lint_off PINCONNECTEMPTY
+ sub sub (.ok(ok), , .nc());
+ // verilator lint_on PINCONNECTEMPTY
+ // verilator lint_on PINNOCONNECT
+endmodule
+
+module sub (input ok, input none, input nc);
+ initial if (ok && none && nc) begin end // No unused warning
+endmodule
+"
+"// DESCRIPTION: Verilator: Simple test of CLkDATA
+//
+// Trigger the CLKDATA detection
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Jie Xu.
+
+localparam ID_MSB = 1;
+
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk,
+ res,
+ res8,
+ res16
+ );
+ input clk;
+ output res;
+ output [7:0] res8;
+ output [15:0] res16;
+
+
+ wire [7:0] clkSet;
+ wire clk_1;
+ wire [2:0] clk_3;
+ wire [3:0] clk_4;
+ wire clk_final;
+ reg [7:0] count;
+
+
+ assign clkSet = {8{clk}};
+ assign clk_4 = clkSet[7:4];
+ assign clk_1 = clk_4[0];;
+
+ // arraysel
+ assign clk_3 = {3{clk_1}};
+ assign clk_final = clk_3[0];
+
+ // the following two assignment triggers the CLKDATA warning
+ // because on LHS there are a mix of signals both CLOCK and
+ // DATA
+ /* verilator lint_off CLKDATA */
+ assign res8 = {clk_3, 1\'b0, clk_4};
+ assign res16 = {count, clk_3, clk_1, clk_4};
+ /* verilator lint_on CLKDATA */
+
+
+ initial
+ count = 0;
+
+
+ always @(posedge clk_final or negedge clk_final) begin
+ count = count + 1;
+ // the following assignment should trigger the CLKDATA warning
+ // because CLOCK signal is used as DATA in sequential block
+ /* verilator lint_off CLKDATA */
+ res <= clk_final;
+ /* verilator lint_on CLKDATA */
+ if ( count == 8\'hf) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Charlie Brej.
+
+module submodule ();
+ // This bug only appears when not inlining
+ // verilator no_inline_module
+ initial begin
+ $write(""d"");
+ end
+ final begin
+ $write(""d"");
+ end
+endmodule
+
+module t ();
+ generate
+ for (genvar i = 0; i < 100; i = i + 1) begin : module_set
+\t submodule u_submodule ();
+ end
+ endgenerate
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Lane Brooks
+
+module t (clk);
+ input clk;
+
+ reg [31:0] state; initial state=0;
+
+ wire A = state[0];
+ wire OE = state[1];
+ wire Z1, Z2, Z3, Z4, Z5, Z6, Z7, Z8, Z9;
+ wire [3:0] Z10;
+ wire Z11;
+
+ Test1 test1(/*AUTOINST*/
+\t // Inouts
+\t .Z1\t\t\t(Z1),
+\t // Inputs
+\t .OE\t\t\t(OE),
+\t .A\t\t\t(A));
+
+ Test2 test2(/*AUTOINST*/
+\t // Inouts
+\t .Z2\t\t\t(Z2),
+\t // Inputs
+\t .OE\t\t\t(OE),
+\t .A\t\t\t(A));
+
+ Test3 test3(/*AUTOINST*/
+\t // Inouts
+\t .Z3\t\t\t(Z3),
+\t // Inputs
+\t .OE\t\t\t(OE),
+\t .A\t\t\t(A));
+
+ Test4 test4(/*AUTOINST*/
+\t // Outputs
+\t .Z4\t\t\t(Z4),
+\t // Inouts
+\t .Z5\t\t\t(Z5));
+
+ Test5 test5(/*AUTOINST*/
+\t // Inouts
+\t .Z6\t\t\t(Z6),
+\t .Z7\t\t\t(Z7),
+\t .Z8\t\t\t(Z8),
+\t .Z9\t\t\t(Z9),
+\t // Inputs
+\t .OE\t\t\t(OE));
+
+ Test6 test6(/*AUTOINST*/
+\t // Inouts
+\t .Z10\t\t\t(Z10[3:0]),
+\t // Inputs
+\t .OE\t\t\t(OE));
+
+ Test7 test7(/*AUTOINST*/
+\t // Outputs
+\t .Z11\t\t\t(Z11),
+\t // Inputs
+\t .state\t\t\t(state[2:0]));
+
+ always @(posedge clk) begin
+ state <= state + 1;
+`ifdef TEST_VERBOSE
+ $write(""[%0t] state=%d Z1=%b 2=%b 3=%b 4=%b 5=%b 6=%b 7=%b 8=%b 9=%b 10=%b 11=%b\
+"",
+\t $time, state, Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8,Z9,Z10,Z11);
+`endif
+
+ if(state == 0) begin
+\t if(Z1 !== 1\'b1) $stop; // tests pullups
+\t if(Z2 !== 1\'b1) $stop;
+\t if(Z3 !== 1\'b1) $stop;
+`ifndef VERILATOR
+\t if(Z4 !== 1\'b1) $stop;
+`endif
+\t if(Z5 !== 1\'b1) $stop;
+\t if(Z6 !== 1\'b1) $stop;
+\t if(Z7 !== 1\'b0) $stop;
+\t if(Z8 !== 1\'b0) $stop;
+\t if(Z9 !== 1\'b1) $stop;
+\t if(Z10 !== 4\'b0001) $stop;
+\t if(Z11 !== 1\'b0) $stop;
+ end
+ else if(state == 1) begin
+\t if(Z1 !== 1\'b1) $stop; // tests pullup
+\t if(Z2 !== 1\'b1) $stop;
+\t if(Z3 !== 1\'b1) $stop;
+`ifndef VERILATOR
+\t if(Z4 !== 1\'b1) $stop;
+`endif
+\t if(Z5 !== 1\'b1) $stop;
+\t if(Z6 !== 1\'b1) $stop;
+\t if(Z7 !== 1\'b0) $stop;
+\t if(Z8 !== 1\'b0) $stop;
+\t if(Z9 !== 1\'b1) $stop;
+\t if(Z10 !== 4\'b0001) $stop;
+\t if(Z11 !== 1\'b1) $stop;
+ end
+ else if(state == 2) begin
+\t if(Z1 !== 1\'b0) $stop; // tests output driver low
+\t if(Z2 !== 1\'b0) $stop;
+\t if(Z3 !== 1\'b1 && Z3 !== 1\'bx) $stop; // Conflicts
+`ifndef VERILATOR
+\t if(Z4 !== 1\'b1) $stop;
+`endif
+\t if(Z5 !== 1\'b1) $stop;
+\t if(Z6 !== 1\'b0) $stop;
+\t if(Z7 !== 1\'b1) $stop;
+\t if(Z8 !== 1\'b1) $stop;
+\t if(Z9 !== 1\'b0) $stop;
+\t if(Z10 !== 4\'b0010) $stop;
+\t //if(Z11 !== 1\'bx) $stop; // Doesn\'t matter
+ end
+ else if(state == 3) begin
+\t if(Z1 !== 1\'b1) $stop; // tests output driver high
+\t if(Z2 !== 1\'b1) $stop;
+\t if(Z3 !== 1\'b1) $stop;
+`ifndef VERILATOR
+\t if(Z4 !== 1\'b1) $stop;
+`endif
+\t if(Z5 !== 1\'b1) $stop;
+\t if(Z6 !== 1\'b0) $stop;
+\t if(Z7 !== 1\'b1) $stop;
+\t if(Z8 !== 1\'b1) $stop;
+\t if(Z9 !== 1\'b0) $stop;
+\t if(Z10 !== 4\'b0010) $stop;
+\t if(Z11 !== 1\'b1) $stop;
+ end
+ else if(state == 4) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+ pullup(Z1);
+ pullup(Z2);
+ pullup(Z3);
+ pullup(Z4);
+ pullup(Z5);
+ pullup(Z6);
+ pulldown(Z7);
+ pullup(Z8);
+ pulldown(Z9);
+ pulldown pd10[3:0] (Z10);
+endmodule
+
+
+module Test1(input OE, input A, inout Z1);
+ assign Z1 = (OE) ? A : 1\'bz;
+endmodule
+
+module Test2(input OE, input A, inout Z2);
+ assign Z2 = (OE) ? A : 1\'bz;
+endmodule
+
+
+// mixed low-Z and tristate
+module Test3(input OE, input A, inout Z3);
+ assign Z3 = (OE) ? A : 1\'bz;
+ assign Z3 = 1\'b1;
+endmodule
+
+
+// floating output and inout
+`ifndef VERILATOR
+// Note verilator doesn\'t know to make Z4 a tristate unless marked an inout
+`endif
+module Test4(output Z4, inout Z5);
+endmodule
+
+
+// AND gate tristates
+module Test5(input OE, inout Z6, inout Z7, inout Z8, inout Z9);
+ assign Z6 = (OE) ? 1\'b0 : 1\'bz;
+ assign Z7 = (OE) ? 1\'b1 : 1\'bz;
+ assign Z8 = (OE) ? 1\'bz : 1\'b0;
+ assign Z9 = (OE) ? 1\'bz : 1\'b1;
+endmodule
+
+// AND gate tristates
+module Test6(input OE, inout [3:0] Z10);
+ wire [1:0] i;
+ Test6a a (.OE(OE), .Z({Z10[0],Z10[1]}));
+ Test6a b (.OE(~OE), .Z({Z10[2],Z10[0]}));
+endmodule
+
+module Test6a(input OE, inout [1:0] Z);
+ assign Z = (OE) ? 2\'b01 : 2\'bzz;
+endmodule
+
+module Test7(input [2:0] state, output reg Z11);
+ always @(*) begin
+ casez (state)
+\t3\'b000: Z11 = 1\'b0;
+\t3\'b0?1: Z11 = 1\'b1;
+\tdefault: Z11 = 1\'bx;
+ endcase
+ end
+endmodule
+
+// This is not implemented yet
+//module Test3(input OE, input A, inout Z3);
+// always @(*) begin
+// if(OE) begin
+//\t Z3 = A;
+// end else begin
+//\t Z3 = 1\'bz;
+// end
+// end
+//endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t;
+
+ // Arguable, but we won\'t throw a hidden warning on tcp_port
+ parameter tcp_port = 5678;
+ import ""DPI-C"" function int dpii_func ( input integer tcp_port,
+ output longint obj );
+ // \'t\' is hidden:
+ integer t;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [31:0] in = crc[31:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [3:0]\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[3:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(in[31:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {60\'h0, out};
+
+ // What checksum will we end up with
+`define EXPECTED_SUM 64\'h1a0d07009b6a30d2
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ clk, in
+ );
+
+ input clk;
+ input [31:0] in;
+ output [3:0] out;
+
+ assign \tout[0] = in[3:0] ==? 4\'b1001;
+ assign \tout[1] = in[3:0] !=? 4\'b1001;
+ assign \tout[2] = in[3:0] ==? 4\'bx01x;
+ assign \tout[3] = in[3:0] !=? 4\'bx01x;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ reg [7:0] cyc; initial cyc=0;
+
+ reg [31:0] loops;
+ reg [31:0] loops2;
+ integer i;
+
+ always @ (posedge clk) begin
+ cyc <= cyc+8\'d1;
+ if (cyc == 8\'d1) begin
+\t $write(""[%0t] t_loop: Running\
+"",$time);
+\t // Unwind <
+\t loops = 0;
+\t loops2 = 0;
+\t for (i=0; i<16; i=i+1) begin
+\t loops = loops + i;\t\t// surefire lint_off_line ASWEMB
+\t loops2 = loops2 + i;\t// surefire lint_off_line ASWEMB
+\t end
+\t if (i !== 16) $stop;
+\t if (loops !== 120) $stop;
+\t if (loops2 !== 120) $stop;
+\t // Unwind <=
+\t loops = 0;
+\t for (i=0; i<=16; i=i+1) begin
+\t loops = loops + 1;
+\t end
+\t if (i !== 17) $stop;
+\t if (loops !== 17) $stop;
+\t // Don\'t unwind breaked loops
+\t loops = 0;
+\t for (i=0; i<16; i=i+1) begin
+\t loops = loops + 1;
+\t if (i==7) i=99;\t// break out of loop
+\t end
+\t if (loops !== 8) $stop;
+\t // Don\'t unwind large loops!
+\t loops = 0;
+\t for (i=0; i<100000; i=i+1) begin
+\t loops = loops + 1;
+\t end
+\t if (loops !== 100000) $stop;
+\t // Test post-increment
+\t loops = 0;
+\t for (i=0; i<=16; i++) begin
+\t loops = loops + 1;
+\t end
+\t if (i !== 17) $stop;
+\t if (loops !== 17) $stop;
+\t // Test pre-increment
+\t loops = 0;
+\t for (i=0; i<=16; ++i) begin
+\t loops = loops + 1;
+\t end
+\t if (i !== 17) $stop;
+\t if (loops !== 17) $stop;
+\t // Test post-decrement
+\t loops = 0;
+\t for (i=16; i>=0; i--) begin
+\t loops = loops + 1;
+\t end
+\t if (i !== -1) $stop;
+\t if (loops !== 17) $stop;
+\t // Test pre-decrement
+\t loops = 0;
+\t for (i=16; i>=0; --i) begin
+\t loops = loops + 1;
+\t end
+\t if (i !== -1) $stop;
+\t if (loops !== 17) $stop;
+\t //
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ reg \t _ranit;
+
+ reg [2:0] a;
+ reg [33:0] wide;
+ reg \t unused_r;
+
+ initial _ranit = 0;
+
+ always @ (posedge clk) begin : blockName
+ begin\t// Verify begin/begin is legal
+\t unused_r <= 1\'b1;
+ end
+ begin end\t// Verify empty is legal
+ end
+
+ wire one = 1\'b1;
+ wire [7:0] rand_bits = 8\'b01xx_xx10;
+
+ always @ (posedge clk) begin
+ if (!_ranit) begin
+\t _ranit <= 1;
+\t //
+\t a = 3\'b1xx;
+\t wide <= 34\'bx1_00000000_xxxxxxxx_00000000_xxxx0000;
+\t if (one !== 1\'b1) $stop;
+\t if ((rand_bits & 8\'b1100_0011) !== 8\'b0100_0010) $stop;
+\t //
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+ // verilator lint_off UNUSED
+ wire _unused_ok = |{1\'b1, wide};
+ // verilator lint_on UNUSED
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+// Anonymous
+struct packed {
+ logic [31:0] val1;
+ logic [31:0] val2;
+} struct1;
+
+struct packed {
+ logic [31:0] val3;
+ logic [31:0] val4;
+} struct2;
+
+module t (
+ output [63:0] \ts1,
+ output [63:0] \ts2
+);
+ initial struct1 = 64'h123456789_abcdef0;
+ always_comb s1 = struct1;
+ initial struct2 = 64'h123456789_abcdef0;
+ always_comb s2 = struct2;
+endmodule
+
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2015 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ outwires,
+ // Inputs
+ inwires
+ );
+ input [7:0] inwires [12:10];
+ output wire [7:0] outwires [12:10];
+
+ assign outwires[10] = inwires[11];
+ assign outwires[11] = inwires[12];
+ assign outwires[12] = inwires[13];\t// must be an error here
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ integer cyc; initial cyc=0;
+
+ wire signed [7:0] sgn_wide;
+ wire [7:0] \t unsgn_wide;
+
+ // The instantiation will Z extend, not sign extend
+ // verilator lint_off WIDTH
+ sub sub (.clk,
+\t .sgn(sgn_wide), .unsgn(unsgn_wide),
+\t .iss(3\'sh7), .isu(3\'h7),
+\t .ius(3\'sh7), .iuu(3\'h7));
+ // verilator lint_on WIDTH
+
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""out: \'b%b \'b%b\
+"", sgn_wide, unsgn_wide);
+`endif
+ if (sgn_wide[2:0] != 3\'sh7) $stop;
+ if (unsgn_wide[2:0] != 3\'h7) $stop;
+ // Simulators differ here.
+ if (sgn_wide !== 8\'sbzzzzz111 // z-extension - NC
+\t && sgn_wide !== 8\'sb11111111) $stop; // sign extension - VCS
+ if (unsgn_wide !== 8\'sbzzzzz111
+\t && unsgn_wide!== 8\'sb00000111) $stop;
+ cyc <= cyc + 1;
+ if (cyc==3) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module sub (
+\t input clk,
+\t output wire signed [2:0] sgn,
+\t output wire [2:0] unsgn,
+\t input signed [7:0] iss,
+\t input signed [7:0] isu,
+\t input [7:0] ius,
+\t input [7:0] iuu);
+ assign sgn = 3\'sh7;
+ assign unsgn = 3\'h7;
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""in: %x %x %x %x\
+"", iss, isu, ius, iuu);
+ if (iss != 8\'hff) $stop;
+ if (isu != 8\'h07) $stop;
+ if (ius != 8\'hff) $stop;
+ if (iuu != 8\'h07) $stop;
+`endif
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+module t (clk);
+
+ sub sub ();
+
+ input clk;
+ integer cyc=1;
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==2) begin
+\t // Not $finish; as we don\'t want a message to scroll by
+\t $c(""Verilated::gotFinish(true);"");
+ end
+ end
+endmodule
+
+module sub;
+ /* verilator public_module */
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ // Life analysis checks
+ reg [15:0] life;
+
+ // Ding case
+ reg [7:0] din;
+ reg [15:0] fixin;
+ always @* begin
+ fixin = {din[7:0],din[7:0]};
+ case (din[1:0])
+\t2\'b00: begin
+\t fixin = {fixin[14:0], 1\'b1};
+\t if (cyc==101) $display(""Prevent ?: optimization a"");
+\tend
+\t2\'b01: begin
+\t fixin = {fixin[13:0], 2\'b11};
+\t if (cyc==101) $display(""Prevent ?: optimization b"");
+\tend
+\t2\'b10: begin
+\t fixin = {fixin[12:0], 3\'b111};
+\t if (cyc==101) $display(""Prevent ?: optimization c"");
+\tend
+\t2\'b11: begin
+\t fixin = {fixin[11:0], 4\'b1111};
+\t if (cyc==101) $display(""Prevent ?: optimization d"");
+\tend
+ endcase
+ end
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc<=cyc+1;
+\t if (cyc==1) begin
+\t life = 16\'h8000;\t// Dropped
+\t life = 16\'h0010;\t// Used below
+\t if (life != 16\'h0010) $stop;
+\t //
+\t life = 16\'h0020;\t// Used below
+\t if ($time < 10000)
+\t if (life != 16\'h0020) $stop;
+\t //
+\t life = 16\'h8000;\t// Dropped
+\t if ($time > 100000) begin
+\t if ($time != 0) $stop;\t// Prevent conversion to ?:
+\t life = 16\'h1030;
+\t end
+\t else
+\t life = 16\'h0030;
+\t if (life != 16\'h0030) $stop;
+\t //
+\t life = 16\'h0040;\t// Not dropped, no else below
+\t if ($time > 100000)
+\t life = 16\'h1040;
+\t if (life != 16\'h0040) $stop;
+\t //
+\t life = 16\'h8000;\t// Dropped
+\t if ($time > 100000) begin
+\t life = 16\'h1050;
+\t if (life != 0) $stop; // Ignored, as set is first
+\t end
+\t else begin
+\t if ($time > 100010)
+\t\t life = 16\'h1050;
+\t else life = 16\'h0050;
+\t end
+\t if (life != 16\'h0050) $stop;
+\t end
+\t if (cyc==2) begin
+\t din <= 8\'haa;
+\t end
+\t if (cyc==3) begin
+\t din <= 8\'hfb;
+\t if (fixin != 16\'h5557) $stop;
+\t end
+\t if (cyc==4) begin
+\t din <= 8\'h5c;
+\t if (fixin != 16\'hbfbf) $stop;
+\t end
+\t if (cyc==5) begin
+\t din <= 8\'hed;
+\t if (fixin != 16\'hb8b9) $stop;
+\t end
+\t if (cyc==6) begin
+\t if (fixin != 16\'hb7b7) $stop;
+\t end
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+
+// verilator lint_off WIDTH
+// verilator lint_off VARHIDDEN
+
+module t (
+ clk
+ );
+ input clk;
+ integer \tcyc=0;
+ reg [63:0] \tcrc; initial crc = 64\'h1;
+
+ chk chk (.clk\t(clk),
+\t .rst_l\t(1\'b1),
+\t .expr\t(|crc)
+\t );
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ if (cyc==0) begin
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module chk (input clk, input rst_l, input expr);
+
+ integer errors; initial errors = 0;
+
+ task printerr;
+ input [8*64:1] msg;
+ begin
+\t errors = errors + 1;
+\t $write(""%%Error: %0s\
+"", msg);
+\t $stop;
+ end
+ endtask
+
+ always @(posedge clk) begin
+ if (rst_l) begin
+\t if (expr == 1\'b0) begin
+ printerr(""expr not asserted"");
+\t end
+ end
+ end
+
+ wire noxs = ((expr ^ expr) == 1\'b0);
+
+ reg \t hasx;
+ always @ (noxs) begin
+ if (noxs) begin
+ hasx = 1\'b0;
+ end
+ else begin
+ hasx = 1\'b1;
+ end
+ end
+
+ always @(posedge clk) begin
+ if (rst_l) begin
+ if (hasx) begin
+ printerr(""expr has unknowns"");
+ end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc=1;
+
+ counter_io c1_data();
+ counter_io c2_data();
+ //counter_io c3_data;\t// IEEE illegal, and VCS doesn\'t allow non-() as it does with cells
+ counter_io c3_data();
+
+ counter_ansi c1 (.clkm(clk),
+\t\t .c_data(c1_data),
+\t\t .i_value(4\'h1));
+ counter_ansi c2 (.clkm(clk),
+\t\t .c_data(c2_data),
+\t\t .i_value(4\'h2));
+`ifdef VERILATOR counter_ansi `else counter_nansi `endif
+ /**/ \t c3 (.clkm(clk),
+\t\t .c_data(c3_data),
+\t\t .i_value(4\'h3));
+
+ initial begin
+ c1_data.value = 4\'h4;
+ c2_data.value = 4\'h5;
+ c3_data.value = 4\'h6;
+ end
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc<2) begin
+\t c1_data.reset <= 1;
+\t c2_data.reset <= 1;
+\t c3_data.reset <= 1;
+ end
+ if (cyc==2) begin
+\t c1_data.reset <= 0;
+\t c2_data.reset <= 0;
+\t c3_data.reset <= 0;
+ end
+ if (cyc==3) begin
+\t if (c1_data.get_lcl() != 12345) $stop;
+ end
+ if (cyc==20) begin
+\t $write(""[%0t] c1 cyc%0d: c1 %0x %0x c2 %0x %0x c3 %0x %0x\
+"", $time, cyc,
+\t\tc1_data.value, c1_data.reset,
+\t\tc2_data.value, c2_data.reset,
+\t\tc3_data.value, c3_data.reset);
+\t if (c1_data.value != 2) $stop;
+\t if (c2_data.value != 3) $stop;
+\t if (c3_data.value != 4) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+interface counter_io;
+ logic [3:0] value;
+ logic reset;
+ integer lcl;
+ task set_lcl (input integer a); lcl=a; endtask
+ function integer get_lcl (); return lcl; endfunction
+endinterface
+
+interface ifunused;
+ logic unused;
+endinterface
+
+module counter_ansi
+ (
+ input clkm,
+ counter_io c_data,
+ input logic [3:0] i_value
+ );
+
+ initial begin
+ c_data.set_lcl(12345);
+ end
+
+ always @ (posedge clkm) begin
+ c_data.value <= c_data.reset ? i_value : c_data.value + 1;
+ end
+endmodule : counter_ansi
+
+`ifndef VERILATOR
+// non-ansi modports not seen in the wild yet. Verilog-Perl needs parser improvement too.
+module counter_nansi(clkm, c_data, i_value);
+ input clkm;
+ counter_io c_data;
+ input logic [3:0] i_value;
+
+ always @ (posedge clkm) begin
+ c_data.value <= c_data.reset ? i_value : c_data.value + 1;
+ end
+endmodule : counter_nansi
+`endif
+
+module modunused (ifunused ifinunused);
+ ifunused ifunused();
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ localparam // synopsys enum En_State
+\t EP_State_IDLE =\t\t{3\'b000,5\'d00},
+\t EP_State_CMDSHIFT0 =\t{3\'b001,5\'d00},
+\t EP_State_CMDSHIFT13 =\t{3\'b001,5\'d13},
+\t EP_State_CMDSHIFT14 =\t{3\'b001,5\'d14},
+\t EP_State_CMDSHIFT15 =\t{3\'b001,5\'d15},
+\t EP_State_CMDSHIFT16 =\t{3\'b001,5\'d16},
+\t EP_State_DWAIT =\t\t{3\'b010,5\'d00},
+\t EP_State_DSHIFT0 =\t{3\'b100,5\'d00},
+\t EP_State_DSHIFT1 =\t{3\'b100,5\'d01},
+\t EP_State_DSHIFT15 =\t{3\'b100,5\'d15};
+
+ reg [7:0]\t/* synopsys enum En_State */
+\t\tm_state_xr;\t\t// Last command, for debugging
+ /*AUTOASCIIENUM(""m_state_xr"", ""m_stateAscii_xr"", ""EP_State_"")*/
+ // Beginning of automatic ASCII enum decoding
+ reg [79:0]\t\tm_stateAscii_xr;\t// Decode of m_state_xr
+ always @(m_state_xr) begin
+ case ({m_state_xr})
+\tEP_State_IDLE: m_stateAscii_xr = ""idle "";
+\tEP_State_CMDSHIFT0: m_stateAscii_xr = ""cmdshift0 "";
+\tEP_State_CMDSHIFT13: m_stateAscii_xr = ""cmdshift13"";
+\tEP_State_CMDSHIFT14: m_stateAscii_xr = ""cmdshift14"";
+\tEP_State_CMDSHIFT15: m_stateAscii_xr = ""cmdshift15"";
+\tEP_State_CMDSHIFT16: m_stateAscii_xr = ""cmdshift16"";
+\tEP_State_DWAIT: m_stateAscii_xr = ""dwait "";
+\tEP_State_DSHIFT0: m_stateAscii_xr = ""dshift0 "";
+\tEP_State_DSHIFT1: m_stateAscii_xr = ""dshift1 "";
+\tEP_State_DSHIFT15: m_stateAscii_xr = ""dshift15 "";
+\tdefault: m_stateAscii_xr = ""%Error "";
+ endcase
+ end
+ // End of automatics
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t //$write(""%d %x %x %x\
+"", cyc, data, wrapcheck_a, wrapcheck_b);
+\t if (cyc==1) begin
+\t m_state_xr <= EP_State_IDLE;
+\t end
+\t if (cyc==2) begin
+\t if (m_stateAscii_xr != ""idle "") $stop;
+\t m_state_xr <= EP_State_CMDSHIFT13;
+\t end
+\t if (cyc==3) begin
+\t if (m_stateAscii_xr != ""cmdshift13"") $stop;
+\t m_state_xr <= EP_State_CMDSHIFT16;
+\t end
+\t if (cyc==4) begin
+\t if (m_stateAscii_xr != ""cmdshift16"") $stop;
+\t m_state_xr <= EP_State_DWAIT;
+\t end
+\t if (cyc==9) begin
+\t if (m_stateAscii_xr != ""dwait "") $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ parameter NPAD = 4;
+
+ tri \t\tpad [NPAD-1:0]; // Array
+ wire\t[NPAD-1:0] data0 = crc[0 +: 4];
+ wire\t[NPAD-1:0] data1 = crc[8 +: 4];
+ wire\t[NPAD-1:0] en = crc[16 +: 4];
+
+ for (genvar g=0; g> i); // surefire lint_off_line LATASS
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Simple test of unoptflat
+//
+// Trigger the DETECTARRAY error.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Jeremy Bennett.
+
+localparam ID_MSB = 1;
+
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ typedef struct packed {
+ logic [ID_MSB:0] \tid;
+ } context_t;
+
+ context_t tsb;
+
+ assign tsb.id = {tsb.id[0], clk};
+
+ initial begin
+ tsb.id = 0;
+ end
+
+ always @(posedge clk or negedge clk) begin
+
+`ifdef TEST_VERBOSE
+ $write(""tsb.id = %x\
+"", tsb.id);
+`endif
+
+ if (tsb.id[1] != 0) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+`ifdef VERILATOR
+ `define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0)
+`else
+ `define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); end while(0)
+`endif
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg [60:0] p;
+ reg [60:0] a;
+ reg [20:0] b;
+ reg [60:0] shifted;
+
+ always @* begin
+ p = a[60:0] ** b[20:0];
+ shifted = 2 ** b[20:0];
+ end
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+`ifdef TEST_VERBOSE
+\t $write(""%0x %x %x\
+"", cyc, p, shifted);
+`endif
+\t // Constant versions
+\t `checkh(61\'h1 ** 21\'h31, 61\'h1);
+\t `checkh(61\'h2 ** 21\'h10, 61\'h10000);
+\t `checkh(61\'d10 ** 21\'h3, 61\'h3e8);
+\t `checkh(61\'h3 ** 21\'h7, 61\'h88b);
+`ifndef VCS
+\t `checkh(61\'h7ab3811219 ** 21\'ha6e30, 61\'h01ea58c703687e81);
+`endif
+\t if (cyc==1) begin
+\t a <= 61\'h0;
+\t b <= 21\'h0;
+\t end
+\t if (cyc==2) begin
+\t a <= 61\'h0;
+\t b <= 21\'h3;
+\t end
+\t if (cyc==3) begin
+\t a <= 61\'h1;
+\t b <= 21\'h31;
+\t end
+\t if (cyc==4) begin
+\t a <= 61\'h2;
+\t b <= 21\'h10;
+\t end
+\t if (cyc==5) begin
+\t a <= 61\'d10;
+\t b <= 21\'d3;
+\t end
+\t if (cyc==6) begin
+\t a <= 61\'d3;
+\t b <= 21\'d7;
+\t end
+\t if (cyc==7) begin
+\t a <= 61\'h7ab3811219;
+\t b <= 21\'ha6e30;
+\t end
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ case (cyc)
+\t32\'d00: ;
+\t32\'d01: ;
+\t32\'d02: ; // 0^x is indeterminate
+\t32\'d03: ; // 0^x is indeterminate
+\t32\'d04: `checkh(p, 61\'h1);
+\t32\'d05: `checkh(p, 61\'h10000);
+\t32\'d06: `checkh(p, 61\'h3e8);
+\t32\'d07: `checkh(p, 61\'h88b);
+\t32\'d08: `checkh(p, 61\'h01ea58c703687e81);
+\t32\'d09: `checkh(p, 61\'h01ea58c703687e81);
+\tdefault: $stop;
+ endcase
+ case (cyc)
+\t32\'d00: ;
+\t32\'d01: ;
+\t32\'d02: `checkh(shifted, 61\'h0000000000000001);
+\t32\'d03: `checkh(shifted, 61\'h0000000000000008);
+\t32\'d04: `checkh(shifted, 61\'h0002000000000000);
+\t32\'d05: `checkh(shifted, 61\'h0000000000010000);
+\t32\'d06: `checkh(shifted, 61\'h0000000000000008);
+\t32\'d07: `checkh(shifted, 61\'h0000000000000080);
+\t32\'d08: `checkh(shifted, 61\'h0000000000000000);
+\t32\'d09: `checkh(shifted, 61\'h0000000000000000);
+\tdefault: $stop;
+ endcase
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+ reg \t _ranit;
+
+ reg [2:0] xor3;
+ reg [1:0] xor2;
+ reg [0:0] xor1;
+ reg [2:0] ma, mb;
+ reg [9:0] mc;
+ reg [4:0] mr1;
+ reg [30:0] mr2;
+
+ reg [67:0] sh1;
+ reg [67:0] shq;
+
+ wire foo, bar; assign {foo,bar} = 2\'b1_0;
+
+ // surefire lint_off STMINI
+ initial _ranit = 0;
+
+ wire [4:0] cond_check = (( xor2 == 2\'b11) ? 5\'h1
+ : (xor2 == 2\'b00) ? 5\'h2
+\t\t\t : (xor2 == 2\'b01) ? 5\'h3
+\t\t\t : 5\'h4);
+
+ wire ctrue = 1\'b1 ? cond_check[1] : cond_check[0];
+ wire cfalse = 1\'b0 ? cond_check[1] : cond_check[0];
+ wire cif = cond_check[2] ? cond_check[1] : cond_check[0];
+ wire cifn = (!cond_check[2]) ? cond_check[1] : cond_check[0];
+
+ wire [4:0] doubleconc = {1\'b0, 1\'b1, 1\'b0, cond_check[0], 1\'b1};
+
+ wire zero = 1\'b0;
+ wire one = 1\'b1;
+ wire [5:0] rep6 = {6{one}};
+
+ // verilator lint_off WIDTH
+ localparam [3:0] bug764_p11 = 1\'bx;
+ // verilator lint_on WIDTH
+
+ always @ (posedge clk) begin
+ if (!_ranit) begin
+\t _ranit <= 1;
+
+\t if (rep6 != 6\'b111111) $stop;
+\t if (!one) $stop;
+\t if (~one) $stop;
+
+\t if (( 1\'b0 ? 3\'h3 : 1\'b0 ? 3\'h2 : 1\'b1 ? 3\'h1 : 3\'h0) !== 3\'h1) $stop;
+\t // verilator lint_off WIDTH
+\t if (( 8\'h10 + 1\'b0 ? 8\'he : 8\'hf) !== 8\'he) $stop; // + is higher than ?
+\t // verilator lint_on WIDTH
+
+\t // surefire lint_off SEQASS
+\t xor1 = 1\'b1;
+\t xor2 = 2\'b11;
+\t xor3 = 3\'b111;
+\t // verilator lint_off WIDTH
+\t if (1\'b1 & | (!xor3)) $stop;
+\t // verilator lint_on WIDTH
+\t if ({1{xor1}} != 1\'b1) $stop;
+\t if ({4{xor1}} != 4\'b1111) $stop;
+\t if (!(~xor1) !== ~(!xor1)) $stop;
+\t if ((^xor1) !== 1\'b1) $stop;
+\t if ((^xor2) !== 1\'b0) $stop;
+\t if ((^xor3) !== 1\'b1) $stop;
+\t if (~(^xor2) !== 1\'b1) $stop;
+\t if (~(^xor3) !== 1\'b0) $stop;
+\t if ((^~xor1) !== 1\'b0) $stop;
+\t if ((^~xor2) !== 1\'b1) $stop;
+\t if ((^~xor3) !== 1\'b0) $stop;
+\t if ((~^xor1) !== 1\'b0) $stop;
+\t if ((~^xor2) !== 1\'b1) $stop;
+\t if ((~^xor3) !== 1\'b0) $stop;
+\t xor1 = 1\'b0;
+\t xor2 = 2\'b10;
+\t xor3 = 3\'b101;
+\t if ((^xor1) !== 1\'b0) $stop;
+\t if ((^xor2) !== 1\'b1) $stop;
+\t if ((^xor3) !== 1\'b0) $stop;
+\t if (~(^xor2) !== 1\'b0) $stop;
+\t if (~(^xor3) !== 1\'b1) $stop;
+\t if ((^~xor1) !== 1\'b1) $stop;
+\t if ((^~xor2) !== 1\'b0) $stop;
+\t if ((^~xor3) !== 1\'b1) $stop;
+\t if ((~^xor1) !== 1\'b1) $stop;
+\t if ((~^xor2) !== 1\'b0) $stop;
+\t if ((~^xor3) !== 1\'b1) $stop;
+
+\t ma = 3\'h3;
+ mb = 3\'h4;
+\t mc = 10\'h5;
+
+ mr1 = ma * mb; \t // Lint ASWESB: Assignment width mismatch
+\t mr2 = 30\'h5 * mc; \t // Lint ASWESB: Assignment width mismatch
+\t if (mr1 !== 5\'d12) $stop;
+\t if (mr2 !== 31\'d25) $stop; // Lint CWECBB: Comparison width mismatch
+
+\t sh1 = 68\'hf_def1_9abc_5678_1234;
+\t shq = sh1 >> 16;
+\t if (shq !== 68\'hf_def1_9abc_5678) $stop;
+\t shq = sh1 << 16; \t // Lint ASWESB: Assignment width mismatch
+\t if (shq !== 68\'h1_9abc_5678_1234_0000) $stop;
+
+\t // surefire lint_on SEQASS
+
+\t // Test display extraction widthing
+\t $display(""[%0t] %x %x %x(%d)"", $time, shq[2:0], shq[2:0]<<2, xor3[2:0], xor3[2:0]);
+
+\t // bug736
+\t //verilator lint_off WIDTH
+\t if ((~| 4\'b0000) != 4\'b0001) $stop;
+\t if ((~| 4\'b0010) != 4\'b0000) $stop;
+\t if ((~& 4\'b1111) != 4\'b0000) $stop;
+\t if ((~& 4\'b1101) != 4\'b0001) $stop;
+\t //verilator lint_on WIDTH
+
+\t // bug764
+\t //verilator lint_off WIDTH
+\t // X does not sign extend
+\t if (bug764_p11 !== 4\'b000x) $stop;
+\t if (~& bug764_p11 !== 1\'b1) $stop;
+\t //verilator lint_on WIDTH
+\t // However IEEE says for constants in 2012 5.7.1 that smaller-sizes do extend
+\t if (4\'bx !== 4\'bxxxx) $stop;
+\t if (4\'bz !== 4\'bzzzz) $stop;
+\t if (4\'b1 !== 4\'b0001) $stop;
+
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+
+ reg [63:0] m_data_pipe2_r;
+ reg [31:0] m_corr_data_w0, m_corr_data_w1;
+ reg [7:0] m_corr_data_b8;
+ initial begin
+ m_data_pipe2_r = 64\'h1234_5678_9abc_def0;
+ {m_corr_data_b8, m_corr_data_w1, m_corr_data_w0} = { m_data_pipe2_r[63:57], 1\'b0,\t//m_corr_data_b8 [7:0]
+\t\t\t\t\t\t\t m_data_pipe2_r[56:26], 1\'b0,\t//m_corr_data_w1 [31:0]
+\t\t\t\t\t\t\t m_data_pipe2_r[25:11], 1\'b0,\t//m_corr_data_w0 [31:16]
+\t\t\t\t\t\t\t m_data_pipe2_r[10:04], 1\'b0,\t//m_corr_data_w0 [15:8]
+\t\t\t\t\t\t\t m_data_pipe2_r[03:01], 1\'b0,\t//m_corr_data_w0 [7:4]
+\t\t\t\t\t\t\t m_data_pipe2_r[0], 3\'b000\t//m_corr_data_w0 [3:0]
+\t\t\t\t\t\t\t };
+ if (m_corr_data_w0 != 32\'haf36de00) $stop;
+ if (m_corr_data_w1 != 32\'h1a2b3c4c) $stop;
+ if (m_corr_data_b8 != 8\'h12) $stop;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ reg [7:0] cyc; initial cyc=0;
+
+ reg [31:0] loops;
+ reg [31:0] loops2;
+
+ always @ (posedge clk) begin
+ cyc <= cyc+8\'d1;
+ if (cyc == 8\'d1) begin
+\t $write(""[%0t] t_loop: Running\
+"",$time);
+\t // Unwind <
+\t loops = 0;
+\t loops2 = 0;
+\t for (int i=0; i<16; i=i+1) begin
+\t loops = loops + i;\t\t// surefire lint_off_line ASWEMB
+\t loops2 = loops2 + i;\t// surefire lint_off_line ASWEMB
+\t end
+\t if (loops !== 120) $stop;
+\t if (loops2 !== 120) $stop;
+\t // Check we can declare the same signal twice
+\t loops = 0;
+\t for (int i=0; i<=16; i=i+1) begin
+\t loops = loops + 1;
+\t end
+\t if (loops !== 17) $stop;
+\t // Check type is correct
+\t loops = 0;
+\t for (byte unsigned i=5; i>4; i=i+1) begin
+\t loops = loops + 1;
+\t end
+\t if (loops !== 251) $stop;
+\t // Check large loops
+\t loops = 0;
+\t for (int i=0; i<100000; i=i+1) begin
+\t loops = loops + 1;
+\t end
+\t if (loops !== 100000) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+
+ reg [43:0] mi;
+ reg \t sel;
+ reg [3:0] sel2;
+
+ always @ (posedge clk) begin
+ mi = 44\'h123;
+ sel = mi[44];
+ sel2 = mi[44:41];
+ $write (""Bad select %x %x\
+"", sel, sel2);
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Iztok Jeras.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ localparam NO = 10; // number of access events
+
+ // packed structures
+ struct packed {
+ logic e0;
+ logic [1:0] e1;
+ logic [3:0] e2;
+ logic [7:0] e3;
+ } struct_bg; // big endian structure
+ /* verilator lint_off LITENDIAN */
+ struct packed {
+ logic e0;
+ logic [0:1] e1;
+ logic [0:3] e2;
+ logic [0:7] e3;
+ } struct_lt; // little endian structure
+ /* verilator lint_on LITENDIAN */
+
+ localparam WS = 15; // $bits(struct_bg)
+
+ integer cnt = 0;
+
+ // event counter
+ always @ (posedge clk)
+ begin
+ cnt <= cnt + 1;
+ end
+
+ // finish report
+ always @ (posedge clk)
+ if ((cnt[30:2]==NO) && (cnt[1:0]==2\'d0)) begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+ // big endian
+ always @ (posedge clk)
+ if (cnt[1:0]==2\'d0) begin
+ // initialize to defaaults (all bits to 0)
+ if (cnt[30:2]==0) struct_bg <= \'0;
+ else if (cnt[30:2]==1) struct_bg <= \'0;
+ else if (cnt[30:2]==2) struct_bg <= \'0;
+ else if (cnt[30:2]==3) struct_bg <= \'0;
+ else if (cnt[30:2]==4) struct_bg <= \'0;
+ else if (cnt[30:2]==5) struct_bg <= \'0;
+ end else if (cnt[1:0]==2\'d1) begin
+ // write value to structure
+ if (cnt[30:2]==0) begin end
+ else if (cnt[30:2]==1) struct_bg <= \'1;
+ else if (cnt[30:2]==2) struct_bg.e0 <= \'1;
+ else if (cnt[30:2]==3) struct_bg.e1 <= \'1;
+ else if (cnt[30:2]==4) struct_bg.e2 <= \'1;
+ else if (cnt[30:2]==5) struct_bg.e3 <= \'1;
+ end else if (cnt[1:0]==2\'d2) begin
+ // check structure value
+ if (cnt[30:2]==0) begin if (struct_bg !== 15\'b000000000000000) begin $display(""%b"", struct_bg); $stop(); end end
+ else if (cnt[30:2]==1) begin if (struct_bg !== 15\'b111111111111111) begin $display(""%b"", struct_bg); $stop(); end end
+ else if (cnt[30:2]==2) begin if (struct_bg !== 15\'b100000000000000) begin $display(""%b"", struct_bg); $stop(); end end
+ else if (cnt[30:2]==3) begin if (struct_bg !== 15\'b011000000000000) begin $display(""%b"", struct_bg); $stop(); end end
+ else if (cnt[30:2]==4) begin if (struct_bg !== 15\'b000111100000000) begin $display(""%b"", struct_bg); $stop(); end end
+ else if (cnt[30:2]==5) begin if (struct_bg !== 15\'b000000011111111) begin $display(""%b"", struct_bg); $stop(); end end
+ end else if (cnt[1:0]==2\'d3) begin
+ // read value from structure (not a very good test for now)
+ if (cnt[30:2]==0) begin if (struct_bg !== {WS{1\'b0}}) $stop(); end
+ else if (cnt[30:2]==1) begin if (struct_bg !== {WS{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==2) begin if (struct_bg.e0 !== { 1{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==3) begin if (struct_bg.e1 !== { 2{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==4) begin if (struct_bg.e2 !== { 4{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==5) begin if (struct_bg.e3 !== { 8{1\'b1}}) $stop(); end
+ end
+
+ // little endian
+ always @ (posedge clk)
+ if (cnt[1:0]==2\'d0) begin
+ // initialize to defaaults (all bits to 0)
+ if (cnt[30:2]==0) struct_lt <= \'0;
+ else if (cnt[30:2]==1) struct_lt <= \'0;
+ else if (cnt[30:2]==2) struct_lt <= \'0;
+ else if (cnt[30:2]==3) struct_lt <= \'0;
+ else if (cnt[30:2]==4) struct_lt <= \'0;
+ else if (cnt[30:2]==5) struct_lt <= \'0;
+ end else if (cnt[1:0]==2\'d1) begin
+ // write value to structure
+ if (cnt[30:2]==0) begin end
+ else if (cnt[30:2]==1) struct_lt <= \'1;
+ else if (cnt[30:2]==2) struct_lt.e0 <= \'1;
+ else if (cnt[30:2]==3) struct_lt.e1 <= \'1;
+ else if (cnt[30:2]==4) struct_lt.e2 <= \'1;
+ else if (cnt[30:2]==5) struct_lt.e3 <= \'1;
+ end else if (cnt[1:0]==2\'d2) begin
+ // check structure value
+ if (cnt[30:2]==0) begin if (struct_lt !== 15\'b000000000000000) begin $display(""%b"", struct_lt); $stop(); end end
+ else if (cnt[30:2]==1) begin if (struct_lt !== 15\'b111111111111111) begin $display(""%b"", struct_lt); $stop(); end end
+ else if (cnt[30:2]==2) begin if (struct_lt !== 15\'b100000000000000) begin $display(""%b"", struct_lt); $stop(); end end
+ else if (cnt[30:2]==3) begin if (struct_lt !== 15\'b011000000000000) begin $display(""%b"", struct_lt); $stop(); end end
+ else if (cnt[30:2]==4) begin if (struct_lt !== 15\'b000111100000000) begin $display(""%b"", struct_lt); $stop(); end end
+ else if (cnt[30:2]==5) begin if (struct_lt !== 15\'b000000011111111) begin $display(""%b"", struct_lt); $stop(); end end
+ end else if (cnt[1:0]==2\'d3) begin
+ // read value from structure (not a very good test for now)
+ if (cnt[30:2]==0) begin if (struct_lt !== {WS{1\'b0}}) $stop(); end
+ else if (cnt[30:2]==1) begin if (struct_lt !== {WS{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==2) begin if (struct_lt.e0 !== { 1{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==3) begin if (struct_lt.e1 !== { 2{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==4) begin if (struct_lt.e2 !== { 4{1\'b1}}) $stop(); end
+ else if (cnt[30:2]==5) begin if (struct_lt.e3 !== { 8{1\'b1}}) $stop(); end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+ reg \t\treset;
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire\t\t\tmyevent;\t\t// From test of Test.v
+ wire\t\t\tmyevent_pending;\t// From test of Test.v
+ wire [1:0]\t\tstate;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .state\t\t\t(state[1:0]),
+\t .myevent\t\t\t(myevent),
+\t .myevent_pending\t\t(myevent_pending),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .reset\t\t\t(reset));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {60\'h0, myevent_pending,myevent,state};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x me=%0x mep=%x\
+"",$time, cyc, crc, result, myevent, myevent_pending);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ reset <= (cyc<2);
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h4e93a74bd97b25ef
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ state, myevent, myevent_pending,
+ // Inputs
+ clk, reset
+ );
+ input clk;
+ input reset;
+ output [1:0] state;
+ output\tmyevent;
+ output\tmyevent_pending;
+
+ reg [5:0] \tcount = 0;
+ always @ (posedge clk)
+ if (reset) count <= 0;
+ else count <= count + 1;
+
+ reg \t\tmyevent = 1\'b0;
+ always @ (posedge clk)
+ myevent <= (count == 6\'d27);
+
+ reg \t\tmyevent_done;
+ reg \t\thickup_ready;
+ reg \t\thickup_done;
+
+ localparam STATE_ZERO = 0;
+ localparam STATE_ONE = 1;
+ localparam STATE_TWO = 2;
+
+ reg [1:0] \tstate = STATE_ZERO;
+ reg \t\tstate_start_myevent = 1\'b0;
+ reg \t\tstate_start_hickup = 1\'b0;
+ reg \t\tmyevent_pending = 1\'b0;
+ always @ (posedge clk) begin
+ state <= state;
+ myevent_pending <= myevent_pending || myevent;
+ state_start_myevent <= 1\'b0;
+ state_start_hickup <= 1\'b0;
+ case (state)
+\tSTATE_ZERO:
+\t if (myevent_pending) begin
+ state <= STATE_ONE;
+ myevent_pending <= 1\'b0;
+ state_start_myevent <= 1\'b1;
+\t end else if (hickup_ready) begin
+ state <= STATE_TWO;
+ state_start_hickup <= 1\'b1;
+\t end
+
+\tSTATE_ONE:
+\t if (myevent_done)
+ state <= STATE_ZERO;
+
+\tSTATE_TWO:
+\t if (hickup_done)
+ state <= STATE_ZERO;
+
+\tdefault:
+\t ; /* do nothing */
+ endcase
+ end
+
+ reg [3:0] myevent_count = 0;
+ always @ (posedge clk)
+ if (state_start_myevent)
+ myevent_count <= 9;
+ else if (myevent_count > 0)
+ myevent_count <= myevent_count - 1;
+
+ initial myevent_done = 1\'b0;
+ always @ (posedge clk)
+ myevent_done <= (myevent_count == 0);
+
+ reg [4:0] hickup_backlog = 2;
+ always @ (posedge clk)
+ if (state_start_myevent)
+ hickup_backlog <= hickup_backlog - 1;
+ else if (state_start_hickup)
+ hickup_backlog <= hickup_backlog + 1;
+
+ initial hickup_ready = 1\'b1;
+ always @ (posedge clk)
+ hickup_ready <= (hickup_backlog < 3);
+
+ reg [3:0] hickup_count = 0;
+ always @ (posedge clk)
+ if (state_start_hickup)
+ hickup_count <= 10;
+ else if (hickup_count > 0)
+ hickup_count <= hickup_count - 1;
+
+ initial hickup_done = 1\'b0;
+ always @ (posedge clk)
+ hickup_done <= (hickup_count == 1);
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2004 by Wilson Snyder.
+
+module t;
+ // verilator_no_inline_module
+ initial $stop; // Should have failed
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t;
+
+ // verilator lint_off LITENDIAN
+ reg [5:0] binary_nostart [2:15];
+ reg [5:0] binary_start [0:15];
+ reg [175:0] hex [0:15];
+ // verilator lint_on LITENDIAN
+
+ integer i;
+
+ initial begin
+
+ begin
+\t $readmemb(""t/t_sys_readmem_b.mem"", binary_nostart);
+`ifdef TEST_VERBOSE
+\t for (i=0; i<16; i=i+1) $write("" @%x = %x\
+"", i, binary_nostart[i]);
+`endif
+\t if (binary_nostart[\'h2] != 6\'h02) $stop;
+\t if (binary_nostart[\'h3] != 6\'h03) $stop;
+\t if (binary_nostart[\'h4] != 6\'h04) $stop;
+\t if (binary_nostart[\'h5] != 6\'h05) $stop;
+\t if (binary_nostart[\'h6] != 6\'h06) $stop;
+\t if (binary_nostart[\'h7] != 6\'h07) $stop;
+\t if (binary_nostart[\'h8] != 6\'h10) $stop;
+\t if (binary_nostart[\'hc] != 6\'h14) $stop;
+\t if (binary_nostart[\'hd] != 6\'h15) $stop;
+ end
+
+ begin
+\t $readmemb(""t/t_sys_readmem_b_8.mem"", binary_start, 4, 4+7);
+`ifdef TEST_VERBOSE
+\t for (i=0; i<16; i=i+1) $write("" @%x = %x\
+"", i, binary_start[i]);
+`endif
+\t if (binary_start[\'h04] != 6\'h10) $stop;
+\t if (binary_start[\'h05] != 6\'h11) $stop;
+\t if (binary_start[\'h06] != 6\'h12) $stop;
+\t if (binary_start[\'h07] != 6\'h13) $stop;
+\t if (binary_start[\'h08] != 6\'h14) $stop;
+\t if (binary_start[\'h09] != 6\'h15) $stop;
+\t if (binary_start[\'h0a] != 6\'h16) $stop;
+\t if (binary_start[\'h0b] != 6\'h17) $stop;
+ end
+
+ begin
+\t $readmemh(""t/t_sys_readmem_h.mem"", hex, 0);
+`ifdef TEST_VERBOSE
+\t for (i=0; i<16; i=i+1) $write("" @%x = %x\
+"", i, hex[i]);
+`endif
+\t if (hex[\'h04] != 176\'h400437654321276543211765432107654321abcdef10) $stop;
+\t if (hex[\'h0a] != 176\'h400a37654321276543211765432107654321abcdef11) $stop;
+\t if (hex[\'h0b] != 176\'h400b37654321276543211765432107654321abcdef12) $stop;
+\t if (hex[\'h0c] != 176\'h400c37654321276543211765432107654321abcdef13) $stop;
+ end
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Outputs
+ bar
+ );
+
+ wire foo;
+ output bar;
+
+ // Oh dear.
+ assign foo = bar;
+ assign bar = foo;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ reg posedge_wr_clocks;
+ reg prev_wr_clocks;
+ reg [31:0] m_din;
+ reg [31:0] m_dout;
+
+ always @(negedge clk) begin
+ prev_wr_clocks = 0;
+ end
+
+ reg comb_pos_1;
+ reg comb_prev_1;
+ always @ (/*AS*/clk or posedge_wr_clocks or prev_wr_clocks) begin
+ comb_pos_1 = (clk &~ prev_wr_clocks);
+ comb_prev_1 = comb_pos_1 | posedge_wr_clocks;
+ comb_pos_1 = 1\'b1;
+ end
+
+ always @ (posedge clk) begin
+ posedge_wr_clocks = (clk &~ prev_wr_clocks); //surefire lint_off_line SEQASS
+ prev_wr_clocks = prev_wr_clocks | posedge_wr_clocks;\t//surefire lint_off_line SEQASS
+ if (posedge_wr_clocks) begin
+\t //$write(""[%0t] Wrclk\
+"", $time);
+\t m_dout <= m_din;
+ end
+ end
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc<=cyc+1;
+\t if (cyc==1) begin
+\t $write("" %x\
+"",comb_pos_1);
+\t m_din <= 32\'hfeed;
+\t end
+\t if (cyc==2) begin
+\t $write("" %x\
+"",comb_pos_1);
+\t m_din <= 32\'he11e;
+\t end
+\t if (cyc==3) begin
+\t m_din <= 32\'he22e;
+\t $write("" %x\
+"",comb_pos_1);
+\t if (m_dout!=32\'hfeed) $stop;
+\t end
+\t if (cyc==4) begin
+\t if (m_dout!=32\'he11e) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+typedef enum { EN_ZERO,
+\t EN_ONE
+\t } En_t;
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ // Insure that we can declare a type with a function declaration
+ function enum integer {
+\t\t\t EF_TRUE = 1,
+\t\t\t EF_FALSE = 0 }
+\t\t\t\t f_enum_inv ( input a);
+ f_enum_inv = a ? EF_FALSE : EF_TRUE;
+ endfunction
+ initial begin
+ if (f_enum_inv(1) != 0) $stop;
+ if (f_enum_inv(0) != 1) $stop;
+ end
+
+ En_t a, z;
+
+ sub sub (/*AUTOINST*/
+\t // Outputs
+\t .z\t\t\t\t(z),
+\t // Inputs
+\t .a\t\t\t\t(a));
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t a <= EN_ZERO;
+\t end
+\t if (cyc==2) begin
+\t a <= EN_ONE;
+\t if (z != EN_ONE) $stop;
+\t end
+\t if (cyc==3) begin
+\t if (z != EN_ZERO) $stop;
+\t end
+\t if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+module sub (input En_t a, output En_t z);
+ always @* z = (a==EN_ONE) ? EN_ZERO : EN_ONE;
+endmodule
+
+// Local Variables:
+// verilog-typedef-regexp: ""_t$""
+// End:
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ reg [3:0] a;
+ reg [99:0] x;
+
+ initial begin
+ a = 4\'b010x;
+ if (a[3:2] !== 2\'b01) $stop;
+ if (|a !== 1\'b1) $stop;
+ if (&a !== 1\'b0) $stop;
+ x = 100\'bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2007 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ v95 v95 ();
+ v01 v01 ();
+ v05 v05 ();
+ s05 s05 ();
+ s09 s09 ();
+ a23 a23 ();
+ s12 s12 ();
+
+ initial begin
+ $finish;
+ end
+endmodule
+
+`begin_keywords ""1364-1995""
+module v95;
+ integer signed; initial signed = 1;
+endmodule
+`end_keywords
+
+`begin_keywords ""1364-2001""
+module v01;
+ integer bit; initial bit = 1;
+endmodule
+`end_keywords
+
+`begin_keywords ""1364-2005""
+module v05;
+ integer final; initial final = 1;
+endmodule
+`end_keywords
+
+`begin_keywords ""1800-2005""
+module s05;
+ integer global; initial global = 1;
+endmodule
+`end_keywords
+
+`begin_keywords ""1800-2009""
+module s09;
+ integer soft; initial soft = 1;
+endmodule
+`end_keywords
+
+`begin_keywords ""1800-2012""
+module s12;
+ final begin
+ $write(""*-* All Finished *-*\
+"");
+ end
+endmodule
+`end_keywords
+
+`begin_keywords ""VAMS-2.3""
+module a23;
+ real foo; initial foo = sqrt(2.0);
+endmodule
+`end_keywords
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t;
+
+ typedef logic [3:0] mc_t;
+ typedef mc_t tocast_t;
+
+ mc_t o;
+
+ logic [15:0] allones = 16\'hffff;
+ parameter FOUR = 4;
+
+ // bug925
+ localparam [6:0] RESULT = 7\'((6*9+92)%96);
+
+ logic signed [14:0] samp0 = 15\'h0000;
+ logic signed [14:0] samp1 = 15\'h0000;
+ logic signed [14:0] samp2 = 15\'h6000;
+ logic signed [11:0] coeff0 = 12\'h009;
+ logic signed [11:0] coeff1 = 12\'h280;
+ logic signed [11:0] coeff2 = 12\'h4C5;
+ logic signed [26:0] mida = ((27\'(coeff2 * samp2) >>> 11));
+ // verilator lint_off WIDTH
+ logic signed [26:0] midb = 15\'((27\'(coeff2 * samp2) >>> 11));
+ // verilator lint_on WIDTH
+ logic signed [14:0] outa = 15\'((27\'(coeff0 * samp0) >>> 11) + // 27\' size casting in order for intermediate result to not be truncated to the width of LHS vector
+\t\t\t\t (27\'(coeff1 * samp1) >>> 11) +
+\t\t\t\t (27\'(coeff2 * samp2) >>> 11)); // 15\' size casting to avoid synthesis/simulator warnings
+
+ initial begin
+ if (4\'shf > 4\'sh0) $stop;
+ if (signed\'(4\'hf) > 4\'sh0) $stop;
+ if (4\'hf < 4\'h0) $stop;
+ if (unsigned\'(4\'shf) < 4\'h0) $stop;
+ if (4\'(allones) !== 4\'hf) $stop;
+ if (6\'(allones) !== 6\'h3f) $stop;
+ if ((4)\'(allones) !== 4\'hf) $stop;
+ if ((4+2)\'(allones) !== 6\'h3f) $stop;
+ if ((4-2)\'(allones) !== 2\'h3) $stop;
+ if ((FOUR+2)\'(allones) !== 6\'h3f) $stop;
+ if (50 !== RESULT) $stop;
+
+ o = tocast_t\'(4\'b1);
+ if (o != 4\'b1) $stop;
+
+ if (15\'h6cec != outa) $stop;
+ if (27\'h7ffecec != mida) $stop;
+ if (27\'h7ffecec != midb) $stop;
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Test of selection with unsized Z.
+//
+// Test selecting Z when size is not explicit. Issue 510.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Jeremy Bennett.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ wire [1:0] b;
+ wire [1:0] c;
+ wire [0:0] d;\t\t// Explicit width due to issue 508
+ wire [0:0] e;
+
+ // This works if we use 1'bz, or 1'bx, but not with just 'bz or 'bx. It
+ // does require the tri-state Z. Since we get the same effect if b is
+ // dimensioned [0:0], this may be connected to issue 508.
+ assign b[1:0] = clk ? 2'bx : 'bz;
+ assign c[1:0] = clk ? 2'bz : 'bx;
+ assign d = clk ? 1'bx : 'bz;
+ assign e = clk ? 1'bz : 'bx;
+
+endmodule // t
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=0;
+
+ reg [7:0] crc;
+ reg [2:0] sum;
+ wire [2:0] in = crc[2:0];
+ wire [2:0] out;
+
+ MxN_pipeline pipe (in, out, clk);
+
+ always @ (posedge clk) begin
+ //$write(""[%0t] cyc==%0d crc=%b sum=%x\
+"",$time, cyc, crc, sum);
+ cyc <= cyc + 1;
+ crc <= {crc[6:0], ~^ {crc[7],crc[5],crc[4],crc[3]}};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 8\'hed;
+\t sum <= 3\'h0;
+ end
+ else if (cyc>10 && cyc<90) begin
+\t sum <= {sum[1:0],sum[2]} ^ out;
+ end
+ else if (cyc==99) begin
+\t if (crc !== 8\'b01110000) $stop;
+\t if (sum !== 3\'h3) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module dffn (q,d,clk);
+ parameter BITS = 1;
+
+ input [BITS-1:0] d;
+ output reg [BITS-1:0] q;
+ input \t clk;
+
+ always @ (posedge clk) begin
+ q <= d;
+ end
+
+endmodule
+
+module MxN_pipeline (in, out, clk);
+ parameter M=3, N=4;
+
+ input [M-1:0] in;
+ output [M-1:0] out;
+ input \t clk;
+
+ // Unsupported: Per-bit array instantiations with output connections to non-wires.
+ //wire [M*(N-1):1] t;
+ //dffn #(M) p[N:1] ({out,t},{t,in},clk);
+
+ wire [M*(N-1):1] w;
+ wire [M*N:1] q;
+ dffn #(M) p[N:1] (q,{w,in},clk);
+ assign \t{out,w} = q;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t_case_huge_sub (/*AUTOARG*/
+ // Outputs
+ outa, outb, outc,
+ // Inputs
+ index
+ );
+
+ input [7:0] index;
+ output [9:0] outa;
+ output [1:0] outb;
+ output \toutc;
+
+ // =============================
+ /*AUTOREG*/
+ // Beginning of automatic regs (for this module\'s undeclared outputs)
+ reg [9:0]\t\touta;
+ reg [1:0]\t\toutb;
+ reg\t\t\toutc;
+ // End of automatics
+
+ // =============================
+ // Created from perl
+ // for $i (0..1023) { printf ""\\t10\'h%03x: begin outa = 10\'h%03x; outb = 2\'b%02b; outc = 1\'b%d; end\
+"", $i, rand(1024),rand(4),rand(2); };
+
+ always @(/*AS*/index) begin
+ case (index)
+\t8\'h00: begin outa = 10\'h152; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h01: begin outa = 10\'h318; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h02: begin outa = 10\'h29f; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h03: begin outa = 10\'h392; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h04: begin outa = 10\'h1ef; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h05: begin outa = 10\'h06c; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h06: begin outa = 10\'h29f; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h07: begin outa = 10\'h29a; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h08: begin outa = 10\'h3ce; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h09: begin outa = 10\'h37c; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h0a: begin outa = 10\'h058; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h0b: begin outa = 10\'h3b2; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h0c: begin outa = 10\'h36f; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h0d: begin outa = 10\'h2c5; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h0e: begin outa = 10\'h23a; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h0f: begin outa = 10\'h222; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h10: begin outa = 10\'h328; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h11: begin outa = 10\'h3c3; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h12: begin outa = 10\'h12c; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h13: begin outa = 10\'h1d0; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h14: begin outa = 10\'h3ff; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h15: begin outa = 10\'h115; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h16: begin outa = 10\'h3ba; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h17: begin outa = 10\'h3ba; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h18: begin outa = 10\'h10d; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h19: begin outa = 10\'h13b; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h1a: begin outa = 10\'h0a0; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h1b: begin outa = 10\'h264; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h1c: begin outa = 10\'h3a2; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h1d: begin outa = 10\'h07c; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h1e: begin outa = 10\'h291; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h1f: begin outa = 10\'h1d1; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h20: begin outa = 10\'h354; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h21: begin outa = 10\'h0c0; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h22: begin outa = 10\'h191; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h23: begin outa = 10\'h379; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h24: begin outa = 10\'h073; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h25: begin outa = 10\'h2fd; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h26: begin outa = 10\'h2e0; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h27: begin outa = 10\'h337; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h28: begin outa = 10\'h2c7; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h29: begin outa = 10\'h19e; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h2a: begin outa = 10\'h107; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h2b: begin outa = 10\'h06a; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h2c: begin outa = 10\'h1c7; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h2d: begin outa = 10\'h107; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h2e: begin outa = 10\'h0cf; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h2f: begin outa = 10\'h009; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h30: begin outa = 10\'h09d; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h31: begin outa = 10\'h28e; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h32: begin outa = 10\'h010; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h33: begin outa = 10\'h1e0; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h34: begin outa = 10\'h079; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h35: begin outa = 10\'h13e; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h36: begin outa = 10\'h282; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h37: begin outa = 10\'h21c; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h38: begin outa = 10\'h148; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h39: begin outa = 10\'h3c0; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h3a: begin outa = 10\'h176; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h3b: begin outa = 10\'h3fc; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h3c: begin outa = 10\'h295; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h3d: begin outa = 10\'h113; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h3e: begin outa = 10\'h354; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h3f: begin outa = 10\'h0db; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h40: begin outa = 10\'h238; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h41: begin outa = 10\'h12b; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h42: begin outa = 10\'h1dc; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h43: begin outa = 10\'h137; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h44: begin outa = 10\'h1e2; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h45: begin outa = 10\'h3d5; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h46: begin outa = 10\'h30c; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h47: begin outa = 10\'h298; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h48: begin outa = 10\'h080; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h49: begin outa = 10\'h35a; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h4a: begin outa = 10\'h01b; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h4b: begin outa = 10\'h0a3; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h4c: begin outa = 10\'h0b3; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h4d: begin outa = 10\'h17a; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h4e: begin outa = 10\'h3ae; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h4f: begin outa = 10\'h078; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h50: begin outa = 10\'h322; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h51: begin outa = 10\'h213; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h52: begin outa = 10\'h11a; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h53: begin outa = 10\'h1a7; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h54: begin outa = 10\'h35a; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h55: begin outa = 10\'h233; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h56: begin outa = 10\'h01d; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h57: begin outa = 10\'h2d5; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h58: begin outa = 10\'h1a0; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h59: begin outa = 10\'h3d0; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h5a: begin outa = 10\'h181; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h5b: begin outa = 10\'h219; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h5c: begin outa = 10\'h26a; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h5d: begin outa = 10\'h050; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h5e: begin outa = 10\'h189; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h5f: begin outa = 10\'h1eb; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h60: begin outa = 10\'h224; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h61: begin outa = 10\'h2fe; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h62: begin outa = 10\'h0ae; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h63: begin outa = 10\'h1cd; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h64: begin outa = 10\'h273; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h65: begin outa = 10\'h268; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h66: begin outa = 10\'h111; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h67: begin outa = 10\'h1f9; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h68: begin outa = 10\'h232; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h69: begin outa = 10\'h255; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h6a: begin outa = 10\'h34c; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h6b: begin outa = 10\'h049; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h6c: begin outa = 10\'h197; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h6d: begin outa = 10\'h0fe; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h6e: begin outa = 10\'h253; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h6f: begin outa = 10\'h2de; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h70: begin outa = 10\'h13b; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h71: begin outa = 10\'h040; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h72: begin outa = 10\'h0b4; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h73: begin outa = 10\'h233; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h74: begin outa = 10\'h198; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h75: begin outa = 10\'h018; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h76: begin outa = 10\'h2f7; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h77: begin outa = 10\'h134; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h78: begin outa = 10\'h1ca; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h79: begin outa = 10\'h286; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h7a: begin outa = 10\'h0e6; outb = 2\'b11; outc = 1\'b1; end
+\t8\'h7b: begin outa = 10\'h064; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h7c: begin outa = 10\'h257; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h7d: begin outa = 10\'h31a; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h7e: begin outa = 10\'h247; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h7f: begin outa = 10\'h299; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h80: begin outa = 10\'h02c; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h81: begin outa = 10\'h2bb; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h82: begin outa = 10\'h180; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h83: begin outa = 10\'h245; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h84: begin outa = 10\'h0da; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h85: begin outa = 10\'h367; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h86: begin outa = 10\'h304; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h87: begin outa = 10\'h38b; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h88: begin outa = 10\'h09f; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h89: begin outa = 10\'h1f0; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h8a: begin outa = 10\'h281; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h8b: begin outa = 10\'h019; outb = 2\'b00; outc = 1\'b0; end
+\t8\'h8c: begin outa = 10\'h1f2; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h8d: begin outa = 10\'h0b1; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h8e: begin outa = 10\'h058; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h8f: begin outa = 10\'h39b; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h90: begin outa = 10\'h2ec; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h91: begin outa = 10\'h250; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h92: begin outa = 10\'h3f4; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h93: begin outa = 10\'h057; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h94: begin outa = 10\'h18f; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h95: begin outa = 10\'h105; outb = 2\'b01; outc = 1\'b1; end
+\t8\'h96: begin outa = 10\'h1ae; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h97: begin outa = 10\'h04e; outb = 2\'b10; outc = 1\'b0; end
+\t8\'h98: begin outa = 10\'h240; outb = 2\'b11; outc = 1\'b0; end
+\t8\'h99: begin outa = 10\'h3e4; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h9a: begin outa = 10\'h3c6; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h9b: begin outa = 10\'h109; outb = 2\'b00; outc = 1\'b1; end
+\t8\'h9c: begin outa = 10\'h073; outb = 2\'b10; outc = 1\'b1; end
+\t8\'h9d: begin outa = 10\'h19f; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h9e: begin outa = 10\'h3b8; outb = 2\'b01; outc = 1\'b0; end
+\t8\'h9f: begin outa = 10\'h00e; outb = 2\'b00; outc = 1\'b1; end
+\t8\'ha0: begin outa = 10\'h1b3; outb = 2\'b11; outc = 1\'b1; end
+\t8\'ha1: begin outa = 10\'h2bd; outb = 2\'b11; outc = 1\'b0; end
+\t8\'ha2: begin outa = 10\'h324; outb = 2\'b00; outc = 1\'b1; end
+\t8\'ha3: begin outa = 10\'h343; outb = 2\'b10; outc = 1\'b0; end
+\t8\'ha4: begin outa = 10\'h1c9; outb = 2\'b01; outc = 1\'b0; end
+\t8\'ha5: begin outa = 10\'h185; outb = 2\'b00; outc = 1\'b1; end
+\t8\'ha6: begin outa = 10\'h37a; outb = 2\'b00; outc = 1\'b1; end
+\t8\'ha7: begin outa = 10\'h0e0; outb = 2\'b01; outc = 1\'b1; end
+\t8\'ha8: begin outa = 10\'h0a3; outb = 2\'b10; outc = 1\'b0; end
+\t8\'ha9: begin outa = 10\'h019; outb = 2\'b11; outc = 1\'b0; end
+\t8\'haa: begin outa = 10\'h099; outb = 2\'b00; outc = 1\'b1; end
+\t8\'hab: begin outa = 10\'h376; outb = 2\'b01; outc = 1\'b1; end
+\t8\'hac: begin outa = 10\'h077; outb = 2\'b00; outc = 1\'b1; end
+\t8\'had: begin outa = 10\'h2b1; outb = 2\'b11; outc = 1\'b1; end
+\t8\'hae: begin outa = 10\'h27f; outb = 2\'b00; outc = 1\'b0; end
+\t8\'haf: begin outa = 10\'h265; outb = 2\'b11; outc = 1\'b0; end
+\t8\'hb0: begin outa = 10\'h156; outb = 2\'b10; outc = 1\'b1; end
+\t8\'hb1: begin outa = 10\'h1ce; outb = 2\'b00; outc = 1\'b0; end
+\t8\'hb2: begin outa = 10\'h008; outb = 2\'b01; outc = 1\'b0; end
+\t8\'hb3: begin outa = 10\'h12e; outb = 2\'b11; outc = 1\'b1; end
+\t8\'hb4: begin outa = 10\'h199; outb = 2\'b11; outc = 1\'b0; end
+\t8\'hb5: begin outa = 10\'h330; outb = 2\'b10; outc = 1\'b0; end
+\t8\'hb6: begin outa = 10\'h1ab; outb = 2\'b01; outc = 1\'b1; end
+\t8\'hb7: begin outa = 10\'h3bd; outb = 2\'b00; outc = 1\'b0; end
+\t8\'hb8: begin outa = 10\'h0ca; outb = 2\'b10; outc = 1\'b0; end
+\t8\'hb9: begin outa = 10\'h367; outb = 2\'b00; outc = 1\'b0; end
+\t8\'hba: begin outa = 10\'h334; outb = 2\'b00; outc = 1\'b0; end
+\t8\'hbb: begin outa = 10\'h040; outb = 2\'b00; outc = 1\'b1; end
+\t8\'hbc: begin outa = 10\'h1a7; outb = 2\'b10; outc = 1\'b1; end
+\t8\'hbd: begin outa = 10\'h036; outb = 2\'b11; outc = 1\'b1; end
+\t8\'hbe: begin outa = 10\'h223; outb = 2\'b11; outc = 1\'b1; end
+\t8\'hbf: begin outa = 10\'h075; outb = 2\'b01; outc = 1\'b0; end
+\t8\'hc0: begin outa = 10\'h3c4; outb = 2\'b00; outc = 1\'b1; end
+\t8\'hc1: begin outa = 10\'h2cc; outb = 2\'b01; outc = 1\'b0; end
+\t8\'hc2: begin outa = 10\'h123; outb = 2\'b01; outc = 1\'b0; end
+\t8\'hc3: begin outa = 10\'h3fd; outb = 2\'b01; outc = 1\'b1; end
+\t8\'hc4: begin outa = 10\'h11e; outb = 2\'b00; outc = 1\'b0; end
+\t8\'hc5: begin outa = 10\'h27c; outb = 2\'b11; outc = 1\'b1; end
+\t8\'hc6: begin outa = 10\'h1e2; outb = 2\'b11; outc = 1\'b0; end
+\t8\'hc7: begin outa = 10\'h377; outb = 2\'b11; outc = 1\'b0; end
+\t8\'hc8: begin outa = 10\'h33a; outb = 2\'b11; outc = 1\'b0; end
+\t8\'hc9: begin outa = 10\'h32d; outb = 2\'b11; outc = 1\'b1; end
+\t8\'hca: begin outa = 10\'h014; outb = 2\'b11; outc = 1\'b0; end
+\t8\'hcb: begin outa = 10\'h332; outb = 2\'b10; outc = 1\'b0; end
+\t8\'hcc: begin outa = 10\'h359; outb = 2\'b00; outc = 1\'b0; end
+\t8\'hcd: begin outa = 10\'h0a4; outb = 2\'b10; outc = 1\'b1; end
+\t8\'hce: begin outa = 10\'h348; outb = 2\'b00; outc = 1\'b1; end
+\t8\'hcf: begin outa = 10\'h04b; outb = 2\'b11; outc = 1\'b1; end
+\t8\'hd0: begin outa = 10\'h147; outb = 2\'b10; outc = 1\'b1; end
+\t8\'hd1: begin outa = 10\'h026; outb = 2\'b00; outc = 1\'b1; end
+\t8\'hd2: begin outa = 10\'h103; outb = 2\'b00; outc = 1\'b0; end
+\t8\'hd3: begin outa = 10\'h106; outb = 2\'b00; outc = 1\'b1; end
+\t8\'hd4: begin outa = 10\'h35a; outb = 2\'b00; outc = 1\'b0; end
+\t8\'hd5: begin outa = 10\'h254; outb = 2\'b01; outc = 1\'b0; end
+\t8\'hd6: begin outa = 10\'h0cd; outb = 2\'b01; outc = 1\'b0; end
+\t8\'hd7: begin outa = 10\'h17c; outb = 2\'b11; outc = 1\'b1; end
+\t8\'hd8: begin outa = 10\'h37e; outb = 2\'b10; outc = 1\'b1; end
+\t8\'hd9: begin outa = 10\'h0a9; outb = 2\'b11; outc = 1\'b1; end
+\t8\'hda: begin outa = 10\'h0fe; outb = 2\'b01; outc = 1\'b0; end
+\t8\'hdb: begin outa = 10\'h3c0; outb = 2\'b11; outc = 1\'b1; end
+\t8\'hdc: begin outa = 10\'h1d9; outb = 2\'b10; outc = 1\'b1; end
+\t8\'hdd: begin outa = 10\'h10e; outb = 2\'b00; outc = 1\'b1; end
+\t8\'hde: begin outa = 10\'h394; outb = 2\'b01; outc = 1\'b0; end
+\t8\'hdf: begin outa = 10\'h316; outb = 2\'b01; outc = 1\'b0; end
+\t8\'he0: begin outa = 10\'h05b; outb = 2\'b11; outc = 1\'b0; end
+\t8\'he1: begin outa = 10\'h126; outb = 2\'b01; outc = 1\'b1; end
+\t8\'he2: begin outa = 10\'h369; outb = 2\'b11; outc = 1\'b0; end
+\t8\'he3: begin outa = 10\'h291; outb = 2\'b10; outc = 1\'b1; end
+\t8\'he4: begin outa = 10\'h2ca; outb = 2\'b00; outc = 1\'b1; end
+\t8\'he5: begin outa = 10\'h25b; outb = 2\'b01; outc = 1\'b1; end
+\t8\'he6: begin outa = 10\'h106; outb = 2\'b00; outc = 1\'b0; end
+\t8\'he7: begin outa = 10\'h172; outb = 2\'b11; outc = 1\'b1; end
+\t8\'he8: begin outa = 10\'h2f7; outb = 2\'b00; outc = 1\'b1; end
+\t8\'he9: begin outa = 10\'h2d3; outb = 2\'b11; outc = 1\'b1; end
+\t8\'hea: begin outa = 10\'h182; outb = 2\'b00; outc = 1\'b0; end
+\t8\'heb: begin outa = 10\'h327; outb = 2\'b00; outc = 1\'b1; end
+\t8\'hec: begin outa = 10\'h1d0; outb = 2\'b10; outc = 1\'b0; end
+\t8\'hed: begin outa = 10\'h204; outb = 2\'b00; outc = 1\'b1; end
+\t8\'hee: begin outa = 10\'h11f; outb = 2\'b00; outc = 1\'b1; end
+\t8\'hef: begin outa = 10\'h365; outb = 2\'b11; outc = 1\'b1; end
+\t8\'hf0: begin outa = 10\'h2c2; outb = 2\'b01; outc = 1\'b1; end
+\t8\'hf1: begin outa = 10\'h2b5; outb = 2\'b10; outc = 1\'b0; end
+\t8\'hf2: begin outa = 10\'h1f8; outb = 2\'b10; outc = 1\'b1; end
+\t8\'hf3: begin outa = 10\'h2a7; outb = 2\'b01; outc = 1\'b1; end
+\t8\'hf4: begin outa = 10\'h1be; outb = 2\'b10; outc = 1\'b1; end
+\t8\'hf5: begin outa = 10\'h25e; outb = 2\'b10; outc = 1\'b1; end
+\t8\'hf6: begin outa = 10\'h032; outb = 2\'b10; outc = 1\'b0; end
+\t8\'hf7: begin outa = 10\'h2ef; outb = 2\'b00; outc = 1\'b0; end
+\t8\'hf8: begin outa = 10\'h02f; outb = 2\'b00; outc = 1\'b1; end
+\t8\'hf9: begin outa = 10\'h201; outb = 2\'b10; outc = 1\'b0; end
+\t8\'hfa: begin outa = 10\'h054; outb = 2\'b01; outc = 1\'b1; end
+\t8\'hfb: begin outa = 10\'h013; outb = 2\'b10; outc = 1\'b0; end
+\t8\'hfc: begin outa = 10\'h249; outb = 2\'b01; outc = 1\'b0; end
+\t8\'hfd: begin outa = 10\'h09a; outb = 2\'b10; outc = 1\'b0; end
+\t8\'hfe: begin outa = 10\'h012; outb = 2\'b00; outc = 1\'b0; end
+\t8\'hff: begin outa = 10\'h114; outb = 2\'b10; outc = 1\'b1; end
+ endcase
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+//bug505
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ a #(1) a1 ();
+ b #(2) b2 ();
+
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+
+module a;
+ parameter ONE /*verilator public*/ = 22;
+ initial if (ONE != 1) $stop;
+`ifdef VERILATOR
+ initial if ($c32(""ONE"") != 1) $stop;
+`endif
+endmodule
+
+module b #(
+\t parameter TWO /*verilator public*/ = 22
+\t );
+ initial if (TWO != 2) $stop;
+`ifdef VERILATOR
+ initial if ($c32(""TWO"") != 2) $stop;
+`endif
+endmodule
+
+//bug804
+package p;
+ localparam INPACK /*verilator public*/ = 6;
+endpackage
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ wire [31:0] inp = crc[31:0];
+ wire\t\treset = (cyc < 5);
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [31:0]\t\toutp;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .outp\t\t\t(outp[31:0]),
+\t // Inputs
+\t .reset\t\t\t(reset),
+\t .clk\t\t\t(clk),
+\t .inp\t\t\t(inp[31:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {32\'h0, outp};
+
+ // What checksum will we end up with
+`define EXPECTED_SUM 64\'ha7f0a34f9cf56ccb
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ outp,
+ // Inputs
+ reset, clk, inp
+ );
+
+ input\t\t reset;
+ input\t\t clk;
+ input [31:0] \t inp;
+ output [31:0] \t outp;
+
+ function [31:0] no_inline_function;
+ input [31:0] \t var1;
+ input [31:0] \t var2;
+ /*verilator no_inline_task*/
+ reg [31*2:0] \t product1 ;
+ reg [31*2:0] \t product2 ;
+ integer \t\t i;
+ reg [31:0] \t tmp;
+
+ begin
+\t product2 = {(31*2+1){1\'b0}};
+
+\t for (i = 0; i < 32; i = i + 1)
+\t if (var2[i]) begin
+\t product1 = { {31*2+1-32{1\'b0}}, var1} << i;
+\t product2 = product2 ^ product1;
+\t end
+\t no_inline_function = 0;
+
+\t for (i= 0; i < 31; i = i + 1 )
+\t no_inline_function[i+1] = no_inline_function[i] ^ product2[i] ^ var1[i];
+ end
+ endfunction
+
+ reg [31:0] outp;
+ reg [31:0] inp_d;
+
+ always @( posedge clk ) begin
+ if( reset ) begin
+\t outp <= 0;
+ end
+ else begin
+\t inp_d <= inp;
+\t outp <= no_inline_function(inp, inp_d);
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t;
+ sub #(10,11,12,13) sub ();
+
+endmodule
+
+module sub ();
+ parameter A = 0;
+ parameter B = 1;
+
+ ip ip();
+
+ parameter C = 2;
+ parameter D = 3;
+
+ initial begin
+ if (A!=10) $stop;
+ if (B!=11) $stop;
+ if (C!=12) $stop;
+ if (D!=13) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+
+module ip;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2010 by Wilson Snyder.
+
+module t;
+
+ sub sub ();
+ defparam sub.P = 2;
+
+endmodule
+
+module sub;
+ parameter P = 6;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Copyright 2009 by Wilson Snyder. This program is free software; you can
+// redistribute it and/or modify it under the terms of either the GNU
+// Lesser General Public License Version 3 or the Perl Artistic License
+// Version 2.0.
+
+// Global is the most likely usage scenario
+import ""DPI-C"" dpii_sys_task = function void \\$dpii_sys (integer i);
+import ""DPI-C"" dpii_sys_func = function int \\$dpii_func (integer i);
+
+module t ();
+
+`ifndef verilator
+ `error ""Only Verilator supports PLI-ish DPI calls.""
+`endif
+
+ initial begin
+ $dpii_sys(1);
+ if ($dpii_func(2) != 3) $stop;
+ $dpii_sys(10);
+ if ($dpii_func(2) != 12) $stop;
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Wilson Snyder.
+
+// Very simple test for interface pathclearing
+
+interface ifc;
+ logic [3:0] value;
+endinterface
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc=1;
+
+ ifc itop();
+
+ sub c1 (.isub(itop),
+\t .i_value(4\'h4));
+
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==20) begin
+\t if (c1.i_value != 4) $stop; // \'Normal\' crossref just for comparison
+\t if (itop.value != 4) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+endmodule
+
+module sub
+ (
+ ifc isub,
+ input logic [3:0] i_value
+ );
+
+ always @* begin
+ isub.value = i_value;
+ end
+endmodule : sub
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+`timescale 1ns/10ps
+`verilog
+
+`suppress_faults
+`nosuppress_faults
+`enable_portfaults
+`disable_portfaults
+
+`delay_mode_distributed
+`delay_mode_path
+`delay_mode_unit
+`delay_mode_zero
+
+`default_decay_time 1
+`default_decay_time 1.0
+`default_decay_time infinite
+// unsupported (recommended not to): `default_trireg_strength 10
+
+`default_nettype wire
+// unsupported: `default_nettype tri
+// unsupported: `default_nettype tri0
+// unsupported: `default_nettype wand
+// unsupported: `default_nettype triand
+// unsupported: `default_nettype wor
+// unsupported: `default_nettype trior
+// unsupported: `default_nettype trireg
+`default_nettype none
+
+`autoexpand_vectornets
+
+`accelerate
+`noaccelerate
+`expand_vectornets
+`noexpand_vectornets
+`remove_gatenames
+`noremove_gatenames
+`remove_netnames
+`noremove_netnames
+`resetall
+
+// unsupported: `unconnected_drive pull1
+// unsupported: `unconnected_drive pull0
+`nounconnected_drive
+
+`line 100 ""hallo.v"" 0
+
+// unsupported: `uselib file=../moto_lib.v
+// unsupported: `uselib dir=../lib.dir libext=.v
+
+module t;
+ initial begin
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/);
+
+ // IEEE: integer_atom_type
+ byte\t\td_byte;
+ shortint\td_shortint;
+ int\t\td_int;
+ longint\td_longint;
+ integer\td_integer;
+ time\t\td_time;
+ chandle\td_chandle;
+
+ // IEEE: integer_atom_type
+ bit\t\td_bit;
+ logic\td_logic;
+ reg\t\td_reg;
+
+ bit\t [1:0]\td_bit2;
+ logic [1:0]\td_logic2;
+ reg\t [1:0]\td_reg2;
+
+ // IEEE: non_integer_type
+ //UNSUP shortreal\td_shortreal;
+ real\t\td_real;
+ realtime\td_realtime;
+
+ // Declarations using var
+ var byte \tv_b;
+`ifndef VCS
+ var [2:0] \tv_b3;
+ var signed [2:0] v_bs;
+`endif
+
+ // verilator lint_off WIDTH
+ localparam \t\tp_implicit = {96{1\'b1}};
+ localparam [89:0]\tp_explicit = {96{1\'b1}};
+ localparam byte \tp_byte\t= {96{1\'b1}};
+ localparam shortint \tp_shortint = {96{1\'b1}};
+ localparam int \tp_int\t= {96{1\'b1}};
+ localparam longint \tp_longint = {96{1\'b1}};
+ localparam integer \tp_integer = {96{1\'b1}};
+ localparam reg \tp_reg\t= {96{1\'b1}};
+ localparam bit \tp_bit\t= {96{1\'b1}};
+ localparam logic \tp_logic\t= {96{1\'b1}};
+ localparam reg [0:0]\tp_reg1\t= {96{1\'b1}};
+ localparam bit [0:0]\tp_bit1\t= {96{1\'b1}};
+ localparam logic [0:0] p_logic1= {96{1\'b1}};
+ localparam reg [1:0]\tp_reg2\t= {96{1\'b1}};
+ localparam bit [1:0]\tp_bit2\t= {96{1\'b1}};
+ localparam logic [1:0] p_logic2= {96{1\'b1}};
+ // verilator lint_on WIDTH
+
+ byte\t\tv_byte[2];
+ shortint\tv_shortint[2];
+ int\t\tv_int[2];
+ longint\tv_longint[2];
+ integer\tv_integer[2];
+ time\t\tv_time[2];
+ chandle\tv_chandle[2];
+ bit\t\tv_bit[2];
+ logic\tv_logic[2];
+ reg\t\tv_reg[2];
+ real\t\tv_real[2];
+ realtime\tv_realtime[2];
+
+ // We do this in two steps so we can check that initialization inside functions works properly
+ // verilator lint_off WIDTH
+ function \t\tf_implicit;\treg\t\tlv_implicit;\tf_implicit\t= lv_implicit;\tendfunction
+ function [89:0]\tf_explicit;\treg [89:0]\tlv_explicit;\tf_explicit\t= lv_explicit;\tendfunction
+ function byte \tf_byte;\t\tbyte \t\tlv_byte;\tf_byte\t \t= lv_byte;\tendfunction
+ function shortint \tf_shortint;\tshortint \tlv_shortint;\tf_shortint\t= lv_shortint;\tendfunction
+ function int \tf_int;\t\tint \t\tlv_int;\t\tf_int\t \t= lv_int;\tendfunction
+ function longint \tf_longint;\tlongint \tlv_longint;\tf_longint\t= lv_longint;\tendfunction
+ function integer \tf_integer;\tinteger \tlv_integer;\tf_integer\t= lv_integer;\tendfunction
+ function reg \tf_reg;\t\treg \t\tlv_reg;\t\tf_reg\t \t= lv_reg;\tendfunction
+ function bit \tf_bit;\t\tbit \t\tlv_bit;\t\tf_bit\t \t= lv_bit;\tendfunction
+ function logic \tf_logic;\tlogic \t\tlv_logic;\tf_logic\t\t= lv_logic;\tendfunction
+ function reg [0:0]\tf_reg1;\t\treg [0:0]\tlv_reg1;\tf_reg1\t \t= lv_reg1;\tendfunction
+ function bit [0:0]\tf_bit1;\t\tbit [0:0]\tlv_bit1;\tf_bit1\t \t= lv_bit1;\tendfunction
+ function logic [0:0] f_logic1;\tlogic [0:0] \tlv_logic1;\tf_logic1\t= lv_logic1;\tendfunction
+ function reg [1:0]\tf_reg2;\t\treg [1:0]\tlv_reg2;\tf_reg2\t \t= lv_reg2;\tendfunction
+ function bit [1:0]\tf_bit2;\t\tbit [1:0]\tlv_bit2;\tf_bit2\t \t= lv_bit2;\tendfunction
+ function logic [1:0] f_logic2;\tlogic [1:0] \tlv_logic2;\tf_logic2\t= lv_logic2;\tendfunction
+ function time \tf_time;\t\ttime \t\tlv_time;\tf_time\t\t= lv_time;\tendfunction
+ function chandle \tf_chandle;\tchandle\t\tlv_chandle;\tf_chandle\t= lv_chandle;\tendfunction
+ // verilator lint_on WIDTH
+
+`ifdef verilator
+ // For verilator zeroinit detection to work properly, we need to x-rand-reset to all 1s. This is the default!
+ `define XINIT 1\'b1
+ `define ALL_TWOSTATE 1\'b1
+`else
+ `define XINIT 1\'bx
+ `define ALL_TWOSTATE 1\'b0
+`endif
+
+`define CHECK_ALL(name,nbits,issigned,twostate,zeroinit) \\
+ if (zeroinit ? ((name & 1\'b1)!==1\'b0) : ((name & 1\'b1)!==`XINIT)) \\
+\tbegin $display(""%%Error: Bad zero/X init for %s: %b"",`""name`"",name); $stop; end \\
+ name = {96{1\'b1}}; \\
+ if (name !== {(nbits){1\'b1}}) begin $display(""%%Error: Bad size for %s"",`""name`""); $stop; end \\
+ if (issigned ? (name > 0) : (name < 0)) begin $display(""%%Error: Bad signed for %s"",`""name`""); $stop; end \\
+ name = {96{1\'bx}}; \\
+ if (name !== {(nbits){`ALL_TWOSTATE ? `XINIT : (twostate ? 1\'b0 : `XINIT)}}) \\
+\tbegin $display(""%%Error: Bad twostate for %s: %b"",`""name`"",name); $stop; end \\
+
+ initial begin
+ // verilator lint_off WIDTH
+ // verilator lint_off UNSIGNED
+ // name b sign twost 0init
+ `CHECK_ALL(d_byte\t\t,8 ,1\'b1,1\'b1,1\'b1);
+ `CHECK_ALL(d_shortint\t,16,1\'b1,1\'b1,1\'b1);
+ `CHECK_ALL(d_int\t\t,32,1\'b1,1\'b1,1\'b1);
+ `CHECK_ALL(d_longint\t,64,1\'b1,1\'b1,1\'b1);
+ `CHECK_ALL(d_integer\t,32,1\'b1,1\'b0,1\'b0);
+ `CHECK_ALL(d_time\t\t,64,1\'b0,1\'b0,1\'b0);
+ `CHECK_ALL(d_bit\t\t,1 ,1\'b0,1\'b1,1\'b1);
+ `CHECK_ALL(d_logic\t,1 ,1\'b0,1\'b0,1\'b0);
+ `CHECK_ALL(d_reg\t\t,1 ,1\'b0,1\'b0,1\'b0);
+ `CHECK_ALL(d_bit2\t\t,2 ,1\'b0,1\'b1,1\'b1);
+ `CHECK_ALL(d_logic2\t,2 ,1\'b0,1\'b0,1\'b0);
+ `CHECK_ALL(d_reg2\t\t,2 ,1\'b0,1\'b0,1\'b0);
+ // verilator lint_on WIDTH
+ // verilator lint_on UNSIGNED
+
+ // Can\'t CHECK_ALL(d_chandle), as many operations not legal on chandles
+`ifdef VERILATOR // else indeterminate
+ if ($bits(d_chandle) !== 64) $stop;
+`endif
+
+`define CHECK_P(name,nbits) \\
+ if (name !== {(nbits){1\'b1}}) begin $display(""%%Error: Bad size for %s"",`""name`""); $stop; end \\
+
+ // name b
+ `CHECK_P(p_implicit\t,96);
+ `CHECK_P(p_implicit[0]\t,1 );
+ `CHECK_P(p_explicit\t,90);
+ `CHECK_P(p_explicit[0]\t,1 );
+ `CHECK_P(p_byte\t\t,8 );
+ `CHECK_P(p_byte[0]\t,1 );
+ `CHECK_P(p_shortint\t,16);
+ `CHECK_P(p_shortint[0]\t,1 );
+ `CHECK_P(p_int\t\t,32);
+ `CHECK_P(p_int[0]\t\t,1 );
+ `CHECK_P(p_longint\t,64);
+ `CHECK_P(p_longint[0]\t,1 );
+ `CHECK_P(p_integer\t,32);
+ `CHECK_P(p_integer[0]\t,1 );
+ `CHECK_P(p_bit\t\t,1 );
+ `CHECK_P(p_logic\t\t,1 );
+ `CHECK_P(p_reg\t\t,1 );
+ `CHECK_P(p_bit1\t\t,1 );
+ `CHECK_P(p_logic1\t\t,1 );
+ `CHECK_P(p_reg1\t\t,1 );
+ `CHECK_P(p_bit1[0]\t,1 );
+ `CHECK_P(p_logic1[0]\t,1 );
+ `CHECK_P(p_reg1[0]\t,1 );
+ `CHECK_P(p_bit2\t\t,2 );
+ `CHECK_P(p_logic2\t\t,2 );
+ `CHECK_P(p_reg2\t\t,2 );
+
+`define CHECK_B(varname,nbits) \\
+ if ($bits(varname) !== nbits) begin $display(""%%Error: Bad size for %s"",`""varname`""); $stop; end \\
+
+ `CHECK_B(v_byte[1]\t,8 );
+ `CHECK_B(v_shortint[1]\t,16);
+ `CHECK_B(v_int[1]\t\t,32);
+ `CHECK_B(v_longint[1]\t,64);
+ `CHECK_B(v_integer[1]\t,32);
+ `CHECK_B(v_time[1]\t,64);
+ //`CHECK_B(v_chandle[1]
+ `CHECK_B(v_bit[1]\t\t,1 );
+ `CHECK_B(v_logic[1]\t,1 );
+ `CHECK_B(v_reg[1]\t\t,1 );
+ //`CHECK_B(v_real[1]\t,64);\t// $bits not allowed
+ //`CHECK_B(v_realtime[1]\t,64);\t// $bits not allowed
+
+`define CHECK_F(fname,nbits,zeroinit) \\
+ if ($bits(fname()) !== nbits) begin $display(""%%Error: Bad size for %s"",`""fname`""); $stop; end \\
+
+ // name b 0init
+ `CHECK_F(f_implicit\t,1 ,1\'b0); // Note 1 bit, not 96
+ `CHECK_F(f_explicit\t,90,1\'b0);
+ `CHECK_F(f_byte\t\t,8 ,1\'b1);
+ `CHECK_F(f_shortint\t,16,1\'b1);
+ `CHECK_F(f_int\t\t,32,1\'b1);
+ `CHECK_F(f_longint\t,64,1\'b1);
+ `CHECK_F(f_integer\t,32,1\'b0);
+ `CHECK_F(f_time\t\t,64,1\'b0);
+`ifdef VERILATOR // else indeterminate
+ `CHECK_F(f_chandle\t,64,1\'b0);
+`endif
+ `CHECK_F(f_bit\t\t,1 ,1\'b1);
+ `CHECK_F(f_logic\t\t,1 ,1\'b0);
+ `CHECK_F(f_reg\t\t,1 ,1\'b0);
+ `CHECK_F(f_bit1\t\t,1 ,1\'b1);
+ `CHECK_F(f_logic1\t\t,1 ,1\'b0);
+ `CHECK_F(f_reg1\t\t,1 ,1\'b0);
+ `CHECK_F(f_bit2\t\t,2 ,1\'b1);
+ `CHECK_F(f_logic2\t\t,2 ,1\'b0);
+ `CHECK_F(f_reg2\t\t,2 ,1\'b0);
+
+ // For unpacked types we don\'t want width warnings for unsized numbers that fit
+ d_byte\t= 2;
+ d_shortint= 2;
+ d_int\t= 2;
+ d_longint\t= 2;
+ d_integer\t= 2;
+
+ // Special check
+ d_time = $time;
+ if ($time !== d_time) $stop;
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+// bug601
+
+module t (
+ input clk,
+ input [3:0] in3, // worky
+ input [0:0] in2 [3:0], // worky
+ input in1 [3:0], // no worky
+ input [1:0] sel,
+ output reg out1,
+ output reg out2,
+ output reg out3
+ );
+
+ always @(posedge clk) begin
+ out3 <= in3[sel] ? in3[sel] : out3;
+ out2 <= in2[sel] ? in2[sel] : out2;
+ out1 <= in1[sel] ? in1[sel] : out1; // breaks
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+ integer cyc; initial cyc=1;
+
+ supply0 [1:0] low;
+ supply1 [1:0] high;
+
+ reg [7:0] isizedwire;
+ reg ionewire;
+
+`ifdef never_just_for_verilog_mode
+ wire oonewire;\t\t// From sub of t_inst_v2k__sub.v
+`endif
+
+ wire [7:0]\t\tosizedreg;\t\t// From sub of t_inst_v2k__sub.v
+ wire [1:0]\t\ttied;
+ wire [3:0]\t\ttied_also;
+
+ hello hsub (.tied_also);
+
+ // Double underscore tests bug631
+ t_inst_v2k__sub sub
+ (
+ // Outputs
+ .osizedreg\t\t\t(osizedreg[7:0]),
+ // verilator lint_off IMPLICIT
+ .oonewire\t\t\t\t(oonewire),
+ // verilator lint_on IMPLICIT
+ .tied\t\t\t\t(tied[1:0]),
+ // Inputs
+ .isizedwire\t\t\t(isizedwire[7:0]),
+ .ionewire\t\t\t\t(ionewire));
+
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+\t ionewire <= 1\'b1;
+\t isizedwire <= 8\'d8;
+\t end
+\t if (cyc==2) begin
+\t if (low != 2\'b00) $stop;
+\t if (high != 2\'b11) $stop;
+\t if (oonewire !== 1\'b1) $stop;
+\t if (isizedwire !== 8\'d8) $stop;
+\t if (tied != 2\'b10) $stop;
+\t if (tied_also != 4\'b1010) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+endmodule
+
+module hello(tied_also);
+ initial $write (""Hello\
+"");
+ output reg [3:0] tied_also = 4\'b1010;
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'h%x exp=\'h%x\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
+`define checks(gotv,expv) do if ((gotv) !== (expv)) begin $write(""%%Error: %s:%0d: got=\'%s\' exp=\'%s\'\
+"", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ typedef enum {
+\t\t E01 = 1,
+\t\t E03 = 3,
+\t\t E04 = 4
+\t\t } my_t;
+
+ integer \tcyc=0;
+ my_t e;
+
+ int arrayfits [e.num]; // Check can use as constant
+
+ string all;
+
+ // Check constification
+ initial begin
+ e = E03;
+ `checkh(e.first, E01);
+ `checkh(e.last, E04);
+ `checkh(e.last(), E04);
+ `checkh(e.next, E04);
+ `checkh(e.next(), E04);
+ `checkh(e.next(1), E04);
+ //Unsup: `checkh(e.next(2), E01);
+ `checkh(e.prev, E01);
+ `checkh(e.prev(1), E01);
+ //Unsup: `checkh(e.prev(2), E04);
+ `checkh(e.num, 3);
+ `checks(e.name, ""E03"");
+ //
+ all = """";
+ for (my_t e = e.first; e != e.last; e = e.next) begin
+\t all = {all, e.name};
+ end
+ e = e.last;
+ all = {all, e.name};
+ `checks(all, ""E01E03E04"");
+ end
+
+ // Check runtime
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+ if (cyc==0) begin
+\t // Setup
+\t e <= E01;
+ end
+ else if (cyc==1) begin
+\t `checks(e.name, ""E01"");
+\t `checkh(e.next, E03);
+\t `checkh(e.next(1), E03);
+\t //Unsup: `checkh(e.next(2), E04);
+\t `checkh(e.prev, E04);
+\t `checkh(e.prev(1), E04);
+\t //Unsup: `checkh(e.prev(2), E03);
+\t e <= E03;
+ end
+ else if (cyc==2) begin
+\t `checks(e.name, ""E03"");
+\t `checkh(e.next, E04);
+\t `checkh(e.next(1), E04);
+\t //Unsup: `checkh(e.next(2), E01);
+\t `checkh(e.prev, E01);
+\t `checkh(e.prev(1), E01);
+\t //Unsup: `checkh(e.prev(2), E04);
+\t e <= E04;
+ end
+ else if (cyc==3) begin
+\t `checks(e.name, ""E04"");
+\t `checkh(e.next, E01);
+\t `checkh(e.next(1), E01);
+\t //Unsup: `checkh(e.next(2), E03);
+\t `checkh(e.prev, E03);
+\t `checkh(e.prev(1), E03);
+\t //Unsup: `checkh(e.prev(2), E01);
+\t e <= E01;
+ end
+ else if (cyc==99) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2006 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ // verilator lint_off MULTIDRIVEN
+
+ wire [31:0] outb0c0;
+ wire [31:0] outb0c1;
+ wire [31:0] outb1c0;
+ wire [31:0] outb1c1;
+
+ reg [7:0] lclmem [7:0];
+
+ ma ma0 (.outb0c0(outb0c0), .outb0c1(outb0c1),
+\t .outb1c0(outb1c0), .outb1c1(outb1c1)
+\t );
+
+ global_mod #(32\'hf00d) global_cell ();
+ global_mod #(32\'hf22d) global_cell2 ();
+
+ input clk;
+ integer cyc=1;
+ always @ (posedge clk) begin
+ cyc <= cyc + 1;
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc%0d: %0x %0x %0x %0x\
+"", $time, cyc, outb0c0, outb0c1, outb1c0, outb1c1);
+`endif
+ if (cyc==2) begin
+\t if (global_cell.globali != 32\'hf00d) $stop;
+\t if (global_cell2.globali != 32\'hf22d) $stop;
+\t if (outb0c0 != 32\'h00) $stop;
+\t if (outb0c1 != 32\'h01) $stop;
+\t if (outb1c0 != 32\'h10) $stop;
+\t if (outb1c1 != 32\'h11) $stop;
+ end
+ if (cyc==3) begin
+\t // Can we scope down and read and write vars?
+\t ma0.mb0.mc0.out <= ma0.mb0.mc0.out + 32\'h100;
+\t ma0.mb0.mc1.out <= ma0.mb0.mc1.out + 32\'h100;
+\t ma0.mb1.mc0.out <= ma0.mb1.mc0.out + 32\'h100;
+\t ma0.mb1.mc1.out <= ma0.mb1.mc1.out + 32\'h100;
+ end
+ if (cyc==4) begin
+\t // Can we do dotted\'s inside array sels?
+\t ma0.rmtmem[ma0.mb0.mc0.out[2:0]] = 8\'h12;
+\t lclmem[ma0.mb0.mc0.out[2:0]] = 8\'h24;
+\t if (outb0c0 != 32\'h100) $stop;
+\t if (outb0c1 != 32\'h101) $stop;
+\t if (outb1c0 != 32\'h110) $stop;
+\t if (outb1c1 != 32\'h111) $stop;
+ end
+ if (cyc==5) begin
+\t if (ma0.rmtmem[ma0.mb0.mc0.out[2:0]] != 8\'h12) $stop;
+\t if (lclmem[ma0.mb0.mc0.out[2:0]] != 8\'h24) $stop;
+\t if (outb0c0 != 32\'h1100) $stop;
+\t if (outb0c1 != 32\'h2101) $stop;
+\t if (outb1c0 != 32\'h2110) $stop;
+\t if (outb1c1 != 32\'h3111) $stop;
+ end
+ if (cyc==6) begin
+\t if (outb0c0 != 32\'h31100) $stop;
+\t if (outb0c1 != 32\'h02101) $stop;
+\t if (outb1c0 != 32\'h42110) $stop;
+\t if (outb1c1 != 32\'h03111) $stop;
+ end
+ if (cyc==9) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+`ifdef USE_INLINE_MID
+ `define INLINE_MODULE /*verilator inline_module*/
+ `define INLINE_MID_MODULE /*verilator no_inline_module*/
+`else
+ `ifdef USE_INLINE
+ `define INLINE_MODULE /*verilator inline_module*/
+ `define INLINE_MID_MODULE /*verilator inline_module*/
+ `else
+ `define INLINE_MODULE /*verilator public_module*/
+ `define INLINE_MID_MODULE /*verilator public_module*/
+ `endif
+`endif
+
+module global_mod;
+ `INLINE_MODULE
+ parameter INITVAL = 0;
+ integer globali;
+ initial globali = INITVAL;
+endmodule
+
+module ma (
+ output wire [31:0] outb0c0,
+ output wire [31:0] outb0c1,
+ output wire [31:0] outb1c0,
+ output wire [31:0] outb1c1
+\t );
+ `INLINE_MODULE
+
+ reg [7:0] rmtmem [7:0];
+
+ mb #(0) mb0 (.outc0(outb0c0), .outc1(outb0c1));
+ mb #(1) mb1 (.outc0(outb1c0), .outc1(outb1c1));
+endmodule
+
+module mb (
+ output wire [31:0] outc0,
+ output wire [31:0] outc1
+ );
+ `INLINE_MID_MODULE
+ parameter P2 = 0;
+ mc #(P2,0) mc0 (.out(outc0));
+ mc #(P2,1) mc1 (.out(outc1));
+ global_mod #(32\'hf33d) global_cell2 ();
+
+ wire reach_up_clk = t.clk;
+ always @(reach_up_clk) begin
+ if (P2==0) begin // Only for mb0
+\t if (outc0 !== t.ma0.mb0.mc0.out) $stop; // Top module name and lower instances
+\t if (outc0 !== ma0.mb0.mc0.out) $stop; // Upper module name and lower instances
+\t if (outc0 !== ma .mb0.mc0.out) $stop; // Upper module name and lower instances
+\t if (outc0 !== mb.mc0.out) $stop; // This module name and lower instances
+\t if (outc0 !== mb0.mc0.out) $stop; // Upper instance name and lower instances
+\t if (outc0 !== mc0.out) $stop; // Lower instances
+
+\t if (outc1 !== t.ma0.mb0.mc1.out) $stop; // Top module name and lower instances
+\t if (outc1 !== ma0.mb0.mc1.out) $stop; // Upper module name and lower instances
+\t if (outc1 !== ma .mb0.mc1.out) $stop; // Upper module name and lower instances
+\t if (outc1 !== mb.mc1.out) $stop; // This module name and lower instances
+\t if (outc1 !== mb0.mc1.out) $stop; // Upper instance name and lower instances
+\t if (outc1 !== mc1.out) $stop; // Lower instances
+ end
+ end
+endmodule
+
+module mc (output reg [31:0] out);
+ `INLINE_MODULE
+ parameter P2 = 0;
+ parameter P3 = 0;
+ initial begin
+ out = {24\'h0,P2[3:0],P3[3:0]};
+ //$write(""%m P2=%0x p3=%0x out=%x\
+"",P2, P3, out);
+ end
+
+ // Can we look from the top module name down?
+ wire [31:0] reach_up_cyc = t.cyc;
+
+ always @ (posedge t.clk) begin
+ //$write(""[%0t] %m: Got reachup, cyc=%0d\
+"", $time, reach_up_cyc);
+ if (reach_up_cyc==2) begin
+\t if (global_cell.globali != 32\'hf00d) $stop;
+\t if (global_cell2.globali != 32\'hf33d) $stop;
+ end
+ if (reach_up_cyc==4) begin
+\t out[15:12] <= {P2[3:0]+P3[3:0]+4\'d1};
+ end
+ if (reach_up_cyc==5) begin
+\t // Can we set another instance?
+\t if (P3==1) begin // Without this, there are two possible correct answers...
+\t mc0.out[19:16] <= {mc0.out[19:16]+P2[3:0]+P3[3:0]+4\'d2};
+\t $display(""%m Set %x->%x %x %x %x %x"",mc0.out, {mc0.out[19:16]+P2[3:0]+P3[3:0]+4\'d2}, mc0.out[19:16],P2[3:0],P3[3:0],4\'d2);
+\t end
+ end
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+// bug823
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [6:0] in = crc[6:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [3:0]\t\tmask;\t\t\t// From test of Test.v
+ wire [3:0]\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[3:0]),
+\t .mask\t\t\t(mask[3:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(in[6:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {60\'h0, out & mask};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x out=%b mask=%b\
+"",$time, cyc, crc, out, mask);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= \'0;
+ end
+ else if (cyc<10) begin
+\t sum <= \'0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h4e9d3a74e9d3f656
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out, mask,
+ // Inputs
+ clk, in
+ );
+
+ input clk;
+ input [6:0] in;\t// Note much wider than any index
+ output reg [3:0] out;
+ output reg [3:0] mask;
+ localparam [15:5] p = 11\'h1ac;
+
+ always @(posedge clk) begin
+ // verilator lint_off WIDTH
+ out <= p[15 + in -: 5];
+ // verilator lint_on WIDTH
+ mask[3] <= ((15 + in - 5) < 12);
+ mask[2] <= ((15 + in - 5) < 13);
+ mask[1] <= ((15 + in - 5) < 14);
+ mask[0] <= ((15 + in - 5) < 15);
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// Use this file as a template for submitting bugs, etc.
+// This module takes a single clock input, and should either
+//\t$write(""*-* All Finished *-*\
+"");
+//\t$finish;
+// on success, or $stop.
+//
+// The code as shown applies a random vector to the Test
+// module, then calculates a CRC on the Test module\'s outputs.
+//
+// **If you do not wish for your code to be released to the public
+// please note it here, otherwise:**
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by ____YOUR_NAME_HERE____.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [255:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [127:0] in = {~crc[63:0], crc[63:0]};
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [127:0]\t\to1;\t\t\t// From test of Test.v
+ wire [127:0]\t\to2;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .o1\t\t\t(o1[127:0]),
+\t .o2\t\t\t(o2[127:0]),
+\t // Inputs
+\t .in\t\t\t(in[127:0]));
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x %x\
+"",$time, cyc, crc, o1, o2);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= {o1,o2} ^ {sum[254:0],sum[255]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= \'0;
+ end
+ else if (cyc<10) begin
+\t sum <= \'0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 256\'h008a080aaa000000140550404115dc7b008a080aaae7c8cd897bc1ca49c9350a
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ o1, o2,
+ // Inputs
+ in
+ );
+
+ input [127:0] in;
+ output logic [127:0] o1;
+ output logic [127:0] o2;
+
+ always_comb begin: b_test
+ logic [127:0] tmpp;
+ logic [127:0] tmp;
+ tmp = \'0;
+ tmpp = \'0;
+
+ tmp[63:0] = in[63:0];
+ tmpp[63:0] = in[63:0];
+
+ tmpp[63:0] = {tmp[0+:32], tmp[32+:32]};
+ tmp[63:0] = {tmp[0+:32], tmp[32+:32]};
+
+ o1 = tmp;
+ o2 = tmpp;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2005 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+
+ input clk;
+
+ reg \t reset_l;
+
+ // verilator lint_off GENCLK
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ // End of automatics
+
+ reg clkgate_e2r;
+ reg \t clkgate_e1r_l;
+ always @(posedge clk or negedge reset_l) begin
+ if (!reset_l) begin
+\t clkgate_e1r_l <= ~1\'b1;
+ end
+ else begin
+\t clkgate_e1r_l <= ~clkgate_e2r;
+ end
+ end
+
+ reg clkgate_e1f;
+ always @(negedge clk) begin
+ // Yes, it\'s really a =
+ clkgate_e1f = ~clkgate_e1r_l | ~reset_l;
+ end
+
+ wire clkgated = clk & clkgate_e1f;
+
+ reg [31:0] countgated;
+ always @(posedge clkgated or negedge reset_l) begin
+ if (!reset_l) begin
+\t countgated <= 32\'h1000;
+ end
+ else begin
+\t countgated <= countgated + 32\'d1;
+ end
+ end
+
+ reg [31:0] count;
+ always @(posedge clk or negedge reset_l) begin
+ if (!reset_l) begin
+\t count <= 32\'h1000;
+ end
+ else begin
+\t count <= count + 32\'d1;
+ end
+ end
+
+ reg [7:0] cyc; initial cyc=0;
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] rs %x cyc %d cg1f %x cnt %x cg %x\
+"",$time,reset_l,cyc,clkgate_e1f,count,countgated);
+`endif
+ cyc <= cyc + 8\'d1;
+ case (cyc)
+\t8\'d00: begin
+\t reset_l <= ~1\'b0;
+\t clkgate_e2r <= 1\'b1;
+\tend
+\t8\'d01: begin
+\t reset_l <= ~1\'b0;
+\tend
+\t8\'d02: begin
+\tend
+\t8\'d03: begin
+\t reset_l <= ~1\'b1;\t// Need a posedge
+\tend
+\t8\'d04: begin
+\tend
+\t8\'d05: begin
+\t reset_l <= ~1\'b0;
+\tend
+\t8\'d09: begin
+\t clkgate_e2r <= 1\'b0;
+\tend
+\t8\'d11: begin
+\t clkgate_e2r <= 1\'b1;
+\tend
+\t8\'d20: begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\tend
+\tdefault: ;
+ endcase
+ case (cyc)
+\t8\'d00: ;
+\t8\'d01: ;
+\t8\'d02: ;
+\t8\'d03: ;
+\t8\'d04: if (count!=32\'h00001000 || countgated!=32\'h 00001000) $stop;
+\t8\'d05: if (count!=32\'h00001000 || countgated!=32\'h 00001000) $stop;
+\t8\'d06: if (count!=32\'h00001000 || countgated!=32\'h 00001000) $stop;
+\t8\'d07: if (count!=32\'h00001001 || countgated!=32\'h 00001001) $stop;
+\t8\'d08: if (count!=32\'h00001002 || countgated!=32\'h 00001002) $stop;
+\t8\'d09: if (count!=32\'h00001003 || countgated!=32\'h 00001003) $stop;
+\t8\'d10: if (count!=32\'h00001004 || countgated!=32\'h 00001004) $stop;
+\t8\'d11: if (count!=32\'h00001005 || countgated!=32\'h 00001005) $stop;
+\t8\'d12: if (count!=32\'h00001006 || countgated!=32\'h 00001005) $stop;
+\t8\'d13: if (count!=32\'h00001007 || countgated!=32\'h 00001005) $stop;
+\t8\'d14: if (count!=32\'h00001008 || countgated!=32\'h 00001006) $stop;
+\t8\'d15: if (count!=32\'h00001009 || countgated!=32\'h 00001007) $stop;
+\t8\'d16: if (count!=32\'h0000100a || countgated!=32\'h 00001008) $stop;
+\t8\'d17: if (count!=32\'h0000100b || countgated!=32\'h 00001009) $stop;
+\t8\'d18: if (count!=32\'h0000100c || countgated!=32\'h 0000100a) $stop;
+\t8\'d19: if (count!=32\'h0000100d || countgated!=32\'h 0000100b) $stop;
+\t8\'d20: if (count!=32\'h0000100e || countgated!=32\'h 0000100c) $stop;
+\tdefault: $stop;
+ endcase
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2008 by Wilson Snyder.
+
+module t (a,z);
+ input a;
+ output z;
+
+ assign b = 1'b1;
+
+ or OR0 (nt0, a, b);
+
+ logic [1:0] dummy_ip;
+ assign {dummy1, dummy2} = dummy_ip;
+
+ assign z = nt0;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2011 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inouts
+ AVDD, AVSS
+ );
+ inout AVDD;
+ inout AVSS;
+
+ sub sub (/*AUTOINST*/
+\t // Inouts
+\t .AVDD\t\t\t(AVDD),
+\t .AVSS\t\t\t(AVSS));
+
+ initial begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+endmodule
+
+module sub (/*AUTOARG*/
+ // Inouts
+ AVDD, AVSS
+ );
+ // verilator no_inline_module
+ inout AVDD;
+ inout AVSS;
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2003 by Wilson Snyder.
+
+module t (clk);
+ input clk;
+
+ tpub p1 (.clk(clk), .i(32\'d1));
+ tpub p2 (.clk(clk), .i(32\'d2));
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t if (cyc==1) begin
+`ifdef verilator
+\t $c(""publicTop();"");
+`endif
+\t end
+\t if (cyc==20) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+\t end
+ end
+ end
+
+ task publicTop;
+ // verilator public
+ // We have different optimizations if only one of something, so try it out.
+ $write(""Hello in publicTop\
+"");
+ endtask
+
+endmodule
+
+module tpub (
+\t input clk,
+\t input [31:0] i);
+
+ reg [23:0] var_long;
+ reg [59:0] var_quad;
+ reg [71:0] var_wide;
+ reg \t var_bool;
+
+ // verilator lint_off BLKANDNBLK
+ reg [11:0] var_flop;
+ // verilator lint_on BLKANDNBLK
+
+ reg [23:0] got_long /*verilator public*/;
+ reg [59:0] got_quad /*verilator public*/;
+ reg [71:0] got_wide /*verilator public*/;
+ reg got_bool /*verilator public*/;
+
+ integer cyc; initial cyc=1;
+ always @ (posedge clk) begin
+ if (cyc!=0) begin
+\t cyc <= cyc + 1;
+\t // cyc==1 is in top level
+\t if (cyc==2) begin
+\t publicNoArgs;
+\t publicSetBool(1\'b1);
+\t publicSetLong(24\'habca);
+\t publicSetQuad(60\'h4444_3333_2222);
+\t publicSetWide(72\'h12_5678_9123_1245_2352);
+\t var_flop <= 12\'habe;
+\t end
+\t if (cyc==3) begin
+\t if (1\'b1 != publicGetSetBool(1\'b0)) $stop;
+\t if (24\'habca != publicGetSetLong(24\'h1234)) $stop;
+\t if (60\'h4444_3333_2222 != publicGetSetQuad(60\'h123_4567_89ab)) $stop;
+\t if (72\'h12_5678_9123_1245_2352 != publicGetSetWide(72\'hac_abca_aaaa_bbbb_1234)) $stop;
+\t end
+\t if (cyc==4) begin
+\t publicGetBool(got_bool);
+\t if (1\'b0 != got_bool) $stop;
+\t publicGetLong(got_long);
+\t if (24\'h1234 != got_long) $stop;
+\t publicGetQuad(got_quad);
+\t if (60\'h123_4567_89ab != got_quad) $stop;
+\t publicGetWide(got_wide);
+\t if (72\'hac_abca_aaaa_bbbb_1234 != got_wide) $stop;
+\t end
+\t //
+`ifdef VERILATOR_PUBLIC_TASKS
+\t if (cyc==11) begin
+\t $c(""publicNoArgs();"");
+\t $c(""publicSetBool(true);"");
+\t $c(""publicSetLong(0x11bca);"");
+\t $c(""publicSetQuad(VL_ULL(0x66655554444));"");
+\t $c(""publicSetFlop(0x321);"");
+\t //Unsupported: $c(""WData w[3] = {0x12, 0x5678_9123, 0x1245_2352}; publicSetWide(w);"");
+\t end
+\t if (cyc==12) begin
+\t $c(""got_bool = publicGetSetBool(true);"");
+\t $c(""got_long = publicGetSetLong(0x11bca);"");
+\t $c(""got_quad = publicGetSetQuad(VL_ULL(0xaaaabbbbcccc));"");
+\t end
+\t if (cyc==13) begin
+\t $c(""{ bool gb; publicGetBool(gb); got_bool=gb; }"");
+\t if (1\'b1 != got_bool) $stop;
+\t $c(""publicGetLong(got_long);"");
+\t if (24\'h11bca != got_long) $stop;
+\t $c(""{ vluint64_t qq; publicGetQuad(qq); got_quad=qq; }"");
+\t if (60\'haaaa_bbbb_cccc != got_quad) $stop;
+\t $c(""{ WData gw[3]; publicGetWide(gw); VL_ASSIGN_W(72,got_wide,gw); }"");
+\t if (72\'hac_abca_aaaa_bbbb_1234 != got_wide) $stop;
+\t //Below doesn\'t work, because we\'re calling it inside the loop that sets var_flop
+\t // if (12\'h321 != var_flop) $stop;
+\t end
+\t if (cyc==14) begin
+\t if ($c32(""publicInstNum()"") != i) $stop;
+\t end
+`endif
+ end
+ end
+
+ task publicEmpty;
+ // verilator public
+ begin end
+ endtask
+
+ task publicNoArgs;
+ // verilator public
+ $write(""Hello in publicNoArgs\
+"");
+ endtask
+
+ task publicSetBool;
+ // verilator public
+ input in_bool;
+ var_bool = in_bool;
+ endtask
+
+ task publicSetLong;
+ // verilator public
+ input [23:0] in_long;
+ reg [23:0] not_long;
+ begin
+\t not_long = ~in_long;\t// Test that we can have local variables
+\t var_long = ~not_long;
+ end
+ endtask
+
+ task publicSetQuad;
+ // verilator public
+ input [59:0] in_quad;
+ var_quad = in_quad;
+ endtask
+
+ task publicSetFlop;
+ // verilator public
+ input [11:0] in_flop;
+ var_flop = in_flop;
+ endtask
+
+ task publicSetWide;
+ // verilator public
+ input [71:0] in_wide;
+ var_wide = in_wide;
+ endtask
+
+ task publicGetBool;
+ // verilator public
+ output out_bool;
+ out_bool = var_bool;
+ endtask
+
+ task publicGetLong;
+ // verilator public
+ output [23:0] out_long;
+ out_long = var_long;
+ endtask
+
+ task publicGetQuad;
+ // verilator public
+ output [59:0] out_quad;
+ out_quad = var_quad;
+ endtask
+
+ task publicGetWide;
+ // verilator public
+ output [71:0] out_wide;
+ out_wide = var_wide;
+ endtask
+
+ function publicGetSetBool;
+ // verilator public
+ input in_bool;
+ begin
+\t publicGetSetBool = var_bool;
+\t var_bool = in_bool;
+ end
+ endfunction
+
+ function [23:0] publicGetSetLong;
+ // verilator public
+ input [23:0] in_long;
+ begin
+\t publicGetSetLong = var_long;
+\t var_long = in_long;
+ end
+ endfunction
+
+ function [59:0] publicGetSetQuad;
+ // verilator public
+ input [59:0] in_quad;
+ begin
+\t publicGetSetQuad = var_quad;
+\t var_quad = in_quad;
+ end
+ endfunction
+
+ function [71:0] publicGetSetWide;
+ // Can\'t be public, as no wide return types in C++
+ input [71:0] in_wide;
+ begin
+\t publicGetSetWide = var_wide;
+\t var_wide = in_wide;
+ end
+ endfunction
+
+`ifdef VERILATOR_PUBLIC_TASKS
+ function [31:0] publicInstNum;
+ // verilator public
+ publicInstNum = i;
+ endfunction
+`endif
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2014 by Wilson Snyder.
+
+// bug823
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [2:0] in = crc[2:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [3:0]\t\tmask;\t\t\t// From test of Test.v
+ wire [3:0]\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[3:0]),
+\t .mask\t\t\t(mask[3:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(in[2:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {60\'h0, out & mask};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x out=%b mask=%b\
+"",$time, cyc, crc, out, mask);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= \'0;
+ end
+ else if (cyc<10) begin
+\t sum <= \'0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'ha9d3a7a69d2bea75
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out, mask,
+ // Inputs
+ clk, in
+ );
+
+ input clk;
+ input [2:0] in;
+ output reg [3:0] out;
+ output reg [3:0] mask;
+ localparam [15:5] p = 11\'h1ac;
+
+ always @(posedge clk) begin
+ // verilator lint_off WIDTH
+ out <= p[15 + in -: 5];
+ // verilator lint_on WIDTH
+ mask[3] <= ((15 + in - 5) < 12);
+ mask[2] <= ((15 + in - 5) < 13);
+ mask[1] <= ((15 + in - 5) < 14);
+ mask[0] <= ((15 + in - 5) < 15);
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Iztok Jeras.
+
+module t (/*AUTOARG*/);
+
+ logic [3:0] array_simp [1:0] [3:0]; // big endian array
+
+ initial begin
+ array_simp[0] = \'{ 4\'d3, 4\'d2, 4\'d1, 4\'d0};
+ if ({array_simp[0][3],array_simp[0][2],array_simp[0][1],array_simp[0][0]} !== 16\'h3210) $stop;
+
+ // verilator lint_off WIDTH
+ array_simp[0] = \'{ 3 ,2 ,1, 0 };
+ // verilator lint_on WIDTH
+ if ({array_simp[0][3],array_simp[0][2],array_simp[0][1],array_simp[0][0]} !== 16\'h3210) $stop;
+
+ // Doesn\'t seem to work for unpacked arrays in other simulators
+ //array_simp[0] = \'{ 1:4\'d3, default:13 };
+ //if ({array_simp[0][3],array_simp[0][2],array_simp[0][1],array_simp[0][0]} !== 16\'hDD3D) $stop;
+
+ array_simp = \'{ \'{ 4\'d3, 4\'d2, 4\'d1, 4\'d0 }, \'{ 4\'d1, 4\'d2, 4\'d3, 4\'d4 }};
+ if ({array_simp[1][3],array_simp[1][2],array_simp[1][1],array_simp[1][0],
+\t array_simp[0][3],array_simp[0][2],array_simp[0][1],array_simp[0][0]} !== 32\'h3210_1234) $stop;
+
+ // Doesn\'t seem to work for unpacked arrays in other simulators
+ array_simp = \'{2{ \'{4\'d3, 4\'d2, 4\'d1, 4\'d0 } }};
+ if ({array_simp[1][3],array_simp[1][2],array_simp[1][1],array_simp[1][0],
+\t array_simp[0][3],array_simp[0][2],array_simp[0][1],array_simp[0][0]} !== 32\'h3210_3210) $stop;
+
+ array_simp = \'{2{ \'{4{ 4\'d3 }} }};
+ if ({array_simp[1][3],array_simp[1][2],array_simp[1][1],array_simp[1][0],
+\t array_simp[0][3],array_simp[0][2],array_simp[0][1],array_simp[0][0]} !== 32\'h3333_3333) $stop;
+
+ // Not legal in other simulators - replication doesn\'t match
+ // However IEEE suggests this is legal.
+ //array_simp = \'{2{ \'{2{ 4\'d3, 4\'d2 }} }}; // Note it\'s not \'{3,2}
+
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2012 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [31:0] in = crc[31:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [31:0]\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[31:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .in\t\t\t(in[31:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {32\'h0, out};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h458c2de282e30f8b
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ clk, in
+ );
+
+ input clk;
+ input [31:0] in;
+ output wire [31:0] out;
+
+ reg [31:0] \t stage [3:0];
+
+ genvar \t g;
+
+ generate
+ for (g=0; g<4; g++) begin
+\t always_comb begin
+\t if (g==0) stage[g] = in;
+\t else stage[g] = {stage[g-1][30:0],1\'b1};
+\t end
+ end
+ endgenerate
+
+ assign out = stage[3];
+endmodule
+"
+"// DESCRIPTION: Verilator: Simple test of unoptflat
+//
+// This should trigger the DETECTARRAY error like t_detectarray_1.v, but in
+// fact it casuses a broken link error. The only difference is that the struct
+// is defined using a constant rather than a localparam.
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2013 by Jeremy Bennett.
+
+localparam ID_MSB = 1;
+
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ typedef struct packed {
+ logic [1:0] \tid;
+ } context_t;
+
+ context_t tsb;
+
+ assign tsb.id = {tsb.id[0], clk};
+
+ initial begin
+ tsb.id = 0;
+ end
+
+ always @(posedge clk or negedge clk) begin
+
+`ifdef TEST_VERBOSE
+ $write(""tsb.id = %x\
+"", tsb.id);
+`endif
+
+ if (tsb.id[1] != 0) begin
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This file ONLY is placed into the Public Domain, for any use,
+// without warranty, 2009 by Wilson Snyder.
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ integer \tcyc=0;
+ reg [63:0] \tcrc;
+ reg [63:0] \tsum;
+
+ // Take CRC data and apply to testblock inputs
+ wire [31:0] in = crc[31:0];
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [63:0]\t\tout;\t\t\t// From test of Test.v
+ // End of automatics
+
+ wire\t\t\treset_l = ~(cyc<15);
+ wire [63:0] \t\td = crc[63:0];
+ wire [8:0] \t\tt_wa = crc[8:0];
+ wire [8:0] \t\tt_addr = {crc[18:17],3\'b0,crc[13:10]};
+
+ Test test (/*AUTOINST*/
+\t // Outputs
+\t .out\t\t\t(out[63:0]),
+\t // Inputs
+\t .clk\t\t\t(clk),
+\t .reset_l\t\t\t(reset_l),
+\t .t_wa\t\t\t(t_wa[8:0]),
+\t .d\t\t\t(d[63:0]),
+\t .t_addr\t\t\t(t_addr[8:0]));
+
+ // Aggregate outputs into a single result vector
+ wire [63:0] result = {out};
+
+ // Test loop
+ always @ (posedge clk) begin
+`ifdef TEST_VERBOSE
+ $write(""[%0t] cyc==%0d crc=%x result=%x\
+"",$time, cyc, crc, result);
+`endif
+ cyc <= cyc + 1;
+ crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
+ sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
+ if (cyc==0) begin
+\t // Setup
+\t crc <= 64\'h5aef0c8d_d70a4497;
+\t sum <= 64\'h0;
+ end
+ else if (cyc<10) begin
+\t sum <= 64\'h0;
+ end
+ else if (cyc<90) begin
+ end
+ else if (cyc==99) begin
+\t $write(""[%0t] cyc==%0d crc=%x sum=%x\
+"",$time, cyc, crc, sum);
+\t if (crc !== 64\'hc77bb9b3784ea091) $stop;
+\t // What checksum will we end up with (above print should match)
+`define EXPECTED_SUM 64\'h421a41d1541ea652
+\t if (sum !== `EXPECTED_SUM) $stop;
+\t $write(""*-* All Finished *-*\
+"");
+\t $finish;
+ end
+ end
+
+endmodule
+
+module Test (/*AUTOARG*/
+ // Outputs
+ out,
+ // Inputs
+ clk, reset_l, t_wa, d, t_addr
+ );
+ input\tclk;
+ input\treset_l;
+
+ reg [63:0] \tm_w0 [47:0];
+ reg [63:0] \tm_w1 [23:0];
+ reg [63:0] \tm_w2 [23:0];
+ reg [63:0] \tm_w3 [23:0];
+ reg [63:0] \tm_w4 [23:0];
+ reg [63:0] \tm_w5 [23:0];
+
+ input [8:0] \tt_wa;
+ input [63:0] \td;
+
+ always @ (posedge clk) begin
+ if (~reset_l) begin : blk
+\t integer i;
+
+\t for (i=0; i<48; i=i+1) begin
+\t m_w0[i] <= 64\'h0;
+\t end
+
+\t for (i=0; i<24; i=i+1) begin
+\t m_w1[i] <= 64\'h0;
+\t m_w2[i] <= 64\'h0;
+\t m_w3[i] <= 64\'h0;
+\t m_w4[i] <= 64\'h0;
+\t m_w5[i] <= 64\'h0;
+\t end
+ end
+ else begin
+\t casez (t_wa[8:6])
+\t 3\'d0: m_w0[t_wa[5:0]] <= d;
+\t 3\'d1: m_w1[t_wa[4:0]] <= d;
+\t 3\'d2: m_w2[t_wa[4:0]] <= d;
+\t 3\'d3: m_w3[t_wa[4:0]] <= d;
+\t 3\'d4: m_w4[t_wa[4:0]] <= d;
+\t default: m_w5[t_wa[4:0]] <= d;
+\t endcase
+ end
+ end
+
+ input [8:0] t_addr;
+
+ wire [63:0]\tt_w0 = m_w0[t_addr[5:0]];
+ wire [63:0]\tt_w1 = m_w1[t_addr[4:0]];
+ wire [63:0]\tt_w2 = m_w2[t_addr[4:0]];
+ wire [63:0]\tt_w3 = m_w3[t_addr[4:0]];
+ wire [63:0]\tt_w4 = m_w4[t_addr[4:0]];
+ wire [63:0]\tt_w5 = m_w5[t_addr[4:0]];
+
+ output reg [63:0] \tout;
+ always @* begin
+ casez (t_addr[8:6])
+\t3\'d0: out = t_w0;
+\t3\'d1: out = t_w1;
+\t3\'d2: out = t_w2;
+\t3\'d3: out = t_w3;
+\t3\'d4: out = t_w4;
+\tdefault: out = t_w5;
+ endcase
+ end
+
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module
+//
+// This test case is used for testing a modeule parameterized with a typed
+// localparam.
+//
+// We find Verilator appears to mis-evaluate the parameter WIDTH as -16 when
+// used in the test module to set the value of MSB. A number of warnings and
+// errors follow, starting with:
+//
+// %Warning-LITENDIAN: t/t_param_module.v:42: Little bit endian vector: MSB
+// < LSB of bit range: -17:0
+//
+// This file ONLY is placed into the Public Domain, for any use, without
+// warranty, 2013 by Jie Xu.
+
+// bug606
+
+module t (/*AUTOARG*/
+ // Inputs
+ clk
+ );
+ input clk;
+
+ localparam logic[4:0] WID = 16;
+ //localparam WID = 16;\t// No problem if defined like this
+ wire [15:0] b33;
+
+ test #(WID) i_test_33(.clk (clk),
+\t\t\t.b (b33));
+
+endmodule
+
+
+module test (/*AUTOARG*/
+ //Inputs
+ clk,
+ // Outputs
+ b
+ );
+ parameter WIDTH = 10;
+ localparam MSB = WIDTH - 1;
+
+ input clk;
+ output wire [MSB:0] b;
+
+ wire [MSB:0] a;
+ assign b = {~a[MSB-1:0], clk};
+
+ initial begin
+ if ($bits(WIDTH)!=5) $stop; // Comes from the parent!
+ if ($bits(MSB)!=32) $stop;
+ $write(""*-* All Finished *-*\
+"");
+ $finish;
+ end
+endmodule
+"
+"// DESCRIPTION: Verilator: Verilog Test module\r
+//\r
+// This file ONLY is placed into the Public Domain, for any use,\r
+// without warranty, 2003 by Wilson Snyder.\r
+\r
+// This file has DOS carrage returns in it!\r
+module t (/*AUTOARG*/\r
+ // Inputs\r
+ clk\r
+ );\r
+\r
+ input clk;\r
+\r
+ always @ (posedge clk) begin\r
+ $write(""*-* All Finished *-*\
+"");\r
+ $finish;\r
+ end\r
+\r
+endmodule\r
+// This file has DOS carrage returns in it!\r
+"
+"//-------------------------------------------------------------------
+//-- txchar_tb.v
+//-- Testbench for the simulation of the txchar.v example
+//-------------------------------------------------------------------
+//-- (c) BQ December 2015. Written by Juan Gonzalez (Obijuan)
+//-------------------------------------------------------------------
+//-- GPL License
+//-------------------------------------------------------------------
+`default_nettype none
+`timescale 100 ns / 1 ns
+
+`include ""baudgen.vh""
+
+
+module txchar_tb();
+
+//-- Baudrate for the simulation
+localparam BAUDRATE = `B115200;
+
+//-- clock tics needed for sending one serial package
+localparam SERIAL_CHAR = (BAUDRATE * 10);
+
+//-- System clock
+reg clk = 0;
+
+//-- Transmission line
+wire tx;
+
+//-- Reset
+reg rstn = 0;
+
+//-- Instantiate the entity the character transmitter
+txchar dut(
+ .clk(clk),
+ .rstn(rstn),
+ .tx(tx)
+);
+
+//-- Clock generator
+always
+ # 0.5 clk <= ~clk;
+
+
+initial begin
+
+ //-- File where to store the simulation
+ $dumpfile(""txchar_tb.vcd"");
+ $dumpvars(0, txchar_tb);
+
+ //-- Activate reset
+ #1 rstn <= 0;
+
+ //-- Disable the reset. The transmission begins!
+ #5 rstn <= 1;
+
+ //-- Wait for 3 characters and finish
+ #(SERIAL_CHAR * 3) $display(""END of simulation"");
+ $finish;
+end
+
+endmodule
+"
+"//----------------------------------------------------------------------------
+//-- Memoria ROM gen\xc3\xa9rica
+//------------------------------------------
+//-- (C) BQ. October 2015. Written by Juan Gonzalez (Obijuan)
+//-- GPL license
+//----------------------------------------------------------------------------
+//-- Memoria con los siguientes parametros:
+//-- * AW: Numero de bits de las direcciones
+//-- * DW: Numero de bits de los datos
+//-- * ROMFILE: Fichero a usar para cargar la memoria
+//--
+//-- Con este componente podemos hacer memorias rom de cualquier tama\xc3\xb1o
+//----------------------------------------------------------------------------
+
+module genrom #( //-- Parametros
+ parameter AW = 6, //-- Bits de las direcciones (Adress width)
+ parameter DW = 8) //-- Bits de los datos (Data witdh)
+
+ ( //-- Puertos
+ input clk, //-- Se\xc3\xb1al de reloj global
+ input wire [AW-1: 0] addr, //-- Direcciones
+ output reg [DW-1: 0] data); //-- Dato de salida
+
+//-- Parametro: Nombre del fichero con el contenido de la ROM
+parameter ROMFILE = ""rom1.list"";
+
+//-- Calcular el numero de posiciones totales de memoria
+localparam NPOS = 2 ** AW;
+
+ //-- Memoria
+ reg [DW-1: 0] rom [0: NPOS-1];
+
+ //-- Lectura de la memoria
+ always @(posedge clk) begin
+ data <= rom[addr];
+ end
+
+//-- Cargar en la memoria el fichero ROMFILE
+//-- Los valores deben estan dados en hexadecimal
+initial begin
+ $readmemh(ROMFILE, rom);
+end
+
+
+endmodule
+"
+"`default_nettype none
+
+//-- Servo test
+module ServoUnit(input wire clk, //-- System clock
+ input wire [7:0] pos, //-- Servo pos 0 - 255
+ output reg servo); //-- Servo control signal
+
+localparam M = 93; //-- 94
+localparam N = $clog2(M);
+
+reg [N-1:0] divcounter = 0;
+reg tic = 0;
+
+//-- Ticks generation. A pulse is emmited every M system clock cycles
+always @(posedge clk)
+ tic <= (divcounter == M - 2);
+
+//-- Module M counter
+always @(posedge clk)
+ if (tic)
+ divcounter <= 0;
+ else
+ divcounter <= divcounter + 1;
+
+//-- Angle counter
+reg [10:0] angle_counter = 0;
+
+wire [8:0] pose = {1'b0, pos} + 9'd46;
+
+always @(posedge clk)
+ if (tic)
+ angle_counter <= angle_counter + 1;
+
+always @(posedge clk)
+ servo <= (angle_counter < {3'b00, pose});
+
+
+endmodule
+"
+"`include ""divider.vh""
+
+`default_nettype none
+
+//-- Servo test
+module test(input wire clk,
+ output wire clk_out,
+ output wire led0);
+
+parameter WAIT_DELAY = `T_16ms;
+parameter SPEED = 1;
+
+//-- Just for debugging
+assign led0 = 1;
+
+reg [7:0] pos = 8\'h0;
+
+//-- Intantiate the servo unit
+ServoUnit
+ SERVO0 (.clk(clk),
+ .pos(pos),
+ .servo(clk_out));
+
+wire tic2;
+
+reg fw = 1;
+
+always @(posedge clk)
+ if (tic2)
+ if (fw)
+ pos <= pos + SPEED;
+ else
+ pos <= pos - SPEED;
+
+always @(posedge clk)
+ if (fw) begin
+ if (pos > 255 - SPEED)
+ fw <= 0;
+ end
+ else if (pos < (SPEED+1))
+ fw <= 1;
+
+
+dividerp1 #(WAIT_DELAY)
+ TIMMER0 (.clk(clk),
+ .timer_ena(1\'b1),
+ .clk_out(tic2));
+
+
+endmodule
+"
+"`include ""divider.vh""
+
+`default_nettype none
+
+//-- Servo test
+module osc(input wire clk,
+ output wire s0,
+ output wire s1,
+ output wire led0);
+
+parameter WAIT_DELAY = `T_50ms + `T_10ms;
+
+//-- Fichero con la rom
+parameter ROMFILE0 = ""rom0.list"";
+parameter ROMFILE1 = ""rom1.list"";
+
+//-- Numero de bits de la direccione
+parameter AW = 5;
+parameter DW = 8;
+
+//-- Just for debugging
+assign led0 = s0;
+
+wire [7:0] pos0;
+wire [7:0] pos1;
+
+//-- Intantiate the servo unit
+ServoUnit
+ SERVO0 (.clk(clk),
+ .pos({1\'b0,pos0[7:1]} + 8\'d64),
+ .servo(s0));
+
+ServoUnit
+ SERVO1 (.clk(clk),
+ .pos({1\'b0,pos1[7:1]} + 8\'d64),
+ .servo(s1));
+
+wire tic;
+
+dividerp1 #(WAIT_DELAY)
+ TIMMER0 (.clk(clk),
+ .timer_ena(1\'b1),
+ .clk_out(tic));
+
+reg [AW-1: 0] addr = 0; //-- Bus de direcciones
+reg [DW-1: 0] data; //-- Bus de datos
+
+always @(posedge clk)
+ if (tic)
+ addr <= addr + 1;
+
+genrom
+ #( .ROMFILE(ROMFILE0), //-- Asignacion de parametros
+ .AW(AW),
+ .DW(DW))
+ ROM0 ( //-- coneion de cables
+ .clk(clk),
+ .addr(addr),
+ .data(pos0)
+ );
+
+
+ genrom
+ #( .ROMFILE(ROMFILE1), //-- Asignacion de parametros
+ .AW(AW),
+ .DW(DW))
+ ROM1 ( //-- coneion de cables
+ .clk(clk),
+ .addr(addr),
+ .data(pos1)
+ );
+
+
+
+
+
+
+endmodule
+"
+"//----------------------------------------------------------------------------
+//-- Asynchronous serial transmitter Unit
+//------------------------------------------
+//-- (C) BQ. December 2015. Written by Juan Gonzalez (Obijuan)
+//-- GPL license
+//----------------------------------------------------------------------------
+//-- Tested at all the standard baudrates:
+//-- 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200
+//----------------------------------------------------------------------------
+//-- Although this transmitter has been written from the scratch, it has been
+//-- inspired by the one developed in the swapforth proyect by James Bowman
+//--
+//-- https://github.com/jamesbowman/swapforth
+//--
+//----------------------------------------------------------------------------
+`default_nettype none
+
+`include ""baudgen.vh""
+
+//--- Serial transmitter unit module
+//--- TX output is not registered
+module uart_tx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire clk, //-- System clcok (12MHz in the ICEstick)
+ input wire rstn, //-- Reset (Active low)
+ input wire start, //-- Set to 1 for starting the transmission
+ input wire [7:0] data, //-- Byte to transmit
+ output reg tx, //-- Serial data output
+ output reg ready //-- Transmitter ready (1) / busy (0)
+);
+
+
+//-- Transmission clock
+wire clk_baud;
+
+//-- Bitcounter
+reg [3:0] bitc;
+
+//-- Registered data
+reg [7:0] data_r;
+
+//--------- control signals
+reg load; //-- Load the shifter register / reset
+reg baud_en; //-- Enable the baud generator
+
+//-------------------------------------
+//-- DATAPATH
+//-------------------------------------
+
+//-- Register the input data
+always @(posedge clk)
+ if (start == 1 && state == IDLE)
+ data_r <= data;
+
+//-- 1 bit start + 8 bits datos + 1 bit stop
+//-- Shifter register. It stored the frame to transmit:
+//-- 1 start bit + 8 data bits + 1 stop bit
+reg [9:0] shifter;
+
+//-- When the control signal load is 1, the frame is loaded
+//-- when load = 0, the frame is shifted right to send 1 bit,
+//-- at the baudrate determined by clk_baud
+//-- 1s are introduced by the left
+always @(posedge clk)
+ //-- Reset
+ if (rstn == 0)
+ shifter <= 10\'b11_1111_1111;
+
+ //-- Load mode
+ else if (load == 1)
+ shifter <= {data_r,2\'b01};
+
+ //-- Shift mode
+ else if (load == 0 && clk_baud == 1)
+ shifter <= {1\'b1, shifter[9:1]};
+
+//-- Sent bit counter
+//-- When load (=1) the counter is reset
+//-- When load = 0, the sent bits are counted (with the raising edge of clk_baud)
+always @(posedge clk)
+ if (!rstn)
+ bitc <= 0;
+
+ else if (load == 1)
+ bitc <= 0;
+ else if (load == 0 && clk_baud == 1)
+ bitc <= bitc + 1;
+
+//-- The less significant bit is transmited through tx
+//-- It is a registed output, because tx is connected to an Asynchronous bus
+//-- and the glitches should be avoided
+always @(posedge clk)
+ tx <= shifter[0];
+
+//-- Baud generator
+baudgen_tx #( .BAUDRATE(BAUDRATE))
+BAUD0 (
+ .rstn(rstn),
+ .clk(clk),
+ .clk_ena(baud_en),
+ .clk_out(clk_baud)
+ );
+
+//------------------------------
+//-- CONTROLLER
+//------------------------------
+
+//-- fsm states
+localparam IDLE = 0; //-- Idle state
+localparam START = 1; //-- Start transmission
+localparam TRANS = 2; //-- Transmitting data
+
+//-- Registers for storing the states
+reg [1:0] state;
+reg [1:0] next_state;
+
+//-- Transition between states
+always @(posedge clk)
+ if (!rstn)
+ state <= IDLE;
+ else
+ state <= next_state;
+
+//-- Control signal generation and next states
+always @(*) begin
+
+ //-- Default values
+ next_state = state; //-- Stay in the same state by default
+ load = 0;
+ baud_en = 0;
+
+ case (state)
+
+ //-- Idle state
+ //-- Remain in this state until start is 1
+ IDLE: begin
+ ready = 1;
+ if (start == 1)
+ next_state = START;
+ end
+
+ //-- 1 cycle long
+ //-- turn on the baudrate generator and the load the shift register
+ START: begin
+ load = 1;
+ baud_en = 1;
+ ready = 0;
+ next_state = TRANS;
+ end
+
+ //-- Stay here until all the bits have been sent
+ TRANS: begin
+ baud_en = 1;
+ ready = 0;
+ if (bitc == 11)
+ next_state = IDLE;
+ end
+
+ default:
+ ready = 0;
+
+ endcase
+end
+
+endmodule
+"
+"//-------------------------------------------------------------------
+//-- txstr_tb.v
+//-- Testbench for the simulation of the txstr.v example
+//-------------------------------------------------------------------
+//-- (c) BQ December 2015. Written by Juan Gonzalez (Obijuan)
+//-------------------------------------------------------------------
+//-- GPL License
+//-------------------------------------------------------------------
+`default_nettype none
+`timescale 100 ns / 10 ns
+
+`include ""baudgen.vh""
+
+
+module txstr_tb();
+
+//-- Baudrate for the simulation
+localparam BAUDRATE = `B115200;
+
+//-- clock tics needed for sending one serial package
+localparam SERIAL_CAR = (BAUDRATE * 10);
+
+//-- System clock
+reg clk = 1;
+
+//-- Transmission line
+wire tx;
+
+//-- Reset
+reg rstn = 0;
+
+//-- Instantiate the entity the character transmitter
+txstr #(
+ .BAUDRATE(BAUDRATE)
+)
+dut (
+ .clk(clk),
+ .rstn(rstn),
+ .tx(tx)
+);
+
+//-- Clock generator
+always
+ # 0.5 clk <= ~clk;
+
+
+initial begin
+
+ //-- File where to store the simulation
+ $dumpfile(""txstr_tb.vcd"");
+ $dumpvars(0, txstr_tb);
+
+ //-- Activate reset
+ #1 rstn <= 0;
+
+ //-- Disable the reset. The transmission begins!
+ #3 rstn <= 1;
+
+ //-- Wait for 3 characters and finish
+ #(SERIAL_CAR * 10) $display(""END of simulation"");
+ $finish;
+end
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//-- Baudrate generator
+//-- It generates a square signal, with a frequency for communicating at the given
+//-- given baudrate
+//-- The output is set to 1 only during one clock cycle. The rest of the time is 0
+//-- Once enabled, the pulse is generated just in the middle of the period
+//-- This is necessary for the implementation of the receptor
+//--------------------------------------------------------------------------------
+//-- (c) BQ. December 2015. written by Juan Gonzalez (obijuan)
+//-----------------------------------------------------------------------------
+//-- GPL license
+//-----------------------------------------------------------------------------
+`include ""baudgen.vh""
+
+//----------------------------------------------------------------------------------------
+//-- baudgen module
+//--
+//-- INPUTS:
+//-- -clk: System clock (12 MHZ in the iceStick board)
+//-- -clk_ena: clock enable:
+//-- 1. Normal working: The squeare signal is generated
+//-- 0: stoped. Output always 0
+//-- OUTPUTS:
+//-- - clk_out: Output signal. Pulse width: 1 clock cycle. Output not registered
+//-- It tells the uart_rx when to sample the next bit
+//-- __ __
+//-- ____________________| |________________________________________| |_____________________
+//-- | -> <- 1 clock cycle |
+//-- <------- Period ------------------------->
+//--
+//---------------------------------------------------------------------------------------
+module baudgen_rx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire rstn, //-- Reset (active low)
+ input wire clk, //-- System clock
+ input wire clk_ena, //-- Clock enable
+ output wire clk_out //-- Bitrate Clock output
+);
+
+//-- Number of bits needed for storing the baudrate divisor
+localparam N = $clog2(BAUDRATE);
+
+//-- Value for generating the pulse in the middle of the period
+localparam M2 = (BAUDRATE >> 1);
+
+//-- Counter for implementing the divisor (it is a BAUDRATE module counter)
+//-- (when BAUDRATE is reached, it start again from 0)
+reg [N-1:0] divcounter = 0;
+
+//-- Contador m\xc3\xb3dulo M
+always @(posedge clk)
+
+ if (!rstn)
+ divcounter <= 0;
+
+ else if (clk_ena)
+ //-- Normal working: counting. When the maximum count is reached, it starts from 0
+ divcounter <= (divcounter == BAUDRATE - 1) ? 0 : divcounter + 1;
+ else
+ //-- Counter fixed to its maximum value
+ //-- When it is resumed it start from 0
+ divcounter <= BAUDRATE - 1;
+
+//-- The output is 1 when the counter is in the middle of the period, if clk_ena is active
+//-- It is 1 only for one system clock cycle
+assign clk_out = (divcounter == M2) ? clk_ena : 0;
+
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//-- Baudrate generator
+//-- It generates a square signal, with a frequency for communicating at the given
+//-- given baudrate
+//-- The output is set to 1 only during one clock cycle. The rest of the time is 0
+//--------------------------------------------------------------------------------
+//-- (c) BQ. December 2015. written by Juan Gonzalez (obijuan)
+//-----------------------------------------------------------------------------
+//-- GPL license
+//-----------------------------------------------------------------------------
+`default_nettype none
+`include ""baudgen.vh""
+
+//----------------------------------------------------------------------------------------
+//-- baudgen module
+//--
+//-- INPUTS:
+//-- -clk: System clock (12 MHZ in the iceStick board)
+//-- -clk_ena: clock enable:
+//-- 1. Normal working: The squeare signal is generated
+//-- 0: stoped. Output always 0
+//-- OUTPUTS:
+//-- - clk_out: Output signal. Pulse width: 1 clock cycle. Output not registered
+//-- It tells the uart_tx when to transmit the next bit
+//-- __ __
+//-- __| |________________________________________________________| |________________
+//-- -> <- 1 clock cycle
+//--
+//---------------------------------------------------------------------------------------
+module baudgen_tx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire rstn, //-- Reset (active low)
+ input wire clk, //-- System clock
+ input wire clk_ena, //-- Clock enable
+ output wire clk_out //-- Bitrate Clock output
+);
+
+//-- Number of bits needed for storing the baudrate divisor
+localparam N = $clog2(BAUDRATE);
+
+//-- Counter for implementing the divisor (it is a BAUDRATE module counter)
+//-- (when BAUDRATE is reached, it start again from 0)
+reg [N-1:0] divcounter = 0;
+
+always @(posedge clk)
+
+ if (!rstn)
+ divcounter <= 0;
+
+ else if (clk_ena)
+ //-- Normal working: counting. When the maximum count is reached, it starts from 0
+ divcounter <= (divcounter == BAUDRATE - 1) ? 0 : divcounter + 1;
+ else
+ //-- Counter fixed to its maximum value
+ //-- When it is resumed it start from 0
+ divcounter <= BAUDRATE - 1;
+
+//-- The output is 1 when the counter is 0, if clk_ena is active
+//-- It is 1 only for one system clock cycle
+assign clk_out = (divcounter == 0) ? clk_ena : 0;
+
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//-- Divisor de reloj
+//-- Se\xc3\xb1al de periodo igual al indicado
+//-- El ancho del pulso positivo es de 1 ciclo de reloj
+//--
+//-- (c) BQ. September 2015. written by Juan Gonzalez (obijuan)
+//-----------------------------------------------------------------------------
+//-- GPL license
+//-----------------------------------------------------------------------------
+`include ""divider.vh""
+
+//-- ENTRADAS:
+//-- -clk: Senal de reloj del sistema (12 MHZ en la iceStick)
+//
+//-- SALIDAS:
+//-- - clk_out. Se\xc3\xb1al de salida para lograr la velocidad en baudios indicada
+//-- Anchura de 1 periodo de clk. SALIDA NO REGISTRADA
+module dividerp1(input wire clk,
+ input wire timer_ena,
+ output wire clk_out);
+
+//-- Valor por defecto de la velocidad en baudios
+parameter M = `T_100ms;
+
+//-- Numero de bits para almacenar el divisor de baudios
+localparam N = $clog2(M);
+
+//-- Registro para implementar el contador modulo M
+reg [N-1:0] divcounter = 0;
+
+//-- Contador m\xc3\xb3dulo M
+always @(posedge clk)
+ if (timer_ena)
+ divcounter <= (divcounter == M - 1) ? 0 : divcounter + 1;
+ else
+ divcounter <= 0;
+
+//-- Sacar un pulso de anchura 1 ciclo de reloj si el generador
+assign clk_out = (divcounter == M - 1) ? 1 : 0;
+
+
+endmodule
+"
+"//----------------------------------------------------------------------------
+//-- rxleds: Uart-rx example 1
+//-- The 4-bits less significant of the character received are shown in the
+//-- red leds of the icestick board
+//----------------------------------------------------------------------------
+//-- (C) BQ. December 2015. Written by Juan Gonzalez (Obijuan)
+//-- GPL license
+//----------------------------------------------------------------------------
+`default_nettype none
+`include ""baudgen.vh""
+
+//-- Top entity
+module rxleds #(
+ parameter BAUDRATE = `B115200
+)(
+ input wire clk, //-- System clock
+ input wire rx, //-- Serial input
+ output reg [3:0] leds //-- Red leds
+);
+
+//-- Received character signal
+wire rcv;
+
+//-- Received data
+wire [7:0] data;
+
+//-- Reset signal
+reg rstn = 0;
+
+//-- Initialization
+always @(posedge clk)
+ rstn <= 1;
+
+//-- Receiver unit instantation
+uart_rx #(BAUDRATE)
+ RX0 (.clk(clk), //-- System clock
+ .rstn(rstn), //-- Reset (Active low)
+ .rx(rx), //-- Serial input
+ .rcv(rcv), //-- Character received notification (1)
+ .data(data) //-- Character received
+ );
+
+//-- Register the character received and show its 4 less significant leds
+//-- in the icestick leds
+always @(posedge clk)
+ if (!rstn)
+ leds <= 0;
+
+ //-- When there is data available, capture it!
+ else if (rcv == 1\'b1)
+ leds <= data[3:0];
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//-- Baudrate generator
+//-- It generates a square signal, with a frequency for communicating at the given
+//-- given baudrate
+//-- The output is set to 1 only during one clock cycle. The rest of the time is 0
+//--------------------------------------------------------------------------------
+//-- (c) BQ. December 2015. written by Juan Gonzalez (obijuan)
+//-----------------------------------------------------------------------------
+//-- GPL license
+//-----------------------------------------------------------------------------
+`default_nettype none
+`include ""baudgen.vh""
+
+//----------------------------------------------------------------------------------------
+//-- baudgen module
+//--
+//-- INPUTS:
+//-- -clk: System clock (12 MHZ in the iceStick board)
+//-- -clk_ena: clock enable:
+//-- 1. Normal working: The squeare signal is generated
+//-- 0: stoped. Output always 0
+//-- OUTPUTS:
+//-- - clk_out: Output signal. Pulse width: 1 clock cycle. Output not registered
+//-- It tells the uart_tx when to transmit the next bit
+//-- __ __
+//-- __| |________________________________________________________| |________________
+//-- -> <- 1 clock cycle
+//--
+//---------------------------------------------------------------------------------------
+module baudgen_tx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire rstn, //-- Reset (active low)
+ input wire clk, //-- System clock
+ input wire clk_ena, //-- Clock enable
+ output wire clk_out //-- Bitrate Clock output
+);
+
+//-- Number of bits needed for storing the baudrate divisor
+localparam N = $clog2(BAUDRATE);
+
+//-- Counter for implementing the divisor (it is a BAUDRATE module counter)
+//-- (when BAUDRATE is reached, it start again from 0)
+reg [N-1:0] divcounter = 0;
+
+always @(posedge clk)
+
+ if (!rstn)
+ divcounter <= 0;
+
+ else if (clk_ena)
+ //-- Normal working: counting. When the maximum count is reached, it starts from 0
+ divcounter <= (divcounter == BAUDRATE - 1) ? 0 : divcounter + 1;
+ else
+ //-- Counter fixed to its maximum value
+ //-- When it is resumed it start from 0
+ divcounter <= BAUDRATE - 1;
+
+//-- The output is 1 when the counter is 0, if clk_ena is active
+//-- It is 1 only for one system clock cycle
+assign clk_out = (divcounter == 0) ? clk_ena : 0;
+
+
+endmodule
+"
+"//----------------------------------------------------------------------------
+//-- Asynchronous serial receiver Unit
+//------------------------------------------
+//-- (C) BQ. December 2015. Written by Juan Gonzalez (Obijuan)
+//-- GPL license
+//----------------------------------------------------------------------------
+//-- Tested at the standard baudrates:
+//-- 300, 600, 1200, 4800, 9600, 19200, 38400, 115200
+//----------------------------------------------------------------------------
+//-- Although this transmitter has been written from the scratch, it has been
+//-- inspired by the one developed in the swapforth proyect by James Bowman
+//--
+//-- https://github.com/jamesbowman/swapforth
+//--
+//----------------------------------------------------------------------------
+`default_nettype none
+
+`include ""baudgen.vh""
+
+//-- Serial receiver unit module
+module uart_rx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire clk, //-- System clock (12MHz in the ICEstick)
+ input wire rstn, //-- Reset (Active low)
+ input wire rx, //-- Serial data input
+ output reg rcv, //-- Data is available (1)
+ output reg [7:0] data //-- Data received
+);
+
+//-- Transmission clock
+wire clk_baud;
+
+//-- Control signals
+reg bauden; //-- Enable the baud generator
+reg clear; //-- Clear the bit counter
+reg load; //-- Load the received character into the data register
+
+
+//-------------------------------------------------------------------
+//-- DATAPATH
+//-------------------------------------------------------------------
+
+//-- The serial input is registered in order to follow the
+//-- synchronous design rules
+reg rx_r;
+
+always @(posedge clk)
+ rx_r <= rx;
+
+//-- Baud generator
+baudgen_rx #(BAUDRATE)
+ baudgen0 (
+ .rstn(rstn),
+ .clk(clk),
+ .clk_ena(bauden),
+ .clk_out(clk_baud)
+ );
+
+//-- Bit counter
+reg [3:0] bitc;
+
+always @(posedge clk)
+ if (clear)
+ bitc <= 4\'d0;
+ else if (clear == 0 && clk_baud == 1)
+ bitc <= bitc + 1;
+
+
+//-- Shift register for storing the received bits
+reg [9:0] raw_data;
+
+always @(posedge clk)
+ if (clk_baud == 1)
+ raw_data <= {rx_r, raw_data[9:1]};
+
+//-- Data register. Store the character received
+always @(posedge clk)
+ if (rstn == 0)
+ data <= 0;
+ else if (load)
+ data <= raw_data[8:1];
+
+//-------------------------------------------
+//-- CONTROLLER (Finite state machine)
+//-------------------------------------------
+
+//-- Receiver states
+localparam IDLE = 2\'d0; //-- IDLEde reposo
+localparam RECV = 2\'d1; //-- Receiving data
+localparam LOAD = 2\'d2; //-- Storing the character received
+localparam DAV = 2\'d3; //-- Data is available
+
+//-- fsm states
+reg [1:0] state;
+reg [1:0] next_state;
+
+//-- Transition between states
+always @(posedge clk)
+ if (!rstn)
+ state <= IDLE;
+ else
+ state <= next_state;
+
+//-- Control signal generation and next states
+always @(*) begin
+
+ //-- Default values
+ next_state = state; //-- Stay in the same state by default
+ bauden = 0;
+ clear = 0;
+ load = 0;
+
+ case(state)
+
+ //-- Idle state
+ //-- Remain in this state until a start bit is received in rx_r
+ IDLE: begin
+ clear = 1;
+ rcv = 0;
+ if (rx_r == 0)
+ next_state = RECV;
+ end
+
+ //-- Receiving state
+ //-- Turn on the baud generator and wait for the serial package to be received
+ RECV: begin
+ bauden = 1;
+ rcv = 0;
+ if (bitc == 4\'d10)
+ next_state = LOAD;
+ end
+
+ //-- Store the received character in the data register (1 cycle)
+ LOAD: begin
+ load = 1;
+ rcv = 0;
+ next_state = DAV;
+ end
+
+ //-- Data Available (1 cycle)
+ DAV: begin
+ rcv = 1;
+ next_state = IDLE;
+ end
+
+ default:
+ rcv = 0;
+
+ endcase
+
+end
+
+endmodule
+"
+"//-----------------------------------------------------------------------------------------
+//-- txchar: Uart_tx example 1
+//-- Continuous transmission of a character when the DTR signal is activated
+//-- The reset signal is connected to the dtr signal (in file txchar.pcf)
+//-- Fot this example to work is necessary to open a serial terminal (gtkterm for example)
+//-- and deactivate DTR. A lot of ""A"" will be received on the terminal
+//-- Fixed BAUDRATE: 115200
+//-----------------------------------------------------------------------------------------
+//-- (C) BQ. December 2015. Written by Juan Gonzalez (Obijuan)
+//-- GPL license
+//-----------------------------------------------------------------------------------------
+`default_nettype none
+`include ""baudgen.vh""
+
+//-- Top entity
+module txchar (
+ input wire clk, //-- System clock
+ input wire rstn, //-- Reset (active low)
+ output wire tx //-- Serial data output
+);
+
+//-- Serial Unit instantation
+uart_tx #(
+ .BAUDRATE(`B115200) //-- Set the baudrate
+
+ ) TX0 (
+ .clk(clk),
+ .rstn(rstn),
+ .data(""A""), //-- Fixed character to transmit (always the same)
+ .start(1\'b1), //-- Start signal always set to 1
+ .tx(tx)
+); //-- Port ready not used
+
+
+endmodule
+"
+"//-------------------------------------------------------------------
+//-- divM_tb.v
+//-- Banco de pruebas para el divisor entre M
+//-------------------------------------------------------------------
+//-- BQ August 2015. Written by Juan Gonzalez (Obijuan)
+//-------------------------------------------------------------------
+`default_nettype none
+`timescale 100 ns / 1 ps
+
+module test_tb();
+
+//-- Registro para generar la se\xc3\xb1al de reloj
+reg clk = 0;
+wire clk_out;
+wire led0;
+
+//-- Instanciar el componente y establecer el valor del divisor
+test #(5)
+ dut(
+ .clk(clk),
+ .clk_out(clk_out),
+ .led0(led0)
+ );
+
+//-- Generador de reloj. Periodo 2 unidades
+always #0.41667 clk = ~clk;
+
+
+//-- Proceso al inicio
+initial begin
+
+ //-- Fichero donde almacenar los resultados
+ $dumpfile(""test_tb.vcd"");
+ $dumpvars(0, test_tb);
+
+ # 400000 $display(""FIN de la simulacion"");
+ $finish;
+end
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//-- Baudrate generator
+//-- It generates a square signal, with a frequency for communicating at the given
+//-- given baudrate
+//-- The output is set to 1 only during one clock cycle. The rest of the time is 0
+//--------------------------------------------------------------------------------
+//-- (c) BQ. December 2015. written by Juan Gonzalez (obijuan)
+//-----------------------------------------------------------------------------
+//-- GPL license
+//-----------------------------------------------------------------------------
+`default_nettype none
+`include ""baudgen.vh""
+
+//----------------------------------------------------------------------------------------
+//-- baudgen module
+//--
+//-- INPUTS:
+//-- -clk: System clock (12 MHZ in the iceStick board)
+//-- -clk_ena: clock enable:
+//-- 1. Normal working: The squeare signal is generated
+//-- 0: stoped. Output always 0
+//-- OUTPUTS:
+//-- - clk_out: Output signal. Pulse width: 1 clock cycle. Output not registered
+//-- It tells the uart_tx when to transmit the next bit
+//-- __ __
+//-- __| |________________________________________________________| |________________
+//-- -> <- 1 clock cycle
+//--
+//---------------------------------------------------------------------------------------
+module baudgen_tx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire rstn, //-- Reset (active low)
+ input wire clk, //-- System clock
+ input wire clk_ena, //-- Clock enable
+ output wire clk_out //-- Bitrate Clock output
+);
+
+//-- Number of bits needed for storing the baudrate divisor
+localparam N = $clog2(BAUDRATE);
+
+//-- Counter for implementing the divisor (it is a BAUDRATE module counter)
+//-- (when BAUDRATE is reached, it start again from 0)
+reg [N-1:0] divcounter = 0;
+
+always @(posedge clk)
+
+ if (!rstn)
+ divcounter <= 0;
+
+ else if (clk_ena)
+ //-- Normal working: counting. When the maximum count is reached, it starts from 0
+ divcounter <= (divcounter == BAUDRATE - 1) ? 0 : divcounter + 1;
+ else
+ //-- Counter fixed to its maximum value
+ //-- When it is resumed it start from 0
+ divcounter <= BAUDRATE - 1;
+
+//-- The output is 1 when the counter is 0, if clk_ena is active
+//-- It is 1 only for one system clock cycle
+assign clk_out = (divcounter == 0) ? clk_ena : 0;
+
+
+endmodule
+"
+"//----------------------------------------------------------------------------
+//-- echo.v: Uart-rx example 2
+//-- All the received characters are echoed
+//----------------------------------------------------------------------------
+//-- (C) BQ. December 2015. Written by Juan Gonzalez (Obijuan)
+//-- GPL license
+//----------------------------------------------------------------------------
+`default_nettype none
+
+`include ""baudgen.vh""
+
+//-- Top design
+module echo #(
+ parameter BAUDRATE = `B115200
+)(
+ input wire clk, //-- System clock
+ input wire rx, //-- Serial input
+ output wire tx, //-- Serial output
+ output reg [3:0] leds //-- Red leds
+);
+
+//-- Received character signal
+wire rcv;
+
+//-- Received data
+wire [7:0] data;
+
+//-- Reset signal
+reg rstn = 0;
+
+//-- Transmitter ready signal
+wire ready;
+
+//-- Initialization
+always @(posedge clk)
+ rstn <= 1;
+
+//-- Turn on all the red leds
+//assign leds = 4\'hF;
+
+//-- Show the 4 less significant bits in the leds
+always @(posedge clk)
+ leds = data[3:0];
+
+//-- Receiver unit instantation
+uart_rx #(.BAUDRATE(BAUDRATE))
+ RX0 (.clk(clk),
+ .rstn(rstn),
+ .rx(rx),
+ .rcv(rcv),
+ .data(data)
+ );
+
+//-- Transmitter unit instantation
+uart_tx #(.BAUDRATE(BAUDRATE))
+ TX0 ( .clk(clk),
+ .rstn(rstn),
+ .start(rcv),
+ .data(data),
+ .tx(tx),
+ .ready(ready)
+ );
+
+
+endmodule
+"
+"`default_nettype none
+
+//-- Servo test
+module ServoUnit(input wire clk, //-- System clock
+ input wire [7:0] pos, //-- Servo pos 0 - 255
+ output reg servo); //-- Servo control signal
+
+localparam M = 93; //-- 94
+localparam N = $clog2(M);
+
+reg [N-1:0] divcounter = 0;
+reg tic = 0;
+
+//-- Ticks generation. A pulse is emmited every M system clock cycles
+always @(posedge clk)
+ tic <= (divcounter == M - 2);
+
+//-- Module M counter
+always @(posedge clk)
+ if (tic)
+ divcounter <= 0;
+ else
+ divcounter <= divcounter + 1;
+
+//-- Angle counter
+reg [10:0] angle_counter = 0;
+
+wire [8:0] pose = {1'b0, pos} + 9'd46;
+
+always @(posedge clk)
+ if (tic)
+ angle_counter <= angle_counter + 1;
+
+always @(posedge clk)
+ servo <= (angle_counter < {3'b00, pose});
+
+
+endmodule
+"
+"//-------------------------------------------------------------------
+//-- divM_tb.v
+//-- Banco de pruebas para el divisor entre M
+//-------------------------------------------------------------------
+//-- BQ August 2015. Written by Juan Gonzalez (Obijuan)
+//-------------------------------------------------------------------
+`default_nettype none
+`timescale 100 ns / 1 ps
+
+module osc_tb();
+
+//-- Registro para generar la se\xc3\xb1al de reloj
+reg clk = 0;
+wire s0;
+wire s1;
+wire led0;
+
+//-- Instanciar el componente y establecer el valor del divisor
+osc dut(
+ .clk(clk),
+ .s0(s0),
+ .s1(s1),
+ .led0(led0)
+ );
+
+//-- Generador de reloj. Periodo 2 unidades
+always #0.41667 clk = ~clk;
+
+
+//-- Proceso al inicio
+initial begin
+
+ //-- Fichero donde almacenar los resultados
+ $dumpfile(""osc_tb.vcd"");
+ $dumpvars(0, osc_tb);
+
+ # 400000 $display(""FIN de la simulacion"");
+ $finish;
+end
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//-- Divisor de reloj
+//-- Se\xc3\xb1al de periodo igual al indicado
+//-- El ancho del pulso positivo es de 1 ciclo de reloj
+//--
+//-- (c) BQ. September 2015. written by Juan Gonzalez (obijuan)
+//-----------------------------------------------------------------------------
+//-- GPL license
+//-----------------------------------------------------------------------------
+`include ""divider.vh""
+
+//-- ENTRADAS:
+//-- -clk: Senal de reloj del sistema (12 MHZ en la iceStick)
+//
+//-- SALIDAS:
+//-- - clk_out. Se\xc3\xb1al de salida para lograr la velocidad en baudios indicada
+//-- Anchura de 1 periodo de clk. SALIDA NO REGISTRADA
+module dividerp1(input wire clk,
+ input wire timer_ena,
+ output wire clk_out);
+
+//-- Valor por defecto de la velocidad en baudios
+parameter M = `T_100ms;
+
+//-- Numero de bits para almacenar el divisor de baudios
+localparam N = $clog2(M);
+
+//-- Registro para implementar el contador modulo M
+reg [N-1:0] divcounter = 0;
+
+//-- Contador m\xc3\xb3dulo M
+always @(posedge clk)
+ if (timer_ena)
+ divcounter <= (divcounter == M - 1) ? 0 : divcounter + 1;
+ else
+ divcounter <= 0;
+
+//-- Sacar un pulso de anchura 1 ciclo de reloj si el generador
+assign clk_out = (divcounter == M - 1) ? 1 : 0;
+
+
+endmodule
+"
+"//----------------------------------------------------------------------------
+//-- Asynchronous serial transmitter Unit
+//------------------------------------------
+//-- (C) BQ. December 2015. Written by Juan Gonzalez (Obijuan)
+//-- GPL license
+//----------------------------------------------------------------------------
+//-- Tested at all the standard baudrates:
+//-- 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200
+//----------------------------------------------------------------------------
+//-- Although this transmitter has been written from the scratch, it has been
+//-- inspired by the one developed in the swapforth proyect by James Bowman
+//--
+//-- https://github.com/jamesbowman/swapforth
+//--
+//----------------------------------------------------------------------------
+`default_nettype none
+
+`include ""baudgen.vh""
+
+//--- Serial transmitter unit module
+//--- TX output is not registered
+module uart_tx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire clk, //-- System clcok (12MHz in the ICEstick)
+ input wire rstn, //-- Reset (Active low)
+ input wire start, //-- Set to 1 for starting the transmission
+ input wire [7:0] data, //-- Byte to transmit
+ output reg tx, //-- Serial data output
+ output reg ready //-- Transmitter ready (1) / busy (0)
+);
+
+
+//-- Transmission clock
+wire clk_baud;
+
+//-- Bitcounter
+reg [3:0] bitc;
+
+//-- Registered data
+reg [7:0] data_r;
+
+//--------- control signals
+reg load; //-- Load the shifter register / reset
+reg baud_en; //-- Enable the baud generator
+
+//-------------------------------------
+//-- DATAPATH
+//-------------------------------------
+
+//-- Register the input data
+always @(posedge clk)
+ if (start == 1 && state == IDLE)
+ data_r <= data;
+
+//-- 1 bit start + 8 bits datos + 1 bit stop
+//-- Shifter register. It stored the frame to transmit:
+//-- 1 start bit + 8 data bits + 1 stop bit
+reg [9:0] shifter;
+
+//-- When the control signal load is 1, the frame is loaded
+//-- when load = 0, the frame is shifted right to send 1 bit,
+//-- at the baudrate determined by clk_baud
+//-- 1s are introduced by the left
+always @(posedge clk)
+ //-- Reset
+ if (rstn == 0)
+ shifter <= 10\'b11_1111_1111;
+
+ //-- Load mode
+ else if (load == 1)
+ shifter <= {data_r,2\'b01};
+
+ //-- Shift mode
+ else if (load == 0 && clk_baud == 1)
+ shifter <= {1\'b1, shifter[9:1]};
+
+//-- Sent bit counter
+//-- When load (=1) the counter is reset
+//-- When load = 0, the sent bits are counted (with the raising edge of clk_baud)
+always @(posedge clk)
+ if (!rstn)
+ bitc <= 0;
+
+ else if (load == 1)
+ bitc <= 0;
+ else if (load == 0 && clk_baud == 1)
+ bitc <= bitc + 1;
+
+//-- The less significant bit is transmited through tx
+//-- It is a registed output, because tx is connected to an Asynchronous bus
+//-- and the glitches should be avoided
+always @(posedge clk)
+ tx <= shifter[0];
+
+//-- Baud generator
+baudgen_tx #( .BAUDRATE(BAUDRATE))
+BAUD0 (
+ .rstn(rstn),
+ .clk(clk),
+ .clk_ena(baud_en),
+ .clk_out(clk_baud)
+ );
+
+//------------------------------
+//-- CONTROLLER
+//------------------------------
+
+//-- fsm states
+localparam IDLE = 0; //-- Idle state
+localparam START = 1; //-- Start transmission
+localparam TRANS = 2; //-- Transmitting data
+
+//-- Registers for storing the states
+reg [1:0] state;
+reg [1:0] next_state;
+
+//-- Transition between states
+always @(posedge clk)
+ if (!rstn)
+ state <= IDLE;
+ else
+ state <= next_state;
+
+//-- Control signal generation and next states
+always @(*) begin
+
+ //-- Default values
+ next_state = state; //-- Stay in the same state by default
+ load = 0;
+ baud_en = 0;
+
+ case (state)
+
+ //-- Idle state
+ //-- Remain in this state until start is 1
+ IDLE: begin
+ ready = 1;
+ if (start == 1)
+ next_state = START;
+ end
+
+ //-- 1 cycle long
+ //-- turn on the baudrate generator and the load the shift register
+ START: begin
+ load = 1;
+ baud_en = 1;
+ ready = 0;
+ next_state = TRANS;
+ end
+
+ //-- Stay here until all the bits have been sent
+ TRANS: begin
+ baud_en = 1;
+ ready = 0;
+ if (bitc == 11)
+ next_state = IDLE;
+ end
+
+ default:
+ ready = 0;
+
+ endcase
+end
+
+endmodule
+"
+"//----------------------------------------------------------------------------
+//-- Memoria ROM gen\xc3\xa9rica
+//------------------------------------------
+//-- (C) BQ. October 2015. Written by Juan Gonzalez (Obijuan)
+//-- GPL license
+//----------------------------------------------------------------------------
+//-- Memoria con los siguientes parametros:
+//-- * AW: Numero de bits de las direcciones
+//-- * DW: Numero de bits de los datos
+//-- * ROMFILE: Fichero a usar para cargar la memoria
+//--
+//-- Con este componente podemos hacer memorias rom de cualquier tama\xc3\xb1o
+//----------------------------------------------------------------------------
+
+module genrom #( //-- Parametros
+ parameter AW = 6, //-- Bits de las direcciones (Adress width)
+ parameter DW = 8) //-- Bits de los datos (Data witdh)
+
+ ( //-- Puertos
+ input clk, //-- Se\xc3\xb1al de reloj global
+ input wire [AW-1: 0] addr, //-- Direcciones
+ output reg [DW-1: 0] data); //-- Dato de salida
+
+//-- Parametro: Nombre del fichero con el contenido de la ROM
+parameter ROMFILE = ""rom1.list"";
+
+//-- Calcular el numero de posiciones totales de memoria
+localparam NPOS = 2 ** AW;
+
+ //-- Memoria
+ reg [DW-1: 0] rom [0: NPOS-1];
+
+ //-- Lectura de la memoria
+ always @(posedge clk) begin
+ data <= rom[addr];
+ end
+
+//-- Cargar en la memoria el fichero ROMFILE
+//-- Los valores deben estan dados en hexadecimal
+initial begin
+ $readmemh(ROMFILE, rom);
+end
+
+
+endmodule
+"
+"//----------------------------------------------------------------------------
+//-- Asynchronous serial transmitter Unit
+//------------------------------------------
+//-- (C) BQ. December 2015. Written by Juan Gonzalez (Obijuan)
+//-- GPL license
+//----------------------------------------------------------------------------
+//-- Tested at all the standard baudrates:
+//-- 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200
+//----------------------------------------------------------------------------
+//-- Although this transmitter has been written from the scratch, it has been
+//-- inspired by the one developed in the swapforth proyect by James Bowman
+//--
+//-- https://github.com/jamesbowman/swapforth
+//--
+//----------------------------------------------------------------------------
+`default_nettype none
+
+`include ""baudgen.vh""
+
+//--- Serial transmitter unit module
+//--- TX output is not registered
+module uart_tx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire clk, //-- System clcok (12MHz in the ICEstick)
+ input wire rstn, //-- Reset (Active low)
+ input wire start, //-- Set to 1 for starting the transmission
+ input wire [7:0] data, //-- Byte to transmit
+ output reg tx, //-- Serial data output
+ output reg ready //-- Transmitter ready (1) / busy (0)
+);
+
+
+//-- Transmission clock
+wire clk_baud;
+
+//-- Bitcounter
+reg [3:0] bitc;
+
+//-- Registered data
+reg [7:0] data_r;
+
+//--------- control signals
+reg load; //-- Load the shifter register / reset
+reg baud_en; //-- Enable the baud generator
+
+//-------------------------------------
+//-- DATAPATH
+//-------------------------------------
+
+//-- Register the input data
+always @(posedge clk)
+ if (start == 1 && state == IDLE)
+ data_r <= data;
+
+//-- 1 bit start + 8 bits datos + 1 bit stop
+//-- Shifter register. It stored the frame to transmit:
+//-- 1 start bit + 8 data bits + 1 stop bit
+reg [9:0] shifter;
+
+//-- When the control signal load is 1, the frame is loaded
+//-- when load = 0, the frame is shifted right to send 1 bit,
+//-- at the baudrate determined by clk_baud
+//-- 1s are introduced by the left
+always @(posedge clk)
+ //-- Reset
+ if (rstn == 0)
+ shifter <= 10\'b11_1111_1111;
+
+ //-- Load mode
+ else if (load == 1)
+ shifter <= {data_r,2\'b01};
+
+ //-- Shift mode
+ else if (load == 0 && clk_baud == 1)
+ shifter <= {1\'b1, shifter[9:1]};
+
+//-- Sent bit counter
+//-- When load (=1) the counter is reset
+//-- When load = 0, the sent bits are counted (with the raising edge of clk_baud)
+always @(posedge clk)
+ if (!rstn)
+ bitc <= 0;
+
+ else if (load == 1)
+ bitc <= 0;
+ else if (load == 0 && clk_baud == 1)
+ bitc <= bitc + 1;
+
+//-- The less significant bit is transmited through tx
+//-- It is a registed output, because tx is connected to an Asynchronous bus
+//-- and the glitches should be avoided
+always @(posedge clk)
+ tx <= shifter[0];
+
+//-- Baud generator
+baudgen_tx #( .BAUDRATE(BAUDRATE))
+BAUD0 (
+ .rstn(rstn),
+ .clk(clk),
+ .clk_ena(baud_en),
+ .clk_out(clk_baud)
+ );
+
+//------------------------------
+//-- CONTROLLER
+//------------------------------
+
+//-- fsm states
+localparam IDLE = 0; //-- Idle state
+localparam START = 1; //-- Start transmission
+localparam TRANS = 2; //-- Transmitting data
+
+//-- Registers for storing the states
+reg [1:0] state;
+reg [1:0] next_state;
+
+//-- Transition between states
+always @(posedge clk)
+ if (!rstn)
+ state <= IDLE;
+ else
+ state <= next_state;
+
+//-- Control signal generation and next states
+always @(*) begin
+
+ //-- Default values
+ next_state = state; //-- Stay in the same state by default
+ load = 0;
+ baud_en = 0;
+
+ case (state)
+
+ //-- Idle state
+ //-- Remain in this state until start is 1
+ IDLE: begin
+ ready = 1;
+ if (start == 1)
+ next_state = START;
+ end
+
+ //-- 1 cycle long
+ //-- turn on the baudrate generator and the load the shift register
+ START: begin
+ load = 1;
+ baud_en = 1;
+ ready = 0;
+ next_state = TRANS;
+ end
+
+ //-- Stay here until all the bits have been sent
+ TRANS: begin
+ baud_en = 1;
+ ready = 0;
+ if (bitc == 11)
+ next_state = IDLE;
+ end
+
+ default:
+ ready = 0;
+
+ endcase
+end
+
+endmodule
+"
+"//-------------------------------------------------------------------
+//-- divM_tb.v
+//-- Banco de pruebas para el divisor entre M
+//-------------------------------------------------------------------
+//-- BQ August 2015. Written by Juan Gonzalez (Obijuan)
+//-------------------------------------------------------------------
+`default_nettype none
+`timescale 100 ns / 1 ps
+
+module osc_tb();
+
+//-- Registro para generar la se\xc3\xb1al de reloj
+reg clk = 0;
+wire clk_out;
+wire led0;
+
+//-- Instanciar el componente y establecer el valor del divisor
+osc dut(
+ .clk(clk),
+ .clk_out(clk_out),
+ .led0(led0)
+ );
+
+//-- Generador de reloj. Periodo 2 unidades
+always #0.41667 clk = ~clk;
+
+
+//-- Proceso al inicio
+initial begin
+
+ //-- Fichero donde almacenar los resultados
+ $dumpfile(""osc_tb.vcd"");
+ $dumpvars(0, osc_tb);
+
+ # 400000 $display(""FIN de la simulacion"");
+ $finish;
+end
+
+endmodule
+"
+"`include ""divider.vh""
+
+`default_nettype none
+
+//-- Servo test
+module osc(input wire clk,
+ output wire clk_out,
+ output wire led0);
+
+parameter WAIT_DELAY = `T_50ms + `T_10ms;
+
+//-- Fichero con la rom
+parameter ROMFILE = ""rom1.list"";
+
+//-- Numero de bits de la direccione
+parameter AW = 5;
+parameter DW = 8;
+
+//-- Just for debugging
+assign led0 = 1;
+
+wire [7:0] pos;
+
+//-- Intantiate the servo unit
+ServoUnit
+ SERVO0 (.clk(clk),
+ .pos({1\'b0,pos[7:1]} + 8\'d64),
+ .servo(clk_out));
+
+wire tic;
+
+dividerp1 #(WAIT_DELAY)
+ TIMMER0 (.clk(clk),
+ .timer_ena(1\'b1),
+ .clk_out(tic));
+
+reg [AW-1: 0] addr = 0; //-- Bus de direcciones
+reg [DW-1: 0] data; //-- Bus de datos
+
+always @(posedge clk)
+ if (tic)
+ addr <= addr + 1;
+
+genrom
+ #( .ROMFILE(ROMFILE), //-- Asignacion de parametros
+ .AW(AW),
+ .DW(DW))
+ ROM ( //-- coneion de cables
+ .clk(clk),
+ .addr(addr),
+ .data(pos)
+ );
+
+
+endmodule
+"
+"//----------------------------------------------------------------------------
+//-- Asynchronous serial receiver Unit
+//------------------------------------------
+//-- (C) BQ. December 2015. Written by Juan Gonzalez (Obijuan)
+//-- GPL license
+//----------------------------------------------------------------------------
+//-- Tested at the standard baudrates:
+//-- 300, 600, 1200, 4800, 9600, 19200, 38400, 115200
+//----------------------------------------------------------------------------
+//-- Although this transmitter has been written from the scratch, it has been
+//-- inspired by the one developed in the swapforth proyect by James Bowman
+//--
+//-- https://github.com/jamesbowman/swapforth
+//--
+//----------------------------------------------------------------------------
+`default_nettype none
+
+`include ""baudgen.vh""
+
+//-- Serial receiver unit module
+module uart_rx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire clk, //-- System clock (12MHz in the ICEstick)
+ input wire rstn, //-- Reset (Active low)
+ input wire rx, //-- Serial data input
+ output reg rcv, //-- Data is available (1)
+ output reg [7:0] data //-- Data received
+);
+
+//-- Transmission clock
+wire clk_baud;
+
+//-- Control signals
+reg bauden; //-- Enable the baud generator
+reg clear; //-- Clear the bit counter
+reg load; //-- Load the received character into the data register
+
+
+//-------------------------------------------------------------------
+//-- DATAPATH
+//-------------------------------------------------------------------
+
+//-- The serial input is registered in order to follow the
+//-- synchronous design rules
+reg rx_r;
+
+always @(posedge clk)
+ rx_r <= rx;
+
+//-- Baud generator
+baudgen_rx #(BAUDRATE)
+ baudgen0 (
+ .rstn(rstn),
+ .clk(clk),
+ .clk_ena(bauden),
+ .clk_out(clk_baud)
+ );
+
+//-- Bit counter
+reg [3:0] bitc;
+
+always @(posedge clk)
+ if (clear)
+ bitc <= 4\'d0;
+ else if (clear == 0 && clk_baud == 1)
+ bitc <= bitc + 1;
+
+
+//-- Shift register for storing the received bits
+reg [9:0] raw_data;
+
+always @(posedge clk)
+ if (clk_baud == 1)
+ raw_data <= {rx_r, raw_data[9:1]};
+
+//-- Data register. Store the character received
+always @(posedge clk)
+ if (rstn == 0)
+ data <= 0;
+ else if (load)
+ data <= raw_data[8:1];
+
+//-------------------------------------------
+//-- CONTROLLER (Finite state machine)
+//-------------------------------------------
+
+//-- Receiver states
+localparam IDLE = 2\'d0; //-- IDLEde reposo
+localparam RECV = 2\'d1; //-- Receiving data
+localparam LOAD = 2\'d2; //-- Storing the character received
+localparam DAV = 2\'d3; //-- Data is available
+
+//-- fsm states
+reg [1:0] state;
+reg [1:0] next_state;
+
+//-- Transition between states
+always @(posedge clk)
+ if (!rstn)
+ state <= IDLE;
+ else
+ state <= next_state;
+
+//-- Control signal generation and next states
+always @(*) begin
+
+ //-- Default values
+ next_state = state; //-- Stay in the same state by default
+ bauden = 0;
+ clear = 0;
+ load = 0;
+
+ case(state)
+
+ //-- Idle state
+ //-- Remain in this state until a start bit is received in rx_r
+ IDLE: begin
+ clear = 1;
+ rcv = 0;
+ if (rx_r == 0)
+ next_state = RECV;
+ end
+
+ //-- Receiving state
+ //-- Turn on the baud generator and wait for the serial package to be received
+ RECV: begin
+ bauden = 1;
+ rcv = 0;
+ if (bitc == 4\'d10)
+ next_state = LOAD;
+ end
+
+ //-- Store the received character in the data register (1 cycle)
+ LOAD: begin
+ load = 1;
+ rcv = 0;
+ next_state = DAV;
+ end
+
+ //-- Data Available (1 cycle)
+ DAV: begin
+ rcv = 1;
+ next_state = IDLE;
+ end
+
+ default:
+ rcv = 0;
+
+ endcase
+
+end
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//-- Divisor de reloj
+//-- Se\xc3\xb1al de periodo igual al indicado
+//-- El ancho del pulso positivo es de 1 ciclo de reloj
+//--
+//-- (c) BQ. September 2015. written by Juan Gonzalez (obijuan)
+//-----------------------------------------------------------------------------
+//-- GPL license
+//-----------------------------------------------------------------------------
+`include ""divider.vh""
+
+//-- ENTRADAS:
+//-- -clk: Senal de reloj del sistema (12 MHZ en la iceStick)
+//
+//-- SALIDAS:
+//-- - clk_out. Se\xc3\xb1al de salida para lograr la velocidad en baudios indicada
+//-- Anchura de 1 periodo de clk. SALIDA NO REGISTRADA
+module dividerp1(input wire clk,
+ input wire timer_ena,
+ output wire clk_out);
+
+//-- Valor por defecto de la velocidad en baudios
+parameter M = `T_100ms;
+
+//-- Numero de bits para almacenar el divisor de baudios
+localparam N = $clog2(M);
+
+//-- Registro para implementar el contador modulo M
+reg [N-1:0] divcounter = 0;
+
+//-- Contador m\xc3\xb3dulo M
+always @(posedge clk)
+ if (timer_ena)
+ divcounter <= (divcounter == M - 1) ? 0 : divcounter + 1;
+ else
+ divcounter <= 0;
+
+//-- Sacar un pulso de anchura 1 ciclo de reloj si el generador
+assign clk_out = (divcounter == M - 1) ? 1 : 0;
+
+
+endmodule
+"
+"//-----------------------------------------------------------------------------------------
+//-- txstr: Uart_tx example 2
+//-- Transmission of string
+//-- The reset signal is connected to the dtr signal (in file txstr.pcf)
+//-- Fot this example to work is necessary to open a serial terminal (gtkterm for example)
+//-- and deactivate DTR. Every time a reset is done, a string appears on the terminal
+//-- Fixed BAUDRATE: 115200
+//-----------------------------------------------------------------------------------------
+//-- (C) BQ. December 2015. Written by Juan Gonzalez (Obijuan)
+//-- GPL license
+//-----------------------------------------------------------------------------------------
+`default_nettype none
+`include ""baudgen.vh""
+
+//-- Top entity
+module txstr #(
+ parameter BAUDRATE = `B115200
+)(
+ input wire clk, //-- System clock
+ input wire rstn, //-- Reset (active low)
+ output wire tx //-- Serial data output
+);
+
+
+//-- Serial Unit instantation
+uart_tx #(
+ .BAUDRATE(BAUDRATE) //-- Set the baudrate
+
+ ) TX0 (
+ .clk(clk),
+ .rstn(rstn),
+ .data(data),
+ .start(start),
+ .tx(tx),
+ .ready(ready)
+);
+
+//-- Connecting wires
+wire ready;
+reg start = 0;
+reg [7:0] data;
+
+//-- Multiplexer with the 8-character string to transmit
+always @*
+ case (char_count)
+ 8\'d0: data <= ""H"";
+ 8\'d1: data <= ""e"";
+ 8\'d2: data <= ""l"";
+ 8\'d3: data <= ""l"";
+ 8\'d4: data <= ""o"";
+ 8\'d5: data <= ""!"";
+ 8\'d6: data <= ""."";
+ 8\'d7: data <= ""."";
+ default: data <= ""."";
+ endcase
+
+//-- Characters counter
+//-- It only counts when the cena control signal is enabled
+reg [2:0] char_count;
+reg cena; //-- Counter enable
+
+always @(posedge clk)
+ if (!rstn)
+ char_count = 0;
+ else if (cena)
+ char_count = char_count + 1;
+
+
+//--------------------- CONTROLLER
+
+localparam INI = 0;
+localparam TXCAR = 1;
+localparam NEXTCAR = 2;
+localparam STOP = 3;
+
+//-- fsm state
+reg [1:0] state;
+reg [1:0] next_state;
+
+//-- Transition between states
+always @(posedge clk) begin
+ if (!rstn)
+ state <= INI;
+ else
+ state <= next_state;
+end
+
+//-- Control signal generation and next states
+always @(*) begin
+ next_state = state;
+ start = 0;
+ cena = 0;
+
+ case (state)
+ //-- Initial state. Start the trasmission
+ INI: begin
+ start = 1;
+ next_state = TXCAR;
+ end
+
+ //-- Wait until one car is transmitted
+ TXCAR: begin
+ if (ready)
+ next_state = NEXTCAR;
+ end
+
+ //-- Increment the character counter
+ //-- Finish when it is the last character
+ NEXTCAR: begin
+ cena = 1;
+ if (char_count == 7)
+ next_state = STOP;
+ else
+ next_state = INI;
+ end
+
+ endcase
+end
+
+
+endmodule
+"
+"//-------------------------------------------------------------------
+//-- echo_tb.v
+//-- Testbench for the simulation of the echo.v
+//-------------------------------------------------------------------
+//-- (c) BQ December 2015. Written by Juan Gonzalez (Obijuan)
+//-------------------------------------------------------------------
+//-- GPL License
+//-------------------------------------------------------------------
+`timescale 100 ns / 10 ns
+
+`include ""baudgen.vh""
+
+
+module echo_tb();
+
+//-- Baudrate for the simulation
+localparam BAUDRATE = `B115200;
+
+//-- clock tics needed for sending one serial package
+localparam SERIAL_PACK = (BAUDRATE * 10);
+
+//-- Time between two characters
+localparam WAIT = (BAUDRATE * 4);
+
+//----------------------------------------
+//-- Task for sending a character in serial
+//----------------------------------------
+ task send_char;
+ input [7:0] char;
+ begin
+ rx <= 0; //-- Send the Start bit
+ #BAUDRATE rx <= char[0]; //-- Bit 0
+ #BAUDRATE rx <= char[1]; //-- Bit 1
+ #BAUDRATE rx <= char[2]; //-- Bit 2
+ #BAUDRATE rx <= char[3]; //-- Bit 3
+ #BAUDRATE rx <= char[4]; //-- Bit 4
+ #BAUDRATE rx <= char[5]; //-- Bit 5
+ #BAUDRATE rx <= char[6]; //-- Bit 6
+ #BAUDRATE rx <= char[7]; //-- Bit 7
+ #BAUDRATE rx <= 1; //-- stop bit
+ #BAUDRATE rx <= 1; //-- Wait until the bits stop is sent
+ end
+ endtask
+
+//-- System clock
+reg clk = 0;
+
+//-- Wire connected to the rx port for transmiting to the receiver
+reg rx = 1;
+
+//-- Wire connected to tx for receiving the echo
+wire tx;
+
+//-- For connecting the leds
+wire [3:0] leds;
+
+//-- Instantiate the entity to test
+echo #(.BAUDRATE(BAUDRATE))
+ dut(
+ .clk(clk),
+ .rx(rx),
+ .tx(tx)
+ );
+
+//-- Clock generator
+always
+ # 0.5 clk <= ~clk;
+
+initial begin
+
+ //-- File where to store the simulation
+ $dumpfile(""echo_tb.vcd"");
+ $dumpvars(0, echo_tb);
+
+ //-- Sent some data
+ #BAUDRATE send_char(8\'h55);
+ #WAIT send_char(""K"");
+
+ #(WAIT * 4) $display(""END of the simulation"");
+ $finish;
+end
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//-- Baudrate generator
+//-- It generates a square signal, with a frequency for communicating at the given
+//-- given baudrate
+//-- The output is set to 1 only during one clock cycle. The rest of the time is 0
+//-- Once enabled, the pulse is generated just in the middle of the period
+//-- This is necessary for the implementation of the receptor
+//--------------------------------------------------------------------------------
+//-- (c) BQ. December 2015. written by Juan Gonzalez (obijuan)
+//-----------------------------------------------------------------------------
+//-- GPL license
+//-----------------------------------------------------------------------------
+`include ""baudgen.vh""
+
+//----------------------------------------------------------------------------------------
+//-- baudgen module
+//--
+//-- INPUTS:
+//-- -clk: System clock (12 MHZ in the iceStick board)
+//-- -clk_ena: clock enable:
+//-- 1. Normal working: The squeare signal is generated
+//-- 0: stoped. Output always 0
+//-- OUTPUTS:
+//-- - clk_out: Output signal. Pulse width: 1 clock cycle. Output not registered
+//-- It tells the uart_rx when to sample the next bit
+//-- __ __
+//-- ____________________| |________________________________________| |_____________________
+//-- | -> <- 1 clock cycle |
+//-- <------- Period ------------------------->
+//--
+//---------------------------------------------------------------------------------------
+module baudgen_rx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire rstn, //-- Reset (active low)
+ input wire clk, //-- System clock
+ input wire clk_ena, //-- Clock enable
+ output wire clk_out //-- Bitrate Clock output
+);
+
+//-- Number of bits needed for storing the baudrate divisor
+localparam N = $clog2(BAUDRATE);
+
+//-- Value for generating the pulse in the middle of the period
+localparam M2 = (BAUDRATE >> 1);
+
+//-- Counter for implementing the divisor (it is a BAUDRATE module counter)
+//-- (when BAUDRATE is reached, it start again from 0)
+reg [N-1:0] divcounter = 0;
+
+//-- Contador m\xc3\xb3dulo M
+always @(posedge clk)
+
+ if (!rstn)
+ divcounter <= 0;
+
+ else if (clk_ena)
+ //-- Normal working: counting. When the maximum count is reached, it starts from 0
+ divcounter <= (divcounter == BAUDRATE - 1) ? 0 : divcounter + 1;
+ else
+ //-- Counter fixed to its maximum value
+ //-- When it is resumed it start from 0
+ divcounter <= BAUDRATE - 1;
+
+//-- The output is 1 when the counter is in the middle of the period, if clk_ena is active
+//-- It is 1 only for one system clock cycle
+assign clk_out = (divcounter == M2) ? clk_ena : 0;
+
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//-- Baudrate generator
+//-- It generates a square signal, with a frequency for communicating at the given
+//-- given baudrate
+//-- The output is set to 1 only during one clock cycle. The rest of the time is 0
+//--------------------------------------------------------------------------------
+//-- (c) BQ. December 2015. written by Juan Gonzalez (obijuan)
+//-----------------------------------------------------------------------------
+//-- GPL license
+//-----------------------------------------------------------------------------
+`default_nettype none
+`include ""baudgen.vh""
+
+//----------------------------------------------------------------------------------------
+//-- baudgen module
+//--
+//-- INPUTS:
+//-- -clk: System clock (12 MHZ in the iceStick board)
+//-- -clk_ena: clock enable:
+//-- 1. Normal working: The squeare signal is generated
+//-- 0: stoped. Output always 0
+//-- OUTPUTS:
+//-- - clk_out: Output signal. Pulse width: 1 clock cycle. Output not registered
+//-- It tells the uart_tx when to transmit the next bit
+//-- __ __
+//-- __| |________________________________________________________| |________________
+//-- -> <- 1 clock cycle
+//--
+//---------------------------------------------------------------------------------------
+module baudgen_tx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire rstn, //-- Reset (active low)
+ input wire clk, //-- System clock
+ input wire clk_ena, //-- Clock enable
+ output wire clk_out //-- Bitrate Clock output
+);
+
+//-- Number of bits needed for storing the baudrate divisor
+localparam N = $clog2(BAUDRATE);
+
+//-- Counter for implementing the divisor (it is a BAUDRATE module counter)
+//-- (when BAUDRATE is reached, it start again from 0)
+reg [N-1:0] divcounter = 0;
+
+always @(posedge clk)
+
+ if (!rstn)
+ divcounter <= 0;
+
+ else if (clk_ena)
+ //-- Normal working: counting. When the maximum count is reached, it starts from 0
+ divcounter <= (divcounter == BAUDRATE - 1) ? 0 : divcounter + 1;
+ else
+ //-- Counter fixed to its maximum value
+ //-- When it is resumed it start from 0
+ divcounter <= BAUDRATE - 1;
+
+//-- The output is 1 when the counter is 0, if clk_ena is active
+//-- It is 1 only for one system clock cycle
+assign clk_out = (divcounter == 0) ? clk_ena : 0;
+
+
+endmodule
+"
+"//----------------------------------------------------------------------------
+//-- Asynchronous serial receiver Unit
+//------------------------------------------
+//-- (C) BQ. December 2015. Written by Juan Gonzalez (Obijuan)
+//-- GPL license
+//----------------------------------------------------------------------------
+//-- Tested at the standard baudrates:
+//-- 300, 600, 1200, 4800, 9600, 19200, 38400, 115200
+//----------------------------------------------------------------------------
+//-- Although this transmitter has been written from the scratch, it has been
+//-- inspired by the one developed in the swapforth proyect by James Bowman
+//--
+//-- https://github.com/jamesbowman/swapforth
+//--
+//----------------------------------------------------------------------------
+`default_nettype none
+
+`include ""baudgen.vh""
+
+//-- Serial receiver unit module
+module uart_rx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire clk, //-- System clock (12MHz in the ICEstick)
+ input wire rstn, //-- Reset (Active low)
+ input wire rx, //-- Serial data input
+ output reg rcv, //-- Data is available (1)
+ output reg [7:0] data //-- Data received
+);
+
+//-- Transmission clock
+wire clk_baud;
+
+//-- Control signals
+reg bauden; //-- Enable the baud generator
+reg clear; //-- Clear the bit counter
+reg load; //-- Load the received character into the data register
+
+
+//-------------------------------------------------------------------
+//-- DATAPATH
+//-------------------------------------------------------------------
+
+//-- The serial input is registered in order to follow the
+//-- synchronous design rules
+reg rx_r;
+
+always @(posedge clk)
+ rx_r <= rx;
+
+//-- Baud generator
+baudgen_rx #(BAUDRATE)
+ baudgen0 (
+ .rstn(rstn),
+ .clk(clk),
+ .clk_ena(bauden),
+ .clk_out(clk_baud)
+ );
+
+//-- Bit counter
+reg [3:0] bitc;
+
+always @(posedge clk)
+ if (clear)
+ bitc <= 4\'d0;
+ else if (clear == 0 && clk_baud == 1)
+ bitc <= bitc + 1;
+
+
+//-- Shift register for storing the received bits
+reg [9:0] raw_data;
+
+always @(posedge clk)
+ if (clk_baud == 1)
+ raw_data <= {rx_r, raw_data[9:1]};
+
+//-- Data register. Store the character received
+always @(posedge clk)
+ if (rstn == 0)
+ data <= 0;
+ else if (load)
+ data <= raw_data[8:1];
+
+//-------------------------------------------
+//-- CONTROLLER (Finite state machine)
+//-------------------------------------------
+
+//-- Receiver states
+localparam IDLE = 2\'d0; //-- IDLEde reposo
+localparam RECV = 2\'d1; //-- Receiving data
+localparam LOAD = 2\'d2; //-- Storing the character received
+localparam DAV = 2\'d3; //-- Data is available
+
+//-- fsm states
+reg [1:0] state;
+reg [1:0] next_state;
+
+//-- Transition between states
+always @(posedge clk)
+ if (!rstn)
+ state <= IDLE;
+ else
+ state <= next_state;
+
+//-- Control signal generation and next states
+always @(*) begin
+
+ //-- Default values
+ next_state = state; //-- Stay in the same state by default
+ bauden = 0;
+ clear = 0;
+ load = 0;
+
+ case(state)
+
+ //-- Idle state
+ //-- Remain in this state until a start bit is received in rx_r
+ IDLE: begin
+ clear = 1;
+ rcv = 0;
+ if (rx_r == 0)
+ next_state = RECV;
+ end
+
+ //-- Receiving state
+ //-- Turn on the baud generator and wait for the serial package to be received
+ RECV: begin
+ bauden = 1;
+ rcv = 0;
+ if (bitc == 4\'d10)
+ next_state = LOAD;
+ end
+
+ //-- Store the received character in the data register (1 cycle)
+ LOAD: begin
+ load = 1;
+ rcv = 0;
+ next_state = DAV;
+ end
+
+ //-- Data Available (1 cycle)
+ DAV: begin
+ rcv = 1;
+ next_state = IDLE;
+ end
+
+ default:
+ rcv = 0;
+
+ endcase
+
+end
+
+endmodule
+"
+"//----------------------------------------------------------------------------
+//-- Asynchronous serial transmitter Unit
+//------------------------------------------
+//-- (C) BQ. December 2015. Written by Juan Gonzalez (Obijuan)
+//-- GPL license
+//----------------------------------------------------------------------------
+//-- Tested at all the standard baudrates:
+//-- 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200
+//----------------------------------------------------------------------------
+//-- Although this transmitter has been written from the scratch, it has been
+//-- inspired by the one developed in the swapforth proyect by James Bowman
+//--
+//-- https://github.com/jamesbowman/swapforth
+//--
+//----------------------------------------------------------------------------
+`default_nettype none
+
+`include ""baudgen.vh""
+
+//--- Serial transmitter unit module
+//--- TX output is not registered
+module uart_tx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire clk, //-- System clcok (12MHz in the ICEstick)
+ input wire rstn, //-- Reset (Active low)
+ input wire start, //-- Set to 1 for starting the transmission
+ input wire [7:0] data, //-- Byte to transmit
+ output reg tx, //-- Serial data output
+ output reg ready //-- Transmitter ready (1) / busy (0)
+);
+
+
+//-- Transmission clock
+wire clk_baud;
+
+//-- Bitcounter
+reg [3:0] bitc;
+
+//-- Registered data
+reg [7:0] data_r;
+
+//--------- control signals
+reg load; //-- Load the shifter register / reset
+reg baud_en; //-- Enable the baud generator
+
+//-------------------------------------
+//-- DATAPATH
+//-------------------------------------
+
+//-- Register the input data
+always @(posedge clk)
+ if (start == 1 && state == IDLE)
+ data_r <= data;
+
+//-- 1 bit start + 8 bits datos + 1 bit stop
+//-- Shifter register. It stored the frame to transmit:
+//-- 1 start bit + 8 data bits + 1 stop bit
+reg [9:0] shifter;
+
+//-- When the control signal load is 1, the frame is loaded
+//-- when load = 0, the frame is shifted right to send 1 bit,
+//-- at the baudrate determined by clk_baud
+//-- 1s are introduced by the left
+always @(posedge clk)
+ //-- Reset
+ if (rstn == 0)
+ shifter <= 10\'b11_1111_1111;
+
+ //-- Load mode
+ else if (load == 1)
+ shifter <= {data_r,2\'b01};
+
+ //-- Shift mode
+ else if (load == 0 && clk_baud == 1)
+ shifter <= {1\'b1, shifter[9:1]};
+
+//-- Sent bit counter
+//-- When load (=1) the counter is reset
+//-- When load = 0, the sent bits are counted (with the raising edge of clk_baud)
+always @(posedge clk)
+ if (!rstn)
+ bitc <= 0;
+
+ else if (load == 1)
+ bitc <= 0;
+ else if (load == 0 && clk_baud == 1)
+ bitc <= bitc + 1;
+
+//-- The less significant bit is transmited through tx
+//-- It is a registed output, because tx is connected to an Asynchronous bus
+//-- and the glitches should be avoided
+always @(posedge clk)
+ tx <= shifter[0];
+
+//-- Baud generator
+baudgen_tx #( .BAUDRATE(BAUDRATE))
+BAUD0 (
+ .rstn(rstn),
+ .clk(clk),
+ .clk_ena(baud_en),
+ .clk_out(clk_baud)
+ );
+
+//------------------------------
+//-- CONTROLLER
+//------------------------------
+
+//-- fsm states
+localparam IDLE = 0; //-- Idle state
+localparam START = 1; //-- Start transmission
+localparam TRANS = 2; //-- Transmitting data
+
+//-- Registers for storing the states
+reg [1:0] state;
+reg [1:0] next_state;
+
+//-- Transition between states
+always @(posedge clk)
+ if (!rstn)
+ state <= IDLE;
+ else
+ state <= next_state;
+
+//-- Control signal generation and next states
+always @(*) begin
+
+ //-- Default values
+ next_state = state; //-- Stay in the same state by default
+ load = 0;
+ baud_en = 0;
+
+ case (state)
+
+ //-- Idle state
+ //-- Remain in this state until start is 1
+ IDLE: begin
+ ready = 1;
+ if (start == 1)
+ next_state = START;
+ end
+
+ //-- 1 cycle long
+ //-- turn on the baudrate generator and the load the shift register
+ START: begin
+ load = 1;
+ baud_en = 1;
+ ready = 0;
+ next_state = TRANS;
+ end
+
+ //-- Stay here until all the bits have been sent
+ TRANS: begin
+ baud_en = 1;
+ ready = 0;
+ if (bitc == 11)
+ next_state = IDLE;
+ end
+
+ default:
+ ready = 0;
+
+ endcase
+end
+
+endmodule
+"
+"//-------------------------------------------------------------------
+//-- rxleds_tb.v
+//-- Testbench for the simulation of the rxleds.v
+//-------------------------------------------------------------------
+//-- (c) BQ December 2015. Written by Juan Gonzalez (Obijuan)
+//-------------------------------------------------------------------
+//-- GPL License
+//-------------------------------------------------------------------
+`timescale 100 ns / 10 ns
+
+`include ""baudgen.vh""
+
+
+module rxleds_tb();
+
+//-- Baudrate for the simulation
+localparam BAUDRATE = `B115200;
+
+//-- clock tics needed for sending one serial package
+localparam SERIAL_PACK = (BAUDRATE * 10);
+
+//-- Time between two characters
+localparam WAIT = (BAUDRATE * 4);
+
+//----------------------------------------
+//-- Task for sending a character in serial
+//----------------------------------------
+ task send_char;
+ input [7:0] char;
+ begin
+ rx <= 0; //-- Send the Start bit
+ #BAUDRATE rx <= char[0]; //-- Bit 0
+ #BAUDRATE rx <= char[1]; //-- Bit 1
+ #BAUDRATE rx <= char[2]; //-- Bit 2
+ #BAUDRATE rx <= char[3]; //-- Bit 3
+ #BAUDRATE rx <= char[4]; //-- Bit 4
+ #BAUDRATE rx <= char[5]; //-- Bit 5
+ #BAUDRATE rx <= char[6]; //-- Bit 6
+ #BAUDRATE rx <= char[7]; //-- Bit 7
+ #BAUDRATE rx <= 1; //-- stop bit
+ #BAUDRATE rx <= 1; //-- Wait until the bits stop is sent
+ end
+ endtask
+
+//-- System clock
+reg clk = 0;
+
+//-- Wire connected to the rx port for transmiting to the receiver
+reg rx = 1;
+
+//-- For connecting the leds
+wire [3:0] leds;
+
+//-- Instantiate the entity to test
+rxleds #(.BAUDRATE(BAUDRATE))
+ dut(
+ .clk(clk),
+ .rx(rx),
+ .leds(leds)
+ );
+
+//-- Clock generator
+always
+ # 0.5 clk <= ~clk;
+
+initial begin
+
+ //-- File where to store the simulation
+ $dumpfile(""rxleds_tb.vcd"");
+ $dumpvars(0, rxleds_tb);
+
+ //-- Sent some data
+ #BAUDRATE send_char(8\'h55);
+ #WAIT send_char(""K"");
+
+ #(WAIT * 4) $display(""END of the simulation"");
+ $finish;
+end
+
+endmodule
+"
+"`default_nettype none
+
+//-- Servo test
+module ServoUnit(input wire clk, //-- System clock
+ input wire [7:0] pos, //-- Servo pos 0 - 255
+ output reg servo); //-- Servo control signal
+
+localparam M = 93; //-- 94
+localparam N = $clog2(M);
+
+reg [N-1:0] divcounter = 0;
+reg tic = 0;
+
+//-- Ticks generation. A pulse is emmited every M system clock cycles
+always @(posedge clk)
+ tic <= (divcounter == M - 2);
+
+//-- Module M counter
+always @(posedge clk)
+ if (tic)
+ divcounter <= 0;
+ else
+ divcounter <= divcounter + 1;
+
+//-- Angle counter
+reg [10:0] angle_counter = 0;
+
+wire [8:0] pose = {1'b0, pos} + 9'd46;
+
+always @(posedge clk)
+ if (tic)
+ angle_counter <= angle_counter + 1;
+
+always @(posedge clk)
+ servo <= (angle_counter < {3'b00, pose});
+
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//-- Baudrate generator
+//-- It generates a square signal, with a frequency for communicating at the given
+//-- given baudrate
+//-- The output is set to 1 only during one clock cycle. The rest of the time is 0
+//-- Once enabled, the pulse is generated just in the middle of the period
+//-- This is necessary for the implementation of the receptor
+//--------------------------------------------------------------------------------
+//-- (c) BQ. December 2015. written by Juan Gonzalez (obijuan)
+//-----------------------------------------------------------------------------
+//-- GPL license
+//-----------------------------------------------------------------------------
+`include ""baudgen.vh""
+
+//----------------------------------------------------------------------------------------
+//-- baudgen module
+//--
+//-- INPUTS:
+//-- -clk: System clock (12 MHZ in the iceStick board)
+//-- -clk_ena: clock enable:
+//-- 1. Normal working: The squeare signal is generated
+//-- 0: stoped. Output always 0
+//-- OUTPUTS:
+//-- - clk_out: Output signal. Pulse width: 1 clock cycle. Output not registered
+//-- It tells the uart_rx when to sample the next bit
+//-- __ __
+//-- ____________________| |________________________________________| |_____________________
+//-- | -> <- 1 clock cycle |
+//-- <------- Period ------------------------->
+//--
+//---------------------------------------------------------------------------------------
+module baudgen_rx #(
+ parameter BAUDRATE = `B115200 //-- Default baudrate
+)(
+ input wire rstn, //-- Reset (active low)
+ input wire clk, //-- System clock
+ input wire clk_ena, //-- Clock enable
+ output wire clk_out //-- Bitrate Clock output
+);
+
+//-- Number of bits needed for storing the baudrate divisor
+localparam N = $clog2(BAUDRATE);
+
+//-- Value for generating the pulse in the middle of the period
+localparam M2 = (BAUDRATE >> 1);
+
+//-- Counter for implementing the divisor (it is a BAUDRATE module counter)
+//-- (when BAUDRATE is reached, it start again from 0)
+reg [N-1:0] divcounter = 0;
+
+//-- Contador m\xc3\xb3dulo M
+always @(posedge clk)
+
+ if (!rstn)
+ divcounter <= 0;
+
+ else if (clk_ena)
+ //-- Normal working: counting. When the maximum count is reached, it starts from 0
+ divcounter <= (divcounter == BAUDRATE - 1) ? 0 : divcounter + 1;
+ else
+ //-- Counter fixed to its maximum value
+ //-- When it is resumed it start from 0
+ divcounter <= BAUDRATE - 1;
+
+//-- The output is 1 when the counter is in the middle of the period, if clk_ena is active
+//-- It is 1 only for one system clock cycle
+assign clk_out = (divcounter == M2) ? clk_ena : 0;
+
+
+endmodule
+"
+"always @(negedge reset or posedge clk) begin
+ if (reset == 0) begin
+ d_out <= 16'h0000;
+ d_out_mem[resetcount] <= d_out;
+ laststoredvalue <= d_out;
+ end else begin
+ d_out <= d_out + 1'b1;
+ end
+end
+
+always @(bufreadaddr)
+ bufreadval = d_out_mem[bufreadaddr];"
+"always @(negedge reset or posedge clk) begin
+ if (reset == 0) begin
+ d_out <= 16'h0000;
+ d_out_mem[resetcount] <= d_out;
+ laststoredvalue <= d_out;
+ end else begin
+ d_out <= d_out + 1'b1;
+ end
+end
+
+always @(bufreadaddr)
+ bufreadval = d_out_mem[bufreadaddr];"
+"`include ""tinker.vh""\r
+module top\r
+ (\r
+ ///////// OSC ////////\r
+ input OSC_50_B3B,\r
+ input OSC_50_B3D,\r
+ input OSC_50_B4A,\r
+ input OSC_50_B4D,\r
+ input OSC_50_B7A,\r
+ input OSC_50_B7D,\r
+ input OSC_50_B8A,\r
+ input OSC_50_B8D,\r
+\r
+ //////// PCIe //////////\r
+ input pcie_refclk,\r
+ input pcie_reset_n, // Reset to embedded PCIe\r
+ input pcie_rx_in0,\r
+ input pcie_rx_in1,\r
+ input pcie_rx_in2,\r
+ input pcie_rx_in3,\r
+ input pcie_rx_in4,\r
+ input pcie_rx_in5,\r
+ input pcie_rx_in6,\r
+ input pcie_rx_in7,\r
+ output pcie_tx_out0,\r
+ output pcie_tx_out1,\r
+ output pcie_tx_out2,\r
+ output pcie_tx_out3,\r
+ output pcie_tx_out4,\r
+ output pcie_tx_out5,\r
+ output pcie_tx_out6,\r
+ output pcie_tx_out7,\r
+\r
+ //////// DDR3 //////////\r
+`ifdef ENABLE_DDR3_A\r
+ output ddr3_a_mem_reset_n,\r
+ output [14:0] ddr3_a_mem_a,\r
+ output [2:0] ddr3_a_mem_ba,\r
+ output ddr3_a_mem_cas_n,\r
+ output ddr3_a_mem_cke,\r
+ output ddr3_a_mem_ck,\r
+ output ddr3_a_mem_ck_n,\r
+ output ddr3_a_mem_cs_n,\r
+ output [7:0] ddr3_a_mem_dm,\r
+ inout [63:0] ddr3_a_mem_dq,\r
+ inout [7:0] ddr3_a_mem_dqs,\r
+ inout [7:0] ddr3_a_mem_dqs_n,\r
+ output ddr3_a_mem_odt,\r
+ output ddr3_a_mem_ras_n,\r
+ output ddr3_a_mem_we_n,\r
+ input ddr3_a_mem_oct_rzqin,\r
+`endif\r
+\r
+ //////// DDR3 //////////\r
+`ifdef ENABLE_DDR3_B\r
+ output ddr3_b_mem_reset_n,\r
+ output [14:0] ddr3_b_mem_a,\r
+ output [2:0] ddr3_b_mem_ba,\r
+ output ddr3_b_mem_cas_n,\r
+ output ddr3_b_mem_cke,\r
+ output ddr3_b_mem_ck,\r
+ output ddr3_b_mem_ck_n,\r
+ output ddr3_b_mem_cs_n,\r
+ output [7:0] ddr3_b_mem_dm,\r
+ inout [63:0] ddr3_b_mem_dq,\r
+ inout [7:0] ddr3_b_mem_dqs,\r
+ inout [7:0] ddr3_b_mem_dqs_n,\r
+ output ddr3_b_mem_odt,\r
+ output ddr3_b_mem_ras_n,\r
+ output ddr3_b_mem_we_n,\r
+ input ddr3_b_mem_oct_rzqin,\r
+`endif\r
+ \r
+ /////////QDRII_A/////////\r
+`ifdef ENABLE_QDRII_A\r
+ output [19:0] qdrii_a_mem_a,\r
+ output [1:0] qdrii_a_mem_bws_n,\r
+ input qdrii_a_mem_cq_n,\r
+ input qdrii_a_mem_cq,\r
+ output [17:0] qdrii_a_mem_d,\r
+ output qdrii_a_mem_doff_n,\r
+ output qdrii_a_mem_k_n,\r
+ output qdrii_a_mem_k,\r
+ output qdrii_a_mem_odt,\r
+ input [17:0] qdrii_a_mem_q,\r
+ input qdrii_a_mem_qvld,\r
+ output qdrii_a_mem_rps_n,\r
+ output qdrii_a_mem_wps_n,\r
+`endif\r
+\r
+ /////////QDRII_B/////////\r
+`ifdef ENABLE_QDRII_B\r
+ output [19:0] qdrii_b_mem_a,\r
+ output [1:0] qdrii_b_mem_bws_n,\r
+ input qdrii_b_mem_cq_n,\r
+ input qdrii_b_mem_cq,\r
+ output [17:0] qdrii_b_mem_d,\r
+ output qdrii_b_mem_doff_n,\r
+ output qdrii_b_mem_k_n,\r
+ output qdrii_b_mem_k,\r
+ output qdrii_b_mem_odt,\r
+ input [17:0] qdrii_b_mem_q,\r
+ input qdrii_b_mem_qvld,\r
+ output qdrii_b_mem_rps_n,\r
+ output qdrii_b_mem_wps_n,\r
+ /// RZQ ///\r
+ input qdrii_b_mem_oct_rzqin,\r
+`endif\r
+\r
+ /////////QDRII_C/////////\r
+`ifdef ENABLE_QDRII_C\r
+ output [19:0] qdrii_c_mem_a,\r
+ output [1:0] qdrii_c_mem_bws_n,\r
+ input qdrii_c_mem_cq_n,\r
+ input qdrii_c_mem_cq,\r
+ output [17:0] qdrii_c_mem_d,\r
+ output qdrii_c_mem_doff_n,\r
+ output qdrii_c_mem_k_n,\r
+ output qdrii_c_mem_k,\r
+ output qdrii_c_mem_odt,\r
+ input [17:0] qdrii_c_mem_q,\r
+ input qdrii_c_mem_qvld,\r
+ output qdrii_c_mem_rps_n,\r
+ output qdrii_c_mem_wps_n,\r
+`endif\r
+\r
+ /////////QDRII_D/////////\r
+`ifdef ENABLE_QDRII_D\r
+ output [19:0] qdrii_d_mem_a,\r
+ output [1:0] qdrii_d_mem_bws_n,\r
+ input qdrii_d_mem_cq_n,\r
+ input qdrii_d_mem_cq,\r
+ output [17:0] qdrii_d_mem_d,\r
+ output qdrii_d_mem_doff_n,\r
+ output qdrii_d_mem_k_n,\r
+ output qdrii_d_mem_k,\r
+ output qdrii_d_mem_odt,\r
+ input [17:0] qdrii_d_mem_q,\r
+ input qdrii_d_mem_qvld,\r
+ output qdrii_d_mem_rps_n,\r
+ output qdrii_d_mem_wps_n,\r
+`endif\r
+\r
+ //////// LED //////////\r
+ output [7:0] leds);\r
+\r
+ //=======================================================\r
+ // PARAMETER declarations\r
+ //=======================================================\r
+\r
+ //=======================================================\r
+ // REG/WIRE declarations\r
+ //=======================================================\r
+ wire resetn;\r
+ wire npor;\r
+\r
+ wire ddr3_a_pll_ref_clk;\r
+ wire ddr3_b_pll_ref_clk;\r
+ wire config_clk_clk;\r
+ wire kernel_pll_refclk_clk;\r
+ wire qdrii_b_pll_ref_clk;\r
+ wire qdrii_d_pll_ref_clk;\r
+\r
+ //=======================================================\r
+ // Board-specific \r
+ //=======================================================\r
+\r
+ assign ddr3_a_pll_ref_clk = OSC_50_B8A;\r
+ assign ddr3_b_pll_ref_clk = OSC_50_B7A;\r
+ assign config_clk_clk = OSC_50_B3B;\r
+ assign qdrii_b_pll_ref_clk = OSC_50_B4A;\r
+ assign qdrii_d_pll_ref_clk = OSC_50_B8D;\r
+ assign kernel_pll_refclk_clk = OSC_50_B3D;\r
+\r
+ //=======================================================\r
+ // Reset logic \r
+ //=======================================================\r
+ assign resetn = 1\'b1;\r
+\r
+ //=======================================================\r
+ // System instantiation\r
+ //=======================================================\r
+\r
+ system system_inst \r
+ (\r
+ .*,\r
+ // Global signals\r
+ .global_reset_reset_n( resetn ), // No hard reset !!!\r
+ // PCIe pins\r
+ .pcie_npor_pin_perst(pcie_reset_n),\r
+ .pcie_npor_npor(1\'b1),\r
+ .pcie_npor_out_reset_n(npor),\r
+ .pcie_refclk_clk( pcie_refclk ),\r
+ .reconfig_to_xcvr_reconfig_to_xcvr({10{24\'h0, 2\'b11, 44\'h0}}),\r
+ .reconfig_from_xcvr_reconfig_from_xcvr());\r
+\r
+ assign leds[7:0] = 8\'b0101000;\r
+\r
+endmodule\r
+"
+"`include ""tinker.vh""\r
+module top\r
+ (\r
+ ///////// OSC ////////\r
+ input OSC_50_B3B,\r
+ input OSC_50_B3D,\r
+ input OSC_50_B4A,\r
+ input OSC_50_B4D,\r
+ input OSC_50_B7A,\r
+ input OSC_50_B7D,\r
+ input OSC_50_B8A,\r
+ input OSC_50_B8D,\r
+\r
+ //////// PCIe //////////\r
+ input pcie_refclk,\r
+ input pcie_reset_n, // Reset to embedded PCIe\r
+ input pcie_rx_in0,\r
+ input pcie_rx_in1,\r
+ input pcie_rx_in2,\r
+ input pcie_rx_in3,\r
+ input pcie_rx_in4,\r
+ input pcie_rx_in5,\r
+ input pcie_rx_in6,\r
+ input pcie_rx_in7,\r
+ output pcie_tx_out0,\r
+ output pcie_tx_out1,\r
+ output pcie_tx_out2,\r
+ output pcie_tx_out3,\r
+ output pcie_tx_out4,\r
+ output pcie_tx_out5,\r
+ output pcie_tx_out6,\r
+ output pcie_tx_out7,\r
+\r
+ //////// DDR3 //////////\r
+`ifdef ENABLE_DDR3_A\r
+ output ddr3_a_mem_reset_n,\r
+ output [14:0] ddr3_a_mem_a,\r
+ output [2:0] ddr3_a_mem_ba,\r
+ output ddr3_a_mem_cas_n,\r
+ output ddr3_a_mem_cke,\r
+ output ddr3_a_mem_ck,\r
+ output ddr3_a_mem_ck_n,\r
+ output ddr3_a_mem_cs_n,\r
+ output [7:0] ddr3_a_mem_dm,\r
+ inout [63:0] ddr3_a_mem_dq,\r
+ inout [7:0] ddr3_a_mem_dqs,\r
+ inout [7:0] ddr3_a_mem_dqs_n,\r
+ output ddr3_a_mem_odt,\r
+ output ddr3_a_mem_ras_n,\r
+ output ddr3_a_mem_we_n,\r
+ input ddr3_a_mem_oct_rzqin,\r
+`endif\r
+\r
+ //////// DDR3 //////////\r
+`ifdef ENABLE_DDR3_B\r
+ output ddr3_b_mem_reset_n,\r
+ output [14:0] ddr3_b_mem_a,\r
+ output [2:0] ddr3_b_mem_ba,\r
+ output ddr3_b_mem_cas_n,\r
+ output ddr3_b_mem_cke,\r
+ output ddr3_b_mem_ck,\r
+ output ddr3_b_mem_ck_n,\r
+ output ddr3_b_mem_cs_n,\r
+ output [7:0] ddr3_b_mem_dm,\r
+ inout [63:0] ddr3_b_mem_dq,\r
+ inout [7:0] ddr3_b_mem_dqs,\r
+ inout [7:0] ddr3_b_mem_dqs_n,\r
+ output ddr3_b_mem_odt,\r
+ output ddr3_b_mem_ras_n,\r
+ output ddr3_b_mem_we_n,\r
+ input ddr3_b_mem_oct_rzqin,\r
+`endif\r
+ \r
+ /////////QDRII_A/////////\r
+`ifdef ENABLE_QDRII_A\r
+ output [19:0] qdrii_a_mem_a,\r
+ output [1:0] qdrii_a_mem_bws_n,\r
+ input qdrii_a_mem_cq_n,\r
+ input qdrii_a_mem_cq,\r
+ output [17:0] qdrii_a_mem_d,\r
+ output qdrii_a_mem_doff_n,\r
+ output qdrii_a_mem_k_n,\r
+ output qdrii_a_mem_k,\r
+ output qdrii_a_mem_odt,\r
+ input [17:0] qdrii_a_mem_q,\r
+ input qdrii_a_mem_qvld,\r
+ output qdrii_a_mem_rps_n,\r
+ output qdrii_a_mem_wps_n,\r
+`endif\r
+\r
+ /////////QDRII_B/////////\r
+`ifdef ENABLE_QDRII_B\r
+ output [19:0] qdrii_b_mem_a,\r
+ output [1:0] qdrii_b_mem_bws_n,\r
+ input qdrii_b_mem_cq_n,\r
+ input qdrii_b_mem_cq,\r
+ output [17:0] qdrii_b_mem_d,\r
+ output qdrii_b_mem_doff_n,\r
+ output qdrii_b_mem_k_n,\r
+ output qdrii_b_mem_k,\r
+ output qdrii_b_mem_odt,\r
+ input [17:0] qdrii_b_mem_q,\r
+ input qdrii_b_mem_qvld,\r
+ output qdrii_b_mem_rps_n,\r
+ output qdrii_b_mem_wps_n,\r
+ /// RZQ ///\r
+ input qdrii_b_mem_oct_rzqin,\r
+`endif\r
+\r
+ /////////QDRII_C/////////\r
+`ifdef ENABLE_QDRII_C\r
+ output [19:0] qdrii_c_mem_a,\r
+ output [1:0] qdrii_c_mem_bws_n,\r
+ input qdrii_c_mem_cq_n,\r
+ input qdrii_c_mem_cq,\r
+ output [17:0] qdrii_c_mem_d,\r
+ output qdrii_c_mem_doff_n,\r
+ output qdrii_c_mem_k_n,\r
+ output qdrii_c_mem_k,\r
+ output qdrii_c_mem_odt,\r
+ input [17:0] qdrii_c_mem_q,\r
+ input qdrii_c_mem_qvld,\r
+ output qdrii_c_mem_rps_n,\r
+ output qdrii_c_mem_wps_n,\r
+`endif\r
+\r
+ /////////QDRII_D/////////\r
+`ifdef ENABLE_QDRII_D\r
+ output [19:0] qdrii_d_mem_a,\r
+ output [1:0] qdrii_d_mem_bws_n,\r
+ input qdrii_d_mem_cq_n,\r
+ input qdrii_d_mem_cq,\r
+ output [17:0] qdrii_d_mem_d,\r
+ output qdrii_d_mem_doff_n,\r
+ output qdrii_d_mem_k_n,\r
+ output qdrii_d_mem_k,\r
+ output qdrii_d_mem_odt,\r
+ input [17:0] qdrii_d_mem_q,\r
+ input qdrii_d_mem_qvld,\r
+ output qdrii_d_mem_rps_n,\r
+ output qdrii_d_mem_wps_n,\r
+`endif\r
+\r
+ //////// LED //////////\r
+ output [7:0] leds);\r
+\r
+ //=======================================================\r
+ // PARAMETER declarations\r
+ //=======================================================\r
+\r
+ //=======================================================\r
+ // REG/WIRE declarations\r
+ //=======================================================\r
+ wire resetn;\r
+ wire npor;\r
+\r
+ wire ddr3_a_pll_ref_clk;\r
+ wire ddr3_b_pll_ref_clk;\r
+ wire config_clk_clk;\r
+ wire kernel_pll_refclk_clk;\r
+ wire qdrii_b_pll_ref_clk;\r
+ wire qdrii_d_pll_ref_clk;\r
+\r
+ //=======================================================\r
+ // Board-specific \r
+ //=======================================================\r
+\r
+ assign ddr3_a_pll_ref_clk = OSC_50_B8A;\r
+ assign ddr3_b_pll_ref_clk = OSC_50_B7A;\r
+ assign config_clk_clk = OSC_50_B3B;\r
+ assign qdrii_b_pll_ref_clk = OSC_50_B4A;\r
+ assign qdrii_d_pll_ref_clk = OSC_50_B8D;\r
+ assign kernel_pll_refclk_clk = OSC_50_B3D;\r
+\r
+ //=======================================================\r
+ // Reset logic \r
+ //=======================================================\r
+ assign resetn = 1\'b1;\r
+\r
+ //=======================================================\r
+ // System instantiation\r
+ //=======================================================\r
+\r
+ system system_inst \r
+ (\r
+ .*,\r
+ // Global signals\r
+ .global_reset_reset_n( resetn ), // No hard reset !!!\r
+ // PCIe pins\r
+ .pcie_npor_pin_perst(pcie_reset_n),\r
+ .pcie_npor_npor(1\'b1),\r
+ .pcie_npor_out_reset_n(npor),\r
+ .pcie_refclk_clk( pcie_refclk ),\r
+ .reconfig_to_xcvr_reconfig_to_xcvr({10{24\'h0, 2\'b11, 44\'h0}}),\r
+ .reconfig_from_xcvr_reconfig_from_xcvr());\r
+\r
+ assign leds[7:0] = 8\'b0101000;\r
+\r
+endmodule\r
+"
+"`include ""tinker.vh""\r
+module top\r
+ (\r
+ ///////// OSC ////////\r
+ input OSC_50_B3B,\r
+ input OSC_50_B3D,\r
+ input OSC_50_B4A,\r
+ input OSC_50_B4D,\r
+ input OSC_50_B7A,\r
+ input OSC_50_B7D,\r
+ input OSC_50_B8A,\r
+ input OSC_50_B8D,\r
+\r
+ //////// PCIe //////////\r
+ input pcie_refclk,\r
+ input pcie_reset_n, // Reset to embedded PCIe\r
+ input pcie_rx_in0,\r
+ input pcie_rx_in1,\r
+ input pcie_rx_in2,\r
+ input pcie_rx_in3,\r
+ input pcie_rx_in4,\r
+ input pcie_rx_in5,\r
+ input pcie_rx_in6,\r
+ input pcie_rx_in7,\r
+ output pcie_tx_out0,\r
+ output pcie_tx_out1,\r
+ output pcie_tx_out2,\r
+ output pcie_tx_out3,\r
+ output pcie_tx_out4,\r
+ output pcie_tx_out5,\r
+ output pcie_tx_out6,\r
+ output pcie_tx_out7,\r
+\r
+ //////// DDR3 //////////\r
+`ifdef ENABLE_DDR3_A\r
+ output ddr3_a_mem_reset_n,\r
+ output [14:0] ddr3_a_mem_a,\r
+ output [2:0] ddr3_a_mem_ba,\r
+ output ddr3_a_mem_cas_n,\r
+ output ddr3_a_mem_cke,\r
+ output ddr3_a_mem_ck,\r
+ output ddr3_a_mem_ck_n,\r
+ output ddr3_a_mem_cs_n,\r
+ output [7:0] ddr3_a_mem_dm,\r
+ inout [63:0] ddr3_a_mem_dq,\r
+ inout [7:0] ddr3_a_mem_dqs,\r
+ inout [7:0] ddr3_a_mem_dqs_n,\r
+ output ddr3_a_mem_odt,\r
+ output ddr3_a_mem_ras_n,\r
+ output ddr3_a_mem_we_n,\r
+ input ddr3_a_mem_oct_rzqin,\r
+`endif\r
+\r
+ //////// DDR3 //////////\r
+`ifdef ENABLE_DDR3_B\r
+ output ddr3_b_mem_reset_n,\r
+ output [14:0] ddr3_b_mem_a,\r
+ output [2:0] ddr3_b_mem_ba,\r
+ output ddr3_b_mem_cas_n,\r
+ output ddr3_b_mem_cke,\r
+ output ddr3_b_mem_ck,\r
+ output ddr3_b_mem_ck_n,\r
+ output ddr3_b_mem_cs_n,\r
+ output [7:0] ddr3_b_mem_dm,\r
+ inout [63:0] ddr3_b_mem_dq,\r
+ inout [7:0] ddr3_b_mem_dqs,\r
+ inout [7:0] ddr3_b_mem_dqs_n,\r
+ output ddr3_b_mem_odt,\r
+ output ddr3_b_mem_ras_n,\r
+ output ddr3_b_mem_we_n,\r
+ input ddr3_b_mem_oct_rzqin,\r
+`endif\r
+ \r
+ /////////QDRII_A/////////\r
+`ifdef ENABLE_QDRII_A\r
+ output [19:0] qdrii_a_mem_a,\r
+ output [1:0] qdrii_a_mem_bws_n,\r
+ input qdrii_a_mem_cq_n,\r
+ input qdrii_a_mem_cq,\r
+ output [17:0] qdrii_a_mem_d,\r
+ output qdrii_a_mem_doff_n,\r
+ output qdrii_a_mem_k_n,\r
+ output qdrii_a_mem_k,\r
+ output qdrii_a_mem_odt,\r
+ input [17:0] qdrii_a_mem_q,\r
+ input qdrii_a_mem_qvld,\r
+ output qdrii_a_mem_rps_n,\r
+ output qdrii_a_mem_wps_n,\r
+`endif\r
+\r
+ /////////QDRII_B/////////\r
+`ifdef ENABLE_QDRII_B\r
+ output [19:0] qdrii_b_mem_a,\r
+ output [1:0] qdrii_b_mem_bws_n,\r
+ input qdrii_b_mem_cq_n,\r
+ input qdrii_b_mem_cq,\r
+ output [17:0] qdrii_b_mem_d,\r
+ output qdrii_b_mem_doff_n,\r
+ output qdrii_b_mem_k_n,\r
+ output qdrii_b_mem_k,\r
+ output qdrii_b_mem_odt,\r
+ input [17:0] qdrii_b_mem_q,\r
+ input qdrii_b_mem_qvld,\r
+ output qdrii_b_mem_rps_n,\r
+ output qdrii_b_mem_wps_n,\r
+ /// RZQ ///\r
+ input qdrii_b_mem_oct_rzqin,\r
+`endif\r
+\r
+ /////////QDRII_C/////////\r
+`ifdef ENABLE_QDRII_C\r
+ output [19:0] qdrii_c_mem_a,\r
+ output [1:0] qdrii_c_mem_bws_n,\r
+ input qdrii_c_mem_cq_n,\r
+ input qdrii_c_mem_cq,\r
+ output [17:0] qdrii_c_mem_d,\r
+ output qdrii_c_mem_doff_n,\r
+ output qdrii_c_mem_k_n,\r
+ output qdrii_c_mem_k,\r
+ output qdrii_c_mem_odt,\r
+ input [17:0] qdrii_c_mem_q,\r
+ input qdrii_c_mem_qvld,\r
+ output qdrii_c_mem_rps_n,\r
+ output qdrii_c_mem_wps_n,\r
+`endif\r
+\r
+ /////////QDRII_D/////////\r
+`ifdef ENABLE_QDRII_D\r
+ output [19:0] qdrii_d_mem_a,\r
+ output [1:0] qdrii_d_mem_bws_n,\r
+ input qdrii_d_mem_cq_n,\r
+ input qdrii_d_mem_cq,\r
+ output [17:0] qdrii_d_mem_d,\r
+ output qdrii_d_mem_doff_n,\r
+ output qdrii_d_mem_k_n,\r
+ output qdrii_d_mem_k,\r
+ output qdrii_d_mem_odt,\r
+ input [17:0] qdrii_d_mem_q,\r
+ input qdrii_d_mem_qvld,\r
+ output qdrii_d_mem_rps_n,\r
+ output qdrii_d_mem_wps_n,\r
+`endif\r
+\r
+ //////// LED //////////\r
+ output [7:0] leds);\r
+\r
+ //=======================================================\r
+ // PARAMETER declarations\r
+ //=======================================================\r
+\r
+ //=======================================================\r
+ // REG/WIRE declarations\r
+ //=======================================================\r
+ wire resetn;\r
+ wire npor;\r
+\r
+ wire ddr3_a_pll_ref_clk;\r
+ wire ddr3_b_pll_ref_clk;\r
+ wire config_clk_clk;\r
+ wire kernel_pll_refclk_clk;\r
+ wire qdrii_b_pll_ref_clk;\r
+ wire qdrii_d_pll_ref_clk;\r
+\r
+ //=======================================================\r
+ // Board-specific \r
+ //=======================================================\r
+\r
+ assign ddr3_a_pll_ref_clk = OSC_50_B8A;\r
+ assign ddr3_b_pll_ref_clk = OSC_50_B7A;\r
+ assign config_clk_clk = OSC_50_B3B;\r
+ assign qdrii_b_pll_ref_clk = OSC_50_B4A;\r
+ assign qdrii_d_pll_ref_clk = OSC_50_B8D;\r
+ assign kernel_pll_refclk_clk = OSC_50_B3D;\r
+\r
+ //=======================================================\r
+ // Reset logic \r
+ //=======================================================\r
+ assign resetn = 1\'b1;\r
+\r
+ //=======================================================\r
+ // System instantiation\r
+ //=======================================================\r
+\r
+ system system_inst \r
+ (\r
+ .*,\r
+ // Global signals\r
+ .global_reset_reset_n( resetn ), // No hard reset !!!\r
+ // PCIe pins\r
+ .pcie_npor_pin_perst(pcie_reset_n),\r
+ .pcie_npor_npor(1\'b1),\r
+ .pcie_npor_out_reset_n(npor),\r
+ .pcie_refclk_clk( pcie_refclk ),\r
+ .reconfig_to_xcvr_reconfig_to_xcvr({10{24\'h0, 2\'b11, 44\'h0}}),\r
+ .reconfig_from_xcvr_reconfig_from_xcvr());\r
+\r
+ assign leds[7:0] = 8\'b0101000;\r
+\r
+endmodule\r
+"
+"// Syntax Highlighting Test file for Verilog
+// Some Comments about this file
+
+module toplevel(clock,reset);
+ input clock;
+ input reset;
+
+ reg flop1;
+ reg flop2;
+
+ always @ (posedge reset or posedge clock)
+ if (reset)
+ begin
+ flop1 <= 0;
+ flop2 <= 1;
+ end
+ else
+ begin
+ flop1 <= flop2;
+ flop2 <= flop1;
+ end
+endmodule
+
+initial
+ fork
+ $write(""A"");
+ $write(""B"");
+ begin
+ #1;
+ $write(""C"");
+ end
+ join
+ "
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+// Very simple model for the PLL in the RX buffer
+
+module pll (inclk0,c0);
+
+ input\t inclk0;
+ output\t c0;
+
+ assign \t c0 = #9 inclk0;
+
+endmodule // pll
+
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2007 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+`include ""../lib/radar_config.vh""
+
+module radar_control(clk_i,saddr_i,sdata_i,s_strobe_i,reset_o,
+\t\t tx_side_o,dbg_o,tx_strobe_o,tx_ctrl_o,rx_ctrl_o,
+\t\t ampl_o,fstart_o,fincr_o,pulse_num_o,io_tx_ena_o);
+
+ // System interface
+ input clk_i;\t\t// Master clock @ 64 MHz
+ input [6:0] saddr_i;\t// Configuration bus address
+ input [31:0] sdata_i;\t// Configuration bus data
+ input \t s_strobe_i; // Configuration bus write
+
+ // Control and configuration outputs
+ output \t reset_o;
+ output tx_side_o;
+ output dbg_o;
+ output tx_strobe_o;
+ output tx_ctrl_o;
+ output rx_ctrl_o;
+ output [15:0] ampl_o;
+ output [31:0] fstart_o;
+ output [31:0] fincr_o;
+ output [15:0] pulse_num_o;
+ output io_tx_ena_o;
+
+ // Internal configuration
+ wire \t lp_ena;
+ wire \t md_ena;
+ wire \t dr_ena;
+ wire [1:0] chirps;
+ wire [15:0] t_on;
+ wire [15:0] t_sw;
+ wire [15:0] t_look;
+ wire [31:0] t_idle;
+ wire [31:0] atrdel;
+
+ // Configuration from host
+ wire [31:0] \t mode;
+ setting_reg #(`FR_RADAR_MODE) sr_mode(.clock(clk_i),.reset(1\'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
+\t\t\t\t\t .out(mode));
+ assign reset_o = mode[0];
+ assign tx_side_o = mode[1];
+ assign lp_ena = mode[2];
+ assign md_ena = mode[3];
+ assign dr_ena = mode[4];
+ assign chirps = mode[6:5];
+ assign dbg_o = mode[7];
+
+ setting_reg #(`FR_RADAR_TON) sr_ton(.clock(clk_i),.reset(1\'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
+\t\t\t\t\t .out(t_on));
+
+ setting_reg #(`FR_RADAR_TSW) sr_tsw(.clock(clk_i),.reset(1\'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
+\t\t\t\t\t .out(t_sw));
+ \t\t\t\t
+ setting_reg #(`FR_RADAR_TLOOK) sr_tlook(.clock(clk_i),.reset(1\'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
+\t\t\t\t\t .out(t_look));
+ \t\t\t\t
+ setting_reg #(`FR_RADAR_TIDLE) sr_tidle(.clock(clk_i),.reset(1\'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
+\t\t\t\t\t .out(t_idle));
+ \t\t\t\t
+ setting_reg #(`FR_RADAR_AMPL) sr_ampl(.clock(clk_i),.reset(1\'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
+\t\t\t\t\t .out(ampl_o));
+
+ setting_reg #(`FR_RADAR_FSTART) sr_fstart(.clock(clk_i),.reset(1\'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
+\t\t\t\t\t .out(fstart_o));
+
+ setting_reg #(`FR_RADAR_FINCR) sr_fincr(.clock(clk_i),.reset(1\'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
+\t\t\t\t\t .out(fincr_o));
+
+ setting_reg #(`FR_RADAR_ATRDEL) sr_atrdel(.clock(clk_i),.reset(1\'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
+\t\t\t\t\t .out(atrdel));
+
+ // Pulse state machine
+ `define ST_ON 4\'b0001
+ `define ST_SW 4\'b0010
+ `define ST_LOOK 4\'b0100
+ `define ST_IDLE 4\'b1000
+
+ reg [3:0] state;
+ reg [31:0] count;
+ reg [15:0] pulse_num_o;
+
+ always @(posedge clk_i)
+ if (reset_o)
+ begin
+\t state <= `ST_ON;
+\t count <= 32\'b0;
+\t pulse_num_o <= 16\'b0;
+ end
+ else
+ case (state)
+\t `ST_ON:
+\t if (count == {16\'b0,t_on})
+\t begin
+\t state <= `ST_SW;
+\t count <= 32\'b0;
+\t\tpulse_num_o <= pulse_num_o + 16\'b1;
+\t end
+\t else
+\t count <= count + 32\'b1;
+\t
+\t `ST_SW:
+\t if (count == {16\'b0,t_sw})
+\t begin
+\t\tstate <= `ST_LOOK;
+\t\tcount <= 32\'b0;
+\t end
+\t else
+\t count <= count + 32\'b1;
+
+\t `ST_LOOK:
+\t if (count == {16\'b0,t_look})
+\t begin
+\t\tstate <= `ST_IDLE;
+\t\tcount <= 32\'b0;
+\t end
+\t else
+\t count <= count + 32\'b1;
+
+\t `ST_IDLE:
+\t if (count == t_idle)
+\t begin
+\t\tstate <= `ST_ON;
+\t\tcount <= 32\'b0;
+\t end
+\t else
+\t count <= count + 32\'b1;
+
+\t default:\t\t // Invalid state, reset state machine
+\t begin
+\t state <= `ST_ON;
+\t count <= 32\'b0;
+\t end
+ endcase
+
+ assign tx_strobe_o = count[0]; // Drive DAC inputs at 32 MHz
+ assign tx_ctrl_o = (state == `ST_ON);
+ assign rx_ctrl_o = (state == `ST_LOOK);
+
+ // Create delayed version of tx_ctrl_o to drive mixers and TX/RX switch
+ atr_delay atr_delay(.clk_i(clk_i),.rst_i(reset_o),.ena_i(1\'b1),.tx_empty_i(!tx_ctrl_o),
+\t\t .tx_delay_i(atrdel[27:16]),.rx_delay_i(atrdel[11:0]),
+\t\t .atr_tx_o(io_tx_ena_o));
+
+endmodule // radar_control
+"
+"// Model of FIFO in Altera
+
+module fifo( data, wrreq, rdreq, rdclk, wrclk, aclr, q,
+\t\t rdfull, rdempty, rdusedw, wrfull, wrempty, wrusedw);
+
+ parameter width = 16;
+ parameter depth = 1024;
+ parameter addr_bits = 10;
+
+ //`define rd_req 0; // Set this to 0 for rd_ack, 1 for rd_req
+
+ input [width-1:0] data;
+ input \t wrreq;
+ input \t rdreq;
+ input \t rdclk;
+ input \t wrclk;
+ input \t aclr;
+ output [width-1:0] q;
+ output \t rdfull;
+ output \t rdempty;
+ output reg [addr_bits-1:0] rdusedw;
+ output wrfull;
+ output wrempty;
+ output reg [addr_bits-1:0] wrusedw;
+
+ reg [width-1:0] mem [0:depth-1];
+ reg [addr_bits-1:0] \t rdptr;
+ reg [addr_bits-1:0] \t wrptr;
+
+`ifdef rd_req
+ reg [width-1:0] q;
+`else
+ wire [width-1:0] q;
+`endif
+
+ integer \t i;
+
+ always @( aclr)
+ begin
+\twrptr <= #1 0;
+\trdptr <= #1 0;
+\tfor(i=0;i= 8)
+\t serial_data <= #1 {serial_data[30:0],serial_data_in};
+\t else if(ser_ctr < 8)
+\t serial_addr <= #1 {serial_addr[5:0],serial_data_in};
+ end // else: !if(~enable)
+
+ reg enable_d1, enable_d2;
+ always @(posedge master_clk)
+ begin
+\tenable_d1 <= #1 enable;
+\tenable_d2 <= #1 enable_d1;
+ end
+
+ assign serial_strobe = enable_d2 & ~enable_d1;
+
+endmodule // serial_io
+
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2007 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+module radar_tx(clk_i,rst_i,ena_i,strobe_i,
+\t\tampl_i,fstart_i,fincr_i,
+\t\ttx_i_o,tx_q_o);
+
+ // System control
+ input clk_i;
+ input rst_i;
+ input ena_i;
+ input strobe_i;
+
+ // Configuration
+ input [15:0] ampl_i;
+ input [31:0] fstart_i;
+ input [31:0] fincr_i;
+
+ // Chirp output
+ output [13:0] tx_i_o;
+ output [13:0] tx_q_o;
+ wire [15:0] cordic_i, cordic_q;
+
+ // Chirp generator
+ reg [31:0] freq;
+
+ always @(posedge clk_i)
+ if (rst_i | ~ena_i)
+ freq <= fstart_i;
+ else
+ if (strobe_i)
+\t freq <= freq + fincr_i;
+
+ cordic_nco nco(.clk_i(clk_i),.rst_i(rst_i),.ena_i(ena_i),.strobe_i(strobe_i),
+\t\t .ampl_i(ampl_i),.freq_i(freq),.phs_i(0),
+\t\t .data_i_o(cordic_i),.data_q_o(cordic_q));
+
+ assign tx_i_o = cordic_i[13:0];
+ assign tx_q_o = cordic_q[13:0];
+\t
+endmodule // radar_tx
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2007 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+`timescale 1ns/100ps
+
+`include ""../lib/sounder.v""
+
+`define FR_MODE \t\t7\'d64
+`define bmFR_MODE_RESET\t\t32\'h0001
+`define bmFR_MODE_TX 32\'h0002
+`define bmFR_MODE_RX 32\'h0004
+`define bmFR_MODE_LP 32\'h0008
+
+`define FR_DEGREE\t\t7\'d65
+`define FR_AMPL 7\'d66
+
+module sounder_tb;
+
+ // System bus
+ reg clk;
+ reg rst;
+ reg ena;
+
+ // Configuration bus
+ reg [6:0] saddr;
+ reg [31:0] sdata;
+ reg \t s_strobe;
+
+ // DAC bus
+ wire tx_strobe;
+ wire [13:0] tx_dac_i;
+ wire [13:0] tx_dac_q;
+
+ // ADC bus
+ reg [15:0] rx_adc_i;
+ reg [15:0] rx_adc_q;
+
+ // FIFO bus
+ wire fifo_strobe;
+ wire [15:0] fifo_i;
+ wire [15:0] fifo_q;
+
+ // Configuration shadow registers
+ reg [31:0] mode;
+ reg [31:0] degree;
+
+ sounder uut
+ (.clk_i(clk),.saddr_i(saddr),.sdata_i(sdata),.s_strobe_i(s_strobe),
+ .tx_strobe_o(tx_strobe),.tx_dac_i_o(tx_dac_i),.tx_dac_q_o(tx_dac_q),
+ .rx_strobe_o(fifo_strobe),.rx_adc_i_i(rx_adc_i),.rx_adc_q_i(rx_adc_q),
+ .rx_imp_i_o(fifo_i),.rx_imp_q_o(fifo_q));
+
+ // Start up initialization
+ initial
+ begin
+\tclk = 0;
+\trst = 0;
+\tena = 0;
+\tsaddr = 0;
+\tsdata = 0;
+\ts_strobe = 0;
+\trx_adc_i = 0;
+\trx_adc_q = 0;
+\tmode = 0;
+\tdegree = 0;
+\t
+\t@(posedge clk);
+\trst = 1;
+\t@(posedge clk);
+\trst = 0;
+\t@(posedge clk);
+\tena = 1;
+ end
+
+ always
+ #5 clk <= ~clk;
+
+ initial
+ begin
+\t$monitor($time, "" c=%b r=%b phs=%d txs=%b rfs=%b rxs=%b sms=%b pn=%b pnr=%b prd=%x sum=%x tot=%x"",
+\t\t clk, rst, uut.master.phase, uut.tx_strobe_o, uut.ref_strobe, uut.rx_strobe_o,
+\t\t uut.sum_strobe, uut.transmitter.pn, uut.receiver.pn_ref, uut.receiver.prod_i,
+\t\t uut.receiver.sum_i, uut.receiver.total_i);
+
+\t$dumpfile(""sounder_tb.vcd"");
+\t$dumpvars(0, sounder_tb);
+ end
+
+ // Test tasks
+ task write_cfg_register;
+ input [6:0] regno;
+ input [31:0] value;
+
+ begin
+\t @(posedge clk);
+\t saddr <= #5 regno;
+\t sdata <= #5 value;
+\t s_strobe <= #5 1\'b1;
+\t @(posedge clk);
+\t s_strobe <= #5 0;
+ end
+ endtask // write_cfg_register
+
+ // Application reset line
+ task set_reset;
+ input reset;
+
+ begin
+\t mode = reset ? (mode | `bmFR_MODE_RESET) : (mode & ~`bmFR_MODE_RESET);
+\t write_cfg_register(`FR_MODE, mode);
+ end
+ endtask // reset
+
+ // Set the PN code degree
+ task set_degree;
+ input [5:0] degree;
+ begin
+\t write_cfg_register(`FR_DEGREE, degree);
+ end
+ endtask // set_degree
+
+ // Set the PN amplitude
+ task set_amplitude;
+ input [13:0] ampl;
+ begin
+\t write_cfg_register(`FR_AMPL, ampl);
+ end
+ endtask // set_ampl
+
+ // Turn on or off the transmitter
+ task enable_tx;
+ input tx;
+
+ begin
+\t mode = tx ? (mode | `bmFR_MODE_TX) : (mode & ~`bmFR_MODE_TX);
+\t write_cfg_register(`FR_MODE, mode);
+ end
+ endtask // enable_tx
+
+ // Turn on or off the receiver
+ task enable_rx;
+ input rx;
+
+ begin
+\t mode = rx ? (mode | `bmFR_MODE_RX) : (mode & ~`bmFR_MODE_RX);
+\t write_cfg_register(`FR_MODE, mode);
+ end
+ endtask // enable_rx
+
+
+ // Turn on or off digital loopback
+ task enable_lp;
+ input lp;
+
+ begin
+\t mode = lp ? (mode | `bmFR_MODE_LP) : (mode & ~`bmFR_MODE_LP);
+\t write_cfg_register(`FR_MODE, mode);
+ end
+ endtask // enable_lp
+
+ // Test transmitter functionality
+ task test_tx;
+ input [5:0] degree;
+ input [31:0] test_len;
+
+ begin
+\t #20 set_reset(1);
+\t #20 set_degree(degree);
+\t #20 set_amplitude(14\'h1000);
+\t #20 enable_tx(1);
+\t #20 enable_rx(0);
+\t #20 enable_lp(0);
+\t #20 set_reset(0);
+\t #(test_len);
+ end
+ endtask // test_tx
+
+ // Test loopback functionality
+ task test_lp;
+ input [5:0] degree;
+ input [31:0] test_len;
+
+ begin
+\t #20 set_reset(1);
+\t #20 set_degree(degree);
+\t #20 enable_tx(1);
+\t #20 enable_rx(1);
+\t #20 enable_lp(1);
+\t #20 set_reset(0);
+\t #(test_len);
+ end
+ endtask // test_lp
+
+ // Test receiver only functionality
+ task test_rx;
+ input [5:0] degree;
+ input [31:0] test_len;
+
+ begin
+\t #20 set_reset(1);
+\t #20 set_degree(degree);
+\t #20 enable_tx(0);
+\t #20 enable_rx(1);
+\t #20 enable_lp(0);
+\t #20 set_reset(0);
+\t #(test_len);
+ end
+ endtask // test_rx
+
+ // Execute tests
+ initial
+ begin
+ #20 test_tx(8,255*20);
+\t#20 test_lp(8,255*255*20*5);
+\t//#20 test_rx(8,255*255*20*5);
+\t#500 $finish;
+ end
+
+endmodule
+
+"
+"pll\tpll_inst (
+\t.inclk0 ( inclk0_sig ),
+\t.c0 ( c0_sig )
+\t);
+"
+"// megafunction wizard: %FIFO%VBB%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: dcfifo
+
+// ============================================================
+// File Name: fifo_4k.v
+// Megafunction Name(s):
+// \t\t\tdcfifo
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 5.0 Build 168 06/22/2005 SP 1 SJ Web Edition
+// ************************************************************
+
+//Copyright (C) 1991-2005 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+module fifo_4k (
+\tdata,
+\twrreq,
+\trdreq,
+\trdclk,
+\twrclk,
+\taclr,
+\tq,
+\trdempty,
+\trdusedw,
+\twrfull,
+\twrusedw)/* synthesis synthesis_clearbox = 1 */;
+
+\tinput\t[15:0] data;
+\tinput\t wrreq;
+\tinput\t rdreq;
+\tinput\t rdclk;
+\tinput\t wrclk;
+\tinput\t aclr;
+\toutput\t[15:0] q;
+\toutput\t rdempty;
+\toutput\t[11:0] rdusedw;
+\toutput\t wrfull;
+\toutput\t[11:0] wrusedw;
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: Width NUMERIC ""16""
+// Retrieval info: PRIVATE: Depth NUMERIC ""4096""
+// Retrieval info: PRIVATE: Clock NUMERIC ""4""
+// Retrieval info: PRIVATE: CLOCKS_ARE_SYNCHRONIZED NUMERIC ""0""
+// Retrieval info: PRIVATE: Full NUMERIC ""1""
+// Retrieval info: PRIVATE: Empty NUMERIC ""1""
+// Retrieval info: PRIVATE: UsedW NUMERIC ""1""
+// Retrieval info: PRIVATE: AlmostFull NUMERIC ""0""
+// Retrieval info: PRIVATE: AlmostEmpty NUMERIC ""0""
+// Retrieval info: PRIVATE: AlmostFullThr NUMERIC ""-1""
+// Retrieval info: PRIVATE: AlmostEmptyThr NUMERIC ""-1""
+// Retrieval info: PRIVATE: sc_aclr NUMERIC ""0""
+// Retrieval info: PRIVATE: sc_sclr NUMERIC ""0""
+// Retrieval info: PRIVATE: rsFull NUMERIC ""0""
+// Retrieval info: PRIVATE: rsEmpty NUMERIC ""1""
+// Retrieval info: PRIVATE: rsUsedW NUMERIC ""1""
+// Retrieval info: PRIVATE: wsFull NUMERIC ""1""
+// Retrieval info: PRIVATE: wsEmpty NUMERIC ""0""
+// Retrieval info: PRIVATE: wsUsedW NUMERIC ""1""
+// Retrieval info: PRIVATE: dc_aclr NUMERIC ""1""
+// Retrieval info: PRIVATE: LegacyRREQ NUMERIC ""0""
+// Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC ""0""
+// Retrieval info: PRIVATE: MAX_DEPTH_BY_9 NUMERIC ""0""
+// Retrieval info: PRIVATE: LE_BasedFIFO NUMERIC ""0""
+// Retrieval info: PRIVATE: Optimize NUMERIC ""2""
+// Retrieval info: PRIVATE: OVERFLOW_CHECKING NUMERIC ""1""
+// Retrieval info: PRIVATE: UNDERFLOW_CHECKING NUMERIC ""1""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: CONSTANT: LPM_WIDTH NUMERIC ""16""
+// Retrieval info: CONSTANT: LPM_NUMWORDS NUMERIC ""4096""
+// Retrieval info: CONSTANT: LPM_WIDTHU NUMERIC ""12""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: CONSTANT: CLOCKS_ARE_SYNCHRONIZED STRING ""FALSE""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""dcfifo""
+// Retrieval info: CONSTANT: LPM_SHOWAHEAD STRING ""ON""
+// Retrieval info: CONSTANT: OVERFLOW_CHECKING STRING ""OFF""
+// Retrieval info: CONSTANT: UNDERFLOW_CHECKING STRING ""OFF""
+// Retrieval info: CONSTANT: USE_EAB STRING ""ON""
+// Retrieval info: CONSTANT: ADD_RAM_OUTPUT_REGISTER STRING ""OFF""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: USED_PORT: data 0 0 16 0 INPUT NODEFVAL data[15..0]
+// Retrieval info: USED_PORT: q 0 0 16 0 OUTPUT NODEFVAL q[15..0]
+// Retrieval info: USED_PORT: wrreq 0 0 0 0 INPUT NODEFVAL wrreq
+// Retrieval info: USED_PORT: rdreq 0 0 0 0 INPUT NODEFVAL rdreq
+// Retrieval info: USED_PORT: rdclk 0 0 0 0 INPUT NODEFVAL rdclk
+// Retrieval info: USED_PORT: wrclk 0 0 0 0 INPUT NODEFVAL wrclk
+// Retrieval info: USED_PORT: rdempty 0 0 0 0 OUTPUT NODEFVAL rdempty
+// Retrieval info: USED_PORT: rdusedw 0 0 12 0 OUTPUT NODEFVAL rdusedw[11..0]
+// Retrieval info: USED_PORT: wrfull 0 0 0 0 OUTPUT NODEFVAL wrfull
+// Retrieval info: USED_PORT: wrusedw 0 0 12 0 OUTPUT NODEFVAL wrusedw[11..0]
+// Retrieval info: USED_PORT: aclr 0 0 0 0 INPUT GND aclr
+// Retrieval info: CONNECT: @data 0 0 16 0 data 0 0 16 0
+// Retrieval info: CONNECT: q 0 0 16 0 @q 0 0 16 0
+// Retrieval info: CONNECT: @wrreq 0 0 0 0 wrreq 0 0 0 0
+// Retrieval info: CONNECT: @rdreq 0 0 0 0 rdreq 0 0 0 0
+// Retrieval info: CONNECT: @rdclk 0 0 0 0 rdclk 0 0 0 0
+// Retrieval info: CONNECT: @wrclk 0 0 0 0 wrclk 0 0 0 0
+// Retrieval info: CONNECT: rdempty 0 0 0 0 @rdempty 0 0 0 0
+// Retrieval info: CONNECT: rdusedw 0 0 12 0 @rdusedw 0 0 12 0
+// Retrieval info: CONNECT: wrfull 0 0 0 0 @wrfull 0 0 0 0
+// Retrieval info: CONNECT: wrusedw 0 0 12 0 @wrusedw 0 0 12 0
+// Retrieval info: CONNECT: @aclr 0 0 0 0 aclr 0 0 0 0
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k_bb.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k_waveforms.html TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k_wave*.jpg FALSE
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+
+// Sign extension ""macro""
+// bits_out should be greater than bits_in
+
+module sign_extend (in,out);
+\tparameter bits_in=0; // FIXME Quartus insists on a default
+\tparameter bits_out=0;
+\t
+\tinput [bits_in-1:0] in;
+\toutput [bits_out-1:0] out;
+\t
+\tassign out = {{(bits_out-bits_in){in[bits_in-1]}},in};
+\t
+endmodule
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003,2004,2005,2006 Matt Ettus
+// Copyright (C) 2006 Martin Dudok van Heel
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+// Top level module for a full setup with DUCs and DDCs
+
+// Define DEBUG_OWNS_IO_PINS if we\'re using the daughterboard i/o pins
+// for debugging info. NB, This can kill the m\'board and/or d\'board if you
+// have anything except basic d\'boards installed.
+
+// Uncomment the following to include optional circuitry
+
+`include ""config.vh""
+`include ""../../../firmware/include/fpga_regs_common.v""
+`include ""../../../firmware/include/fpga_regs_standard.v""
+
+module usrp_multi
+(output MYSTERY_SIGNAL,
+ input master_clk,
+ input SCLK,
+ input SDI,
+ inout SDO,
+ input SEN_FPGA,
+
+ input FX2_1,
+ output FX2_2,
+ output FX2_3,
+
+ input wire [11:0] rx_a_a,
+ input wire [11:0] rx_b_a,
+ input wire [11:0] rx_a_b,
+ input wire [11:0] rx_b_b,
+
+ output wire [13:0] tx_a,
+ output wire [13:0] tx_b,
+
+ output wire TXSYNC_A,
+ output wire TXSYNC_B,
+
+ // USB interface
+ input usbclk,
+ input wire [2:0] usbctl,
+ output wire [1:0] usbrdy,
+ inout [15:0] usbdata, // NB Careful, inout
+
+ // These are the general purpose i/o\'s that go to the daughterboard slots
+ inout wire [15:0] io_tx_a,
+ inout wire [15:0] io_tx_b,
+ inout wire [15:0] io_rx_a,
+ inout wire [15:0] io_rx_b
+ );\t
+ wire [15:0] debugdata,debugctrl;
+ assign MYSTERY_SIGNAL = 1\'b0;
+
+ wire clk64,clk128;
+
+ wire WR = usbctl[0];
+ wire RD = usbctl[1];
+ wire OE = usbctl[2];
+
+ wire have_space, have_pkt_rdy;
+ assign usbrdy[0] = have_space;
+ assign usbrdy[1] = have_pkt_rdy;
+
+ wire tx_underrun, rx_overrun;
+ wire clear_status = FX2_1;
+ assign FX2_2 = rx_overrun;
+ assign FX2_3 = tx_underrun;
+
+ wire [15:0] usbdata_out;
+
+ wire [3:0] dac0mux,dac1mux,dac2mux,dac3mux;
+
+ wire tx_realsignals;
+ wire [3:0] rx_numchan;
+ wire [2:0] tx_numchan;
+
+ wire [7:0] interp_rate, decim_rate;
+ wire [15:0] tx_debugbus, rx_debugbus;
+
+ wire enable_tx, enable_rx;
+ wire reset_data;
+`ifdef MULTI_ON
+ wire sync_rx;
+ assign reset_data = sync_rx;
+`else
+ assign reset_data = 1\'b0;
+`endif // `ifdef MULTI_ON
+
+ wire tx_dsp_reset, rx_dsp_reset, tx_bus_reset, rx_bus_reset;
+ wire [7:0] settings;
+
+ // Tri-state bus macro
+ bustri bustri( .data(usbdata_out),.enabledt(OE),.tridata(usbdata) );
+
+ assign clk64 = master_clk;
+
+ wire [15:0] ch0tx,ch1tx,ch2tx,ch3tx; //,ch4tx,ch5tx,ch6tx,ch7tx;
+ wire [15:0] ch0rx,ch1rx,ch2rx,ch3rx,ch4rx,ch5rx,ch6rx,ch7rx;
+
+ // TX
+ wire [15:0] i_out_0,i_out_1,q_out_0,q_out_1;
+ wire [15:0] bb_tx_i0,bb_tx_q0,bb_tx_i1,bb_tx_q1; // bb_tx_i2,bb_tx_q2,bb_tx_i3,bb_tx_q3;
+
+ wire strobe_interp, tx_sample_strobe;
+ wire tx_empty;
+
+ wire serial_strobe;
+ wire [6:0] serial_addr;
+ wire [31:0] serial_data;
+
+ reg [15:0] debug_counter;
+`ifdef COUNTER_32BIT_ON
+ reg [31:0] sample_counter_32bit;
+`endif // `ifdef COUNTER_32BIT_ON
+ reg [15:0] loopback_i_0,loopback_q_0;
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Transmit Side
+`ifdef TX_ON
+ assign bb_tx_i0 = ch0tx;
+ assign bb_tx_q0 = ch1tx;
+ assign bb_tx_i1 = ch2tx;
+ assign bb_tx_q1 = ch3tx;
+
+ tx_buffer tx_buffer
+ ( .usbclk(usbclk),.bus_reset(tx_bus_reset),.reset(tx_dsp_reset),
+ .usbdata(usbdata),.WR(WR),.have_space(have_space),.tx_underrun(tx_underrun),
+ .channels({tx_numchan,1\'b0}),
+ .tx_i_0(ch0tx),.tx_q_0(ch1tx),
+ .tx_i_1(ch2tx),.tx_q_1(ch3tx),
+ .tx_i_2(),.tx_q_2(),
+ .tx_i_3(),.tx_q_3(),
+ .txclk(clk64),.txstrobe(strobe_interp),
+ .clear_status(clear_status),
+ .tx_empty(tx_empty),
+ .debugbus(tx_debugbus) );
+
+ tx_chain tx_chain_0
+ ( .clock(clk64),.reset(tx_dsp_reset),.enable(enable_tx),
+ .interp_rate(interp_rate),.sample_strobe(tx_sample_strobe),
+ .interpolator_strobe(strobe_interp),.freq(),
+ .i_in(bb_tx_i0),.q_in(bb_tx_q0),.i_out(i_out_0),.q_out(q_out_0) );
+
+ tx_chain tx_chain_1
+ ( .clock(clk64),.reset(tx_dsp_reset),.enable(enable_tx),
+ .interp_rate(interp_rate),.sample_strobe(tx_sample_strobe),
+ .interpolator_strobe(strobe_interp),.freq(),
+ .i_in(bb_tx_i1),.q_in(bb_tx_q1),.i_out(i_out_1),.q_out(q_out_1) );
+
+ setting_reg #(`FR_TX_MUX)
+ sr_txmux(.clock(clk64),.reset(tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
+\t .out({dac3mux,dac2mux,dac1mux,dac0mux,tx_realsignals,tx_numchan}));
+
+ wire [15:0] tx_a_a = dac0mux[3] ? (dac0mux[1] ? (dac0mux[0] ? q_out_1 : i_out_1) : (dac0mux[0] ? q_out_0 : i_out_0)) : 16\'b0;
+ wire [15:0] tx_b_a = dac1mux[3] ? (dac1mux[1] ? (dac1mux[0] ? q_out_1 : i_out_1) : (dac1mux[0] ? q_out_0 : i_out_0)) : 16\'b0;
+ wire [15:0] tx_a_b = dac2mux[3] ? (dac2mux[1] ? (dac2mux[0] ? q_out_1 : i_out_1) : (dac2mux[0] ? q_out_0 : i_out_0)) : 16\'b0;
+ wire [15:0] tx_b_b = dac3mux[3] ? (dac3mux[1] ? (dac3mux[0] ? q_out_1 : i_out_1) : (dac3mux[0] ? q_out_0 : i_out_0)) : 16\'b0;
+
+ wire txsync = tx_sample_strobe;
+ assign TXSYNC_A = txsync;
+ assign TXSYNC_B = txsync;
+
+ assign tx_a = txsync ? tx_b_a[15:2] : tx_a_a[15:2];
+ assign tx_b = txsync ? tx_b_b[15:2] : tx_a_b[15:2];
+`endif // `ifdef TX_ON
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Receive Side
+`ifdef RX_ON
+ wire rx_sample_strobe,strobe_decim,hb_strobe;
+ wire [15:0] bb_rx_i0,bb_rx_q0,bb_rx_i1,bb_rx_q1,
+\t bb_rx_i2,bb_rx_q2,bb_rx_i3,bb_rx_q3;
+
+ wire loopback = settings[0];
+ wire counter = settings[1];
+`ifdef COUNTER_32BIT_ON
+ wire counter_32bit = settings[2];
+
+ always @(posedge clk64)
+ if(rx_dsp_reset)
+ sample_counter_32bit <= #1 32\'d0;
+ else if(~enable_rx | reset_data)
+ sample_counter_32bit <=#1 32\'d0;
+ else if(hb_strobe)
+ sample_counter_32bit <=#1 sample_counter_32bit + 32\'d1;
+`endif // `ifdef COUNTER_32BIT_ON
+
+ always @(posedge clk64)
+ if(rx_dsp_reset)
+ debug_counter <= #1 16\'d0;
+ else if(~enable_rx)
+ debug_counter <= #1 16\'d0;
+ else if(hb_strobe)
+ debug_counter <=#1 debug_counter + 16\'d2;
+
+ always @(posedge clk64)
+ if(strobe_interp)
+ begin
+\t loopback_i_0 <= #1 ch0tx;
+\t loopback_q_0 <= #1 ch1tx;
+ end
+
+`ifdef COUNTER_32BIT_ON
+ assign ch0rx = counter_32bit?sample_counter_32bit[31:16]:counter ? debug_counter : loopback ? loopback_i_0 : bb_rx_i0;
+ assign ch1rx = counter_32bit?sample_counter_32bit[15:0]:counter ? debug_counter + 16\'d1 : loopback ? loopback_q_0 : bb_rx_q0;
+ assign ch2rx = bb_rx_i1;
+ assign ch3rx = bb_rx_q1;
+ assign ch4rx = counter_32bit?bb_rx_i0:bb_rx_i2;
+ assign ch5rx = counter_32bit?bb_rx_q0:bb_rx_q2;// If using counter replicate channels here to be able to get rx_i0 when using counter
+ //This means if you use 4 channels that channel 3 will be replaced by channel 0
+ // and channel 0 will output the 32 bit counter.
+ assign ch6rx = bb_rx_i3;
+ assign ch7rx = bb_rx_q3;
+`else
+ assign ch0rx = counter ? debug_counter : loopback ? loopback_i_0 : bb_rx_i0;
+ assign ch1rx = counter ? debug_counter + 16\'d1 : loopback ? loopback_q_0 : bb_rx_q0;
+ assign ch2rx = bb_rx_i1;
+ assign ch3rx = bb_rx_q1;
+ assign ch4rx = bb_rx_i2;
+ assign ch5rx = bb_rx_q2;
+ assign ch6rx = bb_rx_i3;
+ assign ch7rx = bb_rx_q3;
+`endif // `ifdef COUNTER_32BIT_ON
+
+
+ wire [15:0] ddc0_in_i,ddc0_in_q,ddc1_in_i,ddc1_in_q,ddc2_in_i,ddc2_in_q,ddc3_in_i,ddc3_in_q;
+ adc_interface adc_interface(.clock(clk64),.reset(rx_dsp_reset),.enable(1\'b1),
+\t\t\t .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+\t\t\t .rx_a_a(rx_a_a),.rx_b_a(rx_b_a),.rx_a_b(rx_a_b),.rx_b_b(rx_b_b),
+\t\t\t .ddc0_in_i(ddc0_in_i),.ddc0_in_q(ddc0_in_q),
+\t\t\t .ddc1_in_i(ddc1_in_i),.ddc1_in_q(ddc1_in_q),
+\t\t\t .ddc2_in_i(ddc2_in_i),.ddc2_in_q(ddc2_in_q),
+\t\t\t .ddc3_in_i(ddc3_in_i),.ddc3_in_q(ddc3_in_q),.rx_numchan(rx_numchan) );
+
+ rx_buffer rx_buffer
+ ( .usbclk(usbclk),.bus_reset(rx_bus_reset),.reset(rx_dsp_reset | reset_data),
+ .reset_regs(rx_dsp_reset),
+ .usbdata(usbdata_out),.RD(RD),.have_pkt_rdy(have_pkt_rdy),.rx_overrun(rx_overrun),
+ .channels(rx_numchan),
+ .ch_0(ch0rx),.ch_1(ch1rx),
+ .ch_2(ch2rx),.ch_3(ch3rx),
+ .ch_4(ch4rx),.ch_5(ch5rx),
+ .ch_6(ch6rx),.ch_7(ch7rx),
+ .rxclk(clk64),.rxstrobe(hb_strobe),
+ .clear_status(clear_status),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .debugbus(rx_debugbus) );
+
+ `ifdef RX_EN_0
+ rx_chain #(`FR_RX_FREQ_0,`FR_RX_PHASE_0) rx_chain_0
+ ( .clock(clk64),.reset(reset_data),.enable(enable_rx),
+ .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(hb_strobe),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .i_in(ddc0_in_i),.q_in(ddc0_in_q),.i_out(bb_rx_i0),.q_out(bb_rx_q0),.debugdata(debugdata),.debugctrl(debugctrl));
+ `else
+ assign bb_rx_i0=16\'d0;
+ assign bb_rx_q0=16\'d0;
+ `endif
+
+ `ifdef RX_EN_1
+ rx_chain #(`FR_RX_FREQ_1,`FR_RX_PHASE_1) rx_chain_1
+ ( .clock(clk64),.reset(reset_data),.enable(enable_rx),
+ .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .i_in(ddc1_in_i),.q_in(ddc1_in_q),.i_out(bb_rx_i1),.q_out(bb_rx_q1));
+ `else
+ assign bb_rx_i1=16\'d0;
+ assign bb_rx_q1=16\'d0;
+ `endif
+
+ `ifdef RX_EN_2
+ rx_chain #(`FR_RX_FREQ_2,`FR_RX_PHASE_2) rx_chain_2
+ ( .clock(clk64),.reset(reset_data),.enable(enable_rx),
+ .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .i_in(ddc2_in_i),.q_in(ddc2_in_q),.i_out(bb_rx_i2),.q_out(bb_rx_q2));
+ `else
+ assign bb_rx_i2=16\'d0;
+ assign bb_rx_q2=16\'d0;
+ `endif
+
+ `ifdef RX_EN_3
+ rx_chain #(`FR_RX_FREQ_3,`FR_RX_PHASE_3) rx_chain_3
+ ( .clock(clk64),.reset(reset_data),.enable(enable_rx),
+ .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .i_in(ddc3_in_i),.q_in(ddc3_in_q),.i_out(bb_rx_i3),.q_out(bb_rx_q3));
+ assign bb_rx_i3=16\'d0;
+ assign bb_rx_q3=16\'d0;
+ `endif
+
+`endif // `ifdef RX_ON
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Control Functions
+
+ wire [31:0] capabilities;
+ assign capabilities[7] = `TX_CAP_HB;
+ assign capabilities[6:4] = `TX_CAP_NCHAN;
+ assign capabilities[3] = `RX_CAP_HB;
+ assign capabilities[2:0] = `RX_CAP_NCHAN;
+
+
+ serial_io serial_io
+ ( .master_clk(clk64),.serial_clock(SCLK),.serial_data_in(SDI),
+ .enable(SEN_FPGA),.reset(1\'b0),.serial_data_out(SDO),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .readback_0({io_rx_a,io_tx_a}),.readback_1({io_rx_b,io_tx_b}),.readback_2(capabilities),.readback_3(32\'hf0f0931a) );
+
+ wire [15:0] reg_0,reg_1,reg_2,reg_3;
+
+`ifdef MULTI_ON
+
+ master_control_multi master_control
+ ( .master_clk(clk64),.usbclk(usbclk),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .rx_slave_sync(io_rx_a[`bitnoFR_RX_SYNC_INPUT_IOPIN]),
+ .tx_bus_reset(tx_bus_reset),.rx_bus_reset(rx_bus_reset),
+ .tx_dsp_reset(tx_dsp_reset),.rx_dsp_reset(rx_dsp_reset),
+ .enable_tx(enable_tx),.enable_rx(enable_rx),
+ .sync_rx(sync_rx),
+ .interp_rate(interp_rate),.decim_rate(decim_rate),
+ .tx_sample_strobe(tx_sample_strobe),.strobe_interp(strobe_interp),
+ .rx_sample_strobe(rx_sample_strobe),.strobe_decim(strobe_decim),
+ .tx_empty(tx_empty),
+ //.debug_0(rx_a_a),.debug_1(ddc0_in_i),
+ .debug_0(rx_debugbus),.debug_1(ddc0_in_i),
+ .debug_2({rx_sample_strobe,strobe_decim,serial_strobe,serial_addr}),.debug_3({rx_dsp_reset,tx_dsp_reset,rx_bus_reset,tx_bus_reset,enable_rx,tx_underrun,rx_overrun,decim_rate}),
+ .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3) );
+
+`else //`ifdef MULTI_ON
+
+ master_control master_control
+ ( .master_clk(clk64),.usbclk(usbclk),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .tx_bus_reset(tx_bus_reset),.rx_bus_reset(rx_bus_reset),
+ .tx_dsp_reset(tx_dsp_reset),.rx_dsp_reset(rx_dsp_reset),
+ .enable_tx(enable_tx),.enable_rx(enable_rx),
+ .interp_rate(interp_rate),.decim_rate(decim_rate),
+ .tx_sample_strobe(tx_sample_strobe),.strobe_interp(strobe_interp),
+ .rx_sample_strobe(rx_sample_strobe),.strobe_decim(strobe_decim),
+ .tx_empty(tx_empty),
+ //.debug_0(rx_a_a),.debug_1(ddc0_in_i),
+ .debug_0(rx_debugbus),.debug_1(ddc0_in_i),
+ .debug_2({rx_sample_strobe,strobe_decim,serial_strobe,serial_addr}),.debug_3({rx_dsp_reset,tx_dsp_reset,rx_bus_reset,tx_bus_reset,enable_rx,tx_underrun,rx_overrun,decim_rate}),
+ .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3) );
+
+`endif //`ifdef MULTI_ON
+
+ io_pins io_pins
+ (.io_0(io_tx_a),.io_1(io_rx_a),.io_2(io_tx_b),.io_3(io_rx_b),
+ .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3),
+ .clock(clk64),.rx_reset(rx_dsp_reset),.tx_reset(tx_dsp_reset),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe));
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Misc Settings
+ setting_reg #(`FR_MODE) sr_misc(.clock(clk64),.reset(rx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(settings));
+
+endmodule // usrp_multi
+"
+"
+
+module rssi (input clock, input reset, input enable,
+\t input [11:0] adc, output [15:0] rssi, output [15:0] over_count);
+
+ wire \t\t over_hi = (adc == 12'h7FF);
+ wire \t\t over_lo = (adc == 12'h800);
+ wire \t\t over = over_hi | over_lo;
+
+ reg [25:0] \t\t over_count_int;
+ always @(posedge clock)
+ if(reset | ~enable)
+ over_count_int <= #1 26'd0;
+ else
+ over_count_int <= #1 over_count_int + (over ? 26'd65535 : 26'd0) - over_count_int[25:10];
+
+ assign over_count = over_count_int[25:10];
+
+ wire [11:0] abs_adc = adc[11] ? ~adc : adc;
+
+ reg [25:0] rssi_int;
+ always @(posedge clock)
+ if(reset | ~enable)
+ rssi_int <= #1 26'd0;
+ else
+ rssi_int <= #1 rssi_int + abs_adc - rssi_int[25:10];
+
+ assign rssi = rssi_int[25:10];
+
+endmodule // rssi
+"
+"// megafunction wizard: %FIFO%VBB%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: dcfifo
+
+// ============================================================
+// File Name: fifo_2k.v
+// Megafunction Name(s):
+// \t\t\tdcfifo
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 5.0 Build 168 06/22/2005 SP 1 SJ Web Edition
+// ************************************************************
+
+//Copyright (C) 1991-2005 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+module fifo_2k (
+\tdata,
+\twrreq,
+\trdreq,
+\trdclk,
+\twrclk,
+\taclr,
+\tq,
+\trdempty,
+\trdusedw,
+\twrfull,
+\twrusedw)/* synthesis synthesis_clearbox = 1 */;
+
+\tinput\t[15:0] data;
+\tinput\t wrreq;
+\tinput\t rdreq;
+\tinput\t rdclk;
+\tinput\t wrclk;
+\tinput\t aclr;
+\toutput\t[15:0] q;
+\toutput\t rdempty;
+\toutput\t[10:0] rdusedw;
+\toutput\t wrfull;
+\toutput\t[10:0] wrusedw;
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: Width NUMERIC ""16""
+// Retrieval info: PRIVATE: Depth NUMERIC ""2048""
+// Retrieval info: PRIVATE: Clock NUMERIC ""4""
+// Retrieval info: PRIVATE: CLOCKS_ARE_SYNCHRONIZED NUMERIC ""0""
+// Retrieval info: PRIVATE: Full NUMERIC ""1""
+// Retrieval info: PRIVATE: Empty NUMERIC ""1""
+// Retrieval info: PRIVATE: UsedW NUMERIC ""1""
+// Retrieval info: PRIVATE: AlmostFull NUMERIC ""0""
+// Retrieval info: PRIVATE: AlmostEmpty NUMERIC ""0""
+// Retrieval info: PRIVATE: AlmostFullThr NUMERIC ""-1""
+// Retrieval info: PRIVATE: AlmostEmptyThr NUMERIC ""-1""
+// Retrieval info: PRIVATE: sc_aclr NUMERIC ""0""
+// Retrieval info: PRIVATE: sc_sclr NUMERIC ""0""
+// Retrieval info: PRIVATE: rsFull NUMERIC ""0""
+// Retrieval info: PRIVATE: rsEmpty NUMERIC ""1""
+// Retrieval info: PRIVATE: rsUsedW NUMERIC ""1""
+// Retrieval info: PRIVATE: wsFull NUMERIC ""1""
+// Retrieval info: PRIVATE: wsEmpty NUMERIC ""0""
+// Retrieval info: PRIVATE: wsUsedW NUMERIC ""1""
+// Retrieval info: PRIVATE: dc_aclr NUMERIC ""1""
+// Retrieval info: PRIVATE: LegacyRREQ NUMERIC ""0""
+// Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC ""0""
+// Retrieval info: PRIVATE: MAX_DEPTH_BY_9 NUMERIC ""0""
+// Retrieval info: PRIVATE: LE_BasedFIFO NUMERIC ""0""
+// Retrieval info: PRIVATE: Optimize NUMERIC ""2""
+// Retrieval info: PRIVATE: OVERFLOW_CHECKING NUMERIC ""1""
+// Retrieval info: PRIVATE: UNDERFLOW_CHECKING NUMERIC ""1""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: CONSTANT: LPM_WIDTH NUMERIC ""16""
+// Retrieval info: CONSTANT: LPM_NUMWORDS NUMERIC ""2048""
+// Retrieval info: CONSTANT: LPM_WIDTHU NUMERIC ""11""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: CONSTANT: CLOCKS_ARE_SYNCHRONIZED STRING ""FALSE""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""dcfifo""
+// Retrieval info: CONSTANT: LPM_SHOWAHEAD STRING ""ON""
+// Retrieval info: CONSTANT: OVERFLOW_CHECKING STRING ""OFF""
+// Retrieval info: CONSTANT: UNDERFLOW_CHECKING STRING ""OFF""
+// Retrieval info: CONSTANT: USE_EAB STRING ""ON""
+// Retrieval info: CONSTANT: ADD_RAM_OUTPUT_REGISTER STRING ""OFF""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: USED_PORT: data 0 0 16 0 INPUT NODEFVAL data[15..0]
+// Retrieval info: USED_PORT: q 0 0 16 0 OUTPUT NODEFVAL q[15..0]
+// Retrieval info: USED_PORT: wrreq 0 0 0 0 INPUT NODEFVAL wrreq
+// Retrieval info: USED_PORT: rdreq 0 0 0 0 INPUT NODEFVAL rdreq
+// Retrieval info: USED_PORT: rdclk 0 0 0 0 INPUT NODEFVAL rdclk
+// Retrieval info: USED_PORT: wrclk 0 0 0 0 INPUT NODEFVAL wrclk
+// Retrieval info: USED_PORT: rdempty 0 0 0 0 OUTPUT NODEFVAL rdempty
+// Retrieval info: USED_PORT: rdusedw 0 0 11 0 OUTPUT NODEFVAL rdusedw[10..0]
+// Retrieval info: USED_PORT: wrfull 0 0 0 0 OUTPUT NODEFVAL wrfull
+// Retrieval info: USED_PORT: wrusedw 0 0 11 0 OUTPUT NODEFVAL wrusedw[10..0]
+// Retrieval info: USED_PORT: aclr 0 0 0 0 INPUT GND aclr
+// Retrieval info: CONNECT: @data 0 0 16 0 data 0 0 16 0
+// Retrieval info: CONNECT: q 0 0 16 0 @q 0 0 16 0
+// Retrieval info: CONNECT: @wrreq 0 0 0 0 wrreq 0 0 0 0
+// Retrieval info: CONNECT: @rdreq 0 0 0 0 rdreq 0 0 0 0
+// Retrieval info: CONNECT: @rdclk 0 0 0 0 rdclk 0 0 0 0
+// Retrieval info: CONNECT: @wrclk 0 0 0 0 wrclk 0 0 0 0
+// Retrieval info: CONNECT: rdempty 0 0 0 0 @rdempty 0 0 0 0
+// Retrieval info: CONNECT: rdusedw 0 0 11 0 @rdusedw 0 0 11 0
+// Retrieval info: CONNECT: wrfull 0 0 0 0 @wrfull 0 0 0 0
+// Retrieval info: CONNECT: wrusedw 0 0 11 0 @wrusedw 0 0 11 0
+// Retrieval info: CONNECT: @aclr 0 0 0 0 aclr 0 0 0 0
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k_bb.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k_waveforms.html TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k_wave*.jpg FALSE
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+
+module cic_decim_tb;
+
+cic_decim #(.bitwidth(16),.stages(4))
+ decim(clock,reset,enable,strobe_in,strobe_out,signal_in,signal_out);
+\t
+ reg clock;
+ reg reset;
+ reg enable;
+ wire strobe;
+ reg [15:0] signal_in;
+ wire [15:0] signal_out;
+
+ assign strobe_in = 1\'b1;
+ reg \t strobe_out;
+
+ always @(posedge clock)
+ while(1)
+ begin
+\t @(posedge clock);
+\t @(posedge clock);
+\t @(posedge clock);
+\t @(posedge clock);
+\t strobe_out <= 1\'b1;
+\t @(posedge clock);
+\t @(posedge clock);
+\t @(posedge clock);
+\t @(posedge clock);
+\t strobe_out <= 1\'b0;
+ end
+
+ initial clock = 0;
+ always #50 clock = ~clock;
+
+ initial reset = 1;
+ initial #1000 reset = 0;
+
+ initial enable = 0;
+ initial #2000 enable = 1;
+
+ initial signal_in = 16\'h1;
+ initial #500000 signal_in = 16\'h7fff;
+ initial #1000000 signal_in = 16\'h8000;
+ initial #1500000 signal_in = 16\'hffff;
+
+
+ initial $dumpfile(""decim.vcd"");
+ initial $dumpvars(0,cic_decim_tb);
+
+ initial #10000000 $finish;
+
+endmodule // cic_decim_tb
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+
+// testbench for fullchip
+
+module decim_tb();
+
+`include ""usrp_tasks.v""
+
+\treg clk_120mhz;
+\treg usbclk;
+\treg reset;
+
+\treg [11:0] adc1_data, adc2_data;
+\twire [13:0] dac1_data, dac2_data;
+
+\twire [5:0] usbctl;
+\twire [5:0] usbrdy;
+
+\twire [15:0] usbdata;
+
+\treg WE, RD, OE;
+
+ assign usbctl[0] = WE;
+ assign usbctl[1] = RD;
+ assign usbctl[2] = OE;
+\tassign usbctl[5:3] = 0;
+
+\treg tb_oe;
+\tassign usbdata = tb_oe ? usbdatareg : 16\'hxxxx;
+\treg serload, serenable, serclk, serdata;
+\treg enable_tx, enable_rx;
+\treg [15:0] usbdatareg;
+
+///////////////////////////////////////////////
+// Simulation Control
+initial
+begin
+\t$dumpfile(""decim_tb.vcd"");
+\t$dumpvars(0, fc_tb);
+end
+
+initial #100000 $finish;
+
+///////////////////////////////////////////////
+// Monitors
+
+reg [7:0] counter_decim;
+wire [7:0] decim_rate;
+assign decim_rate = 32;
+initial $monitor(dac1_data);
+
+ always @(posedge clk_120mhz)
+ begin
+ if(reset | ~enable_tx)
+ counter_decim <= #1 0;
+ else if(counter_decim == 0)
+ counter_decim <= #1 decim_rate - 8\'b1;
+ else
+ counter_decim <= #1 counter_decim - 8\'b1;
+ end
+
+///////////////////////////////////////////////
+// Clock and reset
+
+initial clk_120mhz = 0;
+initial usbclk = 0;
+always #48 clk_120mhz = ~clk_120mhz;
+always #120 usbclk = ~usbclk;
+
+initial reset = 1\'b1;
+initial #500 reset = 1\'b0;
+
+
+initial enable_tx = 1\'b1;
+
+\twire [31:0] decim_out, q_decim_out;
+\twire [31:0] decim_out;
+\twire [31:0] phase;
+\t\t\t
+\tcic_decim #(.bitwidth(32),.stages(4))
+\t\tdecim_i(.clock(clk_120mhz),.reset(reset),.enable(enable_tx),
+\t\t\t.strobe(counter_decim == 8\'b0),.signal_in(32\'h1),.signal_out(decim_out));
+
+\tcic_decim #(.bitwidth(32),.stages(4))
+\t\tdecim(.clock(clk_120mhz),.reset(reset),.enable(enable_tx),
+\t\t\t.strobe(counter_decim == 8\'b0),.signal_in(32\'h1),.signal_out(decim_out));
+\t\t\t
+endmodule
+"
+"
+
+module rx_dcoffset (input clock, input enable, input reset,
+\t\t input signed [15:0] adc_in, output signed [15:0] adc_out,
+\t\t input wire [6:0] serial_addr, input wire [31:0] serial_data, input serial_strobe);
+ parameter \t\t MYADDR = 0;
+
+ reg signed [31:0] \t\t integrator;
+ wire signed [15:0] \t\t scaled_integrator = integrator[31:16] + (integrator[31] & |integrator[15:0]);
+ assign \t\t\t adc_out = adc_in - scaled_integrator;
+
+ // FIXME do we need signed?
+ //FIXME What do we do when clipping?
+ always @(posedge clock)
+ if(reset)
+ integrator <= #1 32'd0;
+ else if(serial_strobe & (MYADDR == serial_addr))
+ integrator <= #1 {serial_data[15:0],16'd0};
+ else if(enable)
+ integrator <= #1 integrator + adc_out;
+
+endmodule // rx_dcoffset
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2007 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+`include ""../top/config.vh""
+
+module dac_interface(clk_i,rst_i,ena_i,strobe_i,tx_i_i,tx_q_i,tx_data_o,tx_sync_o);
+ input clk_i;
+ input rst_i;
+ input ena_i;
+ input strobe_i;
+
+ input [13:0] tx_i_i;
+ input [13:0] tx_q_i;
+
+ output [13:0] tx_data_o;
+ output \t tx_sync_o;
+
+`ifdef TX_RATE_MAX
+ wire clk128;
+ reg clk64_d;
+ reg [13:0] tx_data_o;
+
+ // Create a 128 MHz clock
+ dacpll pll128(.areset(rst_i),.inclk0(clk_i),.c0(clk128));
+
+ // Register the clk64 clock in the clk128 domain
+ always @(posedge clk128)
+ clk64_d <= #1 clk_i;
+
+ // Register the tx data in the clk128 domain
+ always @(posedge clk128)
+ tx_data_o <= #1 clk64_d ? tx_i_i : tx_q_i;
+
+ assign tx_sync_o = clk64_d;
+
+
+`else // !`ifdef TX_RATE_MAX
+ assign tx_data_o = strobe_i ? tx_q_i : tx_i_i;
+ assign tx_sync_o = strobe_i;
+`endif // !`ifdef TX_RATE_MAX
+
+endmodule // dac_interface
+"
+"//Copyright (C) 1991-2004 Altera Corporation
+//Any megafunction design, and related netlist (encrypted or decrypted),
+//support information, device programming or simulation file, and any other
+//associated documentation or information provided by Altera or a partner
+//under Altera's Megafunction Partnership Program may be used only
+//to program PLD devices (but not masked PLD devices) from Altera. Any
+//other use of such megafunction design, netlist, support information,
+//device programming or simulation file, or any other related documentation
+//or information is prohibited for any other purpose, including, but not
+//limited to modification, reverse engineering, de-compiling, or use with
+//any other silicon devices, unless such use is explicitly licensed under
+//a separate agreement with Altera or a megafunction partner. Title to the
+//intellectual property, including patents, copyrights, trademarks, trade
+//secrets, or maskworks, embodied in any such megafunction design, netlist,
+//support information, device programming or simulation file, or any other
+//related documentation or information provided by Altera or a megafunction
+//partner, remains with Altera, the megafunction partner, or their respective
+//licensors. No other licenses, including any licenses needed under any third
+//party's intellectual property, are provided herein.
+
+module dspclkpll (
+\tinclk0,
+\tc0,
+\tc1);
+
+\tinput\t inclk0;
+\toutput\t c0;
+\toutput\t c1;
+
+endmodule
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2007 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+`timescale 1ns/1ps
+
+`include ""../lib/radar.v""
+
+module radar_tb;
+
+ // System bus
+ reg clk;
+ reg rst;
+ reg ena;
+
+ // Configuration bus
+ reg [6:0] saddr;
+ reg [31:0] sdata;
+ reg \t s_strobe;
+
+ // DAC bus
+ wire tx_strobe;
+ wire [13:0] tx_dac_i;
+ wire [13:0] tx_dac_q;
+
+ // ADC bus
+ reg [15:0] rx_adc_i;
+ reg [15:0] rx_adc_q;
+
+ // FIFO bus
+ wire fifo_strobe;
+ wire [15:0] fifo_i;
+ wire [15:0] fifo_q;
+
+ // Configuration shadow registers
+ reg [31:0] mode;
+
+ radar uut
+ (.clk_i(clk),.saddr_i(saddr),.sdata_i(sdata),.s_strobe_i(s_strobe),
+ .tx_strobe_o(tx_strobe),.tx_dac_i_o(tx_dac_i),.tx_dac_q_o(tx_dac_q),
+ .rx_adc_i_i(rx_adc_i),.rx_adc_q_i(rx_adc_q),
+ .rx_strobe_o(fifo_strobe),.rx_ech_i_o(fifo_i),.rx_ech_q_o(fifo_q));
+
+ // Start up initialization
+ initial
+ begin
+\tclk = 0;
+\trst = 0;
+\tena = 0;
+\tsaddr = 0;
+\tsdata = 0;
+\ts_strobe = 0;
+\trx_adc_i = 0;
+\trx_adc_q = 0;
+\tmode = 0;
+\t
+\t@(posedge clk);
+\trst = 1;
+\t@(posedge clk);
+\trst = 0;
+\t@(posedge clk);
+\tena = 1;
+ end
+
+ always
+ #5 clk <= ~clk;
+
+ initial
+ begin
+\t//$monitor($time, "" clk=%b rst=%b"", clk, uut.reset);
+\t
+\t$dumpfile(""radar_tb.vcd"");
+\t$dumpvars(0, radar_tb);
+ end
+
+ // Test tasks
+ task write_cfg_register;
+ input [6:0] regno;
+ input [31:0] value;
+
+ begin
+\t @(posedge clk);
+\t saddr <= regno;
+\t sdata <= value;
+\t s_strobe <= 1\'b1;
+\t @(posedge clk);
+\t s_strobe <= 0;
+ end
+ endtask // write_cfg_register
+
+ // Application reset line
+ task set_reset;
+ input reset;
+
+ begin
+\t mode = reset ? (mode | `bmFR_RADAR_MODE_RESET) : (mode & ~`bmFR_RADAR_MODE_RESET);
+\t write_cfg_register(`FR_RADAR_MODE, mode);
+ end
+ endtask // reset
+
+ // Waveform on time
+ task set_ton;
+ input [23:0] t_on;
+
+ begin
+\t write_cfg_register(`FR_RADAR_TON, t_on);
+ end
+ endtask // set_ton
+
+ // Transmitter switching time
+ task set_tsw;
+ input [23:0] t_sw;
+
+ begin
+\t write_cfg_register(`FR_RADAR_TSW, t_sw);
+ end
+ endtask // t_sw
+
+ // Receiver look time
+ task set_tlook;
+ input [23:0] t_look;
+
+ begin
+\t write_cfg_register(`FR_RADAR_TLOOK, t_look);
+ end
+ endtask // set_tlook
+
+ // Inter-pulse idle time
+ task set_tidle;
+ input [23:0] t_idle;
+
+ begin
+\t write_cfg_register(`FR_RADAR_TIDLE, t_idle);
+ end
+ endtask // set_tidle
+
+ // Chirp amplitude
+ task set_ampl;
+ input [31:0] ampl;
+
+ begin
+\t write_cfg_register(`FR_RADAR_AMPL, ampl);
+ end
+ endtask // set_ampl
+
+ // Chirp start frequency
+ task set_fstart;
+ input [31:0] fstart;
+
+ begin
+\t write_cfg_register(`FR_RADAR_FSTART, fstart);
+ end
+ endtask // set_fstart
+
+ // Chirp frequency increment
+ task set_fincr;
+ input [31:0] fincr;
+
+ begin
+\t write_cfg_register(`FR_RADAR_FINCR, fincr);
+ end
+ endtask // set_fincr
+
+ // Chirp frequency increment
+ task set_atrdel;
+ input [31:0] atrdel;
+
+ begin
+\t write_cfg_register(`FR_RADAR_ATRDEL, atrdel);
+ end
+ endtask // set_fincr
+
+ // Test transmitter functionality
+ task test_tx;
+ begin
+\t #20 set_reset(1);
+
+\t #20 set_ton(320-1);\t// 5us on time
+\t #20 set_tsw(26-1);\t// 406ns switching time
+\t #20 set_tlook(640-1); // 10us look time
+\t #20 set_tidle(2854-1); // 60us pulse period
+\t
+\t #20 set_ampl(16\'d9946);
+\t #20 set_fstart(32\'h80000000); // -16 to 16 MHz
+\t #20 set_fincr (32\'h0199999A);
+\t #20 set_atrdel(32\'h00400046); // 64 TX clks, 70 RX clks\t
+\t #20 set_reset(0);
+\t #200000;
+ end
+ endtask // test_tx
+
+ // Execute tests
+ initial
+ begin
+ #20 test_tx;
+\t#100 $finish;
+ end
+endmodule
+"
+"
+
+module mrfm_compensator (input clock, input reset, input strobe_in,
+\t\t\t input serial_strobe, input [6:0] serial_addr, input [31:0] serial_data,
+\t\t\t input [15:0] i_in, input [15:0] q_in, output reg [15:0] i_out, output reg [15:0] q_out);
+
+ wire [15:0] \t\t\t a11,a12,a21,a22;
+ reg [15:0] \t\t\t i_in_reg, q_in_reg;
+ wire [30:0] \t\t\t product;
+ reg [3:0] \t\t\t phase;
+ wire [15:0] \t\t\t data,coeff;
+ wire [7:0] \t\t\t shift;
+ wire [33:0] \t\t\t accum;
+ wire [15:0] \t\t\t scaled_accum;
+ wire enable_acc;
+
+ setting_reg #(`FR_MRFM_COMP_A11) sr_a11(.clock(clock),.reset(reset),
+\t\t\t\t\t .strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
+\t\t\t\t\t .out(a11),.changed());
+ setting_reg #(`FR_MRFM_COMP_A12) sr_a12(.clock(clock),.reset(reset),
+\t\t\t\t\t .strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
+\t\t\t\t\t .out(a12),.changed());
+ setting_reg #(`FR_MRFM_COMP_A21) sr_a21(.clock(clock),.reset(reset),
+\t\t\t\t\t .strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
+\t\t\t\t\t .out(a21),.changed());
+ setting_reg #(`FR_MRFM_COMP_A22) sr_a22(.clock(clock),.reset(reset),
+\t\t\t\t\t .strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
+\t\t\t\t\t .out(a22),.changed());
+ setting_reg #(`FR_MRFM_COMP_SHIFT) sr_cshift(.clock(clock),.reset(reset),
+\t\t\t\t\t\t.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
+\t\t\t\t\t\t.out(shift),.changed());
+
+ mult mult (.clock(clock),.x(data),.y(coeff),.product(product),.enable_in(1'b1),.enable_out() );
+ acc acc (.clock(clock),.reset(reset),.clear(clear_acc),.enable_in(enable_acc),.enable_out(),
+\t .addend(product),.sum(accum) );
+ shifter shifter (.in(accum),.out(scaled_accum),.shift(shift));
+
+ always @(posedge clock)
+ if(reset)
+ begin
+\t i_in_reg <= #1 16'd0;
+\t q_in_reg <= #1 16'd0;
+ end
+ else if(strobe_in)
+ begin
+\t i_in_reg <= #1 i_in;
+\t q_in_reg <= #1 q_in;
+ end\t
+
+ always @(posedge clock)
+ if(reset)
+ phase <= #1 4'd0;
+ else if(strobe_in)
+ phase <= #1 4'd1;
+ else if(strobe_in != 4'd8)
+ phase <= #1 phase + 4'd1;
+
+ assign data = ((phase == 4'd1)||(phase === 4'd4)) ? i_in_reg :
+\t ((phase == 4'd2)||(phase == 4'd5)) ? q_in_reg : 16'd0;
+
+ assign coeff = (phase == 4'd1) ? a11 : (phase == 4'd2) ? a12 :
+\t (phase == 4'd4) ? a21 : (phase == 4'd5) ? a22 : 16'd0;
+
+ assign clear_acc = (phase == 4'd0) || (phase == 4'd1) || (phase == 4'd4) || (phase==4'd8);
+ assign enable_acc = ~clear_acc;
+
+ always @(posedge clock)
+ if(reset)
+ i_out <= #1 16'd0;
+ else if(phase == 4'd4)
+ i_out <= #1 scaled_accum;
+
+ always @(posedge clock)
+ if(reset)
+ q_out <= #1 16'd0;
+ else if(phase == 4'd7)
+ q_out <= #1 scaled_accum;
+
+
+endmodule // mrfm_compensator
+"
+"
+
+module fifo_4k
+ ( input [15:0] data,
+ input \twrreq,
+ input \trdreq,
+ input \trdclk,
+ input \twrclk,
+ input \taclr,
+ output [15:0] q,
+ output \t rdfull,
+ output \t rdempty,
+ output [11:0] rdusedw,
+ output \t wrfull,
+ output \t wrempty,
+ output [11:0] wrusedw
+ );
+
+fifo #(.width(16),.depth(4096),.addr_bits(12)) fifo_4k
+ ( data, wrreq, rdreq, rdclk, wrclk, aclr, q,
+ rdfull, rdempty, rdusedw, wrfull, wrempty, wrusedw);
+
+endmodule // fifo_1k
+
+"
+"
+// Model for tristate bus on altera
+// FIXME do we really need to use a megacell for this?
+
+module bustri (data,
+\t enabledt,
+\t tridata);
+
+ input [15:0] data;
+ input \t enabledt;
+ inout [15:0] tridata;
+
+ assign \t tridata = enabledt ? data :16'bz;
+
+endmodule // bustri
+
+
+"
+"
+// Model of Pipelined [ZBT] Synchronous SRAM
+
+module ssram(clock,addr,data,wen,ce);
+ parameter addrbits = 19;
+ parameter depth = 524288;
+
+ input clock;
+ input [addrbits-1:0] addr;
+ inout [35:0] data;
+ input wen;
+ input ce;
+
+ reg [35:0] ram [0:depth-1];
+
+ reg read_d1,read_d2;
+ reg write_d1,write_d2;
+ reg [addrbits-1:0] addr_d1,addr_d2;
+
+ always @(posedge clock)
+ begin
+\tread_d1 <= #1 ce & ~wen;
+\twrite_d1 <= #1 ce & wen;
+\taddr_d1 <= #1 addr;
+\tread_d2 <= #1 read_d1;
+\twrite_d2 <= #1 write_d1;
+\taddr_d2 <= #1 addr_d1;
+\tif(write_d2)
+\t ram[addr_d2] = data;
+ end // always @ (posedge clock)
+
+ data = (ce & read_d2) ? ram[addr_d2] : 36\'bz;
+
+ always @(posedge clock)
+ if(~ce & (write_d2 | write_d1 | wen))
+ $display(""$time ERROR: RAM CE not asserted during write cycle"");
+
+endmodule // ssram
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+module tx_chain_hb
+ (input clock,
+ input reset,
+ input enable,
+ input wire [7:0] interp_rate,
+ input sample_strobe,
+ input interpolator_strobe,
+ input hb_strobe,
+ input wire [31:0] freq,
+ input wire [15:0] i_in,
+ input wire [15:0] q_in,
+ output wire [15:0] i_out,
+ output wire [15:0] q_out,
+output wire [15:0] debug, output [15:0] hb_i_out
+ );
+assign debug[15:13] = {sample_strobe,hb_strobe,interpolator_strobe};
+
+ wire [15:0] bb_i, bb_q;
+ wire [15:0] hb_i_out, hb_q_out;
+
+ halfband_interp hb
+ (.clock(clock),.reset(reset),.enable(enable),
+ .strobe_in(interpolator_strobe),.strobe_out(hb_strobe),
+ .signal_in_i(i_in),.signal_in_q(q_in),
+ .signal_out_i(hb_i_out),.signal_out_q(hb_q_out),
+\t.debug(debug[12:0]));
+
+ cic_interp cic_interp_i
+ ( .clock(clock),.reset(reset),.enable(enable),
+ .rate(interp_rate),.strobe_in(hb_strobe),.strobe_out(sample_strobe),
+ .signal_in(hb_i_out),.signal_out(bb_i) );
+
+ cic_interp cic_interp_q
+ ( .clock(clock),.reset(reset),.enable(enable),
+ .rate(interp_rate),.strobe_in(hb_strobe),.strobe_out(sample_strobe),
+ .signal_in(hb_q_out),.signal_out(bb_q) );
+
+`define NOCORDIC_TX
+`ifdef NOCORDIC_TX
+ assign i_out = bb_i;
+ assign q_out = bb_q;
+`else
+ wire [31:0] phase;
+
+ phase_acc phase_acc_tx
+ (.clk(clock),.reset(reset),.enable(enable),
+ .strobe(sample_strobe),.freq(freq),.phase(phase) );
+
+ cordic tx_cordic_0
+ ( .clock(clock),.reset(reset),.enable(sample_strobe),
+ .xi(bb_i),.yi(bb_q),.zi(phase[31:16]),
+ .xo(i_out),.yo(q_out),.zo() );
+`endif
+
+endmodule // tx_chain
+"
+"// Bidirectional registers
+
+module bidir_reg
+ ( inout wire [15:0] tristate,
+ input wire [15:0] oe,
+ input wire [15:0] reg_val );
+
+ // This would be much cleaner if all the tools
+ // supported ""for generate""........
+
+ assign \t tristate[0] = oe[0] ? reg_val[0] : 1\'bz;
+ assign \t tristate[1] = oe[1] ? reg_val[1] : 1\'bz;
+ assign \t tristate[2] = oe[2] ? reg_val[2] : 1\'bz;
+ assign \t tristate[3] = oe[3] ? reg_val[3] : 1\'bz;
+ assign \t tristate[4] = oe[4] ? reg_val[4] : 1\'bz;
+ assign \t tristate[5] = oe[5] ? reg_val[5] : 1\'bz;
+ assign \t tristate[6] = oe[6] ? reg_val[6] : 1\'bz;
+ assign \t tristate[7] = oe[7] ? reg_val[7] : 1\'bz;
+ assign \t tristate[8] = oe[8] ? reg_val[8] : 1\'bz;
+ assign \t tristate[9] = oe[9] ? reg_val[9] : 1\'bz;
+ assign \t tristate[10] = oe[10] ? reg_val[10] : 1\'bz;
+ assign \t tristate[11] = oe[11] ? reg_val[11] : 1\'bz;
+ assign \t tristate[12] = oe[12] ? reg_val[12] : 1\'bz;
+ assign \t tristate[13] = oe[13] ? reg_val[13] : 1\'bz;
+ assign \t tristate[14] = oe[14] ? reg_val[14] : 1\'bz;
+ assign \t tristate[15] = oe[15] ? reg_val[15] : 1\'bz;
+
+endmodule // bidir_reg
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+
+// NOTE This only works for N=4, max interp rate of 128
+// NOTE signal ""rate"" is ONE LESS THAN the actual rate
+
+module cic_int_shifter(rate,signal_in,signal_out);
+ parameter bw = 16;
+ parameter maxbitgain = 21;
+
+ input [7:0] rate;
+ input wire [bw+maxbitgain-1:0] signal_in;
+ output reg [bw-1:0] signal_out;
+
+ function [4:0] bitgain;
+ input [7:0] rate;
+ case(rate)
+\t// Exact Cases
+\t8\'d4 : bitgain = 6;
+\t8\'d8 : bitgain = 9;
+\t8\'d16 : bitgain = 12;
+\t8\'d32 : bitgain = 15;
+\t8\'d64 : bitgain = 18;
+\t8\'d128 : bitgain = 21;
+\t
+\t// Nearest without overflow
+\t8\'d5 : bitgain = 7;
+\t8\'d6 : bitgain = 8;
+\t8\'d7 : bitgain = 9;
+\t8\'d9,8\'d10 : bitgain = 10;
+\t8\'d11,8\'d12 : bitgain = 11;
+\t8\'d13,8\'d14,8\'d15 : bitgain = 12;
+\t8\'d17,8\'d18,8\'d19,8\'d20 : bitgain = 13;
+\t8\'d21,8\'d22,8\'d23,8\'d24,8\'d25 : bitgain = 14;
+\t8\'d26,8\'d27,8\'d28,8\'d29,8\'d30,8\'d31 : bitgain = 15;
+\t8\'d33,8\'d34,8\'d35,8\'d36,8\'d37,8\'d38,8\'d39,8\'d40 : bitgain = 16;
+\t8\'d41,8\'d42,8\'d43,8\'d44,8\'d45,8\'d46,8\'d47,8\'d48,8\'d49,8\'d50 : bitgain = 17;
+\t8\'d51,8\'d52,8\'d53,8\'d54,8\'d55,8\'d56,8\'d57,8\'d58,8\'d59,8\'d60,8\'d61,8\'d62,8\'d63 : bitgain = 18;
+\t8\'d65,8\'d66,8\'d67,8\'d68,8\'d69,8\'d70,8\'d71,8\'d72,8\'d73,8\'d74,8\'d75,8\'d76,8\'d77,8\'d78,8\'d79,8\'d80 : bitgain = 19;
+\t8\'d81,8\'d82,8\'d83,8\'d84,8\'d85,8\'d86,8\'d87,8\'d88,8\'d89,8\'d90,8\'d91,8\'d92,8\'d93,8\'d94,8\'d95,8\'d96,8\'d97,8\'d98,8\'d99,8\'d100,8\'d101 : bitgain = 20;
+\t
+\tdefault : bitgain = 21;
+ endcase // case(rate)
+ endfunction // bitgain
+
+ wire [4:0] \t shift = bitgain(rate+1);
+
+ // We should be able to do this, but can\'t ....
+ // assign \t signal_out = signal_in[shift+bw-1:shift];
+
+ always @*
+ case(shift)
+ 5\'d6 : signal_out = signal_in[6+bw-1:6];
+ 5\'d9 : signal_out = signal_in[9+bw-1:9];
+ 5\'d12 : signal_out = signal_in[12+bw-1:12];
+ 5\'d15 : signal_out = signal_in[15+bw-1:15];
+ 5\'d18 : signal_out = signal_in[18+bw-1:18];
+ 5\'d21 : signal_out = signal_in[21+bw-1:21];
+
+ 5\'d7 : signal_out = signal_in[7+bw-1:7];
+ 5\'d8 : signal_out = signal_in[8+bw-1:8];
+ 5\'d10 : signal_out = signal_in[10+bw-1:10];
+ 5\'d11 : signal_out = signal_in[11+bw-1:11];
+ 5\'d13 : signal_out = signal_in[13+bw-1:13];
+ 5\'d14 : signal_out = signal_in[14+bw-1:14];
+ 5\'d16 : signal_out = signal_in[16+bw-1:16];
+ 5\'d17 : signal_out = signal_in[17+bw-1:17];
+ 5\'d19 : signal_out = signal_in[19+bw-1:19];
+ 5\'d20 : signal_out = signal_in[20+bw-1:20];
+
+ default : signal_out = signal_in[21+bw-1:21];
+ endcase // case(shift)
+
+endmodule // cic_int_shifter
+
+"
+"
+
+module mult (input clock, input signed [15:0] x, input signed [15:0] y, output reg signed [30:0] product,
+\t input enable_in, output reg enable_out );
+
+ always @(posedge clock)
+ if(enable_in)
+ product <= #1 x*y;
+ else
+ product <= #1 31'd0;
+
+ always @(posedge clock)
+ enable_out <= #1 enable_in;
+
+endmodule // mult
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+// Copyright (C) 2008 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+
+// NOTE: This only works for a max decim rate of 256
+// NOTE: Signal ""rate"" is ONE LESS THAN the actual rate
+
+module integ_shifter(rate,signal_in,signal_out);
+ parameter bw = 16;
+ parameter maxbitgain = 8;
+
+ input [7:0] rate;
+ input wire [bw+maxbitgain-1:0] signal_in;
+ output reg [bw-1:0] signal_out;
+
+ reg [3:0] bitgain;
+
+ // Nearest without overflow -- ceil(log2(rate+1))
+ always @*
+ if (rate >= 8\'d128)
+ bitgain = 8;
+ else if (rate >= 8\'d64)
+ bitgain = 7;
+ else if (rate >= 8\'d32)
+ bitgain = 6;
+ else if (rate >= 8\'d16)
+ bitgain = 5;
+ else if (rate >= 8\'d8)
+ bitgain = 4;
+ else if (rate >= 8\'d4)
+ bitgain = 3;
+ else if (rate >= 8\'d2)
+ bitgain = 2;
+ else
+ bitgain = 1;
+
+ always @*
+ case(bitgain)
+ 5\'d1 : signal_out = signal_in[1+bw-1:1];
+ 5\'d2 : signal_out = signal_in[2+bw-1:2];
+ 5\'d3 : signal_out = signal_in[3+bw-1:3];
+ 5\'d4 : signal_out = signal_in[4+bw-1:4];
+ 5\'d5 : signal_out = signal_in[5+bw-1:5];
+ 5\'d6 : signal_out = signal_in[6+bw-1:6];
+ 5\'d7 : signal_out = signal_in[7+bw-1:7];
+ default : signal_out = signal_in[8+bw-1:8];
+ endcase // case(shift)
+
+endmodule // integ_shifter
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+// Interface to Cypress FX2 bus
+// A packet is 512 Bytes, the fifo has 4096 lines of 18 bits each
+
+`include ""../../firmware/include/fpga_regs_common.v""
+`include ""../../firmware/include/fpga_regs_standard.v""
+
+module rx_buffer
+ ( // Read/USB side
+ input usbclk,
+ input bus_reset,
+ output [15:0] usbdata,
+ input RD,
+ output reg have_pkt_rdy,
+ output reg rx_overrun,
+ input clear_status,
+ // Write/DSP side
+ input rxclk,
+ input reset, // DSP side reset (used here), do not reset registers
+ input rxstrobe,
+ input wire [3:0] channels,
+ input wire [15:0] ch_0,
+ input wire [15:0] ch_1,
+ input wire [15:0] ch_2,
+ input wire [15:0] ch_3,
+ input wire [15:0] ch_4,
+ input wire [15:0] ch_5,
+ input wire [15:0] ch_6,
+ input wire [15:0] ch_7,
+ // Settings, on rxclk also
+ input [6:0] serial_addr, input [31:0] serial_data, input serial_strobe,
+ input reset_regs, //Only reset registers
+ output [31:0] debugbus
+ );
+
+ wire [15:0] \t fifodata, fifodata_8;
+ reg [15:0] \t fifodata_16;
+
+ wire [11:0] \t rxfifolevel;
+ wire \t rx_full;
+
+ wire \t bypass_hb, want_q;
+ wire [4:0] \t bitwidth;
+ wire [3:0] \t bitshift;
+
+ setting_reg #(`FR_RX_FORMAT) sr_rxformat(.clock(rxclk),.reset(reset_regs),
+\t\t\t\t\t .strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
+\t\t\t\t\t .out({bypass_hb,want_q,bitwidth,bitshift}));
+
+ // USB Read Side of FIFO
+ always @(negedge usbclk)
+ have_pkt_rdy <= (rxfifolevel >= 256);
+
+ // 257 Bug Fix
+ reg [8:0] \t read_count;
+ always @(negedge usbclk)
+ if(bus_reset)
+ read_count <= 0;
+ else if(RD)
+ read_count <= read_count + 1;
+ else
+ read_count <= 0;
+
+ // FIFO
+ wire \t ch0_in, ch0_out, iq_out;
+ assign \t ch0_in = (phase == 1);
+
+ fifo_4k_18 rxfifo
+ ( // DSP Write Side
+ .data ( {ch0_in, phase[0], fifodata} ),
+ .wrreq (~rx_full & (phase != 0)),
+ .wrclk ( rxclk ),
+ .wrfull ( rx_full ),
+ .wrempty ( ),
+ .wrusedw ( ),
+ // USB Read Side
+ .q ( {ch0_out,iq_out,usbdata} ),
+ .rdreq ( RD & ~read_count[8] ),
+ .rdclk ( ~usbclk ),
+ .rdfull ( ),
+ .rdempty ( ),
+ .rdusedw ( rxfifolevel ),
+ // Async, shared
+ .aclr ( reset ) );
+
+ // DSP Write Side of FIFO
+ reg [15:0] ch_0_reg;
+ reg [15:0] ch_1_reg;
+ reg [15:0] ch_2_reg;
+ reg [15:0] ch_3_reg;
+ reg [15:0] ch_4_reg;
+ reg [15:0] ch_5_reg;
+ reg [15:0] ch_6_reg;
+ reg [15:0] ch_7_reg;
+
+ always @(posedge rxclk)
+ if (rxstrobe)
+ begin
+ ch_0_reg <= ch_0;
+ ch_1_reg <= ch_1;
+ ch_2_reg <= ch_2;
+ ch_3_reg <= ch_3;
+ ch_4_reg <= ch_4;
+ ch_5_reg <= ch_5;
+ ch_6_reg <= ch_6;
+ ch_7_reg <= ch_7;
+ end
+
+ reg [3:0] phase;
+ always @(posedge rxclk)
+ if(reset)
+ phase <= 4\'d0;
+ else if(phase == 0)
+ begin
+\t if(rxstrobe)
+\t phase <= 4\'d1;
+ end
+ else if(~rx_full)
+ if(phase == ((bitwidth == 5\'d8) ? (channels>>1) : channels))
+\t phase <= 4\'d0;
+ else
+\t phase <= phase + 4\'d1;
+
+ assign fifodata = (bitwidth == 5\'d8) ? fifodata_8 : fifodata_16;
+
+ assign fifodata_8 = {round_8(top),round_8(bottom)};
+ reg [15:0] top,bottom;
+
+ function [7:0] round_8;
+ input [15:0] in_val;
+
+ round_8 = in_val[15:8] + (in_val[15] & |in_val[7:0]);
+ endfunction // round_8
+
+ always @*
+ case(phase)
+ 4\'d1 : begin
+\t bottom = ch_0_reg;
+\t top = ch_1_reg;
+ end
+ 4\'d2 : begin
+\t bottom = ch_2_reg;
+\t top = ch_3_reg;
+ end
+ 4\'d3 : begin
+\t bottom = ch_4_reg;
+\t top = ch_5_reg;
+ end
+ 4\'d4 : begin
+\t bottom = ch_6_reg;
+\t top = ch_7_reg;
+ end
+ default : begin
+\t top = 16\'hFFFF;
+\t bottom = 16\'hFFFF;
+ end
+ endcase // case(phase)
+
+ always @*
+ case(phase)
+ 4\'d1 : fifodata_16 = ch_0_reg;
+ 4\'d2 : fifodata_16 = ch_1_reg;
+ 4\'d3 : fifodata_16 = ch_2_reg;
+ 4\'d4 : fifodata_16 = ch_3_reg;
+ 4\'d5 : fifodata_16 = ch_4_reg;
+ 4\'d6 : fifodata_16 = ch_5_reg;
+ 4\'d7 : fifodata_16 = ch_6_reg;
+ 4\'d8 : fifodata_16 = ch_7_reg;
+ default : fifodata_16 = 16\'hFFFF;
+ endcase // case(phase)
+
+ // Detect overrun
+ reg clear_status_dsp, rx_overrun_dsp;
+ always @(posedge rxclk)
+ clear_status_dsp <= clear_status;
+
+ always @(negedge usbclk)
+ rx_overrun <= rx_overrun_dsp;
+
+ always @(posedge rxclk)
+ if(reset)
+ rx_overrun_dsp <= 1\'b0;
+ else if(rxstrobe & (phase != 0))
+ rx_overrun_dsp <= 1\'b1;
+ else if(clear_status_dsp)
+ rx_overrun_dsp <= 1\'b0;
+
+ // Debug bus
+ //
+ // 15:0 rxclk domain => TXA 15:0
+ // 31:16 usbclk domain => RXA 15:0
+
+ assign debugbus[0] = reset;
+ assign debugbus[1] = reset_regs;
+ assign debugbus[2] = rxstrobe;
+ assign debugbus[6:3] = channels;
+ assign debugbus[7] = rx_full;
+ assign debugbus[11:8] = phase;
+ assign debugbus[12] = ch0_in;
+ assign debugbus[13] = clear_status_dsp;
+ assign debugbus[14] = rx_overrun_dsp;
+ assign debugbus[15] = rxclk;
+
+ assign debugbus[16] = bus_reset;
+ assign debugbus[17] = RD;
+ assign debugbus[18] = have_pkt_rdy;
+ assign debugbus[19] = rx_overrun;
+ assign debugbus[20] = read_count[0];
+ assign debugbus[21] = read_count[8];
+ assign debugbus[22] = ch0_out;
+ assign debugbus[23] = iq_out;
+ assign debugbus[24] = clear_status;
+ assign debugbus[30:25] = 0;
+ assign debugbus[31] = usbclk;
+
+endmodule // rx_buffer
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2006 Martin Dudok van Heel
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+`include ""config.vh""
+`include ""../../../firmware/include/fpga_regs_common.v""
+`include ""../../../firmware/include/fpga_regs_standard.v""
+// Clock, enable, and reset controls for whole system
+// Modified version to enable multi_usrp synchronisation
+
+module master_control_multi
+ ( input master_clk, input usbclk,
+ input wire [6:0] serial_addr, input wire [31:0] serial_data, input wire serial_strobe,
+ input wire rx_slave_sync,
+ output tx_bus_reset, output rx_bus_reset,
+ output wire tx_dsp_reset, output wire rx_dsp_reset,
+ output wire enable_tx, output wire enable_rx,
+ output wire sync_rx,
+ output wire [7:0] interp_rate, output wire [7:0] decim_rate,
+ output tx_sample_strobe, output strobe_interp,
+ output rx_sample_strobe, output strobe_decim,
+ input tx_empty,
+ input wire [15:0] debug_0,input wire [15:0] debug_1,input wire [15:0] debug_2,input wire [15:0] debug_3,
+ output wire [15:0] reg_0, output wire [15:0] reg_1, output wire [15:0] reg_2, output wire [15:0] reg_3
+ );
+
+ wire [15:0] reg_1_std;
+
+ master_control master_control_standard
+ ( .master_clk(master_clk),.usbclk(usbclk),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .tx_bus_reset(tx_bus_reset),.rx_bus_reset(rx_bus_reset),
+ .tx_dsp_reset(tx_dsp_reset),.rx_dsp_reset(rx_dsp_reset),
+ .enable_tx(enable_tx),.enable_rx(enable_rx),
+ .interp_rate(interp_rate),.decim_rate(decim_rate),
+ .tx_sample_strobe(tx_sample_strobe),.strobe_interp(strobe_interp),
+ .rx_sample_strobe(rx_sample_strobe),.strobe_decim(strobe_decim),
+ .tx_empty(tx_empty),
+ .debug_0(debug_0),.debug_1(debug_1),
+ .debug_2(debug_2),.debug_3(debug_3),
+ .reg_0(reg_0),.reg_1(reg_1_std),.reg_2(reg_2),.reg_3(reg_3) );
+
+ // FIXME need a separate reset for all control settings
+ // Master/slave Controls assignments
+ wire [7:0] rx_master_slave_controls;
+ setting_reg_masked #(`FR_RX_MASTER_SLAVE) sr_rx_mstr_slv_ctrl(.clock(master_clk),.reset(1\'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(rx_master_slave_controls));
+
+ assign sync_rx = rx_master_slave_controls[`bitnoFR_RX_SYNC] | (rx_master_slave_controls[`bitnoFR_RX_SYNC_SLAVE] & rx_slave_sync);
+ //sync if we are told by master_control or if we get a hardware slave sync
+ //TODO There can be a one sample difference between master and slave sync.
+ // Maybe use a register for sync_rx which uses the (neg or pos) edge of master_clock and/or rx_slave_sync to trigger
+ // Or even use a seperate sync_rx_out and sync_rx_internal (which lags behind)
+ //TODO make output pin not hardwired
+assign reg_1 ={(rx_master_slave_controls[`bitnoFR_RX_SYNC_MASTER])? sync_rx:reg_1_std[15],reg_1_std[14:0]};
+
+
+endmodule // master_control
+"
+"
+
+module fifo_1k
+ ( input [15:0] data,
+ input \twrreq,
+ input \trdreq,
+ input \trdclk,
+ input \twrclk,
+ input \taclr,
+ output [15:0] q,
+ output \t rdfull,
+ output \t rdempty,
+ output [9:0] rdusedw,
+ output \t wrfull,
+ output \t wrempty,
+ output [9:0] wrusedw
+ );
+
+fifo #(.width(16),.depth(1024),.addr_bits(10)) fifo_1k
+ ( data, wrreq, rdreq, rdclk, wrclk, aclr, q,
+ rdfull, rdempty, rdusedw, wrfull, wrempty, wrusedw);
+
+endmodule // fifo_1k
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2005,2006 Matt Ettus
+// Copyright (C) 2008 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+`include ""../../../../usrp/firmware/include/fpga_regs_common.v""
+`include ""../../../../usrp/firmware/include/fpga_regs_standard.v""
+
+module io_pins
+ ( inout wire [15:0] io_0, inout wire [15:0] io_1, inout wire [15:0] io_2, inout wire [15:0] io_3,
+ input wire [15:0] reg_0, input wire [15:0] reg_1, input wire [15:0] reg_2, input wire [15:0] reg_3,
+ input wire [15:0] io_0_force_output, input wire [15:0] io_2_force_output,
+ input wire [15:0] io_1_force_input, input wire [15:0] io_3_force_input,
+ input clock, input rx_reset, input tx_reset,
+ input [6:0] serial_addr, input [31:0] serial_data, input serial_strobe);
+
+ reg [15:0] io_0_oe,io_1_oe,io_2_oe,io_3_oe;
+
+ bidir_reg bidir_reg_0 (.tristate(io_0),.oe(io_0_oe | io_0_force_output),.reg_val(reg_0));
+ bidir_reg bidir_reg_1 (.tristate(io_1),.oe(io_1_oe & (~io_1_force_input)),.reg_val(reg_1));
+ bidir_reg bidir_reg_2 (.tristate(io_2),.oe(io_2_oe | io_2_force_output),.reg_val(reg_2));
+ bidir_reg bidir_reg_3 (.tristate(io_3),.oe(io_3_oe & (~io_3_force_input)),.reg_val(reg_3));
+
+ // Upper 16 bits are mask for lower 16
+ always @(posedge clock)
+ if(serial_strobe)
+ case(serial_addr)
+\t `FR_OE_0 : io_0_oe
+\t <= #1 (io_0_oe & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] );
+\t `FR_OE_1 : io_1_oe
+\t <= #1 (io_1_oe & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] );
+\t `FR_OE_2 : io_2_oe
+\t <= #1 (io_2_oe & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] );
+\t `FR_OE_3 : io_3_oe
+\t <= #1 (io_3_oe & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] );
+ endcase // case(serial_addr)
+
+endmodule // io_pins
+"
+"
+
+module ram16 (input clock, input write,
+\t input [3:0] wr_addr, input [15:0] wr_data,
+\t input [3:0] rd_addr, output reg [15:0] rd_data);
+
+ reg [15:0] \t\tram_array [0:15];
+
+ always @(posedge clock)
+ rd_data <= #1 ram_array[rd_addr];
+
+ always @(posedge clock)
+ if(write)
+ ram_array[wr_addr] <= #1 wr_data;
+
+endmodule // ram16
+
+"
+"
+
+module ram32_2sum (input clock, input write,
+\t\t input [4:0] wr_addr, input [15:0] wr_data,
+\t\t input [4:0] rd_addr1, input [4:0] rd_addr2,
+\t\t output reg [15:0] sum);
+
+ reg [15:0] \t\t\tram_array [0:31];
+ wire [16:0] \t\t\tsum_int;
+
+ always @(posedge clock)
+ if(write)
+ ram_array[wr_addr] <= #1 wr_data;
+
+ assign sum_int = ram_array[rd_addr1] + ram_array[rd_addr2];
+
+ always @(posedge clock)
+ sum <= #1 sum_int[16:1] + (sum_int[16]&sum_int[0]);
+
+
+endmodule // ram32_2sum
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2007 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+`include ""../lib/radar_config.vh""
+
+module radar(clk_i,saddr_i,sdata_i,s_strobe_i,
+\t tx_side_o,tx_strobe_o,tx_dac_i_o,tx_dac_q_o,
+\t rx_adc_i_i,rx_adc_q_i,
+\t rx_strobe_o,rx_ech_i_o,rx_ech_q_o,io_tx_ena_o);
+
+ // System interface
+ input clk_i;\t\t// Master clock @ 64 MHz
+ input [6:0] saddr_i;\t// Configuration bus address
+ input [31:0] sdata_i;\t// Configuration bus data
+ input \t s_strobe_i; // Configuration bus write
+
+ // Transmit subsystem
+ output tx_side_o; // Transmitter slot
+ output tx_strobe_o;\t// Generate an transmitter output sample
+ output [13:0] tx_dac_i_o;\t// I channel transmitter output to DAC
+ output [13:0] tx_dac_q_o; // Q channel transmitter output to DAC
+ output io_tx_ena_o; // Transmit/Receive switching
+
+ // Receive subsystem
+ input [15:0] rx_adc_i_i;\t// I channel input from ADC
+ input [15:0] rx_adc_q_i;\t// Q channel input from ADC
+ output \t rx_strobe_o;\t// Indicates output samples ready for Rx FIFO
+ output [15:0] rx_ech_i_o;\t// I channel processed echos to Rx FIFO
+ output [15:0] rx_ech_q_o;\t// Q channel processed echos to Rx FIFO
+
+ // Application control
+ wire reset;\t\t// Master application reset
+ wire tx_side;\t// Transmitter slot
+ wire debug_enabled; // Enable debugging mode; \t
+ wire \t tx_enable; // Transmitter enable
+ wire \t rx_enable; // Receiver enable
+ wire tx_ctrl; // Transmitter on control
+ wire rx_ctrl; // Receiver on control
+ wire [15:0] \t pulse_num; // Count of pulses since tx_enabled
+ \t
+ // Configuration
+ wire [15:0] \t ampl;\t\t// Pulse amplitude
+ wire [31:0] \t fstart;\t// Chirp start frequency
+ wire [31:0] \t fincr; // Chirp per strobe frequency increment
+
+ radar_control controller
+ (.clk_i(clk_i),.saddr_i(saddr_i),.sdata_i(sdata_i),.s_strobe_i(s_strobe_i),
+ .reset_o(reset),.tx_side_o(tx_side_o),.dbg_o(debug_enabled),
+ .tx_strobe_o(tx_strobe_o),.tx_ctrl_o(tx_ctrl),.rx_ctrl_o(rx_ctrl),
+ .ampl_o(ampl),.fstart_o(fstart),.fincr_o(fincr),.pulse_num_o(pulse_num),
+ .io_tx_ena_o(io_tx_ena_o));
+
+ radar_tx transmitter
+ ( .clk_i(clk_i),.rst_i(reset),.ena_i(tx_ctrl),.strobe_i(tx_strobe_o),
+ .ampl_i(ampl),.fstart_i(fstart),.fincr_i(fincr),
+ .tx_i_o(tx_dac_i_o),.tx_q_o(tx_dac_q_o) );
+
+ radar_rx receiver
+ ( .clk_i(clk_i),.rst_i(reset),.ena_i(rx_ctrl),.dbg_i(debug_enabled),
+ .pulse_num_i(pulse_num),.rx_in_i_i(rx_adc_i_i),.rx_in_q_i(rx_adc_q_i),
+ .rx_strobe_o(rx_strobe_o),.rx_i_o(rx_ech_i_o),.rx_q_o(rx_ech_q_o) );
+
+endmodule // radar
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003,2004 Matt Ettus
+// Copyright (C) 2007 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+module usrp_radar_mono
+(output MYSTERY_SIGNAL,
+ input master_clk,
+ input SCLK,
+ input SDI,
+ inout SDO,
+ input SEN_FPGA,
+
+ input FX2_1,
+ output FX2_2,
+ output FX2_3,
+
+ input wire [11:0] rx_a_a,
+ input wire [11:0] rx_b_a,
+ input wire [11:0] rx_a_b,
+ input wire [11:0] rx_b_b,
+
+ output wire [13:0] tx_a,
+ output wire [13:0] tx_b,
+
+ output wire TXSYNC_A,
+ output wire TXSYNC_B,
+
+ // USB interface
+ input usbclk,
+ input wire [2:0] usbctl,
+ output wire [1:0] usbrdy,
+ inout [15:0] usbdata, // NB Careful, inout
+
+ // These are the general purpose i/o's that go to the daughterboard slots
+ inout wire [15:0] io_tx_a,
+ inout wire [15:0] io_tx_b,
+ inout wire [15:0] io_rx_a,
+ inout wire [15:0] io_rx_b
+ );\t
+ wire [15:0] debugdata,debugctrl;
+ assign MYSTERY_SIGNAL = 1'b0;
+
+ wire clk64;
+
+ // wire WR = usbctl[0];
+ wire RD = usbctl[1];
+ wire OE = usbctl[2];
+
+ wire have_pkt_rdy;
+ assign usbrdy[0] = 1'b0; // have_space;
+ assign usbrdy[1] = have_pkt_rdy;
+
+ wire tx_underrun, rx_overrun;
+ wire clear_status = FX2_1;
+ assign FX2_2 = rx_overrun;
+ assign FX2_3 = 1'b0; // tx_underrun;
+
+ wire [15:0] usbdata_out;
+
+ wire [3:0] rx_numchan;
+ wire enable_tx, enable_rx;
+ wire tx_dsp_reset, rx_dsp_reset, tx_bus_reset, rx_bus_reset;
+
+ // Tri-state bus macro
+ bustri bustri( .data(usbdata_out),.enabledt(OE),.tridata(usbdata) );
+
+ assign clk64 = master_clk;
+
+ // TX
+ wire tx_sample_strobe;
+ wire io_tx_ena;
+
+ wire serial_strobe;
+ wire [6:0] serial_addr;
+ wire [31:0] serial_data;
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Transmit Side
+
+ wire tx_side;
+ wire [13:0] tx_i, tx_q;
+ wire [13:0] tx_dac;
+ wire tx_sync;
+
+ dac_interface dac(.clk_i(clk64),.rst_i(tx_dsp_reset),.ena_i(enable_tx),
+\t\t .strobe_i(tx_sample_strobe),.tx_i_i(tx_i),.tx_q_i(tx_q),
+\t\t .tx_data_o(tx_dac),.tx_sync_o(tx_sync));
+
+ // Route transmitted signal to side A or side B
+ assign tx_a = tx_side ? 14'b0 : tx_dac;
+ assign tx_b = tx_side ? tx_dac : 14'b0;
+ assign TXSYNC_A = tx_side ? 1'b0 : tx_sync;
+ assign TXSYNC_B = tx_side ? tx_sync : 1'b0;
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Receive Side
+ wire rx_strobe;
+ wire [15:0] rx_adc0_i, rx_adc0_q;
+ wire [15:0] rx_buf_i, rx_buf_q;
+
+ adc_interface adc_interface(.clock(clk64),.reset(rx_dsp_reset),.enable(enable_rx),
+\t\t\t .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+\t\t\t .rx_a_a(rx_a_a),.rx_b_a(rx_b_a),.rx_a_b(rx_a_b),.rx_b_b(rx_b_b),
+\t\t\t .rssi_0(),.rssi_1(),.rssi_2(),.rssi_3(),
+\t\t\t .ddc0_in_i(rx_adc0_i),.ddc0_in_q(rx_adc0_q),
+\t\t\t .ddc1_in_i(),.ddc1_in_q(),
+\t\t\t .ddc2_in_i(),.ddc2_in_q(),
+\t\t\t .ddc3_in_i(),.ddc3_in_q(),.rx_numchan(rx_numchan) );
+
+ rx_buffer rx_buffer
+ ( .usbclk(usbclk),.bus_reset(rx_bus_reset),.reset(rx_dsp_reset),
+ .reset_regs(rx_dsp_reset),
+ .usbdata(usbdata_out),.RD(RD),.have_pkt_rdy(have_pkt_rdy),.rx_overrun(rx_overrun),
+ .channels(rx_numchan),
+ .ch_0(rx_buf_i),.ch_1(rx_buf_q),
+ .ch_2(),.ch_3(),
+ .ch_4(),.ch_5(),
+ .ch_6(),.ch_7(),
+ .rxclk(clk64),.rxstrobe(rx_strobe),
+ .clear_status(clear_status),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .debugbus() );
+
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Top level application
+ radar radar_mono ( .clk_i(clk64),.saddr_i(serial_addr),.sdata_i(serial_data),.s_strobe_i(serial_strobe),
+\t .tx_side_o(tx_side),.tx_strobe_o(tx_sample_strobe),.tx_dac_i_o(tx_i),.tx_dac_q_o(tx_q),
+\t .rx_adc_i_i(rx_adc0_i),.rx_adc_q_i(rx_adc0_q),
+\t .rx_strobe_o(rx_strobe),.rx_ech_i_o(rx_buf_i),.rx_ech_q_o(rx_buf_q),.io_tx_ena_o(io_tx_ena)
+\t );
+
+ // Route TX enable out to RFX transmit mixer enable
+ assign io_tx_a[5] = tx_side ? 1'bz : io_tx_ena;
+ assign io_tx_b[5] = tx_side ? io_tx_ena : 1'bz;
+
+ // Route opposite of TX enable out to RFX receive mixer
+ //assign io_rx_a[5] = tx_side ? 1'bz : ~io_tx_ena;
+ //assign io_rx_b[5] = tx_side ? ~io_tx_ena : 1'bz;
+ assign io_rx_a[5] = 1'b1;
+ assign io_rx_b[5] = 1'b1;
+
+
+ // Route TX enable out to RX/TX switch
+ assign io_tx_a[6] = tx_side ? 1'bz : ~io_tx_ena;
+ assign io_tx_b[6] = tx_side ? ~io_tx_ena : 1'bz;
+
+ // Enable common RX/TX antenna
+ assign io_rx_a[6] = tx_side ? 1'bz : 1'b0;
+ assign io_rx_b[6] = tx_side ? 1'b0 : 1'bz;
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Control Functions
+
+ wire [31:0] capabilities;
+ assign capabilities[7] = 0; // `TX_CAP_HB;
+ assign capabilities[6:4] = 1; // `TX_CAP_NCHAN;
+ assign capabilities[3] = 0; // `RX_CAP_HB;
+ assign capabilities[2:0] = 2; // `RX_CAP_NCHAN;
+
+ serial_io serial_io
+ ( .master_clk(clk64),.serial_clock(SCLK),.serial_data_in(SDI),
+ .enable(SEN_FPGA),.reset(1'b0),.serial_data_out(SDO),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .readback_0({io_rx_a,io_tx_a}),.readback_1({io_rx_b,io_tx_b}),.readback_2(capabilities),.readback_3(32'hf0f0931a),
+ .readback_4(),.readback_5(),.readback_6(),.readback_7()
+ );
+
+ wire [15:0] reg_0,reg_1,reg_2,reg_3;
+ master_control master_control
+ ( .master_clk(clk64),.usbclk(usbclk),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .tx_bus_reset(tx_bus_reset),.rx_bus_reset(rx_bus_reset),
+ .tx_dsp_reset(tx_dsp_reset),.rx_dsp_reset(rx_dsp_reset),
+ .enable_tx(enable_tx),.enable_rx(enable_rx),
+ .interp_rate(),.decim_rate(),
+ .tx_sample_strobe(),.strobe_interp(),
+ .rx_sample_strobe(),.strobe_decim(),
+ .tx_empty(),
+ .debug_0(),.debug_1(),
+ .debug_2(),.debug_3(),
+ .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3) );
+
+ wire [1:0] dummy_io = 2'bz;
+
+ io_pins io_pins
+ (.io_0({io_tx_a[15:7],dummy_io,io_tx_a[4:0]}), // Don't connect pins used above
+ .io_1({io_rx_a[15:7],dummy_io,io_rx_a[4:0]}),
+ .io_2({io_tx_b[15:7],dummy_io,io_tx_b[4:0]}),
+ .io_3({io_rx_b[15:7],dummy_io,io_rx_b[4:0]}),
+ .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3),
+ .clock(clk64),.rx_reset(rx_dsp_reset),.tx_reset(tx_dsp_reset),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe));
+
+endmodule // usrp_radar_mono
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2008 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+`include ""../../../../usrp/firmware/include/fpga_regs_common.v""
+`include ""../../../../usrp/firmware/include/fpga_regs_standard.v""
+
+module gpio_input
+ (input clock, input reset, input enable,
+ input out_strobe,
+ input wire [6:0] serial_addr, input wire [31:0] serial_data, input serial_strobe,
+ input wire [15:0] io_rx_a_in, input wire [15:0] io_rx_b_in,
+ //input wire [15:0] io_tx_a_in, input wire [15:0] io_tx_b_in,
+ output reg rx_dig0_i, output reg rx_dig0_q,
+ output reg rx_dig1_i, output reg rx_dig1_q );
+
+ // Buffer at input to chip
+
+ reg rx_dig_rx_a_a,rx_dig_rx_b_a,rx_dig_rx_a_b,rx_dig_rx_b_b;
+ //TODO possibly use a flancter here
+ //This code can optionally be extended to do streaming input from gpio of tx boards
+ //The code can also be extended to input more bits
+
+ always @(posedge clock)
+ begin
+ //This is the first point where is determined which physical input gpio pins are used for streaming digital input
+ //The other point is the code which overrides these pins as input (oe = 0)
+\t//rx_dig_tx_a_a <= #1 io_tx_a_in[14];
+\t//rx_dig_tx_b_a <= #1 io_tx_a_in[15];
+\trx_dig_rx_a_a <= #1 io_rx_a_in[14];
+\trx_dig_rx_b_a <= #1 io_rx_a_in[15];
+\t//rx_dig_tx_a_b <= #1 io_tx_b_in[14];
+\t//rx_dig_tx_b_b <= #1 io_tx_b_in[15];
+\trx_dig_rx_a_b <= #1 io_rx_b_in[14];
+\trx_dig_rx_b_b <= #1 io_rx_b_in[15];
+ end
+
+ // Now mux to the appropriate outputs
+ wire [3:0] \tddc3mux,ddc2mux,ddc1mux,ddc0mux;
+ wire \trx_realsignals;
+ wire [3:0] rx_numchan;//not used here
+ //TODO This setting reg readout is a duplicate of the one in adc_interface.v.
+ // Change code so this is done in only one place, or give this code its own register.
+ setting_reg #(`FR_RX_MUX) sr_rxmux(.clock(clock),.reset(reset),.strobe(serial_strobe),.addr(serial_addr),
+\t\t\t\t .in(serial_data),.out({ddc3mux,ddc2mux,ddc1mux,ddc0mux,rx_realsignals,rx_numchan[3:1]}));
+ //assign \trx_numchan[0] = 1\'b0;
+
+ always @(posedge clock)
+ if (out_strobe) //out_strobe determines the time at which the digital inputs are sampled (with a delay of one sample)
+ begin
+\trx_dig0_i <= #1 ddc0mux[1] ? (ddc0mux[0] ? rx_dig_rx_b_b : rx_dig_rx_a_b) : (ddc0mux[0] ? rx_dig_rx_b_a : rx_dig_rx_a_a);
+\trx_dig0_q <= #1 rx_realsignals ? 1\'b0 : ddc0mux[3] ? (ddc0mux[2] ? rx_dig_rx_b_b : rx_dig_rx_a_b) : (ddc0mux[2] ? rx_dig_rx_b_a : rx_dig_rx_a_a);
+\trx_dig1_i <= #1 ddc1mux[1] ? (ddc1mux[0] ? rx_dig_rx_b_b : rx_dig_rx_a_b) : (ddc1mux[0] ? rx_dig_rx_b_a : rx_dig_rx_a_a);
+\trx_dig1_q <= #1 rx_realsignals ? 1\'b0 : ddc1mux[3] ? (ddc1mux[2] ? rx_dig_rx_b_b : rx_dig_rx_a_b) : (ddc1mux[2] ? rx_dig_rx_b_a : rx_dig_rx_a_a);
+\t//rx_dig2_i <= #1 ddc2mux[1] ? (ddc2mux[0] ? rx_dig_rx_b_b : rx_dig_rx_a_b) : (ddc2mux[0] ? rx_dig_rx_b_a : rx_dig_rx_a_a);
+\t//rx_dig2_q <= #1 rx_realsignals ? 1\'b0 : ddc2mux[3] ? (ddc2mux[2] ? rx_dig_rx_b_b : rx_dig_rx_a_b) : (ddc2mux[2] ? rx_dig_rx_b_a : rx_dig_rx_a_a);
+\t//rx_dig3_i <= #1 ddc3mux[1] ? (ddc3mux[0] ? rx_dig_rx_b_b : rx_dig_rx_a_b) : (ddc3mux[0] ? rx_dig_rx_b_a : rx_dig_rx_a_a);
+\t//rx_dig3_q <= #1 rx_realsignals ? 1\'b0 : ddc3mux[3] ? (ddc3mux[2] ? rx_dig_rx_b_b : rx_dig_rx_a_b) : (ddc3mux[2] ? rx_dig_rx_b_a : rx_dig_rx_a_a);
+ end
+
+endmodule // gpio_input
+
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2007 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+`include ""../../../../usrp/firmware/include/fpga_regs_common.v""
+`include ""../../../../usrp/firmware/include/fpga_regs_standard.v""
+
+module sounder_tx(clk_i,rst_i,ena_i,strobe_i,ampl_i,mask_i,tx_i_o,tx_q_o);
+ input clk_i;
+ input rst_i;
+ input ena_i;
+ input strobe_i;
+ input [13:0] ampl_i;
+ input [15:0] mask_i;
+ output [13:0] tx_i_o;
+ output [13:0] tx_q_o;
+
+ wire pn;
+ wire [13:0] min_value = (~ampl_i)+14\'b1;
+
+ lfsr pn_code
+ ( .clk_i(clk_i),.rst_i(rst_i),.ena_i(ena_i),.strobe_i(strobe_i),.mask_i(mask_i),.pn_o(pn) );
+
+ assign tx_i_o = ena_i ? (pn ? ampl_i : min_value) : 14\'b0; // Bipolar
+ assign tx_q_o = 14\'b0;
+
+endmodule // sounder_tx
+"
+"// megafunction wizard: %ALTPLL%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altpll
+
+// ============================================================
+// File Name: clk_doubler.v
+// Megafunction Name(s):
+// \t\t\taltpll
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 4.2 Build 156 11/29/2004 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2004 Altera Corporation
+//Any megafunction design, and related netlist (encrypted or decrypted),
+//support information, device programming or simulation file, and any other
+//associated documentation or information provided by Altera or a partner
+//under Altera\'s Megafunction Partnership Program may be used only
+//to program PLD devices (but not masked PLD devices) from Altera. Any
+//other use of such megafunction design, netlist, support information,
+//device programming or simulation file, or any other related documentation
+//or information is prohibited for any other purpose, including, but not
+//limited to modification, reverse engineering, de-compiling, or use with
+//any other silicon devices, unless such use is explicitly licensed under
+//a separate agreement with Altera or a megafunction partner. Title to the
+//intellectual property, including patents, copyrights, trademarks, trade
+//secrets, or maskworks, embodied in any such megafunction design, netlist,
+//support information, device programming or simulation file, or any other
+//related documentation or information provided by Altera or a megafunction
+//partner, remains with Altera, the megafunction partner, or their respective
+//licensors. No other licenses, including any licenses needed under any third
+//party\'s intellectual property, are provided herein.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module clk_doubler (
+\tinclk0,
+\tc0);
+
+\tinput\t inclk0;
+\toutput\t c0;
+
+\twire [5:0] sub_wire0;
+\twire [0:0] sub_wire4 = 1\'h0;
+\twire [0:0] sub_wire1 = sub_wire0[0:0];
+\twire c0 = sub_wire1;
+\twire sub_wire2 = inclk0;
+\twire [1:0] sub_wire3 = {sub_wire4, sub_wire2};
+
+\taltpll\taltpll_component (
+\t\t\t\t.inclk (sub_wire3),
+\t\t\t\t.clk (sub_wire0)
+\t\t\t\t// synopsys translate_off
+\t\t\t\t,
+\t\t\t\t.activeclock (),
+\t\t\t\t.areset (),
+\t\t\t\t.clkbad (),
+\t\t\t\t.clkena (),
+\t\t\t\t.clkloss (),
+\t\t\t\t.clkswitch (),
+\t\t\t\t.enable0 (),
+\t\t\t\t.enable1 (),
+\t\t\t\t.extclk (),
+\t\t\t\t.extclkena (),
+\t\t\t\t.fbin (),
+\t\t\t\t.locked (),
+\t\t\t\t.pfdena (),
+\t\t\t\t.pllena (),
+\t\t\t\t.scanaclr (),
+\t\t\t\t.scanclk (),
+\t\t\t\t.scandata (),
+\t\t\t\t.scandataout (),
+\t\t\t\t.scandone (),
+\t\t\t\t.scanread (),
+\t\t\t\t.scanwrite (),
+\t\t\t\t.sclkout0 (),
+\t\t\t\t.sclkout1 ()
+\t\t\t\t// synopsys translate_on
+\t\t\t\t);
+\tdefparam
+\t\taltpll_component.clk0_duty_cycle = 50,
+\t\taltpll_component.lpm_type = ""altpll"",
+\t\taltpll_component.clk0_multiply_by = 2,
+\t\taltpll_component.inclk0_input_frequency = 15625,
+\t\taltpll_component.clk0_divide_by = 1,
+\t\taltpll_component.pll_type = ""AUTO"",
+\t\taltpll_component.intended_device_family = ""Cyclone"",
+\t\taltpll_component.operation_mode = ""NORMAL"",
+\t\taltpll_component.compensate_clock = ""CLK0"",
+\t\taltpll_component.clk0_phase_shift = ""0"";
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: MIRROR_CLK0 STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: SPREAD_USE STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC ""1048575""
+// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING ""0""
+// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING ""50.00000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING ""0.00000000""
+// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC ""2""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_PERCENT STRING ""0.500""
+// Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING ""0""
+// Retrieval info: PRIVATE: STICKY_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: BANDWIDTH STRING ""1.000""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_CUSTOM STRING ""0""
+// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING ""8""
+// Retrieval info: PRIVATE: SPREAD_FREQ STRING ""50.000""
+// Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING ""1""
+// Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC ""0""
+// Retrieval info: PRIVATE: USE_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING ""0""
+// Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING ""0""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING ""100.000""
+// Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING ""c0""
+// Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING ""0""
+// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: CUR_FBIN_CLK STRING ""e0""
+// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING ""1""
+// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING ""0""
+// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC ""1""
+// Retrieval info: PRIVATE: CLKLOSS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING ""1""
+// Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING ""0""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING ""512.000""
+// Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING ""KHz""
+// Retrieval info: PRIVATE: PLL_ENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING ""64.000""
+// Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING ""0""
+// Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING ""100.000""
+// Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING ""inclk0""
+// Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: DEV_FAMILY STRING ""Cyclone""
+// Retrieval info: PRIVATE: LOCK_LOSS_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING ""Low""
+// Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: USE_CLKENA0 STRING ""0""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING ""0""
+// Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: DEVICE_FAMILY NUMERIC ""11""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""altpll""
+// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC ""2""
+// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC ""15625""
+// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: PLL_TYPE STRING ""AUTO""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: CONSTANT: OPERATION_MODE STRING ""NORMAL""
+// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING ""CLK0""
+// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING ""0""
+// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT VCC ""c0""
+// Retrieval info: USED_PORT: @clk 0 0 6 0 OUTPUT VCC ""@clk[5..0]""
+// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT GND ""inclk0""
+// Retrieval info: USED_PORT: @extclk 0 0 4 0 OUTPUT VCC ""@extclk[3..0]""
+// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
+// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
+// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL clk_doubler.v TRUE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL clk_doubler.inc FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL clk_doubler.cmp FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL clk_doubler.bsf FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL clk_doubler_inst.v FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL clk_doubler_bb.v TRUE FALSE
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2006 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+// Top level module for a full setup with DUCs and DDCs
+
+// Uncomment the following to include optional circuitry
+
+`include ""mrfm.vh""
+`include ""../../../firmware/include/fpga_regs_common.v""
+`include ""../../../firmware/include/fpga_regs_standard.v""
+
+module mrfm
+(output MYSTERY_SIGNAL,
+ input master_clk,
+ input SCLK,
+ input SDI,
+ inout SDO,
+ input SEN_FPGA,
+
+ input FX2_1,
+ output FX2_2,
+ output FX2_3,
+
+ input wire [11:0] rx_a_a,
+ input wire [11:0] rx_b_a,
+ input wire [11:0] rx_a_b,
+ input wire [11:0] rx_b_b,
+
+ output wire [13:0] tx_a,
+ output wire [13:0] tx_b,
+
+ output wire TXSYNC_A,
+ output wire TXSYNC_B,
+
+ // USB interface
+ input usbclk,
+ input wire [2:0] usbctl,
+ output wire [1:0] usbrdy,
+ inout [15:0] usbdata, // NB Careful, inout
+
+ // These are the general purpose i/o\'s that go to the daughterboard slots
+ inout wire [15:0] io_tx_a,
+ inout wire [15:0] io_tx_b,
+ inout wire [15:0] io_rx_a,
+ inout wire [15:0] io_rx_b
+ );\t
+ wire [15:0] debugdata,debugctrl;
+ assign MYSTERY_SIGNAL = 1\'b0;
+
+ wire clk64;
+
+ wire WR = usbctl[0];
+ wire RD = usbctl[1];
+ wire OE = usbctl[2];
+
+ wire have_space, have_pkt_rdy;
+ assign usbrdy[0] = have_space;
+ assign usbrdy[1] = have_pkt_rdy;
+
+ wire tx_underrun, rx_overrun;
+ wire clear_status = FX2_1;
+ assign FX2_2 = rx_overrun;
+ assign FX2_3 = tx_underrun;
+
+ wire [15:0] usbdata_out;
+
+ wire [3:0] dac0mux,dac1mux,dac2mux,dac3mux;
+
+ wire tx_realsignals;
+ wire [3:0] rx_numchan;
+
+ wire [15:0] tx_debugbus, rx_debugbus;
+
+ wire enable_tx, enable_rx;
+ wire tx_dsp_reset, rx_dsp_reset, tx_bus_reset, rx_bus_reset;
+ wire [7:0] settings;
+
+ // Tri-state bus macro
+ bustri bustri( .data(usbdata_out),.enabledt(OE),.tridata(usbdata) );
+
+ assign clk64 = master_clk;
+
+ wire [15:0] ch0tx,ch1tx,ch2tx,ch3tx;
+ wire [15:0] ch0rx,ch1rx,ch2rx,ch3rx,ch4rx,ch5rx,ch6rx,ch7rx;
+
+ wire serial_strobe;
+ wire [6:0] serial_addr;
+ wire [31:0] serial_data;
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ setting_reg #(`FR_TX_MUX)
+ sr_txmux(.clock(clk64),.reset(tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
+\t .out({dac3mux,dac2mux,dac1mux,dac0mux,tx_realsignals,tx_numchan}));
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Signal Processing Chain
+
+ reg [15:0] adc0;
+ wire [15:0] dac0;
+ wire [15:0] i,q,ip,qp;
+ wire strobe_out;
+ wire sync_out;
+
+ always @(posedge clk64)
+ adc0 <= #1 {rx_a_a[11],rx_a_a[11:0],3\'b0};
+
+ wire [15:0] adc0_corr;
+ rx_dcoffset #(0)rx_dcoffset0(.clock(clk64),.enable(1\'b1),.reset(reset),.adc_in(adc0),.adc_out(adc0_corr),
+\t.serial_addr(7\'d0),.serial_data(32\'d0),.serial_strobe(1\'b0));
+
+ //wire [63:0] filt_debug = 64\'d0;
+
+ mrfm_proc mrfm_proc(.clock(clk64),.reset(rx_dsp_reset),.enable(enable_rx),
+\t\t .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+\t\t .signal_in(adc0_corr),.signal_out(dac0),.sync_out(sync_out),
+\t\t .i(i),.q(q),.ip(ip),.qp(qp),.strobe_out(strobe_out),
+\t\t .debugbus( /* filt_debug */ ));
+
+ wire txsync = 1\'b0;
+ assign TXSYNC_A = txsync;
+ assign TXSYNC_B = txsync;
+
+ assign tx_a = dac0[15:2];
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////
+ // Data Collection on RX Buffer
+
+ assign rx_numchan[0] = 1\'b0;
+ setting_reg #(`FR_RX_MUX) sr_rxmux(.clock(clk64),.reset(rx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),
+\t\t\t\t .in(serial_data),.out(rx_numchan[3:1]));
+
+ rx_buffer rx_buffer
+ ( .usbclk(usbclk),.bus_reset(rx_bus_reset),.reset(rx_dsp_reset),
+ .usbdata(usbdata_out),.RD(RD),.have_pkt_rdy(have_pkt_rdy),.rx_overrun(rx_overrun),
+ .channels(rx_numchan),
+ .ch_0(i),.ch_1(q),
+ .ch_2(ip),.ch_3(qp),
+ .ch_4(16\'d0),.ch_5(16\'d0),
+ .ch_6(16\'d0),.ch_7(16\'d0),
+ .rxclk(clk64),.rxstrobe(strobe_out),
+ .clear_status(clear_status),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .debugbus(rx_debugbus) );
+
+ //////////////////////////////////////////////////////////////////////////////
+ // Control Functions
+
+ wire [31:0] capabilities = 32\'d2;
+
+ serial_io serial_io
+ ( .master_clk(clk64),.serial_clock(SCLK),.serial_data_in(SDI),
+ .enable(SEN_FPGA),.reset(1\'b0),.serial_data_out(SDO),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .readback_0({io_rx_a,io_tx_a}),.readback_1({io_rx_b,io_tx_b}),.readback_2(capabilities),.readback_3(32\'hf0f0931a) );
+
+ wire [15:0] reg_0,reg_1,reg_2,reg_3;
+ master_control master_control
+ ( .master_clk(clk64),.usbclk(usbclk),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .tx_bus_reset(tx_bus_reset),.rx_bus_reset(rx_bus_reset),
+ .tx_dsp_reset(tx_dsp_reset),.rx_dsp_reset(rx_dsp_reset),
+ .enable_tx(enable_tx),.enable_rx(enable_rx),
+ .interp_rate(interp_rate),.decim_rate(decim_rate),
+ .tx_sample_strobe(tx_sample_strobe),.strobe_interp(strobe_interp),
+ .rx_sample_strobe(rx_sample_strobe),.strobe_decim(strobe_decim),
+ .tx_empty(tx_empty),
+ .debug_0({15\'d0,sync_out}), //filt_debug[63:48]),
+ .debug_1({15\'d0,sync_out}), //filt_debug[47:32]),
+ .debug_2({15\'d0,sync_out}), //filt_debug[31:16]),
+ .debug_3({15\'d0,sync_out}), //filt_debug[15:0]),
+ .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3) );
+
+ io_pins io_pins
+ (.io_0(io_tx_a),.io_1(io_rx_a),.io_2(io_tx_b),.io_3(io_rx_b),
+ .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3),
+ .clock(clk64),.rx_reset(rx_dsp_reset),.tx_reset(tx_dsp_reset),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe));
+
+endmodule // mrfm
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+
+module sizetest(input clock,
+\t\t\t\tinput reset,
+\t\t\t\tinput enable,
+\t\t\t\tinput [15:0]xi,
+\t\t\t\tinput [15:0] yi,
+\t\t\t\tinput [15:0] zi,
+\t\t\t\toutput [15:0] xo,
+\t\t\t\toutput [15:0] yo,
+\t\t\t\toutput [15:0] zo
+//\t\t\t\tinput [15:0] constant
+\t\t\t\t);
+
+wire [16:0] zo;
+
+cordic_stage cordic_stage(clock, reset, enable, xi, yi, zi, 16'd16383, xo, yo, zo );
+
+endmodule
+"
+"`include ""mrfm.vh""
+
+module mrfm_iir (input clock, input reset, input strobe_in,
+\t\t input serial_strobe, input [6:0] serial_addr, input [31:0] serial_data,
+\t\t input wire [15:0] sample_in, output reg [15:0] sample_out);
+
+ wire [5:0] \t coeff_addr, coeff_wr_addr;
+ wire [4:0] \t data_addr, data_wr_addr;
+ reg [4:0] \t cur_offset, data_addr_int, data_wr_addr_int;
+
+ wire [15:0] \t coeff, coeff_wr_data, data, data_wr_data;
+ wire \t coeff_wr;
+ reg \t\t data_wr;
+
+ wire [30:0] \t product;
+ wire [33:0] \t accum;
+ wire [15:0] \t scaled_accum; \t\t
+
+ wire [7:0] \t shift;
+ reg [5:0] \t phase;
+ wire \t enable_mult, enable_acc, latch_out, select_input;
+ reg \t\t done, clear_acc;
+
+ setting_reg #(`FR_MRFM_IIR_COEFF) sr_coeff(.clock(clock),.reset(reset),
+\t\t\t\t\t .strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
+\t\t\t\t\t .out({coeff_wr_addr,coeff_wr_data}),.changed(coeff_wr));
+
+ setting_reg #(`FR_MRFM_IIR_SHIFT) sr_shift(.clock(clock),.reset(reset),
+\t\t\t\t\t .strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
+\t\t\t\t\t .out(shift),.changed());
+
+ ram64 coeff_ram(.clock(clock),.write(coeff_wr),.wr_addr(coeff_wr_addr),.wr_data(coeff_wr_data),
+\t\t .rd_addr(coeff_addr),.rd_data(coeff));
+
+ ram32 data_ram(.clock(clock),.write(data_wr),.wr_addr(data_wr_addr),.wr_data(data_wr_data),
+\t\t .rd_addr(data_addr),.rd_data(data));
+
+ mult mult (.clock(clock),.x(data),.y(coeff),.product(product),.enable_in(enable_mult),.enable_out() );
+
+ acc acc (.clock(clock),.reset(reset),.clear(clear_acc),.enable_in(enable_acc),.enable_out(),
+\t .addend(product),.sum(accum) );
+
+ shifter shifter (.in(accum),.out(scaled_accum),.shift(shift));
+
+ assign \t data_wr_data = select_input ? sample_in : scaled_accum;
+ assign \t enable_mult = 1\'b1;
+
+ always @(posedge clock)
+ if(reset)
+ cur_offset <= #1 5\'d0;
+ else if(latch_out)
+ cur_offset <= #1 cur_offset + 5\'d1;
+
+ assign \t data_addr = data_addr_int + cur_offset;\t\t
+ assign \t data_wr_addr = data_wr_addr_int + cur_offset;\t\t
+
+ always @(posedge clock)
+ if(reset)
+ done <= #1 1\'b0;
+ else if(latch_out)
+ done <= #1 1\'b1;
+ else if(strobe_in)
+ done <= #1 1\'b0;
+
+ always @(posedge clock)
+ if(reset)
+ phase <= #1 6\'d0;
+ else if(strobe_in)
+ phase <= #1 6\'d0;
+ else if(!done)
+ phase <= #1 phase + 6\'d1;
+
+ always @(phase)
+ case(phase)
+ 6\'d0 : data_addr_int = 5\'d0;
+ default : data_addr_int = 5\'d0;
+ endcase // case(phase)
+
+ assign \t coeff_addr = phase;
+
+ always @(phase)
+ case(phase)
+ 6\'d01 : data_addr_int = 5\'d00; 6\'d02 : data_addr_int = 5\'d01; 6\'d03 : data_addr_int = 5\'d02;
+ 6\'d04 : data_addr_int = 5\'d03; 6\'d05 : data_addr_int = 5\'d04;
+
+ 6\'d07 : data_addr_int = 5\'d03; 6\'d08 : data_addr_int = 5\'d04; 6\'d09 : data_addr_int = 5\'d05;
+ 6\'d10 : data_addr_int = 5\'d06; 6\'d11 : data_addr_int = 5\'d07;
+
+ 6\'d13 : data_addr_int = 5\'d06; 6\'d14 : data_addr_int = 5\'d07; 6\'d15 : data_addr_int = 5\'d08;
+ 6\'d16 : data_addr_int = 5\'d09; 6\'d17 : data_addr_int = 5\'d10;
+
+ 6\'d19 : data_addr_int = 5\'d09; 6\'d20 : data_addr_int = 5\'d10; 6\'d21 : data_addr_int = 5\'d11;
+ 6\'d22 : data_addr_int = 5\'d12; 6\'d23 : data_addr_int = 5\'d13;
+
+ 6\'d25 : data_addr_int = 5\'d12; 6\'d26 : data_addr_int = 5\'d13; 6\'d27 : data_addr_int = 5\'d14;
+ 6\'d28 : data_addr_int = 5\'d15; 6\'d29 : data_addr_int = 5\'d16;
+
+ 6\'d31 : data_addr_int = 5\'d15; 6\'d32 : data_addr_int = 5\'d16; 6\'d33 : data_addr_int = 5\'d17;
+ 6\'d34 : data_addr_int = 5\'d18; 6\'d35 : data_addr_int = 5\'d19;
+
+ default : data_addr_int = 5\'d00;
+ endcase // case(phase)
+
+ always @(phase)
+ case(phase)
+ 6\'d0 : data_wr_addr_int = 5\'d2;
+ 6\'d8 : data_wr_addr_int = 5\'d5;
+ 6\'d14 : data_wr_addr_int = 5\'d8;
+ 6\'d20 : data_wr_addr_int = 5\'d11;
+ 6\'d26 : data_wr_addr_int = 5\'d14;
+ 6\'d32 : data_wr_addr_int = 5\'d17;
+ 6\'d38 : data_wr_addr_int = 5\'d20;
+ default : data_wr_addr_int = 5\'d0;
+ endcase // case(phase)
+
+ always @(phase)
+ case(phase)
+ 6\'d0, 6\'d8, 6\'d14, 6\'d20, 6\'d26, 6\'d32, 6\'d38: data_wr = 1\'b1;
+ default : data_wr = 1\'b0;
+ endcase // case(phase)
+
+ always @(phase)
+ case(phase)
+ 6\'d0, 6\'d1, 6\'d2, 6\'d3, 6\'d9, 6\'d15, 6\'d21, 6\'d27, 6\'d33 : clear_acc = 1\'d1;
+ default : clear_acc = 1\'b0;
+ endcase // case(phase)
+
+ assign \t enable_acc = ~clear_acc;
+ assign \t latch_out = (phase == 6\'d38);
+
+ always @(posedge clock)
+ if(reset)
+ sample_out <= #1 16\'d0;
+ else if(latch_out)
+ sample_out <= #1 scaled_accum;
+
+endmodule // mrfm_iir
+"
+"// megafunction wizard: %ALTPLL%VBB%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altpll
+
+// ============================================================
+// File Name: clk_doubler.v
+// Megafunction Name(s):
+// \t\t\taltpll
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 4.2 Build 156 11/29/2004 SJ Web Edition
+// ************************************************************
+
+//Copyright (C) 1991-2004 Altera Corporation
+//Any megafunction design, and related netlist (encrypted or decrypted),
+//support information, device programming or simulation file, and any other
+//associated documentation or information provided by Altera or a partner
+//under Altera\'s Megafunction Partnership Program may be used only
+//to program PLD devices (but not masked PLD devices) from Altera. Any
+//other use of such megafunction design, netlist, support information,
+//device programming or simulation file, or any other related documentation
+//or information is prohibited for any other purpose, including, but not
+//limited to modification, reverse engineering, de-compiling, or use with
+//any other silicon devices, unless such use is explicitly licensed under
+//a separate agreement with Altera or a megafunction partner. Title to the
+//intellectual property, including patents, copyrights, trademarks, trade
+//secrets, or maskworks, embodied in any such megafunction design, netlist,
+//support information, device programming or simulation file, or any other
+//related documentation or information provided by Altera or a megafunction
+//partner, remains with Altera, the megafunction partner, or their respective
+//licensors. No other licenses, including any licenses needed under any third
+//party\'s intellectual property, are provided herein.
+
+module clk_doubler (
+\tinclk0,
+\tc0);
+
+\tinput\t inclk0;
+\toutput\t c0;
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: MIRROR_CLK0 STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: SPREAD_USE STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC ""1048575""
+// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING ""0""
+// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING ""50.00000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING ""0.00000000""
+// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC ""2""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_PERCENT STRING ""0.500""
+// Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING ""0""
+// Retrieval info: PRIVATE: STICKY_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: BANDWIDTH STRING ""1.000""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_CUSTOM STRING ""0""
+// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING ""8""
+// Retrieval info: PRIVATE: SPREAD_FREQ STRING ""50.000""
+// Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING ""1""
+// Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC ""0""
+// Retrieval info: PRIVATE: USE_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING ""0""
+// Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING ""0""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING ""100.000""
+// Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING ""c0""
+// Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING ""0""
+// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: CUR_FBIN_CLK STRING ""e0""
+// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING ""1""
+// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING ""0""
+// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC ""1""
+// Retrieval info: PRIVATE: CLKLOSS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING ""1""
+// Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING ""0""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING ""512.000""
+// Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING ""KHz""
+// Retrieval info: PRIVATE: PLL_ENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING ""64.000""
+// Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING ""0""
+// Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING ""100.000""
+// Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING ""inclk0""
+// Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: DEV_FAMILY STRING ""Cyclone""
+// Retrieval info: PRIVATE: LOCK_LOSS_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING ""Low""
+// Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: USE_CLKENA0 STRING ""0""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING ""0""
+// Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: DEVICE_FAMILY NUMERIC ""11""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""altpll""
+// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC ""2""
+// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC ""15625""
+// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: PLL_TYPE STRING ""AUTO""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: CONSTANT: OPERATION_MODE STRING ""NORMAL""
+// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING ""CLK0""
+// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING ""0""
+// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT VCC ""c0""
+// Retrieval info: USED_PORT: @clk 0 0 6 0 OUTPUT VCC ""@clk[5..0]""
+// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT GND ""inclk0""
+// Retrieval info: USED_PORT: @extclk 0 0 4 0 OUTPUT VCC ""@extclk[3..0]""
+// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
+// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
+// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL clk_doubler.v TRUE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL clk_doubler.inc FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL clk_doubler.cmp FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL clk_doubler.bsf FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL clk_doubler_inst.v FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL clk_doubler_bb.v TRUE FALSE
+"
+"// megafunction wizard: %ALTPLL%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altpll
+
+// ============================================================
+// File Name: dspclkpll.v
+// Megafunction Name(s):
+// \t\t\taltpll
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 4.0 Build 214 3/25/2004 SP 1 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2004 Altera Corporation
+//Any megafunction design, and related netlist (encrypted or decrypted),
+//support information, device programming or simulation file, and any other
+//associated documentation or information provided by Altera or a partner
+//under Altera\'s Megafunction Partnership Program may be used only
+//to program PLD devices (but not masked PLD devices) from Altera. Any
+//other use of such megafunction design, netlist, support information,
+//device programming or simulation file, or any other related documentation
+//or information is prohibited for any other purpose, including, but not
+//limited to modification, reverse engineering, de-compiling, or use with
+//any other silicon devices, unless such use is explicitly licensed under
+//a separate agreement with Altera or a megafunction partner. Title to the
+//intellectual property, including patents, copyrights, trademarks, trade
+//secrets, or maskworks, embodied in any such megafunction design, netlist,
+//support information, device programming or simulation file, or any other
+//related documentation or information provided by Altera or a megafunction
+//partner, remains with Altera, the megafunction partner, or their respective
+//licensors. No other licenses, including any licenses needed under any third
+//party\'s intellectual property, are provided herein.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module dspclkpll (
+\tinclk0,
+\tc0,
+\tc1);
+
+\tinput\t inclk0;
+\toutput\t c0;
+\toutput\t c1;
+
+\twire [5:0] sub_wire0;
+\twire [0:0] sub_wire5 = 1\'h0;
+\twire [1:1] sub_wire2 = sub_wire0[1:1];
+\twire [0:0] sub_wire1 = sub_wire0[0:0];
+\twire c0 = sub_wire1;
+\twire c1 = sub_wire2;
+\twire sub_wire3 = inclk0;
+\twire [1:0] sub_wire4 = {sub_wire5, sub_wire3};
+
+\taltpll\taltpll_component (
+\t\t\t\t.inclk (sub_wire4),
+\t\t\t\t.clk (sub_wire0)
+\t\t\t\t// synopsys translate_off
+,
+\t\t\t\t.fbin (),
+\t\t\t\t.pllena (),
+\t\t\t\t.clkswitch (),
+\t\t\t\t.areset (),
+\t\t\t\t.pfdena (),
+\t\t\t\t.clkena (),
+\t\t\t\t.extclkena (),
+\t\t\t\t.scanclk (),
+\t\t\t\t.scanaclr (),
+\t\t\t\t.scandata (),
+\t\t\t\t.scanread (),
+\t\t\t\t.scanwrite (),
+\t\t\t\t.extclk (),
+\t\t\t\t.clkbad (),
+\t\t\t\t.activeclock (),
+\t\t\t\t.locked (),
+\t\t\t\t.clkloss (),
+\t\t\t\t.scandataout (),
+\t\t\t\t.scandone (),
+\t\t\t\t.sclkout1 (),
+\t\t\t\t.sclkout0 (),
+\t\t\t\t.enable0 (),
+\t\t\t\t.enable1 ()
+\t\t\t\t// synopsys translate_on
+
+);
+\tdefparam
+\t\taltpll_component.clk1_divide_by = 1,
+\t\taltpll_component.clk1_phase_shift = ""0"",
+\t\taltpll_component.clk0_duty_cycle = 50,
+\t\taltpll_component.lpm_type = ""altpll"",
+\t\taltpll_component.clk0_multiply_by = 1,
+\t\taltpll_component.inclk0_input_frequency = 15625,
+\t\taltpll_component.clk0_divide_by = 1,
+\t\taltpll_component.clk1_duty_cycle = 50,
+\t\taltpll_component.pll_type = ""AUTO"",
+\t\taltpll_component.clk1_multiply_by = 2,
+\t\taltpll_component.clk0_time_delay = ""0"",
+\t\taltpll_component.intended_device_family = ""Cyclone"",
+\t\taltpll_component.operation_mode = ""NORMAL"",
+\t\taltpll_component.compensate_clock = ""CLK0"",
+\t\taltpll_component.clk1_time_delay = ""0"",
+\t\taltpll_component.clk0_phase_shift = ""0"";
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: MIRROR_CLK0 STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: SPREAD_USE STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC ""1048575""
+// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING ""0""
+// Retrieval info: PRIVATE: MIRROR_CLK1 STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT1 STRING ""deg""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT1 STRING ""MHz""
+// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING ""50.00000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING ""0.00000000""
+// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_PERCENT STRING ""0.500""
+// Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING ""0""
+// Retrieval info: PRIVATE: DUTY_CYCLE1 STRING ""50.00000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT1 STRING ""0.00000000""
+// Retrieval info: PRIVATE: MULT_FACTOR1 NUMERIC ""2""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE1 STRING ""0""
+// Retrieval info: PRIVATE: TIME_SHIFT0 STRING ""0.00000000""
+// Retrieval info: PRIVATE: STICKY_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: BANDWIDTH STRING ""1.000""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_CUSTOM STRING ""0""
+// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING ""8""
+// Retrieval info: PRIVATE: TIME_SHIFT1 STRING ""0.00000000""
+// Retrieval info: PRIVATE: STICKY_CLK1 STRING ""1""
+// Retrieval info: PRIVATE: SPREAD_FREQ STRING ""50.000""
+// Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING ""1""
+// Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC ""0""
+// Retrieval info: PRIVATE: USE_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING ""0""
+// Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: USE_CLK1 STRING ""1""
+// Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING ""0""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING ""100.000""
+// Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING ""c0""
+// Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: MEGAFN_PORT_INFO_0 STRING ""inclk;fbin;pllena;clkswitch;areset""
+// Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING ""0""
+// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: CUR_FBIN_CLK STRING ""e0""
+// Retrieval info: PRIVATE: MEGAFN_PORT_INFO_1 STRING ""pfdena;clkena;extclkena;scanclk;scanaclr""
+// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING ""1""
+// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING ""0""
+// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC ""1""
+// Retrieval info: PRIVATE: MEGAFN_PORT_INFO_2 STRING ""scandata;scanread;scanwrite;clk;extclk""
+// Retrieval info: PRIVATE: DIV_FACTOR1 NUMERIC ""1""
+// Retrieval info: PRIVATE: CLKLOSS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING ""1""
+// Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING ""0""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING ""512.000""
+// Retrieval info: PRIVATE: MEGAFN_PORT_INFO_3 STRING ""clkbad;activeclock;locked;clkloss;scandataout""
+// Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING ""KHz""
+// Retrieval info: PRIVATE: PLL_ENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING ""64.000""
+// Retrieval info: PRIVATE: MEGAFN_PORT_INFO_4 STRING ""scandone;sclkout1;sclkout0;enable0;enable1""
+// Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING ""0""
+// Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING ""100.000""
+// Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING ""inclk0""
+// Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: DEV_FAMILY STRING ""Cyclone""
+// Retrieval info: PRIVATE: OUTPUT_FREQ1 STRING ""100.000""
+// Retrieval info: PRIVATE: LOCK_LOSS_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING ""Low""
+// Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: USE_CLKENA0 STRING ""0""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: USE_CLKENA1 STRING ""0""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT1 STRING ""deg""
+// Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING ""0""
+// Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: DEVICE_FAMILY NUMERIC ""11""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: CLK1_DIVIDE_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: CLK1_PHASE_SHIFT STRING ""0""
+// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""altpll""
+// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC ""15625""
+// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: CLK1_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: PLL_TYPE STRING ""AUTO""
+// Retrieval info: CONSTANT: CLK1_MULTIPLY_BY NUMERIC ""2""
+// Retrieval info: CONSTANT: CLK0_TIME_DELAY STRING ""0""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: CONSTANT: OPERATION_MODE STRING ""NORMAL""
+// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING ""CLK0""
+// Retrieval info: CONSTANT: CLK1_TIME_DELAY STRING ""0""
+// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING ""0""
+// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT VCC ""c0""
+// Retrieval info: USED_PORT: @clk 0 0 6 0 OUTPUT VCC ""@clk[5..0]""
+// Retrieval info: USED_PORT: c1 0 0 0 0 OUTPUT VCC ""c1""
+// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT GND ""inclk0""
+// Retrieval info: USED_PORT: @extclk 0 0 4 0 OUTPUT VCC ""@extclk[3..0]""
+// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
+// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
+// Retrieval info: CONNECT: c1 0 0 0 0 @clk 0 0 1 1
+// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL dspclkpll.v TRUE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL dspclkpll.inc FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL dspclkpll.cmp FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL dspclkpll.bsf FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL dspclkpll_inst.v FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL dspclkpll_bb.v TRUE FALSE
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2007 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+`include ""../../../../usrp/firmware/include/fpga_regs_common.v""
+`include ""../../../../usrp/firmware/include/fpga_regs_standard.v""
+
+module sounder_ctrl(clk_i,rst_i,saddr_i,sdata_i,s_strobe_i,
+\t\t reset_o,transmit_o,receive_o,loopback_o,
+\t\t degree_o,ampl_o,mask_o,
+\t\t tx_strobe_o,rx_strobe_o,sum_strobe_o,ref_strobe_o);
+
+ input clk_i; // Master clock @ 64 MHz
+ input rst_i; // Master synchronous reset
+ input [6:0] saddr_i;\t// Configuration bus address
+ input [31:0] sdata_i;\t// Configuration bus data
+ input \t s_strobe_i; // Configuration bus write
+ output \t reset_o;
+ output \t transmit_o;
+ output \t receive_o;
+ output \t loopback_o;
+ output [4:0] degree_o;
+ output [13:0] ampl_o;
+ output [15:0] mask_o;
+ output \t tx_strobe_o;
+ output rx_strobe_o;
+ output sum_strobe_o;
+ output ref_strobe_o;
+
+ setting_reg #(`FR_USER_0) sr_mode
+ ( .clock(clk_i),.reset(1\'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
+ .out({loopback_o,receive_o,transmit_o,reset_o}) );
+
+ setting_reg #(`FR_USER_1) sr_lfsr_degree
+ ( .clock(clk_i),.reset(1\'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
+ .out(degree_o) );
+
+ setting_reg #(`FR_USER_2) sr_lfsr_ampl
+ ( .clock(clk_i),.reset(1\'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
+ .out(ampl_o) );
+
+ wire [16:0] len;
+ lfsr_constants constants
+ (.clk_i(clk_i),.rst_i(rst_i),.degree_i(degree_o),.mask_o(mask_o),
+ .len_o(len) );
+
+ reg [15:0] phase;
+ assign tx_strobe_o = ~phase[0];
+ assign ref_strobe_o = tx_strobe_o & !(phase>>1 == len>>1);
+ assign sum_strobe_o = (phase == len);
+
+ reg \t rx_strobe_o;
+ always @(posedge clk_i)
+ if (rst_i)
+ begin
+\t phase <= #5 16\'hFFFF;
+\t rx_strobe_o <= #5 0;
+ end
+ else
+ if (sum_strobe_o)
+\t begin
+\t phase <= #5 0;
+\t rx_strobe_o <= #5 1\'b1;
+\t end
+ else
+\t begin
+\t phase <= #5 phase + 16\'b1;
+\t rx_strobe_o <= #5 0;
+\t end
+
+
+
+
+
+
+
+
+
+
+endmodule // sounder_ctrl
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003,2004 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+// Top level module for a full setup with DUCs and DDCs
+
+// Define DEBUG_OWNS_IO_PINS if we\'re using the daughterboard i/o pins
+// for debugging info. NB, This can kill the m\'board and/or d\'board if you
+// have anything except basic d\'boards installed.
+
+// Uncomment the following to include optional circuitry
+
+`include ""config.vh""
+`include ""../../../firmware/include/fpga_regs_common.v""
+`include ""../../../firmware/include/fpga_regs_standard.v""
+
+module usrp_std
+(output MYSTERY_SIGNAL,
+ input master_clk,
+ input SCLK,
+ input SDI,
+ inout SDO,
+ input SEN_FPGA,
+
+ input FX2_1,
+ output FX2_2,
+ output FX2_3,
+
+ input wire [11:0] rx_a_a,
+ input wire [11:0] rx_b_a,
+ input wire [11:0] rx_a_b,
+ input wire [11:0] rx_b_b,
+
+ output wire [13:0] tx_a,
+ output wire [13:0] tx_b,
+
+ output wire TXSYNC_A,
+ output wire TXSYNC_B,
+
+ // USB interface
+ input usbclk,
+ input wire [2:0] usbctl,
+ output wire [1:0] usbrdy,
+ inout [15:0] usbdata, // NB Careful, inout
+
+ // These are the general purpose i/o\'s that go to the daughterboard slots
+ inout wire [15:0] io_tx_a,
+ inout wire [15:0] io_tx_b,
+ inout wire [15:0] io_rx_a,
+ inout wire [15:0] io_rx_b
+ );\t
+ wire [15:0] debugdata,debugctrl;
+ assign MYSTERY_SIGNAL = 1\'b0;
+
+ wire clk64,clk128;
+
+ wire WR = usbctl[0];
+ wire RD = usbctl[1];
+ wire OE = usbctl[2];
+
+ wire have_space, have_pkt_rdy;
+ assign usbrdy[0] = have_space;
+ assign usbrdy[1] = have_pkt_rdy;
+
+ wire tx_underrun, rx_overrun;
+ wire clear_status = FX2_1;
+ assign FX2_2 = rx_overrun;
+ assign FX2_3 = tx_underrun;
+
+ wire [15:0] usbdata_out;
+
+ wire [3:0] dac0mux,dac1mux,dac2mux,dac3mux;
+
+ wire tx_realsignals;
+ wire [3:0] rx_numchan;
+ wire [2:0] tx_numchan;
+
+ wire [7:0] interp_rate, decim_rate;
+ wire [31:0] tx_debugbus, rx_debugbus;
+
+ wire enable_tx, enable_rx;
+ wire tx_dsp_reset, rx_dsp_reset, tx_bus_reset, rx_bus_reset;
+ wire [7:0] settings;
+
+ // Tri-state bus macro
+ bustri bustri( .data(usbdata_out),.enabledt(OE),.tridata(usbdata) );
+
+ assign clk64 = master_clk;
+
+ wire [15:0] ch0tx,ch1tx,ch2tx,ch3tx; //,ch4tx,ch5tx,ch6tx,ch7tx;
+ wire [15:0] ch0rx,ch1rx,ch2rx,ch3rx,ch4rx,ch5rx,ch6rx,ch7rx;
+
+ // TX
+ wire [15:0] i_out_0,i_out_1,q_out_0,q_out_1;
+ wire [15:0] bb_tx_i0,bb_tx_q0,bb_tx_i1,bb_tx_q1; // bb_tx_i2,bb_tx_q2,bb_tx_i3,bb_tx_q3;
+
+ wire strobe_interp, tx_sample_strobe;
+ wire tx_empty;
+
+ wire serial_strobe;
+ wire [6:0] serial_addr;
+ wire [31:0] serial_data;
+
+ reg [15:0] debug_counter;
+ reg [15:0] loopback_i_0,loopback_q_0;
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Transmit Side
+`ifdef TX_ON
+ assign bb_tx_i0 = ch0tx;
+ assign bb_tx_q0 = ch1tx;
+ assign bb_tx_i1 = ch2tx;
+ assign bb_tx_q1 = ch3tx;
+
+ tx_buffer tx_buffer
+ ( .usbclk(usbclk), .bus_reset(tx_bus_reset),
+ .usbdata(usbdata),.WR(WR), .have_space(have_space),
+ .tx_underrun(tx_underrun), .clear_status(clear_status),
+ .txclk(clk64), .reset(tx_dsp_reset),
+ .channels({tx_numchan,1\'b0}),
+ .tx_i_0(ch0tx),.tx_q_0(ch1tx),
+ .tx_i_1(ch2tx),.tx_q_1(ch3tx),
+ .txstrobe(strobe_interp),
+ .tx_empty(tx_empty),
+ .debugbus(tx_debugbus) );
+
+ `ifdef TX_EN_0
+ tx_chain tx_chain_0
+ ( .clock(clk64),.reset(tx_dsp_reset),.enable(enable_tx),
+ .interp_rate(interp_rate),.sample_strobe(tx_sample_strobe),
+ .interpolator_strobe(strobe_interp),.freq(),
+ .i_in(bb_tx_i0),.q_in(bb_tx_q0),.i_out(i_out_0),.q_out(q_out_0) );
+ `else
+ assign i_out_0=16\'d0;
+ assign q_out_0=16\'d0;
+ `endif
+
+ `ifdef TX_EN_1
+ tx_chain tx_chain_1
+ ( .clock(clk64),.reset(tx_dsp_reset),.enable(enable_tx),
+ .interp_rate(interp_rate),.sample_strobe(tx_sample_strobe),
+ .interpolator_strobe(strobe_interp),.freq(),
+ .i_in(bb_tx_i1),.q_in(bb_tx_q1),.i_out(i_out_1),.q_out(q_out_1) );
+ `else
+ assign i_out_1=16\'d0;
+ assign q_out_1=16\'d0;
+ `endif
+
+ setting_reg #(`FR_TX_MUX)
+ sr_txmux(.clock(clk64),.reset(tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
+\t .out({dac3mux,dac2mux,dac1mux,dac0mux,tx_realsignals,tx_numchan}));
+
+ wire [15:0] tx_a_a = dac0mux[3] ? (dac0mux[1] ? (dac0mux[0] ? q_out_1 : i_out_1) : (dac0mux[0] ? q_out_0 : i_out_0)) : 16\'b0;
+ wire [15:0] tx_b_a = dac1mux[3] ? (dac1mux[1] ? (dac1mux[0] ? q_out_1 : i_out_1) : (dac1mux[0] ? q_out_0 : i_out_0)) : 16\'b0;
+ wire [15:0] tx_a_b = dac2mux[3] ? (dac2mux[1] ? (dac2mux[0] ? q_out_1 : i_out_1) : (dac2mux[0] ? q_out_0 : i_out_0)) : 16\'b0;
+ wire [15:0] tx_b_b = dac3mux[3] ? (dac3mux[1] ? (dac3mux[0] ? q_out_1 : i_out_1) : (dac3mux[0] ? q_out_0 : i_out_0)) : 16\'b0;
+
+ wire txsync = tx_sample_strobe;
+ assign TXSYNC_A = txsync;
+ assign TXSYNC_B = txsync;
+
+ assign tx_a = txsync ? tx_b_a[15:2] : tx_a_a[15:2];
+ assign tx_b = txsync ? tx_b_b[15:2] : tx_a_b[15:2];
+`endif // `ifdef TX_ON
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Receive Side
+`ifdef RX_ON
+ wire rx_sample_strobe,strobe_decim,hb_strobe;
+ wire [15:0] bb_rx_i0,bb_rx_q0,bb_rx_i1,bb_rx_q1,
+\t bb_rx_i2,bb_rx_q2,bb_rx_i3,bb_rx_q3;
+
+ wire loopback = settings[0];
+ wire counter = settings[1];
+
+ always @(posedge clk64)
+ if(rx_dsp_reset)
+ debug_counter <= #1 16\'d0;
+ else if(~enable_rx)
+ debug_counter <= #1 16\'d0;
+ else if(hb_strobe)
+ debug_counter <=#1 debug_counter + 16\'d2;
+
+ always @(posedge clk64)
+ if(strobe_interp)
+ begin
+\t loopback_i_0 <= #1 ch0tx;
+\t loopback_q_0 <= #1 ch1tx;
+ end
+
+ assign ch0rx = counter ? debug_counter : loopback ? loopback_i_0 : bb_rx_i0;
+ assign ch1rx = counter ? debug_counter + 16\'d1 : loopback ? loopback_q_0 : bb_rx_q0;
+ assign ch2rx = bb_rx_i1;
+ assign ch3rx = bb_rx_q1;
+ assign ch4rx = bb_rx_i2;
+ assign ch5rx = bb_rx_q2;
+ assign ch6rx = bb_rx_i3;
+ assign ch7rx = bb_rx_q3;
+
+ wire [15:0] ddc0_in_i,ddc0_in_q,ddc1_in_i,ddc1_in_q,ddc2_in_i,ddc2_in_q,ddc3_in_i,ddc3_in_q;
+ wire [31:0] rssi_0,rssi_1,rssi_2,rssi_3;
+
+ adc_interface adc_interface(.clock(clk64),.reset(rx_dsp_reset),.enable(1\'b1),
+\t\t\t .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+\t\t\t .rx_a_a(rx_a_a),.rx_b_a(rx_b_a),.rx_a_b(rx_a_b),.rx_b_b(rx_b_b),
+\t\t\t .rssi_0(rssi_0),.rssi_1(rssi_1),.rssi_2(rssi_2),.rssi_3(rssi_3),
+\t\t\t .ddc0_in_i(ddc0_in_i),.ddc0_in_q(ddc0_in_q),
+\t\t\t .ddc1_in_i(ddc1_in_i),.ddc1_in_q(ddc1_in_q),
+\t\t\t .ddc2_in_i(ddc2_in_i),.ddc2_in_q(ddc2_in_q),
+\t\t\t .ddc3_in_i(ddc3_in_i),.ddc3_in_q(ddc3_in_q),.rx_numchan(rx_numchan) );
+
+ rx_buffer rx_buffer
+ ( .usbclk(usbclk),.bus_reset(rx_bus_reset),.reset(rx_dsp_reset),
+ .reset_regs(rx_dsp_reset),
+ .usbdata(usbdata_out),.RD(RD),.have_pkt_rdy(have_pkt_rdy),.rx_overrun(rx_overrun),
+ .channels(rx_numchan),
+ .ch_0(ch0rx),.ch_1(ch1rx),
+ .ch_2(ch2rx),.ch_3(ch3rx),
+ .ch_4(ch4rx),.ch_5(ch5rx),
+ .ch_6(ch6rx),.ch_7(ch7rx),
+ .rxclk(clk64),.rxstrobe(hb_strobe),
+ .clear_status(clear_status),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .debugbus(rx_debugbus) );
+
+ `ifdef RX_EN_0
+ rx_chain #(`FR_RX_FREQ_0,`FR_RX_PHASE_0) rx_chain_0
+ ( .clock(clk64),.reset(1\'b0),.enable(enable_rx),
+ .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(hb_strobe),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .i_in(ddc0_in_i),.q_in(ddc0_in_q),.i_out(bb_rx_i0),.q_out(bb_rx_q0),.debugdata(debugdata),.debugctrl(debugctrl));
+ `else
+ assign bb_rx_i0=16\'d0;
+ assign bb_rx_q0=16\'d0;
+ `endif
+
+ `ifdef RX_EN_1
+ rx_chain #(`FR_RX_FREQ_1,`FR_RX_PHASE_1) rx_chain_1
+ ( .clock(clk64),.reset(1\'b0),.enable(enable_rx),
+ .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .i_in(ddc1_in_i),.q_in(ddc1_in_q),.i_out(bb_rx_i1),.q_out(bb_rx_q1));
+ `else
+ assign bb_rx_i1=16\'d0;
+ assign bb_rx_q1=16\'d0;
+ `endif
+
+ `ifdef RX_EN_2
+ rx_chain #(`FR_RX_FREQ_2,`FR_RX_PHASE_2) rx_chain_2
+ ( .clock(clk64),.reset(1\'b0),.enable(enable_rx),
+ .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .i_in(ddc2_in_i),.q_in(ddc2_in_q),.i_out(bb_rx_i2),.q_out(bb_rx_q2));
+ `else
+ assign bb_rx_i2=16\'d0;
+ assign bb_rx_q2=16\'d0;
+ `endif
+
+ `ifdef RX_EN_3
+ rx_chain #(`FR_RX_FREQ_3,`FR_RX_PHASE_3) rx_chain_3
+ ( .clock(clk64),.reset(1\'b0),.enable(enable_rx),
+ .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .i_in(ddc3_in_i),.q_in(ddc3_in_q),.i_out(bb_rx_i3),.q_out(bb_rx_q3));
+ `else
+ assign bb_rx_i3=16\'d0;
+ assign bb_rx_q3=16\'d0;
+ `endif
+
+`endif // `ifdef RX_ON
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Control Functions
+
+ wire [31:0] capabilities;
+ assign capabilities[7] = `TX_CAP_HB;
+ assign capabilities[6:4] = `TX_CAP_NCHAN;
+ assign capabilities[3] = `RX_CAP_HB;
+ assign capabilities[2:0] = `RX_CAP_NCHAN;
+
+
+ serial_io serial_io
+ ( .master_clk(clk64),.serial_clock(SCLK),.serial_data_in(SDI),
+ .enable(SEN_FPGA),.reset(1\'b0),.serial_data_out(SDO),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .readback_0({io_rx_a,io_tx_a}),.readback_1({io_rx_b,io_tx_b}),.readback_2(capabilities),.readback_3(32\'hf0f0931a),
+ .readback_4(rssi_0),.readback_5(rssi_1),.readback_6(rssi_2),.readback_7(rssi_3)
+ );
+
+ wire [15:0] reg_0,reg_1,reg_2,reg_3;
+ master_control master_control
+ ( .master_clk(clk64),.usbclk(usbclk),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .tx_bus_reset(tx_bus_reset),.rx_bus_reset(rx_bus_reset),
+ .tx_dsp_reset(tx_dsp_reset),.rx_dsp_reset(rx_dsp_reset),
+ .enable_tx(enable_tx),.enable_rx(enable_rx),
+ .interp_rate(interp_rate),.decim_rate(decim_rate),
+ .tx_sample_strobe(tx_sample_strobe),.strobe_interp(strobe_interp),
+ .rx_sample_strobe(rx_sample_strobe),.strobe_decim(strobe_decim),
+ .tx_empty(tx_empty),
+ //.debug_0(rx_a_a),.debug_1(ddc0_in_i),
+ .debug_0(tx_debugbus[15:0]),.debug_1(tx_debugbus[31:16]),
+ .debug_2(rx_debugbus[15:0]),.debug_3(rx_debugbus[31:16]),
+ .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3) );
+
+ io_pins io_pins
+ (.io_0(io_tx_a),.io_1(io_rx_a),.io_2(io_tx_b),.io_3(io_rx_b),
+ .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3),
+ .clock(clk64),.rx_reset(rx_dsp_reset),.tx_reset(tx_dsp_reset),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe));
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Misc Settings
+ setting_reg #(`FR_MODE) sr_misc(.clock(clk64),.reset(rx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(settings));
+
+endmodule // usrp_std
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2007 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+module cordic_nco(clk_i,rst_i,ena_i,strobe_i,ampl_i,freq_i,phs_i,data_i_o,data_q_o);
+ input clk_i;
+ input rst_i;
+ input ena_i;
+ input strobe_i;
+
+ input [15:0] ampl_i;
+ input [31:0] freq_i;
+ input [31:0] phs_i;
+
+ output [15:0] data_i_o;
+ output [15:0] data_q_o;
+
+ reg [31:0] phase_reg;
+ wire [31:0] phase = phase_reg + phs_i;
+ wire [15:0] ampl;
+
+ always @(posedge clk_i)
+ begin
+\tif (rst_i | ~ena_i)
+\t phase_reg <= 32'b0;
+\telse if (strobe_i)
+\t phase_reg <= phase_reg + freq_i;
+ end
+
+ assign ampl = ena_i ? ampl_i : 16'b0;
+
+ cordic tx_cordic
+ (.clock(clk_i),.reset(rst_i),.enable(strobe_i),
+ .xi(ampl),.yi(16'b0),.zi(phase[31:16]),
+ .xo(data_i_o),.yo(data_q_o),.zo());
+\t
+endmodule // cordic_nco
+"
+"//
+// This file is machine generated from fpga_regs_standard.h
+// Do not edit by hand; your edits will be overwritten.
+//
+
+// Register numbers 0 to 31 are reserved for use in fpga_regs_common.h.
+// Registers 64 to 79 are available for custom FPGA builds.
+
+
+// DDC / DUC
+
+`define FR_INTERP_RATE 7'd32\t// [1,1024]
+`define FR_DECIM_RATE 7'd33\t// [1,256]
+
+// DDC center freq
+
+`define FR_RX_FREQ_0 7'd34
+`define FR_RX_FREQ_1 7'd35
+`define FR_RX_FREQ_2 7'd36
+`define FR_RX_FREQ_3 7'd37
+
+// See below for DDC Starting Phase
+
+// ------------------------------------------------------------------------
+// configure FPGA Rx mux
+//
+// 3 2 1
+// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+// +-----------------------+-------+-------+-------+-------+-+-----+
+// | must be zero | Q3| I3| Q2| I2| Q1| I1| Q0| I0|Z| NCH |
+// +-----------------------+-------+-------+-------+-------+-+-----+
+//
+// There are a maximum of 4 digital downconverters in the the FPGA.
+// Each DDC has two 16-bit inputs, I and Q, and two 16-bit outputs, I & Q.
+//
+// DDC I inputs are specified by the two bit fields I3, I2, I1 & I0
+//
+// 0 = DDC input is from ADC 0
+// 1 = DDC input is from ADC 1
+// 2 = DDC input is from ADC 2
+// 3 = DDC input is from ADC 3
+//
+// If Z == 1, all DDC Q inputs are set to zero
+// If Z == 0, DDC Q inputs are specified by the two bit fields Q3, Q2, Q1 & Q0
+//
+// NCH specifies the number of complex channels that are sent across
+// the USB. The legal values are 1, 2 or 4, corresponding to 2, 4 or
+// 8 16-bit values.
+
+`define FR_RX_MUX 7'd38
+
+// ------------------------------------------------------------------------
+// configure FPGA Tx Mux.
+//
+// 3 2 1
+// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+// +-----------------------+-------+-------+-------+-------+-+-----+
+// | | DAC3 | DAC2 | DAC1 | DAC0 |0| NCH |
+// +-----------------------------------------------+-------+-+-----+
+//
+// NCH specifies the number of complex channels that are sent across
+// the USB. The legal values are 1 or 2, corresponding to 2 or 4
+// 16-bit values.
+//
+// There are two interpolators with complex inputs and outputs.
+// There are four DACs. (We use the DUC in each AD9862.)
+//
+// Each 4-bit DACx field specifies the source for the DAC and
+// whether or not that DAC is enabled. Each subfield is coded
+// like this:
+//
+// 3 2 1 0
+// +-+-----+
+// |E| N |
+// +-+-----+
+//
+// Where E is set if the DAC is enabled, and N specifies which
+// interpolator output is connected to this DAC.
+//
+// N which interp output
+// --- -------------------
+// 0 chan 0 I
+// 1 chan 0 Q
+// 2 chan 1 I
+// 3 chan 1 Q
+
+`define FR_TX_MUX 7'd39
+
+// ------------------------------------------------------------------------
+// REFCLK control
+//
+// Control whether a reference clock is sent to the daughterboards,
+// and what frequency. The refclk is sent on d'board i/o pin 0.
+//
+// 3 2 1
+// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+// +-----------------------------------------------+-+------------+
+// | Reserved (Must be zero) |E| DIVISOR |
+// +-----------------------------------------------+-+------------+
+
+//
+// Bit 7 -- 1 turns on refclk, 0 allows IO use
+// Bits 6:0 Divider value
+
+`define FR_TX_A_REFCLK 7'd40
+`define FR_RX_A_REFCLK 7'd41
+`define FR_TX_B_REFCLK 7'd42
+`define FR_RX_B_REFCLK 7'd43
+
+
+// ------------------------------------------------------------------------
+// DDC Starting Phase
+
+`define FR_RX_PHASE_0 7'd44
+`define FR_RX_PHASE_1 7'd45
+`define FR_RX_PHASE_2 7'd46
+`define FR_RX_PHASE_3 7'd47
+
+// ------------------------------------------------------------------------
+// Tx data format control register
+//
+// 3 2 1
+// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+// +-------------------------------------------------------+-------+
+// | Reserved (Must be zero) | FMT |
+// +-------------------------------------------------------+-------+
+//
+// FMT values:
+
+`define FR_TX_FORMAT 7'd48
+
+// ------------------------------------------------------------------------
+// Rx data format control register
+//
+// 3 2 1
+// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+// +-----------------------------------------+-+-+---------+-------+
+// | Reserved (Must be zero) |B|Q| WIDTH | SHIFT |
+// +-----------------------------------------+-+-+---------+-------+
+//
+// FMT values:
+
+`define FR_RX_FORMAT 7'd49
+
+
+// The valid combinations currently are:
+//
+// B Q WIDTH SHIFT
+// 0 1 16 0
+// 0 1 8 8
+
+
+// Possible future values of WIDTH = {4, 2, 1}
+// 12 takes a bit more work, since we need to know packet alignment.
+
+// ------------------------------------------------------------------------
+// FIXME register numbers 50 to 63 are available
+
+// ------------------------------------------------------------------------
+// Registers 64 to 95 are reserved for user custom FPGA builds.
+// The standard USRP software will not touch these.
+
+`define FR_USER_0 7'd64
+`define FR_USER_1 7'd65
+`define FR_USER_2 7'd66
+`define FR_USER_3 7'd67
+`define FR_USER_4 7'd68
+`define FR_USER_5 7'd69
+`define FR_USER_6 7'd70
+`define FR_USER_7 7'd71
+`define FR_USER_8 7'd72
+`define FR_USER_9 7'd73
+`define FR_USER_10 7'd74
+`define FR_USER_11 7'd75
+`define FR_USER_12 7'd76
+`define FR_USER_13 7'd77
+`define FR_USER_14 7'd78
+`define FR_USER_15 7'd79
+`define FR_USER_16 7'd80
+`define FR_USER_17 7'd81
+`define FR_USER_18 7'd82
+`define FR_USER_19 7'd83
+`define FR_USER_20 7'd84
+`define FR_USER_21 7'd85
+`define FR_USER_22 7'd86
+`define FR_USER_23 7'd87
+`define FR_USER_24 7'd88
+`define FR_USER_25 7'd89
+`define FR_USER_26 7'd90
+`define FR_USER_27 7'd91
+`define FR_USER_28 7'd92
+`define FR_USER_29 7'd93
+`define FR_USER_30 7'd94
+`define FR_USER_31 7'd95
+
+//Registers needed for multi usrp master/slave configuration
+//
+//Rx Master/slave control register (FR_RX_MASTER_SLAVE = FR_USER_0)
+//
+`define FR_RX_MASTER_SLAVE 7'd64
+`define bitnoFR_RX_SYNC 0
+`define bitnoFR_RX_SYNC_MASTER 1
+`define bitnoFR_RX_SYNC_SLAVE 2
+
+
+//Caution The master settings will output values on the io lines.
+//They inheritely enable these lines as output. If you have a daughtercard which uses these lines also as output then you will burn your usrp and daughtercard.
+//If you set the slave bits then your usrp won't do anything if you don't connect a master.
+// Rx Master/slave control register
+//
+// The way this is supposed to be used is connecting a (short) 16pin flatcable from an rx daughterboard in RXA master io_rx[8..15] to slave io_rx[8..15] on RXA of slave usrp
+// This can be done with basic_rx boards or dbsrx boards
+//dbsrx: connect master-J25 to slave-J25
+//basic rx: connect J25 to slave-J25
+//CAUTION: pay attention to the lineup of your connector.
+//The red line (pin1) should be at the same side of the daughterboards on master and slave.
+//If you turnaround the cable on one end you will burn your usrp.
+
+//You cannot use a 16pin flatcable if you are using FLEX400 or FLEX2400 daughterboards, since these use a lot of the io pins.
+//You can still link them but you must use only a 2pin or 1pin cable
+//You can also use a 2-wire link. put a 2pin header on io[15],gnd of the master RXA daughterboard and connect it to io15,gnd of the slave RXA db.
+//You can use a cable like the ones found with the leds on the mainbord of a PC.
+//Make sure you don't twist the cable, otherwise you connect the sync output to ground.
+//To be save you could also just use a single wire from master io[15] to slave io[15], but this is not optimal for signal integrity.
+
+
+// Since rx_io[0] can normally be used as a refclk and is not exported on all daughterboards this line
+// still has the refclk function if you use the master/slave setup (it is not touched by the master/slave settings).
+// The master/slave circuitry will only use io pin 15 and does not touch any of the other io pins.
+`define bitnoFR_RX_SYNC_INPUT_IOPIN 15
+`define bmFR_RX_SYNC_INPUT_IOPIN (1< TXA [15:0]
+ // 31:16 usbclk domain => RXA [15:0]
+
+ assign debugbus[0] = reset;
+ assign debugbus[1] = txstrobe;
+ assign debugbus[2] = rdreq;
+ assign debugbus[6:3] = phase;
+ assign debugbus[7] = tx_empty;
+ assign debugbus[8] = tx_underrun_dsp;
+ assign debugbus[9] = iq_f;
+ assign debugbus[10] = sop_f;
+ assign debugbus[14:11] = 0;
+ assign debugbus[15] = txclk;
+\t
+ assign debugbus[16] = bus_reset;
+ assign debugbus[17] = WR;
+ assign debugbus[18] = wr_reg;
+ assign debugbus[19] = have_space;
+ assign debugbus[20] = write_count[8];
+ assign debugbus[21] = write_count[0];
+ assign debugbus[22] = sop;
+ assign debugbus[23] = tx_underrun;
+ assign debugbus[30:24] = 0;
+ assign debugbus[31] = usbclk;
+
+endmodule // tx_buffer
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+module gen_sync
+ ( input clock,
+ input reset,
+ input enable,
+ input [7:0] rate,
+ output wire sync );
+
+// parameter width = 8;
+
+ reg [7:0] counter;
+ assign sync = |(((rate+1)>>1)& counter);
+
+ always @(posedge clock)
+ if(reset || ~enable)
+ counter <= #1 0;
+ else if(counter == rate)
+ counter <= #1 0;
+ else
+ counter <= #1 counter + 8'd1;
+
+endmodule // gen_sync
+
+"
+"
+
+module ram64 (input clock, input write,
+\t input [5:0] wr_addr, input [15:0] wr_data,
+\t input [5:0] rd_addr, output reg [15:0] rd_data);
+
+ reg [15:0] \t\tram_array [0:63];
+
+ always @(posedge clock)
+ rd_data <= #1 ram_array[rd_addr];
+
+ always @(posedge clock)
+ if(write)
+ ram_array[wr_addr] <= #1 wr_data;
+
+endmodule // ram64
+"
+"
+
+module test_hbd();
+
+ reg clock;
+ initial clock = 1\'b0;
+ always #5 clock <= ~clock;
+
+ reg reset;
+ initial reset = 1\'b1;
+ initial #1000 reset = 1\'b0;
+
+ initial $dumpfile(""test_hbd.vcd"");
+ initial $dumpvars(0,test_hbd);
+
+ reg [15:0] i_in, q_in;
+ wire [15:0] i_out, q_out;
+
+ reg \t strobe_in;
+ wire strobe_out;
+ reg \t coeff_write;
+ reg [15:0] coeff_data;
+ reg [4:0] coeff_addr;
+
+ halfband_decim halfband_decim
+ ( .clock(clock),.reset(reset),.enable(),.strobe_in(strobe_in),.strobe_out(strobe_out),
+ .data_in(i_in),.data_out(i_out) );
+
+ always @(posedge strobe_out)
+ if(i_out[15])
+ $display(""-%d"",65536-i_out);
+ else
+ $display(""%d"",i_out);
+
+ initial
+ begin
+\tstrobe_in = 1\'b0;
+\t@(negedge reset);
+\t@(posedge clock);
+\twhile(1)
+\t begin
+\t strobe_in <= #1 1\'b1;
+\t @(posedge clock);
+\t strobe_in <= #1 1\'b0;
+\t repeat (`RATE)
+\t @(posedge clock);
+\t end
+ end
+
+ initial #10000000 $finish; // Just in case...
+
+ initial
+ begin
+\ti_in <= #1 16\'d0;
+\trepeat (40) @(posedge strobe_in);
+\ti_in <= #1 16\'d16384;
+\t@(posedge strobe_in);
+\ti_in <= #1 16\'d0;
+\trepeat (40) @(posedge strobe_in);
+\ti_in <= #1 16\'d16384;
+\t@(posedge strobe_in);
+\ti_in <= #1 16\'d0;
+\trepeat (40) @(posedge strobe_in);
+\ti_in <= #1 16\'d16384;
+\trepeat (40) @(posedge strobe_in);
+\ti_in <= #1 16\'d0;
+\trepeat (41) @(posedge strobe_in);
+\ti_in <= #1 16\'d16384;
+\trepeat (40) @(posedge strobe_in);
+\ti_in <= #1 16\'d0;
+\trepeat (40) @(posedge strobe_in);
+\trepeat (7) @(posedge clock);
+\t$finish;
+ end // initial begin
+endmodule // test_hb
+"
+"//Copyright (C) 1991-2004 Altera Corporation
+//Any megafunction design, and related netlist (encrypted or decrypted),
+//support information, device programming or simulation file, and any other
+//associated documentation or information provided by Altera or a partner
+//under Altera's Megafunction Partnership Program may be used only
+//to program PLD devices (but not masked PLD devices) from Altera. Any
+//other use of such megafunction design, netlist, support information,
+//device programming or simulation file, or any other related documentation
+//or information is prohibited for any other purpose, including, but not
+//limited to modification, reverse engineering, de-compiling, or use with
+//any other silicon devices, unless such use is explicitly licensed under
+//a separate agreement with Altera or a megafunction partner. Title to the
+//intellectual property, including patents, copyrights, trademarks, trade
+//secrets, or maskworks, embodied in any such megafunction design, netlist,
+//support information, device programming or simulation file, or any other
+//related documentation or information provided by Altera or a megafunction
+//partner, remains with Altera, the megafunction partner, or their respective
+//licensors. No other licenses, including any licenses needed under any third
+//party's intellectual property, are provided herein.
+
+module pll (
+\tinclk0,
+\tc0);
+
+\tinput\t inclk0;
+\toutput\t c0;
+
+endmodule
+
+"
+"
+
+module fifo_2k
+ ( input [15:0] data,
+ input \twrreq,
+ input \trdreq,
+ input \trdclk,
+ input \twrclk,
+ input \taclr,
+ output [15:0] q,
+ output \t rdfull,
+ output \t rdempty,
+ output [10:0] rdusedw,
+ output \t wrfull,
+ output \t wrempty,
+ output [10:0] wrusedw
+ );
+
+fifo #(.width(16),.depth(2048),.addr_bits(11)) fifo_2k
+ ( data, wrreq, rdreq, rdclk, wrclk, aclr, q,
+ rdfull, rdempty, rdusedw, wrfull, wrempty, wrusedw);
+
+endmodule // fifo_1k
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+module rx_chain_dual
+ (input clock,
+ input clock_2x,
+ input reset,
+ input enable,
+ input wire [7:0] decim_rate,
+ input sample_strobe,
+ input decimator_strobe,
+ input wire [31:0] freq0,
+ input wire [15:0] i_in0,
+ input wire [15:0] q_in0,
+ output wire [15:0] i_out0,
+ output wire [15:0] q_out0,
+ input wire [31:0] freq1,
+ input wire [15:0] i_in1,
+ input wire [15:0] q_in1,
+ output wire [15:0] i_out1,
+ output wire [15:0] q_out1
+ );
+
+ wire [15:0] phase;
+ wire [15:0] bb_i, bb_q;
+ wire [15:0] i_in, q_in;
+
+ wire [31:0] phase0;
+ wire [31:0] phase1;
+ reg [15:0] bb_i0, bb_q0;
+ reg [15:0] bb_i1, bb_q1;
+
+ // We want to time-share the CORDIC by double-clocking it
+
+ phase_acc rx_phase_acc_0
+ (.clk(clock),.reset(reset),.enable(enable),
+ .strobe(sample_strobe),.freq(freq0),.phase(phase0) );
+
+ phase_acc rx_phase_acc_1
+ (.clk(clock),.reset(reset),.enable(enable),
+ .strobe(sample_strobe),.freq(freq1),.phase(phase1) );
+
+ assign phase = clock ? phase0[31:16] : phase1[31:16];
+ assign i_in = clock ? i_in0 : i_in1;
+ assign q_in = clock ? q_in0 : q_in1;
+
+// This appears reversed because of the number of CORDIC stages
+ always @(posedge clock_2x)
+ if(clock)
+ begin
+\t bb_i1 <= #1 bb_i;
+\t bb_q1 <= #1 bb_q;
+ end
+ else
+ begin
+\t bb_i0 <= #1 bb_i;
+\t bb_q0 <= #1 bb_q;
+ end
+\t
+ cordic rx_cordic
+ ( .clock(clock_2x),.reset(reset),.enable(enable),
+ .xi(i_in),.yi(q_in),.zi(phase),
+ .xo(bb_i),.yo(bb_q),.zo() );
+
+ cic_decim cic_decim_i_0
+ ( .clock(clock),.reset(reset),.enable(enable),
+ .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe),
+ .signal_in(bb_i0),.signal_out(i_out0) );
+
+ cic_decim cic_decim_q_0
+ ( .clock(clock),.reset(reset),.enable(enable),
+ .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe),
+ .signal_in(bb_q0),.signal_out(q_out0) );
+
+ cic_decim cic_decim_i_1
+ ( .clock(clock),.reset(reset),.enable(enable),
+ .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe),
+ .signal_in(bb_i1),.signal_out(i_out1) );
+
+ cic_decim cic_decim_q_1
+ ( .clock(clock),.reset(reset),.enable(enable),
+ .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe),
+ .signal_in(bb_q1),.signal_out(q_out1) );
+
+endmodule // rx_chain
+"
+"// megafunction wizard: %FIFO%CBX%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: dcfifo
+
+// ============================================================
+// File Name: fifo_2k.v
+// Megafunction Name(s):
+// \t\t\tdcfifo
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 5.0 Build 168 06/22/2005 SP 1 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2005 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+//dcfifo ADD_RAM_OUTPUT_REGISTER=""OFF"" CLOCKS_ARE_SYNCHRONIZED=""FALSE"" DEVICE_FAMILY=""Cyclone"" LPM_NUMWORDS=2048 LPM_SHOWAHEAD=""ON"" LPM_WIDTH=16 LPM_WIDTHU=11 OVERFLOW_CHECKING=""OFF"" UNDERFLOW_CHECKING=""OFF"" USE_EAB=""ON"" aclr data q rdclk rdempty rdreq rdusedw wrclk wrfull wrreq wrusedw
+//VERSION_BEGIN 5.0 cbx_a_gray2bin 2004:03:06:00:52:20:SJ cbx_a_graycounter 2004:10:01:12:13:16:SJ cbx_altdpram 2004:11:30:11:29:56:SJ cbx_altsyncram 2005:03:24:13:58:56:SJ cbx_cycloneii 2004:12:20:14:28:52:SJ cbx_dcfifo 2005:03:07:17:11:14:SJ cbx_fifo_common 2004:12:13:14:26:24:SJ cbx_flex10ke 2002:10:18:16:54:38:SJ cbx_lpm_add_sub 2005:04:12:13:30:42:SJ cbx_lpm_compare 2004:11:30:11:30:40:SJ cbx_lpm_counter 2005:02:02:04:37:10:SJ cbx_lpm_decode 2004:12:13:14:19:12:SJ cbx_lpm_mux 2004:12:13:14:16:38:SJ cbx_mgl 2005:05:19:13:51:58:SJ cbx_scfifo 2005:03:10:10:52:20:SJ cbx_stratix 2005:06:02:09:53:04:SJ cbx_stratixii 2004:12:22:13:27:12:SJ cbx_util_mgl 2005:04:04:13:50:06:SJ VERSION_END
+
+
+//a_gray2bin device_family=""Cyclone"" WIDTH=11 bin gray
+//VERSION_BEGIN 5.0 cbx_a_gray2bin 2004:03:06:00:52:20:SJ cbx_mgl 2005:05:19:13:51:58:SJ VERSION_END
+
+//synthesis_resources =
+//synopsys translate_off
+`timescale 1 ps / 1 ps
+//synopsys translate_on
+module fifo_2k_a_gray2bin_8m4
+\t(
+\tbin,
+\tgray) /* synthesis synthesis_clearbox=1 */;
+\toutput [10:0] bin;
+\tinput [10:0] gray;
+
+\twire xor0;
+\twire xor1;
+\twire xor2;
+\twire xor3;
+\twire xor4;
+\twire xor5;
+\twire xor6;
+\twire xor7;
+\twire xor8;
+\twire xor9;
+
+\tassign
+\t\tbin = {gray[10], xor9, xor8, xor7, xor6, xor5, xor4, xor3, xor2, xor1, xor0},
+\t\txor0 = (gray[0] ^ xor1),
+\t\txor1 = (gray[1] ^ xor2),
+\t\txor2 = (gray[2] ^ xor3),
+\t\txor3 = (gray[3] ^ xor4),
+\t\txor4 = (gray[4] ^ xor5),
+\t\txor5 = (gray[5] ^ xor6),
+\t\txor6 = (gray[6] ^ xor7),
+\t\txor7 = (gray[7] ^ xor8),
+\t\txor8 = (gray[8] ^ xor9),
+\t\txor9 = (gray[10] ^ gray[9]);
+endmodule //fifo_2k_a_gray2bin_8m4
+
+
+//a_graycounter DEVICE_FAMILY=""Cyclone"" WIDTH=11 aclr clock cnt_en q
+//VERSION_BEGIN 5.0 cbx_a_gray2bin 2004:03:06:00:52:20:SJ cbx_a_graycounter 2004:10:01:12:13:16:SJ cbx_cycloneii 2004:12:20:14:28:52:SJ cbx_flex10ke 2002:10:18:16:54:38:SJ cbx_mgl 2005:05:19:13:51:58:SJ cbx_stratix 2005:06:02:09:53:04:SJ cbx_stratixii 2004:12:22:13:27:12:SJ VERSION_END
+
+//synthesis_resources = lut 12
+//synopsys translate_off
+`timescale 1 ps / 1 ps
+//synopsys translate_on
+module fifo_2k_a_graycounter_726
+\t(
+\taclr,
+\tclock,
+\tcnt_en,
+\tq) /* synthesis synthesis_clearbox=1 */;
+\tinput aclr;
+\tinput clock;
+\tinput cnt_en;
+\toutput [10:0] q;
+
+\twire [0:0] wire_countera_0cout;
+\twire [0:0] wire_countera_1cout;
+\twire [0:0] wire_countera_2cout;
+\twire [0:0] wire_countera_3cout;
+\twire [0:0] wire_countera_4cout;
+\twire [0:0] wire_countera_5cout;
+\twire [0:0] wire_countera_6cout;
+\twire [0:0] wire_countera_7cout;
+\twire [0:0] wire_countera_8cout;
+\twire [0:0] wire_countera_9cout;
+\twire [10:0] wire_countera_regout;
+\twire wire_parity_cout;
+\twire wire_parity_regout;
+\twire [10:0] power_modified_counter_values;
+\twire sclr;
+\twire updown;
+
+\tcyclone_lcell countera_0
+\t(
+\t.aclr(aclr),
+\t.cin(wire_parity_cout),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_0cout[0:0]),
+\t.dataa(cnt_en),
+\t.datab(wire_countera_regout[0:0]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[0:0]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_0.cin_used = ""true"",
+\t\tcountera_0.lut_mask = ""c6a0"",
+\t\tcountera_0.operation_mode = ""arithmetic"",
+\t\tcountera_0.sum_lutc_input = ""cin"",
+\t\tcountera_0.synch_mode = ""on"",
+\t\tcountera_0.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_1
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_0cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_1cout[0:0]),
+\t.dataa(power_modified_counter_values[0]),
+\t.datab(power_modified_counter_values[1]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[1:1]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_1.cin_used = ""true"",
+\t\tcountera_1.lut_mask = ""6c50"",
+\t\tcountera_1.operation_mode = ""arithmetic"",
+\t\tcountera_1.sum_lutc_input = ""cin"",
+\t\tcountera_1.synch_mode = ""on"",
+\t\tcountera_1.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_2
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_1cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_2cout[0:0]),
+\t.dataa(power_modified_counter_values[1]),
+\t.datab(power_modified_counter_values[2]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[2:2]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_2.cin_used = ""true"",
+\t\tcountera_2.lut_mask = ""6c50"",
+\t\tcountera_2.operation_mode = ""arithmetic"",
+\t\tcountera_2.sum_lutc_input = ""cin"",
+\t\tcountera_2.synch_mode = ""on"",
+\t\tcountera_2.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_3
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_2cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_3cout[0:0]),
+\t.dataa(power_modified_counter_values[2]),
+\t.datab(power_modified_counter_values[3]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[3:3]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_3.cin_used = ""true"",
+\t\tcountera_3.lut_mask = ""6c50"",
+\t\tcountera_3.operation_mode = ""arithmetic"",
+\t\tcountera_3.sum_lutc_input = ""cin"",
+\t\tcountera_3.synch_mode = ""on"",
+\t\tcountera_3.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_4
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_3cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_4cout[0:0]),
+\t.dataa(power_modified_counter_values[3]),
+\t.datab(power_modified_counter_values[4]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[4:4]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_4.cin_used = ""true"",
+\t\tcountera_4.lut_mask = ""6c50"",
+\t\tcountera_4.operation_mode = ""arithmetic"",
+\t\tcountera_4.sum_lutc_input = ""cin"",
+\t\tcountera_4.synch_mode = ""on"",
+\t\tcountera_4.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_5
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_4cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_5cout[0:0]),
+\t.dataa(power_modified_counter_values[4]),
+\t.datab(power_modified_counter_values[5]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[5:5]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_5.cin_used = ""true"",
+\t\tcountera_5.lut_mask = ""6c50"",
+\t\tcountera_5.operation_mode = ""arithmetic"",
+\t\tcountera_5.sum_lutc_input = ""cin"",
+\t\tcountera_5.synch_mode = ""on"",
+\t\tcountera_5.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_6
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_5cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_6cout[0:0]),
+\t.dataa(power_modified_counter_values[5]),
+\t.datab(power_modified_counter_values[6]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[6:6]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_6.cin_used = ""true"",
+\t\tcountera_6.lut_mask = ""6c50"",
+\t\tcountera_6.operation_mode = ""arithmetic"",
+\t\tcountera_6.sum_lutc_input = ""cin"",
+\t\tcountera_6.synch_mode = ""on"",
+\t\tcountera_6.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_7
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_6cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_7cout[0:0]),
+\t.dataa(power_modified_counter_values[6]),
+\t.datab(power_modified_counter_values[7]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[7:7]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_7.cin_used = ""true"",
+\t\tcountera_7.lut_mask = ""6c50"",
+\t\tcountera_7.operation_mode = ""arithmetic"",
+\t\tcountera_7.sum_lutc_input = ""cin"",
+\t\tcountera_7.synch_mode = ""on"",
+\t\tcountera_7.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_8
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_7cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_8cout[0:0]),
+\t.dataa(power_modified_counter_values[7]),
+\t.datab(power_modified_counter_values[8]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[8:8]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_8.cin_used = ""true"",
+\t\tcountera_8.lut_mask = ""6c50"",
+\t\tcountera_8.operation_mode = ""arithmetic"",
+\t\tcountera_8.sum_lutc_input = ""cin"",
+\t\tcountera_8.synch_mode = ""on"",
+\t\tcountera_8.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_9
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_8cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_9cout[0:0]),
+\t.dataa(power_modified_counter_values[8]),
+\t.datab(power_modified_counter_values[9]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[9:9]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_9.cin_used = ""true"",
+\t\tcountera_9.lut_mask = ""6c50"",
+\t\tcountera_9.operation_mode = ""arithmetic"",
+\t\tcountera_9.sum_lutc_input = ""cin"",
+\t\tcountera_9.synch_mode = ""on"",
+\t\tcountera_9.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_10
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_9cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(),
+\t.dataa(power_modified_counter_values[10]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[10:10]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datab(1\'b1),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_10.cin_used = ""true"",
+\t\tcountera_10.lut_mask = ""5a5a"",
+\t\tcountera_10.operation_mode = ""normal"",
+\t\tcountera_10.sum_lutc_input = ""cin"",
+\t\tcountera_10.synch_mode = ""on"",
+\t\tcountera_10.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell parity
+\t(
+\t.aclr(aclr),
+\t.cin(updown),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_parity_cout),
+\t.dataa(cnt_en),
+\t.datab(wire_parity_regout),
+\t.ena(1\'b1),
+\t.regout(wire_parity_regout),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tparity.cin_used = ""true"",
+\t\tparity.lut_mask = ""6682"",
+\t\tparity.operation_mode = ""arithmetic"",
+\t\tparity.synch_mode = ""on"",
+\t\tparity.lpm_type = ""cyclone_lcell"";
+\tassign
+\t\tpower_modified_counter_values = {wire_countera_regout[10:0]},
+\t\tq = power_modified_counter_values,
+\t\tsclr = 1\'b0,
+\t\tupdown = 1\'b1;
+endmodule //fifo_2k_a_graycounter_726
+
+
+//a_graycounter DEVICE_FAMILY=""Cyclone"" PVALUE=1 WIDTH=11 aclr clock cnt_en q
+//VERSION_BEGIN 5.0 cbx_a_gray2bin 2004:03:06:00:52:20:SJ cbx_a_graycounter 2004:10:01:12:13:16:SJ cbx_cycloneii 2004:12:20:14:28:52:SJ cbx_flex10ke 2002:10:18:16:54:38:SJ cbx_mgl 2005:05:19:13:51:58:SJ cbx_stratix 2005:06:02:09:53:04:SJ cbx_stratixii 2004:12:22:13:27:12:SJ VERSION_END
+
+//synthesis_resources = lut 12
+//synopsys translate_off
+`timescale 1 ps / 1 ps
+//synopsys translate_on
+module fifo_2k_a_graycounter_2r6
+\t(
+\taclr,
+\tclock,
+\tcnt_en,
+\tq) /* synthesis synthesis_clearbox=1 */;
+\tinput aclr;
+\tinput clock;
+\tinput cnt_en;
+\toutput [10:0] q;
+
+\twire [0:0] wire_countera_0cout;
+\twire [0:0] wire_countera_1cout;
+\twire [0:0] wire_countera_2cout;
+\twire [0:0] wire_countera_3cout;
+\twire [0:0] wire_countera_4cout;
+\twire [0:0] wire_countera_5cout;
+\twire [0:0] wire_countera_6cout;
+\twire [0:0] wire_countera_7cout;
+\twire [0:0] wire_countera_8cout;
+\twire [0:0] wire_countera_9cout;
+\twire [10:0] wire_countera_regout;
+\twire wire_parity_cout;
+\twire wire_parity_regout;
+\twire [10:0] power_modified_counter_values;
+\twire sclr;
+\twire updown;
+
+\tcyclone_lcell countera_0
+\t(
+\t.aclr(aclr),
+\t.cin(wire_parity_cout),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_0cout[0:0]),
+\t.dataa(cnt_en),
+\t.datab(wire_countera_regout[0:0]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[0:0]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_0.cin_used = ""true"",
+\t\tcountera_0.lut_mask = ""c6a0"",
+\t\tcountera_0.operation_mode = ""arithmetic"",
+\t\tcountera_0.sum_lutc_input = ""cin"",
+\t\tcountera_0.synch_mode = ""on"",
+\t\tcountera_0.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_1
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_0cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_1cout[0:0]),
+\t.dataa(power_modified_counter_values[0]),
+\t.datab(power_modified_counter_values[1]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[1:1]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_1.cin_used = ""true"",
+\t\tcountera_1.lut_mask = ""6c50"",
+\t\tcountera_1.operation_mode = ""arithmetic"",
+\t\tcountera_1.sum_lutc_input = ""cin"",
+\t\tcountera_1.synch_mode = ""on"",
+\t\tcountera_1.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_2
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_1cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_2cout[0:0]),
+\t.dataa(power_modified_counter_values[1]),
+\t.datab(power_modified_counter_values[2]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[2:2]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_2.cin_used = ""true"",
+\t\tcountera_2.lut_mask = ""6c50"",
+\t\tcountera_2.operation_mode = ""arithmetic"",
+\t\tcountera_2.sum_lutc_input = ""cin"",
+\t\tcountera_2.synch_mode = ""on"",
+\t\tcountera_2.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_3
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_2cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_3cout[0:0]),
+\t.dataa(power_modified_counter_values[2]),
+\t.datab(power_modified_counter_values[3]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[3:3]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_3.cin_used = ""true"",
+\t\tcountera_3.lut_mask = ""6c50"",
+\t\tcountera_3.operation_mode = ""arithmetic"",
+\t\tcountera_3.sum_lutc_input = ""cin"",
+\t\tcountera_3.synch_mode = ""on"",
+\t\tcountera_3.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_4
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_3cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_4cout[0:0]),
+\t.dataa(power_modified_counter_values[3]),
+\t.datab(power_modified_counter_values[4]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[4:4]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_4.cin_used = ""true"",
+\t\tcountera_4.lut_mask = ""6c50"",
+\t\tcountera_4.operation_mode = ""arithmetic"",
+\t\tcountera_4.sum_lutc_input = ""cin"",
+\t\tcountera_4.synch_mode = ""on"",
+\t\tcountera_4.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_5
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_4cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_5cout[0:0]),
+\t.dataa(power_modified_counter_values[4]),
+\t.datab(power_modified_counter_values[5]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[5:5]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_5.cin_used = ""true"",
+\t\tcountera_5.lut_mask = ""6c50"",
+\t\tcountera_5.operation_mode = ""arithmetic"",
+\t\tcountera_5.sum_lutc_input = ""cin"",
+\t\tcountera_5.synch_mode = ""on"",
+\t\tcountera_5.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_6
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_5cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_6cout[0:0]),
+\t.dataa(power_modified_counter_values[5]),
+\t.datab(power_modified_counter_values[6]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[6:6]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_6.cin_used = ""true"",
+\t\tcountera_6.lut_mask = ""6c50"",
+\t\tcountera_6.operation_mode = ""arithmetic"",
+\t\tcountera_6.sum_lutc_input = ""cin"",
+\t\tcountera_6.synch_mode = ""on"",
+\t\tcountera_6.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_7
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_6cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_7cout[0:0]),
+\t.dataa(power_modified_counter_values[6]),
+\t.datab(power_modified_counter_values[7]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[7:7]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_7.cin_used = ""true"",
+\t\tcountera_7.lut_mask = ""6c50"",
+\t\tcountera_7.operation_mode = ""arithmetic"",
+\t\tcountera_7.sum_lutc_input = ""cin"",
+\t\tcountera_7.synch_mode = ""on"",
+\t\tcountera_7.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_8
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_7cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_8cout[0:0]),
+\t.dataa(power_modified_counter_values[7]),
+\t.datab(power_modified_counter_values[8]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[8:8]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_8.cin_used = ""true"",
+\t\tcountera_8.lut_mask = ""6c50"",
+\t\tcountera_8.operation_mode = ""arithmetic"",
+\t\tcountera_8.sum_lutc_input = ""cin"",
+\t\tcountera_8.synch_mode = ""on"",
+\t\tcountera_8.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_9
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_8cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_countera_9cout[0:0]),
+\t.dataa(power_modified_counter_values[8]),
+\t.datab(power_modified_counter_values[9]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[9:9]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_9.cin_used = ""true"",
+\t\tcountera_9.lut_mask = ""6c50"",
+\t\tcountera_9.operation_mode = ""arithmetic"",
+\t\tcountera_9.sum_lutc_input = ""cin"",
+\t\tcountera_9.synch_mode = ""on"",
+\t\tcountera_9.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell countera_10
+\t(
+\t.aclr(aclr),
+\t.cin(wire_countera_9cout[0:0]),
+\t.clk(clock),
+\t.combout(),
+\t.cout(),
+\t.dataa(power_modified_counter_values[10]),
+\t.ena(1\'b1),
+\t.regout(wire_countera_regout[10:10]),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datab(1\'b1),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tcountera_10.cin_used = ""true"",
+\t\tcountera_10.lut_mask = ""5a5a"",
+\t\tcountera_10.operation_mode = ""normal"",
+\t\tcountera_10.sum_lutc_input = ""cin"",
+\t\tcountera_10.synch_mode = ""on"",
+\t\tcountera_10.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell parity
+\t(
+\t.aclr(aclr),
+\t.cin(updown),
+\t.clk(clock),
+\t.combout(),
+\t.cout(wire_parity_cout),
+\t.dataa(cnt_en),
+\t.datab((~ wire_parity_regout)),
+\t.ena(1\'b1),
+\t.regout(wire_parity_regout),
+\t.sclr(sclr)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aload(1\'b0),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tparity.cin_used = ""true"",
+\t\tparity.lut_mask = ""9982"",
+\t\tparity.operation_mode = ""arithmetic"",
+\t\tparity.synch_mode = ""on"",
+\t\tparity.lpm_type = ""cyclone_lcell"";
+\tassign
+\t\tpower_modified_counter_values = {wire_countera_regout[10:1], (~ wire_countera_regout[0])},
+\t\tq = power_modified_counter_values,
+\t\tsclr = 1\'b0,
+\t\tupdown = 1\'b1;
+endmodule //fifo_2k_a_graycounter_2r6
+
+
+//altsyncram ADDRESS_REG_B=""CLOCK1"" DEVICE_FAMILY=""Cyclone"" OPERATION_MODE=""DUAL_PORT"" OUTDATA_REG_B=""UNREGISTERED"" WIDTH_A=16 WIDTH_B=16 WIDTH_BYTEENA_A=1 WIDTHAD_A=11 WIDTHAD_B=11 address_a address_b clock0 clock1 clocken1 data_a q_b wren_a
+//VERSION_BEGIN 5.0 cbx_altsyncram 2005:03:24:13:58:56:SJ cbx_cycloneii 2004:12:20:14:28:52:SJ cbx_lpm_add_sub 2005:04:12:13:30:42:SJ cbx_lpm_compare 2004:11:30:11:30:40:SJ cbx_lpm_decode 2004:12:13:14:19:12:SJ cbx_lpm_mux 2004:12:13:14:16:38:SJ cbx_mgl 2005:05:19:13:51:58:SJ cbx_stratix 2005:06:02:09:53:04:SJ cbx_stratixii 2004:12:22:13:27:12:SJ cbx_util_mgl 2005:04:04:13:50:06:SJ VERSION_END
+
+//synthesis_resources = M4K 8
+//synopsys translate_off
+`timescale 1 ps / 1 ps
+//synopsys translate_on
+module fifo_2k_altsyncram_6pl
+\t(
+\taddress_a,
+\taddress_b,
+\tclock0,
+\tclock1,
+\tclocken1,
+\tdata_a,
+\tq_b,
+\twren_a) /* synthesis synthesis_clearbox=1 */;
+\tinput [10:0] address_a;
+\tinput [10:0] address_b;
+\tinput clock0;
+\tinput clock1;
+\tinput clocken1;
+\tinput [15:0] data_a;
+\toutput [15:0] q_b;
+\tinput wren_a;
+
+\twire [0:0] wire_ram_block3a_0portbdataout;
+\twire [0:0] wire_ram_block3a_1portbdataout;
+\twire [0:0] wire_ram_block3a_2portbdataout;
+\twire [0:0] wire_ram_block3a_3portbdataout;
+\twire [0:0] wire_ram_block3a_4portbdataout;
+\twire [0:0] wire_ram_block3a_5portbdataout;
+\twire [0:0] wire_ram_block3a_6portbdataout;
+\twire [0:0] wire_ram_block3a_7portbdataout;
+\twire [0:0] wire_ram_block3a_8portbdataout;
+\twire [0:0] wire_ram_block3a_9portbdataout;
+\twire [0:0] wire_ram_block3a_10portbdataout;
+\twire [0:0] wire_ram_block3a_11portbdataout;
+\twire [0:0] wire_ram_block3a_12portbdataout;
+\twire [0:0] wire_ram_block3a_13portbdataout;
+\twire [0:0] wire_ram_block3a_14portbdataout;
+\twire [0:0] wire_ram_block3a_15portbdataout;
+\twire [10:0] address_a_wire;
+\twire [10:0] address_b_wire;
+
+\tcyclone_ram_block ram_block3a_0
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[0]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_0portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_0.connectivity_checking = ""OFF"",
+\t\tram_block3a_0.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_0.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_0.operation_mode = ""dual_port"",
+\t\tram_block3a_0.port_a_address_width = 11,
+\t\tram_block3a_0.port_a_data_width = 1,
+\t\tram_block3a_0.port_a_first_address = 0,
+\t\tram_block3a_0.port_a_first_bit_number = 0,
+\t\tram_block3a_0.port_a_last_address = 2047,
+\t\tram_block3a_0.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_0.port_a_logical_ram_width = 16,
+\t\tram_block3a_0.port_b_address_clear = ""none"",
+\t\tram_block3a_0.port_b_address_clock = ""clock1"",
+\t\tram_block3a_0.port_b_address_width = 11,
+\t\tram_block3a_0.port_b_data_out_clear = ""none"",
+\t\tram_block3a_0.port_b_data_out_clock = ""none"",
+\t\tram_block3a_0.port_b_data_width = 1,
+\t\tram_block3a_0.port_b_first_address = 0,
+\t\tram_block3a_0.port_b_first_bit_number = 0,
+\t\tram_block3a_0.port_b_last_address = 2047,
+\t\tram_block3a_0.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_0.port_b_logical_ram_width = 16,
+\t\tram_block3a_0.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_0.ram_block_type = ""auto"",
+\t\tram_block3a_0.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_1
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[1]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_1portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_1.connectivity_checking = ""OFF"",
+\t\tram_block3a_1.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_1.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_1.operation_mode = ""dual_port"",
+\t\tram_block3a_1.port_a_address_width = 11,
+\t\tram_block3a_1.port_a_data_width = 1,
+\t\tram_block3a_1.port_a_first_address = 0,
+\t\tram_block3a_1.port_a_first_bit_number = 1,
+\t\tram_block3a_1.port_a_last_address = 2047,
+\t\tram_block3a_1.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_1.port_a_logical_ram_width = 16,
+\t\tram_block3a_1.port_b_address_clear = ""none"",
+\t\tram_block3a_1.port_b_address_clock = ""clock1"",
+\t\tram_block3a_1.port_b_address_width = 11,
+\t\tram_block3a_1.port_b_data_out_clear = ""none"",
+\t\tram_block3a_1.port_b_data_out_clock = ""none"",
+\t\tram_block3a_1.port_b_data_width = 1,
+\t\tram_block3a_1.port_b_first_address = 0,
+\t\tram_block3a_1.port_b_first_bit_number = 1,
+\t\tram_block3a_1.port_b_last_address = 2047,
+\t\tram_block3a_1.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_1.port_b_logical_ram_width = 16,
+\t\tram_block3a_1.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_1.ram_block_type = ""auto"",
+\t\tram_block3a_1.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_2
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[2]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_2portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_2.connectivity_checking = ""OFF"",
+\t\tram_block3a_2.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_2.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_2.operation_mode = ""dual_port"",
+\t\tram_block3a_2.port_a_address_width = 11,
+\t\tram_block3a_2.port_a_data_width = 1,
+\t\tram_block3a_2.port_a_first_address = 0,
+\t\tram_block3a_2.port_a_first_bit_number = 2,
+\t\tram_block3a_2.port_a_last_address = 2047,
+\t\tram_block3a_2.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_2.port_a_logical_ram_width = 16,
+\t\tram_block3a_2.port_b_address_clear = ""none"",
+\t\tram_block3a_2.port_b_address_clock = ""clock1"",
+\t\tram_block3a_2.port_b_address_width = 11,
+\t\tram_block3a_2.port_b_data_out_clear = ""none"",
+\t\tram_block3a_2.port_b_data_out_clock = ""none"",
+\t\tram_block3a_2.port_b_data_width = 1,
+\t\tram_block3a_2.port_b_first_address = 0,
+\t\tram_block3a_2.port_b_first_bit_number = 2,
+\t\tram_block3a_2.port_b_last_address = 2047,
+\t\tram_block3a_2.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_2.port_b_logical_ram_width = 16,
+\t\tram_block3a_2.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_2.ram_block_type = ""auto"",
+\t\tram_block3a_2.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_3
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[3]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_3portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_3.connectivity_checking = ""OFF"",
+\t\tram_block3a_3.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_3.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_3.operation_mode = ""dual_port"",
+\t\tram_block3a_3.port_a_address_width = 11,
+\t\tram_block3a_3.port_a_data_width = 1,
+\t\tram_block3a_3.port_a_first_address = 0,
+\t\tram_block3a_3.port_a_first_bit_number = 3,
+\t\tram_block3a_3.port_a_last_address = 2047,
+\t\tram_block3a_3.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_3.port_a_logical_ram_width = 16,
+\t\tram_block3a_3.port_b_address_clear = ""none"",
+\t\tram_block3a_3.port_b_address_clock = ""clock1"",
+\t\tram_block3a_3.port_b_address_width = 11,
+\t\tram_block3a_3.port_b_data_out_clear = ""none"",
+\t\tram_block3a_3.port_b_data_out_clock = ""none"",
+\t\tram_block3a_3.port_b_data_width = 1,
+\t\tram_block3a_3.port_b_first_address = 0,
+\t\tram_block3a_3.port_b_first_bit_number = 3,
+\t\tram_block3a_3.port_b_last_address = 2047,
+\t\tram_block3a_3.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_3.port_b_logical_ram_width = 16,
+\t\tram_block3a_3.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_3.ram_block_type = ""auto"",
+\t\tram_block3a_3.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_4
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[4]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_4portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_4.connectivity_checking = ""OFF"",
+\t\tram_block3a_4.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_4.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_4.operation_mode = ""dual_port"",
+\t\tram_block3a_4.port_a_address_width = 11,
+\t\tram_block3a_4.port_a_data_width = 1,
+\t\tram_block3a_4.port_a_first_address = 0,
+\t\tram_block3a_4.port_a_first_bit_number = 4,
+\t\tram_block3a_4.port_a_last_address = 2047,
+\t\tram_block3a_4.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_4.port_a_logical_ram_width = 16,
+\t\tram_block3a_4.port_b_address_clear = ""none"",
+\t\tram_block3a_4.port_b_address_clock = ""clock1"",
+\t\tram_block3a_4.port_b_address_width = 11,
+\t\tram_block3a_4.port_b_data_out_clear = ""none"",
+\t\tram_block3a_4.port_b_data_out_clock = ""none"",
+\t\tram_block3a_4.port_b_data_width = 1,
+\t\tram_block3a_4.port_b_first_address = 0,
+\t\tram_block3a_4.port_b_first_bit_number = 4,
+\t\tram_block3a_4.port_b_last_address = 2047,
+\t\tram_block3a_4.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_4.port_b_logical_ram_width = 16,
+\t\tram_block3a_4.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_4.ram_block_type = ""auto"",
+\t\tram_block3a_4.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_5
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[5]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_5portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_5.connectivity_checking = ""OFF"",
+\t\tram_block3a_5.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_5.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_5.operation_mode = ""dual_port"",
+\t\tram_block3a_5.port_a_address_width = 11,
+\t\tram_block3a_5.port_a_data_width = 1,
+\t\tram_block3a_5.port_a_first_address = 0,
+\t\tram_block3a_5.port_a_first_bit_number = 5,
+\t\tram_block3a_5.port_a_last_address = 2047,
+\t\tram_block3a_5.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_5.port_a_logical_ram_width = 16,
+\t\tram_block3a_5.port_b_address_clear = ""none"",
+\t\tram_block3a_5.port_b_address_clock = ""clock1"",
+\t\tram_block3a_5.port_b_address_width = 11,
+\t\tram_block3a_5.port_b_data_out_clear = ""none"",
+\t\tram_block3a_5.port_b_data_out_clock = ""none"",
+\t\tram_block3a_5.port_b_data_width = 1,
+\t\tram_block3a_5.port_b_first_address = 0,
+\t\tram_block3a_5.port_b_first_bit_number = 5,
+\t\tram_block3a_5.port_b_last_address = 2047,
+\t\tram_block3a_5.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_5.port_b_logical_ram_width = 16,
+\t\tram_block3a_5.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_5.ram_block_type = ""auto"",
+\t\tram_block3a_5.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_6
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[6]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_6portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_6.connectivity_checking = ""OFF"",
+\t\tram_block3a_6.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_6.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_6.operation_mode = ""dual_port"",
+\t\tram_block3a_6.port_a_address_width = 11,
+\t\tram_block3a_6.port_a_data_width = 1,
+\t\tram_block3a_6.port_a_first_address = 0,
+\t\tram_block3a_6.port_a_first_bit_number = 6,
+\t\tram_block3a_6.port_a_last_address = 2047,
+\t\tram_block3a_6.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_6.port_a_logical_ram_width = 16,
+\t\tram_block3a_6.port_b_address_clear = ""none"",
+\t\tram_block3a_6.port_b_address_clock = ""clock1"",
+\t\tram_block3a_6.port_b_address_width = 11,
+\t\tram_block3a_6.port_b_data_out_clear = ""none"",
+\t\tram_block3a_6.port_b_data_out_clock = ""none"",
+\t\tram_block3a_6.port_b_data_width = 1,
+\t\tram_block3a_6.port_b_first_address = 0,
+\t\tram_block3a_6.port_b_first_bit_number = 6,
+\t\tram_block3a_6.port_b_last_address = 2047,
+\t\tram_block3a_6.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_6.port_b_logical_ram_width = 16,
+\t\tram_block3a_6.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_6.ram_block_type = ""auto"",
+\t\tram_block3a_6.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_7
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[7]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_7portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_7.connectivity_checking = ""OFF"",
+\t\tram_block3a_7.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_7.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_7.operation_mode = ""dual_port"",
+\t\tram_block3a_7.port_a_address_width = 11,
+\t\tram_block3a_7.port_a_data_width = 1,
+\t\tram_block3a_7.port_a_first_address = 0,
+\t\tram_block3a_7.port_a_first_bit_number = 7,
+\t\tram_block3a_7.port_a_last_address = 2047,
+\t\tram_block3a_7.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_7.port_a_logical_ram_width = 16,
+\t\tram_block3a_7.port_b_address_clear = ""none"",
+\t\tram_block3a_7.port_b_address_clock = ""clock1"",
+\t\tram_block3a_7.port_b_address_width = 11,
+\t\tram_block3a_7.port_b_data_out_clear = ""none"",
+\t\tram_block3a_7.port_b_data_out_clock = ""none"",
+\t\tram_block3a_7.port_b_data_width = 1,
+\t\tram_block3a_7.port_b_first_address = 0,
+\t\tram_block3a_7.port_b_first_bit_number = 7,
+\t\tram_block3a_7.port_b_last_address = 2047,
+\t\tram_block3a_7.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_7.port_b_logical_ram_width = 16,
+\t\tram_block3a_7.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_7.ram_block_type = ""auto"",
+\t\tram_block3a_7.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_8
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[8]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_8portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_8.connectivity_checking = ""OFF"",
+\t\tram_block3a_8.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_8.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_8.operation_mode = ""dual_port"",
+\t\tram_block3a_8.port_a_address_width = 11,
+\t\tram_block3a_8.port_a_data_width = 1,
+\t\tram_block3a_8.port_a_first_address = 0,
+\t\tram_block3a_8.port_a_first_bit_number = 8,
+\t\tram_block3a_8.port_a_last_address = 2047,
+\t\tram_block3a_8.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_8.port_a_logical_ram_width = 16,
+\t\tram_block3a_8.port_b_address_clear = ""none"",
+\t\tram_block3a_8.port_b_address_clock = ""clock1"",
+\t\tram_block3a_8.port_b_address_width = 11,
+\t\tram_block3a_8.port_b_data_out_clear = ""none"",
+\t\tram_block3a_8.port_b_data_out_clock = ""none"",
+\t\tram_block3a_8.port_b_data_width = 1,
+\t\tram_block3a_8.port_b_first_address = 0,
+\t\tram_block3a_8.port_b_first_bit_number = 8,
+\t\tram_block3a_8.port_b_last_address = 2047,
+\t\tram_block3a_8.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_8.port_b_logical_ram_width = 16,
+\t\tram_block3a_8.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_8.ram_block_type = ""auto"",
+\t\tram_block3a_8.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_9
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[9]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_9portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_9.connectivity_checking = ""OFF"",
+\t\tram_block3a_9.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_9.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_9.operation_mode = ""dual_port"",
+\t\tram_block3a_9.port_a_address_width = 11,
+\t\tram_block3a_9.port_a_data_width = 1,
+\t\tram_block3a_9.port_a_first_address = 0,
+\t\tram_block3a_9.port_a_first_bit_number = 9,
+\t\tram_block3a_9.port_a_last_address = 2047,
+\t\tram_block3a_9.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_9.port_a_logical_ram_width = 16,
+\t\tram_block3a_9.port_b_address_clear = ""none"",
+\t\tram_block3a_9.port_b_address_clock = ""clock1"",
+\t\tram_block3a_9.port_b_address_width = 11,
+\t\tram_block3a_9.port_b_data_out_clear = ""none"",
+\t\tram_block3a_9.port_b_data_out_clock = ""none"",
+\t\tram_block3a_9.port_b_data_width = 1,
+\t\tram_block3a_9.port_b_first_address = 0,
+\t\tram_block3a_9.port_b_first_bit_number = 9,
+\t\tram_block3a_9.port_b_last_address = 2047,
+\t\tram_block3a_9.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_9.port_b_logical_ram_width = 16,
+\t\tram_block3a_9.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_9.ram_block_type = ""auto"",
+\t\tram_block3a_9.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_10
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[10]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_10portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_10.connectivity_checking = ""OFF"",
+\t\tram_block3a_10.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_10.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_10.operation_mode = ""dual_port"",
+\t\tram_block3a_10.port_a_address_width = 11,
+\t\tram_block3a_10.port_a_data_width = 1,
+\t\tram_block3a_10.port_a_first_address = 0,
+\t\tram_block3a_10.port_a_first_bit_number = 10,
+\t\tram_block3a_10.port_a_last_address = 2047,
+\t\tram_block3a_10.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_10.port_a_logical_ram_width = 16,
+\t\tram_block3a_10.port_b_address_clear = ""none"",
+\t\tram_block3a_10.port_b_address_clock = ""clock1"",
+\t\tram_block3a_10.port_b_address_width = 11,
+\t\tram_block3a_10.port_b_data_out_clear = ""none"",
+\t\tram_block3a_10.port_b_data_out_clock = ""none"",
+\t\tram_block3a_10.port_b_data_width = 1,
+\t\tram_block3a_10.port_b_first_address = 0,
+\t\tram_block3a_10.port_b_first_bit_number = 10,
+\t\tram_block3a_10.port_b_last_address = 2047,
+\t\tram_block3a_10.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_10.port_b_logical_ram_width = 16,
+\t\tram_block3a_10.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_10.ram_block_type = ""auto"",
+\t\tram_block3a_10.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_11
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[11]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_11portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_11.connectivity_checking = ""OFF"",
+\t\tram_block3a_11.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_11.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_11.operation_mode = ""dual_port"",
+\t\tram_block3a_11.port_a_address_width = 11,
+\t\tram_block3a_11.port_a_data_width = 1,
+\t\tram_block3a_11.port_a_first_address = 0,
+\t\tram_block3a_11.port_a_first_bit_number = 11,
+\t\tram_block3a_11.port_a_last_address = 2047,
+\t\tram_block3a_11.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_11.port_a_logical_ram_width = 16,
+\t\tram_block3a_11.port_b_address_clear = ""none"",
+\t\tram_block3a_11.port_b_address_clock = ""clock1"",
+\t\tram_block3a_11.port_b_address_width = 11,
+\t\tram_block3a_11.port_b_data_out_clear = ""none"",
+\t\tram_block3a_11.port_b_data_out_clock = ""none"",
+\t\tram_block3a_11.port_b_data_width = 1,
+\t\tram_block3a_11.port_b_first_address = 0,
+\t\tram_block3a_11.port_b_first_bit_number = 11,
+\t\tram_block3a_11.port_b_last_address = 2047,
+\t\tram_block3a_11.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_11.port_b_logical_ram_width = 16,
+\t\tram_block3a_11.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_11.ram_block_type = ""auto"",
+\t\tram_block3a_11.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_12
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[12]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_12portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_12.connectivity_checking = ""OFF"",
+\t\tram_block3a_12.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_12.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_12.operation_mode = ""dual_port"",
+\t\tram_block3a_12.port_a_address_width = 11,
+\t\tram_block3a_12.port_a_data_width = 1,
+\t\tram_block3a_12.port_a_first_address = 0,
+\t\tram_block3a_12.port_a_first_bit_number = 12,
+\t\tram_block3a_12.port_a_last_address = 2047,
+\t\tram_block3a_12.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_12.port_a_logical_ram_width = 16,
+\t\tram_block3a_12.port_b_address_clear = ""none"",
+\t\tram_block3a_12.port_b_address_clock = ""clock1"",
+\t\tram_block3a_12.port_b_address_width = 11,
+\t\tram_block3a_12.port_b_data_out_clear = ""none"",
+\t\tram_block3a_12.port_b_data_out_clock = ""none"",
+\t\tram_block3a_12.port_b_data_width = 1,
+\t\tram_block3a_12.port_b_first_address = 0,
+\t\tram_block3a_12.port_b_first_bit_number = 12,
+\t\tram_block3a_12.port_b_last_address = 2047,
+\t\tram_block3a_12.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_12.port_b_logical_ram_width = 16,
+\t\tram_block3a_12.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_12.ram_block_type = ""auto"",
+\t\tram_block3a_12.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_13
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[13]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_13portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_13.connectivity_checking = ""OFF"",
+\t\tram_block3a_13.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_13.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_13.operation_mode = ""dual_port"",
+\t\tram_block3a_13.port_a_address_width = 11,
+\t\tram_block3a_13.port_a_data_width = 1,
+\t\tram_block3a_13.port_a_first_address = 0,
+\t\tram_block3a_13.port_a_first_bit_number = 13,
+\t\tram_block3a_13.port_a_last_address = 2047,
+\t\tram_block3a_13.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_13.port_a_logical_ram_width = 16,
+\t\tram_block3a_13.port_b_address_clear = ""none"",
+\t\tram_block3a_13.port_b_address_clock = ""clock1"",
+\t\tram_block3a_13.port_b_address_width = 11,
+\t\tram_block3a_13.port_b_data_out_clear = ""none"",
+\t\tram_block3a_13.port_b_data_out_clock = ""none"",
+\t\tram_block3a_13.port_b_data_width = 1,
+\t\tram_block3a_13.port_b_first_address = 0,
+\t\tram_block3a_13.port_b_first_bit_number = 13,
+\t\tram_block3a_13.port_b_last_address = 2047,
+\t\tram_block3a_13.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_13.port_b_logical_ram_width = 16,
+\t\tram_block3a_13.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_13.ram_block_type = ""auto"",
+\t\tram_block3a_13.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_14
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[14]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_14portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_14.connectivity_checking = ""OFF"",
+\t\tram_block3a_14.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_14.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_14.operation_mode = ""dual_port"",
+\t\tram_block3a_14.port_a_address_width = 11,
+\t\tram_block3a_14.port_a_data_width = 1,
+\t\tram_block3a_14.port_a_first_address = 0,
+\t\tram_block3a_14.port_a_first_bit_number = 14,
+\t\tram_block3a_14.port_a_last_address = 2047,
+\t\tram_block3a_14.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_14.port_a_logical_ram_width = 16,
+\t\tram_block3a_14.port_b_address_clear = ""none"",
+\t\tram_block3a_14.port_b_address_clock = ""clock1"",
+\t\tram_block3a_14.port_b_address_width = 11,
+\t\tram_block3a_14.port_b_data_out_clear = ""none"",
+\t\tram_block3a_14.port_b_data_out_clock = ""none"",
+\t\tram_block3a_14.port_b_data_width = 1,
+\t\tram_block3a_14.port_b_first_address = 0,
+\t\tram_block3a_14.port_b_first_bit_number = 14,
+\t\tram_block3a_14.port_b_last_address = 2047,
+\t\tram_block3a_14.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_14.port_b_logical_ram_width = 16,
+\t\tram_block3a_14.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_14.ram_block_type = ""auto"",
+\t\tram_block3a_14.lpm_type = ""cyclone_ram_block"";
+\tcyclone_ram_block ram_block3a_15
+\t(
+\t.clk0(clock0),
+\t.clk1(clock1),
+\t.ena0(wren_a),
+\t.ena1(clocken1),
+\t.portaaddr({address_a_wire[10:0]}),
+\t.portadatain({data_a[15]}),
+\t.portadataout(),
+\t.portawe(1\'b1),
+\t.portbaddr({address_b_wire[10:0]}),
+\t.portbdataout(wire_ram_block3a_15portbdataout[0:0]),
+\t.portbrewe(1\'b1)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.clr0(1\'b0),
+\t.clr1(1\'b0),
+\t.portabyteenamasks(1\'b1),
+\t.portbbyteenamasks(1\'b1),
+\t.portbdatain(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tram_block3a_15.connectivity_checking = ""OFF"",
+\t\tram_block3a_15.logical_ram_name = ""ALTSYNCRAM"",
+\t\tram_block3a_15.mixed_port_feed_through_mode = ""dont_care"",
+\t\tram_block3a_15.operation_mode = ""dual_port"",
+\t\tram_block3a_15.port_a_address_width = 11,
+\t\tram_block3a_15.port_a_data_width = 1,
+\t\tram_block3a_15.port_a_first_address = 0,
+\t\tram_block3a_15.port_a_first_bit_number = 15,
+\t\tram_block3a_15.port_a_last_address = 2047,
+\t\tram_block3a_15.port_a_logical_ram_depth = 2048,
+\t\tram_block3a_15.port_a_logical_ram_width = 16,
+\t\tram_block3a_15.port_b_address_clear = ""none"",
+\t\tram_block3a_15.port_b_address_clock = ""clock1"",
+\t\tram_block3a_15.port_b_address_width = 11,
+\t\tram_block3a_15.port_b_data_out_clear = ""none"",
+\t\tram_block3a_15.port_b_data_out_clock = ""none"",
+\t\tram_block3a_15.port_b_data_width = 1,
+\t\tram_block3a_15.port_b_first_address = 0,
+\t\tram_block3a_15.port_b_first_bit_number = 15,
+\t\tram_block3a_15.port_b_last_address = 2047,
+\t\tram_block3a_15.port_b_logical_ram_depth = 2048,
+\t\tram_block3a_15.port_b_logical_ram_width = 16,
+\t\tram_block3a_15.port_b_read_enable_write_enable_clock = ""clock1"",
+\t\tram_block3a_15.ram_block_type = ""auto"",
+\t\tram_block3a_15.lpm_type = ""cyclone_ram_block"";
+\tassign
+\t\taddress_a_wire = address_a,
+\t\taddress_b_wire = address_b,
+\t\tq_b = {wire_ram_block3a_15portbdataout[0], wire_ram_block3a_14portbdataout[0], wire_ram_block3a_13portbdataout[0], wire_ram_block3a_12portbdataout[0], wire_ram_block3a_11portbdataout[0], wire_ram_block3a_10portbdataout[0], wire_ram_block3a_9portbdataout[0], wire_ram_block3a_8portbdataout[0], wire_ram_block3a_7portbdataout[0], wire_ram_block3a_6portbdataout[0], wire_ram_block3a_5portbdataout[0], wire_ram_block3a_4portbdataout[0], wire_ram_block3a_3portbdataout[0], wire_ram_block3a_2portbdataout[0], wire_ram_block3a_1portbdataout[0], wire_ram_block3a_0portbdataout[0]};
+endmodule //fifo_2k_altsyncram_6pl
+
+
+//dffpipe DELAY=1 WIDTH=11 clock clrn d q
+//VERSION_BEGIN 5.0 cbx_mgl 2005:05:19:13:51:58:SJ cbx_stratixii 2004:12:22:13:27:12:SJ cbx_util_mgl 2005:04:04:13:50:06:SJ VERSION_END
+
+//synthesis_resources = lut 11
+//synopsys translate_off
+`timescale 1 ps / 1 ps
+//synopsys translate_on
+module fifo_2k_dffpipe_ab3
+\t(
+\tclock,
+\tclrn,
+\td,
+\tq) /* synthesis synthesis_clearbox=1 */
+\t\t/* synthesis ALTERA_ATTRIBUTE=""AUTO_SHIFT_REGISTER_RECOGNITION=OFF"" */;
+\tinput clock;
+\tinput clrn;
+\tinput [10:0] d;
+\toutput [10:0] q;
+
+\twire\t[10:0]\twire_dffe4a_D;
+\treg\t[10:0]\tdffe4a;
+\twire ena;
+\twire prn;
+\twire sclr;
+
+\t// synopsys translate_off
+\tinitial
+\t\tdffe4a[0:0] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe4a[0:0] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe4a[0:0] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe4a[0:0] <= wire_dffe4a_D[0:0];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe4a[1:1] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe4a[1:1] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe4a[1:1] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe4a[1:1] <= wire_dffe4a_D[1:1];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe4a[2:2] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe4a[2:2] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe4a[2:2] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe4a[2:2] <= wire_dffe4a_D[2:2];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe4a[3:3] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe4a[3:3] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe4a[3:3] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe4a[3:3] <= wire_dffe4a_D[3:3];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe4a[4:4] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe4a[4:4] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe4a[4:4] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe4a[4:4] <= wire_dffe4a_D[4:4];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe4a[5:5] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe4a[5:5] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe4a[5:5] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe4a[5:5] <= wire_dffe4a_D[5:5];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe4a[6:6] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe4a[6:6] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe4a[6:6] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe4a[6:6] <= wire_dffe4a_D[6:6];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe4a[7:7] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe4a[7:7] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe4a[7:7] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe4a[7:7] <= wire_dffe4a_D[7:7];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe4a[8:8] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe4a[8:8] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe4a[8:8] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe4a[8:8] <= wire_dffe4a_D[8:8];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe4a[9:9] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe4a[9:9] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe4a[9:9] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe4a[9:9] <= wire_dffe4a_D[9:9];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe4a[10:10] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe4a[10:10] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe4a[10:10] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe4a[10:10] <= wire_dffe4a_D[10:10];
+\tassign
+\t\twire_dffe4a_D = (d & {11{(~ sclr)}});
+\tassign
+\t\tena = 1\'b1,
+\t\tprn = 1\'b1,
+\t\tq = dffe4a,
+\t\tsclr = 1\'b0;
+endmodule //fifo_2k_dffpipe_ab3
+
+
+//dffpipe WIDTH=11 clock clrn d q
+//VERSION_BEGIN 5.0 cbx_a_gray2bin 2004:03:06:00:52:20:SJ cbx_a_graycounter 2004:10:01:12:13:16:SJ cbx_altdpram 2004:11:30:11:29:56:SJ cbx_altsyncram 2005:03:24:13:58:56:SJ cbx_cycloneii 2004:12:20:14:28:52:SJ cbx_dcfifo 2005:03:07:17:11:14:SJ cbx_fifo_common 2004:12:13:14:26:24:SJ cbx_flex10ke 2002:10:18:16:54:38:SJ cbx_lpm_add_sub 2005:04:12:13:30:42:SJ cbx_lpm_compare 2004:11:30:11:30:40:SJ cbx_lpm_counter 2005:02:02:04:37:10:SJ cbx_lpm_decode 2004:12:13:14:19:12:SJ cbx_lpm_mux 2004:12:13:14:16:38:SJ cbx_mgl 2005:05:19:13:51:58:SJ cbx_scfifo 2005:03:10:10:52:20:SJ cbx_stratix 2005:06:02:09:53:04:SJ cbx_stratixii 2004:12:22:13:27:12:SJ cbx_util_mgl 2005:04:04:13:50:06:SJ VERSION_END
+
+
+//dffpipe WIDTH=11 clock clrn d q
+//VERSION_BEGIN 5.0 cbx_mgl 2005:05:19:13:51:58:SJ cbx_stratixii 2004:12:22:13:27:12:SJ cbx_util_mgl 2005:04:04:13:50:06:SJ VERSION_END
+
+//synthesis_resources = lut 11
+//synopsys translate_off
+`timescale 1 ps / 1 ps
+//synopsys translate_on
+module fifo_2k_dffpipe_dm2
+\t(
+\tclock,
+\tclrn,
+\td,
+\tq) /* synthesis synthesis_clearbox=1 */
+\t\t/* synthesis ALTERA_ATTRIBUTE=""AUTO_SHIFT_REGISTER_RECOGNITION=OFF"" */;
+\tinput clock;
+\tinput clrn;
+\tinput [10:0] d;
+\toutput [10:0] q;
+
+\twire\t[10:0]\twire_dffe6a_D;
+\treg\t[10:0]\tdffe6a;
+\twire ena;
+\twire prn;
+\twire sclr;
+
+\t// synopsys translate_off
+\tinitial
+\t\tdffe6a[0:0] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe6a[0:0] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe6a[0:0] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe6a[0:0] <= wire_dffe6a_D[0:0];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe6a[1:1] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe6a[1:1] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe6a[1:1] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe6a[1:1] <= wire_dffe6a_D[1:1];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe6a[2:2] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe6a[2:2] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe6a[2:2] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe6a[2:2] <= wire_dffe6a_D[2:2];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe6a[3:3] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe6a[3:3] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe6a[3:3] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe6a[3:3] <= wire_dffe6a_D[3:3];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe6a[4:4] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe6a[4:4] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe6a[4:4] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe6a[4:4] <= wire_dffe6a_D[4:4];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe6a[5:5] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe6a[5:5] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe6a[5:5] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe6a[5:5] <= wire_dffe6a_D[5:5];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe6a[6:6] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe6a[6:6] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe6a[6:6] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe6a[6:6] <= wire_dffe6a_D[6:6];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe6a[7:7] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe6a[7:7] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe6a[7:7] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe6a[7:7] <= wire_dffe6a_D[7:7];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe6a[8:8] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe6a[8:8] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe6a[8:8] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe6a[8:8] <= wire_dffe6a_D[8:8];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe6a[9:9] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe6a[9:9] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe6a[9:9] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe6a[9:9] <= wire_dffe6a_D[9:9];
+\t// synopsys translate_off
+\tinitial
+\t\tdffe6a[10:10] = 0;
+\t// synopsys translate_on
+\talways @ ( posedge clock or negedge prn or negedge clrn)
+\t\tif (prn == 1\'b0) dffe6a[10:10] <= 1\'b1;
+\t\telse if (clrn == 1\'b0) dffe6a[10:10] <= 1\'b0;
+\t\telse if (ena == 1\'b1) dffe6a[10:10] <= wire_dffe6a_D[10:10];
+\tassign
+\t\twire_dffe6a_D = (d & {11{(~ sclr)}});
+\tassign
+\t\tena = 1\'b1,
+\t\tprn = 1\'b1,
+\t\tq = dffe6a,
+\t\tsclr = 1\'b0;
+endmodule //fifo_2k_dffpipe_dm2
+
+//synthesis_resources = lut 11
+//synopsys translate_off
+`timescale 1 ps / 1 ps
+//synopsys translate_on
+module fifo_2k_alt_synch_pipe_dm2
+\t(
+\tclock,
+\tclrn,
+\td,
+\tq) /* synthesis synthesis_clearbox=1 */
+\t\t/* synthesis ALTERA_ATTRIBUTE=""X_ON_VIOLATION_OPTION=OFF"" */;
+\tinput clock;
+\tinput clrn;
+\tinput [10:0] d;
+\toutput [10:0] q;
+
+\twire [10:0] wire_dffpipe5_q;
+
+\tfifo_2k_dffpipe_dm2 dffpipe5
+\t(
+\t.clock(clock),
+\t.clrn(clrn),
+\t.d(d),
+\t.q(wire_dffpipe5_q));
+\tassign
+\t\tq = wire_dffpipe5_q;
+endmodule //fifo_2k_alt_synch_pipe_dm2
+
+
+//lpm_add_sub DEVICE_FAMILY=""Cyclone"" LPM_DIRECTION=""SUB"" LPM_WIDTH=11 dataa datab result
+//VERSION_BEGIN 5.0 cbx_cycloneii 2004:12:20:14:28:52:SJ cbx_lpm_add_sub 2005:04:12:13:30:42:SJ cbx_mgl 2005:05:19:13:51:58:SJ cbx_stratix 2005:06:02:09:53:04:SJ cbx_stratixii 2004:12:22:13:27:12:SJ VERSION_END
+
+//synthesis_resources = lut 11
+//synopsys translate_off
+`timescale 1 ps / 1 ps
+//synopsys translate_on
+module fifo_2k_add_sub_a18
+\t(
+\tdataa,
+\tdatab,
+\tresult) /* synthesis synthesis_clearbox=1 */;
+\tinput [10:0] dataa;
+\tinput [10:0] datab;
+\toutput [10:0] result;
+
+\twire [10:0] wire_add_sub_cella_combout;
+\twire [0:0] wire_add_sub_cella_0cout;
+\twire [0:0] wire_add_sub_cella_1cout;
+\twire [0:0] wire_add_sub_cella_2cout;
+\twire [0:0] wire_add_sub_cella_3cout;
+\twire [0:0] wire_add_sub_cella_4cout;
+\twire [0:0] wire_add_sub_cella_5cout;
+\twire [0:0] wire_add_sub_cella_6cout;
+\twire [0:0] wire_add_sub_cella_7cout;
+\twire [0:0] wire_add_sub_cella_8cout;
+\twire [0:0] wire_add_sub_cella_9cout;
+\twire [10:0] wire_add_sub_cella_dataa;
+\twire [10:0] wire_add_sub_cella_datab;
+
+\tcyclone_lcell add_sub_cella_0
+\t(
+\t.cin(1\'b1),
+\t.combout(wire_add_sub_cella_combout[0:0]),
+\t.cout(wire_add_sub_cella_0cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[0:0]),
+\t.datab(wire_add_sub_cella_datab[0:0]),
+\t.regout()
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aclr(1\'b0),
+\t.aload(1\'b0),
+\t.clk(1\'b1),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.ena(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sclr(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tadd_sub_cella_0.cin_used = ""true"",
+\t\tadd_sub_cella_0.lut_mask = ""69b2"",
+\t\tadd_sub_cella_0.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_0.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_0.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell add_sub_cella_1
+\t(
+\t.cin(wire_add_sub_cella_0cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[1:1]),
+\t.cout(wire_add_sub_cella_1cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[1:1]),
+\t.datab(wire_add_sub_cella_datab[1:1]),
+\t.regout()
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aclr(1\'b0),
+\t.aload(1\'b0),
+\t.clk(1\'b1),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.ena(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sclr(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tadd_sub_cella_1.cin_used = ""true"",
+\t\tadd_sub_cella_1.lut_mask = ""69b2"",
+\t\tadd_sub_cella_1.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_1.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_1.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell add_sub_cella_2
+\t(
+\t.cin(wire_add_sub_cella_1cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[2:2]),
+\t.cout(wire_add_sub_cella_2cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[2:2]),
+\t.datab(wire_add_sub_cella_datab[2:2]),
+\t.regout()
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aclr(1\'b0),
+\t.aload(1\'b0),
+\t.clk(1\'b1),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.ena(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sclr(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tadd_sub_cella_2.cin_used = ""true"",
+\t\tadd_sub_cella_2.lut_mask = ""69b2"",
+\t\tadd_sub_cella_2.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_2.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_2.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell add_sub_cella_3
+\t(
+\t.cin(wire_add_sub_cella_2cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[3:3]),
+\t.cout(wire_add_sub_cella_3cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[3:3]),
+\t.datab(wire_add_sub_cella_datab[3:3]),
+\t.regout()
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aclr(1\'b0),
+\t.aload(1\'b0),
+\t.clk(1\'b1),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.ena(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sclr(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tadd_sub_cella_3.cin_used = ""true"",
+\t\tadd_sub_cella_3.lut_mask = ""69b2"",
+\t\tadd_sub_cella_3.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_3.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_3.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell add_sub_cella_4
+\t(
+\t.cin(wire_add_sub_cella_3cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[4:4]),
+\t.cout(wire_add_sub_cella_4cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[4:4]),
+\t.datab(wire_add_sub_cella_datab[4:4]),
+\t.regout()
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aclr(1\'b0),
+\t.aload(1\'b0),
+\t.clk(1\'b1),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.ena(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sclr(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tadd_sub_cella_4.cin_used = ""true"",
+\t\tadd_sub_cella_4.lut_mask = ""69b2"",
+\t\tadd_sub_cella_4.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_4.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_4.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell add_sub_cella_5
+\t(
+\t.cin(wire_add_sub_cella_4cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[5:5]),
+\t.cout(wire_add_sub_cella_5cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[5:5]),
+\t.datab(wire_add_sub_cella_datab[5:5]),
+\t.regout()
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aclr(1\'b0),
+\t.aload(1\'b0),
+\t.clk(1\'b1),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.ena(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sclr(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tadd_sub_cella_5.cin_used = ""true"",
+\t\tadd_sub_cella_5.lut_mask = ""69b2"",
+\t\tadd_sub_cella_5.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_5.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_5.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell add_sub_cella_6
+\t(
+\t.cin(wire_add_sub_cella_5cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[6:6]),
+\t.cout(wire_add_sub_cella_6cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[6:6]),
+\t.datab(wire_add_sub_cella_datab[6:6]),
+\t.regout()
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aclr(1\'b0),
+\t.aload(1\'b0),
+\t.clk(1\'b1),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.ena(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sclr(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tadd_sub_cella_6.cin_used = ""true"",
+\t\tadd_sub_cella_6.lut_mask = ""69b2"",
+\t\tadd_sub_cella_6.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_6.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_6.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell add_sub_cella_7
+\t(
+\t.cin(wire_add_sub_cella_6cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[7:7]),
+\t.cout(wire_add_sub_cella_7cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[7:7]),
+\t.datab(wire_add_sub_cella_datab[7:7]),
+\t.regout()
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aclr(1\'b0),
+\t.aload(1\'b0),
+\t.clk(1\'b1),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.ena(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sclr(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tadd_sub_cella_7.cin_used = ""true"",
+\t\tadd_sub_cella_7.lut_mask = ""69b2"",
+\t\tadd_sub_cella_7.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_7.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_7.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell add_sub_cella_8
+\t(
+\t.cin(wire_add_sub_cella_7cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[8:8]),
+\t.cout(wire_add_sub_cella_8cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[8:8]),
+\t.datab(wire_add_sub_cella_datab[8:8]),
+\t.regout()
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aclr(1\'b0),
+\t.aload(1\'b0),
+\t.clk(1\'b1),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.ena(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sclr(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tadd_sub_cella_8.cin_used = ""true"",
+\t\tadd_sub_cella_8.lut_mask = ""69b2"",
+\t\tadd_sub_cella_8.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_8.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_8.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell add_sub_cella_9
+\t(
+\t.cin(wire_add_sub_cella_8cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[9:9]),
+\t.cout(wire_add_sub_cella_9cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[9:9]),
+\t.datab(wire_add_sub_cella_datab[9:9]),
+\t.regout()
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aclr(1\'b0),
+\t.aload(1\'b0),
+\t.clk(1\'b1),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.ena(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sclr(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tadd_sub_cella_9.cin_used = ""true"",
+\t\tadd_sub_cella_9.lut_mask = ""69b2"",
+\t\tadd_sub_cella_9.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_9.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_9.lpm_type = ""cyclone_lcell"";
+\tcyclone_lcell add_sub_cella_10
+\t(
+\t.cin(wire_add_sub_cella_9cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[10:10]),
+\t.cout(),
+\t.dataa(wire_add_sub_cella_dataa[10:10]),
+\t.datab(wire_add_sub_cella_datab[10:10]),
+\t.regout()
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_off
+\t`endif
+\t,
+\t.aclr(1\'b0),
+\t.aload(1\'b0),
+\t.clk(1\'b1),
+\t.datac(1\'b1),
+\t.datad(1\'b1),
+\t.ena(1\'b1),
+\t.inverta(1\'b0),
+\t.regcascin(1\'b0),
+\t.sclr(1\'b0),
+\t.sload(1\'b0)
+\t`ifdef FORMAL_VERIFICATION
+\t`else
+\t// synopsys translate_on
+\t`endif
+\t// synopsys translate_off
+\t,
+\t.cin0(),
+\t.cin1(),
+\t.cout0(),
+\t.cout1(),
+\t.devclrn(),
+\t.devpor()
+\t// synopsys translate_on
+\t);
+\tdefparam
+\t\tadd_sub_cella_10.cin_used = ""true"",
+\t\tadd_sub_cella_10.lut_mask = ""6969"",
+\t\tadd_sub_cella_10.operation_mode = ""normal"",
+\t\tadd_sub_cella_10.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_10.lpm_type = ""cyclone_lcell"";
+\tassign
+\t\twire_add_sub_cella_dataa = dataa,
+\t\twire_add_sub_cella_datab = datab;
+\tassign
+\t\tresult = wire_add_sub_cella_combout;
+endmodule //fifo_2k_add_sub_a18
+
+
+//lpm_compare DEVICE_FAMILY=""Cyclone"" LPM_WIDTH=11 aeb dataa datab
+//VERSION_BEGIN 5.0 cbx_cycloneii 2004:12:20:14:28:52:SJ cbx_lpm_add_sub 2005:04:12:13:30:42:SJ cbx_lpm_compare 2004:11:30:11:30:40:SJ cbx_mgl 2005:05:19:13:51:58:SJ cbx_stratix 2005:06:02:09:53:04:SJ cbx_stratixii 2004:12:22:13:27:12:SJ VERSION_END
+
+
+//lpm_compare DEVICE_FAMILY=""Cyclone"" LPM_WIDTH=11 aeb dataa datab
+//VERSION_BEGIN 5.0 cbx_cycloneii 2004:12:20:14:28:52:SJ cbx_lpm_add_sub 2005:04:12:13:30:42:SJ cbx_lpm_compare 2004:11:30:11:30:40:SJ cbx_mgl 2005:05:19:13:51:58:SJ cbx_stratix 2005:06:02:09:53:04:SJ cbx_stratixii 2004:12:22:13:27:12:SJ VERSION_END
+
+//synthesis_resources = lut 97 M4K 8
+//synopsys translate_off
+`timescale 1 ps / 1 ps
+//synopsys translate_on
+module fifo_2k_dcfifo_0cq
+\t(
+\taclr,
+\tdata,
+\tq,
+\trdclk,
+\trdempty,
+\trdreq,
+\trdusedw,
+\twrclk,
+\twrfull,
+\twrreq,
+\twrusedw) /* synthesis synthesis_clearbox=1 */
+\t\t/* synthesis ALTERA_ATTRIBUTE=""AUTO_SHIFT_REGISTER_RECOGNITION=OFF;{ -from \\""rdptr_g|power_modified_counter_values\\"" -to \\""ws_dgrp|dffpipe5|dffe6a\\"" }CUT=ON;{ -from \\""delayed_wrptr_g\\"" -to \\""rs_dgwp|dffpipe5|dffe6a\\"" }CUT=ON"" */;
+\tinput aclr;
+\tinput [15:0] data;
+\toutput [15:0] q;
+\tinput rdclk;
+\toutput rdempty;
+\tinput rdreq;
+\toutput [10:0] rdusedw;
+\tinput wrclk;
+\toutput wrfull;
+\tinput wrreq;
+\toutput [10:0] wrusedw;
+
+\twire [10:0] wire_rdptr_g_gray2bin_bin;
+\twire [10:0] wire_rs_dgwp_gray2bin_bin;
+\twire [10:0] wire_wrptr_g_gray2bin_bin;
+\twire [10:0] wire_ws_dgrp_gray2bin_bin;
+\twire [10:0] wire_rdptr_g_q;
+\twire [10:0] wire_rdptr_g1p_q;
+\twire [10:0] wire_wrptr_g1p_q;
+\twire [15:0] wire_fifo_ram_q_b;
+\treg\t[10:0]\tdelayed_wrptr_g;
+\treg\t[10:0]\twrptr_g;
+\twire [10:0] wire_rs_brp_q;
+\twire [10:0] wire_rs_bwp_q;
+\twire [10:0] wire_rs_dgwp_q;
+\twire [10:0] wire_ws_brp_q;
+\twire [10:0] wire_ws_bwp_q;
+\twire [10:0] wire_ws_dgrp_q;
+\twire [10:0] wire_rdusedw_sub_result;
+\twire [10:0] wire_wrusedw_sub_result;
+\treg\twire_rdempty_eq_comp_aeb_int;
+\twire\twire_rdempty_eq_comp_aeb;
+\twire\t[10:0]\twire_rdempty_eq_comp_dataa;
+\twire\t[10:0]\twire_rdempty_eq_comp_datab;
+\treg\twire_wrfull_eq_comp_aeb_int;
+\twire\twire_wrfull_eq_comp_aeb;
+\twire\t[10:0]\twire_wrfull_eq_comp_dataa;
+\twire\t[10:0]\twire_wrfull_eq_comp_datab;
+\twire int_rdempty;
+\twire int_wrfull;
+\twire valid_rdreq;
+\twire valid_wrreq;
+
+\tfifo_2k_a_gray2bin_8m4 rdptr_g_gray2bin
+\t(
+\t.bin(wire_rdptr_g_gray2bin_bin),
+\t.gray(wire_rdptr_g_q));
+\tfifo_2k_a_gray2bin_8m4 rs_dgwp_gray2bin
+\t(
+\t.bin(wire_rs_dgwp_gray2bin_bin),
+\t.gray(wire_rs_dgwp_q));
+\tfifo_2k_a_gray2bin_8m4 wrptr_g_gray2bin
+\t(
+\t.bin(wire_wrptr_g_gray2bin_bin),
+\t.gray(wrptr_g));
+\tfifo_2k_a_gray2bin_8m4 ws_dgrp_gray2bin
+\t(
+\t.bin(wire_ws_dgrp_gray2bin_bin),
+\t.gray(wire_ws_dgrp_q));
+\tfifo_2k_a_graycounter_726 rdptr_g
+\t(
+\t.aclr(aclr),
+\t.clock(rdclk),
+\t.cnt_en(valid_rdreq),
+\t.q(wire_rdptr_g_q));
+\tfifo_2k_a_graycounter_2r6 rdptr_g1p
+\t(
+\t.aclr(aclr),
+\t.clock(rdclk),
+\t.cnt_en(valid_rdreq),
+\t.q(wire_rdptr_g1p_q));
+\tfifo_2k_a_graycounter_2r6 wrptr_g1p
+\t(
+\t.aclr(aclr),
+\t.clock(wrclk),
+\t.cnt_en(valid_wrreq),
+\t.q(wire_wrptr_g1p_q));
+\tfifo_2k_altsyncram_6pl fifo_ram
+\t(
+\t.address_a(wrptr_g),
+\t.address_b(((wire_rdptr_g_q & {11{int_rdempty}}) | (wire_rdptr_g1p_q & {11{(~ int_rdempty)}}))),
+\t.clock0(wrclk),
+\t.clock1(rdclk),
+\t.clocken1((valid_rdreq | int_rdempty)),
+\t.data_a(data),
+\t.q_b(wire_fifo_ram_q_b),
+\t.wren_a(valid_wrreq));
+\t// synopsys translate_off
+\tinitial
+\t\tdelayed_wrptr_g = 0;
+\t// synopsys translate_on
+\talways @ ( posedge wrclk or posedge aclr)
+\t\tif (aclr == 1\'b1) delayed_wrptr_g <= 11\'b0;
+\t\telse delayed_wrptr_g <= wrptr_g;
+\t// synopsys translate_off
+\tinitial
+\t\twrptr_g = 0;
+\t// synopsys translate_on
+\talways @ ( posedge wrclk or posedge aclr)
+\t\tif (aclr == 1\'b1) wrptr_g <= 11\'b0;
+\t\telse if (valid_wrreq == 1\'b1) wrptr_g <= wire_wrptr_g1p_q;
+\tfifo_2k_dffpipe_ab3 rs_brp
+\t(
+\t.clock(rdclk),
+\t.clrn((~ aclr)),
+\t.d(wire_rdptr_g_gray2bin_bin),
+\t.q(wire_rs_brp_q));
+\tfifo_2k_dffpipe_ab3 rs_bwp
+\t(
+\t.clock(rdclk),
+\t.clrn((~ aclr)),
+\t.d(wire_rs_dgwp_gray2bin_bin),
+\t.q(wire_rs_bwp_q));
+\tfifo_2k_alt_synch_pipe_dm2 rs_dgwp
+\t(
+\t.clock(rdclk),
+\t.clrn((~ aclr)),
+\t.d(delayed_wrptr_g),
+\t.q(wire_rs_dgwp_q));
+\tfifo_2k_dffpipe_ab3 ws_brp
+\t(
+\t.clock(wrclk),
+\t.clrn((~ aclr)),
+\t.d(wire_ws_dgrp_gray2bin_bin),
+\t.q(wire_ws_brp_q));
+\tfifo_2k_dffpipe_ab3 ws_bwp
+\t(
+\t.clock(wrclk),
+\t.clrn((~ aclr)),
+\t.d(wire_wrptr_g_gray2bin_bin),
+\t.q(wire_ws_bwp_q));
+\tfifo_2k_alt_synch_pipe_dm2 ws_dgrp
+\t(
+\t.clock(wrclk),
+\t.clrn((~ aclr)),
+\t.d(wire_rdptr_g_q),
+\t.q(wire_ws_dgrp_q));
+\tfifo_2k_add_sub_a18 rdusedw_sub
+\t(
+\t.dataa(wire_rs_bwp_q),
+\t.datab(wire_rs_brp_q),
+\t.result(wire_rdusedw_sub_result));
+\tfifo_2k_add_sub_a18 wrusedw_sub
+\t(
+\t.dataa(wire_ws_bwp_q),
+\t.datab(wire_ws_brp_q),
+\t.result(wire_wrusedw_sub_result));
+\talways @(wire_rdempty_eq_comp_dataa or wire_rdempty_eq_comp_datab)
+\t\tif (wire_rdempty_eq_comp_dataa == wire_rdempty_eq_comp_datab)
+\t\t\tbegin
+\t\t\t\twire_rdempty_eq_comp_aeb_int = 1\'b1;
+\t\t\tend
+\t\telse
+\t\t\tbegin
+\t\t\t\twire_rdempty_eq_comp_aeb_int = 1\'b0;
+\t\t\tend
+\tassign
+\t\twire_rdempty_eq_comp_aeb = wire_rdempty_eq_comp_aeb_int;
+\tassign
+\t\twire_rdempty_eq_comp_dataa = wire_rs_dgwp_q,
+\t\twire_rdempty_eq_comp_datab = wire_rdptr_g_q;
+\talways @(wire_wrfull_eq_comp_dataa or wire_wrfull_eq_comp_datab)
+\t\tif (wire_wrfull_eq_comp_dataa == wire_wrfull_eq_comp_datab)
+\t\t\tbegin
+\t\t\t\twire_wrfull_eq_comp_aeb_int = 1\'b1;
+\t\t\tend
+\t\telse
+\t\t\tbegin
+\t\t\t\twire_wrfull_eq_comp_aeb_int = 1\'b0;
+\t\t\tend
+\tassign
+\t\twire_wrfull_eq_comp_aeb = wire_wrfull_eq_comp_aeb_int;
+\tassign
+\t\twire_wrfull_eq_comp_dataa = wire_ws_dgrp_q,
+\t\twire_wrfull_eq_comp_datab = wire_wrptr_g1p_q;
+\tassign
+\t\tint_rdempty = wire_rdempty_eq_comp_aeb,
+\t\tint_wrfull = wire_wrfull_eq_comp_aeb,
+\t\tq = wire_fifo_ram_q_b,
+\t\trdempty = int_rdempty,
+\t\trdusedw = wire_rdusedw_sub_result,
+\t\tvalid_rdreq = rdreq,
+\t\tvalid_wrreq = wrreq,
+\t\twrfull = int_wrfull,
+\t\twrusedw = wire_wrusedw_sub_result;
+endmodule //fifo_2k_dcfifo_0cq
+//VALID FILE
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module fifo_2k (
+\tdata,
+\twrreq,
+\trdreq,
+\trdclk,
+\twrclk,
+\taclr,
+\t'b'q,
+\trdempty,
+\trdusedw,
+\twrfull,
+\twrusedw)/* synthesis synthesis_clearbox = 1 */;
+
+\tinput\t[15:0] data;
+\tinput\t wrreq;
+\tinput\t rdreq;
+\tinput\t rdclk;
+\tinput\t wrclk;
+\tinput\t aclr;
+\toutput\t[15:0] q;
+\toutput\t rdempty;
+\toutput\t[10:0] rdusedw;
+\toutput\t wrfull;
+\toutput\t[10:0] wrusedw;
+
+\twire sub_wire0;
+\twire [10:0] sub_wire1;
+\twire sub_wire2;
+\twire [15:0] sub_wire3;
+\twire [10:0] sub_wire4;
+\twire rdempty = sub_wire0;
+\twire [10:0] wrusedw = sub_wire1[10:0];
+\twire wrfull = sub_wire2;
+\twire [15:0] q = sub_wire3[15:0];
+\twire [10:0] rdusedw = sub_wire4[10:0];
+
+\tfifo_2k_dcfifo_0cq\tfifo_2k_dcfifo_0cq_component (
+\t\t\t\t.wrclk (wrclk),
+\t\t\t\t.rdreq (rdreq),
+\t\t\t\t.aclr (aclr),
+\t\t\t\t.rdclk (rdclk),
+\t\t\t\t.wrreq (wrreq),
+\t\t\t\t.data (data),
+\t\t\t\t.rdempty (sub_wire0),
+\t\t\t\t.wrusedw (sub_wire1),
+\t\t\t\t.wrfull (sub_wire2),
+\t\t\t\t.q (sub_wire3),
+\t\t\t\t.rdusedw (sub_wire4));
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: Width NUMERIC ""16""
+// Retrieval info: PRIVATE: Depth NUMERIC ""2048""
+// Retrieval info: PRIVATE: Clock NUMERIC ""4""
+// Retrieval info: PRIVATE: CLOCKS_ARE_SYNCHRONIZED NUMERIC ""0""
+// Retrieval info: PRIVATE: Full NUMERIC ""1""
+// Retrieval info: PRIVATE: Empty NUMERIC ""1""
+// Retrieval info: PRIVATE: UsedW NUMERIC ""1""
+// Retrieval info: PRIVATE: AlmostFull NUMERIC ""0""
+// Retrieval info: PRIVATE: AlmostEmpty NUMERIC ""0""
+// Retrieval info: PRIVATE: AlmostFullThr NUMERIC ""-1""
+// Retrieval info: PRIVATE: AlmostEmptyThr NUMERIC ""-1""
+// Retrieval info: PRIVATE: sc_aclr NUMERIC ""0""
+// Retrieval info: PRIVATE: sc_sclr NUMERIC ""0""
+// Retrieval info: PRIVATE: rsFull NUMERIC ""0""
+// Retrieval info: PRIVATE: rsEmpty NUMERIC ""1""
+// Retrieval info: PRIVATE: rsUsedW NUMERIC ""1""
+// Retrieval info: PRIVATE: wsFull NUMERIC ""1""
+// Retrieval info: PRIVATE: wsEmpty NUMERIC ""0""
+// Retrieval info: PRIVATE: wsUsedW NUMERIC ""1""
+// Retrieval info: PRIVATE: dc_aclr NUMERIC ""1""
+// Retrieval info: PRIVATE: LegacyRREQ NUMERIC ""0""
+// Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC ""0""
+// Retrieval info: PRIVATE: MAX_DEPTH_BY_9 NUMERIC ""0""
+// Retrieval info: PRIVATE: LE_BasedFIFO NUMERIC ""0""
+// Retrieval info: PRIVATE: Optimize NUMERIC ""2""
+// Retrieval info: PRIVATE: OVERFLOW_CHECKING NUMERIC ""1""
+// Retrieval info: PRIVATE: UNDERFLOW_CHECKING NUMERIC ""1""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: CONSTANT: LPM_WIDTH NUMERIC ""16""
+// Retrieval info: CONSTANT: LPM_NUMWORDS NUMERIC ""2048""
+// Retrieval info: CONSTANT: LPM_WIDTHU NUMERIC ""11""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: CONSTANT: CLOCKS_ARE_SYNCHRONIZED STRING ""FALSE""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""dcfifo""
+// Retrieval info: CONSTANT: LPM_SHOWAHEAD STRING ""ON""
+// Retrieval info: CONSTANT: OVERFLOW_CHECKING STRING ""OFF""
+// Retrieval info: CONSTANT: UNDERFLOW_CHECKING STRING ""OFF""
+// Retrieval info: CONSTANT: USE_EAB STRING ""ON""
+// Retrieval info: CONSTANT: ADD_RAM_OUTPUT_REGISTER STRING ""OFF""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: USED_PORT: data 0 0 16 0 INPUT NODEFVAL data[15..0]
+// Retrieval info: USED_PORT: q 0 0 16 0 OUTPUT NODEFVAL q[15..0]
+// Retrieval info: USED_PORT: wrreq 0 0 0 0 INPUT NODEFVAL wrreq
+// Retrieval info: USED_PORT: rdreq 0 0 0 0 INPUT NODEFVAL rdreq
+// Retrieval info: USED_PORT: rdclk 0 0 0 0 INPUT NODEFVAL rdclk
+// Retrieval info: USED_PORT: wrclk 0 0 0 0 INPUT NODEFVAL wrclk
+// Retrieval info: USED_PORT: rdempty 0 0 0 0 OUTPUT NODEFVAL rdempty
+// Retrieval info: USED_PORT: rdusedw 0 0 11 0 OUTPUT NODEFVAL rdusedw[10..0]
+// Retrieval info: USED_PORT: wrfull 0 0 0 0 OUTPUT NODEFVAL wrfull
+// Retrieval info: USED_PORT: wrusedw 0 0 11 0 OUTPUT NODEFVAL wrusedw[10..0]
+// Retrieval info: USED_PORT: aclr 0 0 0 0 INPUT GND aclr
+// Retrieval info: CONNECT: @data 0 0 16 0 data 0 0 16 0
+// Retrieval info: CONNECT: q 0 0 16 0 @q 0 0 16 0
+// Retrieval info: CONNECT: @wrreq 0 0 0 0 wrreq 0 0 0 0
+// Retrieval info: CONNECT: @rdreq 0 0 0 0 rdreq 0 0 0 0
+// Retrieval info: CONNECT: @rdclk 0 0 0 0 rdclk 0 0 0 0
+// Retrieval info: CONNECT: @wrclk 0 0 0 0 wrclk 0 0 0 0
+// Retrieval info: CONNECT: rdempty 0 0 0 0 @rdempty 0 0 0 0
+// Retrieval info: CONNECT: rdusedw 0 0 11 0 @rdusedw 0 0 11 0
+// Retrieval info: CONNECT: wrfull 0 0 0 0 @wrfull 0 0 0 0
+// Retrieval info: CONNECT: wrusedw 0 0 11 0 @wrusedw 0 0 11 0
+// Retrieval info: CONNECT: @aclr 0 0 0 0 aclr 0 0 0 0
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k_bb.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k_waveforms.html TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_2k_wave*.jpg FALSE
+"
+"
+
+module mac (input clock, input reset, input enable, input clear,
+\t input signed [15:0] x, input signed [15:0] y,
+\t input [7:0] shift, output [15:0] z );
+
+ reg signed [30:0] product;
+ reg signed [39:0] z_int;
+ reg signed [15:0] z_shift;
+
+ reg enable_d1;
+ always @(posedge clock)
+ enable_d1 <= #1 enable;
+
+ always @(posedge clock)
+ if(reset | clear)
+ z_int <= #1 40'd0;
+ else if(enable_d1)
+ z_int <= #1 z_int + {{9{product[30]}},product};
+
+ always @(posedge clock)
+ product <= #1 x*y;
+
+ always @* // FIXME full case? parallel case?
+ case(shift)
+ //8'd0 : z_shift <= z_int[39:24];
+ //8'd1 : z_shift <= z_int[38:23];
+ //8'd2 : z_shift <= z_int[37:22];
+ //8'd3 : z_shift <= z_int[36:21];
+ //8'd4 : z_shift <= z_int[35:20];
+ //8'd5 : z_shift <= z_int[34:19];
+ 8'd6 : z_shift <= z_int[33:18];
+ 8'd7 : z_shift <= z_int[32:17];
+ 8'd8 : z_shift <= z_int[31:16];
+ 8'd9 : z_shift <= z_int[30:15];
+ 8'd10 : z_shift <= z_int[29:14];
+ 8'd11 : z_shift <= z_int[28:13];
+ //8'd12 : z_shift <= z_int[27:12];
+ //8'd13 : z_shift <= z_int[26:11];
+ //8'd14 : z_shift <= z_int[25:10];
+ //8'd15 : z_shift <= z_int[24:9];
+ //8'd16 : z_shift <= z_int[23:8];
+ //8'd17 : z_shift <= z_int[22:7];
+ //8'd18 : z_shift <= z_int[21:6];
+ //8'd19 : z_shift <= z_int[20:5];
+ //8'd20 : z_shift <= z_int[19:4];
+ //8'd21 : z_shift <= z_int[18:3];
+ //8'd22 : z_shift <= z_int[17:2];
+ //8'd23 : z_shift <= z_int[16:1];
+ //8'd24 : z_shift <= z_int[15:0];
+ default : z_shift <= z_int[15:0];
+ endcase // case(shift)
+
+ // FIXME do we need to saturate?
+ //assign z = z_shift;
+ assign z = z_int[15:0];
+
+endmodule // mac
+"
+"// -*- verilog -*-\r
+//\r
+// USRP - Universal Software Radio Peripheral\r
+//\r
+// Copyright (C) 2007 Corgan Enterprises LLC\r
+//\r
+// This program is free software; you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation; either version 2 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA\r
+//\r
+\r
+`include ""../top/config.vh""\r
+\r
+module dac_interface(clk_i,rst_i,ena_i,strobe_i,tx_i_i,tx_q_i,tx_data_o,tx_sync_o);\r
+ input clk_i;\r
+ input rst_i;\r
+ input ena_i;\r
+ input strobe_i;\r
+ \r
+ input [13:0] tx_i_i;\r
+ input [13:0] tx_q_i;\r
+\r
+ output [13:0] tx_data_o;\r
+ output \t tx_sync_o;\r
+\r
+`ifdef TX_RATE_MAX\r
+ wire clk128;\r
+ reg clk64_d;\r
+ reg [13:0] tx_data_o;\r
+ \r
+ // Create a 128 MHz clock\r
+ dacpll pll128(.areset(rst_i),.inclk0(clk_i),.c0(clk128));\r
+\r
+ // Register the clk64 clock in the clk128 domain\r
+ always @(posedge clk128)\r
+ clk64_d <= clk_i;\r
+\r
+ // Register the tx data in the clk128 domain\r
+ always @(posedge clk128)\r
+ tx_data_o <= clk64_d ? tx_i_i : tx_q_i;\r
+\r
+ assign tx_sync_o = clk64_d;\r
+ \r
+\r
+`else // !`ifdef TX_RATE_MAX\r
+ assign tx_data_o = strobe_i ? tx_i_i : tx_q_i;\r
+ assign tx_sync_o = strobe_i;\r
+`endif // !`ifdef TX_RATE_MAX\r
+ \r
+endmodule // dac_interface\r
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003,2005 Matt Ettus
+// Copyright (C) 2007 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+// Clock, enable, and reset controls for whole system
+
+module master_control
+ ( input master_clk, input usbclk,
+ input wire [6:0] serial_addr, input wire [31:0] serial_data, input wire serial_strobe,
+ output tx_bus_reset, output rx_bus_reset,
+ output wire tx_dsp_reset, output wire rx_dsp_reset,
+ output wire enable_tx, output wire enable_rx,
+ output wire [7:0] interp_rate, output wire [7:0] decim_rate,
+ output tx_sample_strobe, output strobe_interp,
+ output rx_sample_strobe, output strobe_decim,
+ input tx_empty,
+ input wire [15:0] debug_0,input wire [15:0] debug_1,input wire [15:0] debug_2,input wire [15:0] debug_3,
+ output wire [15:0] reg_0, output wire [15:0] reg_1, output wire [15:0] reg_2, output wire [15:0] reg_3
+ );
+
+ // FIXME need a separate reset for all control settings
+ // Master Controls assignments
+ wire [7:0] master_controls;
+ setting_reg #(`FR_MASTER_CTRL) sr_mstr_ctrl(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(master_controls));
+ assign enable_tx = master_controls[0];
+ assign enable_rx = master_controls[1];
+ assign tx_dsp_reset = master_controls[2];
+ assign rx_dsp_reset = master_controls[3];
+ // Unused - 4-7
+
+ // Strobe Generators
+ setting_reg #(`FR_INTERP_RATE) sr_interp(.clock(master_clk),.reset(tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(interp_rate));
+ setting_reg #(`FR_DECIM_RATE) sr_decim(.clock(master_clk),.reset(rx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(decim_rate));
+
+ strobe_gen da_strobe_gen
+ ( .clock(master_clk),.reset(tx_dsp_reset),.enable(enable_tx),
+ .rate(8'd1),.strobe_in(1'b1),.strobe(tx_sample_strobe) );
+
+ strobe_gen tx_strobe_gen
+ ( .clock(master_clk),.reset(tx_dsp_reset),.enable(enable_tx),
+ .rate(interp_rate),.strobe_in(tx_sample_strobe),.strobe(strobe_interp) );
+
+ assign rx_sample_strobe = 1'b1;
+
+ strobe_gen decim_strobe_gen
+ ( .clock(master_clk),.reset(rx_dsp_reset),.enable(enable_rx),
+ .rate(decim_rate),.strobe_in(rx_sample_strobe),.strobe(strobe_decim) );
+
+ // Reset syncs for bus (usbclk) side
+ // The RX bus side reset isn't used, the TX bus side one may not be needed
+ reg \t tx_reset_bus_sync1, rx_reset_bus_sync1, tx_reset_bus_sync2, rx_reset_bus_sync2;
+ \t
+ always @(posedge usbclk)
+ begin
+ \ttx_reset_bus_sync1 <= #1 tx_dsp_reset;
+ \trx_reset_bus_sync1 <= #1 rx_dsp_reset;
+ \ttx_reset_bus_sync2 <= #1 tx_reset_bus_sync1;
+ \trx_reset_bus_sync2 <= #1 rx_reset_bus_sync1;
+ end
+
+ assign tx_bus_reset = tx_reset_bus_sync2;
+ assign rx_bus_reset = rx_reset_bus_sync2;
+
+ wire [7:0] txa_refclk, rxa_refclk, txb_refclk, rxb_refclk;
+ wire txaclk,txbclk,rxaclk,rxbclk;
+ wire [3:0] debug_en, txcvr_ctrl;
+
+ wire [31:0] txcvr_rxlines, txcvr_txlines;
+
+ setting_reg #(`FR_TX_A_REFCLK) sr_txaref(.clock(master_clk),.reset(tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(txa_refclk));
+ setting_reg #(`FR_RX_A_REFCLK) sr_rxaref(.clock(master_clk),.reset(rx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(rxa_refclk));
+ setting_reg #(`FR_TX_B_REFCLK) sr_txbref(.clock(master_clk),.reset(tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(txb_refclk));
+ setting_reg #(`FR_RX_B_REFCLK) sr_rxbref(.clock(master_clk),.reset(rx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(rxb_refclk));
+
+ setting_reg #(`FR_DEBUG_EN) sr_debugen(.clock(master_clk),.reset(rx_dsp_reset|tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(debug_en));
+
+ clk_divider clk_div_0 (.reset(tx_dsp_reset),.in_clk(master_clk),.out_clk(txaclk),.ratio(txa_refclk[6:0]));
+ clk_divider clk_div_1 (.reset(rx_dsp_reset),.in_clk(master_clk),.out_clk(rxaclk),.ratio(rxa_refclk[6:0]));
+ clk_divider clk_div_2 (.reset(tx_dsp_reset),.in_clk(master_clk),.out_clk(txbclk),.ratio(txb_refclk[6:0]));
+ clk_divider clk_div_3 (.reset(rx_dsp_reset),.in_clk(master_clk),.out_clk(rxbclk),.ratio(rxb_refclk[6:0]));
+
+ reg [15:0] io_0_reg,io_1_reg,io_2_reg,io_3_reg;
+ // Upper 16 bits are mask for lower 16
+ always @(posedge master_clk)
+ if(serial_strobe)
+ case(serial_addr)
+\t `FR_IO_0 : io_0_reg
+\t <= #1 (io_0_reg & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] );
+\t `FR_IO_1 : io_1_reg
+\t <= #1 (io_1_reg & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] );
+\t `FR_IO_2 : io_2_reg
+\t <= #1 (io_2_reg & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] );
+\t `FR_IO_3 : io_3_reg
+\t <= #1 (io_3_reg & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] );
+ endcase // case(serial_addr)
+
+ wire transmit_now;
+ wire atr_ctl;
+ wire [11:0] atr_tx_delay, atr_rx_delay;
+ wire [15:0] atr_mask_0, atr_txval_0, atr_rxval_0, atr_mask_1, atr_txval_1, atr_rxval_1, atr_mask_2, atr_txval_2, atr_rxval_2, atr_mask_3, atr_txval_3, atr_rxval_3;
+
+ setting_reg #(`FR_ATR_MASK_0) sr_atr_mask_0(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_mask_0));
+ setting_reg #(`FR_ATR_TXVAL_0) sr_atr_txval_0(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_txval_0));
+ setting_reg #(`FR_ATR_RXVAL_0) sr_atr_rxval_0(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_rxval_0));
+
+ setting_reg #(`FR_ATR_MASK_1) sr_atr_mask_1(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_mask_1));
+ setting_reg #(`FR_ATR_TXVAL_1) sr_atr_txval_1(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_txval_1));
+ setting_reg #(`FR_ATR_RXVAL_1) sr_atr_rxval_1(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_rxval_1));
+
+ setting_reg #(`FR_ATR_MASK_2) sr_atr_mask_2(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_mask_2));
+ setting_reg #(`FR_ATR_TXVAL_2) sr_atr_txval_2(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_txval_2));
+ setting_reg #(`FR_ATR_RXVAL_2) sr_atr_rxval_2(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_rxval_2));
+
+ setting_reg #(`FR_ATR_MASK_3) sr_atr_mask_3(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_mask_3));
+ setting_reg #(`FR_ATR_TXVAL_3) sr_atr_txval_3(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_txval_3));
+ setting_reg #(`FR_ATR_RXVAL_3) sr_atr_rxval_3(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_rxval_3));
+
+ //setting_reg #(`FR_ATR_CTL) sr_atr_ctl(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_ctl));
+ setting_reg #(`FR_ATR_TX_DELAY) sr_atr_tx_delay(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_tx_delay));
+ setting_reg #(`FR_ATR_RX_DELAY) sr_atr_rx_delay(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_rx_delay));
+
+ assign atr_ctl = 1'b1;
+
+ atr_delay atr_delay(.clk_i(master_clk),.rst_i(tx_dsp_reset),.ena_i(atr_ctl),.tx_empty_i(tx_empty),
+\t\t .tx_delay_i(atr_tx_delay),.rx_delay_i(atr_rx_delay),.atr_tx_o(transmit_now));
+
+ wire [15:0] atr_selected_0 = transmit_now ? atr_txval_0 : atr_rxval_0;
+ wire [15:0] io_0 = ({{16{atr_ctl}}} & atr_mask_0 & atr_selected_0) | (~({{16{atr_ctl}}} & atr_mask_0) & io_0_reg);
+
+ wire [15:0] atr_selected_1 = transmit_now ? atr_txval_1 : atr_rxval_1;
+ wire [15:0] io_1 = ({{16{atr_ctl}}} & atr_mask_1 & atr_selected_1) | (~({{16{atr_ctl}}} & atr_mask_1) & io_1_reg);
+
+ wire [15:0] atr_selected_2 = transmit_now ? atr_txval_2 : atr_rxval_2;
+ wire [15:0] io_2 = ({{16{atr_ctl}}} & atr_mask_2 & atr_selected_2) | (~({{16{atr_ctl}}} & atr_mask_2) & io_2_reg);
+
+ wire [15:0] atr_selected_3 = transmit_now ? atr_txval_3 : atr_rxval_3;
+ wire [15:0] io_3 = ({{16{atr_ctl}}} & atr_mask_3 & atr_selected_3) | (~({{16{atr_ctl}}} & atr_mask_3) & io_3_reg);
+
+ assign reg_0 = debug_en[0] ? debug_0 : txa_refclk[7] ? {io_0[15:1],txaclk} : io_0;
+ assign reg_1 = debug_en[1] ? debug_1 : rxa_refclk[7] ? {io_1[15:1],rxaclk} : io_1;
+ assign reg_2 = debug_en[2] ? debug_2 : txb_refclk[7] ? {io_2[15:1],txbclk} : io_2;
+ assign reg_3 = debug_en[3] ? debug_3 : rxb_refclk[7] ? {io_3[15:1],rxbclk} : io_3;
+
+
+endmodule // master_control
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+
+
+module cordic_tb();
+
+ cordic cordic(clk, reset, enable, xi, yi, zi, xo, yo, zo );
+
+ reg reset;
+ reg clk;
+ reg enable;
+ reg [15:0] xi, yi, zi;
+
+ initial reset = 1\'b1;
+ initial #1000 reset = 1\'b0;
+
+ initial clk = 1\'b0;
+ always #50 clk <= ~clk;
+
+ initial enable = 1\'b1;
+
+ initial zi = 16\'b0;
+
+ always @(posedge clk)
+ zi <= #1 zi + 16\'d0;
+
+ wire [15:0] xo,yo,zo;
+
+ initial $dumpfile(""cordic.vcd"");
+ initial $dumpvars(0,cordic_tb);
+ initial
+ begin
+`include ""sine.txt""
+ end
+
+\twire [15:0] xiu = {~xi[15],xi[14:0]};
+\twire [15:0] yiu = {~yi[15],yi[14:0]};
+\twire [15:0] xou = {~xo[15],xo[14:0]};
+\twire [15:0] you = {~yo[15],yo[14:0]};
+ initial $monitor(""%d\\t%d\\t%d\\t%d\\t%d"",$time,xiu,yiu,xou,you);
+
+endmodule // cordic_tb
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+// Following defines conditionally include RX path circuitry
+
+`include ""config.vh""\t// resolved relative to project root
+
+module rx_chain
+ (input clock,
+ input reset,
+ input enable,
+ input wire [7:0] decim_rate,
+ input sample_strobe,
+ input decimator_strobe,
+ output wire hb_strobe,
+ input [6:0] serial_addr, input [31:0] serial_data, input serial_strobe,
+ input wire [15:0] i_in,
+ input wire [15:0] q_in,
+ output wire [15:0] i_out,
+ output wire [15:0] q_out,
+ output wire [15:0] debugdata,output wire [15:0] debugctrl
+ );
+
+ parameter FREQADDR = 0;
+ parameter PHASEADDR = 0;
+
+ wire [31:0] phase;
+ wire [15:0] bb_i, bb_q;
+ wire [15:0] hb_in_i, hb_in_q;
+
+ assign\tdebugdata = hb_in_i;
+
+`ifdef RX_NCO_ON
+ phase_acc #(FREQADDR,PHASEADDR,32) rx_phase_acc
+ (.clk(clock),.reset(reset),.enable(enable),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .strobe(sample_strobe),.phase(phase) );
+
+ cordic rx_cordic
+ ( .clock(clock),.reset(reset),.enable(enable),
+ .xi(i_in),.yi(q_in),.zi(phase[31:16]),
+ .xo(bb_i),.yo(bb_q),.zo() );
+`else
+ assign bb_i = i_in;
+ assign bb_q = q_in;
+ assign sample_strobe = 1;
+`endif // !`ifdef RX_NCO_ON
+
+`ifdef RX_INTEG_ON
+ integrator integ_decim_i_0
+ ( .clock(clock),.reset(reset),.enable(enable),
+ .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe),
+ .signal_in(bb_i),.signal_out(i_out) );
+
+ assign hb_strobe = decimator_strobe;
+`else
+`ifdef RX_CIC_ON
+ cic_decim cic_decim_i_0
+ ( .clock(clock),.reset(reset),.enable(enable),
+ .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe),
+ .signal_in(bb_i),.signal_out(hb_in_i) );
+`else
+ assign hb_in_i = bb_i;
+ assign decimator_strobe = sample_strobe;
+`endif
+
+`ifdef RX_HB_ON
+ halfband_decim hbd_i_0
+ ( .clock(clock),.reset(reset),.enable(enable),
+ .strobe_in(decimator_strobe),.strobe_out(hb_strobe),
+ .data_in(hb_in_i),.data_out(i_out),.debugctrl(debugctrl) );
+`else
+ assign i_out = hb_in_i;
+ assign hb_strobe = decimator_strobe;
+`endif
+`endif // RX_INTEG_ON
+
+`ifdef RX_INTEG_ON
+ integrator integ_decim_q_0
+ ( .clock(clock),.reset(reset),.enable(enable),
+ .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe),
+ .signal_in(bb_q),.signal_out(q_out) );
+`else
+`ifdef RX_CIC_ON
+ cic_decim cic_decim_q_0
+ ( .clock(clock),.reset(reset),.enable(enable),
+ .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe),
+ .signal_in(bb_q),.signal_out(hb_in_q) );
+`else
+ assign hb_in_q = bb_q;
+`endif
+
+`ifdef RX_HB_ON
+ halfband_decim hbd_q_0
+ ( .clock(clock),.reset(reset),.enable(enable),
+ .strobe_in(decimator_strobe),.strobe_out(),
+ .data_in(hb_in_q),.data_out(q_out) );
+`else
+ assign q_out = hb_in_q;
+`endif
+`endif // RX_INTEG_ON
+
+endmodule // rx_chain
+"
+"
+
+module ram (input clock, input write,
+\t input [4:0] wr_addr, input [15:0] wr_data,
+\t input [4:0] rd_addr, output reg [15:0] rd_data);
+
+ reg [15:0] \t\tram_array [0:31];
+
+ always @(posedge clock)
+ rd_data <= #1 ram_array[rd_addr];
+
+ always @(posedge clock)
+ if(write)
+ ram_array[wr_addr] <= #1 wr_data;
+
+endmodule // ram
+"
+"/* -*- verilog -*- */
+/*
+ * Copyright (C) 2003 Matt Ettus
+ * Copyright (C) 2007 Corgan Enterprises LLC
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+// Model of Altera FIFO with common clock domain
+
+module fifo_1clk(data, wrreq, rdreq, clock, sclr, q,
+\t\t full, empty, usedw);
+
+ parameter width = 32;
+ parameter depth = 4096;
+ //`define rd_req 0; // Set this to 0 for rd_ack, 1 for rd_req
+
+ input [31:0] data;
+ input \t wrreq;
+ input \t rdreq;
+ input \t clock;
+ input \t sclr;
+ output [31:0] q;
+ output \t full;
+ output \t empty;
+ output [11:0] usedw;
+
+ reg [width-1:0] mem [0:depth-1];
+ reg [7:0] \t rdptr;
+ reg [7:0] \t wrptr;
+
+`ifdef rd_req
+ reg [width-1:0] q;
+`else
+ wire [width-1:0] q;
+`endif
+
+ reg [11:0] \t usedw;
+
+ integer \t i;
+
+ always @( sclr)
+ begin
+\twrptr <= #1 0;
+\trdptr <= #1 0;
+\tfor(i=0;i=0;i=i-1)
+\t bin_val[i] = bin_val[i+1] ^ gray_val[i];
+ end
+endmodule // gray2bin
+"
+"
+
+module ram16_2port (input clock, input write,
+\t\t input [3:0] wr_addr, input [15:0] wr_data,
+\t\t input [3:0] rd_addr1, output reg [15:0] rd_data1,
+\t\t input [3:0] rd_addr2, output reg [15:0] rd_data2);
+
+ reg [15:0] \t\t\tram_array [0:31];
+
+ always @(posedge clock)
+ rd_data1 <= #1 ram_array[rd_addr1];
+
+ always @(posedge clock)
+ rd_data2 <= #1 ram_array[rd_addr2];
+
+ always @(posedge clock)
+ if(write)
+ ram_array[wr_addr] <= #1 wr_data;
+
+endmodule // ram16_2port
+
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2005,2006 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+`include ""../../firmware/include/fpga_regs_common.v""
+`include ""../../firmware/include/fpga_regs_standard.v""
+
+module io_pins
+ ( inout wire [15:0] io_0, inout wire [15:0] io_1, inout wire [15:0] io_2, inout wire [15:0] io_3,
+ input wire [15:0] reg_0, input wire [15:0] reg_1, input wire [15:0] reg_2, input wire [15:0] reg_3,
+ input clock, input rx_reset, input tx_reset,
+ input [6:0] serial_addr, input [31:0] serial_data, input serial_strobe);
+
+ reg [15:0] io_0_oe,io_1_oe,io_2_oe,io_3_oe;
+
+ bidir_reg bidir_reg_0 (.tristate(io_0),.oe(io_0_oe),.reg_val(reg_0));
+ bidir_reg bidir_reg_1 (.tristate(io_1),.oe(io_1_oe),.reg_val(reg_1));
+ bidir_reg bidir_reg_2 (.tristate(io_2),.oe(io_2_oe),.reg_val(reg_2));
+ bidir_reg bidir_reg_3 (.tristate(io_3),.oe(io_3_oe),.reg_val(reg_3));
+
+ // Upper 16 bits are mask for lower 16
+ always @(posedge clock)
+ if(serial_strobe)
+ case(serial_addr)
+\t `FR_OE_0 : io_0_oe
+\t <= #1 (io_0_oe & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] );
+\t `FR_OE_1 : io_1_oe
+\t <= #1 (io_1_oe & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] );
+\t `FR_OE_2 : io_2_oe
+\t <= #1 (io_2_oe & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] );
+\t `FR_OE_3 : io_3_oe
+\t <= #1 (io_3_oe & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] );
+ endcase // case(serial_addr)
+
+endmodule // io_pins
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003,2004 Matt Ettus
+// Copyright (C) 2008 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+// Top level module for a full setup with DUCs and DDCs
+
+// Define DEBUG_OWNS_IO_PINS if we\'re using the daughterboard i/o pins
+// for debugging info. NB, This can kill the m\'board and/or d\'board if you
+// have anything except basic d\'boards installed.
+
+// Uncomment the following to include optional circuitry
+
+`include ""../top/config.vh""
+`include ""../../../../usrp/firmware/include/fpga_regs_common.v""
+`include ""../../../../usrp/firmware/include/fpga_regs_standard.v""
+
+module usrp_gpio
+(output MYSTERY_SIGNAL,
+ input master_clk,
+ input SCLK,
+ input SDI,
+ inout SDO,
+ input SEN_FPGA,
+
+ input FX2_1,
+ output FX2_2,
+ output FX2_3,
+
+ input wire [11:0] rx_a_a,
+ input wire [11:0] rx_b_a,
+ input wire [11:0] rx_a_b,
+ input wire [11:0] rx_b_b,
+
+ output wire [13:0] tx_a,
+ output wire [13:0] tx_b,
+
+ output wire TXSYNC_A,
+ output wire TXSYNC_B,
+
+ // USB interface
+ input usbclk,
+ input wire [2:0] usbctl,
+ output wire [1:0] usbrdy,
+ inout [15:0] usbdata, // NB Careful, inout
+
+ // These are the general purpose i/o\'s that go to the daughterboard slots
+ inout wire [15:0] io_tx_a,
+ inout wire [15:0] io_tx_b,
+ inout wire [15:0] io_rx_a,
+ inout wire [15:0] io_rx_b
+ );\t
+ wire [15:0] debugdata,debugctrl;
+ assign MYSTERY_SIGNAL = 1\'b0;
+
+ wire clk64,clk128;
+
+ wire WR = usbctl[0];
+ wire RD = usbctl[1];
+ wire OE = usbctl[2];
+
+ wire have_space, have_pkt_rdy;
+ assign usbrdy[0] = have_space;
+ assign usbrdy[1] = have_pkt_rdy;
+
+ wire tx_underrun, rx_overrun;
+ wire clear_status = FX2_1;
+ assign FX2_2 = rx_overrun;
+ assign FX2_3 = tx_underrun;
+
+ wire [15:0] usbdata_out;
+
+ wire [3:0] dac0mux,dac1mux,dac2mux,dac3mux;
+
+ wire tx_realsignals;
+ wire [3:0] rx_numchan;
+ wire [2:0] tx_numchan;
+
+ wire [7:0] interp_rate, decim_rate;
+ wire [31:0] tx_debugbus, rx_debugbus;
+
+ wire enable_tx, enable_rx;
+ wire tx_dsp_reset, rx_dsp_reset, tx_bus_reset, rx_bus_reset;
+ wire [7:0] settings;
+
+ // Tri-state bus macro
+ bustri bustri( .data(usbdata_out),.enabledt(OE),.tridata(usbdata) );
+
+ assign clk64 = master_clk;
+
+ wire [15:0] ch0tx,ch1tx,ch2tx,ch3tx; //,ch4tx,ch5tx,ch6tx,ch7tx;
+ wire [15:0] ch0rx,ch1rx,ch2rx,ch3rx,ch4rx,ch5rx,ch6rx,ch7rx;
+ wire [15:0] ch0rx_ext,ch1rx_ext;
+
+ // TX
+ wire [15:0] i_out_0,i_out_1,q_out_0,q_out_1;//analog signals
+ wire [15:0] bb_tx_i0,bb_tx_q0,bb_tx_i1,bb_tx_q1; // bb_tx_i2,bb_tx_q2,bb_tx_i3,bb_tx_q3;
+
+ wire strobe_interp, tx_sample_strobe;
+ wire tx_empty;
+
+ wire serial_strobe;
+ wire [6:0] serial_addr;
+ wire [31:0] serial_data;
+
+ reg [15:0] debug_counter;
+ reg [15:0] loopback_i_0,loopback_q_0;
+
+ //TX_DIG streaming digital IO signals
+ wire i_out_dig_0,i_out_dig_1,q_out_dig_0,q_out_dig_1;
+ wire rx_dig0_i, rx_dig0_q,rx_dig1_i,rx_dig1_q;
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Transmit Side
+`ifdef TX_ON
+
+ tx_buffer tx_buffer
+ ( .usbclk(usbclk), .bus_reset(tx_bus_reset),
+ .usbdata(usbdata),.WR(WR), .have_space(have_space),
+ .tx_underrun(tx_underrun), .clear_status(clear_status),
+ .txclk(clk64), .reset(tx_dsp_reset),
+ .channels({tx_numchan,1\'b0}),
+ .tx_i_0(ch0tx),.tx_q_0(ch1tx),
+ .tx_i_1(ch2tx),.tx_q_1(ch3tx),
+ .txstrobe(strobe_interp),
+ .tx_empty(tx_empty),
+ .debugbus(tx_debugbus) );
+
+ `ifdef TX_EN_0
+ tx_chain tx_chain_0
+ ( .clock(clk64),.reset(tx_dsp_reset),.enable(enable_tx),
+ .interp_rate(interp_rate),.sample_strobe(tx_sample_strobe),
+ .interpolator_strobe(strobe_interp),.freq(),
+ .i_in(bb_tx_i0),.q_in(bb_tx_q0),.i_out(i_out_0),.q_out(q_out_0));
+ `else
+ assign i_out_0=16\'d0;
+ assign q_out_0=16\'d0;
+ `endif
+
+ `ifdef TX_EN_1
+ tx_chain tx_chain_1
+ ( .clock(clk64),.reset(tx_dsp_reset),.enable(enable_tx),
+ .interp_rate(interp_rate),.sample_strobe(tx_sample_strobe),
+ .interpolator_strobe(strobe_interp),.freq(),
+ .i_in(bb_tx_i1),.q_in(bb_tx_q1),.i_out(i_out_1),.q_out(q_out_1) );
+ `else
+ assign i_out_1=16\'d0;
+ assign q_out_1=16\'d0;
+ `endif
+
+
+
+ setting_reg #(`FR_TX_MUX)
+ sr_txmux(.clock(clk64),.reset(tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
+\t .out({dac3mux,dac2mux,dac1mux,dac0mux,tx_realsignals,tx_numchan}));
+
+ wire [15:0] tx_a_a = dac0mux[3] ? (dac0mux[1] ? (dac0mux[0] ? q_out_1 : i_out_1) : (dac0mux[0] ? q_out_0 : i_out_0)) : 16\'b0;
+ wire [15:0] tx_b_a = dac1mux[3] ? (dac1mux[1] ? (dac1mux[0] ? q_out_1 : i_out_1) : (dac1mux[0] ? q_out_0 : i_out_0)) : 16\'b0;
+ wire [15:0] tx_a_b = dac2mux[3] ? (dac2mux[1] ? (dac2mux[0] ? q_out_1 : i_out_1) : (dac2mux[0] ? q_out_0 : i_out_0)) : 16\'b0;
+ wire [15:0] tx_b_b = dac3mux[3] ? (dac3mux[1] ? (dac3mux[0] ? q_out_1 : i_out_1) : (dac3mux[0] ? q_out_0 : i_out_0)) : 16\'b0;
+
+ wire tx_dig_a_a = (dac0mux[1] ? (dac0mux[0] ? q_out_dig_1 : i_out_dig_1) : (dac0mux[0] ? q_out_dig_0 : i_out_dig_0));
+ wire tx_dig_b_a = (dac1mux[1] ? (dac1mux[0] ? q_out_dig_1 : i_out_dig_1) : (dac1mux[0] ? q_out_dig_0 : i_out_dig_0));
+ wire tx_dig_a_b = (dac2mux[1] ? (dac2mux[0] ? q_out_dig_1 : i_out_dig_1) : (dac2mux[0] ? q_out_dig_0 : i_out_dig_0));
+ wire tx_dig_b_b = (dac3mux[1] ? (dac3mux[0] ? q_out_dig_1 : i_out_dig_1) : (dac3mux[0] ? q_out_dig_0 : i_out_dig_0));
+
+ //wire [1:0] tx_dig_a = {tx_dig_a_a,tx_dig_b_a};
+ //wire [1:0] tx_dig_b = {tx_dig_a_b,tx_dig_b_b};
+
+ //wire tx_dig_a_chan = (dac0mux[1] | dac1mux[1] );
+ //wire tx_dig_b_chan = (dac2mux[1] | dac3mux[1] );
+
+ //TODO make enabling tx_dig configurable through register
+
+ wire enable_tx_dig_a = 1\'b1 & enable_tx;
+ wire enable_tx_dig_b = 1\'b1 & enable_tx;
+
+ wire tx_dig_a_a_en = dac0mux[3] & enable_tx_dig_a;
+ wire tx_dig_b_a_en = dac1mux[3] & enable_tx_dig_a;
+ wire tx_dig_a_b_en = dac2mux[3] & enable_tx_dig_b;
+ wire tx_dig_b_b_en = dac3mux[3] & enable_tx_dig_b;
+
+ //TODO make gpio bits used for tx_dig configurable through register
+ assign io_tx_a_out = {tx_dig_a_a_en?tx_dig_a_a:reg_0[15],tx_dig_b_a_en?tx_dig_b_a:reg_0[14],reg_0[13:0]};
+ assign io_tx_b_out = {tx_dig_a_b_en?tx_dig_a_b:reg_2[15],tx_dig_b_b_en?tx_dig_b_b:reg_2[14],reg_2[13:0]};
+ assign io_tx_a_force_output = {tx_dig_a_a_en,tx_dig_b_a_en,14\'b0};
+ assign io_tx_b_force_output = {tx_dig_a_b_en,tx_dig_b_b_en,14\'b0};
+
+
+ `ifdef TX_EN_DIG_0
+ //TODO make enabling tx_dig configurable through register
+ //tx_chain_dig tx_chain_dig_0
+ // ( .clock(clk64),.reset(tx_dsp_reset),.enable(enable_tx),
+ // .i_in(ch0tx), q_in(ch1tx),
+ // .i_out_ana(bb_tx_i0),
+ // .q_out_ana(bb_tx_q0),
+ // .i_out_dig(i_out_dig_0),
+ // .q_out_dig(q_out_dig_0)
+ // );
+ tx_chain_dig tx_chain_dig_0
+ ( .clock(clk64),.reset(tx_dsp_reset),.enable(enable_tx),
+ .i_in(ch0tx),.q_in(ch1tx),
+ .i_out_ana(bb_tx_i0),.q_out_ana(bb_tx_q0),
+ .i_out_dig(i_out_dig_0),.q_out_dig(q_out_dig_0));
+ `else
+ assign bb_tx_i0 = ch0tx;
+ assign bb_tx_q0 = ch1tx;
+ assign i_out_dig_0=1\'b0;
+ assign q_out_dig_0=1\'b0;
+ `endif
+
+ `ifdef TX_EN_DIG_1
+ //TODO make enabling tx_dig configurable through register
+ tx_chain_dig tx_chain_dig_1
+ ( .clock(clk64),.reset(tx_dsp_reset),.enable(enable_tx),
+ .i_in(ch2tx),.q_in(ch3tx),
+ .i_out_ana(bb_tx_i1),.q_out_ana(bb_tx_q1),
+ .i_out_dig(i_out_dig_1),.q_out_dig(q_out_dig_1));
+// tx_chain_dig tx_chain_dig_1
+// ( .clock(clk64),.reset(tx_dsp_reset),.enable(enable_tx),
+// .i_in(ch2tx), q_in(ch3tx),
+// .i_out_ana(bb_tx_i1),
+// .q_out_ana(bb_tx_q1),
+// .i_out_dig(i_out_dig_1),
+// .q_out_dig(q_out_dig_1)
+// );
+ `else
+ assign bb_tx_i1 = ch2tx;
+ assign bb_tx_q1 = ch3tx;
+ assign i_out_dig_1=1\'b0;
+ assign q_out_dig_1=1\'b0;
+ `endif
+
+ wire txsync = tx_sample_strobe;
+ assign TXSYNC_A = txsync;
+ assign TXSYNC_B = txsync;
+
+ assign tx_a = txsync ? tx_b_a[15:2] : tx_a_a[15:2];
+ assign tx_b = txsync ? tx_b_b[15:2] : tx_a_b[15:2];
+`else // `ifdef TX_ON
+ assign io_tx_a_out = reg_0;
+ assign io_tx_b_out = reg_2;
+ assign io_tx_a_force_output=16\'b0;
+ assign io_tx_b_force_output=16\'b0;
+`endif
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Receive Side
+`ifdef RX_ON
+ wire rx_sample_strobe,strobe_decim,hb_strobe;
+ wire [15:0] bb_rx_i0,bb_rx_q0,bb_rx_i1,bb_rx_q1,
+\t bb_rx_i2,bb_rx_q2,bb_rx_i3,bb_rx_q3;
+
+ wire loopback = settings[0];
+ wire counter = settings[1];
+
+ always @(posedge clk64)
+ if(rx_dsp_reset)
+ debug_counter <= #1 16\'d0;
+ else if(~enable_rx)
+ debug_counter <= #1 16\'d0;
+ else if(hb_strobe)
+ debug_counter <=#1 debug_counter + 16\'d2;
+
+ always @(posedge clk64)
+ if(strobe_interp)
+ begin
+\t loopback_i_0 <= #1 ch0tx;
+\t loopback_q_0 <= #1 ch1tx;
+ end
+
+
+ wire [15:0] ddc0_in_i,ddc0_in_q,ddc1_in_i,ddc1_in_q,ddc2_in_i,ddc2_in_q,ddc3_in_i,ddc3_in_q;
+ wire [31:0] rssi_0,rssi_1,rssi_2,rssi_3;
+
+ adc_interface adc_interface(.clock(clk64),.reset(rx_dsp_reset),.enable(1\'b1),
+\t\t\t .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+\t\t\t .rx_a_a(rx_a_a),.rx_b_a(rx_b_a),.rx_a_b(rx_a_b),.rx_b_b(rx_b_b),
+\t\t\t .rssi_0(rssi_0),.rssi_1(rssi_1),.rssi_2(rssi_2),.rssi_3(rssi_3),
+\t\t\t .ddc0_in_i(ddc0_in_i),.ddc0_in_q(ddc0_in_q),
+\t\t\t .ddc1_in_i(ddc1_in_i),.ddc1_in_q(ddc1_in_q),
+\t\t\t .ddc2_in_i(ddc2_in_i),.ddc2_in_q(ddc2_in_q),
+\t\t\t .ddc3_in_i(ddc3_in_i),.ddc3_in_q(ddc3_in_q),.rx_numchan(rx_numchan) );
+
+ rx_buffer rx_buffer
+ ( .usbclk(usbclk),.bus_reset(rx_bus_reset),.reset(rx_dsp_reset),
+ .reset_regs(rx_dsp_reset),
+ .usbdata(usbdata_out),.RD(RD),.have_pkt_rdy(have_pkt_rdy),.rx_overrun(rx_overrun),
+ .channels(rx_numchan),
+ .ch_0(ch0rx_ext),.ch_1(ch1rx_ext),
+ .ch_2(ch2rx),.ch_3(ch3rx),
+ .ch_4(ch4rx),.ch_5(ch5rx),
+ .ch_6(ch6rx),.ch_7(ch7rx),
+ .rxclk(clk64),.rxstrobe(hb_strobe),
+ .clear_status(clear_status),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .debugbus(rx_debugbus) );
+
+ `ifdef RX_EN_0
+ rx_chain #(`FR_RX_FREQ_0,`FR_RX_PHASE_0) rx_chain_0
+ ( .clock(clk64),.reset(1\'b0),.enable(enable_rx),
+ .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(hb_strobe),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .i_in(ddc0_in_i),.q_in(ddc0_in_q),.i_out(bb_rx_i0),.q_out(bb_rx_q0),.debugdata(debugdata),.debugctrl(debugctrl));
+ `else
+ assign bb_rx_i0=16\'d0;
+ assign bb_rx_q0=16\'d0;
+ `endif
+
+ `ifdef RX_EN_1
+ rx_chain #(`FR_RX_FREQ_1,`FR_RX_PHASE_1) rx_chain_1
+ ( .clock(clk64),.reset(1\'b0),.enable(enable_rx),
+ .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .i_in(ddc1_in_i),.q_in(ddc1_in_q),.i_out(bb_rx_i1),.q_out(bb_rx_q1));
+ `else
+ assign bb_rx_i1=16\'d0;
+ assign bb_rx_q1=16\'d0;
+ `endif
+
+ `ifdef RX_EN_2
+ rx_chain #(`FR_RX_FREQ_2,`FR_RX_PHASE_2) rx_chain_2
+ ( .clock(clk64),.reset(1\'b0),.enable(enable_rx),
+ .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .i_in(ddc2_in_i),.q_in(ddc2_in_q),.i_out(bb_rx_i2),.q_out(bb_rx_q2));
+ `else
+ assign bb_rx_i2=16\'d0;
+ assign bb_rx_q2=16\'d0;
+ `endif
+
+ `ifdef RX_EN_3
+ rx_chain #(`FR_RX_FREQ_3,`FR_RX_PHASE_3) rx_chain_3
+ ( .clock(clk64),.reset(1\'b0),.enable(enable_rx),
+ .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .i_in(ddc3_in_i),.q_in(ddc3_in_q),.i_out(bb_rx_i3),.q_out(bb_rx_q3));
+ `else
+ assign bb_rx_i3=16\'d0;
+ assign bb_rx_q3=16\'d0;
+ `endif
+
+ `ifdef RX_DIG_ON
+ wire enable_rx_dig = 1\'b1 & enable_rx;//TODO make enabling rx_dig configurable through register
+ assign io_rx_a_force_input = {enable_rx_dig,enable_rx_dig,14\'b0};
+ assign io_rx_b_force_input = {enable_rx_dig,enable_rx_dig,14\'b0};
+ gpio_input gpio_input(.clock(clk64),.reset(rx_dsp_reset),.enable(1\'b1),
+ .out_strobe(hb_strobe),
+\t\t\t .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+\t\t\t .io_rx_a_in(io_rx_a),.io_rx_b_in(io_rx_b),
+ //.io_tx_a_in(io_tx_a),.io_tx_b_in(io_tx_b),
+\t\t\t .rx_dig0_i(rx_dig0_i),.rx_dig0_q(rx_dig0_q),
+\t\t\t .rx_dig1_i(rx_dig1_i),.rx_dig1_q(rx_dig1_q) );
+
+ `ifdef RX_EN_DIG_0
+ rx_chain_dig rx_chain_dig_0
+ ( .clock(clk64),.reset(rx_dsp_reset),.enable(enable_rx_dig),
+ .i_in_ana(bb_rx_i0),.q_in_ana(bb_rx_q0),
+ .i_in_dig(rx_dig0_i),.q_in_dig(rx_dig0_q),
+ .i_out(ch0rx),.q_out(ch1rx));
+ `else
+ assign ch0rx = bb_rx_i0;
+ assign ch1rx = bb_rx_q0;
+ `endif
+
+ assign ch0rx_ext = counter ? debug_counter : loopback ? loopback_i_0 : ch0rx;
+ assign ch1rx_ext = counter ? debug_counter + 16\'d1 : loopback ? loopback_q_0 : ch1rx;
+
+ `ifdef RX_EN_DIG_1
+ rx_chain_dig rx_chain_dig_1
+ ( .clock(clk64),.reset(rx_dsp_reset),.enable(enable_rx_dig),
+ .i_in_ana(bb_rx_i1),.q_in_ana(bb_rx_q1),
+ .i_in_dig(rx_dig1_i),.q_in_dig(rx_dig1_q),
+ .i_out(ch2rx),.q_out(ch3rx));
+ `else
+ assign ch2rx = bb_rx_i1;
+ assign ch3rx = bb_rx_q1;
+ `endif
+
+ assign ch4rx = bb_rx_i2;
+ assign ch5rx = bb_rx_q2;
+ assign ch6rx = bb_rx_i3;
+ assign ch7rx = bb_rx_q3;
+ `else // `ifdef RX_DIG_ON
+ assign ch0rx = counter ? debug_counter : loopback ? loopback_i_0 : bb_rx_i0;
+ assign ch1rx = counter ? debug_counter + 16\'d1 : loopback ? loopback_q_0 : bb_rx_q0;
+ assign ch2rx = bb_rx_i1;
+ assign ch3rx = bb_rx_q1;
+ assign ch4rx = bb_rx_i2;
+ assign ch5rx = bb_rx_q2;
+ assign ch6rx = bb_rx_i3;
+ assign ch7rx = bb_rx_q3;
+ `endif // `ifdef RX_DIG_ON
+
+`endif // `ifdef RX_ON
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Control Functions
+
+ wire [31:0] capabilities;
+ assign capabilities[7] = `TX_CAP_HB;
+ assign capabilities[6:4] = `TX_CAP_NCHAN;
+ assign capabilities[3] = `RX_CAP_HB;
+ assign capabilities[2:0] = `RX_CAP_NCHAN;
+
+
+ serial_io serial_io
+ ( .master_clk(clk64),.serial_clock(SCLK),.serial_data_in(SDI),
+ .enable(SEN_FPGA),.reset(1\'b0),.serial_data_out(SDO),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .readback_0({io_rx_a,io_tx_a}),.readback_1({io_rx_b,io_tx_b}),.readback_2(capabilities),.readback_3(32\'hf0f0931a),
+ .readback_4(rssi_0),.readback_5(rssi_1),.readback_6(rssi_2),.readback_7(rssi_3)
+ );
+
+ wire [15:0] reg_0,reg_1,reg_2,reg_3;
+ wire [15:0] io_tx_a_out;
+ wire [15:0] io_tx_b_out;
+ wire [15:0] io_tx_a_force_output;
+ wire [15:0] io_tx_b_force_output;
+ wire [15:0] io_rx_a_force_input;
+ wire [15:0] io_rx_b_force_input;
+
+ master_control master_control
+ ( .master_clk(clk64),.usbclk(usbclk),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
+ .tx_bus_reset(tx_bus_reset),.rx_bus_reset(rx_bus_reset),
+ .tx_dsp_reset(tx_dsp_reset),.rx_dsp_reset(rx_dsp_reset),
+ .enable_tx(enable_tx),.enable_rx(enable_rx),
+ .interp_rate(interp_rate),.decim_rate(decim_rate),
+ .tx_sample_strobe(tx_sample_strobe),.strobe_interp(strobe_interp),
+ .rx_sample_strobe(rx_sample_strobe),.strobe_decim(strobe_decim),
+ .tx_empty(tx_empty),
+ //.debug_0(rx_a_a),.debug_1(ddc0_in_i),
+ .debug_0(tx_debugbus[15:0]),.debug_1(tx_debugbus[31:16]),
+ .debug_2(rx_debugbus[15:0]),.debug_3(rx_debugbus[31:16]),
+ //.tx_dig_a(tx_dig_a),tx_dig_b(tx_dig_b),
+ .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3) );
+
+ io_pins io_pins
+ (.io_0(io_tx_a),.io_1(io_rx_a),.io_2(io_tx_b),.io_3(io_rx_b),
+ .reg_0(io_tx_a_out),.reg_1(reg_1),.reg_2(io_tx_b_out),.reg_3(reg_3),
+ .io_0_force_output(io_tx_a_force_output), .io_2_force_output(io_tx_b_force_output),
+ .io_1_force_input(io_rx_a_force_input), .io_3_force_input(io_rx_b_force_input),
+ .clock(clk64),.rx_reset(rx_dsp_reset),.tx_reset(tx_dsp_reset),
+ .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe));
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Misc Settings
+ setting_reg #(`FR_MODE) sr_misc(.clock(clk64),.reset(rx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(settings));
+
+endmodule // usrp_gpio
+"
+"
+
+module ram16_2sum (input clock, input write,
+\t\t input [3:0] wr_addr, input [15:0] wr_data,
+\t\t input [3:0] rd_addr1, input [3:0] rd_addr2,
+ output reg [15:0] sum);
+
+ reg signed [15:0] \t ram_array [0:15];
+ reg signed [15:0] \t a,b;
+ wire signed [16:0] \t sum_int;
+
+ always @(posedge clock)
+ if(write)
+ ram_array[wr_addr] <= #1 wr_data;
+
+ always @(posedge clock)
+ begin
+\ta <= #1 ram_array[rd_addr1];
+\tb <= #1 ram_array[rd_addr2];
+ end
+
+ assign sum_int = {a[15],a} + {b[15],b};
+
+ always @(posedge clock)
+ sum <= #1 sum_int[16:1] + (sum_int[16]&sum_int[0]);
+
+endmodule // ram16_2sum
+"
+"// megafunction wizard: %ALTPLL%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altpll
+
+// ============================================================
+// File Name: pll.v
+// Megafunction Name(s):
+// \t\t\taltpll
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 4.0 Build 214 3/25/2004 SP 1 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2004 Altera Corporation
+//Any megafunction design, and related netlist (encrypted or decrypted),
+//support information, device programming or simulation file, and any other
+//associated documentation or information provided by Altera or a partner
+//under Altera\'s Megafunction Partnership Program may be used only
+//to program PLD devices (but not masked PLD devices) from Altera. Any
+//other use of such megafunction design, netlist, support information,
+//device programming or simulation file, or any other related documentation
+//or information is prohibited for any other purpose, including, but not
+//limited to modification, reverse engineering, de-compiling, or use with
+//any other silicon devices, unless such use is explicitly licensed under
+//a separate agreement with Altera or a megafunction partner. Title to the
+//intellectual property, including patents, copyrights, trademarks, trade
+//secrets, or maskworks, embodied in any such megafunction design, netlist,
+//support information, device programming or simulation file, or any other
+//related documentation or information provided by Altera or a megafunction
+//partner, remains with Altera, the megafunction partner, or their respective
+//licensors. No other licenses, including any licenses needed under any third
+//party\'s intellectual property, are provided herein.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module pll (
+\tinclk0,
+\tc0);
+
+\tinput\t inclk0;
+\toutput\t c0;
+
+\twire [5:0] sub_wire0;
+\twire [0:0] sub_wire4 = 1\'h0;
+\twire [0:0] sub_wire1 = sub_wire0[0:0];
+\twire c0 = sub_wire1;
+\twire sub_wire2 = inclk0;
+\twire [1:0] sub_wire3 = {sub_wire4, sub_wire2};
+
+\taltpll\taltpll_component (
+\t\t\t\t.inclk (sub_wire3),
+\t\t\t\t.clk (sub_wire0)
+\t\t\t\t// synopsys translate_off
+,
+\t\t\t\t.fbin (),
+\t\t\t\t.pllena (),
+\t\t\t\t.clkswitch (),
+\t\t\t\t.areset (),
+\t\t\t\t.pfdena (),
+\t\t\t\t.clkena (),
+\t\t\t\t.extclkena (),
+\t\t\t\t.scanclk (),
+\t\t\t\t.scanaclr (),
+\t\t\t\t.scandata (),
+\t\t\t\t.scanread (),
+\t\t\t\t.scanwrite (),
+\t\t\t\t.extclk (),
+\t\t\t\t.clkbad (),
+\t\t\t\t.activeclock (),
+\t\t\t\t.locked (),
+\t\t\t\t.clkloss (),
+\t\t\t\t.scandataout (),
+\t\t\t\t.scandone (),
+\t\t\t\t.sclkout1 (),
+\t\t\t\t.sclkout0 (),
+\t\t\t\t.enable0 (),
+\t\t\t\t.enable1 ()
+\t\t\t\t// synopsys translate_on
+
+);
+\tdefparam
+\t\taltpll_component.clk0_duty_cycle = 50,
+\t\taltpll_component.lpm_type = ""altpll"",
+\t\taltpll_component.clk0_multiply_by = 1,
+\t\taltpll_component.inclk0_input_frequency = 20833,
+\t\taltpll_component.clk0_divide_by = 1,
+\t\taltpll_component.pll_type = ""AUTO"",
+\t\taltpll_component.clk0_time_delay = ""0"",
+\t\taltpll_component.intended_device_family = ""Cyclone"",
+\t\taltpll_component.operation_mode = ""NORMAL"",
+\t\taltpll_component.compensate_clock = ""CLK0"",
+\t\taltpll_component.clk0_phase_shift = ""-3000"";
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: MIRROR_CLK0 STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING ""ns""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: SPREAD_USE STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC ""1048575""
+// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING ""0""
+// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING ""50.00000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING ""-3.00000000""
+// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_PERCENT STRING ""0.500""
+// Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING ""0""
+// Retrieval info: PRIVATE: TIME_SHIFT0 STRING ""0.00000000""
+// Retrieval info: PRIVATE: STICKY_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: BANDWIDTH STRING ""1.000""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_CUSTOM STRING ""0""
+// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING ""8""
+// Retrieval info: PRIVATE: SPREAD_FREQ STRING ""50.000""
+// Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING ""1""
+// Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC ""0""
+// Retrieval info: PRIVATE: USE_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING ""0""
+// Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING ""0""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING ""100.000""
+// Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING ""c0""
+// Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: MEGAFN_PORT_INFO_0 STRING ""inclk;fbin;pllena;clkswitch;areset""
+// Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING ""0""
+// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: CUR_FBIN_CLK STRING ""e0""
+// Retrieval info: PRIVATE: MEGAFN_PORT_INFO_1 STRING ""pfdena;clkena;extclkena;scanclk;scanaclr""
+// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING ""1""
+// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING ""0""
+// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC ""1""
+// Retrieval info: PRIVATE: MEGAFN_PORT_INFO_2 STRING ""scandata;scanread;scanwrite;clk;extclk""
+// Retrieval info: PRIVATE: CLKLOSS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING ""1""
+// Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING ""0""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING ""528.000""
+// Retrieval info: PRIVATE: MEGAFN_PORT_INFO_3 STRING ""clkbad;activeclock;locked;clkloss;scandataout""
+// Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING ""KHz""
+// Retrieval info: PRIVATE: PLL_ENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING ""48.000""
+// Retrieval info: PRIVATE: MEGAFN_PORT_INFO_4 STRING ""scandone;sclkout1;sclkout0;enable0;enable1""
+// Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING ""0""
+// Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING ""100.000""
+// Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING ""inclk0""
+// Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: DEV_FAMILY STRING ""Cyclone""
+// Retrieval info: PRIVATE: LOCK_LOSS_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING ""Low""
+// Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: USE_CLKENA0 STRING ""0""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING ""0""
+// Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: DEVICE_FAMILY NUMERIC ""11""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""altpll""
+// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC ""20833""
+// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: PLL_TYPE STRING ""AUTO""
+// Retrieval info: CONSTANT: CLK0_TIME_DELAY STRING ""0""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: CONSTANT: OPERATION_MODE STRING ""NORMAL""
+// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING ""CLK0""
+// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING ""-3000""
+// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT VCC ""c0""
+// Retrieval info: USED_PORT: @clk 0 0 6 0 OUTPUT VCC ""@clk[5..0]""
+// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT GND ""inclk0""
+// Retrieval info: USED_PORT: @extclk 0 0 4 0 OUTPUT VCC ""@extclk[3..0]""
+// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
+// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
+// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.v TRUE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.inc FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.cmp FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.bsf FALSE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_inst.v TRUE FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_bb.v TRUE FALSE
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+
+// NOTE This only works for N=4, max decim rate of 128
+// NOTE signal ""rate"" is ONE LESS THAN the actual rate
+
+module cic_dec_shifter(rate,signal_in,signal_out);
+ parameter bw = 16;
+ parameter maxbitgain = 28;
+
+ input [7:0] rate;
+ input wire [bw+maxbitgain-1:0] signal_in;
+ output reg [bw-1:0] signal_out;
+
+ function [4:0] bitgain;
+ input [7:0] rate;
+ case(rate)
+\t// Exact Cases -- N*log2(rate)
+\t8\'d4 : bitgain = 8;
+\t8\'d8 : bitgain = 12;
+\t8\'d16 : bitgain = 16;
+\t8\'d32 : bitgain = 20;
+\t8\'d64 : bitgain = 24;
+\t8\'d128 : bitgain = 28;
+\t
+\t// Nearest without overflow -- ceil(N*log2(rate))
+\t8\'d5 : bitgain = 10;
+\t8\'d6 : bitgain = 11;
+\t8\'d7 : bitgain = 12;
+\t8\'d9 : bitgain = 13;
+\t8\'d10,8\'d11 : bitgain = 14;
+\t8\'d12,8\'d13 : bitgain = 15;
+\t8\'d14,8\'d15 : bitgain = 16;
+\t8\'d17,8\'d18,8\'d19 : bitgain = 17;
+\t8\'d20,8\'d21,8\'d22 : bitgain = 18;
+\t8\'d23,8\'d24,8\'d25,8\'d26 : bitgain = 19;
+\t8\'d27,8\'d28,8\'d29,8\'d30,8\'d31 : bitgain = 20;
+\t8\'d33,8\'d34,8\'d35,8\'d36,8\'d37,8\'d38 : bitgain = 21;
+\t8\'d39,8\'d40,8\'d41,8\'d42,8\'d43,8\'d44,8\'d45 : bitgain = 22;
+\t8\'d46,8\'d47,8\'d48,8\'d49,8\'d50,8\'d51,8\'d52,8\'d53 : bitgain = 23;
+\t8\'d54,8\'d55,8\'d56,8\'d57,8\'d58,8\'d59,8\'d60,8\'d61,8\'d62,8\'d63 : bitgain = 24;
+\t8\'d65,8\'d66,8\'d67,8\'d68,8\'d69,8\'d70,8\'d71,8\'d72,8\'d73,8\'d74,8\'d75,8\'d76 : bitgain = 25;
+\t8\'d77,8\'d78,8\'d79,8\'d80,8\'d81,8\'d82,8\'d83,8\'d84,8\'d85,8\'d86,8\'d87,8\'d88,8\'d89,8\'d90 : bitgain = 26;
+\t8\'d91,8\'d92,8\'d93,8\'d94,8\'d95,8\'d96,8\'d97,8\'d98,8\'d99,8\'d100,8\'d101,8\'d102,8\'d103,8\'d104,8\'d105,8\'d106,8\'d107 : bitgain = 27;
+\tdefault : bitgain = 28;
+ endcase // case(rate)
+ endfunction // bitgain
+
+ wire [4:0] \t shift = bitgain(rate+1);
+
+ // We should be able to do this, but can\'t ....
+ // assign \t signal_out = signal_in[shift+bw-1:shift];
+
+ always @*
+ case(shift)
+ 5\'d8 : signal_out = signal_in[8+bw-1:8];
+ 5\'d10 : signal_out = signal_in[10+bw-1:10];
+ 5\'d11 : signal_out = signal_in[11+bw-1:11];
+ 5\'d12 : signal_out = signal_in[12+bw-1:12];
+ 5\'d13 : signal_out = signal_in[13+bw-1:13];
+ 5\'d14 : signal_out = signal_in[14+bw-1:14];
+ 5\'d15 : signal_out = signal_in[15+bw-1:15];
+ 5\'d16 : signal_out = signal_in[16+bw-1:16];
+ 5\'d17 : signal_out = signal_in[17+bw-1:17];
+ 5\'d18 : signal_out = signal_in[18+bw-1:18];
+ 5\'d19 : signal_out = signal_in[19+bw-1:19];
+ 5\'d20 : signal_out = signal_in[20+bw-1:20];
+ 5\'d21 : signal_out = signal_in[21+bw-1:21];
+ 5\'d22 : signal_out = signal_in[22+bw-1:22];
+ 5\'d23 : signal_out = signal_in[23+bw-1:23];
+ 5\'d24 : signal_out = signal_in[24+bw-1:24];
+ 5\'d25 : signal_out = signal_in[25+bw-1:25];
+ 5\'d26 : signal_out = signal_in[26+bw-1:26];
+ 5\'d27 : signal_out = signal_in[27+bw-1:27];
+ 5\'d28 : signal_out = signal_in[28+bw-1:28];
+
+ default : signal_out = signal_in[28+bw-1:28];
+ endcase // case(shift)
+
+endmodule // cic_dec_shifter
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2008 Corgan Enterprises LLC
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+// Following defines conditionally include RX path circuitry
+
+`include ""../top/config.vh""\t// resolved relative to project root
+
+module rx_chain_dig
+ (input clock,
+ input reset,
+ input enable,
+ input wire [15:0] i_in_ana,
+ input wire [15:0] q_in_ana,
+ input wire i_in_dig,
+ input wire q_in_dig,
+ output wire [15:0] i_out,
+ output wire [15:0] q_out
+ );
+
+ //assign upper 15 bits of output to analog input,
+ // discards lsb of analog input and replace with digital input bit (which comes from gpio)
+ assign i_out = (enable)?{i_in_ana[15:1],i_in_dig}:i_in_ana;
+ assign q_out = (enable)?{q_in_ana[15:1],q_in_dig}:q_in_ana;
+
+endmodule // rx_chain_dig
+"
+"module cbus_tb;
+
+`define ch1in_freq 0
+`define ch2in_freq 1
+`define ch3in_freq 2
+`define ch4in_freq 3
+`define ch1out_freq 4
+`define ch2out_freq 5
+`define ch3out_freq 6
+`define ch4out_freq 7
+`define rates 8
+`define misc 9
+
+ task send_config_word;
+ input [7:0] addr;
+ input [31:0] data;
+ integer i;
+
+ begin
+\t #10 serenable = 1;
+\t for(i=7;i>=0;i=i-1)
+\t begin
+\t #10 serdata = addr[i];
+\t #10 serclk = 0;
+\t #10 serclk = 1;
+\t #10 serclk = 0;
+\t end
+\t for(i=31;i>=0;i=i-1)
+\t begin
+\t #10 serdata = data[i];
+\t #10 serclk = 0;
+\t #10 serclk = 1;
+\t #10 serclk = 0;
+\t end
+\t #10 serenable = 0;
+\t // #10 serclk = 1;
+\t // #10 serclk = 0;
+ end
+ endtask // send_config_word
+
+ initial $dumpfile(""cbus_tb.vcd"");
+ initial $dumpvars(0,cbus_tb);
+
+ initial reset = 1;
+ initial #500 reset = 0;
+
+ reg serclk, serdata, serenable, reset;
+ wire SDO;
+
+ control_bus control_bus
+ ( .serial_clock(serclk),
+ .serial_data_in(serdata),
+ .enable(serenable),
+ .reset(reset),
+ .serial_data_out(SDO) );
+
+
+ initial
+ begin
+\t#1000 send_config_word(8\'d1,32\'hDEAD_BEEF);
+\t#1000 send_config_word(8\'d3,32\'hDDEE_FF01);
+\t#1000 send_config_word(8\'d19,32\'hFFFF_FFFF);
+\t#1000 send_config_word(8\'d23,32\'h1234_FEDC);
+\t#1000 send_config_word(8\'h80,32\'h0);
+\t#1000 send_config_word(8\'h81,32\'h0);
+\t#1000 send_config_word(8\'h82,32\'h0);
+\t#1000 reset = 1;
+\t#1 $finish;
+ end
+
+endmodule // cbus_tb
+"
+"
+
+module halfband_interp
+ (input clock, input reset, input enable,
+ input strobe_in, input strobe_out,
+ input [15:0] signal_in_i, input [15:0] signal_in_q,
+ output reg [15:0] signal_out_i, output reg [15:0] signal_out_q,
+ output wire [12:0] debug);
+
+ wire [15:0] \tcoeff_ram_out;
+ wire [15:0] \tdata_ram_out_i;
+ wire [15:0] \tdata_ram_out_q;
+
+ wire [3:0] \tdata_rd_addr;
+ reg [3:0] \tdata_wr_addr;
+ reg [2:0] \tcoeff_rd_addr;
+
+ wire \t\tfilt_done;
+
+ wire [15:0] \tmac_out_i;
+ wire [15:0] \tmac_out_q;
+ reg [15:0] \tdelayed_middle_i, delayed_middle_q;
+ wire [7:0] \tshift = 8'd9;
+
+ reg \t\tstb_out_happened;
+
+ wire [15:0] \tdata_ram_out_i_b;
+
+ always @(posedge clock)
+ if(strobe_in)
+ stb_out_happened <= #1 1'b0;
+ else if(strobe_out)
+ stb_out_happened <= #1 1'b1;
+
+assign debug = {filt_done,data_rd_addr,data_wr_addr,coeff_rd_addr};
+
+ wire [15:0] \tsignal_out_i = stb_out_happened ? mac_out_i : delayed_middle_i;
+ wire [15:0] \tsignal_out_q = stb_out_happened ? mac_out_q : delayed_middle_q;
+
+/* always @(posedge clock)
+ if(reset)
+ begin
+\t signal_out_i <= #1 16'd0;
+\t signal_out_q <= #1 16'd0;
+ end
+ else if(strobe_in)
+ begin
+\t signal_out_i <= #1 delayed_middle_i; // Multiply by 1 for middle coeff
+\t signal_out_q <= #1 delayed_middle_q;
+ end
+ //else if(filt_done&stb_out_happened)
+ else if(stb_out_happened)
+ begin
+\t signal_out_i <= #1 mac_out_i;
+\t signal_out_q <= #1 mac_out_q;
+ end
+*/
+
+ always @(posedge clock)
+ if(reset)
+ coeff_rd_addr <= #1 3'd0;
+ else if(coeff_rd_addr != 3'd0)
+ coeff_rd_addr <= #1 coeff_rd_addr + 3'd1;
+ else if(strobe_in)
+ coeff_rd_addr <= #1 3'd1;
+
+ reg filt_done_d1;
+ always@(posedge clock)
+ filt_done_d1 <= #1 filt_done;
+
+ always @(posedge clock)
+ if(reset)
+ data_wr_addr <= #1 4'd0;
+ //else if(strobe_in)
+ else if(filt_done & ~filt_done_d1)
+ data_wr_addr <= #1 data_wr_addr + 4'd1;
+
+ always @(posedge clock)
+ if(coeff_rd_addr == 3'd7)
+ begin
+\t delayed_middle_i <= #1 data_ram_out_i_b;
+\t// delayed_middle_q <= #1 data_ram_out_q_b;
+ end
+
+// always @(posedge clock)
+// if(reset)
+// data_rd_addr <= #1 4'd0;
+// else if(strobe_in)
+// data_rd_addr <= #1 data_wr_addr + 4'd1;
+// else if(!filt_done)
+// data_rd_addr <= #1 data_rd_addr + 4'd1;
+// else
+// data_rd_addr <= #1 data_wr_addr;
+
+ wire [3:0] data_rd_addr1 = data_wr_addr + {1'b0,coeff_rd_addr};
+ wire [3:0] data_rd_addr2 = data_wr_addr + 15 - {1'b0,coeff_rd_addr};
+// always @(posedge clock)
+// if(reset)
+// filt_done <= #1 1'b1;
+// else if(strobe_in)
+ // filt_done <= #1 1'b0;
+// else if(coeff_rd_addr == 4'd0)
+// filt_done <= #1 1'b1;
+
+ assign filt_done = (coeff_rd_addr == 3'd0);
+
+ coeff_ram coeff_ram ( .clock(clock),.rd_addr({1'b0,coeff_rd_addr}),.rd_data(coeff_ram_out) );
+
+ ram16_2sum data_ram_i ( .clock(clock),.write(strobe_in),.wr_addr(data_wr_addr),.wr_data(signal_in_i),
+\t\t .rd_addr1(data_rd_addr1),.rd_addr2(data_rd_addr2),.rd_data(data_ram_out_i_b),.sum(data_ram_out_i));
+
+ ram16_2sum data_ram_q ( .clock(clock),.write(strobe_in),.wr_addr(data_wr_addr),.wr_data(signal_in_q),
+\t\t .rd_addr1(data_rd_addr1),.rd_addr2(data_rd_addr2),.rd_data(data_ram_out_q));
+
+ mac mac_i (.clock(clock),.reset(reset),.enable(~filt_done),.clear(strobe_in),
+\t .x(data_ram_out_i),.y(coeff_ram_out),.shift(shift),.z(mac_out_i) );
+
+ mac mac_q (.clock(clock),.reset(reset),.enable(~filt_done),.clear(strobe_in),
+\t .x(data_ram_out_q),.y(coeff_ram_out),.shift(shift),.z(mac_out_q) );
+
+endmodule // halfband_interp
+"
+"
+
+module acc (input clock, input reset, input clear, input enable_in, output reg enable_out,
+\t input signed [30:0] addend, output reg signed [33:0] sum );
+
+ always @(posedge clock)
+ if(reset)
+ sum <= #1 34'd0;
+ //else if(clear & enable_in)
+ // sum <= #1 addend;
+ //else if(clear)
+ // sum <= #1 34'd0;
+ else if(clear)
+ sum <= #1 addend;
+ else if(enable_in)
+ sum <= #1 sum + addend;
+
+ always @(posedge clock)
+ enable_out <= #1 enable_in;
+
+endmodule // acc
+
+"
+"
+
+module ram32 (input clock, input write,
+\t input [4:0] wr_addr, input [15:0] wr_data,
+\t input [4:0] rd_addr, output reg [15:0] rd_data);
+
+ reg [15:0] \t\tram_array [0:31];
+
+ always @(posedge clock)
+ rd_data <= #1 ram_array[rd_addr];
+
+ always @(posedge clock)
+ if(write)
+ ram_array[wr_addr] <= #1 wr_data;
+
+endmodule // ram32
+
+"
+"// Model of FIFO in Altera
+
+module fifo_1c_2k ( data, wrreq, rdreq, rdclk, wrclk, aclr, q,
+\t\t rdfull, rdempty, rdusedw, wrfull, wrempty, wrusedw);
+
+ parameter width = 32;
+ parameter depth = 2048;
+ //`define rd_req 0; // Set this to 0 for rd_ack, 1 for rd_req
+
+ input [31:0] data;
+ input \twrreq;
+ input \trdreq;
+ input \trdclk;
+ input \twrclk;
+ input \taclr;
+ output [31:0] q;
+ output \t rdfull;
+ output \t rdempty;
+ output [10:0] rdusedw;
+ output \t wrfull;
+ output \t wrempty;
+ output [10:0] wrusedw;
+
+ reg [width-1:0] mem [0:depth-1];
+ reg [7:0] \t rdptr;
+ reg [7:0] \t wrptr;
+
+`ifdef rd_req
+ reg [width-1:0] q;
+`else
+ wire [width-1:0] q;
+`endif
+
+ reg [10:0] \t rdusedw;
+ reg [10:0] \t wrusedw;
+
+ integer \t i;
+
+ always @( aclr)
+ begin
+\twrptr <= #1 0;
+\trdptr <= #1 0;
+\tfor(i=0;ic5XHk }u&%6Y.AdM:^UEh(K8[0SCf,O=b4WGj7Z/BeNc5XHk }x\\
+&6YAdM:^UEh(K8[0SCf,O=b4WGj7ZBec5XHk }tE6YAd:^Eh(K8[0SCf,O=b\\
+4WGj7ZBc5XHk }eE6A:^Eh(K8[0SCf,O=b4WG"",
+""%%%%%k99j09,,8b(D/%%%&%%&%%%%% }wGj7Bc5XHk }uG6A^h(K8[0SCf,O=\\
+b4WGj7ai)L9]1TDg-P>c5XHk }xG^h(K8[0SCf,O=b4WGja)L9]1TDg-P>c5XHk }]2%I6Y.QAd*\\
+M:^2UEh(K8[0SCf,O=b4WG&J7Z/RBe+N<3VF)L9]1Tg-P>5XH }^2%IY.Qd*M:2UE(K[0Sf,O=4W\\
+&JZ/Re+N3V)L]1T-P5X jaP%I6Y.QAd*M:^2Eh(K8[0CO=b4GJZ/BNaFL]c!}t&0k!}w&0k!}u&0\\
+k!}x&0k!}tE0k!}wE0k!}uE0k!}xE0k!}t00k!}w00k!}u00k!}x00k"",
+""%%%%%k99j09,,8b&D/%%%&%%&%%%%%!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}x\\
+)0k!}tG0k!}wG0k!}uG0k!}xG0k!}t20k!}w20k!}u20k!}x209"",
+""%%%%%k99j09,,8b(D8,%%&%%&%%%%%!}o3D6,!}tQD0k!}wQD0k!}uQD0k!}xQD0k!}t%/0k!}w\\
+%/0k!}u%/0k!}x%/0k!}tD/0k!}wD/0k!}uD/0k!}xD/0k!}t//0k!}w//0k!}u//0k!}*//.c"",
+""%%%%%k99j09,,8%(D%)%%&%%&%%%%%!}x/5P!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u\\
+)0k!}x)0k!}tG0k!}wG0k!}uG0k!}xG0k!}t20k!}w20k!}u20^"",
+""%%%%%k99j09,,8b&D%)%%&%%&%%%%%!{N/-b!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w\\
+)0k!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k!}xG0k!}t20k!}w20k!}c2/g"",
+""%%%%%k99j09,,8b(D8)%%&%%&%%%%%!}l3%/g!}x3%0k!}tQ%0k!}wQ%0k!}uQ%0k!}xQ%0k!}t\\
+%D0k!}w%D0k!}u%D0k!}x%D0k!}tDD0k!}wDD0k!}uDD0k!}xDD0k!}t/D0k!}w/D0k!z&/D-b"",
+""%%%%%k99j09,,8%(D/)%%&%%&%%%%%!}u/6.!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w\\
+)0k!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k!}xG0k!}t20k!}w20M"",
+""%%%%%k99j09,,8b&D/)%%&%%&%%%%%!}P/.c!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t\\
+)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k!}xG0k!}t20k!}e2/I"",
+""%%%%%k99j09,,8b(D8,,%&%%&%%%%%!}w3M6Q!}u3M0k!}x3M0k!}tQM0k!}wQM0k!}uQM0k!}x\\
+QM0k!}t%)0k!}w%)0k!}u%)0k!}x%)0k!}tD)0k!}wD)0k!}uD)0k!}xD)0k!}t/)0k"",
+""%%%%%k99j09,,8b%D%%)%&%%&%%%%%!}w/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t\\
+)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k!}xG0k!}t209"",
+""%%%%%k99j09,,8b(D%%)%&%%&%%%%%!}k26,!}w20k!}u20k!}x20k!}tP0k!}wP0k!}uP0k!}x\\
+P0k!}t&0k!}w&0k!}u&0k!}x&0k!}tE0k!}wE0k!}uE0k!}xE0k!}%0.c"",
+""%%%%%k99j09,,8b&D%%)%&%%&%%%%%!}t/5P!}w/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}x\\
+M0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k!}xG0^"",
+""%%%%%k99j09,,8b(D8%)%&%%&%%%%%!{QH%-b!}t3%0k!}w3%0k!}u3%0k!}x3%0k!}tQ%0k!}w\\
+Q%0k!}uQ%0k!}xQ%0k!}t%D0k!}w%D0k!}u%D0k!}x%D0k!}tDD0k!}wDD0k!}uDD0k!}fDD/g"",
+""%%%%%k99j09,,8b%D/%)%&%%&%%%%%!}oD/g!}t/0k!}w/0k!}u/0k!}x/0k!}tM0k!}wM0k!}u\\
+M0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k!z*G-b"",
+""%%%%%k99j09,,8b(D/%)%&%%&%%%%%!}xG6.!}t20k!}w20k!}u20k!}x20k!}tP0k!}wP0k!}u\\
+P0k!}xP0k!}t&0k!}w&0k!}u&0k!}x&0k!}tE0k!}wE0k!}uE0M"",
+""%%%%%k99j09,,8b&D/%)%&%%&%%%%%!}ND.c!}xD0k!}t/0k!}w/0k!}u/0k!}x/0k!}tM0k!}w\\
+M0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}cG/I"",
+""%%%%%k99j09,,8b(D8,)%&%%&%%%%%!}uHD6Q!}xHD0k!}t3D0k!}w3D0k!}u3D0k!}x3D0k!}t\\
+QD0k!}wQD0k!}uQD0k!}xQD0k!}t%/0k!}w%/0k!}u%/0k!}x%/0k!}tD/0k!}wD/0k"",
+""%%%%%k99j09,,8b%D%))%&%%&%%%%%!}uD0k!}xD0k!}t/0k!}w/0k!}u/0k!}x/0k!}tM0k!}w\\
+M0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG09"",
+""%%%%%k99j09,,8b(D%))%&%%&%%%%%!}nG6,!}uG0k!}xG0k!}t20k!}w20k!}u20k!}x20k!}t\\
+P0k!}wP0k!}uP0k!}xP0k!}t&0k!}w&0k!}u&0k!}x&0k!}tE0k!})E.c"",
+""%%%%%k99j09,,8b&D%))%&%%&%%%%%!}wD5P!}uD0k!}xD0k!}t/0k!}w/0k!}u/0k!}x/0k!}t\\
+M0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0^"",
+""%%%%%k99j09,,8b(D8))%&%%&%%%%%!{MH%-b!}wH%0k!}uH%0k!}xH%0k!}t3%0k!}w3%0k!}u\\
+3%0k!}x3%0k!}tQ%0k!}wQ%0k!}uQ%0k!}xQ%0k!}t%D0k!}w%D0k!}u%D0k!}x%D0k!}bDD/g"",
+""%%%%%k99j09,,8b%D/))%&%%&%%%%%!}kD/g!}wD0k!}uD0k!}xD0k!}t/0k!}w/0k!}u/0k!}x\\
+/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!z%G-b"",
+""%%%%%k99j09,,8b(D/))%&%%&%%%%%!}tG6.!}wG0k!}uG0k!}xG0k!}t20k!}w20k!}u20k!}x\\
+20k!}tP0k!}wP0k!}uP0k!}xP0k!}t&0k!}w&0k!}u&0k!}x&0M"",
+""%%%%%k99j09,,8b&D/))%&%%&%%%%%!}Q%.c!}tD0k!}wD0k!}uD0k!}xD0k!}t/0k!}w/0k!}u\\
+/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}f)/I"",
+""%%%%%k99j09,,8D(D8,,%c%%&%%%%%!}x*M6Q!}tHM0k!}wHM0k!}uHM0k!}xHM0k!}t3M0k!}w\\
+3M0k!}u3M0k!}x3M0k!}tQM0k!}wQM0k!}uQM0k!}xQM0k!}t%)02 }w%)%6Y.Ad*M:^2UEh(K8[\\
+0SCf,O=b4WGj&7Z/Be+Nc5XHk }u%)%6Y.AdM:^UEh(K8[0SCf,O=b4WGj&7\\
+ZBeNc5XHk }f%)6YAdM:^UEh(K8[0"",
+""%%%%%k99j09,,8b(D%%%%E%%&%%%%% }x)SCf,O=b4WGj7ZBeNc5XHk }tG6\\
+YAd:^Eh(K8[0SCf,O=b4WGj7Bec5XHk }wG6A:^Eh(K8[0SCf,O=b4WGj7BaF\\
+i)L9]1TDg-P>c5XHk }uG6A^h(K8[0SCf,O=b4WGjBai)L9]1TDg-P>c5XHk }xG^h(K8[0SCf,O\\
+=b4WGji)L9]1TDg-P>c5XHk }]2%I6Y.QAd*M:^2UEh(K8[0SCf,O=4WGj&J7Z/RBe+N<3VF)L]1\\
+TDg-P>5XH }^2%IY.Qd*M:2UE(K[0Sf,O4WG&JZ/Re+N3V)L1Tg-P5X jaP%I6Y.QAd*M:^2UE(K\\
+8[0C,Ob4GJZ/BNa3L]P!}t&0k!}w&0k!}u&0k!}x&0k!}tE0k!}wE0k!}uE0k!}xE0k!}t00k!}w\\
+00k!}c0/I"",
+""%%%%%k99j09,,8b&D%%%%E%%&%%%%%!}u/6Q!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w\\
+)0k!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k!}xG0k!}t20k!}w20k"",
+""%%%%%k99j09,,8b&D8%%%E%%&%%%%%!}u20k!}x20k!}tP0k!}wP0k!}uP0k!}xP0k!}t&0k!}w\\
+&0k!}u&0k!}x&0k!}tE0k!}wE0k!}uE0k!}xE0k!}t00k!}w009"",
+""%%%%%k99j09,,8b&D/%%%E%%&%%%%%!}n/6,!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t\\
+)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k!}xG0k!}t20k!})2.c"",
+""%%%%%k99j09,,8b(D8,%%E%%&%%%%%!}w3D5P!}u3D0k!}x3D0k!}tQD0k!}wQD0k!}uQD0k!}x\\
+QD0k!}t%/0k!}w%/0k!}u%/0k!}x%/0k!}tD/0k!}wD/0k!}uD/0k!}xD/0k!}t//0^"",
+""%%%%%k99j09,,8%(D%)%%E%%&%%%%%!{M/-b!}w/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}x\\
+M0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k!}xG0k!}b2/g"",
+""%%%%%k99j09,,8b&D%)%%E%%&%%%%%!}k//g!}w/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}x\\
+M0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k!}xG0k!z%2-b"",
+""%%%%%k99j09,,8b(D8)%%E%%&%%%%%!}t3%6.!}w3%0k!}u3%0k!}x3%0k!}tQ%0k!}wQ%0k!}u\\
+Q%0k!}xQ%0k!}t%D0k!}w%D0k!}u%D0k!}x%D0k!}tDD0k!}wDD0k!}uDD0k!}xDD0M"",
+""%%%%%k99j09,,8%(D/)%%E%%&%%%%%!}QD.c!}t/0k!}w/0k!}u/0k!}x/0k!}tM0k!}wM0k!}u\\
+M0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k!}fG/I"",
+""%%%%%k99j09,,8b&D/)%%E%%&%%%%%!}xD6Q!}t/0k!}w/0k!}u/0k!}x/0k!}tM0k!}wM0k!}u\\
+M0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k"",
+""%%%%%k99j09,,8b(D8,,%E%%&%%%%%!}xHM0k!}t3M0k!}w3M0k!}u3M0k!}x3M0k!}tQM0k!}w\\
+QM0k!}uQM0k!}xQM0k!}t%)0k!}w%)0k!}u%)0k!}x%)0k!}tD)0k!}wD)0k!}uD)09"",
+""%%%%%k99j09,,8b%D%%)%E%%&%%%%%!}lD6,!}xD0k!}t/0k!}w/0k!}u/0k!}x/0k!}tM0k!}w\\
+M0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}&G.c"",
+""%%%%%k99j09,,8b(D%%)%E%%&%%%%%!}uG5P!}xG0k!}t20k!}w20k!}u20k!}x20k!}tP0k!}w\\
+P0k!}uP0k!}xP0k!}t&0k!}w&0k!}u&0k!}x&0k!}tE0k!}wE0^"",
+""%%%%%k99j09,,8b&D%%)%E%%&%%%%%!{PD-b!}uD0k!}xD0k!}t/0k!}w/0k!}u/0k!}x/0k!}t\\
+M0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}eG/g"",
+""%%%%%k99j09,,8b(D8%)%E%%&%%%%%!}nH%/g!}uH%0k!}xH%0k!}t3%0k!}w3%0k!}u3%0k!}x\\
+3%0k!}tQ%0k!}wQ%0k!}uQ%0k!}xQ%0k!}t%D0k!}w%D0k!}u%D0k!}x%D0k!}tDD0k!z)DD-b"",
+""%%%%%k99j09,,8b%D/%)%E%%&%%%%%!}wD6.!}uD0k!}xD0k!}t/0k!}w/0k!}u/0k!}x/0k!}t\\
+M0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0M"",
+""%%%%%k99j09,,8b(D/%)%E%%&%%%%%!}MG.c!}wG0k!}uG0k!}xG0k!}t20k!}w20k!}u20k!}x\\
+20k!}tP0k!}wP0k!}uP0k!}xP0k!}t&0k!}w&0k!}u&0k!}x&0k!}bE/I"",
+""%%%%%k99j09,,8b&D/%)%E%%&%%%%%!}tD6Q!}wD0k!}uD0k!}xD0k!}t/0k!}w/0k!}u/0k!}x\\
+/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k"",
+""%%%%%k99j09,,8b(D8,)%E%%&%%%%%!}tHD0k!}wHD0k!}uHD0k!}xHD0k!}t3D0k!}w3D0k!}u\\
+3D0k!}x3D0k!}tQD0k!}wQD0k!}uQD0k!}xQD0k!}t%/0k!}w%/0k!}u%/0k!}x%/09"",
+""%%%%%k99j09,,8b%D%))%E%%&%%%%%!}o%6,!}tD0k!}wD0k!}uD0k!}xD0k!}t/0k!}w/0k!}u\\
+/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}*).c"",
+""%%%%%k99j09,,8b(D%))%E%%&%%%%%!}x)5P!}tG0k!}wG0k!}uG0k!}xG0k!}t20k!}w20k!}u\\
+20k!}x20k!}tP0k!}wP0k!}uP0k!}xP0k!}t&0k!}w&0k!}u&0^"",
+""%%%%%k99j09,,8b&D%))%E%%&%%%%%!{N%-b!}x%0k!}tD0k!}wD0k!}uD0k!}xD0k!}t/0k!}w\\
+/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}c)/g"",
+""%%%%%k99j09,,8b(D8))%E%%&%%%%%!}l*%/g!}x*%0k!}tH%0k!}wH%0k!}uH%0k!}xH%0k!}t\\
+3%0k!}w3%0k!}u3%0k!}x3%0k!}tQ%0k!}wQ%0k!}uQ%0k!}xQ%0k!}t%D0k!}w%D0k!z&%D-b"",
+""%%%%%k99j09,,8b%D/))%E%%&%%%%%!}u%6.!}x%0k!}tD0k!}wD0k!}uD0k!}xD0k!}t/0k!}w\\
+/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0M"",
+""%%%%%k99j09,,8b(D/))%E%%&%%%%%!}P).c!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k!}xG0k!}t\\
+20k!}w20k!}u20k!}x20k!}tP0k!}wP0k!}uP0k!}xP0k!}t&0k!}e&/I"",
+""%%%%%k99j09,,8b&D/))%E%%&%%%%%!}w%6Q!}u%0k!}x%0k!}tD0k!}wD0k!}uD0k!}xD0k!}t\\
+/0k!}w/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k"",
+""%%%%%k99j09,,8b&D8,,%c%b&%%%%%!}w*P0k!}u*P0k!}x*P0k!}tHP0k!}wHP0k!}uHP0k!}x\\
+HP0k!}t3P0k!}w3P0k!}u3P0k!}x3P0k!}tQP0k!}wQP0k!}uQP0k!}xQP0k!}t%&09"",
+""%%%%%k99j09,,8b&D%%%%&%D&%%%%%!}k%6,!}w%0k!}u%0k!}x%0k!}tD0k!}wD0k!}uD0k!}x\\
+D0k!}t/0k!}w/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}%).c"",
+""%%%%%k99j09,,8D&D%%%%&%D&%%%%%!}t%5P!}w%0k!}u%0k!}x%0k!}tD0k!}wD0k!}uD0k!}x\\
+D0k!}t/0k!}w/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0^"",
+""%%%%%k99j09,,8b&D8%%%&%D&%%%%%!{QP-b!}t&0k!}w&0k!}u&0k!}x&0k!}tE0k!}wE0k!}u\\
+E0k!}xE0k!}t00k!}w00k!}u00k!}x00k!}tN0k!}wN0k!}uN0k!}fN/g"",
+""%%%%%k99j09,,8b&D/%%%&%D&%%%%%!}oM/g!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}u\\
+G0k!}xG0k!}t20k!}w20k!}u20k!}x20k!}tP0k!}wP0k!}uP0k!z*P-b"",
+""%%%%%k99j09,,8b(D8,%%&%D&%%%%%!}xQD6.!}t%/0k!}w%/0k!}u%/0k!}x%/0k!}tD/0k!}w\\
+D/0k!}uD/0k!}xD/0k!}t//0k!}w//0k!}u//0k!}x//0k!}tM/0k!}wM/0k!}uM/0M"",
+""%%%%%k99j09,,8%(D%)%%&%D&%%%%%!}NM.c!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}w\\
+G0k!}uG0k!}xG0k!}t20k!}w20k!}u20k!}x20k!}tP0k!}wP0k!}cP/I"",
+""%%%%%k99j09,,8b&D%)%%&%D&%%%%%!}uM6Q!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}w\\
+G0k!}uG0k!}xG0k!}t20k!}w20k!}u20k!}x20k!}tP0k!}wP0k"",
+""%%%%%k99j09,,8b(D8)%%&%D&%%%%%!}uQ%0k!}xQ%0k!}t%D1, }w%D%I6Y.QAdM:^UEh(K8[0\\
+SCf,O=b4WGj&7Z/RBeNc5XHk }u%D%6Y.AdM:^UEh(K8[0SCf,O=b4WGj&7Z\\
+/Bec5XHk }x%D%6Y.Ad:^Eh(K8[0SCf,O=b4WGj7Z/Bec\\
+5XHk }tDD6YAd:^Eh(K8[0SCf,O=b4WGj7ZBec5XHk }wDD6YAd^h(K8[0SCf,\\
+O=b4WGj7ZBai)L9]1TDg-P>c5XHk }uDD6A^h(K8[0SCf,O=b4WGj7Ba)L9]1TDg-P>c5XHk }xD\\
+D6A(K8[0SCf,O=b4WGj7)L9]1TDg-P>c5XHk }]/D%I6Y.QAd*M:^2UEh(K8[0Sf,O=b4WGj&JZ/\\
+Re+Nc5XH }^/D%IY.Qd*M:2UE(K[0S,O=4WG&J/R+N<3VF)L1T-P>5X jaMD%\\
+I6Y.QAdM:^2UEhK[0SCfOb4GjJZ/Ba3F1DH!}t&D0k!}w&D0k!}u&D0k!}x&D0k!}tED0k!}eED/\\
+I"",
+""%%%%%k99j09,,8b&D/)%%&%D&%%%%%!}wD6Q!}uD0k!}xD0k!}t/0k!}w/0k!}u/0k!}x/0k!}t\\
+M0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k"",
+""%%%%%k99j09,,8b(D8,,%&%D&%%%%%!}wHM0k!}uHM0k!}xHM0k!}t3M0k!}w3M0k!}u3M0k!}x\\
+3M0k!}tQM0k!}wQM0k!}uQM0k!}xQM0k!}t%)0k!}w%)0k!}u%)0k!}x%)0k!}tD)09"",
+""%%%%%k99j09,,8b%D%%)%&%D&%%%%%!}kD6,!}wD0k!}uD0k!}xD0k!}t/0k!}w/0k!}u/0k!}x\\
+/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}%G.c"",
+""%%%%%k99j09,,8b(D%%)%&%D&%%%%%!}tG5P!}wG0k!}uG0k!}xG0k!}t20k!}w20k!}u20k!}x\\
+20k!}tP0k!}wP0k!}uP0k!}xP0k!}t&0k!}w&0k!}u&0k!}x&0^"",
+""%%%%%k99j09,,8b&D%%)%&%D&%%%%%!{Q%-b!}tD0k!}wD0k!}uD0k!}xD0k!}t/0k!}w/0k!}u\\
+/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}f)/g"",
+""%%%%%k99j09,,8b(D8%)%&%D&%%%%%!}o*%/g!}tH%0k!}wH%0k!}uH%0k!}xH%0k!}t3%0k!}w\\
+3%0k!}u3%0k!}x3%0k!}tQ%0k!}wQ%0k!}uQ%0k!}xQ%0k!}t%D0k!}w%D0k!}u%D0k!z*%D-b"",
+""%%%%%k99j09,,8b%D/%)%&%D&%%%%%!}x%6.!}tD0k!}wD0k!}uD0k!}xD0k!}t/0k!}w/0k!}u\\
+/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0M"",
+""%%%%%k99j09,,8b(D/%)%&%D&%%%%%!}N).c!}x)0k!}tG0k!}wG0k!}uG0k!}xG0k!}t20k!}w\\
+20k!}u20k!}x20k!}tP0k!}wP0k!}uP0k!}xP0k!}t&0k!}w&0k!}c&/I"",
+""%%%%%k99j09,,8b&D/%)%&%D&%%%%%!}u%6Q!}x%0k!}tD0k!}wD0k!}uD0k!}xD0k!}t/0k!}w\\
+/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k"",
+""%%%%%k99j09,,8b(D8,)%&%D&%%%%%!}u*D0k!}x*D0k!}tHD0k!}wHD0k!}uHD0k!}xHD0k!}t\\
+3D0k!}w3D0k!}u3D0k!}x3D0k!}tQD0k!}wQD0k!}uQD0k!}xQD0k!}t%/0k!}w%/09"",
+""%%%%%k99j09,,8b%D%))%&%D&%%%%%!}n%6,!}u%0k!}x%0k!}tD0k!}wD0k!}uD0k!}xD0k!}t\\
+/0k!}w/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!})).c"",
+""%%%%%k99j09,,8b(D%))%&%D&%%%%%!}w)5P!}u)0k!}x)0k!}tG0k!}wG0k!}uG0k!}xG0k!}t\\
+20k!}w20k!}u20k!}x20k!}tP0k!}wP0k!}uP0k!}xP0k!}t&0^"",
+""%%%%%k99j09,,8b&D%))%&%D&%%%%%!{M%-b!}w%0k!}u%0k!}x%0k!}tD0k!}wD0k!}uD0k!}x\\
+D0k!}t/0k!}w/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}b)/g"",
+""%%%%%k99j09,,8b(D8))%&%D&%%%%%!}k*%/g!}w*%0k!}u*%0k!}x*%0k!}tH%0k!}wH%0k!}u\\
+H%0k!}xH%0k!}t3%0k!}w3%0k!}u3%0k!}x3%0k!}tQ%0k!}wQ%0k!}uQ%0k!}xQ%0k!z%%D-b"",
+""%%%%%k99j09,,8%%D/))%&%D&%%%%%!}t%6.!}w%0k!}u%0k!}x%0k!}tD0k!}wD0k!}uD0k!}x\\
+D0k!}t/0k!}w/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0M"",
+""%%%%%k99j09,,8b%D/))%&%D&%%%%%!}QM.c!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}u\\
+G0k!}xG0k!}t20k!}w20k!}u20k!}x20k!}tP0k!}wP0k!}uP0k!}fP/I"",
+""%%%%%k99j09,,8b(D/))%&%D&%%%%%!}xP6Q!}t&0k!}w&0k!}u&0k!}x&0k!}tE0k!}wE0k!}u\\
+E0k!}xE0k!}t00k!}w00k!}u00k!}x00k!}tN0k!}wN0k!}uN0k"",
+""%%%%%k99j09,,8b&D/))%&%D&%%%%%!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}wG0k!}u\\
+G0k!}xG0k!}t20k!}w20k!}u20k!}x20k!}tP0k!}wP0k!}uP09"",
+""%%%%%k99j09,,8b&D8,,%c%D&%%%%%!}lQM6,!}xQM0k!}t%)0k!}w%)0k!}u%)0k!}x%)0k!}t\\
+D)0k!}wD)0k!}uD)0k!}xD)0k!}t/)0k!}w/)0k!}u/)0k!}x/)0k!}tM)0k!}wM)0k!}&M).c"",
+""%%%%%k99j09,,8b&D%%%%E%D&%%%%%!}uM5P!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}tG0k!}w\\
+G0k!}uG0k!}xG0k!}t20k!}w20k!}u20k!}x20k!}tP0k!}wP0^"",
+""%%%%%k99j09,,8b&D8%%%E%D&%%%%%!{PP-b!}uP0k!}xP0k!}t&0k!}w&0k!}u&0k!}x&0k!}t\\
+E0k!}wE0k!}uE0k!}xE0k!}t00k!}w00k!}u00k!}x00k!}tN0k!}eN/g"",
+""%%%%%k99j09,,8b&D/%%%E%D&%%%%%!}nM/g!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!}t\\
+G0k!}wG0k!}uG0k!}xG0k!}t20k!}w20k!}u20k!}x20k!}tP0k!z)P-b"",
+""%%%%%k99j09,,8b(D8,%%E%D&%%%%%!}wQD6.!}uQD0k!}xQD0k!}t%/1( }w%/%I6Y.QAdM:^U\\
+Eh(K8[0SCf,O=b4WGj&J7Z/BeNc5XHk }u%/%6Y.AdM:^UEh(K8[0SCf,O=b\\
+4WGj&7Z/BeNc5XHk }x%/%6Y.Ad:^Eh(K8[0SCf,O=b4WGj&7ZBec5XHk }tD/6YAd:^Eh(K8[0SCf,O=b4WGj7ZBeaFi)L9]1TDg-P>c5XHk }wD/6YAd^h(K\\
+8[0SCf,O=b4WGj7Beai)L9]1TDg-P>c5XHk }uD/6A^h(K8[0SCf,O=b4WGj7Bi)L9]1TDg-P>c5\\
+XHk }xD/6A(K8[0SCf,O=b4WGjB)L9]1TDg-P>c5XHk }]//%I6Y.QAd*M:^2UEh(K[0SCf,O=b4\\
+WGj&JZ/Re+N5XHk }^//%IY.Qd*M:2UE(K0Sf,O=4WG&J/R+N<3VF)L1T-P5X\\
+H jaM/%I6Y.QAd*M^2UEhK[0SCfOb4WGJZ/BN3F1D5!}t&/0k!}w&/0k!}u&/0k!}x&/0k!}bE//\\
+g"",
+""%%%%%k99j09,,8b&D%)%%E%D&%%%%%!}kD/g!}wD0k!}uD0k!}xD0k!}t/0k!}w/0k!}u/0k!}x\\
+/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}x)0k!z%G-b"",
+""%%%%%k99j09,,8b&D8)%%E%D&%%%%%!}tG6.!}wG0k!}uG0k!}xG0k!}t20k!}w20k!}u20k!}x\\
+20k!}tP0k!}wP0k!}uP0k!}xP0k!}t&0k!}w&0k!}u&0k!}x&0M"",
+""%%%%%k99j09,,8b&D/)%%E%D&%%%%%!}Q%.c!}tD0k!}wD0k!}uD0k!}xD0k!}t/0k!}w/0k!}u\\
+/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)0k!}f)/I"",
+""%%%%%k99j09,,8b(D8,,%E%D&%%%%%!}x*M6Q!}tHM0k!}wHM0k!}uHM0k!}xHM0k!}t3M0k!}w\\
+3M0k!}u3M0k!}x3M0k!}tQM0k!}wQM0k!}uQM0k!}xQM0k!}t%)0k!}w%)0k!}u%)0k"",
+""%%%%%k99j09,,8b%D%%)%E%D&%%%%%!}x%0k!}tD0k!}wD0k!}uD0k!}xD0k!}t/0k!}w/0k!}u\\
+/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0k!}u)09"",
+""%%%%%k99j09,,8b(D%%)%E%D&%%%%%!}l)6,!}x)0k!}tG0k!}wG0k!}uG0k!}xG0k!}t20k!}w\\
+20k!}u20k!}x20k!}tP0k!}wP0k!}uP0k!}xP0k!}t&0k!}w&0k!}&&.c"",
+""%%%%%k99j09,,8b&D%%)%E%D&%%%%%!}u%5P!}x%0k!}tD0k!}wD0k!}uD0k!}xD0k!}t/0k!}w\\
+/0k!}u/0k!}x/0k!}tM0k!}wM0k!}uM0k!}xM0k!}t)0k!}w)0^"" ];
+"
+"#############################################################################
+##
+#W id1440.v GAP library of id's Hans Ulrich Besche
+##
+
+ID_GROUP_TREE.next[1440].next[22]:=
+rec(
+ fp:= [ 911, 1612, 2595, 5108, 5239, 5356, 8231, 8242, 8625, 11389, 11397,
+12659, 13676, 14802, 15398, 16488, 20702, 21830, 22171, 22733, 23466, 24953,
+24964, 25321, 25503, 26230, 26419, 27822, 28390, 31154, 31170, 31686, 32030,
+32444, 33788, 34048, 34769, 36112, 36259, 37014, 37184, 38051, 39948, 41996,
+44383, 45316, 45850, 48361, 48614, 48664, 48705, 48752, 49261, 49394, 50649,
+51491, 52025, 53606, 53631, 53753, 54603, 54726, 54789, 56074, 56335, 58695,
+58718, 58842, 59300, 62267, 62975, 63276, 64940, 65031, 65083, 65474, 65842,
+66669, 67371, 68213, 70917, 71247, 71325, 71448, 72207, 72281, 74409, 75020,
+75440, 76072, 76189, 76336, 77173, 77820, 78286, 78572, 79697, 80226, 80584,
+81805, 82434, 83348, 84093, 84461, 87167, 87523, 88047, 88170, 90826, 90931,
+91170, 91181, 92177, 93203, 93566, 93590, 93670, 93830, 96409, 96419, 97191,
+98655, 99492, 99546 ],
+ level:= 4,
+ next:= [ 568, 907, 560, 874, 598, 569, rec(
+ fp:= [ 23442, 47370 ],
+ next:= [ 345, 337 ] ), 883, 581, 579, 896, 435, 368, 575, 425, 589, 439,
+864, 564, 597, 437, 346, 882, 349, 908, 436, 599, 593, 553, 559, 372, rec(
+ fp:= [ 5729, 67448 ],
+ next:= [ 348, 341 ] ), 339, 915, 588, 434, 875, 562, 374, 595, 582, 342,
+580, 336, 592, 594, 558, 328, 556, 369, 576, 340, 433, 906, 354, 876, 431,
+561, 428, 370, 869, 327, 427, 563, 916, 565, 321, 373, 572, 577, 879, 897,
+573, 583, rec(
+ fp:= [ 842, 45029 ],
+ next:= [ 334, 326 ] ), 347, 350, 567, 352, 877, 596, 371, 873, 329, 343,
+429, 557, 424, 319, 585, 566, 375, 555, 430, 591, 344, rec(
+ fp:= [ 13443, 48933 ],
+ next:= [ 881, 878 ] ), 914, 432, 320, 574, 426, 351, 353, 898, 570, rec(
+ fp:= [ 5925, 66535 ],
+ next:= [ 868, 870 ] ), 335, rec(
+ fp:= [ 32700, 83412 ],
+ next:= [ 578, 355 ] ), 438, 338, 884, 600, 571, 586, 584, 423, 367, 422,
+880, 356, 590, 554, 587 ] );
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+module cordic(clock, reset, enable, xi, yi, zi, xo, yo, zo );
+ parameter bitwidth = 16;
+ parameter zwidth = 16;
+
+ input clock;
+ input reset;
+ input enable;
+ input [bitwidth-1:0] xi, yi;
+ output [bitwidth-1:0] xo, yo;
+ input [zwidth-1:0] zi;
+ output [zwidth-1:0] zo;
+
+ reg [bitwidth+1:0] \t x0,y0;
+ reg [zwidth-2:0] \t z0;
+ wire [bitwidth+1:0] \t x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12;
+ wire [bitwidth+1:0] \t y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12;
+ wire [zwidth-2:0] z1,z2,z3,z4,z5,z6,z7,z8,z9,z10,z11,z12;
+
+ wire [bitwidth+1:0] xi_ext = {{2{xi[bitwidth-1]}},xi};
+ wire [bitwidth+1:0] yi_ext = {{2{yi[bitwidth-1]}},yi};
+
+ // Compute consts. Would be easier if vlog had atan...
+ // see gen_cordic_consts.py
+
+`define c00 16'd8192
+`define c01 16'd4836
+`define c02 16'd2555
+`define c03 16'd1297
+`define c04 16'd651
+`define c05 16'd326
+`define c06 16'd163
+`define c07 16'd81
+`define c08 16'd41
+`define c09 16'd20
+`define c10 16'd10
+`define c11 16'd5
+`define c12 16'd3
+`define c13 16'd1
+`define c14 16'd1
+`define c15 16'd0
+`define c16 16'd0
+
+ always @(posedge clock)
+ if(reset)
+ begin
+\t x0 <= #1 0; y0 <= #1 0; z0 <= #1 0;
+ end
+ else if(enable)
+ begin
+\t z0 <= #1 zi[zwidth-2:0];
+\t case (zi[zwidth-1:zwidth-2])
+\t 2'b00, 2'b11 :
+\t begin
+\t\t x0 <= #1 xi_ext;
+\t\t y0 <= #1 yi_ext;
+\t end
+\t 2'b01, 2'b10 :
+\t begin
+\t\t x0 <= #1 -xi_ext;
+\t\t y0 <= #1 -yi_ext;
+\t end
+\t endcase // case(zi[zwidth-1:zwidth-2])
+ end // else: !if(reset)
+
+ // FIXME need to handle variable number of stages
+ // FIXME should be able to narrow zwidth but quartus makes it bigger...
+ // This would be easier if arrays worked better in vlog...
+ cordic_stage #(bitwidth+2,zwidth-1,0) cordic_stage0 (clock,reset,enable,x0,y0,z0,`c00,x1,y1,z1);
+ cordic_stage #(bitwidth+2,zwidth-1,1) cordic_stage1 (clock,reset,enable,x1,y1,z1,`c01,x2,y2,z2);
+ cordic_stage #(bitwidth+2,zwidth-1,2) cordic_stage2 (clock,reset,enable,x2,y2,z2,`c02,x3,y3,z3);
+ cordic_stage #(bitwidth+2,zwidth-1,3) cordic_stage3 (clock,reset,enable,x3,y3,z3,`c03,x4,y4,z4);
+ cordic_stage #(bitwidth+2,zwidth-1,4) cordic_stage4 (clock,reset,enable,x4,y4,z4,`c04,x5,y5,z5);
+ cordic_stage #(bitwidth+2,zwidth-1,5) cordic_stage5 (clock,reset,enable,x5,y5,z5,`c05,x6,y6,z6);
+ cordic_stage #(bitwidth+2,zwidth-1,6) cordic_stage6 (clock,reset,enable,x6,y6,z6,`c06,x7,y7,z7);
+ cordic_stage #(bitwidth+2,zwidth-1,7) cordic_stage7 (clock,reset,enable,x7,y7,z7,`c07,x8,y8,z8);
+ cordic_stage #(bitwidth+2,zwidth-1,8) cordic_stage8 (clock,reset,enable,x8,y8,z8,`c08,x9,y9,z9);
+ cordic_stage #(bitwidth+2,zwidth-1,9) cordic_stage9 (clock,reset,enable,x9,y9,z9,`c09,x10,y10,z10);
+ cordic_stage #(bitwidth+2,zwidth-1,10) cordic_stage10 (clock,reset,enable,x10,y10,z10,`c10,x11,y11,z11);
+ cordic_stage #(bitwidth+2,zwidth-1,11) cordic_stage11 (clock,reset,enable,x11,y11,z11,`c11,x12,y12,z12);
+
+ assign xo = x12[bitwidth:1];
+ assign yo = y12[bitwidth:1];
+ //assign xo = x12[bitwidth+1:2]; // CORDIC gain is ~1.6, plus gain from rotating vectors
+ //assign yo = y12[bitwidth+1:2];
+ assign zo = z12;\t\t
+
+endmodule // cordic
+
+"
+"bustri\tbustri_inst (
+\t.data ( data_sig ),
+\t.enabledt ( enabledt_sig ),
+\t.tridata ( tridata_sig )
+\t);
+"
+"// megafunction wizard: %LPM_ADD_SUB%CBX%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: lpm_add_sub
+
+// ============================================================
+// File Name: add32.v
+// Megafunction Name(s):
+// \t\t\tlpm_add_sub
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+// ************************************************************
+
+
+//Copyright (C) 1991-2003 Altera Corporation
+//Any megafunction design, and related netlist (encrypted or decrypted),
+//support information, device programming or simulation file, and any other
+//associated documentation or information provided by Altera or a partner
+//under Altera\'s Megafunction Partnership Program may be used only
+//to program PLD devices (but not masked PLD devices) from Altera. Any
+//other use of such megafunction design, netlist, support information,
+//device programming or simulation file, or any other related documentation
+//or information is prohibited for any other purpose, including, but not
+//limited to modification, reverse engineering, de-compiling, or use with
+//any other silicon devices, unless such use is explicitly licensed under
+//a separate agreement with Altera or a megafunction partner. Title to the
+//intellectual property, including patents, copyrights, trademarks, trade
+//secrets, or maskworks, embodied in any such megafunction design, netlist,
+//support information, device programming or simulation file, or any other
+//related documentation or information provided by Altera or a megafunction
+//partner, remains with Altera, the megafunction partner, or their respective
+//licensors. No other licenses, including any licenses needed under any third
+//party\'s intellectual property, are provided herein.
+
+
+//lpm_add_sub DEVICE_FAMILY=Cyclone LPM_DIRECTION=ADD LPM_WIDTH=8 dataa datab result
+//VERSION_BEGIN 3.0 cbx_lpm_add_sub 2003:04:10:18:28:42:SJ cbx_mgl 2003:06:11:11:00:44:SJ cbx_stratix 2003:05:16:10:26:50:SJ VERSION_END
+
+//synthesis_resources = lut 8
+module add32_add_sub_nq7
+\t(
+\tdataa,
+\tdatab,
+\tresult) /* synthesis synthesis_clearbox=1 */;
+\tinput [7:0] dataa;
+\tinput [7:0] datab;
+\toutput [7:0] result;
+
+\twire [7:0] wire_add_sub_cella_combout;
+\twire [0:0] wire_add_sub_cella_0cout;
+\twire [0:0] wire_add_sub_cella_1cout;
+\twire [0:0] wire_add_sub_cella_2cout;
+\twire [0:0] wire_add_sub_cella_3cout;
+\twire [0:0] wire_add_sub_cella_4cout;
+\twire [0:0] wire_add_sub_cella_5cout;
+\twire [0:0] wire_add_sub_cella_6cout;
+\twire [7:0] wire_add_sub_cella_dataa;
+\twire [7:0] wire_add_sub_cella_datab;
+
+\tstratix_lcell add_sub_cella_0
+\t(
+\t.cin(1\'b0),
+\t.combout(wire_add_sub_cella_combout[0:0]),
+\t.cout(wire_add_sub_cella_0cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[0:0]),
+\t.datab(wire_add_sub_cella_datab[0:0]));
+\tdefparam
+\t\tadd_sub_cella_0.cin_used = ""true"",
+\t\tadd_sub_cella_0.lut_mask = ""96e8"",
+\t\tadd_sub_cella_0.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_0.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_0.lpm_type = ""stratix_lcell"";
+\tstratix_lcell add_sub_cella_1
+\t(
+\t.cin(wire_add_sub_cella_0cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[1:1]),
+\t.cout(wire_add_sub_cella_1cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[1:1]),
+\t.datab(wire_add_sub_cella_datab[1:1]));
+\tdefparam
+\t\tadd_sub_cella_1.cin_used = ""true"",
+\t\tadd_sub_cella_1.lut_mask = ""96e8"",
+\t\tadd_sub_cella_1.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_1.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_1.lpm_type = ""stratix_lcell"";
+\tstratix_lcell add_sub_cella_2
+\t(
+\t.cin(wire_add_sub_cella_1cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[2:2]),
+\t.cout(wire_add_sub_cella_2cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[2:2]),
+\t.datab(wire_add_sub_cella_datab[2:2]));
+\tdefparam
+\t\tadd_sub_cella_2.cin_used = ""true"",
+\t\tadd_sub_cella_2.lut_mask = ""96e8"",
+\t\tadd_sub_cella_2.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_2.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_2.lpm_type = ""stratix_lcell"";
+\tstratix_lcell add_sub_cella_3
+\t(
+\t.cin(wire_add_sub_cella_2cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[3:3]),
+\t.cout(wire_add_sub_cella_3cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[3:3]),
+\t.datab(wire_add_sub_cella_datab[3:3]));
+\tdefparam
+\t\tadd_sub_cella_3.cin_used = ""true"",
+\t\tadd_sub_cella_3.lut_mask = ""96e8"",
+\t\tadd_sub_cella_3.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_3.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_3.lpm_type = ""stratix_lcell"";
+\tstratix_lcell add_sub_cella_4
+\t(
+\t.cin(wire_add_sub_cella_3cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[4:4]),
+\t.cout(wire_add_sub_cella_4cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[4:4]),
+\t.datab(wire_add_sub_cella_datab[4:4]));
+\tdefparam
+\t\tadd_sub_cella_4.cin_used = ""true"",
+\t\tadd_sub_cella_4.lut_mask = ""96e8"",
+\t\tadd_sub_cella_4.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_4.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_4.lpm_type = ""stratix_lcell"";
+\tstratix_lcell add_sub_cella_5
+\t(
+\t.cin(wire_add_sub_cella_4cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[5:5]),
+\t.cout(wire_add_sub_cella_5cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[5:5]),
+\t.datab(wire_add_sub_cella_datab[5:5]));
+\tdefparam
+\t\tadd_sub_cella_5.cin_used = ""true"",
+\t\tadd_sub_cella_5.lut_mask = ""96e8"",
+\t\tadd_sub_cella_5.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_5.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_5.lpm_type = ""stratix_lcell"";
+\tstratix_lcell add_sub_cella_6
+\t(
+\t.cin(wire_add_sub_cella_5cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[6:6]),
+\t.cout(wire_add_sub_cella_6cout[0:0]),
+\t.dataa(wire_add_sub_cella_dataa[6:6]),
+\t.datab(wire_add_sub_cella_datab[6:6]));
+\tdefparam
+\t\tadd_sub_cella_6.cin_used = ""true"",
+\t\tadd_sub_cella_6.lut_mask = ""96e8"",
+\t\tadd_sub_cella_6.operation_mode = ""arithmetic"",
+\t\tadd_sub_cella_6.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_6.lpm_type = ""stratix_lcell"";
+\tstratix_lcell add_sub_cella_7
+\t(
+\t.cin(wire_add_sub_cella_6cout[0:0]),
+\t.combout(wire_add_sub_cella_combout[7:7]),
+\t.dataa(wire_add_sub_cella_dataa[7:7]),
+\t.datab(wire_add_sub_cella_datab[7:7]));
+\tdefparam
+\t\tadd_sub_cella_7.cin_used = ""true"",
+\t\tadd_sub_cella_7.lut_mask = ""9696"",
+\t\tadd_sub_cella_7.operation_mode = ""normal"",
+\t\tadd_sub_cella_7.sum_lutc_input = ""cin"",
+\t\tadd_sub_cella_7.lpm_type = ""stratix_lcell"";
+\tassign
+\t\twire_add_sub_cella_dataa = dataa,
+\t\twire_add_sub_cella_datab = datab;
+\tassign
+\t\tresult = wire_add_sub_cella_combout;
+endmodule //add32_add_sub_nq7
+//VALID FILE
+
+
+module add32 (
+\tdataa,
+\tdatab,
+\tresult)/* synthesis synthesis_clearbox = 1 */;
+
+\tinput\t[7:0] dataa;
+\tinput\t[7:0] datab;
+\toutput\t[7:0] result;
+
+\twire [7:0] sub_wire0;
+\twire [7:0] result = sub_wire0[7:0];
+
+\tadd32_add_sub_nq7\tadd32_add_sub_nq7_component (
+\t\t\t\t.dataa (dataa),
+\t\t\t\t.datab (datab),
+\t\t\t\t.result (sub_wire0));
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: nBit NUMERIC ""8""
+// Retrieval info: PRIVATE: Function NUMERIC ""0""
+// Retrieval info: PRIVATE: WhichConstant NUMERIC ""0""
+// Retrieval info: PRIVATE: ConstantA NUMERIC ""0""
+// Retrieval info: PRIVATE: ConstantB NUMERIC ""0""
+// Retrieval info: PRIVATE: ValidCtA NUMERIC ""0""
+// Retrieval info: PRIVATE: ValidCtB NUMERIC ""0""
+// Retrieval info: PRIVATE: CarryIn NUMERIC ""0""
+// Retrieval info: PRIVATE: CarryOut NUMERIC ""0""
+// Retrieval info: PRIVATE: Overflow NUMERIC ""0""
+// Retrieval info: PRIVATE: Latency NUMERIC ""0""
+// Retrieval info: PRIVATE: aclr NUMERIC ""0""
+// Retrieval info: PRIVATE: clken NUMERIC ""0""
+// Retrieval info: PRIVATE: LPM_PIPELINE NUMERIC ""0""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: CONSTANT: LPM_WIDTH NUMERIC ""8""
+// Retrieval info: CONSTANT: LPM_DIRECTION STRING ""ADD""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""LPM_ADD_SUB""
+// Retrieval info: CONSTANT: LPM_HINT STRING ""ONE_INPUT_IS_CONSTANT=NO""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone""
+// Retrieval info: USED_PORT: result 0 0 8 0 OUTPUT NODEFVAL result[7..0]
+// Retrieval info: USED_PORT: dataa 0 0 8 0 INPUT NODEFVAL dataa[7..0]
+// Retrieval info: USED_PORT: datab 0 0 8 0 INPUT NODEFVAL datab[7..0]
+// Retrieval info: CONNECT: result 0 0 8 0 @result 0 0 8 0
+// Retrieval info: CONNECT: @dataa 0 0 8 0 dataa 0 0 8 0
+// Retrieval info: CONNECT: @datab 0 0 8 0 datab 0 0 8 0
+// Retrieval info: LIBRARY: lpm lpm.lpm_components.all
+"
+"addsub16\taddsub16_inst (
+\t.add_sub ( add_sub_sig ),
+\t.dataa ( dataa_sig ),
+\t.datab ( datab_sig ),
+\t.clock ( clock_sig ),
+\t.aclr ( aclr_sig ),
+\t.clken ( clken_sig ),
+\t.result ( result_sig )
+\t);
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+
+// testbench for fullchip
+
+`timescale 1ns/1ns
+
+module fullchip_tb();
+
+`include ""usrp_tasks.v""
+
+fullchip fullchip
+ (
+ .clk_120mhz(clk_120mhz),
+ .reset(reset),
+ .enable_rx(enable_rx),
+ .enable_tx(enable_tx),
+ .SLD(serload),
+ .SEN(serenable),
+ .clear_status(),
+ .SDI(serdata),
+ .SCLK(serclk),
+\t
+ .adc1_data(adc1_data),
+ .adc2_data(adc2_data),
+ .adc3_data(adc1_data),
+ .adc4_data(adc2_data),
+
+ .dac1_data(dac1_data),
+ .dac2_data(dac2_data),
+ .dac3_data(),.dac4_data(),
+
+ .adclk0(adclk),.adclk1(),
+
+ .adc_oeb(),.adc_otr(4\'b0),
+
+ .clk_out(clk_out),
+
+ .misc_pins(),
+
+ // USB interface
+ .usbclk(usbclk),.usbctl(usbctl),
+ .usbrdy(usbrdy),.usbdata(usbdata)
+ );\t
+\t
+\treg clk_120mhz;
+\treg usbclk;
+\treg reset;
+
+\treg [11:0] adc1_data, adc2_data;
+\twire [13:0] dac1_data, dac2_data;
+
+\twire [5:0] usbctl;
+\twire [5:0] usbrdy;
+
+\twire [15:0] usbdata;
+
+\treg WE, RD, OE;
+
+ assign usbctl[0] = WE;
+ assign usbctl[1] = RD;
+ assign usbctl[2] = OE;
+\tassign usbctl[5:3] = 0;
+
+ wire have_packet_rdy = usbrdy[1];
+
+\treg tb_oe;
+ initial tb_oe=1\'b1;
+
+\tassign usbdata = tb_oe ? usbdatareg : 16\'hxxxx;
+\treg serload, serenable, serclk, serdata;
+\treg enable_tx, enable_rx;
+\treg [15:0] usbdatareg;
+
+///////////////////////////////////////////////
+// Simulation Control
+initial
+begin
+\t$dumpfile(""fullchip_tb.vcd"");
+\t$dumpvars(0, fullchip_tb);
+end
+
+//initial #1000000 $finish;
+
+///////////////////////////////////////////////
+// Monitors
+
+//initial $monitor(dac1_data);
+
+///////////////////////////////////////////////
+// Clock and reset
+
+initial clk_120mhz = 0;
+initial usbclk = 0;
+always #24 clk_120mhz = ~clk_120mhz;
+always #60 usbclk = ~usbclk;
+
+initial reset = 1\'b1;
+initial #500 reset = 1\'b0;
+
+/////////////////////////////////////////////////
+// Run AD input
+
+always @(posedge adclk)\t adc1_data <= #1 12\'d1234;
+always @(posedge adclk)\t adc2_data <= #1 12\'d1234;
+
+/////////////////////////////////////////////////
+// USB interface
+
+ initial
+ begin
+ initialize_usb;
+ #30000 @(posedge usbclk);
+ burst_usb_write(257);
+
+ #30000 burst_usb_read(256);
+ #10000 $finish;
+
+//\trepeat(30)
+//\tbegin
+//\t\twrite_from_usb;
+//\t\tread_from_usb;
+//\tend
+end
+
+/////////////////////////////////////////////////
+// TX and RX enable
+
+initial enable_tx = 1\'b0;
+initial #40000 enable_tx = 1\'b1;
+initial enable_rx = 1\'b0;
+initial #40000 enable_rx = 1\'b1;
+
+//////////////////////////////////////////////////
+// Set up control bus
+
+initial
+begin
+\t#1000 send_config_word(`ch1in_freq,32\'h0); // 1 MHz on 60 MHz clock
+\tsend_config_word(`ch2in_freq,32\'h0);
+\tsend_config_word(`ch3in_freq,32\'h0);
+\tsend_config_word(`ch4in_freq,32\'h0);
+\tsend_config_word(`ch1out_freq,32\'h01234567);
+\tsend_config_word(`ch2out_freq,32\'h0);
+\tsend_config_word(`ch3out_freq,32\'h0);
+\tsend_config_word(`ch4out_freq,32\'h0);
+\tsend_config_word(`misc,32\'h0);
+\tsend_config_word(`rates,{8\'d2,8\'d12,8\'h0f,8\'h07});
+\t// adc, ext, interp, decim
+end
+
+/////////////////////////////////////////////////////////
+
+endmodule
+
+"
+"// megafunction wizard: %FIFO%\r
+// GENERATION: STANDARD\r
+// VERSION: WM1.0\r
+// MODULE: dcfifo \r
+\r
+// ============================================================\r
+// File Name: fifo_4kx16_dc.v\r
+// Megafunction Name(s):\r
+// \t\t\tdcfifo\r
+// ============================================================\r
+// ************************************************************\r
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!\r
+//\r
+// 5.1 Build 213 01/19/2006 SP 1 SJ Web Edition\r
+// ************************************************************\r
+\r
+\r
+//Copyright (C) 1991-2006 Altera Corporation\r
+//Your use of Altera Corporation\'s design tools, logic functions \r
+//and other software and tools, and its AMPP partner logic \r
+//functions, and any output files any of the foregoing \r
+//(including device programming or simulation files), and any \r
+//associated documentation or information are expressly subject \r
+//to the terms and conditions of the Altera Program License \r
+//Subscription Agreement, Altera MegaCore Function License \r
+//Agreement, or other applicable license agreement, including, \r
+//without limitation, that your use is for the sole purpose of \r
+//programming logic devices manufactured by Altera and sold by \r
+//Altera or its authorized distributors. Please refer to the \r
+//applicable agreement for further details.\r
+\r
+\r
+// synopsys translate_off\r
+`timescale 1 ps / 1 ps\r
+// synopsys translate_on\r
+module fifo_4kx16_dc (\r
+\taclr,\r
+\tdata,\r
+\trdclk,\r
+\trdreq,\r
+\twrclk,\r
+\twrreq,\r
+\tq,\r
+\trdempty,\r
+\trdusedw,\r
+\twrfull,\r
+\twrusedw);\r
+\r
+\tinput\t aclr;\r
+\tinput\t[15:0] data;\r
+\tinput\t rdclk;\r
+\tinput\t rdreq;\r
+\tinput\t wrclk;\r
+\tinput\t wrreq;\r
+\toutput\t[15:0] q;\r
+\toutput\t rdempty;\r
+\toutput\t[11:0] rdusedw;\r
+\toutput\t wrfull;\r
+\toutput\t[11:0] wrusedw;\r
+\r
+\twire sub_wire0;\r
+\twire [11:0] sub_wire1;\r
+\twire sub_wire2;\r
+\twire [15:0] sub_wire3;\r
+\twire [11:0] sub_wire4;\r
+\twire rdempty = sub_wire0;\r
+\twire [11:0] wrusedw = sub_wire1[11:0];\r
+\twire wrfull = sub_wire2;\r
+\twire [15:0] q = sub_wire3[15:0];\r
+\twire [11:0] rdusedw = sub_wire4[11:0];\r
+\r
+\tdcfifo\tdcfifo_component (\r
+\t\t\t\t.wrclk (wrclk),\r
+\t\t\t\t.rdreq (rdreq),\r
+\t\t\t\t.aclr (aclr),\r
+\t\t\t\t.rdclk (rdclk),\r
+\t\t\t\t.wrreq (wrreq),\r
+\t\t\t\t.data (data),\r
+\t\t\t\t.rdempty (sub_wire0),\r
+\t\t\t\t.wrusedw (sub_wire1),\r
+\t\t\t\t.wrfull (sub_wire2),\r
+\t\t\t\t.q (sub_wire3),\r
+\t\t\t\t.rdusedw (sub_wire4)\r
+\t\t\t\t// synopsys translate_off\r
+\t\t\t\t,\r
+\t\t\t\t.wrempty (),\r
+\t\t\t\t.rdfull ()\r
+\t\t\t\t// synopsys translate_on\r
+\t\t\t\t);\r
+\tdefparam\r
+\t\tdcfifo_component.add_ram_output_register = ""OFF"",\r
+\t\tdcfifo_component.clocks_are_synchronized = ""FALSE"",\r
+\t\tdcfifo_component.intended_device_family = ""Cyclone"",\r
+\t\tdcfifo_component.lpm_numwords = 4096,\r
+\t\tdcfifo_component.lpm_showahead = ""ON"",\r
+\t\tdcfifo_component.lpm_type = ""dcfifo"",\r
+\t\tdcfifo_component.lpm_width = 16,\r
+\t\tdcfifo_component.lpm_widthu = 12,\r
+\t\tdcfifo_component.overflow_checking = ""OFF"",\r
+\t\tdcfifo_component.underflow_checking = ""OFF"",\r
+\t\tdcfifo_component.use_eab = ""ON"";\r
+\r
+\r
+endmodule\r
+\r
+// ============================================================\r
+// CNX file retrieval info\r
+// ============================================================\r
+// Retrieval info: PRIVATE: AlmostEmpty NUMERIC ""0""\r
+// Retrieval info: PRIVATE: AlmostEmptyThr NUMERIC ""-1""\r
+// Retrieval info: PRIVATE: AlmostFull NUMERIC ""0""\r
+// Retrieval info: PRIVATE: AlmostFullThr NUMERIC ""-1""\r
+// Retrieval info: PRIVATE: CLOCKS_ARE_SYNCHRONIZED NUMERIC ""0""\r
+// Retrieval info: PRIVATE: Clock NUMERIC ""4""\r
+// Retrieval info: PRIVATE: Depth NUMERIC ""4096""\r
+// Retrieval info: PRIVATE: Empty NUMERIC ""1""\r
+// Retrieval info: PRIVATE: Full NUMERIC ""1""\r
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone""\r
+// Retrieval info: PRIVATE: LE_BasedFIFO NUMERIC ""0""\r
+// Retrieval info: PRIVATE: LegacyRREQ NUMERIC ""0""\r
+// Retrieval info: PRIVATE: MAX_DEPTH_BY_9 NUMERIC ""0""\r
+// Retrieval info: PRIVATE: OVERFLOW_CHECKING NUMERIC ""1""\r
+// Retrieval info: PRIVATE: Optimize NUMERIC ""2""\r
+// Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC ""0""\r
+// Retrieval info: PRIVATE: UNDERFLOW_CHECKING NUMERIC ""1""\r
+// Retrieval info: PRIVATE: UsedW NUMERIC ""1""\r
+// Retrieval info: PRIVATE: Width NUMERIC ""16""\r
+// Retrieval info: PRIVATE: dc_aclr NUMERIC ""1""\r
+// Retrieval info: PRIVATE: rsEmpty NUMERIC ""1""\r
+// Retrieval info: PRIVATE: rsFull NUMERIC ""0""\r
+// Retrieval info: PRIVATE: rsUsedW NUMERIC ""1""\r
+// Retrieval info: PRIVATE: sc_aclr NUMERIC ""0""\r
+// Retrieval info: PRIVATE: sc_sclr NUMERIC ""0""\r
+// Retrieval info: PRIVATE: wsEmpty NUMERIC ""0""\r
+// Retrieval info: PRIVATE: wsFull NUMERIC ""1""\r
+// Retrieval info: PRIVATE: wsUsedW NUMERIC ""1""\r
+// Retrieval info: CONSTANT: ADD_RAM_OUTPUT_REGISTER STRING ""OFF""\r
+// Retrieval info: CONSTANT: CLOCKS_ARE_SYNCHRONIZED STRING ""FALSE""\r
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone""\r
+// Retrieval info: CONSTANT: LPM_NUMWORDS NUMERIC ""4096""\r
+// Retrieval info: CONSTANT: LPM_SHOWAHEAD STRING ""ON""\r
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""dcfifo""\r
+// Retrieval info: CONSTANT: LPM_WIDTH NUMERIC ""16""\r
+// Retrieval info: CONSTANT: LPM_WIDTHU NUMERIC ""12""\r
+// Retrieval info: CONSTANT: OVERFLOW_CHECKING STRING ""OFF""\r
+// Retrieval info: CONSTANT: UNDERFLOW_CHECKING STRING ""OFF""\r
+// Retrieval info: CONSTANT: USE_EAB STRING ""ON""\r
+// Retrieval info: USED_PORT: aclr 0 0 0 0 INPUT GND aclr\r
+// Retrieval info: USED_PORT: data 0 0 16 0 INPUT NODEFVAL data[15..0]\r
+// Retrieval info: USED_PORT: q 0 0 16 0 OUTPUT NODEFVAL q[15..0]\r
+// Retrieval info: USED_PORT: rdclk 0 0 0 0 INPUT NODEFVAL rdclk\r
+// Retrieval info: USED_PORT: rdempty 0 0 0 0 OUTPUT NODEFVAL rdempty\r
+// Retrieval info: USED_PORT: rdreq 0 0 0 0 INPUT NODEFVAL rdreq\r
+// Retrieval info: USED_PORT: rdusedw 0 0 12 0 OUTPUT NODEFVAL rdusedw[11..0]\r
+// Retrieval info: USED_PORT: wrclk 0 0 0 0 INPUT NODEFVAL wrclk\r
+// Retrieval info: USED_PORT: wrfull 0 0 0 0 OUTPUT NODEFVAL wrfull\r
+// Retrieval info: USED_PORT: wrreq 0 0 0 0 INPUT NODEFVAL wrreq\r
+// Retrieval info: USED_PORT: wrusedw 0 0 12 0 OUTPUT NODEFVAL wrusedw[11..0]\r
+// Retrieval info: CONNECT: @data 0 0 16 0 data 0 0 16 0\r
+// Retrieval info: CONNECT: q 0 0 16 0 @q 0 0 16 0\r
+// Retrieval info: CONNECT: @wrreq 0 0 0 0 wrreq 0 0 0 0\r
+// Retrieval info: CONNECT: @rdreq 0 0 0 0 rdreq 0 0 0 0\r
+// Retrieval info: CONNECT: @rdclk 0 0 0 0 rdclk 0 0 0 0\r
+// Retrieval info: CONNECT: @wrclk 0 0 0 0 wrclk 0 0 0 0\r
+// Retrieval info: CONNECT: rdempty 0 0 0 0 @rdempty 0 0 0 0\r
+// Retrieval info: CONNECT: rdusedw 0 0 12 0 @rdusedw 0 0 12 0\r
+// Retrieval info: CONNECT: wrfull 0 0 0 0 @wrfull 0 0 0 0\r
+// Retrieval info: CONNECT: wrusedw 0 0 12 0 @wrusedw 0 0 12 0\r
+// Retrieval info: CONNECT: @aclr 0 0 0 0 aclr 0 0 0 0\r
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4kx16_dc.v TRUE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4kx16_dc.inc TRUE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4kx16_dc.cmp TRUE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4kx16_dc.bsf TRUE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4kx16_dc_inst.v TRUE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4kx16_dc_bb.v TRUE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4kx16_dc_waveforms.html FALSE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4kx16_dc_wave*.jpg FALSE\r
+"
+"//Copyright (C) 1991-2003 Altera Corporation
+//Any megafunction design, and related netlist (encrypted or decrypted),
+//support information, device programming or simulation file, and any other
+//associated documentation or information provided by Altera or a partner
+//under Altera's Megafunction Partnership Program may be used only
+//to program PLD devices (but not masked PLD devices) from Altera. Any
+//other use of such megafunction design, netlist, support information,
+//device programming or simulation file, or any other related documentation
+//or information is prohibited for any other purpose, including, but not
+//limited to modification, reverse engineering, de-compiling, or use with
+//any other silicon devices, unless such use is explicitly licensed under
+//a separate agreement with Altera or a megafunction partner. Title to the
+//intellectual property, including patents, copyrights, trademarks, trade
+//secrets, or maskworks, embodied in any such megafunction design, netlist,
+//support information, device programming or simulation file, or any other
+//related documentation or information provided by Altera or a megafunction
+//partner, remains with Altera, the megafunction partner, or their respective
+//licensors. No other licenses, including any licenses needed under any third
+//party's intellectual property, are provided herein.
+
+module mylpm_addsub (
+\tadd_sub,
+\tdataa,
+\tdatab,
+\tclock,
+\tresult);
+
+\tinput\t add_sub;
+\tinput\t[15:0] dataa;
+\tinput\t[15:0] datab;
+\tinput\t clock;
+\toutput\t[15:0] result;
+
+endmodule
+
+"
+"add32\tadd32_inst (
+\t.dataa ( dataa_sig ),
+\t.datab ( datab_sig ),
+\t.result ( result_sig )
+\t);
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+
+
+// DDC block
+
+module ddc(input clock,
+\t\t\tinput reset,
+\t\t\tinput enable,
+\t\t\tinput [3:0] rate1,
+\t\t\tinput [3:0] rate2,
+\t\t\toutput strobe,
+\t\t\tinput [31:0] freq,
+\t\t\tinput [15:0] i_in,
+\t\t\tinput [15:0] q_in,
+\t\t\toutput [15:0] i_out,
+\t\t\toutput [15:0] q_out
+\t\t\t);
+ parameter bw = 16;
+ parameter zw = 16;
+
+\twire [15:0] i_cordic_out, q_cordic_out;
+\twire [31:0] phase;
+
+\twire strobe1, strobe2;
+\treg [3:0] strobe_ctr1,strobe_ctr2;
+
+\talways @(posedge clock)
+\t\tif(reset | ~enable)
+\t\t\tstrobe_ctr2 <= #1 4'd0;
+\t\telse if(strobe2)
+\t\t\tstrobe_ctr2 <= #1 4'd0;
+\t\telse\t
+\t\t\tstrobe_ctr2 <= #1 strobe_ctr2 + 4'd1;
+\t\t\t\t
+\talways @(posedge clock)
+\t\tif(reset | ~enable)
+\t\t\tstrobe_ctr1 <= #1 4'd0;
+\t\telse if(strobe1)
+\t\t\tstrobe_ctr1 <= #1 4'd0;
+\t\telse if(strobe2)
+\t\t\tstrobe_ctr1 <= #1 strobe_ctr1 + 4'd1;
+\t\t\t\t
+
+\tassign strobe2 = enable & ( strobe_ctr2 == rate2 );
+\tassign strobe1 = strobe2 & ( strobe_ctr1 == rate1 );
+
+\tassign strobe = strobe1;
+
+\tfunction [2:0] log_ceil;
+\tinput [3:0] val;
+\t
+\t\tlog_ceil = val[3] ? 3'd4 : val[2] ? 3'd3 : val[1] ? 3'd2 : 3'd1;
+\tendfunction\t
+\t
+\twire [2:0] shift1 = log_ceil(rate1);
+\twire [2:0] shift2 = log_ceil(rate2);
+\t
+\tcordic #(.bitwidth(bw),.zwidth(zw),.stages(16))
+\t\tcordic(.clock(clock), .reset(reset), .enable(enable),
+\t\t\t.xi(i_in), .yi(q_in), .zi(phase[31:32-zw]),
+\t\t\t.xo(i_cordic_out), .yo(q_cordic_out), .zo() );
+\t\t
+\tcic_decim_2stage #(.bw(bw),.N(4))
+\t\tdecim_i(.clock(clock),.reset(reset),.enable(enable),
+\t\t\t.strobe1(1'b1),.strobe2(strobe2),.strobe3(strobe1),.shift1(shift2),.shift2(shift1),
+\t\t\t.signal_in(i_cordic_out),.signal_out(i_out));
+\t\t\t
+\tcic_decim_2stage #(.bw(bw),.N(4))
+\t\tdecim_q(.clock(clock),.reset(reset),.enable(enable),
+\t\t\t.strobe1(1'b1),.strobe2(strobe2),.strobe3(strobe1),.shift1(shift2),.shift2(shift1),
+\t\t\t.signal_in(q_cordic_out),.signal_out(q_out));
+\t
+\tphase_acc #(.resolution(32))
+\t\tnco (.clk(clock),.reset(reset),.enable(enable),
+\t\t\t.freq(freq),.phase(phase));
+\t\t
+endmodule
+"
+"// megafunction wizard: %FIFO%\r
+// GENERATION: STANDARD\r
+// VERSION: WM1.0\r
+// MODULE: dcfifo \r
+\r
+// ============================================================\r
+// File Name: fifo_4k_18.v\r
+// Megafunction Name(s):\r
+// \t\t\tdcfifo\r
+//\r
+// Simulation Library Files(s):\r
+// \t\t\taltera_mf\r
+// ============================================================\r
+// ************************************************************\r
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!\r
+//\r
+// 7.1 Build 178 06/25/2007 SP 1 SJ Web Edition\r
+// ************************************************************\r
+\r
+\r
+//Copyright (C) 1991-2007 Altera Corporation\r
+//Your use of Altera Corporation\'s design tools, logic functions \r
+//and other software and tools, and its AMPP partner logic \r
+//functions, and any output files from any of the foregoing \r
+//(including device programming or simulation files), and any \r
+//associated documentation or information are expressly subject \r
+//to the terms and conditions of the Altera Program License \r
+//Subscription Agreement, Altera MegaCore Function License \r
+//Agreement, or other applicable license agreement, including, \r
+//without limitation, that your use is for the sole purpose of \r
+//programming logic devices manufactured by Altera and sold by \r
+//Altera or its authorized distributors. Please refer to the \r
+//applicable agreement for further details.\r
+\r
+\r
+// synopsys translate_off\r
+`timescale 1 ps / 1 ps\r
+// synopsys translate_on\r
+module fifo_4k_18 (\r
+\taclr,\r
+\tdata,\r
+\trdclk,\r
+\trdreq,\r
+\twrclk,\r
+\twrreq,\r
+\tq,\r
+\trdempty,\r
+\trdusedw,\r
+\twrfull,\r
+\twrusedw);\r
+\r
+\tinput\t aclr;\r
+\tinput\t[17:0] data;\r
+\tinput\t rdclk;\r
+\tinput\t rdreq;\r
+\tinput\t wrclk;\r
+\tinput\t wrreq;\r
+\toutput\t[17:0] q;\r
+\toutput\t rdempty;\r
+\toutput\t[11:0] rdusedw;\r
+\toutput\t wrfull;\r
+\toutput\t[11:0] wrusedw;\r
+\r
+\twire sub_wire0;\r
+\twire [11:0] sub_wire1;\r
+\twire sub_wire2;\r
+\twire [17:0] sub_wire3;\r
+\twire [11:0] sub_wire4;\r
+\twire rdempty = sub_wire0;\r
+\twire [11:0] wrusedw = sub_wire1[11:0];\r
+\twire wrfull = sub_wire2;\r
+\twire [17:0] q = sub_wire3[17:0];\r
+\twire [11:0] rdusedw = sub_wire4[11:0];\r
+\r
+\tdcfifo\tdcfifo_component (\r
+\t\t\t\t.wrclk (wrclk),\r
+\t\t\t\t.rdreq (rdreq),\r
+\t\t\t\t.aclr (aclr),\r
+\t\t\t\t.rdclk (rdclk),\r
+\t\t\t\t.wrreq (wrreq),\r
+\t\t\t\t.data (data),\r
+\t\t\t\t.rdempty (sub_wire0),\r
+\t\t\t\t.wrusedw (sub_wire1),\r
+\t\t\t\t.wrfull (sub_wire2),\r
+\t\t\t\t.q (sub_wire3),\r
+\t\t\t\t.rdusedw (sub_wire4)\r
+\t\t\t\t// synopsys translate_off\r
+\t\t\t\t,\r
+\t\t\t\t.rdfull (),\r
+\t\t\t\t.wrempty ()\r
+\t\t\t\t// synopsys translate_on\r
+\t\t\t\t);\r
+\tdefparam\r
+\t\tdcfifo_component.add_ram_output_register = ""OFF"",\r
+\t\tdcfifo_component.clocks_are_synchronized = ""FALSE"",\r
+\t\tdcfifo_component.intended_device_family = ""Cyclone"",\r
+\t\tdcfifo_component.lpm_numwords = 4096,\r
+\t\tdcfifo_component.lpm_showahead = ""ON"",\r
+\t\tdcfifo_component.lpm_type = ""dcfifo"",\r
+\t\tdcfifo_component.lpm_width = 18,\r
+\t\tdcfifo_component.lpm_widthu = 12,\r
+\t\tdcfifo_component.overflow_checking = ""OFF"",\r
+\t\tdcfifo_component.underflow_checking = ""OFF"",\r
+\t\tdcfifo_component.use_eab = ""ON"";\r
+\r
+\r
+endmodule\r
+\r
+// ============================================================\r
+// CNX file retrieval info\r
+// ============================================================\r
+// Retrieval info: PRIVATE: AlmostEmpty NUMERIC ""0""\r
+// Retrieval info: PRIVATE: AlmostEmptyThr NUMERIC ""-1""\r
+// Retrieval info: PRIVATE: AlmostFull NUMERIC ""0""\r
+// Retrieval info: PRIVATE: AlmostFullThr NUMERIC ""-1""\r
+// Retrieval info: PRIVATE: CLOCKS_ARE_SYNCHRONIZED NUMERIC ""0""\r
+// Retrieval info: PRIVATE: Clock NUMERIC ""4""\r
+// Retrieval info: PRIVATE: Depth NUMERIC ""4096""\r
+// Retrieval info: PRIVATE: Empty NUMERIC ""1""\r
+// Retrieval info: PRIVATE: Full NUMERIC ""1""\r
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone""\r
+// Retrieval info: PRIVATE: LE_BasedFIFO NUMERIC ""0""\r
+// Retrieval info: PRIVATE: LegacyRREQ NUMERIC ""0""\r
+// Retrieval info: PRIVATE: MAX_DEPTH_BY_9 NUMERIC ""0""\r
+// Retrieval info: PRIVATE: OVERFLOW_CHECKING NUMERIC ""1""\r
+// Retrieval info: PRIVATE: Optimize NUMERIC ""2""\r
+// Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC ""0""\r
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING ""0""\r
+// Retrieval info: PRIVATE: UNDERFLOW_CHECKING NUMERIC ""1""\r
+// Retrieval info: PRIVATE: UsedW NUMERIC ""1""\r
+// Retrieval info: PRIVATE: Width NUMERIC ""18""\r
+// Retrieval info: PRIVATE: dc_aclr NUMERIC ""1""\r
+// Retrieval info: PRIVATE: diff_widths NUMERIC ""0""\r
+// Retrieval info: PRIVATE: msb_usedw NUMERIC ""0""\r
+// Retrieval info: PRIVATE: output_width NUMERIC ""18""\r
+// Retrieval info: PRIVATE: rsEmpty NUMERIC ""1""\r
+// Retrieval info: PRIVATE: rsFull NUMERIC ""0""\r
+// Retrieval info: PRIVATE: rsUsedW NUMERIC ""1""\r
+// Retrieval info: PRIVATE: sc_aclr NUMERIC ""0""\r
+// Retrieval info: PRIVATE: sc_sclr NUMERIC ""0""\r
+// Retrieval info: PRIVATE: wsEmpty NUMERIC ""0""\r
+// Retrieval info: PRIVATE: wsFull NUMERIC ""1""\r
+// Retrieval info: PRIVATE: wsUsedW NUMERIC ""1""\r
+// Retrieval info: CONSTANT: ADD_RAM_OUTPUT_REGISTER STRING ""OFF""\r
+// Retrieval info: CONSTANT: CLOCKS_ARE_SYNCHRONIZED STRING ""FALSE""\r
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone""\r
+// Retrieval info: CONSTANT: LPM_NUMWORDS NUMERIC ""4096""\r
+// Retrieval info: CONSTANT: LPM_SHOWAHEAD STRING ""ON""\r
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""dcfifo""\r
+// Retrieval info: CONSTANT: LPM_WIDTH NUMERIC ""18""\r
+// Retrieval info: CONSTANT: LPM_WIDTHU NUMERIC ""12""\r
+// Retrieval info: CONSTANT: OVERFLOW_CHECKING STRING ""OFF""\r
+// Retrieval info: CONSTANT: UNDERFLOW_CHECKING STRING ""OFF""\r
+// Retrieval info: CONSTANT: USE_EAB STRING ""ON""\r
+// Retrieval info: USED_PORT: aclr 0 0 0 0 INPUT GND aclr\r
+// Retrieval info: USED_PORT: data 0 0 18 0 INPUT NODEFVAL data[17..0]\r
+// Retrieval info: USED_PORT: q 0 0 18 0 OUTPUT NODEFVAL q[17..0]\r
+// Retrieval info: USED_PORT: rdclk 0 0 0 0 INPUT NODEFVAL rdclk\r
+// Retrieval info: USED_PORT: rdempty 0 0 0 0 OUTPUT NODEFVAL rdempty\r
+// Retrieval info: USED_PORT: rdreq 0 0 0 0 INPUT NODEFVAL rdreq\r
+// Retrieval info: USED_PORT: rdusedw 0 0 12 0 OUTPUT NODEFVAL rdusedw[11..0]\r
+// Retrieval info: USED_PORT: wrclk 0 0 0 0 INPUT NODEFVAL wrclk\r
+// Retrieval info: USED_PORT: wrfull 0 0 0 0 OUTPUT NODEFVAL wrfull\r
+// Retrieval info: USED_PORT: wrreq 0 0 0 0 INPUT NODEFVAL wrreq\r
+// Retrieval info: USED_PORT: wrusedw 0 0 12 0 OUTPUT NODEFVAL wrusedw[11..0]\r
+// Retrieval info: CONNECT: @data 0 0 18 0 data 0 0 18 0\r
+// Retrieval info: CONNECT: q 0 0 18 0 @q 0 0 18 0\r
+// Retrieval info: CONNECT: @wrreq 0 0 0 0 wrreq 0 0 0 0\r
+// Retrieval info: CONNECT: @rdreq 0 0 0 0 rdreq 0 0 0 0\r
+// Retrieval info: CONNECT: @rdclk 0 0 0 0 rdclk 0 0 0 0\r
+// Retrieval info: CONNECT: @wrclk 0 0 0 0 wrclk 0 0 0 0\r
+// Retrieval info: CONNECT: rdempty 0 0 0 0 @rdempty 0 0 0 0\r
+// Retrieval info: CONNECT: rdusedw 0 0 12 0 @rdusedw 0 0 12 0\r
+// Retrieval info: CONNECT: wrfull 0 0 0 0 @wrfull 0 0 0 0\r
+// Retrieval info: CONNECT: wrusedw 0 0 12 0 @wrusedw 0 0 12 0\r
+// Retrieval info: CONNECT: @aclr 0 0 0 0 aclr 0 0 0 0\r
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k_18.v TRUE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k_18.inc FALSE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k_18.cmp FALSE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k_18.bsf FALSE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k_18_inst.v FALSE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k_18_bb.v FALSE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k_18_waveforms.html FALSE\r
+// Retrieval info: GEN_FILE: TYPE_NORMAL fifo_4k_18_wave*.jpg FALSE\r
+// Retrieval info: LIB_FILE: altera_mf\r
+"
+"//Copyright (C) 1991-2003 Altera Corporation
+//Any megafunction design, and related netlist (encrypted or decrypted),
+//support information, device programming or simulation file, and any other
+//associated documentation or information provided by Altera or a partner
+//under Altera's Megafunction Partnership Program may be used only
+//to program PLD devices (but not masked PLD devices) from Altera. Any
+//other use of such megafunction design, netlist, support information,
+//device programming or simulation file, or any other related documentation
+//or information is prohibited for any other purpose, including, but not
+//limited to modification, reverse engineering, de-compiling, or use with
+//any other silicon devices, unless such use is explicitly licensed under
+//a separate agreement with Altera or a megafunction partner. Title to the
+//intellectual property, including patents, copyrights, trademarks, trade
+//secrets, or maskworks, embodied in any such megafunction design, netlist,
+//support information, device programming or simulation file, or any other
+//related documentation or information provided by Altera or a megafunction
+//partner, remains with Altera, the megafunction partner, or their respective
+//licensors. No other licenses, including any licenses needed under any third
+//party's intellectual property, are provided herein.
+
+module sub32 (
+\tdataa,
+\tdatab,
+\tclock,
+\taclr,
+\tclken,
+\tresult)/* synthesis synthesis_clearbox = 1 */;
+
+\tinput\t[31:0] dataa;
+\tinput\t[31:0] datab;
+\tinput\t clock;
+\tinput\t aclr;
+\tinput\t clken;
+\toutput\t[31:0] result;
+
+endmodule
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+// Tasks
+
+/////////////////////////////////////////////////
+// USB interface
+
+task initialize_usb;
+begin
+\tOE = 0;WE = 0;RD = 0;
+\tusbdatareg <= 16'h0;
+end
+endtask
+
+task write_from_usb;
+begin
+\ttb_oe <= 1'b1;
+\t@(posedge usbclk);
+\tusbdatareg <= #1 $random % 65536;
+\tWE <= #1 1'b1;
+\t@(posedge usbclk)
+\tWE <= #1 1'b0;
+\ttb_oe <= #1 1'b0;
+end
+endtask
+
+task burst_usb_write;
+ input [31:0] repeat_count;
+
+ begin
+\t tb_oe <= 1'b1;
+\t repeat(repeat_count)
+\t begin
+\t @(posedge usbclk)
+\t\tusbdatareg <= #1 usbdatareg + 1;\t //$random % 65536;
+\t WE <= #1 1'b1;
+\t end
+\t @(posedge usbclk)
+\t WE <= #1 1'b0;
+\t tb_oe <= 1'b0;
+ end
+endtask // burst_usb_write
+
+
+task read_from_usb;
+begin
+\t@(posedge usbclk);
+\tRD <= #1 1'b1;
+\t@(posedge usbclk);
+\tRD <= #1 1'b0;
+\tOE <= #1 1'b1;
+\t@(posedge usbclk);
+\tOE <= #1 1'b0;
+end
+endtask
+
+task burst_usb_read;
+ input [31:0] repeat_count;
+ begin
+\t while (~have_packet_rdy) begin
+\t @(posedge usbclk);
+\t end
+\t
+\t @(posedge usbclk)
+\t RD <= #1 1'b1;
+\t repeat(repeat_count)
+\t begin
+\t @(posedge usbclk)
+\t\tOE <= #1 1'b1;
+\t end
+\t RD <= #1 1'b0;
+\t @(posedge usbclk);
+\t OE <= #1 1'b0;
+ end
+endtask // burst_usb_read
+
+/////////////////////////////////////////////////
+// TX and RX enable
+
+//////////////////////////////////////////////////
+// Set up control bus
+
+`define ch1in_freq 0
+`define ch2in_freq 1
+`define ch3in_freq 2
+`define ch4in_freq 3
+`define ch1out_freq 4
+`define ch2out_freq 5
+`define ch3out_freq 6
+`define ch4out_freq 7
+`define rates 8
+`define misc 9
+
+ task send_config_word;
+ input [7:0] addr;
+ input [31:0] data;
+ integer i;
+
+ begin
+\t #10 serenable = 1;
+\t for(i=7;i>=0;i=i-1)
+\t begin
+\t #10 serdata = addr[i];
+\t #10 serclk = 0;
+\t #10 serclk = 1;
+\t #10 serclk = 0;
+\t end
+\t for(i=31;i>=0;i=i-1)
+\t begin
+\t #10 serdata = data[i];
+\t #10 serclk = 0;
+\t #10 serclk = 1;
+\t #10 serclk = 0;
+\t end
+\t #10 serenable = 0;
+\t //\t#10 serload = 0;
+\t //\t#10 serload = 1;
+\t #10 serclk = 1;
+\t #10 serclk = 0;
+\t //#10 serload = 0;
+ end
+ endtask // send_config_word
+
+
+/////////////////////////////////////////////////////////
+
+"
+"accum32\taccum32_inst (
+\t.data ( data_sig ),
+\t.clock ( clock_sig ),
+\t.clken ( clken_sig ),
+\t.aclr ( aclr_sig ),
+\t.result ( result_sig )
+\t);
+"
+"sub32\tsub32_inst (
+\t.dataa ( dataa_sig ),
+\t.datab ( datab_sig ),
+\t.clock ( clock_sig ),
+\t.aclr ( aclr_sig ),
+\t.clken ( clken_sig ),
+\t.result ( result_sig )
+\t);
+"
+"//Copyright (C) 1991-2003 Altera Corporation
+//Any megafunction design, and related netlist (encrypted or decrypted),
+//support information, device programming or simulation file, and any other
+//associated documentation or information provided by Altera or a partner
+//under Altera's Megafunction Partnership Program may be used only
+//to program PLD devices (but not masked PLD devices) from Altera. Any
+//other use of such megafunction design, netlist, support information,
+//device programming or simulation file, or any other related documentation
+//or information is prohibited for any other purpose, including, but not
+//limited to modification, reverse engineering, de-compiling, or use with
+//any other silicon devices, unless such use is explicitly licensed under
+//a separate agreement with Altera or a megafunction partner. Title to the
+//intellectual property, including patents, copyrights, trademarks, trade
+//secrets, or maskworks, embodied in any such megafunction design, netlist,
+//support information, device programming or simulation file, or any other
+//related documentation or information provided by Altera or a megafunction
+//partner, remains with Altera, the megafunction partner, or their respective
+//licensors. No other licenses, including any licenses needed under any third
+//party's intellectual property, are provided herein.
+
+module accum32 (
+\tdata,
+\tclock,
+\tclken,
+\taclr,
+\tresult)/* synthesis synthesis_clearbox = 1 */;
+
+\tinput\t[31:0] data;
+\tinput\t clock;
+\tinput\t clken;
+\tinput\t aclr;
+\toutput\t[31:0] result;
+
+endmodule
+
+"
+"//Copyright (C) 1991-2003 Altera Corporation
+//Any megafunction design, and related netlist (encrypted or decrypted),
+//support information, device programming or simulation file, and any other
+//associated documentation or information provided by Altera or a partner
+//under Altera's Megafunction Partnership Program may be used only
+//to program PLD devices (but not masked PLD devices) from Altera. Any
+//other use of such megafunction design, netlist, support information,
+//device programming or simulation file, or any other related documentation
+//or information is prohibited for any other purpose, including, but not
+//limited to modification, reverse engineering, de-compiling, or use with
+//any other silicon devices, unless such use is explicitly licensed under
+//a separate agreement with Altera or a megafunction partner. Title to the
+//intellectual property, including patents, copyrights, trademarks, trade
+//secrets, or maskworks, embodied in any such megafunction design, netlist,
+//support information, device programming or simulation file, or any other
+//related documentation or information provided by Altera or a megafunction
+//partner, remains with Altera, the megafunction partner, or their respective
+//licensors. No other licenses, including any licenses needed under any third
+//party's intellectual property, are provided herein.
+
+module addsub16 (
+\tadd_sub,
+\tdataa,
+\tdatab,
+\tclock,
+\taclr,
+\tclken,
+\tresult)/* synthesis synthesis_clearbox = 1 */;
+
+\tinput\t add_sub;
+\tinput\t[15:0] dataa;
+\tinput\t[15:0] datab;
+\tinput\t clock;
+\tinput\t aclr;
+\tinput\t clken;
+\toutput\t[15:0] result;
+
+endmodule
+
+"
+"// -*- verilog -*-
+//
+// USRP - Universal Software Radio Peripheral
+//
+// Copyright (C) 2003 Matt Ettus
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
+//
+
+
+module cic_interp(clock,reset,enable,rate,strobe_in,strobe_out,signal_in,signal_out);
+ parameter bw = 16;
+ parameter N = 4;
+ parameter log2_of_max_rate = 7;
+ parameter maxbitgain = (N-1)*log2_of_max_rate;
+
+ input clock;
+ input reset;
+ input enable;
+ input [7:0] rate;
+ input strobe_in,strobe_out;\t
+ input [bw-1:0] signal_in;
+ wire [bw-1:0] \tsignal_in;
+ output [bw-1:0] signal_out;
+ wire [bw-1:0] signal_out;
+
+ wire [bw+maxbitgain-1:0] signal_in_ext;
+ reg [bw+maxbitgain-1:0] integrator [0:N-1];
+ reg [bw+maxbitgain-1:0] differentiator [0:N-1];
+ reg [bw+maxbitgain-1:0] pipeline [0:N-1];
+
+ integer i;
+
+ sign_extend #(bw,bw+maxbitgain)
+ ext_input (.in(signal_in),.out(signal_in_ext));
+
+ //FIXME Note that this section has pipe and diff reversed
+ // It still works, but is confusing
+ always @(posedge clock)
+ if(reset)
+ for(i=0;i NAND_ALLOWED_LOG_BLOCKS) \r
+ err_invalid_erase_block <= 1; \r
+ else\r
+ state <= ST_ERASEBLOCK_1; \r
+ //state <= state_return;\r
+ end\r
+ end\r
+ ST_ERASEBLOCK_1: begin\r
+ op_page_do <= 1;\r
+ op_page_cmd <= OP_PAGE_BLOCKERASE;\r
+ op_page_num <= erase_block * NAND_PAGE_PER_BLOCK;\r
+ if(op_page_done & ~op_page_done_1) begin\r
+ op_page_do <= 0;\r
+ state <= ST_ERASEBLOCK_2;\r
+ // but wait, there\'s error!\r
+ if(op_page_status) begin\r
+ // retry! assume FTL_PHYSICAL is going to update the bad block table\r
+ state <= ST_ERASEBLOCK_0;\r
+ end\r
+ end\r
+ end\r
+ ST_ERASEBLOCK_2: begin\r
+ state <= state_return;\r
+ end\r
+ \r
+ //\r
+ // ST_READBLOCK: read a block (64 pages)\r
+ //\r
+ ST_READBLOCK_0: begin\r
+ if(~op_page_ack) begin\r
+ // open to accept new commands\r
+ block_page_idx <= 0;\r
+ state <= ST_READBLOCK_1;\r
+ end\r
+ end\r
+ ST_READBLOCK_1: begin\r
+ op_page_do <= 1;\r
+ // if this block was empty, do not read in garbage/FF data from real device\r
+ // instead just tell FTL_PHYSICAL to fill the page with 00\'s\r
+ op_page_cmd <= read_block_empty ? OP_PAGE_READ_EMPTY : OP_PAGE_READ;\r
+ op_page_num <= read_block * NAND_PAGE_PER_BLOCK + block_page_idx;\r
+ op_page_bram <= block_page_idx;\r
+ if(op_page_done & ~op_page_done_1) begin\r
+ op_page_do <= 0;\r
+ state <= ST_READBLOCK_2;\r
+ end\r
+ end\r
+ ST_READBLOCK_2: begin \r
+ if(~op_page_ack) begin\r
+ state <= ST_READBLOCK_1;\r
+ block_page_idx <= block_page_idx + 1\'b1;\r
+ if(block_page_idx == 63) begin\r
+ $display(""FTL_LOGICAL: read block %d, empty=%d"", read_block, read_block_empty);\r
+ state <= state_return;\r
+ end\r
+ end\r
+ end\r
+ \r
+ //\r
+ // ST_WRITEBLOCK: write a block (64 pages), abort if the block turned bad\r
+ //\r
+ ST_WRITEBLOCK_0: begin\r
+ if(~op_page_ack) begin\r
+ // open to accept new commands\r
+ block_page_idx <= 0;\r
+ state <= ST_WRITEBLOCK_1;\r
+ end\r
+ end\r
+ ST_WRITEBLOCK_1: begin\r
+ op_page_do <= 1;\r
+ op_page_cmd <= OP_PAGE_WRITE;\r
+ op_page_num <= write_block * NAND_PAGE_PER_BLOCK + block_page_idx;\r
+ op_page_bram <= block_page_idx;\r
+ if(op_page_done & ~op_page_done_1) begin\r
+ op_page_do <= 0;\r
+ state <= ST_WRITEBLOCK_2;\r
+ // but wait, there\'s error!\r
+ if(op_page_status) begin\r
+ // can\'t do anything here, up to the caller to handle it\r
+ $display(""FTL_LOGICAL: write block %d failed"", write_block);\r
+ state <= state_return;\r
+ end\r
+ end\r
+ end\r
+ ST_WRITEBLOCK_2: begin\r
+ if(~op_page_ack) begin\r
+ state <= ST_WRITEBLOCK_1;\r
+ block_page_idx <= block_page_idx + 1\'b1;\r
+ if(block_page_idx == 63) begin\r
+ $display(""FTL_LOGICAL: wrote block %d"", write_block);\r
+ state <= state_return;\r
+ end\r
+ end\r
+ end\r
+ \r
+ endcase\r
+ \r
+ if(~reset_n) begin\r
+ state <= ST_RESET;\r
+ end \r
+end\r
+\r
+\r
+ftl_free_fifo ilfifo(\r
+ .clk_50 ( clk_50 ),\r
+ .reset_n ( reset_n ),\r
+\r
+ .fifo_data_in ( fifo_data_in ),\r
+ .fifo_data_wr ( fifo_data_wr ),\r
+ .fifo_data_out ( fifo_data_out ),\r
+ .fifo_data_valid ( fifo_data_valid ),\r
+ .fifo_data_rd ( fifo_data_rd ),\r
+ .fifo_empty ( fifo_empty )\r
+);\r
+\r
+// remap table 32 + 10 + 1\r
+ftl_bram_block_dp #(43, 10) ilrbram (\r
+ .a_clk ( clk_50 ),\r
+ .a_wr ( bram_remap_wren ),\r
+ .a_addr ( bram_remap_addr ),\r
+ .a_din ( bram_remap_data ),\r
+ .a_dout ( bram_remap_q ),\r
+ .b_clk ( clk_50 ),\r
+ .b_wr ( 1\'b0 ),\r
+ .b_addr ( \'h0 ),\r
+ .b_din ( \'h0 ),\r
+ .b_dout ( )\r
+);\r
+\r
+endmodule\r
+"
+"/*\r
+ Copyright 2015, Google Inc.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the ""License"");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an ""AS IS"" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+module sd_wishbone (\r
+ input wire clk_50,\r
+ input wire reset_n,\r
+\r
+ // dma bus to MGR\r
+ input wire ext_read_act,\r
+ output reg ext_read_go,\r
+ input wire [31:0] ext_read_addr,\r
+ input wire ext_read_stop,\r
+\r
+ input wire ext_write_act,\r
+ output reg ext_write_done,\r
+ input wire [31:0] ext_write_addr,\r
+ \r
+ output wire bram_rd_ext_clk,\r
+ output reg [6:0] bram_rd_ext_addr,\r
+ output reg bram_rd_ext_wren,\r
+ output reg [31:0] bram_rd_ext_data,\r
+ input wire [31:0] bram_rd_ext_q,\r
+\r
+ output wire bram_wr_ext_clk,\r
+ output reg [6:0] bram_wr_ext_addr,\r
+ output wire bram_wr_ext_wren,\r
+ output wire [31:0] bram_wr_ext_data,\r
+ input wire [31:0] bram_wr_ext_q,\r
+\r
+ // wishbone bus\r
+ output wire wbm_clk_o, // clock - bus clock\r
+ output reg [31:0] wbm_adr_o, // addr - bus address\r
+ input wire [31:0] wbm_dat_i, // data - write data input\r
+ output wire [31:0] wbm_dat_o, // data - write data output\r
+ output reg [3:0] wbm_sel_o, // select - 8-bit enable for data bus\r
+ output reg wbm_cyc_o, // cycle - valid bus cycle is in progress\r
+ output reg wbm_stb_o, // strobe - slave is selected\r
+ output reg wbm_we_o, // write - bus cycle is in write mode\r
+ input wire wbm_ack_i, // ack - end of a normal bus cycle\r
+ output reg [2:0] wbm_cti_o, // cti - cycle type identifier\r
+ output reg [1:0] wbm_bte_o // bte - burst type\r
+);\r
+\r
+\r
+assign wbm_clk_o = clk_50;\r
+assign wbm_dat_o = bram_wr_ext_q;\r
+\r
+assign bram_rd_ext_clk = wbm_clk_o;\r
+assign bram_wr_ext_clk = wbm_clk_o;\r
+\r
+reg [4:0] state;\r
+parameter [4:0] ST_RESET = \'d0,\r
+ ST_IDLE = \'d4,\r
+ ST_WB_READ_0 = \'d8,\r
+ ST_WB_READ_1 = \'d9,\r
+ ST_WB_READ_2 = \'d10,\r
+ ST_WB_READ_3 = \'d11,\r
+ ST_WB_READ_4 = \'d12,\r
+ ST_WB_WRITE_0 = \'d13,\r
+ ST_WB_WRITE_1 = \'d14,\r
+ ST_WB_WRITE_2 = \'d15,\r
+ ST_WB_WRITE_3 = \'d16,\r
+ ST_WB_WRITE_4 = \'d17,\r
+ ST_LAST = \'d31;\r
+\r
+wire [6:0] bram_rd_ext_addr_next = bram_rd_ext_addr + 1\'b1;\r
+reg [15:0] bytes_done;\r
+ \r
+reg [31:0] ext_read_addr_latch;\r
+reg [31:0] ext_write_addr_latch;\r
+ \r
+reg ext_read_act_last;\r
+reg ext_write_act_last;\r
+reg wbm_ack_i_last;\r
+ \r
+ \r
+wire reset_s;\r
+synch_3 a(reset_n, reset_s, clk_50);\r
+\r
+always @(posedge wbm_clk_o) begin\r
+ ext_read_act_last <= ext_read_act;\r
+ ext_write_act_last <= ext_write_act;\r
+ wbm_ack_i_last <= wbm_ack_i;\r
+ \r
+ wbm_sel_o <= 4\'b1111;\r
+ wbm_cyc_o <= 0;\r
+ wbm_stb_o <= 0;\r
+ wbm_we_o <= 0;\r
+ wbm_cti_o <= 3\'b000;\r
+ wbm_bte_o <= 2\'b00;\r
+ \r
+ bram_rd_ext_wren <= 0;\r
+ ext_read_go <= 0;\r
+ \r
+ case(state)\r
+ ST_RESET: begin\r
+ state <= ST_IDLE;\r
+ end\r
+ ST_IDLE: begin\r
+ if(~ext_read_act_last & ext_read_act) begin\r
+ ext_read_addr_latch <= ext_read_addr;\r
+ bytes_done <= 0;\r
+ bram_rd_ext_addr <= -1;\r
+ state <= ST_WB_READ_0;\r
+ end\r
+ if(~ext_write_act_last & ext_write_act) begin\r
+ ext_write_addr_latch <= ext_write_addr;\r
+ bytes_done <= 0;\r
+ bram_wr_ext_addr <= 0;\r
+ ext_write_done <= 0;\r
+ state <= ST_WB_WRITE_0;\r
+ end\r
+ end\r
+ ST_WB_READ_0: begin\r
+ wbm_cyc_o <= 1;\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= ext_read_addr_latch * 512 + bram_rd_ext_addr_next * 4;\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ // latch incoming data from wishbone slave\r
+ bram_rd_ext_addr <= bram_rd_ext_addr_next;\r
+ bram_rd_ext_data <= wbm_dat_i;\r
+ bram_rd_ext_wren <= 1;\r
+ wbm_stb_o <= 0;\r
+ \r
+ bytes_done <= bytes_done + 16\'h4;\r
+ if(bytes_done + 16\'h4 == 512) begin\r
+ // done\r
+ state <= ST_WB_READ_1;\r
+ end\r
+ end \r
+ end\r
+ ST_WB_READ_1: begin \r
+ // signal MGR that bram is filled and wait for completion\r
+ ext_read_go <= 1;\r
+ if(ext_read_stop) state <= ST_IDLE;\r
+ end\r
+ \r
+ ST_WB_WRITE_0: begin\r
+ wbm_cyc_o <= 1;\r
+ wbm_we_o <= 1;\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= ext_write_addr_latch * 512 + bram_wr_ext_addr * 4;\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ // increment bram read pointer\r
+ bram_wr_ext_addr <= bram_wr_ext_addr + 1;\r
+ wbm_stb_o <= 0;\r
+ \r
+ bytes_done <= bytes_done + 16\'h4;\r
+ if(bytes_done + 16\'h4 == 512) begin\r
+ // done\r
+ state <= ST_WB_WRITE_1;\r
+ end\r
+ end \r
+ end\r
+ ST_WB_WRITE_1: begin \r
+ // signal MGR that bram was read\r
+ ext_write_done <= 1;\r
+ state <= ST_IDLE;\r
+ end\r
+ endcase\r
+ \r
+ if(~reset_s) begin\r
+ state <= ST_RESET;\r
+ end\r
+end\r
+\r
+endmodule\r
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 22:19:37 02/11/2015
+// Design Name: aes_ks
+// Project Name: crypto_aes
+// Target Device:
+// Tool versions:
+// Description:
+//
+// Verilog Test Fixture created by ISE for module: aes_ks
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+////////////////////////////////////////////////////////////////////////////////
+
+module aes_ks_tb;
+
+\t// Inputs
+\treg clk;
+\treg load_i;
+\treg en_i;
+\treg [1:0] size_i;
+\treg [255:0] key_i;
+
+\t// Outputs
+\twire [127:0] ks_o;
+\t
+\treg [3:0] i;
+\twire [127:0] test_val;
+\treg [60 * 32 - 1:0] test_data;
+\t
+\t// Instantiate the Unit Under Test (UUT)
+\taes_ks uut (
+\t\t.clk(clk),
+\t\t.load_i(load_i),
+\t\t.en_i(en_i),
+\t\t.size_i(size_i),
+\t\t.key_i(key_i),
+\t\t.ks_o(ks_o)
+\t);
+
+\tinitial begin
+\t\t// Initialize Inputs
+\t\tclk = 0;
+\t\tload_i = 0;
+\t\tsize_i = 0;
+\t\tkey_i = 0;
+
+\t\t// Wait 100 ns for global reset to finish
+\t\t#100;
+
+\t\t// Add stimulus here
+\t\tkey_i[255:128] = 128\'h2b_7e_15_16_28_ae_d2_a6_ab_f7_15_88_09_cf_4f_3c;
+\t\ttest_data = {
+\t\t\t32\'h2b7e1516, 32\'h28aed2a6, 32\'habf71588, 32\'h09cf4f3c, /* 00 */
+\t\t\t32\'ha0fafe17, 32\'h88542cb1, 32\'h23a33939, 32\'h2a6c7605, /* 04 */
+\t\t\t32\'hf2c295f2, 32\'h7a96b943, 32\'h5935807a, 32\'h7359f67f, /* 08 */
+\t\t\t32\'h3d80477d, 32\'h4716fe3e, 32\'h1e237e44, 32\'h6d7a883b, /* 0c */
+\t\t\t32\'hef44a541, 32\'ha8525b7f, 32\'hb671253b, 32\'hdb0bad00, /* 10 */
+\t\t\t32\'hd4d1c6f8, 32\'h7c839d87, 32\'hcaf2b8bc, 32\'h11f915bc, /* 14 */
+\t\t\t32\'h6d88a37a, 32\'h110b3efd, 32\'hdbf98641, 32\'hca0093fd, /* 18 */
+\t\t\t32\'h4e54f70e, 32\'h5f5fc9f3, 32\'h84a64fb2, 32\'h4ea6dc4f, /* 1c */
+\t\t\t32\'head27321, 32\'hb58dbad2, 32\'h312bf560, 32\'h7f8d292f, /* 20 */
+\t\t\t32\'hac7766f3, 32\'h19fadc21, 32\'h28d12941, 32\'h575c006e, /* 24 */
+\t\t\t32\'hd014f9a8, 32\'hc9ee2589, 32\'he13f0cc8, 32\'hb6630ca6, /* 28 */
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000000, /* 2c */
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000000, /* 30 */
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000000, /* 34 */
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000000 /* 38 */
+\t\t};
+\t\tsize_i = 2\'b00;
+\t\tload_i = 1;
+\t\ten_i = 1;
+\t\t
+\t\t#20;
+\t\tload_i = 0;
+\t\t\t
+\t\tfor(i = 0; i < 11; i = i + 1)
+\t\tbegin
+\t\t\t$display(""i: %d test_val: %h ks_o: %h"", i, test_val, ks_o);
+\t\t\tif(test_val != ks_o)
+\t\t\tbegin
+\t\t\t\t$display(""AES 128 mismatch step %d"", i);
+\t\t\t\t$stop;
+\t\t\tend
+\t\t\ttest_data = test_data << 128;
+\t\t\t#20;
+\t\tend
+\t\t
+\t\tkey_i[255:64] = 192\'h8e_73_b0_f7_da_0e_64_52_c8_10_f3_2b_80_90_79_e5_62_f8_ea_d2_52_2c_6b_7b;
+\t\ttest_data = {
+\t\t\t32\'h8e73b0f7, 32\'hda0e6452, 32\'hc810f32b, 32\'h809079e5, /* 00 */
+\t\t\t32\'h62f8ead2, 32\'h522c6b7b, 32\'hfe0c91f7, 32\'h2402f5a5, /* 04 */
+\t\t\t32\'hec12068e, 32\'h6c827f6b, 32\'h0e7a95b9, 32\'h5c56fec2, /* 08 */
+\t\t\t32\'h4db7b4bd, 32\'h69b54118, 32\'h85a74796, 32\'he92538fd, /* 0c */
+\t\t\t32\'he75fad44, 32\'hbb095386, 32\'h485af057, 32\'h21efb14f, /* 10 */
+\t\t\t32\'ha448f6d9, 32\'h4d6dce24, 32\'haa326360, 32\'h113b30e6, /* 14 */
+\t\t\t32\'ha25e7ed5, 32\'h83b1cf9a, 32\'h27f93943, 32\'h6a94f767, /* 18 */
+\t\t\t32\'hc0a69407, 32\'hd19da4e1, 32\'hec1786eb, 32\'h6fa64971, /* 1c */
+\t\t\t32\'h485f7032, 32\'h22cb8755, 32\'he26d1352, 32\'h33f0b7b3, /* 20 */
+\t\t\t32\'h40beeb28, 32\'h2f18a259, 32\'h6747d26b, 32\'h458c553e, /* 24 */
+\t\t\t32\'ha7e1466c, 32\'h9411f1df, 32\'h821f750a, 32\'had07d753, /* 28 */
+\t\t\t32\'hca400538, 32\'h8fcc5006, 32\'h282d166a, 32\'hbc3ce7b5, /* 2c */
+\t\t\t32\'he98ba06f, 32\'h448c773c, 32\'h8ecc7204, 32\'h01002202, /* 30 */
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000000, /* 34 */
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000000 /* 38 */
+\t\t};
+\t\tsize_i = 2\'b01;
+\t\tload_i = 1;
+\t\t#20;
+\t\tload_i = 0;
+\t\t\t
+\t\tfor(i = 0; i < 13; i = i + 1)
+\t\tbegin
+\t\t\t$display(""i: %d test_val: %h ks_o: %h"", i, test_val, ks_o);
+\t\t\tif(test_val != ks_o)
+\t\t\tbegin
+\t\t\t\t$display(""AES 192 mismatch step %d"", i);
+\t\t\t\t$stop;
+\t\t\tend
+\t\t\ttest_data = test_data << 128;
+\t\t\t#20;
+\t\tend
+
+\t\tkey_i[255:0] = 256\'h60_3d_eb_10_15_ca_71_be_2b_73_ae_f0_85_7d_77_81_1f_35_2c_07_3b_61_08_d7_2d_98_10_a3_09_14_df_f4;
+\t\ttest_data = {
+\t\t\t32\'h603deb10, 32\'h15ca71be, 32\'h2b73aef0, 32\'h857d7781, /* 00 */
+\t\t\t32\'h1f352c07, 32\'h3b6108d7, 32\'h2d9810a3, 32\'h0914dff4, /* 04 */
+\t\t\t32\'h9ba35411, 32\'h8e6925af, 32\'ha51a8b5f, 32\'h2067fcde, /* 08 */
+\t\t\t32\'ha8b09c1a, 32\'h93d194cd, 32\'hbe49846e, 32\'hb75d5b9a, /* 0c */
+\t\t\t32\'hd59aecb8, 32\'h5bf3c917, 32\'hfee94248, 32\'hde8ebe96, /* 10 */
+\t\t\t32\'hb5a9328a, 32\'h2678a647, 32\'h98312229, 32\'h2f6c79b3, /* 14 */
+\t\t\t32\'h812c81ad, 32\'hdadf48ba, 32\'h24360af2, 32\'hfab8b464, /* 18 */
+\t\t\t32\'h98c5bfc9, 32\'hbebd198e, 32\'h268c3ba7, 32\'h09e04214, /* 1c */
+\t\t\t32\'h68007bac, 32\'hb2df3316, 32\'h96e939e4, 32\'h6c518d80, /* 20 */
+\t\t\t32\'hc814e204, 32\'h76a9fb8a, 32\'h5025c02d, 32\'h59c58239, /* 24 */
+\t\t\t32\'hde136967, 32\'h6ccc5a71, 32\'hfa256395, 32\'h9674ee15, /* 28 */
+\t\t\t32\'h5886ca5d, 32\'h2e2f31d7, 32\'h7e0af1fa, 32\'h27cf73c3, /* 2c */
+\t\t\t32\'h749c47ab, 32\'h18501dda, 32\'he2757e4f, 32\'h7401905a, /* 30 */
+\t\t\t32\'hcafaaae3, 32\'he4d59b34, 32\'h9adf6ace, 32\'hbd10190d, /* 34 */
+\t\t\t32\'hfe4890d1, 32\'he6188d0b, 32\'h046df344, 32\'h706c631e /* 38 */
+\t\t};
+\t\tsize_i = 2\'b10;
+\t\tload_i = 1;
+\t\t#20;
+\t\tload_i = 0;
+\t\t\t
+\t\tfor(i = 0; i < 15; i = i + 1)
+\t\tbegin
+\t\t\t$display(""i: %d test_val: %h ks_o: %h"", i, test_val, ks_o);
+\t\t\tif(test_val != ks_o)
+\t\t\tbegin
+\t\t\t\t$display(""AES 256 mismatch step %d"", i);
+\t\t\t\t$stop;
+\t\t\tend
+\t\t\ttest_data = test_data << 128;
+\t\t\t#20;
+\t\tend
+\t\t
+\t\t$display(""AES key schedule passed"");
+\t\t$finish;
+\tend
+
+always #10 clk <= ~clk;
+assign test_val = test_data[32 * 60 - 1:32 * 60 - 128];
+
+endmodule
+
+"
+"/*\r
+ Copyright 2015, Google Inc.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the ""License"");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an ""AS IS"" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+module sd_bram_block_dp #(\r
+ parameter DATA = 32,\r
+ parameter ADDR = 7\r
+) (\r
+ input wire a_clk,\r
+ input wire a_wr,\r
+ input wire [ADDR-1:0] a_addr,\r
+ input wire [DATA-1:0] a_din,\r
+ output reg [DATA-1:0] a_dout,\r
+ \r
+ input wire b_clk,\r
+ input wire b_wr,\r
+ input wire [ADDR-1:0] b_addr,\r
+ input wire [DATA-1:0] b_din,\r
+ output reg [DATA-1:0] b_dout\r
+);\r
+\r
+reg [DATA-1:0] mem [(2**ADDR)-1:0];\r
+ \r
+always @(posedge a_clk) begin\r
+ if(a_wr) begin\r
+ a_dout <= a_din;\r
+ mem[a_addr] <= a_din;\r
+ end else\r
+ a_dout <= mem[a_addr];\r
+end\r
+ \r
+always @(posedge b_clk) begin\r
+ if(b_wr) begin\r
+ b_dout <= b_din;\r
+ mem[b_addr] <= b_din;\r
+ end else\r
+ b_dout <= mem[b_addr];\r
+end\r
+\r
+endmodule\r
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 13:54:01 02/02/2015
+// Design Name:
+// Module Name: sha256_K
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module sha256_K (
+\tinput [5:0] step_i,
+\toutput reg [31:0] K_o
+);
+
+always @*
+begin
+\tcase(step_i)
+\t0: K_o = 32\'h428a2f98;
+\t1: K_o = 32\'h71374491;
+\t2: K_o = 32\'hb5c0fbcf;
+\t3: K_o = 32\'he9b5dba5;
+\t4: K_o = 32\'h3956c25b;
+\t5: K_o = 32\'h59f111f1;
+\t6: K_o = 32\'h923f82a4;
+\t7: K_o = 32\'hab1c5ed5;
+\t8: K_o = 32\'hd807aa98;
+\t9: K_o = 32\'h12835b01;
+\t10: K_o = 32\'h243185be;
+\t11: K_o = 32\'h550c7dc3;
+\t12: K_o = 32\'h72be5d74;
+\t13: K_o = 32\'h80deb1fe;
+\t14: K_o = 32\'h9bdc06a7;
+\t15: K_o = 32\'hc19bf174;
+\t16: K_o = 32\'he49b69c1;
+\t17: K_o = 32\'hefbe4786;
+\t18: K_o = 32\'h0fc19dc6;
+\t19: K_o = 32\'h240ca1cc;
+\t20: K_o = 32\'h2de92c6f;
+\t21: K_o = 32\'h4a7484aa;
+\t22: K_o = 32\'h5cb0a9dc;
+\t23: K_o = 32\'h76f988da;
+\t24: K_o = 32\'h983e5152;
+\t25: K_o = 32\'ha831c66d;
+\t26: K_o = 32\'hb00327c8;
+\t27: K_o = 32\'hbf597fc7;
+\t28: K_o = 32\'hc6e00bf3;
+\t29: K_o = 32\'hd5a79147;
+\t30: K_o = 32\'h06ca6351;
+\t31: K_o = 32\'h14292967;
+\t32: K_o = 32\'h27b70a85;
+\t33: K_o = 32\'h2e1b2138;
+\t34: K_o = 32\'h4d2c6dfc;
+\t35: K_o = 32\'h53380d13;
+\t36: K_o = 32\'h650a7354;
+\t37: K_o = 32\'h766a0abb;
+\t38: K_o = 32\'h81c2c92e;
+\t39: K_o = 32\'h92722c85;
+\t40: K_o = 32\'ha2bfe8a1;
+\t41: K_o = 32\'ha81a664b;
+\t42: K_o = 32\'hc24b8b70;
+\t43: K_o = 32\'hc76c51a3;
+\t44: K_o = 32\'hd192e819;
+\t45: K_o = 32\'hd6990624;
+\t46: K_o = 32\'hf40e3585;
+\t47: K_o = 32\'h106aa070;
+\t48: K_o = 32\'h19a4c116;
+\t49: K_o = 32\'h1e376c08;
+\t50: K_o = 32\'h2748774c;
+\t51: K_o = 32\'h34b0bcb5;
+\t52: K_o = 32\'h391c0cb3;
+\t53: K_o = 32\'h4ed8aa4a;
+\t54: K_o = 32\'h5b9cca4f;
+\t55: K_o = 32\'h682e6ff3;
+\t56: K_o = 32\'h748f82ee;
+\t57: K_o = 32\'h78a5636f;
+\t58: K_o = 32\'h84c87814;
+\t59: K_o = 32\'h8cc70208;
+\t60: K_o = 32\'h90befffa;
+\t61: K_o = 32\'ha4506ceb;
+\t62: K_o = 32\'hbef9a3f7;
+\t63: K_o = 32\'hc67178f2;
+\tendcase
+end
+
+endmodule
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 21:51:42 02/11/2015
+// Design Name:
+// Module Name: aes_ks
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module aes_ks (
+\tinput clk,
+\tinput load_i,
+\tinput en_i,
+\tinput [1:0] size_i,
+\tinput [255:0] key_i,
+\toutput reg [127:0] ks_o
+);
+
+localparam AES_128 = 0;
+localparam AES_192 = 1;
+localparam AES_256 = 2;
+localparam KEYSCHED_TYPE_1 = 0;
+localparam KEYSCHED_TYPE_2 = 1;
+localparam KEYSCHED_TYPE_3 = 2;
+localparam KEYSCHED_TYPE_A = 3;
+localparam KEYSCHED_TYPE_B = 4;
+localparam KEYSCHED_TYPE_C = 5;
+
+reg [2:0] fsm;
+reg [255:0] state;
+reg [7:0] Rcon;
+
+wire [31:0] w0, w1, w2, w3, w4, w5;
+wire [31:0] w0_new, w1_new, w2_new, w3_new, w4_new, w5_new;
+wire [31:0] w0_temp, w0_sub_o;
+reg [31:0] w0_sub_i;
+wire [7:0] Rcon_new = {Rcon[6:0], 1\'h0} ^ ((Rcon[7]) ? 8\'h1b : 8\'h0);
+
+assign {w0,w1,w2,w3} = (fsm == KEYSCHED_TYPE_2)
+\t? state[127: 0] : state[255:128];
+assign {w4,w5} = state[127: 64];
+
+reg [1:0] size_r;
+
+always @*
+begin : ks_h1
+\treg [31:0] wN;
+\t
+\tcase(size_r)
+\tAES_128: wN = state[159:128];
+\tAES_192: wN = state[ 95: 64];
+\tdefault: wN = (fsm == KEYSCHED_TYPE_1)
+\t\t? state[ 31: 0] : state[159:128];
+\tendcase
+\t
+\tw0_sub_i = (fsm == KEYSCHED_TYPE_2)
+\t\t? wN : {wN[23:0], wN[31:24]};
+end
+
+aes_sbox ks_inst0(.U(w0_sub_i[7:0]), .dec(1\'b0), .S(w0_sub_o[7:0]));
+aes_sbox ks_inst1(.U(w0_sub_i[15:8]), .dec(1\'b0), .S(w0_sub_o[15:8]));
+aes_sbox ks_inst2(.U(w0_sub_i[23:16]), .dec(1\'b0), .S(w0_sub_o[23:16]));
+aes_sbox ks_inst3(.U(w0_sub_i[31:24]), .dec(1\'b0), .S(w0_sub_o[31:24]));
+
+assign w0_temp = (fsm == KEYSCHED_TYPE_2)
+\t? w0_sub_o : {w0_sub_o[31:24] ^ Rcon,w0_sub_o[23:0]};
+
+assign w0_new = w0 ^ w0_temp;
+assign w1_new = w1 ^ w0_new;
+assign w2_new = w2 ^ w1_new;
+assign w3_new = w3 ^ w2_new;
+assign w4_new = w4 ^ w3_new;
+assign w5_new = w5 ^ w4_new;
+
+always @(posedge clk)
+begin
+\tif(load_i)
+\tbegin
+\t\tstate <= key_i;
+\t\tsize_r <= size_i;
+\t\tcase(size_i)
+\t\tAES_128: fsm <= KEYSCHED_TYPE_1;
+\t\tAES_192: fsm <= KEYSCHED_TYPE_B;
+\t\tAES_256: fsm <= KEYSCHED_TYPE_3;
+\t\tendcase
+\t\tRcon <= 1;
+\t\tks_o <= key_i[255:128];
+\tend
+\telse if(en_i)
+\tbegin
+\t\tcase(fsm)
+\t\tKEYSCHED_TYPE_1:
+\t\tbegin
+\t\t\tRcon <= Rcon_new;
+\t\t\tks_o <= {w0_new,w1_new,w2_new,w3_new};
+\t\t\tstate[255:128] <= {w0_new,w1_new,w2_new,w3_new};
+\t\t\tfsm <= (size_r == AES_128) ? KEYSCHED_TYPE_1 : KEYSCHED_TYPE_2;
+\t\tend
+\t\tKEYSCHED_TYPE_2:
+\t\tbegin
+\t\t\tks_o <= {w0_new,w1_new,w2_new,w3_new};
+\t\t\tstate[127: 0] <= {w0_new,w1_new,w2_new,w3_new};
+\t\t\tfsm <= KEYSCHED_TYPE_1;
+\t\tend
+\t\tKEYSCHED_TYPE_3:
+\t\tbegin
+\t\t\tks_o <= state[127: 0];
+\t\t\tfsm <= KEYSCHED_TYPE_1;
+\t\tend
+\t\tKEYSCHED_TYPE_A:
+\t\tbegin
+\t\t\tks_o <= state[255:128];
+\t\t\tfsm <= KEYSCHED_TYPE_B;
+\t\tend
+\t\tKEYSCHED_TYPE_B:
+\t\tbegin
+\t\t\tks_o <= {state[127:64],w0_new,w1_new};
+\t\t\tstate[255:64] <= {w0_new,w1_new,w2_new,w3_new,w4_new,w5_new};
+\t\t\tRcon <= Rcon_new;
+\t\t\tfsm <= KEYSCHED_TYPE_C;
+\t\tend
+\t\tKEYSCHED_TYPE_C:
+\t\tbegin
+\t\t\tks_o <= state[191:64];
+\t\t\tstate[255:64] <= {w0_new,w1_new,w2_new,w3_new,w4_new,w5_new};
+\t\t\tRcon <= Rcon_new;
+\t\t\tfsm <= KEYSCHED_TYPE_A;
+\t\tend
+\t\tendcase
+\tend
+end
+
+endmodule
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 19:35:02 01/05/2015
+// Design Name:
+// Module Name: wb_rom
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module wb_rom #(
+\tparameter depth = 65536,
+\tparameter aw = $clog2(depth),
+\tparameter memfile = ""rom.dat""
+) (
+ input wb_clk,
+ input wb_rst,
+ input [31:0] wb_adr_i,
+ input [2:0] wb_cti_i,
+ input [1:0] wb_bte_i,
+ input wb_we_i,
+ input wb_cyc_i,
+ input wb_stb_i,
+ output [31:0] wb_dat_o,
+ output reg wb_ack_o,
+ output wb_err_o,
+ output wb_rty_o
+);
+
+`include ""wb_common.v""
+
+assign wb_err_o = 0;
+assign wb_rty_o = 0;
+
+wire valid = (wb_cyc_i & wb_stb_i);
+reg valid_r;
+wire new_cycle = valid & ~valid_r;
+
+reg [aw - 1:0] adr_r;
+wire [aw - 1:0] next_adr = wb_next_adr(adr_r, wb_cti_i, wb_bte_i, 32);
+wire [aw - 1:0] wb_adr = new_cycle ? wb_adr_i : next_adr;
+
+always @(posedge wb_clk)
+begin
+\tadr_r <= wb_adr;
+\tvalid_r <= valid;
+\twb_ack_o <= valid & (!((wb_cti_i == 3\'b000) | (wb_cti_i == 3\'b111)) | !wb_ack_o);
+\tif(wb_rst)
+\tbegin
+\t\tadr_r <= 0;
+\t\tvalid_r <= 0;
+\t\twb_ack_o <= 0;
+\tend
+end
+
+dp_rom #(
+\t.memfile(memfile),
+\t.aw(aw - 2)
+) rom_inst (
+\t.clk1(wb_clk),
+\t.en1(valid),
+\t.adr1(wb_adr[aw - 1:2]),
+\t.dat1(wb_dat_o),
+\t.clk2(1\'b0),
+\t.en2(1\'b0),
+\t.adr2(0),
+\t.dat2()
+);
+
+endmodule
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 14:37:26 05/13/2014
+// Design Name:
+// Module Name: wb_aes_ctrl
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module wb_aes_ctrl (
+\tinput wb_clk_i,
+\tinput wb_rst_i,
+\tinput [31:0] wb_adr_i,
+\tinput [31:0] wb_dat_i,
+\tinput [3:0] wb_sel_i,
+\tinput wb_we_i,
+\tinput [1:0] wb_bte_i,
+\tinput [2:0] wb_cti_i,
+\tinput wb_cyc_i,
+\tinput wb_stb_i,
+\toutput reg wb_ack_o,
+\toutput wb_err_o,
+\toutput wb_rty_o,
+\toutput reg [31:0] wb_dat_o,
+\t
+\toutput reg [255:0] key_o,
+\toutput reg dec_o,
+\toutput reg [1:0] size_o,
+\toutput reg [127:0] data_o,
+\toutput reg load_o,
+\tinput [127:0] data_i,
+\tinput busy_i
+);
+
+`include ""wb_common.v""
+
+assign wb_err_o = 0;
+assign wb_rty_o = 0;
+
+wire valid = (wb_cyc_i & wb_stb_i);
+reg valid_r;
+wire new_cycle = valid & ~valid_r;
+
+reg [6:0] adr_r;
+wire [6:0] next_adr = wb_next_adr(adr_r, wb_cti_i, wb_bte_i, 32);
+wire [6:0] wb_adr = new_cycle ? wb_adr_i : next_adr;
+
+reg [127:0] data_ir;
+
+always @(posedge wb_clk_i)
+begin
+\tadr_r <= wb_adr;
+\tvalid_r <= valid;
+\twb_ack_o <= valid & (!((wb_cti_i == 3\'b000) | (wb_cti_i == 3\'b111)) | !wb_ack_o);
+\tif(wb_rst_i)
+\tbegin
+\t\tadr_r <= 0;
+\t\tvalid_r <= 0;
+\t\twb_ack_o <= 0;
+\tend
+end
+
+reg busy_r, rst_r, go_r;
+wire rst = (rst_r | wb_rst_i);
+
+`define KEY_WRITE(x) \\
+\tkey_o[256 - (x * 32) - 23:256 - (x * 32) - 32] <= (wb_sel_i[0]) \\
+\t\t? wb_dat_i[ 7: 0] : key_o[256 - (x * 32) - 23:256 - (x * 32) - 32]; \\
+\tkey_o[256 - (x * 32) - 17:256 - (x * 32) - 24] <= (wb_sel_i[1]) \\
+\t\t? wb_dat_i[15: 8] : key_o[256 - (x * 32) - 17:256 - (x * 32) - 24]; \\
+\tkey_o[256 - (x * 32) - 9:256 - (x * 32) - 16] <= (wb_sel_i[2]) \\
+\t\t? wb_dat_i[23:16] : key_o[256 - (x * 32) - 9:256 - (x * 32) - 16]; \\
+\tkey_o[256 - (x * 32) - 1:256 - (x * 32) - 8] <= (wb_sel_i[3]) \\
+\t\t? wb_dat_i[31:24] : key_o[256 - (x * 32) - 1:256 - (x * 32) - 8];
+
+`define DATA_READ(x) \\
+\twb_dat_o <= (load_o | busy_i) \\
+\t\t? 32\'h0 : data_ir[128 - (x * 32) - 1:128 - (x * 32) - 32];
+
+`define DATA_WRITE(x) \\
+\tdata_o[128 - (x * 32) - 23:128 - (x * 32) - 32] <= (wb_sel_i[0]) \\
+\t\t? wb_dat_i[ 7: 0] : data_o[128 - (x * 32) - 23:128 - (x * 32) - 32]; \\
+\tdata_o[128 - (x * 32) - 17:128 - (x * 32) - 24] <= (wb_sel_i[1]) \\
+\t\t? wb_dat_i[15: 8] : data_o[128 - (x * 32) - 17:128 - (x * 32) - 24]; \\
+\tdata_o[128 - (x * 32) - 9:128 - (x * 32) - 16] <= (wb_sel_i[2]) \\
+\t\t? wb_dat_i[23:16] : data_o[128 - (x * 32) - 9:128 - (x * 32) - 16]; \\
+\tdata_o[128 - (x * 32) - 1:128 - (x * 32) - 8] <= (wb_sel_i[3]) \\
+\t\t? wb_dat_i[31:24] : data_o[128 - (x * 32) - 1:128 - (x * 32) - 8];
+
+
+always @(posedge wb_clk_i)
+begin : ctrl_block
+\tbusy_r <= busy_i;
+\trst_r <= 0;
+\t
+\tif(rst)
+\tbegin\t
+\t\tdata_ir <= 0;
+\t\tload_o <= 0;
+\t\tdec_o <= 0;
+\t\tsize_o <= 0;
+\t\tdata_o <= 0;
+\t\tkey_o <= 0;
+\t\tload_o <= 0;
+\tend
+\telse
+\tbegin
+\t\tif(busy_r & ~busy_i)
+\t\tbegin
+\t\t\tdata_ir <= data_i;
+\t\tend
+\t\tif(busy_i)
+\t\t\tload_o <= 0;
+\t\t\t
+\t\tif(valid & wb_we_i & ~busy_i & ~load_o)
+\t\tbegin
+\t\t\tcase(wb_adr[6:4])
+\t\t\t3\'b000:
+\t\t\tbegin
+\t\t\t\tcase(wb_adr[3:2])
+\t\t\t\t0: begin `KEY_WRITE(0); end
+\t\t\t\t1: begin `KEY_WRITE(1); end
+\t\t\t\t2: begin `KEY_WRITE(2); end
+\t\t\t\t3: begin `KEY_WRITE(3); end
+\t\t\t\tendcase
+\t\t\tend
+\t\t\t3\'b001:
+\t\t\tbegin
+\t\t\t\tcase(wb_adr[3:2])
+\t\t\t\t0: begin `KEY_WRITE(4); end
+\t\t\t\t1: begin `KEY_WRITE(5); end
+\t\t\t\t2: begin `KEY_WRITE(6); end
+\t\t\t\t3: begin `KEY_WRITE(7); end
+\t\t\t\tendcase
+\t\t\tend
+\t\t\t3\'b010:
+\t\t\tbegin
+\t\t\t\tcase(wb_adr[3:2])
+\t\t\t\t0: begin `DATA_WRITE(0); end
+\t\t\t\t1: begin `DATA_WRITE(1); end
+\t\t\t\t2: begin `DATA_WRITE(2); end
+\t\t\t\t3: begin `DATA_WRITE(3); end
+\t\t\t\tendcase
+\t\t\tend
+\t\t\t3\'b100:
+\t\t\tbegin
+\t\t\t\tif(wb_adr[3:2] == 0)
+\t\t\t\tbegin
+\t\t\t\t\tload_o <= wb_sel_i[0] & wb_dat_i[0];
+\t\t\t\t\tdec_o <= wb_sel_i[0] & wb_dat_i[1];\t\t\t
+\t\t\t\t\tsize_o <= {2{wb_sel_i[0]}} & wb_dat_i[3:2];
+\t\t\t\t\trst_r <= wb_sel_i[1] & wb_dat_i[8];
+\t\t\t\tend
+\t\t\tend
+\t\t\tendcase
+\t\tend // write handler
+\t\t
+\t\tif(valid & ~wb_we_i)
+\t\tbegin
+\t\t\tcase(wb_adr[6:4])
+\t\t\t3\'b011:
+\t\t\tbegin
+\t\t\t\tcase(wb_adr[3:2])
+\t\t\t\t0: begin `DATA_READ(0); end
+\t\t\t\t1: begin `DATA_READ(1); end
+\t\t\t\t2: begin `DATA_READ(2); end
+\t\t\t\t3: begin `DATA_READ(3); end
+\t\t\t\tendcase
+\t\t\tend
+\t\t\t3\'b100:
+\t\t\tbegin\t\t
+\t\t\t\tif(wb_adr[3:2] == 0)
+\t\t\t\t\twb_dat_o <= { 15\'h0, load_o | busy_i, 16\'h0 };
+\t\t\t\telse
+\t\t\t\t\twb_dat_o <= 32\'h0;
+\t\t\tend
+\t\t\tdefault: wb_dat_o <= 32\'h0;
+\t\t\tendcase
+\t\tend // read handler
+\tend
+end
+
+endmodule
+"
+"/*\r
+ Copyright 2015, Google Inc.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the ""License"");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an ""AS IS"" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+//\r
+// 2-stage synchronizer\r
+//\r
+module synch_2 #(parameter WIDTH = 1) (\r
+ input wire [WIDTH-1:0] i, // input signal\r
+ output reg [WIDTH-1:0] o, // synchronized output\r
+ input wire clk // clock to synchronize on\r
+);\r
+\r
+reg [WIDTH-1:0] stage_1;\r
+always @(posedge clk)\r
+ {o, stage_1} <= {stage_1, i};\r
+\r
+endmodule\r
+\r
+\r
+//\r
+// 3-stage synchronizer\r
+//\r
+module synch_3 #(parameter WIDTH = 1) (\r
+ input wire [WIDTH-1:0] i, // input signal\r
+ output reg [WIDTH-1:0] o, // synchronized output\r
+ input wire clk, // clock to synchronize on\r
+ output wire rise // one-cycle rising edge pulse\r
+);\r
+\r
+reg [WIDTH-1:0] stage_1;\r
+reg [WIDTH-1:0] stage_2;\r
+reg [WIDTH-1:0] stage_3;\r
+\r
+assign rise = (WIDTH == 1) ? (o & ~stage_3) : 1\'b0;\r
+always @(posedge clk) \r
+ {stage_3, o, stage_2, stage_1} <= {o, stage_2, stage_1, i};\r
+ \r
+endmodule\r
+"
+"`include ""nandc_def.vh""
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+module nandc_ecc_dual_master #(
+ //
+ // PORT 0 (FTL)
+ //
+
+ // base offset on the wishbone bus that everything is located at
+ parameter WB0_FLASH_BASEADDR = `WB0_FLASH_BASEADDR,
+
+ // the offset to place wishbone registers at on the bus
+ parameter WB0_REG_BASEADDR = `WB0_REG_BASEADDR,
+
+ // the start block that this nand controller is able to address
+ parameter WB0_FLASH_S = `WB0_FLASH_S,
+
+ // the number of blocks this nand controller is able to address (out of 1024)
+ parameter WB0_FLASH_N = `WB0_FLASH_N,
+
+
+ //
+ // PORT 1 (CPU)
+ //
+
+ // base offset on the wishbone bus that everything is located at (on CPU side)
+ parameter WBCPU_FLASH_BASEADDR = `WBCPU_FLASH_BASEADDR,
+
+ // the offset to place wishbone registers at on the bus (on CPU side)
+ parameter WBCPU_REG_BASEADDR = `WBCPU_REG_BASEADDR,
+
+ // base offset on the wishbone bus that everything is located at (on NANDC side)
+ parameter WB1_FLASH_BASEADDR = `WB1_FLASH_BASEADDR,
+
+ // the offset to place wishbone registers at on the bus (on NANDC side)
+ parameter WB1_REG_BASEADDR = `WB1_REG_BASEADDR,
+
+ // the start block that this nand controller is able to address
+ parameter WB1_FLASH_S = `WB1_FLASH_S,
+
+ // the number of blocks this nand controller is able to address (out of 1024)
+ parameter WB1_FLASH_N = `WB1_FLASH_N
+) (
+ input wire wb_clk, // wishbone clock
+ input wire wb_rst, // reset synchronous with wb_clk
+
+ input wire [2:0] wbs0_cti_i, // type - cycle type identifier, supports either 000 ""Classic cycle"" or 010 ""Incrementing burst cycle""
+ input wire [1:0] wbs0_bte_i, // exten - burst type extension, only supports 00 ""Linear burst""
+ input wire [31:0] wbs0_adr_i, // addr - bus address
+ output wire [31:0] wbs0_dat_o, // data - write data output
+ input wire [31:0] wbs0_dat_i, // data - write data input
+ input wire [3:0] wbs0_sel_i, // select - 8-bit enable for data bus
+ input wire wbs0_cyc_i, // cycle - valid bus cycle is in progress
+ input wire wbs0_stb_i, // strobe - slave is selected
+ input wire wbs0_we_i, // write - bus cycle is in write mode
+ output wire wbs0_ack_o, // ack - end of a normal bus cycle
+
+ input wire [2:0] wbs1_cti_i, // type - cycle type identifier, supports either 000 ""Classic cycle"" or 010 ""Incrementing burst cycle""
+ input wire [1:0] wbs1_bte_i, // exten - burst type extension, only supports 00 ""Linear burst""
+ input wire [31:0] wbs1_adr_i, // addr - bus address
+ output wire [31:0] wbs1_dat_o, // data - write data output
+ input wire [31:0] wbs1_dat_i, // data - write data input
+ input wire [3:0] wbs1_sel_i, // select - 8-bit enable for data bus
+ input wire wbs1_cyc_i, // cycle - valid bus cycle is in progress
+ input wire wbs1_stb_i, // strobe - slave is selected
+ input wire wbs1_we_i, // write - bus cycle is in write mode
+ output wire wbs1_ack_o, // ack - end of a normal bus cycle
+
+ input wire [7:0] IO_i, // io - data input from flash
+ output wire [7:0] IO_o, // io - data output to flash
+ output wire [7:0] IO_t, // io - data tristate control
+ output wire CLE, // cle - command latch enable
+ output wire ALE, // ale - address latch enable
+ output wire CE_n, // ce - chip enable
+ output wire WE_n, // we - write enable
+ output wire RE_n, // re - read enable
+ output wire WP_n, // wp - write protect enable
+ input wire RB_n // rb - read/busy signal from flash
+);
+
+`include ""nandc_const.vh""
+
+wire [2:0] wbm0_cti_o;
+wire [1:0] wbm0_bte_o;
+wire [31:0] wbm0_adr_o, wbm0_dat_i, wbm0_dat_o;
+wire [3:0] wbm0_sel_o;
+wire wbm0_cyc_o;
+wire wbm0_stb_o;
+wire wbm0_we_o;
+wire wbm0_ack_i;
+
+nandc_ecc_inline #(
+ .WB_FLASH_BASEADDR ( WB0_FLASH_BASEADDR ),
+ .WB_REG_BASEADDR ( WB0_REG_BASEADDR ),
+ .WB_FLASH_S ( WB0_FLASH_S ),
+ .WB_FLASH_N ( WB0_FLASH_N )
+) nandc_ecc_inline (
+ .wb_clk ( wb_clk ),
+ .wb_rst ( wb_rst ),
+ .wbs_cti_i ( wbs0_cti_i ),
+ .wbs_bte_i ( wbs0_bte_i ),
+ .wbs_adr_i ( wbs0_adr_i ),
+ .wbs_dat_o ( wbs0_dat_o ),
+ .wbs_dat_i ( wbs0_dat_i ),
+ .wbs_sel_i ( wbs0_sel_i ),
+ .wbs_cyc_i ( wbs0_cyc_i ),
+ .wbs_stb_i ( wbs0_stb_i ),
+ .wbs_we_i ( wbs0_we_i ),
+ .wbs_ack_o ( wbs0_ack_o ),
+ .wbm_cti_o ( wbm0_cti_o ),
+ .wbm_bte_o ( wbm0_bte_o ),
+ .wbm_adr_o ( wbm0_adr_o ),
+ .wbm_dat_i ( wbm0_dat_i ),
+ .wbm_dat_o ( wbm0_dat_o ),
+ .wbm_sel_o ( wbm0_sel_o ),
+ .wbm_cyc_o ( wbm0_cyc_o ),
+ .wbm_stb_o ( wbm0_stb_o ),
+ .wbm_we_o ( wbm0_we_o ),
+ .wbm_ack_i ( wbm0_ack_i )
+);
+
+wire [2:0] wbm1_cti_o;
+wire [1:0] wbm1_bte_o;
+wire [31:0] wbm1_adr_o, wbm1_dat_i, wbm1_dat_o;
+wire [3:0] wbm1_sel_o;
+wire wbm1_cyc_o;
+wire wbm1_stb_o;
+wire wbm1_we_o;
+wire wbm1_ack_i;
+
+nandc_ecc_inline_cpu #(
+ .WBCPU_FLASH_BASEADDR ( WBCPU_FLASH_BASEADDR ),
+ .WBCPU_REG_BASEADDR ( WBCPU_REG_BASEADDR ),
+ .WB_FLASH_BASEADDR ( WB1_FLASH_BASEADDR ),
+ .WB_REG_BASEADDR ( WB1_REG_BASEADDR ),
+ .WB_FLASH_S ( WB1_FLASH_S ),
+ .WB_FLASH_N ( WB1_FLASH_N )
+) nandc_ecc_inline_cpu (
+ .wb_clk ( wb_clk ),
+ .wb_rst ( wb_rst ),
+ .wbs_cti_i ( wbs1_cti_i ),
+ .wbs_bte_i ( wbs1_bte_i ),
+ .wbs_adr_i ( wbs1_adr_i ),
+ .wbs_dat_o ( wbs1_dat_o ),
+ .wbs_dat_i ( wbs1_dat_i ),
+ .wbs_sel_i ( wbs1_sel_i ),
+ .wbs_cyc_i ( wbs1_cyc_i ),
+ .wbs_stb_i ( wbs1_stb_i ),
+ .wbs_we_i ( wbs1_we_i ),
+ .wbs_ack_o ( wbs1_ack_o ),
+ .wbm_cti_o ( wbm1_cti_o ),
+ .wbm_bte_o ( wbm1_bte_o ),
+ .wbm_adr_o ( wbm1_adr_o ),
+ .wbm_dat_i ( wbm1_dat_i ),
+ .wbm_dat_o ( wbm1_dat_o ),
+ .wbm_sel_o ( wbm1_sel_o ),
+ .wbm_cyc_o ( wbm1_cyc_o ),
+ .wbm_stb_o ( wbm1_stb_o ),
+ .wbm_we_o ( wbm1_we_o ),
+ .wbm_ack_i ( wbm1_ack_i )
+);
+
+reg [1:0] master_sel;
+
+always @(posedge wb_clk) begin
+ if(wb_rst) begin
+ master_sel <= \'h0;
+ end else begin
+ case(master_sel)
+ \'b00: begin
+ if(wbm1_cyc_o)
+ master_sel <= 2\'b10;
+ else if(wbm0_cyc_o)
+ master_sel <= 2\'b01;
+ end
+ \'b01: if(!wbm0_cyc_o) master_sel <= 2\'b00;
+ \'b10: if(!wbm1_cyc_o) master_sel <= 2\'b00;
+ endcase
+ end
+end
+
+wire [2:0] wbm_cti_o = master_sel[1] ? wbm1_cti_o : master_sel[0] ? wbm0_cti_o : \'h0;
+wire [1:0] wbm_bte_o = master_sel[1] ? wbm1_bte_o : master_sel[0] ? wbm0_bte_o : \'h0;
+wire [31:0] wbm_adr_o = master_sel[1] ? wbm1_adr_o : master_sel[0] ? wbm0_adr_o : \'h0;
+wire [31:0] wbm_dat_o = master_sel[1] ? wbm1_dat_o : master_sel[0] ? wbm0_dat_o : \'h0;
+wire [3:0] wbm_sel_o = master_sel[1] ? wbm1_sel_o : master_sel[0] ? wbm0_sel_o : \'h0;
+wire wbm_cyc_o = master_sel[1] ? wbm1_cyc_o : master_sel[0] ? wbm0_cyc_o : 0;
+wire wbm_stb_o = master_sel[1] ? wbm1_stb_o : master_sel[0] ? wbm0_stb_o : 0;
+wire wbm_we_o = master_sel[1] ? wbm1_we_o : master_sel[0] ? wbm0_we_o : 0;
+
+wire [31:0] wbm_dat_i;
+wire wbm_ack_i;
+
+assign wbm0_dat_i = master_sel[0] ? wbm_dat_i : \'h0;
+assign wbm0_ack_i = master_sel[0] & wbm_ack_i;
+assign wbm1_dat_i = master_sel[1] ? wbm_dat_i : \'h0;
+assign wbm1_ack_i = master_sel[1] & wbm_ack_i;
+
+nandc #(
+ .WB_FLASH_BASEADDR ( `WB_FLASH_BASEADDR ),
+ .WB_REG_BASEADDR ( `WB_REG_BASEADDR ),
+ .WB_FLASH_S ( `WB_FLASH_S ),
+ .WB_FLASH_N ( `WB_FLASH_N )
+) nandc (
+ .wb_clk ( wb_clk ),
+ .wb_rst ( wb_rst ),
+ .wbs_cti_i ( wbm_cti_o ),
+ .wbs_bte_i ( wbm_bte_o ),
+ .wbs_adr_i ( wbm_adr_o ),
+ .wbs_dat_o ( wbm_dat_i ),
+ .wbs_dat_i ( wbm_dat_o ),
+ .wbs_sel_i ( wbm_sel_o ),
+ .wbs_cyc_i ( wbm_cyc_o ),
+ .wbs_stb_i ( wbm_stb_o ),
+ .wbs_we_i ( wbm_we_o ),
+ .wbs_ack_o ( wbm_ack_i ),
+ .IO_i ( IO_i ),
+ .IO_o ( IO_o ),
+ .IO_t ( IO_t ),
+ .CLE ( CLE ),
+ .ALE ( ALE ),
+ .CE_n ( CE_n ),
+ .WE_n ( WE_n ),
+ .RE_n ( RE_n ),
+ .WP_n ( WP_n ),
+ .RB_n ( RB_n )
+);
+
+endmodule
+
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 18:20:43 02/02/2015
+// Design Name:
+// Module Name: sha256_W
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module sha256_W (
+ input clk,
+ input load_i,
+\t input busy_i,
+\t input [511:0] data_i,
+ output [31:0] W_o
+);
+
+`define DATA_IDX(x) data_i[512 - (x * 32) - 1:512 - (x * 32) - 32]
+
+reg [31:0] W[15:0];
+reg [31:0] W_new00, W_new01, W_new02, W_new03, W_new04, W_new05, W_new06, W_new07;
+reg [31:0] W_new08, W_new09, W_new10, W_new11, W_new12, W_new13, W_new14, W_new15;
+reg [31:0] W_new;
+reg [31:0] h0, h1, h0_new, h1_new;
+
+always @(posedge clk)
+begin\t
+\tW[ 0] <= W_new00;
+\tW[ 1] <= W_new01;
+\tW[ 2] <= W_new02;
+\tW[ 3] <= W_new03;
+\tW[ 4] <= W_new04;
+\tW[ 5] <= W_new05;
+\tW[ 6] <= W_new06;
+\tW[ 7] <= W_new07;
+\tW[ 8] <= W_new08;
+\tW[ 9] <= W_new09;
+\tW[10] <= W_new10;
+\tW[11] <= W_new11;
+\tW[12] <= W_new12;
+\tW[13] <= W_new13;
+\tW[14] <= W_new14;
+\tW[15] <= W_new15;
+\t\t
+\th0 <= h0_new;
+\th1 <= h1_new;
+end
+
+assign W_o = W[0];
+
+always @*
+begin : W_update
+\treg [31:0] w_0, w_1, w_9, w_14, d0, d1;
+\t
+\tW_new00 = 0;
+\tW_new01 = 0;
+\tW_new02 = 0;
+\tW_new03 = 0;
+\tW_new04 = 0;
+\tW_new05 = 0;
+\tW_new06 = 0;
+\tW_new07 = 0;
+\tW_new08 = 0;
+\tW_new09 = 0;
+\tW_new10 = 0;
+\tW_new11 = 0;
+\tW_new12 = 0;
+\tW_new13 = 0;
+\tW_new14 = 0;
+\tW_new15 = 0;
+
+\tw_0 = W[1];
+\tw_1 = W[2];
+\tw_9 = W[10];
+\tw_14 = W[15];
+\t
+\tW_new = h0 + h1;
+
+\tif(load_i)
+\tbegin
+\t\tW_new00 = `DATA_IDX( 0);
+\t\tW_new01 = `DATA_IDX( 1);
+\t\tW_new02 = `DATA_IDX( 2);
+\t\tW_new03 = `DATA_IDX( 3);
+\t\tW_new04 = `DATA_IDX( 4);
+\t\tW_new05 = `DATA_IDX( 5);
+\t\tW_new06 = `DATA_IDX( 6);
+\t\tW_new07 = `DATA_IDX( 7);
+\t\tW_new08 = `DATA_IDX( 8);
+\t\tW_new09 = `DATA_IDX( 9);
+\t\tW_new10 = `DATA_IDX(10);
+\t\tW_new11 = `DATA_IDX(11);
+\t\tW_new12 = `DATA_IDX(12);
+\t\tW_new13 = `DATA_IDX(13);
+\t\tW_new14 = `DATA_IDX(14);
+\t\tW_new15 = `DATA_IDX(15);
+\t\t
+\t\tw_0 = `DATA_IDX(0);
+\t\tw_1 = `DATA_IDX(1);
+\t\tw_9 = `DATA_IDX(9);
+\t\tw_14 = `DATA_IDX(14);
+\tend
+\telse if(busy_i)
+\tbegin
+\t\tW_new00 = W[ 1];
+\t\tW_new01 = W[ 2];
+\t\tW_new02 = W[ 3];
+\t\tW_new03 = W[ 4];
+\t\tW_new04 = W[ 5];
+\t\tW_new05 = W[ 6];
+\t\tW_new06 = W[ 7];
+\t\tW_new07 = W[ 8];
+\t\tW_new08 = W[ 9];
+\t\tW_new09 = W[10];
+\t\tW_new10 = W[11];
+\t\tW_new11 = W[12];
+\t\tW_new12 = W[13];
+\t\tW_new13 = W[14];
+\t\tW_new14 = W[15];
+\t\tW_new15 = W_new;
+\tend
+\t
+\td0 = {w_1[ 6: 0], w_1[31: 7]} ^ {w_1[17: 0], w_1[31:18]} ^ {3\'h0, w_1[31: 3]};
+\td1 = {w_14[16: 0], w_14[31:17]} ^ {w_14[18: 0], w_14[31:19]} ^ {10\'h0, w_14[31:10]};
+\t
+\th0_new = d0 + w_0;
+\th1_new = d1 + w_9;
+end
+
+endmodule
+
+"
+"/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+module nand_bram_block_dp #(
+ parameter DATA = 32,
+ parameter ADDR = 10,
+ parameter DEPTH = 517
+) (
+ input wire a_clk,
+ input wire a_wr,
+ input wire [ADDR-1:0] a_addr,
+ input wire [DATA-1:0] a_din,
+ output reg [DATA-1:0] a_dout,
+
+ input wire b_clk,
+ input wire b_wr,
+ input wire [ADDR-1:0] b_addr,
+ input wire [DATA-1:0] b_din,
+ output reg [DATA-1:0] b_dout
+);
+
+reg [DATA-1:0] mem [DEPTH-1:0];
+
+always @(posedge a_clk) begin
+ a_dout <= mem[a_addr];
+ if(a_wr) begin
+ a_dout <= a_din;
+ mem[a_addr] <= a_din;
+ end
+end
+
+always @(posedge b_clk) begin
+ b_dout <= mem[b_addr];
+ if(b_wr) begin
+ b_dout <= b_din;
+ mem[b_addr] <= b_din;
+ end
+end
+
+endmodule
+"
+"/*\r
+ Copyright 2015, Google Inc.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the ""License"");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an ""AS IS"" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+module ftl_physical (\r
+ input wire clk_50,\r
+ input wire reset_n,\r
+\r
+ output reg init_done,\r
+ output reg [9:0] dbg_num_valid_blocks,\r
+ output reg dbg_rebuilt_badblock,\r
+ output reg dbg_remapped_runtime,\r
+\r
+ output wire [9:0] dbg_logical_block,\r
+ output wire [9:0] dbg_physical_block, \r
+ output reg err_out_of_extras,\r
+\r
+ input wire op_page_do, // assert to start operation\r
+ input wire [2:0] op_page_cmd, // command to perform\r
+ input wire [15:0] op_page_num, // logical page\r
+ input wire [15:0] op_page_bram, // bram page number dest\r
+ input wire [41:0] op_page_spare_wr, // data to write to spare\r
+ output reg [41:0] op_page_spare_rd, // data read from spare\r
+ output reg op_page_status, // status on program/erase\r
+ output reg op_page_ack, // acknowledge op\r
+ output reg op_page_done, // complete\r
+\r
+ // interface to master block bram\r
+ output reg [15:0] bram_page_addr,\r
+ output reg bram_page_wren,\r
+ output reg [31:0] bram_page_data,\r
+ input wire [31:0] bram_page_q,\r
+\r
+ // master wishbone interface (to NANDC)\r
+ output wire wbm_clk_o,\r
+ output reg [2:0] wbm_cti_o, // type - cycle type identifier\r
+ output wire [1:0] wbm_bte_o, // exten - burst type extension\r
+ output reg [31:0] wbm_adr_o,\r
+ input wire [31:0] wbm_dat_i,\r
+ output wire [31:0] wbm_dat_o,\r
+ output wire [3:0] wbm_sel_o,\r
+ output reg wbm_cyc_o,\r
+ output reg wbm_stb_o,\r
+ output reg wbm_we_o,\r
+ input wire wbm_ack_i\r
+\r
+ ,\r
+ output wire clk_slow\r
+);\r
+\r
+`include ""ftl_const.vh""\r
+\r
+reg [15:0] cnt;\r
+always @(posedge clk_50) cnt <= cnt + 1\'b1;\r
+assign clk_slow = cnt[7];\r
+\r
+assign wbm_clk_o = clk_50;\r
+\r
+assign wbm_bte_o = 2\'b00;\r
+assign wbm_sel_o = 4\'b1111;\r
+reg [31:0] wbm_dat_out;\r
+reg wbm_ack_i_last;\r
+ \r
+reg op_page_do_1;\r
+ \r
+//\r
+// storage for the bad block remapping table\r
+//\r
+reg [9:0] bram_badmap_addr;\r
+wire [9:0] bram_badmap_addr_1 = bram_badmap_addr + 1\'b1;\r
+reg [15:0] bram_badmap_data;\r
+reg bram_badmap_wren;\r
+wire [15:0] bram_badmap_q;\r
+reg [31:0] bram_badmap_data_32;\r
+\r
+// \r
+// modelsim refuses to notice these unless they\'re above the first use\r
+//\r
+reg [9:0] scan_block;\r
+reg [7:0] scan_page;\r
+reg scan_blockgood;\r
+ \r
+reg [9:0] last_good_block;\r
+reg remapping_a_block;\r
+ \r
+reg [15:0] physical_page;\r
+ \r
+reg [15:0] bytes_done;\r
+ \r
+reg [15:0] dc;\r
+\r
+reg [6:0] state;\r
+\r
+parameter [6:0] ST_RESET = \'d0,\r
+ ST_IDLE = \'d10,\r
+ ST_IDLE_REQ = \'d11,\r
+ ST_IDLE_WAIT = \'d12,\r
+ ST_READ_0 = \'d20,\r
+ ST_READ_1 = \'d21,\r
+ ST_READ_2 = \'d22,\r
+ ST_EMPTY_0 = \'d25,\r
+ ST_WRITE_0 = \'d26,\r
+ ST_POKE_0 = \'d27,\r
+ ST_ERASE_0 = \'d28,\r
+ ST_STATUS_RD_0 = \'d29,\r
+ ST_SPARE_RD_0 = \'d30,\r
+ ST_SPARE_WR_0 = \'d31,\r
+ \r
+ ST_CHECKINIT_0 = \'d48,\r
+ ST_CHECKINIT_1 = \'d49,\r
+ \r
+ ST_LOADTABLE_0 = \'d50,\r
+ ST_LOADTABLE_1 = \'d51,\r
+ \r
+ ST_SCANBLOCKS_0 = \'d60,\r
+ ST_SCANBLOCKS_1 = \'d61,\r
+ ST_SCANBLOCKS_2 = \'d62,\r
+ ST_SCANBLOCKS_3 = \'d63,\r
+ \r
+ ST_FLUSHTABLE_0 = \'d64,\r
+ ST_FLUSHTABLE_1 = \'d65,\r
+ ST_FLUSHTABLE_2 = \'d66,\r
+ ST_FLUSHTABLE_3 = \'d67,\r
+ \r
+ ST_REMAPNEW_0 = \'d70,\r
+ ST_REMAPNEW_1 = \'d71,\r
+ ST_REMAPNEW_2 = \'d72,\r
+ ST_REMAPNEW_3 = \'d73,\r
+ \r
+ ST_ERASEBLOCK1 = \'d80,\r
+ \r
+ ST_LAST = \'d127;\r
+\r
+assign wbm_dat_o = ((state == ST_WRITE_0) ? bram_page_q : \r
+ (state == ST_FLUSHTABLE_2 || state == ST_FLUSHTABLE_3) ? bram_badmap_data_32 : \r
+ wbm_dat_out);\r
+ \r
+assign dbg_logical_block = op_page_num / NAND_PAGE_PER_BLOCK;\r
+assign dbg_physical_block = physical_page / NAND_PAGE_PER_BLOCK;\r
+ \r
+always @(posedge clk_50) begin \r
+ op_page_do_1 <= op_page_do;\r
+ \r
+ wbm_cyc_o <= 0;\r
+ wbm_stb_o <= 0;\r
+ wbm_we_o <= 0;\r
+ wbm_cti_o <= 3\'b000; // classic default\r
+ wbm_ack_i_last <= wbm_ack_i;\r
+\r
+ bram_badmap_wren <= 0;\r
+ bram_page_wren <= 0;\r
+ \r
+ dc <= dc + 1\'b1;\r
+ \r
+ // this code especially the the wishbone master I/F could be\r
+ // more compact/efficient, maybe in the future\r
+ case(state)\r
+ ST_RESET: begin\r
+ op_page_status <= 0;\r
+ op_page_ack <= 0;\r
+ op_page_done <= 0;\r
+ op_page_do_1 <= 0;\r
+ init_done <= 0;\r
+ err_out_of_extras <= 0;\r
+ remapping_a_block <= 0;\r
+ \r
+ dbg_num_valid_blocks <= 0;\r
+ dbg_rebuilt_badblock <= 0;\r
+ dbg_remapped_runtime <= 0;\r
+ \r
+ bram_badmap_addr <= -1;\r
+ scan_block <= 1; // set to start scanning factory data at physical block 1 \r
+ scan_page <= 0;\r
+ state <= ST_CHECKINIT_0;\r
+ \r
+ // uncomment to wipe all blocks (careful)\r
+ //scan_block <= 0;\r
+ //state <= ST_ERASEBLOCK1;\r
+ end\r
+ ST_ERASEBLOCK1: begin\r
+ //debug, erase block1\r
+ wbm_cyc_o <= 1;\r
+ wbm_we_o <= 1;\r
+ wbm_dat_out <= scan_block; \r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= NANDC_REG_ERASE;\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ wbm_stb_o <= 0;\r
+ \r
+ scan_block <= scan_block + 1\'b1;\r
+ if(scan_block == NAND_ALLOWED_PHY_BLOCKS) begin\r
+ scan_block <= 1;\r
+ state <= ST_CHECKINIT_0;\r
+ end\r
+ end \r
+ end\r
+ ST_IDLE: begin\r
+ dc <= 0;\r
+ if(op_page_do & ~op_page_do_1) begin \r
+ // rising edge\r
+ // lookup this block in the remap table\r
+ bram_badmap_addr <= op_page_num / NAND_PAGE_PER_BLOCK;\r
+ state <= ST_IDLE_REQ;\r
+ end \r
+ end\r
+ ST_IDLE_REQ: begin\r
+ physical_page <= bram_badmap_q * NAND_PAGE_PER_BLOCK + (op_page_num % NAND_PAGE_PER_BLOCK);\r
+ op_page_ack <= 1;\r
+ op_page_done <= 0;\r
+ op_page_status <= 0;\r
+ bytes_done <= 0;\r
+ \r
+ if(dc == 2) begin // delay to let bram_q settle\r
+ case(op_page_cmd)\r
+ OP_PAGE_READ: begin // read 1 page and its 64bit spare\r
+ bram_page_addr <= op_page_bram * (NAND_PAGE_SIZE / 4) - 1;\r
+ state <= ST_READ_0;\r
+ // ST_READ_0\r
+ // ST_SPARE_RD_0\r
+ // [return]\r
+ end\r
+ OP_PAGE_READ_EMPTY: begin // zero out bram, used for empty physical blocks\r
+ bram_page_addr <= op_page_bram * (NAND_PAGE_SIZE / 4) - 1;\r
+ state <= ST_EMPTY_0;\r
+ // ST_EMPTY_0\r
+ // [return]\r
+ end\r
+ OP_PAGE_WRITE: begin // write 64bit spare and its 1 page\r
+ bram_page_addr <= op_page_bram * (NAND_PAGE_SIZE / 4);\r
+ state <= ST_SPARE_WR_0;\r
+ // ST_SPARE_WR_0\r
+ // ST_WRITE_0\r
+ // ST_STATUS_RD_0\r
+ // [return]\r
+ end\r
+ OP_PAGE_POKE: begin // poke 1 page and return its spare only\r
+ state <= ST_POKE_0;\r
+ // ST_POKE_0\r
+ // ST_SPARE_RD_0\r
+ // [return]\r
+ end\r
+ OP_PAGE_BLOCKERASE: begin // erase an entire block (64 pages)\r
+ state <= ST_ERASE_0;\r
+ // ST_ERASE_0\r
+ // ST_STATUS_RD_0\r
+ // [return]\r
+ end\r
+ endcase\r
+ end\r
+ end\r
+ ST_IDLE_WAIT: begin\r
+ if(~op_page_do) begin\r
+ // clear ACK to logical\r
+ op_page_ack <= 0;\r
+ state <= ST_IDLE;\r
+ end\r
+ end\r
+ ST_READ_0: begin\r
+ /*\r
+ wbm_cyc_o <= 1;\r
+ wbm_cti_o <= 3\'b000; // classic mode\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= physical_page * NAND_PAGE_SIZE + bytes_done;\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ // latch incoming data from wishbone slave\r
+ bram_page_addr <= bram_page_addr + 1\'b1;\r
+ bram_page_data <= wbm_dat_i;\r
+ bram_page_wren <= 1;\r
+ wbm_stb_o <= 0;\r
+ \r
+ bytes_done <= bytes_done + 16\'h4;\r
+ if(bytes_done + 16\'h4 == NAND_PAGE_SIZE) begin\r
+ // done, read spare data\r
+ $display(""FTL_PHYSICAL: read logical page %d, which is logical block %d mapped to physical block %d"", \r
+ op_page_num, op_page_num / NAND_PAGE_PER_BLOCK, physical_page / NAND_PAGE_PER_BLOCK);\r
+ bytes_done <= 0;\r
+ state <= ST_SPARE_RD_0;\r
+ end\r
+ end \r
+ */\r
+ wbm_cyc_o <= 1;\r
+ wbm_stb_o <= 1;\r
+ wbm_cti_o <= 3\'b010; // incrementing address mode\r
+ wbm_adr_o <= physical_page * NAND_PAGE_SIZE;\r
+ state <= ST_READ_1;\r
+ end\r
+ ST_READ_1: begin\r
+ wbm_cyc_o <= 1;\r
+ wbm_stb_o <= 1;\r
+ wbm_cti_o <= wbm_cti_o; // incrementing address mode\r
+ if(wbm_ack_i) begin\r
+ // latch incoming data from wishbone slave\r
+ bram_page_addr <= bram_page_addr + 1\'b1;\r
+ bram_page_data <= wbm_dat_i;\r
+ bram_page_wren <= 1;\r
+ wbm_adr_o <= wbm_adr_o + \'d4;\r
+ bytes_done <= bytes_done + 16\'h4;\r
+ if(bytes_done + 16\'h0 == NAND_PAGE_SIZE) wbm_cti_o <= 3\'b111; // end of burst\r
+ if(bytes_done + 16\'h4 == NAND_PAGE_SIZE) begin\r
+ wbm_cyc_o <= 0;\r
+ wbm_stb_o <= 0;\r
+ // done, read spare data\r
+ $display(""FTL_PHYSICAL: read logical page %d, which is logical block %d mapped to physical block %d"", \r
+ op_page_num, op_page_num / NAND_PAGE_PER_BLOCK, physical_page / NAND_PAGE_PER_BLOCK);\r
+ bytes_done <= 0;\r
+ // only read in spare space on first page in block\r
+ if(physical_page % NAND_PAGE_PER_BLOCK == 0)\r
+ state <= ST_SPARE_RD_0;\r
+ else\r
+ state <= ST_READ_2;\r
+ end\r
+ end \r
+ end\r
+ ST_READ_2: begin\r
+ op_page_done <= 1;\r
+ state <= ST_IDLE_WAIT;\r
+ end\r
+ ST_EMPTY_0: begin\r
+ bram_page_addr <= bram_page_addr + 1;\r
+ bram_page_data <= 32\'h0; // if you want empty blocks to return FF\'s, change to 32\'hFFFFFFFF\r
+ bram_page_wren <= 1;\r
+ bytes_done <= bytes_done + 16\'h4;\r
+ if(bytes_done + 16\'h4 == NAND_PAGE_SIZE) begin\r
+ op_page_done <= 1;\r
+ state <= ST_IDLE_WAIT;\r
+ $display(""FTL_PHYSICAL: read empty logical page %d, which is logical block %d mapped to physical block %d"", \r
+ op_page_num, op_page_num / NAND_PAGE_PER_BLOCK, physical_page / NAND_PAGE_PER_BLOCK);\r
+ end \r
+ end\r
+ ST_POKE_0: begin\r
+ // single word read to make NANDC load the page and its spare data\r
+ wbm_cyc_o <= 1;\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= physical_page * NAND_PAGE_SIZE;\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ wbm_stb_o <= 0;\r
+ $display(""FTL_PHYSICAL: poke logical page %d, which is logical block %d mapped to physical block %d"", \r
+ op_page_num, op_page_num / NAND_PAGE_PER_BLOCK, physical_page / NAND_PAGE_PER_BLOCK);\r
+ bytes_done <= 0;\r
+ state <= ST_SPARE_RD_0;\r
+ end\r
+ end\r
+ ST_SPARE_RD_0: begin\r
+ wbm_cyc_o <= 1;\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= NANDC_REG_SPARE_RD + bytes_done;\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ // latch incoming data from wishbone slave\r
+ if(bytes_done == 0) op_page_spare_rd[41:32] <= wbm_dat_i;\r
+ if(bytes_done == 4) op_page_spare_rd[31:0] <= wbm_dat_i;\r
+ wbm_stb_o <= 0;\r
+ \r
+ bytes_done <= bytes_done + 16\'h4;\r
+ if(bytes_done + 16\'h4 == 8) begin\r
+ op_page_done <= 1;\r
+ state <= ST_IDLE_WAIT;\r
+ end\r
+ end \r
+ end\r
+ ST_SPARE_WR_0: begin\r
+ wbm_cyc_o <= 1;\r
+ wbm_we_o <= 1;\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= NANDC_REG_SPARE_WR + bytes_done;\r
+ wbm_stb_o <= 1;\r
+ if(bytes_done == 0) wbm_dat_out <= op_page_spare_wr[41:32]; \r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ wbm_stb_o <= 0;\r
+ if(bytes_done == 0) wbm_dat_out <= op_page_spare_wr[31:0];\r
+ \r
+ bytes_done <= bytes_done + 16\'h4;\r
+ if(bytes_done + 16\'h4 == 8) begin\r
+ // done\r
+ // now write page data\r
+ bytes_done <= 0;\r
+ state <= ST_WRITE_0;\r
+ end\r
+ end \r
+ end\r
+ ST_WRITE_0: begin\r
+ wbm_cyc_o <= 1;\r
+ wbm_we_o <= 1;\r
+\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= physical_page * NAND_PAGE_SIZE + bytes_done;\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ // increment bram read pointer\r
+ bram_page_addr <= bram_page_addr + 1;\r
+ wbm_stb_o <= 0;\r
+ \r
+ bytes_done <= bytes_done + 16\'h4;\r
+ if(bytes_done + 16\'h4 == NAND_PAGE_SIZE) begin\r
+ state <= ST_STATUS_RD_0;\r
+ $display(""FTL_PHYSICAL: wrote logical page %d, which is logical block %d mapped to physical block %d : phys page %d"", \r
+ op_page_num, op_page_num / NAND_PAGE_PER_BLOCK, physical_page / NAND_PAGE_PER_BLOCK, physical_page);\r
+ end\r
+ end \r
+ end\r
+ ST_ERASE_0: begin\r
+ wbm_cyc_o <= 1;\r
+ wbm_we_o <= 1;\r
+ wbm_dat_out <= physical_page / NAND_PAGE_PER_BLOCK;\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= NANDC_REG_ERASE;\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ wbm_stb_o <= 0;\r
+ state <= ST_STATUS_RD_0;\r
+ $display(""FTL_PHYSICAL: erased logical pageblock %d, which is logical block %d mapped to physical block %d"", \r
+ op_page_num, op_page_num / NAND_PAGE_PER_BLOCK, physical_page / NAND_PAGE_PER_BLOCK);\r
+ end \r
+ end\r
+ ST_STATUS_RD_0: begin\r
+ wbm_cyc_o <= 1;\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= NANDC_REG_STATUS;\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ // latch incoming data from wishbone slave\r
+ op_page_status <= wbm_dat_i[0];\r
+ wbm_stb_o <= 0;\r
+ if(wbm_dat_i[0]) begin\r
+ // nonzero return flag! error\r
+ $display(""FTL_PHYSICAL: nonzero STATUS_RD from program/erase"");\r
+ dc <= 0;\r
+ remapping_a_block <= 1;\r
+ state <= ST_REMAPNEW_0;\r
+ // set table pointer to last entry of bram, prepare to work backwards\r
+ bram_badmap_addr <= -1;\r
+ end else begin\r
+ op_page_done <= 1;\r
+ state <= ST_IDLE_WAIT;\r
+ end\r
+ end \r
+ end \r
+ \r
+ //\r
+ // CHECKINIT: load block 0 and see if badblock table is already made\r
+ //\r
+ ST_CHECKINIT_0: begin\r
+ wbm_cyc_o <= 1;\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= 0;\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ wbm_stb_o <= 0;\r
+ if(wbm_dat_i == 32\'hDEADBEEF) begin\r
+ $display(""FTL_PHYSICAL: valid badblock table magic was found, loading"");\r
+ state <= ST_LOADTABLE_0;\r
+ end else begin\r
+ $display(""FTL_PHYSICAL: no badblock table found, rebuilding from factory data"");\r
+ dbg_rebuilt_badblock <= 1;\r
+ scan_blockgood <= 1;\r
+ state <= ST_SCANBLOCKS_0;\r
+ end\r
+ end \r
+ end\r
+ ST_CHECKINIT_1: begin \r
+ // return here from either loading the remap table, or creating it!\r
+ // also here after a flush from a new bad block being added\r
+ init_done <= 1;\r
+ state <= ST_IDLE;\r
+ end\r
+ //\r
+ // ST_LOADTABLE: read bram into local remap table\r
+ //\r
+ ST_LOADTABLE_0: begin\r
+ wbm_cyc_o <= 1;\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= (bram_badmap_addr_1) * 2 + 4; // skip 4bytes for the magic\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ wbm_stb_o <= 0;\r
+ bram_badmap_data_32 <= wbm_dat_i;\r
+ $display(""FTL_PHYSICAL: loading from %h: data %h"", wbm_adr_o, wbm_dat_i);\r
+ dc <= 0;\r
+ state <= ST_LOADTABLE_1;\r
+ end \r
+ end\r
+ ST_LOADTABLE_1: begin\r
+ wbm_cyc_o <= 1;\r
+ case(dc) // load two entries (each is 16bit) to fill the 32bit wishbone word \r
+ 1: begin\r
+ bram_badmap_data <= bram_badmap_data_32[31:16];\r
+ bram_badmap_addr <= bram_badmap_addr + 1\'b1;\r
+ bram_badmap_wren <= 1;\r
+ if(bram_badmap_data_32[31:16]) dbg_num_valid_blocks <= dbg_num_valid_blocks + 1\'b1;\r
+ end\r
+ 3: begin\r
+ bram_badmap_data <= bram_badmap_data_32[15:0];\r
+ bram_badmap_addr <= bram_badmap_addr + 1\'b1;\r
+ bram_badmap_wren <= 1;\r
+ if(bram_badmap_data_32[15:0]) dbg_num_valid_blocks <= dbg_num_valid_blocks + 1\'b1;\r
+ \r
+ state <= ST_LOADTABLE_0;\r
+ if(bram_badmap_addr == NAND_ALLOWED_PHY_BLOCKS) begin\r
+ // there is only room for 1022 entries in the first page, NAND_ALLOWED_PHY_BLOCKS \r
+ // must be smaller or equal to this\r
+ state <= ST_CHECKINIT_1;\r
+ end\r
+ end\r
+ endcase\r
+ end\r
+ \r
+ //\r
+ // ST_SCANBLOCKS: read spare data in each block to determine factory bad block marking\r
+ //\r
+ ST_SCANBLOCKS_0: begin\r
+ wbm_cyc_o <= 1;\r
+ wbm_stb_o <= 1;\r
+ wbm_we_o <= 1;\r
+ wbm_dat_out <= 1; // enable raw spare data access\r
+ wbm_adr_o <= NANDC_REG_OFFSET;\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ wbm_stb_o <= 0;\r
+ state <= ST_SCANBLOCKS_1;\r
+ end \r
+ end\r
+ ST_SCANBLOCKS_1: begin\r
+ wbm_cyc_o <= 1;\r
+ wbm_stb_o <= 1;\r
+ wbm_adr_o <= (scan_block * NAND_PAGE_PER_BLOCK + scan_page) * NAND_PAGE_SIZE;\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ wbm_stb_o <= 0;\r
+ if(wbm_dat_i[31:0] != 32\'hFFFFFFFF) begin // wbm_dat_i[31:24] == 8\'hFF\r
+ scan_blockgood <= 0;\r
+ $display(""FTL_PHYSICAL: found bad block factory marked at physical block %d: page %d"", scan_block, scan_page);\r
+ end\r
+ state <= ST_SCANBLOCKS_2;\r
+ end \r
+ end\r
+ ST_SCANBLOCKS_2: begin\r
+ wbm_cyc_o <= 1;\r
+ wbm_stb_o <= 1;\r
+ wbm_we_o <= 1;\r
+ wbm_dat_out <= 0; // disable raw spare data access (necessary?)\r
+ wbm_adr_o <= NANDC_REG_OFFSET;\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ wbm_stb_o <= 0;\r
+ \r
+ state <= ST_SCANBLOCKS_0;\r
+ case(scan_page)\r
+ 0: scan_page <= 1;\r
+ 1: scan_page <= 63;\r
+ 63: begin\r
+ scan_blockgood <= 1;\r
+ scan_page <= 0;\r
+ scan_block <= scan_block + 1\'b1;\r
+ if(scan_blockgood) begin\r
+ // load this block into the table\r
+ dbg_num_valid_blocks <= dbg_num_valid_blocks + 1\'b1;\r
+ bram_badmap_addr <= bram_badmap_addr + 1\'b1;\r
+ bram_badmap_data <= scan_block;\r
+ bram_badmap_wren <= 1;\r
+ $display(""FTL_PHYSICAL: adding physical block %d as logical %d"", scan_block, bram_badmap_addr+1 == 1024 ? 0 : bram_badmap_addr+1);\r
+ end else $display(""FTL_PHYSICAL: not adding bad block %d"", scan_block);\r
+ if(scan_block == NAND_ALLOWED_PHY_BLOCKS-1) begin\r
+ // last one\r
+ state <= ST_SCANBLOCKS_3;\r
+ end\r
+ end\r
+ endcase\r
+ end \r
+ end\r
+ ST_SCANBLOCKS_3: begin\r
+ // zero out the remaining entries\r
+ bram_badmap_addr <= bram_badmap_addr + 1\'b1;\r
+ bram_badmap_data <= 0;\r
+ bram_badmap_wren <= 1;\r
+ if(bram_badmap_addr == NAND_DEVICE_NUM_BLOCKS-2) state <= ST_FLUSHTABLE_0;\r
+ end\r
+ \r
+ //\r
+ // ST_FLUSHTABLE: erase block0 and write 1022 entries into the first page\r
+ //\r
+ ST_FLUSHTABLE_0: begin\r
+ wbm_cyc_o <= 1;\r
+ wbm_we_o <= 1;\r
+ wbm_dat_out <= 0; // erase block 0\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= NANDC_REG_ERASE;\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ wbm_stb_o <= 0;\r
+ $display(""FTL_PHYSICAL: flushing badblock table"");\r
+ state <= ST_FLUSHTABLE_1;\r
+ end \r
+ end\r
+ ST_FLUSHTABLE_1: begin\r
+ wbm_cyc_o <= 1;\r
+ wbm_we_o <= 1;\r
+ wbm_dat_out <= 32\'hDEADBEEF; // block0 magic\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= 0;\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ wbm_stb_o <= 0;\r
+ dc <= 0;\r
+ bram_badmap_addr <= 0;\r
+ state <= ST_FLUSHTABLE_2;\r
+ end \r
+ end\r
+ ST_FLUSHTABLE_2: begin\r
+ //wbm_cyc_o <= 1;\r
+ case(dc) // load two entries (each is 16bit) to fill the 32bit wishbone word \r
+ 1: begin\r
+ bram_badmap_data_32[31:16] <= bram_badmap_q;\r
+ bram_badmap_addr <= bram_badmap_addr + 1\'b1;\r
+ end\r
+ 3: begin\r
+ bram_badmap_data_32[15:0] <= bram_badmap_q;\r
+ bram_badmap_addr <= bram_badmap_addr + 1\'b1;\r
+ state <= ST_FLUSHTABLE_3;\r
+ end\r
+ endcase\r
+ end\r
+ ST_FLUSHTABLE_3: begin\r
+ wbm_cyc_o <= 1; // write the word into the page of block0\r
+ wbm_we_o <= 1;\r
+ if(~wbm_ack_i) begin\r
+ wbm_adr_o <= (bram_badmap_addr-2) * 2 + 4; // skip 4bytes for the magic\r
+ wbm_stb_o <= 1;\r
+ end\r
+ if(wbm_ack_i & ~wbm_ack_i_last) begin\r
+ wbm_stb_o <= 0;\r
+ dc <= 0;\r
+ state <= ST_FLUSHTABLE_2;\r
+ if(bram_badmap_addr == NAND_DEVICE_NUM_BLOCKS-2) begin \r
+ // end, remember only 1022 entries are allowed to fit this page\r
+ state <= ST_CHECKINIT_1;\r
+ // if this was a flush caused by a new block, return to normal operation\r
+ if(remapping_a_block) begin\r
+ op_page_done <= 1;\r
+ state <= ST_IDLE_WAIT;\r
+ end\r
+ end\r
+ end \r
+ end\r
+ \r
+ //\r
+ // ST_REMAPNEW: find a substitute for the new bad block and then update&flush the table\r
+ //\r
+ ST_REMAPNEW_0: begin\r
+ dbg_remapped_runtime <= 1;\r
+ if(dc == 2) begin // delay for bram\r
+ state <= ST_REMAPNEW_1;\r
+ if(bram_badmap_q != 0) begin\r
+ // nonzero entry, swap\r
+ last_good_block <= bram_badmap_addr;\r
+ state <= ST_REMAPNEW_2;\r
+ end\r
+ end\r
+ end\r
+ ST_REMAPNEW_1: begin\r
+ dc <= 0;\r
+ state <= ST_REMAPNEW_0;\r
+ bram_badmap_addr <= bram_badmap_addr - 1\'b1;\r
+ // is this entry next to the end of user area?\r
+ if(bram_badmap_addr == NAND_ALLOWED_LOG_BLOCKS) begin\r
+ $display(""FTL_PHYSICAL: ran out of remappable blocks and encroaching upon user area"");\r
+ err_out_of_extras <= 1;\r
+ end\r
+ end\r
+ ST_REMAPNEW_2: begin\r
+ $display(""FTL_PHYSICAL: new bad block; logical block %d was physical %d, now physical %d"", \r
+ op_page_num / NAND_PAGE_PER_BLOCK, \r
+ physical_page / NAND_PAGE_PER_BLOCK,\r
+ bram_badmap_q);\r
+ bram_badmap_addr <= op_page_num / NAND_PAGE_PER_BLOCK;\r
+ bram_badmap_data <= bram_badmap_q;\r
+ bram_badmap_wren <= 1;\r
+ state <= ST_REMAPNEW_3;\r
+ end\r
+ ST_REMAPNEW_3: begin\r
+ bram_badmap_addr <= last_good_block;\r
+ bram_badmap_data <= 0;\r
+ bram_badmap_wren <= 1;\r
+ \r
+ state <= ST_FLUSHTABLE_0;\r
+ end\r
+ endcase\r
+ \r
+ if(~reset_n) begin\r
+ state <= ST_RESET;\r
+ end \r
+end\r
+\r
+// 2048 byte bram (2^10=1024 x 16bit word)\r
+ftl_bram_block_dp #(16, 10) ipbbram (\r
+ .a_clk ( clk_50 ),\r
+ .a_wr ( bram_badmap_wren ),\r
+ .a_addr ( bram_badmap_addr ),\r
+ .a_din ( bram_badmap_data ),\r
+ .a_dout ( bram_badmap_q )\r
+);\r
+\r
+endmodule\r
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 21:28:10 02/03/2015
+// Design Name: sha256_core
+// Project Name: crypto_sha256
+// Target Device:
+// Tool versions:
+// Description:
+//
+// Verilog Test Fixture created by ISE for module: sha256_core
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+////////////////////////////////////////////////////////////////////////////////
+
+module sha256_core_tb;
+
+\t// Inputs
+\treg clk;
+\treg rst_i;
+\treg load_i;
+\treg [511:0] data_i;
+\treg [255:0] state_i;
+\treg [255:0] test_val;
+\t
+\t// Outputs
+\twire [255:0] state_o;
+\twire busy_o;
+
+\t// Instantiate the Unit Under Test (UUT)
+\tsha256_core uut (
+\t\t.clk(clk),
+\t\t//.rst_i(rst_i),
+\t\t.load_i(load_i),
+\t\t.data_i(data_i),
+\t\t.state_i(state_i),
+\t\t.state_o(state_o),
+\t\t.busy_o(busy_o)
+\t);
+
+\tinitial begin
+\t\t// Initialize Inputs
+\t\tclk = 0;
+\t\trst_i = 1;
+\t\tload_i = 0;
+\t\tdata_i = 0;
+\t\tstate_i = 0;
+
+\t\t// Wait 100 ns for global reset to finish
+\t\t#100;
+
+\t\t// Add stimulus here
+\t\trst_i = 0;
+\t\tstate_i = {
+\t\t\t32\'h6a09e667, 32\'hbb67ae85, 32\'h3c6ef372, 32\'ha54ff53a,
+\t\t\t32\'h510e527f, 32\'h9b05688c, 32\'h1f83d9ab, 32\'h5be0cd19
+\t\t};
+\t\tdata_i = {
+\t\t\t32\'h61626380, 32\'h00000000, 32\'h00000000, 32\'h00000000,
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000000,
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000000,
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000018
+\t\t};
+\t\ttest_val = {
+\t\t\t32\'hba7816bf, 32\'h8f01cfea, 32\'h414140de, 32\'h5dae2223,
+\t\t\t32\'hb00361a3, 32\'h96177a9c, 32\'hb410ff61, 32\'hf20015ad
+\t\t};
+\t\t
+\t\tload_i = 1;
+\t\twhile(!busy_o) #1;
+\t\tload_i = 0;
+\t\twhile(busy_o) #1;
+\t\tif(test_val != state_o)
+\t\tbegin
+\t\t\t$display(""test #1 fail"");
+\t\t\t$stop;
+\t\tend
+\t\t$display(""sha256_core passed"");
+\t\t$finish;
+\tend
+
+always #10 clk <= ~clk;
+
+endmodule
+
+"
+"`include ""nandc_def.vh""
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+module nandc_ecc_inline_cpu #(
+ // base offset on the CPU wishbone bus that everything is located at
+ parameter WBCPU_FLASH_BASEADDR = `WBCPU_FLASH_BASEADDR,
+
+ // the offset to place CPU wishbone registers at on the bus
+ parameter WBCPU_REG_BASEADDR = `WBCPU_REG_BASEADDR,
+
+ // base offset on the NAND controller wishbone bus that everything is located at
+ parameter WB_FLASH_BASEADDR = `WB_FLASH_BASEADDR,
+
+ // the offset where the NAND controller wishbone registers are on the bus
+ parameter WB_REG_BASEADDR = `WB_REG_BASEADDR,
+
+ // the start block that this nand controller is able to address
+ parameter WB_FLASH_S = `WB_FLASH_S,
+
+ // the number of blocks this nand controller is able to address (out of 1024)
+ parameter WB_FLASH_N = `WB_FLASH_N
+) (
+ input wire wb_clk, // clock - bus clock
+ input wire wb_rst, // reset synchronous with wb_clk
+
+ input wire [2:0] wbs_cti_i, // type - cycle type identifier, supports either 000 ""Classic cycle"" or 010 ""Incrementing burst cycle""
+ input wire [1:0] wbs_bte_i, // exten - burst type extension, only supports 00 ""Linear burst""
+ input wire [31:0] wbs_adr_i, // addr - bus address
+ output reg [31:0] wbs_dat_o, // data - write data output
+ input wire [31:0] wbs_dat_i, // data - write data input
+ input wire [3:0] wbs_sel_i, // select - 8-bit enable for data bus
+ input wire wbs_cyc_i, // cycle - valid bus cycle is in progress
+ input wire wbs_stb_i, // strobe - slave is selected
+ input wire wbs_we_i, // write - bus cycle is in write mode
+ output reg wbs_ack_o, // ack - end of a normal bus cycle
+
+ output reg [2:0] wbm_cti_o, // type - cycle type identifier, supports either 000 ""Classic cycle"" or 010 ""Incrementing burst cycle""
+ output reg [1:0] wbm_bte_o, // exten - burst type extension, only supports 00 ""Linear burst""
+ output reg [31:0] wbm_adr_o, // addr - bus address
+ input wire [31:0] wbm_dat_i, // data - write data input
+ output reg [31:0] wbm_dat_o, // data - write data output
+ output reg [3:0] wbm_sel_o, // select - 8-bit enable for data bus
+ output reg wbm_cyc_o, // cycle - valid bus cycle is in progress
+ output reg wbm_stb_o, // strobe - slave is selected
+ output reg wbm_we_o, // write - bus cycle is in write mode
+ input wire wbm_ack_i // ack - end of a normal bus cycle
+);
+
+`include ""wb_common.v""
+
+reg [31:0] adr_r;
+wire valid = wbs_cyc_i & wbs_stb_i;
+reg valid_r;
+wire new_cycle = valid & !valid_r;
+wire [31:0] next_adr = wb_next_adr(adr_r, wbs_cti_i, wbs_bte_i, 32);
+wire [31:0] adr = new_cycle ? wbs_adr_i : next_adr;
+
+always @(posedge wb_clk) begin
+ if(wb_rst) begin
+ adr_r <= \'h0;
+ valid_r <= \'b0;
+ wbs_ack_o <= \'b0;
+ end else begin
+ adr_r <= adr;
+ valid_r <= valid;
+ wbs_ack_o <= valid & (!((wbs_cti_i == 3\'b000) | (wbs_cti_i == 3\'b111)) | !wbs_ack_o);
+ end
+end
+
+wire ram_we = wbs_we_i & valid & wbs_ack_o;
+reg [31:0] wbs_dat_o_r;
+reg [31:0] wbm_dat_o_r;
+
+`include ""nandc_const.vh""
+
+// Wishbone addresses on the CPU bus
+//
+// The main difference with the CPU bus is that the FLASH space is just the size of 1 page
+// and acts as a scratch buffer for reads and writes. To initiate a READ or WRITE operation
+// you write the address you wish to read/write to to the READ or WRITE address on the bus.
+// To determine if the last operation (READ/WRITE/ERASE/STATUS/etc) is finished, you must
+// read a 1 for the READY bit at the STATUS address before initiating another command:
+//
+// bit 0 - READY: 1 = Operation complete, 0 = Bus Busy, any transactions initiated while busy will be ignored
+// bit 1 - STATUS: 1 = The last STATUS command reported back an error, 0 = No errors
+//
+// If you wish to read the STATUS of the last PROG or ERASE operation, you must write to
+// the STATUS register and then poll the STATUS register until READY = 1 at which point
+// the STATUS bit will reflect the result of the STATUS command.
+//
+parameter WBCPU_FLASH_HIGHADDR = WBCPU_FLASH_BASEADDR + (1 << `FCOLUMNS);
+parameter WBCPU_PAGE_OFFSET_BASEADDR = WBCPU_REG_BASEADDR + `WB_PAGE_OFFSET_OFF;
+parameter WBCPU_SPARE_SPACE_WR_BASEADDR = WBCPU_REG_BASEADDR + `WB_SPARE_SPACE_WR_OFF;
+parameter WBCPU_SPARE_SPACE_RD_BASEADDR = WBCPU_REG_BASEADDR + `WB_SPARE_SPACE_RD_OFF;
+parameter WBCPU_ERASE_BASEADDR = WBCPU_REG_BASEADDR + `WB_ERASE_OFF;
+parameter WBCPU_STATUS_BASEADDR = WBCPU_REG_BASEADDR + `WB_STATUS_OFF;
+parameter WBCPU_WRITE_BASEADDR = WBCPU_REG_BASEADDR + `WB_WRITE_OFF;
+parameter WBCPU_READ_BASEADDR = WBCPU_REG_BASEADDR + `WB_READ_OFF;
+
+// Wishbone addreses on the NANDC bus
+parameter WB_FLASH_HIGHADDR = WB_FLASH_BASEADDR + (WB_FLASH_N << (`FPAGES + `FCOLUMNS));
+parameter WB_FLASH_N_BASEADDR = 0;
+parameter WB_FLASH_N_HIGHADDR = WB_FLASH_N << (`FPAGES + `FCOLUMNS);
+parameter WB_PAGE_OFFSET_BASEADDR = WB_REG_BASEADDR + `WB_PAGE_OFFSET_OFF;
+parameter WB_SPARE_SPACE_WR_BASEADDR = WB_REG_BASEADDR + `WB_SPARE_SPACE_WR_OFF;
+parameter WB_SPARE_SPACE_RD_BASEADDR = WB_REG_BASEADDR + `WB_SPARE_SPACE_RD_OFF;
+parameter WB_ERASE_BASEADDR = WB_REG_BASEADDR + `WB_ERASE_OFF;
+parameter WB_STATUS_BASEADDR = WB_REG_BASEADDR + `WB_STATUS_OFF;
+
+reg [31:0] data_i;
+reg valid_i, sof_i, eof_i;
+wire [31:0] data_o;
+wire valid_o, sof_o, eof_o;
+wire [23:0] ecc_o;
+
+hamm_4096x1_512x32 hamm_4096x1_512x32 (
+ .clk ( wb_clk ),
+ .rst ( wb_rst ),
+ .data_i ( data_i ),
+ .valid_i ( valid_i ),
+ .sof_i ( sof_i ),
+ .eof_i ( eof_i ),
+ .data_o ( data_o ),
+ .valid_o ( valid_o ),
+ .sof_o ( sof_o ),
+ .eof_o ( eof_o ),
+ .ecc_o ( ecc_o )
+);
+
+reg a_wr;
+reg [`FCOLUMNS-2:0] a_addr;
+reg [31:0] a_din;
+wire [31:0] a_dout;
+reg b_wr;
+reg [`FCOLUMNS-2:0] b_addr;
+wire [31:0] b_dout;
+
+parameter [4:0] ST_IDLE = \'d0,
+ ST_IDLE_0 = \'d1,
+ ST_ERASE = \'d2,
+ ST_STATUS = \'d3,
+ ST_WBWRITE = \'d4,
+ ST_WBWRITE_0 = \'d5,
+ ST_WBWRITE_1 = \'d6,
+ ST_WBWRITE_2 = \'d7,
+ ST_WBWRITE_3 = \'d8,
+ ST_WBWRITE_4 = \'d9,
+ ST_WBWRITE_5 = \'d10,
+ ST_WBREAD = \'d11,
+ ST_WBREAD_0 = \'d12,
+ ST_WBREAD_1 = \'d13,
+ ST_WBREAD_2 = \'d14,
+ ST_WBREAD_3 = \'d15,
+ ST_WBREAD_4 = \'d16;
+
+reg page_offset;
+reg [63:0] spare_space_wr, spare_space_rd;
+reg [23:0] spare_space_ecc, spare_space_ecc_cmp;
+reg spare_space_erased;
+reg [1:0] ecc_addr;
+reg [23:0] ecc0, ecc1, ecc2, ecc3;
+reg [23:0] ecc0_cmp, ecc1_cmp, ecc2_cmp, ecc3_cmp;
+reg [7:0] i;
+reg [31:0] data, addr;
+reg [13:0] fix_bit;
+reg ready;
+reg status;
+reg [4:0] hstate;
+
+always @(posedge wb_clk) begin
+ if(wb_rst) begin
+ wbs_dat_o_r <= \'h0;
+ wbm_cti_o <= WB_CTI_CLASSIC;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_adr_o <= \'h0;
+ wbm_dat_o_r <= \'h0;
+ wbm_sel_o <= \'h0;
+ wbm_cyc_o <= 0;
+ wbm_stb_o <= 0;
+ wbm_we_o <= 0;
+ page_offset <= 0;
+ spare_space_wr <= \'h0;
+ spare_space_rd <= \'h0;
+ spare_space_ecc <= \'h0;
+ spare_space_ecc_cmp <= \'h0;
+ spare_space_erased <= 0;
+ ecc_addr <= \'h0;
+ ecc0 <= \'h0;
+ ecc1 <= \'h0;
+ ecc2 <= \'h0;
+ ecc3 <= \'h0;
+ ecc0_cmp <= \'h0;
+ ecc1_cmp <= \'h0;
+ ecc2_cmp <= \'h0;
+ ecc3_cmp <= \'h0;
+ i <= \'h0;
+ data <= \'h0;
+ fix_bit <= \'h0;
+ ready <= 1;
+ status <= 0;
+ hstate <= ST_IDLE;
+ end else begin
+ case(hstate)
+ ST_IDLE: begin
+ wbm_cti_o <= WB_CTI_CLASSIC;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_adr_o <= \'h0;
+ wbm_dat_o_r <= \'h0;
+ wbm_sel_o <= \'h0;
+ wbm_stb_o <= 0;
+ wbm_we_o <= 0;
+ valid_i <= 0;
+ sof_i <= 0;
+ eof_i <= 0;
+ i <= \'h0;
+ data <= \'h0;
+ ready <= 1;
+ hstate <= ST_IDLE_0;
+ end
+ ST_IDLE_0: begin
+ if(valid) begin
+ if(wbs_we_i & wbs_ack_o) begin
+ case(adr_r)
+ // set ECC controller registers
+ WBCPU_PAGE_OFFSET_BASEADDR: begin
+ page_offset <= wbs_dat_i[0];
+ hstate <= ST_IDLE;
+ end
+ WBCPU_SPARE_SPACE_WR_BASEADDR + \'h0: begin
+ spare_space_wr[31:0] <= wbs_dat_i;
+ hstate <= ST_IDLE;
+ end
+ WBCPU_SPARE_SPACE_WR_BASEADDR + \'h4: begin
+ spare_space_wr[63:32] <= wbs_dat_i;
+ hstate <= ST_IDLE;
+ end
+ WBCPU_ERASE_BASEADDR: begin
+ // make sure we\'re erasing a block in our range
+ if(wbs_dat_i < WB_FLASH_N) begin
+ // offset erase by WB_FLASH_S
+ wbm_dat_o_r <= wbs_dat_i + WB_FLASH_S;
+ ready <= 0;
+ hstate <= ST_ERASE;
+ end else begin
+ hstate <= ST_IDLE;
+ end
+ end
+ WBCPU_STATUS_BASEADDR: begin
+ ready <= 0;
+ hstate <= ST_STATUS;
+ end
+ // handle flash read requests within our address boundary
+ WBCPU_READ_BASEADDR: begin
+ if((wbs_dat_i >= WB_FLASH_N_BASEADDR) && (wbs_dat_i <= WB_FLASH_N_HIGHADDR)) begin
+ // if we\'re reading from the correct range, then construct new address offset by WB_FLASH_S
+ wbm_adr_o <= {wbs_dat_i[31:`FALL+1], wbs_dat_i[`FALL-1:`FCOLUMNS], {`FCOLUMNS+1{1\'b0}}} + {WB_FLASH_S, {`FCOLUMNS + `FPAGES + 1{1\'b0}}};
+ ready <= 0;
+ hstate <= ST_WBREAD;
+ end else begin
+ hstate <= ST_IDLE;
+ end
+ end
+ // handle flash write requests within our address boundary
+ WBCPU_WRITE_BASEADDR: begin
+ if((wbs_dat_i >= WB_FLASH_N_BASEADDR) && (wbs_dat_i <= WB_FLASH_N_HIGHADDR) &&
+ // don\'t allow the user to write when page_offset is set
+ !page_offset) begin
+ // if we\'re writing to the correct range, then construct new address offset by WB_FLASH_S
+ wbm_adr_o <= {wbs_dat_i[31:`FALL+1], wbs_dat_i[`FALL-1:`FCOLUMNS], {`FCOLUMNS+1{1\'b0}}} + {WB_FLASH_S, {`FCOLUMNS + `FPAGES + 1{1\'b0}}};
+ ready <= 0;
+ hstate <= ST_WBWRITE;
+ end else begin
+ hstate <= ST_IDLE;
+ end
+ end
+ endcase
+ end else if(!wbs_we_i) begin
+ case(adr)
+ // read back ECC controller registers
+ WBCPU_PAGE_OFFSET_BASEADDR: begin
+ wbs_dat_o_r <= {31\'h0, page_offset};
+ hstate <= ST_IDLE;
+ end
+ WBCPU_SPARE_SPACE_WR_BASEADDR + \'h0: begin
+ wbs_dat_o_r <= spare_space_wr[31:0];
+ hstate <= ST_IDLE;
+ end
+ WBCPU_SPARE_SPACE_WR_BASEADDR + \'h4: begin
+ wbs_dat_o_r <= spare_space_wr[63:32];
+ hstate <= ST_IDLE;
+ end
+ WBCPU_SPARE_SPACE_RD_BASEADDR + \'h0: begin
+ wbs_dat_o_r <= spare_space_erased ? 32\'hffffffff : spare_space_rd[31:0];
+ hstate <= ST_IDLE;
+ end
+ WBCPU_SPARE_SPACE_RD_BASEADDR + \'h4: begin
+ wbs_dat_o_r <= spare_space_erased ? 32\'hffffffff : spare_space_rd[63:32];
+ hstate <= ST_IDLE;
+ end
+ WBCPU_STATUS_BASEADDR: begin
+ wbs_dat_o_r <= {30\'h0, status, ready};
+ hstate <= ST_IDLE;
+ end
+ endcase
+ end
+ end
+ end
+
+
+ //
+ // ERASE FORWARD
+ //
+ // forward this transaction until we get an ack
+ ST_ERASE: begin
+ if(!wbm_ack_i) begin
+ wbm_cti_o <= WB_CTI_CLASSIC;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_adr_o <= WB_ERASE_BASEADDR;
+ wbm_sel_o <= 1;
+ wbm_cyc_o <= 1;
+ wbm_stb_o <= 1;
+ wbm_we_o <= 1;
+ end else begin
+ wbm_cti_o <= WB_CTI_CLASSIC;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_adr_o <= \'h0;
+ wbm_dat_o_r <= \'h0;
+ wbm_sel_o <= \'h0;
+ wbm_cyc_o <= 0;
+ wbm_stb_o <= 0;
+ wbm_we_o <= 0;
+
+ hstate <= ST_IDLE;
+ end
+ end
+
+
+ //
+ // STATUS FORWARD
+ //
+ // forward this transaction until we get an ack
+ ST_STATUS: begin
+ if(!wbm_ack_i) begin
+ wbm_cti_o <= WB_CTI_CLASSIC;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_adr_o <= WB_STATUS_BASEADDR;
+ wbm_sel_o <= 1;
+ wbm_cyc_o <= 1;
+ wbm_stb_o <= 1;
+ wbm_we_o <= 0;
+ end else begin
+ wbm_cti_o <= WB_CTI_CLASSIC;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_adr_o <= \'h0;
+ wbm_dat_o_r <= \'h0;
+ wbm_sel_o <= \'h0;
+ wbm_cyc_o <= 0;
+ wbm_stb_o <= 0;
+ wbm_we_o <= 0;
+ status <= wbm_dat_i[0];
+
+ hstate <= ST_IDLE;
+ end
+ end
+
+
+ //
+ // WRITE WITH ECC
+ //
+ // forward this transaction to the slave and compute and add ecc while we\'re doing it
+ ST_WBWRITE: begin
+ // insert dummy cycle to read data from BRAM buffer
+ hstate <= ST_WBWRITE_0;
+ end
+ ST_WBWRITE_0: begin
+ wbm_cti_o <= WB_CTI_INCR_BURST;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_sel_o <= \'b1111;
+ wbm_cyc_o <= 1;
+ wbm_we_o <= 1;
+
+ if(wbm_ack_i) begin
+ // drop strobe when we have an ack
+ wbm_stb_o <= 0;
+ wbm_adr_o <= wbm_adr_o + \'h4;
+ data_i <= wbm_dat_o;
+ valid_i <= 1;
+ sof_i <= wbm_adr_o[8:2] == {9-2{1\'b0}};
+ eof_i <= wbm_adr_o[8:2] == {9-2{1\'b1}};
+ ecc_addr <= wbm_adr_o[10:9];
+
+ // if we\'re in the last word of our 512-byte block then save ECC
+ if((wbm_adr_o[8:2] == {9-2{1\'b1}}))
+ hstate <= ST_WBWRITE_1;
+ end else begin
+ // otherwise keep strobe high
+ wbm_stb_o <= 1;
+ valid_i <= 0;
+ sof_i <= 0;
+ eof_i <= 0;
+ end
+ end
+ ST_WBWRITE_1: begin
+ valid_i <= 0;
+ sof_i <= 0;
+ eof_i <= 0;
+ if(eof_o) begin
+ case(ecc_addr)
+ 0: ecc0 <= ecc_o;
+ 1: ecc1 <= ecc_o;
+ 2: ecc2 <= ecc_o;
+ 3: ecc3 <= ecc_o;
+ endcase
+ // if we\'re in the last 512-byte block, then also write ecc, spare_space, and spare_space_ecc
+ if(ecc_addr == 3) begin
+ hstate <= ST_WBWRITE_2;
+ // if we\'re not in the last 512-byte block, then ack and return to idle state
+ end else begin
+ hstate <= ST_WBWRITE_0;
+ end
+ end
+ end
+ ST_WBWRITE_2: begin
+ data_i <= spare_space_wr[31:0];
+ valid_i <= 1;
+ sof_i <= 1;
+ eof_i <= 0;
+ hstate <= ST_WBWRITE_3;
+ end
+ ST_WBWRITE_3: begin
+ data_i <= spare_space_wr[63:32];
+ valid_i <= 1;
+ sof_i <= 0;
+ eof_i <= 1;
+ hstate <= ST_WBWRITE_4;
+ end
+ ST_WBWRITE_4: begin
+ data_i <= \'h0;
+ valid_i <= 0;
+ sof_i <= 0;
+ eof_i <= 0;
+ if(eof_o) begin
+ wbm_adr_o <= wbm_adr_o + \'h4;
+ spare_space_ecc <= ecc_o;
+ i <= 0;
+ hstate <= ST_WBWRITE_5;
+ end
+ end
+ ST_WBWRITE_5: begin
+ case(wbm_ack_i ? i + \'h1 : i)
+ 0: wbm_dat_o_r <= {ecc1[7:0], ecc0[23:0]};
+ 1: wbm_dat_o_r <= {ecc2[15:0], ecc1[23:8]};
+ 2: wbm_dat_o_r <= {ecc3[23:0], ecc2[23:16]};
+ 3: wbm_dat_o_r <= {spare_space_wr[31:0]};
+ 4: wbm_dat_o_r <= {spare_space_wr[63:32]};
+ 5: wbm_dat_o_r <= {20\'h0, spare_space_ecc[17:12], spare_space_ecc[5:0]};
+ endcase
+
+ wbm_cti_o <= i == 5 ? WB_CTI_EOB : WB_CTI_INCR_BURST;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_sel_o <= \'b1111;
+ wbm_cyc_o <= 1;
+ wbm_stb_o <= 1;
+ wbm_we_o <= 1;
+
+ if(wbm_ack_i) begin
+ wbm_adr_o <= wbm_adr_o + \'h4;
+ if(i >= 5) begin
+ wbm_cyc_o <= 0;
+ hstate <= ST_IDLE;
+ end else
+ i <= i + 1;
+ end
+ end
+
+
+ //
+ // READ WITH ECC
+ //
+ ST_WBREAD: begin
+ // start read from address 0 of the selected page
+ hstate <= ST_WBREAD_0;
+ end
+ // perform read cycle
+ ST_WBREAD_0, ST_WBREAD_1: begin if(ST_WBREAD_0) begin
+ wbm_cti_o <= addr_page_end(wbm_adr_o) ? WB_CTI_EOB : WB_CTI_INCR_BURST;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_sel_o <= \'b1111;
+ wbm_cyc_o <= 1;
+ wbm_stb_o <= 1;
+ wbm_we_o <= 0;
+
+ if(wbm_ack_i) begin
+ // calculate ECC on read data
+ data_i <= wbm_dat_i;
+ valid_i <= !wbm_adr_o[`FCOLUMNS] || (wbm_adr_o[5:2] == 3) || (wbm_adr_o[5:2] == 4);
+ sof_i <= (!wbm_adr_o[`FCOLUMNS] && (wbm_adr_o[8:2] == {9-2{1\'b0}})) || (wbm_adr_o[`FCOLUMNS] && wbm_adr_o[5:2] == 3);
+ eof_i <= (!wbm_adr_o[`FCOLUMNS] && (wbm_adr_o[8:2] == {9-2{1\'b1}})) || (wbm_adr_o[`FCOLUMNS] && wbm_adr_o[5:2] == 4);
+
+ if(wbm_adr_o[`FCOLUMNS]) begin
+ case(wbm_adr_o[5:2])
+ 0: begin
+ ecc0_cmp[23:0] <= wbm_dat_i[23:0];
+ ecc1_cmp[7:0] <= wbm_dat_i[31:24];
+ end
+ 1: begin
+ ecc1_cmp[23:8] <= wbm_dat_i[15:0];
+ ecc2_cmp[15:0] <= wbm_dat_i[31:16];
+ end
+ 2: begin
+ ecc2_cmp[23:16] <= wbm_dat_i[7:0];
+ ecc3_cmp[23:0] <= wbm_dat_i[31:8];
+ end
+ 3: spare_space_rd[31:0] <= wbm_dat_i;
+ 4: spare_space_rd[63:32] <= wbm_dat_i;
+ 5: begin
+ spare_space_erased <= |wbm_dat_i[31:12];
+ spare_space_ecc_cmp[23:0] <= {6\'h0, wbm_dat_i[11:6], 6\'h0, wbm_dat_i[5:0]};
+ end
+ endcase
+ end
+
+ if(addr_page_end(wbm_adr_o))
+ hstate <= ST_WBREAD_1;
+ else begin
+ wbm_adr_o <= wbm_adr_o + \'h4;
+ end
+ end else begin
+ valid_i <= 0;
+ sof_i <= 0;
+ eof_i <= 0;
+ end
+ end
+
+ // save ecc and keep looping if we haven\'t gotten the full page yet
+ if(eof_o) begin
+ case({wbm_adr_o[2], wbm_adr_o[`FCOLUMNS:9]})
+ 1: ecc0 <= ecc_o;
+ 2: ecc1 <= ecc_o;
+ 3: ecc2 <= ecc_o;
+ 4: ecc3 <= ecc_o;
+ 12: spare_space_ecc <= ecc_o;
+ endcase
+ end
+ if(hstate == ST_WBREAD_1) begin
+ wbm_cti_o <= WB_CTI_CLASSIC;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_adr_o <= \'h0;
+ wbm_sel_o <= \'b0000;
+ wbm_cyc_o <= 0;
+ wbm_stb_o <= 0;
+ wbm_we_o <= 0;
+ hstate <= ST_WBREAD_2;
+ end
+ end
+ // done reading full page, now fix bits
+ ST_WBREAD_2: begin
+ casez({ecc_err(spare_space_ecc, spare_space_ecc_cmp),
+ ecc_err(ecc3, ecc3_cmp),
+ ecc_err(ecc2, ecc2_cmp),
+ ecc_err(ecc1, ecc1_cmp),
+ ecc_err(ecc0, ecc0_cmp)})
+ 5\'bzzzz1: begin
+ fix_bit <= {2\'h0, ecc_bit_pos(ecc0, ecc0_cmp)};
+ ecc0_cmp <= ecc0;
+ $display(""fixing bit %d"", ecc_bit_pos(ecc0, ecc0_cmp));
+ hstate <= ST_WBREAD_3;
+ end
+ 5\'bzzz10: begin
+ fix_bit <= {2\'h1, ecc_bit_pos(ecc1, ecc1_cmp)};
+ ecc1_cmp <= ecc1;
+ $display(""fixing bit %d"", ecc_bit_pos(ecc1, ecc1_cmp) + 2048);
+ hstate <= ST_WBREAD_3;
+ end
+ 5\'bzz100: begin
+ fix_bit <= {2\'h2, ecc_bit_pos(ecc2, ecc2_cmp)};
+ ecc2_cmp <= ecc2;
+ $display(""fixing bit %d"", ecc_bit_pos(ecc2, ecc2_cmp) + 4096);
+ hstate <= ST_WBREAD_3;
+ end
+ 5\'bz1000: begin
+ fix_bit <= {2\'h3, ecc_bit_pos(ecc3, ecc2_cmp)};
+ ecc3_cmp <= ecc3;
+ $display(""fixing bit %d"", ecc_bit_pos(ecc3, ecc3_cmp) + 6144);
+ hstate <= ST_WBREAD_3;
+ end
+ 5\'b10000: begin
+ spare_space_rd[ecc_bit_pos(spare_space_ecc, spare_space_ecc_cmp)] <=
+ !spare_space_rd[ecc_bit_pos(spare_space_ecc, spare_space_ecc_cmp)];
+ $display(""fixing spare_space bit %d"", ecc_bit_pos(spare_space_ecc, spare_space_ecc_cmp));
+ hstate <= ST_IDLE;
+ end
+ default: begin
+ hstate <= ST_IDLE;
+ end
+ endcase
+ end
+ // to fix the bit error, first read from the bram
+ ST_WBREAD_3: begin
+ hstate <= ST_WBREAD_4;
+ end
+ // then fix it!
+ ST_WBREAD_4: begin
+ hstate <= ST_WBREAD_2;
+ end
+ endcase
+ end
+end
+
+
+//
+// Scratch BRAM
+//
+nand_bram_block_dp #(
+ .DATA ( 32 ),
+ .ADDR ( `FCOLUMNS - 1 ),
+ .DEPTH ( `FCOLUMNS_AND_SPARE / 4 )
+) nand_bram_block_dp (
+ .a_clk ( wb_clk ),
+ .a_wr ( a_wr ),
+ .a_addr ( a_addr ),
+ .a_din ( a_din ),
+ .a_dout ( a_dout ),
+ .b_clk ( wb_clk ),
+ .b_wr ( 1\'b0 ), // read only port
+ .b_addr ( b_addr ),
+ .b_din ( \'h0 ),
+ .b_dout ( b_dout )
+);
+
+always @(*) begin
+ if(wb_rst) begin
+ a_wr <= 0;
+ a_addr <= \'h0;
+ a_din <= \'h0;
+ b_addr <= \'h0;
+ end else begin
+ // handle write to bram from wishbone bus
+ if((hstate == ST_IDLE_0) & ram_we & (adr_r >= WBCPU_FLASH_BASEADDR) & (adr_r <= WBCPU_FLASH_HIGHADDR)) begin
+ a_addr <= adr_r[`FCOLUMNS-1:2];
+ a_wr <= 1;
+ a_din <= wbs_dat_i;
+ // handle read from bram to wishbone bus
+ end else if((hstate == ST_IDLE_0) & valid & (adr >= WBCPU_FLASH_BASEADDR) & (adr <= WBCPU_FLASH_HIGHADDR)) begin
+ a_addr <= adr[`FCOLUMNS-1:2];
+ a_wr <= 0;
+ end else if((hstate == ST_WBREAD_0) & wbm_ack_i & (wbm_adr_o[`FCOLUMNS:2] < (`FCOLUMNS_AND_SPARE/4))) begin
+ a_wr <= 1;
+ a_addr <= wbm_adr_o[`FCOLUMNS:2];
+ a_din <= wbm_dat_i;
+ end else if(hstate == ST_WBREAD_4) begin
+ a_wr <= 1;
+ a_addr <= fix_bit[13:5];
+ a_din <= b_dout ^ (1\'b1 << fix_bit[4:0]);
+ end else begin
+ a_wr <= 0;
+ a_addr <= \'h0;
+ a_din <= \'h0;
+ end
+
+ // return data for reads from bram on same clock cycle to wishbone bus
+ if((hstate == ST_IDLE_0) & valid & (adr_r >= WBCPU_FLASH_BASEADDR) & (adr_r <= WBCPU_FLASH_HIGHADDR)) begin
+ wbs_dat_o <= a_dout;
+ end else if(valid & !wbs_we_i & (adr == WBCPU_STATUS_BASEADDR)) begin
+ wbs_dat_o <= {30\'h0, status, ready};
+ end else
+ wbs_dat_o <= wbs_dat_o_r;
+
+ if((hstate == ST_WBWRITE) || (hstate == ST_WBWRITE_0)) begin
+ b_addr <= wbm_adr_o[`FCOLUMNS-1:2];
+ end else if(hstate == ST_WBREAD) begin
+ b_addr <= {page_offset, wbs_adr_i[`FCOLUMNS-1:2]};
+ end else if(hstate == ST_WBREAD_3) begin
+ b_addr <= fix_bit[13:5];
+ end else if(hstate == ST_WBREAD_2) begin
+ b_addr <= {page_offset, wbs_adr_i[`FCOLUMNS-1:2]};
+ end else
+ b_addr <= \'h0;
+
+ // return data to NANDC wishbone bus when issuing writes directly from BRAM
+ if(hstate == ST_WBWRITE_0) begin
+ wbm_dat_o <= b_dout;
+ end else begin
+ wbm_dat_o <= wbm_dat_o_r;
+ end
+ end
+end
+
+
+
+//
+// FUNCTIONS
+//
+
+// return true if there\'s 1 bit error
+function ecc_err;
+input [23:0] a;
+input [23:0] b;
+begin
+ ecc_err = (a[11:0] ^ a[23:12] ^ b[11:0] ^ b[23:12]) == {12{1\'b1}};
+end
+endfunction
+
+// return position of bit error
+function [11:0] ecc_bit_pos;
+input [23:0] a;
+input [23:0] b;
+begin
+ ecc_bit_pos = a[23:12] ^ b[23:12];
+end
+endfunction
+
+
+endmodule
+"
+"/*\r
+ Copyright 2015, Google Inc.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the ""License"");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an ""AS IS"" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+module ftl_bram_block_dp #(\r
+ parameter DATA = 32,\r
+ parameter ADDR = 7\r
+) (\r
+ input wire a_clk,\r
+ input wire a_wr,\r
+ input wire [ADDR-1:0] a_addr,\r
+ input wire [DATA-1:0] a_din,\r
+ output reg [DATA-1:0] a_dout,\r
+ \r
+ input wire b_clk,\r
+ input wire b_wr,\r
+ input wire [ADDR-1:0] b_addr,\r
+ input wire [DATA-1:0] b_din,\r
+ output reg [DATA-1:0] b_dout\r
+);\r
+\r
+reg [DATA-1:0] mem [(2**ADDR)-1:0];\r
+ \r
+always @(posedge a_clk) begin\r
+ if(a_wr) begin\r
+ a_dout <= a_din;\r
+ mem[a_addr] <= a_din;\r
+ end else\r
+\ta_dout <= mem[a_addr];\r
+end\r
+ \r
+always @(posedge b_clk) begin\r
+ if(b_wr) begin\r
+ b_dout <= b_din;\r
+ mem[b_addr] <= b_din;\r
+ end else\r
+\tb_dout <= mem[b_addr];\r
+end\r
+\r
+endmodule\r
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 16:08:02 02/13/2015
+// Design Name: aes_core
+// Project Name: crypto_aes
+// Target Device:
+// Tool versions:
+// Description:
+//
+// Verilog Test Fixture created by ISE for module: aes_core
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+////////////////////////////////////////////////////////////////////////////////
+
+module aes_core_tb;
+
+\t// Inputs
+\treg clk;
+\treg load_i;
+\treg [255:0] key_i;
+\treg [127:0] data_i;
+\treg [1:0] size_i;
+\treg dec_i;
+
+\t// Outputs
+\twire [127:0] data_o;
+\twire busy_o;
+
+\treg [127:0] pt;
+\treg [127:0] ct;
+\t
+\t// Instantiate the Unit Under Test (UUT)
+\taes_core uut (
+\t\t.clk(clk),
+\t\t.load_i(load_i),
+\t\t.key_i(key_i),
+\t\t.data_i(data_i),
+\t\t.size_i(size_i),
+\t\t.dec_i(dec_i),
+\t\t.data_o(data_o),
+\t\t.busy_o(busy_o)
+\t);
+
+\tinitial begin
+\t\t// Initialize Inputs
+\t\tclk = 0;
+\t\tload_i = 0;
+\t\tkey_i = 0;
+\t\tdata_i = 0;
+\t\tsize_i = 0;
+\t\tdec_i = 0;
+
+\t\t// Wait 100 ns for global reset to finish
+\t\t#100;
+
+\t\t// Add stimulus here
+\t\tsize_i = 2\'b00;\t
+\t\tkey_i[255:128] = 128\'h00_01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f;
+\t\tpt = 128\'h00_11_22_33_44_55_66_77_88_99_aa_bb_cc_dd_ee_ff;
+\t\tct = 128\'h69_c4_e0_d8_6a_7b_04_30_d8_cd_b7_80_70_b4_c5_5a;
+\t\t
+\t\tdec_i = 0;
+\t\tdata_i = pt;
+\t\tload_i = 1;
+\t\twhile(!busy_o) #1;
+\t\tload_i = 0;
+\t\twhile(busy_o) #1;
+\t\t
+\t\tif(data_o != ct)
+\t\tbegin
+\t\t\t$display(""AES 128 encrypt failed"");
+\t\t\t$stop;
+\t\tend
+\t\t
+\t\tdec_i = 1;
+\t\tdata_i = ct;
+\t\tload_i = 1;
+\t\twhile(!busy_o) #1;
+\t\tload_i = 0;
+\t\twhile(busy_o) #1;
+\t\t
+\t\tif(data_o != pt)
+\t\tbegin
+\t\t\t$display(""AES 128 decrypt failed"");
+\t\t\t$stop;
+\t\tend
+
+\t\tsize_i = 2\'b01;\t
+\t\tkey_i[255:64] = 192\'h00_01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f_10_11_12_13_14_15_16_17;
+\t\tpt = 128\'h00_11_22_33_44_55_66_77_88_99_aa_bb_cc_dd_ee_ff;
+\t\tct = 128\'hdd_a9_7c_a4_86_4c_df_e0_6e_af_70_a0_ec_0d_71_91;
+\t\t
+\t\tdec_i = 0;
+\t\tdata_i = pt;
+\t\tload_i = 1;
+\t\twhile(!busy_o) #1;
+\t\tload_i = 0;
+\t\twhile(busy_o) #1;
+\t\t
+\t\tif(data_o != ct)
+\t\tbegin
+\t\t\t$display(""AES 192 encrypt failed"");
+\t\t\t$stop;
+\t\tend
+
+\t\tdec_i = 1;
+\t\tdata_i = ct;
+\t\tload_i = 1;
+\t\twhile(!busy_o) #1;
+\t\tload_i = 0;
+\t\twhile(busy_o) #1;
+\t\t
+\t\tif(data_o != pt)
+\t\tbegin
+\t\t\t$display(""AES 192 decrypt failed"");
+\t\t\t$stop;
+\t\tend
+
+\t\tsize_i = 2\'b10;\t
+\t\tkey_i[255:0] = 256\'h00_01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f_10_11_12_13_14_15_16_17_18_19_1a_1b_1c_1d_1e_1f;
+\t\tpt = 128\'h00_11_22_33_44_55_66_77_88_99_aa_bb_cc_dd_ee_ff;
+\t\tct = 128\'h8e_a2_b7_ca_51_67_45_bf_ea_fc_49_90_4b_49_60_89;
+\t\t
+\t\tdec_i = 0;
+\t\tdata_i = pt;
+\t\tload_i = 1;
+\t\twhile(!busy_o) #1;
+\t\tload_i = 0;
+\t\twhile(busy_o) #1;
+\t\t
+\t\tif(data_o != ct)
+\t\tbegin
+\t\t\t$display(""AES 256 encrypt failed"");
+\t\t\t$stop;
+\t\tend
+
+\t\tdec_i = 1;
+\t\tdata_i = ct;
+\t\tload_i = 1;
+\t\twhile(!busy_o) #1;
+\t\tload_i = 0;
+\t\twhile(busy_o) #1;
+\t\t
+\t\tif(data_o != pt)
+\t\tbegin
+\t\t\t$display(""AES 256 decrypt failed"");
+\t\t\t$stop;
+\t\tend
+
+\t\t$display(""AES core passed"");
+\t\t$finish;
+\tend
+
+always #10 clk <= ~clk;
+
+endmodule
+
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 00:50:45 02/08/2015
+// Design Name:
+// Module Name: aes_sbox
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module aes_sbox (
+\tinput [7:0] U,
+\tinput dec,
+\toutput reg [7:0] S
+);
+
+
+
+always @*
+begin : sbox_update
+
+\treg U0, U1, U2, U3, U4, U5, U6, U7;
+\treg S0, S1, S2, S3, S4, S5, S6, S7;
+\treg Y5;
+\treg T1, T2, T3, T4, T6, T8, T9, T10, T13, T14, T15, T16, T17, T19;
+\treg T20, T22, T23, T24, T25, T26, T27;
+\treg M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13, M14;
+\treg M15, M16, M17, M18, M19, M20, M21, M22, M23, M24, M25, M26, M27;
+\treg M28, M29, M30, M31, M32, M33, M34, M35, M36, M37, M38, M39, M40;
+\treg M41, M42, M43, M44, M45, M46, M47, M48, M49, M50, M51, M52, M53;
+\treg M54, M55, M56, M57, M58, M59, M60, M61, M62, M63;
+\t
+\t{ U0, U1, U2, U3, U4, U5, U6, U7 } = U;
+\t
+\tif(dec)
+\tbegin : decrypt_top
+\t\treg R5, R13, R17, R18, R19;
+\t\t
+\t\tT23 = U0 ^ U3;
+\t\tT22 = ~(U1 ^ U3);
+\t\tT2 = ~(U0 ^ U1);
+\t\tT1 = U3 ^ U4;
+\t\tT24 = ~(U4 ^ U7);
+\t\tR5 = U6 ^ U7;
+\t\tT8 = ~(U1 ^ T23);
+\t\tT19 = T22 ^ R5;
+\t\tT9 = ~(U7 ^ T1);
+\t\tT10 = T2 ^ T24;
+\t\tT13 = T2 ^ R5;
+\t\tT3 = T1 ^ R5;
+\t\tT25 = ~(U2 ^ T1);
+\t\tR13 = U1 ^ U6;
+\t\tT17 = ~(U2 ^ T19);
+\t\tT20 = T24 ^ R13;
+\t\tT4 = U4 ^ T8;
+\t\tR17 = ~(U2 ^ U5);
+\t\tR18 = ~(U5 ^ U6);
+\t\tR19 = ~(U2 ^ U4);
+\t\tY5 = U0 ^ R17;
+\t\tT6 = T22 ^ R17;
+\t\tT16 = R13 ^ R19;
+\t\tT27 = T1 ^ R18;
+\t\tT15 = T10 ^ T27;
+\t\tT14 = T10 ^ R18;
+\t\tT26 = T3 ^ T16;
+\tend
+\telse // !dec
+\tbegin : encrypt_top
+\t\treg T5, T7, T11, T12, T18, T21;
+\t\t
+\t\tT1 = U0 ^ U3; /* T1 = U0 + U3 */
+\t\tT2 = U0 ^ U5; /* T2 = U0 + U5 */
+\t\tT3 = U0 ^ U6; /* T3 = U0 + U6 */
+\t\tT4 = U3 ^ U5; /* T4 = U3 + U5 */
+\t\tT5 = U4 ^ U6; /* T5 = U4 + U6 */
+\t\tT6 = T1 ^ T5; /* T6 = T1 + T5 */
+\t\tT7 = U1 ^ U2; /* T7 = U1 + U2 */
+\t\tT8 = U7 ^ T6; /* T8 = U7 + T6 */
+\t\tT9 = U7 ^ T7; /* T9 = U7 + T7 */
+\t\tT10 = T6 ^ T7; /* T10 = T6 + T7 */
+\t\tT11 = U1 ^ U5; /* T11 = U1 + U5 */
+\t\tT12 = U2 ^ U5; /* T12 = U2 + U5 */
+\t\tT13 = T3 ^ T4; /* T13 = T3 + T4 */
+\t\tT14 = T6 ^ T11; /* T14 = T6 + T11 */
+\t\tT15 = T5 ^ T11; /* T15 = T5 + T11 */
+\t\tT16 = T5 ^ T12; /* T16 = T5 + T12 */
+\t\tT17 = T9 ^ T16; /* T17 = T9 + T16 */
+\t\tT18 = U3 ^ U7; /* T18 = U3 + U7 */
+\t\tT19 = T7 ^ T18; /* T19 = T7 + T18 */
+\t\tT20 = T1 ^ T19; /* T20 = T1 + T19 */
+\t\tT21 = U6 ^ U7; /* T21 = U6 + U7 */
+\t\tT22 = T7 ^ T21; /* T22 = T7 + T21 */
+\t\tT23 = T2 ^ T22; /* T23 = T2 + T22 */
+\t\tT24 = T2 ^ T10; /* T24 = T2 + T10 */
+\t\tT25 = T20 ^ T17; /* T25 = T20 + T17 */
+\t\tT26 = T3 ^ T16; /* T26 = T3 + T16 */
+\t\tT27 = T1 ^ T12; /* T27 = T1 + T12 */
+\t\tY5 = U7;
+\tend
+\t
+\tM1 = T13 & T6; /* M1 = T13 x T6 */
+\tM2 = T23 & T8; /* M2 = T23 x T8 */
+\tM3 = T14 ^ M1; /* M3 = T14 + M1 */
+\tM4 = T19 & Y5; /* M4 = T19 x Y5 */
+\tM5 = M4 ^ M1; /* M5 = M4 + M1 */
+\tM6 = T3 & T16; /* M6 = T3 x T16 */
+\tM7 = T22 & T9; /* M7 = T22 x T9 */
+\tM8 = T26 ^ M6; /* M8 = T26 + M6 */
+\tM9 = T20 & T17; /* M9 = T20 x T17 */
+\tM10 = M9 ^ M6; /* M10 = M9 + M6 */
+\tM11 = T1 & T15; /* M11 = T1 x T15 */
+\tM12 = T4 & T27; /* M12 = T4 x T27 */
+\tM13 = M12 ^ M11; /* M13 = M12 + M11 */
+\tM14 = T2 & T10; /* M14 = T2 x T10 */
+\tM15 = M14 ^ M11; /* M15 = M14 + M11 */
+\tM16 = M3 ^ M2; /* M16 = M3 + M2 */
+\tM17 = M5 ^ T24; /* M17 = M5 + T24 */
+\tM18 = M8 ^ M7; /* M18 = M8 + M7 */
+\tM19 = M10 ^ M15; /* M19 = M10 + M15 */
+\tM20 = M16 ^ M13; /* M20 = M16 + M13 */
+\tM21 = M17 ^ M15; /* M21 = M17 + M15 */
+\tM22 = M18 ^ M13; /* M22 = M18 + M13 */
+\tM23 = M19 ^ T25; /* M23 = M19 + T25 */
+\tM24 = M22 ^ M23; /* M24 = M22 + M23 */
+\tM25 = M22 & M20; /* M25 = M22 x M20 */
+\tM26 = M21 ^ M25; /* M26 = M21 + M25 */
+\tM27 = M20 ^ M21; /* M27 = M20 + M21 */
+\tM28 = M23 ^ M25; /* M28 = M23 + M25 */
+\tM29 = M28 & M27; /* M29 = M28 x M27 */
+\tM30 = M26 & M24; /* M30 = M26 x M24 */
+\tM31 = M20 & M23; /* M31 = M20 x M23 */
+\tM32 = M27 & M31; /* M32 = M27 x M31 */
+\tM33 = M27 ^ M25; /* M33 = M27 + M25 */
+\tM34 = M21 & M22; /* M34 = M21 x M22 */
+\tM35 = M24 & M34; /* M35 = M24 x M34 */
+\tM36 = M24 ^ M25; /* M36 = M24 + M25 */
+\tM37 = M21 ^ M29; /* M37 = M21 + M29 */
+\tM38 = M32 ^ M33; /* M38 = M32 + M33 */
+\tM39 = M23 ^ M30; /* M39 = M23 + M30 */
+\tM40 = M35 ^ M36; /* M40 = M35 + M36 */
+\tM41 = M38 ^ M40; /* M41 = M38 + M40 */
+\tM42 = M37 ^ M39; /* M42 = M37 + M39 */
+\tM43 = M37 ^ M38; /* M43 = M37 + M38 */
+\tM44 = M39 ^ M40; /* M44 = M39 + M40 */
+\tM45 = M42 ^ M41; /* M45 = M42 + M41 */
+\tM46 = M44 & T6; /* M46 = M44 x T6 */
+\tM47 = M40 & T8; /* M47 = M40 x T8 */
+\tM48 = M39 & Y5; /* M48 = M39 x Y5 */
+\tM49 = M43 & T16; /* M49 = M43 x T16 */
+\tM50 = M38 & T9; /* M50 = M38 x T9 */
+\tM51 = M37 & T17; /* M51 = M37 x T17 */
+\tM52 = M42 & T15; /* M52 = M42 x T15 */
+\tM53 = M45 & T27; /* M53 = M45 x T27 */
+\tM54 = M41 & T10; /* M54 = M41 x T10 */
+\tM55 = M44 & T13; /* M55 = M44 x T13 */
+\tM56 = M40 & T23; /* M56 = M40 x T23 */
+\tM57 = M39 & T19; /* M57 = M39 x T19 */
+\tM58 = M43 & T3; /* M58 = M43 x T3 */
+\tM59 = M38 & T22; /* M59 = M38 x T22 */
+\tM60 = M37 & T20; /* M60 = M37 x T20 */
+\tM61 = M42 & T1; /* M61 = M42 x T1 */
+\tM62 = M45 & T4; /* M62 = M45 x T4 */
+\tM63 = M41 & T2; /* M63 = M41 x T2 */
+
+\tif(dec)
+\tbegin : decrypt_bot
+\t\treg P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14;
+\t\treg P15, P16, P17, P18, P19, P20, P22, P23, P24, P25, P26, P27;
+\t\treg P28, P29;
+\t\t
+\t\tP0 = M52 ^ M61;
+\t\tP1 = M58 ^ M59;
+\t\tP2 = M54 ^ M62;
+\t\tP3 = M47 ^ M50;
+\t\tP4 = M48 ^ M56;
+\t\tP5 = M46 ^ M51;
+\t\tP6 = M49 ^ M60;
+\t\tP7 = P0 ^ P1;
+\t\tP8 = M50 ^ M53;
+\t\tP9 = M55 ^ M63;
+\t\tP10 = M57 ^ P4;
+\t\tP11 = P0 ^ P3;
+\t\tP12 = M46 ^ M48;
+\t\tP13 = M49 ^ M51;
+\t\tP14 = M49 ^ M62;
+\t\tP15 = M54 ^ M59;
+\t\tP16 = M57 ^ M61;
+\t\tP17 = M58 ^ P2;
+\t\tP18 = M63 ^ P5;
+\t\tP19 = P2 ^ P3;
+\t\tP20 = P4 ^ P6;
+\t\tP22 = P2 ^ P7;
+\t\tP23 = P7 ^ P8;
+\t\tP24 = P5 ^ P7;
+\t\tP25 = P6 ^ P10;
+\t\tP26 = P9 ^ P11;
+\t\tP27 = P10 ^ P18;
+\t\tP28 = P11 ^ P25;
+\t\tP29 = P15 ^ P20;
+
+\t\tS0 = P13 ^ P22;
+\t\tS1 = P26 ^ P29;
+\t\tS2 = P17 ^ P28;
+\t\tS3 = P12 ^ P22;
+\t\tS4 = P23 ^ P27;
+\t\tS5 = P19 ^ P24;
+\t\tS6 = P14 ^ P23;
+\t\tS7 = P9 ^ P16;
+\tend
+\telse // !dec
+\tbegin : encrypt_bot
+\t\treg L0, L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14;
+\t\treg L15, L16, L17, L18, L19, L20, L21, L22, L23, L24, L25, L26, L27;
+\t\treg L28, L29;
+\t\t\t\t\t
+\t\tL0 = M61 ^ M62; /* L0 = M61 + M62 */
+\t\tL1 = M50 ^ M56; /* L1 = M50 + M56 */
+\t\tL2 = M46 ^ M48; /* L2 = M46 + M48 */
+\t\tL3 = M47 ^ M55; /* L3 = M47 + M55 */
+\t\tL4 = M54 ^ M58; /* L4 = M54 + M58 */
+\t\tL5 = M49 ^ M61; /* L5 = M49 + M61 */
+\t\tL6 = M62 ^ L5; /* L6 = M62 + L5 */
+\t\tL7 = M46 ^ L3; /* L7 = M46 + L3 */
+\t\tL8 = M51 ^ M59; /* L8 = M51 + M59 */
+\t\tL9 = M52 ^ M53; /* L9 = M52 + M53 */
+\t\tL10 = M53 ^ L4; /* L10 = M53 + L4 */
+\t\tL11 = M60 ^ L2; /* L11 = M60 + L2 */
+\t\tL12 = M48 ^ M51; /* L12 = M48 + M51 */
+\t\tL13 = M50 ^ L0; /* L13 = M50 + L0 */
+\t\tL14 = M52 ^ M61; /* L14 = M52 + M61 */
+\t\tL15 = M55 ^ L1; /* L15 = M55 + L1 */
+\t\tL16 = M56 ^ L0; /* L16 = M56 + L0 */
+\t\tL17 = M57 ^ L1; /* L17 = M57 + L1 */
+\t\tL18 = M58 ^ L8; /* L18 = M58 + L8 */
+\t\tL19 = M63 ^ L4; /* L19 = M63 + L4 */
+\t\tL20 = L0 ^ L1; /* L20 = L0 + L1 */
+\t\tL21 = L1 ^ L7; /* L21 = L1 + L7 */
+\t\tL22 = L3 ^ L12; /* L22 = L3 + L12 */
+\t\tL23 = L18 ^ L2; /* L23 = L18 + L2 */
+\t\tL24 = L15 ^ L9; /* L24 = L15 + L9 */
+\t\tL25 = L6 ^ L10; /* L25 = L6 + L10 */
+\t\tL26 = L7 ^ L9; /* L26 = L7 + L9 */
+\t\tL27 = L8 ^ L10; /* L27 = L8 + L10 */
+\t\tL28 = L11 ^ L14; /* L28 = L11 + L14 */
+\t\tL29 = L11 ^ L17; /* L29 = L11 + L17 */
+
+\t\tS0 = L6 ^ L24; /* S0 = L6 + L24 */
+\t\tS1 = ~(L16 ^ L26); /* S1 = L16 # L26 */
+\t\tS2 = ~(L19 ^ L28); /* S2 = L19 # L28 */
+\t\tS3 = L6 ^ L21; /* S3 = L6 + L21 */
+\t\tS4 = L20 ^ L22; /* S4 = L20 + L22 */
+\t\tS5 = L25 ^ L29; /* S5 = L25 + L29 */
+\t\tS6 = ~(L13 ^ L27); /* S6 = L13 # L27 */
+\t\tS7 = ~(L6 ^ L23); /* S7 = L6 # L23 */
+\tend
+\t
+\tS = { S0, S1, S2, S3, S4, S5, S6, S7 };
+end
+
+endmodule
+"
+"/*\r
+ Copyright 2015, Google Inc.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the ""License"");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an ""AS IS"" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+module ftl_buf (\r
+ input wire clk_50,\r
+ input wire reset_n,\r
+\r
+ // port for ftl_wbs (external clock) (should be SDHC)\r
+ input wire bram_wbs_clk,\r
+ input wire [15:0] bram_wbs_addr,\r
+ input wire bram_wbs_wren,\r
+ input wire [31:0] bram_wbs_data,\r
+ output wire [31:0] bram_wbs_q,\r
+\r
+ // port to ftl_physical\r
+ input wire [15:0] bram_physical_addr,\r
+ input wire bram_physical_wren,\r
+ input wire [31:0] bram_physical_data,\r
+ output wire [31:0] bram_physical_q\r
+);\r
+\r
+`include ""ftl_const.vh""\r
+\r
+// 131072 byte bram (2^15=32768 x 32bit word)\r
+ftl_bram_block_dp #(32, 15) ifbram (\r
+ .a_clk ( bram_wbs_clk ),\r
+ .a_wr ( bram_wbs_wren ),\r
+ .a_addr ( bram_wbs_addr ),\r
+ .a_din ( bram_wbs_data ),\r
+ .a_dout ( bram_wbs_q ),\r
+ \r
+ .b_clk ( clk_50 ),\r
+ .b_wr ( bram_physical_wren ),\r
+ .b_addr ( bram_physical_addr ),\r
+ .b_din ( bram_physical_data ),\r
+ .b_dout ( bram_physical_q )\r
+);\r
+\r
+endmodule\r
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 13:58:16 05/13/2014
+// Design Name:
+// Module Name: crypto_aes_top
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module crypto_aes_top (
+\tinput core_clk,
+\t
+\tinput wb_clk_i,
+\tinput wb_rst_i,
+
+\tinput [31:0] wb_adr_i,
+\tinput [31:0] wb_dat_i,
+\tinput [3:0] wb_sel_i,
+\tinput wb_we_i,
+\tinput [1:0] wb_bte_i,
+\tinput [2:0] wb_cti_i,
+\tinput wb_cyc_i,
+\tinput wb_stb_i,
+
+\toutput wb_ack_o,
+\toutput wb_err_o,
+\toutput wb_rty_o,
+\toutput [31:0] wb_dat_o
+);
+
+wire [255:0] key_i;
+wire dec_i;
+wire [1:0] size_i;
+wire [127:0] data_i, data_o;
+wire load_clk1, busy_clk2;
+
+reg [1:0] busy_clk1_buf;
+reg [1:0] load_clk2_buf;
+wire busy_clk1 = busy_clk1_buf[1];
+wire load_clk2 = load_clk2_buf[1];
+
+wb_aes_ctrl wb_ctrl (
+\t// Wishbone slave
+\t.wb_clk_i(wb_clk_i),
+\t.wb_rst_i(wb_rst_i),
+\t.wb_adr_i(wb_adr_i),
+\t.wb_dat_i(wb_dat_i),
+\t.wb_sel_i(wb_sel_i),
+\t.wb_we_i(wb_we_i),
+\t.wb_bte_i(wb_bte_i),
+\t.wb_cti_i(wb_cti_i),
+\t.wb_cyc_i(wb_cyc_i),
+\t.wb_stb_i(wb_stb_i),
+\t.wb_ack_o(wb_ack_o),
+\t.wb_err_o(wb_err_o),
+\t.wb_rty_o(wb_rty_o),
+\t.wb_dat_o(wb_dat_o),
+\t// AES core
+\t.key_o(key_i),
+\t.dec_o(dec_i),
+\t.size_o(size_i),
+\t.data_o(data_i),
+\t.load_o(load_clk1),
+\t.data_i(data_o),
+\t.busy_i(busy_clk1)
+);
+
+always @(posedge wb_clk_i) busy_clk1_buf <= { busy_clk1_buf[0], busy_clk2 };
+always @(posedge core_clk) load_clk2_buf <= { load_clk2_buf[0], load_clk1 };
+
+aes_core aes (
+\t.clk(core_clk),
+\t.load_i(load_clk2),
+\t.dec_i(dec_i),
+\t.size_i(size_i),
+\t.data_i(data_i),
+\t.key_i(key_i),
+\t.data_o(data_o),
+\t.busy_o(busy_clk2)
+);
+
+endmodule
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+`include ""nandc_def.vh""
+
+//`define TEST_1BIT_ERROR
+//`define TEST_2BIT_ERROR
+
+//
+// WISHBONE NAND CONTROLLER
+//
+// Note: this controller is designed to have an wishbone ECC controller placed
+// in-line before it. This controller has a few restrictions for it\'s
+// direct master:
+//
+// 1. Reads and Writes to flash MUST start at 0 address in page
+// 2. They must always write a full page plus spare with ECC (2048+20 bytes)
+// 3. The address space of this controller lets you address the page_offset
+// (bit 11), the higher controller should remap to hide bit 11 and provide
+// access to spare space through other registers.
+//
+module nandc #(
+ // base offset on the wishbone bus that everything is located at
+ parameter WB_FLASH_BASEADDR = `WB_FLASH_BASEADDR,
+
+ // the offset to place wishbone registers at on the bus
+ parameter WB_REG_BASEADDR = `WB_REG_BASEADDR,
+
+ // the start block that this nand controller is able to address
+ parameter WB_FLASH_S = `WB_FLASH_S,
+
+ // the number of blocks this nand controller is able to address (out of 1024)
+ parameter WB_FLASH_N = `WB_FLASH_N,
+
+ // number of wbs_clk cycles that fit in a tRC cycle of the flash
+ parameter TRC = 2, // 10ns * 2 = 20ns > 12.5ns tRC/2
+ parameter TADL = 4, // 20ns * 4 = 80ns > 70ns tADL
+ parameter TWB = 5, // 20ns * 5 = 100ns > 100ns tWB
+ parameter TWHR = 3, // 20ns * 3 = 60ns == 60ns tWHR
+ parameter ADDR_CYC = 4 // 4 address cycles for this part
+) (
+ input wire wb_clk, // clock - bus clock
+ input wire wb_rst, // reset synchronous with wb_clk
+
+ input wire [2:0] wbs_cti_i, // type - cycle type identifier, supports either 000 ""Classic cycle"" or 010 ""Incrementing burst cycle""
+ input wire [1:0] wbs_bte_i, // exten - burst type extension, only supports 00 ""Linear burst""
+ input wire [31:0] wbs_adr_i, // addr - bus address
+ output reg [31:0] wbs_dat_o, // data - write data output
+ input wire [31:0] wbs_dat_i, // data - write data input
+ input wire [3:0] wbs_sel_i, // select - 8-bit enable for data bus
+ input wire wbs_cyc_i, // cycle - valid bus cycle is in progress
+ input wire wbs_stb_i, // strobe - slave is selected
+ input wire wbs_we_i, // write - bus cycle is in write mode
+ output reg wbs_ack_o, // ack - end of a normal bus cycle
+
+ input wire [7:0] IO_i, // io - data input from flash
+ output reg [7:0] IO_o, // io - data output to flash
+ output reg [7:0] IO_t, // io - data tristate control
+ output reg CLE, // cle - command latch enable
+ output reg ALE, // ale - address latch enable
+ output wire CE_n, // ce - chip enable
+ output wire WE_n, // we - write enable
+ output wire RE_n, // re - read enable
+ output wire WP_n, // wp - write protect enable
+ input wire RB_n // rb - read/busy signal from flash
+);
+
+`include ""nandc_const.vh""
+
+parameter WB_ERASE_BASEADDR = WB_REG_BASEADDR + `WB_ERASE_OFF;
+parameter WB_STATUS_BASEADDR = WB_REG_BASEADDR + `WB_STATUS_OFF;
+parameter WB_FLASH_HIGHADDR = WB_FLASH_BASEADDR + (WB_FLASH_N << (`FPAGES + `FCOLUMNS + 1));
+
+reg CE, WE, RE, WP;
+assign CE_n = !CE;
+assign WE_n = !WE;
+assign RE_n = !RE;
+assign WP_n = !WP;
+
+reg [2:0] RB_n_;
+always @(posedge wb_clk) RB_n_ <= {RB_n_[1:0], RB_n};
+wire RB = !RB_n_[2];
+
+reg [5:0] fstate, n_fstate, fstate_l;
+
+parameter [5:0] ST_RESET = \'d0,
+ ST_IDLE = \'d1,
+ ST_IDLE_0 = \'d2,
+ ST_WBWRITE = \'d3,
+ ST_WBWRITE_0 = \'d4,
+ ST_WBWRITE_1 = \'d5,
+ ST_WBWRITE_2 = \'d6,
+ ST_WBWRITE_3 = \'d7,
+ ST_WBWRITE_4 = \'d8,
+ ST_WBWRITE_5 = \'d9,
+ ST_WBWRITE_6 = \'d10,
+ ST_WBWRITE_7 = \'d11,
+ ST_WBREAD = \'d12,
+ ST_WBREAD_0 = \'d13,
+ ST_WBREAD_1 = \'d14,
+ ST_WBREAD_2 = \'d15,
+ ST_WBREAD_3 = \'d16,
+ ST_WBREAD_4 = \'d17,
+ ST_WBREAD_5 = \'d18,
+ ST_WBERASE = \'d19,
+ ST_WBERASE_0 = \'d20,
+ ST_WBERASE_1 = \'d21,
+ ST_WBERASE_2 = \'d22,
+ ST_WBERASE_3 = \'d23,
+ ST_WBSTATUS = \'d24,
+ ST_WBSTATUS_0 = \'d25,
+ ST_WBSTATUS_1 = \'d26,
+ ST_WBSTATUS_2 = \'d27,
+ ST_SYNC_CYCLE = \'d28,
+ ST_WE_TOGGLE = \'d29,
+ ST_RE_TOGGLE = \'d30;
+
+reg trc;
+reg [3:0] trc_state;
+reg [31:0] addr, addr_l;
+reg [31:0] data;
+reg [3:0] i;
+
+// read buffer for ECC
+reg [7:0] bram [2047:0];
+
+// change state
+`define state(now) \\
+ fstate <= now
+
+// change state and the next state
+`define next_state(now, next) \\
+ n_fstate <= next; \\
+ fstate <= now
+
+parameter IO_TRI = 8\'hff;
+parameter IO_DRIVE = 8\'h00;
+
+always @(posedge wb_clk) begin
+ if(wb_rst) begin
+ IO_o <= 0;
+ IO_t <= IO_TRI;
+ CLE <= 0;
+ ALE <= 0;
+ CE <= 0;
+ WE <= 0;
+ RE <= 0;
+ WP <= 0;
+ wbs_dat_o <= 0;
+ wbs_ack_o <= 0;
+ fstate <= ST_RESET;
+ n_fstate <= ST_RESET;
+ fstate_l <= ST_RESET;
+ trc <= 0;
+ trc_state <= \'h0;
+ addr <= \'h0;
+ addr_l <= ~\'h0;
+ data <= 0;
+ i <= 0;
+ end else begin
+ case(fstate)
+ ST_RESET: begin
+ IO_o <= 0;
+ IO_t <= IO_TRI;
+ CLE <= 0;
+ ALE <= 0;
+ CE <= 0;
+ WE <= 0;
+ RE <= 0;
+ WP <= 0;
+ fstate <= ST_IDLE;
+ n_fstate <= ST_IDLE;
+ fstate_l <= ST_IDLE;
+ addr <= \'h0;
+ addr_l <= \'h0;
+ i <= 0;
+ wbs_ack_o <= 0;
+ wbs_dat_o <= \'h0;
+ end
+ ST_IDLE: begin
+ i <= 0;
+ wbs_ack_o <= 0;
+ wbs_dat_o <= \'h0;
+ `state(ST_IDLE_0);
+ end
+ ST_IDLE_0: begin
+ if(wbs_cyc_i & wbs_stb_i) begin
+ if(wbs_we_i) begin
+ case(wbs_adr_i)
+ WB_ERASE_BASEADDR: `state(ST_WBERASE);
+ default: begin
+ if((wbs_adr_i >= WB_FLASH_BASEADDR) &&
+ (wbs_adr_i < WB_FLASH_HIGHADDR)) begin
+ `state(ST_WBWRITE);
+ end else begin
+ wbs_ack_o <= 1;
+ `state(ST_IDLE);
+ end
+ end
+ endcase
+ end else begin
+ case(wbs_adr_i)
+ WB_STATUS_BASEADDR: `state(ST_WBSTATUS);
+ default: begin
+ if((wbs_adr_i >= WB_FLASH_BASEADDR) &&
+ (wbs_adr_i < WB_FLASH_HIGHADDR)) begin
+ `state(ST_WBREAD);
+ end else begin
+ wbs_ack_o <= 1;
+ `state(ST_IDLE);
+ end
+ end
+ endcase
+ end
+ addr <= wbs_adr_i;
+ end
+ end
+
+
+ //
+ // WRITE
+ //
+ // first check to see if this is a continuation of an old
+ // transaction. otherwise reset and start over.
+ ST_WBWRITE: if(wbs_stb_i) begin
+ // terminate if we don\'t support the cycle type
+ if(!((wbs_cti_i == WB_CTI_CLASSIC) || (wbs_cti_i == WB_CTI_INCR_BURST)) || (wbs_bte_i != WB_BTE_LINEAR)) begin
+ wbs_ack_o <= 1;
+ `state(ST_RESET);
+ // if we\'re still in a continuous block/burst then carry on
+ end else if((fstate == fstate_l) && (addr == addr_l + 4)) begin
+ `next_state(ST_SYNC_CYCLE, ST_WBWRITE_3);
+ // otherwise begin transaction
+ end else begin
+ `next_state(ST_SYNC_CYCLE, ST_WBWRITE_0);
+ end
+ fstate_l <= fstate;
+ end
+ // send the prog command
+ ST_WBWRITE_0: if(trc) begin
+ CE <= 1;
+ CLE <= 1;
+ ALE <= 0;
+ RE <= 0;
+ WE <= 1;
+ IO_o <= FCMD_PROG_0;
+ IO_t <= IO_DRIVE;
+ i <= 0;
+ `next_state(ST_WE_TOGGLE, ST_WBWRITE_1);
+ end
+ // send our column and row addresses
+ ST_WBWRITE_1: if(trc) begin
+ CE <= 1;
+ CLE <= 0;
+ ALE <= 1;
+ RE <= 0;
+ WE <= 1;
+ IO_o <= addr_cycle(i, addr + (WB_FLASH_S << (`FPAGES + `FCOLUMNS + 1)));
+ IO_t <= IO_DRIVE;
+ if(i < (ADDR_CYC-1)) begin
+ i <= i + 1;
+ `next_state(ST_WE_TOGGLE, ST_WBWRITE_1);
+ end else begin
+ `next_state(ST_WE_TOGGLE, ST_WBWRITE_2);
+ i <= 0;
+ end
+ end
+ // set ALE and wait tADL
+ ST_WBWRITE_2: if(trc) begin
+ CE <= 1;
+ CLE <= 0;
+ ALE <= 0;
+ RE <= 0;
+ WE <= 0;
+ IO_o <= \'h0;
+ IO_t <= IO_DRIVE;
+ if(i < (TADL-1)) begin
+ i <= i + 1;
+ `state(ST_WBWRITE_2);
+ end else begin
+ i <= 0;
+ `state(ST_WBWRITE_3);
+ end
+ end
+ // begin sending data 8 bits at a time
+ ST_WBWRITE_3: if(wbs_stb_i && trc) begin
+ CE <= 1;
+ CLE <= 0;
+ ALE <= 0;
+ RE <= 0;
+ WE <= 1;
+ IO_o <= data_byte(i, wbs_dat_i);
+ IO_t <= IO_DRIVE;
+ if(i < 3) begin
+ i <= i + 1;
+ `next_state(ST_WE_TOGGLE, ST_WBWRITE_3);
+ end else begin
+ // if we\'re at the end of the page, then flush
+ if(addr_page_end(addr) || (wbs_cti_i == WB_CTI_EOB)) begin
+ `next_state(ST_WE_TOGGLE, ST_WBWRITE_5);
+ // otherwise ack and resume wishbone bus
+ end else begin
+ `next_state(ST_WE_TOGGLE, ST_WBWRITE_4);
+ end
+ end
+ end
+ // send wishbone ack and then return to idle state to receive next command
+ ST_WBWRITE_4: if(wbs_stb_i) begin // if(trc) begin
+ CE <= 1;
+ CLE <= 0;
+ ALE <= 0;
+ RE <= 0;
+ WE <= 0;
+ IO_o <= \'h0;
+ IO_t <= IO_DRIVE;
+ wbs_ack_o <= 1;
+ addr_l <= addr;
+
+ if(wbs_cti_i == WB_CTI_INCR_BURST) begin
+ `state(ST_WBWRITE_7);
+ end else begin
+ `state(ST_IDLE);
+ end
+ end
+ // send program command
+ ST_WBWRITE_5: if(trc) begin
+ CE <= 1;
+ CLE <= 1;
+ ALE <= 0;
+ RE <= 0;
+ WE <= 1;
+ IO_o <= FCMD_PROG_1;
+ IO_t <= IO_DRIVE;
+ i <= 0;
+ `next_state(ST_WE_TOGGLE, ST_WBWRITE_6);
+ end
+ // wait tWB
+ ST_WBWRITE_6: if(wbs_stb_i && trc) begin
+ CE <= 1;
+ CLE <= 0;
+ ALE <= 0;
+ RE <= 0;
+ WE <= 0;
+ IO_o <= \'h0;
+ IO_t <= IO_TRI;
+ // make sure to wait TWB before polling RB
+ if(i < (TWB-1)) begin
+ i <= i + 1;
+ `state(ST_WBWRITE_6);
+ // when RB signals write is done, then reset
+ end else if(!RB) begin
+ wbs_ack_o <= 1;
+ `state(ST_RESET);
+ end
+ end
+ // handle bursts
+ ST_WBWRITE_7: begin
+ i <= 0;
+ wbs_ack_o <= 0;
+ if(wbs_stb_i) begin
+ `state(ST_WBWRITE_3);
+ end
+ end
+
+
+ //
+ // READ
+ //
+ // save state and synchronize with tRC
+ ST_WBREAD: if(wbs_stb_i) begin
+ // terminate if we don\'t support the cycle type
+ if(!((wbs_cti_i == WB_CTI_CLASSIC) || (wbs_cti_i == WB_CTI_INCR_BURST)) || (wbs_bte_i != WB_BTE_LINEAR)) begin
+ wbs_ack_o <= 1;
+ `state(ST_RESET);
+ // if we\'re still in a continuous block/burst then carry on
+ end else if((fstate == fstate_l) && (addr == addr_l + 4)) begin
+ `next_state(ST_SYNC_CYCLE, ST_WBREAD_4);
+ // otherwise begin transaction
+ end else begin
+ `next_state(ST_SYNC_CYCLE, ST_WBREAD_0);
+ end
+ fstate_l <= fstate;
+ end
+ // send read command to flash
+ ST_WBREAD_0: if(trc) begin
+ CE <= 1;
+ CLE <= 1;
+ ALE <= 0;
+ RE <= 0;
+ WE <= 1;
+ IO_o <= FCMD_READ_0;
+ IO_t <= IO_DRIVE;
+ i <= 0;
+ `next_state(ST_WE_TOGGLE, ST_WBREAD_1);
+ end
+ // send address cycle to flash
+ ST_WBREAD_1: if(trc) begin
+ CE <= 1;
+ CLE <= 0;
+ ALE <= 1;
+ RE <= 0;
+ WE <= 1;
+ IO_o <= addr_cycle(i, addr + (WB_FLASH_S << (`FPAGES + `FCOLUMNS + 1)));
+ IO_t <= IO_DRIVE;
+ if(i < (ADDR_CYC-1)) begin
+ i <= i + 1;
+ `next_state(ST_WE_TOGGLE, ST_WBREAD_1);
+ end else begin
+ `next_state(ST_WE_TOGGLE, ST_WBREAD_2);
+ end
+ end
+ // begin read
+ ST_WBREAD_2: if(trc) begin
+ CE <= 1;
+ CLE <= 1;
+ ALE <= 0;
+ RE <= 0;
+ WE <= 1;
+ IO_o <= FCMD_READ_1;
+ IO_t <= IO_DRIVE;
+ i <= 0;
+ `next_state(ST_WE_TOGGLE, ST_WBREAD_3);
+ end
+ // wait tWB, then RB to finish
+ ST_WBREAD_3: if(trc) begin
+ CE <= 1;
+ CLE <= 0;
+ ALE <= 0;
+ RE <= 0;
+ WE <= 0;
+ IO_o <= \'h0;
+ IO_t <= IO_TRI;
+ if(i < (TWB-1)) begin
+ i <= i + 1;
+ `state(ST_WBREAD_3);
+ end else if(!RB) begin
+ i <= 0;
+ `state(ST_WBREAD_4);
+ end
+ end
+ // then grab 4 bytes of data and output and ack to wishbone
+ ST_WBREAD_4: begin if(trc) begin
+ CE <= 1;
+ CLE <= 0;
+ ALE <= 0;
+ RE <= 1;
+ WE <= 0;
+ IO_o <= \'h0;
+ IO_t <= IO_TRI;
+ if(i < 3) begin
+ i <= i + 1;
+ `next_state(ST_RE_TOGGLE, ST_WBREAD_4);
+ end else begin
+ `next_state(ST_RE_TOGGLE, ST_WBREAD_5);
+ end
+ end
+ wbs_ack_o <= 0;
+ end
+ // handle ack and state transition
+ ST_WBREAD_5: if(wbs_stb_i) begin
+ RE <= 0;
+`ifdef TEST_1BIT_ERROR
+ wbs_dat_o <= wbs_adr_i[`FCOLUMNS-1:2] == \'h137 ? data ^ \'h8000 : data;
+`else
+`ifdef TEST_2BIT_ERROR
+ wbs_dat_o <= wbs_adr_i[`FCOLUMNS-1:2] == \'h137 ? data ^ \'hc000 : data;
+`else
+ wbs_dat_o <= data;
+`endif
+`endif
+ wbs_ack_o <= 1;
+ addr_l <= addr;
+ if(wbs_cti_i == WB_CTI_INCR_BURST) begin
+ i <= 0;
+ `state(ST_WBREAD_4);
+ end else if(addr_page_end(addr) || (wbs_cti_i == WB_CTI_EOB)) begin
+ `state(ST_RESET);
+ end else begin
+ `state(ST_IDLE);
+ end
+ end
+
+
+ //
+ // ERASE
+ //
+ // make sure the address we\'re erasing is in allowed range
+ ST_WBERASE: if(wbs_stb_i) begin
+ if((wbs_dat_i[9:0] >= WB_FLASH_S) && (wbs_dat_i[9:0] < WB_FLASH_N)) begin
+ addr <= {wbs_dat_i[9:0], {`FPAGES{1\'b0}}, {`FCOLUMNS+1{1\'b0}}};
+ fstate_l <= fstate;
+ `next_state(ST_SYNC_CYCLE, ST_WBERASE_0);
+ end else begin
+ wbs_ack_o <= 1;
+ `state(ST_IDLE);
+ end
+ end
+ // issue erase command
+ ST_WBERASE_0: if(trc) begin
+ CE <= 1;
+ CLE <= 1;
+ ALE <= 0;
+ WE <= 1;
+ RE <= 0;
+ IO_o <= FCMD_ERASE_0;
+ IO_t <= IO_DRIVE;
+ i <= 2;
+ `next_state(ST_WE_TOGGLE, ST_WBERASE_1);
+ end
+ // send address cycles for block
+ ST_WBERASE_1: if(trc) begin
+ CE <= 1;
+ CLE <= 0;
+ ALE <= 1;
+ RE <= 0;
+ WE <= 1;
+ IO_o <= addr_cycle(i, addr + (WB_FLASH_S << (`FPAGES + `FCOLUMNS + 1)));
+ IO_t <= IO_DRIVE;
+ if(i < (ADDR_CYC-1)) begin
+ i <= i + 1;
+ `next_state(ST_WE_TOGGLE, ST_WBERASE_1);
+ end else begin
+ `next_state(ST_WE_TOGGLE, ST_WBERASE_2);
+ i <= 0;
+ end
+ end
+ // send erase command
+ ST_WBERASE_2: if(trc) begin
+ CE <= 1;
+ CLE <= 1;
+ ALE <= 0;
+ RE <= 0;
+ WE <= 1;
+ IO_o <= FCMD_ERASE_1;
+ IO_t <= IO_DRIVE;
+ i <= 0;
+ `next_state(ST_WE_TOGGLE, ST_WBERASE_3);
+ end
+ // wait for command to finish
+ ST_WBERASE_3: if(trc) begin
+ CE <= 1;
+ CLE <= 0;
+ ALE <= 0;
+ RE <= 0;
+ WE <= 0;
+ IO_t <= IO_TRI;
+ if(i < (TWB-1))
+ i <= i + 1;
+ else if(!RB & wbs_stb_i) begin
+ wbs_ack_o <= 1;
+ `state(ST_RESET);
+ end
+ end
+
+
+ //
+ // READ STATUS
+ //
+ ST_WBSTATUS: if(wbs_stb_i) begin
+ `next_state(ST_SYNC_CYCLE, ST_WBSTATUS_0);
+ end
+ // issue status command
+ ST_WBSTATUS_0: if(trc) begin
+ CE <= 1;
+ CLE <= 1;
+ ALE <= 0;
+ RE <= 0;
+ WE <= 1;
+ IO_o <= FCMD_READ_STAT_0;
+ IO_t <= IO_DRIVE;
+ i <= 0;
+ `next_state(ST_WE_TOGGLE, ST_WBSTATUS_1);
+ end
+ ST_WBSTATUS_1: if(trc) begin
+ CE <= 1;
+ CLE <= 0;
+ ALE <= 0;
+ WE <= 0;
+ IO_t <= IO_TRI;
+ if(i < (TWHR - 1)) begin
+ RE <= 0;
+ i <= i + 1;
+ end else begin
+ RE <= 1;
+ `next_state(ST_RE_TOGGLE, ST_WBSTATUS_2);
+ end
+ end
+ ST_WBSTATUS_2: if(wbs_stb_i) begin
+ wbs_dat_o <= {31\'h0, data[24]};
+ wbs_ack_o <= 1;
+ `state(ST_RESET);
+ end
+
+
+ //
+ // COMMON STATE FUNCTIONS
+ //
+ // synchronize with the trc
+ ST_SYNC_CYCLE: if(trc) begin
+ `state(n_fstate);
+ end
+ // wait for trc and then toggle WE low
+ ST_WE_TOGGLE: if(trc) begin
+ WE <= 0;
+ `state(n_fstate);
+ end
+ // wait for trc and then toggle RE low and save data
+ ST_RE_TOGGLE: if(trc) begin
+ RE <= 0;
+ data <= {IO_i, data[31:8]};
+ `state(n_fstate);
+ end
+ endcase
+
+
+ //
+ // TRC PULSE
+ //
+ // create a trc pulse that goes high every TRC bus clock cycles
+ if(trc_state >= (TRC-1)) begin
+ trc_state <= 0;
+ trc <= 1;
+ end else begin
+ trc_state <= trc_state + 1;
+ trc <= 0;
+ end
+ end
+end
+
+endmodule
+
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 15:31:28 02/03/2015
+// Design Name:
+// Module Name: wb_sha2_ctrl
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module wb_sha256_ctrl (
+\tinput wb_clk_i,
+\tinput wb_rst_i,
+\t
+\tinput [6:0] wb_adr_i,
+\tinput [31:0] wb_dat_i,
+\tinput [3:0] wb_sel_i,
+\tinput wb_we_i,
+\tinput [1:0] wb_bte_i,
+\tinput [2:0] wb_cti_i,
+\tinput wb_cyc_i,
+\tinput wb_stb_i,
+\toutput reg wb_ack_o,
+\toutput wb_err_o,
+\toutput wb_rty_o,
+\toutput reg [31:0] wb_dat_o,
+\t
+\toutput reg load_o,
+\toutput reg [255:0] state_o,
+\toutput reg [511:0] data_o,
+\tinput busy_i,
+\tinput [255:0] state_i
+);
+
+`include ""wb_common.v""
+
+assign wb_err_o = 0;
+assign wb_rty_o = 0;
+
+wire valid = (wb_cyc_i & wb_stb_i);
+reg valid_r;
+wire new_cycle = valid & ~valid_r;
+
+reg [6:0] adr_r;
+wire [6:0] next_adr = wb_next_adr(adr_r, wb_cti_i, wb_bte_i, 32);
+wire [6:0] wb_adr = new_cycle ? wb_adr_i : next_adr;
+
+always @(posedge wb_clk_i)
+begin
+\tadr_r <= wb_adr;
+\tvalid_r <= valid;
+\twb_ack_o <= valid & (!((wb_cti_i == 3\'b000) | (wb_cti_i == 3\'b111)) | !wb_ack_o);
+\tif(wb_rst_i)
+\tbegin
+\t\tadr_r <= 0;
+\t\tvalid_r <= 0;
+\t\twb_ack_o <= 0;
+\tend
+end
+
+reg busy_r, rst_r;
+wire rst = (rst_r | wb_rst_i);
+
+`define STATE_WRITE(x) \\
+\tstate_o[256 - (x * 32) - 23:256 - (x * 32) - 32] <= (wb_sel_i[0]) \\
+\t\t? wb_dat_i[ 7: 0] : state_o[256 - (x * 32) - 23:256 - (x * 32) - 32]; \\
+\tstate_o[256 - (x * 32) - 17:256 - (x * 32) - 24] <= (wb_sel_i[1]) \\
+\t\t? wb_dat_i[15: 8] : state_o[256 - (x * 32) - 17:256 - (x * 32) - 24]; \\
+\tstate_o[256 - (x * 32) - 9:256 - (x * 32) - 16] <= (wb_sel_i[2]) \\
+\t\t? wb_dat_i[23:16] : state_o[256 - (x * 32) - 9:256 - (x * 32) - 16]; \\
+\tstate_o[256 - (x * 32) - 1:256 - (x * 32) - 8] <= (wb_sel_i[3]) \\
+\t\t? wb_dat_i[31:24] : state_o[256 - (x * 32) - 1:256 - (x * 32) - 8];
+
+`define STATE_READ(x) \\
+\twb_dat_o <= (load_o | busy_i) \\
+\t\t? 32\'h0 : state_o[256 - (x * 32) - 1:256 - (x * 32) - 32];
+
+`define DATA_WRITE(x) \\
+\tdata_o[512 - (x * 32) - 23:512 - (x * 32) - 32] <= (wb_sel_i[0]) \\
+\t\t? wb_dat_i[ 7: 0] : data_o[512 - (x * 32) - 23:512 - (x * 32) - 32]; \\
+\tdata_o[512 - (x * 32) - 17:512 - (x * 32) - 24] <= (wb_sel_i[1]) \\
+\t\t? wb_dat_i[15: 8] : data_o[512 - (x * 32) - 17:512 - (x * 32) - 24]; \\
+\tdata_o[512 - (x * 32) - 9:512 - (x * 32) - 16] <= (wb_sel_i[2]) \\
+\t\t? wb_dat_i[23:16] : data_o[512 - (x * 32) - 9:512 - (x * 32) - 16]; \\
+\tdata_o[512 - (x * 32) - 1:512 - (x * 32) - 8] <= (wb_sel_i[3]) \\
+\t\t? wb_dat_i[31:24] : data_o[512 - (x * 32) - 1:512 - (x * 32) - 8];
+
+
+always @(posedge wb_clk_i)
+begin : ctrl_block
+\tbusy_r <= busy_i;
+\trst_r <= 0;
+\t
+\tif(rst)
+\tbegin\t
+\t\tload_o <= 0;
+\t\tstate_o <= {
+\t\t\t32\'h6a09e667, 32\'hbb67ae85, 32\'h3c6ef372, 32\'ha54ff53a,
+\t\t\t32\'h510e527f, 32\'h9b05688c, 32\'h1f83d9ab, 32\'h5be0cd19
+\t\t};
+\t\tdata_o <= 0;
+\tend
+\telse
+\tbegin
+\t\tif(busy_r & ~busy_i)
+\t\tbegin
+\t\t\tstate_o <= state_i;
+\t\t\tdata_o <= 0;
+\t\tend
+\t\tif(busy_i)
+\t\t\tload_o <= 0;
+
+\t\tif(valid & wb_we_i & ~busy_i & ~load_o)
+\t\tbegin
+\t\t\tcase(wb_adr[6:5])
+\t\t\t2\'b00:
+\t\t\tbegin
+\t\t\t\tcase(wb_adr[4:2])
+\t\t\t\t0: begin `STATE_WRITE(0); end
+\t\t\t\t1: begin `STATE_WRITE(1); end
+\t\t\t\t2: begin `STATE_WRITE(2); end
+\t\t\t\t3: begin `STATE_WRITE(3); end
+\t\t\t\t4: begin `STATE_WRITE(4); end
+\t\t\t\t5: begin `STATE_WRITE(5); end
+\t\t\t\t6: begin `STATE_WRITE(6); end
+\t\t\t\t7: begin `STATE_WRITE(7); end
+\t\t\t\tendcase
+\t\t\tend
+\t\t\t2\'b01:
+\t\t\tbegin
+\t\t\t\tcase(wb_adr[4:2])
+\t\t\t\t0: begin `DATA_WRITE( 0); end
+\t\t\t\t1: begin `DATA_WRITE( 1); end
+\t\t\t\t2: begin `DATA_WRITE( 2); end
+\t\t\t\t3: begin `DATA_WRITE( 3); end
+\t\t\t\t4: begin `DATA_WRITE( 4); end
+\t\t\t\t5: begin `DATA_WRITE( 5); end
+\t\t\t\t6: begin `DATA_WRITE( 6); end
+\t\t\t\t7: begin `DATA_WRITE( 7); end
+\t\t\t\tendcase
+\t\t\tend
+\t\t\t2\'b10:
+\t\t\tbegin
+\t\t\t\tcase(wb_adr[4:2])
+\t\t\t\t0: begin `DATA_WRITE( 8); end
+\t\t\t\t1: begin `DATA_WRITE( 9); end
+\t\t\t\t2: begin `DATA_WRITE(10); end
+\t\t\t\t3: begin `DATA_WRITE(11); end
+\t\t\t\t4: begin `DATA_WRITE(12); end
+\t\t\t\t5: begin `DATA_WRITE(13); end
+\t\t\t\t6: begin `DATA_WRITE(14); end
+\t\t\t\t7: begin `DATA_WRITE(15); end
+\t\t\t\tendcase
+\t\t\tend
+\t\t\t2\'b11:
+\t\t\tbegin
+\t\t\t\tif(wb_adr[4:2] == 0)
+\t\t\t\tbegin
+\t\t\t\t\tload_o <= wb_sel_i[0] & wb_dat_i[0];
+\t\t\t\t\trst_r <= wb_sel_i[1] & wb_dat_i[8];
+\t\t\t\tend
+\t\t\tend
+\t\t\tendcase
+\t\tend // write handler
+\t\t
+\t\tif(valid & ~wb_we_i)
+\t\tbegin
+\t\t\tcase(wb_adr[6:5])
+\t\t\t2\'b00:
+\t\t\tbegin
+\t\t\t\tcase(wb_adr[4:2])
+\t\t\t\t0: begin `STATE_READ(0); end
+\t\t\t\t1: begin `STATE_READ(1); end
+\t\t\t\t2: begin `STATE_READ(2); end
+\t\t\t\t3: begin `STATE_READ(3); end
+\t\t\t\t4: begin `STATE_READ(4); end
+\t\t\t\t5: begin `STATE_READ(5); end
+\t\t\t\t6: begin `STATE_READ(6); end
+\t\t\t\t7: begin `STATE_READ(7); end
+\t\t\t\tendcase
+\t\t\tend
+\t\t\t2\'b01: wb_dat_o <= 32\'h0;
+\t\t\t2\'b10: wb_dat_o <= 32\'h0;
+\t\t\t2\'b11:
+\t\t\tbegin
+\t\t\t\tif(wb_adr[4:2] == 0)
+\t\t\t\t\twb_dat_o <= { 15\'h0, load_o | busy_i, 16\'h0 };
+\t\t\t\telse
+\t\t\t\t\twb_dat_o <= 0;
+\t\t\tend
+\t\t\tendcase
+\t\tend // read handler
+\tend
+end
+
+endmodule
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 18:21:38 02/02/2015
+// Design Name:
+// Module Name: crypto_sha256_top
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module crypto_sha256_top (
+\tinput wb_clk_i,
+\tinput wb_rst_i,
+\t
+\tinput core_clk,
+\t
+\tinput [31:0] wb_adr_i,
+\tinput [31:0] wb_dat_i,
+\tinput [3:0] wb_sel_i,
+\tinput wb_we_i,
+\tinput [1:0] wb_bte_i,
+\tinput [2:0] wb_cti_i,
+\tinput wb_cyc_i,
+\tinput wb_stb_i,
+\toutput wb_ack_o,
+\toutput wb_err_o,
+\toutput wb_rty_o,
+\toutput [31:0] wb_dat_o
+
+);
+
+wire [255:0] wb2core_state, core2wb_state;
+wire [511:0] wb2core_data;
+wire load_clk1, busy_clk2;
+reg [1:0] busy_clk1_buf;
+reg [1:0] load_clk2_buf;
+wire busy_clk1 = busy_clk1_buf[1];
+wire load_clk2 = load_clk2_buf[1];
+
+wb_sha256_ctrl wb_ctrl_inst (
+\t.wb_clk_i(wb_clk_i),
+\t.wb_rst_i(wb_rst_i),
+\t
+\t.wb_adr_i(wb_adr_i[6:0]),
+\t.wb_dat_i(wb_dat_i),
+\t.wb_sel_i(wb_sel_i),
+\t.wb_we_i(wb_we_i),
+\t.wb_bte_i(wb_bte_i),
+\t.wb_cti_i(wb_cti_i),
+\t.wb_cyc_i(wb_cyc_i),
+\t.wb_stb_i(wb_stb_i),
+\t.wb_ack_o(wb_ack_o),
+\t.wb_err_o(wb_err_o),
+\t.wb_rty_o(wb_rty_o),
+\t.wb_dat_o(wb_dat_o),
+\t
+\t.load_o(load_clk1),
+\t.state_o(wb2core_state),
+\t.data_o(wb2core_data),
+\t.busy_i(busy_clk1),
+\t.state_i(core2wb_state)
+);
+
+always @(posedge wb_clk_i) busy_clk1_buf <= { busy_clk1_buf[0], busy_clk2 };
+always @(posedge core_clk) load_clk2_buf <= { load_clk2_buf[0], load_clk1 };
+
+// Adding (* use_dsp48 = ""yes"" *) allows DSP48\'s for addition
+// However this is slower and only saves 400 LUTs
+sha256_core sha256_inst (
+\t.clk(core_clk),
+\t.load_i(load_clk2),
+\t.data_i(wb2core_data),
+\t.state_i(wb2core_state),
+\t.state_o(core2wb_state),
+\t.busy_o(busy_clk2)
+);
+
+endmodule
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 13:49:03 02/02/2015
+// Design Name:
+// Module Name: sha256
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module sha256_core (\t
+\tinput clk,
+\tinput load_i,
+\tinput [511:0] data_i,
+\tinput [255:0] state_i,
+\toutput [255:0] state_o,
+\toutput reg busy_o
+);
+
+localparam SHA256_MAX_STEP = 64;
+
+`define STATE_LOAD(i) state_i[256 - (i * 32) - 1: 256 - (i * 32) - 32]
+
+reg [31:0] A, B, C, D, E, F, G, H;
+reg [31:0] A_new, B_new, C_new, D_new, E_new, F_new, G_new, H_new;
+reg [31:0] HKW, HKW_new;
+reg [6:0] step, step_new;
+reg busy_new;
+wire [31:0] W, K;
+
+assign state_o = { A, B, C, D, E, F, G, H };
+\t
+sha256_W W_inst(
+\t.clk(clk),
+\t.data_i(data_i),
+\t.load_i(load_i),
+\t.busy_i(busy_o),
+\t.W_o(W)
+);
+
+sha256_K K_inst(
+\t.step_i(step[5:0]),
+\t.K_o(K)
+);
+
+always @(posedge clk)
+begin
+\tbusy_o <= busy_new;
+\tstep <= step_new;
+\tA <= A_new;
+\tB <= B_new;
+\tC <= C_new;
+\tD <= D_new;
+\tE <= E_new;
+\tF <= F_new;
+\tG <= G_new;
+\tH <= H_new;
+\tHKW <= HKW_new;
+end
+
+always @*
+begin
+\tstep_new = 0;
+\tif(~load_i & busy_o)
+\t\tstep_new = step + 1;
+end
+
+always @*
+begin : HKW_update
+\treg [31:0] H_pre;
+\t
+\tH_pre = G;
+\tif(step == 0)
+\t\tH_pre = `STATE_LOAD(7);\t
+\t\t
+\tHKW_new = H_pre + K + W;
+end
+
+reg [31:0] T1, T2;
+
+always @*
+begin : T1_update
+\treg [31:0] Ch, S1;
+\tCh = (E & F) ^ (~E & G);
+\tS1 = {E[5:0],E[31:6]} ^ {E[10:0],E[31:11]} ^ {E[24:0],E[31:25]};
+\tT1 = S1 + Ch + HKW;
+end
+
+always @*
+begin : T2_update
+\treg [31:0] Maj, S0;
+\t
+\tMaj = (A & (B ^ C)) ^ (B & C);
+\tS0 = {A[1:0],A[31:2]} ^ {A[12:0],A[31:13]} ^ {A[21:0],A[31:22]};
+\tT2 = S0 + Maj;
+end
+
+always @*
+begin
+\tbusy_new = 0;
+\t
+\tA_new = A;
+\tB_new = B;
+\tC_new = C;
+\tD_new = D;
+\tE_new = E;
+\tF_new = F;
+\tG_new = G;
+\tH_new = H;
+\t
+\tif(load_i)
+\tbegin
+\t\tbusy_new = 1;
+\t\t
+\t\tA_new = `STATE_LOAD(0);
+\t\tB_new = `STATE_LOAD(1);
+\t\tC_new = `STATE_LOAD(2);
+\t\tD_new = `STATE_LOAD(3);
+\t\tE_new = `STATE_LOAD(4);
+\t\tF_new = `STATE_LOAD(5);
+\t\tG_new = `STATE_LOAD(6);
+\t\tH_new = `STATE_LOAD(7);
+\tend
+\telse if(busy_o)
+\tbegin
+\t\tif(step == SHA256_MAX_STEP + 1)
+\t\tbegin\t\t\t
+\t\t\tA_new = A + `STATE_LOAD(0);
+\t\t\tB_new = B + `STATE_LOAD(1);
+\t\t\tC_new = C + `STATE_LOAD(2);
+\t\t\tD_new = D + `STATE_LOAD(3);
+\t\t\tE_new = E + `STATE_LOAD(4);
+\t\t\tF_new = F + `STATE_LOAD(5);
+\t\t\tG_new = G + `STATE_LOAD(6);
+\t\t\tH_new = H + `STATE_LOAD(7);
+\t\tend
+\t\telse if(step == 0)
+\t\tbegin
+\t\t\tbusy_new = 1;
+\t\t\t
+\t\t\tA_new = A;
+\t\t\tB_new = B;
+\t\t\tC_new = C;
+\t\t\tD_new = D;
+\t\t\tE_new = E;
+\t\t\tF_new = F;
+\t\t\tG_new = G;
+\t\t\tH_new = H;
+\t\tend
+\t\telse
+\t\tbegin
+\t\t\tbusy_new = 1;
+\t\t\t
+\t\t\tA_new = T1 + T2;
+\t\t\tB_new = A;
+\t\t\tC_new = B;
+\t\t\tD_new = C;
+\t\t\tE_new = D + T1;
+\t\t\tF_new = E;
+\t\t\tG_new = F;
+\t\t\tH_new = G;
+\t\tend
+\tend
+end
+
+endmodule
+
+"
+"/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+module wb_trng (
+\tinput wb_clk,
+\tinput wb_rst,
+
+\tinput [31:0] wb_adr_i,
+\tinput [7:0] wb_dat_i,
+\tinput wb_we_i,
+\tinput wb_cyc_i,
+\tinput wb_stb_i,
+\tinput [2:0] wb_cti_i,
+\tinput [1:0] wb_bte_i,
+\toutput [7:0] wb_dat_o,
+\toutput reg wb_ack_o,
+\toutput wb_err_o,
+\toutput wb_rty_o
+);
+
+wire valid = wb_cyc_i & wb_stb_i;
+
+trng trng_inst (
+\t.clk(wb_clk),
+\t.en(valid),
+\t.R(wb_dat_o)
+);
+
+always @(posedge wb_clk)
+begin
+\twb_ack_o <= 0;
+\tif(valid)
+\t\twb_ack_o <= 1;
+end
+
+assign wb_err_o = 0;
+assign wb_rty_o = 0;
+
+endmodule
+"
+"`include ""nandc_def.vh""
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+module nandc_ecc_inline #(
+ // base offset on the wishbone bus that everything is located at
+ parameter WB_FLASH_BASEADDR = `WB_FLASH_BASEADDR,
+
+ // the offset to place wishbone registers at on the bus
+ parameter WB_REG_BASEADDR = `WB_REG_BASEADDR,
+
+ // the start block that this nand controller is able to address
+ parameter WB_FLASH_S = `WB_FLASH_S,
+
+ // the number of blocks this nand controller is able to address (out of 1024)
+ parameter WB_FLASH_N = `WB_FLASH_N
+) (
+ input wire wb_clk, // clock - bus clock
+ input wire wb_rst, // reset synchronous with wb_clk
+
+ input wire [2:0] wbs_cti_i, // type - cycle type identifier, supports either 000 ""Classic cycle"" or 010 ""Incrementing burst cycle""
+ input wire [1:0] wbs_bte_i, // exten - burst type extension, only supports 00 ""Linear burst""
+ input wire [31:0] wbs_adr_i, // addr - bus address
+ output reg [31:0] wbs_dat_o, // data - write data output
+ input wire [31:0] wbs_dat_i, // data - write data input
+ input wire [3:0] wbs_sel_i, // select - 8-bit enable for data bus
+ input wire wbs_cyc_i, // cycle - valid bus cycle is in progress
+ input wire wbs_stb_i, // strobe - slave is selected
+ input wire wbs_we_i, // write - bus cycle is in write mode
+ output reg wbs_ack_o, // ack - end of a normal bus cycle
+
+ output reg [2:0] wbm_cti_o, // type - cycle type identifier, supports either 000 ""Classic cycle"" or 010 ""Incrementing burst cycle""
+ output reg [1:0] wbm_bte_o, // exten - burst type extension, only supports 00 ""Linear burst""
+ output reg [31:0] wbm_adr_o, // addr - bus address
+ input wire [31:0] wbm_dat_i, // data - write data input
+ output reg [31:0] wbm_dat_o, // data - write data output
+ output reg [3:0] wbm_sel_o, // select - 8-bit enable for data bus
+ output reg wbm_cyc_o, // cycle - valid bus cycle is in progress
+ output reg wbm_stb_o, // strobe - slave is selected
+ output reg wbm_we_o, // write - bus cycle is in write mode
+ input wire wbm_ack_i // ack - end of a normal bus cycle
+);
+
+`include ""nandc_const.vh""
+
+parameter WB_FLASH_HIGHADDR = WB_FLASH_BASEADDR + (WB_FLASH_N << (`FPAGES + `FCOLUMNS));
+parameter WB_PAGE_OFFSET_BASEADDR = WB_REG_BASEADDR + `WB_PAGE_OFFSET_OFF;
+parameter WB_SPARE_SPACE_WR_BASEADDR = WB_REG_BASEADDR + `WB_SPARE_SPACE_WR_OFF;
+parameter WB_SPARE_SPACE_RD_BASEADDR = WB_REG_BASEADDR + `WB_SPARE_SPACE_RD_OFF;
+parameter WB_ERASE_BASEADDR = WB_REG_BASEADDR + `WB_ERASE_OFF;
+parameter WB_STATUS_BASEADDR = WB_REG_BASEADDR + `WB_STATUS_OFF;
+
+reg [31:0] data_i;
+reg valid_i, sof_i, eof_i;
+wire [31:0] data_o;
+wire valid_o, sof_o, eof_o;
+wire [23:0] ecc_o;
+
+hamm_4096x1_512x32 hamm_4096x1_512x32 (
+ .clk ( wb_clk ),
+ .rst ( wb_rst ),
+ .data_i ( data_i ),
+ .valid_i ( valid_i ),
+ .sof_i ( sof_i ),
+ .eof_i ( eof_i ),
+ .data_o ( data_o ),
+ .valid_o ( valid_o ),
+ .sof_o ( sof_o ),
+ .eof_o ( eof_o ),
+ .ecc_o ( ecc_o )
+);
+
+reg a_wr;
+reg [`FCOLUMNS-2:0] a_addr;
+reg [31:0] a_din;
+wire [31:0] a_dout;
+reg b_wr;
+reg [`FCOLUMNS-2:0] b_addr;
+reg [31:0] b_din;
+wire [31:0] b_dout;
+
+parameter [4:0] ST_IDLE = \'d0,
+ ST_IDLE_0 = \'d1,
+ ST_ERASE = \'d2,
+ ST_STATUS = \'d3,
+ ST_WBWRITE = \'d4,
+ ST_WBWRITE_0 = \'d5,
+ ST_WBWRITE_1 = \'d6,
+ ST_WBWRITE_2 = \'d7,
+ ST_WBWRITE_3 = \'d8,
+ ST_WBWRITE_4 = \'d9,
+ ST_WBREAD = \'d10,
+ ST_WBREAD_0 = \'d11,
+ ST_WBREAD_1 = \'d12,
+ ST_WBREAD_2 = \'d13,
+ ST_WBREAD_3 = \'d14,
+ ST_WBREAD_4 = \'d15,
+ ST_WBREAD_5 = \'d16,
+ ST_WBREAD_6 = \'d17;
+
+reg page_offset;
+reg [63:0] spare_space_wr, spare_space_rd;
+reg [23:0] spare_space_ecc, spare_space_ecc_cmp;
+reg spare_space_erased;
+reg [1:0] ecc_addr;
+reg [23:0] ecc0, ecc1, ecc2, ecc3;
+reg [23:0] ecc0_cmp, ecc1_cmp, ecc2_cmp, ecc3_cmp;
+reg [7:0] i;
+reg [31:0] data, addr;
+reg [13:0] fix_bit;
+reg [`FPAGES+`FBLOCKS:0] paged, newpaged;
+reg [4:0] hstate;
+
+always @(posedge wb_clk) begin
+ if(wb_rst) begin
+ wbs_dat_o <= \'h0;
+ wbs_ack_o <= 0;
+ wbm_cti_o <= WB_CTI_CLASSIC;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_adr_o <= \'h0;
+ wbm_dat_o <= \'h0;
+ wbm_sel_o <= \'h0;
+ wbm_cyc_o <= 0;
+ wbm_stb_o <= 0;
+ wbm_we_o <= 0;
+ page_offset <= 0;
+ spare_space_wr <= \'h0;
+ spare_space_rd <= \'h0;
+ spare_space_ecc <= \'h0;
+ spare_space_ecc_cmp <= \'h0;
+ spare_space_erased <= 0;
+ ecc_addr <= \'h0;
+ ecc0 <= \'h0;
+ ecc1 <= \'h0;
+ ecc2 <= \'h0;
+ ecc3 <= \'h0;
+ ecc0_cmp <= \'h0;
+ ecc1_cmp <= \'h0;
+ ecc2_cmp <= \'h0;
+ ecc3_cmp <= \'h0;
+ i <= \'h0;
+ data <= \'h0;
+ fix_bit <= \'h0;
+ paged <= {`FPAGES+`FBLOCKS+1{1\'b1}};
+ newpaged <= {`FPAGES+`FBLOCKS+1{1\'b1}};
+ hstate <= ST_IDLE;
+ end else begin
+ case(hstate)
+ ST_IDLE: begin
+ wbm_cti_o <= WB_CTI_CLASSIC;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_adr_o <= \'h0;
+ wbm_dat_o <= \'h0;
+ wbm_sel_o <= \'h0;
+ //wbm_cyc_o <= 0;
+ wbm_stb_o <= 0;
+ wbm_we_o <= 0;
+ wbs_ack_o <= 0;
+ valid_i <= 0;
+ sof_i <= 0;
+ eof_i <= 0;
+ i <= \'h0;
+ data <= \'h0;
+ hstate <= ST_IDLE_0;
+ end
+ ST_IDLE_0: begin
+ if(wbs_cyc_i & wbs_stb_i) begin
+ if(wbs_we_i) begin
+ case(wbs_adr_i)
+ // set ECC controller registers
+ WB_PAGE_OFFSET_BASEADDR: begin
+ page_offset <= wbs_dat_i[0];
+ wbs_ack_o <= 1;
+ hstate <= ST_IDLE;
+ end
+ WB_SPARE_SPACE_WR_BASEADDR + \'h0: begin
+ spare_space_wr[31:0] <= wbs_dat_i;
+ wbs_ack_o <= 1;
+ hstate <= ST_IDLE;
+ end
+ WB_SPARE_SPACE_WR_BASEADDR + \'h4: begin
+ spare_space_wr[63:32] <= wbs_dat_i;
+ wbs_ack_o <= 1;
+ hstate <= ST_IDLE;
+ end
+ WB_ERASE_BASEADDR: begin
+ // make sure we\'re erasing a block in our range
+ if(wbs_dat_i < WB_FLASH_N) begin
+ // offset erase by WB_FLASH_S
+ wbm_dat_o <= wbs_dat_i + WB_FLASH_S;
+ hstate <= ST_ERASE;
+ end else begin
+ wbs_ack_o <= 1;
+ hstate <= ST_IDLE;
+ end
+ end
+ // handle flash write requests within our address boundary
+ default: begin
+ if((wbs_adr_i >= WB_FLASH_BASEADDR) && (wbs_adr_i <= WB_FLASH_HIGHADDR) &&
+ // don\'t allow the user to write when page_offset is set
+ !page_offset) begin
+ // if we\'re writing to the correct range, then construct new address offset by WB_FLASH_S
+ wbm_adr_o <= {wbs_adr_i[31:`FALL+1], wbs_adr_i[`FALL-1:`FCOLUMNS], 1\'b0, wbs_adr_i[`FCOLUMNS-1:0]} + {WB_FLASH_S, {`FCOLUMNS + `FPAGES + 1{1\'b0}}};
+ hstate <= ST_WBWRITE;
+ end else begin
+ wbs_ack_o <= 1;
+ hstate <= ST_IDLE;
+ end
+ end
+ endcase
+ end else begin
+ case(wbs_adr_i)
+ // read back ECC controller registers
+ WB_PAGE_OFFSET_BASEADDR: begin
+ wbs_dat_o <= {31\'h0, page_offset};
+ wbs_ack_o <= 1;
+ hstate <= ST_IDLE;
+ end
+ WB_SPARE_SPACE_WR_BASEADDR + \'h0: begin
+ wbs_dat_o <= spare_space_wr[31:0];
+ wbs_ack_o <= 1;
+ hstate <= ST_IDLE;
+ end
+ WB_SPARE_SPACE_WR_BASEADDR + \'h4: begin
+ wbs_dat_o <= spare_space_wr[63:32];
+ wbs_ack_o <= 1;
+ hstate <= ST_IDLE;
+ end
+ WB_SPARE_SPACE_RD_BASEADDR + \'h0: begin
+ wbs_dat_o <= spare_space_erased ? 32\'hffffffff : spare_space_rd[31:0];
+ wbs_ack_o <= 1;
+ hstate <= ST_IDLE;
+ end
+ WB_SPARE_SPACE_RD_BASEADDR + \'h4: begin
+ wbs_dat_o <= spare_space_erased ? 32\'hffffffff : spare_space_rd[63:32];
+ wbs_ack_o <= 1;
+ hstate <= ST_IDLE;
+ end
+ WB_STATUS_BASEADDR: begin
+ hstate <= ST_STATUS;
+ end
+ // handle flash read requests within our address boundary
+ default: begin
+ if((wbs_adr_i >= WB_FLASH_BASEADDR) && (wbs_adr_i <= WB_FLASH_HIGHADDR)) begin
+ // if we\'re reading from the correct range, then construct new address offset by WB_FLASH_S
+ wbm_adr_o <= {wbs_adr_i[31:`FALL+1], wbs_adr_i[`FALL-1:`FCOLUMNS], {`FCOLUMNS+1{1\'b0}}} + {WB_FLASH_S, {`FCOLUMNS + `FPAGES + 1{1\'b0}}};
+ hstate <= ST_WBREAD;
+ end else begin
+ wbs_ack_o <= 1;
+ hstate <= ST_IDLE;
+ end
+ end
+ endcase
+ end
+ end
+ end
+
+
+ //
+ // ERASE FORWARD
+ //
+ // forward this transaction until we get an ack
+ ST_ERASE: if(wbs_stb_i) begin
+ if(!wbm_ack_i) begin
+ wbm_cti_o <= wbs_cti_i;
+ wbm_bte_o <= wbs_bte_i;
+ wbm_adr_o <= wbs_adr_i;
+ //wbm_dat_o <= wbs_dat_i;
+ wbm_sel_o <= wbs_sel_i;
+ wbm_cyc_o <= wbs_cyc_i;
+ wbm_stb_o <= wbs_stb_i;
+ wbm_we_o <= wbs_we_i;
+ end else begin
+ wbm_cti_o <= WB_CTI_CLASSIC;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_adr_o <= \'h0;
+ wbm_dat_o <= \'h0;
+ wbm_sel_o <= \'h0;
+ wbm_cyc_o <= 0;
+ wbm_stb_o <= 0;
+ wbm_we_o <= 0;
+ wbs_dat_o <= wbm_dat_i;
+ wbs_ack_o <= 1;
+
+ // if we just erased our currently paged block, then invalidate cache
+ if({1\'b0, wbm_dat_o[`FBLOCKS-1:0]} == paged[`FBLOCKS+`FPAGES-1:`FPAGES])
+ paged <= {`FPAGES+`FBLOCKS+1{1\'b1}};
+
+ hstate <= ST_IDLE;
+ end
+ end
+
+
+ //
+ // STATUS FORWARD
+ //
+ // forward this transaction until we get an ack
+ ST_STATUS: if(wbs_stb_i) begin
+ if(!wbm_ack_i) begin
+ wbm_cti_o <= wbs_cti_i;
+ wbm_bte_o <= wbs_bte_i;
+ wbm_adr_o <= wbs_adr_i;
+ wbm_dat_o <= wbs_dat_i;
+ wbm_sel_o <= wbs_sel_i;
+ wbm_cyc_o <= wbs_cyc_i;
+ wbm_stb_o <= wbs_stb_i;
+ wbm_we_o <= wbs_we_i;
+ end else begin
+ wbm_cti_o <= WB_CTI_CLASSIC;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_adr_o <= \'h0;
+ wbm_dat_o <= \'h0;
+ wbm_sel_o <= \'h0;
+ wbm_cyc_o <= 0;
+ wbm_stb_o <= 0;
+ wbm_we_o <= 0;
+ wbs_dat_o <= wbm_dat_i;
+ wbs_ack_o <= 1;
+
+ hstate <= ST_IDLE;
+ end
+ end
+
+
+ //
+ // WRITE WITH ECC
+ //
+ // forward this transaction to the slave and compute and add ecc while we\'re doing it
+ ST_WBWRITE: begin
+ if(!wbm_ack_i || (wbs_cti_i == WB_CTI_INCR_BURST) || (wbs_cti_i == WB_CTI_EOB)) begin
+ wbm_cti_o <= wbs_cti_i == WB_CTI_CLASSIC ? WB_CTI_CLASSIC : WB_CTI_INCR_BURST;
+ wbm_bte_o <= wbs_bte_i;
+ wbm_dat_o <= wbs_dat_i;
+ wbm_sel_o <= \'b1111;
+ wbm_cyc_o <= 1;
+ wbm_we_o <= 1;
+ end
+
+ // drop strobe if we\'ve been acked on either side
+ wbm_stb_o <= !(wbm_ack_i | wbs_ack_o);
+
+ if(wbm_ack_i) begin
+ if(wbs_cti_i == WB_CTI_CLASSIC) begin
+ wbm_sel_o <= \'h0;
+ //wbm_cyc_o <= 0;
+ wbm_we_o <= 0;
+ end else
+ wbm_adr_o <= wbm_adr_o + \'h4;
+
+ data_i <= wbm_dat_o;
+ valid_i <= 1;
+ sof_i <= wbm_adr_o[8:2] == {9-2{1\'b0}};
+ eof_i <= wbm_adr_o[8:2] == {9-2{1\'b1}};
+ ecc_addr <= wbm_adr_o[10:9];
+
+ // if we\'re in the last word of our 512-byte block then save ECC
+ if((wbm_adr_o[8:2] == {9-2{1\'b1}}) || (wbs_cti_i == WB_CTI_EOB))
+ hstate <= ST_WBWRITE_0;
+ else begin
+ wbs_ack_o <= 1;
+ if(wbs_cti_i == WB_CTI_CLASSIC)
+ hstate <= ST_IDLE;
+ end
+ end else begin
+ valid_i <= 0;
+ sof_i <= 0;
+ eof_i <= 0;
+
+ wbs_ack_o <= 0;
+ end
+ end
+ ST_WBWRITE_0: begin
+ valid_i <= 0;
+ sof_i <= 0;
+ eof_i <= 0;
+ if(eof_o) begin
+ case(ecc_addr)
+ 0: ecc0 <= ecc_o;
+ 1: ecc1 <= ecc_o;
+ 2: ecc2 <= ecc_o;
+ 3: ecc3 <= ecc_o;
+ endcase
+ // if we\'re in the last 512-byte block, then also write ecc, spare_space, and spare_space_ecc
+ if(ecc_addr == 3) begin
+ hstate <= ST_WBWRITE_1;
+ // if we\'re not in the last 512-byte block, then ack and return to idle state
+ end else begin
+ wbs_ack_o <= 1;
+ if(wbs_cti_i == WB_CTI_CLASSIC)
+ hstate <= ST_IDLE;
+ else
+ hstate <= ST_WBWRITE;
+ end
+ end
+ end
+ ST_WBWRITE_1: begin
+ data_i <= spare_space_wr[31:0];
+ valid_i <= 1;
+ sof_i <= 1;
+ eof_i <= 0;
+ hstate <= ST_WBWRITE_2;
+ end
+ ST_WBWRITE_2: begin
+ data_i <= spare_space_wr[63:32];
+ valid_i <= 1;
+ sof_i <= 0;
+ eof_i <= 1;
+ hstate <= ST_WBWRITE_3;
+ end
+ ST_WBWRITE_3: begin
+ data_i <= \'h0;
+ valid_i <= 0;
+ sof_i <= 0;
+ eof_i <= 0;
+ if(eof_o) begin
+ wbm_adr_o <= wbm_adr_o + \'h4;
+ spare_space_ecc <= ecc_o;
+ i <= 0;
+ hstate <= ST_WBWRITE_4;
+ end
+ end
+ ST_WBWRITE_4: begin
+ case(wbm_ack_i ? i + \'h1 : i)
+ 0: wbm_dat_o <= {ecc1[7:0], ecc0[23:0]};
+ 1: wbm_dat_o <= {ecc2[15:0], ecc1[23:8]};
+ 2: wbm_dat_o <= {ecc3[23:0], ecc2[23:16]};
+ 3: wbm_dat_o <= {spare_space_wr[31:0]};
+ 4: wbm_dat_o <= {spare_space_wr[63:32]};
+ 5: wbm_dat_o <= {20\'h0, spare_space_ecc[17:12], spare_space_ecc[5:0]};
+ endcase
+
+ wbm_cti_o <= i == 5 ? WB_CTI_EOB : WB_CTI_INCR_BURST;
+ wbm_bte_o <= \'b00;
+ wbm_sel_o <= \'b1111;
+ wbm_cyc_o <= 1;
+ wbm_stb_o <= 1;
+ wbm_we_o <= 1;
+
+ if(wbm_ack_i) begin //wbm_ack_i
+ wbm_adr_o <= wbm_adr_o + \'h4;
+ if(i >= 5) begin
+ wbs_ack_o <= 1;
+
+ // if we just programmed our currently paged block, then invalidate cache
+ if({1\'b0, wbm_adr_o[`FALL:`FPAGES+`FCOLUMNS+1]} == paged[`FBLOCKS+`FPAGES-1:`FPAGES])
+ paged <= {`FPAGES+`FBLOCKS+1{1\'b1}};
+
+ wbm_cyc_o <= 0;
+ hstate <= ST_IDLE;
+ end else
+ i <= i + 1;
+ end
+ end
+
+
+ //
+ // READ WITH ECC
+ //
+ ST_WBREAD: begin
+ newpaged <= {1\'b0, wbm_adr_o[`FALL:`FCOLUMNS+1]};
+
+ if({1\'b0, wbm_adr_o[`FALL:`FCOLUMNS+1]} == paged) begin
+ hstate <= ST_WBREAD_5;
+ end else begin
+ // start read from address 0 of the selected page
+ hstate <= ST_WBREAD_0;
+ end
+ end
+ // perform read cycle
+ ST_WBREAD_0, ST_WBREAD_1: begin if(ST_WBREAD_0) begin
+ wbm_cti_o <= addr_page_end(wbm_adr_o) ? WB_CTI_EOB : WB_CTI_INCR_BURST;
+ wbm_bte_o <= \'b00;
+ wbm_sel_o <= \'b1111;
+ wbm_cyc_o <= 1;
+ wbm_stb_o <= 1;
+ wbm_we_o <= 0;
+
+ if(wbm_ack_i) begin
+ // calculate ECC on read data
+ data_i <= wbm_dat_i;
+ valid_i <= !wbm_adr_o[`FCOLUMNS] || (wbm_adr_o[5:2] == 3) || (wbm_adr_o[5:2] == 4);
+ sof_i <= (!wbm_adr_o[`FCOLUMNS] && (wbm_adr_o[8:2] == {9-2{1\'b0}})) || (wbm_adr_o[`FCOLUMNS] && wbm_adr_o[5:2] == 3);
+ eof_i <= (!wbm_adr_o[`FCOLUMNS] && (wbm_adr_o[8:2] == {9-2{1\'b1}})) || (wbm_adr_o[`FCOLUMNS] && wbm_adr_o[5:2] == 4);
+
+ if(wbm_adr_o[`FCOLUMNS]) begin
+ case(wbm_adr_o[5:2])
+ 0: begin
+ ecc0_cmp[23:0] <= wbm_dat_i[23:0];
+ ecc1_cmp[7:0] <= wbm_dat_i[31:24];
+ end
+ 1: begin
+ ecc1_cmp[23:8] <= wbm_dat_i[15:0];
+ ecc2_cmp[15:0] <= wbm_dat_i[31:16];
+ end
+ 2: begin
+ ecc2_cmp[23:16] <= wbm_dat_i[7:0];
+ ecc3_cmp[23:0] <= wbm_dat_i[31:8];
+ end
+ 3: spare_space_rd[31:0] <= wbm_dat_i;
+ 4: spare_space_rd[63:32] <= wbm_dat_i;
+ 5: begin
+ spare_space_erased <= |wbm_dat_i[31:12];
+ spare_space_ecc_cmp[23:0] <= {6\'h0, wbm_dat_i[11:6], 6\'h0, wbm_dat_i[5:0]};
+ end
+ endcase
+ end
+
+ if(addr_page_end(wbm_adr_o))
+ hstate <= ST_WBREAD_1;
+ else begin
+ wbm_adr_o <= wbm_adr_o + \'h4;
+ end
+ end else begin
+ valid_i <= 0;
+ sof_i <= 0;
+ eof_i <= 0;
+ end
+ end
+
+ // save ecc and keep looping if we haven\'t gotten the full page yet
+ if(eof_o) begin
+ case({wbm_adr_o[2], wbm_adr_o[`FCOLUMNS:9]})
+ 1: ecc0 <= ecc_o;
+ 2: ecc1 <= ecc_o;
+ 3: ecc2 <= ecc_o;
+ 4: ecc3 <= ecc_o;
+ 12: spare_space_ecc <= ecc_o;
+ endcase
+ end
+ if(hstate == ST_WBREAD_1) begin
+ wbm_cti_o <= WB_CTI_CLASSIC;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_adr_o <= \'h0;
+ wbm_sel_o <= \'b0000;
+ wbm_cyc_o <= 0;
+ wbm_stb_o <= 0;
+ wbm_we_o <= 0;
+ hstate <= ST_WBREAD_2;
+ end
+ end
+ // done reading full page, now fix bits
+ ST_WBREAD_2: begin
+ casez({ecc_err(spare_space_ecc, spare_space_ecc_cmp),
+ ecc_err(ecc3, ecc3_cmp),
+ ecc_err(ecc2, ecc2_cmp),
+ ecc_err(ecc1, ecc1_cmp),
+ ecc_err(ecc0, ecc0_cmp)})
+ 5\'bzzzz1: begin
+ fix_bit <= {2\'h0, ecc_bit_pos(ecc0, ecc0_cmp)};
+ ecc0_cmp <= ecc0;
+ hstate <= ST_WBREAD_3;
+ end
+ 5\'bzzz10: begin
+ fix_bit <= {2\'h1, ecc_bit_pos(ecc1, ecc1_cmp)};
+ ecc1_cmp <= ecc1;
+ hstate <= ST_WBREAD_3;
+ end
+ 5\'bzz100: begin
+ fix_bit <= {2\'h2, ecc_bit_pos(ecc2, ecc2_cmp)};
+ ecc2_cmp <= ecc2;
+ hstate <= ST_WBREAD_3;
+ end
+ 5\'bz1000: begin
+ fix_bit <= {2\'h3, ecc_bit_pos(ecc3, ecc2_cmp)};
+ ecc3_cmp <= ecc3;
+ hstate <= ST_WBREAD_3;
+ end
+ 5\'b10000: begin
+ spare_space_rd[ecc_bit_pos(spare_space_ecc, spare_space_ecc_cmp)] <=
+ !spare_space_rd[ecc_bit_pos(spare_space_ecc, spare_space_ecc_cmp)];
+ hstate <= ST_WBREAD_5;
+ end
+ default: begin
+ hstate <= ST_WBREAD_5;
+ end
+ endcase
+ end
+ // to fix the bit error, first read from the bram
+ ST_WBREAD_3: begin
+ hstate <= ST_WBREAD_4;
+ end
+ // then fix it!
+ ST_WBREAD_4: begin
+ hstate <= ST_WBREAD_2;
+ end
+ // now finally return read data to user
+ ST_WBREAD_5: begin
+ wbm_cti_o <= WB_CTI_CLASSIC;
+ wbm_bte_o <= WB_BTE_LINEAR;
+ wbm_adr_o <= \'h0;
+ wbm_sel_o <= \'h0;
+ wbm_cyc_o <= 0;
+ wbm_stb_o <= 0;
+ wbm_we_o <= 0;
+
+ if(wbs_stb_i) begin
+ // make sure we don\'t read further into BRAM than we can
+ if({page_offset, wbs_adr_i[`FCOLUMNS-1:2]} >= (`FCOLUMNS_AND_SPARE/4))
+ wbs_dat_o <= \'h0;
+ else
+ wbs_dat_o <= b_dout;
+
+ // save the last address read from, so next address is + 1
+ addr <= {page_offset, wbs_adr_i[`FCOLUMNS-1:2]} + \'h2;
+ wbs_ack_o <= 1;
+ paged <= newpaged;
+
+ if(wbs_cti_i != WB_CTI_INCR_BURST)
+ hstate <= ST_IDLE;
+ else
+ hstate <= ST_WBREAD_6;
+ end else
+ wbs_ack_o <= 0;
+ end
+ // if we\'re bursting, preemptively increment address
+ ST_WBREAD_6: begin
+ if(wbs_stb_i) begin
+ if(b_addr >= (`FCOLUMNS_AND_SPARE/4))
+ wbs_dat_o <= \'h0;
+ else
+ wbs_dat_o <= b_dout;
+
+ wbs_ack_o <= (wbs_cti_i == WB_CTI_EOB) ? 0 : 1;
+ addr <= addr + \'h1;
+ end else
+ wbs_ack_o <= 0;
+
+ if(!wbs_cyc_i || (wbs_cti_i == WB_CTI_EOB))
+ hstate <= ST_IDLE;
+ end
+ endcase
+ end
+end
+
+
+//
+// Scratch BRAM
+//
+nand_bram_block_dp #(
+ .DATA ( 32 ),
+ .ADDR ( `FCOLUMNS - 1 ),
+ .DEPTH ( `FCOLUMNS_AND_SPARE / 4 )
+) nand_bram_block_dp (
+ .a_clk ( wb_clk ),
+ .a_wr ( a_wr ),
+ .a_addr ( a_addr ),
+ .a_din ( a_din ),
+ .a_dout ( a_dout ),
+ .b_clk ( wb_clk ),
+ .b_wr ( 1\'b0 ), // read only port
+ .b_addr ( b_addr ),
+ .b_din ( b_din ),
+ .b_dout ( b_dout )
+);
+
+always @(*) begin
+ if(wb_rst) begin
+ a_wr <= 0;
+ a_addr <= \'h0;
+ a_din <= \'h0;
+ b_addr <= \'h0;
+ end else begin
+ if((hstate == ST_WBREAD_0) & wbm_ack_i & (wbm_adr_o[`FCOLUMNS:2] < (`FCOLUMNS_AND_SPARE/4))) begin
+ a_wr <= 1;
+ a_addr <= wbm_adr_o[`FCOLUMNS:2];
+ a_din <= wbm_dat_i;
+ end else if(hstate == ST_WBREAD_4) begin
+ a_wr <= 1;
+ a_addr <= fix_bit[13:5];
+ a_din <= b_dout ^ (1\'b1 << fix_bit[4:0]);
+ end else begin
+ a_wr <= 0;
+ a_addr <= \'h0;
+ a_din <= \'h0;
+ end
+
+ if(hstate == ST_WBREAD) begin
+ b_addr <= {page_offset, wbs_adr_i[`FCOLUMNS-1:2]};
+ end else if(hstate == ST_WBREAD_3) begin
+ b_addr <= fix_bit[13:5];
+ end else if(hstate == ST_WBREAD_2) begin
+ b_addr <= {page_offset, wbs_adr_i[`FCOLUMNS-1:2]};
+ end else if((hstate == ST_WBREAD_5) & wbs_stb_i) begin
+ b_addr <= {page_offset, wbs_adr_i[`FCOLUMNS-1:2]} + \'h1;
+ end else if((hstate == ST_WBREAD_6) & wbs_stb_i) begin
+ b_addr <= addr;
+ end else
+ b_addr <= \'h0;
+ end
+end
+
+
+
+//
+// FUNCTIONS
+//
+
+// return true if there\'s 1 bit error
+function ecc_err;
+input [23:0] a;
+input [23:0] b;
+begin
+ ecc_err = (a[11:0] ^ a[23:12] ^ b[11:0] ^ b[23:12]) == {12{1\'b1}};
+end
+endfunction
+
+// return position of bit error
+function [11:0] ecc_bit_pos;
+input [23:0] a;
+input [23:0] b;
+begin
+ ecc_bit_pos = a[23:12] ^ b[23:12];
+end
+endfunction
+
+
+endmodule
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 22:34:23 02/11/2015
+// Design Name: aes_sbox
+// Project Name: crypto_aes
+// Target Device:
+// Tool versions:
+// Description:
+//
+// Verilog Test Fixture created by ISE for module: aes_sbox
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+////////////////////////////////////////////////////////////////////////////////
+
+module aes_sbox_tb;
+
+\t// Inputs
+\treg [7:0] U;
+\treg dec;
+
+\t// Outputs
+\twire [7:0] S;
+
+\treg [8:0] i;
+\treg [8 * 256 - 1:0] test_data;
+\twire [7:0] test_val;
+\t
+\t// Instantiate the Unit Under Test (UUT)
+\taes_sbox uut (
+\t\t.U(U),
+\t\t.dec(dec),
+\t\t.S(S)
+\t);
+
+\tinitial begin
+\t\t// Initialize Inputs
+\t\tU = 0;
+\t\tdec = 0;
+
+\t\t// Wait 100 ns for global reset to finish
+\t\t#100;
+
+\t\t// Add stimulus here
+\t\ttest_data = {
+\t\t\t8\'h63, 8\'h7c, 8\'h77, 8\'h7b, 8\'hf2, 8\'h6b, 8\'h6f, 8\'hc5,
+\t\t\t8\'h30, 8\'h01, 8\'h67, 8\'h2b, 8\'hfe, 8\'hd7, 8\'hab, 8\'h76,
+\t\t\t8\'hca, 8\'h82, 8\'hc9, 8\'h7d, 8\'hfa, 8\'h59, 8\'h47, 8\'hf0,
+\t\t\t8\'had, 8\'hd4, 8\'ha2, 8\'haf, 8\'h9c, 8\'ha4, 8\'h72, 8\'hc0,
+\t\t\t8\'hb7, 8\'hfd, 8\'h93, 8\'h26, 8\'h36, 8\'h3f, 8\'hf7, 8\'hcc,
+\t\t\t8\'h34, 8\'ha5, 8\'he5, 8\'hf1, 8\'h71, 8\'hd8, 8\'h31, 8\'h15,
+\t\t\t8\'h04, 8\'hc7, 8\'h23, 8\'hc3, 8\'h18, 8\'h96, 8\'h05, 8\'h9a,
+\t\t\t8\'h07, 8\'h12, 8\'h80, 8\'he2, 8\'heb, 8\'h27, 8\'hb2, 8\'h75,
+\t\t\t8\'h09, 8\'h83, 8\'h2c, 8\'h1a, 8\'h1b, 8\'h6e, 8\'h5a, 8\'ha0,
+\t\t\t8\'h52, 8\'h3b, 8\'hd6, 8\'hb3, 8\'h29, 8\'he3, 8\'h2f, 8\'h84,
+\t\t\t8\'h53, 8\'hd1, 8\'h00, 8\'hed, 8\'h20, 8\'hfc, 8\'hb1, 8\'h5b,
+\t\t\t8\'h6a, 8\'hcb, 8\'hbe, 8\'h39, 8\'h4a, 8\'h4c, 8\'h58, 8\'hcf,
+\t\t\t8\'hd0, 8\'hef, 8\'haa, 8\'hfb, 8\'h43, 8\'h4d, 8\'h33, 8\'h85,
+\t\t\t8\'h45, 8\'hf9, 8\'h02, 8\'h7f, 8\'h50, 8\'h3c, 8\'h9f, 8\'ha8,
+\t\t\t8\'h51, 8\'ha3, 8\'h40, 8\'h8f, 8\'h92, 8\'h9d, 8\'h38, 8\'hf5,
+\t\t\t8\'hbc, 8\'hb6, 8\'hda, 8\'h21, 8\'h10, 8\'hff, 8\'hf3, 8\'hd2,
+\t\t\t8\'hcd, 8\'h0c, 8\'h13, 8\'hec, 8\'h5f, 8\'h97, 8\'h44, 8\'h17,
+\t\t\t8\'hc4, 8\'ha7, 8\'h7e, 8\'h3d, 8\'h64, 8\'h5d, 8\'h19, 8\'h73,
+\t\t\t8\'h60, 8\'h81, 8\'h4f, 8\'hdc, 8\'h22, 8\'h2a, 8\'h90, 8\'h88,
+\t\t\t8\'h46, 8\'hee, 8\'hb8, 8\'h14, 8\'hde, 8\'h5e, 8\'h0b, 8\'hdb,
+\t\t\t8\'he0, 8\'h32, 8\'h3a, 8\'h0a, 8\'h49, 8\'h06, 8\'h24, 8\'h5c,
+\t\t\t8\'hc2, 8\'hd3, 8\'hac, 8\'h62, 8\'h91, 8\'h95, 8\'he4, 8\'h79,
+\t\t\t8\'he7, 8\'hc8, 8\'h37, 8\'h6d, 8\'h8d, 8\'hd5, 8\'h4e, 8\'ha9,
+\t\t\t8\'h6c, 8\'h56, 8\'hf4, 8\'hea, 8\'h65, 8\'h7a, 8\'hae, 8\'h08,
+\t\t\t8\'hba, 8\'h78, 8\'h25, 8\'h2e, 8\'h1c, 8\'ha6, 8\'hb4, 8\'hc6,
+\t\t\t8\'he8, 8\'hdd, 8\'h74, 8\'h1f, 8\'h4b, 8\'hbd, 8\'h8b, 8\'h8a,
+\t\t\t8\'h70, 8\'h3e, 8\'hb5, 8\'h66, 8\'h48, 8\'h03, 8\'hf6, 8\'h0e,
+\t\t\t8\'h61, 8\'h35, 8\'h57, 8\'hb9, 8\'h86, 8\'hc1, 8\'h1d, 8\'h9e,
+\t\t\t8\'he1, 8\'hf8, 8\'h98, 8\'h11, 8\'h69, 8\'hd9, 8\'h8e, 8\'h94,
+\t\t\t8\'h9b, 8\'h1e, 8\'h87, 8\'he9, 8\'hce, 8\'h55, 8\'h28, 8\'hdf,
+\t\t\t8\'h8c, 8\'ha1, 8\'h89, 8\'h0d, 8\'hbf, 8\'he6, 8\'h42, 8\'h68,
+\t\t\t8\'h41, 8\'h99, 8\'h2d, 8\'h0f, 8\'hb0, 8\'h54, 8\'hbb, 8\'h16
+\t\t};
+\t\t
+\t\t#1;
+\t\t
+\t\tfor(i = 0; i < 256; i = i + 1)
+\t\tbegin
+\t\t\tU = i[7:0];
+\t\t\tdec = 0;
+\t\t\t#1;
+\t\t\tif(test_val != S)
+\t\t\tbegin
+\t\t\t\t$display(""AES sbox forward mismatch at %d"", i);
+\t\t\t\t$stop;
+\t\t\tend
+\t\t\tU = S;
+\t\t\tdec = 1;
+\t\t\t#1;
+\t\t\tif(S != i[7:0])
+\t\t\tbegin
+\t\t\t\t$display(""AES sbox reverse mismatch at %d"", i);
+\t\t\t\t$stop;
+\t\t\tend
+\t\t\ttest_data = test_data << 8;
+\t\tend
+\t\t$display(""AES sbox pass"");
+\t\t$finish;
+\tend
+
+assign test_val = test_data[8 * 256 - 1:8 * 256 - 8];
+
+endmodule
+
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 19:46:48 01/05/2015
+// Design Name:
+// Module Name: db_rom
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module dp_rom #(
+\tparameter aw = 5,
+\tparameter memfile = """"
+) (
+\tinput clk1,
+\tinput en1,
+\tinput [aw - 1:0] adr1,
+\toutput reg [31:0] dat1,
+\tinput clk2,
+\tinput en2,
+\tinput [aw - 1:0] adr2,
+\toutput reg [31:0] dat2
+);
+
+reg [31:0] rom_data[2**aw - 1:0];
+
+initial
+\t$readmemh(memfile, rom_data);
+\t
+always @(posedge clk1)
+begin
+\tif(en1)
+\t\tdat1 <= rom_data[adr1];
+end
+
+always @(posedge clk2)
+begin
+\tif(en2)
+\t\tdat2 <= rom_data[adr2];
+end
+
+endmodule
+"
+"/*\r
+ Copyright 2015, Google Inc.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the ""License"");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an ""AS IS"" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+module ftl_free_fifo (\r
+ input wire clk_50,\r
+ input wire reset_n,\r
+\r
+ input wire [9:0] fifo_data_in,\r
+ input wire fifo_data_wr,\r
+ output wire [9:0] fifo_data_out,\r
+ output reg fifo_data_valid,\r
+ input wire fifo_data_rd,\r
+ output wire fifo_empty\r
+);\r
+\r
+`include ""ftl_const.vh""\r
+\r
+reg fifo_data_wr_1;\r
+reg fifo_data_rd_1;\r
+ \r
+//\r
+// storage for the free block fifo\r
+//\r
+reg [9:0] bram_fifo_wraddr;\r
+reg [9:0] bram_fifo_rdaddr;\r
+reg [9:0] bram_fifo_data;\r
+reg bram_fifo_wren;\r
+wire [9:0] bram_fifo_q;\r
+ \r
+reg [3:0] state;\r
+parameter [3:0] ST_RESET = \'d0,\r
+ ST_IDLE = \'d1, \r
+ ST_UNK = \'d2;\r
+\r
+assign fifo_data_out = bram_fifo_q;\r
+assign fifo_empty = (bram_fifo_rdaddr == bram_fifo_wraddr);\r
+ \r
+always @(posedge clk_50) begin\r
+ bram_fifo_wren <= 0;\r
+\r
+ fifo_data_wr_1 <= fifo_data_wr;\r
+ fifo_data_rd_1 <= fifo_data_rd;\r
+\r
+ case(state)\r
+ ST_RESET: begin\r
+ bram_fifo_rdaddr <= 0; // 1020? why\r
+ bram_fifo_wraddr <= 0;\r
+ fifo_data_valid <= 0;\r
+ state <= ST_IDLE;\r
+ end\r
+ ST_IDLE: begin\r
+ if(fifo_data_wr & ~fifo_data_wr_1) begin\r
+ // new write\r
+ bram_fifo_data <= fifo_data_in;\r
+ bram_fifo_wren <= 1\'b1;\r
+ end else if(fifo_data_rd & ~fifo_data_rd_1) begin\r
+ // new read\r
+ if(!fifo_empty) begin\r
+ fifo_data_valid <= 1;\r
+ end\r
+ end\r
+\r
+ if(~fifo_data_wr & fifo_data_wr_1) begin\r
+ bram_fifo_wraddr <= bram_fifo_wraddr + 1\'b1;\r
+ end\r
+ if(~fifo_data_rd & fifo_data_rd_1) begin\r
+ fifo_data_valid <= 0;\r
+ if(fifo_data_valid) begin\r
+ bram_fifo_rdaddr <= bram_fifo_rdaddr + 1\'b1;\r
+ end\r
+ end\r
+\r
+ end\r
+ endcase\r
+ \r
+ if(~reset_n) begin\r
+ state <= ST_RESET;\r
+ end\r
+end\r
+ \r
+ftl_bram_block_dp #(10, 10) iffbram (\r
+ .a_clk ( clk_50 ),\r
+ .a_wr ( bram_fifo_wren ),\r
+ .a_addr ( bram_fifo_wraddr ),\r
+ .a_din ( bram_fifo_data ),\r
+ .a_dout ( ),\r
+ \r
+ .b_clk ( clk_50 ),\r
+ .b_wr ( 1\'b0 ),\r
+ .b_addr ( bram_fifo_rdaddr ),\r
+ .b_din ( \'h0 ),\r
+ .b_dout ( bram_fifo_q )\r
+);\r
+\r
+endmodule\r
+"
+"/*\r
+ Copyright 2015, Google Inc.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the ""License"");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an ""AS IS"" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+module sd_mgr (\r
+ input wire clk_50,\r
+ input wire reset_n,\r
+\r
+ input wire bram_rd_sd_clk,\r
+ input wire [6:0] bram_rd_sd_addr,\r
+ input wire bram_rd_sd_wren,\r
+ input wire [31:0] bram_rd_sd_data,\r
+ output wire [31:0] bram_rd_sd_q,\r
+\r
+ input wire bram_rd_ext_clk,\r
+ input wire [6:0] bram_rd_ext_addr,\r
+ input wire bram_rd_ext_wren,\r
+ input wire [31:0] bram_rd_ext_data,\r
+ output wire [31:0] bram_rd_ext_q,\r
+\r
+ input wire bram_wr_sd_clk,\r
+ input wire [6:0] bram_wr_sd_addr,\r
+ input wire bram_wr_sd_wren,\r
+ input wire [31:0] bram_wr_sd_data,\r
+ output wire [31:0] bram_wr_sd_q,\r
+\r
+ input wire bram_wr_ext_clk,\r
+ input wire [6:0] bram_wr_ext_addr,\r
+ input wire bram_wr_ext_wren,\r
+ input wire [31:0] bram_wr_ext_data,\r
+ output wire [31:0] bram_wr_ext_q,\r
+\r
+ input wire link_read_act,\r
+ output reg link_read_go,\r
+ input wire [31:0] link_read_addr,\r
+ input wire [31:0] link_read_num,\r
+ input wire link_read_stop,\r
+\r
+ input wire link_write_act,\r
+ output reg link_write_done,\r
+ input wire [31:0] link_write_addr,\r
+ input wire [31:0] link_write_num,\r
+\r
+ output reg ext_read_act,\r
+ input wire ext_read_go,\r
+ output reg [31:0] ext_read_addr,\r
+ output reg [31:0] ext_read_num,\r
+ output reg ext_read_stop,\r
+\r
+ output reg ext_write_act,\r
+ input wire ext_write_done,\r
+ output reg [31:0] ext_write_addr,\r
+ output reg [31:0] ext_write_num\r
+);\r
+\r
+reg [31:0] link_read_addr_latch;\r
+reg [15:0] dc;\r
+ \r
+reg [4:0] state;\r
+parameter [4:0] ST_RESET = \'d0,\r
+ ST_IDLE = \'d4,\r
+ ST_BREAD_0 = \'d5,\r
+ ST_BREAD_1 = \'d6,\r
+ ST_BREAD_2 = \'d7,\r
+ ST_BREAD_3 = \'d8,\r
+ ST_BREAD_4 = \'d9,\r
+ ST_BREAD_5 = \'d10,\r
+ ST_BWRITE_0 = \'d13,\r
+ ST_BWRITE_1 = \'d14,\r
+ ST_BWRITE_2 = \'d15,\r
+ ST_BWRITE_3 = \'d16,\r
+ ST_BWRITE_4 = \'d17,\r
+ ST_BWRITE_5 = \'d18,\r
+ ST_LAST = \'d31;\r
+ \r
+wire reset_s;\r
+wire ext_read_go_s, ext_read_go_r;\r
+wire ext_write_done_s, ext_write_done_r;\r
+synch_3 a(reset_n, reset_s, clk_50);\r
+synch_3 b(ext_read_go, ext_read_go_s, clk_50, ext_read_go_r);\r
+synch_3 c(ext_write_done, ext_write_done_s, clk_50, ext_write_done_r);\r
+\r
+always @(posedge clk_50) begin\r
+\r
+ // free running counter\r
+ dc <= dc + 1\'b1;\r
+ \r
+ link_write_done <= 0;\r
+ \r
+ case(state)\r
+ ST_RESET: begin\r
+ ext_read_act <= 0;\r
+ ext_read_stop <= 0;\r
+ \r
+ ext_write_act <= 0;\r
+ \r
+ sel_rd_sd <= 0;\r
+ sel_rd_ext <= 0;\r
+ \r
+ buf_rd_a_full <= 0;\r
+ buf_rd_b_full <= 0;\r
+ \r
+ sel_wr_sd <= 0;\r
+ sel_wr_ext <= 0;\r
+ \r
+ link_read_go <= 0;\r
+ \r
+ state <= ST_IDLE;\r
+ end\r
+ ST_IDLE: begin\r
+ dc <= 0;\r
+ if(link_read_act) begin\r
+ ext_read_addr <= link_read_addr;\r
+ link_read_addr_latch <= link_read_addr;\r
+ //ext_read_num <= link_read_num;\r
+ ext_read_stop <= 0;\r
+ state <= ST_BREAD_0;\r
+ end else\r
+ if(link_write_act) begin\r
+ ext_write_addr <= link_write_addr;\r
+ //ext_write_num <= link_write_num;\r
+ state <= ST_BWRITE_0;\r
+ end\r
+ end\r
+ ST_BREAD_0: begin\r
+ // 1. check if desired block was already cached in the next read slot\r
+ // 2. if it is, immediately let the SD have it, otherwise stall until it\'s ready\r
+ // 3. then start another read to preload the next block in the sequence\r
+ if( (sel_rd_sd ? {buf_rd_b_block, buf_rd_b_full} : \r
+ {buf_rd_a_block, buf_rd_a_full}) == {ext_read_addr, 1\'b1} ) begin\r
+ // selected buffer has the data already\r
+ link_read_go <= 1;\r
+ // swap wishbone pointer to the next slot\r
+ sel_rd_ext <= ~sel_rd_ext;\r
+ state <= ST_BREAD_3;\r
+ end else begin\r
+ // not in next buffer\r
+ state <= ST_BREAD_1;\r
+ end\r
+ dc <= 0;\r
+ end\r
+ ST_BREAD_1: begin\r
+ // load block if one is not cached\r
+ case(sel_rd_ext)\r
+ 0: buf_rd_a_block <= link_read_addr_latch;\r
+ 1: buf_rd_b_block <= link_read_addr_latch;\r
+ endcase\r
+\r
+ // signal to external (wishbone) to start a block read\r
+ ext_read_act <= 1;\r
+ if(ext_read_go_r ) begin\r
+ ext_read_act <= 0;\r
+ ext_read_stop <= 1;\r
+ // tell link to start pushing data to SD\r
+ link_read_go <= 1;\r
+ case(sel_rd_ext)\r
+ 0: buf_rd_a_full <= 1;\r
+ 1: buf_rd_b_full <= 1;\r
+ endcase\r
+ // swap wishbone pointer to the next slot\r
+ sel_rd_ext <= ~sel_rd_ext;\r
+ state <= ST_BREAD_2;\r
+ end \r
+ end\r
+ ST_BREAD_2: begin\r
+ if(~ext_read_go) begin\r
+ ext_read_stop <= 0;\r
+ state <= ST_BREAD_3;\r
+ end\r
+ dc <= 0;\r
+ end\r
+ ST_BREAD_3: begin\r
+ // preload next block\r
+ case(sel_rd_ext)\r
+ 0: buf_rd_a_block <= link_read_addr_latch + 1;\r
+ 1: buf_rd_b_block <= link_read_addr_latch + 1;\r
+ endcase\r
+ \r
+ // signal to external (wishbone) to start a block read\r
+ ext_read_addr <= link_read_addr_latch + 1;\r
+ ext_read_act <= 1;\r
+ if(ext_read_go_r) begin\r
+ // data is valid\r
+ ext_read_act <= 0;\r
+ ext_read_stop <= 1;\r
+ case(sel_rd_ext)\r
+ 0: buf_rd_a_full <= 1;\r
+ 1: buf_rd_b_full <= 1;\r
+ endcase\r
+ state <= ST_BREAD_4;\r
+ end \r
+ end\r
+ ST_BREAD_4: begin\r
+ if(~ext_read_go) begin\r
+ ext_read_stop <= 0;\r
+ state <= ST_BREAD_5;\r
+ end\r
+ end\r
+ ST_BREAD_5: begin\r
+ // wait for SD to stop sending\r
+ if(link_read_stop) begin\r
+ // finished, or interrupted\r
+ case(sel_rd_sd)\r
+ 0: buf_rd_a_full <= 0;\r
+ 1: buf_rd_b_full <= 0;\r
+ endcase\r
+ link_read_go <= 0;\r
+ state <= ST_IDLE;\r
+ // swap buffers\r
+ sel_rd_sd <= ~sel_rd_sd;\r
+ end\r
+ end\r
+ \r
+ ST_BWRITE_0: begin\r
+ // 1. immediately flush loaded data to wishbone ext\r
+ // 2. accept new data from SD after swapping buffers\r
+ // 3. stall done until WB write is finished\r
+ \r
+ // signal to external (wishbone) to start a block write\r
+ ext_write_act <= 1;\r
+ if(~ext_write_done) begin\r
+ // wait for done to fall to be able to detect the rising/risen edge later\r
+ sel_wr_sd <= ~sel_wr_sd;\r
+ state <= ST_BWRITE_1;\r
+ end\r
+ end \r
+ ST_BWRITE_1: begin\r
+ // tell SD we can accept another block\r
+ link_write_done <= 1;\r
+ // SD may dump another load, we won\'t service it until the FSM returns to idle and notices\r
+ if(~link_write_act) begin\r
+ state <= ST_BWRITE_2;\r
+ end else\r
+ if(ext_write_done) begin \r
+ // external has written the buffer, tell link\r
+ sel_wr_ext <= ~sel_wr_ext;\r
+ ext_write_act <= 0;\r
+ state <= ST_BWRITE_3;\r
+ end \r
+ end\r
+ ST_BWRITE_2: begin\r
+ if(ext_write_done) begin \r
+ // external has written the buffer, tell link\r
+ sel_wr_ext <= ~sel_wr_ext;\r
+ ext_write_act <= 0;\r
+ state <= ST_BWRITE_3;\r
+ end \r
+ end\r
+ ST_BWRITE_3: begin\r
+ // invalidate read cache \r
+ buf_rd_a_full <= 0;\r
+ buf_rd_b_full <= 0;\r
+ state <= ST_IDLE;\r
+ end\r
+ endcase\r
+ \r
+ if(~reset_s) begin\r
+ state <= ST_RESET;\r
+ end \r
+end\r
+\r
+reg sel_rd_sd;\r
+reg sel_rd_ext;\r
+ \r
+reg buf_rd_a_full;\r
+reg buf_rd_b_full;\r
+ \r
+reg [31:0] buf_rd_a_block;\r
+reg [31:0] buf_rd_b_block;\r
+ \r
+// address two sector buffers inside the bram\r
+wire [7:0] bram_rd_sd_addr_sel = (sel_rd_sd ? bram_rd_sd_addr + 8\'d128 : bram_rd_sd_addr) /* synthesis keep */;\r
+wire [7:0] bram_rd_ext_addr_sel = (sel_rd_ext ? bram_rd_ext_addr + 8\'d128 : bram_rd_ext_addr) /* synthesis keep */;\r
+ \r
+// 512 byte bram (2 x 128 x 32bit word)\r
+sd_bram_block_dp #(32, 8) isdb1 (\r
+ .a_clk ( bram_rd_sd_clk ),\r
+ .a_wr ( bram_rd_sd_wren ),\r
+ .a_addr ( bram_rd_sd_addr_sel ),\r
+ .a_din ( bram_rd_sd_data ),\r
+ .a_dout ( bram_rd_sd_q ),\r
+ \r
+ .b_clk ( bram_rd_ext_clk ),\r
+ .b_wr ( bram_rd_ext_wren ),\r
+ .b_addr ( bram_rd_ext_addr_sel ),\r
+ .b_din ( bram_rd_ext_data ),\r
+ .b_dout ( bram_rd_ext_q )\r
+);\r
+\r
+reg sel_wr_sd;\r
+reg sel_wr_ext;\r
+ \r
+// address two sector buffers inside the bram\r
+wire [7:0] bram_wr_sd_addr_sel = (sel_wr_sd ? bram_wr_sd_addr + 8\'d128 : bram_wr_sd_addr) /* synthesis keep */;\r
+wire [7:0] bram_wr_ext_addr_sel = (sel_wr_ext ? bram_wr_ext_addr + 8\'d128 : bram_wr_ext_addr) /* synthesis keep */;\r
+ \r
+// 512 byte bram (2 x 128 x 32bit word)\r
+sd_bram_block_dp #(32, 8) isdb2 (\r
+ .a_clk ( bram_wr_sd_clk ),\r
+ .a_wr ( bram_wr_sd_wren ),\r
+ .a_addr ( bram_wr_sd_addr_sel ),\r
+ .a_din ( bram_wr_sd_data ),\r
+ .a_dout ( bram_wr_sd_q ),\r
+ \r
+ .b_clk ( bram_wr_ext_clk ),\r
+ .b_wr ( bram_wr_ext_wren ),\r
+ .b_addr ( bram_wr_ext_addr_sel ),\r
+ .b_din ( bram_wr_ext_data ),\r
+ .b_dout ( bram_wr_ext_q )\r
+);\r
+\r
+endmodule\r
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 18:26:44 02/02/2015
+// Design Name: sha256_W
+// Project Name: crypto_sha256
+// Target Device:
+// Tool versions:
+// Description:
+//
+// Verilog Test Fixture created by ISE for module: sha256_W
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+////////////////////////////////////////////////////////////////////////////////
+
+module sha256_W_tb;
+
+\t// Inputs
+\treg clk;
+\treg load_i;
+\treg busy_i;
+\treg [511:0] data_i;
+\t
+\treg [31:0] i;
+\treg [32 * 64 - 1:0] test_data;
+\t
+\t// Outputs
+\twire [31:0] W_o;
+
+\twire [31:0] test_val;
+\t
+\t// Instantiate the Unit Under Test (UUT)
+\tsha256_W uut (
+\t\t.clk(clk),
+\t\t.load_i(load_i),
+\t\t.busy_i(busy_i),
+\t\t.data_i(data_i),
+\t\t.W_o(W_o)
+\t);
+
+\tinitial begin
+\t\t// Initialize Inputs
+\t\tclk = 0;
+\t\tload_i = 0;
+\t\tbusy_i = 0;
+\t\tdata_i = 0;
+
+\t\t// Wait 100 ns for global reset to finish
+\t\t#100;
+
+\t\t// Add stimulus here
+\t\tdata_i = {
+\t\t\t32\'h61626380, 32\'h00000000, 32\'h00000000, 32\'h00000000,
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000000,
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000000,
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000018
+\t\t};
+\t\ttest_data = {
+\t\t\t32\'h61626380, 32\'h00000000, 32\'h00000000, 32\'h00000000,
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000000,
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000000,
+\t\t\t32\'h00000000, 32\'h00000000, 32\'h00000000, 32\'h00000018,
+\t\t\t32\'h61626380, 32\'h000f0000, 32\'h7da86405, 32\'h600003c6,
+\t\t\t32\'h3e9d7b78, 32\'h0183fc00, 32\'h12dcbfdb, 32\'he2e2c38e,
+\t\t\t32\'hc8215c1a, 32\'hb73679a2, 32\'he5bc3909, 32\'h32663c5b,
+\t\t\t32\'h9d209d67, 32\'hec8726cb, 32\'h702138a4, 32\'hd3b7973b,
+\t\t\t32\'h93f5997f, 32\'h3b68ba73, 32\'haff4ffc1, 32\'hf10a5c62,
+\t\t\t32\'h0a8b3996, 32\'h72af830a, 32\'h9409e33e, 32\'h24641522,
+\t\t\t32\'h9f47bf94, 32\'hf0a64f5a, 32\'h3e246a79, 32\'h27333ba3,
+\t\t\t32\'h0c4763f2, 32\'h840abf27, 32\'h7a290d5d, 32\'h065c43da,
+\t\t\t32\'hfb3e89cb, 32\'hcc7617db, 32\'hb9e66c34, 32\'ha9993667,
+\t\t\t32\'h84badedd, 32\'hc21462bc, 32\'h1487472c, 32\'hb20f7a99,
+\t\t\t32\'hef57b9cd, 32\'hebe6b238, 32\'h9fe3095e, 32\'h78bc8d4b,
+\t\t\t32\'ha43fcf15, 32\'h668b2ff8, 32\'heeaba2cc, 32\'h12b1edeb,
+\t\t\t32\'hb80a5a34, 32\'h1ce797d5, 32\'h310fc1d7, 32\'ha31968ce,
+\t\t\t32\'h7d8ce042, 32\'hd5892c87, 32\'h0ef2e48b, 32\'h86476aaa
+\t\t};
+\t\tload_i = 1;
+\t\t#20;
+\t\tload_i = 0;
+\t\tbusy_i = 1;
+\t\t
+\t\tfor(i = 0; i < 64; i = i + 1)
+\t\tbegin
+\t\t\tif(test_val != W_o)
+\t\t\tbegin
+\t\t\t\t$display(""MISMATCH: %d %h != %h"",
+\t\t\t\t\t\ti, test_val, W_o);
+\t\t\t\t$stop;
+\t\t\tend
+\t\t\ttest_data <= test_data << 32;
+\t\t\t#20;
+\t\tend
+\t\t$display(""sha256_W passed"");
+\t\t$finish;
+\tend
+
+always #10 clk <= ~clk;
+
+assign test_val = test_data[32 * 80 - 1:32 * 80 - 32];
+endmodule
+
+"
+"/*\r
+ Copyright 2015, Google Inc.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the ""License"");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an ""AS IS"" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+module ftl_wbs (\r
+ input wire clk_50,\r
+ input wire reset_n,\r
+\r
+ // slave wishbone interface (from SDHC)\r
+ input wire wbs_clk_i,\r
+ input wire [31:0] wbs_adr_i,\r
+ output wire [31:0] wbs_dat_o,\r
+ input wire [31:0] wbs_dat_i,\r
+ input wire [3:0] wbs_sel_i,\r
+ input wire wbs_cyc_i,\r
+ input wire wbs_stb_i,\r
+ input wire wbs_we_i,\r
+ output wire wbs_ack_o,\r
+\r
+ // port to cached block ram\r
+ output wire bram_wbs_clk,\r
+ output wire [15:0] bram_wbs_addr,\r
+ output reg bram_wbs_wren,\r
+ output reg [31:0] bram_wbs_data,\r
+ input wire [31:0] bram_wbs_q,\r
+\r
+ input wire logical_init_done,\r
+ output reg wb_read,\r
+ output reg wb_write,\r
+ output reg [9:0] wb_block,\r
+ input wire wb_ack,\r
+ input wire wb_done\r
+);\r
+\r
+`include ""ftl_const.vh""\r
+\r
+assign bram_wbs_clk = wbs_clk_i;\r
+assign bram_wbs_addr = (wbs_adr_i % NAND_BLOCK_SIZE) / 4;\r
+assign wbs_ack_o = wbs_ack & wbs_stb_i;\r
+assign wbs_dat_o = bram_wbs_q;\r
+reg wbs_ack;\r
+reg wbs_stb_i_1;\r
+ \r
+reg wb_done_s_1;\r
+ \r
+wire reset_s;\r
+wire logical_init_done_s;\r
+wire wb_ack_s;\r
+wire wb_done_s;\r
+\r
+synch_3 a(reset_n, reset_s, wbs_clk_i);\r
+synch_3 b(logical_init_done, logical_init_done_s, wbs_clk_i);\r
+synch_3 c(wb_ack, wb_ack_s, wbs_clk_i);\r
+synch_3 d(wb_done, wb_done_s, wbs_clk_i);\r
+\r
+wire [9:0] req_block = wbs_adr_i / NAND_BLOCK_SIZE;\r
+reg [9:0] req_block_latch;\r
+reg [9:0] cached_block;\r
+reg modified;\r
+ \r
+reg [3:0] state;\r
+\r
+wire ftl_valid = wbs_adr_i >= 32\'h200000;\r
+\r
+parameter [3:0] ST_RESET = \'d0,\r
+ ST_IDLE = \'d1,\r
+ ST_READ = \'d2,\r
+ ST_WRITE = \'d3,\r
+ ST_IDLE_WAIT = \'d5,\r
+ ST_READ_DELAY = \'d6;\r
+ \r
+always @(posedge wbs_clk_i) begin\r
+ wbs_ack <= 0;\r
+ wbs_stb_i_1 <= wbs_stb_i;\r
+ \r
+ wb_done_s_1 <= wb_done_s;\r
+ wb_read <= 0;\r
+ wb_write <= 0;\r
+ \r
+ bram_wbs_wren <= 0;\r
+ \r
+ case(state)\r
+ ST_RESET: begin\r
+ cached_block <= -1;\r
+ modified <= 0;\r
+ if(logical_init_done_s) state <= ST_IDLE;\r
+ end\r
+ ST_IDLE: begin\r
+ // on rising edge of WBS_STB_I\r
+ if(wbs_cyc_i & wbs_stb_i & ~wbs_stb_i_1 & ftl_valid) begin\r
+ if(wbs_we_i) begin\r
+ if((cached_block == req_block) && modified) begin\r
+ // write to bram\r
+ bram_wbs_data <= wbs_dat_i;\r
+ bram_wbs_wren <= 1;\r
+ wbs_ack <= 1;\r
+ end else begin\r
+ // switch blocks and mark modified\r
+ state <= ST_WRITE;\r
+ req_block_latch <= req_block;\r
+ end\r
+ //wbs_ack <= 1;\r
+ end else begin\r
+ if(cached_block == req_block) begin\r
+ // read from bram\r
+ state <= ST_READ_DELAY;\r
+ end else begin\r
+ // switch blocks and mark unmodified\r
+ state <= ST_READ;\r
+ req_block_latch <= req_block;\r
+ end\r
+ end\r
+ end\r
+ end\r
+ ST_IDLE_WAIT: begin\r
+ wbs_stb_i_1 <= 0; // make idle state fire again\r
+ if(~wb_ack_s) state <= ST_IDLE;\r
+ end\r
+ ST_WRITE: begin\r
+ modified <= 1;\r
+ wb_block <= req_block_latch;\r
+ wb_write <= 1;\r
+ if(wb_done_s & ~wb_done_s_1) begin\r
+ cached_block <= req_block_latch;\r
+ state <= ST_IDLE_WAIT;\r
+ end \r
+ end\r
+ ST_READ: begin\r
+ modified <= 0;\r
+ wb_block <= req_block_latch;\r
+ wb_read <= 1;\r
+ if(wb_done_s & ~wb_done_s_1) begin\r
+ cached_block <= req_block_latch;\r
+ state <= ST_IDLE_WAIT;\r
+ end \r
+ end\r
+ ST_READ_DELAY: begin\r
+ // delay for bram\r
+ wbs_ack <= 1;\r
+ state <= ST_IDLE;\r
+ end\r
+ endcase\r
+ \r
+ if(~reset_s) begin\r
+ state <= ST_RESET;\r
+ end\r
+end\r
+\r
+endmodule\r
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 23:29:02 11/06/2014
+// Design Name:
+// Module Name: trng_top
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module trng (
+ input clk,
+ input en,
+ output [7:0] R
+);
+
+
+wire [7:0] a, c;
+reg [7:0] b, d;
+
+assign a = (en) ? ({ a[6:0], a[7] } ^ a ^ { a[0], a[7:1] } ^ 8\'h80) : a;
+
+always @(posedge clk)
+begin
+\tb <= a;
+end
+
+assign c = (d & 8\'h96) ^ { d[6:0], 1\'b0 } ^ { 1\'b0, d[7:1] } ^ b;
+always @(posedge clk)
+begin
+\td <= (en) ? c : d;
+end
+
+assign R = d;
+
+endmodule
+"
+"// THIS FILE IS AUTOGENERATED BY wb_intercon_gen
+// ANY MANUAL CHANGES WILL BE LOST
+module wb_intercon
+ (input wb_clk_i,
+ input wb_rst_i,
+ input [31:0] wb_or1k_i_adr_i,
+ input [31:0] wb_or1k_i_dat_i,
+ input [3:0] wb_or1k_i_sel_i,
+ input wb_or1k_i_we_i,
+ input wb_or1k_i_cyc_i,
+ input wb_or1k_i_stb_i,
+ input [2:0] wb_or1k_i_cti_i,
+ input [1:0] wb_or1k_i_bte_i,
+ output [31:0] wb_or1k_i_dat_o,
+ output wb_or1k_i_ack_o,
+ output wb_or1k_i_err_o,
+ output wb_or1k_i_rty_o,
+ input [31:0] wb_or1k_d_adr_i,
+ input [31:0] wb_or1k_d_dat_i,
+ input [3:0] wb_or1k_d_sel_i,
+ input wb_or1k_d_we_i,
+ input wb_or1k_d_cyc_i,
+ input wb_or1k_d_stb_i,
+ input [2:0] wb_or1k_d_cti_i,
+ input [1:0] wb_or1k_d_bte_i,
+ output [31:0] wb_or1k_d_dat_o,
+ output wb_or1k_d_ack_o,
+ output wb_or1k_d_err_o,
+ output wb_or1k_d_rty_o,
+ input [31:0] wb_dbg_adr_i,
+ input [31:0] wb_dbg_dat_i,
+ input [3:0] wb_dbg_sel_i,
+ input wb_dbg_we_i,
+ input wb_dbg_cyc_i,
+ input wb_dbg_stb_i,
+ input [2:0] wb_dbg_cti_i,
+ input [1:0] wb_dbg_bte_i,
+ output [31:0] wb_dbg_dat_o,
+ output wb_dbg_ack_o,
+ output wb_dbg_err_o,
+ output wb_dbg_rty_o,
+ output [31:0] wb_rom0_adr_o,
+ output [31:0] wb_rom0_dat_o,
+ output [3:0] wb_rom0_sel_o,
+ output wb_rom0_we_o,
+ output wb_rom0_cyc_o,
+ output wb_rom0_stb_o,
+ output [2:0] wb_rom0_cti_o,
+ output [1:0] wb_rom0_bte_o,
+ input [31:0] wb_rom0_dat_i,
+ input wb_rom0_ack_i,
+ input wb_rom0_err_i,
+ input wb_rom0_rty_i,
+ output [31:0] wb_ram0_adr_o,
+ output [31:0] wb_ram0_dat_o,
+ output [3:0] wb_ram0_sel_o,
+ output wb_ram0_we_o,
+ output wb_ram0_cyc_o,
+ output wb_ram0_stb_o,
+ output [2:0] wb_ram0_cti_o,
+ output [1:0] wb_ram0_bte_o,
+ input [31:0] wb_ram0_dat_i,
+ input wb_ram0_ack_i,
+ input wb_ram0_err_i,
+ input wb_ram0_rty_i,
+ output [31:0] wb_uart0_adr_o,
+ output [7:0] wb_uart0_dat_o,
+ output [3:0] wb_uart0_sel_o,
+ output wb_uart0_we_o,
+ output wb_uart0_cyc_o,
+ output wb_uart0_stb_o,
+ output [2:0] wb_uart0_cti_o,
+ output [1:0] wb_uart0_bte_o,
+ input [7:0] wb_uart0_dat_i,
+ input wb_uart0_ack_i,
+ input wb_uart0_err_i,
+ input wb_uart0_rty_i,
+ output [31:0] wb_gpio0_adr_o,
+ output [7:0] wb_gpio0_dat_o,
+ output [3:0] wb_gpio0_sel_o,
+ output wb_gpio0_we_o,
+ output wb_gpio0_cyc_o,
+ output wb_gpio0_stb_o,
+ output [2:0] wb_gpio0_cti_o,
+ output [1:0] wb_gpio0_bte_o,
+ input [7:0] wb_gpio0_dat_i,
+ input wb_gpio0_ack_i,
+ input wb_gpio0_err_i,
+ input wb_gpio0_rty_i,
+ output [31:0] wb_trng_adr_o,
+ output [7:0] wb_trng_dat_o,
+ output [3:0] wb_trng_sel_o,
+ output wb_trng_we_o,
+ output wb_trng_cyc_o,
+ output wb_trng_stb_o,
+ output [2:0] wb_trng_cti_o,
+ output [1:0] wb_trng_bte_o,
+ input [7:0] wb_trng_dat_i,
+ input wb_trng_ack_i,
+ input wb_trng_err_i,
+ input wb_trng_rty_i,
+ output [31:0] wb_crypto_aes_adr_o,
+ output [31:0] wb_crypto_aes_dat_o,
+ output [3:0] wb_crypto_aes_sel_o,
+ output wb_crypto_aes_we_o,
+ output wb_crypto_aes_cyc_o,
+ output wb_crypto_aes_stb_o,
+ output [2:0] wb_crypto_aes_cti_o,
+ output [1:0] wb_crypto_aes_bte_o,
+ input [31:0] wb_crypto_aes_dat_i,
+ input wb_crypto_aes_ack_i,
+ input wb_crypto_aes_err_i,
+ input wb_crypto_aes_rty_i,
+ output [31:0] wb_crypto_sha256_adr_o,
+ output [31:0] wb_crypto_sha256_dat_o,
+ output [3:0] wb_crypto_sha256_sel_o,
+ output wb_crypto_sha256_we_o,
+ output wb_crypto_sha256_cyc_o,
+ output wb_crypto_sha256_stb_o,
+ output [2:0] wb_crypto_sha256_cti_o,
+ output [1:0] wb_crypto_sha256_bte_o,
+ input [31:0] wb_crypto_sha256_dat_i,
+ input wb_crypto_sha256_ack_i,
+ input wb_crypto_sha256_err_i,
+ input wb_crypto_sha256_rty_i,
+ output [31:0] wb_fauxfs_cpu_adr_o,
+ output [31:0] wb_fauxfs_cpu_dat_o,
+ output [3:0] wb_fauxfs_cpu_sel_o,
+ output wb_fauxfs_cpu_we_o,
+ output wb_fauxfs_cpu_cyc_o,
+ output wb_fauxfs_cpu_stb_o,
+ output [2:0] wb_fauxfs_cpu_cti_o,
+ output [1:0] wb_fauxfs_cpu_bte_o,
+ input [31:0] wb_fauxfs_cpu_dat_i,
+ input wb_fauxfs_cpu_ack_i,
+ input wb_fauxfs_cpu_err_i,
+ input wb_fauxfs_cpu_rty_i,
+ output [31:0] wb_nand_cpu_adr_o,
+ output [31:0] wb_nand_cpu_dat_o,
+ output [3:0] wb_nand_cpu_sel_o,
+ output wb_nand_cpu_we_o,
+ output wb_nand_cpu_cyc_o,
+ output wb_nand_cpu_stb_o,
+ output [2:0] wb_nand_cpu_cti_o,
+ output [1:0] wb_nand_cpu_bte_o,
+ input [31:0] wb_nand_cpu_dat_i,
+ input wb_nand_cpu_ack_i,
+ input wb_nand_cpu_err_i,
+ input wb_nand_cpu_rty_i,
+ output [31:0] wb_bootrom0_adr_o,
+ output [31:0] wb_bootrom0_dat_o,
+ output [3:0] wb_bootrom0_sel_o,
+ output wb_bootrom0_we_o,
+ output wb_bootrom0_cyc_o,
+ output wb_bootrom0_stb_o,
+ output [2:0] wb_bootrom0_cti_o,
+ output [1:0] wb_bootrom0_bte_o,
+ input [31:0] wb_bootrom0_dat_i,
+ input wb_bootrom0_ack_i,
+ input wb_bootrom0_err_i,
+ input wb_bootrom0_rty_i);
+
+wire [31:0] wb_m2s_or1k_i_rom0_adr;
+wire [31:0] wb_m2s_or1k_i_rom0_dat;
+wire [3:0] wb_m2s_or1k_i_rom0_sel;
+wire wb_m2s_or1k_i_rom0_we;
+wire wb_m2s_or1k_i_rom0_cyc;
+wire wb_m2s_or1k_i_rom0_stb;
+wire [2:0] wb_m2s_or1k_i_rom0_cti;
+wire [1:0] wb_m2s_or1k_i_rom0_bte;
+wire [31:0] wb_s2m_or1k_i_rom0_dat;
+wire wb_s2m_or1k_i_rom0_ack;
+wire wb_s2m_or1k_i_rom0_err;
+wire wb_s2m_or1k_i_rom0_rty;
+wire [31:0] wb_m2s_or1k_i_bootrom0_adr;
+wire [31:0] wb_m2s_or1k_i_bootrom0_dat;
+wire [3:0] wb_m2s_or1k_i_bootrom0_sel;
+wire wb_m2s_or1k_i_bootrom0_we;
+wire wb_m2s_or1k_i_bootrom0_cyc;
+wire wb_m2s_or1k_i_bootrom0_stb;
+wire [2:0] wb_m2s_or1k_i_bootrom0_cti;
+wire [1:0] wb_m2s_or1k_i_bootrom0_bte;
+wire [31:0] wb_s2m_or1k_i_bootrom0_dat;
+wire wb_s2m_or1k_i_bootrom0_ack;
+wire wb_s2m_or1k_i_bootrom0_err;
+wire wb_s2m_or1k_i_bootrom0_rty;
+wire [31:0] wb_m2s_or1k_d_rom0_adr;
+wire [31:0] wb_m2s_or1k_d_rom0_dat;
+wire [3:0] wb_m2s_or1k_d_rom0_sel;
+wire wb_m2s_or1k_d_rom0_we;
+wire wb_m2s_or1k_d_rom0_cyc;
+wire wb_m2s_or1k_d_rom0_stb;
+wire [2:0] wb_m2s_or1k_d_rom0_cti;
+wire [1:0] wb_m2s_or1k_d_rom0_bte;
+wire [31:0] wb_s2m_or1k_d_rom0_dat;
+wire wb_s2m_or1k_d_rom0_ack;
+wire wb_s2m_or1k_d_rom0_err;
+wire wb_s2m_or1k_d_rom0_rty;
+wire [31:0] wb_m2s_or1k_d_ram0_adr;
+wire [31:0] wb_m2s_or1k_d_ram0_dat;
+wire [3:0] wb_m2s_or1k_d_ram0_sel;
+wire wb_m2s_or1k_d_ram0_we;
+wire wb_m2s_or1k_d_ram0_cyc;
+wire wb_m2s_or1k_d_ram0_stb;
+wire [2:0] wb_m2s_or1k_d_ram0_cti;
+wire [1:0] wb_m2s_or1k_d_ram0_bte;
+wire [31:0] wb_s2m_or1k_d_ram0_dat;
+wire wb_s2m_or1k_d_ram0_ack;
+wire wb_s2m_or1k_d_ram0_err;
+wire wb_s2m_or1k_d_ram0_rty;
+wire [31:0] wb_m2s_or1k_d_uart0_adr;
+wire [31:0] wb_m2s_or1k_d_uart0_dat;
+wire [3:0] wb_m2s_or1k_d_uart0_sel;
+wire wb_m2s_or1k_d_uart0_we;
+wire wb_m2s_or1k_d_uart0_cyc;
+wire wb_m2s_or1k_d_uart0_stb;
+wire [2:0] wb_m2s_or1k_d_uart0_cti;
+wire [1:0] wb_m2s_or1k_d_uart0_bte;
+wire [31:0] wb_s2m_or1k_d_uart0_dat;
+wire wb_s2m_or1k_d_uart0_ack;
+wire wb_s2m_or1k_d_uart0_err;
+wire wb_s2m_or1k_d_uart0_rty;
+wire [31:0] wb_m2s_or1k_d_gpio0_adr;
+wire [31:0] wb_m2s_or1k_d_gpio0_dat;
+wire [3:0] wb_m2s_or1k_d_gpio0_sel;
+wire wb_m2s_or1k_d_gpio0_we;
+wire wb_m2s_or1k_d_gpio0_cyc;
+wire wb_m2s_or1k_d_gpio0_stb;
+wire [2:0] wb_m2s_or1k_d_gpio0_cti;
+wire [1:0] wb_m2s_or1k_d_gpio0_bte;
+wire [31:0] wb_s2m_or1k_d_gpio0_dat;
+wire wb_s2m_or1k_d_gpio0_ack;
+wire wb_s2m_or1k_d_gpio0_err;
+wire wb_s2m_or1k_d_gpio0_rty;
+wire [31:0] wb_m2s_or1k_d_trng_adr;
+wire [31:0] wb_m2s_or1k_d_trng_dat;
+wire [3:0] wb_m2s_or1k_d_trng_sel;
+wire wb_m2s_or1k_d_trng_we;
+wire wb_m2s_or1k_d_trng_cyc;
+wire wb_m2s_or1k_d_trng_stb;
+wire [2:0] wb_m2s_or1k_d_trng_cti;
+wire [1:0] wb_m2s_or1k_d_trng_bte;
+wire [31:0] wb_s2m_or1k_d_trng_dat;
+wire wb_s2m_or1k_d_trng_ack;
+wire wb_s2m_or1k_d_trng_err;
+wire wb_s2m_or1k_d_trng_rty;
+wire [31:0] wb_m2s_or1k_d_crypto_aes_adr;
+wire [31:0] wb_m2s_or1k_d_crypto_aes_dat;
+wire [3:0] wb_m2s_or1k_d_crypto_aes_sel;
+wire wb_m2s_or1k_d_crypto_aes_we;
+wire wb_m2s_or1k_d_crypto_aes_cyc;
+wire wb_m2s_or1k_d_crypto_aes_stb;
+wire [2:0] wb_m2s_or1k_d_crypto_aes_cti;
+wire [1:0] wb_m2s_or1k_d_crypto_aes_bte;
+wire [31:0] wb_s2m_or1k_d_crypto_aes_dat;
+wire wb_s2m_or1k_d_crypto_aes_ack;
+wire wb_s2m_or1k_d_crypto_aes_err;
+wire wb_s2m_or1k_d_crypto_aes_rty;
+wire [31:0] wb_m2s_or1k_d_crypto_sha256_adr;
+wire [31:0] wb_m2s_or1k_d_crypto_sha256_dat;
+wire [3:0] wb_m2s_or1k_d_crypto_sha256_sel;
+wire wb_m2s_or1k_d_crypto_sha256_we;
+wire wb_m2s_or1k_d_crypto_sha256_cyc;
+wire wb_m2s_or1k_d_crypto_sha256_stb;
+wire [2:0] wb_m2s_or1k_d_crypto_sha256_cti;
+wire [1:0] wb_m2s_or1k_d_crypto_sha256_bte;
+wire [31:0] wb_s2m_or1k_d_crypto_sha256_dat;
+wire wb_s2m_or1k_d_crypto_sha256_ack;
+wire wb_s2m_or1k_d_crypto_sha256_err;
+wire wb_s2m_or1k_d_crypto_sha256_rty;
+wire [31:0] wb_m2s_or1k_d_fauxfs_cpu_adr;
+wire [31:0] wb_m2s_or1k_d_fauxfs_cpu_dat;
+wire [3:0] wb_m2s_or1k_d_fauxfs_cpu_sel;
+wire wb_m2s_or1k_d_fauxfs_cpu_we;
+wire wb_m2s_or1k_d_fauxfs_cpu_cyc;
+wire wb_m2s_or1k_d_fauxfs_cpu_stb;
+wire [2:0] wb_m2s_or1k_d_fauxfs_cpu_cti;
+wire [1:0] wb_m2s_or1k_d_fauxfs_cpu_bte;
+wire [31:0] wb_s2m_or1k_d_fauxfs_cpu_dat;
+wire wb_s2m_or1k_d_fauxfs_cpu_ack;
+wire wb_s2m_or1k_d_fauxfs_cpu_err;
+wire wb_s2m_or1k_d_fauxfs_cpu_rty;
+wire [31:0] wb_m2s_or1k_d_nand_cpu_adr;
+wire [31:0] wb_m2s_or1k_d_nand_cpu_dat;
+wire [3:0] wb_m2s_or1k_d_nand_cpu_sel;
+wire wb_m2s_or1k_d_nand_cpu_we;
+wire wb_m2s_or1k_d_nand_cpu_cyc;
+wire wb_m2s_or1k_d_nand_cpu_stb;
+wire [2:0] wb_m2s_or1k_d_nand_cpu_cti;
+wire [1:0] wb_m2s_or1k_d_nand_cpu_bte;
+wire [31:0] wb_s2m_or1k_d_nand_cpu_dat;
+wire wb_s2m_or1k_d_nand_cpu_ack;
+wire wb_s2m_or1k_d_nand_cpu_err;
+wire wb_s2m_or1k_d_nand_cpu_rty;
+wire [31:0] wb_m2s_or1k_d_bootrom0_adr;
+wire [31:0] wb_m2s_or1k_d_bootrom0_dat;
+wire [3:0] wb_m2s_or1k_d_bootrom0_sel;
+wire wb_m2s_or1k_d_bootrom0_we;
+wire wb_m2s_or1k_d_bootrom0_cyc;
+wire wb_m2s_or1k_d_bootrom0_stb;
+wire [2:0] wb_m2s_or1k_d_bootrom0_cti;
+wire [1:0] wb_m2s_or1k_d_bootrom0_bte;
+wire [31:0] wb_s2m_or1k_d_bootrom0_dat;
+wire wb_s2m_or1k_d_bootrom0_ack;
+wire wb_s2m_or1k_d_bootrom0_err;
+wire wb_s2m_or1k_d_bootrom0_rty;
+wire [31:0] wb_m2s_dbg_rom0_adr;
+wire [31:0] wb_m2s_dbg_rom0_dat;
+wire [3:0] wb_m2s_dbg_rom0_sel;
+wire wb_m2s_dbg_rom0_we;
+wire wb_m2s_dbg_rom0_cyc;
+wire wb_m2s_dbg_rom0_stb;
+wire [2:0] wb_m2s_dbg_rom0_cti;
+wire [1:0] wb_m2s_dbg_rom0_bte;
+wire [31:0] wb_s2m_dbg_rom0_dat;
+wire wb_s2m_dbg_rom0_ack;
+wire wb_s2m_dbg_rom0_err;
+wire wb_s2m_dbg_rom0_rty;
+wire [31:0] wb_m2s_dbg_ram0_adr;
+wire [31:0] wb_m2s_dbg_ram0_dat;
+wire [3:0] wb_m2s_dbg_ram0_sel;
+wire wb_m2s_dbg_ram0_we;
+wire wb_m2s_dbg_ram0_cyc;
+wire wb_m2s_dbg_ram0_stb;
+wire [2:0] wb_m2s_dbg_ram0_cti;
+wire [1:0] wb_m2s_dbg_ram0_bte;
+wire [31:0] wb_s2m_dbg_ram0_dat;
+wire wb_s2m_dbg_ram0_ack;
+wire wb_s2m_dbg_ram0_err;
+wire wb_s2m_dbg_ram0_rty;
+wire [31:0] wb_m2s_dbg_uart0_adr;
+wire [31:0] wb_m2s_dbg_uart0_dat;
+wire [3:0] wb_m2s_dbg_uart0_sel;
+wire wb_m2s_dbg_uart0_we;
+wire wb_m2s_dbg_uart0_cyc;
+wire wb_m2s_dbg_uart0_stb;
+wire [2:0] wb_m2s_dbg_uart0_cti;
+wire [1:0] wb_m2s_dbg_uart0_bte;
+wire [31:0] wb_s2m_dbg_uart0_dat;
+wire wb_s2m_dbg_uart0_ack;
+wire wb_s2m_dbg_uart0_err;
+wire wb_s2m_dbg_uart0_rty;
+wire [31:0] wb_m2s_dbg_gpio0_adr;
+wire [31:0] wb_m2s_dbg_gpio0_dat;
+wire [3:0] wb_m2s_dbg_gpio0_sel;
+wire wb_m2s_dbg_gpio0_we;
+wire wb_m2s_dbg_gpio0_cyc;
+wire wb_m2s_dbg_gpio0_stb;
+wire [2:0] wb_m2s_dbg_gpio0_cti;
+wire [1:0] wb_m2s_dbg_gpio0_bte;
+wire [31:0] wb_s2m_dbg_gpio0_dat;
+wire wb_s2m_dbg_gpio0_ack;
+wire wb_s2m_dbg_gpio0_err;
+wire wb_s2m_dbg_gpio0_rty;
+wire [31:0] wb_m2s_dbg_trng_adr;
+wire [31:0] wb_m2s_dbg_trng_dat;
+wire [3:0] wb_m2s_dbg_trng_sel;
+wire wb_m2s_dbg_trng_we;
+wire wb_m2s_dbg_trng_cyc;
+wire wb_m2s_dbg_trng_stb;
+wire [2:0] wb_m2s_dbg_trng_cti;
+wire [1:0] wb_m2s_dbg_trng_bte;
+wire [31:0] wb_s2m_dbg_trng_dat;
+wire wb_s2m_dbg_trng_ack;
+wire wb_s2m_dbg_trng_err;
+wire wb_s2m_dbg_trng_rty;
+wire [31:0] wb_m2s_dbg_crypto_aes_adr;
+wire [31:0] wb_m2s_dbg_crypto_aes_dat;
+wire [3:0] wb_m2s_dbg_crypto_aes_sel;
+wire wb_m2s_dbg_crypto_aes_we;
+wire wb_m2s_dbg_crypto_aes_cyc;
+wire wb_m2s_dbg_crypto_aes_stb;
+wire [2:0] wb_m2s_dbg_crypto_aes_cti;
+wire [1:0] wb_m2s_dbg_crypto_aes_bte;
+wire [31:0] wb_s2m_dbg_crypto_aes_dat;
+wire wb_s2m_dbg_crypto_aes_ack;
+wire wb_s2m_dbg_crypto_aes_err;
+wire wb_s2m_dbg_crypto_aes_rty;
+wire [31:0] wb_m2s_dbg_crypto_sha256_adr;
+wire [31:0] wb_m2s_dbg_crypto_sha256_dat;
+wire [3:0] wb_m2s_dbg_crypto_sha256_sel;
+wire wb_m2s_dbg_crypto_sha256_we;
+wire wb_m2s_dbg_crypto_sha256_cyc;
+wire wb_m2s_dbg_crypto_sha256_stb;
+wire [2:0] wb_m2s_dbg_crypto_sha256_cti;
+wire [1:0] wb_m2s_dbg_crypto_sha256_bte;
+wire [31:0] wb_s2m_dbg_crypto_sha256_dat;
+wire wb_s2m_dbg_crypto_sha256_ack;
+wire wb_s2m_dbg_crypto_sha256_err;
+wire wb_s2m_dbg_crypto_sha256_rty;
+wire [31:0] wb_m2s_dbg_fauxfs_cpu_adr;
+wire [31:0] wb_m2s_dbg_fauxfs_cpu_dat;
+wire [3:0] wb_m2s_dbg_fauxfs_cpu_sel;
+wire wb_m2s_dbg_fauxfs_cpu_we;
+wire wb_m2s_dbg_fauxfs_cpu_cyc;
+wire wb_m2s_dbg_fauxfs_cpu_stb;
+wire [2:0] wb_m2s_dbg_fauxfs_cpu_cti;
+wire [1:0] wb_m2s_dbg_fauxfs_cpu_bte;
+wire [31:0] wb_s2m_dbg_fauxfs_cpu_dat;
+wire wb_s2m_dbg_fauxfs_cpu_ack;
+wire wb_s2m_dbg_fauxfs_cpu_err;
+wire wb_s2m_dbg_fauxfs_cpu_rty;
+wire [31:0] wb_m2s_dbg_nand_cpu_adr;
+wire [31:0] wb_m2s_dbg_nand_cpu_dat;
+wire [3:0] wb_m2s_dbg_nand_cpu_sel;
+wire wb_m2s_dbg_nand_cpu_we;
+wire wb_m2s_dbg_nand_cpu_cyc;
+wire wb_m2s_dbg_nand_cpu_stb;
+wire [2:0] wb_m2s_dbg_nand_cpu_cti;
+wire [1:0] wb_m2s_dbg_nand_cpu_bte;
+wire [31:0] wb_s2m_dbg_nand_cpu_dat;
+wire wb_s2m_dbg_nand_cpu_ack;
+wire wb_s2m_dbg_nand_cpu_err;
+wire wb_s2m_dbg_nand_cpu_rty;
+wire [31:0] wb_m2s_dbg_bootrom0_adr;
+wire [31:0] wb_m2s_dbg_bootrom0_dat;
+wire [3:0] wb_m2s_dbg_bootrom0_sel;
+wire wb_m2s_dbg_bootrom0_we;
+wire wb_m2s_dbg_bootrom0_cyc;
+wire wb_m2s_dbg_bootrom0_stb;
+wire [2:0] wb_m2s_dbg_bootrom0_cti;
+wire [1:0] wb_m2s_dbg_bootrom0_bte;
+wire [31:0] wb_s2m_dbg_bootrom0_dat;
+wire wb_s2m_dbg_bootrom0_ack;
+wire wb_s2m_dbg_bootrom0_err;
+wire wb_s2m_dbg_bootrom0_rty;
+wire [31:0] wb_m2s_resize_uart0_adr;
+wire [31:0] wb_m2s_resize_uart0_dat;
+wire [3:0] wb_m2s_resize_uart0_sel;
+wire wb_m2s_resize_uart0_we;
+wire wb_m2s_resize_uart0_cyc;
+wire wb_m2s_resize_uart0_stb;
+wire [2:0] wb_m2s_resize_uart0_cti;
+wire [1:0] wb_m2s_resize_uart0_bte;
+wire [31:0] wb_s2m_resize_uart0_dat;
+wire wb_s2m_resize_uart0_ack;
+wire wb_s2m_resize_uart0_err;
+wire wb_s2m_resize_uart0_rty;
+wire [31:0] wb_m2s_resize_gpio0_adr;
+wire [31:0] wb_m2s_resize_gpio0_dat;
+wire [3:0] wb_m2s_resize_gpio0_sel;
+wire wb_m2s_resize_gpio0_we;
+wire wb_m2s_resize_gpio0_cyc;
+wire wb_m2s_resize_gpio0_stb;
+wire [2:0] wb_m2s_resize_gpio0_cti;
+wire [1:0] wb_m2s_resize_gpio0_bte;
+wire [31:0] wb_s2m_resize_gpio0_dat;
+wire wb_s2m_resize_gpio0_ack;
+wire wb_s2m_resize_gpio0_err;
+wire wb_s2m_resize_gpio0_rty;
+wire [31:0] wb_m2s_resize_trng_adr;
+wire [31:0] wb_m2s_resize_trng_dat;
+wire [3:0] wb_m2s_resize_trng_sel;
+wire wb_m2s_resize_trng_we;
+wire wb_m2s_resize_trng_cyc;
+wire wb_m2s_resize_trng_stb;
+wire [2:0] wb_m2s_resize_trng_cti;
+wire [1:0] wb_m2s_resize_trng_bte;
+wire [31:0] wb_s2m_resize_trng_dat;
+wire wb_s2m_resize_trng_ack;
+wire wb_s2m_resize_trng_err;
+wire wb_s2m_resize_trng_rty;
+
+wb_mux
+ #(.num_slaves (2),
+ .MATCH_ADDR ({32'h00100000, 32'hf0000100}),
+ .MATCH_MASK ({32'hffff0000, 32'hffffff80}))
+ wb_mux_or1k_i
+ (.wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wbm_adr_i (wb_or1k_i_adr_i),
+ .wbm_dat_i (wb_or1k_i_dat_i),
+ .wbm_sel_i (wb_or1k_i_sel_i),
+ .wbm_we_i (wb_or1k_i_we_i),
+ .wbm_cyc_i (wb_or1k_i_cyc_i),
+ .wbm_stb_i (wb_or1k_i_stb_i),
+ .wbm_cti_i (wb_or1k_i_cti_i),
+ .wbm_bte_i (wb_or1k_i_bte_i),
+ .wbm_dat_o (wb_or1k_i_dat_o),
+ .wbm_ack_o (wb_or1k_i_ack_o),
+ .wbm_err_o (wb_or1k_i_err_o),
+ .wbm_rty_o (wb_or1k_i_rty_o),
+ .wbs_adr_o ({wb_m2s_or1k_i_rom0_adr, wb_m2s_or1k_i_bootrom0_adr}),
+ .wbs_dat_o ({wb_m2s_or1k_i_rom0_dat, wb_m2s_or1k_i_bootrom0_dat}),
+ .wbs_sel_o ({wb_m2s_or1k_i_rom0_sel, wb_m2s_or1k_i_bootrom0_sel}),
+ .wbs_we_o ({wb_m2s_or1k_i_rom0_we, wb_m2s_or1k_i_bootrom0_we}),
+ .wbs_cyc_o ({wb_m2s_or1k_i_rom0_cyc, wb_m2s_or1k_i_bootrom0_cyc}),
+ .wbs_stb_o ({wb_m2s_or1k_i_rom0_stb, wb_m2s_or1k_i_bootrom0_stb}),
+ .wbs_cti_o ({wb_m2s_or1k_i_rom0_cti, wb_m2s_or1k_i_bootrom0_cti}),
+ .wbs_bte_o ({wb_m2s_or1k_i_rom0_bte, wb_m2s_or1k_i_bootrom0_bte}),
+ .wbs_dat_i ({wb_s2m_or1k_i_rom0_dat, wb_s2m_or1k_i_bootrom0_dat}),
+ .wbs_ack_i ({wb_s2m_or1k_i_rom0_ack, wb_s2m_or1k_i_bootrom0_ack}),
+ .wbs_err_i ({wb_s2m_or1k_i_rom0_err, wb_s2m_or1k_i_bootrom0_err}),
+ .wbs_rty_i ({wb_s2m_or1k_i_rom0_rty, wb_s2m_or1k_i_bootrom0_rty}));
+
+wb_mux
+ #(.num_slaves (10),
+ .MATCH_ADDR ({32'h00100000, 32'h00200000, 32'h90000000, 32'h91000000, 32'h92000000, 32'h93000000, 32'h94000000, 32'h98000000, 32'ha0000000, 32'hf0000100}),
+ .MATCH_MASK ({32'hffff0000, 32'hfffe0000, 32'hffffffe0, 32'hfffffffe, 32'hffffffff, 32'hffffff80, 32'hffffff00, 32'hffffe000, 32'hffffe000, 32'hffffff80}))
+ wb_mux_or1k_d
+ (.wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wbm_adr_i (wb_or1k_d_adr_i),
+ .wbm_dat_i (wb_or1k_d_dat_i),
+ .wbm_sel_i (wb_or1k_d_sel_i),
+ .wbm_we_i (wb_or1k_d_we_i),
+ .wbm_cyc_i (wb_or1k_d_cyc_i),
+ .wbm_stb_i (wb_or1k_d_stb_i),
+ .wbm_cti_i (wb_or1k_d_cti_i),
+ .wbm_bte_i (wb_or1k_d_bte_i),
+ .wbm_dat_o (wb_or1k_d_dat_o),
+ .wbm_ack_o (wb_or1k_d_ack_o),
+ .wbm_err_o (wb_or1k_d_err_o),
+ .wbm_rty_o (wb_or1k_d_rty_o),
+ .wbs_adr_o ({wb_m2s_or1k_d_rom0_adr, wb_m2s_or1k_d_ram0_adr, wb_m2s_or1k_d_uart0_adr, wb_m2s_or1k_d_gpio0_adr, wb_m2s_or1k_d_trng_adr, wb_m2s_or1k_d_crypto_aes_adr, wb_m2s_or1k_d_crypto_sha256_adr, wb_m2s_or1k_d_fauxfs_cpu_adr, wb_m2s_or1k_d_nand_cpu_adr, wb_m2s_or1k_d_bootrom0_adr}),
+ .wbs_dat_o ({wb_m2s_or1k_d_rom0_dat, wb_m2s_or1k_d_ram0_dat, wb_m2s_or1k_d_uart0_dat, wb_m2s_or1k_d_gpio0_dat, wb_m2s_or1k_d_trng_dat, wb_m2s_or1k_d_crypto_aes_dat, wb_m2s_or1k_d_crypto_sha256_dat, wb_m2s_or1k_d_fauxfs_cpu_dat, wb_m2s_or1k_d_nand_cpu_dat, wb_m2s_or1k_d_bootrom0_dat}),
+ .wbs_sel_o ({wb_m2s_or1k_d_rom0_sel, wb_m2s_or1k_d_ram0_sel, wb_m2s_or1k_d_uart0_sel, wb_m2s_or1k_d_gpio0_sel, wb_m2s_or1k_d_trng_sel, wb_m2s_or1k_d_crypto_aes_sel, wb_m2s_or1k_d_crypto_sha256_sel, wb_m2s_or1k_d_fauxfs_cpu_sel, wb_m2s_or1k_d_nand_cpu_sel, wb_m2s_or1k_d_bootrom0_sel}),
+ .wbs_we_o ({wb_m2s_or1k_d_rom0_we, wb_m2s_or1k_d_ram0_we, wb_m2s_or1k_d_uart0_we, wb_m2s_or1k_d_gpio0_we, wb_m2s_or1k_d_trng_we, wb_m2s_or1k_d_crypto_aes_we, wb_m2s_or1k_d_crypto_sha256_we, wb_m2s_or1k_d_fauxfs_cpu_we, wb_m2s_or1k_d_nand_cpu_we, wb_m2s_or1k_d_bootrom0_we}),
+ .wbs_cyc_o ({wb_m2s_or1k_d_rom0_cyc, wb_m2s_or1k_d_ram0_cyc, wb_m2s_or1k_d_uart0_cyc, wb_m2s_or1k_d_gpio0_cyc, wb_m2s_or1k_d_trng_cyc, wb_m2s_or1k_d_crypto_aes_cyc, wb_m2s_or1k_d_crypto_sha256_cyc, wb_m2s_or1k_d_fauxfs_cpu_cyc, wb_m2s_or1k_d_nand_cpu_cyc, wb_m2s_or1k_d_bootrom0_cyc}),
+ .wbs_stb_o ({wb_m2s_or1k_d_rom0_stb, wb_m2s_or1k_d_ram0_stb, wb_m2s_or1k_d_uart0_stb, wb_m2s_or1k_d_gpio0_stb, wb_m2s_or1k_d_trng_stb, wb_m2s_or1k_d_crypto_aes_stb, wb_m2s_or1k_d_crypto_sha256_stb, wb_m2s_or1k_d_fauxfs_cpu_stb, wb_m2s_or1k_d_nand_cpu_stb, wb_m2s_or1k_d_bootrom0_stb}),
+ .wbs_cti_o ({wb_m2s_or1k_d_rom0_cti, wb_m2s_or1k_d_ram0_cti, wb_m2s_or1k_d_uart0_cti, wb_m2s_or1k_d_gpio0_cti, wb_m2s_or1k_d_trng_cti, wb_m2s_or1k_d_crypto_aes_cti, wb_m2s_or1k_d_crypto_sha256_cti, wb_m2s_or1k_d_fauxfs_cpu_cti, wb_m2s_or1k_d_nand_cpu_cti, wb_m2s_or1k_d_bootrom0_cti}),
+ .wbs_bte_o ({wb_m2s_or1k_d_rom0_bte, wb_m2s_or1k_d_ram0_bte, wb_m2s_or1k_d_uart0_bte, wb_m2s_or1k_d_gpio0_bte, wb_m2s_or1k_d_trng_bte, wb_m2s_or1k_d_crypto_aes_bte, wb_m2s_or1k_d_crypto_sha256_bte, wb_m2s_or1k_d_fauxfs_cpu_bte, wb_m2s_or1k_d_nand_cpu_bte, wb_m2s_or1k_d_bootrom0_bte}),
+ .wbs_dat_i ({wb_s2m_or1k_d_rom0_dat, wb_s2m_or1k_d_ram0_dat, wb_s2m_or1k_d_uart0_dat, wb_s2m_or1k_d_gpio0_dat, wb_s2m_or1k_d_trng_dat, wb_s2m_or1k_d_crypto_aes_dat, wb_s2m_or1k_d_crypto_sha256_dat, wb_s2m_or1k_d_fauxfs_cpu_dat, wb_s2m_or1k_d_nand_cpu_dat, wb_s2m_or1k_d_bootrom0_dat}),
+ .wbs_ack_i ({wb_s2m_or1k_d_rom0_ack, wb_s2m_or1k_d_ram0_ack, wb_s2m_or1k_d_uart0_ack, wb_s2m_or1k_d_gpio0_ack, wb_s2m_or1k_d_trng_ack, wb_s2m_or1k_d_crypto_aes_ack, wb_s2m_or1k_d_crypto_sha256_ack, wb_s2m_or1k_d_fauxfs_cpu_ack, wb_s2m_or1k_d_nand_cpu_ack, wb_s2m_or1k_d_bootrom0_ack}),
+ .wbs_err_i ({wb_s2m_or1k_d_rom0_err, wb_s2m_or1k_d_ram0_err, wb_s2m_or1k_d_uart0_err, wb_s2m_or1k_d_gpio0_err, wb_s2m_or1k_d_trng_err, wb_s2m_or1k_d_crypto_aes_err, wb_s2m_or1k_d_crypto_sha256_err, wb_s2m_or1k_d_fauxfs_cpu_err, wb_s2m_or1k_d_nand_cpu_err, wb_s2m_or1k_d_bootrom0_err}),
+ .wbs_rty_i ({wb_s2m_or1k_d_rom0_rty, wb_s2m_or1k_d_ram0_rty, wb_s2m_or1k_d_uart0_rty, wb_s2m_or1k_d_gpio0_rty, wb_s2m_or1k_d_trng_rty, wb_s2m_or1k_d_crypto_aes_rty, wb_s2m_or1k_d_crypto_sha256_rty, wb_s2m_or1k_d_fauxfs_cpu_rty, wb_s2m_or1k_d_nand_cpu_rty, wb_s2m_or1k_d_bootrom0_rty}));
+
+wb_mux
+ #(.num_slaves (10),
+ .MATCH_ADDR ({32'h00100000, 32'h00200000, 32'h90000000, 32'h91000000, 32'h92000000, 32'h93000000, 32'h94000000, 32'h98000000, 32'ha0000000, 32'hf0000100}),
+ .MATCH_MASK ({32'hffff0000, 32'hfffe0000, 32'hffffffe0, 32'hfffffffe, 32'hffffffff, 32'hffffff80, 32'hffffff00, 32'hffffe000, 32'hffffe000, 32'hffffff80}))
+ wb_mux_dbg
+ (.wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wbm_adr_i (wb_dbg_adr_i),
+ .wbm_dat_i (wb_dbg_dat_i),
+ .wbm_sel_i (wb_dbg_sel_i),
+ .wbm_we_i (wb_dbg_we_i),
+ .wbm_cyc_i (wb_dbg_cyc_i),
+ .wbm_stb_i (wb_dbg_stb_i),
+ .wbm_cti_i (wb_dbg_cti_i),
+ .wbm_bte_i (wb_dbg_bte_i),
+ .wbm_dat_o (wb_dbg_dat_o),
+ .wbm_ack_o (wb_dbg_ack_o),
+ .wbm_err_o (wb_dbg_err_o),
+ .wbm_rty_o (wb_dbg_rty_o),
+ .wbs_adr_o ({wb_m2s_dbg_rom0_adr, wb_m2s_dbg_ram0_adr, wb_m2s_dbg_uart0_adr, wb_m2s_dbg_gpio0_adr, wb_m2s_dbg_trng_adr, wb_m2s_dbg_crypto_aes_adr, wb_m2s_dbg_crypto_sha256_adr, wb_m2s_dbg_fauxfs_cpu_adr, wb_m2s_dbg_nand_cpu_adr, wb_m2s_dbg_bootrom0_adr}),
+ .wbs_dat_o ({wb_m2s_dbg_rom0_dat, wb_m2s_dbg_ram0_dat, wb_m2s_dbg_uart0_dat, wb_m2s_dbg_gpio0_dat, wb_m2s_dbg_trng_dat, wb_m2s_dbg_crypto_aes_dat, wb_m2s_dbg_crypto_sha256_dat, wb_m2s_dbg_fauxfs_cpu_dat, wb_m2s_dbg_nand_cpu_dat, wb_m2s_dbg_bootrom0_dat}),
+ .wbs_sel_o ({wb_m2s_dbg_rom0_sel, wb_m2s_dbg_ram0_sel, wb_m2s_dbg_uart0_sel, wb_m2s_dbg_gpio0_sel, wb_m2s_dbg_trng_sel, wb_m2s_dbg_crypto_aes_sel, wb_m2s_dbg_crypto_sha256_sel, wb_m2s_dbg_fauxfs_cpu_sel, wb_m2s_dbg_nand_cpu_sel, wb_m2s_dbg_bootrom0_sel}),
+ .wbs_we_o ({wb_m2s_dbg_rom0_we, wb_m2s_dbg_ram0_we, wb_m2s_dbg_uart0_we, wb_m2s_dbg_gpio0_we, wb_m2s_dbg_trng_we, wb_m2s_dbg_crypto_aes_we, wb_m2s_dbg_crypto_sha256_we, wb_m2s_dbg_fauxfs_cpu_we, wb_m2s_dbg_nand_cpu_we, wb_m2s_dbg_bootrom0_we}),
+ .wbs_cyc_o ({wb_m2s_dbg_rom0_cyc, wb_m2s_dbg_ram0_cyc, wb_m2s_dbg_uart0_cyc, wb_m2s_dbg_gpio0_cyc, wb_m2s_dbg_trng_cyc, wb_m2s_dbg_crypto_aes_cyc, wb_m2s_dbg_crypto_sha256_cyc, wb_m2s_dbg_fauxfs_cpu_cyc, wb_m2s_dbg_nand_cpu_cyc, wb_m2s_dbg_bootrom0_cyc}),
+ .wbs_stb_o ({wb_m2s_dbg_rom0_stb, wb_m2s_dbg_ram0_stb, wb_m2s_dbg_uart0_stb, wb_m2s_dbg_gpio0_stb, wb_m2s_dbg_trng_stb, wb_m2s_dbg_crypto_aes_stb, wb_m2s_dbg_crypto_sha256_stb, wb_m2s_dbg_fauxfs_cpu_stb, wb_m2s_dbg_nand_cpu_stb, wb_m2s_dbg_bootrom0_stb}),
+ .wbs_cti_o ({wb_m2s_dbg_rom0_cti, wb_m2s_dbg_ram0_cti, wb_m2s_dbg_uart0_cti, wb_m2s_dbg_gpio0_cti, wb_m2s_dbg_trng_cti, wb_m2s_dbg_crypto_aes_cti, wb_m2s_dbg_crypto_sha256_cti, wb_m2s_dbg_fauxfs_cpu_cti, wb_m2s_dbg_nand_cpu_cti, wb_m2s_dbg_bootrom0_cti}),
+ .wbs_bte_o ({wb_m2s_dbg_rom0_bte, wb_m2s_dbg_ram0_bte, wb_m2s_dbg_uart0_bte, wb_m2s_dbg_gpio0_bte, wb_m2s_dbg_trng_bte, wb_m2s_dbg_crypto_aes_bte, wb_m2s_dbg_crypto_sha256_bte, wb_m2s_dbg_fauxfs_cpu_bte, wb_m2s_dbg_nand_cpu_bte, wb_m2s_dbg_bootrom0_bte}),
+ .wbs_dat_i ({wb_s2m_dbg_rom0_dat, wb_s2m_dbg_ram0_dat, wb_s2m_dbg_uart0_dat, wb_s2m_dbg_gpio0_dat, wb_s2m_dbg_trng_dat, wb_s2m_dbg_crypto_aes_dat, wb_s2m_dbg_crypto_sha256_dat, wb_s2m_dbg_fauxfs_cpu_dat, wb_s2m_dbg_nand_cpu_dat, wb_s2m_dbg_bootrom0_dat}),
+ .wbs_ack_i ({wb_s2m_dbg_rom0_ack, wb_s2m_dbg_ram0_ack, wb_s2m_dbg_uart0_ack, wb_s2m_dbg_gpio0_ack, wb_s2m_dbg_trng_ack, wb_s2m_dbg_crypto_aes_ack, wb_s2m_dbg_crypto_sha256_ack, wb_s2m_dbg_fauxfs_cpu_ack, wb_s2m_dbg_nand_cpu_ack, wb_s2m_dbg_bootrom0_ack}),
+ .wbs_err_i ({wb_s2m_dbg_rom0_err, wb_s2m_dbg_ram0_err, wb_s2m_dbg_uart0_err, wb_s2m_dbg_gpio0_err, wb_s2m_dbg_trng_err, wb_s2m_dbg_crypto_aes_err, wb_s2m_dbg_crypto_sha256_err, wb_s2m_dbg_fauxfs_cpu_err, wb_s2m_dbg_nand_cpu_err, wb_s2m_dbg_bootrom0_err}),
+ .wbs_rty_i ({wb_s2m_dbg_rom0_rty, wb_s2m_dbg_ram0_rty, wb_s2m_dbg_uart0_rty, wb_s2m_dbg_gpio0_rty, wb_s2m_dbg_trng_rty, wb_s2m_dbg_crypto_aes_rty, wb_s2m_dbg_crypto_sha256_rty, wb_s2m_dbg_fauxfs_cpu_rty, wb_s2m_dbg_nand_cpu_rty, wb_s2m_dbg_bootrom0_rty}));
+
+wb_arbiter
+ #(.num_masters (3))
+ wb_arbiter_rom0
+ (.wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wbm_adr_i ({wb_m2s_or1k_i_rom0_adr, wb_m2s_or1k_d_rom0_adr, wb_m2s_dbg_rom0_adr}),
+ .wbm_dat_i ({wb_m2s_or1k_i_rom0_dat, wb_m2s_or1k_d_rom0_dat, wb_m2s_dbg_rom0_dat}),
+ .wbm_sel_i ({wb_m2s_or1k_i_rom0_sel, wb_m2s_or1k_d_rom0_sel, wb_m2s_dbg_rom0_sel}),
+ .wbm_we_i ({wb_m2s_or1k_i_rom0_we, wb_m2s_or1k_d_rom0_we, wb_m2s_dbg_rom0_we}),
+ .wbm_cyc_i ({wb_m2s_or1k_i_rom0_cyc, wb_m2s_or1k_d_rom0_cyc, wb_m2s_dbg_rom0_cyc}),
+ .wbm_stb_i ({wb_m2s_or1k_i_rom0_stb, wb_m2s_or1k_d_rom0_stb, wb_m2s_dbg_rom0_stb}),
+ .wbm_cti_i ({wb_m2s_or1k_i_rom0_cti, wb_m2s_or1k_d_rom0_cti, wb_m2s_dbg_rom0_cti}),
+ .wbm_bte_i ({wb_m2s_or1k_i_rom0_bte, wb_m2s_or1k_d_rom0_bte, wb_m2s_dbg_rom0_bte}),
+ .wbm_dat_o ({wb_s2m_or1k_i_rom0_dat, wb_s2m_or1k_d_rom0_dat, wb_s2m_dbg_rom0_dat}),
+ .wbm_ack_o ({wb_s2m_or1k_i_rom0_ack, wb_s2m_or1k_d_rom0_ack, wb_s2m_dbg_rom0_ack}),
+ .wbm_err_o ({wb_s2m_or1k_i_rom0_err, wb_s2m_or1k_d_rom0_err, wb_s2m_dbg_rom0_err}),
+ .wbm_rty_o ({wb_s2m_or1k_i_rom0_rty, wb_s2m_or1k_d_rom0_rty, wb_s2m_dbg_rom0_rty}),
+ .wbs_adr_o (wb_rom0_adr_o),
+ .wbs_dat_o (wb_rom0_dat_o),
+ .wbs_sel_o (wb_rom0_sel_o),
+ .wbs_we_o (wb_rom0_we_o),
+ .wbs_cyc_o (wb_rom0_cyc_o),
+ .wbs_stb_o (wb_rom0_stb_o),
+ .wbs_cti_o (wb_rom0_cti_o),
+ .wbs_bte_o (wb_rom0_bte_o),
+ .wbs_dat_i (wb_rom0_dat_i),
+ .wbs_ack_i (wb_rom0_ack_i),
+ .wbs_err_i (wb_rom0_err_i),
+ .wbs_rty_i (wb_rom0_rty_i));
+
+wb_arbiter
+ #(.num_masters (2))
+ wb_arbiter_ram0
+ (.wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wbm_adr_i ({wb_m2s_or1k_d_ram0_adr, wb_m2s_dbg_ram0_adr}),
+ .wbm_dat_i ({wb_m2s_or1k_d_ram0_dat, wb_m2s_dbg_ram0_dat}),
+ .wbm_sel_i ({wb_m2s_or1k_d_ram0_sel, wb_m2s_dbg_ram0_sel}),
+ .wbm_we_i ({wb_m2s_or1k_d_ram0_we, wb_m2s_dbg_ram0_we}),
+ .wbm_cyc_i ({wb_m2s_or1k_d_ram0_cyc, wb_m2s_dbg_ram0_cyc}),
+ .wbm_stb_i ({wb_m2s_or1k_d_ram0_stb, wb_m2s_dbg_ram0_stb}),
+ .wbm_cti_i ({wb_m2s_or1k_d_ram0_cti, wb_m2s_dbg_ram0_cti}),
+ .wbm_bte_i ({wb_m2s_or1k_d_ram0_bte, wb_m2s_dbg_ram0_bte}),
+ .wbm_dat_o ({wb_s2m_or1k_d_ram0_dat, wb_s2m_dbg_ram0_dat}),
+ .wbm_ack_o ({wb_s2m_or1k_d_ram0_ack, wb_s2m_dbg_ram0_ack}),
+ .wbm_err_o ({wb_s2m_or1k_d_ram0_err, wb_s2m_dbg_ram0_err}),
+ .wbm_rty_o ({wb_s2m_or1k_d_ram0_rty, wb_s2m_dbg_ram0_rty}),
+ .wbs_adr_o (wb_ram0_adr_o),
+ .wbs_dat_o (wb_ram0_dat_o),
+ .wbs_sel_o (wb_ram0_sel_o),
+ .wbs_we_o (wb_ram0_we_o),
+ .wbs_cyc_o (wb_ram0_cyc_o),
+ .wbs_stb_o (wb_ram0_stb_o),
+ .wbs_cti_o (wb_ram0_cti_o),
+ .wbs_bte_o (wb_ram0_bte_o),
+ .wbs_dat_i (wb_ram0_dat_i),
+ .wbs_ack_i (wb_ram0_ack_i),
+ .wbs_err_i (wb_ram0_err_i),
+ .wbs_rty_i (wb_ram0_rty_i));
+
+wb_arbiter
+ #(.num_masters (2))
+ wb_arbiter_uart0
+ (.wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wbm_adr_i ({wb_m2s_or1k_d_uart0_adr, wb_m2s_dbg_uart0_adr}),
+ .wbm_dat_i ({wb_m2s_or1k_d_uart0_dat, wb_m2s_dbg_uart0_dat}),
+ .wbm_sel_i ({wb_m2s_or1k_d_uart0_sel, wb_m2s_dbg_uart0_sel}),
+ .wbm_we_i ({wb_m2s_or1k_d_uart0_we, wb_m2s_dbg_uart0_we}),
+ .wbm_cyc_i ({wb_m2s_or1k_d_uart0_cyc, wb_m2s_dbg_uart0_cyc}),
+ .wbm_stb_i ({wb_m2s_or1k_d_uart0_stb, wb_m2s_dbg_uart0_stb}),
+ .wbm_cti_i ({wb_m2s_or1k_d_uart0_cti, wb_m2s_dbg_uart0_cti}),
+ .wbm_bte_i ({wb_m2s_or1k_d_uart0_bte, wb_m2s_dbg_uart0_bte}),
+ .wbm_dat_o ({wb_s2m_or1k_d_uart0_dat, wb_s2m_dbg_uart0_dat}),
+ .wbm_ack_o ({wb_s2m_or1k_d_uart0_ack, wb_s2m_dbg_uart0_ack}),
+ .wbm_err_o ({wb_s2m_or1k_d_uart0_err, wb_s2m_dbg_uart0_err}),
+ .wbm_rty_o ({wb_s2m_or1k_d_uart0_rty, wb_s2m_dbg_uart0_rty}),
+ .wbs_adr_o (wb_m2s_resize_uart0_adr),
+ .wbs_dat_o (wb_m2s_resize_uart0_dat),
+ .wbs_sel_o (wb_m2s_resize_uart0_sel),
+ .wbs_we_o (wb_m2s_resize_uart0_we),
+ .wbs_cyc_o (wb_m2s_resize_uart0_cyc),
+ .wbs_stb_o (wb_m2s_resize_uart0_stb),
+ .wbs_cti_o (wb_m2s_resize_uart0_cti),
+ .wbs_bte_o (wb_m2s_resize_uart0_bte),
+ .wbs_dat_i (wb_s2m_resize_uart0_dat),
+ .wbs_ack_i (wb_s2m_resize_uart0_ack),
+ .wbs_err_i (wb_s2m_resize_uart0_err),
+ .wbs_rty_i (wb_s2m_resize_uart0_rty));
+
+wb_data_resize
+ #(.aw (32),
+ .mdw (32),
+ .sdw (8))
+ wb_data_resize_uart0
+ (.wbm_adr_i (wb_m2s_resize_uart0_adr),
+ .wbm_dat_i (wb_m2s_resize_uart0_dat),
+ .wbm_sel_i (wb_m2s_resize_uart0_sel),
+ .wbm_we_i (wb_m2s_resize_uart0_we),
+ .wbm_cyc_i (wb_m2s_resize_uart0_cyc),
+ .wbm_stb_i (wb_m2s_resize_uart0_stb),
+ .wbm_cti_i (wb_m2s_resize_uart0_cti),
+ .wbm_bte_i (wb_m2s_resize_uart0_bte),
+ .wbm_dat_o (wb_s2m_resize_uart0_dat),
+ .wbm_ack_o (wb_s2m_resize_uart0_ack),
+ .wbm_err_o (wb_s2m_resize_uart0_err),
+ .wbm_rty_o (wb_s2m_resize_uart0_rty),
+ .wbs_adr_o (wb_uart0_adr_o),
+ .wbs_dat_o (wb_uart0_dat_o),
+ .wbs_we_o (wb_uart0_we_o),
+ .wbs_cyc_o (wb_uart0_cyc_o),
+ .wbs_stb_o (wb_uart0_stb_o),
+ .wbs_cti_o (wb_uart0_cti_o),
+ .wbs_bte_o (wb_uart0_bte_o),
+ .wbs_dat_i (wb_uart0_dat_i),
+ .wbs_ack_i (wb_uart0_ack_i),
+ .wbs_err_i (wb_uart0_err_i),
+ .wbs_rty_i (wb_uart0_rty_i));
+
+wb_arbiter
+ #(.num_masters (2))
+ wb_arbiter_gpio0
+ (.wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wbm_adr_i ({wb_m2s_or1k_d_gpio0_adr, wb_m2s_dbg_gpio0_adr}),
+ .wbm_dat_i ({wb_m2s_or1k_d_gpio0_dat, wb_m2s_dbg_gpio0_dat}),
+ .wbm_sel_i ({wb_m2s_or1k_d_gpio0_sel, wb_m2s_dbg_gpio0_sel}),
+ .wbm_we_i ({wb_m2s_or1k_d_gpio0_we, wb_m2s_dbg_gpio0_we}),
+ .wbm_cyc_i ({wb_m2s_or1k_d_gpio0_cyc, wb_m2s_dbg_gpio0_cyc}),
+ .wbm_stb_i ({wb_m2s_or1k_d_gpio0_stb, wb_m2s_dbg_gpio0_stb}),
+ .wbm_cti_i ({wb_m2s_or1k_d_gpio0_cti, wb_m2s_dbg_gpio0_cti}),
+ .wbm_bte_i ({wb_m2s_or1k_d_gpio0_bte, wb_m2s_dbg_gpio0_bte}),
+ .wbm_dat_o ({wb_s2m_or1k_d_gpio0_dat, wb_s2m_dbg_gpio0_dat}),
+ .wbm_ack_o ({wb_s2m_or1k_d_gpio0_ack, wb_s2m_dbg_gpio0_ack}),
+ .wbm_err_o ({wb_s2m_or1k_d_gpio0_err, wb_s2m_dbg_gpio0_err}),
+ .wbm_rty_o ({wb_s2m_or1k_d_gpio0_rty, wb_s2m_dbg_gpio0_rty}),
+ .wbs_adr_o (wb_m2s_resize_gpio0_adr),
+ .wbs_dat_o (wb_m2s_resize_gpio0_dat),
+ .wbs_sel_o (wb_m2s_resize_gpio0_sel),
+ .wbs_we_o (wb_m2s_resize_gpio0_we),
+ .wbs_cyc_o (wb_m2s_resize_gpio0_cyc),
+ .wbs_stb_o (wb_m2s_resize_gpio0_stb),
+ .wbs_cti_o (wb_m2s_resize_gpio0_cti),
+ .wbs_bte_o (wb_m2s_resize_gpio0_bte),
+ .wbs_dat_i (wb_s2m_resize_gpio0_dat),
+ .wbs_ack_i (wb_s2m_resize_gpio0_ack),
+ .wbs_err_i (wb_s2m_resize_gpio0_err),
+ .wbs_rty_i (wb_s2m_resize_gpio0_rty));
+
+wb_data_resize
+ #(.aw (32),
+ .mdw (32),
+ .sdw (8))
+ wb_data_resize_gpio0
+ (.wbm_adr_i (wb_m2s_resize_gpio0_adr),
+ .wbm_dat_i (wb_m2s_resize_gpio0_dat),
+ .wbm_sel_i (wb_m2s_resize_gpio0_sel),
+ .wbm_we_i (wb_m2s_resize_gpio0_we),
+ .wbm_cyc_i (wb_m2s_resize_gpio0_cyc),
+ .wbm_stb_i (wb_m2s_resize_gpio0_stb),
+ .wbm_cti_i (wb_m2s_resize_gpio0_cti),
+ .wbm_bte_i (wb_m2s_resize_gpio0_bte),
+ .wbm_dat_o (wb_s2m_resize_gpio0_dat),
+ .wbm_ack_o (wb_s2m_resize_gpio0_ack),
+ .wbm_err_o (wb_s2m_resize_gpio0_err),
+ .wbm_rty_o (wb_s2m_resize_gpio0_rty),
+ .wbs_adr_o (wb_gpio0_adr_o),
+ .wbs_dat_o (wb_gpio0_dat_o),
+ .wbs_we_o (wb_gpio0_we_o),
+ .wbs_cyc_o (wb_gpio0_cyc_o),
+ .wbs_stb_o (wb_gpio0_stb_o),
+ .wbs_cti_o (wb_gpio0_cti_o),
+ .wbs_bte_o (wb_gpio0_bte_o),
+ .wbs_dat_i (wb_gpio0_dat_i),
+ .wbs_ack_i (wb_gpio0_ack_i),
+ .wbs_err_i (wb_gpio0_err_i),
+ .wbs_rty_i (wb_gpio0_rty_i));
+
+wb_arbiter
+ #(.num_masters (2))
+ wb_arbiter_trng
+ (.wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wbm_adr_i ({wb_m2s_or1k_d_trng_adr, wb_m2s_dbg_trng_adr}),
+ .wbm_dat_i ({wb_m2s_or1k_d_trng_dat, wb_m2s_dbg_trng_dat}),
+ .wbm_sel_i ({wb_m2s_or1k_d_trng_sel, wb_m2s_dbg_trng_sel}),
+ .wbm_we_i ({wb_m2s_or1k_d_trng_we, wb_m2s_dbg_trng_we}),
+ .wbm_cyc_i ({wb_m2s_or1k_d_trng_cyc, wb_m2s_dbg_trng_cyc}),
+ .wbm_stb_i ({wb_m2s_or1k_d_trng_stb, wb_m2s_dbg_trng_stb}),
+ .wbm_cti_i ({wb_m2s_or1k_d_trng_cti, wb_m2s_dbg_trng_cti}),
+ .wbm_bte_i ({wb_m2s_or1k_d_trng_bte, wb_m2s_dbg_trng_bte}),
+ .wbm_dat_o ({wb_s2m_or1k_d_trng_dat, wb_s2m_dbg_trng_dat}),
+ .wbm_ack_o ({wb_s2m_or1k_d_trng_ack, wb_s2m_dbg_trng_ack}),
+ .wbm_err_o ({wb_s2m_or1k_d_trng_err, wb_s2m_dbg_trng_err}),
+ .wbm_rty_o ({wb_s2m_or1k_d_trng_rty, wb_s2m_dbg_trng_rty}),
+ .wbs_adr_o (wb_m2s_resize_trng_adr),
+ .wbs_dat_o (wb_m2s_resize_trng_dat),
+ .wbs_sel_o (wb_m2s_resize_trng_sel),
+ .wbs_we_o (wb_m2s_resize_trng_we),
+ .wbs_cyc_o (wb_m2s_resize_trng_cyc),
+ .wbs_stb_o (wb_m2s_resize_trng_stb),
+ .wbs_cti_o (wb_m2s_resize_trng_cti),
+ .wbs_bte_o (wb_m2s_resize_trng_bte),
+ .wbs_dat_i (wb_s2m_resize_trng_dat),
+ .wbs_ack_i (wb_s2m_resize_trng_ack),
+ .wbs_err_i (wb_s2m_resize_trng_err),
+ .wbs_rty_i (wb_s2m_resize_trng_rty));
+
+wb_data_resize
+ #(.aw (32),
+ .mdw (32),
+ .sdw (8))
+ wb_data_resize_trng
+ (.wbm_adr_i (wb_m2s_resize_trng_adr),
+ .wbm_dat_i (wb_m2s_resize_trng_dat),
+ .wbm_sel_i (wb_m2s_resize_trng_sel),
+ .wbm_we_i (wb_m2s_resize_trng_we),
+ .wbm_cyc_i (wb_m2s_resize_trng_cyc),
+ .wbm_stb_i (wb_m2s_resize_trng_stb),
+ .wbm_cti_i (wb_m2s_resize_trng_cti),
+ .wbm_bte_i (wb_m2s_resize_trng_bte),
+ .wbm_dat_o (wb_s2m_resize_trng_dat),
+ .wbm_ack_o (wb_s2m_resize_trng_ack),
+ .wbm_err_o (wb_s2m_resize_trng_err),
+ .wbm_rty_o (wb_s2m_resize_trng_rty),
+ .wbs_adr_o (wb_trng_adr_o),
+ .wbs_dat_o (wb_trng_dat_o),
+ .wbs_we_o (wb_trng_we_o),
+ .wbs_cyc_o (wb_trng_cyc_o),
+ .wbs_stb_o (wb_trng_stb_o),
+ .wbs_cti_o (wb_trng_cti_o),
+ .wbs_bte_o (wb_trng_bte_o),
+ .wbs_dat_i (wb_trng_dat_i),
+ .wbs_ack_i (wb_trng_ack_i),
+ .wbs_err_i (wb_trng_err_i),
+ .wbs_rty_i (wb_trng_rty_i));
+
+wb_arbiter
+ #(.num_masters (2))
+ wb_arbiter_crypto_aes
+ (.wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wbm_adr_i ({wb_m2s_or1k_d_crypto_aes_adr, wb_m2s_dbg_crypto_aes_adr}),
+ .wbm_dat_i ({wb_m2s_or1k_d_crypto_aes_dat, wb_m2s_dbg_crypto_aes_dat}),
+ .wbm_sel_i ({wb_m2s_or1k_d_crypto_aes_sel, wb_m2s_dbg_crypto_aes_sel}),
+ .wbm_we_i ({wb_m2s_or1k_d_crypto_aes_we, wb_m2s_dbg_crypto_aes_we}),
+ .wbm_cyc_i ({wb_m2s_or1k_d_crypto_aes_cyc, wb_m2s_dbg_crypto_aes_cyc}),
+ .wbm_stb_i ({wb_m2s_or1k_d_crypto_aes_stb, wb_m2s_dbg_crypto_aes_stb}),
+ .wbm_cti_i ({wb_m2s_or1k_d_crypto_aes_cti, wb_m2s_dbg_crypto_aes_cti}),
+ .wbm_bte_i ({wb_m2s_or1k_d_crypto_aes_bte, wb_m2s_dbg_crypto_aes_bte}),
+ .wbm_dat_o ({wb_s2m_or1k_d_crypto_aes_dat, wb_s2m_dbg_crypto_aes_dat}),
+ .wbm_ack_o ({wb_s2m_or1k_d_crypto_aes_ack, wb_s2m_dbg_crypto_aes_ack}),
+ .wbm_err_o ({wb_s2m_or1k_d_crypto_aes_err, wb_s2m_dbg_crypto_aes_err}),
+ .wbm_rty_o ({wb_s2m_or1k_d_crypto_aes_rty, wb_s2m_dbg_crypto_aes_rty}),
+ .wbs_adr_o (wb_crypto_aes_adr_o),
+ .wbs_dat_o (wb_crypto_aes_dat_o),
+ .wbs_sel_o (wb_crypto_aes_sel_o),
+ .wbs_we_o (wb_crypto_aes_we_o),
+ .wbs_cyc_o (wb_crypto_aes_cyc_o),
+ .wbs_stb_o (wb_crypto_aes_stb_o),
+ .wbs_cti_o (wb_crypto_aes_cti_o),
+ .wbs_bte_o (wb_crypto_aes_bte_o),
+ .wbs_dat_i (wb_crypto_aes_dat_i),
+ .wbs_ack_i (wb_crypto_aes_ack_i),
+ .wbs_err_i (wb_crypto_aes_err_i),
+ .wbs_rty_i (wb_crypto_aes_rty_i));
+
+wb_arbiter
+ #(.num_masters (2))
+ wb_arbiter_crypto_sha256
+ (.wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wbm_adr_i ({wb_m2s_or1k_d_crypto_sha256_adr, wb_m2s_dbg_crypto_sha256_adr}),
+ .wbm_dat_i ({wb_m2s_or1k_d_crypto_sha256_dat, wb_m2s_dbg_crypto_sha256_dat}),
+ .wbm_sel_i ({wb_m2s_or1k_d_crypto_sha256_sel, wb_m2s_dbg_crypto_sha256_sel}),
+ .wbm_we_i ({wb_m2s_or1k_d_crypto_sha256_we, wb_m2s_dbg_crypto_sha256_we}),
+ .wbm_cyc_i ({wb_m2s_or1k_d_crypto_sha256_cyc, wb_m2s_dbg_crypto_sha256_cyc}),
+ .wbm_stb_i ({wb_m2s_or1k_d_crypto_sha256_stb, wb_m2s_dbg_crypto_sha256_stb}),
+ .wbm_cti_i ({wb_m2s_or1k_d_crypto_sha256_cti, wb_m2s_dbg_crypto_sha256_cti}),
+ .wbm_bte_i ({wb_m2s_or1k_d_crypto_sha256_bte, wb_m2s_dbg_crypto_sha256_bte}),
+ .wbm_dat_o ({wb_s2m_or1k_d_crypto_sha256_dat, wb_s2m_dbg_crypto_sha256_dat}),
+ .wbm_ack_o ({wb_s2m_or1k_d_crypto_sha256_ack, wb_s2m_dbg_crypto_sha256_ack}),
+ .wbm_err_o ({wb_s2m_or1k_d_crypto_sha256_err, wb_s2m_dbg_crypto_sha256_err}),
+ .wbm_rty_o ({wb_s2m_or1k_d_crypto_sha256_rty, wb_s2m_dbg_crypto_sha256_rty}),
+ .wbs_adr_o (wb_crypto_sha256_adr_o),
+ .wbs_dat_o (wb_crypto_sha256_dat_o),
+ .wbs_sel_o (wb_crypto_sha256_sel_o),
+ .wbs_we_o (wb_crypto_sha256_we_o),
+ .wbs_cyc_o (wb_crypto_sha256_cyc_o),
+ .wbs_stb_o (wb_crypto_sha256_stb_o),
+ .wbs_cti_o (wb_crypto_sha256_cti_o),
+ .wbs_bte_o (wb_crypto_sha256_bte_o),
+ .wbs_dat_i (wb_crypto_sha256_dat_i),
+ .wbs_ack_i (wb_crypto_sha256_ack_i),
+ .wbs_err_i (wb_crypto_sha256_err_i),
+ .wbs_rty_i (wb_crypto_sha256_rty_i));
+
+wb_arbiter
+ #(.num_masters (2))
+ wb_arbiter_fauxfs_cpu
+ (.wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wbm_adr_i ({wb_m2s_or1k_d_fauxfs_cpu_adr, wb_m2s_dbg_fauxfs_cpu_adr}),
+ .wbm_dat_i ({wb_m2s_or1k_d_fauxfs_cpu_dat, wb_m2s_dbg_fauxfs_cpu_dat}),
+ .wbm_sel_i ({wb_m2s_or1k_d_fauxfs_cpu_sel, wb_m2s_dbg_fauxfs_cpu_sel}),
+ .wbm_we_i ({wb_m2s_or1k_d_fauxfs_cpu_we, wb_m2s_dbg_fauxfs_cpu_we}),
+ .wbm_cyc_i ({wb_m2s_or1k_d_fauxfs_cpu_cyc, wb_m2s_dbg_fauxfs_cpu_cyc}),
+ .wbm_stb_i ({wb_m2s_or1k_d_fauxfs_cpu_stb, wb_m2s_dbg_fauxfs_cpu_stb}),
+ .wbm_cti_i ({wb_m2s_or1k_d_fauxfs_cpu_cti, wb_m2s_dbg_fauxfs_cpu_cti}),
+ .wbm_bte_i ({wb_m2s_or1k_d_fauxfs_cpu_bte, wb_m2s_dbg_fauxfs_cpu_bte}),
+ .wbm_dat_o ({wb_s2m_or1k_d_fauxfs_cpu_dat, wb_s2m_dbg_fauxfs_cpu_dat}),
+ .wbm_ack_o ({wb_s2m_or1k_d_fauxfs_cpu_ack, wb_s2m_dbg_fauxfs_cpu_ack}),
+ .wbm_err_o ({wb_s2m_or1k_d_fauxfs_cpu_err, wb_s2m_dbg_fauxfs_cpu_err}),
+ .wbm_rty_o ({wb_s2m_or1k_d_fauxfs_cpu_rty, wb_s2m_dbg_fauxfs_cpu_rty}),
+ .wbs_adr_o (wb_fauxfs_cpu_adr_o),
+ .wbs_dat_o (wb_fauxfs_cpu_dat_o),
+ .wbs_sel_o (wb_fauxfs_cpu_sel_o),
+ .wbs_we_o (wb_fauxfs_cpu_we_o),
+ .wbs_cyc_o (wb_fauxfs_cpu_cyc_o),
+ .wbs_stb_o (wb_fauxfs_cpu_stb_o),
+ .wbs_cti_o (wb_fauxfs_cpu_cti_o),
+ .wbs_bte_o (wb_fauxfs_cpu_bte_o),
+ .wbs_dat_i (wb_fauxfs_cpu_dat_i),
+ .wbs_ack_i (wb_fauxfs_cpu_ack_i),
+ .wbs_err_i (wb_fauxfs_cpu_err_i),
+ .wbs_rty_i (wb_fauxfs_cpu_rty_i));
+
+wb_arbiter
+ #(.num_masters (2))
+ wb_arbiter_nand_cpu
+ (.wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wbm_adr_i ({wb_m2s_or1k_d_nand_cpu_adr, wb_m2s_dbg_nand_cpu_adr}),
+ .wbm_dat_i ({wb_m2s_or1k_d_nand_cpu_dat, wb_m2s_dbg_nand_cpu_dat}),
+ .wbm_sel_i ({wb_m2s_or1k_d_nand_cpu_sel, wb_m2s_dbg_nand_cpu_sel}),
+ .wbm_we_i ({wb_m2s_or1k_d_nand_cpu_we, wb_m2s_dbg_nand_cpu_we}),
+ .wbm_cyc_i ({wb_m2s_or1k_d_nand_cpu_cyc, wb_m2s_dbg_nand_cpu_cyc}),
+ .wbm_stb_i ({wb_m2s_or1k_d_nand_cpu_stb, wb_m2s_dbg_nand_cpu_stb}),
+ .wbm_cti_i ({wb_m2s_or1k_d_nand_cpu_cti, wb_m2s_dbg_nand_cpu_cti}),
+ .wbm_bte_i ({wb_m2s_or1k_d_nand_cpu_bte, wb_m2s_dbg_nand_cpu_bte}),
+ .wbm_dat_o ({wb_s2m_or1k_d_nand_cpu_dat, wb_s2m_dbg_nand_cpu_dat}),
+ .wbm_ack_o ({wb_s2m_or1k_d_nand_cpu_ack, wb_s2m_dbg_nand_cpu_ack}),
+ .wbm_err_o ({wb_s2m_or1k_d_nand_cpu_err, wb_s2m_dbg_nand_cpu_err}),
+ .wbm_rty_o ({wb_s2m_or1k_d_nand_cpu_rty, wb_s2m_dbg_nand_cpu_rty}),
+ .wbs_adr_o (wb_nand_cpu_adr_o),
+ .wbs_dat_o (wb_nand_cpu_dat_o),
+ .wbs_sel_o (wb_nand_cpu_sel_o),
+ .wbs_we_o (wb_nand_cpu_we_o),
+ .wbs_cyc_o (wb_nand_cpu_cyc_o),
+ .wbs_stb_o (wb_nand_cpu_stb_o),
+ .wbs_cti_o (wb_nand_cpu_cti_o),
+ .wbs_bte_o (wb_nand_cpu_bte_o),
+ .wbs_dat_i (wb_nand_cpu_dat_i),
+ .wbs_ack_i (wb_nand_cpu_ack_i),
+ .wbs_err_i (wb_nand_cpu_err_i),
+ .wbs_rty_i (wb_nand_cpu_rty_i));
+
+wb_arbiter
+ #(.num_masters (3))
+ wb_arbiter_bootrom0
+ (.wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wbm_adr_i ({wb_m2s_or1k_i_bootrom0_adr, wb_m2s_or1k_d_bootrom0_adr, wb_m2s_dbg_bootrom0_adr}),
+ .wbm_dat_i ({wb_m2s_or1k_i_bootrom0_dat, wb_m2s_or1k_d_bootrom0_dat, wb_m2s_dbg_bootrom0_dat}),
+ .wbm_sel_i ({wb_m2s_or1k_i_bootrom0_sel, wb_m2s_or1k_d_bootrom0_sel, wb_m2s_dbg_bootrom0_sel}),
+ .wbm_we_i ({wb_m2s_or1k_i_bootrom0_we, wb_m2s_or1k_d_bootrom0_we, wb_m2s_dbg_bootrom0_we}),
+ .wbm_cyc_i ({wb_m2s_or1k_i_bootrom0_cyc, wb_m2s_or1k_d_bootrom0_cyc, wb_m2s_dbg_bootrom0_cyc}),
+ .wbm_stb_i ({wb_m2s_or1k_i_bootrom0_stb, wb_m2s_or1k_d_bootrom0_stb, wb_m2s_dbg_bootrom0_stb}),
+ .wbm_cti_i ({wb_m2s_or1k_i_bootrom0_cti, wb_m2s_or1k_d_bootrom0_cti, wb_m2s_dbg_bootrom0_cti}),
+ .wbm_bte_i ({wb_m2s_or1k_i_bootrom0_bte, wb_m2s_or1k_d_bootrom0_bte, wb_m2s_dbg_bootrom0_bte}),
+ .wbm_dat_o ({wb_s2m_or1k_i_bootrom0_dat, wb_s2m_or1k_d_bootrom0_dat, wb_s2m_dbg_bootrom0_dat}),
+ .wbm_ack_o ({wb_s2m_or1k_i_bootrom0_ack, wb_s2m_or1k_d_bootrom0_ack, wb_s2m_dbg_bootrom0_ack}),
+ .wbm_err_o ({wb_s2m_or1k_i_bootrom0_err, wb_s2m_or1k_d_bootrom0_err, wb_s2m_dbg_bootrom0_err}),
+ .wbm_rty_o ({wb_s2m_or1k_i_bootrom0_rty, wb_s2m_or1k_d_bootrom0_rty, wb_s2m_dbg_bootrom0_rty}),
+ .wbs_adr_o (wb_bootrom0_adr_o),
+ .wbs_dat_o (wb_bootrom0_dat_o),
+ .wbs_sel_o (wb_bootrom0_sel_o),
+ .wbs_we_o (wb_bootrom0_we_o),
+ .wbs_cyc_o (wb_bootrom0_cyc_o),
+ .wbs_stb_o (wb_bootrom0_stb_o),
+ .wbs_cti_o (wb_bootrom0_cti_o),
+ .wbs_bte_o (wb_bootrom0_bte_o),
+ .wbs_dat_i (wb_bootrom0_dat_i),
+ .wbs_ack_i (wb_bootrom0_ack_i),
+ .wbs_err_i (wb_bootrom0_err_i),
+ .wbs_rty_i (wb_bootrom0_rty_i));
+
+endmodule
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 18:59:52 11/12/2014
+// Design Name:
+// Module Name: clkgen
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module clkgen(
+\t// Clock in
+\tinput sys_clk_i,
+\t// Input reset - active on high
+\tinput sys_rst_i,
+\t// Wishbone clock, 2x clock, and reset out
+\toutput wb_clk_o,
+\toutput wb_clk2x_o,
+\toutput wb_rst_o
+);
+
+// Input buffering
+IBUFG sys_clk_in_ibufg(
+\t.I(sys_clk_i),
+\t.O(sys_clk_ibufg)
+);
+
+// Clocking primitive
+//------------------------------------
+// Instantiation of the MMCM primitive
+// * Unused inputs are tied off
+// * Unused outputs are labeled unused
+wire [15:0] do_unused;
+wire drdy_unused;
+wire psdone_unused;
+wire clkfbout;
+wire clkfbout_buf;
+wire clkfboutb_unused;
+wire clkout0b_unused;
+wire clkout1b_unused;
+wire clkout2_unused;
+wire clkout2b_unused;
+wire clkout3_unused;
+wire clkout3b_unused;
+wire clkout4_unused;
+wire clkout5_unused;
+wire clkout6_unused;
+wire clkfbstopped_unused;
+wire clkinstopped_unused;
+
+MMCME2_ADV #(
+\t.BANDWIDTH(""OPTIMIZED""),
+\t.CLKOUT4_CASCADE(""FALSE""),
+\t.COMPENSATION(""ZHOLD""),
+\t.STARTUP_WAIT(""FALSE""),
+\t.DIVCLK_DIVIDE(1),
+\t.CLKFBOUT_MULT_F(10.000),
+\t.CLKFBOUT_PHASE(0.000),
+\t.CLKFBOUT_USE_FINE_PS (""FALSE""),
+\t.CLKOUT0_DIVIDE_F(20.000),
+\t.CLKOUT0_PHASE(0.000),
+\t.CLKOUT0_DUTY_CYCLE(0.500),
+\t.CLKOUT0_USE_FINE_PS(""FALSE""),
+\t.CLKOUT1_DIVIDE(10),
+\t.CLKOUT1_PHASE(0.000),
+\t.CLKOUT1_DUTY_CYCLE(0.500),
+\t.CLKOUT1_USE_FINE_PS(""FALSE""),
+\t.CLKIN1_PERIOD(10.000),
+\t.REF_JITTER1(0.010)
+) mmcm_adv_inst(
+\t.CLKFBOUT(clkfbout),
+\t.CLKFBOUTB(clkfboutb_unused),
+\t.CLKOUT0(clkout0),
+\t.CLKOUT0B(clkout0b_unused),
+\t.CLKOUT1(clkout1),
+\t.CLKOUT1B(clkout1b_unused),
+\t.CLKOUT2(clkout2_unused),
+\t.CLKOUT2B(clkout2b_unused),
+\t.CLKOUT3(clkout3_unused),
+\t.CLKOUT3B(clkout3b_unused),
+\t.CLKOUT4(clkout4_unused),
+\t.CLKOUT5(clkout5_unused),
+\t.CLKOUT6(clkout6_unused),
+\t// Input clock control
+\t.CLKFBIN(clkfbout_buf),
+\t.CLKIN1(sys_clk_ibufg),
+\t.CLKIN2(1\'b0),
+\t// Tied to always select the primary input clock
+\t.CLKINSEL(1\'b1),
+\t// Ports for dynamic reconfiguration
+\t.DADDR(7\'h0),
+\t.DCLK(1\'b0),
+\t.DEN(1\'b0),
+\t.DI(16\'h0),
+\t.DO(do_unused),
+\t.DRDY(drdy_unused),
+\t.DWE(1\'b0),
+\t// Ports for dynamic phase shift
+\t.PSCLK(1\'b0),
+\t.PSEN(1\'b0),
+\t.PSINCDEC(1\'b0),
+\t.PSDONE(psdone_unused),
+\t// Other control and status signals
+\t.LOCKED(LOCKED),
+\t.CLKINSTOPPED(clkinstopped_unused),
+\t.CLKFBSTOPPED(clkfbstopped_unused),
+\t.PWRDWN(1\'b0),
+\t.RST(sys_rst_i)
+);
+
+// Output buffering
+//-----------------------------------
+BUFG clkf_buf(
+\t.O(clkfbout_buf),
+\t.I(clkfbout)
+);
+
+BUFG wb_clk_buf(
+\t.O(wb_clk_o),
+\t.I(clkout0)
+);
+
+
+BUFG wb_clk2x_buf(
+\t.O(wb_clk2x_o),
+\t.I(clkout1)
+);
+
+
+reg [15:0] wb_rst_shr;
+always @(posedge wb_clk_o or posedge sys_rst_i)
+begin
+\tif(sys_rst_i)
+\t\twb_rst_shr <= 16\'hffff;
+\telse
+\t\twb_rst_shr <= {wb_rst_shr[14:0], ~(LOCKED)};
+end
+
+assign wb_rst_o = wb_rst_shr[15];
+
+endmodule
+"
+"/*\r
+ Copyright 2015, Google Inc.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the ""License"");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an ""AS IS"" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+module sd_phy (\r
+ input wire clk_50,\r
+ input wire reset_n,\r
+\r
+ input wire sd_clk,\r
+ input wire sd_cmd_i,\r
+ output wire sd_cmd_o,\r
+ output wire sd_cmd_t,\r
+ input wire [3:0] sd_dat_i,\r
+ output wire [3:0] sd_dat_o,\r
+ output wire [3:0] sd_dat_t,\r
+\r
+ input wire [3:0] card_state,\r
+\r
+ output reg [47:0] cmd_in,\r
+ output reg cmd_in_crc_good,\r
+ output reg cmd_in_act,\r
+ input wire data_in_act,\r
+ output reg data_in_busy,\r
+ input wire data_in_another,\r
+ input wire data_in_stop,\r
+ output reg data_in_done,\r
+ output reg data_in_crc_good,\r
+\r
+ input wire [135:0] resp_out,\r
+ input wire [3:0] resp_type,\r
+ input wire resp_busy,\r
+ input wire resp_act,\r
+ output reg resp_done,\r
+ input wire mode_4bit,\r
+ input wire [511:0] data_out_reg,\r
+ input wire data_out_src,\r
+ input wire [9:0] data_out_len,\r
+ output reg data_out_busy,\r
+ input wire data_out_act,\r
+ input wire data_out_stop,\r
+ output reg data_out_done,\r
+\r
+ output wire bram_rd_sd_clk,\r
+ output reg [6:0] bram_rd_sd_addr,\r
+ output reg bram_rd_sd_wren,\r
+ output reg [31:0] bram_rd_sd_data,\r
+ input wire [31:0] bram_rd_sd_q,\r
+\r
+ output wire bram_wr_sd_clk,\r
+ output reg [6:0] bram_wr_sd_addr,\r
+ output reg bram_wr_sd_wren,\r
+ output reg [31:0] bram_wr_sd_data,\r
+ input wire [31:0] bram_wr_sd_q\r
+ ,\r
+ output reg [10:0] odc,\r
+ output reg [6:0] ostate\r
+);\r
+\r
+`include ""sd_params.vh""\r
+`include ""sd_const.vh""\r
+ \r
+assign bram_rd_sd_clk = sd_clk;\r
+assign bram_wr_sd_clk = sd_clk;\r
+ \r
+reg sd_cmd_out;\r
+reg sd_cmd_oe;\r
+wire sd_cmd = sd_cmd_i;\r
+//assign sd_cmd = sd_cmd_oe ? sd_cmd_out : 1\'bZ;\r
+assign sd_cmd_t = !sd_cmd_oe;\r
+assign sd_cmd_o = sd_cmd_out;\r
+ \r
+// tristate data lines when card state is DISCONNECT\r
+reg [3:0] sd_dat_out;\r
+reg [3:0] sd_dat_oe;\r
+wire [3:0] sd_dat = sd_dat_i;\r
+ \r
+/*\r
+assign sd_dat[3] = (sd_dat_oe[3] && card_state_s != CARD_DIS) ? sd_dat_out[3] : 1\'bZ;\r
+assign sd_dat[2] = (sd_dat_oe[2] && card_state_s != CARD_DIS) ? sd_dat_out[2] : 1\'bZ;\r
+assign sd_dat[1] = (sd_dat_oe[1] && card_state_s != CARD_DIS) ? sd_dat_out[1] : 1\'bZ;\r
+assign sd_dat[0] = (sd_dat_oe[0] && card_state_s != CARD_DIS) ? sd_dat_out[0] : 1\'bZ;\r
+*/\r
+assign sd_dat_o = sd_dat_out;\r
+assign sd_dat_t = ~sd_dat_oe | {4{card_state_s == CARD_DIS}};\r
+ \r
+reg sd_cmd_last;\r
+reg sd_dat_last;\r
+reg [46:0] cmd_in_latch;\r
+reg [135:0] resp_out_latch;\r
+\r
+reg [6:0] crc7_in;\r
+reg [6:0] crc7_out;\r
+ \r
+reg [512:0] data_out_reg_latch;\r
+ \r
+reg [15:0] crc16_out3, crc16_out2, crc16_out1, crc16_out0;\r
+reg [15:0] crc16_in3, crc16_in2, crc16_in1, crc16_in0;\r
+reg [15:0] crc16_check3, crc16_check2, crc16_check1, crc16_check0;\r
+\r
+ \r
+reg [10:0] idc;\r
+//reg [10:0] odc;\r
+ \r
+reg [6:0] istate;\r
+//reg [6:0] ostate;\r
+ \r
+parameter [6:0] ST_RESET = \'d0,\r
+ ST_RESET_WAIT = \'d1,\r
+ ST_IDLE = \'d4,\r
+ \r
+ ST_CMD_CHECK = \'d10,\r
+ ST_CMD_READ = \'d11,\r
+ ST_RESP_PREAMBLE = \'d14,\r
+ ST_RESP_WRITE = \'d15,\r
+ ST_RESP_WRITE_END = \'d16,\r
+ \r
+ ST_DATA_READ = \'d20,\r
+ ST_DATA_READ_1 = \'d21,\r
+ ST_DATA_READ_2 = \'d22,\r
+ ST_DATA_READ_3 = \'d23,\r
+ \r
+ ST_DATA_TOKEN = \'d24,\r
+ ST_DATA_TOKEN_1 = \'d25,\r
+ ST_DATA_TOKEN_2 = \'d26,\r
+ ST_DATA_TOKEN_3 = \'d27,\r
+ \r
+ ST_DATA_WRITE = \'d30,\r
+ ST_DATA_WRITE_1 = \'d31,\r
+ ST_DATA_WRITE_2 = \'d32,\r
+ ST_DATA_WRITE_3 = \'d33,\r
+ \r
+ ST_LAST = \'d127;\r
+\r
+reg [15:0] didc;\r
+reg [15:0] dodc;\r
+\r
+reg [6:0] distate;\r
+reg [6:0] dostate;\r
+ \r
+reg [31:0] dout_buf;\r
+wire [3:0] dout_4bit = data_out_src ? data_out_reg_latch[511:508] : dout_buf[31:28];\r
+wire [0:0] dout_1bit = data_out_src ? data_out_reg_latch[511] : dout_buf[31];\r
+ \r
+reg do_crc_token;\r
+ \r
+// synchronizers\r
+wire data_in_act_s, data_in_act_r;\r
+wire data_in_stop_s;\r
+wire data_in_another_s;\r
+wire resp_act_s, resp_act_r;\r
+wire [3:0] resp_type_s;\r
+wire [9:0] data_out_len_s;\r
+wire data_out_act_s, data_out_act_r;\r
+wire data_out_stop_s;\r
+wire [3:0] card_state_s;\r
+wire mode_4bit_s;\r
+synch_3 a(data_in_act, data_in_act_s, sd_clk, data_in_act_r);\r
+synch_3 i(data_in_stop, data_in_stop_s, sd_clk);\r
+synch_3 j(data_in_another, data_in_another_s, sd_clk);\r
+synch_3 b(resp_act, resp_act_s, sd_clk, resp_act_r);\r
+synch_3 #(4) c(resp_type, resp_type_s, sd_clk);\r
+synch_3 #(10) d(data_out_len, data_out_len_s, sd_clk);\r
+synch_3 e(data_out_act, data_out_act_s, sd_clk, data_out_act_r);\r
+synch_3 f(data_out_stop, data_out_stop_s, sd_clk);\r
+synch_3 #(4) g(card_state, card_state_s, sd_clk);\r
+synch_3 h(mode_4bit, mode_4bit_s, sd_clk);\r
+\r
+always @(posedge sd_clk or negedge reset_n) begin\r
+\r
+ if(~reset_n) begin\r
+ istate <= ST_RESET;\r
+ distate <= ST_RESET;\r
+ end else begin\r
+ \r
+ sd_cmd_last <= sd_cmd;\r
+ sd_dat_last <= sd_dat[0];\r
+ \r
+ // free running counter\r
+ idc <= idc + 1\'b1;\r
+ \r
+ //\r
+ // command input FSM\r
+ //\r
+ case(istate)\r
+ ST_RESET: begin\r
+ idc <= 0;\r
+ if(sd_cmd) istate <= ST_RESET_WAIT;\r
+ end\r
+ ST_RESET_WAIT: begin\r
+ // spec mandates that hosts send at least 74 clocks before any commands\r
+ // some hosts may send many more, some only a few (which violates spec)\r
+ if (idc == 60) istate <= ST_IDLE;\r
+ end\r
+ ST_IDLE: begin\r
+ // falling edge of CMD, and output state not driving\r
+ if((~sd_cmd & sd_cmd_last) & ~sd_cmd_oe) begin //~resp_act_s) begin\r
+ // start bit 0 of command\r
+ \r
+ cmd_in_latch <= 0;\r
+ cmd_in_act <= 0;\r
+ crc7_in <= 0;\r
+ idc <= 0;\r
+ istate <= ST_CMD_READ;\r
+ end\r
+ end\r
+ ST_CMD_READ: begin\r
+ // shift in command\r
+ cmd_in_latch <= {cmd_in_latch[45:0], sd_cmd};\r
+ // advance CRC over first 40 bits\r
+ if(idc < 39) begin\r
+ crc7_in <= { crc7_in[5], crc7_in[4], crc7_in[3], crc7_in[2] ^ crc7_in[6] ^ sd_cmd,\r
+ crc7_in[1], crc7_in[0], sd_cmd ^ crc7_in[6] }; \r
+ end\r
+ // after last bit of CRC \r
+ if(idc == 45) begin\r
+ istate <= ST_CMD_CHECK;\r
+ end\r
+ end\r
+ ST_CMD_CHECK: begin\r
+ // compare CRC7\r
+ cmd_in_crc_good <= ( cmd_in_latch[6:0] == crc7_in );\r
+ cmd_in <= {cmd_in_latch, sd_cmd};\r
+ cmd_in_act <= cmd_in_latch[45];\r
+ \r
+ istate <= ST_IDLE;\r
+ end\r
+ ST_LAST: begin\r
+ end\r
+ default: istate <= ST_RESET;\r
+ endcase\r
+ \r
+ //\r
+ // data input FSM\r
+ //\r
+ didc <= didc + 1\'b1;\r
+ bram_wr_sd_wren <= 0;\r
+ case(distate)\r
+ ST_RESET: begin\r
+ do_crc_token <= 0;\r
+ distate <= ST_IDLE;\r
+ end\r
+ ST_IDLE: begin\r
+ if(data_in_act_r | (data_in_another_s & ~data_in_stop_s)) begin\r
+ data_in_busy <= 1;\r
+ data_in_done <= 0;\r
+ distate <= ST_DATA_READ;\r
+ end\r
+ end\r
+ ST_DATA_READ: begin\r
+ // falling edge of DAT0, and output state not driving\r
+ if((~sd_dat[0] & sd_dat_last) & ~sd_dat_oe[0]) begin \r
+ // start bit 0 of data packet\r
+ crc16_in3 <= 0;\r
+ crc16_in2 <= 0;\r
+ crc16_in1 <= 0;\r
+ crc16_in0 <= 0;\r
+ didc <= 0;\r
+ bram_wr_sd_addr <= -1;\r
+ distate <= ST_DATA_READ_1;\r
+ end\r
+ if(data_in_stop_s) begin\r
+ data_in_done <= 1;\r
+ distate <= ST_DATA_READ_3;\r
+ end\r
+ end\r
+ ST_DATA_READ_1: begin\r
+ // shift in data\r
+ if(mode_4bit_s) begin\r
+ bram_wr_sd_data <= {bram_wr_sd_data[27:0], sd_dat};\r
+ crc16_in3 <= {crc16_in3[14:0], 1\'b0} ^ ((sd_dat[3] ^ crc16_in3[15]) ? 16\'h1021 : 16\'h0);\r
+ crc16_in2 <= {crc16_in2[14:0], 1\'b0} ^ ((sd_dat[2] ^ crc16_in2[15]) ? 16\'h1021 : 16\'h0);\r
+ crc16_in1 <= {crc16_in1[14:0], 1\'b0} ^ ((sd_dat[1] ^ crc16_in1[15]) ? 16\'h1021 : 16\'h0);\r
+ crc16_in0 <= {crc16_in0[14:0], 1\'b0} ^ ((sd_dat[0] ^ crc16_in0[15]) ? 16\'h1021 : 16\'h0);\r
+ \r
+ if(didc[2:0] == 3\'d0) bram_wr_sd_addr <= bram_wr_sd_addr + 1\'b1;\r
+ if(didc[2:0] == 3\'d7) bram_wr_sd_wren <= 1;\r
+ end else begin\r
+ bram_wr_sd_data <= {bram_wr_sd_data[31:0], sd_dat[0]};\r
+ crc16_in0 <= {crc16_in0[14:0], 1\'b0} ^ ((sd_dat[0] ^ crc16_in0[15]) ? 16\'h1021 : 16\'h0);\r
+ \r
+ if(didc[4:0] == 5\'d0) bram_wr_sd_addr <= bram_wr_sd_addr + 1\'b1;\r
+ if(didc[4:0] == 5\'d31) bram_wr_sd_wren <= 1;\r
+ end\r
+ if((mode_4bit_s ? (didc+1) >> 1 : (didc+1) >> 3) == 512) begin\r
+ // end, read crc\r
+ didc <= 0;\r
+ distate <= ST_DATA_READ_2;\r
+ end\r
+ if(data_in_stop_s) begin\r
+ data_in_done <= 1;\r
+ distate <= ST_DATA_READ_3;\r
+ end\r
+ end\r
+ ST_DATA_READ_2: begin\r
+ // shift in CRC16\r
+ crc16_check3[15:0] <= {crc16_check3[14:0], sd_dat[3]};\r
+ crc16_check2[15:0] <= {crc16_check2[14:0], sd_dat[2]};\r
+ crc16_check1[15:0] <= {crc16_check1[14:0], sd_dat[1]};\r
+ crc16_check0[15:0] <= {crc16_check0[14:0], sd_dat[0]};\r
+ \r
+ if(didc == 16 || data_in_stop_s) begin\r
+ // end, including 1 stop bit\r
+ data_in_done <= 1;\r
+ if( {crc16_check3, crc16_check2, crc16_check1, crc16_check0} ==\r
+ {crc16_in3, crc16_in2, crc16_in1, crc16_in0} ) begin\r
+ data_in_crc_good <= 1;\r
+ end else data_in_crc_good <= 0;\r
+ didc <= 0;\r
+ distate <= ST_DATA_READ_3;\r
+ \r
+ // if STOP sent, do not send CRC token, just busy signal \r
+ do_crc_token <= ~data_in_stop_s;\r
+ end\r
+ end\r
+ ST_DATA_READ_3: begin\r
+ // after telling link we\'re done, wait for it to respond\r
+ if(~data_in_act_s) begin\r
+ do_crc_token <= 0;\r
+ data_in_busy <= 0;\r
+ distate <= ST_IDLE;\r
+ end\r
+ end\r
+ default: distate <= ST_RESET;\r
+ endcase\r
+\r
+ end\r
+end\r
+\r
+\r
+always @(negedge sd_clk or negedge reset_n) begin\r
+\r
+ if(~reset_n) begin\r
+ ostate <= ST_RESET;\r
+ dostate <= ST_RESET;\r
+ end else begin\r
+ \r
+ // free running counter\r
+ odc <= odc + 1\'b1;\r
+ \r
+ //\r
+ // command output FSM\r
+ //\r
+ case(ostate)\r
+ ST_RESET: begin\r
+ resp_done <= 0;\r
+ sd_cmd_oe <= 0;\r
+ ostate <= ST_IDLE;\r
+ end\r
+ ST_IDLE: begin\r
+ if(resp_act_r) begin\r
+ resp_done <= 0;\r
+ resp_out_latch <= resp_out;\r
+ crc7_out <= 0;\r
+ \r
+ ostate <= ST_RESP_PREAMBLE;\r
+ end\r
+ end\r
+ ST_RESP_PREAMBLE: begin\r
+ // to meet exact 5 cycle requirement between command and response for CMD2/ACMD41\r
+ odc <= 0;\r
+ ostate <= ST_RESP_WRITE;\r
+ end\r
+ ST_RESP_WRITE: begin\r
+ sd_cmd_oe <= 1;\r
+ sd_cmd_out <= resp_out_latch[135];\r
+ crc7_out <= { crc7_out[5], crc7_out[4], crc7_out[3], crc7_out[2] ^ crc7_out[6] ^ resp_out_latch[135],\r
+ crc7_out[1], crc7_out[0], resp_out_latch[135] ^ crc7_out[6] }; \r
+ resp_out_latch <= {resp_out_latch[134:0], 1\'b1}; \r
+ case(resp_type_s)\r
+ RESP_R1, RESP_R1B, RESP_R3, RESP_R6, RESP_R7: begin\r
+ // 48 bit codes \r
+ if(resp_type_s == RESP_R3) begin\r
+ // fix R3 CRC to 1\'s\r
+ crc7_out <= 7\'b1111111;\r
+ end\r
+ if(odc >= 40) begin\r
+ crc7_out <= {crc7_out[5:0], 1\'b1};\r
+ sd_cmd_out <= crc7_out[6];\r
+ end\r
+ if(odc == 47) ostate <= ST_RESP_WRITE_END;\r
+ end\r
+ RESP_R2: begin\r
+ // 136 bit codes\r
+ // only CRC over the last 128 bits\r
+ if(odc < 8) crc7_out <= 0;\r
+ if(odc >= 128) begin\r
+ crc7_out <= {crc7_out[5:0], 1\'b1};\r
+ sd_cmd_out <= crc7_out[6];\r
+ end\r
+ if(odc == 135) ostate <= ST_RESP_WRITE_END;\r
+ end\r
+ endcase\r
+ end\r
+ ST_RESP_WRITE_END: begin\r
+ sd_cmd_oe <= 0;\r
+ resp_done <= 1;\r
+ ostate <= ST_IDLE;\r
+ end\r
+ default: ostate <= ST_RESET;\r
+ endcase\r
+ \r
+ \r
+ \r
+ dodc <= dodc + 1\'b1;\r
+ bram_rd_sd_wren <= 0;\r
+ \r
+ //\r
+ // data output FSM\r
+ //\r
+ case(dostate)\r
+ ST_RESET: begin\r
+ sd_dat_oe <= 4\'b0;\r
+ data_out_busy <= 0;\r
+ data_out_done <= 0;\r
+ dostate <= ST_IDLE;\r
+ end\r
+ ST_IDLE: begin\r
+ dodc <= 0;\r
+ sd_dat_oe <= 4\'b0;\r
+ if(data_out_act_r) begin\r
+ // start sending data packet\r
+ data_out_busy <= 1;\r
+ data_out_done <= 0;\r
+ bram_rd_sd_addr <= 0;\r
+ dostate <= ST_DATA_WRITE;\r
+ end else\r
+ if(do_crc_token) begin\r
+ // send data CRC token, busy signal for written blocks\r
+ dostate <= ST_DATA_TOKEN;\r
+ end\r
+ end\r
+ ST_DATA_WRITE: begin\r
+ // delay start of output\r
+ if(dodc == 0) begin // 0: no delay\r
+ dodc <= 0;\r
+ // enable which data lines will be driven\r
+ sd_dat_oe <= mode_4bit_s ? 4\'b1111 : 4\'b0001;\r
+ sd_dat_out <= 4\'b0;\r
+ dostate <= ST_DATA_WRITE_1;\r
+ end\r
+ crc16_out3 <= 16\'h0;\r
+ crc16_out2 <= 16\'h0;\r
+ crc16_out1 <= 16\'h0;\r
+ crc16_out0 <= 16\'h0;\r
+ \r
+ // preload bram Q data\r
+ dout_buf <= bram_rd_sd_q;\r
+ data_out_reg_latch <= data_out_reg;\r
+ end\r
+ ST_DATA_WRITE_1: begin\r
+ if(mode_4bit_s) begin\r
+ sd_dat_out <= dout_4bit;\r
+ crc16_out3 <= {crc16_out3[14:0], 1\'b0} ^ ((dout_4bit[3] ^ crc16_out3[15]) ? 16\'h1021 : 16\'h0);\r
+ crc16_out2 <= {crc16_out2[14:0], 1\'b0} ^ ((dout_4bit[2] ^ crc16_out2[15]) ? 16\'h1021 : 16\'h0);\r
+ crc16_out1 <= {crc16_out1[14:0], 1\'b0} ^ ((dout_4bit[1] ^ crc16_out1[15]) ? 16\'h1021 : 16\'h0);\r
+ crc16_out0 <= {crc16_out0[14:0], 1\'b0} ^ ((dout_4bit[0] ^ crc16_out0[15]) ? 16\'h1021 : 16\'h0);\r
+ \r
+ data_out_reg_latch[511:0] <= {data_out_reg_latch[507:0], 4\'b0};\r
+ dout_buf[31:0] <= {dout_buf[27:0], 4\'b0};\r
+ \r
+ // advance thru 32bit bram output word\r
+ if(dodc[2:0] == 3\'d0) bram_rd_sd_addr <= bram_rd_sd_addr + 1\'b1;\r
+ if(dodc[2:0] == 3\'d7) dout_buf <= bram_rd_sd_q;\r
+ end else begin\r
+ sd_dat_out[0] <= dout_1bit;\r
+ crc16_out0 <= {crc16_out0[14:0], 1\'b0} ^ ((dout_1bit[0] ^ crc16_out0[15]) ? 16\'h1021 : 16\'h0);\r
+ \r
+ data_out_reg_latch[511:0] <= {data_out_reg_latch[510:0], 1\'b0};\r
+ dout_buf[31:0] <= {dout_buf[30:0], 1\'b0};\r
+ \r
+ // advance thru 32bit bram output word\r
+ if(dodc[4:0] == 5\'d0) bram_rd_sd_addr <= bram_rd_sd_addr + 1\'b1;\r
+ if(dodc[4:0] == 5\'d31) dout_buf <= bram_rd_sd_q;\r
+ end\r
+ \r
+ if((mode_4bit_s ? (dodc+1) >> 1 : (dodc+1) >> 3) == data_out_len_s) begin\r
+ // end, dump crc\r
+ dodc <= 0;\r
+ dostate <= ST_DATA_WRITE_2;\r
+ end\r
+\r
+ if(data_out_stop_s) begin\r
+ sd_dat_out <= 4\'hF;\r
+ data_out_done <= 1;\r
+ dostate <= ST_DATA_WRITE_3;\r
+ end\r
+ end\r
+ ST_DATA_WRITE_2: begin\r
+ sd_dat_out[3] <= crc16_out3[15];\r
+ sd_dat_out[2] <= crc16_out2[15];\r
+ sd_dat_out[1] <= crc16_out1[15];\r
+ sd_dat_out[0] <= crc16_out0[15];\r
+ \r
+ crc16_out3[15:0] <= {crc16_out3[14:0], 1\'b1};\r
+ crc16_out2[15:0] <= {crc16_out2[14:0], 1\'b1};\r
+ crc16_out1[15:0] <= {crc16_out1[14:0], 1\'b1};\r
+ crc16_out0[15:0] <= {crc16_out0[14:0], 1\'b1};\r
+ \r
+ if(dodc == 16 || data_out_stop_s) begin\r
+ // end, including 1 stop bit\r
+ data_out_done <= 1;\r
+ dostate <= ST_DATA_WRITE_3;\r
+ end\r
+ end\r
+ ST_DATA_WRITE_3: begin\r
+ if(~data_out_act_s) begin\r
+ // let link know we are able to detect ACT\'s next rising edge\r
+ // due to extreme differences in clock rates\r
+ data_out_busy <= 0;\r
+ dostate <= ST_IDLE;\r
+ end\r
+ end\r
+ \r
+ ST_DATA_TOKEN: begin\r
+ // send CRC token\r
+ case(dodc)\r
+ 1: begin\r
+ sd_dat_oe[0] <= 1; \r
+ sd_dat_out[0] <= 0; // start bit\r
+ end\r
+ 2: sd_dat_out[0] <= ~data_in_crc_good;\r
+ 3: sd_dat_out[0] <= data_in_crc_good;\r
+ 4: sd_dat_out[0] <= ~data_in_crc_good;\r
+ 5: sd_dat_out[0] <= 1; // stop/end bit\r
+ 6: begin\r
+ sd_dat_out[0] <= 0; // start bit of busy\r
+ dostate <= ST_DATA_TOKEN_1;\r
+ end\r
+ endcase\r
+ end\r
+ ST_DATA_TOKEN_1: begin\r
+ // busy signal until data sink deasserts ACT\r
+ sd_dat_oe[0] <= 1;\r
+ sd_dat_out[0] <= 0;\r
+ if(~data_in_act_s) begin\r
+ // drive stop bit high\r
+ sd_dat_oe[0] <= 1;\r
+ sd_dat_out[0] <= 1;\r
+ dostate <= ST_DATA_TOKEN_2;\r
+ end\r
+ end\r
+ ST_DATA_TOKEN_2: begin\r
+ sd_dat_oe[0] <= 0;\r
+ dostate <= ST_IDLE;\r
+ end\r
+ default: dostate <= ST_RESET;\r
+ endcase\r
+ \r
+ // for snooping real cards\r
+ // sd_dat_oe <= 4\'b0;\r
+ // sd_cmd_oe <= 1\'b0;\r
+ end\r
+end\r
+\r
+\r
+endmodule\r
+"
+"/*\r
+ Copyright 2015, Google Inc.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the ""License"");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an ""AS IS"" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+module ftl_top (\r
+ input wire clk_50,\r
+ input wire reset_n,\r
+\r
+ output wire [9:0] dbg_phy_num_valid_blocks,\r
+ output wire dbg_phy_rebuilt_badblock,\r
+ output wire dbg_phy_remapped_runtime,\r
+ output wire err_phy_out_of_extras,\r
+\r
+ // slave wishbone interface (from SDHC)\r
+ input wire wbs_clk_i,\r
+ input wire [31:0] wbs_adr_i,\r
+ output wire [31:0] wbs_dat_o,\r
+ input wire [31:0] wbs_dat_i,\r
+ input wire [3:0] wbs_sel_i,\r
+ input wire wbs_cyc_i,\r
+ input wire wbs_stb_i,\r
+ input wire wbs_we_i,\r
+ output wire wbs_ack_o,\r
+\r
+ // master wishbone interface (to NANDC)\r
+ output wire wbm_clk_o,\r
+ output wire [2:0] wbm_cti_o, // type - cycle type identifier\r
+ output wire [1:0] wbm_bte_o, // exten - burst type extension\r
+ output wire [31:0] wbm_adr_o,\r
+ input wire [31:0] wbm_dat_i,\r
+ output wire [31:0] wbm_dat_o,\r
+ output wire [3:0] wbm_sel_o,\r
+ output wire wbm_cyc_o,\r
+ output wire wbm_stb_o,\r
+ output wire wbm_we_o,\r
+ input wire wbm_ack_i\r
+);\r
+\r
+wire reset_s;\r
+synch_3 a(reset_n, reset_s, clk_50);\r
+ \r
+wire physical_init_done;\r
+wire op_page_do;\r
+wire [2:0] op_page_cmd;\r
+wire [15:0] op_page_num;\r
+wire [15:0] op_page_bram;\r
+wire [41:0] op_page_spare_wr;\r
+wire [41:0] op_page_spare_rd;\r
+wire op_page_status;\r
+wire op_page_ack;\r
+wire op_page_done;\r
+ \r
+wire logical_init_done;\r
+ \r
+wire wb_read;\r
+wire wb_write;\r
+wire [9:0] wb_block;\r
+wire wb_ack;\r
+wire wb_done;\r
+\r
+wire bram_wbs_clk;\r
+wire [15:0] bram_wbs_addr;\r
+wire bram_wbs_wren;\r
+wire [31:0] bram_wbs_data;\r
+wire [31:0] bram_wbs_q;\r
+\r
+wire bram_physical_req;\r
+wire bram_physical_ack;\r
+wire [15:0] bram_physical_addr;\r
+wire bram_physical_wren;\r
+wire [31:0] bram_physical_data;\r
+wire [31:0] bram_physical_q;\r
+\r
+ftl_wbs ifw (\r
+ .clk_50 ( clk_50 ),\r
+ .reset_n ( reset_s ),\r
+\r
+ // slave wishbone interface (from SDHC)\r
+ .wbs_clk_i ( wbs_clk_i ),\r
+ .wbs_adr_i ( wbs_adr_i ),\r
+ .wbs_dat_o ( wbs_dat_o ),\r
+ .wbs_dat_i ( wbs_dat_i ),\r
+ .wbs_sel_i ( wbs_sel_i ),\r
+ .wbs_cyc_i ( wbs_cyc_i ),\r
+ .wbs_stb_i ( wbs_stb_i ),\r
+ .wbs_we_i ( wbs_we_i ),\r
+ .wbs_ack_o ( wbs_ack_o ),\r
+\r
+ // port to cached block ram\r
+ .bram_wbs_clk ( bram_wbs_clk ),\r
+ .bram_wbs_addr ( bram_wbs_addr ),\r
+ .bram_wbs_wren ( bram_wbs_wren ),\r
+ .bram_wbs_data ( bram_wbs_data ),\r
+ .bram_wbs_q ( bram_wbs_q ),\r
+\r
+ .logical_init_done ( logical_init_done ),\r
+ .wb_read ( wb_read ),\r
+ .wb_write ( wb_write ),\r
+ .wb_block ( wb_block ),\r
+ .wb_ack ( wb_ack ),\r
+ .wb_done ( wb_done )\r
+);\r
+\r
+ftl_logical ilog (\r
+ .clk_50 ( clk_50 ),\r
+ .reset_n ( reset_s ),\r
+ \r
+ .physical_init_done ( physical_init_done ),\r
+ .init_done ( logical_init_done ),\r
+ \r
+ .wb_read ( wb_read ),\r
+ .wb_write ( wb_write ),\r
+ .wb_block ( wb_block ),\r
+ .wb_ack ( wb_ack ),\r
+ .wb_done ( wb_done ),\r
+ \r
+ .op_page_do ( op_page_do ),\r
+ .op_page_cmd ( op_page_cmd ),\r
+ .op_page_num ( op_page_num ),\r
+ .op_page_bram ( op_page_bram ),\r
+ .op_page_spare_wr ( op_page_spare_wr ),\r
+ .op_page_spare_rd ( op_page_spare_rd ),\r
+ .op_page_status ( op_page_status ),\r
+ .op_page_ack ( op_page_ack ),\r
+ .op_page_done ( op_page_done )\r
+);\r
+\r
+ftl_buf ibuf (\r
+ .clk_50 ( clk_50 ),\r
+ .reset_n ( reset_s ),\r
+\r
+ .bram_wbs_clk ( bram_wbs_clk ),\r
+ .bram_wbs_addr ( bram_wbs_addr ),\r
+ .bram_wbs_wren ( bram_wbs_wren ),\r
+ .bram_wbs_data ( bram_wbs_data ),\r
+ .bram_wbs_q ( bram_wbs_q ),\r
+\r
+ .bram_physical_addr ( bram_physical_addr ),\r
+ .bram_physical_wren ( bram_physical_wren ),\r
+ .bram_physical_data ( bram_physical_data ),\r
+ .bram_physical_q ( bram_physical_q )\r
+);\r
+\r
+ftl_physical iphy(\r
+ .clk_50 ( clk_50 ),\r
+ .reset_n ( reset_s ),\r
+ \r
+ .init_done ( physical_init_done ),\r
+ \r
+ .dbg_num_valid_blocks ( dbg_phy_num_valid_blocks ),\r
+ .dbg_rebuilt_badblock ( dbg_phy_rebuilt_badblock ),\r
+ .dbg_remapped_runtime ( dbg_phy_remapped_runtime ),\r
+ .err_out_of_extras ( err_phy_out_of_extras ),\r
+ \r
+ .bram_page_addr ( bram_physical_addr ),\r
+ .bram_page_wren ( bram_physical_wren ),\r
+ .bram_page_data ( bram_physical_data ),\r
+ .bram_page_q ( bram_physical_q ),\r
+ \r
+ .op_page_do ( op_page_do ),\r
+ .op_page_cmd ( op_page_cmd ),\r
+ .op_page_num ( op_page_num ),\r
+ .op_page_bram ( op_page_bram ),\r
+ .op_page_spare_wr ( op_page_spare_wr ),\r
+ .op_page_spare_rd ( op_page_spare_rd ),\r
+ .op_page_status ( op_page_status ),\r
+ .op_page_ack ( op_page_ack ),\r
+ .op_page_done ( op_page_done ),\r
+\r
+ .wbm_clk_o ( wbm_clk_o ),\r
+ .wbm_cti_o ( wbm_cti_o ),\r
+ .wbm_bte_o ( wbm_bte_o ),\r
+ .wbm_adr_o ( wbm_adr_o ),\r
+ .wbm_dat_i ( wbm_dat_i ),\r
+ .wbm_dat_o ( wbm_dat_o ),\r
+ .wbm_sel_o ( wbm_sel_o ),\r
+ .wbm_cyc_o ( wbm_cyc_o ),\r
+ .wbm_stb_o ( wbm_stb_o ),\r
+ .wbm_we_o ( wbm_we_o ),\r
+ .wbm_ack_i ( wbm_ack_i )\r
+);\r
+\r
+/*\r
+(* mark_debug = ""true"" *) reg wb_read_reg;\r
+(* mark_debug = ""true"" *) reg wb_write_reg;\r
+(* mark_debug = ""true"" *) reg [9:0] wb_block_reg;\r
+(* mark_debug = ""true"" *) reg wb_ack_reg;\r
+(* mark_debug = ""true"" *) reg wb_done_reg;\r
+(* mark_debug = ""true"" *) reg logical_init_done_reg;\r
+(* mark_debug = ""true"" *) reg physical_init_done_reg;\r
+\r
+always @(posedge clk_50) begin\r
+ wb_read_reg <= wb_read;\r
+ wb_write_reg <= wb_write;\r
+ wb_block_reg <= wb_block;\r
+ wb_ack_reg <= wb_ack;\r
+ wb_done_reg <= wb_done;\r
+ logical_init_done_reg <= logical_init_done;\r
+ physical_init_done_reg <= physical_init_done;\r
+end\r
+\r
+ila_0 ila_0 (\r
+ .clk(clk_50),\r
+ .probe0({\r
+ physical_init_done_reg,\r
+ logical_init_done_reg,\r
+ wb_done_reg,\r
+ wb_ack_reg,\r
+ wb_block_reg,\r
+ wb_write_reg,\r
+ wb_read_reg \r
+ })\r
+);\r
+*/\r
+\r
+endmodule\r
+"
+"/*\r
+ Copyright 2015, Google Inc.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the ""License"");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an ""AS IS"" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+module sd_link (\r
+ input wire clk_50,\r
+ input wire reset_n,\r
+\r
+ output wire [3:0] link_card_state,\r
+\r
+ input wire [47:0] phy_cmd_in,\r
+ input wire phy_cmd_in_crc_good,\r
+ input wire phy_cmd_in_act,\r
+ output reg phy_data_in_act,\r
+ input wire phy_data_in_busy,\r
+ output reg phy_data_in_stop,\r
+ output reg phy_data_in_another,\r
+ input wire phy_data_in_done,\r
+ input wire phy_data_in_crc_good,\r
+\r
+ output reg [135:0] phy_resp_out,\r
+ output reg [3:0] phy_resp_type,\r
+ output reg phy_resp_busy,\r
+ output reg phy_resp_act,\r
+ input wire phy_resp_done,\r
+ output reg phy_mode_4bit,\r
+ output reg [511:0] phy_data_out_reg,\r
+ output reg phy_data_out_src,\r
+ output reg [9:0] phy_data_out_len,\r
+ input wire phy_data_out_busy,\r
+ output reg phy_data_out_act,\r
+ output reg phy_data_out_stop,\r
+ input wire phy_data_out_done,\r
+\r
+ output reg block_read_act,\r
+ input wire block_read_go,\r
+ output reg [31:0] block_read_addr,\r
+ output reg [31:0] block_read_num,\r
+ output reg block_read_stop,\r
+\r
+ output reg block_write_act,\r
+ input wire block_write_done,\r
+ output reg [31:0] block_write_addr,\r
+ output reg [31:0] block_write_num,\r
+ output reg [22:0] block_preerase_num,\r
+\r
+ output reg [31:0] block_erase_start,\r
+ output reg [31:0] block_erase_end,\r
+\r
+ input wire opt_enable_hs,\r
+\r
+ output reg [5:0] cmd_in_last,\r
+ output reg info_card_desel,\r
+ output reg err_host_is_spi,\r
+ output reg err_op_out_range,\r
+ output reg err_unhandled_cmd,\r
+ output reg err_cmd_crc\r
+ ,\r
+ output wire [5:0] cmd_in_cmd\r
+);\r
+\r
+`include ""sd_params.vh""\r
+`include ""sd_const.vh""\r
+\r
+reg [47:0] cmd_in_latch;\r
+// wire [5:0] cmd_in_cmd = cmd_in_latch[45:40] /* synthesis noprune */;\r
+assign cmd_in_cmd = cmd_in_latch[45:40];\r
+wire [31:0] cmd_in_arg = cmd_in_latch[39:8] /* synthesis noprune */;\r
+wire [6:0] cmd_in_crc = cmd_in_latch[7:1];\r
+ \r
+reg [3:0] card_state;\r
+assign link_card_state = card_state;\r
+reg [3:0] card_state_next;\r
+reg [3:0] card_acmd41_count;\r
+reg [2:0] card_erase_state;\r
+reg card_appcmd;\r
+reg [31:0] card_status;\r
+reg [127:0] card_sd_status;\r
+reg [127:0] card_csd;\r
+reg [127:0] card_cid;\r
+reg [31:0] card_ocr;\r
+reg [15:0] card_rca;\r
+reg [63:0] card_scr;\r
+reg [111:0] card_function_caps;\r
+reg [23:0] card_function;\r
+reg [23:0] card_function_check;\r
+reg [31:0] card_blocks_written;\r
+reg [127:0] resp_arg; // for 32 or 128bit\r
+reg [3:0] resp_type;\r
+\r
+reg [15:0] dc;\r
+reg [15:0] ddc;\r
+ \r
+reg [6:0] state;\r
+parameter [6:0] ST_RESET = \'d0,\r
+ ST_IDLE = \'d4,\r
+ ST_CMD_ACT = \'d8,\r
+ ST_CMD_RESP_0 = \'d9,\r
+ ST_CMD_RESP_1 = \'d10,\r
+ ST_CMD_RESP_2 = \'d11,\r
+ ST_LAST = \'d127;\r
+ \r
+reg [6:0] data_state;\r
+parameter [6:0] DST_RESET = \'d0,\r
+ DST_IDLE = \'d1,\r
+ DST_IDLE_1 = \'d2,\r
+ DST_DATA_OUT_0 = \'d10,\r
+ DST_DATA_OUT_1 = \'d11,\r
+ DST_DATA_OUT_2 = \'d12,\r
+ DST_DATA_OUT_3 = \'d13,\r
+ DST_DATA_OUT_4 = \'d14,\r
+ DST_DATA_OUT_5 = \'d15,\r
+ DST_DATA_IN_0 = \'d20,\r
+ DST_DATA_IN_1 = \'d21,\r
+ DST_DATA_IN_2 = \'d22,\r
+ DST_DATA_IN_3 = \'d23,\r
+ DST_DATA_IN_4 = \'d24,\r
+ DST_DATA_IN_5 = \'d25,\r
+ DST_LAST = \'d127;\r
+\r
+reg data_op_send_scr;\r
+reg data_op_send_sdstatus;\r
+reg data_op_send_function;\r
+reg data_op_send_written;\r
+reg data_op_send_block;\r
+reg data_op_send_block_queue;\r
+ \r
+reg data_op_recv_block;\r
+ \r
+// synchronizers\r
+wire reset_s;\r
+wire [47:0] cmd_in_s;\r
+wire cmd_in_crc_good_s;\r
+wire cmd_in_act_s, cmd_in_act_r;\r
+wire data_in_busy_s;\r
+wire data_in_done_s, data_in_done_r;\r
+wire data_in_crc_good_s;\r
+wire resp_done_s, resp_done_r;\r
+wire data_out_busy_s;\r
+wire data_out_done_s, data_out_done_r;\r
+synch_3 a(reset_n, reset_s, clk_50);\r
+synch_3 #(48) b(phy_cmd_in, cmd_in_s, clk_50);\r
+synch_3 c(phy_cmd_in_crc_good, cmd_in_crc_good_s, clk_50);\r
+synch_3 d(phy_cmd_in_act, cmd_in_act_s, clk_50, cmd_in_act_r);\r
+synch_3 e(phy_data_in_busy, data_in_busy_s, clk_50);\r
+synch_3 f(phy_data_in_done, data_in_done_s, clk_50, data_in_done_r);\r
+synch_3 g(phy_data_in_crc_good, data_in_crc_good_s, clk_50);\r
+synch_3 h(phy_resp_done, resp_done_s, clk_50, resp_done_r);\r
+synch_3 i(phy_data_out_busy, data_out_busy_s, clk_50);\r
+synch_3 j(phy_data_out_done, data_out_done_s, clk_50, data_out_done_r);\r
+\r
+always @(posedge clk_50) begin\r
+\r
+ // free running counter\r
+ dc <= dc + 1\'b1;\r
+ \r
+ case(state)\r
+ ST_RESET: begin\r
+ dc <= 0;\r
+ info_card_desel <= 0;\r
+ err_host_is_spi <= 0;\r
+ err_op_out_range <= 0;\r
+ err_unhandled_cmd <= 0;\r
+ err_cmd_crc <= 0;\r
+ card_erase_state <= 0;\r
+ card_acmd41_count <= 0;\r
+ card_blocks_written <= 0;\r
+ card_appcmd <= 0;\r
+ card_rca <= 16\'h0;\r
+ card_status <= 0;\r
+ card_status[STAT_READY_FOR_DATA] <= 1\'b1;\r
+ card_state <= CARD_IDLE;\r
+ card_ocr <= {8\'b01000000, OCR_VOLTAGE_WINDOW}; // high capacity, not powered up\r
+ card_cid <= {CID_FIELD_MID, CID_FIELD_OID, CID_FIELD_PNM, CID_FIELD_PRV, CID_FIELD_PSN, \r
+ 4\'b0, CID_FIELD_MDT, 8\'hFF};\r
+ card_csd <= {CSD_CSD_STRUCTURE, 6\'h0, CSD_TAAC, CSD_NSAC, CSD_TRAN_SPEED_25, CSD_CCC, CSD_READ_BL_LEN,\r
+ CSD_READ_BL_PARTIAL, CSD_WRITE_BLK_MISALIGN, CSD_READ_BLK_MISALIGN, CSD_DSR_IMPL, 6\'h0,\r
+ CSD_C_SIZE, 1\'b0, CSD_ERASE_BLK_EN, CSD_SECTOR_SIZE, CSD_WP_GRP_SIZE, CSD_WP_GRP_ENABLE,\r
+ 2\'b00, CSD_R2W_FACTOR, CSD_WRITE_BL_LEN, CSD_WRITE_BL_PARTIAL, 5\'h0, CSD_FILE_FORMAT_GRP,\r
+ CSD_COPY, CSD_PERM_WRITE_PROTECT, CSD_TMP_WRITE_PROTECT, CSD_FILE_FORMAT, 2\'h0, 8\'hFF};\r
+ card_scr <= {SCR_SCR_STRUCTURE, SCR_SD_SPEC, SCR_DATA_STATE_ERASE, SCR_SD_SECURITY, SCR_SD_BUS_WIDTHS,\r
+ SCR_SD_SPEC3, 13\'h0, 2\'h0, 32\'h0};\r
+ card_sd_status <= { STAT_DAT_BUS_WIDTH_1, STAT_SECURED_MODE, 7\'h0, 6\'h0, STAT_SD_CARD_TYPE, \r
+ STAT_SIZE_OF_PROT_AREA, STAT_SPEED_CLASS, STAT_PERFORMANCE_MOVE, STAT_AU_SIZE,\r
+ 4\'h0, STAT_ERASE_SIZE, STAT_ERASE_TIMEOUT, STAT_ERASE_OFFSET, 15\'h0};\r
+ // set high speed capability bit\r
+ card_function_caps <= 112\'h0032800180018001800180018001 | opt_enable_hs ? 2\'b10 : 2\'b00;\r
+ card_function <= 24\'h0;\r
+ card_function_check <= 24\'h0; \r
+ \r
+ data_op_send_scr <= 0; \r
+ data_op_send_sdstatus <= 0;\r
+ data_op_send_function <= 0;\r
+ data_op_send_written <= 0;\r
+ data_op_send_block <= 0;\r
+ data_op_send_block_queue <= 0;\r
+ \r
+ data_op_recv_block <= 0;\r
+ \r
+ phy_data_in_act <= 0;\r
+ phy_data_in_stop <= 0;\r
+ phy_resp_act <= 0;\r
+ phy_data_out_act <= 0;\r
+ phy_data_out_stop <= 0;\r
+ phy_mode_4bit <= 0; \r
+ \r
+ block_read_act <= 0;\r
+ block_read_num <= 0;\r
+ block_read_stop <= 0;\r
+ block_write_act <= 0;\r
+ block_write_num <= 0;\r
+ block_preerase_num <= 0;\r
+ \r
+ state <= ST_IDLE;\r
+ end\r
+ ST_IDLE: begin\r
+ // rising edge + crc is good\r
+ if(cmd_in_act_r) begin\r
+ phy_resp_act <= 0;\r
+ if(cmd_in_crc_good_s) begin\r
+ // new command\r
+ cmd_in_latch <= phy_cmd_in; //cmd_in_s;\r
+ card_status[STAT_COM_CRC_ERROR] <= 0;\r
+ card_status[STAT_ILLEGAL_COMMAND] <= 0;\r
+ state <= ST_CMD_ACT;\r
+ cmd_in_last <= cmd_in_cmd;\r
+ end else begin\r
+ // bad crc\r
+ err_cmd_crc <= 1;\r
+ card_status[STAT_COM_CRC_ERROR] <= 1;\r
+ end\r
+ end\r
+ end\r
+ ST_CMD_ACT: begin\r
+ // parse the command\r
+ state <= ST_CMD_RESP_0;\r
+ // unless otherwise, stay in the same SD state\r
+ card_state_next <= card_state;\r
+ // unless set below, assume it\'s illegal\r
+ resp_type <= RESP_BAD;\r
+ \r
+ if(~card_appcmd) begin\r
+ // CMD\r
+ case(cmd_in_cmd)\r
+ CMD0_GO_IDLE: begin\r
+ if(card_state != CARD_INA) begin\r
+ // reset everything to default\r
+ resp_type <= RESP_NONE;\r
+ state <= ST_RESET;\r
+ data_state <= DST_RESET;\r
+ end\r
+ end\r
+ CMD2_ALL_SEND_CID: case(card_state)\r
+ CARD_READY: begin\r
+ resp_type <= RESP_R2;\r
+ card_state_next <= CARD_IDENT;\r
+ end\r
+ endcase\r
+ CMD3_SEND_REL_ADDR : case(card_state)\r
+ CARD_IDENT, CARD_STBY: begin\r
+ card_rca <= card_rca + 16\'h1337;\r
+ resp_type <= RESP_R6;\r
+ card_state_next <= CARD_STBY;\r
+ end\r
+ endcase\r
+ //CMD4_SET_DSR: begin\r
+ //end\r
+ CMD6_SWITCH_FUNC: begin\r
+ case(card_state)\r
+ CARD_TRAN: begin\r
+ case(cmd_in_arg[23:20])\r
+ 4\'h0, 4\'hF: card_function_check[23:20] <= 4\'h0; // valid\r
+ default: card_function_check[23:20] <= 4\'hF; // invalid\r
+ endcase\r
+ case(cmd_in_arg[19:16])\r
+ 4\'h0, 4\'hF: card_function_check[19:16] <= 4\'h0; // valid\r
+ default: card_function_check[19:16] <= 4\'hF; // invalid\r
+ endcase\r
+ case(cmd_in_arg[15:12])\r
+ 4\'h0, 4\'hF: card_function_check[15:12] <= 4\'h0; // valid\r
+ default: card_function_check[15:12] <= 4\'hF; // invalid\r
+ endcase\r
+ case(cmd_in_arg[11:8]) \r
+ 4\'h0, 4\'hF: card_function_check[11:8] <= 4\'h0; // valid\r
+ default: card_function_check[11:8] <= 4\'hF; // invalid\r
+ endcase\r
+ case(cmd_in_arg[7:4])\r
+ 4\'h0, 4\'hF: card_function_check[7:4] <= 4\'h0; // valid\r
+ default: card_function_check[7:4] <= 4\'hF; // invalid\r
+ endcase\r
+ case(cmd_in_arg[3:0])\r
+ 4\'h0: card_function_check[3:0] <= 4\'h0;\r
+ 4\'hF: card_function_check[3:0] <= card_function[3:0];\r
+ 4\'h1: begin \r
+ card_function_check[3:0] <= 4\'h1; // high speed enable\r
+ if(cmd_in_arg[31]) card_function[3:0] <= 4\'h1;\r
+ end\r
+ default: card_function_check[3:0] <= 4\'hF; // invalid\r
+ endcase\r
+ resp_type <= RESP_R1;\r
+ card_state_next <= CARD_DATA;\r
+ data_op_send_function <= 1;\r
+ end\r
+ endcase\r
+ end\r
+ CMD7_SEL_CARD: begin\r
+ if(cmd_in_arg[31:16] == card_rca) begin\r
+ // select\r
+ resp_type <= RESP_R1B;\r
+ case(card_state)\r
+ CARD_STBY: card_state_next <= CARD_TRAN;\r
+ //CARD_DIS: card_state_next <= CARD_PRG;\r
+ CARD_DIS: card_state_next <= CARD_TRAN;\r
+ default: resp_type <= RESP_BAD;\r
+ endcase\r
+ end else begin\r
+ // deselected\r
+ case(card_state)\r
+ CARD_STBY: card_state_next <= CARD_STBY;\r
+ CARD_TRAN: card_state_next <= CARD_STBY;\r
+ CARD_DATA: card_state_next <= CARD_STBY;\r
+ CARD_PRG: card_state_next <= CARD_DIS;\r
+ //default: resp_type <= RESP_BAD;\r
+ endcase\r
+ info_card_desel <= 1;\r
+ resp_type <= RESP_NONE;\r
+ end\r
+ end\r
+ CMD8_SEND_IF_COND: case(card_state)\r
+ CARD_IDLE: begin\r
+ if(cmd_in_arg[11:8] == 4\'b0001) begin\r
+ resp_type <= RESP_R7;\r
+ resp_arg <= {20\'h0, 4\'b0001, cmd_in_arg[7:0]};\r
+ end else resp_type <= RESP_NONE;\r
+ end\r
+ endcase\r
+ CMD9_SEND_CSD: begin\r
+ if(cmd_in_arg[31:16] == card_rca) begin\r
+ case(card_state)\r
+ CARD_STBY: begin\r
+ resp_type <= RESP_R2;\r
+ end\r
+ endcase\r
+ end else resp_type <= RESP_NONE;\r
+ end\r
+ CMD10_SEND_CID: begin\r
+ if(cmd_in_arg[31:16] == card_rca) begin\r
+ case(card_state)\r
+ CARD_STBY: begin\r
+ resp_type <= RESP_R2;\r
+ end\r
+ endcase\r
+ end else resp_type <= RESP_NONE;\r
+ end\r
+ CMD12_STOP: case(card_state)\r
+ // N.B. should not be allowed in PRG state, but readers do anyway\r
+ CARD_DATA, CARD_RCV, CARD_PRG: begin\r
+ resp_type <= RESP_R1B;\r
+ if(card_state == CARD_DATA) card_state_next <= CARD_TRAN;\r
+ // PRG > TRAN transition is handled by the data states below\r
+ if(card_state == CARD_RCV) card_state_next <= CARD_TRAN;\r
+ if(card_state == CARD_PRG) card_state_next <= CARD_TRAN;\r
+ phy_data_in_stop <= 1;\r
+ phy_data_out_stop <= 1;\r
+ end\r
+ endcase\r
+ CMD13_SEND_STATUS: begin\r
+ if(cmd_in_arg[31:16] == card_rca) begin\r
+ case(card_state)\r
+ CARD_STBY, CARD_TRAN, CARD_DATA, CARD_RCV, CARD_PRG, CARD_DIS: begin\r
+ resp_type <= RESP_R1;\r
+ end\r
+ endcase\r
+ end else resp_type <= RESP_NONE;\r
+ end\r
+ CMD15_GO_INACTIVE: begin\r
+ if(cmd_in_arg[31:16] == card_rca) begin\r
+ case(card_state)\r
+ CARD_STBY, CARD_TRAN, CARD_DATA, CARD_RCV, CARD_PRG, CARD_DIS: begin\r
+ card_state_next <= CARD_INA;\r
+ resp_type <= RESP_NONE;\r
+ end\r
+ endcase\r
+ end else resp_type <= RESP_NONE;\r
+ end\r
+ CMD16_SET_BLOCKLEN: case(card_state)\r
+ CARD_TRAN: begin\r
+ resp_type <= RESP_R1;\r
+ if(cmd_in_arg > 512) card_status[STAT_BLOCK_LEN_ERROR] <= 1;\r
+ end\r
+ endcase\r
+ CMD17_READ_SINGLE: case(card_state)\r
+ CARD_TRAN: begin\r
+ if(cmd_in_arg >= SD_TOTAL_BLOCKS) begin\r
+ card_status[STAT_OUT_OF_RANGE] <= 1\'b1; err_op_out_range <= 1;\r
+ end else begin\r
+ resp_type <= RESP_R1;\r
+ block_read_addr <= cmd_in_arg;\r
+ block_read_num <= 1;\r
+ data_op_send_block_queue <= 1;\r
+ card_state_next <= CARD_DATA;\r
+ end\r
+ end\r
+ endcase\r
+ CMD18_READ_MULTIPLE: case(card_state)\r
+ CARD_TRAN: begin\r
+ if(cmd_in_arg >= SD_TOTAL_BLOCKS) begin\r
+ card_status[STAT_OUT_OF_RANGE] <= 1\'b1; err_op_out_range <= 1;\r
+ end else begin\r
+ resp_type <= RESP_R1;\r
+ block_read_addr <= cmd_in_arg;\r
+ block_read_num <= 32\'hFFFFFFFF;\r
+ data_op_send_block_queue <= 1;\r
+ card_state_next <= CARD_DATA;\r
+ end\r
+ end\r
+ endcase\r
+ CMD24_WRITE_SINGLE: case(card_state)\r
+ CARD_TRAN: begin\r
+ if(cmd_in_arg >= SD_TOTAL_BLOCKS) begin\r
+ card_status[STAT_OUT_OF_RANGE] <= 1\'b1; err_op_out_range <= 1;\r
+ end else begin\r
+ resp_type <= RESP_R1;\r
+ block_write_addr <= cmd_in_arg;\r
+ block_write_num <= 1;\r
+ card_blocks_written <= 0;\r
+ data_op_recv_block <= 1;\r
+ card_state_next <= CARD_RCV;\r
+ end\r
+ end\r
+ endcase\r
+ CMD25_WRITE_MULTIPLE: case(card_state)\r
+ CARD_TRAN: begin\r
+ if(cmd_in_arg >= SD_TOTAL_BLOCKS) begin\r
+ card_status[STAT_OUT_OF_RANGE] <= 1\'b1; err_op_out_range <= 1;\r
+ end else begin\r
+ resp_type <= RESP_R1;\r
+ block_write_addr <= cmd_in_arg;\r
+ block_write_num <= 32\'hFFFFFFFF;\r
+ card_blocks_written <= 0;\r
+ data_op_recv_block <= 1;\r
+ card_state_next <= CARD_RCV;\r
+ end\r
+ end\r
+ endcase\r
+ //CMD27_PROGRAM_CSD: begin\r
+ //end\r
+ CMD32_ERASE_START: case(card_state)\r
+ CARD_TRAN: begin\r
+ resp_type <= RESP_R1;\r
+ card_erase_state <= 0;\r
+ if(card_erase_state == 0) begin\r
+ block_erase_start <= cmd_in_arg;\r
+ card_erase_state <= 1;\r
+ end else card_status[STAT_ERASE_SEQ_ERROR] <= 1\'b1;\r
+ end\r
+ endcase\r
+ CMD33_ERASE_END: case(card_state)\r
+ CARD_TRAN: begin\r
+ resp_type <= RESP_R1;\r
+ card_erase_state <= 0;\r
+ if(card_erase_state == 1) begin\r
+ block_erase_end <= cmd_in_arg;\r
+ card_erase_state <= 2;\r
+ end else card_status[STAT_ERASE_SEQ_ERROR] <= 1\'b1;\r
+ end\r
+ endcase\r
+ CMD38_ERASE: case(card_state)\r
+ CARD_TRAN: begin\r
+ resp_type <= RESP_R1B;\r
+ card_erase_state <= 0;\r
+ if(card_erase_state == 2) begin\r
+ // process erase \r
+ \r
+ end else card_status[STAT_ERASE_SEQ_ERROR] <= 1\'b1;\r
+ // since erase are unimpl they happen immediately\r
+ //card_state_next <= CARD_PRG;\r
+ end\r
+ endcase\r
+ //CMD42_LOCK_UNLOCK: begin\r
+ //end\r
+ CMD55_APP_CMD: begin\r
+ if(cmd_in_arg[31:16] == card_rca) begin\r
+ case(card_state)\r
+ CARD_IDLE, CARD_STBY, CARD_TRAN, CARD_DATA, CARD_RCV, CARD_PRG, CARD_DIS: begin\r
+ resp_type <= RESP_R1;\r
+ card_appcmd <= 1;\r
+ card_status[STAT_APP_CMD] <= 1;\r
+ end\r
+ endcase\r
+ end else resp_type <= RESP_NONE;\r
+ end\r
+ //CMD56_GEN_CMD: begin\r
+ //end\r
+ default: begin\r
+ err_unhandled_cmd <= 1;\r
+ if(cmd_in_cmd == 6\'d1) err_unhandled_cmd <= 0; // CMD1 for SPI cards\r
+ if(cmd_in_cmd == 6\'d5) err_unhandled_cmd <= 0; // CMD5 for SDIO combo cards\r
+ end\r
+ endcase\r
+ // CMD1 is only used in SPI mode, which is not supported\r
+ if(cmd_in_cmd == 6\'h1) err_host_is_spi <= 1;\r
+ // check for illegal commands during an expected erase sequence\r
+ if(card_erase_state > 0) begin\r
+ if( cmd_in_cmd != CMD13_SEND_STATUS && \r
+ cmd_in_cmd != CMD33_ERASE_END && \r
+ cmd_in_cmd != CMD38_ERASE) begin\r
+ card_erase_state <= 0;\r
+ card_status[STAT_ERASE_RESET] <= 1;\r
+ end\r
+ end\r
+ end else begin\r
+ // ACMD\r
+ case(cmd_in_cmd)\r
+ ACMD6_SET_BUS_WIDTH: case(card_state)\r
+ CARD_TRAN: begin\r
+ resp_type <= RESP_R1;\r
+ phy_mode_4bit <= cmd_in_arg[1];\r
+ end\r
+ endcase\r
+ ACMD13_SD_STATUS: case(card_state)\r
+ CARD_TRAN: begin\r
+ resp_type <= RESP_R1;\r
+ // send SD status\r
+ data_op_send_sdstatus <= 1;\r
+ card_state_next <= CARD_DATA;\r
+ end\r
+ endcase\r
+ ACMD22_NUM_WR_BLK: case(card_state)\r
+ CARD_TRAN: begin\r
+ resp_type <= RESP_R1;\r
+ // send number blocks written\r
+ data_op_send_written <= 1;\r
+ card_state_next <= CARD_DATA;\r
+ end\r
+ endcase\r
+ ACMD23_SET_WR_BLK: case(card_state)\r
+ CARD_TRAN: begin\r
+ resp_type <= RESP_R1;\r
+ block_preerase_num[22:0] <= cmd_in_arg[22:0];\r
+ end\r
+ endcase\r
+ ACMD41_SEND_OP_COND: case(card_state)\r
+ CARD_IDLE: begin\r
+ resp_type <= RESP_R3;\r
+ card_acmd41_count <= card_acmd41_count + 1\'b1;\r
+ if(cmd_in_arg[23:0] == 24\'h0) begin\r
+ // ocr is zero, this is a query.\r
+ \r
+ end else\r
+ if(cmd_in_arg[30]) begin\r
+ // is host SDHC compatible? otherwise we\'ll never be ready\r
+ if(card_acmd41_count > 2) begin\r
+ card_ocr[OCR_POWERED_UP] <= 1;\r
+ card_state_next <= CARD_READY;\r
+ end\r
+ end \r
+ end\r
+ endcase\r
+ ACMD42_SET_CARD_DET: case(card_state)\r
+ // card detect pullup is unsupported\r
+ CARD_TRAN: resp_type <= RESP_R1;\r
+ endcase\r
+ ACMD51_SEND_SCR: case(card_state)\r
+ CARD_TRAN: begin\r
+ resp_type <= RESP_R1;\r
+ // send SCR\r
+ data_op_send_scr <= 1;\r
+ card_state_next <= CARD_DATA;\r
+ end\r
+ endcase\r
+ default: begin\r
+ // retry this as a regular CMD (retry this state with APPCMD=0)\r
+ state <= ST_CMD_ACT;\r
+ card_appcmd <= 0;\r
+ //err_unhandled_cmd <= 1;\r
+ \r
+ end\r
+ endcase\r
+ end\r
+ end\r
+ ST_CMD_RESP_0: begin\r
+ // update status register and such\r
+ card_status[12:9] <= card_state;\r
+ \r
+ state <= ST_CMD_RESP_1;\r
+ end\r
+ ST_CMD_RESP_1: begin\r
+ // send response\r
+ state <= ST_CMD_RESP_2;\r
+ phy_resp_type <= resp_type;\r
+ phy_resp_busy <= 0;\r
+ case(resp_type)\r
+ RESP_NONE: begin \r
+ // don\'t send a response\r
+ card_state <= card_state_next;\r
+ state <= ST_IDLE;\r
+ end\r
+ RESP_BAD: begin\r
+ // illegal\r
+ card_status[STAT_ILLEGAL_COMMAND] <= 1;\r
+ state <= ST_IDLE;\r
+ end\r
+ RESP_R1, RESP_R1B: begin\r
+ phy_resp_out <= {2\'b00, cmd_in_cmd, card_status, 8\'h1, 88\'h0};\r
+ end\r
+ RESP_R2: begin\r
+ phy_resp_out <= {2\'b00, 6\'b111111, cmd_in_cmd == CMD9_SEND_CSD ? card_csd[127:1] : card_cid[127:1], 1\'b1};\r
+ end\r
+ RESP_R3: begin\r
+ phy_resp_out <= {2\'b00, 6\'b111111, card_ocr, 8\'hFF, 88\'h0};\r
+ end\r
+ RESP_R6: begin\r
+ phy_resp_out <= {2\'b00, 6\'b000011, card_rca, {card_status[23:22], card_status[19], card_status[12:0]}, 8\'h1, 88\'h0};\r
+ end\r
+ RESP_R7: begin\r
+ phy_resp_out <= {2\'b00, 6\'b001000, resp_arg[31:0], 8\'h1, 88\'h0};\r
+ end\r
+ endcase \r
+ end\r
+ ST_CMD_RESP_2: begin\r
+ phy_resp_act <= 1;\r
+ \r
+ if(resp_done_r) begin\r
+ // rising edge, phy is done sending response\r
+ phy_resp_act <= 0;\r
+ \r
+ // clear APP_CMD after ACMD response sent\r
+ if(card_appcmd && (cmd_in_cmd != CMD55_APP_CMD)) begin\r
+ card_appcmd <= 0;\r
+ card_status[STAT_APP_CMD] <= 0; // not spec? but cards do it\r
+ end\r
+ case(cmd_in_cmd)\r
+ CMD13_SEND_STATUS: begin\r
+ // clear all bits that are Clear-On-Read\r
+ card_status[STAT_OUT_OF_RANGE] <= 0;\r
+ card_status[STAT_ADDRESS_ERROR] <= 0;\r
+ card_status[STAT_BLOCK_LEN_ERROR] <= 0;\r
+ card_status[STAT_ERASE_SEQ_ERROR] <= 0;\r
+ card_status[STAT_ERASE_PARAM] <= 0;\r
+ card_status[STAT_WP_VIOLATION] <= 0;\r
+ card_status[STAT_LOCK_UNLOCK_FAILED] <= 0;\r
+ card_status[STAT_CARD_ECC_FAILED] <= 0;\r
+ card_status[STAT_CC_ERROR] <= 0;\r
+ card_status[STAT_CSD_OVERWRITE] <= 0;\r
+ card_status[STAT_WP_ERASE_SKIP] <= 0;\r
+ card_status[STAT_ERASE_RESET] <= 0;\r
+ card_status[STAT_APP_CMD] <= 0;\r
+ card_status[STAT_AKE_SEQ_ERROR] <= 0;\r
+ end\r
+ endcase\r
+ card_state <= card_state_next;\r
+ state <= ST_IDLE;\r
+ end\r
+ end\r
+ endcase\r
+ \r
+ \r
+ // data FSM\r
+ // must be separate so that data packets can be transferred\r
+ // and commands still sent/responsed\r
+ //\r
+ // free running counter\r
+ ddc <= ddc + 1\'b1;\r
+ \r
+ case(data_state)\r
+ DST_RESET: begin\r
+ phy_data_out_act <= 0;\r
+ data_state <= DST_IDLE;\r
+ end\r
+ DST_IDLE: begin\r
+ card_status[STAT_READY_FOR_DATA] <= 1\'b1;\r
+ \r
+ if(data_op_recv_block) begin\r
+ // for data receive ops\r
+ data_state <= DST_DATA_IN_0;\r
+ end else \r
+ if( data_op_send_scr | data_op_send_sdstatus | \r
+ data_op_send_function | data_op_send_written | data_op_send_block_queue ) begin\r
+ \r
+ // move to next state once response is processing\r
+ // to prevent false starts\r
+ if(~resp_done_s) begin\r
+ data_state <= DST_IDLE_1;\r
+ // queue block read, so that it can be accepted after a much-delayed read cycle\r
+ if(data_op_send_block_queue) begin\r
+ //card_state <= CARD_DATA;\r
+ data_op_send_block_queue <= 0;\r
+ data_op_send_block <= 1;\r
+ end\r
+ end\r
+ end\r
+ end\r
+ DST_IDLE_1: begin\r
+ ddc <= 0;\r
+ \r
+ // process these data ops while response starts to send\r
+ if( data_op_send_scr | data_op_send_sdstatus | \r
+ data_op_send_function | data_op_send_written | data_op_send_block ) begin\r
+ \r
+ phy_data_out_src <= 1; // default: send from register\r
+ data_state <= DST_DATA_OUT_0;\r
+ \r
+ if(data_op_send_scr) begin\r
+ data_op_send_scr <= 0;\r
+ phy_data_out_len <= 8;\r
+ phy_data_out_reg <= {card_scr, 448\'h0};\r
+ end else\r
+ if(data_op_send_sdstatus) begin\r
+ data_op_send_sdstatus <= 0;\r
+ phy_data_out_len <= 64;\r
+ phy_data_out_reg <= {card_sd_status, 384\'h0};\r
+ end else\r
+ if(data_op_send_function) begin\r
+ data_op_send_function <= 0;\r
+ phy_data_out_len <= 64;\r
+ phy_data_out_reg <= {card_function_caps, card_function_check, 376\'h0};\r
+ end else \r
+ if(data_op_send_written) begin\r
+ data_op_send_written <= 0;\r
+ phy_data_out_len <= 4;\r
+ phy_data_out_reg <= {card_blocks_written, 480\'h0};\r
+ end else \r
+ if(data_op_send_block) begin\r
+ phy_data_out_src <= 0; // send data from bram\r
+ phy_data_out_len <= 512;\r
+ data_state <= DST_DATA_OUT_5;\r
+ end\r
+ end\r
+ end\r
+ DST_DATA_OUT_5: begin\r
+ // make sure MGR cleared from any previous ops\r
+ if(~block_read_go) begin\r
+ block_read_stop <= 0;\r
+ data_state <= DST_DATA_OUT_3;\r
+ end\r
+ end\r
+ DST_DATA_OUT_3: begin\r
+ // external bram op:\r
+ // wait for bram contents to be valid\r
+ block_read_act <= 1;\r
+ if(block_read_go) begin\r
+ // ready\r
+ block_read_act <= 0;\r
+ data_state <= DST_DATA_OUT_0;\r
+ end\r
+ end\r
+ DST_DATA_OUT_0: begin\r
+ // wait to send data until response was sent\r
+ if(resp_done_s) begin\r
+ phy_data_out_act <= 1;\r
+ data_state <= DST_DATA_OUT_1;\r
+ end\r
+ end\r
+ DST_DATA_OUT_1: begin\r
+ if(data_out_done_r) begin\r
+ // rising edge, phy is done sending data\r
+ phy_data_out_act <= 0;\r
+\r
+ // did link detect a stop command?\r
+ if(phy_data_out_stop) begin\r
+ phy_data_in_stop <= 0;\r
+ phy_data_out_stop <= 0;\r
+ data_op_send_block <= 0;\r
+ end\r
+\r
+ // tell upper level we\'re done\r
+ block_read_stop <= 1;\r
+ data_state <= DST_DATA_OUT_4;\r
+ end\r
+ end\r
+ DST_DATA_OUT_4: begin\r
+ // wait for SD_MGR to finish \r
+ if(~block_read_go) data_state <= DST_DATA_OUT_2;\r
+\r
+ // link detected stop while we\'re waiting\r
+ if(phy_data_out_stop) begin\r
+ phy_data_in_stop <= 0;\r
+ phy_data_out_stop <= 0;\r
+ data_op_send_block <= 0;\r
+ block_read_stop <= 1;\r
+ data_state <= DST_DATA_OUT_2;\r
+ end\r
+ end\r
+ DST_DATA_OUT_2: begin\r
+ // wait until phy de-asserts busy so that it can detect another rising edge\r
+ // due to clocking differences\r
+ if(~data_out_busy_s) begin\r
+ //block_read_stop <= 0;\r
+ // fall back to TRAN state\r
+ card_state <= CARD_TRAN;\r
+ data_state <= DST_IDLE;\r
+ // don\'t wait around for a response to be sent if more blocks are to be done\r
+ if(data_op_send_block) begin\r
+ if(block_read_num == 1) begin\r
+ data_op_send_block <= 0;\r
+ end else begin\r
+ // stay in current state\r
+ // advance block count\r
+ card_state <= card_state;\r
+ block_read_addr <= block_read_addr + 1\'b1;\r
+ block_read_num <= block_read_num - 1\'b1; \r
+ if(block_read_addr >= SD_TOTAL_BLOCKS) begin \r
+ card_status[STAT_OUT_OF_RANGE] <= 1\'b1; \r
+ err_op_out_range <= 1; \r
+ end\r
+ data_state <= DST_IDLE_1;\r
+ end\r
+ end\r
+ end\r
+ end\r
+ \r
+ DST_DATA_IN_0: begin\r
+ // signal to PHY that we are expecting a data packet\r
+ phy_data_in_act <= 1;\r
+ if(data_in_done_r) begin\r
+ card_status[STAT_READY_FOR_DATA] <= 1\'b0;\r
+ data_state <= DST_DATA_IN_1; \r
+ end\r
+ if(phy_data_in_stop) begin\r
+ phy_data_in_act <= 0;\r
+ card_state <= CARD_TRAN;\r
+ data_state <= DST_DATA_IN_2; \r
+ end\r
+ end\r
+ DST_DATA_IN_1: begin\r
+ if(~data_in_crc_good_s) begin\r
+ // bad CRC, don\'t commit\r
+ // expect host to re-send entire CMD24/25 sequence\r
+ phy_data_in_act <= 0;\r
+ data_op_recv_block <= 0;\r
+ card_state <= CARD_TRAN;\r
+ data_state <= DST_IDLE;\r
+ end else begin\r
+ // tell mgr/ext there is data to be written\r
+ block_write_act <= 1;\r
+ card_state <= CARD_PRG;\r
+ // mgr/ext has finished\r
+ if(block_write_done) begin\r
+ // tell PHY to let go of the busy signal on DAT0\r
+ card_state <= CARD_RCV;\r
+ phy_data_in_act <= 0;\r
+ block_write_act <= 0;\r
+ data_state <= DST_DATA_IN_2;\r
+ end\r
+ end\r
+ end\r
+ DST_DATA_IN_2: begin\r
+ // wait until PHY is able to detect new ACT\r
+ // or if it\'s a burst write, just go ahead anyway\r
+ if(~data_in_busy_s | (phy_data_in_another & ~phy_data_in_stop)) begin\r
+ data_state <= DST_DATA_IN_3;\r
+ end\r
+ phy_data_in_another <= block_write_num > 1;\r
+ //phy_data_in_stop <= 1;\r
+ end\r
+ DST_DATA_IN_3: begin\r
+ card_blocks_written <= card_blocks_written + 1\'b1;\r
+ if(block_write_num == 1 || phy_data_in_stop) begin\r
+ // last block, or it was CMD12\'d\r
+ card_state <= CARD_TRAN;\r
+ phy_data_in_stop <= 0;\r
+ phy_data_out_stop <= 0;\r
+ phy_data_in_another <= 0;\r
+ data_op_recv_block <= 0;\r
+ data_state <= DST_IDLE;\r
+ end else begin\r
+ // more blocks to go\r
+ card_state <= CARD_RCV;\r
+ card_status[STAT_READY_FOR_DATA] <= 1\'b1;\r
+ block_write_addr <= block_write_addr + 1\'b1; \r
+ block_write_num <= block_write_num - 1\'b1; \r
+ if(block_write_addr >= SD_TOTAL_BLOCKS) begin \r
+ card_status[STAT_OUT_OF_RANGE] <= 1\'b1; \r
+ err_op_out_range <= 1; \r
+ end\r
+ data_state <= DST_DATA_IN_0;\r
+ end\r
+ end\r
+ endcase\r
+ \r
+ if(~reset_s) begin\r
+ state <= ST_RESET;\r
+ data_state <= DST_RESET;\r
+ end \r
+end\r
+\r
+\r
+endmodule\r
+"
+"/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//
+// Computes the ECC for an 32-bit data stream based on the data and address of
+// data in the stream.
+//
+// data_i - 32-bit input data
+// addr_i - address of data in stream
+// ecc_o - 24-bit ecc value for the current 8-bit value
+//
+module hamm_4096x1_1x32 (
+ input wire [31:0] data_i,
+ input wire [6:0] addr_i,
+ output wire [23:0] ecc_o
+);
+
+wire [31:0] d = data_i;
+
+// compute xor of all bits in data_i
+wire [7:0] data_xor = ^d;
+
+// calculate even bits for bit addresses then byte addresses
+assign ecc_o[0] = d[0] ^ d[2] ^ d[4] ^ d[6] ^ d[8] ^ d[10] ^ d[12] ^ d[14] ^ d[16] ^ d[18] ^ d[20] ^ d[22] ^ d[24] ^ d[26] ^ d[28] ^ d[30];
+assign ecc_o[1] = d[0] ^ d[1] ^ d[4] ^ d[5] ^ d[8] ^ d[9] ^ d[12] ^ d[13] ^ d[16] ^ d[17] ^ d[20] ^ d[21] ^ d[24] ^ d[25] ^ d[28] ^ d[29];
+assign ecc_o[2] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[8] ^ d[9] ^ d[10] ^ d[11] ^ d[16] ^ d[17] ^ d[18] ^ d[19] ^ d[24] ^ d[25] ^ d[26] ^ d[27];
+assign ecc_o[3] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[6] ^ d[7] ^ d[16] ^ d[17] ^ d[18] ^ d[19] ^ d[20] ^ d[21] ^ d[22] ^ d[23];
+assign ecc_o[4] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[6] ^ d[7] ^ d[8] ^ d[9] ^ d[10] ^ d[11] ^ d[12] ^ d[13] ^ d[14] ^ d[15];
+assign ecc_o[5] = ~addr_i[0] & data_xor;
+assign ecc_o[6] = ~addr_i[1] & data_xor;
+assign ecc_o[7] = ~addr_i[2] & data_xor;
+assign ecc_o[8] = ~addr_i[3] & data_xor;
+assign ecc_o[9] = ~addr_i[4] & data_xor;
+assign ecc_o[10] = ~addr_i[5] & data_xor;
+assign ecc_o[11] = ~addr_i[6] & data_xor;
+
+// calculate odd bits for bit addresses then byte addresses
+assign ecc_o[12+0] = d[1] ^ d[3] ^ d[5] ^ d[7] ^ d[9] ^ d[11] ^ d[13] ^ d[15] ^ d[17] ^ d[19] ^ d[21] ^ d[23] ^ d[25] ^ d[27] ^ d[29] ^ d[31];
+assign ecc_o[12+1] = d[2] ^ d[3] ^ d[6] ^ d[7] ^ d[10] ^ d[11] ^ d[14] ^ d[15] ^ d[18] ^ d[19] ^ d[22] ^ d[23] ^ d[26] ^ d[27] ^ d[30] ^ d[31];
+assign ecc_o[12+2] = d[4] ^ d[5] ^ d[6] ^ d[7] ^ d[12] ^ d[13] ^ d[14] ^ d[15] ^ d[20] ^ d[21] ^ d[22] ^ d[23] ^ d[28] ^ d[29] ^ d[30] ^ d[31];
+assign ecc_o[12+3] = d[8] ^ d[9] ^ d[10] ^ d[11] ^ d[12] ^ d[13] ^ d[14] ^ d[15] ^ d[24] ^ d[25] ^ d[26] ^ d[27] ^ d[28] ^ d[29] ^ d[30] ^ d[31];
+assign ecc_o[12+4] = d[16] ^ d[17] ^ d[18] ^ d[19] ^ d[20] ^ d[21] ^ d[22] ^ d[23] ^ d[24] ^ d[25] ^ d[26] ^ d[27] ^ d[28] ^ d[29] ^ d[30] ^ d[31];
+assign ecc_o[12+5] = addr_i[0] & data_xor;
+assign ecc_o[12+6] = addr_i[1] & data_xor;
+assign ecc_o[12+7] = addr_i[2] & data_xor;
+assign ecc_o[12+8] = addr_i[3] & data_xor;
+assign ecc_o[12+9] = addr_i[4] & data_xor;
+assign ecc_o[12+10] = addr_i[5] & data_xor;
+assign ecc_o[12+11] = addr_i[6] & data_xor;
+
+endmodule
+
+
+//
+// Performs hamming calculations on up to 4096 bits (512 bytes) and computes a
+// 24-bit hamming ECC
+//
+// clk, rst -
+// standard clocking and reset signals
+// data_i, valid_i, sof_i, eof_i -
+// 8-bit input data bus on its way to/from the flash device
+// data_o, valid_o, sof_o, eof_o, ecc_o -
+// 8-bit output data bus and ecc on its way to/from the flash device
+// pipelined one clock cycle after input
+//
+module hamm_4096x1_512x32 (
+ input wire clk,
+ input wire rst,
+
+ input wire [31:0] data_i,
+ input wire valid_i,
+ input wire sof_i,
+ input wire eof_i,
+
+ output wire [31:0] data_o,
+ output wire valid_o,
+ output wire sof_o,
+ output wire eof_o,
+ output wire [23:0] ecc_o
+);
+
+// register all inputs to ease timing
+reg [31:0] data_r;
+reg valid_r;
+reg sof_r;
+reg eof_r;
+always @(posedge clk) begin
+ data_r <= data_i;
+ valid_r <= valid_i;
+ sof_r <= sof_i;
+ eof_r <= eof_i;
+end
+
+reg [6:0] addr_r;
+wire [23:0] byte_ecc;
+hamm_4096x1_1x32 hamm_4096x1_1x32 (
+ .data_i ( data_r ),
+ .addr_i ( addr_r ),
+ .ecc_o ( byte_ecc )
+);
+
+reg [23:0] ecc_r;
+always @(posedge clk) begin
+ // sync reset all registers to 0
+ if(rst) begin
+ addr_r <= 0;
+ ecc_r <= 0;
+ end else begin
+ if(valid_r) begin
+ // clear ecc when sof_i is asserted
+ if(sof_r) begin
+ // computed for addr_r == 0
+ ecc_r <= byte_ecc;
+ addr_r <= 1;
+ // otherwise keep computing ecc
+ end else begin
+ // computed for addr_r++
+ ecc_r <= ecc_r ^ byte_ecc;
+ // reset addr_r on eof
+ addr_r <= eof_r ? 0 : addr_r + 1;
+ end
+ end
+ end
+end
+
+// output data_o one clock cycle after data_i
+assign data_o = data_r;
+assign valid_o = valid_r;
+assign sof_o = sof_r;
+assign eof_o = eof_r;
+
+// ecc_o is output when eof_o is high
+assign ecc_o = eof_r ? ecc_r ^ byte_ecc : 0;
+
+endmodule
+"
+"/*\r
+ Copyright 2015, Google Inc.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the ""License"");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an ""AS IS"" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+module sd_top (\r
+ // clocking/reset\r
+ input wire clk_50,\r
+ input wire clk_100,\r
+ input wire clk_200,\r
+ input wire reset_n,\r
+\r
+ // physical interface to SD pins\r
+ input wire sd_clk,\r
+ input wire sd_cmd_i,\r
+ output wire sd_cmd_o,\r
+ output wire sd_cmd_t,\r
+ input wire [3:0] sd_dat_i,\r
+ output wire [3:0] sd_dat_o,\r
+ output wire [3:0] sd_dat_t,\r
+\r
+ // wishbone interface\r
+ output wire wbm_clk_o,\r
+ output wire [31:0] wbm_adr_o,\r
+ input wire [31:0] wbm_dat_i,\r
+ output wire [31:0] wbm_dat_o,\r
+ output wire [3:0] wbm_sel_o,\r
+ output wire wbm_cyc_o,\r
+ output wire wbm_stb_o,\r
+ output wire wbm_we_o,\r
+ input wire wbm_ack_i,\r
+ output wire [2:0] wbm_cti_o,\r
+ output wire [1:0] wbm_bte_o,\r
+\r
+ // options\r
+ input wire opt_enable_hs\r
+\r
+ // debug (optional)\r
+);\r
+\r
+wire bram_rd_ext_clk;\r
+wire [6:0] bram_rd_ext_addr;\r
+wire bram_rd_ext_wren;\r
+wire [31:0] bram_rd_ext_data;\r
+wire [31:0] bram_rd_ext_q;\r
+\r
+wire bram_wr_ext_clk;\r
+wire [6:0] bram_wr_ext_addr;\r
+wire bram_wr_ext_wren;\r
+wire [31:0] bram_wr_ext_data;\r
+wire [31:0] bram_wr_ext_q;\r
+\r
+wire ext_read_act;\r
+wire ext_read_go;\r
+wire [31:0] ext_read_addr;\r
+wire ext_read_stop;\r
+\r
+wire ext_write_act;\r
+wire ext_write_done;\r
+wire [31:0] ext_write_addr;\r
+\r
+ \r
+sd_wishbone isdw (\r
+ .clk_50 ( clk_50 ),\r
+ .reset_n ( reset_n ),\r
+ \r
+ .ext_read_act ( ext_read_act ),\r
+ .ext_read_go ( ext_read_go ),\r
+ .ext_read_addr ( ext_read_addr ),\r
+ .ext_read_stop ( ext_read_stop ),\r
+ \r
+ .ext_write_act ( ext_write_act ),\r
+ .ext_write_done ( ext_write_done ),\r
+ .ext_write_addr ( ext_write_addr ),\r
+ \r
+ .bram_rd_ext_clk ( bram_rd_ext_clk ),\r
+ .bram_rd_ext_addr ( bram_rd_ext_addr ),\r
+ .bram_rd_ext_wren ( bram_rd_ext_wren ),\r
+ .bram_rd_ext_data ( bram_rd_ext_data ),\r
+ .bram_rd_ext_q ( bram_rd_ext_q ),\r
+ \r
+ .bram_wr_ext_clk ( bram_wr_ext_clk ),\r
+ .bram_wr_ext_addr ( bram_wr_ext_addr ),\r
+ .bram_wr_ext_wren ( bram_wr_ext_wren ),\r
+ .bram_wr_ext_data ( bram_wr_ext_data ),\r
+ .bram_wr_ext_q ( bram_wr_ext_q ),\r
+\r
+ .wbm_clk_o ( wbm_clk_o ),\r
+ .wbm_adr_o ( wbm_adr_o ),\r
+ .wbm_dat_i ( wbm_dat_i ),\r
+ .wbm_dat_o ( wbm_dat_o ),\r
+ .wbm_sel_o ( wbm_sel_o ),\r
+ .wbm_cyc_o ( wbm_cyc_o ),\r
+ .wbm_stb_o ( wbm_stb_o ),\r
+ .wbm_we_o ( wbm_we_o ),\r
+ .wbm_ack_i ( wbm_ack_i ),\r
+ .wbm_cti_o ( wbm_cti_o ),\r
+ .wbm_bte_o ( wbm_bte_o )\r
+);\r
+ \r
+wire bram_rd_sd_clk;\r
+wire [6:0] bram_rd_sd_addr;\r
+wire bram_rd_sd_wren;\r
+wire [31:0] bram_rd_sd_data;\r
+wire [31:0] bram_rd_sd_q;\r
+ \r
+wire bram_wr_sd_clk;\r
+wire [6:0] bram_wr_sd_addr;\r
+wire bram_wr_sd_wren;\r
+wire [31:0] bram_wr_sd_data;\r
+wire [31:0] bram_wr_sd_q;\r
+\r
+wire link_read_act;\r
+wire link_read_go;\r
+wire [31:0] link_read_addr;\r
+wire [31:0] link_read_num;\r
+wire link_read_stop;\r
+ \r
+wire link_write_act;\r
+wire link_write_done;\r
+wire [31:0] link_write_addr;\r
+wire [31:0] link_write_num;\r
+\r
+(* mark_debug = ""true"" *) wire [47:0] phy_cmd_in;\r
+(* mark_debug = ""true"" *) wire phy_cmd_in_crc_good;\r
+(* mark_debug = ""true"" *) wire phy_cmd_in_act;\r
+(* mark_debug = ""true"" *) wire [3:0] phy_resp_type;\r
+(* mark_debug = ""true"" *) wire phy_resp_act;\r
+(* mark_debug = ""true"" *) wire phy_resp_done;\r
+(* mark_debug = ""true"" *) wire [3:0] link_card_state;\r
+(* mark_debug = ""true"" *) wire [10:0] odc;\r
+(* mark_debug = ""true"" *) wire [6:0] ostate;\r
+(* mark_debug = ""true"" *) wire [5:0] cmd_in_cmd;\r
+ \r
+wire phy_data_in_act;\r
+wire phy_data_in_busy;\r
+wire phy_data_in_another;\r
+wire phy_data_in_stop;\r
+wire phy_data_in_done;\r
+wire phy_data_in_crc_good;\r
+ \r
+wire [135:0] phy_resp_out;\r
+wire phy_resp_busy;\r
+wire phy_mode_4bit;\r
+wire [511:0] phy_data_out_reg;\r
+wire phy_data_out_src;\r
+wire [9:0] phy_data_out_len;\r
+wire phy_data_out_busy;\r
+wire phy_data_out_act;\r
+wire phy_data_out_stop;\r
+wire phy_data_out_done;\r
+\r
+sd_mgr isdm (\r
+ .clk_50 ( clk_50 ),\r
+ .reset_n ( reset_n ),\r
+ \r
+ .bram_rd_sd_clk ( bram_rd_sd_clk ),\r
+ .bram_rd_sd_addr ( bram_rd_sd_addr ),\r
+ .bram_rd_sd_wren ( bram_rd_sd_wren ),\r
+ .bram_rd_sd_data ( bram_rd_sd_data ),\r
+ .bram_rd_sd_q ( bram_rd_sd_q ),\r
+ \r
+ .bram_rd_ext_clk ( bram_rd_ext_clk ),\r
+ .bram_rd_ext_addr ( bram_rd_ext_addr ),\r
+ .bram_rd_ext_wren ( bram_rd_ext_wren ),\r
+ .bram_rd_ext_data ( bram_rd_ext_data ),\r
+ .bram_rd_ext_q ( bram_rd_ext_q ),\r
+ \r
+ .bram_wr_sd_clk ( bram_wr_sd_clk ),\r
+ .bram_wr_sd_addr ( bram_wr_sd_addr ),\r
+ .bram_wr_sd_wren ( bram_wr_sd_wren ),\r
+ .bram_wr_sd_data ( bram_wr_sd_data ),\r
+ .bram_wr_sd_q ( bram_wr_sd_q ),\r
+ \r
+ .bram_wr_ext_clk ( bram_wr_ext_clk ),\r
+ .bram_wr_ext_addr ( bram_wr_ext_addr ),\r
+ .bram_wr_ext_wren ( bram_wr_ext_wren ),\r
+ .bram_wr_ext_data ( bram_wr_ext_data ),\r
+ .bram_wr_ext_q ( bram_wr_ext_q ),\r
+ \r
+ .link_read_act ( link_read_act ),\r
+ .link_read_go ( link_read_go ),\r
+ .link_read_addr ( link_read_addr ),\r
+ .link_read_num ( link_read_num ),\r
+ .link_read_stop ( link_read_stop ),\r
+ \r
+ .link_write_act ( link_write_act ),\r
+ .link_write_done ( link_write_done ),\r
+ .link_write_addr ( link_write_addr ),\r
+ .link_write_num ( link_write_num ),\r
+ \r
+ .ext_read_act ( ext_read_act ),\r
+ .ext_read_go ( ext_read_go ),\r
+ .ext_read_addr ( ext_read_addr ),\r
+ .ext_read_num ( ),\r
+ .ext_read_stop ( ext_read_stop ),\r
+ \r
+ .ext_write_act ( ext_write_act ),\r
+ .ext_write_done ( ext_write_done ),\r
+ .ext_write_addr ( ext_write_addr ),\r
+ .ext_write_num ( )\r
+);\r
+\r
+\r
+sd_link isdl (\r
+ .clk_50 ( clk_50 ),\r
+ .reset_n ( reset_n ),\r
+\r
+ .link_card_state ( link_card_state ),\r
+ \r
+ .phy_cmd_in ( phy_cmd_in ),\r
+ .phy_cmd_in_crc_good ( phy_cmd_in_crc_good ),\r
+ .phy_cmd_in_act ( phy_cmd_in_act ),\r
+ .phy_data_in_act ( phy_data_in_act ),\r
+ .phy_data_in_busy ( phy_data_in_busy ),\r
+ .phy_data_in_another ( phy_data_in_another ),\r
+ .phy_data_in_stop ( phy_data_in_stop ),\r
+ .phy_data_in_done ( phy_data_in_done),\r
+ .phy_data_in_crc_good ( phy_data_in_crc_good ),\r
+ \r
+ .phy_resp_out ( phy_resp_out ),\r
+ .phy_resp_type ( phy_resp_type ),\r
+ .phy_resp_busy ( phy_resp_busy ),\r
+ .phy_resp_act ( phy_resp_act ),\r
+ .phy_resp_done ( phy_resp_done ),\r
+ .phy_mode_4bit ( phy_mode_4bit ),\r
+ .phy_data_out_reg ( phy_data_out_reg ),\r
+ .phy_data_out_src ( phy_data_out_src ),\r
+ .phy_data_out_len ( phy_data_out_len ),\r
+ .phy_data_out_busy ( phy_data_out_busy ),\r
+ .phy_data_out_act ( phy_data_out_act ),\r
+ .phy_data_out_stop ( phy_data_out_stop ),\r
+ .phy_data_out_done ( phy_data_out_done ),\r
+ \r
+ .block_read_act ( link_read_act ),\r
+ .block_read_go ( link_read_go ),\r
+ .block_read_addr ( link_read_addr ),\r
+ .block_read_num ( link_read_num ),\r
+ .block_read_stop ( link_read_stop ),\r
+ \r
+ .block_write_act ( link_write_act ),\r
+ .block_write_done ( link_write_done ),\r
+ .block_write_addr ( link_write_addr ),\r
+ .block_write_num ( link_write_num ),\r
+ \r
+ .opt_enable_hs ( opt_enable_hs )\r
+\r
+ /* DEBUG SIGNALS */,\r
+ .cmd_in_cmd ( cmd_in_cmd )\r
+);\r
+ \r
+sd_phy isdph (\r
+ .clk_50 ( clk_50 ),\r
+ .reset_n ( reset_n ),\r
+ .sd_clk ( sd_clk ),\r
+ .sd_cmd_i ( sd_cmd_i ),\r
+ .sd_cmd_o ( sd_cmd_o ),\r
+ .sd_cmd_t ( sd_cmd_t ),\r
+ .sd_dat_i ( sd_dat_i ),\r
+ .sd_dat_o ( sd_dat_o ),\r
+ .sd_dat_t ( sd_dat_t ),\r
+ \r
+ .card_state ( link_card_state ),\r
+ .cmd_in ( phy_cmd_in ),\r
+ .cmd_in_crc_good ( phy_cmd_in_crc_good ),\r
+ .cmd_in_act ( phy_cmd_in_act ),\r
+ .data_in_act ( phy_data_in_act ),\r
+ .data_in_busy ( phy_data_in_busy ),\r
+ .data_in_stop ( phy_data_in_stop ),\r
+ .data_in_another ( phy_data_in_another ),\r
+ .data_in_done ( phy_data_in_done),\r
+ .data_in_crc_good ( phy_data_in_crc_good ),\r
+\r
+ .resp_out ( phy_resp_out ),\r
+ .resp_type ( phy_resp_type ),\r
+ .resp_busy ( phy_resp_busy ),\r
+ .resp_act ( phy_resp_act ),\r
+ .resp_done ( phy_resp_done ),\r
+ .mode_4bit ( phy_mode_4bit ),\r
+ .data_out_reg ( phy_data_out_reg ),\r
+ .data_out_src ( phy_data_out_src ),\r
+ .data_out_len ( phy_data_out_len ),\r
+ .data_out_busy ( phy_data_out_busy ),\r
+ .data_out_act ( phy_data_out_act ),\r
+ .data_out_stop ( phy_data_out_stop ),\r
+ .data_out_done ( phy_data_out_done ),\r
+\r
+ .bram_rd_sd_clk ( bram_rd_sd_clk ),\r
+ .bram_rd_sd_addr ( bram_rd_sd_addr ),\r
+ .bram_rd_sd_wren ( bram_rd_sd_wren ),\r
+ .bram_rd_sd_data ( bram_rd_sd_data ),\r
+ .bram_rd_sd_q ( bram_rd_sd_q ),\r
+ \r
+ .bram_wr_sd_clk ( bram_wr_sd_clk ),\r
+ .bram_wr_sd_addr ( bram_wr_sd_addr ),\r
+ .bram_wr_sd_wren ( bram_wr_sd_wren ),\r
+ .bram_wr_sd_data ( bram_wr_sd_data ),\r
+ .bram_wr_sd_q ( bram_wr_sd_q )\r
+\r
+ /* DEBUG SIGNALS */, \r
+ .odc ( odc ),\r
+ .ostate ( ostate )\r
+);\r
+\r
+/*\r
+ * ILA Debug\r
+ */\r
+/*\r
+(* mark_debug = ""true"" *) reg sd_clk_reg, sd_cmd_reg;\r
+(* mark_debug = ""true"" *) reg [3:0] sd_dat_reg;\r
+(* mark_debug = ""true"" *) reg wb_clk_reg;\r
+(* mark_debug = ""true"" *) reg [31:0] wb_adr_reg;\r
+(* mark_debug = ""true"" *) reg [31:0] wb_dat_i_reg;\r
+(* mark_debug = ""true"" *) reg [31:0] wb_dat_o_reg;\r
+(* mark_debug = ""true"" *) reg [3:0] wb_sel_reg;\r
+(* mark_debug = ""true"" *) reg wb_cyc_reg;\r
+(* mark_debug = ""true"" *) reg wb_stb_reg;\r
+(* mark_debug = ""true"" *) reg wb_we_reg;\r
+(* mark_debug = ""true"" *) reg wb_ack_reg;\r
+\r
+always @(posedge clk_50) begin\r
+ sd_clk_reg <= sd_clk;\r
+ sd_cmd_reg <= sd_cmd_i;\r
+ sd_dat_reg <= sd_dat_i;\r
+end\r
+\r
+always @(posedge wbm_clk_o) begin\r
+ wb_adr_reg <= wbm_adr_o;\r
+ wb_dat_i_reg <= wbm_dat_i;\r
+ wb_dat_o_reg <= wbm_dat_o;\r
+ wb_sel_reg <= wbm_sel_o;\r
+ wb_cyc_reg <= wbm_cyc_o;\r
+ wb_stb_reg <= wbm_stb_o;\r
+ wb_we_reg <= wbm_we_o;\r
+ wb_ack_reg <= wbm_ack_i;\r
+end\r
+\r
+ila_0 ila_0 (\r
+ .clk ( wbm_clk_o ),\r
+ .probe0 ( {wb_adr_reg,\r
+ wb_dat_i_reg,\r
+ wb_dat_o_reg,\r
+ wb_sel_reg,\r
+ wb_cyc_reg,\r
+ wb_stb_reg,\r
+ wb_we_reg,\r
+ wb_ack_reg,\r
+ link_card_state,\r
+ phy_resp_type,\r
+ odc,\r
+ ostate,\r
+ phy_resp_done,\r
+ phy_resp_act,\r
+ phy_cmd_in_act,\r
+ cmd_in_cmd,\r
+ phy_cmd_in,\r
+ phy_cmd_in_crc_good,\r
+ sd_dat_reg,\r
+ sd_cmd_reg,\r
+ sd_clk_reg} )\r
+);\r
+*/\r
+\r
+endmodule\r
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 14:37:57 05/13/2014
+// Design Name:
+// Module Name: aes_core
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module aes_core (
+\tinput clk,
+\tinput load_i,
+\tinput [255:0] key_i,
+\tinput [127:0] data_i,
+\tinput [1:0] size_i,
+\tinput dec_i,
+\toutput reg [127:0] data_o,
+\toutput reg busy_o
+);
+
+localparam AES_128 = 0;
+localparam AES_192 = 1;
+localparam AES_256 = 2;
+
+localparam AES_KEYSCHED = 0;
+localparam AES_DECRYPT = 1;
+
+//(* max_fanout = ""1024"" *)
+reg dec_r;
+reg [1:0] fsm, fsm_new;
+
+reg [3:0] round, round_new, round_max;
+wire [3:0] round_inc = round + 1;
+wire [3:0] round_dec = round - 1;
+reg [127:0] state, state_new;
+reg [127:0] sbb_i;
+wire [127:0] sbb_o;
+
+reg [127:0] ks_mem[14:0];
+reg [127:0] ks;
+wire [127:0] ks_val;
+wire ks_en = (fsm == AES_KEYSCHED);
+
+aes_ks ks_inst (
+\t.clk(clk),
+\t.load_i(load_i),
+\t.en_i(ks_en),
+\t.size_i(size_i),
+\t.key_i(key_i),
+\t.ks_o(ks_val)
+);
+
+always @(posedge clk)
+begin
+\tif(load_i)
+\tbegin
+\t\tcase(size_i)
+\t\tAES_128: round_max <= 10;
+\t\tAES_192: round_max <= 12;
+\t\tdefault: round_max <= 14;
+\t\tendcase
+\tend
+end
+
+aes_sbox sbox_inst00(.U(sbb_i[ 7: 0]), .dec(dec_r), .S(sbb_o[ 7: 0]));
+aes_sbox sbox_inst01(.U(sbb_i[ 15: 8]), .dec(dec_r), .S(sbb_o[ 15: 8]));
+aes_sbox sbox_inst02(.U(sbb_i[ 23: 16]), .dec(dec_r), .S(sbb_o[ 23: 16]));
+aes_sbox sbox_inst03(.U(sbb_i[ 31: 24]), .dec(dec_r), .S(sbb_o[ 31: 24]));
+aes_sbox sbox_inst04(.U(sbb_i[ 39: 32]), .dec(dec_r), .S(sbb_o[ 39: 32]));
+aes_sbox sbox_inst05(.U(sbb_i[ 47: 40]), .dec(dec_r), .S(sbb_o[ 47: 40]));
+aes_sbox sbox_inst06(.U(sbb_i[ 55: 48]), .dec(dec_r), .S(sbb_o[ 55: 48]));
+aes_sbox sbox_inst07(.U(sbb_i[ 63: 56]), .dec(dec_r), .S(sbb_o[ 63: 56]));
+aes_sbox sbox_inst08(.U(sbb_i[ 71: 64]), .dec(dec_r), .S(sbb_o[ 71: 64]));
+aes_sbox sbox_inst09(.U(sbb_i[ 79: 72]), .dec(dec_r), .S(sbb_o[ 79: 72]));
+aes_sbox sbox_inst10(.U(sbb_i[ 87: 80]), .dec(dec_r), .S(sbb_o[ 87: 80]));
+aes_sbox sbox_inst11(.U(sbb_i[ 95: 88]), .dec(dec_r), .S(sbb_o[ 95: 88]));
+aes_sbox sbox_inst12(.U(sbb_i[103: 96]), .dec(dec_r), .S(sbb_o[103: 96]));
+aes_sbox sbox_inst13(.U(sbb_i[111:104]), .dec(dec_r), .S(sbb_o[111:104]));
+aes_sbox sbox_inst14(.U(sbb_i[119:112]), .dec(dec_r), .S(sbb_o[119:112]));
+aes_sbox sbox_inst15(.U(sbb_i[127:120]), .dec(dec_r), .S(sbb_o[127:120]));
+
+always @*
+begin : subbytes_pre
+\tif(dec_r)
+\tbegin\t\t
+\t\t//InvShiftRows(state);
+\t\tsbb_i = {
+\t\t\tstate[127:120], state[ 23: 16], state[ 47: 40], state[ 71: 64],
+\t\t\tstate[ 95: 88], state[119:112], state[ 15: 8], state[ 39: 32],
+\t\t\tstate[ 63: 56], state[ 87: 80], state[111:104], state[ 7: 0],
+\t\t\tstate[ 31: 24], state[ 55: 48], state[ 79: 72], state[103: 96]
+\t\t};
+\tend
+\telse
+\tbegin
+\t\tsbb_i = state;
+\tend
+end
+
+function [7:0] xtime;
+\tinput [7:0] b; xtime={b[6:0],1\'b0} ^ (8\'h1b & {8{b[7]}});
+endfunction
+
+function [7:0] x02;
+\tinput [7:0] b; x02={b[6:0],1\'b0} ^ (8\'h1b & {8{b[7]}});
+endfunction
+
+function [7:0] x03;
+\tinput [7:0] b; x03=x02(b)^b;
+endfunction
+
+function [7:0] x04;
+\tinput [7:0] b; x04=x02(x02(b));
+endfunction
+
+function [7:0] x08;
+\tinput [7:0] b; x08=x02(x04(b));
+endfunction
+
+function [7:0] x09;
+\tinput [7:0] b; x09=x08(b)^b;
+endfunction
+
+function [7:0] x11;
+\tinput [7:0] b; x11=x08(b)^x02(b)^b;
+endfunction
+
+function [7:0] x13;
+\tinput [7:0] b; x13=x08(b)^x04(b)^b;
+endfunction
+
+function [7:0] x14;
+\tinput [7:0] b; x14=x08(b)^x04(b)^x02(b);
+endfunction
+\t
+always @*
+begin : subbytes_pst
+\tif(dec_r)
+\tbegin : subbytes_pst_decrypt
+\t\treg [127:0] ark_i, ark_o, mxc_o;
+\t\t
+\t\t// AddRoundKey(state, &ctx->ks[round * Nb]);
+\t\tif(round == round_max)
+\t\t\tark_i = state;
+\t\telse
+\t\t\tark_i = sbb_o;
+\t\tark_o = ark_i ^ ks;
+\t\t
+\t\t// InvMixColumns(state);
+\t\tmxc_o = {
+\t\t\tx14(ark_o[127:120]) ^ x11(ark_o[119:112]) ^ x13(ark_o[111:104]) ^ x09(ark_o[103: 96]),
+\t\t\tx09(ark_o[127:120]) ^ x14(ark_o[119:112]) ^ x11(ark_o[111:104]) ^ x13(ark_o[103: 96]),
+\t\t\tx13(ark_o[127:120]) ^ x09(ark_o[119:112]) ^ x14(ark_o[111:104]) ^ x11(ark_o[103: 96]),
+\t\t\tx11(ark_o[127:120]) ^ x13(ark_o[119:112]) ^ x09(ark_o[111:104]) ^ x14(ark_o[103: 96]),
+\t\t\t
+\t\t\tx14(ark_o[ 95: 88]) ^ x11(ark_o[ 87: 80]) ^ x13(ark_o[ 79: 72]) ^ x09(ark_o[ 71: 64]),
+\t\t\tx09(ark_o[ 95: 88]) ^ x14(ark_o[ 87: 80]) ^ x11(ark_o[ 79: 72]) ^ x13(ark_o[ 71: 64]),
+\t\t\tx13(ark_o[ 95: 88]) ^ x09(ark_o[ 87: 80]) ^ x14(ark_o[ 79: 72]) ^ x11(ark_o[ 71: 64]),
+\t\t\tx11(ark_o[ 95: 88]) ^ x13(ark_o[ 87: 80]) ^ x09(ark_o[ 79: 72]) ^ x14(ark_o[ 71: 64]),
+\t\t\t
+\t\t\tx14(ark_o[ 63: 56]) ^ x11(ark_o[ 55: 48]) ^ x13(ark_o[ 47: 40]) ^ x09(ark_o[ 39: 32]),
+\t\t\tx09(ark_o[ 63: 56]) ^ x14(ark_o[ 55: 48]) ^ x11(ark_o[ 47: 40]) ^ x13(ark_o[ 39: 32]),
+\t\t\tx13(ark_o[ 63: 56]) ^ x09(ark_o[ 55: 48]) ^ x14(ark_o[ 47: 40]) ^ x11(ark_o[ 39: 32]),
+\t\t\tx11(ark_o[ 63: 56]) ^ x13(ark_o[ 55: 48]) ^ x09(ark_o[ 47: 40]) ^ x14(ark_o[ 39: 32]),
+\t\t\t
+\t\t\tx14(ark_o[ 31: 24]) ^ x11(ark_o[ 23: 16]) ^ x13(ark_o[ 15: 8]) ^ x09(ark_o[ 7: 0]),
+\t\t\tx09(ark_o[ 31: 24]) ^ x14(ark_o[ 23: 16]) ^ x11(ark_o[ 15: 8]) ^ x13(ark_o[ 7: 0]),
+\t\t\tx13(ark_o[ 31: 24]) ^ x09(ark_o[ 23: 16]) ^ x14(ark_o[ 15: 8]) ^ x11(ark_o[ 7: 0]),
+\t\t\tx11(ark_o[ 31: 24]) ^ x13(ark_o[ 23: 16]) ^ x09(ark_o[ 15: 8]) ^ x14(ark_o[ 7: 0])
+\t\t};
+\t\t
+\t\tif((round == round_max) || (round == 0))
+\t\t\tstate_new = ark_o;
+\t\telse
+\t\t\tstate_new = mxc_o;
+\tend
+\telse
+\tbegin : subbytes_pst_encrypt
+\t\treg [127:0] shr_o, mxc_o, ark_i;
+\t\treg [31:0] mxc_tmp;
+\t\t
+\t\t// ShiftRows(state);
+\t\tshr_o = {
+\t\t\tsbb_o[127:120], sbb_o[ 87: 80], sbb_o[ 47: 40], sbb_o[ 7: 0],
+\t\t\tsbb_o[ 95: 88], sbb_o[ 55: 48], sbb_o[ 15: 8], sbb_o[103: 96],
+\t\t\tsbb_o[ 63: 56], sbb_o[ 23: 16], sbb_o[111:104], sbb_o[ 71: 64],
+\t\t\tsbb_o[ 31: 24], sbb_o[119:112], sbb_o[ 79: 72], sbb_o[ 39: 32]
+\t\t};
+\t\t
+\t\t// MixColumns(state);
+\t\tmxc_tmp = {
+\t\t\tshr_o[127:120] ^ shr_o[119:112] ^ shr_o[111:104] ^ shr_o[103: 96],
+\t\t\tshr_o[ 95: 88] ^ shr_o[ 87: 80] ^ shr_o[ 79: 72] ^ shr_o[ 71: 64],
+\t\t\tshr_o[ 63: 56] ^ shr_o[ 55: 48] ^ shr_o[ 47: 40] ^ shr_o[ 39: 32],
+\t\t\tshr_o[ 31: 24] ^ shr_o[ 23: 16] ^ shr_o[ 15: 8] ^ shr_o[ 7: 0]
+\t\t};
+\t\tmxc_o = {
+\t\t\tshr_o[127:120] ^ xtime(shr_o[127:120] ^ shr_o[119:112]) ^ mxc_tmp[31:24],
+\t\t\tshr_o[119:112] ^ xtime(shr_o[119:112] ^ shr_o[111:104]) ^ mxc_tmp[31:24],
+\t\t\tshr_o[111:104] ^ xtime(shr_o[111:104] ^ shr_o[103: 96]) ^ mxc_tmp[31:24],
+\t\t\tshr_o[103: 96] ^ xtime(shr_o[103: 96] ^ shr_o[127:120]) ^ mxc_tmp[31:24],
+\t\t\t
+\t\t\tshr_o[ 95: 88] ^ xtime(shr_o[ 95: 88] ^ shr_o[ 87: 80]) ^ mxc_tmp[23:16],
+\t\t\tshr_o[ 87: 80] ^ xtime(shr_o[ 87: 80] ^ shr_o[ 79: 72]) ^ mxc_tmp[23:16],
+\t\t\tshr_o[ 79: 72] ^ xtime(shr_o[ 79: 72] ^ shr_o[ 71: 64]) ^ mxc_tmp[23:16],
+\t\t\tshr_o[ 71: 64] ^ xtime(shr_o[ 71: 64] ^ shr_o[ 95: 88]) ^ mxc_tmp[23:16],
+\t\t\t
+\t\t\tshr_o[ 63: 56] ^ xtime(shr_o[ 63: 56] ^ shr_o[ 55: 48]) ^ mxc_tmp[15: 8],
+\t\t\tshr_o[ 55: 48] ^ xtime(shr_o[ 55: 48] ^ shr_o[ 47: 40]) ^ mxc_tmp[15: 8],
+\t\t\tshr_o[ 47: 40] ^ xtime(shr_o[ 47: 40] ^ shr_o[ 39: 32]) ^ mxc_tmp[15: 8],
+\t\t\tshr_o[ 39: 32] ^ xtime(shr_o[ 39: 32] ^ shr_o[ 63: 56]) ^ mxc_tmp[15: 8],
+\t\t\t
+\t\t\tshr_o[ 31: 24] ^ xtime(shr_o[ 31: 24] ^ shr_o[ 23: 16]) ^ mxc_tmp[ 7: 0],
+\t\t\tshr_o[ 23: 16] ^ xtime(shr_o[ 23: 16] ^ shr_o[ 15: 8]) ^ mxc_tmp[ 7: 0],
+\t\t\tshr_o[ 15: 8] ^ xtime(shr_o[ 15: 8] ^ shr_o[ 7: 0]) ^ mxc_tmp[ 7: 0],
+\t\t\tshr_o[ 7: 0] ^ xtime(shr_o[ 7: 0] ^ shr_o[ 31: 24]) ^ mxc_tmp[ 7: 0]
+\t\t};
+\t\t
+\t\t// AddRoundKey(state, &ctx->ks[round * Nb]);
+\t\tif(round == 0)
+\t\t\tark_i = state;
+\t\telse if(round == round_max)
+\t\t\tark_i = shr_o;
+\t\telse
+\t\t\tark_i = mxc_o;
+\t\t\t
+\t\tstate_new = ark_i ^ ks_val;
+\tend
+end
+
+always @(posedge clk)
+begin
+\tbusy_o <= 0;
+\tif(load_i)
+\tbegin
+\t\tfsm <= AES_KEYSCHED;\t\t
+\t\tround <= 0;
+\t\tbusy_o <= 1;
+\t\tdata_o <= 0;
+\t\tdec_r <= dec_i;
+\t\tstate <= data_i;
+\tend
+\telse if(busy_o)
+\tbegin
+\t\tbusy_o <= 1;
+\t\tcase(fsm)
+\t\tAES_KEYSCHED:
+\t\tbegin
+\t\t\tround <= round_inc;
+\t\t\tif(dec_r)
+\t\t\tbegin
+\t\t\t\tks_mem[round] <= ks_val;
+\t\t\t\tks <= ks_val;
+\t\t\t\tif(round == round_max)
+\t\t\t\tbegin
+\t\t\t\t\tfsm <= AES_DECRYPT;
+\t\t\t\t\tround <= round_max;
+\t\t\t\tend
+\t\t\tend
+\t\t\telse
+\t\t\tbegin
+\t\t\t\tstate <= state_new;
+\t\t\t\tif(round == round_max)
+\t\t\t\tbegin
+\t\t\t\t\tdata_o <= state_new;
+\t\t\t\t\tbusy_o <= 0;
+\t\t\t\tend
+\t\t\tend
+\t\tend
+\t\tAES_DECRYPT:
+\t\tbegin
+\t\t\tks <= ks_mem[round_dec];
+\t\t\tround <= round_dec;
+\t\t\tstate <= state_new;
+\t\t\tif(round == 0)
+\t\t\tbegin
+\t\t\t\tdata_o <= state_new;
+\t\t\t\tbusy_o <= 0;
+\t\t\tend
+\t\tend
+\t\tendcase
+\tend
+end
+
+endmodule
+"
+"/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 13:14:48 11/12/2014
+// Design Name:
+// Module Name: orpsoc_top
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+//`define TAORP_DEBUG 1
+`include ""orpsoc-defines.v""
+
+module orpsoc_top(
+\tinput sys_clk_pad_i,
+\tinput rst_n_pad_i,
+\t// SDHC
+\tinput wire sd_clk,
+\tinout wire sd_cmd,
+\tinout wire [3:0] sd_dat,
+\t// UART
+\tinput\tuart0_srx_pad_i,
+\toutput uart0_stx_pad_o,
+\t//input uart0_cts_pad_i,
+\t//output uart0_rts_pad_o,
+\t// NAND
+\tinout [7:0] nand_io,
+\toutput nand_cle,
+\toutput nand_ale,
+\toutput nand_ce_n,
+\toutput nand_we_n,
+\toutput nand_re_n,
+\toutput nand_wp_n,
+\tinput nand_rb_n,
+\t// GPIO
+\tinout [6:0] gpio0_io
+\t);
+
+wire sys_rst;
+
+assign sys_rst = ~rst_n_pad_i;
+
+////////////////////////////////////////////////////////////////////////
+//
+// Clock and reset generation module
+//
+////////////////////////////////////////////////////////////////////////
+
+wire wb_clk, wb_clk2x, wb_rst;
+
+clkgen clkgen0(
+\t.sys_clk_i(sys_clk_pad_i),
+\t.sys_rst_i(sys_rst),
+\t.wb_clk_o(wb_clk),
+\t.wb_clk2x_o(wb_clk2x),
+\t.wb_rst_o(wb_rst)
+);
+
+////////////////////////////////////////////////////////////////////////
+//
+// Modules interconnections
+//
+////////////////////////////////////////////////////////////////////////
+
+`include ""wb_intercon.vh""
+
+////////////////////////////////////////////////////////////////////////
+//
+// ARTIX7 JTAG TAP
+//
+////////////////////////////////////////////////////////////////////////
+wire jtag_capture_o, jtag_drck_o, jtag_reset_o, jtag_runtest_o;
+wire jtag_sel_o, jtag_shift_o, jtag_tck_o, jtag_tdi_o, jtag_tms_o;
+wire jtag_update_o, jtag_tdo_i;
+
+wire jtag_tck_unbuf;
+
+wire jtag_pause_o;
+assign jtag_pause_o = 1\'b0;
+
+BSCANE2 #(
+\t.JTAG_CHAIN(1) // Value for USER command. Possible values: 1-4.
+)
+BSCANE2_inst (
+\t.CAPTURE(jtag_capture_o),
+\t// 1-bit output: CAPTURE output from TAP controller.
+\t.DRCK(jtag_drck_o),
+\t// 1-bit output: Gated TCK output. When SEL is asserted,
+\t// DRCK toggles when CAPTURE or SHIFT are asserted.
+\t.RESET(jtag_reset_o),
+\t// 1-bit output: Reset output for TAP controller.
+\t.RUNTEST(jtag_runtest_o),
+\t// 1-bit output: Output asserted when TAP controller is in Run Test/Idle state.
+\t.SEL(jtag_sel_o),
+\t// 1-bit output: USER instruction active output.
+\t.SHIFT(jtag_shift_o),
+\t// 1-bit output: SHIFT output from TAP controller.
+\t.TCK(jtag_tck_unbuf),
+\t// 1-bit output: Test Clock output. Fabric connection to TAP Clock pin.
+\t.TDI(jtag_tdi_o),
+\t// 1-bit output: Test Data Input (TDI) output from TAP controller.
+\t.TMS(jtag_tms_o),
+\t// 1-bit output: Test Mode Select output. Fabric connection to TAP.
+\t.UPDATE(jtag_update_o),
+\t//.UPDATE(update_bscan),
+\t// 1-bit output: UPDATE output from TAP controller
+\t.TDO(jtag_tdo_i)
+\t// 1-bit input: Test Data Output (TDO) input for USER function.
+);
+
+BUFG jtag_tck_bufg (
+\t.O(jtag_tck_o),
+\t.I(jtag_tck_unbuf)
+);
+
+////////////////////////////////////////////////////////////////////////
+//
+// OR1K CPU
+//
+////////////////////////////////////////////////////////////////////////
+
+`ifdef ORP_DEBUG
+localparam reset_pc = 32\'hf0000100;
+`else
+localparam reset_pc = 32\'h00100100;
+`endif
+
+`ifdef MOR1KX_CPU
+wire [31:0] or1k_irq;
+wire or1k_rst;
+
+wire [31:0] or1k_dbg_adr_i;
+wire [31:0] or1k_dbg_dat_i;
+wire\t or1k_dbg_stb_i;
+wire\t or1k_dbg_we_i;
+wire [31:0] or1k_dbg_dat_o;
+wire\t or1k_dbg_ack_o;
+wire\t or1k_dbg_stall_i;
+wire\t or1k_dbg_bp_o;
+
+mor1kx #(
+\t.FEATURE_DEBUGUNIT(""ENABLED""),
+\t.FEATURE_CMOV(""ENABLED""),
+\t.FEATURE_INSTRUCTIONCACHE(""ENABLED""),
+\t.OPTION_ICACHE_BLOCK_WIDTH(5),
+\t.OPTION_ICACHE_SET_WIDTH(8),
+\t.OPTION_ICACHE_WAYS(2),
+\t.OPTION_ICACHE_LIMIT_WIDTH(32),
+\t.FEATURE_IMMU(""ENABLED""),
+\t.FEATURE_DATACACHE(""ENABLED""),
+\t.OPTION_DCACHE_BLOCK_WIDTH(5),
+\t.OPTION_DCACHE_SET_WIDTH(8),
+\t.OPTION_DCACHE_WAYS(2),
+\t.OPTION_DCACHE_LIMIT_WIDTH(31),
+\t.FEATURE_DMMU(""ENABLED""),
+\t.OPTION_PIC_TRIGGER(""LATCHED_LEVEL""),
+
+\t.IBUS_WB_TYPE(""B3_REGISTERED_FEEDBACK""),
+\t.DBUS_WB_TYPE(""B3_REGISTERED_FEEDBACK""),
+\t.OPTION_CPU0(""CAPPUCCINO""),
+\t.OPTION_RESET_PC(reset_pc)
+) mor1kx0 (
+\t.iwbm_adr_o(wb_m2s_or1k_i_adr),
+\t.iwbm_stb_o(wb_m2s_or1k_i_stb),
+\t.iwbm_cyc_o(wb_m2s_or1k_i_cyc),
+\t.iwbm_sel_o(wb_m2s_or1k_i_sel),
+\t.iwbm_we_o (wb_m2s_or1k_i_we),
+\t.iwbm_cti_o(wb_m2s_or1k_i_cti),
+\t.iwbm_bte_o(wb_m2s_or1k_i_bte),
+\t.iwbm_dat_o(wb_m2s_or1k_i_dat),
+\t.dwbm_adr_o(wb_m2s_or1k_d_adr),
+\t.dwbm_stb_o(wb_m2s_or1k_d_stb),
+\t.dwbm_cyc_o(wb_m2s_or1k_d_cyc),
+\t.dwbm_sel_o(wb_m2s_or1k_d_sel),
+\t.dwbm_we_o (wb_m2s_or1k_d_we ),
+\t.dwbm_cti_o(wb_m2s_or1k_d_cti),
+\t.dwbm_bte_o(wb_m2s_or1k_d_bte),
+\t.dwbm_dat_o(wb_m2s_or1k_d_dat),
+
+\t.clk(wb_clk),
+\t.rst(wb_rst),
+
+\t.iwbm_err_i(wb_s2m_or1k_i_err),
+\t.iwbm_ack_i(wb_s2m_or1k_i_ack),
+\t.iwbm_dat_i(wb_s2m_or1k_i_dat),
+\t.iwbm_rty_i(wb_s2m_or1k_i_rty),
+
+\t.dwbm_err_i(wb_s2m_or1k_d_err),
+\t.dwbm_ack_i(wb_s2m_or1k_d_ack),
+\t.dwbm_dat_i(wb_s2m_or1k_d_dat),
+\t.dwbm_rty_i(wb_s2m_or1k_d_rty),
+
+\t.irq_i(or1k_irq),
+
+\t.du_addr_i(or1k_dbg_adr_i[15:0]),
+\t.du_stb_i(or1k_dbg_stb_i),
+\t.du_dat_i(or1k_dbg_dat_i),
+\t.du_we_i(or1k_dbg_we_i),
+\t.du_dat_o(or1k_dbg_dat_o),
+\t.du_ack_o(or1k_dbg_ack_o),
+\t.du_stall_i(or1k_dbg_stall_i),
+\t.du_stall_o(or1k_dbg_bp_o)
+);
+`endif // MOR1KX
+
+`ifdef OR1200_CPU
+wire [31:0] or1k_irq;
+
+wire [31:0] or1k_dbg_dat_i;
+wire [31:0] or1k_dbg_adr_i;
+wire or1k_dbg_we_i;
+wire or1k_dbg_stb_i;
+wire or1k_dbg_ack_o;
+wire [31:0] or1k_dbg_dat_o;
+
+wire or1k_dbg_stall_i;
+wire or1k_dbg_ewt_i;
+wire [3:0] or1k_dbg_lss_o;
+wire [1:0] or1k_dbg_is_o;
+wire [10:0] or1k_dbg_wp_o;
+wire or1k_dbg_bp_o;
+wire or1k_dbg_rst;
+
+wire or1k_rst;
+
+assign or1k_rst = wb_rst | or1k_dbg_rst;
+
+or1200_top #(
+\t.boot_adr(reset_pc)
+) or1200_top0(
+\t// Instruction bus, clocks, reset
+\t.iwb_clk_i(wb_clk),
+\t.iwb_rst_i(wb_rst),
+\t.iwb_ack_i(wb_s2m_or1k_i_ack),
+\t.iwb_err_i(wb_s2m_or1k_i_err),
+\t.iwb_rty_i(wb_s2m_or1k_i_rty),
+\t.iwb_dat_i(wb_s2m_or1k_i_dat),
+
+\t.iwb_cyc_o(wb_m2s_or1k_i_cyc),
+\t.iwb_adr_o(wb_m2s_or1k_i_adr),
+\t.iwb_stb_o(wb_m2s_or1k_i_stb),
+\t.iwb_we_o(wb_m2s_or1k_i_we),
+\t.iwb_sel_o(wb_m2s_or1k_i_sel),
+\t.iwb_dat_o(wb_m2s_or1k_i_dat),
+\t.iwb_cti_o(wb_m2s_or1k_i_cti),
+\t.iwb_bte_o(wb_m2s_or1k_i_bte),
+\t// Data bus, clocks, reset
+\t.dwb_clk_i(wb_clk),
+\t.dwb_rst_i(wb_rst),
+\t.dwb_ack_i(wb_s2m_or1k_d_ack),
+\t.dwb_err_i(wb_s2m_or1k_d_err),
+\t.dwb_rty_i(wb_s2m_or1k_d_rty),
+\t.dwb_dat_i(wb_s2m_or1k_d_dat),
+
+\t.dwb_cyc_o(wb_m2s_or1k_d_cyc),
+\t.dwb_adr_o(wb_m2s_or1k_d_adr),
+\t.dwb_stb_o(wb_m2s_or1k_d_stb),
+\t.dwb_we_o(wb_m2s_or1k_d_we),
+\t.dwb_sel_o(wb_m2s_or1k_d_sel),
+\t.dwb_dat_o(wb_m2s_or1k_d_dat),
+\t.dwb_cti_o(wb_m2s_or1k_d_cti),
+\t.dwb_bte_o(wb_m2s_or1k_d_bte),
+
+\t// Debug interface ports
+\t.dbg_stall_i(or1k_dbg_stall_i),
+\t.dbg_ewt_i(1\'b0),
+\t.dbg_lss_o(or1k_dbg_lss_o),
+\t.dbg_is_o(or1k_dbg_is_o),
+\t.dbg_wp_o(or1k_dbg_wp_o),
+\t.dbg_bp_o(or1k_dbg_bp_o),
+
+\t.dbg_adr_i(or1k_dbg_adr_i),
+\t.dbg_we_i(or1k_dbg_we_i),
+\t.dbg_stb_i(or1k_dbg_stb_i),
+\t.dbg_dat_i(or1k_dbg_dat_i),
+\t.dbg_dat_o(or1k_dbg_dat_o),
+\t.dbg_ack_o(or1k_dbg_ack_o),
+
+\t.pm_clksd_o(),
+\t.pm_dc_gate_o(),
+\t.pm_ic_gate_o(),
+\t.pm_dmmu_gate_o(),
+\t.pm_immu_gate_o(),
+\t.pm_tt_gate_o(),
+\t.pm_cpu_gate_o(),
+\t.pm_wakeup_o(),
+\t.pm_lvolt_o(),
+
+\t.clk_i(wb_clk),
+\t.rst_i(or1k_rst),
+
+\t.clmode_i(2\'b00),
+
+\t// Interrupts
+\t.pic_ints_i(or1k_irq),
+\t.sig_tick(),
+
+\t.pm_cpustall_i(1\'b0)
+);
+`endif // OR1200_CPU
+
+////////////////////////////////////////////////////////////////////////
+//
+// Debug Interface
+//
+////////////////////////////////////////////////////////////////////////
+
+adbg_top dbg_if0(
+\t// OR1K interface
+\t.cpu0_clk_i (wb_clk),
+\t.cpu0_rst_o (or1k_dbg_rst),
+\t.cpu0_addr_o (or1k_dbg_adr_i),
+\t.cpu0_data_o (or1k_dbg_dat_i),
+\t.cpu0_stb_o (or1k_dbg_stb_i),
+\t.cpu0_we_o (or1k_dbg_we_i),
+\t.cpu0_data_i (or1k_dbg_dat_o),
+\t.cpu0_ack_i (or1k_dbg_ack_o),
+\t.cpu0_stall_o (or1k_dbg_stall_i),
+\t.cpu0_bp_i (or1k_dbg_bp_o),
+
+\t// TAP interface
+\t.tck_i(jtag_tck_o),
+\t.tdi_i(jtag_tdi_o),
+\t.tdo_o(jtag_tdo_i),
+\t//.rst_i(wb_rst),
+\t.rst_i(jtag_reset_o),
+\t.capture_dr_i(jtag_capture_o),
+\t.shift_dr_i(jtag_shift_o),
+\t.pause_dr_i(jtag_pause_o),
+\t.update_dr_i(jtag_update_o),
+\t.debug_select_i(jtag_sel_o),
+
+\t// Wishbone debug master
+\t.wb_rst_i(wb_rst),
+\t.wb_clk_i(wb_clk),
+\t.wb_dat_i(wb_s2m_dbg_dat),
+\t.wb_ack_i(wb_s2m_dbg_ack),
+\t.wb_err_i(wb_s2m_dbg_err),
+
+\t.wb_adr_o(wb_m2s_dbg_adr),
+\t.wb_dat_o(wb_m2s_dbg_dat),
+\t.wb_cyc_o(wb_m2s_dbg_cyc),
+\t.wb_stb_o(wb_m2s_dbg_stb),
+\t.wb_sel_o(wb_m2s_dbg_sel),
+\t.wb_we_o(wb_m2s_dbg_we),
+\t.wb_cti_o(wb_m2s_dbg_cti),
+\t.wb_bte_o(wb_m2s_dbg_bte)
+);
+
+////////////////////////////////////////////////////////////////////////
+//
+// ROM
+//
+////////////////////////////////////////////////////////////////////////
+localparam ROM0_SIZE = (64 * 1024);
+
+`ifndef ORP_DEBUG
+
+wb_rom #(
+\t.depth(ROM0_SIZE),
+\t.memfile(""rom.dat"")
+) rom0 (
+\t.wb_clk(wb_clk),
+\t.wb_rst(wb_rst),
+\t.wb_adr_i(wb_m2s_rom0_adr),
+\t.wb_cyc_i(wb_m2s_rom0_cyc),
+\t.wb_stb_i(wb_m2s_rom0_stb),
+\t.wb_cti_i(wb_m2s_rom0_cti),
+\t.wb_bte_i(wb_m2s_rom0_bte),
+\t.wb_dat_o(wb_s2m_rom0_dat),
+\t.wb_ack_o(wb_s2m_rom0_ack),
+\t.wb_rty_o(wb_s2m_rom0_rty),
+\t.wb_err_o(wb_s2m_rom0_err)
+);
+
+`else
+
+wb_ram #(
+\t.depth(ROM0_SIZE)
+) rom0 (
+\t// Wishbone slave interface
+\t.wb_dat_i(wb_m2s_rom0_dat),
+\t.wb_adr_i(wb_m2s_rom0_adr[$clog2(ROM0_SIZE) - 1:0]),
+\t.wb_sel_i(wb_m2s_rom0_sel),
+\t.wb_cti_i(wb_m2s_rom0_cti),
+\t.wb_bte_i(wb_m2s_rom0_bte),
+\t.wb_we_i(wb_m2s_rom0_we),
+\t.wb_cyc_i(wb_m2s_rom0_cyc),
+\t.wb_stb_i(wb_m2s_rom0_stb),
+\t.wb_dat_o(wb_s2m_rom0_dat),
+\t.wb_ack_o(wb_s2m_rom0_ack),
+\t.wb_err_o(wb_s2m_rom0_err),
+\t// Clock, reset
+\t.wb_clk_i(wb_clk),
+\t.wb_rst_i(wb_rst)
+);
+
+assign wb_s2m_rom0_rty = 1\'b0;
+`endif
+
+////////////////////////////////////////////////////////////////////////
+//
+// RAM
+//
+////////////////////////////////////////////////////////////////////////
+localparam RAM0_SIZE = (128 * 1024);
+
+wb_ram #(
+\t.depth(RAM0_SIZE)
+) ram0 (
+\t// Wishbone slave interface
+\t.wb_dat_i(wb_m2s_ram0_dat),
+\t.wb_adr_i(wb_m2s_ram0_adr[$clog2(RAM0_SIZE) - 1:0]),
+\t.wb_sel_i(wb_m2s_ram0_sel),
+\t.wb_cti_i(wb_m2s_ram0_cti),
+\t.wb_bte_i(wb_m2s_ram0_bte),
+\t.wb_we_i(wb_m2s_ram0_we),
+\t.wb_cyc_i(wb_m2s_ram0_cyc),
+\t.wb_stb_i(wb_m2s_ram0_stb),
+\t.wb_dat_o(wb_s2m_ram0_dat),
+\t.wb_ack_o(wb_s2m_ram0_ack),
+\t.wb_err_o(wb_s2m_ram0_err),
+\t// Clock, reset
+\t.wb_clk_i(wb_clk),
+\t.wb_rst_i(wb_rst)
+);
+
+assign wb_s2m_ram0_rty = 1\'b0;
+
+////////////////////////////////////////////////////////////////////////
+//
+// UART0
+//
+////////////////////////////////////////////////////////////////////////
+
+parameter uart0_aw = 3;
+
+wire uart0_irq;
+
+assign wb_s2m_uart0_err = 0;
+assign wb_s2m_uart0_rty = 0;
+
+uart_top uart16550_0 (
+\t// Wishbone slave interface
+\t.wb_clk_i (wb_clk),
+\t.wb_rst_i (wb_rst),
+\t.wb_adr_i (wb_m2s_uart0_adr[uart0_aw-1:0]),
+\t.wb_dat_i (wb_m2s_uart0_dat),
+\t.wb_we_i\t(wb_m2s_uart0_we),
+\t.wb_stb_i (wb_m2s_uart0_stb),
+\t.wb_cyc_i (wb_m2s_uart0_cyc),
+\t.wb_sel_i (4\'b0), // Not used in 8-bit mode
+\t.wb_dat_o (wb_s2m_uart0_dat),
+\t.wb_ack_o (wb_s2m_uart0_ack),
+
+\t// Outputs
+\t.int_o(uart0_irq),
+\t.stx_pad_o (uart0_stx_pad_o),
+\t.rts_pad_o (),
+\t.dtr_pad_o (),
+
+\t// Inputs
+\t.srx_pad_i (uart0_srx_pad_i),
+\t.cts_pad_i (1\'b0),
+\t.dsr_pad_i (1\'b0),
+\t.ri_pad_i (1\'b0),
+\t.dcd_pad_i (1\'b0)
+);
+
+////////////////////////////////////////////////////////////////////////
+//
+// GPIO0
+//
+////////////////////////////////////////////////////////////////////////
+
+wire [7:0]\tgpio0_in;
+wire [7:0]\tgpio0_out;
+wire [7:0]\tgpio0_dir;
+
+// Tristate logic for IO
+// 0 = input, 1 = output
+genvar i;
+generate
+for (i = 0; i < 7; i = i+1)
+begin: gpio0_tris
+\tassign gpio0_io[i] = gpio0_dir[i] ? gpio0_out[i] : 1\'bz;
+\tassign gpio0_in[i] = gpio0_dir[i] ? gpio0_out[i] : gpio0_io[i];
+end
+endgenerate
+
+assign gpio0_in[7] = 1\'b0;
+
+gpio gpio0(
+\t// GPIO bus
+\t.gpio_i(gpio0_in),
+\t.gpio_o(gpio0_out),
+\t.gpio_dir_o(gpio0_dir),
+\t// Wishbone slave interface
+\t.wb_adr_i(wb_m2s_gpio0_adr[0]),
+\t.wb_dat_i(wb_m2s_gpio0_dat),
+\t.wb_we_i(wb_m2s_gpio0_we),
+\t.wb_cyc_i(wb_m2s_gpio0_cyc),
+\t.wb_stb_i(wb_m2s_gpio0_stb),
+\t.wb_cti_i(wb_m2s_gpio0_cti),
+\t.wb_bte_i(wb_m2s_gpio0_bte),
+\t.wb_dat_o(wb_s2m_gpio0_dat),
+\t.wb_ack_o(wb_s2m_gpio0_ack),
+\t.wb_err_o(wb_s2m_gpio0_err),
+\t.wb_rty_o(wb_s2m_gpio0_rty),
+
+\t.wb_clk(wb_clk),
+\t.wb_rst(wb_rst)
+);
+
+////////////////////////////////////////////////////////////////////////
+//
+// TRNG
+//
+////////////////////////////////////////////////////////////////////////
+
+wb_trng trng0 (
+\t// Wishbone slave interface
+\t.wb_adr_i(wb_m2s_trng_adr),
+\t.wb_dat_i(wb_m2s_trng_dat),
+\t.wb_we_i(wb_m2s_trng_we),
+\t.wb_cyc_i(wb_m2s_trng_cyc),
+\t.wb_stb_i(wb_m2s_trng_stb),
+\t.wb_cti_i(wb_m2s_trng_cti),
+\t.wb_bte_i(wb_m2s_trng_bte),
+\t.wb_dat_o(wb_s2m_trng_dat),
+\t.wb_ack_o(wb_s2m_trng_ack),
+\t.wb_err_o(wb_s2m_trng_err),
+\t.wb_rty_o(wb_s2m_trng_rty),
+
+\t.wb_clk(wb_clk),
+\t.wb_rst(wb_rst)
+);
+
+////////////////////////////////////////////////////////////////////////
+//
+// CRYPTO_AES
+//
+////////////////////////////////////////////////////////////////////////
+
+crypto_aes_top crypto_aes (
+\t.wb_clk_i(wb_clk),
+ .wb_rst_i(wb_rst),
+
+ .core_clk(wb_clk2x),
+
+\t.wb_adr_i(wb_m2s_crypto_aes_adr),
+\t.wb_dat_i(wb_m2s_crypto_aes_dat),
+\t.wb_sel_i(wb_m2s_crypto_aes_sel),
+\t.wb_cti_i(wb_m2s_crypto_aes_cti),
+\t.wb_bte_i(wb_m2s_crypto_aes_bte),
+\t.wb_we_i(wb_m2s_crypto_aes_we),
+\t.wb_cyc_i(wb_m2s_crypto_aes_cyc),
+\t.wb_stb_i(wb_m2s_crypto_aes_stb),
+\t.wb_dat_o(wb_s2m_crypto_aes_dat),
+\t.wb_ack_o(wb_s2m_crypto_aes_ack),
+\t.wb_err_o(wb_s2m_crypto_aes_err),
+\t.wb_rty_o(wb_s2m_crypto_aes_rty)
+);
+
+////////////////////////////////////////////////////////////////////////
+//
+// CRYPTO_SHA256
+//
+////////////////////////////////////////////////////////////////////////
+
+crypto_sha256_top crypto_sha256 (
+\t.wb_clk_i(wb_clk),
+ .wb_rst_i(wb_rst),
+
+ .core_clk(wb_clk2x),
+
+\t.wb_adr_i(wb_m2s_crypto_sha256_adr),
+\t.wb_dat_i(wb_m2s_crypto_sha256_dat),
+\t.wb_sel_i(wb_m2s_crypto_sha256_sel),
+\t.wb_cti_i(wb_m2s_crypto_sha256_cti),
+\t.wb_bte_i(wb_m2s_crypto_sha256_bte),
+\t.wb_we_i(wb_m2s_crypto_sha256_we),
+\t.wb_cyc_i(wb_m2s_crypto_sha256_cyc),
+\t.wb_stb_i(wb_m2s_crypto_sha256_stb),
+\t.wb_dat_o(wb_s2m_crypto_sha256_dat),
+\t.wb_ack_o(wb_s2m_crypto_sha256_ack),
+\t.wb_err_o(wb_s2m_crypto_sha256_err),
+\t.wb_rty_o(wb_s2m_crypto_sha256_rty)
+);
+
+////////////////////////////////////////////////////////////////////////
+//
+// BOOTROM0
+//
+////////////////////////////////////////////////////////////////////////
+localparam bootrom0_aw = 6;
+
+assign wb_s2m_bootrom0_err = 1\'b0;
+assign wb_s2m_bootrom0_rty = 1\'b0;
+
+bootrom #(
+\t.addr_width(bootrom0_aw)
+) bootrom0 (
+\t.wb_clk(wb_clk),
+\t.wb_rst(wb_rst),
+\t.wb_adr_i(wb_m2s_bootrom0_adr[(bootrom0_aw + 2) - 1 : 2]),
+\t.wb_cyc_i(wb_m2s_bootrom0_cyc),
+\t.wb_stb_i(wb_m2s_bootrom0_stb),
+\t.wb_cti_i(wb_m2s_bootrom0_cti),
+\t.wb_bte_i(wb_m2s_bootrom0_bte),
+\t.wb_dat_o(wb_s2m_bootrom0_dat),
+\t.wb_ack_o(wb_s2m_bootrom0_ack)
+);
+
+////////////////////////////////////////////////////////////////////////
+//
+// SDHC
+//
+////////////////////////////////////////////////////////////////////////
+wire sd_clk_buf, wb_sdhc_clk;
+
+IBUFG sd_clk_IBUFG (
+ .I ( sd_clk ),
+ .O ( sd_clk_buf )
+);
+wire sd_cmd_i, sd_cmd_o, sd_cmd_t;
+IOBUF sd_cmd_IOBUF (
+ .IO ( sd_cmd ),
+ .I ( sd_cmd_o ),
+ .O ( sd_cmd_i ),
+ .T ( sd_cmd_t )
+);
+wire [3:0] sd_dat_i, sd_dat_o, sd_dat_t;
+generate for(i = 0; i < 4; i = i + 1) begin : sd_dat_IOBUF
+ IOBUF sd_dat_IOBUF (
+ .IO ( sd_dat[i] ),
+ .I ( sd_dat_o[i] ),
+ .O ( sd_dat_i[i] ),
+ .T ( sd_dat_t[i] )
+ );
+end endgenerate
+
+wire [31:0] wb_m2s_sdhc_adr;
+wire [31:0] wb_m2s_sdhc_dat;
+wire [3:0] wb_m2s_sdhc_sel;
+wire wb_m2s_sdhc_we;
+wire wb_m2s_sdhc_cyc;
+wire wb_m2s_sdhc_stb;
+wire [2:0] wb_m2s_sdhc_cti;
+wire [1:0] wb_m2s_sdhc_bte;
+wire [31:0] wb_s2m_sdhc_dat;
+wire wb_s2m_sdhc_ack;
+wire wb_s2m_sdhc_err;
+wire wb_s2m_sdhc_rty;
+
+wire [31:0] wb_s2m_sdhc_dat_fauxfs, wb_s2m_sdhc_dat_ftl;
+wire wb_s2m_sdhc_ack_fauxfs, wb_s2m_sdhc_ack_fauxfs;
+assign wb_s2m_sdhc_dat = wb_s2m_sdhc_dat_fauxfs | wb_s2m_sdhc_dat_ftl;
+assign wb_s2m_sdhc_ack = wb_s2m_sdhc_ack_fauxfs | wb_s2m_sdhc_ack_ftl;
+
+sd_top sd_top (
+ .clk_50 ( wb_clk ),
+ .reset_n ( ~wb_rst ),
+
+ .sd_clk ( sd_clk_buf ),
+ .sd_cmd_i ( sd_cmd_i ),
+ .sd_cmd_o ( sd_cmd_o ),
+ .sd_cmd_t ( sd_cmd_t ),
+ .sd_dat_i ( sd_dat_i ),
+ .sd_dat_o ( sd_dat_o ),
+ .sd_dat_t ( sd_dat_t ),
+
+ .wbm_clk_o ( wb_sdhc_clk ),
+ .wbm_adr_o ( wb_m2s_sdhc_adr ),
+ .wbm_dat_o ( wb_m2s_sdhc_dat ),
+ .wbm_sel_o ( wb_m2s_sdhc_sel ),
+ .wbm_cyc_o ( wb_m2s_sdhc_cyc ),
+ .wbm_stb_o ( wb_m2s_sdhc_stb ),
+ .wbm_we_o ( wb_m2s_sdhc_we ),
+ .wbm_cti_o ( wb_m2s_sdhc_cti ),
+ .wbm_bte_o ( wb_m2s_sdhc_bte ),
+ .wbm_dat_i ( wb_s2m_sdhc_dat ),
+ .wbm_ack_i ( wb_s2m_sdhc_ack ),
+
+ .opt_enable_hs ( 1 )
+);
+
+////////////////////////////////////////////////////////////////////////
+//
+// FAUXFS
+//
+////////////////////////////////////////////////////////////////////////
+wire rfile_ack_irq, wfile_dat_irq;
+
+fauxfs_top (
+\t.wb_cpu_clk_i(wb_clk),
+\t.wb_cpu_rst_i(wb_rst),
+\t.wb_cpu_adr_i(wb_m2s_fauxfs_cpu_adr),
+\t.wb_cpu_dat_i(wb_m2s_fauxfs_cpu_dat),
+\t.wb_cpu_sel_i(wb_m2s_fauxfs_cpu_sel),
+\t.wb_cpu_cti_i(wb_m2s_fauxfs_cpu_cti),
+\t.wb_cpu_bte_i(wb_m2s_fauxfs_cpu_bti),
+\t.wb_cpu_we_i(wb_m2s_fauxfs_cpu_we),
+\t.wb_cpu_cyc_i(wb_m2s_fauxfs_cpu_cyc),
+\t.wb_cpu_stb_i(wb_m2s_fauxfs_cpu_stb),
+\t.wb_cpu_dat_o(wb_s2m_fauxfs_cpu_dat),
+\t.wb_cpu_ack_o(wb_s2m_fauxfs_cpu_ack),
+\t.wb_cpu_err_o(wb_s2m_fauxfs_cpu_err),
+\t.wb_cpu_rty_o(wb_s2m_fauxfs_cpu_rty),
+
+\t.wfile_dat_int_o(wfile_dat_irq),
+\t.rfile_ack_int_o(rfile_ack_irq),
+\t
+\t.wb_sdhc_clk_i(wb_sdhc_clk),
+\t.wb_sdhc_rst_i(wb_rst),
+\t.wb_sdhc_adr_i(wb_m2s_sdhc_adr),
+\t.wb_sdhc_dat_i(wb_m2s_sdhc_dat),
+\t.wb_sdhc_sel_i(wb_m2s_sdhc_sel),
+\t.wb_sdhc_cti_i(wb_m2s_shdc_cti),
+\t.wb_sdhc_bte_i(wb_m2s_sdhc_bti),
+\t.wb_sdhc_we_i(wb_m2s_sdhc_we),
+\t.wb_sdhc_cyc_i(wb_m2s_sdhc_cyc),
+\t.wb_sdhc_stb_i(wb_m2s_sdhc_stb),
+\t.wb_sdhc_dat_o(wb_s2m_sdhc_dat_fauxfs),
+\t.wb_sdhc_ack_o(wb_s2m_sdhc_ack_fauxfs),
+\t.wb_sdhc_err_o(wb_s2m_sdhc_err),
+\t.wb_sdhc_rty_o(wb_s2m_sdhc_rty)
+);
+
+////////////////////////////////////////////////////////////////////////
+//
+// FTL
+//
+////////////////////////////////////////////////////////////////////////
+
+wire [9:0] dbg_phy_num_valid_blocks;
+wire dbg_phy_rebuilt_badblock;
+wire dbg_phy_remapped_runtime;
+wire err_phy_out_of_extras;
+
+wire [2:0] wb_m2s_ftl_cti;
+wire [1:0] wb_m2s_ftl_bte;
+wire [31:0] wb_m2s_ftl_adr;
+wire [31:0] wb_m2s_ftl_dat;
+wire [3:0] wb_m2s_ftl_sel;
+wire wb_m2s_ftl_cyc;
+wire wb_m2s_ftl_stb;
+wire wb_m2s_ftl_we;
+wire [31:0] wb_s2m_ftl_dat;
+wire wb_s2m_ftl_ack;
+
+ftl_top ftl_top (
+ .clk_50 ( wb_sdhc_clk ),
+ .reset_n ( ~wb_rst ),
+ .dbg_phy_num_valid_blocks ( dbg_phy_num_valid_blocks ),
+ .dbg_phy_rebuilt_badblock ( dbg_phy_rebuilt_badblock ),
+ .dbg_phy_remapped_runtime ( dbg_phy_remapped_runtime ),
+ .err_phy_out_of_extras ( err_phy_out_of_extras ),
+
+ .wbs_clk_i ( wb_sdhc_clk ),
+ .wbs_adr_i ( wb_m2s_sdhc_adr ),
+ .wbs_dat_i ( wb_m2s_sdhc_dat ),
+ .wbs_sel_i ( wb_m2s_sdhc_sel ),
+ .wbs_cyc_i ( wb_m2s_sdhc_cyc ),
+ .wbs_stb_i ( wb_m2s_sdhc_stb ),
+ .wbs_we_i ( wb_m2s_sdhc_we ),
+ .wbs_dat_o ( wb_s2m_sdhc_dat_ftl ),
+ .wbs_ack_o ( wb_s2m_sdhc_ack_ftl ),
+
+ .wbm_cti_o ( wb_m2s_ftl_cti ),
+ .wbm_bte_o ( wb_m2s_ftl_bte ),
+ .wbm_adr_o ( wb_m2s_ftl_adr ),
+ .wbm_dat_o ( wb_m2s_ftl_dat ),
+ .wbm_sel_o ( wb_m2s_ftl_sel ),
+ .wbm_cyc_o ( wb_m2s_ftl_cyc ),
+ .wbm_stb_o ( wb_m2s_ftl_stb ),
+ .wbm_we_o ( wb_m2s_ftl_we ),
+ .wbm_dat_i ( wb_s2m_ftl_dat ),
+ .wbm_ack_i ( wb_s2m_ftl_ack )
+);
+
+////////////////////////////////////////////////////////////////////////
+//
+// NANDC
+//
+////////////////////////////////////////////////////////////////////////
+
+wire [7:0] nand_io_i, nand_io_o, nand_io_t;
+generate for(i = 0; i < 8; i = i + 1) begin : nand_io_IOBUF
+ IOBUF nand_io_IOBUF (
+ .IO(nand_io[i]),
+ .I(nand_io_o[i]),
+ .O(nand_io_i[i]),
+ .T(nand_io_t[i])
+ );
+end endgenerate
+
+nandc_ecc_dual_master #(
+ .WB0_FLASH_S ( 0 ),
+ .WB0_FLASH_N ( 1020 ),
+ .WB1_FLASH_S ( 1020 ),
+ .WB1_FLASH_N ( 4 )
+) nandc_ecc (
+ .wb_clk ( wb_sdhc_clk ),
+ .wb_rst ( wb_rst ),
+
+ .wbs0_cti_i ( wb_m2s_ftl_cti ),
+ .wbs0_bte_i ( wb_m2s_ftl_bte ),
+ .wbs0_adr_i ( wb_m2s_ftl_adr ),
+ .wbs0_dat_i ( wb_m2s_ftl_dat ),
+ .wbs0_sel_i ( wb_m2s_ftl_sel ),
+ .wbs0_cyc_i ( wb_m2s_ftl_cyc ),
+ .wbs0_stb_i ( wb_m2s_ftl_stb ),
+ .wbs0_we_i ( wb_m2s_ftl_we ),
+ .wbs0_dat_o ( wb_s2m_ftl_dat ),
+ .wbs0_ack_o ( wb_s2m_ftl_ack ),
+
+ .wbs1_cti_i ( wb_m2s_nand_cpu_cti ),
+ .wbs1_bte_i ( wb_m2s_nand_cpu_bte ),
+ .wbs1_adr_i ( wb_m2s_nand_cpu_adr ),
+ .wbs1_dat_i ( wb_m2s_nand_cpu_dat ),
+ .wbs1_sel_i ( wb_m2s_nand_cpu_sel ),
+ .wbs1_cyc_i ( wb_m2s_nand_cpu_cyc ),
+ .wbs1_stb_i ( wb_m2s_nand_cpu_stb ),
+ .wbs1_we_i ( wb_m2s_nand_cpu_we ),
+ .wbs1_dat_o ( wb_s2m_nand_cpu_dat ),
+ .wbs1_ack_o ( wb_s2m_nand_cpu_ack ),
+
+ .IO_i ( nand_io_i ),
+ .IO_o ( nand_io_o ),
+ .IO_t ( nand_io_t ),
+ .CLE ( nand_cle ),
+ .ALE ( nand_ale ),
+ .CE_n ( nand_ce_n ),
+ .WE_n ( nand_we_n ),
+ .RE_n ( nand_re_n ),
+ .WP_n ( nand_wp_n ),
+ .RB_n ( nand_rb_n )
+);
+
+assign wb_m2s_nand_cpu_err = 0;
+assign wb_m2s_nand_cpu_rty = 0;
+
+////////////////////////////////////////////////////////////////////////
+//
+// Interrupt assignment
+//
+////////////////////////////////////////////////////////////////////////
+
+assign or1k_irq[0] = 0; // Non-maskable inside OR1K
+assign or1k_irq[1] = 0; // Non-maskable inside OR1K
+assign or1k_irq[2] = uart0_irq;
+assign or1k_irq[3] = 0;
+assign or1k_irq[4] = 0;
+assign or1k_irq[5] = 0;
+assign or1k_irq[6] = 0;
+assign or1k_irq[7] = 0;
+assign or1k_irq[8] = 0;
+assign or1k_irq[9] = 0;
+assign or1k_irq[10] = 0;
+assign or1k_irq[11] = 0;
+assign or1k_irq[12] = 0;
+assign or1k_irq[13] = 0;
+assign or1k_irq[14] = 0;
+assign or1k_irq[15] = 0;
+assign or1k_irq[16] = wfile_dat_irq;
+assign or1k_irq[17] = rfile_ack_irq;
+assign or1k_irq[18] = 0;
+assign or1k_irq[19] = 0;
+assign or1k_irq[20] = 0;
+assign or1k_irq[21] = 0;
+assign or1k_irq[22] = 0;
+assign or1k_irq[23] = 0;
+assign or1k_irq[24] = 0;
+assign or1k_irq[25] = 0;
+assign or1k_irq[26] = 0;
+assign or1k_irq[27] = 0;
+assign or1k_irq[28] = 0;
+assign or1k_irq[29] = 0;
+assign or1k_irq[30] = 0;
+assign or1k_irq[31] = 0;
+
+endmodule
+"
+"`timescale 1ns / 1ps
+/*
+ Copyright 2015, Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the ""License"");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an ""AS IS"" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 01:09:00 02/19/2015
+// Design Name:
+// Module Name: fauxfs_top
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module fauxfs_top(
+\t// SDHC wishbone slave
+\tinput wb_sdhc_clk_i,
+\tinput wb_sdhc_rst_i,
+
+\tinput [31:0] wb_sdhc_adr_i,
+\tinput [31:0] wb_sdhc_dat_i,
+\tinput [3:0] wb_sdhc_sel_i,
+\tinput wb_sdhc_we_i,
+\tinput [1:0] wb_sdhc_bte_i,
+\tinput [2:0] wb_sdhc_cti_i,
+\tinput wb_sdhc_cyc_i,
+\tinput wb_sdhc_stb_i,
+
+\toutput reg wb_sdhc_ack_o,
+\toutput wb_sdhc_rty_o,
+\toutput wb_sdhc_err_o,
+\toutput reg [31:0] wb_sdhc_dat_o,
+\t
+\t// CPU wishbone slave
+\tinput wb_cpu_clk_i,
+\tinput wb_cpu_rst_i,
+
+\tinput [31:0] wb_cpu_adr_i,
+\tinput [31:0] wb_cpu_dat_i,
+\tinput [3:0] wb_cpu_sel_i,
+\tinput wb_cpu_we_i,
+\tinput [1:0] wb_cpu_bte_i,
+\tinput [2:0] wb_cpu_cti_i,
+\tinput wb_cpu_cyc_i,
+\tinput wb_cpu_stb_i,
+
+\toutput reg wb_cpu_ack_o,
+\toutput wb_cpu_rty_o,
+\toutput wb_cpu_err_o,
+\toutput reg [31:0] wb_cpu_dat_o,
+\t
+\toutput wfile_dat_int_o,
+\toutput rfile_ack_int_o
+);
+
+`include ""wb_common.v""
+// common memories
+reg [31:0] rfile_dat_mem[511:0];
+reg [31:0] rfile_ack_mem[3:0];
+reg [31:0] wfile_dat_mem[511:0];
+reg [31:0] wfile_ack_mem[3:0];
+
+// CPU side
+reg wfile_dat_int_cpu, rfile_ack_int_cpu;
+reg wfile_dat_clr_cpu, rfile_ack_clr_cpu;
+
+assign wfile_dat_int_o = wfile_dat_int_cpu;
+assign rfile_ack_int_o = rfile_ack_int_cpu;
+
+assign wb_cpu_rty_o = 0;
+assign wb_cpu_err_o = 0;
+
+reg [12:0] cpu_adr_r;
+wire [12:0] cpu_next_adr;
+wire cpu_valid = wb_cpu_cyc_i & wb_cpu_stb_i;
+reg cpu_valid_r;
+
+wire cpu_new_cycle = cpu_valid & !cpu_valid_r;
+
+assign cpu_next_adr = wb_next_adr(cpu_adr_r, wb_cpu_cti_i, wb_cpu_bte_i, 32);
+
+wire [12:0] cpu_adr = cpu_new_cycle ? wb_cpu_adr_i[12:0] : cpu_next_adr;
+
+always@(posedge wb_cpu_clk_i)
+begin
+\tcpu_adr_r <= cpu_adr;
+\tcpu_valid_r <= cpu_valid;
+
+\twb_cpu_ack_o <= cpu_valid & (!((wb_cpu_cti_i == 3\'b000) | (wb_cpu_cti_i == 3\'b111)) | !wb_cpu_ack_o);
+\tif(wb_cpu_rst_i)
+\tbegin
+\t\tcpu_adr_r <= 0;
+\t\tcpu_valid_r <= 0;
+\t\twb_cpu_ack_o <= 0;
+\tend
+end
+
+always @(posedge wb_cpu_clk_i)
+begin
+\twfile_dat_clr_cpu <= wfile_dat_clr_cpu & wfile_dat_int_cpu;
+\trfile_ack_clr_cpu <= rfile_ack_clr_cpu & rfile_ack_int_cpu;
+\tif(wb_cpu_rst_i)
+\tbegin
+\t\twfile_dat_clr_cpu <= 0;
+\t\trfile_ack_clr_cpu <= 0;
+\tend
+\telse if(cpu_valid)
+\tbegin
+\t\tcase(cpu_adr[12:11])
+\t\t2\'b00: wb_cpu_dat_o <= wfile_dat_mem[cpu_adr[10:2]];
+\t\t2\'b01:
+\t\tbegin
+\t\t\twb_cpu_dat_o <= rfile_dat_mem[cpu_adr[10:2]];
+\t\t\tif(wb_cpu_we_i & wb_cpu_sel_i[0])
+\t\t\t\trfile_dat_mem[cpu_adr[10:2]][ 7: 0] <= wb_cpu_dat_i[ 7: 0];
+\t\t\tif(wb_cpu_we_i & wb_cpu_sel_i[1])
+\t\t\t\trfile_dat_mem[cpu_adr[10:2]][15: 8] <= wb_cpu_dat_i[15: 8];
+\t\t\tif(wb_cpu_we_i & wb_cpu_sel_i[2])
+\t\t\t\trfile_dat_mem[cpu_adr[10:2]][23:16] <= wb_cpu_dat_i[23:16];
+\t\t\tif(wb_cpu_we_i & wb_cpu_sel_i[3])
+\t\t\t\trfile_dat_mem[cpu_adr[10:2]][31:24] <= wb_cpu_dat_i[31:24];
+\t\tend
+\t\t2\'b10:
+\t\tbegin
+\t\t\tcase(cpu_adr[10:4])
+\t\t\t7\'h00:
+\t\t\tbegin
+\t\t\t\twb_cpu_dat_o <= wfile_ack_mem[cpu_adr[3:2]];
+\t\t\t\tif(wb_cpu_we_i & wb_cpu_sel_i[0])
+\t\t\t\t\twfile_ack_mem[cpu_adr[3:2]][ 7: 0] <= wb_cpu_dat_i[ 7: 0];
+\t\t\t\tif(wb_cpu_we_i & wb_cpu_sel_i[1])
+\t\t\t\t\twfile_ack_mem[cpu_adr[3:2]][15: 8] <= wb_cpu_dat_i[15: 8];
+\t\t\t\tif(wb_cpu_we_i & wb_cpu_sel_i[2])
+\t\t\t\t\twfile_ack_mem[cpu_adr[3:2]][23:16] <= wb_cpu_dat_i[23:16];
+\t\t\t\tif(wb_cpu_we_i & wb_cpu_sel_i[3])
+\t\t\t\t\twfile_ack_mem[cpu_adr[3:2]][31:24] <= wb_cpu_dat_i[31:24];
+\t\t\tend
+\t\t\t7\'h01:
+\t\t\t\twb_cpu_dat_o <= rfile_ack_mem[cpu_adr[3:2]];
+\t\t\t7\'h02:
+\t\t\tbegin
+\t\t\t\twb_cpu_dat_o <= { 30\'h0, rfile_ack_int_cpu, wfile_dat_int_cpu };
+\t\t\t\tif(wb_cpu_we_i & wb_cpu_sel_i[0])
+\t\t\t\tbegin
+\t\t\t\t\twfile_dat_clr_cpu <= wb_cpu_dat_i[0];
+\t\t\t\t\trfile_ack_clr_cpu <= wb_cpu_dat_i[1];
+\t\t\t\tend
+\t\t\tend
+\t\t\tdefault: wb_cpu_dat_o <= 32\'h0;
+\t\t\tendcase
+\t\tend
+\t\t2\'b11: wb_cpu_dat_o <= 32\'h0;
+\t\tendcase
+\tend
+end
+
+// SDHC side
+assign wb_sdhc_rty_o = 0;
+assign wb_sdhc_err_o = 0;
+
+reg wfile_dat_int_sdhc, rfile_ack_int_sdhc;
+reg wfile_dat_clr_sdhc, rfile_ack_clr_sdhc;
+
+reg [31:0] sdhc_adr_r;
+wire [31:0] sdhc_next_adr;
+// only ack if we\'re being addressed (< 2MB)
+// FTL will also be tied to this wishbone bus but will only ack when
+// receiving requests >2MB
+wire sdhc_valid = wb_sdhc_cyc_i & wb_sdhc_stb_i & ((wb_sdhc_adr_i < 32\'h200000));
+reg sdhc_valid_r;
+
+wire sdhc_new_cycle = sdhc_valid & !sdhc_valid_r;
+
+assign sdhc_next_adr = wb_next_adr(sdhc_adr_r, wb_sdhc_cti_i, wb_sdhc_bte_i, 32);
+
+wire [31:0] sdhc_adr = sdhc_new_cycle ? wb_sdhc_adr_i[31:0] : sdhc_next_adr;
+
+always@(posedge wb_sdhc_clk_i)
+begin
+\tsdhc_adr_r <= sdhc_adr;
+\tsdhc_valid_r <= sdhc_valid;
+
+\twb_sdhc_ack_o <= sdhc_valid & (!((wb_sdhc_cti_i == 3\'b000) | (wb_sdhc_cti_i == 3\'b111)) | !wb_sdhc_ack_o);
+\tif(wb_sdhc_rst_i)
+\tbegin
+\t\tsdhc_adr_r <= 0;
+\t\tsdhc_valid_r <= 0;
+\t\twb_sdhc_ack_o <= 0;
+\tend
+end
+
+wire mbr_rom_sel = ((sdhc_adr & 32\'hfffffe00) == 32\'h00000000);
+wire fat_rom_sel = ((sdhc_adr & 32\'hfffff000) == 32\'h00100000);
+wire rfile_sel = ((sdhc_adr & 32\'hfffff800) == 32\'h00105000);
+wire wfile_sel = ((sdhc_adr & 32\'hfffff800) == 32\'h00105800);
+
+always @(posedge wb_sdhc_clk_i)
+begin
+\trfile_ack_int_sdhc <= rfile_ack_int_sdhc & ~rfile_ack_clr_sdhc;
+\twfile_dat_int_sdhc <= wfile_dat_int_sdhc & ~wfile_dat_clr_sdhc;
+\t
+\tif(wb_sdhc_rst_i)
+\tbegin
+\t\trfile_ack_int_sdhc <= 0;
+\t\twfile_dat_int_sdhc <= 0;
+\tend
+\telse if(sdhc_valid)
+\tbegin
+\t\twb_sdhc_dat_o <= 32\'h0;
+\t\tif(mbr_rom_sel)
+\t\tbegin
+\t\t\tcase(sdhc_adr[8:2])
+\t\t\t`include ""mbr_rom.vh""
+\t\t\tdefault: wb_sdhc_dat_o <= 32\'h0;
+\t\t\tendcase
+\t\tend
+\t\tif(fat_rom_sel)
+\t\tbegin
+\t\t\tcase(sdhc_adr[11:2])
+\t\t\t`include ""fat_rom.vh""
+\t\t\tdefault: wb_sdhc_dat_o <= 32\'h0;
+\t\t\tendcase
+\t\tend
+\t\tif(rfile_sel)
+\t\tbegin
+\t\t\twb_sdhc_dat_o <= rfile_dat_mem[sdhc_adr[10:2]];
+\t\t\tif(wb_sdhc_we_i && ((sdhc_adr & 32\'hfffffff0) == 32\'h00105000))
+\t\t\tbegin
+\t\t\t\tif((sdhc_adr & 32\'hfffffffc) == 32\'h0010500c)
+\t\t\t\t\trfile_ack_int_sdhc <= 1;
+\t\t\t\trfile_ack_mem[sdhc_adr[3:2]] <= wb_sdhc_dat_i;
+\t\t\tend
+\t\tend
+\t\tif(wfile_sel)
+\t\tbegin
+\t\t\twb_sdhc_dat_o <= wfile_ack_mem[sdhc_adr[3:2]];
+\t\t\tif(wb_sdhc_we_i)
+\t\t\tbegin
+\t\t\t\tif((sdhc_adr & 32\'hfffffffc) == 32\'h00105ffc)
+\t\t\t\t\twfile_dat_int_sdhc <= 1;
+\t\t\t\twfile_dat_mem[sdhc_adr[10:2]] <= wb_sdhc_dat_i;
+\t\t\tend
+\t\tend
+\tend
+end
+
+// CDC stuff
+
+reg wfile_dat_int_cpu_buf, rfile_ack_int_cpu_buf;
+reg wfile_dat_clr_sdhc_buf, rfile_ack_clr_sdhc_buf;
+
+always @(posedge wb_cpu_clk_i)
+begin
+\twfile_dat_int_cpu <= wfile_dat_int_cpu_buf;
+\twfile_dat_int_cpu_buf <= wfile_dat_int_sdhc;
+\tif(wb_cpu_rst_i)
+\tbegin
+\t\twfile_dat_int_cpu <= 0;
+\t\twfile_dat_int_cpu_buf <= 0;
+\tend
+end
+
+always @(posedge wb_cpu_clk_i)
+begin
+\trfile_ack_int_cpu <= rfile_ack_int_cpu_buf;
+\trfile_ack_int_cpu_buf <= rfile_ack_int_sdhc;
+\tif(wb_cpu_rst_i)
+\tbegin
+\t\trfile_ack_int_cpu <= 0;
+\t\trfile_ack_int_cpu_buf <= 0;
+\tend
+end
+
+always @(posedge wb_sdhc_clk_i)
+begin
+\twfile_dat_clr_sdhc <= wfile_dat_clr_sdhc_buf;
+\twfile_dat_clr_sdhc_buf <= wfile_dat_clr_cpu;
+\tif(wb_cpu_rst_i)
+\tbegin
+\t\twfile_dat_clr_sdhc <= 0;
+\t\twfile_dat_clr_sdhc_buf <= 0;
+\tend
+end
+
+always @(posedge wb_sdhc_clk_i)
+begin
+\trfile_ack_clr_sdhc <= rfile_ack_clr_sdhc_buf;
+\trfile_ack_clr_sdhc_buf <= rfile_ack_clr_cpu;
+\tif(wb_cpu_rst_i)
+\tbegin
+\t\trfile_ack_clr_sdhc <= 0;
+\t\trfile_ack_clr_sdhc_buf <= 0;
+\tend
+end
+
+endmodule
+"
+"`timescale 1ps/1ps
+"
+"//////////////////////////////////////////////////////////////////////
+//// ////
+//// OR1200\'s definitions ////
+//// ////
+//// This file is part of the OpenRISC 1200 project ////
+//// http://opencores.org/project,or1k ////
+//// ////
+//// Description ////
+//// Defines for the OR1200 core ////
+//// ////
+//// To Do: ////
+//// - add parameters that are missing ////
+//// ////
+//// Author(s): ////
+//// - Damjan Lampret, lampret@opencores.org ////
+//// ////
+//////////////////////////////////////////////////////////////////////
+//// ////
+//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
+//// ////
+//// This source file may be used and distributed without ////
+//// restriction provided that this copyright statement is not ////
+//// removed from the file and that any derivative work contains ////
+//// the original copyright notice and the associated disclaimer. ////
+//// ////
+//// This source file is free software; you can redistribute it ////
+//// and/or modify it under the terms of the GNU Lesser General ////
+//// Public License as published by the Free Software Foundation; ////
+//// either version 2.1 of the License, or (at your option) any ////
+//// later version. ////
+//// ////
+//// This source is distributed in the hope that it will be ////
+//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
+//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
+//// PURPOSE. See the GNU Lesser General Public License for more ////
+//// details. ////
+//// ////
+//// You should have received a copy of the GNU Lesser General ////
+//// Public License along with this source; if not, download it ////
+//// from http://www.opencores.org/lgpl.shtml ////
+//// ////
+//////////////////////////////////////////////////////////////////////
+//
+// $Log: or1200_defines.v,v $
+// Revision 2.0 2010/06/30 11:00:00 ORSoC
+// Minor update:
+// Defines added, bugs fixed.
+
+//
+// Dump VCD
+//
+//`define OR1200_VCD_DUMP
+
+//
+// Generate debug messages during simulation
+//
+//`define OR1200_VERBOSE
+
+// `define OR1200_ASIC
+////////////////////////////////////////////////////////
+//
+// Typical configuration for an ASIC
+//
+`ifdef OR1200_ASIC
+
+//
+// Target ASIC memories
+//
+//`define OR1200_ARTISAN_SSP
+//`define OR1200_ARTISAN_SDP
+//`define OR1200_ARTISAN_STP
+`define OR1200_VIRTUALSILICON_SSP
+//`define OR1200_VIRTUALSILICON_STP_T1
+//`define OR1200_VIRTUALSILICON_STP_T2
+
+//
+// Do not implement Data cache
+//
+//`define OR1200_NO_DC
+
+//
+// Do not implement Insn cache
+//
+//`define OR1200_NO_IC
+
+//
+// Do not implement Data MMU
+//
+//`define OR1200_NO_DMMU
+
+//
+// Do not implement Insn MMU
+//
+//`define OR1200_NO_IMMU
+
+//
+// Select between ASIC optimized and generic multiplier
+//
+//`define OR1200_ASIC_MULTP2_32X32
+`define OR1200_GENERIC_MULTP2_32X32
+
+//
+// Size/type of insn/data cache if implemented
+//
+// `define OR1200_IC_1W_512B
+`define OR1200_IC_1W_4KB
+//`define OR1200_IC_1W_8KB
+`define OR1200_DC_1W_4KB
+//`define OR1200_DC_1W_8KB
+
+`else
+
+
+/////////////////////////////////////////////////////////
+//
+// Typical configuration for an FPGA
+//
+
+//
+// Target FPGA memories
+//
+//`define OR1200_ALTERA_LPM
+`define OR1200_XILINX_RAMB16
+//`define OR1200_XILINX_RAMB4
+//`define OR1200_XILINX_RAM32X1D
+//`define OR1200_USE_RAM16X1D_FOR_RAM32X1D
+// Generic models should infer RAM blocks at synthesis time (not only effects
+// single port ram.)
+//`define OR1200_GENERIC
+
+//
+// Do not implement Data cache
+//
+//`define OR1200_NO_DC
+
+//
+// Do not implement Insn cache
+//
+//`define OR1200_NO_IC
+
+//
+// Do not implement Data MMU
+//
+//`define OR1200_NO_DMMU
+
+//
+// Do not implement Insn MMU
+//
+//`define OR1200_NO_IMMU
+
+//
+// Select between ASIC and generic multiplier
+//
+// (Generic seems to trigger a bug in the Cadence Ncsim simulator)
+//
+//`define OR1200_ASIC_MULTP2_32X32
+`define OR1200_GENERIC_MULTP2_32X32
+
+//
+// Size/type of insn/data cache if implemented
+// (consider available FPGA memory resources)
+//
+//`define OR1200_IC_1W_512B
+`define OR1200_IC_1W_4KB
+//`define OR1200_IC_1W_8KB
+//`define OR1200_IC_1W_16KB
+//`define OR1200_IC_1W_32KB
+`define OR1200_DC_1W_4KB
+//`define OR1200_DC_1W_8KB
+//`define OR1200_DC_1W_16KB
+//`define OR1200_DC_1W_32KB
+
+`endif
+
+
+//////////////////////////////////////////////////////////
+//
+// Do not change below unless you know what you are doing
+//
+
+//
+// Reset active low
+//
+//`define OR1200_RST_ACT_LOW
+
+//
+// Enable RAM BIST
+//
+// At the moment this only works for Virtual Silicon
+// single port RAMs. For other RAMs it has not effect.
+// Special wrapper for VS RAMs needs to be provided
+// with scan flops to facilitate bist scan.
+//
+//`define OR1200_BIST
+
+//
+// Register OR1200 WISHBONE outputs
+// (must be defined/enabled)
+//
+`define OR1200_REGISTERED_OUTPUTS
+
+//
+// Register OR1200 WISHBONE inputs
+//
+// (must be undefined/disabled)
+//
+//`define OR1200_REGISTERED_INPUTS
+
+//
+// Disable bursts if they are not supported by the
+// memory subsystem (only affect cache line fill)
+//
+//`define OR1200_NO_BURSTS
+//
+
+//
+// WISHBONE retry counter range
+//
+// 2^value range for retry counter. Retry counter
+// is activated whenever *wb_rty_i is asserted and
+// until retry counter expires, corresponding
+// WISHBONE interface is deactivated.
+//
+// To disable retry counters and *wb_rty_i all together,
+// undefine this macro.
+//
+//`define OR1200_WB_RETRY 7
+
+//
+// WISHBONE Consecutive Address Burst
+//
+// This was used prior to WISHBONE B3 specification
+// to identify bursts. It is no longer needed but
+// remains enabled for compatibility with old designs.
+//
+// To remove *wb_cab_o ports undefine this macro.
+//
+//`define OR1200_WB_CAB
+
+//
+// WISHBONE B3 compatible interface
+//
+// This follows the WISHBONE B3 specification.
+// It is not enabled by default because most
+// designs still don\'t use WB b3.
+//
+// To enable *wb_cti_o/*wb_bte_o ports,
+// define this macro.
+//
+`define OR1200_WB_B3
+
+//
+// LOG all WISHBONE accesses
+//
+`define OR1200_LOG_WB_ACCESS
+
+//
+// Enable additional synthesis directives if using
+// _Synopsys_ synthesis tool
+//
+//`define OR1200_ADDITIONAL_SYNOPSYS_DIRECTIVES
+
+//
+// Enables default statement in some case blocks
+// and disables Synopsys synthesis directive full_case
+//
+// By default it is enabled. When disabled it
+// can increase clock frequency.
+//
+`define OR1200_CASE_DEFAULT
+
+//
+// Operand width / register file address width
+//
+// (DO NOT CHANGE)
+//
+`define OR1200_OPERAND_WIDTH\t\t32
+`define OR1200_REGFILE_ADDR_WIDTH\t5
+
+//
+// l.add/l.addi/l.and and optional l.addc/l.addic
+// also set (compare) flag when result of their
+// operation equals zero
+//
+// At the time of writing this, default or32
+// C/C++ compiler doesn\'t generate code that
+// would benefit from this optimization.
+//
+// By default this optimization is disabled to
+// save area.
+//
+//`define OR1200_ADDITIONAL_FLAG_MODIFIERS
+
+//
+// Implement l.addc/l.addic instructions
+//
+// By default implementation of l.addc/l.addic
+// instructions is enabled in case you need them.
+// If you don\'t use them, then disable implementation
+// to save area.
+//
+//`define OR1200_IMPL_ADDC
+
+//
+// Implement l.sub instruction
+//
+// By default implementation of l.sub instructions
+// is enabled to be compliant with the simulator.
+// If you don\'t use carry bit, then disable
+// implementation to save area.
+//
+`define OR1200_IMPL_SUB
+
+//
+// Implement carry bit SR[CY]
+//
+//
+// By default implementation of SR[CY] is enabled
+// to be compliant with the simulator. However SR[CY]
+// is explicitly only used by l.addc/l.addic/l.sub
+// instructions and if these three insns are not
+// implemented there is not much point having SR[CY].
+//
+//`define OR1200_IMPL_CY
+
+//
+// Implement carry bit SR[OV]
+//
+// Compiler doesn\'t use this, but other code may like
+// to.
+//
+//`define OR1200_IMPL_OV
+
+//
+// Implement carry bit SR[OVE]
+//
+// Overflow interrupt indicator. When enabled, SR[OV] flag
+// does not remain asserted after exception.
+//
+//`define OR1200_IMPL_OVE
+
+
+//
+// Implement rotate in the ALU
+//
+// At the time of writing this, or32
+// C/C++ compiler doesn\'t generate rotate
+// instructions. However or32 assembler
+// can assemble code that uses rotate insn.
+// This means that rotate instructions
+// must be used manually inserted.
+//
+// By default implementation of rotate
+// is disabled to save area and increase
+// clock frequency.
+//
+//`define OR1200_IMPL_ALU_ROTATE
+
+//
+// Type of ALU compare to implement
+//
+// Try either one to find what yields
+// higher clock frequencyin your case.
+//
+//`define OR1200_IMPL_ALU_COMP1
+`define OR1200_IMPL_ALU_COMP2
+//`define OR1200_IMPL_ALU_COMP3
+
+//
+// Implement Find First/Last \'1\'
+//
+`define OR1200_IMPL_ALU_FFL1
+
+//
+// Implement l.cust5 ALU instruction
+//
+//`define OR1200_IMPL_ALU_CUST5
+
+//
+// Implement l.extXs and l.extXz instructions
+//
+//`define OR1200_IMPL_ALU_EXT
+
+//
+// Implement multiplier
+//
+// By default multiplier is implemented
+//
+`define OR1200_MULT_IMPLEMENTED
+
+//
+// Implement multiply-and-accumulate
+//
+// By default MAC is implemented. To
+// implement MAC, multiplier (non-serial) needs to be
+// implemented.
+//
+//`define OR1200_MAC_IMPLEMENTED
+
+//
+// Implement optional l.div/l.divu instructions
+//
+// By default divide instructions are not implemented
+// to save area.
+//
+//
+`define OR1200_DIV_IMPLEMENTED
+
+//
+// Serial multiplier.
+//
+`define OR1200_MULT_SERIAL
+
+//
+// Serial divider.
+// Uncomment to use a serial divider, otherwise will
+// be a generic parallel implementation.
+//
+`define OR1200_DIV_SERIAL
+
+//
+// Implement HW Single Precision FPU
+//
+//`define OR1200_FPU_IMPLEMENTED
+
+//
+// Clock ratio RISC clock versus WB clock
+//
+// If you plan to run WB:RISC clock fixed to 1:1, disable
+// both defines
+//
+// For WB:RISC 1:2 or 1:1, enable OR1200_CLKDIV_2_SUPPORTED
+// and use clmode to set ratio
+//
+// For WB:RISC 1:4, 1:2 or 1:1, enable both defines and use
+// clmode to set ratio
+//
+//`define OR1200_CLKDIV_2_SUPPORTED
+//`define OR1200_CLKDIV_4_SUPPORTED
+
+//
+// Type of register file RAM
+//
+// Memory macro w/ two ports (see or1200_tpram_32x32.v)
+//`define OR1200_RFRAM_TWOPORT
+//
+// Memory macro dual port (see or1200_dpram.v)
+`define OR1200_RFRAM_DUALPORT
+
+//
+// Generic (flip-flop based) register file (see or1200_rfram_generic.v)
+//`define OR1200_RFRAM_GENERIC
+// Generic register file supports - 16 registers
+`ifdef OR1200_RFRAM_GENERIC
+// `define OR1200_RFRAM_16REG
+`endif
+
+//
+// Type of mem2reg aligner to implement.
+//
+// Once OR1200_IMPL_MEM2REG2 yielded faster
+// circuit, however with today tools it will
+// most probably give you slower circuit.
+//
+`define OR1200_IMPL_MEM2REG1
+//`define OR1200_IMPL_MEM2REG2
+
+//
+// Reset value and event
+//
+`ifdef OR1200_RST_ACT_LOW
+ `define OR1200_RST_VALUE (1\'b0)
+ `define OR1200_RST_EVENT negedge
+`else
+ `define OR1200_RST_VALUE (1\'b1)
+ `define OR1200_RST_EVENT posedge
+`endif
+
+//
+// ALUOPs
+//
+`define OR1200_ALUOP_WIDTH\t5
+`define OR1200_ALUOP_NOP\t5\'b0_0100
+/* LS-nibble encodings correspond to bits [3:0] of instruction */
+`define OR1200_ALUOP_ADD\t5\'b0_0000 // 0
+`define OR1200_ALUOP_ADDC\t5\'b0_0001 // 1
+`define OR1200_ALUOP_SUB\t5\'b0_0010 // 2
+`define OR1200_ALUOP_AND\t5\'b0_0011 // 3
+`define OR1200_ALUOP_OR\t\t5\'b0_0100 // 4
+`define OR1200_ALUOP_XOR\t5\'b0_0101 // 5
+`define OR1200_ALUOP_MUL\t5\'b0_0110 // 6
+`define OR1200_ALUOP_RESERVED\t5\'b0_0111 // 7
+`define OR1200_ALUOP_SHROT\t5\'b0_1000 // 8
+`define OR1200_ALUOP_DIV\t5\'b0_1001 // 9
+`define OR1200_ALUOP_DIVU\t5\'b0_1010 // a
+`define OR1200_ALUOP_MULU\t5\'b0_1011 // b
+`define OR1200_ALUOP_EXTHB\t5\'b0_1100 // c
+`define OR1200_ALUOP_EXTW\t5\'b0_1101 // d
+`define OR1200_ALUOP_CMOV\t5\'b0_1110 // e
+`define OR1200_ALUOP_FFL1\t5\'b0_1111 // f
+
+/* Values sent to ALU from decode unit - not defined by ISA */
+`define OR1200_ALUOP_COMP 5\'b1_0000 // Comparison
+`define OR1200_ALUOP_MOVHI 5\'b1_0001 // Move-high
+`define OR1200_ALUOP_CUST5\t5\'b1_0010 // l.cust5
+
+// ALU instructions second opcode field
+`define OR1200_ALUOP2_POS\t9:6
+`define OR1200_ALUOP2_WIDTH\t4
+
+//
+// MACOPs
+//
+`define OR1200_MACOP_WIDTH\t3
+`define OR1200_MACOP_NOP\t3\'b000
+`define OR1200_MACOP_MAC\t3\'b001
+`define OR1200_MACOP_MSB\t3\'b010
+
+//
+// Shift/rotate ops
+//
+`define OR1200_SHROTOP_WIDTH\t4
+`define OR1200_SHROTOP_NOP\t4\'d0
+`define OR1200_SHROTOP_SLL\t4\'d0
+`define OR1200_SHROTOP_SRL\t4\'d1
+`define OR1200_SHROTOP_SRA\t4\'d2
+`define OR1200_SHROTOP_ROR\t4\'d3
+
+//
+// Zero/Sign Extend ops
+//
+`define OR1200_EXTHBOP_WIDTH 4
+`define OR1200_EXTHBOP_BS 4\'h1
+`define OR1200_EXTHBOP_HS 4\'h0
+`define OR1200_EXTHBOP_BZ 4\'h3
+`define OR1200_EXTHBOP_HZ 4\'h2
+`define OR1200_EXTWOP_WIDTH 4
+`define OR1200_EXTWOP_WS 4\'h0
+`define OR1200_EXTWOP_WZ 4\'h1
+
+// Execution cycles per instruction
+`define OR1200_MULTICYCLE_WIDTH\t3
+`define OR1200_ONE_CYCLE\t\t3\'d0
+`define OR1200_TWO_CYCLES\t\t3\'d1
+
+// Execution control which will ""wait on"" a module to finish
+`define OR1200_WAIT_ON_WIDTH 2
+`define OR1200_WAIT_ON_NOTHING `OR1200_WAIT_ON_WIDTH\'d0
+`define OR1200_WAIT_ON_MULTMAC `OR1200_WAIT_ON_WIDTH\'d1
+`define OR1200_WAIT_ON_FPU `OR1200_WAIT_ON_WIDTH\'d2
+`define OR1200_WAIT_ON_MTSPR `OR1200_WAIT_ON_WIDTH\'d3
+
+
+// Operand MUX selects
+`define OR1200_SEL_WIDTH\t\t2
+`define OR1200_SEL_RF\t\t\t2\'d0
+`define OR1200_SEL_IMM\t\t\t2\'d1
+`define OR1200_SEL_EX_FORW\t\t2\'d2
+`define OR1200_SEL_WB_FORW\t\t2\'d3
+
+//
+// BRANCHOPs
+//
+`define OR1200_BRANCHOP_WIDTH\t\t3
+`define OR1200_BRANCHOP_NOP\t\t3\'d0
+`define OR1200_BRANCHOP_J\t\t3\'d1
+`define OR1200_BRANCHOP_JR\t\t3\'d2
+`define OR1200_BRANCHOP_BAL\t\t3\'d3
+`define OR1200_BRANCHOP_BF\t\t3\'d4
+`define OR1200_BRANCHOP_BNF\t\t3\'d5
+`define OR1200_BRANCHOP_RFE\t\t3\'d6
+
+//
+// LSUOPs
+//
+// Bit 0: sign extend
+// Bits 1-2: 00 doubleword, 01 byte, 10 halfword, 11 singleword
+// Bit 3: 0 load, 1 store
+`define OR1200_LSUOP_WIDTH\t\t4
+`define OR1200_LSUOP_NOP\t\t4\'b0000
+`define OR1200_LSUOP_LBZ\t\t4\'b0010
+`define OR1200_LSUOP_LBS\t\t4\'b0011
+`define OR1200_LSUOP_LHZ\t\t4\'b0100
+`define OR1200_LSUOP_LHS\t\t4\'b0101
+`define OR1200_LSUOP_LWZ\t\t4\'b0110
+`define OR1200_LSUOP_LWS\t\t4\'b0111
+`define OR1200_LSUOP_LD\t\t\t4\'b0001
+`define OR1200_LSUOP_SD\t\t\t4\'b1000
+`define OR1200_LSUOP_SB\t\t\t4\'b1010
+`define OR1200_LSUOP_SH\t\t\t4\'b1100
+`define OR1200_LSUOP_SW\t\t\t4\'b1110
+
+// Number of bits of load/store EA precalculated in ID stage
+// for balancing ID and EX stages.
+//
+// Valid range: 2,3,...,30,31
+`define OR1200_LSUEA_PRECALC\t\t2
+
+// FETCHOPs
+`define OR1200_FETCHOP_WIDTH\t\t1
+`define OR1200_FETCHOP_NOP\t\t1\'b0
+`define OR1200_FETCHOP_LW\t\t1\'b1
+
+//
+// Register File Write-Back OPs
+//
+// Bit 0: register file write enable
+// Bits 3-1: write-back mux selects
+//
+`define OR1200_RFWBOP_WIDTH\t\t4
+`define OR1200_RFWBOP_NOP\t\t4\'b0000
+`define OR1200_RFWBOP_ALU\t\t3\'b000
+`define OR1200_RFWBOP_LSU\t\t3\'b001
+`define OR1200_RFWBOP_SPRS\t\t3\'b010
+`define OR1200_RFWBOP_LR\t\t3\'b011
+`define OR1200_RFWBOP_FPU\t\t3\'b100
+
+// Compare instructions
+`define OR1200_COP_SFEQ 3\'b000
+`define OR1200_COP_SFNE 3\'b001
+`define OR1200_COP_SFGT 3\'b010
+`define OR1200_COP_SFGE 3\'b011
+`define OR1200_COP_SFLT 3\'b100
+`define OR1200_COP_SFLE 3\'b101
+`define OR1200_COP_X 3\'b111
+`define OR1200_SIGNED_COMPARE \'d3
+`define OR1200_COMPOP_WIDTH\t4
+
+//
+// FP OPs
+//
+// MSbit indicates FPU operation valid
+//
+`define OR1200_FPUOP_WIDTH\t8
+// FPU unit from Usselman takes 5 cycles from decode, so 4 ex. cycles
+`define OR1200_FPUOP_CYCLES 3\'d4
+// FP instruction is double precision if bit 4 is set. We\'re a 32-bit
+// implementation thus do not support double precision FP
+`define OR1200_FPUOP_DOUBLE_BIT 4
+`define OR1200_FPUOP_ADD 8\'b0000_0000
+`define OR1200_FPUOP_SUB 8\'b0000_0001
+`define OR1200_FPUOP_MUL 8\'b0000_0010
+`define OR1200_FPUOP_DIV 8\'b0000_0011
+`define OR1200_FPUOP_ITOF 8\'b0000_0100
+`define OR1200_FPUOP_FTOI 8\'b0000_0101
+`define OR1200_FPUOP_REM 8\'b0000_0110
+`define OR1200_FPUOP_RESERVED 8\'b0000_0111
+// FP Compare instructions
+`define OR1200_FPCOP_SFEQ 8\'b0000_1000
+`define OR1200_FPCOP_SFNE 8\'b0000_1001
+`define OR1200_FPCOP_SFGT 8\'b0000_1010
+`define OR1200_FPCOP_SFGE 8\'b0000_1011
+`define OR1200_FPCOP_SFLT 8\'b0000_1100
+`define OR1200_FPCOP_SFLE 8\'b0000_1101
+
+//
+// TAGs for instruction bus
+//
+`define OR1200_ITAG_IDLE\t4\'h0\t// idle bus
+`define\tOR1200_ITAG_NI\t\t4\'h1\t// normal insn
+`define OR1200_ITAG_BE\t\t4\'hb\t// Bus error exception
+`define OR1200_ITAG_PE\t\t4\'hc\t// Page fault exception
+`define OR1200_ITAG_TE\t\t4\'hd\t// TLB miss exception
+
+//
+// TAGs for data bus
+//
+`define OR1200_DTAG_IDLE\t4\'h0\t// idle bus
+`define\tOR1200_DTAG_ND\t\t4\'h1\t// normal data
+`define OR1200_DTAG_AE\t\t4\'ha\t// Alignment exception
+`define OR1200_DTAG_BE\t\t4\'hb\t// Bus error exception
+`define OR1200_DTAG_PE\t\t4\'hc\t// Page fault exception
+`define OR1200_DTAG_TE\t\t4\'hd\t// TLB miss exception
+
+
+//////////////////////////////////////////////
+//
+// ORBIS32 ISA specifics
+//
+
+// SHROT_OP position in machine word
+`define OR1200_SHROTOP_POS\t\t7:6
+
+//
+// Instruction opcode groups (basic)
+//
+`define OR1200_OR32_J 6\'b000000
+`define OR1200_OR32_JAL 6\'b000001
+`define OR1200_OR32_BNF 6\'b000011
+`define OR1200_OR32_BF 6\'b000100
+`define OR1200_OR32_NOP 6\'b000101
+`define OR1200_OR32_MOVHI 6\'b000110
+`define OR1200_OR32_MACRC 6\'b000110
+`define OR1200_OR32_XSYNC 6\'b001000
+`define OR1200_OR32_RFE 6\'b001001
+/* */
+`define OR1200_OR32_JR 6\'b010001
+`define OR1200_OR32_JALR 6\'b010010
+`define OR1200_OR32_MACI 6\'b010011
+/* */
+`define OR1200_OR32_LWZ 6\'b100001
+`define OR1200_OR32_LWS 6\'b100010
+`define OR1200_OR32_LBZ 6\'b100011
+`define OR1200_OR32_LBS 6\'b100100
+`define OR1200_OR32_LHZ 6\'b100101
+`define OR1200_OR32_LHS 6\'b100110
+`define OR1200_OR32_ADDI 6\'b100111
+`define OR1200_OR32_ADDIC 6\'b101000
+`define OR1200_OR32_ANDI 6\'b101001
+`define OR1200_OR32_ORI 6\'b101010
+`define OR1200_OR32_XORI 6\'b101011
+`define OR1200_OR32_MULI 6\'b101100
+`define OR1200_OR32_MFSPR 6\'b101101
+`define OR1200_OR32_SH_ROTI \t 6\'b101110
+`define OR1200_OR32_SFXXI 6\'b101111
+/* */
+`define OR1200_OR32_MTSPR 6\'b110000
+`define OR1200_OR32_MACMSB 6\'b110001
+`define OR1200_OR32_FLOAT 6\'b110010
+/* */
+`define OR1200_OR32_SW 6\'b110101
+`define OR1200_OR32_SB 6\'b110110
+`define OR1200_OR32_SH 6\'b110111
+`define OR1200_OR32_ALU 6\'b111000
+`define OR1200_OR32_SFXX 6\'b111001
+`define OR1200_OR32_CUST5 6\'b111100
+
+/////////////////////////////////////////////////////
+//
+// Exceptions
+//
+
+//
+// Exception vectors per OR1K architecture:
+// 0xPPPPP100 - reset
+// 0xPPPPP200 - bus error
+// ... etc
+// where P represents exception prefix.
+//
+// Exception vectors can be customized as per
+// the following formula:
+// 0xPPPPPNVV - exception N
+//
+// P represents exception prefix
+// N represents exception N
+// VV represents length of the individual vector space,
+// usually it is 8 bits wide and starts with all bits zero
+//
+
+//
+// PPPPP and VV parts
+//
+// Sum of these two defines needs to be 28
+//
+`define OR1200_EXCEPT_EPH0_P 20\'h00100
+`define OR1200_EXCEPT_EPH1_P 20\'hF0000
+`define OR1200_EXCEPT_V\t\t 8\'h00
+
+//
+// N part width
+//
+`define OR1200_EXCEPT_WIDTH 4
+
+//
+// Definition of exception vectors
+//
+// To avoid implementation of a certain exception,
+// simply comment out corresponding line
+//
+`define OR1200_EXCEPT_UNUSED\t\t`OR1200_EXCEPT_WIDTH\'hf
+`define OR1200_EXCEPT_TRAP\t\t`OR1200_EXCEPT_WIDTH\'he
+`define OR1200_EXCEPT_FLOAT\t\t`OR1200_EXCEPT_WIDTH\'hd
+`define OR1200_EXCEPT_SYSCALL\t\t`OR1200_EXCEPT_WIDTH\'hc
+`define OR1200_EXCEPT_RANGE\t\t`OR1200_EXCEPT_WIDTH\'hb
+`define OR1200_EXCEPT_ITLBMISS\t\t`OR1200_EXCEPT_WIDTH\'ha
+`define OR1200_EXCEPT_DTLBMISS\t\t`OR1200_EXCEPT_WIDTH\'h9
+`define OR1200_EXCEPT_INT\t\t`OR1200_EXCEPT_WIDTH\'h8
+`define OR1200_EXCEPT_ILLEGAL\t\t`OR1200_EXCEPT_WIDTH\'h7
+`define OR1200_EXCEPT_ALIGN\t\t`OR1200_EXCEPT_WIDTH\'h6
+`define OR1200_EXCEPT_TICK\t\t`OR1200_EXCEPT_WIDTH\'h5
+`define OR1200_EXCEPT_IPF\t\t`OR1200_EXCEPT_WIDTH\'h4
+`define OR1200_EXCEPT_DPF\t\t`OR1200_EXCEPT_WIDTH\'h3
+`define OR1200_EXCEPT_BUSERR\t\t`OR1200_EXCEPT_WIDTH\'h2
+`define OR1200_EXCEPT_RESET\t\t`OR1200_EXCEPT_WIDTH\'h1
+`define OR1200_EXCEPT_NONE\t\t`OR1200_EXCEPT_WIDTH\'h0
+
+
+/////////////////////////////////////////////////////
+//
+// SPR groups
+//
+
+// Bits that define the group
+`define OR1200_SPR_GROUP_BITS\t15:11
+
+// Width of the group bits
+`define OR1200_SPR_GROUP_WIDTH \t5
+
+// Bits that define offset inside the group
+`define OR1200_SPR_OFS_BITS 10:0
+
+// List of groups
+`define OR1200_SPR_GROUP_SYS\t5\'d00
+`define OR1200_SPR_GROUP_DMMU\t5\'d01
+`define OR1200_SPR_GROUP_IMMU\t5\'d02
+`define OR1200_SPR_GROUP_DC\t5\'d03
+`define OR1200_SPR_GROUP_IC\t5\'d04
+`define OR1200_SPR_GROUP_MAC\t5\'d05
+`define OR1200_SPR_GROUP_DU\t5\'d06
+`define OR1200_SPR_GROUP_PM\t5\'d08
+`define OR1200_SPR_GROUP_PIC\t5\'d09
+`define OR1200_SPR_GROUP_TT\t5\'d10
+`define OR1200_SPR_GROUP_FPU 5\'d11
+
+/////////////////////////////////////////////////////
+//
+// System group
+//
+
+//
+// System registers
+//
+`define OR1200_SPR_CFGR\t\t7\'d0
+`define OR1200_SPR_RF\t\t6\'d32\t// 1024 >> 5
+`define OR1200_SPR_NPC\t\t11\'d16
+`define OR1200_SPR_SR\t\t11\'d17
+`define OR1200_SPR_PPC\t\t11\'d18
+`define OR1200_SPR_FPCSR 11\'d20
+`define OR1200_SPR_EPCR\t\t11\'d32
+`define OR1200_SPR_EEAR\t\t11\'d48
+`define OR1200_SPR_ESR\t\t11\'d64
+
+//
+// SR bits
+//
+`define OR1200_SR_WIDTH 17
+`define OR1200_SR_SM 0
+`define OR1200_SR_TEE 1
+`define OR1200_SR_IEE 2
+`define OR1200_SR_DCE 3
+`define OR1200_SR_ICE 4
+`define OR1200_SR_DME 5
+`define OR1200_SR_IME 6
+`define OR1200_SR_LEE 7
+`define OR1200_SR_CE 8
+`define OR1200_SR_F 9
+`define OR1200_SR_CY 10\t// Optional
+`define OR1200_SR_OV 11\t// Optional
+`define OR1200_SR_OVE 12\t// Optional
+`define OR1200_SR_DSX 13\t// Unused
+`define OR1200_SR_EPH 14
+`define OR1200_SR_FO 15
+`define OR1200_SR_TED 16
+`define OR1200_SR_CID 31:28\t// Unimplemented
+
+//
+// Bits that define offset inside the group
+//
+`define OR1200_SPROFS_BITS 10:0
+
+//
+// Default Exception Prefix
+//
+// 1\'b0 - OR1200_EXCEPT_EPH0_P (0x0000_0000)
+// 1\'b1 - OR1200_EXCEPT_EPH1_P (0xF000_0000)
+//
+`define OR1200_SR_EPH_DEF\t1\'b0
+
+
+//
+// FPCSR bits
+//
+`define OR1200_FPCSR_WIDTH 12
+`define OR1200_FPCSR_FPEE 0
+`define OR1200_FPCSR_RM 2:1
+`define OR1200_FPCSR_OVF 3
+`define OR1200_FPCSR_UNF 4
+`define OR1200_FPCSR_SNF 5
+`define OR1200_FPCSR_QNF 6
+`define OR1200_FPCSR_ZF 7
+`define OR1200_FPCSR_IXF 8
+`define OR1200_FPCSR_IVF 9
+`define OR1200_FPCSR_INF 10
+`define OR1200_FPCSR_DZF 11
+`define OR1200_FPCSR_RES 31:12
+
+/////////////////////////////////////////////////////
+//
+// Power Management (PM)
+//
+
+// Define it if you want PM implemented
+//`define OR1200_PM_IMPLEMENTED
+
+// Bit positions inside PMR (don\'t change)
+`define OR1200_PM_PMR_SDF 3:0
+`define OR1200_PM_PMR_DME 4
+`define OR1200_PM_PMR_SME 5
+`define OR1200_PM_PMR_DCGE 6
+`define OR1200_PM_PMR_UNUSED 31:7
+
+// PMR offset inside PM group of registers
+`define OR1200_PM_OFS_PMR 11\'b0
+
+// PM group
+`define OR1200_SPRGRP_PM 5\'d8
+
+// Define if PMR can be read/written at any address inside PM group
+`define OR1200_PM_PARTIAL_DECODING
+
+// Define if reading PMR is allowed
+`define OR1200_PM_READREGS
+
+// Define if unused PMR bits should be zero
+`define OR1200_PM_UNUSED_ZERO
+
+
+/////////////////////////////////////////////////////
+//
+// Debug Unit (DU)
+//
+
+// Define it if you want DU implemented
+`define OR1200_DU_IMPLEMENTED
+
+//
+// Define if you want HW Breakpoints
+// (if HW breakpoints are not implemented
+// only default software trapping is
+// possible with l.trap insn - this is
+// however already enough for use
+// with or32 gdb)
+//
+//`define OR1200_DU_HWBKPTS
+
+// Number of DVR/DCR pairs if HW breakpoints enabled
+//\tComment / uncomment DU_DVRn / DU_DCRn pairs bellow according to this number !
+//\tDU_DVR0..DU_DVR7 should be uncommented for 8 DU_DVRDCR_PAIRS
+`define OR1200_DU_DVRDCR_PAIRS 8
+
+// Define if you want trace buffer
+//\t(for now only available for Xilinx Virtex FPGAs)
+//`define OR1200_DU_TB_IMPLEMENTED
+
+
+//
+// Address offsets of DU registers inside DU group
+//
+// To not implement a register, doq not define its address
+//
+`ifdef OR1200_DU_HWBKPTS
+`define OR1200_DU_DVR0\t\t11\'d0
+`define OR1200_DU_DVR1\t\t11\'d1
+`define OR1200_DU_DVR2\t\t11\'d2
+`define OR1200_DU_DVR3\t\t11\'d3
+`define OR1200_DU_DVR4\t\t11\'d4
+`define OR1200_DU_DVR5\t\t11\'d5
+`define OR1200_DU_DVR6\t\t11\'d6
+`define OR1200_DU_DVR7\t\t11\'d7
+`define OR1200_DU_DCR0\t\t11\'d8
+`define OR1200_DU_DCR1\t\t11\'d9
+`define OR1200_DU_DCR2\t\t11\'d10
+`define OR1200_DU_DCR3\t\t11\'d11
+`define OR1200_DU_DCR4\t\t11\'d12
+`define OR1200_DU_DCR5\t\t11\'d13
+`define OR1200_DU_DCR6\t\t11\'d14
+`define OR1200_DU_DCR7\t\t11\'d15
+`endif
+`define OR1200_DU_DMR1\t\t11\'d16
+`ifdef OR1200_DU_HWBKPTS
+`define OR1200_DU_DMR2\t\t11\'d17
+`define OR1200_DU_DWCR0\t\t11\'d18
+`define OR1200_DU_DWCR1\t\t11\'d19
+`endif
+`define OR1200_DU_DSR\t\t11\'d20
+`define OR1200_DU_DRR\t\t11\'d21
+`ifdef OR1200_DU_TB_IMPLEMENTED
+`define OR1200_DU_TBADR\t\t11\'h0ff
+`define OR1200_DU_TBIA\t\t11\'h1??
+`define OR1200_DU_TBIM\t\t11\'h2??
+`define OR1200_DU_TBAR\t\t11\'h3??
+`define OR1200_DU_TBTS\t\t11\'h4??
+`endif
+
+// Position of offset bits inside SPR address
+`define OR1200_DUOFS_BITS\t10:0
+
+// DCR bits
+`define OR1200_DU_DCR_DP\t0
+`define OR1200_DU_DCR_CC\t3:1
+`define OR1200_DU_DCR_SC\t4
+`define OR1200_DU_DCR_CT\t7:5
+
+// DMR1 bits
+`define OR1200_DU_DMR1_CW0\t1:0
+`define OR1200_DU_DMR1_CW1\t3:2
+`define OR1200_DU_DMR1_CW2\t5:4
+`define OR1200_DU_DMR1_CW3\t7:6
+`define OR1200_DU_DMR1_CW4\t9:8
+`define OR1200_DU_DMR1_CW5\t11:10
+`define OR1200_DU_DMR1_CW6\t13:12
+`define OR1200_DU_DMR1_CW7\t15:14
+`define OR1200_DU_DMR1_CW8\t17:16
+`define OR1200_DU_DMR1_CW9\t19:18
+`define OR1200_DU_DMR1_CW10\t21:20
+`define OR1200_DU_DMR1_ST\t22
+`define OR1200_DU_DMR1_BT\t23
+`define OR1200_DU_DMR1_DXFW\t24
+`define OR1200_DU_DMR1_ETE\t25
+
+// DMR2 bits
+`define OR1200_DU_DMR2_WCE0\t0
+`define OR1200_DU_DMR2_WCE1\t1
+`define OR1200_DU_DMR2_AWTC\t12:2
+`define OR1200_DU_DMR2_WGB\t23:13
+
+// DWCR bits
+`define OR1200_DU_DWCR_COUNT\t15:0
+`define OR1200_DU_DWCR_MATCH\t31:16
+
+// DSR bits
+`define OR1200_DU_DSR_WIDTH\t14
+`define OR1200_DU_DSR_RSTE\t0
+`define OR1200_DU_DSR_BUSEE\t1
+`define OR1200_DU_DSR_DPFE\t2
+`define OR1200_DU_DSR_IPFE\t3
+`define OR1200_DU_DSR_TTE\t4
+`define OR1200_DU_DSR_AE\t5
+`define OR1200_DU_DSR_IIE\t6
+`define OR1200_DU_DSR_IE\t7
+`define OR1200_DU_DSR_DME\t8
+`define OR1200_DU_DSR_IME\t9
+`define OR1200_DU_DSR_RE\t10
+`define OR1200_DU_DSR_SCE\t11
+`define OR1200_DU_DSR_FPE\t12
+`define OR1200_DU_DSR_TE\t13
+
+// DRR bits
+`define OR1200_DU_DRR_RSTE\t0
+`define OR1200_DU_DRR_BUSEE\t1
+`define OR1200_DU_DRR_DPFE\t2
+`define OR1200_DU_DRR_IPFE\t3
+`define OR1200_DU_DRR_TTE\t4
+`define OR1200_DU_DRR_AE\t5
+`define OR1200_DU_DRR_IIE\t6
+`define OR1200_DU_DRR_IE\t7
+`define OR1200_DU_DRR_DME\t8
+`define OR1200_DU_DRR_IME\t9
+`define OR1200_DU_DRR_RE\t10
+`define OR1200_DU_DRR_SCE\t11
+`define OR1200_DU_DRR_FPE\t12
+`define OR1200_DU_DRR_TE\t13
+
+// Define if reading DU regs is allowed
+`define OR1200_DU_READREGS
+
+// Define if unused DU registers bits should be zero
+`define OR1200_DU_UNUSED_ZERO
+
+// Define if IF/LSU status is not needed by devel i/f
+`define OR1200_DU_STATUS_UNIMPLEMENTED
+
+/////////////////////////////////////////////////////
+//
+// Programmable Interrupt Controller (PIC)
+//
+
+// Define it if you want PIC implemented
+`define OR1200_PIC_IMPLEMENTED
+
+// Define number of interrupt inputs (2-31)
+`define OR1200_PIC_INTS 31
+
+// Address offsets of PIC registers inside PIC group
+`define OR1200_PIC_OFS_PICMR 2\'d0
+`define OR1200_PIC_OFS_PICSR 2\'d2
+
+// Position of offset bits inside SPR address
+`define OR1200_PICOFS_BITS 1:0
+
+// Define if you want these PIC registers to be implemented
+`define OR1200_PIC_PICMR
+`define OR1200_PIC_PICSR
+
+// Define if reading PIC registers is allowed
+`define OR1200_PIC_READREGS
+
+// Define if unused PIC register bits should be zero
+`define OR1200_PIC_UNUSED_ZERO
+
+
+/////////////////////////////////////////////////////
+//
+// Tick Timer (TT)
+//
+
+// Define it if you want TT implemented
+`define OR1200_TT_IMPLEMENTED
+
+// Address offsets of TT registers inside TT group
+`define OR1200_TT_OFS_TTMR 1\'d0
+`define OR1200_TT_OFS_TTCR 1\'d1
+
+// Position of offset bits inside SPR group
+`define OR1200_TTOFS_BITS 0
+
+// Define if you want these TT registers to be implemented
+`define OR1200_TT_TTMR
+`define OR1200_TT_TTCR
+
+// TTMR bits
+`define OR1200_TT_TTMR_TP 27:0
+`define OR1200_TT_TTMR_IP 28
+`define OR1200_TT_TTMR_IE 29
+`define OR1200_TT_TTMR_M 31:30
+
+// Define if reading TT registers is allowed
+`define OR1200_TT_READREGS
+
+
+//////////////////////////////////////////////
+//
+// MAC
+//
+`define OR1200_MAC_ADDR\t\t0\t// MACLO 0xxxxxxxx1, MACHI 0xxxxxxxx0
+`define OR1200_MAC_SPR_WE\t\t// Define if MACLO/MACHI are SPR writable
+
+//
+// Shift {MACHI,MACLO} into destination register when executing l.macrc
+//
+// According to architecture manual there is no shift, so default value is 0.
+// However the implementation has devia'b'ted in this from the arch manual and had
+// hard coded shift by 28 bits which is a useful optimization for MP3 decoding
+// (if using libmad fixed point library). Shifts are no longer default setup,
+// but if you need to remain backward compatible, define your shift bits, which
+// were normally
+// dest_GPR = {MACHI,MACLO}[59:28]
+`define OR1200_MAC_SHIFTBY\t0\t// 0 = According to arch manual, 28 = obsolete backward compatibility
+
+
+//////////////////////////////////////////////
+//
+// Data MMU (DMMU)
+//
+
+//
+// Address that selects between TLB TR and MR
+//
+`define OR1200_DTLB_TM_ADDR\t7
+
+//
+// DTLBMR fields
+//
+`define\tOR1200_DTLBMR_V_BITS\t0
+`define\tOR1200_DTLBMR_CID_BITS\t4:1
+`define\tOR1200_DTLBMR_RES_BITS\t11:5
+`define OR1200_DTLBMR_VPN_BITS\t31:13
+
+//
+// DTLBTR fields
+//
+`define\tOR1200_DTLBTR_CC_BITS\t0
+`define\tOR1200_DTLBTR_CI_BITS\t1
+`define\tOR1200_DTLBTR_WBC_BITS\t2
+`define\tOR1200_DTLBTR_WOM_BITS\t3
+`define\tOR1200_DTLBTR_A_BITS\t4
+`define\tOR1200_DTLBTR_D_BITS\t5
+`define\tOR1200_DTLBTR_URE_BITS\t6
+`define\tOR1200_DTLBTR_UWE_BITS\t7
+`define\tOR1200_DTLBTR_SRE_BITS\t8
+`define\tOR1200_DTLBTR_SWE_BITS\t9
+`define\tOR1200_DTLBTR_RES_BITS\t11:10
+`define OR1200_DTLBTR_PPN_BITS\t31:13
+
+//
+// DTLB configuration
+//
+`define\tOR1200_DMMU_PS\t\t13\t\t\t\t\t// 13 for 8KB page size
+`define\tOR1200_DTLB_INDXW\t6\t\t\t\t\t// 6 for 64 entry DTLB\t7 for 128 entries
+`define OR1200_DTLB_INDXL\t`OR1200_DMMU_PS\t\t\t\t// 13\t\t\t13
+`define OR1200_DTLB_INDXH\t`OR1200_DMMU_PS+`OR1200_DTLB_INDXW-1\t// 18\t\t\t19
+`define\tOR1200_DTLB_INDX\t`OR1200_DTLB_INDXH:`OR1200_DTLB_INDXL\t// 18:13\t\t19:13
+`define OR1200_DTLB_TAGW\t32-`OR1200_DTLB_INDXW-`OR1200_DMMU_PS\t// 13\t\t\t12
+`define OR1200_DTLB_TAGL\t`OR1200_DTLB_INDXH+1\t\t\t// 19\t\t\t20
+`define\tOR1200_DTLB_TAG\t\t31:`OR1200_DTLB_TAGL\t\t\t// 31:19\t\t31:20
+`define\tOR1200_DTLBMRW\t\t`OR1200_DTLB_TAGW+1\t\t\t// +1 because of V bit
+`define\tOR1200_DTLBTRW\t\t32-`OR1200_DMMU_PS+5\t\t\t// +5 because of protection bits and CI
+
+//
+// Cache inhibit while DMMU is not enabled/implemented
+//
+// cache inhibited 0GB-4GB\t\t1\'b1
+// cache inhibited 0GB-2GB\t\t!dcpu_adr_i[31]
+// cache inhibited 0GB-1GB 2GB-3GB\t!dcpu_adr_i[30]
+// cache inhibited 1GB-2GB 3GB-4GB\tdcpu_adr_i[30]
+// cache inhibited 2GB-4GB (default)\tdcpu_adr_i[31]
+// cached 0GB-4GB\t\t\t1\'b0
+//
+`define OR1200_DMMU_CI\t\t\tdcpu_adr_i[31]
+
+
+//////////////////////////////////////////////
+//
+// Insn MMU (IMMU)
+//
+
+//
+// Address that selects between TLB TR and MR
+//
+`define OR1200_ITLB_TM_ADDR\t7
+
+//
+// ITLBMR fields
+//
+`define\tOR1200_ITLBMR_V_BITS\t0
+`define\tOR1200_ITLBMR_CID_BITS\t4:1
+`define\tOR1200_ITLBMR_RES_BITS\t11:5
+`define OR1200_ITLBMR_VPN_BITS\t31:13
+
+//
+// ITLBTR fields
+//
+`define\tOR1200_ITLBTR_CC_BITS\t0
+`define\tOR1200_ITLBTR_CI_BITS\t1
+`define\tOR1200_ITLBTR_WBC_BITS\t2
+`define\tOR1200_ITLBTR_WOM_BITS\t3
+`define\tOR1200_ITLBTR_A_BITS\t4
+`define\tOR1200_ITLBTR_D_BITS\t5
+`define\tOR1200_ITLBTR_SXE_BITS\t6
+`define\tOR1200_ITLBTR_UXE_BITS\t7
+`define\tOR1200_ITLBTR_RES_BITS\t11:8
+`define OR1200_ITLBTR_PPN_BITS\t31:13
+
+//
+// ITLB configuration
+//
+`define\tOR1200_IMMU_PS\t\t13\t\t\t\t\t// 13 for 8KB page size
+`define\tOR1200_ITLB_INDXW\t6\t\t\t\t\t// 6 for 64 entry ITLB\t7 for 128 entries
+`define OR1200_ITLB_INDXL\t`OR1200_IMMU_PS\t\t\t\t// 13\t\t\t13
+`define OR1200_ITLB_INDXH\t`OR1200_IMMU_PS+`OR1200_ITLB_INDXW-1\t// 18\t\t\t19
+`define\tOR1200_ITLB_INDX\t`OR1200_ITLB_INDXH:`OR1200_ITLB_INDXL\t// 18:13\t\t19:13
+`define OR1200_ITLB_TAGW\t32-`OR1200_ITLB_INDXW-`OR1200_IMMU_PS\t// 13\t\t\t12
+`define OR1200_ITLB_TAGL\t`OR1200_ITLB_INDXH+1\t\t\t// 19\t\t\t20
+`define\tOR1200_ITLB_TAG\t\t31:`OR1200_ITLB_TAGL\t\t\t// 31:19\t\t31:20
+`define\tOR1200_ITLBMRW\t\t`OR1200_ITLB_TAGW+1\t\t\t// +1 because of V bit
+`define\tOR1200_ITLBTRW\t\t32-`OR1200_IMMU_PS+3\t\t\t// +3 because of protection bits and CI
+
+//
+// Cache inhibit while IMMU is not enabled/implemented
+// Note: all combinations that use icpu_adr_i cause async loop
+//
+// cache inhibited 0GB-4GB\t\t1\'b1
+// cache inhibited 0GB-2GB\t\t!icpu_adr_i[31]
+// cache inhibited 0GB-1GB 2GB-3GB\t!icpu_adr_i[30]
+// cache inhibited 1GB-2GB 3GB-4GB\ticpu_adr_i[30]
+// cache inhibited 2GB-4GB (default)\ticpu_adr_i[31]
+// cached 0GB-4GB\t\t\t1\'b0
+//
+`define OR1200_IMMU_CI\t\t\t1\'b0
+
+
+/////////////////////////////////////////////////
+//
+// Insn cache (IC)
+//
+
+// 4 for 16 byte line, 5 for 32 byte lines.
+`ifdef OR1200_IC_1W_32KB
+ `define OR1200_ICLS\t\t5
+`else
+ `define OR1200_ICLS\t\t4
+`endif
+
+//
+// IC configurations
+//
+`ifdef OR1200_IC_1W_512B
+`define OR1200_ICSIZE 9 // 512
+`define OR1200_ICINDX `OR1200_ICSIZE-2 // 7
+`define OR1200_ICINDXH `OR1200_ICSIZE-1 // 8
+`define OR1200_ICTAGL `OR1200_ICINDXH+1 // 9
+`define OR1200_ICTAG `OR1200_ICSIZE-`OR1200_ICLS // 5
+`define OR1200_ICTAG_W 24
+`endif
+`ifdef OR1200_IC_1W_4KB
+`define OR1200_ICSIZE\t\t\t12\t\t\t// 4096
+`define OR1200_ICINDX\t\t\t`OR1200_ICSIZE-2\t// 10
+`define OR1200_ICINDXH\t\t\t`OR1200_ICSIZE-1\t// 11
+`define OR1200_ICTAGL\t\t\t`OR1200_ICINDXH+1\t// 12
+`define\tOR1200_ICTAG\t\t\t`OR1200_ICSIZE-`OR1200_ICLS\t// 8
+`define\tOR1200_ICTAG_W\t\t\t21
+`endif
+`ifdef OR1200_IC_1W_8KB
+`define OR1200_ICSIZE\t\t\t13\t\t\t// 8192
+`define OR1200_ICINDX\t\t\t`OR1200_ICSIZE-2\t// 11
+`define OR1200_ICINDXH\t\t\t`OR1200_ICSIZE-1\t// 12
+`define OR1200_ICTAGL\t\t\t`OR1200_ICINDXH+1\t// 13
+`define\tOR1200_ICTAG\t\t\t`OR1200_ICSIZE-`OR1200_ICLS\t// 9
+`define\tOR1200_ICTAG_W\t\t\t20
+`endif
+`ifdef OR1200_IC_1W_16KB
+`define OR1200_ICSIZE\t\t\t14\t\t\t// 16384
+`define OR1200_ICINDX\t\t\t`OR1200_ICSIZE-2\t// 12
+`define OR1200_ICINDXH\t\t\t`OR1200_ICSIZE-1\t// 13
+`define OR1200_ICTAGL\t\t\t`OR1200_ICINDXH+1\t// 14
+`define\tOR1200_ICTAG\t\t\t`OR1200_ICSIZE-`OR1200_ICLS\t// 10
+`define\tOR1200_ICTAG_W\t\t\t19
+`endif
+`ifdef OR1200_IC_1W_32KB
+`define OR1200_ICSIZE\t\t\t15\t\t\t// 32768
+`define OR1200_ICINDX\t\t\t`OR1200_ICSIZE-2\t// 13
+`define OR1200_ICINDXH\t\t\t`OR1200_ICSIZE-1\t// 14
+`define OR1200_ICTAGL\t\t\t`OR1200_ICINDXH+1\t// 14
+`define\tOR1200_ICTAG\t\t\t`OR1200_ICSIZE-`OR1200_ICLS\t// 10
+`define\tOR1200_ICTAG_W\t\t\t18
+`endif
+
+
+/////////////////////////////////////////////////
+//
+// Data cache (DC)
+//
+
+// 4 for 16 bytes, 5 for 32 bytes
+`ifdef OR1200_DC_1W_32KB
+ `define OR1200_DCLS\t\t5
+`else
+ `define OR1200_DCLS\t\t4
+`endif
+
+// Define to enable default behavior of cache as write through
+// Turning this off enabled write back statergy
+//
+`define OR1200_DC_WRITETHROUGH
+
+// Define to enable stores from the stack not doing writethrough.
+// EXPERIMENTAL
+//`define OR1200_DC_NOSTACKWRITETHROUGH
+
+// Data cache SPR definitions
+`define OR1200_SPRGRP_DC_ADR_WIDTH 3
+// Data cache group SPR addresses
+`define OR1200_SPRGRP_DC_DCCR\t\t3\'d0 // Not implemented
+`define OR1200_SPRGRP_DC_DCBPR\t\t3\'d1 // Not implemented
+`define OR1200_SPRGRP_DC_DCBFR\t\t3\'d2
+`define OR1200_SPRGRP_DC_DCBIR\t\t3\'d3
+`define OR1200_SPRGRP_DC_DCBWR\t\t3\'d4 // Not implemented
+`define OR1200_SPRGRP_DC_DCBLR\t\t3\'d5 // Not implemented
+
+//
+// DC configurations
+//
+`ifdef OR1200_DC_1W_4KB
+`define OR1200_DCSIZE\t\t\t12\t\t\t// 4096
+`define OR1200_DCINDX\t\t\t`OR1200_DCSIZE-2\t// 10
+`define OR1200_DCINDXH\t\t\t`OR1200_DCSIZE-1\t// 11
+`define OR1200_DCTAGL\t\t\t`OR1200_DCINDXH+1\t// 12
+`define\tOR1200_DCTAG\t\t\t`OR1200_DCSIZE-`OR1200_DCLS\t// 8
+`define\tOR1200_DCTAG_W\t\t\t21
+`endif
+`ifdef OR1200_DC_1W_8KB
+`define OR1200_DCSIZE\t\t\t13\t\t\t// 8192
+`define OR1200_DCINDX\t\t\t`OR1200_DCSIZE-2\t// 11
+`define OR1200_DCINDXH\t\t\t`OR1200_DCSIZE-1\t// 12
+`define OR1200_DCTAGL\t\t\t`OR1200_DCINDXH+1\t// 13
+`define\tOR1200_DCTAG\t\t\t`OR1200_DCSIZE-`OR1200_DCLS\t// 9
+`define\tOR1200_DCTAG_W\t\t\t20
+`endif
+`ifdef OR1200_DC_1W_16KB
+`define OR1200_DCSIZE\t\t\t14\t\t\t// 16384
+`define OR1200_DCINDX\t\t\t`OR1200_DCSIZE-2\t// 12
+`define OR1200_DCINDXH\t\t\t`OR1200_DCSIZE-1\t// 13
+`define OR1200_DCTAGL\t\t\t`OR1200_DCINDXH+1\t// 14
+`define\tOR1200_DCTAG\t\t\t`OR1200_DCSIZE-`OR1200_DCLS\t// 10
+`define\tOR1200_DCTAG_W\t\t\t19
+`endif
+`ifdef OR1200_DC_1W_32KB
+`define OR1200_DCSIZE\t\t\t15\t\t\t// 32768
+`define OR1200_DCINDX\t\t\t`OR1200_DCSIZE-2\t// 13
+`define OR1200_DCINDXH\t\t\t`OR1200_DCSIZE-1\t// 14
+`define OR1200_DCTAGL\t\t\t`OR1200_DCINDXH+1\t// 15
+`define\tOR1200_DCTAG\t\t\t`OR1200_DCSIZE-`OR1200_DCLS\t// 10
+`define\tOR1200_DCTAG_W\t\t\t18
+`endif
+
+
+/////////////////////////////////////////////////
+//
+// Store buffer (SB)
+//
+
+//
+// Store buffer
+//
+// It will improve performance by ""caching"" CPU stores
+// using store buffer. This is most important for function
+// prologues because DC can only work in write though mode
+// and all stores would have to complete external WB writes
+// to memory.
+// Store buffer is between DC and data BIU.
+// All stores will be stored into store buffer and immediately
+// completed by the CPU, even though actual external writes
+// will be performed later. As a consequence store buffer masks
+// all data bus errors related to stores (data bus errors
+// related to loads are delivered normally).
+// All pending CPU loads will wait until store buffer is empty to
+// ensure strict memory model. Right now this is necessary because
+// we don\'t make destinction between cached and cache inhibited
+// address space, so we simply empty store buffer until loads
+// can begin.
+//
+// It makes design a bit bigger, depending what is the number of
+// entries in SB FIFO. Number of entries can be changed further
+// down.
+//
+//`define OR1200_SB_IMPLEMENTED
+
+//
+// Number of store buffer entries
+//
+// Verified number of entries are 4 and 8 entries
+// (2 and 3 for OR1200_SB_LOG). OR1200_SB_ENTRIES must
+// always match 2**OR1200_SB_LOG.
+// To disable store buffer, undefine
+// OR1200_SB_IMPLEMENTED.
+//
+`define OR1200_SB_LOG\t\t2\t// 2 or 3
+`define OR1200_SB_ENTRIES\t4\t// 4 or 8
+
+
+/////////////////////////////////////////////////
+//
+// Quick Embedded Memory (QMEM)
+//
+
+//
+// Quick Embedded Memory
+//
+// Instantiation of dedicated insn/data memory (RAM or ROM).
+// Insn fetch has effective throughput 1insn / clock cycle.
+// Data load takes two clock cycles / access, data store
+// takes 1 clock cycle / access (if there is no insn fetch)).
+// Memory instantiation is shared between insn and data,
+// meaning if insn fetch are performed, data load/store
+// performance will be lower.
+//
+// Main reason for QMEM is to put some time critical functions
+// into this memory and to have predictable and fast access
+// to these functions. (soft fpu, context switch, exception
+// handlers, stack, etc)
+//
+// It makes design a bit bigger and slower. QMEM sits behind
+// IMMU/DMMU so all addresses are physical (so the MMUs can be
+// used with QMEM and QMEM is seen by the CPU just like any other
+// memory in the system). IC/DC are sitting behind QMEM so the
+// whole design timing might be worse with QMEM implemented.
+//
+//`define OR1200_QMEM_IMPLEMENTED
+
+//
+// Base address and mask of QMEM
+//
+// Base address defines first address of QMEM. Mask defines
+// QMEM range in address space. Actual size of QMEM is however
+// determined with instantiated RAM/ROM. However bigger
+// mask will reserve more address space for QMEM, but also
+// make design faster, while more tight mask will take
+// less address space but also make design slower. If
+// instantiated RAM/ROM is smaller than space reserved with
+// the mask, instatiated RAM/ROM will also be shadowed
+// at higher addresses in reserved space.
+//
+`define OR1200_QMEM_IADDR\t32\'h0080_0000
+`define OR1200_QMEM_IMASK\t32\'hfff0_0000 // Max QMEM size 1MB
+`define OR1200_QMEM_DADDR\t32\'h0080_0000
+`define OR1200_QMEM_DMASK\t32\'hfff0_0000 // Max QMEM size 1MB
+
+//
+// QMEM interface byte-select capability
+//
+// To enable qmem_sel* ports, define this macro.
+//
+//`define OR1200_QMEM_BSEL
+
+//
+// QMEM interface acknowledge
+//
+// To enable qmem_ack port, define this macro.
+//
+//`define OR1200_QMEM_ACK
+
+/////////////////////////////////////////////////////
+//
+// VR, UPR and Configuration Registers
+//
+//
+// VR, UPR and configuration registers are optional. If
+// implemented, operating system can automatically figure
+// out how to use the processor because it knows
+// what units are available in the processor and how they
+// are configured.
+//
+// This section must be last in or1200_defines.v file so
+// that all units are already configured and thus
+// configuration registers are properly set.
+//
+
+// Define if you want configuration registers implemented
+`define OR1200_CFGR_IMPLEMENTED
+
+// Define if you want full address decode inside SYS group
+`define OR1200_SYS_FULL_DECODE
+
+// Offsets of VR, UPR and CFGR registers
+`define OR1200_SPRGRP_SYS_VR\t\t4\'h0
+`define OR1200_SPRGRP_SYS_UPR\t\t4\'h1
+`define OR1200_SPRGRP_SYS_CPUCFGR\t4\'h2
+`define OR1200_SPRGRP_SYS_DMMUCFGR\t4\'h3
+`define OR1200_SPRGRP_SYS_IMMUCFGR\t4\'h4
+`define OR1200_SPRGRP_SYS_DCCFGR\t4\'h5
+`define OR1200_SPRGRP_SYS_ICCFGR\t4\'h6
+`define OR1200_SPRGRP_SYS_DCFGR\t4\'h7
+
+// VR fields
+`define OR1200_VR_REV_BITS\t\t5:0
+`define OR1200_VR_RES1_BITS\t\t15:6
+`define OR1200_VR_CFG_BITS\t\t23:16
+`define OR1200_VR_VER_BITS\t\t31:24
+
+// VR values
+`define OR1200_VR_REV\t\t\t6\'h08
+`define OR1200_VR_RES1\t\t\t10\'h000
+`define OR1200_VR_CFG\t\t\t8\'h00
+`define OR1200_VR_VER\t\t\t8\'h12
+
+// UPR fields
+`define OR1200_UPR_UP_BITS\t\t0
+`define OR1200_UPR_DCP_BITS\t\t1
+`define OR1200_UPR_ICP_BITS\t\t2
+`define OR1200_UPR_DMP_BITS\t\t3
+`define OR1200_UPR_IMP_BITS\t\t4
+`define OR1200_UPR_MP_BITS\t\t5
+`define OR1200_UPR_DUP_BITS\t\t6
+`define OR1200_UPR_PCUP_BITS\t\t7
+`define OR1200_UPR_PMP_BITS\t\t8
+`define OR1200_UPR_PICP_BITS\t\t9
+`define OR1200_UPR_TTP_BITS\t\t10
+`define OR1200_UPR_FPP_BITS\t\t11
+`define OR1200_UPR_RES1_BITS\t\t23:12
+`define OR1200_UPR_CUP_BITS\t\t31:24
+
+// UPR values
+`define OR1200_UPR_UP\t\t\t1\'b1
+`ifdef OR1200_NO_DC
+`define OR1200_UPR_DCP\t\t\t1\'b0
+`else
+`define OR1200_UPR_DCP\t\t\t1\'b1
+`endif
+`ifdef OR1200_NO_IC
+`define OR1200_UPR_ICP\t\t\t1\'b0
+`else
+`define OR1200_UPR_ICP\t\t\t1\'b1
+`endif
+`ifdef OR1200_NO_DMMU
+`define OR1200_UPR_DMP\t\t\t1\'b0
+`else
+`define OR1200_UPR_DMP\t\t\t1\'b1
+`endif
+`ifdef OR1200_NO_IMMU
+`define OR1200_UPR_IMP\t\t\t1\'b0
+`else
+`define OR1200_UPR_IMP\t\t\t1\'b1
+`endif
+`ifdef OR1200_MAC_IMPLEMENTED
+`define OR1200_UPR_MP\t\t\t1\'b1
+`else
+`define OR1200_UPR_MP\t\t\t1\'b0
+`endif
+`ifdef OR1200_DU_IMPLEMENTED
+`define OR1200_UPR_DUP\t\t\t1\'b1
+`else
+`define OR1200_UPR_DUP\t\t\t1\'b0
+`endif
+`define OR1200_UPR_PCUP\t\t\t1\'b0\t// Performance counters not present
+`ifdef OR1200_PM_IMPLEMENTED
+`define OR1200_UPR_PMP\t\t\t1\'b1
+`else
+`define OR1200_UPR_PMP\t\t\t1\'b0
+`endif
+`ifdef OR1200_PIC_IMPLEMENTED
+`define OR1200_UPR_PICP\t\t\t1\'b1
+`else
+`define OR1200_UPR_PICP\t\t\t1\'b0
+`endif
+`ifdef OR1200_TT_IMPLEMENTED
+`define OR1200_UPR_TTP\t\t\t1\'b1
+`else
+`define OR1200_UPR_TTP\t\t\t1\'b0
+`endif
+`ifdef OR1200_FPU_IMPLEMENTED
+`define OR1200_UPR_FPP\t\t\t1\'b1
+`else
+`define OR1200_UPR_FPP\t\t\t1\'b0
+`endif
+`define OR1200_UPR_RES1\t\t\t12\'h000
+`define OR1200_UPR_CUP\t\t\t8\'h00
+
+// CPUCFGR fields
+`define OR1200_CPUCFGR_NSGF_BITS\t3:0
+`define OR1200_CPUCFGR_HGF_BITS 4
+`define OR1200_CPUCFGR_OB32S_BITS\t5
+`define OR1200_CPUCFGR_OB64S_BITS\t6
+`define OR1200_CPUCFGR_OF32S_BITS\t7
+`define OR1200_CPUCFGR_OF64S_BITS\t8
+`define OR1200_CPUCFGR_OV64S_BITS\t9
+`define OR1200_CPUCFGR_RES1_BITS\t31:10
+
+// CPUCFGR values
+`define OR1200_CPUCFGR_NSGF\t\t 4\'h0
+`ifdef OR1200_RFRAM_16REG
+ `define OR1200_CPUCFGR_HGF \t\t1\'b1
+`else
+ `define OR1200_CPUCFGR_HGF \t\t1\'b0
+`endif
+`define OR1200_CPUCFGR_OB32S\t\t1\'b1
+`define OR1200_CPUCFGR_OB64S\t\t1\'b0
+`ifdef OR1200_FPU_IMPLEMENTED
+ `define OR1200_CPUCFGR_OF32S\t\t1\'b1
+`else
+ `define OR1200_CPUCFGR_OF32S\t\t1\'b0
+`endif
+
+`define OR1200_CPUCFGR_OF64S\t\t1\'b0
+`define OR1200_CPUCFGR_OV64S\t\t1\'b0
+`define OR1200_CPUCFGR_RES1\t\t22\'h000000
+
+// DMMUCFGR fields
+`define OR1200_DMMUCFGR_NTW_BITS\t1:0
+`define OR1200_DMMUCFGR_NTS_BITS\t4:2
+`define OR1200_DMMUCFGR_NAE_BITS\t7:5
+`define OR1200_DMMUCFGR_CRI_BITS\t8
+`define OR1200_DMMUCFGR_PRI_BITS\t9
+`define OR1200_DMMUCFGR_TEIRI_BITS\t10
+`define OR1200_DMMUCFGR_HTR_BITS\t11
+`define OR1200_DMMUCFGR_RES1_BITS\t31:12
+
+// DMMUCFGR values
+`ifdef OR1200_NO_DMMU
+`define OR1200_DMMUCFGR_NTW\t\t2\'h0\t// Irrelevant
+`define OR1200_DMMUCFGR_NTS\t\t3\'h0\t// Irrelevant
+`define OR1200_DMMUCFGR_NAE\t\t3\'h0\t// Irrelevant
+`define OR1200_DMMUCFGR_CRI\t\t1\'b0\t// Irrelevant
+`define OR1200_DMMUCFGR_PRI\t\t1\'b0\t// Irrelevant
+`define OR1200_DMMUCFGR_TEIRI\t\t1\'b0\t// Irrelevant
+`define OR1200_DMMUCFGR_HTR\t\t1\'b0\t// Irrelevant
+`define OR1200_DMMUCFGR_RES1\t\t20\'h00000
+`else
+`define OR1200_DMMUCFGR_NTW\t\t2\'h0\t// 1 TLB way
+`define OR1200_DMMUCFGR_NTS 3\'h`OR1200_DTLB_INDXW\t// Num TLB sets
+`define OR1200_DMMUCFGR_NAE\t\t3\'h0\t// No ATB entries
+`define OR1200_DMMUCFGR_CRI\t\t1\'b0\t// No control register
+`define OR1200_DMMUCFGR_PRI\t\t1\'b0\t// No protection reg
+`define OR1200_DMMUCFGR_TEIRI\t\t1\'b0\t// TLB entry inv reg NOT impl.
+`define OR1200_DMMUCFGR_HTR\t\t1\'b0\t// No HW TLB reload
+`define OR1200_DMMUCFGR_RES1\t\t20\'h00000
+`endif
+
+// IMMUCFGR fields
+`define OR1200_IMMUCFGR_NTW_BITS\t1:0
+`define OR1200_IMMUCFGR_NTS_BITS\t4:2
+`define OR1200_IMMUCFGR_NAE_BITS\t7:5
+`define OR1200_IMMUCFGR_CRI_BITS\t8
+`define OR1200_IMMUCFGR_PRI_BITS\t9
+`define OR1200_IMMUCFGR_TEIRI_BITS\t10
+`define OR1200_IMMUCFGR_HTR_BITS\t11
+`define OR1200_IMMUCFGR_RES1_BITS\t31:12
+
+// IMMUCFGR values
+`ifdef OR1200_NO_IMMU
+`define OR1200_IMMUCFGR_NTW\t\t2\'h0\t// Irrelevant
+`define OR1200_IMMUCFGR_NTS\t\t3\'h0\t// Irrelevant
+`define OR1200_IMMUCFGR_NAE\t\t3\'h0\t// Irrelevant
+`define OR1200_IMMUCFGR_CRI\t\t1\'b0\t// Irrelevant
+`define OR1200_IMMUCFGR_PRI\t\t1\'b0\t// Irrelevant
+`define OR1200_IMMUCFGR_TEIRI\t\t1\'b0\t// Irrelevant
+`define OR1200_IMMUCFGR_HTR\t\t1\'b0\t// Irrelevant
+`define OR1200_IMMUCFGR_RES1\t\t20\'h00000
+`else
+`define OR1200_IMMUCFGR_NTW\t\t2\'h0\t// 1 TLB way
+`define OR1200_IMMUCFGR_NTS 3\'h`OR1200_ITLB_INDXW\t// Num TLB sets
+`define OR1200_IMMUCFGR_NAE\t\t3\'h0\t// No ATB entry
+`define OR1200_IMMUCFGR_CRI\t\t1\'b0\t// No control reg
+`define OR1200_IMMUCFGR_PRI\t\t1\'b0\t// No protection reg
+`define OR1200_IMMUCFGR_TEIRI\t\t1\'b0\t// TLB entry inv reg NOT impl
+`define OR1200_IMMUCFGR_HTR\t\t1\'b0\t// No HW TLB reload
+`define OR1200_IMMUCFGR_RES1\t\t20\'h00000
+`endif
+
+// DCCFGR fields
+`define OR1200_DCCFGR_NCW_BITS\t\t2:0
+`define OR1200_DCCFGR_NCS_BITS\t\t6:3
+`define OR1200_DCCFGR_CBS_BITS\t\t7
+`define OR1200_DCCFGR_CWS_BITS\t\t8
+`define OR1200_DCCFGR_CCRI_BITS\t\t9
+`define OR1200_DCCFGR_CBIRI_BITS\t10
+`define OR1200_DCCFGR_CBPRI_BITS\t11
+`define OR1200_DCCFGR_CBLRI_BITS\t12
+`define OR1200_DCCFGR_CBFRI_BITS\t13
+`define OR1200_DCCFGR_CBWBRI_BITS\t14
+`define OR1200_DCCFGR_RES1_BITS\t31:15
+
+// DCCFGR values
+`ifdef OR1200_NO_DC
+`define OR1200_DCCFGR_NCW\t\t3\'h0\t// Irrelevant
+`define OR1200_DCCFGR_NCS\t\t4\'h0\t// Irrelevant
+`define OR1200_DCCFGR_CBS\t\t1\'b0\t// Irrelevant
+`define OR1200_DCCFGR_CWS\t\t1\'b0\t// Irrelevant
+`define OR1200_DCCFGR_CCRI\t\t1\'b0\t// Irrelevant
+`define OR1200_DCCFGR_CBIRI\t\t1\'b0\t// Irrelevant
+`define OR1200_DCCFGR_CBPRI\t\t1\'b0\t// Irrelevant
+`define OR1200_DCCFGR_CBLRI\t\t1\'b0\t// Irrelevant
+`define OR1200_DCCFGR_CBFRI\t\t1\'b0\t// Irrelevant
+`define OR1200_DCCFGR_CBWBRI\t\t1\'b0\t// Irrelevant
+`define OR1200_DCCFGR_RES1\t\t17\'h00000
+`else
+`define OR1200_DCCFGR_NCW\t\t3\'h0\t// 1 cache way
+`define OR1200_DCCFGR_NCS (`OR1200_DCTAG)\t// Num cache sets
+`define OR1200_DCCFGR_CBS `OR1200_DCLS==4 ? 1\'b0 : 1\'b1 // 16 byte cache block
+`ifdef OR1200_DC_WRITETHROUGH
+ `define OR1200_DCCFGR_CWS\t\t1\'b0\t// Write-through strategy
+`else
+ `define OR1200_DCCFGR_CWS\t\t1\'b1\t// Write-back strategy
+`endif
+`define OR1200_DCCFGR_CCRI\t\t1\'b1\t// Cache control reg impl.
+`define OR1200_DCCFGR_CBIRI\t\t1\'b1\t// Cache block inv reg impl.
+`define OR1200_DCCFGR_CBPRI\t\t1\'b0\t// Cache block prefetch reg not impl.
+`define OR1200_DCCFGR_CBLRI\t\t1\'b0\t// Cache block lock reg not impl.
+`define OR1200_DCCFGR_CBFRI\t\t1\'b1\t// Cache block flush reg impl.
+`ifdef OR1200_DC_WRITETHROUGH
+ `define OR1200_DCCFGR_CBWBRI\t\t1\'b0\t// Cache block WB reg not impl.
+`else
+ `define OR1200_DCCFGR_CBWBRI\t\t1\'b1\t// Cache block WB reg impl.
+`endif
+`define OR1200_DCCFGR_RES1\t\t17\'h00000
+`endif
+
+// ICCFGR fields
+`define OR1200_ICCFGR_NCW_BITS\t\t2:0
+`define OR1200_ICCFGR_NCS_BITS\t\t6:3
+`define OR1200_ICCFGR_CBS_BITS\t\t7
+`define OR1200_ICCFGR_CWS_BITS\t\t8
+`define OR1200_ICCFGR_CCRI_BITS\t\t9
+`define OR1200_ICCFGR_CBIRI_BITS\t10
+`define OR1200_ICCFGR_CBPRI_BITS\t11
+`define OR1200_ICCFGR_CBLRI_BITS\t12
+`define OR1200_ICCFGR_CBFRI_BITS\t13
+`define OR1200_ICCFGR_CBWBRI_BITS\t14
+`define OR1200_ICCFGR_RES1_BITS\t31:15
+
+// ICCFGR values
+`ifdef OR1200_NO_IC
+`define OR1200_ICCFGR_NCW\t\t3\'h0\t// Irrelevant
+`define OR1200_ICCFGR_NCS \t\t4\'h0\t// Irrelevant
+`define OR1200_ICCFGR_CBS \t\t1\'b0\t// Irrelevant
+`define OR1200_ICCFGR_CWS\t\t1\'b0\t// Irrelevant
+`define OR1200_ICCFGR_CCRI\t\t1\'b0\t// Irrelevant
+`define OR1200_ICCFGR_CBIRI\t\t1\'b0\t// Irrelevant
+`define OR1200_ICCFGR_CBPRI\t\t1\'b0\t// Irrelevant
+`define OR1200_ICCFGR_CBLRI\t\t1\'b0\t// Irrelevant
+`define OR1200_ICCFGR_CBFRI\t\t1\'b0\t// Irrelevant
+`define OR1200_ICCFGR_CBWBRI\t\t1\'b0\t// Irrelevant
+`define OR1200_ICCFGR_RES1\t\t17\'h00000
+`else
+`define OR1200_ICCFGR_NCW\t\t3\'h0\t// 1 cache way
+`define OR1200_ICCFGR_NCS (`OR1200_ICTAG)\t// Num cache sets
+`define OR1200_ICCFGR_CBS `OR1200_ICLS==4 ? 1\'b0: 1\'b1\t// 16 byte cache block
+`define OR1200_ICCFGR_CWS\t\t1\'b0\t// Irrelevant
+`define OR1200_ICCFGR_CCRI\t\t1\'b1\t// Cache control reg impl.
+`define OR1200_ICCFGR_CBIRI\t\t1\'b1\t// Cache block inv reg impl.
+`define OR1200_ICCFGR_CBPRI\t\t1\'b0\t// Cache block prefetch reg not impl.
+`define OR1200_ICCFGR_CBLRI\t\t1\'b0\t// Cache block lock reg not impl.
+`define OR1200_ICCFGR_CBFRI\t\t1\'b1\t// Cache block flush reg impl.
+`define OR1200_ICCFGR_CBWBRI\t\t1\'b0\t// Irrelevant
+`define OR1200_ICCFGR_RES1\t\t17\'h00000
+`endif
+
+// DCFGR fields
+`define OR1200_DCFGR_NDP_BITS\t\t3:0
+`define OR1200_DCFGR_WPCI_BITS\t\t4
+`define OR1200_DCFGR_RES1_BITS\t\t31:5
+
+// DCFGR values
+`ifdef OR1200_DU_HWBKPTS
+`define OR1200_DCFGR_NDP\t\t4\'h`OR1200_DU_DVRDCR_PAIRS // # of DVR/DCR pairs
+`ifdef OR1200_DU_DWCR0
+`define OR1200_DCFGR_WPCI\t\t1\'b1
+`else
+`define OR1200_DCFGR_WPCI\t\t1\'b0\t// WP counters not impl.
+`endif
+`else
+`define OR1200_DCFGR_NDP\t\t4\'h0\t// Zero DVR/DCR pairs
+`define OR1200_DCFGR_WPCI\t\t1\'b0\t// WP counters not impl.
+`endif
+`define OR1200_DCFGR_RES1\t\t27\'d0
+
+///////////////////////////////////////////////////////////////////////////////
+// Boot Address Selection //
+// //
+// Allows a definable boot address, potentially different to the usual reset //
+// vector to allow for power-on code to be run, if desired. //
+// //
+// OR1200_BOOT_ADR should be the 32-bit address of the boot location //
+// OR1200_BOOT_PCREG_DEFAULT should be ((OR1200_BOOT_ADR-4)>>2) //
+// //
+// For default reset behavior uncomment the settings under the ""Boot 0x100"" //
+// comment below. //
+// //
+///////////////////////////////////////////////////////////////////////////////
+// Boot from 0xf0000100
+//`define OR1200_BOOT_PCREG_DEFAULT 30\'h3c00003f
+//`define OR1200_BOOT_ADR 32\'hf0000100
+// Boot from 0x100
+`define OR1200_BOOT_PCREG_DEFAULT 30\'h0000003f
+`define OR1200_BOOT_ADR 32\'h00000100
+"
+"//////////////////////////////////////////////////////////////////////
+//// ////
+//// ROM ////
+//// ////
+//// Author(s): ////
+//// - Michael Unneback (unneback@opencores.org) ////
+//// - Julius Baxter (julius@opencores.org) ////
+//// ////
+//////////////////////////////////////////////////////////////////////
+//// ////
+//// Copyright (C) 2009 Authors ////
+//// ////
+//// This source file may be used and distributed without ////
+//// restriction provided that this copyright statement is not ////
+//// removed from the file and that any derivative work contains ////
+//// the original copyright notice and the associated disclaimer. ////
+//// ////
+//// This source file is free software; you can redistribute it ////
+//// and/or modify it under the terms of the GNU Lesser General ////
+//// Public License as published by the Free Software Foundation; ////
+//// either version 2.1 of the License, or (at your option) any ////
+//// later version. ////
+//// ////
+//// This source is distributed in the hope that it will be ////
+//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
+//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
+//// PURPOSE. See the GNU Lesser General Public License for more ////
+//// details. ////
+//// ////
+//// You should have received a copy of the GNU Lesser General ////
+//// Public License along with this source; if not, download it ////
+//// from http://www.opencores.org/lgpl.shtml ////
+//// ////
+//////////////////////////////////////////////////////////////////////
+
+module bootrom
+ #(parameter addr_width = 5,
+ parameter b3_burst = 0)
+ (
+ input \t\t wb_clk,
+ input \t\t wb_rst,
+ input [(addr_width+2)-1:2] wb_adr_i,
+ input \t\t wb_stb_i,
+ input \t\t wb_cyc_i,
+ input [2:0] \t wb_cti_i,
+ input [1:0] \t wb_bte_i,
+ output reg [31:0] \t wb_dat_o,
+ output reg \t\t wb_ack_o);
+
+ reg [addr_width-1:0] \t adr;
+
+ always @ (posedge wb_clk or posedge wb_rst)
+ if (wb_rst)
+ wb_dat_o <= 32\'h15000000;
+ else
+ case (adr)
+`include ""bootrom_data.vh""
+/*
+\t // Zero r0 and endless loop
+\t 0 : wb_dat_o <= 32\'h18000000;
+\t 1 : wb_dat_o <= 32\'hA8200000;
+\t 2 : wb_dat_o <= 32\'hA8C00100;
+\t 3 : wb_dat_o <= 32\'h00000000;
+\t 4 : wb_dat_o <= 32\'h15000000;
+*/
+/*
+\t // Zero r0 and jump to 0x00000100
+\t 0 : wb_dat_o <= 32\'h18000000;
+\t 1 : wb_dat_o <= 32\'hA8200000;
+\t 2 : wb_dat_o <= 32\'hA8C00100;
+\t 3 : wb_dat_o <= 32\'h44003000;
+\t 4 : wb_dat_o <= 32\'h15000000;
+ */
+\t default:
+\t wb_dat_o <= 32\'h00000000;
+ endcase // case (wb_adr_i)
+
+generate
+if(b3_burst) begin : gen_b3_burst
+ reg \t\t\t\t wb_stb_i_r;
+ reg \t\t\t\t new_access_r;
+ reg \t\t\t\t burst_r;
+\t
+ wire burst = wb_cyc_i & (!(wb_cti_i == 3\'b000)) & (!(wb_cti_i == 3\'b111));
+ wire new_access = (wb_stb_i & !wb_stb_i_r);
+ wire new_burst = (burst & !burst_r);
+
+ always @(posedge wb_clk) begin
+ new_access_r <= new_access;
+ burst_r <= burst;
+ wb_stb_i_r <= wb_stb_i;
+ end
+
+
+ always @(posedge wb_clk)
+ if (wb_rst)
+ adr <= 0;
+ else if (new_access)
+ // New access, register address, ack a cycle later
+ adr <= wb_adr_i[(addr_width+2)-1:2];
+ else if (burst) begin
+\tif (wb_cti_i == 3\'b010)
+\t case (wb_bte_i)
+\t 2\'b00: adr <= adr + 1;
+\t 2\'b01: adr[1:0] <= adr[1:0] + 1;
+\t 2\'b10: adr[2:0] <= adr[2:0] + 1;
+\t 2\'b11: adr[3:0] <= adr[3:0] + 1;
+\t endcase // case (wb_bte_i)
+\telse
+\t adr <= wb_adr_i[(addr_width+2)-1:2];
+ end // if (burst)
+
+
+ always @(posedge wb_clk)
+ if (wb_rst)
+ wb_ack_o <= 0;
+ else if (wb_ack_o & (!burst | (wb_cti_i == 3\'b111)))
+ wb_ack_o <= 0;
+ else if (wb_stb_i & ((!burst & !new_access & new_access_r) | (burst & burst_r)))
+ wb_ack_o <= 1;
+ else
+ wb_ack_o <= 0;
+
+ end else begin
+\talways @(wb_adr_i)
+\t adr <= wb_adr_i;
+\t
+\talways @ (posedge wb_clk or posedge wb_rst)
+\t if (wb_rst)
+\t wb_ack_o <= 1\'b0;
+\t else
+\t wb_ack_o <= wb_stb_i & wb_cyc_i & !wb_ack_o;
+\t
+ end
+endgenerate
+endmodule
+"
+"//////////////////////////////////////////////////////////////////////
+//// ////
+//// orpsoc-defines ////
+//// ////
+//// Top level ORPSoC defines file ////
+//// ////
+//// Included in toplevel and testbench ////
+//// ////
+//////////////////////////////////////////////////////////////////////
+//// ////
+//// Copyright (C) 2009, 2010 Authors and OPENCORES.ORG ////
+//// ////
+//// This source file may be used and distributed without ////
+//// restriction provided that this copyright statement is not ////
+//// removed from the file and that any derivative work contains ////
+//// the original copyright notice and the associated disclaimer. ////
+//// ////
+//// This source file is free software; you can redistribute it ////
+//// and/or modify it under the terms of the GNU Lesser General ////
+//// Public License as published by the Free Software Foundation; ////
+//// either version 2.1 of the License, or (at your option) any ////
+//// later version. ////
+//// ////
+//// This source is distributed in the hope that it will be ////
+//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
+//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
+//// PURPOSE. See the GNU Lesser General Public License for more ////
+//// details. ////
+//// ////
+//// You should have received a copy of the GNU Lesser General ////
+//// Public License along with this source; if not, download it ////
+//// from http://www.opencores.org/lgpl.shtml ////
+//// ////
+//////////////////////////////////////////////////////////////////////
+
+// Included modules: define to include
+`define OR1200_CPU
+// end of included module defines - keep this comment line here
+"
+"//////////////////////////////////////////////////////////////////////
+//// ////
+//// uart_defines.v ////
+//// ////
+//// ////
+//// This file is part of the ""UART 16550 compatible"" project ////
+//// http://www.opencores.org/cores/uart16550/ ////
+//// ////
+//// Documentation related to this project: ////
+//// - http://www.opencores.org/cores/uart16550/ ////
+//// ////
+//// Projects compatibility: ////
+//// - WISHBONE ////
+//// RS232 Protocol ////
+//// 16550D uart (mostly supported) ////
+//// ////
+//// Overview (main Features): ////
+//// Defines of the Core ////
+//// ////
+//// Known problems (limits): ////
+//// None ////
+//// ////
+//// To Do: ////
+//// Nothing. ////
+//// ////
+//// Author(s): ////
+//// - gorban@opencores.org ////
+//// - Jacob Gorban ////
+//// - Igor Mohor (igorm@opencores.org) ////
+//// ////
+//// Created: 2001/05/12 ////
+//// Last Updated: 2001/05/17 ////
+//// (See log for the revision history) ////
+//// ////
+//// ////
+//////////////////////////////////////////////////////////////////////
+//// ////
+//// Copyright (C) 2000, 2001 Authors ////
+//// ////
+//// This source file may be used and distributed without ////
+//// restriction provided that this copyright statement is not ////
+//// removed from the file and that any derivative work contains ////
+//// the original copyright notice and the associated disclaimer. ////
+//// ////
+//// This source file is free software; you can redistribute it ////
+//// and/or modify it under the terms of the GNU Lesser General ////
+//// Public License as published by the Free Software Foundation; ////
+//// either version 2.1 of the License, or (at your option) any ////
+//// later version. ////
+//// ////
+//// This source is distributed in the hope that it will be ////
+//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
+//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
+//// PURPOSE. See the GNU Lesser General Public License for more ////
+//// details. ////
+//// ////
+//// You should have received a copy of the GNU Lesser General ////
+//// Public License along with this source; if not, download it ////
+//// from http://www.opencores.org/lgpl.shtml ////
+//// ////
+//////////////////////////////////////////////////////////////////////
+//
+// CVS Revision History
+//
+// $Log: not supported by cvs2svn $
+// Revision 1.13 2003/06/11 16:37:47 gorban
+// This fixes errors in some cases when data is being read and put to the FIFO at the same time. Patch is submitted by Scott Furman. Update is very recommended.
+//
+// Revision 1.12 2002/07/22 23:02:23 gorban
+// Bug Fixes:
+// * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
+// Problem reported by Kenny.Tung.
+// * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
+//
+// Improvements:
+// * Made FIFO\'s as general inferrable memory where possible.
+// So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
+// This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
+//
+// * Added optional baudrate output (baud_o).
+// This is identical to BAUDOUT* signal on 16550 chip.
+// It outputs 16xbit_clock_rate - the divided clock.
+// It\'s disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
+//
+// Revision 1.10 2001/12/11 08:55:40 mohor
+// Scratch register define added.
+//
+// Revision 1.9 2001/12/03 21:44:29 gorban
+// Updated specification documentation.
+// Added full 32-bit data bus interface, now as default.
+// Address is 5-bit wide in 32-bit data bus mode.
+// Added wb_sel_i input to the core. It\'s used in the 32-bit mode.
+// Added debug interface with two 32-bit read-only registers in 32-bit mode.
+// Bits 5 and 6 of LSR are now only cleared on TX FIFO write.
+// My small test bench is modified to work with 32-bit mode.
+//
+// Revision 1.8 2001/11/26 21:38:54 gorban
+// Lots of fixes:
+// Break condition wasn\'t handled correctly at all.
+// LSR bits could lose their values.
+// LSR value after reset was wrong.
+// Timing of THRE interrupt signal corrected.
+// LSR bit 0 timing corrected.
+//
+// Revision 1.7 2001/08/24 21:01:12 mohor
+// Things connected to parity changed.
+// Clock devider changed.
+//
+// Revision 1.6 2001/08/23 16:05:05 mohor
+// Stop bit bug fixed.
+// Parity bug fixed.
+// WISHBONE read cycle bug fixed,
+// OE indicator (Overrun Error) bug fixed.
+// PE indicator (Parity Error) bug fixed.
+// Register read bug fixed.
+//
+// Revision 1.5 2001/05/31 20:08:01 gorban
+// FIFO changes and other corrections.
+//
+// Revision 1.4 2001/05/21 19:12:02 gorban
+// Corrected some Linter messages.
+//
+// Revision 1.3 2001/05/17 18:34:18 gorban
+// First \'stable\' release. Should be sythesizable now. Also added new header.
+//
+// Revision 1.0 2001-05-17 21:27:11+02 jacob
+// Initial revision
+//
+//
+
+// remove comments to restore to use the new version with 8 data bit interface
+// in 32bit-bus mode, the wb_sel_i signal is used to put data in correct place
+// also, in 8-bit version there\'ll be no debugging features included
+// CAUTION: doesn\'t work with current version of OR1200
+`define DATA_BUS_WIDTH_8
+
+`ifdef DATA_BUS_WIDTH_8
+ `define UART_ADDR_WIDTH 3
+ `define UART_DATA_WIDTH 8
+`else
+ `define UART_ADDR_WIDTH 5
+ `define UART_DATA_WIDTH 32
+`endif
+
+// Uncomment this if you want your UART to have
+// 16xBaudrate output port.
+// If defined, the enable signal will be used to drive baudrate_o signal
+// It\'s frequency is 16xbaudrate
+
+// `define UART_HAS_BAUDRATE_OUTPUT
+
+// Register addresses
+`define UART_REG_RB\t`UART_ADDR_WIDTH\'d0\t// receiver buffer
+`define UART_REG_TR `UART_ADDR_WIDTH\'d0\t// transmitter
+`define UART_REG_IE\t`UART_ADDR_WIDTH\'d1\t// Interrupt enable
+`define UART_REG_II `UART_ADDR_WIDTH\'d2\t// Interrupt identification
+`define UART_REG_FC `UART_ADDR_WIDTH\'d2\t// FIFO control
+`define UART_REG_LC\t`UART_ADDR_WIDTH\'d3\t// Line Control
+`define UART_REG_MC\t`UART_ADDR_WIDTH\'d4\t// Modem control
+`define UART_REG_LS `UART_ADDR_WIDTH\'d5\t// Line status
+`define UART_REG_MS `UART_ADDR_WIDTH\'d6\t// Modem status
+`define UART_REG_SR `UART_ADDR_WIDTH\'d7\t// Scratch register
+`define UART_REG_DL1\t`UART_ADDR_WIDTH\'d0\t// Divisor latch bytes (1-2)
+`define UART_REG_DL2\t`UART_ADDR_WIDTH\'d1
+
+// Interrupt Enable register bits
+`define UART_IE_RDA\t0\t// Received Data available interrupt
+`define UART_IE_THRE\t1\t// Transmitter Holding Register empty interrupt
+`define UART_IE_RLS\t2\t// Receiver Line Status Interrupt
+`define UART_IE_MS\t3\t// Modem Status Interrupt
+
+// Interrupt Identification register bits
+`define UART_II_IP\t0\t// Interrupt pending when 0
+`define UART_II_II\t3:1\t// Interrupt identification
+
+// Interrupt identification values for bits 3:1
+`define UART_II_RLS\t3\'b011\t// Receiver Line Status
+`define UART_II_RDA\t3\'b010\t// Receiver Data available
+`define UART_II_TI\t3\'b110\t// Timeout Indication
+`define UART_II_THRE\t3\'b001\t// Transmitter Holding Register empty
+`define UART_II_MS\t3\'b000\t// Modem Status
+
+// FIFO Control Register bits
+`define UART_FC_TL\t1:0\t// Trigger level
+
+// FIFO trigger level values
+`define UART_FC_1\t\t2\'b00
+`define UART_FC_4\t\t2\'b01
+`define UART_FC_8\t\t2\'b10
+`define UART_FC_14\t2\'b11
+
+// Line Control register bits
+`define UART_LC_BITS\t1:0\t// bits in character
+`define UART_LC_SB\t2\t// stop bits
+`define UART_LC_PE\t3\t// parity enable
+`define UART_LC_EP\t4\t// even parity
+`define UART_LC_SP\t5\t// stick parity
+`define UART_LC_BC\t6\t// Break control
+`define UART_LC_DL\t7\t// Divisor Latch access bit
+
+// Modem Control register bits
+`define UART_MC_DTR\t0
+`define UART_MC_RTS\t1
+`define UART_MC_OUT1\t2
+`define UART_MC_OUT2\t3
+`define UART_MC_LB\t4\t// Loopback mode
+
+// Line Status Register bits
+`define UART_LS_DR\t0\t// Data ready
+`define UART_LS_OE\t1\t// Overrun Error
+`define UART_LS_PE\t2\t// Parity Error
+`define UART_LS_FE\t3\t// Framing Error
+`define UART_LS_BI\t4\t// Break interrupt
+`define UART_LS_TFE\t5\t// Transmit FIFO is empty
+`define UART_LS_TE\t6\t// Transmitter Empty indicator
+`define UART_LS_EI\t7\t// Error indicator
+
+// Modem Status Register bits
+`define UART_MS_DCTS\t0\t// Delta signals
+`define UART_MS_DDSR\t1
+`define UART_MS_TERI\t2
+`define UART_MS_DDCD\t3
+`define UART_MS_CCTS\t4\t// Complement signals
+`define UART_MS_CDSR\t5
+`define UART_MS_CRI\t6
+`define UART_MS_CDCD\t7
+
+// FIFO parameter defines
+
+`define UART_FIFO_WIDTH\t8
+`define UART_FIFO_DEPTH\t16
+`define UART_FIFO_POINTER_W\t4
+`define UART_FIFO_COUNTER_W\t5
+// receiver fifo has width 11 because it has break, parity and framing error bits
+`define UART_FIFO_REC_WIDTH 11
+
+
+`define VERBOSE_WB 0 // All activity on the WISHBONE is recorded
+`define VERBOSE_LINE_STATUS 0 // Details about the lsr (line status register)
+`define FAST_TEST 1 // 64/1024 packets are sent
+
+// Defines hard baud prescaler register - uncomment to enable
+//`define PRESCALER_PRESET_HARD
+// 115200 baud preset values
+// 20MHz: prescaler 10.8 (11, rounded up)
+//`define PRESCALER_HIGH_PRESET 8\'d0
+//`define PRESCALER_LOW_PRESET 8\'d11
+// 50MHz: prescaler 27.1
+//`define PRESCALER_HIGH_PRESET 8\'d0
+//`define PRESCALER_LOW_PRESET 8\'d27
+"
+"LIBAVFORMAT_MAJOR {
+ global:
+ av*;
+ #FIXME those are for ffserver
+ ff_inet_aton;
+ ff_socket_nonblock;
+ ff_rtsp_parse_line;
+ ff_rtp_get_local_rtp_port;
+ ff_rtp_get_local_rtcp_port;
+ ffio_open_dyn_packet_buf;
+ ffio_set_buf_size;
+ ffurl_close;
+ ffurl_open;
+ ffurl_write;
+ #those are deprecated, remove on next bump
+ url_feof;
+ local:
+ *;
+};
+"
+"LIBSWRESAMPLE_MAJOR {
+ global:
+ swr_*;
+ swresample_*;
+ local:
+ *;
+};
+"
+"LIBAVDEVICE_MAJOR {
+ global:
+ avdevice_*;
+ av_*;
+ local:
+ *;
+};
+"
+"LIBAVCODEC_MAJOR {
+ global:
+ av*;
+ #deprecated, remove after next bump
+ audio_resample;
+ audio_resample_close;
+ local:
+ *;
+};
+"
+"LIBSWSCALE_MAJOR {
+ global:
+ swscale_*;
+ sws_*;
+ local:
+ *;
+};
+"
+"LIBAVRESAMPLE_MAJOR {
+ global:
+ av*;
+ local:
+ *;
+};
+"
+"LIBAVFILTER_MAJOR {
+ global:
+ avfilter_*;
+ av_*;
+ local:
+ *;
+};
+"
+"LIBAVUTIL_MAJOR {
+ global:
+ av*;
+ local:
+ *;
+};
+"
+"LIBPOSTPROC_MAJOR {
+ global:
+ postproc_*;
+ pp_*;
+ local:
+ *;
+};
+"
+"module HeaderRam(d, waddr, raddr, we, clk, q);\r
+output [7:0] q;\r
+input [7:0] d;\r
+input[9:0] raddr;\r
+input[9:0] waddr;\r
+input clk, we;\r
+\r
+reg [9:0] read_addr;\r
+reg[7:0] mem [1023:0] /* synthesis syn_ramstyle=""block_ram"" */;\r
+\r
+initial $readmemh(""../design/jfifgen/header.hex"", mem);\r
+\r
+assign q = mem[read_addr];\r
+\r
+always @(posedge clk) begin\r
+if (we)\r
+mem[waddr] <= d;\r
+read_addr <= raddr;\r
+end\r
+\r
+endmodule\r
+"
+"//IEEE Floating Point Adder (Single Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+
+module adder(
+ input_a,
+ input_b,
+ input_a_stb,
+ input_b_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack,
+ input_b_ack);
+
+ input clk;
+ input rst;
+
+ input [31:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ input [31:0] input_b;
+ input input_b_stb;
+ output input_b_ack;
+
+ output [31:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [31:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [3:0] state;
+ parameter get_a = 4'd0,
+ get_b = 4'd1,
+ unpack = 4'd2,
+ special_cases = 4'd3,
+ align = 4'd4,
+ add_0 = 4'd5,
+ add_1 = 4'd6,
+ normalise_1 = 4'd7,
+ normalise_2 = 4'd8,
+ round = 4'd9,
+ pack = 4'd10,
+ put_z = 4'd11;
+
+ reg [31:0] a, b, z;
+ reg [26:0] a_m, b_m;
+ reg [23:0] z_m;
+ reg [9:0] a_e, b_e, z_e;
+ reg a_s, b_s, z_s;
+ reg guard, round_bit, sticky;
+ reg [27:0] sum;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= get_b;
+ end
+ end
+
+ get_b:
+ begin
+ s_input_b_ack <= 1;
+ if (s_input_b_ack && input_b_stb) begin
+ b <= input_b;
+ s_input_b_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m <= {a[22 : 0], 3'd0};
+ b_m <= {b[22 : 0], 3'd0};
+ a_e <= a[30 : 23] - 127;
+ b_e <= b[30 : 23] - 127;
+ a_s <= a[31];
+ b_s <= b[31];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ //if a is NaN or b is NaN return NaN
+ if ((a_e == 128 && a_m != 0) || (b_e == 128 && b_m != 0)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ //if a is inf return inf
+ end else if (a_e == 128) begin
+ z[31] <= a_s;
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if b is inf return inf
+ end else if (b_e == 128) begin
+ z[31] <= b_s;
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if a is zero return b
+ end else if ((($signed(a_e) == -127) && (a_m == 0)) && (($signed(b_e) == -127) && (b_m == 0))) begin
+ z[31] <= a_s & b_s;
+ z[30:23] <= b_e[7:0] + 127;
+ z[22:0] <= b_m[26:3];
+ state <= put_z;
+ //if a is zero return b
+ end else if (($signed(a_e) == -127) && (a_m == 0)) begin
+ z[31] <= b_s;
+ z[30:23] <= b_e[7:0] + 127;
+ z[22:0] <= b_m[26:3];
+ state <= put_z;
+ //if b is zero return a
+ end else if (($signed(b_e) == -127) && (b_m == 0)) begin
+ z[31] <= a_s;
+ z[30:23] <= a_e[7:0] + 127;
+ z[22:0] <= a_m[26:3];
+ state <= put_z;
+ end else begin
+ //Denormalised Number
+ if ($signed(a_e) == -127) begin
+ a_e <= -126;
+ end else begin
+ a_m[26] <= 1;
+ end
+ //Denormalised Number
+ if ($signed(b_e) == -127) begin
+ b_e <= -126;
+ end else begin
+ b_m[26] <= 1;
+ end
+ state <= align;
+ end
+ end
+
+ align:
+ begin
+ if ($signed(a_e) > $signed(b_e)) begin
+ b_e <= b_e + 1;
+ b_m <= b_m >> 1;
+ b_m[0] <= b_m[0] | b_m[1];
+ end else if ($signed(a_e) < $signed(b_e)) begin
+ a_e <= a_e + 1;
+ a_m <= a_m >> 1;
+ a_m[0] <= a_m[0] | a_m[1];
+ end else begin
+ state <= add_0;
+ end
+ end
+
+ add_0:
+ begin
+ z_e <= a_e;
+ if (a_s == b_s) begin
+ sum <= a_m + b_m;
+ z_s <= a_s;
+ end else begin
+ if (a_m >= b_m) begin
+ sum <= a_m - b_m;
+ z_s <= a_s;
+ end else begin
+ sum <= b_m - a_m;
+ z_s <= b_s;
+ end
+ end
+ state <= add_1;
+ end
+
+ add_1:
+ begin
+ if (sum[27]) begin
+ z_m <= sum[27:4];
+ guard <= sum[3];
+ round_bit <= sum[2];
+ sticky <= sum[1] | sum[0];
+ z_e <= z_e + 1;
+ end else begin
+ z_m <= sum[26:3];
+ guard <= sum[2];
+ round_bit <= sum[1];
+ sticky <= sum[0];
+ end
+ state <= normalise_1;
+ end
+
+ normalise_1:
+ begin
+ if (z_m[23] == 0 && $signed(z_e) > -126) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= guard;
+ guard <= round_bit;
+ round_bit <= 0;
+ end else begin
+ state <= normalise_2;
+ end
+ end
+
+ normalise_2:
+ begin
+ if ($signed(z_e) < -126) begin
+ z_e <= z_e + 1;
+ z_m <= z_m >> 1;
+ guard <= z_m[0];
+ round_bit <= guard;
+ sticky <= sticky | round_bit;
+ end else begin
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit | sticky | z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 24'hffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[22 : 0] <= z_m[22:0];
+ z[30 : 23] <= z_e[7:0] + 127;
+ z[31] <= z_s;
+ if ($signed(z_e) == -126 && z_m[23] == 0) begin
+ z[30 : 23] <= 0;
+ end
+ //if overflow occurs, return inf
+ if ($signed(z_e) > 127) begin
+ z[22 : 0] <= 0;
+ z[30 : 23] <= 255;
+ z[31] <= z_s;
+ end
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_input_b_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign input_b_ack = s_input_b_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point Divider (Single Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+//
+module divider(
+ input_a,
+ input_b,
+ input_a_stb,
+ input_b_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack,
+ input_b_ack);
+
+ input clk;
+ input rst;
+
+ input [31:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ input [31:0] input_b;
+ input input_b_stb;
+ output input_b_ack;
+
+ output [31:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [31:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [3:0] state;
+ parameter get_a = 4'd0,
+ get_b = 4'd1,
+ unpack = 4'd2,
+ special_cases = 4'd3,
+ normalise_a = 4'd4,
+ normalise_b = 4'd5,
+ divide_0 = 4'd6,
+ divide_1 = 4'd7,
+ divide_2 = 4'd8,
+ divide_3 = 4'd9,
+ normalise_1 = 4'd10,
+ normalise_2 = 4'd11,
+ round = 4'd12,
+ pack = 4'd13,
+ put_z = 4'd14;
+
+ reg [31:0] a, b, z;
+ reg [23:0] a_m, b_m, z_m;
+ reg [9:0] a_e, b_e, z_e;
+ reg a_s, b_s, z_s;
+ reg guard, round_bit, sticky;
+ reg [50:0] quotient, divisor, dividend, remainder;
+ reg [5:0] count;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= get_b;
+ end
+ end
+
+ get_b:
+ begin
+ s_input_b_ack <= 1;
+ if (s_input_b_ack && input_b_stb) begin
+ b <= input_b;
+ s_input_b_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m <= a[22 : 0];
+ b_m <= b[22 : 0];
+ a_e <= a[30 : 23] - 127;
+ b_e <= b[30 : 23] - 127;
+ a_s <= a[31];
+ b_s <= b[31];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ //if a is NaN or b is NaN return NaN
+ if ((a_e == 128 && a_m != 0) || (b_e == 128 && b_m != 0)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ //if a is inf and b is inf return NaN
+ end else if ((a_e == 128) && (b_e == 128)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ //if a is inf return inf
+ end else if (a_e == 128) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if b is zero return NaN
+ if ($signed(b_e == -127) && (b_m == 0)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ end
+ //if b is inf return zero
+ end else if (b_e == 128) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 0;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if a is zero return zero
+ end else if (($signed(a_e) == -127) && (a_m == 0)) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 0;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if b is zero return NaN
+ if (($signed(b_e) == -127) && (b_m == 0)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ end
+ //if b is zero return inf
+ end else if (($signed(b_e) == -127) && (b_m == 0)) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ state <= put_z;
+ end else begin
+ //Denormalised Number
+ if ($signed(a_e) == -127) begin
+ a_e <= -126;
+ end else begin
+ a_m[23] <= 1;
+ end
+ //Denormalised Number
+ if ($signed(b_e) == -127) begin
+ b_e <= -126;
+ end else begin
+ b_m[23] <= 1;
+ end
+ state <= normalise_a;
+ end
+ end
+
+ normalise_a:
+ begin
+ if (a_m[23]) begin
+ state <= normalise_b;
+ end else begin
+ a_m <= a_m << 1;
+ a_e <= a_e - 1;
+ end
+ end
+
+ normalise_b:
+ begin
+ if (b_m[23]) begin
+ state <= divide_0;
+ end else begin
+ b_m <= b_m << 1;
+ b_e <= b_e - 1;
+ end
+ end
+
+ divide_0:
+ begin
+ z_s <= a_s ^ b_s;
+ z_e <= a_e - b_e;
+ quotient <= 0;
+ remainder <= 0;
+ count <= 0;
+ dividend <= a_m << 27;
+ divisor <= b_m;
+ state <= divide_1;
+ end
+
+ divide_1:
+ begin
+ quotient <= quotient << 1;
+ remainder <= remainder << 1;
+ remainder[0] <= dividend[50];
+ dividend <= dividend << 1;
+ state <= divide_2;
+ end
+
+ divide_2:
+ begin
+ if (remainder >= divisor) begin
+ quotient[0] <= 1;
+ remainder <= remainder - divisor;
+ end
+ if (count == 49) begin
+ state <= divide_3;
+ end else begin
+ count <= count + 1;
+ state <= divide_1;
+ end
+ end
+
+ divide_3:
+ begin
+ z_m <= quotient[26:3];
+ guard <= quotient[2];
+ round_bit <= quotient[1];
+ sticky <= quotient[0] | (remainder != 0);
+ state <= normalise_1;
+ end
+
+ normalise_1:
+ begin
+ if (z_m[23] == 0 && $signed(z_e) > -126) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= guard;
+ guard <= round_bit;
+ round_bit <= 0;
+ end else begin
+ state <= normalise_2;
+ end
+ end
+
+ normalise_2:
+ begin
+ if ($signed(z_e) < -126) begin
+ z_e <= z_e + 1;
+ z_m <= z_m >> 1;
+ guard <= z_m[0];
+ round_bit <= guard;
+ sticky <= sticky | round_bit;
+ end else begin
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit | sticky | z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 24'hffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[22 : 0] <= z_m[22:0];
+ z[30 : 23] <= z_e[7:0] + 127;
+ z[31] <= z_s;
+ if ($signed(z_e) == -126 && z_m[23] == 0) begin
+ z[30 : 23] <= 0;
+ end
+ //if overflow occurs, return inf
+ if ($signed(z_e) > 127) begin
+ z[22 : 0] <= 0;
+ z[30 : 23] <= 255;
+ z[31] <= z_s;
+ end
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_input_b_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign input_b_ack = s_input_b_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point Multiplier (Single Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+module multiplier(
+ input_a,
+ input_b,
+ input_a_stb,
+ input_b_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack,
+ input_b_ack);
+
+ input clk;
+ input rst;
+
+ input [31:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ input [31:0] input_b;
+ input input_b_stb;
+ output input_b_ack;
+
+ output [31:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [31:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [3:0] state;
+ parameter get_a = 4'd0,
+ get_b = 4'd1,
+ unpack = 4'd2,
+ special_cases = 4'd3,
+ normalise_a = 4'd4,
+ normalise_b = 4'd5,
+ multiply_0 = 4'd6,
+ multiply_1 = 4'd7,
+ normalise_1 = 4'd8,
+ normalise_2 = 4'd9,
+ round = 4'd10,
+ pack = 4'd11,
+ put_z = 4'd12;
+
+ reg [31:0] a, b, z;
+ reg [23:0] a_m, b_m, z_m;
+ reg [9:0] a_e, b_e, z_e;
+ reg a_s, b_s, z_s;
+ reg guard, round_bit, sticky;
+ reg [49:0] product;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= get_b;
+ end
+ end
+
+ get_b:
+ begin
+ s_input_b_ack <= 1;
+ if (s_input_b_ack && input_b_stb) begin
+ b <= input_b;
+ s_input_b_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m <= a[22 : 0];
+ b_m <= b[22 : 0];
+ a_e <= a[30 : 23] - 127;
+ b_e <= b[30 : 23] - 127;
+ a_s <= a[31];
+ b_s <= b[31];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ //if a is NaN or b is NaN return NaN
+ if ((a_e == 128 && a_m != 0) || (b_e == 128 && b_m != 0)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ //if a is inf return inf
+ end else if (a_e == 128) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if b is zero return NaN
+ if ($signed(b_e == -127) && (b_m == 0)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ end
+ //if b is inf return inf
+ end else if (b_e == 128) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if a is zero return zero
+ end else if (($signed(a_e) == -127) && (a_m == 0)) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 0;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if b is zero return zero
+ end else if (($signed(b_e) == -127) && (b_m == 0)) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 0;
+ z[22:0] <= 0;
+ state <= put_z;
+ end else begin
+ //Denormalised Number
+ if ($signed(a_e) == -127) begin
+ a_e <= -126;
+ end else begin
+ a_m[23] <= 1;
+ end
+ //Denormalised Number
+ if ($signed(b_e) == -127) begin
+ b_e <= -126;
+ end else begin
+ b_m[23] <= 1;
+ end
+ state <= normalise_a;
+ end
+ end
+
+ normalise_a:
+ begin
+ if (a_m[23]) begin
+ state <= normalise_b;
+ end else begin
+ a_m <= a_m << 1;
+ a_e <= a_e - 1;
+ end
+ end
+
+ normalise_b:
+ begin
+ if (b_m[23]) begin
+ state <= multiply_0;
+ end else begin
+ b_m <= b_m << 1;
+ b_e <= b_e - 1;
+ end
+ end
+
+ multiply_0:
+ begin
+ z_s <= a_s ^ b_s;
+ z_e <= a_e + b_e + 1;
+ product <= a_m * b_m * 4;
+ state <= multiply_1;
+ end
+
+ multiply_1:
+ begin
+ z_m <= product[49:26];
+ guard <= product[25];
+ round_bit <= product[24];
+ sticky <= (product[23:0] != 0);
+ state <= normalise_1;
+ end
+
+ normalise_1:
+ begin
+ if (z_m[23] == 0) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= guard;
+ guard <= round_bit;
+ round_bit <= 0;
+ end else begin
+ state <= normalise_2;
+ end
+ end
+
+ normalise_2:
+ begin
+ if ($signed(z_e) < -126) begin
+ z_e <= z_e + 1;
+ z_m <= z_m >> 1;
+ guard <= z_m[0];
+ round_bit <= guard;
+ sticky <= sticky | round_bit;
+ end else begin
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit | sticky | z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 24'hffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[22 : 0] <= z_m[22:0];
+ z[30 : 23] <= z_e[7:0] + 127;
+ z[31] <= z_s;
+ if ($signed(z_e) == -126 && z_m[23] == 0) begin
+ z[30 : 23] <= 0;
+ end
+ //if overflow occurs, return inf
+ if ($signed(z_e) > 127) begin
+ z[22 : 0] <= 0;
+ z[30 : 23] <= 255;
+ z[31] <= z_s;
+ end
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_input_b_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign input_b_ack = s_input_b_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point Divider (Double Precision)
+//Copyright (C) Jonathan P Dawson 2014
+//2014-01-11
+//
+module double_divider(
+ input_a,
+ input_b,
+ input_a_stb,
+ input_b_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack,
+ input_b_ack);
+
+ input clk;
+ input rst;
+
+ input [63:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ input [63:0] input_b;
+ input input_b_stb;
+ output input_b_ack;
+
+ output [63:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [63:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [3:0] state;
+ parameter get_a = 4'd0,
+ get_b = 4'd1,
+ unpack = 4'd2,
+ special_cases = 4'd3,
+ normalise_a = 4'd4,
+ normalise_b = 4'd5,
+ divide_0 = 4'd6,
+ divide_1 = 4'd7,
+ divide_2 = 4'd8,
+ divide_3 = 4'd9,
+ normalise_1 = 4'd10,
+ normalise_2 = 4'd11,
+ round = 4'd12,
+ pack = 4'd13,
+ put_z = 4'd14;
+
+ reg [63:0] a, b, z;
+ reg [52:0] a_m, b_m, z_m;
+ reg [12:0] a_e, b_e, z_e;
+ reg a_s, b_s, z_s;
+ reg guard, round_bit, sticky;
+ reg [108:0] quotient, divisor, dividend, remainder;
+ reg [6:0] count;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= get_b;
+ end
+ end
+
+ get_b:
+ begin
+ s_input_b_ack <= 1;
+ if (s_input_b_ack && input_b_stb) begin
+ b <= input_b;
+ s_input_b_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m <= a[51 : 0];
+ b_m <= b[51 : 0];
+ a_e <= a[62 : 52] - 1023;
+ b_e <= b[62 : 52] - 1023;
+ a_s <= a[63];
+ b_s <= b[63];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ //if a is NaN or b is NaN return NaN
+ if ((a_e == 1024 && a_m != 0) || (b_e == 1024 && b_m != 0)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ //if a is inf and b is inf return NaN
+ end else if ((a_e == 1024) && (b_e == 1024)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ //if a is inf return inf
+ end else if (a_e == 1024) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 2047;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if b is zero return NaN
+ if ($signed(b_e == -1023) && (b_m == 0)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ end
+ //if b is inf return zero
+ end else if (b_e == 1024) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 0;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if a is zero return zero
+ end else if (($signed(a_e) == -1023) && (a_m == 0)) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 0;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if b is zero return NaN
+ if (($signed(b_e) == -1023) && (b_m == 0)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ end
+ //if b is zero return inf
+ end else if (($signed(b_e) == -1023) && (b_m == 0)) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 2047;
+ z[51:0] <= 0;
+ state <= put_z;
+ end else begin
+ //Denormalised Number
+ if ($signed(a_e) == -1023) begin
+ a_e <= -1022;
+ end else begin
+ a_m[52] <= 1;
+ end
+ //Denormalised Number
+ if ($signed(b_e) == -1023) begin
+ b_e <= -1022;
+ end else begin
+ b_m[52] <= 1;
+ end
+ state <= normalise_a;
+ end
+ end
+
+ normalise_a:
+ begin
+ if (a_m[52]) begin
+ state <= normalise_b;
+ end else begin
+ a_m <= a_m << 1;
+ a_e <= a_e - 1;
+ end
+ end
+
+ normalise_b:
+ begin
+ if (b_m[52]) begin
+ state <= divide_0;
+ end else begin
+ b_m <= b_m << 1;
+ b_e <= b_e - 1;
+ end
+ end
+
+ divide_0:
+ begin
+ z_s <= a_s ^ b_s;
+ z_e <= a_e - b_e;
+ quotient <= 0;
+ remainder <= 0;
+ count <= 0;
+ dividend <= a_m << 56;
+ divisor <= b_m;
+ state <= divide_1;
+ end
+
+ divide_1:
+ begin
+ quotient <= quotient << 1;
+ remainder <= remainder << 1;
+ remainder[0] <= dividend[108];
+ dividend <= dividend << 1;
+ state <= divide_2;
+ end
+
+ divide_2:
+ begin
+ if (remainder >= divisor) begin
+ quotient[0] <= 1;
+ remainder <= remainder - divisor;
+ end
+ if (count == 107) begin
+ state <= divide_3;
+ end else begin
+ count <= count + 1;
+ state <= divide_1;
+ end
+ end
+
+ divide_3:
+ begin
+ z_m <= quotient[55:3];
+ guard <= quotient[2];
+ round_bit <= quotient[1];
+ sticky <= quotient[0] | (remainder != 0);
+ state <= normalise_1;
+ end
+
+ normalise_1:
+ begin
+ if (z_m[52] == 0 && $signed(z_e) > -1022) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= guard;
+ guard <= round_bit;
+ round_bit <= 0;
+ end else begin
+ state <= normalise_2;
+ end
+ end
+
+ normalise_2:
+ begin
+ if ($signed(z_e) < -1022) begin
+ z_e <= z_e + 1;
+ z_m <= z_m >> 1;
+ guard <= z_m[0];
+ round_bit <= guard;
+ sticky <= sticky | round_bit;
+ end else begin
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit | sticky | z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 53'hffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[51 : 0] <= z_m[51:0];
+ z[62 : 52] <= z_e[10:0] + 1023;
+ z[63] <= z_s;
+ if ($signed(z_e) == -1022 && z_m[52] == 0) begin
+ z[62 : 52] <= 0;
+ end
+ //if overflow occurs, return inf
+ if ($signed(z_e) > 1023) begin
+ z[51 : 0] <= 0;
+ z[62 : 52] <= 2047;
+ z[63] <= z_s;
+ end
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_input_b_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign input_b_ack = s_input_b_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point Multiplier (Double Precision)
+//Copyright (C) Jonathan P Dawson 2014
+//2014-01-10
+module double_multiplier(
+ input_a,
+ input_b,
+ input_a_stb,
+ input_b_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack,
+ input_b_ack);
+
+ input clk;
+ input rst;
+
+ input [63:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ input [63:0] input_b;
+ input input_b_stb;
+ output input_b_ack;
+
+ output [63:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [63:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [3:0] state;
+ parameter get_a = 4'd0,
+ get_b = 4'd1,
+ unpack = 4'd2,
+ special_cases = 4'd3,
+ normalise_a = 4'd4,
+ normalise_b = 4'd5,
+ multiply_0 = 4'd6,
+ multiply_1 = 4'd7,
+ normalise_1 = 4'd8,
+ normalise_2 = 4'd9,
+ round = 4'd10,
+ pack = 4'd11,
+ put_z = 4'd12;
+
+ reg [63:0] a, b, z;
+ reg [52:0] a_m, b_m, z_m;
+ reg [12:0] a_e, b_e, z_e;
+ reg a_s, b_s, z_s;
+ reg guard, round_bit, sticky;
+ reg [107:0] product;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= get_b;
+ end
+ end
+
+ get_b:
+ begin
+ s_input_b_ack <= 1;
+ if (s_input_b_ack && input_b_stb) begin
+ b <= input_b;
+ s_input_b_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m <= a[51 : 0];
+ b_m <= b[51 : 0];
+ a_e <= a[62 : 52] - 1023;
+ b_e <= b[62 : 52] - 1023;
+ a_s <= a[63];
+ b_s <= b[63];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ //if a is NaN or b is NaN return NaN
+ if ((a_e == 1024 && a_m != 0) || (b_e == 1024 && b_m != 0)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ //if a is inf return inf
+ end else if (a_e == 1024) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 2047;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if b is zero return NaN
+ if ($signed(b_e == -1023) && (b_m == 0)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ end
+ //if b is inf return inf
+ end else if (b_e == 1024) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 2047;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if a is zero return zero
+ end else if (($signed(a_e) == -1023) && (a_m == 0)) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 0;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if b is zero return zero
+ end else if (($signed(b_e) == -1023) && (b_m == 0)) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 0;
+ z[51:0] <= 0;
+ state <= put_z;
+ end else begin
+ //Denormalised Number
+ if ($signed(a_e) == -1023) begin
+ a_e <= -1022;
+ end else begin
+ a_m[52] <= 1;
+ end
+ //Denormalised Number
+ if ($signed(b_e) == -1023) begin
+ b_e <= -1022;
+ end else begin
+ b_m[52] <= 1;
+ end
+ state <= normalise_a;
+ end
+ end
+
+ normalise_a:
+ begin
+ if (a_m[52]) begin
+ state <= normalise_b;
+ end else begin
+ a_m <= a_m << 1;
+ a_e <= a_e - 1;
+ end
+ end
+
+ normalise_b:
+ begin
+ if (b_m[52]) begin
+ state <= multiply_0;
+ end else begin
+ b_m <= b_m << 1;
+ b_e <= b_e - 1;
+ end
+ end
+
+ multiply_0:
+ begin
+ z_s <= a_s ^ b_s;
+ z_e <= a_e + b_e + 1;
+ product <= a_m * b_m * 4;
+ state <= multiply_1;
+ end
+
+ multiply_1:
+ begin
+ z_m <= product[107:55];
+ guard <= product[54];
+ round_bit <= product[53];
+ sticky <= (product[52:0] != 0);
+ state <= normalise_1;
+ end
+
+ normalise_1:
+ begin
+ if (z_m[52] == 0) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= guard;
+ guard <= round_bit;
+ round_bit <= 0;
+ end else begin
+ state <= normalise_2;
+ end
+ end
+
+ normalise_2:
+ begin
+ if ($signed(z_e) < -1022) begin
+ z_e <= z_e + 1;
+ z_m <= z_m >> 1;
+ guard <= z_m[0];
+ round_bit <= guard;
+ sticky <= sticky | round_bit;
+ end else begin
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit | sticky | z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 53'hffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[51 : 0] <= z_m[51:0];
+ z[62 : 52] <= z_e[11:0] + 1023;
+ z[63] <= z_s;
+ if ($signed(z_e) == -1022 && z_m[52] == 0) begin
+ z[62 : 52] <= 0;
+ end
+ //if overflow occurs, return inf
+ if ($signed(z_e) > 1023) begin
+ z[51 : 0] <= 0;
+ z[62 : 52] <= 2047;
+ z[63] <= z_s;
+ end
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_input_b_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign input_b_ack = s_input_b_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point Adder (Double Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+
+module double_adder(
+ input_a,
+ input_b,
+ input_a_stb,
+ input_b_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack,
+ input_b_ack);
+
+ input clk;
+ input rst;
+
+ input [63:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ input [63:0] input_b;
+ input input_b_stb;
+ output input_b_ack;
+
+ output [63:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [63:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [3:0] state;
+ parameter get_a = 4'd0,
+ get_b = 4'd1,
+ unpack = 4'd2,
+ special_cases = 4'd3,
+ align = 4'd4,
+ add_0 = 4'd5,
+ add_1 = 4'd6,
+ normalise_1 = 4'd7,
+ normalise_2 = 4'd8,
+ round = 4'd9,
+ pack = 4'd10,
+ put_z = 4'd11;
+
+ reg [63:0] a, b, z;
+ reg [55:0] a_m, b_m;
+ reg [52:0] z_m;
+ reg [12:0] a_e, b_e, z_e;
+ reg a_s, b_s, z_s;
+ reg guard, round_bit, sticky;
+ reg [56:0] sum;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= get_b;
+ end
+ end
+
+ get_b:
+ begin
+ s_input_b_ack <= 1;
+ if (s_input_b_ack && input_b_stb) begin
+ b <= input_b;
+ s_input_b_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m <= {a[51 : 0], 3'd0};
+ b_m <= {b[51 : 0], 3'd0};
+ a_e <= a[62 : 52] - 1023;
+ b_e <= b[62 : 52] - 1023;
+ a_s <= a[63];
+ b_s <= b[63];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ //if a is NaN or b is NaN return NaN
+ if ((a_e == 1024 && a_m != 0) || (b_e == 1024 && b_m != 0)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ //if a is inf return inf
+ end else if (a_e == 1024) begin
+ z[63] <= a_s;
+ z[62:52] <= 2047;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if b is inf return inf
+ end else if (b_e == 1024) begin
+ z[63] <= b_s;
+ z[62:52] <= 2047;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if a is zero return b
+ end else if ((($signed(a_e) == -1023) && (a_m == 0)) && (($signed(b_e) == -1023) && (b_m == 0))) begin
+ z[63] <= a_s & b_s;
+ z[62:52] <= b_e[10:0] + 1023;
+ z[51:0] <= b_m[55:3];
+ state <= put_z;
+ //if a is zero return b
+ end else if (($signed(a_e) == -1023) && (a_m == 0)) begin
+ z[63] <= b_s;
+ z[62:52] <= b_e[10:0] + 1023;
+ z[51:0] <= b_m[55:3];
+ state <= put_z;
+ //if b is zero return a
+ end else if (($signed(b_e) == -1023) && (b_m == 0)) begin
+ z[63] <= a_s;
+ z[62:52] <= a_e[10:0] + 1023;
+ z[51:0] <= a_m[55:3];
+ state <= put_z;
+ end else begin
+ //Denormalised Number
+ if ($signed(a_e) == -1023) begin
+ a_e <= -1022;
+ end else begin
+ a_m[55] <= 1;
+ end
+ //Denormalised Number
+ if ($signed(b_e) == -1023) begin
+ b_e <= -1022;
+ end else begin
+ b_m[55] <= 1;
+ end
+ state <= align;
+ end
+ end
+
+ align:
+ begin
+ if ($signed(a_e) > $signed(b_e)) begin
+ b_e <= b_e + 1;
+ b_m <= b_m >> 1;
+ b_m[0] <= b_m[0] | b_m[1];
+ end else if ($signed(a_e) < $signed(b_e)) begin
+ a_e <= a_e + 1;
+ a_m <= a_m >> 1;
+ a_m[0] <= a_m[0] | a_m[1];
+ end else begin
+ state <= add_0;
+ end
+ end
+
+ add_0:
+ begin
+ z_e <= a_e;
+ if (a_s == b_s) begin
+ sum <= {1'd0, a_m} + b_m;
+ z_s <= a_s;
+ end else begin
+ if (a_m > b_m) begin
+ sum <= {1'd0, a_m} - b_m;
+ z_s <= a_s;
+ end else begin
+ sum <= {1'd0, b_m} - a_m;
+ z_s <= b_s;
+ end
+ end
+ state <= add_1;
+ end
+
+ add_1:
+ begin
+ if (sum[56]) begin
+ z_m <= sum[56:4];
+ guard <= sum[3];
+ round_bit <= sum[2];
+ sticky <= sum[1] | sum[0];
+ z_e <= z_e + 1;
+ end else begin
+ z_m <= sum[55:3];
+ guard <= sum[2];
+ round_bit <= sum[1];
+ sticky <= sum[0];
+ end
+ state <= normalise_1;
+ end
+
+ normalise_1:
+ begin
+ if (z_m[52] == 0 && $signed(z_e) > -1022) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= guard;
+ guard <= round_bit;
+ round_bit <= 0;
+ end else begin
+ state <= normalise_2;
+ end
+ end
+
+ normalise_2:
+ begin
+ if ($signed(z_e) < -1022) begin
+ z_e <= z_e + 1;
+ z_m <= z_m >> 1;
+ guard <= z_m[0];
+ round_bit <= guard;
+ sticky <= sticky | round_bit;
+ end else begin
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit | sticky | z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 53'h1fffffffffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[51 : 0] <= z_m[51:0];
+ z[62 : 52] <= z_e[10:0] + 1023;
+ z[63] <= z_s;
+ if ($signed(z_e) == -1022 && z_m[52] == 0) begin
+ z[62 : 52] <= 0;
+ end
+ //if overflow occurs, return inf
+ if ($signed(z_e) > 1023) begin
+ z[51 : 0] <= 0;
+ z[62 : 52] <= 2047;
+ z[63] <= z_s;
+ end
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_input_b_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign input_b_ack = s_input_b_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//Integer to IEEE Floating Point Converter (Single Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+module int_to_float(
+ input_a,
+ input_a_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack);
+
+ input clk;
+ input rst;
+
+ input [31:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ output [31:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [31:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [2:0] state;
+ parameter get_a = 3'd0,
+ convert_0 = 3'd1,
+ convert_1 = 3'd2,
+ convert_2 = 3'd3,
+ round = 3'd4,
+ pack = 3'd5,
+ put_z = 3'd6;
+
+ reg [31:0] a, z, value;
+ reg [23:0] z_m;
+ reg [7:0] z_r;
+ reg [7:0] z_e;
+ reg z_s;
+ reg guard, round_bit, sticky;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= convert_0;
+ end
+ end
+
+ convert_0:
+ begin
+ if ( a == 0 ) begin
+ z_s <= 0;
+ z_m <= 0;
+ z_e <= -127;
+ state <= pack;
+ end else begin
+ value <= a[31] ? -a : a;
+ z_s <= a[31];
+ state <= convert_1;
+ end
+ end
+
+ convert_1:
+ begin
+ z_e <= 31;
+ z_m <= value[31:8];
+ z_r <= value[7:0];
+ state <= convert_2;
+ end
+
+ convert_2:
+ begin
+ if (!z_m[23]) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= z_r[7];
+ z_r <= z_r << 1;
+ end else begin
+ guard <= z_r[7];
+ round_bit <= z_r[6];
+ sticky <= z_r[5:0] != 0;
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit || sticky || z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 24'hffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[22 : 0] <= z_m[22:0];
+ z[30 : 23] <= z_e + 127;
+ z[31] <= z_s;
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point to Integer Converter (Single Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+module float_to_int(
+ input_a,
+ input_a_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack);
+
+ input clk;
+ input rst;
+
+ input [31:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ output [31:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [31:0] s_output_z;
+ reg s_input_a_ack;
+
+ reg [2:0] state;
+ parameter get_a = 3'd0,
+ special_cases = 3'd1,
+ unpack = 3'd2,
+ convert = 3'd3,
+ put_z = 3'd4;
+
+ reg [31:0] a_m, a, z;
+ reg [8:0] a_e;
+ reg a_s;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m[31:8] <= {1'b1, a[22 : 0]};
+ a_m[7:0] <= 0;
+ a_e <= a[30 : 23] - 127;
+ a_s <= a[31];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ if ($signed(a_e) == -127) begin
+ z <= 0;
+ state <= put_z;
+ end else if ($signed(a_e) > 31) begin
+ z <= 32'h80000000;
+ state <= put_z;
+ end else begin
+ state <= convert;
+ end
+ end
+
+ convert:
+ begin
+ if ($signed(a_e) < 31 && a_m) begin
+ a_e <= a_e + 1;
+ a_m <= a_m >> 1;
+ end else begin
+ if (a_m[31]) begin
+ z <= 32'h80000000;
+ end else begin
+ z <= a_s ? -a_m : a_m;
+ end
+ state <= put_z;
+ end
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//Integer to IEEE Floating Point Converter (Double Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+module long_to_double(
+ input_a,
+ input_a_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack);
+
+ input clk;
+ input rst;
+
+ input [63:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ output [63:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [63:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [2:0] state;
+ parameter get_a = 3'd0,
+ convert_0 = 3'd1,
+ convert_1 = 3'd2,
+ convert_2 = 3'd3,
+ round = 3'd4,
+ pack = 3'd5,
+ put_z = 3'd6;
+
+ reg [63:0] a, z, value;
+ reg [52:0] z_m;
+ reg [10:0] z_r;
+ reg [10:0] z_e;
+ reg z_s;
+ reg guard, round_bit, sticky;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= convert_0;
+ end
+ end
+
+ convert_0:
+ begin
+ if ( a == 0 ) begin
+ z_s <= 0;
+ z_m <= 0;
+ z_e <= -1023;
+ state <= pack;
+ end else begin
+ value <= a[63] ? -a : a;
+ z_s <= a[63];
+ state <= convert_1;
+ end
+ end
+
+ convert_1:
+ begin
+ z_e <= 63;
+ z_m <= value[63:11];
+ z_r <= value[10:0];
+ state <= convert_2;
+ end
+
+ convert_2:
+ begin
+ if (!z_m[52]) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= z_r[10];
+ z_r <= z_r << 1;
+ end else begin
+ guard <= z_r[10];
+ round_bit <= z_r[9];
+ sticky <= z_r[8:0] != 0;
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit || sticky || z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 53'h1fffffffffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[51 : 0] <= z_m[51:0];
+ z[62 : 52] <= z_e + 1023;
+ z[63] <= z_s;
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point to Integer Converter (Double Precision)
+//Copyright (C) Jonathan P Dawson 2014
+//2014-01-11
+module double_to_long(
+ input_a,
+ input_a_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack);
+
+ input clk;
+ input rst;
+
+ input [63:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ output [63:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [63:0] s_output_z;
+ reg s_input_a_ack;
+
+ reg [2:0] state;
+ parameter get_a = 3'd0,
+ special_cases = 3'd1,
+ unpack = 3'd2,
+ convert = 3'd3,
+ put_z = 3'd4;
+
+ reg [63:0] a_m, a, z;
+ reg [11:0] a_e;
+ reg a_s;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m[63:11] <= {1'b1, a[51 : 0]};
+ a_m[10:0] <= 0;
+ a_e <= a[62 : 52] - 1023;
+ a_s <= a[63];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ if ($signed(a_e) == -1023) begin
+ //zero
+ z <= 0;
+ state <= put_z;
+ end else if ($signed(a_e) == 1024 && a[51:0] != 0) begin
+ //nan
+ z <= 64'h8000000000000000;
+ state <= put_z;
+ end else if ($signed(a_e) > 63) begin
+ //too big
+ if (a_s) begin
+ z <= 64'h8000000000000000;
+ end else begin
+ z <= 64'h0000000000000000;
+ end
+ state <= put_z;
+ end else begin
+ state <= convert;
+ end
+ end
+
+ convert:
+ begin
+ if ($signed(a_e) < 63 && a_m) begin
+ a_e <= a_e + 1;
+ a_m <= a_m >> 1;
+ end else begin
+ if (a_m[63] && a_s) begin
+ z <= 64'h8000000000000000;
+ end else begin
+ z <= a_s ? -a_m : a_m;
+ end
+ state <= put_z;
+ end
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//Integer to IEEE Floating Point Converter (Double Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+module float_to_double(
+ input_a,
+ input_a_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack);
+
+ input clk;
+ input rst;
+
+ input [31:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ output [63:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [63:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [1:0] state;
+ parameter get_a = 3'd0,
+ convert_0 = 3'd1,
+ normalise_0 = 3'd2,
+ put_z = 3'd3;
+
+ reg [63:0] z;
+ reg [10:0] z_e;
+ reg [52:0] z_m;
+ reg [31:0] a;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= convert_0;
+ end
+ end
+
+ convert_0:
+ begin
+ z[63] <= a[31];
+ z[62:52] <= (a[30:23] - 127) + 1023;
+ z[51:0] <= {a[22:0], 29'd0};
+ if (a[30:23] == 255) begin
+ z[62:52] <= 2047;
+ end
+ state <= put_z;
+ if (a[30:23] == 0) begin
+ if (a[23:0]) begin
+ state <= normalise_0;
+ z_e <= 897;
+ z_m <= {1'd0, a[22:0], 29'd0};
+ end
+ z[62:52] <= 0;
+ end
+ end
+
+ normalise_0:
+ begin
+ if (z_m[52]) begin
+ z[62:52] <= z_e;
+ z[51:0] <= z_m[51:0];
+ state <= put_z;
+ end else begin
+ z_m <= {z_m[51:0], 1'd0};
+ z_e <= z_e - 1;
+ end
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point to Integer Converter (Double Precision)
+//Copyright (C) Jonathan P Dawson 2014
+//2014-01-11
+module double_to_float(
+ input_a,
+ input_a_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack);
+
+ input clk;
+ input rst;
+
+ input [63:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ output [31:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [31:0] s_output_z;
+ reg s_input_a_ack;
+
+ reg [1:0] state;
+ parameter get_a = 3'd0,
+ unpack = 3'd1,
+ denormalise = 3'd2,
+ put_z = 3'd3;
+
+ reg [63:0] a;
+ reg [31:0] z;
+ reg [10:0] z_e;
+ reg [23:0] z_m;
+ reg guard;
+ reg round;
+ reg sticky;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ z[31] <= a[63];
+ state <= put_z;
+ if (a[62:52] == 0) begin
+ z[30:23] <= 0;
+ z[22:0] <= 0;
+ end else if (a[62:52] < 897) begin
+ z[30:23] <= 0;
+ z_m <= {1'd1, a[51:29]};
+ z_e <= a[62:52];
+ guard <= a[28];
+ round <= a[27];
+ sticky <= a[26:0] != 0;
+ state <= denormalise;
+ end else if (a[62:52] == 2047) begin
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ if (a[51:0]) begin
+ z[22] <= 1;
+ end
+ end else if (a[62:52] > 1150) begin
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ end else begin
+ z[30:23] <= (a[62:52] - 1023) + 127;
+ if (a[28] && (a[27] || a[26:0])) begin
+ z[22:0] <= a[51:29] + 1;
+ end else begin
+ z[22:0] <= a[51:29];
+ end
+ end
+ end
+
+ denormalise:
+ begin
+ if (z_e == 897 || (z_m == 0 && guard == 0)) begin
+ state <= put_z;
+ z[22:0] <= z_m;
+ if (guard && (round || sticky)) begin
+ z[22:0] <= z_m + 1;
+ end
+ end else begin
+ z_e <= z_e + 1;
+ z_m <= {1'd0, z_m[23:1]};
+ guard <= z_m[0];
+ round <= guard;
+ sticky <= sticky | round;
+ end
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+"
+"module servo(clk, rst, rs232_in, rs232_in_stb, rs232_in_ack, rs232_out, servos, rs232_out_stb, servos_stb, rs232_out_ack, servos_ack);
+ input clk;
+ input rst;
+ input [15:0] rs232_in;
+ input rs232_in_stb;
+ output rs232_in_ack;
+ output [15:0] rs232_out;
+ output rs232_out_stb;
+ input rs232_out_ack;
+ output [15:0] servos;
+ output servos_stb;
+ input servos_ack;
+ wire [15:0] wire_140036826114168;
+ wire wire_140036826114168_stb;
+ wire wire_140036826114168_ack;
+ servo_ui servo_ui_32237832(
+ .clk(clk),
+ .rst(rst),
+ .input_rs232(rs232_in),
+ .input_rs232_stb(rs232_in_stb),
+ .input_rs232_ack(rs232_in_ack),
+ .output_control(wire_140036826114168),
+ .output_control_stb(wire_140036826114168_stb),
+ .output_control_ack(wire_140036826114168_ack),
+ .output_rs232(rs232_out),
+ .output_rs232_stb(rs232_out_stb),
+ .output_rs232_ack(rs232_out_ack));
+ servo_controller servo_controller_32246024(
+ .clk(clk),
+ .rst(rst),
+ .input_control(wire_140036826114168),
+ .input_control_stb(wire_140036826114168_stb),
+ .input_control_ack(wire_140036826114168_ack),
+ .output_servos(servos),
+ .output_servos_stb(servos_stb),
+ .output_servos_ack(servos_ack));
+endmodule
+"
+"//////////////////////////////////////////////////////////////////////////////
+//name : servo_ui
+//input : input_rs232:16
+//output : output_control:16
+//output : output_rs232:16
+//source_file : servo_ui.c
+///========
+///
+///Created by C2CHIP
+
+//////////////////////////////////////////////////////////////////////////////
+// Register Allocation
+// ===================
+// Register Name Size
+// 0 array 2
+// 1 temporary_register 2
+// 2 temporary_register 2
+// 3 temporary_register 2
+// 4 temporary_register 2
+// 5 temporary_register 36
+// 6 temporary_register 38
+// 7 temporary_register 24
+// 8 temporary_register 42
+// 9 temporary_register 8
+// 10 temporary_register 64
+// 11 temporary_register 58
+// 12 temporary_register 80
+// 13 stdin_get_char return address 2
+// 14 variable stdin_get_char return value 2
+// 15 stdout_put_char return address 2
+// 16 variable character 2
+// 17 print_string return address 2
+// 18 array 2
+// 19 variable i 2
+// 20 is_num return address 2
+// 21 variable is_num return value 2
+// 22 variable character 2
+// 23 scan return address 2
+// 24 variable scan return value 2
+// 25 variable character 2
+// 26 variable value 2
+// 27 servo_ui return address 2
+// 28 variable servo 2
+// 29 variable position 2
+// 30 array 2
+// 31 array 2
+// 32 array 2
+// 33 array 2
+// 34 array 2
+// 35 array 2
+// 36 array 2
+// 37 array 2
+module servo_ui(input_rs232,input_rs232_stb,output_control_ack,output_rs232_ack,clk,rst,output_control,output_rs232,output_control_stb,output_rs232_stb,input_rs232_ack);
+ integer file_count;
+ real fp_value;
+ input [15:0] input_rs232;
+ input input_rs232_stb;
+ input output_control_ack;
+ input output_rs232_ack;
+ input clk;
+ input rst;
+ output [15:0] output_control;
+ output [15:0] output_rs232;
+ output output_control_stb;
+ output output_rs232_stb;
+ output input_rs232_ack;
+ reg [15:0] timer;
+ reg timer_enable;
+ reg stage_0_enable;
+ reg stage_1_enable;
+ reg stage_2_enable;
+ reg [8:0] program_counter;
+ reg [8:0] program_counter_0;
+ reg [48:0] instruction_0;
+ reg [4:0] opcode_0;
+ reg [5:0] dest_0;
+ reg [5:0] src_0;
+ reg [5:0] srcb_0;
+ reg [31:0] literal_0;
+ reg [8:0] program_counter_1;
+ reg [4:0] opcode_1;
+ reg [5:0] dest_1;
+ reg [31:0] register_1;
+ reg [31:0] registerb_1;
+ reg [31:0] literal_1;
+ reg [5:0] dest_2;
+ reg [31:0] result_2;
+ reg write_enable_2;
+ reg [15:0] address_2;
+ reg [15:0] data_out_2;
+ reg [15:0] data_in_2;
+ reg memory_enable_2;
+ reg [15:0] address_4;
+ reg [31:0] data_out_4;
+ reg [31:0] data_in_4;
+ reg memory_enable_4;
+ reg [15:0] s_output_control_stb;
+ reg [15:0] s_output_rs232_stb;
+ reg [15:0] s_output_control;
+ reg [15:0] s_output_rs232;
+ reg [15:0] s_input_rs232_ack;
+ reg [15:0] memory_2 [180:0];
+ reg [48:0] instructions [285:0];
+ reg [31:0] registers [37:0];
+
+ //////////////////////////////////////////////////////////////////////////////
+ // MEMORY INITIALIZATION
+ //
+ // In order to reduce program size, array contents have been stored into
+ // memory at initialization. In an FPGA, this will result in the memory being
+ // initialized when the FPGA configures.
+ // Memory will not be re-initialized at reset.
+ // Dissable this behaviour using the no_initialize_memory switch
+
+ initial
+ begin
+ memory_2[2] = 83;
+ memory_2[3] = 101;
+ memory_2[4] = 114;
+ memory_2[5] = 118;
+ memory_2[6] = 111;
+ memory_2[7] = 32;
+ memory_2[8] = 67;
+ memory_2[9] = 111;
+ memory_2[10] = 110;
+ memory_2[11] = 116;
+ memory_2[12] = 114;
+ memory_2[13] = 111;
+ memory_2[14] = 108;
+ memory_2[15] = 108;
+ memory_2[16] = 101;
+ memory_2[17] = 114;
+ memory_2[18] = 10;
+ memory_2[19] = 0;
+ memory_2[20] = 74;
+ memory_2[21] = 111;
+ memory_2[22] = 110;
+ memory_2[23] = 97;
+ memory_2[24] = 116;
+ memory_2[25] = 104;
+ memory_2[26] = 97;
+ memory_2[27] = 110;
+ memory_2[28] = 32;
+ memory_2[29] = 80;
+ memory_2[30] = 32;
+ memory_2[31] = 68;
+ memory_2[32] = 97;
+ memory_2[33] = 119;
+ memory_2[34] = 115;
+ memory_2[35] = 111;
+ memory_2[36] = 110;
+ memory_2[37] = 10;
+ memory_2[38] = 0;
+ memory_2[39] = 50;
+ memory_2[40] = 48;
+ memory_2[41] = 49;
+ memory_2[42] = 51;
+ memory_2[43] = 45;
+ memory_2[44] = 49;
+ memory_2[45] = 50;
+ memory_2[46] = 45;
+ memory_2[47] = 50;
+ memory_2[48] = 52;
+ memory_2[49] = 10;
+ memory_2[50] = 0;
+ memory_2[51] = 69;
+ memory_2[52] = 110;
+ memory_2[53] = 116;
+ memory_2[54] = 101;
+ memory_2[55] = 114;
+ memory_2[56] = 32;
+ memory_2[57] = 83;
+ memory_2[58] = 101;
+ memory_2[59] = 114;
+ memory_2[60] = 118;
+ memory_2[61] = 111;
+ memory_2[62] = 32;
+ memory_2[63] = 48;
+ memory_2[64] = 32;
+ memory_2[65] = 116;
+ memory_2[66] = 111;
+ memory_2[67] = 32;
+ memory_2[68] = 55;
+ memory_2[69] = 58;
+ memory_2[70] = 10;
+ memory_2[71] = 0;
+ memory_2[72] = 126;
+ memory_2[73] = 36;
+ memory_2[74] = 10;
+ memory_2[75] = 0;
+ memory_2[76] = 115;
+ memory_2[77] = 101;
+ memory_2[78] = 114;
+ memory_2[79] = 118;
+ memory_2[80] = 111;
+ memory_2[81] = 32;
+ memory_2[82] = 115;
+ memory_2[83] = 104;
+ memory_2[84] = 111;
+ memory_2[85] = 117;
+ memory_2[86] = 108;
+ memory_2[87] = 100;
+ memory_2[88] = 32;
+ memory_2[89] = 98;
+ memory_2[90] = 101;
+ memory_2[91] = 32;
+ memory_2[92] = 98;
+ memory_2[93] = 101;
+ memory_2[94] = 116;
+ memory_2[95] = 119;
+ memory_2[96] = 101;
+ memory_2[97] = 101;
+ memory_2[98] = 110;
+ memory_2[99] = 32;
+ memory_2[100] = 48;
+ memory_2[101] = 32;
+ memory_2[102] = 97;
+ memory_2[103] = 110;
+ memory_2[104] = 100;
+ memory_2[105] = 32;
+ memory_2[106] = 55;
+ memory_2[107] = 0;
+ memory_2[108] = 69;
+ memory_2[109] = 110;
+ memory_2[110] = 116;
+ memory_2[111] = 101;
+ memory_2[112] = 114;
+ memory_2[113] = 32;
+ memory_2[114] = 80;
+ memory_2[115] = 111;
+ memory_2[116] = 115;
+ memory_2[117] = 105;
+ memory_2[118] = 116;
+ memory_2[119] = 105;
+ memory_2[120] = 111;
+ memory_2[121] = 110;
+ memory_2[122] = 32;
+ memory_2[123] = 45;
+ memory_2[124] = 53;
+ memory_2[125] = 48;
+ memory_2[126] = 48;
+ memory_2[127] = 32;
+ memory_2[128] = 116;
+ memory_2[129] = 111;
+ memory_2[130] = 32;
+ memory_2[131] = 53;
+ memory_2[132] = 48;
+ memory_2[133] = 48;
+ memory_2[134] = 58;
+ memory_2[135] = 10;
+ memory_2[136] = 0;
+ memory_2[137] = 126;
+ memory_2[138] = 36;
+ memory_2[139] = 10;
+ memory_2[140] = 0;
+ memory_2[141] = 112;
+ memory_2[142] = 111;
+ memory_2[143] = 115;
+ memory_2[144] = 105;
+ memory_2[145] = 116;
+ memory_2[146] = 105;
+ memory_2[147] = 111;
+ memory_2[148] = 110;
+ memory_2[149] = 32;
+ memory_2[150] = 115;
+ memory_2[151] = 104;
+ memory_2[152] = 111;
+ memory_2[153] = 117;
+ memory_2[154] = 108;
+ memory_2[155] = 100;
+ memory_2[156] = 32;
+ memory_2[157] = 98;
+ memory_2[158] = 101;
+ memory_2[159] = 32;
+ memory_2[160] = 98;
+ memory_2[161] = 101;
+ memory_2[162] = 116;
+ memory_2[163] = 119;
+ memory_2[164] = 101;
+ memory_2[165] = 101;
+ memory_2[166] = 110;
+ memory_2[167] = 32;
+ memory_2[168] = 45;
+ memory_2[169] = 53;
+ memory_2[170] = 48;
+ memory_2[171] = 48;
+ memory_2[172] = 32;
+ memory_2[173] = 97;
+ memory_2[174] = 110;
+ memory_2[175] = 100;
+ memory_2[176] = 32;
+ memory_2[177] = 53;
+ memory_2[178] = 48;
+ memory_2[179] = 48;
+ memory_2[180] = 0;
+ end
+
+
+ //////////////////////////////////////////////////////////////////////////////
+ // INSTRUCTION INITIALIZATION
+ //
+ // Initialise the contents of the instruction memory
+ //
+ // Intruction Set
+ // ==============
+ // 0 {'float': False, 'literal': True, 'right': False, 'unsigned': False, 'op': 'jmp_and_link'}
+ // 1 {'float': False, 'literal': False, 'right': False, 'unsigned': False, 'op': 'stop'}
+ // 2 {'right': False, 'float': False, 'unsigned': False, 'literal': False, 'input': 'rs232', 'op': 'read'}
+ // 3 {'float': False, 'literal': False, 'right': False, 'unsigned': False, 'op': 'nop'}
+ // 4 {'float': False, 'literal': False, 'right': False, 'unsigned': False, 'op': 'move'}
+ // 5 {'float': False, 'literal': False, 'right': False, 'unsigned': False, 'op': 'jmp_to_reg'}
+ // 6 {'right': False, 'float': False, 'unsigned': False, 'literal': False, 'output': 'rs232', 'op': 'write'}
+ // 7 {'float': False, 'literal': True, 'right': False, 'unsigned': False, 'op': 'literal'}
+ // 8 {'float': False, 'literal': False, 'right': False, 'unsigned': True, 'op': '+'}
+ // 9 {'right': False, 'element_size': 2, 'float': False, 'unsigned': False, 'literal': False, 'op': 'memory_read_request'}
+ // 10 {'right': False, 'element_size': 2, 'float': False, 'unsigned': False, 'literal': False, 'op': 'memory_read_wait'}
+ // 11 {'right': False, 'element_size': 2, 'float': False, 'unsigned': False, 'literal': False, 'op': 'memory_read'}
+ // 12 {'float': False, 'literal': True, 'right': False, 'unsigned': False, 'op': 'jmp_if_false'}
+ // 13 {'float': False, 'literal': True, 'right': True, 'unsigned': True, 'op': '+'}
+ // 14 {'float': False, 'literal': True, 'right': False, 'unsigned': False, 'op': 'goto'}
+ // 15 {'float': False, 'literal': True, 'right': True, 'unsigned': False, 'op': '>='}
+ // 16 {'float': False, 'literal': True, 'right': True, 'unsigned': False, 'op': '<='}
+ // 17 {'float': False, 'literal': True, 'right': True, 'unsigned': True, 'op': '=='}
+ // 18 {'float': False, 'literal': True, 'right': True, 'unsigned': True, 'op': '-'}
+ // 19 {'float': False, 'literal': True, 'right': True, 'unsigned': False, 'op': '*'}
+ // 20 {'float': False, 'literal': True, 'right': True, 'unsigned': True, 'op': '>='}
+ // 21 {'float': False, 'literal': True, 'right': True, 'unsigned': True, 'op': '<='}
+ // 22 {'right': False, 'float': False, 'unsigned': False, 'literal': False, 'output': 'control', 'op': 'write'}
+ // Intructions
+ // ===========
+
+ initial
+ begin
+ instructions[0] = {5'd0, 6'd27, 6'd0, 32'd161};//{'dest': 27, 'label': 161, 'op': 'jmp_and_link'}
+ instructions[1] = {5'd1, 6'd0, 6'd0, 32'd0};//{'op': 'stop'}
+ instructions[2] = {5'd2, 6'd1, 6'd0, 32'd0};//{'dest': 1, 'input': 'rs232', 'op': 'read'}
+ instructions[3] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[4] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[5] = {5'd4, 6'd14, 6'd1, 32'd0};//{'dest': 14, 'src': 1, 'op': 'move'}
+ instructions[6] = {5'd5, 6'd0, 6'd13, 32'd0};//{'src': 13, 'op': 'jmp_to_reg'}
+ instructions[7] = {5'd4, 6'd1, 6'd16, 32'd0};//{'dest': 1, 'src': 16, 'op': 'move'}
+ instructions[8] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[9] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[10] = {5'd6, 6'd0, 6'd1, 32'd0};//{'src': 1, 'output': 'rs232', 'op': 'write'}
+ instructions[11] = {5'd5, 6'd0, 6'd15, 32'd0};//{'src': 15, 'op': 'jmp_to_reg'}
+ instructions[12] = {5'd7, 6'd19, 6'd0, 32'd0};//{'dest': 19, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[13] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[14] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[15] = {5'd4, 6'd2, 6'd19, 32'd0};//{'dest': 2, 'src': 19, 'op': 'move'}
+ instructions[16] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[17] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[18] = {5'd8, 6'd3, 6'd2, 32'd18};//{'dest': 3, 'src': 2, 'srcb': 18, 'signed': False, 'op': '+'}
+ instructions[19] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[20] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[21] = {5'd9, 6'd0, 6'd3, 32'd0};//{'element_size': 2, 'src': 3, 'sequence': 32208080, 'op': 'memory_read_request'}
+ instructions[22] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[23] = {5'd10, 6'd0, 6'd3, 32'd0};//{'element_size': 2, 'src': 3, 'sequence': 32208080, 'op': 'memory_read_wait'}
+ instructions[24] = {5'd11, 6'd1, 6'd3, 32'd0};//{'dest': 1, 'src': 3, 'sequence': 32208080, 'element_size': 2, 'op': 'memory_read'}
+ instructions[25] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[26] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[27] = {5'd12, 6'd0, 6'd1, 32'd45};//{'src': 1, 'label': 45, 'op': 'jmp_if_false'}
+ instructions[28] = {5'd4, 6'd3, 6'd19, 32'd0};//{'dest': 3, 'src': 19, 'op': 'move'}
+ instructions[29] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[30] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[31] = {5'd8, 6'd4, 6'd3, 32'd18};//{'dest': 4, 'src': 3, 'srcb': 18, 'signed': False, 'op': '+'}
+ instructions[32] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[33] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[34] = {5'd9, 6'd0, 6'd4, 32'd0};//{'element_size': 2, 'src': 4, 'sequence': 32212752, 'op': 'memory_read_request'}
+ instructions[35] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[36] = {5'd10, 6'd0, 6'd4, 32'd0};//{'element_size': 2, 'src': 4, 'sequence': 32212752, 'op': 'memory_read_wait'}
+ instructions[37] = {5'd11, 6'd2, 6'd4, 32'd0};//{'dest': 2, 'src': 4, 'sequence': 32212752, 'element_size': 2, 'op': 'memory_read'}
+ instructions[38] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[39] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[40] = {5'd4, 6'd16, 6'd2, 32'd0};//{'dest': 16, 'src': 2, 'op': 'move'}
+ instructions[41] = {5'd0, 6'd15, 6'd0, 32'd7};//{'dest': 15, 'label': 7, 'op': 'jmp_and_link'}
+ instructions[42] = {5'd4, 6'd1, 6'd19, 32'd0};//{'dest': 1, 'src': 19, 'op': 'move'}
+ instructions[43] = {5'd13, 6'd19, 6'd19, 32'd1};//{'src': 19, 'right': 1, 'dest': 19, 'signed': False, 'op': '+', 'size': 2}
+ instructions[44] = {5'd14, 6'd0, 6'd0, 32'd46};//{'label': 46, 'op': 'goto'}
+ instructions[45] = {5'd14, 6'd0, 6'd0, 32'd47};//{'label': 47, 'op': 'goto'}
+ instructions[46] = {5'd14, 6'd0, 6'd0, 32'd13};//{'label': 13, 'op': 'goto'}
+ instructions[47] = {5'd5, 6'd0, 6'd17, 32'd0};//{'src': 17, 'op': 'jmp_to_reg'}
+ instructions[48] = {5'd4, 6'd2, 6'd22, 32'd0};//{'dest': 2, 'src': 22, 'op': 'move'}
+ instructions[49] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[50] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[51] = {5'd15, 6'd1, 6'd2, 32'd48};//{'src': 2, 'right': 48, 'dest': 1, 'signed': True, 'op': '>=', 'type': 'int', 'size': 2}
+ instructions[52] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[53] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[54] = {5'd12, 6'd0, 6'd1, 32'd59};//{'src': 1, 'label': 59, 'op': 'jmp_if_false'}
+ instructions[55] = {5'd4, 6'd2, 6'd22, 32'd0};//{'dest': 2, 'src': 22, 'op': 'move'}
+ instructions[56] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[57] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[58] = {5'd16, 6'd1, 6'd2, 32'd57};//{'src': 2, 'right': 57, 'dest': 1, 'signed': True, 'op': '<=', 'type': 'int', 'size': 2}
+ instructions[59] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[60] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[61] = {5'd12, 6'd0, 6'd1, 32'd68};//{'src': 1, 'label': 68, 'op': 'jmp_if_false'}
+ instructions[62] = {5'd7, 6'd1, 6'd0, 32'd1};//{'dest': 1, 'literal': 1, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[63] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[64] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[65] = {5'd4, 6'd21, 6'd1, 32'd0};//{'dest': 21, 'src': 1, 'op': 'move'}
+ instructions[66] = {5'd5, 6'd0, 6'd20, 32'd0};//{'src': 20, 'op': 'jmp_to_reg'}
+ instructions[67] = {5'd14, 6'd0, 6'd0, 32'd68};//{'label': 68, 'op': 'goto'}
+ instructions[68] = {5'd7, 6'd1, 6'd0, 32'd0};//{'dest': 1, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[69] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[70] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[71] = {5'd4, 6'd21, 6'd1, 32'd0};//{'dest': 21, 'src': 1, 'op': 'move'}
+ instructions[72] = {5'd5, 6'd0, 6'd20, 32'd0};//{'src': 20, 'op': 'jmp_to_reg'}
+ instructions[73] = {5'd7, 6'd25, 6'd0, 32'd0};//{'dest': 25, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[74] = {5'd7, 6'd26, 6'd0, 32'd0};//{'dest': 26, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[75] = {5'd0, 6'd13, 6'd0, 32'd2};//{'dest': 13, 'label': 2, 'op': 'jmp_and_link'}
+ instructions[76] = {5'd4, 6'd1, 6'd14, 32'd0};//{'dest': 1, 'src': 14, 'op': 'move'}
+ instructions[77] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[78] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[79] = {5'd4, 6'd25, 6'd1, 32'd0};//{'dest': 25, 'src': 1, 'op': 'move'}
+ instructions[80] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[81] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[82] = {5'd4, 6'd2, 6'd25, 32'd0};//{'dest': 2, 'src': 25, 'op': 'move'}
+ instructions[83] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[84] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[85] = {5'd17, 6'd1, 6'd2, 32'd45};//{'src': 2, 'right': 45, 'dest': 1, 'signed': False, 'op': '==', 'type': 'int', 'size': 2}
+ instructions[86] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[87] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[88] = {5'd12, 6'd0, 6'd1, 32'd95};//{'src': 1, 'label': 95, 'op': 'jmp_if_false'}
+ instructions[89] = {5'd7, 6'd1, 6'd0, -32'd1};//{'dest': 1, 'literal': -1, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[90] = {5'd7, 6'd1, 6'd0, 32'd0};//{'dest': 1, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[91] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[92] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[93] = {5'd4, 6'd26, 6'd1, 32'd0};//{'dest': 26, 'src': 1, 'op': 'move'}
+ instructions[94] = {5'd14, 6'd0, 6'd0, 32'd116};//{'label': 116, 'op': 'goto'}
+ instructions[95] = {5'd4, 6'd2, 6'd25, 32'd0};//{'dest': 2, 'src': 25, 'op': 'move'}
+ instructions[96] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[97] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[98] = {5'd17, 6'd1, 6'd2, 32'd43};//{'src': 2, 'right': 43, 'dest': 1, 'signed': False, 'op': '==', 'type': 'int', 'size': 2}
+ instructions[99] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[100] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[101] = {5'd12, 6'd0, 6'd1, 32'd108};//{'src': 1, 'label': 108, 'op': 'jmp_if_false'}
+ instructions[102] = {5'd7, 6'd1, 6'd0, 32'd1};//{'dest': 1, 'literal': 1, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[103] = {5'd7, 6'd1, 6'd0, 32'd0};//{'dest': 1, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[104] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[105] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[106] = {5'd4, 6'd26, 6'd1, 32'd0};//{'dest': 26, 'src': 1, 'op': 'move'}
+ instructions[107] = {5'd14, 6'd0, 6'd0, 32'd116};//{'label': 116, 'op': 'goto'}
+ instructions[108] = {5'd7, 6'd1, 6'd0, 32'd1};//{'dest': 1, 'literal': 1, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[109] = {5'd4, 6'd2, 6'd25, 32'd0};//{'dest': 2, 'src': 25, 'op': 'move'}
+ instructions[110] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[111] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[112] = {5'd18, 6'd1, 6'd2, 32'd48};//{'src': 2, 'right': 48, 'dest': 1, 'signed': False, 'op': '-', 'type': 'int', 'size': 2}
+ instructions[113] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[114] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[115] = {5'd4, 6'd26, 6'd1, 32'd0};//{'dest': 26, 'src': 1, 'op': 'move'}
+ instructions[116] = {5'd0, 6'd13, 6'd0, 32'd2};//{'dest': 13, 'label': 2, 'op': 'jmp_and_link'}
+ instructions[117] = {5'd4, 6'd1, 6'd14, 32'd0};//{'dest': 1, 'src': 14, 'op': 'move'}
+ instructions[118] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[119] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[120] = {5'd4, 6'd25, 6'd1, 32'd0};//{'dest': 25, 'src': 1, 'op': 'move'}
+ instructions[121] = {5'd4, 6'd2, 6'd26, 32'd0};//{'dest': 2, 'src': 26, 'op': 'move'}
+ instructions[122] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[123] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[124] = {5'd19, 6'd1, 6'd2, 32'd10};//{'src': 2, 'right': 10, 'dest': 1, 'signed': True, 'op': '*', 'type': 'int', 'size': 2}
+ instructions[125] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[126] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[127] = {5'd4, 6'd26, 6'd1, 32'd0};//{'dest': 26, 'src': 1, 'op': 'move'}
+ instructions[128] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[129] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[130] = {5'd4, 6'd2, 6'd26, 32'd0};//{'dest': 2, 'src': 26, 'op': 'move'}
+ instructions[131] = {5'd4, 6'd4, 6'd25, 32'd0};//{'dest': 4, 'src': 25, 'op': 'move'}
+ instructions[132] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[133] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[134] = {5'd18, 6'd3, 6'd4, 32'd48};//{'src': 4, 'right': 48, 'dest': 3, 'signed': False, 'op': '-', 'type': 'int', 'size': 2}
+ instructions[135] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[136] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[137] = {5'd8, 6'd1, 6'd2, 32'd3};//{'srcb': 3, 'src': 2, 'dest': 1, 'signed': False, 'op': '+', 'type': 'int', 'size': 2}
+ instructions[138] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[139] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[140] = {5'd4, 6'd26, 6'd1, 32'd0};//{'dest': 26, 'src': 1, 'op': 'move'}
+ instructions[141] = {5'd4, 6'd3, 6'd25, 32'd0};//{'dest': 3, 'src': 25, 'op': 'move'}
+ instructions[142] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[143] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[144] = {5'd4, 6'd22, 6'd3, 32'd0};//{'dest': 22, 'src': 3, 'op': 'move'}
+ instructions[145] = {5'd0, 6'd20, 6'd0, 32'd48};//{'dest': 20, 'label': 48, 'op': 'jmp_and_link'}
+ instructions[146] = {5'd4, 6'd2, 6'd21, 32'd0};//{'dest': 2, 'src': 21, 'op': 'move'}
+ instructions[147] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[148] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[149] = {5'd17, 6'd1, 6'd2, 32'd0};//{'src': 2, 'right': 0, 'dest': 1, 'signed': False, 'op': '==', 'type': 'int', 'size': 2}
+ instructions[150] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[151] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[152] = {5'd12, 6'd0, 6'd1, 32'd155};//{'src': 1, 'label': 155, 'op': 'jmp_if_false'}
+ instructions[153] = {5'd14, 6'd0, 6'd0, 32'd156};//{'label': 156, 'op': 'goto'}
+ instructions[154] = {5'd14, 6'd0, 6'd0, 32'd155};//{'label': 155, 'op': 'goto'}
+ instructions[155] = {5'd14, 6'd0, 6'd0, 32'd116};//{'label': 116, 'op': 'goto'}
+ instructions[156] = {5'd4, 6'd1, 6'd26, 32'd0};//{'dest': 1, 'src': 26, 'op': 'move'}
+ instructions[157] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[158] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[159] = {5'd4, 6'd24, 6'd1, 32'd0};//{'dest': 24, 'src': 1, 'op': 'move'}
+ instructions[160] = {5'd5, 6'd0, 6'd23, 32'd0};//{'src': 23, 'op': 'jmp_to_reg'}
+ instructions[161] = {5'd7, 6'd28, 6'd0, 32'd0};//{'dest': 28, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[162] = {5'd7, 6'd29, 6'd0, 32'd0};//{'dest': 29, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[163] = {5'd7, 6'd30, 6'd0, 32'd2};//{'dest': 30, 'literal': 2, 'op': 'literal'}
+ instructions[164] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[165] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[166] = {5'd4, 6'd5, 6'd30, 32'd0};//{'dest': 5, 'src': 30, 'op': 'move'}
+ instructions[167] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[168] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[169] = {5'd4, 6'd18, 6'd5, 32'd0};//{'dest': 18, 'src': 5, 'op': 'move'}
+ instructions[170] = {5'd0, 6'd17, 6'd0, 32'd12};//{'dest': 17, 'label': 12, 'op': 'jmp_and_link'}
+ instructions[171] = {5'd7, 6'd31, 6'd0, 32'd20};//{'dest': 31, 'literal': 20, 'op': 'literal'}
+ instructions[172] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[173] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[174] = {5'd4, 6'd6, 6'd31, 32'd0};//{'dest': 6, 'src': 31, 'op': 'move'}
+ instructions[175] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[176] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[177] = {5'd4, 6'd18, 6'd6, 32'd0};//{'dest': 18, 'src': 6, 'op': 'move'}
+ instructions[178] = {5'd0, 6'd17, 6'd0, 32'd12};//{'dest': 17, 'label': 12, 'op': 'jmp_and_link'}
+ instructions[179] = {5'd7, 6'd32, 6'd0, 32'd39};//{'dest': 32, 'literal': 39, 'op': 'literal'}
+ instructions[180] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[181] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[182] = {5'd4, 6'd7, 6'd32, 32'd0};//{'dest': 7, 'src': 32, 'op': 'move'}
+ instructions[183] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[184] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[185] = {5'd4, 6'd18, 6'd7, 32'd0};//{'dest': 18, 'src': 7, 'op': 'move'}
+ instructions[186] = {5'd0, 6'd17, 6'd0, 32'd12};//{'dest': 17, 'label': 12, 'op': 'jmp_and_link'}
+ instructions[187] = {5'd7, 6'd33, 6'd0, 32'd51};//{'dest': 33, 'literal': 51, 'op': 'literal'}
+ instructions[188] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[189] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[190] = {5'd4, 6'd8, 6'd33, 32'd0};//{'dest': 8, 'src': 33, 'op': 'move'}
+ instructions[191] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[192] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[193] = {5'd4, 6'd18, 6'd8, 32'd0};//{'dest': 18, 'src': 8, 'op': 'move'}
+ instructions[194] = {5'd0, 6'd17, 6'd0, 32'd12};//{'dest': 17, 'label': 12, 'op': 'jmp_and_link'}
+ instructions[195] = {5'd7, 6'd34, 6'd0, 32'd72};//{'dest': 34, 'literal': 72, 'op': 'literal'}
+ instructions[196] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[197] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[198] = {5'd4, 6'd9, 6'd34, 32'd0};//{'dest': 9, 'src': 34, 'op': 'move'}
+ instructions[199] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[200] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[201] = {5'd4, 6'd18, 6'd9, 32'd0};//{'dest': 18, 'src': 9, 'op': 'move'}
+ instructions[202] = {5'd0, 6'd17, 6'd0, 32'd12};//{'dest': 17, 'label': 12, 'op': 'jmp_and_link'}
+ instructions[203] = {5'd0, 6'd23, 6'd0, 32'd73};//{'dest': 23, 'label': 73, 'op': 'jmp_and_link'}
+ instructions[204] = {5'd4, 6'd1, 6'd24, 32'd0};//{'dest': 1, 'src': 24, 'op': 'move'}
+ instructions[205] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[206] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[207] = {5'd4, 6'd28, 6'd1, 32'd0};//{'dest': 28, 'src': 1, 'op': 'move'}
+ instructions[208] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[209] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[210] = {5'd4, 6'd2, 6'd28, 32'd0};//{'dest': 2, 'src': 28, 'op': 'move'}
+ instructions[211] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[212] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[213] = {5'd20, 6'd1, 6'd2, 32'd0};//{'src': 2, 'right': 0, 'dest': 1, 'signed': False, 'op': '>=', 'type': 'int', 'size': 2}
+ instructions[214] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[215] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[216] = {5'd12, 6'd0, 6'd1, 32'd221};//{'src': 1, 'label': 221, 'op': 'jmp_if_false'}
+ instructions[217] = {5'd4, 6'd2, 6'd28, 32'd0};//{'dest': 2, 'src': 28, 'op': 'move'}
+ instructions[218] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[219] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[220] = {5'd21, 6'd1, 6'd2, 32'd7};//{'src': 2, 'right': 7, 'dest': 1, 'signed': False, 'op': '<=', 'type': 'int', 'size': 2}
+ instructions[221] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[222] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[223] = {5'd12, 6'd0, 6'd1, 32'd226};//{'src': 1, 'label': 226, 'op': 'jmp_if_false'}
+ instructions[224] = {5'd14, 6'd0, 6'd0, 32'd235};//{'label': 235, 'op': 'goto'}
+ instructions[225] = {5'd14, 6'd0, 6'd0, 32'd234};//{'label': 234, 'op': 'goto'}
+ instructions[226] = {5'd7, 6'd35, 6'd0, 32'd76};//{'dest': 35, 'literal': 76, 'op': 'literal'}
+ instructions[227] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[228] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[229] = {5'd4, 6'd10, 6'd35, 32'd0};//{'dest': 10, 'src': 35, 'op': 'move'}
+ instructions[230] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[231] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[232] = {5'd4, 6'd18, 6'd10, 32'd0};//{'dest': 18, 'src': 10, 'op': 'move'}
+ instructions[233] = {5'd0, 6'd17, 6'd0, 32'd12};//{'dest': 17, 'label': 12, 'op': 'jmp_and_link'}
+ instructions[234] = {5'd14, 6'd0, 6'd0, 32'd187};//{'label': 187, 'op': 'goto'}
+ instructions[235] = {5'd7, 6'd36, 6'd0, 32'd108};//{'dest': 36, 'literal': 108, 'op': 'literal'}
+ instructions[236] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[237] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[238] = {5'd4, 6'd11, 6'd36, 32'd0};//{'dest': 11, 'src': 36, 'op': 'move'}
+ instructions[239] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[240] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[241] = {5'd4, 6'd18, 6'd11, 32'd0};//{'dest': 18, 'src': 11, 'op': 'move'}
+ instructions[242] = {5'd0, 6'd17, 6'd0, 32'd12};//{'dest': 17, 'label': 12, 'op': 'jmp_and_link'}
+ instructions[243] = {5'd7, 6'd37, 6'd0, 32'd137};//{'dest': 37, 'literal': 137, 'op': 'literal'}
+ instructions[244] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[245] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[246] = {5'd4, 6'd9, 6'd37, 32'd0};//{'dest': 9, 'src': 37, 'op': 'move'}
+ instructions[247] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[248] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[249] = {5'd4, 6'd18, 6'd9, 32'd0};//{'dest': 18, 'src': 9, 'op': 'move'}
+ instructions[250] = {5'd0, 6'd17, 6'd0, 32'd12};//{'dest': 17, 'label': 12, 'op': 'jmp_and_link'}
+ instructions[251] = {5'd4, 6'd2, 6'd29, 32'd0};//{'dest': 2, 'src': 29, 'op': 'move'}
+ instructions[252] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[253] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[254] = {5'd20, 6'd1, 6'd2, 32'd0};//{'src': 2, 'right': 0, 'dest': 1, 'signed': False, 'op': '>=', 'type': 'int', 'size': 2}
+ instructions[255] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[256] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[257] = {5'd12, 6'd0, 6'd1, 32'd262};//{'src': 1, 'label': 262, 'op': 'jmp_if_false'}
+ instructions[258] = {5'd4, 6'd2, 6'd29, 32'd0};//{'dest': 2, 'src': 29, 'op': 'move'}
+ instructions[259] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[260] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[261] = {5'd21, 6'd1, 6'd2, 32'd7};//{'src': 2, 'right': 7, 'dest': 1, 'signed': False, 'op': '<=', 'type': 'int', 'size': 2}
+ instructions[262] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[263] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[264] = {5'd12, 6'd0, 6'd1, 32'd267};//{'src': 1, 'label': 267, 'op': 'jmp_if_false'}
+ instructions[265] = {5'd14, 6'd0, 6'd0, 32'd276};//{'label': 276, 'op': 'goto'}
+ instructions[266] = {5'd14, 6'd0, 6'd0, 32'd275};//{'label': 275, 'op': 'goto'}
+ instructions[267] = {5'd7, 6'd0, 6'd0, 32'd141};//{'dest': 0, 'literal': 141, 'op': 'literal'}
+ instructions[268] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[269] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[270] = {5'd4, 6'd12, 6'd0, 32'd0};//{'dest': 12, 'src': 0, 'op': 'move'}
+ instructions[271] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[272] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[273] = {5'd4, 6'd18, 6'd12, 32'd0};//{'dest': 18, 'src': 12, 'op': 'move'}
+ instructions[274] = {5'd0, 6'd17, 6'd0, 32'd12};//{'dest': 17, 'label': 12, 'op': 'jmp_and_link'}
+ instructions[275] = {5'd14, 6'd0, 6'd0, 32'd235};//{'label': 235, 'op': 'goto'}
+ instructions[276] = {5'd4, 6'd1, 6'd28, 32'd0};//{'dest': 1, 'src': 28, 'op': 'move'}
+ instructions[277] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[278] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[279] = {5'd22, 6'd0, 6'd1, 32'd0};//{'src': 1, 'output': 'control', 'op': 'write'}
+ instructions[280] = {5'd4, 6'd1, 6'd29, 32'd0};//{'dest': 1, 'src': 29, 'op': 'move'}
+ instructions[281] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[282] = {5'd3, 6'd0, 6'd0, 32'd0};//{'op': 'nop'}
+ instructions[283] = {5'd22, 6'd0, 6'd1, 32'd0};//{'src': 1, 'output': 'control', 'op': 'write'}
+ instructions[284] = {5'd14, 6'd0, 6'd0, 32'd187};//{'label': 187, 'op': 'goto'}
+ instructions[285] = {5'd5, 6'd0, 6'd27, 32'd0};//{'src': 27, 'op': 'jmp_to_reg'}
+ end
+
+
+ //////////////////////////////////////////////////////////////////////////////
+ // CPU IMPLEMENTAION OF C PROCESS
+ //
+ // This section of the file contains a CPU implementing the C process.
+
+ always @(posedge clk)
+ begin
+
+ //implement memory for 2 byte x n arrays
+ if (memory_enable_2 == 1'b1) begin
+ memory_2[address_2] <= data_in_2;
+ end
+ data_out_2 <= memory_2[address_2];
+ memory_enable_2 <= 1'b0;
+
+ write_enable_2 <= 0;
+ //stage 0 instruction fetch
+ if (stage_0_enable) begin
+ stage_1_enable <= 1;
+ instruction_0 <= instructions[program_counter];
+ opcode_0 = instruction_0[48:44];
+ dest_0 = instruction_0[43:38];
+ src_0 = instruction_0[37:32];
+ srcb_0 = instruction_0[5:0];
+ literal_0 = instruction_0[31:0];
+ if(write_enable_2) begin
+ registers[dest_2] <= result_2;
+ end
+ program_counter_0 <= program_counter;
+ program_counter <= program_counter + 1;
+ end
+
+ //stage 1 opcode fetch
+ if (stage_1_enable) begin
+ stage_2_enable <= 1;
+ register_1 <= registers[src_0];
+ registerb_1 <= registers[srcb_0];
+ dest_1 <= dest_0;
+ literal_1 <= literal_0;
+ opcode_1 <= opcode_0;
+ program_counter_1 <= program_counter_0;
+ end
+
+ //stage 2 opcode fetch
+ if (stage_2_enable) begin
+ dest_2 <= dest_1;
+ case(opcode_1)
+
+ 16'd0:
+ begin
+ program_counter <= literal_1;
+ result_2 <= program_counter_1 + 1;
+ write_enable_2 <= 1;
+ stage_0_enable <= 1;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ end
+
+ 16'd1:
+ begin
+ stage_0_enable <= 0;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ end
+
+ 16'd2:
+ begin
+ stage_0_enable <= 0;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ s_input_rs232_ack <= 1'b1;
+ end
+
+ 16'd4:
+ begin
+ result_2 <= register_1;
+ write_enable_2 <= 1;
+ end
+
+ 16'd5:
+ begin
+ program_counter <= register_1;
+ stage_0_enable <= 1;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ end
+
+ 16'd6:
+ begin
+ stage_0_enable <= 0;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ s_output_rs232_stb <= 1'b1;
+ s_output_rs232 <= register_1;
+ end
+
+ 16'd7:
+ begin
+ result_2 <= literal_1;
+ write_enable_2 <= 1;
+ end
+
+ 16'd8:
+ begin
+ result_2 <= $unsigned(register_1) + $unsigned(registerb_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd9:
+ begin
+ address_2 <= register_1;
+ end
+
+ 16'd11:
+ begin
+ result_2 <= data_out_2;
+ write_enable_2 <= 1;
+ end
+
+ 16'd12:
+ begin
+ if (register_1 == 0) begin
+ program_counter <= literal_1;
+ stage_0_enable <= 1;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ end
+ end
+
+ 16'd13:
+ begin
+ result_2 <= $unsigned(register_1) + $unsigned(literal_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd14:
+ begin
+ program_counter <= literal_1;
+ stage_0_enable <= 1;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ end
+
+ 16'd15:
+ begin
+ result_2 <= $signed(register_1) >= $signed(literal_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd16:
+ begin
+ result_2 <= $signed(register_1) <= $signed(literal_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd17:
+ begin
+ result_2 <= $unsigned(register_1) == $unsigned(literal_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd18:
+ begin
+ result_2 <= $unsigned(register_1) - $unsigned(literal_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd19:
+ begin
+ result_2 <= $signed(register_1) * $signed(literal_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd20:
+ begin
+ result_2 <= $unsigned(register_1) >= $unsigned(literal_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd21:
+ begin
+ result_2 <= $unsigned(register_1) <= $unsigned(literal_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd22:
+ begin
+ stage_0_enable <= 0;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ s_output_control_stb <= 1'b1;
+ s_output_control <= register_1;
+ end
+
+ endcase
+ end
+ if (s_input_rs232_ack == 1'b1 && input_rs232_stb == 1'b1) begin
+ result_2 <= input_rs232;
+ write_enable_2 <= 1;
+ s_input_rs232_ack <= 1'b0;
+ stage_0_enable <= 1;
+ stage_1_enable <= 1;
+ stage_2_enable <= 1;
+ end
+
+ if (s_output_rs232_stb == 1'b1 && output_rs232_ack == 1'b1) begin
+ s_output_rs232_stb <= 1'b0;
+ stage_0_enable <= 1;
+ stage_1_enable <= 1;
+ stage_2_enable <= 1;
+ end
+
+ if (s_output_control_stb == 1'b1 && output_control_ack == 1'b1) begin
+ s_output_control_stb <= 1'b0;
+ stage_0_enable <= 1;
+ stage_1_enable <= 1;
+ stage_2_enable <= 1;
+ end
+
+ if (timer == 0) begin
+ if (timer_enable) begin
+ stage_0_enable <= 1;
+ stage_1_enable <= 1;
+ stage_2_enable <= 1;
+ timer_enable <= 0;
+ end
+ end else begin
+ timer <= timer - 1;
+ end
+
+ if (rst == 1'b1) begin
+ stage_0_enable <= 1;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ timer <= 0;
+ timer_enable <= 0;
+ program_counter <= 0;
+ s_input_rs232_ack <= 0;
+ s_output_control_stb <= 0;
+ s_output_rs232_stb <= 0;
+ end
+ end
+ assign input_rs232_ack = s_input_rs232_ack;
+ assign output_control_stb = s_output_control_stb;
+ assign output_control = s_output_control;
+ assign output_rs232_stb = s_output_rs232_stb;
+ assign output_rs232 = s_output_rs232;
+
+endmodule
+"
+"module servo_tb;
+ reg clk;
+ reg rst;
+ wire [15:0] rs232_in;
+ wire rs232_in_stb;
+ wire rs232_in_ack;
+ wire [15:0] rs232_out;
+ wire rs232_out_stb;
+ wire rs232_out_ack;
+ wire [15:0] servos;
+ wire servos_stb;
+ wire servos_ack;
+
+ initial
+ begin
+ rst <= 1'b1;
+ #50 rst <= 1'b0;
+ end
+
+
+ initial
+ begin
+ #1000000 $finish;
+ end
+
+
+ initial
+ begin
+ clk <= 1'b0;
+ while (1) begin
+ #5 clk <= ~clk;
+ end
+ end
+
+ servo uut(
+ .clk(clk),
+ .rst(rst),
+ .rs232_in(rs232_in),
+ .rs232_in_stb(rs232_in_stb),
+ .rs232_in_ack(rs232_in_ack),
+ .rs232_out(rs232_out),
+ .rs232_out_stb(rs232_out_stb),
+ .rs232_out_ack(rs232_out_ack),
+ .servos(servos),
+ .servos_stb(servos_stb),
+ .servos_ack(servos_ack));
+endmodule
+"
+"//IEEE Floating Point Adder (Single Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+
+module adder(
+ input_a,
+ input_b,
+ input_a_stb,
+ input_b_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack,
+ input_b_ack);
+
+ input clk;
+ input rst;
+
+ input [31:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ input [31:0] input_b;
+ input input_b_stb;
+ output input_b_ack;
+
+ output [31:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [31:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [3:0] state;
+ parameter get_a = 4'd0,
+ get_b = 4'd1,
+ unpack = 4'd2,
+ special_cases = 4'd3,
+ align = 4'd4,
+ add_0 = 4'd5,
+ add_1 = 4'd6,
+ normalise_1 = 4'd7,
+ normalise_2 = 4'd8,
+ round = 4'd9,
+ pack = 4'd10,
+ put_z = 4'd11;
+
+ reg [31:0] a, b, z;
+ reg [26:0] a_m, b_m;
+ reg [23:0] z_m;
+ reg [9:0] a_e, b_e, z_e;
+ reg a_s, b_s, z_s;
+ reg guard, round_bit, sticky;
+ reg [27:0] sum;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= get_b;
+ end
+ end
+
+ get_b:
+ begin
+ s_input_b_ack <= 1;
+ if (s_input_b_ack && input_b_stb) begin
+ b <= input_b;
+ s_input_b_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m <= {a[22 : 0], 3'd0};
+ b_m <= {b[22 : 0], 3'd0};
+ a_e <= a[30 : 23] - 127;
+ b_e <= b[30 : 23] - 127;
+ a_s <= a[31];
+ b_s <= b[31];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ //if a is NaN or b is NaN return NaN
+ if ((a_e == 128 && a_m != 0) || (b_e == 128 && b_m != 0)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ //if a is inf return inf
+ end else if (a_e == 128) begin
+ z[31] <= a_s;
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if b is inf return inf
+ end else if (b_e == 128) begin
+ z[31] <= b_s;
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if a is zero return b
+ end else if ((($signed(a_e) == -127) && (a_m == 0)) && (($signed(b_e) == -127) && (b_m == 0))) begin
+ z[31] <= a_s & b_s;
+ z[30:23] <= b_e[7:0] + 127;
+ z[22:0] <= b_m[26:3];
+ state <= put_z;
+ //if a is zero return b
+ end else if (($signed(a_e) == -127) && (a_m == 0)) begin
+ z[31] <= b_s;
+ z[30:23] <= b_e[7:0] + 127;
+ z[22:0] <= b_m[26:3];
+ state <= put_z;
+ //if b is zero return a
+ end else if (($signed(b_e) == -127) && (b_m == 0)) begin
+ z[31] <= a_s;
+ z[30:23] <= a_e[7:0] + 127;
+ z[22:0] <= a_m[26:3];
+ state <= put_z;
+ end else begin
+ //Denormalised Number
+ if ($signed(a_e) == -127) begin
+ a_e <= -126;
+ end else begin
+ a_m[26] <= 1;
+ end
+ //Denormalised Number
+ if ($signed(b_e) == -127) begin
+ b_e <= -126;
+ end else begin
+ b_m[26] <= 1;
+ end
+ state <= align;
+ end
+ end
+
+ align:
+ begin
+ if ($signed(a_e) > $signed(b_e)) begin
+ b_e <= b_e + 1;
+ b_m <= b_m >> 1;
+ b_m[0] <= b_m[0] | b_m[1];
+ end else if ($signed(a_e) < $signed(b_e)) begin
+ a_e <= a_e + 1;
+ a_m <= a_m >> 1;
+ a_m[0] <= a_m[0] | a_m[1];
+ end else begin
+ state <= add_0;
+ end
+ end
+
+ add_0:
+ begin
+ z_e <= a_e;
+ if (a_s == b_s) begin
+ sum <= a_m + b_m;
+ z_s <= a_s;
+ end else begin
+ if (a_m >= b_m) begin
+ sum <= a_m - b_m;
+ z_s <= a_s;
+ end else begin
+ sum <= b_m - a_m;
+ z_s <= b_s;
+ end
+ end
+ state <= add_1;
+ end
+
+ add_1:
+ begin
+ if (sum[27]) begin
+ z_m <= sum[27:4];
+ guard <= sum[3];
+ round_bit <= sum[2];
+ sticky <= sum[1] | sum[0];
+ z_e <= z_e + 1;
+ end else begin
+ z_m <= sum[26:3];
+ guard <= sum[2];
+ round_bit <= sum[1];
+ sticky <= sum[0];
+ end
+ state <= normalise_1;
+ end
+
+ normalise_1:
+ begin
+ if (z_m[23] == 0 && $signed(z_e) > -126) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= guard;
+ guard <= round_bit;
+ round_bit <= 0;
+ end else begin
+ state <= normalise_2;
+ end
+ end
+
+ normalise_2:
+ begin
+ if ($signed(z_e) < -126) begin
+ z_e <= z_e + 1;
+ z_m <= z_m >> 1;
+ guard <= z_m[0];
+ round_bit <= guard;
+ sticky <= sticky | round_bit;
+ end else begin
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit | sticky | z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 24'hffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[22 : 0] <= z_m[22:0];
+ z[30 : 23] <= z_e[7:0] + 127;
+ z[31] <= z_s;
+ if ($signed(z_e) == -126 && z_m[23] == 0) begin
+ z[30 : 23] <= 0;
+ end
+ //if overflow occurs, return inf
+ if ($signed(z_e) > 127) begin
+ z[22 : 0] <= 0;
+ z[30 : 23] <= 255;
+ z[31] <= z_s;
+ end
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_input_b_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign input_b_ack = s_input_b_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point Divider (Single Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+//
+module divider(
+ input_a,
+ input_b,
+ input_a_stb,
+ input_b_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack,
+ input_b_ack);
+
+ input clk;
+ input rst;
+
+ input [31:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ input [31:0] input_b;
+ input input_b_stb;
+ output input_b_ack;
+
+ output [31:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [31:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [3:0] state;
+ parameter get_a = 4'd0,
+ get_b = 4'd1,
+ unpack = 4'd2,
+ special_cases = 4'd3,
+ normalise_a = 4'd4,
+ normalise_b = 4'd5,
+ divide_0 = 4'd6,
+ divide_1 = 4'd7,
+ divide_2 = 4'd8,
+ divide_3 = 4'd9,
+ normalise_1 = 4'd10,
+ normalise_2 = 4'd11,
+ round = 4'd12,
+ pack = 4'd13,
+ put_z = 4'd14;
+
+ reg [31:0] a, b, z;
+ reg [23:0] a_m, b_m, z_m;
+ reg [9:0] a_e, b_e, z_e;
+ reg a_s, b_s, z_s;
+ reg guard, round_bit, sticky;
+ reg [50:0] quotient, divisor, dividend, remainder;
+ reg [5:0] count;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= get_b;
+ end
+ end
+
+ get_b:
+ begin
+ s_input_b_ack <= 1;
+ if (s_input_b_ack && input_b_stb) begin
+ b <= input_b;
+ s_input_b_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m <= a[22 : 0];
+ b_m <= b[22 : 0];
+ a_e <= a[30 : 23] - 127;
+ b_e <= b[30 : 23] - 127;
+ a_s <= a[31];
+ b_s <= b[31];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ //if a is NaN or b is NaN return NaN
+ if ((a_e == 128 && a_m != 0) || (b_e == 128 && b_m != 0)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ //if a is inf and b is inf return NaN
+ end else if ((a_e == 128) && (b_e == 128)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ //if a is inf return inf
+ end else if (a_e == 128) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if b is zero return NaN
+ if ($signed(b_e == -127) && (b_m == 0)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ end
+ //if b is inf return zero
+ end else if (b_e == 128) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 0;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if a is zero return zero
+ end else if (($signed(a_e) == -127) && (a_m == 0)) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 0;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if b is zero return NaN
+ if (($signed(b_e) == -127) && (b_m == 0)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ end
+ //if b is zero return inf
+ end else if (($signed(b_e) == -127) && (b_m == 0)) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ state <= put_z;
+ end else begin
+ //Denormalised Number
+ if ($signed(a_e) == -127) begin
+ a_e <= -126;
+ end else begin
+ a_m[23] <= 1;
+ end
+ //Denormalised Number
+ if ($signed(b_e) == -127) begin
+ b_e <= -126;
+ end else begin
+ b_m[23] <= 1;
+ end
+ state <= normalise_a;
+ end
+ end
+
+ normalise_a:
+ begin
+ if (a_m[23]) begin
+ state <= normalise_b;
+ end else begin
+ a_m <= a_m << 1;
+ a_e <= a_e - 1;
+ end
+ end
+
+ normalise_b:
+ begin
+ if (b_m[23]) begin
+ state <= divide_0;
+ end else begin
+ b_m <= b_m << 1;
+ b_e <= b_e - 1;
+ end
+ end
+
+ divide_0:
+ begin
+ z_s <= a_s ^ b_s;
+ z_e <= a_e - b_e;
+ quotient <= 0;
+ remainder <= 0;
+ count <= 0;
+ dividend <= a_m << 27;
+ divisor <= b_m;
+ state <= divide_1;
+ end
+
+ divide_1:
+ begin
+ quotient <= quotient << 1;
+ remainder <= remainder << 1;
+ remainder[0] <= dividend[50];
+ dividend <= dividend << 1;
+ state <= divide_2;
+ end
+
+ divide_2:
+ begin
+ if (remainder >= divisor) begin
+ quotient[0] <= 1;
+ remainder <= remainder - divisor;
+ end
+ if (count == 49) begin
+ state <= divide_3;
+ end else begin
+ count <= count + 1;
+ state <= divide_1;
+ end
+ end
+
+ divide_3:
+ begin
+ z_m <= quotient[26:3];
+ guard <= quotient[2];
+ round_bit <= quotient[1];
+ sticky <= quotient[0] | (remainder != 0);
+ state <= normalise_1;
+ end
+
+ normalise_1:
+ begin
+ if (z_m[23] == 0 && $signed(z_e) > -126) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= guard;
+ guard <= round_bit;
+ round_bit <= 0;
+ end else begin
+ state <= normalise_2;
+ end
+ end
+
+ normalise_2:
+ begin
+ if ($signed(z_e) < -126) begin
+ z_e <= z_e + 1;
+ z_m <= z_m >> 1;
+ guard <= z_m[0];
+ round_bit <= guard;
+ sticky <= sticky | round_bit;
+ end else begin
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit | sticky | z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 24'hffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[22 : 0] <= z_m[22:0];
+ z[30 : 23] <= z_e[7:0] + 127;
+ z[31] <= z_s;
+ if ($signed(z_e) == -126 && z_m[23] == 0) begin
+ z[30 : 23] <= 0;
+ end
+ //if overflow occurs, return inf
+ if ($signed(z_e) > 127) begin
+ z[22 : 0] <= 0;
+ z[30 : 23] <= 255;
+ z[31] <= z_s;
+ end
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_input_b_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign input_b_ack = s_input_b_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point Multiplier (Single Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+module multiplier(
+ input_a,
+ input_b,
+ input_a_stb,
+ input_b_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack,
+ input_b_ack);
+
+ input clk;
+ input rst;
+
+ input [31:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ input [31:0] input_b;
+ input input_b_stb;
+ output input_b_ack;
+
+ output [31:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [31:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [3:0] state;
+ parameter get_a = 4'd0,
+ get_b = 4'd1,
+ unpack = 4'd2,
+ special_cases = 4'd3,
+ normalise_a = 4'd4,
+ normalise_b = 4'd5,
+ multiply_0 = 4'd6,
+ multiply_1 = 4'd7,
+ normalise_1 = 4'd8,
+ normalise_2 = 4'd9,
+ round = 4'd10,
+ pack = 4'd11,
+ put_z = 4'd12;
+
+ reg [31:0] a, b, z;
+ reg [23:0] a_m, b_m, z_m;
+ reg [9:0] a_e, b_e, z_e;
+ reg a_s, b_s, z_s;
+ reg guard, round_bit, sticky;
+ reg [49:0] product;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= get_b;
+ end
+ end
+
+ get_b:
+ begin
+ s_input_b_ack <= 1;
+ if (s_input_b_ack && input_b_stb) begin
+ b <= input_b;
+ s_input_b_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m <= a[22 : 0];
+ b_m <= b[22 : 0];
+ a_e <= a[30 : 23] - 127;
+ b_e <= b[30 : 23] - 127;
+ a_s <= a[31];
+ b_s <= b[31];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ //if a is NaN or b is NaN return NaN
+ if ((a_e == 128 && a_m != 0) || (b_e == 128 && b_m != 0)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ //if a is inf return inf
+ end else if (a_e == 128) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if b is zero return NaN
+ if ($signed(b_e == -127) && (b_m == 0)) begin
+ z[31] <= 1;
+ z[30:23] <= 255;
+ z[22] <= 1;
+ z[21:0] <= 0;
+ state <= put_z;
+ end
+ //if b is inf return inf
+ end else if (b_e == 128) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if a is zero return zero
+ end else if (($signed(a_e) == -127) && (a_m == 0)) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 0;
+ z[22:0] <= 0;
+ state <= put_z;
+ //if b is zero return zero
+ end else if (($signed(b_e) == -127) && (b_m == 0)) begin
+ z[31] <= a_s ^ b_s;
+ z[30:23] <= 0;
+ z[22:0] <= 0;
+ state <= put_z;
+ end else begin
+ //Denormalised Number
+ if ($signed(a_e) == -127) begin
+ a_e <= -126;
+ end else begin
+ a_m[23] <= 1;
+ end
+ //Denormalised Number
+ if ($signed(b_e) == -127) begin
+ b_e <= -126;
+ end else begin
+ b_m[23] <= 1;
+ end
+ state <= normalise_a;
+ end
+ end
+
+ normalise_a:
+ begin
+ if (a_m[23]) begin
+ state <= normalise_b;
+ end else begin
+ a_m <= a_m << 1;
+ a_e <= a_e - 1;
+ end
+ end
+
+ normalise_b:
+ begin
+ if (b_m[23]) begin
+ state <= multiply_0;
+ end else begin
+ b_m <= b_m << 1;
+ b_e <= b_e - 1;
+ end
+ end
+
+ multiply_0:
+ begin
+ z_s <= a_s ^ b_s;
+ z_e <= a_e + b_e + 1;
+ product <= a_m * b_m * 4;
+ state <= multiply_1;
+ end
+
+ multiply_1:
+ begin
+ z_m <= product[49:26];
+ guard <= product[25];
+ round_bit <= product[24];
+ sticky <= (product[23:0] != 0);
+ state <= normalise_1;
+ end
+
+ normalise_1:
+ begin
+ if (z_m[23] == 0) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= guard;
+ guard <= round_bit;
+ round_bit <= 0;
+ end else begin
+ state <= normalise_2;
+ end
+ end
+
+ normalise_2:
+ begin
+ if ($signed(z_e) < -126) begin
+ z_e <= z_e + 1;
+ z_m <= z_m >> 1;
+ guard <= z_m[0];
+ round_bit <= guard;
+ sticky <= sticky | round_bit;
+ end else begin
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit | sticky | z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 24'hffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[22 : 0] <= z_m[22:0];
+ z[30 : 23] <= z_e[7:0] + 127;
+ z[31] <= z_s;
+ if ($signed(z_e) == -126 && z_m[23] == 0) begin
+ z[30 : 23] <= 0;
+ end
+ //if overflow occurs, return inf
+ if ($signed(z_e) > 127) begin
+ z[22 : 0] <= 0;
+ z[30 : 23] <= 255;
+ z[31] <= z_s;
+ end
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_input_b_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign input_b_ack = s_input_b_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point Divider (Double Precision)
+//Copyright (C) Jonathan P Dawson 2014
+//2014-01-11
+//
+module double_divider(
+ input_a,
+ input_b,
+ input_a_stb,
+ input_b_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack,
+ input_b_ack);
+
+ input clk;
+ input rst;
+
+ input [63:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ input [63:0] input_b;
+ input input_b_stb;
+ output input_b_ack;
+
+ output [63:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [63:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [3:0] state;
+ parameter get_a = 4'd0,
+ get_b = 4'd1,
+ unpack = 4'd2,
+ special_cases = 4'd3,
+ normalise_a = 4'd4,
+ normalise_b = 4'd5,
+ divide_0 = 4'd6,
+ divide_1 = 4'd7,
+ divide_2 = 4'd8,
+ divide_3 = 4'd9,
+ normalise_1 = 4'd10,
+ normalise_2 = 4'd11,
+ round = 4'd12,
+ pack = 4'd13,
+ put_z = 4'd14;
+
+ reg [63:0] a, b, z;
+ reg [52:0] a_m, b_m, z_m;
+ reg [12:0] a_e, b_e, z_e;
+ reg a_s, b_s, z_s;
+ reg guard, round_bit, sticky;
+ reg [108:0] quotient, divisor, dividend, remainder;
+ reg [6:0] count;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= get_b;
+ end
+ end
+
+ get_b:
+ begin
+ s_input_b_ack <= 1;
+ if (s_input_b_ack && input_b_stb) begin
+ b <= input_b;
+ s_input_b_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m <= a[51 : 0];
+ b_m <= b[51 : 0];
+ a_e <= a[62 : 52] - 1023;
+ b_e <= b[62 : 52] - 1023;
+ a_s <= a[63];
+ b_s <= b[63];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ //if a is NaN or b is NaN return NaN
+ if ((a_e == 1024 && a_m != 0) || (b_e == 1024 && b_m != 0)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ //if a is inf and b is inf return NaN
+ end else if ((a_e == 1024) && (b_e == 1024)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ //if a is inf return inf
+ end else if (a_e == 1024) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 2047;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if b is zero return NaN
+ if ($signed(b_e == -1023) && (b_m == 0)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ end
+ //if b is inf return zero
+ end else if (b_e == 1024) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 0;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if a is zero return zero
+ end else if (($signed(a_e) == -1023) && (a_m == 0)) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 0;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if b is zero return NaN
+ if (($signed(b_e) == -1023) && (b_m == 0)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ end
+ //if b is zero return inf
+ end else if (($signed(b_e) == -1023) && (b_m == 0)) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 2047;
+ z[51:0] <= 0;
+ state <= put_z;
+ end else begin
+ //Denormalised Number
+ if ($signed(a_e) == -1023) begin
+ a_e <= -1022;
+ end else begin
+ a_m[52] <= 1;
+ end
+ //Denormalised Number
+ if ($signed(b_e) == -1023) begin
+ b_e <= -1022;
+ end else begin
+ b_m[52] <= 1;
+ end
+ state <= normalise_a;
+ end
+ end
+
+ normalise_a:
+ begin
+ if (a_m[52]) begin
+ state <= normalise_b;
+ end else begin
+ a_m <= a_m << 1;
+ a_e <= a_e - 1;
+ end
+ end
+
+ normalise_b:
+ begin
+ if (b_m[52]) begin
+ state <= divide_0;
+ end else begin
+ b_m <= b_m << 1;
+ b_e <= b_e - 1;
+ end
+ end
+
+ divide_0:
+ begin
+ z_s <= a_s ^ b_s;
+ z_e <= a_e - b_e;
+ quotient <= 0;
+ remainder <= 0;
+ count <= 0;
+ dividend <= a_m << 56;
+ divisor <= b_m;
+ state <= divide_1;
+ end
+
+ divide_1:
+ begin
+ quotient <= quotient << 1;
+ remainder <= remainder << 1;
+ remainder[0] <= dividend[108];
+ dividend <= dividend << 1;
+ state <= divide_2;
+ end
+
+ divide_2:
+ begin
+ if (remainder >= divisor) begin
+ quotient[0] <= 1;
+ remainder <= remainder - divisor;
+ end
+ if (count == 107) begin
+ state <= divide_3;
+ end else begin
+ count <= count + 1;
+ state <= divide_1;
+ end
+ end
+
+ divide_3:
+ begin
+ z_m <= quotient[55:3];
+ guard <= quotient[2];
+ round_bit <= quotient[1];
+ sticky <= quotient[0] | (remainder != 0);
+ state <= normalise_1;
+ end
+
+ normalise_1:
+ begin
+ if (z_m[52] == 0 && $signed(z_e) > -1022) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= guard;
+ guard <= round_bit;
+ round_bit <= 0;
+ end else begin
+ state <= normalise_2;
+ end
+ end
+
+ normalise_2:
+ begin
+ if ($signed(z_e) < -1022) begin
+ z_e <= z_e + 1;
+ z_m <= z_m >> 1;
+ guard <= z_m[0];
+ round_bit <= guard;
+ sticky <= sticky | round_bit;
+ end else begin
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit | sticky | z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 53'hffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[51 : 0] <= z_m[51:0];
+ z[62 : 52] <= z_e[10:0] + 1023;
+ z[63] <= z_s;
+ if ($signed(z_e) == -1022 && z_m[52] == 0) begin
+ z[62 : 52] <= 0;
+ end
+ //if overflow occurs, return inf
+ if ($signed(z_e) > 1023) begin
+ z[51 : 0] <= 0;
+ z[62 : 52] <= 2047;
+ z[63] <= z_s;
+ end
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_input_b_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign input_b_ack = s_input_b_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point Multiplier (Double Precision)
+//Copyright (C) Jonathan P Dawson 2014
+//2014-01-10
+module double_multiplier(
+ input_a,
+ input_b,
+ input_a_stb,
+ input_b_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack,
+ input_b_ack);
+
+ input clk;
+ input rst;
+
+ input [63:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ input [63:0] input_b;
+ input input_b_stb;
+ output input_b_ack;
+
+ output [63:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [63:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [3:0] state;
+ parameter get_a = 4'd0,
+ get_b = 4'd1,
+ unpack = 4'd2,
+ special_cases = 4'd3,
+ normalise_a = 4'd4,
+ normalise_b = 4'd5,
+ multiply_0 = 4'd6,
+ multiply_1 = 4'd7,
+ normalise_1 = 4'd8,
+ normalise_2 = 4'd9,
+ round = 4'd10,
+ pack = 4'd11,
+ put_z = 4'd12;
+
+ reg [63:0] a, b, z;
+ reg [52:0] a_m, b_m, z_m;
+ reg [12:0] a_e, b_e, z_e;
+ reg a_s, b_s, z_s;
+ reg guard, round_bit, sticky;
+ reg [107:0] product;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= get_b;
+ end
+ end
+
+ get_b:
+ begin
+ s_input_b_ack <= 1;
+ if (s_input_b_ack && input_b_stb) begin
+ b <= input_b;
+ s_input_b_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m <= a[51 : 0];
+ b_m <= b[51 : 0];
+ a_e <= a[62 : 52] - 1023;
+ b_e <= b[62 : 52] - 1023;
+ a_s <= a[63];
+ b_s <= b[63];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ //if a is NaN or b is NaN return NaN
+ if ((a_e == 1024 && a_m != 0) || (b_e == 1024 && b_m != 0)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ //if a is inf return inf
+ end else if (a_e == 1024) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 2047;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if b is zero return NaN
+ if ($signed(b_e == -1023) && (b_m == 0)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ end
+ //if b is inf return inf
+ end else if (b_e == 1024) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 2047;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if a is zero return zero
+ end else if (($signed(a_e) == -1023) && (a_m == 0)) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 0;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if b is zero return zero
+ end else if (($signed(b_e) == -1023) && (b_m == 0)) begin
+ z[63] <= a_s ^ b_s;
+ z[62:52] <= 0;
+ z[51:0] <= 0;
+ state <= put_z;
+ end else begin
+ //Denormalised Number
+ if ($signed(a_e) == -1023) begin
+ a_e <= -1022;
+ end else begin
+ a_m[52] <= 1;
+ end
+ //Denormalised Number
+ if ($signed(b_e) == -1023) begin
+ b_e <= -1022;
+ end else begin
+ b_m[52] <= 1;
+ end
+ state <= normalise_a;
+ end
+ end
+
+ normalise_a:
+ begin
+ if (a_m[52]) begin
+ state <= normalise_b;
+ end else begin
+ a_m <= a_m << 1;
+ a_e <= a_e - 1;
+ end
+ end
+
+ normalise_b:
+ begin
+ if (b_m[52]) begin
+ state <= multiply_0;
+ end else begin
+ b_m <= b_m << 1;
+ b_e <= b_e - 1;
+ end
+ end
+
+ multiply_0:
+ begin
+ z_s <= a_s ^ b_s;
+ z_e <= a_e + b_e + 1;
+ product <= a_m * b_m * 4;
+ state <= multiply_1;
+ end
+
+ multiply_1:
+ begin
+ z_m <= product[107:55];
+ guard <= product[54];
+ round_bit <= product[53];
+ sticky <= (product[52:0] != 0);
+ state <= normalise_1;
+ end
+
+ normalise_1:
+ begin
+ if (z_m[52] == 0) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= guard;
+ guard <= round_bit;
+ round_bit <= 0;
+ end else begin
+ state <= normalise_2;
+ end
+ end
+
+ normalise_2:
+ begin
+ if ($signed(z_e) < -1022) begin
+ z_e <= z_e + 1;
+ z_m <= z_m >> 1;
+ guard <= z_m[0];
+ round_bit <= guard;
+ sticky <= sticky | round_bit;
+ end else begin
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit | sticky | z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 53'hffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[51 : 0] <= z_m[51:0];
+ z[62 : 52] <= z_e[11:0] + 1023;
+ z[63] <= z_s;
+ if ($signed(z_e) == -1022 && z_m[52] == 0) begin
+ z[62 : 52] <= 0;
+ end
+ //if overflow occurs, return inf
+ if ($signed(z_e) > 1023) begin
+ z[51 : 0] <= 0;
+ z[62 : 52] <= 2047;
+ z[63] <= z_s;
+ end
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_input_b_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign input_b_ack = s_input_b_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point Adder (Double Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+
+module double_adder(
+ input_a,
+ input_b,
+ input_a_stb,
+ input_b_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack,
+ input_b_ack);
+
+ input clk;
+ input rst;
+
+ input [63:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ input [63:0] input_b;
+ input input_b_stb;
+ output input_b_ack;
+
+ output [63:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [63:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [3:0] state;
+ parameter get_a = 4'd0,
+ get_b = 4'd1,
+ unpack = 4'd2,
+ special_cases = 4'd3,
+ align = 4'd4,
+ add_0 = 4'd5,
+ add_1 = 4'd6,
+ normalise_1 = 4'd7,
+ normalise_2 = 4'd8,
+ round = 4'd9,
+ pack = 4'd10,
+ put_z = 4'd11;
+
+ reg [63:0] a, b, z;
+ reg [55:0] a_m, b_m;
+ reg [52:0] z_m;
+ reg [12:0] a_e, b_e, z_e;
+ reg a_s, b_s, z_s;
+ reg guard, round_bit, sticky;
+ reg [56:0] sum;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= get_b;
+ end
+ end
+
+ get_b:
+ begin
+ s_input_b_ack <= 1;
+ if (s_input_b_ack && input_b_stb) begin
+ b <= input_b;
+ s_input_b_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m <= {a[51 : 0], 3'd0};
+ b_m <= {b[51 : 0], 3'd0};
+ a_e <= a[62 : 52] - 1023;
+ b_e <= b[62 : 52] - 1023;
+ a_s <= a[63];
+ b_s <= b[63];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ //if a is NaN or b is NaN return NaN
+ if ((a_e == 1024 && a_m != 0) || (b_e == 1024 && b_m != 0)) begin
+ z[63] <= 1;
+ z[62:52] <= 2047;
+ z[51] <= 1;
+ z[50:0] <= 0;
+ state <= put_z;
+ //if a is inf return inf
+ end else if (a_e == 1024) begin
+ z[63] <= a_s;
+ z[62:52] <= 2047;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if b is inf return inf
+ end else if (b_e == 1024) begin
+ z[63] <= b_s;
+ z[62:52] <= 2047;
+ z[51:0] <= 0;
+ state <= put_z;
+ //if a is zero return b
+ end else if ((($signed(a_e) == -1023) && (a_m == 0)) && (($signed(b_e) == -1023) && (b_m == 0))) begin
+ z[63] <= a_s & b_s;
+ z[62:52] <= b_e[10:0] + 1023;
+ z[51:0] <= b_m[55:3];
+ state <= put_z;
+ //if a is zero return b
+ end else if (($signed(a_e) == -1023) && (a_m == 0)) begin
+ z[63] <= b_s;
+ z[62:52] <= b_e[10:0] + 1023;
+ z[51:0] <= b_m[55:3];
+ state <= put_z;
+ //if b is zero return a
+ end else if (($signed(b_e) == -1023) && (b_m == 0)) begin
+ z[63] <= a_s;
+ z[62:52] <= a_e[10:0] + 1023;
+ z[51:0] <= a_m[55:3];
+ state <= put_z;
+ end else begin
+ //Denormalised Number
+ if ($signed(a_e) == -1023) begin
+ a_e <= -1022;
+ end else begin
+ a_m[55] <= 1;
+ end
+ //Denormalised Number
+ if ($signed(b_e) == -1023) begin
+ b_e <= -1022;
+ end else begin
+ b_m[55] <= 1;
+ end
+ state <= align;
+ end
+ end
+
+ align:
+ begin
+ if ($signed(a_e) > $signed(b_e)) begin
+ b_e <= b_e + 1;
+ b_m <= b_m >> 1;
+ b_m[0] <= b_m[0] | b_m[1];
+ end else if ($signed(a_e) < $signed(b_e)) begin
+ a_e <= a_e + 1;
+ a_m <= a_m >> 1;
+ a_m[0] <= a_m[0] | a_m[1];
+ end else begin
+ state <= add_0;
+ end
+ end
+
+ add_0:
+ begin
+ z_e <= a_e;
+ if (a_s == b_s) begin
+ sum <= {1'd0, a_m} + b_m;
+ z_s <= a_s;
+ end else begin
+ if (a_m > b_m) begin
+ sum <= {1'd0, a_m} - b_m;
+ z_s <= a_s;
+ end else begin
+ sum <= {1'd0, b_m} - a_m;
+ z_s <= b_s;
+ end
+ end
+ state <= add_1;
+ end
+
+ add_1:
+ begin
+ if (sum[56]) begin
+ z_m <= sum[56:4];
+ guard <= sum[3];
+ round_bit <= sum[2];
+ sticky <= sum[1] | sum[0];
+ z_e <= z_e + 1;
+ end else begin
+ z_m <= sum[55:3];
+ guard <= sum[2];
+ round_bit <= sum[1];
+ sticky <= sum[0];
+ end
+ state <= normalise_1;
+ end
+
+ normalise_1:
+ begin
+ if (z_m[52] == 0 && $signed(z_e) > -1022) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= guard;
+ guard <= round_bit;
+ round_bit <= 0;
+ end else begin
+ state <= normalise_2;
+ end
+ end
+
+ normalise_2:
+ begin
+ if ($signed(z_e) < -1022) begin
+ z_e <= z_e + 1;
+ z_m <= z_m >> 1;
+ guard <= z_m[0];
+ round_bit <= guard;
+ sticky <= sticky | round_bit;
+ end else begin
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit | sticky | z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 53'h1fffffffffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[51 : 0] <= z_m[51:0];
+ z[62 : 52] <= z_e[10:0] + 1023;
+ z[63] <= z_s;
+ if ($signed(z_e) == -1022 && z_m[52] == 0) begin
+ z[62 : 52] <= 0;
+ end
+ //if overflow occurs, return inf
+ if ($signed(z_e) > 1023) begin
+ z[51 : 0] <= 0;
+ z[62 : 52] <= 2047;
+ z[63] <= z_s;
+ end
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_input_b_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign input_b_ack = s_input_b_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//Integer to IEEE Floating Point Converter (Single Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+module int_to_float(
+ input_a,
+ input_a_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack);
+
+ input clk;
+ input rst;
+
+ input [31:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ output [31:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [31:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [2:0] state;
+ parameter get_a = 3'd0,
+ convert_0 = 3'd1,
+ convert_1 = 3'd2,
+ convert_2 = 3'd3,
+ round = 3'd4,
+ pack = 3'd5,
+ put_z = 3'd6;
+
+ reg [31:0] a, z, value;
+ reg [23:0] z_m;
+ reg [7:0] z_r;
+ reg [7:0] z_e;
+ reg z_s;
+ reg guard, round_bit, sticky;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= convert_0;
+ end
+ end
+
+ convert_0:
+ begin
+ if ( a == 0 ) begin
+ z_s <= 0;
+ z_m <= 0;
+ z_e <= -127;
+ state <= pack;
+ end else begin
+ value <= a[31] ? -a : a;
+ z_s <= a[31];
+ state <= convert_1;
+ end
+ end
+
+ convert_1:
+ begin
+ z_e <= 31;
+ z_m <= value[31:8];
+ z_r <= value[7:0];
+ state <= convert_2;
+ end
+
+ convert_2:
+ begin
+ if (!z_m[23]) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= z_r[7];
+ z_r <= z_r << 1;
+ end else begin
+ guard <= z_r[7];
+ round_bit <= z_r[6];
+ sticky <= z_r[5:0] != 0;
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit || sticky || z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 24'hffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[22 : 0] <= z_m[22:0];
+ z[30 : 23] <= z_e + 127;
+ z[31] <= z_s;
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point to Integer Converter (Single Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+module float_to_int(
+ input_a,
+ input_a_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack);
+
+ input clk;
+ input rst;
+
+ input [31:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ output [31:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [31:0] s_output_z;
+ reg s_input_a_ack;
+
+ reg [2:0] state;
+ parameter get_a = 3'd0,
+ special_cases = 3'd1,
+ unpack = 3'd2,
+ convert = 3'd3,
+ put_z = 3'd4;
+
+ reg [31:0] a_m, a, z;
+ reg [8:0] a_e;
+ reg a_s;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m[31:8] <= {1'b1, a[22 : 0]};
+ a_m[7:0] <= 0;
+ a_e <= a[30 : 23] - 127;
+ a_s <= a[31];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ if ($signed(a_e) == -127) begin
+ z <= 0;
+ state <= put_z;
+ end else if ($signed(a_e) > 31) begin
+ z <= 32'h80000000;
+ state <= put_z;
+ end else begin
+ state <= convert;
+ end
+ end
+
+ convert:
+ begin
+ if ($signed(a_e) < 31 && a_m) begin
+ a_e <= a_e + 1;
+ a_m <= a_m >> 1;
+ end else begin
+ if (a_m[31]) begin
+ z <= 32'h80000000;
+ end else begin
+ z <= a_s ? -a_m : a_m;
+ end
+ state <= put_z;
+ end
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//Integer to IEEE Floating Point Converter (Double Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+module long_to_double(
+ input_a,
+ input_a_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack);
+
+ input clk;
+ input rst;
+
+ input [63:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ output [63:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [63:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [2:0] state;
+ parameter get_a = 3'd0,
+ convert_0 = 3'd1,
+ convert_1 = 3'd2,
+ convert_2 = 3'd3,
+ round = 3'd4,
+ pack = 3'd5,
+ put_z = 3'd6;
+
+ reg [63:0] a, z, value;
+ reg [52:0] z_m;
+ reg [10:0] z_r;
+ reg [10:0] z_e;
+ reg z_s;
+ reg guard, round_bit, sticky;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= convert_0;
+ end
+ end
+
+ convert_0:
+ begin
+ if ( a == 0 ) begin
+ z_s <= 0;
+ z_m <= 0;
+ z_e <= -1023;
+ state <= pack;
+ end else begin
+ value <= a[63] ? -a : a;
+ z_s <= a[63];
+ state <= convert_1;
+ end
+ end
+
+ convert_1:
+ begin
+ z_e <= 63;
+ z_m <= value[63:11];
+ z_r <= value[10:0];
+ state <= convert_2;
+ end
+
+ convert_2:
+ begin
+ if (!z_m[52]) begin
+ z_e <= z_e - 1;
+ z_m <= z_m << 1;
+ z_m[0] <= z_r[10];
+ z_r <= z_r << 1;
+ end else begin
+ guard <= z_r[10];
+ round_bit <= z_r[9];
+ sticky <= z_r[8:0] != 0;
+ state <= round;
+ end
+ end
+
+ round:
+ begin
+ if (guard && (round_bit || sticky || z_m[0])) begin
+ z_m <= z_m + 1;
+ if (z_m == 53'h1fffffffffffff) begin
+ z_e <=z_e + 1;
+ end
+ end
+ state <= pack;
+ end
+
+ pack:
+ begin
+ z[51 : 0] <= z_m[51:0];
+ z[62 : 52] <= z_e + 1023;
+ z[63] <= z_s;
+ state <= put_z;
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point to Integer Converter (Double Precision)
+//Copyright (C) Jonathan P Dawson 2014
+//2014-01-11
+module double_to_long(
+ input_a,
+ input_a_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack);
+
+ input clk;
+ input rst;
+
+ input [63:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ output [63:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [63:0] s_output_z;
+ reg s_input_a_ack;
+
+ reg [2:0] state;
+ parameter get_a = 3'd0,
+ special_cases = 3'd1,
+ unpack = 3'd2,
+ convert = 3'd3,
+ put_z = 3'd4;
+
+ reg [63:0] a_m, a, z;
+ reg [11:0] a_e;
+ reg a_s;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ a_m[63:11] <= {1'b1, a[51 : 0]};
+ a_m[10:0] <= 0;
+ a_e <= a[62 : 52] - 1023;
+ a_s <= a[63];
+ state <= special_cases;
+ end
+
+ special_cases:
+ begin
+ if ($signed(a_e) == -1023) begin
+ //zero
+ z <= 0;
+ state <= put_z;
+ end else if ($signed(a_e) == 1024 && a[51:0] != 0) begin
+ //nan
+ z <= 64'h8000000000000000;
+ state <= put_z;
+ end else if ($signed(a_e) > 63) begin
+ //too big
+ if (a_s) begin
+ z <= 64'h8000000000000000;
+ end else begin
+ z <= 64'h0000000000000000;
+ end
+ state <= put_z;
+ end else begin
+ state <= convert;
+ end
+ end
+
+ convert:
+ begin
+ if ($signed(a_e) < 63 && a_m) begin
+ a_e <= a_e + 1;
+ a_m <= a_m >> 1;
+ end else begin
+ if (a_m[63] && a_s) begin
+ z <= 64'h8000000000000000;
+ end else begin
+ z <= a_s ? -a_m : a_m;
+ end
+ state <= put_z;
+ end
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//Integer to IEEE Floating Point Converter (Double Precision)
+//Copyright (C) Jonathan P Dawson 2013
+//2013-12-12
+module float_to_double(
+ input_a,
+ input_a_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack);
+
+ input clk;
+ input rst;
+
+ input [31:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ output [63:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [63:0] s_output_z;
+ reg s_input_a_ack;
+ reg s_input_b_ack;
+
+ reg [1:0] state;
+ parameter get_a = 3'd0,
+ convert_0 = 3'd1,
+ normalise_0 = 3'd2,
+ put_z = 3'd3;
+
+ reg [63:0] z;
+ reg [10:0] z_e;
+ reg [52:0] z_m;
+ reg [31:0] a;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= convert_0;
+ end
+ end
+
+ convert_0:
+ begin
+ z[63] <= a[31];
+ z[62:52] <= (a[30:23] - 127) + 1023;
+ z[51:0] <= {a[22:0], 29'd0};
+ if (a[30:23] == 255) begin
+ z[62:52] <= 2047;
+ end
+ state <= put_z;
+ if (a[30:23] == 0) begin
+ if (a[23:0]) begin
+ state <= normalise_0;
+ z_e <= 897;
+ z_m <= {1'd0, a[22:0], 29'd0};
+ end
+ z[62:52] <= 0;
+ end
+ end
+
+ normalise_0:
+ begin
+ if (z_m[52]) begin
+ z[62:52] <= z_e;
+ z[51:0] <= z_m[51:0];
+ state <= put_z;
+ end else begin
+ z_m <= {z_m[51:0], 1'd0};
+ z_e <= z_e - 1;
+ end
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+//IEEE Floating Point to Integer Converter (Double Precision)
+//Copyright (C) Jonathan P Dawson 2014
+//2014-01-11
+module double_to_float(
+ input_a,
+ input_a_stb,
+ output_z_ack,
+ clk,
+ rst,
+ output_z,
+ output_z_stb,
+ input_a_ack);
+
+ input clk;
+ input rst;
+
+ input [63:0] input_a;
+ input input_a_stb;
+ output input_a_ack;
+
+ output [31:0] output_z;
+ output output_z_stb;
+ input output_z_ack;
+
+ reg s_output_z_stb;
+ reg [31:0] s_output_z;
+ reg s_input_a_ack;
+
+ reg [1:0] state;
+ parameter get_a = 3'd0,
+ unpack = 3'd1,
+ denormalise = 3'd2,
+ put_z = 3'd3;
+
+ reg [63:0] a;
+ reg [31:0] z;
+ reg [10:0] z_e;
+ reg [23:0] z_m;
+ reg guard;
+ reg round;
+ reg sticky;
+
+ always @(posedge clk)
+ begin
+
+ case(state)
+
+ get_a:
+ begin
+ s_input_a_ack <= 1;
+ if (s_input_a_ack && input_a_stb) begin
+ a <= input_a;
+ s_input_a_ack <= 0;
+ state <= unpack;
+ end
+ end
+
+ unpack:
+ begin
+ z[31] <= a[63];
+ state <= put_z;
+ if (a[62:52] == 0) begin
+ z[30:23] <= 0;
+ z[22:0] <= 0;
+ end else if (a[62:52] < 897) begin
+ z[30:23] <= 0;
+ z_m <= {1'd1, a[51:29]};
+ z_e <= a[62:52];
+ guard <= a[28];
+ round <= a[27];
+ sticky <= a[26:0] != 0;
+ state <= denormalise;
+ end else if (a[62:52] == 2047) begin
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ if (a[51:0]) begin
+ z[22] <= 1;
+ end
+ end else if (a[62:52] > 1150) begin
+ z[30:23] <= 255;
+ z[22:0] <= 0;
+ end else begin
+ z[30:23] <= (a[62:52] - 1023) + 127;
+ if (a[28] && (a[27] || a[26:0])) begin
+ z[22:0] <= a[51:29] + 1;
+ end else begin
+ z[22:0] <= a[51:29];
+ end
+ end
+ end
+
+ denormalise:
+ begin
+ if (z_e == 897 || (z_m == 0 && guard == 0)) begin
+ state <= put_z;
+ z[22:0] <= z_m;
+ if (guard && (round || sticky)) begin
+ z[22:0] <= z_m + 1;
+ end
+ end else begin
+ z_e <= z_e + 1;
+ z_m <= {1'd0, z_m[23:1]};
+ guard <= z_m[0];
+ round <= guard;
+ sticky <= sticky | round;
+ end
+ end
+
+ put_z:
+ begin
+ s_output_z_stb <= 1;
+ s_output_z <= z;
+ if (s_output_z_stb && output_z_ack) begin
+ s_output_z_stb <= 0;
+ state <= get_a;
+ end
+ end
+
+ endcase
+
+ if (rst == 1) begin
+ state <= get_a;
+ s_input_a_ack <= 0;
+ s_output_z_stb <= 0;
+ end
+
+ end
+ assign input_a_ack = s_input_a_ack;
+ assign output_z_stb = s_output_z_stb;
+ assign output_z = s_output_z;
+
+endmodule
+
+"
+"//////////////////////////////////////////////////////////////////////////////
+//name : servo_controller
+//input : input_control:16
+//output : output_servos:16
+//source_file : servo_controller.c
+///================
+///
+///Created by C2CHIP
+
+//////////////////////////////////////////////////////////////////////////////
+// Register Allocation
+// ===================
+// Register Name Size
+// 0 variable pulses 2
+// 1 temporary_register 2
+// 2 temporary_register 2
+// 3 temporary_register 2
+// 4 temporary_register 4
+// 5 temporary_register 4
+// 6 temporary_register 4
+// 7 temporary_register 2
+// 8 temporary_register 2
+// 9 wait_us return address 2
+// 10 variable us 4
+// 11 variable i 2
+// 12 servo_controller return address 2
+// 13 array 2
+// 14 variable servo 2
+// 15 variable position 2
+module servo_controller(input_control,input_control_stb,output_servos_ack,clk,rst,output_servos,output_servos_stb,input_control_ack);
+ integer file_count;
+ real fp_value;
+ input [15:0] input_control;
+ input input_control_stb;
+ input output_servos_ack;
+ input clk;
+ input rst;
+ output [15:0] output_servos;
+ output output_servos_stb;
+ output input_control_ack;
+ reg [15:0] timer;
+ reg timer_enable;
+ reg stage_0_enable;
+ reg stage_1_enable;
+ reg stage_2_enable;
+ reg [7:0] program_counter;
+ reg [7:0] program_counter_0;
+ reg [44:0] instruction_0;
+ reg [4:0] opcode_0;
+ reg [3:0] dest_0;
+ reg [3:0] src_0;
+ reg [3:0] srcb_0;
+ reg [31:0] literal_0;
+ reg [7:0] program_counter_1;
+ reg [4:0] opcode_1;
+ reg [3:0] dest_1;
+ reg [31:0] register_1;
+ reg [31:0] registerb_1;
+ reg [31:0] literal_1;
+ reg [3:0] dest_2;
+ reg [31:0] result_2;
+ reg write_enable_2;
+ reg [15:0] address_2;
+ reg [15:0] data_out_2;
+ reg [15:0] data_in_2;
+ reg memory_enable_2;
+ reg [15:0] address_4;
+ reg [31:0] data_out_4;
+ reg [31:0] data_in_4;
+ reg memory_enable_4;
+ reg [15:0] s_output_servos_stb;
+ reg [15:0] s_output_servos;
+ reg [15:0] s_input_control_ack;
+ reg [15:0] memory_2 [7:0];
+ reg [44:0] instructions [166:0];
+ reg [31:0] registers [15:0];
+
+ //////////////////////////////////////////////////////////////////////////////
+ // INSTRUCTION INITIALIZATION
+ //
+ // Initialise the contents of the instruction memory
+ //
+ // Intruction Set
+ // ==============
+ // 0 {'float': False, 'literal': True, 'right': False, 'unsigned': False, 'op': 'jmp_and_link'}
+ // 1 {'float': False, 'literal': False, 'right': False, 'unsigned': False, 'op': 'stop'}
+ // 2 {'float': False, 'literal': True, 'right': False, 'unsigned': False, 'op': 'literal'}
+ // 3 {'float': False, 'literal': False, 'right': False, 'unsigned': False, 'op': 'nop'}
+ // 4 {'float': False, 'literal': False, 'right': False, 'unsigned': False, 'op': 'move'}
+ // 5 {'float': False, 'literal': False, 'right': False, 'unsigned': True, 'op': '<'}
+ // 6 {'float': False, 'literal': True, 'right': False, 'unsigned': False, 'op': 'jmp_if_false'}
+ // 7 {'float': False, 'literal': False, 'right': False, 'unsigned': False, 'op': 'wait_clocks'}
+ // 8 {'float': False, 'literal': True, 'right': True, 'unsigned': True, 'op': '+'}
+ // 9 {'float': False, 'literal': True, 'right': False, 'unsigned': False, 'op': 'goto'}
+ // 10 {'float': False, 'literal': False, 'right': False, 'unsigned': False, 'op': 'jmp_to_reg'}
+ // 11 {'float': False, 'literal': True, 'right': True, 'unsigned': True, 'op': '<'}
+ // 12 {'float': False, 'literal': False, 'right': False, 'unsigned': False, 'op': '+'}
+ // 13 {'right': False, 'element_size': 2, 'float': False, 'unsigned': False, 'literal': False, 'op': 'memory_write'}
+ // 14 {'right': False, 'float': False, 'unsigned': False, 'literal': False, 'input': 'control', 'op': 'ready'}
+ // 15 {'right': False, 'float': False, 'unsigned': False, 'literal': False, 'input': 'control', 'op': 'read'}
+ // 16 {'float': False, 'literal': False, 'right': False, 'unsigned': True, 'op': '+'}
+ // 17 {'right': False, 'element_size': 2, 'float': False, 'unsigned': False, 'literal': False, 'op': 'memory_read_request'}
+ // 18 {'right': False, 'element_size': 2, 'float': False, 'unsigned': False, 'literal': False, 'op': 'memory_read_wait'}
+ // 19 {'right': False, 'element_size': 2, 'float': False, 'unsigned': False, 'literal': False, 'op': 'memory_read'}
+ // 20 {'float': False, 'literal': False, 'right': False, 'unsigned': True, 'op': '>='}
+ // 21 {'float': False, 'literal': True, 'right': False, 'unsigned': True, 'op': '<<'}
+ // 22 {'float': False, 'literal': False, 'right': False, 'unsigned': False, 'op': '~'}
+ // 23 {'float': False, 'literal': False, 'right': False, 'unsigned': True, 'op': '&'}
+ // 24 {'right': False, 'float': False, 'unsigned': False, 'literal': False, 'output': 'servos', 'op': 'write'}
+ // Intructions
+ // ===========
+
+ initial
+ begin
+ instructions[0] = {5'd0, 4'd12, 4'd0, 32'd25};//{'dest': 12, 'label': 25, 'op': 'jmp_and_link'}
+ instructions[1] = {5'd1, 4'd0, 4'd0, 32'd0};//{'op': 'stop'}
+ instructions[2] = {5'd2, 4'd11, 4'd0, 32'd0};//{'dest': 11, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[3] = {5'd2, 4'd1, 4'd0, 32'd0};//{'dest': 1, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[4] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[5] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[6] = {5'd4, 4'd11, 4'd1, 32'd0};//{'dest': 11, 'src': 1, 'op': 'move'}
+ instructions[7] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[8] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[9] = {5'd4, 4'd5, 4'd11, 32'd0};//{'dest': 5, 'src': 11, 'op': 'move'}
+ instructions[10] = {5'd4, 4'd6, 4'd10, 32'd0};//{'dest': 6, 'src': 10, 'op': 'move'}
+ instructions[11] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[12] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[13] = {5'd5, 4'd4, 4'd5, 32'd6};//{'srcb': 6, 'src': 5, 'dest': 4, 'signed': False, 'op': '<', 'type': 'int', 'size': 4}
+ instructions[14] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[15] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[16] = {5'd6, 4'd0, 4'd4, 32'd24};//{'src': 4, 'label': 24, 'op': 'jmp_if_false'}
+ instructions[17] = {5'd2, 4'd4, 4'd0, 32'd100};//{'dest': 4, 'literal': 100, 'size': 4, 'signed': 4, 'op': 'literal'}
+ instructions[18] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[19] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[20] = {5'd7, 4'd0, 4'd4, 32'd0};//{'src': 4, 'op': 'wait_clocks'}
+ instructions[21] = {5'd4, 4'd1, 4'd11, 32'd0};//{'dest': 1, 'src': 11, 'op': 'move'}
+ instructions[22] = {5'd8, 4'd11, 4'd11, 32'd1};//{'src': 11, 'right': 1, 'dest': 11, 'signed': False, 'op': '+', 'size': 2}
+ instructions[23] = {5'd9, 4'd0, 4'd0, 32'd7};//{'label': 7, 'op': 'goto'}
+ instructions[24] = {5'd10, 4'd0, 4'd9, 32'd0};//{'src': 9, 'op': 'jmp_to_reg'}
+ instructions[25] = {5'd2, 4'd13, 4'd0, 32'd0};//{'dest': 13, 'literal': 0, 'op': 'literal'}
+ instructions[26] = {5'd2, 4'd14, 4'd0, 32'd0};//{'dest': 14, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[27] = {5'd2, 4'd15, 4'd0, 32'd0};//{'dest': 15, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[28] = {5'd2, 4'd0, 4'd0, 32'd0};//{'dest': 0, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[29] = {5'd2, 4'd1, 4'd0, 32'd0};//{'dest': 1, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[30] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[31] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[32] = {5'd4, 4'd14, 4'd1, 32'd0};//{'dest': 14, 'src': 1, 'op': 'move'}
+ instructions[33] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[34] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[35] = {5'd4, 4'd2, 4'd14, 32'd0};//{'dest': 2, 'src': 14, 'op': 'move'}
+ instructions[36] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[37] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[38] = {5'd11, 4'd1, 4'd2, 32'd8};//{'src': 2, 'right': 8, 'dest': 1, 'signed': False, 'op': '<', 'type': 'int', 'size': 2}
+ instructions[39] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[40] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[41] = {5'd6, 4'd0, 4'd1, 32'd53};//{'src': 1, 'label': 53, 'op': 'jmp_if_false'}
+ instructions[42] = {5'd2, 4'd1, 4'd0, 32'd0};//{'dest': 1, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[43] = {5'd4, 4'd2, 4'd14, 32'd0};//{'dest': 2, 'src': 14, 'op': 'move'}
+ instructions[44] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[45] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[46] = {5'd12, 4'd3, 4'd2, 32'd13};//{'dest': 3, 'src': 2, 'srcb': 13, 'signed': True, 'op': '+'}
+ instructions[47] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[48] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[49] = {5'd13, 4'd0, 4'd3, 32'd1};//{'srcb': 1, 'src': 3, 'element_size': 2, 'op': 'memory_write'}
+ instructions[50] = {5'd4, 4'd1, 4'd14, 32'd0};//{'dest': 1, 'src': 14, 'op': 'move'}
+ instructions[51] = {5'd8, 4'd14, 4'd14, 32'd1};//{'src': 14, 'right': 1, 'dest': 14, 'signed': False, 'op': '+', 'size': 2}
+ instructions[52] = {5'd9, 4'd0, 4'd0, 32'd33};//{'label': 33, 'op': 'goto'}
+ instructions[53] = {5'd14, 4'd1, 4'd0, 32'd0};//{'dest': 1, 'input': 'control', 'op': 'ready'}
+ instructions[54] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[55] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[56] = {5'd6, 4'd0, 4'd1, 32'd76};//{'src': 1, 'label': 76, 'op': 'jmp_if_false'}
+ instructions[57] = {5'd15, 4'd1, 4'd0, 32'd0};//{'dest': 1, 'input': 'control', 'op': 'read'}
+ instructions[58] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[59] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[60] = {5'd4, 4'd14, 4'd1, 32'd0};//{'dest': 14, 'src': 1, 'op': 'move'}
+ instructions[61] = {5'd15, 4'd1, 4'd0, 32'd0};//{'dest': 1, 'input': 'control', 'op': 'read'}
+ instructions[62] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[63] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[64] = {5'd4, 4'd15, 4'd1, 32'd0};//{'dest': 15, 'src': 1, 'op': 'move'}
+ instructions[65] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[66] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[67] = {5'd4, 4'd1, 4'd15, 32'd0};//{'dest': 1, 'src': 15, 'op': 'move'}
+ instructions[68] = {5'd4, 4'd2, 4'd14, 32'd0};//{'dest': 2, 'src': 14, 'op': 'move'}
+ instructions[69] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[70] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[71] = {5'd16, 4'd3, 4'd2, 32'd13};//{'dest': 3, 'src': 2, 'srcb': 13, 'signed': False, 'op': '+'}
+ instructions[72] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[73] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[74] = {5'd13, 4'd0, 4'd3, 32'd1};//{'srcb': 1, 'src': 3, 'element_size': 2, 'op': 'memory_write'}
+ instructions[75] = {5'd9, 4'd0, 4'd0, 32'd76};//{'label': 76, 'op': 'goto'}
+ instructions[76] = {5'd2, 4'd1, 4'd0, 32'd255};//{'dest': 1, 'literal': 255, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[77] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[78] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[79] = {5'd4, 4'd0, 4'd1, 32'd0};//{'dest': 0, 'src': 1, 'op': 'move'}
+ instructions[80] = {5'd2, 4'd2, 4'd0, 32'd1000};//{'dest': 2, 'literal': 1000, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[81] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[82] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[83] = {5'd4, 4'd10, 4'd2, 32'd0};//{'dest': 10, 'src': 2, 'op': 'move'}
+ instructions[84] = {5'd0, 4'd9, 4'd0, 32'd2};//{'dest': 9, 'label': 2, 'op': 'jmp_and_link'}
+ instructions[85] = {5'd2, 4'd1, 4'd0, -32'd500};//{'dest': 1, 'literal': -500, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[86] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[87] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[88] = {5'd4, 4'd15, 4'd1, 32'd0};//{'dest': 15, 'src': 1, 'op': 'move'}
+ instructions[89] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[90] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[91] = {5'd4, 4'd2, 4'd15, 32'd0};//{'dest': 2, 'src': 15, 'op': 'move'}
+ instructions[92] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[93] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[94] = {5'd11, 4'd1, 4'd2, 32'd500};//{'src': 2, 'right': 500, 'dest': 1, 'signed': False, 'op': '<', 'type': 'int', 'size': 2}
+ instructions[95] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[96] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[97] = {5'd6, 4'd0, 4'd1, 32'd160};//{'src': 1, 'label': 160, 'op': 'jmp_if_false'}
+ instructions[98] = {5'd2, 4'd1, 4'd0, 32'd0};//{'dest': 1, 'literal': 0, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[99] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[100] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[101] = {5'd4, 4'd14, 4'd1, 32'd0};//{'dest': 14, 'src': 1, 'op': 'move'}
+ instructions[102] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[103] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[104] = {5'd4, 4'd2, 4'd14, 32'd0};//{'dest': 2, 'src': 14, 'op': 'move'}
+ instructions[105] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[106] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[107] = {5'd11, 4'd1, 4'd2, 32'd8};//{'src': 2, 'right': 8, 'dest': 1, 'signed': False, 'op': '<', 'type': 'int', 'size': 2}
+ instructions[108] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[109] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[110] = {5'd6, 4'd0, 4'd1, 32'd152};//{'src': 1, 'label': 152, 'op': 'jmp_if_false'}
+ instructions[111] = {5'd4, 4'd2, 4'd15, 32'd0};//{'dest': 2, 'src': 15, 'op': 'move'}
+ instructions[112] = {5'd4, 4'd7, 4'd14, 32'd0};//{'dest': 7, 'src': 14, 'op': 'move'}
+ instructions[113] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[114] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[115] = {5'd16, 4'd8, 4'd7, 32'd13};//{'dest': 8, 'src': 7, 'srcb': 13, 'signed': False, 'op': '+'}
+ instructions[116] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[117] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[118] = {5'd17, 4'd0, 4'd8, 32'd0};//{'element_size': 2, 'src': 8, 'sequence': 32296400, 'op': 'memory_read_request'}
+ instructions[119] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[120] = {5'd18, 4'd0, 4'd8, 32'd0};//{'element_size': 2, 'src': 8, 'sequence': 32296400, 'op': 'memory_read_wait'}
+ instructions[121] = {5'd19, 4'd3, 4'd8, 32'd0};//{'dest': 3, 'src': 8, 'sequence': 32296400, 'element_size': 2, 'op': 'memory_read'}
+ instructions[122] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[123] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[124] = {5'd20, 4'd1, 4'd2, 32'd3};//{'srcb': 3, 'src': 2, 'dest': 1, 'signed': False, 'op': '>=', 'type': 'int', 'size': 2}
+ instructions[125] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[126] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[127] = {5'd6, 4'd0, 4'd1, 32'd149};//{'src': 1, 'label': 149, 'op': 'jmp_if_false'}
+ instructions[128] = {5'd4, 4'd2, 4'd0, 32'd0};//{'dest': 2, 'src': 0, 'op': 'move'}
+ instructions[129] = {5'd4, 4'd8, 4'd14, 32'd0};//{'dest': 8, 'src': 14, 'op': 'move'}
+ instructions[130] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[131] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[132] = {5'd21, 4'd7, 4'd8, 32'd1};//{'src': 8, 'dest': 7, 'signed': False, 'op': '<<', 'size': 2, 'type': 'int', 'left': 1}
+ instructions[133] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[134] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[135] = {5'd22, 4'd3, 4'd7, 32'd0};//{'dest': 3, 'src': 7, 'op': '~'}
+ instructions[136] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[137] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[138] = {5'd23, 4'd1, 4'd2, 32'd3};//{'srcb': 3, 'src': 2, 'dest': 1, 'signed': False, 'op': '&', 'type': 'int', 'size': 2}
+ instructions[139] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[140] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[141] = {5'd4, 4'd0, 4'd1, 32'd0};//{'dest': 0, 'src': 1, 'op': 'move'}
+ instructions[142] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[143] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[144] = {5'd4, 4'd1, 4'd0, 32'd0};//{'dest': 1, 'src': 0, 'op': 'move'}
+ instructions[145] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[146] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[147] = {5'd24, 4'd0, 4'd1, 32'd0};//{'src': 1, 'output': 'servos', 'op': 'write'}
+ instructions[148] = {5'd9, 4'd0, 4'd0, 32'd149};//{'label': 149, 'op': 'goto'}
+ instructions[149] = {5'd4, 4'd1, 4'd14, 32'd0};//{'dest': 1, 'src': 14, 'op': 'move'}
+ instructions[150] = {5'd8, 4'd14, 4'd14, 32'd1};//{'src': 14, 'right': 1, 'dest': 14, 'signed': False, 'op': '+', 'size': 2}
+ instructions[151] = {5'd9, 4'd0, 4'd0, 32'd102};//{'label': 102, 'op': 'goto'}
+ instructions[152] = {5'd2, 4'd2, 4'd0, 32'd1};//{'dest': 2, 'literal': 1, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[153] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[154] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[155] = {5'd4, 4'd10, 4'd2, 32'd0};//{'dest': 10, 'src': 2, 'op': 'move'}
+ instructions[156] = {5'd0, 4'd9, 4'd0, 32'd2};//{'dest': 9, 'label': 2, 'op': 'jmp_and_link'}
+ instructions[157] = {5'd4, 4'd1, 4'd15, 32'd0};//{'dest': 1, 'src': 15, 'op': 'move'}
+ instructions[158] = {5'd8, 4'd15, 4'd15, 32'd1};//{'src': 15, 'right': 1, 'dest': 15, 'signed': False, 'op': '+', 'size': 2}
+ instructions[159] = {5'd9, 4'd0, 4'd0, 32'd89};//{'label': 89, 'op': 'goto'}
+ instructions[160] = {5'd2, 4'd2, 4'd0, 32'd10000};//{'dest': 2, 'literal': 10000, 'size': 2, 'signed': 2, 'op': 'literal'}
+ instructions[161] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[162] = {5'd3, 4'd0, 4'd0, 32'd0};//{'op': 'nop'}
+ instructions[163] = {5'd4, 4'd10, 4'd2, 32'd0};//{'dest': 10, 'src': 2, 'op': 'move'}
+ instructions[164] = {5'd0, 4'd9, 4'd0, 32'd2};//{'dest': 9, 'label': 2, 'op': 'jmp_and_link'}
+ instructions[165] = {5'd9, 4'd0, 4'd0, 32'd53};//{'label': 53, 'op': 'goto'}
+ instructions[166] = {5'd10, 4'd0, 4'd12, 32'd0};//{'src': 12, 'op': 'jmp_to_reg'}
+ end
+
+
+ //////////////////////////////////////////////////////////////////////////////
+ // CPU IMPLEMENTAION OF C PROCESS
+ //
+ // This section of the file contains a CPU implementing the C process.
+
+ always @(posedge clk)
+ begin
+
+ //implement memory for 2 byte x n arrays
+ if (memory_enable_2 == 1'b1) begin
+ memory_2[address_2] <= data_in_2;
+ end
+ data_out_2 <= memory_2[address_2];
+ memory_enable_2 <= 1'b0;
+
+ write_enable_2 <= 0;
+ //stage 0 instruction fetch
+ if (stage_0_enable) begin
+ stage_1_enable <= 1;
+ instruction_0 <= instructions[program_counter];
+ opcode_0 = instruction_0[44:40];
+ dest_0 = instruction_0[39:36];
+ src_0 = instruction_0[35:32];
+ srcb_0 = instruction_0[3:0];
+ literal_0 = instruction_0[31:0];
+ if(write_enable_2) begin
+ registers[dest_2] <= result_2;
+ end
+ program_counter_0 <= program_counter;
+ program_counter <= program_counter + 1;
+ end
+
+ //stage 1 opcode fetch
+ if (stage_1_enable) begin
+ stage_2_enable <= 1;
+ register_1 <= registers[src_0];
+ registerb_1 <= registers[srcb_0];
+ dest_1 <= dest_0;
+ literal_1 <= literal_0;
+ opcode_1 <= opcode_0;
+ program_counter_1 <= program_counter_0;
+ end
+
+ //stage 2 opcode fetch
+ if (stage_2_enable) begin
+ dest_2 <= dest_1;
+ case(opcode_1)
+
+ 16'd0:
+ begin
+ program_counter <= literal_1;
+ result_2 <= program_counter_1 + 1;
+ write_enable_2 <= 1;
+ stage_0_enable <= 1;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ end
+
+ 16'd1:
+ begin
+ stage_0_enable <= 0;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ end
+
+ 16'd2:
+ begin
+ result_2 <= literal_1;
+ write_enable_2 <= 1;
+ end
+
+ 16'd4:
+ begin
+ result_2 <= register_1;
+ write_enable_2 <= 1;
+ end
+
+ 16'd5:
+ begin
+ result_2 <= $unsigned(register_1) < $unsigned(registerb_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd6:
+ begin
+ if (register_1 == 0) begin
+ program_counter <= literal_1;
+ stage_0_enable <= 1;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ end
+ end
+
+ 16'd7:
+ begin
+ timer <= register_1;
+ timer_enable <= 1;
+ stage_0_enable <= 0;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ end
+
+ 16'd8:
+ begin
+ result_2 <= $unsigned(register_1) + $unsigned(literal_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd9:
+ begin
+ program_counter <= literal_1;
+ stage_0_enable <= 1;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ end
+
+ 16'd10:
+ begin
+ program_counter <= register_1;
+ stage_0_enable <= 1;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ end
+
+ 16'd11:
+ begin
+ result_2 <= $unsigned(register_1) < $unsigned(literal_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd12:
+ begin
+ result_2 <= $signed(register_1) + $signed(registerb_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd13:
+ begin
+ address_2 <= register_1;
+ data_in_2 <= registerb_1;
+ memory_enable_2 <= 1'b1;
+ end
+
+ 16'd14:
+ begin
+ result_2 <= 0;
+ result_2[0] <= input_control_stb;
+ write_enable_2 <= 1;
+ end
+
+ 16'd15:
+ begin
+ stage_0_enable <= 0;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ s_input_control_ack <= 1'b1;
+ end
+
+ 16'd16:
+ begin
+ result_2 <= $unsigned(register_1) + $unsigned(registerb_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd17:
+ begin
+ address_2 <= register_1;
+ end
+
+ 16'd19:
+ begin
+ result_2 <= data_out_2;
+ write_enable_2 <= 1;
+ end
+
+ 16'd20:
+ begin
+ result_2 <= $unsigned(register_1) >= $unsigned(registerb_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd21:
+ begin
+ result_2 <= $unsigned(literal_1) << $unsigned(register_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd22:
+ begin
+ result_2 <= ~register_1;
+ write_enable_2 <= 1;
+ end
+
+ 16'd23:
+ begin
+ result_2 <= $unsigned(register_1) & $unsigned(registerb_1);
+ write_enable_2 <= 1;
+ end
+
+ 16'd24:
+ begin
+ stage_0_enable <= 0;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ s_output_servos_stb <= 1'b1;
+ s_output_servos <= register_1;
+ end
+
+ endcase
+ end
+ if (s_input_control_ack == 1'b1 && input_control_stb == 1'b1) begin
+ result_2 <= input_control;
+ write_enable_2 <= 1;
+ s_input_control_ack <= 1'b0;
+ stage_0_enable <= 1;
+ stage_1_enable <= 1;
+ stage_2_enable <= 1;
+ end
+
+ if (s_output_servos_stb == 1'b1 && output_servos_ack == 1'b1) begin
+ s_output_servos_stb <= 1'b0;
+ stage_0_enable <= 1;
+ stage_1_enable <= 1;
+ stage_2_enable <= 1;
+ end
+
+ if (timer == 0) begin
+ if (timer_enable) begin
+ stage_0_enable <= 1;
+ stage_1_enable <= 1;
+ stage_2_enable <= 1;
+ timer_enable <= 0;
+ end
+ end else begin
+ timer <= timer - 1;
+ end
+
+ if (rst == 1'b1) begin
+ stage_0_enable <= 1;
+ stage_1_enable <= 0;
+ stage_2_enable <= 0;
+ timer <= 0;
+ timer_enable <= 0;
+ program_counter <= 0;
+ s_input_control_ack <= 0;
+ s_output_servos_stb <= 0;
+ end
+ end
+ assign input_control_ack = s_input_control_ack;
+ assign output_servos_stb = s_output_servos_stb;
+ assign output_servos = s_output_servos;
+
+endmodule
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_virtualdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_tts_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_parsedata_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_virtualdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_virtualdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_parsedata_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_virtualdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_misc_plugin_init;
+\t\t\tstardict_misc_plugin_on_mainwin_finish;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_virtualdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_specialdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_parsedata_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_parsedata_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_tts_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_parsedata_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_netdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"module LedShiz01(
+\tinput clk_50,
+\toutput [3:0] leds
+);
+
+`define led(default_pwm_width, index) \\
+PwmLed #( \\
+\t.DEFAULT_PWM_WIDTH(default_pwm_width) \\
+) ( \\
+\t.clk_50(clk_50), \\
+\t.led(leds[index]) \\
+);
+
+`led(8'h00, 0)
+`led(8'h40, 1)
+`led(8'h80, 2)
+`led(8'hc0, 3)
+
+endmodule
+"
+"module PwmLed(
+\tinput clk_50,
+\toutput led
+);
+
+parameter DEFAULT_PWM_WIDTH = 8'h00;
+
+reg [31:0] pwm_width_counter;
+reg [7:0] pwm_width = DEFAULT_PWM_WIDTH;
+reg pwm_width_dir;
+
+reg [31:0] pwm_counter;
+reg [7:0] pwm_pos;
+
+reg led_state;
+
+assign led = led_state;
+
+always @ (posedge clk_50) begin
+\tif (pwm_counter == 32'd2500 - 1) begin
+\t\tpwm_pos <= pwm_pos + 1;
+\t\tled_state <= pwm_pos >= pwm_width;
+\t\tpwm_counter <= 0;
+\tend else
+\t\tpwm_counter <= pwm_counter + 1;
+\t
+\tif (pwm_width_counter == 32'd100000 - 1) begin
+\t\tif (pwm_width_dir == 0)
+\t\t\tif (pwm_width == 8'hff)
+\t\t\t\tpwm_width_dir <= ~pwm_width_dir;
+\t\t\telse
+\t\t\t\tpwm_width <= pwm_width + 1;
+\t\telse
+\t\t\tif (pwm_width == 0)
+\t\t\t\tpwm_width_dir <= ~pwm_width_dir;
+\t\t\telse
+\t\t\t\tpwm_width <= pwm_width - 1;
+\t\tpwm_width_counter <= 0;
+\tend else
+\t\tpwm_width_counter <= pwm_width_counter + 1;
+end
+
+endmodule
+"
+"/*
+ * Copyright (c) 2009 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module sdspi (
+ // Serial pad signal
+ output reg sclk,
+ input miso,
+ output reg mosi,
+ output reg ss,
+
+ // Wishbone slave interface
+ input wb_clk_i,
+ input wb_rst_i,
+ input [8:0] wb_dat_i,
+ output reg [7:0] wb_dat_o,
+ input wb_we_i,
+ input [1:0] wb_sel_i,
+ input wb_stb_i,
+ input wb_cyc_i,
+ output reg wb_ack_o
+ );
+
+ // Registers and nets
+ wire op;
+ wire start;
+ wire send;
+ reg [7:0] tr;
+ reg st;
+ reg [7:0] sft;
+ reg [1:0] clk_div;
+
+ // Continuous assignments
+ assign op = wb_stb_i & wb_cyc_i;
+ assign start = !st & op;
+ assign send = start & wb_we_i & wb_sel_i[0];
+
+ // Behaviour
+ // mosi
+ always @(posedge wb_clk_i)
+ mosi <= wb_rst_i ? 1'b1
+ : (clk_div==2'b10 ? (send ? wb_dat_i[7] : tr[7]) : mosi);
+
+ // tr
+ always @(posedge wb_clk_i)
+ tr <= wb_rst_i ? 8'hff
+ : (clk_div==2'b10 ? { (send ?
+ wb_dat_i[6:0] : tr[6:0]), 1'b1 } : tr);
+
+ // wb_ack_o
+ always @(posedge wb_clk_i)
+ wb_ack_o <= wb_rst_i ? 1'b0
+ : (wb_ack_o ? 1'b0 : (sft[0] && clk_div==2'b00));
+
+ // sft
+ always @(posedge wb_clk_i)
+ sft <= wb_rst_i ? 8'h0
+ : (clk_div==2'b10 ? { start, sft[7:1] } : sft);
+
+ // st
+ always @(posedge wb_clk_i)
+ st <= wb_rst_i ? 1'b0 : (st ? !sft[0] : op && clk_div==2'b10);
+
+ // wb_dat_o
+ always @(posedge wb_clk_i)
+ wb_dat_o <= wb_rst_i ? 8'h0
+ : ((op && clk_div==2'b0) ?
+ { wb_dat_o[6:0], miso } : wb_dat_o);
+
+ // sclk
+ always @(posedge wb_clk_i)
+ sclk <= wb_rst_i ? 1'b1
+ : (clk_div[0] ? sclk : !(op & clk_div[1]));
+
+ // ss
+ always @(negedge wb_clk_i)
+ ss <= wb_rst_i ? 1'b1
+ : ((op & wb_we_i & wb_sel_i[1]) ? wb_dat_i[8] : ss);
+
+ // clk_div
+ always @(posedge wb_clk_i) clk_div <= clk_div - 2'd1;
+endmodule
+"
+"/**************************************************************************
+*
+* File Name: MT48LC16M16A2.V
+* Version: 2.1
+* Date: June 6th, 2002
+* Model: BUS Functional
+* Simulator: Model Technology
+*
+* Dependencies: None
+*
+* Email: modelsupport@micron.com
+* Company: Micron Technology, Inc.
+* Model: MT48LC16M16A2 (4Meg x 16 x 4 Banks)
+* Altera DE1: PSC A2V64S40CTP (1048576 addresses/bank
+* x 16 bits/address
+* x 4 Banks = 64 Mbits = 8 Mbytes)
+*
+* Description: Micron 256Mb SDRAM Verilog model
+*
+* Limitation: - Doesn\'t check for 8192 cycle refresh
+*
+* Note: - Set simulator resolution to ""ps"" accuracy
+* - Set Debug = 0 to disable $display messages
+*
+* Disclaimer: THESE DESIGNS ARE PROVIDED ""AS IS"" WITH NO WARRANTY
+* WHATSOEVER AND MICRON SPECIFICALLY DISCLAIMS ANY
+* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+* A PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT.
+*
+* Copyright \xef\xbf\xbd 2001 Micron Semiconductor Products, Inc.
+* All rights researved
+*
+* Rev Author Date Changes
+* --- -------------------------- ---------------------------------------
+* 2.1 SH 06/06/2002 - Typo in bank multiplex
+* Micron Technology Inc.
+*
+* 2.0 SH 04/30/2002 - Second release
+* Micron Technology Inc.
+*
+**************************************************************************/
+
+`timescale 1ns / 1ps
+
+module mt48lc16m16a2 (Dq, Addr, Ba, Clk, Cke, Cs_n, Ras_n, Cas_n, We_n, Dqm);
+
+ parameter addr_bits = 12; // 12 PSC, 13 MT
+ parameter data_bits = 16;
+ parameter col_bits = 8; // 8 in PSC, 9 MT
+ parameter mem_sizes = 1048575; // 1048575 PSC, 4194303 MT
+
+ inout [data_bits - 1 : 0] Dq;
+ input [addr_bits - 1 : 0] Addr;
+ input [1 : 0] Ba;
+ input Clk;
+ input Cke;
+ input Cs_n;
+ input Ras_n;
+ input Cas_n;
+ input We_n;
+ input [1 : 0] Dqm;
+
+ reg [data_bits - 1 : 0] Bank0 [0 : mem_sizes];
+ reg [data_bits - 1 : 0] Bank1 [0 : mem_sizes];
+ reg [data_bits - 1 : 0] Bank2 [0 : mem_sizes];
+ reg [data_bits - 1 : 0] Bank3 [0 : mem_sizes];
+
+ reg [1 : 0] Bank_addr [0 : 3]; // Bank Address Pipeline
+ reg [col_bits - 1 : 0] Col_addr [0 : 3]; // Column Address Pipeline
+ reg [3 : 0] Command [0 : 3]; // Command Operation Pipeline
+ reg [1 : 0] Dqm_reg0, Dqm_reg1; // DQM Operation Pipeline
+ reg [addr_bits - 1 : 0] B0_row_addr, B1_row_addr, B2_row_addr, B3_row_addr;
+
+ reg [addr_bits - 1 : 0] Mode_reg;
+ reg [data_bits - 1 : 0] Dq_reg, Dq_dqm;
+ reg [col_bits - 1 : 0] Col_temp, Burst_counter;
+
+ reg Act_b0, Act_b1, Act_b2, Act_b3; // Bank Activate
+ reg Pc_b0, Pc_b1, Pc_b2, Pc_b3; // Bank Precharge
+
+ reg [1 : 0] Bank_precharge [0 : 3]; // Precharge Command
+ reg A10_precharge [0 : 3]; // Addr[10] = 1 (All banks)
+ reg Auto_precharge [0 : 3]; // RW Auto Precharge (Bank)
+ reg Read_precharge [0 : 3]; // R Auto Precharge
+ reg Write_precharge [0 : 3]; // W Auto Precharge
+ reg RW_interrupt_read [0 : 3]; // RW Interrupt Read with Auto Precharge
+ reg RW_interrupt_write [0 : 3]; // RW Interrupt Write with Auto Precharge
+ reg [1 : 0] RW_interrupt_bank; // RW Interrupt Bank
+ integer RW_interrupt_counter [0 : 3]; // RW Interrupt Counter
+ integer Count_precharge [0 : 3]; // RW Auto Precharge Counter
+
+ reg Data_in_enable;
+ reg Data_out_enable;
+
+ reg [1 : 0] Bank, Prev_bank;
+ reg [addr_bits - 1 : 0] Row;
+ reg [col_bits - 1 : 0] Col, Col_brst;
+
+ // Internal system clock
+ reg CkeZ, Sys_clk;
+
+ // Commands Decode
+ wire Active_enable = ~Cs_n & ~Ras_n & Cas_n & We_n;
+ wire Aref_enable = ~Cs_n & ~Ras_n & ~Cas_n & We_n;
+ wire Burst_term = ~Cs_n & Ras_n & Cas_n & ~We_n;
+ wire Mode_reg_enable = ~Cs_n & ~Ras_n & ~Cas_n & ~We_n;
+ wire Prech_enable = ~Cs_n & ~Ras_n & Cas_n & ~We_n;
+ wire Read_enable = ~Cs_n & Ras_n & ~Cas_n & We_n;
+ wire Write_enable = ~Cs_n & Ras_n & ~Cas_n & ~We_n;
+
+ // Burst Length Decode
+ wire Burst_length_1 = ~Mode_reg[2] & ~Mode_reg[1] & ~Mode_reg[0];
+ wire Burst_length_2 = ~Mode_reg[2] & ~Mode_reg[1] & Mode_reg[0];
+ wire Burst_length_4 = ~Mode_reg[2] & Mode_reg[1] & ~Mode_reg[0];
+ wire Burst_length_8 = ~Mode_reg[2] & Mode_reg[1] & Mode_reg[0];
+ wire Burst_length_f = Mode_reg[2] & Mode_reg[1] & Mode_reg[0];
+
+ // CAS Latency Decode
+ wire Cas_latency_2 = ~Mode_reg[6] & Mode_reg[5] & ~Mode_reg[4];
+ wire Cas_latency_3 = ~Mode_reg[6] & Mode_reg[5] & Mode_reg[4];
+
+ // Write Burst Mode
+ wire Write_burst_mode = Mode_reg[9];
+
+ wire Debug = 1\'b1; // Debug messages : 1 = On
+ wire Dq_chk = Sys_clk & Data_in_enable; // Check setup/hold time for DQ
+
+ assign Dq = Dq_reg; // DQ buffer
+
+/* Dump the content of the memory after some delay */
+/*
+integer dumpi;
+initial begin
+\t#206640
+\t$display(""Contents of bank 0"");
+\tfor(dumpi=0;dumpi<20;dumpi=dumpi+1) begin
+\t\t$display(""%h: %h"", dumpi, Bank0[dumpi]);
+\tend
+\t$display(""Contents of bank 1"");
+\tfor(dumpi=0;dumpi<20;dumpi=dumpi+1) begin
+\t\t$display(""%h: %h"", dumpi, Bank1[dumpi]);
+\tend
+\t$display(""Contents of bank 2"");
+\tfor(dumpi=0;dumpi<20;dumpi=dumpi+1) begin
+\t\t$display(""%h: %h"", dumpi, Bank2[dumpi]);
+\tend
+\t$display(""Contents of bank 3"");
+\tfor(dumpi=0;dumpi<20;dumpi=dumpi+1) begin
+\t\t$display(""%h: %h"", dumpi, Bank3[dumpi]);
+\tend
+end
+*/
+
+ // Commands Operation
+ `define ACT 0
+ `define NOP 1
+ `define READ 2
+ `define WRITE 3
+ `define PRECH 4
+ `define A_REF 5
+ `define BST 6
+ `define LMR 7
+
+ // Timing Parameters for -7E PC133 CL2
+ parameter tAC = 5.4;
+ parameter tHZ = 5.4;
+ parameter tOH = 3.0;
+ parameter tMRD = 2.0; // 2 Clk Cycles
+ parameter tRAS = 37.0;
+ parameter tRC = 60.0;
+ parameter tRCD = 15.0;
+ parameter tRFC = 66.0;
+ parameter tRP = 15.0;
+ parameter tRRD = 14.0;
+ parameter tWRa = 7.0; // A2 Version - Auto precharge mode (1 Clk + 7 ns)
+ parameter tWRm = 14.0; // A2 Version - Manual precharge mode (14 ns)
+
+ // Timing Check variable
+ time MRD_chk;
+ time WR_chkm [0 : 3];
+ time RFC_chk, RRD_chk;
+ time RC_chk0, RC_chk1, RC_chk2, RC_chk3;
+ time RAS_chk0, RAS_chk1, RAS_chk2, RAS_chk3;
+ time RCD_chk0, RCD_chk1, RCD_chk2, RCD_chk3;
+ time RP_chk0, RP_chk1, RP_chk2, RP_chk3;
+
+ initial begin
+ Dq_reg = {data_bits{1\'bz}};
+ Data_in_enable = 0; Data_out_enable = 0;
+ Act_b0 = 1; Act_b1 = 1; Act_b2 = 1; Act_b3 = 1;
+ Pc_b0 = 0; Pc_b1 = 0; Pc_b2 = 0; Pc_b3 = 0;
+ WR_chkm[0] = 0; WR_chkm[1] = 0; WR_chkm[2] = 0; WR_chkm[3] = 0;
+ RW_interrupt_read[0] = 0; RW_interrupt_read[1] = 0; RW_interrupt_read[2] = 0; RW_interrupt_read[3] = 0;
+ RW_interrupt_write[0] = 0; RW_interrupt_write[1] = 0; RW_interrupt_write[2] = 0; RW_interrupt_write[3] = 0;
+ MRD_chk = 0; RFC_chk = 0; RRD_chk = 0;
+ RAS_chk0 = 0; RAS_chk1 = 0; RAS_chk2 = 0; RAS_chk3 = 0;
+ RCD_chk0 = 0; RCD_chk1 = 0; RCD_chk2 = 0; RCD_chk3 = 0;
+ RC_chk0 = 0; RC_chk1 = 0; RC_chk2 = 0; RC_chk3 = 0;
+ RP_chk0 = 0; RP_chk1 = 0; RP_chk2 = 0; RP_chk3 = 0;
+ $timeformat (-9, 1, "" ns"", 12);
+ end
+
+ // System clock generator
+ always begin
+ @ (posedge Clk) begin
+ Sys_clk = CkeZ;
+ CkeZ = Cke;
+ end
+ @ (negedge Clk) begin
+ Sys_clk = 1\'b0;
+ end
+ end
+
+ always @ (posedge Sys_clk) begin
+ // Internal Commamd Pipelined
+ Command[0] = Command[1];
+ Command[1] = Command[2];
+ Command[2] = Command[3];
+ Command[3] = `NOP;
+
+ Col_addr[0] = Col_addr[1];
+ Col_addr[1] = Col_addr[2];
+ Col_addr[2] = Col_addr[3];
+ Col_addr[3] = {col_bits{1\'b0}};
+
+ Bank_addr[0] = Bank_addr[1];
+ Bank_addr[1] = Bank_addr[2];
+ Bank_addr[2] = Bank_addr[3];
+ Bank_addr[3] = 2\'b0;
+
+ Bank_precharge[0] = Bank_precharge[1];
+ Bank_precharge[1] = Bank_precharge[2];
+ Bank_precharge[2] = Bank_precharge[3];
+ Bank_precharge[3] = 2\'b0;
+
+ A10_precharge[0] = A10_precharge[1];
+ A10_precharge[1] = A10_precharge[2];
+ A10_precharge[2] = A10_precharge[3];
+ A10_precharge[3] = 1\'b0;
+
+ // Dqm pipeline for Read
+ Dqm_reg0 = Dqm_reg1;
+ Dqm_reg1 = Dqm;
+
+ // Read or Write with Auto Precharge Counter
+ if (Auto_precharge[0] === 1\'b1) begin
+ Count_precharge[0] = Count_precharge[0] + 1;
+ end
+ if (Auto_precharge[1] === 1\'b1) begin
+ Count_precharge[1] = Count_precharge[1] + 1;
+ end
+ if (Auto_precharge[2] === 1\'b1) begin
+ Count_precharge[2] = Count_precharge[2] + 1;
+ end
+ if (Auto_precharge[3] === 1\'b1) begin
+ Count_precharge[3] = Count_precharge[3] + 1;
+ end
+
+ // Read or Write Interrupt Counter
+ if (RW_interrupt_write[0] === 1\'b1) begin
+ RW_interrupt_counter[0] = RW_interrupt_counter[0] + 1;
+ end
+ if (RW_interrupt_write[1] === 1\'b1) begin
+ RW_interrupt_counter[1] = RW_interrupt_counter[1] + 1;
+ end
+ if (RW_interrupt_write[2] === 1\'b1) begin
+ RW_interrupt_counter[2] = RW_interrupt_counter[2] + 1;
+ end
+ if (RW_interrupt_write[3] === 1\'b1) begin
+ RW_interrupt_counter[3] = RW_interrupt_counter[3] + 1;
+ end
+
+ // tMRD Counter
+ MRD_chk = MRD_chk + 1;
+
+ // Auto Refresh
+ if (Aref_enable === 1\'b1) begin
+ if (Debug) begin
+ $display (""%m : at time %t AREF : Auto Refresh"", $time);
+ end
+
+ // Auto Refresh to Auto Refresh
+ if ($time - RFC_chk < tRFC) begin
+ $display (""%m : at time %t ERROR: tRFC violation during Auto Refresh"", $time);
+ end
+
+ // Precharge to Auto Refresh
+ if (($time - RP_chk0 < tRP) || ($time - RP_chk1 < tRP) ||
+ ($time - RP_chk2 < tRP) || ($time - RP_chk3 < tRP)) begin
+ $display (""%m : at time %t ERROR: tRP violation during Auto Refresh"", $time);
+ end
+
+ // Precharge to Refresh
+ if (Pc_b0 === 1\'b0 || Pc_b1 === 1\'b0 || Pc_b2 === 1\'b0 || Pc_b3 === 1\'b0) begin
+ $display (""%m : at time %t ERROR: All banks must be Precharge before Auto Refresh"", $time);
+ end
+
+ // Load Mode Register to Auto Refresh
+ if (MRD_chk < tMRD) begin
+ $display (""%m : at time %t ERROR: tMRD violation during Auto Refresh"", $time);
+ end
+
+ // Record Current tRFC time
+ RFC_chk = $time;
+ end
+
+ // Load Mode Register
+ if (Mode_reg_enable === 1\'b1) begin
+ // Register Mode
+ Mode_reg = Addr;
+
+ // Decode CAS Latency, Burst Length, Burst Type, and Write Burst Mode
+ if (Debug) begin
+ $display (""%m : at time %t LMR : Load Mode Register"", $time);
+ // CAS Latency
+ case (Addr[6 : 4])
+ 3\'b010 : $display (""%m : CAS Latency = 2"");
+ 3\'b011 : $display (""%m : CAS Latency = 3"");
+ default : $display (""%m : CAS Latency = Reserved"");
+ endcase
+
+ // Burst Length
+ case (Addr[2 : 0])
+ 3\'b000 : $display (""%m : Burst Length = 1"");
+ 3\'b001 : $display (""%m : Burst Length = 2"");
+ 3\'b010 : $display (""%m : Burst Length = 4"");
+ 3\'b011 : $display (""%m : Burst Length = 8"");
+ 3\'b111 : $display (""%m : Burst Length = Full"");
+ default : $display (""%m : Burst Length = Reserved"");
+ endcase
+
+ // Burst Type
+ if (Addr[3] === 1\'b0) begin
+ $display (""%m : Burst Type = Sequential"");
+ end else if (Addr[3] === 1\'b1) begin
+ $display (""%m : Burst Type = Interleaved"");
+ end else begin
+ $display (""%m : Burst Type = Reserved"");
+ end
+
+ // Write Burst Mode
+ if (Addr[9] === 1\'b0) begin
+ $display (""%m : Write Burst Mode = Programmed Burst Length"");
+ end else if (Addr[9] === 1\'b1) begin
+ $display (""%m : Write Burst Mode = Single Location Access"");
+ end else begin
+ $display (""%m : Write Burst Mode = Reserved"");
+ end
+ end
+
+ // Precharge to Load Mode Register
+ if (Pc_b0 === 1\'b0 && Pc_b1 === 1\'b0 && Pc_b2 === 1\'b0 && Pc_b3 === 1\'b0) begin
+ $display (""%m : at time %t ERROR: all banks must be Precharge before Load Mode Register"", $time);
+ end
+
+ // Precharge to Load Mode Register
+ if (($time - RP_chk0 < tRP) || ($time - RP_chk1 < tRP) ||
+ ($time - RP_chk2 < tRP) || ($time - RP_chk3 < tRP)) begin
+ $display (""%m : at time %t ERROR: tRP violation during Load Mode Register"", $time);
+ end
+
+ // Auto Refresh to Load Mode Register
+ if ($time - RFC_chk < tRFC) begin
+ $display (""%m : at time %t ERROR: tRFC violation during Load Mode Register"", $time);
+ end
+
+ // Load Mode Register to Load Mode Register
+ if (MRD_chk < tMRD) begin
+ $display (""%m : at time %t ERROR: tMRD violation during Load Mode Register"", $time);
+ end
+
+ // Reset MRD Counter
+ MRD_chk = 0;
+ end
+
+ // Active Block (Latch Bank Address and Row Address)
+ if (Active_enable === 1\'b1) begin
+ // Activate an open bank can corrupt data
+ if ((Ba === 2\'b00 && Act_b0 === 1\'b1) || (Ba === 2\'b01 && Act_b1 === 1\'b1) ||
+ (Ba === 2\'b10 && Act_b2 === 1\'b1) || (Ba === 2\'b11 && Act_b3 === 1\'b1)) begin
+ $display (""%m : at time %t ERROR: Bank already activated -- data can be corrupted"", $time);
+ end
+
+ // Activate Bank 0
+ if (Ba === 2\'b00 && Pc_b0 === 1\'b1) begin
+ // Debug Message
+ if (Debug) begin
+ $display (""%m : at time %t ACT : Bank = 0 Row = %d"", $time, Addr);
+ end
+
+ // ACTIVE to ACTIVE command period
+ if ($time - RC_chk0 < tRC) begin
+ $display (""%m : at time %t ERROR: tRC violation during Activate bank 0"", $time);
+ end
+
+ // Precharge to Activate Bank 0
+ if ($time - RP_chk0 < tRP) begin
+ $display (""%m : at time %t ERROR: tRP violation during Activate bank 0"", $time);
+ end
+
+ // Record variables
+ Act_b0 = 1\'b1;
+ Pc_b0 = 1\'b0;
+ B0_row_addr = Addr [addr_bits - 1 : 0];
+ RAS_chk0 = $time;
+ RC_chk0 = $time;
+ RCD_chk0 = $time;
+ end
+
+ if (Ba == 2\'b01 && Pc_b1 == 1\'b1) begin
+ // Debug Message
+ if (Debug) begin
+ $display (""%m : at time %t ACT : Bank = 1 Row = %d"", $time, Addr);
+ end
+
+ // ACTIVE to ACTIVE command period
+ if ($time - RC_chk1 < tRC) begin
+ $display (""%m : at time %t ERROR: tRC violation during Activate bank 1"", $time);
+ end
+
+ // Precharge to Activate Bank 1
+ if ($time - RP_chk1 < tRP) begin
+ $display (""%m : at time %t ERROR: tRP violation during Activate bank 1"", $time);
+ end
+
+ // Record variables
+ Act_b1 = 1\'b1;
+ Pc_b1 = 1\'b0;
+ B1_row_addr = Addr [addr_bits - 1 : 0];
+ RAS_chk1 = $time;
+ RC_chk1 = $time;
+ RCD_chk1 = $time;
+ end
+
+ if (Ba == 2\'b10 && Pc_b2 == 1\'b1) begin
+ // Debug Message
+ if (Debug) begin
+ $display (""%m : at time %t ACT : Bank = 2 Row = %d"", $time, Addr);
+ end
+
+ // ACTIVE to ACTIVE command period
+ if ($time - RC_chk2 < tRC) begin
+ $display (""%m : at time %t ERROR: tRC violation during Activate bank 2"", $time);
+ end
+
+ // Precharge to Activate Bank 2
+ if ($time - RP_chk2 < tRP) begin
+ $display (""%m : at time %t ERROR: tRP violation during Activate bank 2"", $time);
+ end
+
+ // Record variables
+ Act_b2 = 1\'b1;
+ Pc_b2 = 1\'b0;
+ B2_row_addr = Addr [addr_bits - 1 : 0];
+ RAS_chk2 = $time;
+ RC_chk2 = $time;
+ RCD_chk2 = $time;
+ end
+
+ if (Ba == 2\'b11 && Pc_b3 == 1\'b1) begin
+ // Debug Message
+ if (Debug) begin
+ $display (""%m : at time %t ACT : Bank = 3 Row = %d"", $time, Addr);
+ end
+
+ // ACTIVE to ACTIVE command period
+ if ($time - RC_chk3 < tRC) begin
+ $display (""%m : at time %t ERROR: tRC violation during Activate bank 3"", $time);
+ end
+
+ // Precharge to Activate Bank 3
+ if ($time - RP_chk3 < tRP) begin
+ $display (""%m : at time %t ERROR: tRP violation during Activate bank 3"", $time);
+ end
+
+ // Record variables
+ Act_b3 = 1\'b1;
+ Pc_b3 = 1\'b0;
+ B3_row_addr = Addr [addr_bits - 1 : 0];
+ RAS_chk3 = $time;
+ RC_chk3 = $time;
+ RCD_chk3 = $time;
+ end
+
+ // Active Bank A to Active Bank B
+ if ((Prev_bank != Ba) && ($time - RRD_chk < tRRD)) begin
+ $display (""%m : at time %t ERROR: tRRD violation during Activate bank = %d"", $time, Ba);
+ end
+
+ // Auto Refresh to Activate
+ if ($time - RFC_chk < tRFC) begin
+ $display (""%m : at time %t ERROR: tRFC violation during Activate bank = %d"", $time, Ba);
+ end
+
+ // Load Mode Register to Active
+ if (MRD_chk < tMRD ) begin
+ $display (""%m : at time %t ERROR: tMRD violation during Activate bank = %d"", $time, Ba);
+ end
+
+ // Record variables for checking violation
+ RRD_chk = $time;
+ Prev_bank = Ba;
+ end
+
+ // Precharge Block
+ if (Prech_enable == 1\'b1) begin
+ // Load Mode Register to Precharge
+ if ($time - MRD_chk < tMRD) begin
+ $display (""%m : at time %t ERROR: tMRD violaiton during Precharge"", $time);
+ end
+
+ // Precharge Bank 0
+ if ((Addr[10] === 1\'b1 || (Addr[10] === 1\'b0 && Ba === 2\'b00)) && Act_b0 === 1\'b1) begin
+ Act_b0 = 1\'b0;
+ Pc_b0 = 1\'b1;
+ RP_chk0 = $time;
+
+ // Activate to Precharge
+ if ($time - RAS_chk0 < tRAS) begin
+ $display (""%m : at time %t ERROR: tRAS violation during Precharge"", $time);
+ end
+
+ // tWR violation check for write
+ if ($time - WR_chkm[0] < tWRm) begin
+ $display (""%m : at time %t ERROR: tWR violation during Precharge"", $time);
+ end
+ end
+
+ // Precharge Bank 1
+ if ((Addr[10] === 1\'b1 || (Addr[10] === 1\'b0 && Ba === 2\'b01)) && Act_b1 === 1\'b1) begin
+ Act_b1 = 1\'b0;
+ Pc_b1 = 1\'b1;
+ RP_chk1 = $time;
+
+ // Activate to Precharge
+ if ($time - RAS_chk1 < tRAS) begin
+ $display (""%m : at time %t ERROR: tRAS violation during Precharge"", $time);
+ end
+
+ // tWR violation check for write
+ if ($time - WR_chkm[1] < tWRm) begin
+ $display (""%m : at time %t ERROR: tWR violation during Precharge"", $time);
+ end
+ end
+
+ // Precharge Bank 2
+ if ((Addr[10] === 1\'b1 || (Addr[10] === 1\'b0 && Ba === 2\'b10)) && Act_b2 === 1\'b1) begin
+ Act_b2 = 1\'b0;
+ Pc_b2 = 1\'b1;
+ RP_chk2 = $time;
+
+ // Activate to Precharge
+ if ($time - RAS_chk2 < tRAS) begin
+ $display (""%m : at time %t ERROR: tRAS violation during Precharge"", $time);
+ end
+
+ // tWR violation check for write
+ if ($time - WR_chkm[2] < tWRm) begin
+ $display (""%m : at time %t ERROR: tWR violation during Precharge"", $time);
+ end
+ end
+
+ // Precharge Bank 3
+ if ((Addr[10] === 1\'b1 || (Addr[10] === 1\'b0 && Ba === 2\'b11)) && Act_b3 === 1\'b1) begin
+ Act_b3 = 1\'b0;
+ Pc_b3 = 1\'b1;
+ RP_chk3 = $time;
+
+ // Activate to Precharge
+ if ($time - RAS_chk3 < tRAS) begin
+ $display (""%m : at time %t ERROR: tRAS violation during Precharge"", $time);
+ end
+
+ // tWR violation check for write
+ if ($time - WR_chkm[3] < tWRm) begin
+ $display (""%m : at time %t ERROR: tWR violation during Precharge"", $time);
+ end
+ end
+
+ // Terminate a Write Immediately (if same bank or all banks)
+ if (Data_in_enable === 1\'b1 && (Bank === Ba || Addr[10] === 1\'b1)) begin
+ Data_in_enable = 1\'b0;
+ end
+
+ // Precharge Command Pipeline for Read
+ if (Cas_latency_3 === 1\'b1) begin
+ Command[2] = `PRECH;
+ Bank_precharge[2] = Ba;
+ A10_precharge[2] = Addr[10];
+ end else if (Cas_latency_2 === 1\'b1) begin
+ Command[1] = `PRECH;
+ Bank_precharge[1] = Ba;
+ A10_precharge[1] = Addr[10];
+ end
+ end
+
+ // Burst terminate
+ if (Burst_term === 1\'b1) begin
+ // Terminate a Write Immediately
+ if (Data_in_enable == 1\'b1) begin
+ Data_in_enable = 1\'b0;
+ end
+
+ // Terminate a Read Depend on CAS Latency
+ if (Cas_latency_3 === 1\'b1) begin
+ Command[2] = `BST;
+ end else if (Cas_latency_2 == 1\'b1) begin
+ Command[1] = `BST;
+ end
+
+ // Display debug message
+ if (Debug) begin
+ $display (""%m : at time %t BST : Burst Terminate"",$time);
+ end
+ end
+
+ // Read, Write, Column Latch
+ if (Read_enable === 1\'b1) begin
+ // Check to see if bank is open (ACT)
+ if ((Ba == 2\'b00 && Pc_b0 == 1\'b1) || (Ba == 2\'b01 && Pc_b1 == 1\'b1) ||
+ (Ba == 2\'b10 && Pc_b2 == 1\'b1) || (Ba == 2\'b11 && Pc_b3 == 1\'b1)) begin
+ $display(""%m : at time %t ERROR: Bank is not Activated for Read"", $time);
+ end
+
+ // Activate to Read or Write
+ if ((Ba == 2\'b00) && ($time - RCD_chk0 < tRCD) ||
+ (Ba == 2\'b01) && ($time - RCD_chk1 < tRCD) ||
+ (Ba == 2\'b10) && ($time - RCD_chk2 < tRCD) ||
+ (Ba == 2\'b11) && ($time - RCD_chk3 < tRCD)) begin
+ $display(""%m : at time %t ERROR: tRCD violation during Read"", $time);
+ end
+
+ // CAS Latency pipeline
+ if (Cas_latency_3 == 1\'b1) begin
+ Command[2] = `READ;
+ Col_addr[2] = Addr;
+ Bank_addr[2] = Ba;
+ end else if (Cas_latency_2 == 1\'b1) begin
+ Command[1] = `READ;
+ Col_addr[1] = Addr;
+ Bank_addr[1] = Ba;
+ end
+
+ // Read interrupt Write (terminate Write immediately)
+ if (Data_in_enable == 1\'b1) begin
+ Data_in_enable = 1\'b0;
+
+ // Interrupting a Write with Autoprecharge
+ if (Auto_precharge[RW_interrupt_bank] == 1\'b1 && Write_precharge[RW_interrupt_bank] == 1\'b1) begin
+ RW_interrupt_write[RW_interrupt_bank] = 1\'b1;
+ RW_interrupt_counter[RW_interrupt_bank] = 0;
+
+ // Display debug message
+ if (Debug) begin
+ $display (""%m : at time %t NOTE : Read interrupt Write with Autoprecharge"", $time);
+ end
+ end
+ end
+
+ // Write with Auto Precharge
+ if (Addr[10] == 1\'b1) begin
+ Auto_precharge[Ba] = 1\'b1;
+ Count_precharge[Ba] = 0;
+ RW_interrupt_bank = Ba;
+ Read_precharge[Ba] = 1\'b1;
+ end
+ end
+
+ // Write Command
+ if (Write_enable == 1\'b1) begin
+ // Activate to Write
+ if ((Ba == 2\'b00 && Pc_b0 == 1\'b1) || (Ba == 2\'b01 && Pc_b1 == 1\'b1) ||
+ (Ba == 2\'b10 && Pc_b2 == 1\'b1) || (Ba == 2\'b11 && Pc_b3 == 1\'b1)) begin
+ $display(""%m : at time %t ERROR: Bank is not Activated for Write"", $time);
+ end
+
+ // Activate to Read or Write
+ if ((Ba == 2\'b00) && ($time - RCD_chk0 < tRCD) ||
+ (Ba == 2\'b01) && ($time - RCD_chk1 < tRCD) ||
+ (Ba == 2\'b10) && ($time - RCD_chk2 < tRCD) ||
+ (Ba == 2\'b11) && ($time - RCD_chk3 < tRCD)) begin
+ $display(""%m : at time %t ERROR: tRCD violation during Read"", $time);
+ end
+
+ // Latch Write command, Bank, and Column
+ Command[0] = `WRITE;
+ Col_addr[0] = Addr;
+ Bank_addr[0] = Ba;
+
+ // Write interrupt Write (terminate Write immediately)
+ if (Data_in_enable == 1\'b1) begin
+ Data_in_enable = 1\'b0;
+
+ // Interrupting a Write with Autoprecharge
+ if (Auto_precharge[RW_interrupt_bank] == 1\'b1 && Write_precharge[RW_interrupt_bank] == 1\'b1) begin
+ RW_interrupt_write[RW_interrupt_bank] = 1\'b1;
+
+ // Display debug message
+ if (Debug) begin
+ $display (""%m : at time %t NOTE : Read Bank %d interrupt Write Bank %d with Autoprecharge"", $time, Ba, RW_interrupt_bank);
+ end
+ end
+ end
+
+ // Write interrupt Read (terminate Read immediately)
+ if (Data_out_enable == 1\'b1) begin
+ Data_out_enable = 1\'b0;
+
+ // Interrupting a Read with Autoprecharge
+ if (Auto_precharge[RW_interrupt_bank] == 1\'b1 && Read_precharge[RW_interrupt_bank] == 1\'b1) begin
+ RW_interrupt_read[RW_interrupt_bank] = 1\'b1;
+
+ // Display debug message
+ if (Debug) begin
+ $display (""%m : at time %t NOTE : Write Bank %d interrupt Read Bank %d with Autoprecharge"", $time, Ba, RW_interrupt_bank);
+ end
+ end
+ end
+
+ // Write with Auto Precharge
+ if (Addr[10] == 1\'b1) begin
+ Auto_precharge[Ba] = 1\'b1;
+ Count_precharge[Ba] = 0;
+ RW_interrupt_bank = Ba;
+ Write_precharge[Ba] = 1\'b1;
+ end
+ end
+
+ /*
+ Write with Auto Precharge Calculation
+ The device start internal precharge when:
+ 1. Meet minimum tRAS requirement
+ and 2. tWR cycle(s) after last valid data
+ or 3. Interrupt by a Read or Write (with or without Auto Precharge)
+
+ Note: Model is starting the internal precharge 1 cycle after they meet all the
+ requirement but tRP will be compensate for the time after the 1 cycle.
+ */
+ if ((Auto_precharge[0] == 1\'b1) && (Write_precharge[0] == 1\'b1)) begin
+ if ((($time - RAS_chk0 >= tRAS) && // Case 1
+ (((Burst_length_1 == 1\'b1 || Write_burst_mode == 1\'b1) && Count_precharge [0] >= 1) || // Case 2
+ (Burst_length_2 == 1\'b1 && Count_precharge [0] >= 2) ||
+ (Burst_length_4 == 1\'b1 && Count_precharge [0] >= 4) ||
+ (Burst_length_8 == 1\'b1 && Count_precharge [0] >= 8))) ||
+ (RW_interrupt_write[0] == 1\'b1 && RW_interrupt_counter[0] >= 1)) begin // Case 3
+ Auto_precharge[0] = 1\'b0;
+ Write_precharge[0] = 1\'b0;
+ RW_interrupt_write[0] = 1\'b0;
+ Pc_b0 = 1\'b1;
+ Act_b0 = 1\'b0;
+ RP_chk0 = $time + tWRa;
+ if (Debug) begin
+ $display (""%m : at time %t NOTE : Start Internal Auto Precharge for Bank 0"", $time);
+ end
+ end
+ end
+ if ((Auto_precharge[1] == 1\'b1) && (Write_precharge[1] == 1\'b1)) begin
+ if ((($time - RAS_chk1 >= tRAS) && // Case 1
+ (((Burst_length_1 == 1\'b1 || Write_burst_mode == 1\'b1) && Count_precharge [1] >= 1) || // Case 2
+ (Burst_length_2 == 1\'b1 && Count_precharge [1] >= 2) ||
+ (Burst_length_4 == 1\'b1 && Count_precharge [1] >= 4) ||
+ (Burst_length_8 == 1\'b1 && Count_precharge [1] >= 8))) ||
+ (RW_interrupt_write[1] == 1\'b1 && RW_interrupt_counter[1] >= 1)) begin // Case 3
+ Auto_precharge[1] = 1\'b0;
+ Write_precharge[1] = 1\'b0;
+ RW_interrupt_write[1] = 1\'b0;
+ Pc_b1 = 1\'b1;
+ Act_b1 = 1\'b0;
+ RP_chk1 = $time + tWRa;
+ if (Debug) begin
+ $display (""%m : at time %t NOTE : Start Internal Auto Precharge for Bank 1"", $time);
+ end
+ end
+ end
+ if ((Auto_precharge[2] == 1\'b1) && (Write_precharge[2] == 1\'b1)) begin
+ if ((($time - RAS_chk2 >= tRAS) && // Case 1
+ (((Burst_length_1 == 1\'b1 || Write_burst_mode == 1\'b1) && Count_precharge [2] >= 1) || // Case 2
+ (Burst_length_2 == 1\'b1 && Count_precharge [2] >= 2) ||
+ (Burst_length_4 == 1\'b1 && Count_precharge [2] >= 4) ||
+ (Burst_length_8 == 1\'b1 && Count_precharge [2] >= 8))) ||
+ (RW_interrupt_write[2] == 1\'b1 && RW_interrupt_counter[2] >= 1)) begin // Case 3
+ Auto_precharge[2] = 1\'b0;
+ Write_precharge[2] = 1\'b0;
+ RW_interrupt_write[2] = 1\'b0;
+ Pc_b2 = 1\'b1;
+ Act_b2 = 1\'b0;
+ RP_chk2 = $time + tWRa;
+ if (Debug) begin
+ $display (""%m : at time %t NOTE : Start Internal Auto Precharge for Bank 2"", $time);
+ end
+ end
+ end
+ if ((Auto_precharge[3] == 1\'b1) && (Write_precharge[3] == 1\'b1)) begin
+ if ((($time - RAS_chk3 >= tRAS) && // Case 1
+ (((Burst_length_1 == 1\'b1 || Write_burst_mode == 1\'b1) && Count_precharge [3] >= 1) || // Case 2
+ (Burst_length_2 == 1\'b1 && Count_precharge [3] >= 2) ||
+ (Burst_length_4 == 1\'b1 && Count_precharge [3] >= 4) ||
+ (Burst_length_8 == 1\'b1 && Count_precharge [3] >= 8))) ||
+ (RW_interrupt_write[3] == 1\'b1 && RW_interrupt_counter[3] >= 1)) begin // Case 3
+ Auto_precharge[3] = 1\'b0;
+ Write_precharge[3] = 1\'b0;
+ RW_interrupt_write[3] = 1\'b0;
+ Pc_b3 = 1\'b1;
+ Act_b3 = 1\'b0;
+ RP_chk3 = $time + tWRa;
+ if (Debug) begin
+ $display (""%m : at time %t NOTE : Start Internal Auto Precharge for Bank 3"", $time);
+ end
+ end
+ end
+
+ // Read with Auto Precharge Calculation
+ // The device start internal precharge:
+ // 1. Meet minimum tRAS requirement
+ // and 2. CAS Latency - 1 cycles before last burst
+ // or 3. Interrupt by a Read or Write (with or without AutoPrecharge)
+ if ((Auto_precharge[0] == 1\'b1) && (Read_precharge[0] == 1\'b1)) begin
+ if ((($time - RAS_chk0 >= tRAS) && // Case 1
+ ((Burst_length_1 == 1\'b1 && Count_precharge[0] >= 1) || // Case 2
+ (Burst_length_2 == 1\'b1 && Count_precharge[0] >= 2) ||
+ (Burst_length_4 == 1\'b1 && Count_precharge[0] >= 4) ||
+ (Burst_length_8 == 1\'b1 && Count_precharge[0] >= 8))) ||
+ (RW_interrupt_read[0] == 1\'b1)) begin // Case 3
+ Pc_b0 = 1\'b1;
+ Act_b0 = 1\'b0;
+ RP_chk0 = $time;
+ Auto_precharge[0] = 1\'b0;
+ Read_precharge[0] = 1\'b0;
+ RW_interrupt_read[0] = 1\'b0;
+ if (Debug) begin
+ $display (""%m : at time %t NOTE : Start Internal Auto Precharge for Bank 0"", $time);
+ end
+ end
+ end
+ if ((Auto_precharge[1] == 1\'b1) && (Read_precharge[1] == 1\'b1)) begin
+ if ((($time - RAS_chk1 >= tRAS) &&
+ ((Burst_length_1 == 1\'b1 && Count_precharge[1] >= 1) ||
+ (Burst_length_2 == 1\'b1 && Count_precharge[1] >= 2) ||
+ (Burst_length_4 == 1\'b1 && Count_precharge[1] >= 4) ||
+ (Burst_length_8 == 1\'b1 && Count_precharge[1] >= 8))) ||
+ (RW_interrupt_read[1] == 1\'b1)) begin
+ Pc_b1 = 1\'b1;
+ Act_b1 = 1\'b0;
+ RP_chk1 = $time;
+ Auto_precharge[1] = 1\'b0;
+ Read_precharge[1] = 1\'b0;
+ RW_interrupt_read[1] = 1\'b0;
+ if (Debug) begin
+ $display (""%m : at time %t NOTE : Start Internal Auto Precharge for Bank 1"", $time);
+ end
+ end
+ end
+ if ((Auto_precharge[2] == 1\'b1) && (Read_precharge[2] == 1\'b1)) begin
+ if ((($time - RAS_chk2 >= tRAS) &&
+ ((Burst_length_1 == 1\'b1 && Count_precharge[2] >= 1) ||
+ (Burst_length_2 == 1\'b1 && Count_precharge[2] >= 2) ||
+ (Burst_length_4 == 1\'b1 && Count_precharge[2] >= 4) ||
+ (Burst_length_8 == 1\'b1 && Count_precharge[2] >= 8))) ||
+ (RW_interrupt_read[2] == 1\'b1)) begin
+ Pc_b2 = 1\'b1;
+ Act_b2 = 1\'b0;
+ RP_chk2 = $time;
+ Auto_precharge[2] = 1\'b0;
+ Read_precharge[2] = 1\'b0;
+ RW_interrupt_read[2] = 1\'b0;
+ if (Debug) begin
+ $display (""%m : at time %t NOTE : Start Internal Auto Precharge for Bank 2"", $time);
+ end
+ end
+ end
+ if ((Auto_precharge[3] == 1\'b1) && (Read_precharge[3] == 1\'b1)) begin
+ if ((($time - RAS_chk3 >= tRAS) &&
+ ((Burst_length_1 == 1\'b1 && Count_precharge[3] >= 1) ||
+ (Burst_length_2 == 1\'b1 && Count_precharge[3] >= 2) ||
+ (Burst_length_4 == 1\'b1 && Count_precharge[3] >= 4) ||
+ (Burst_length_8 == 1\'b1 && Count_precharge[3] >= 8))) ||
+ (RW_interrupt_read[3] == 1\'b1)) begin
+ Pc_b3 = 1\'b1;
+ Act_b3 = 1\'b0;
+ RP_chk3 = $time;
+ Auto_precharge[3] = 1\'b0;
+ Read_precharge[3] = 1\'b0;
+ RW_interrupt_read[3] = 1\'b0;
+ if (Debug) begin
+ $display(""%m : at time %t NOTE : Start Internal Auto Precharge for Bank 3"", $time);
+ end
+ end
+ end
+
+ // Internal Precharge or Bst
+ if (Command[0] == `PRECH) begin // Precharge terminate a read with same bank or all banks
+ if (Bank_precharge[0] == Bank || A10_precharge[0] == 1\'b1) begin
+ if (Data_out_enable == 1\'b1) begin
+ Data_out_enable = 1\'b0;
+ end
+ end
+ end else if (Command[0] == `BST) begin // BST terminate a read to current bank
+ if (Data_out_enable == 1\'b1) begin
+ Data_out_enable = 1\'b0;
+ end
+ end
+
+ if (Data_out_enable == 1\'b0) begin
+ Dq_reg <= #tOH {data_bits{1\'bz}};
+ end
+
+ // Detect Read or Write command
+ if (Command[0] == `READ) begin
+ Bank = Bank_addr[0];
+ Col = Col_addr[0];
+ Col_brst = Col_addr[0];
+ case (Bank_addr[0])
+ 2\'b00 : Row = B0_row_addr;
+ 2\'b01 : Row = B1_row_addr;
+ 2\'b10 : Row = B2_row_addr;
+ 2\'b11 : Row = B3_row_addr;
+ endcase
+ Burst_counter = 0;
+ Data_in_enable = 1\'b0;
+ Data_out_enable = 1\'b1;
+ end else if (Command[0] == `WRITE) begin
+ Bank = Bank_addr[0];
+ Col = Col_addr[0];
+ Col_brst = Col_addr[0];
+ case (Bank_addr[0])
+ 2\'b00 : Row = B0_row_addr;
+ 2\'b01 : Row = B1_row_addr;
+ 2\'b10 : Row = B2_row_addr;
+ 2\'b11 : Row = B3_row_addr;
+ endcase
+ Burst_counter = 0;
+ Data_in_enable = 1\'b1;
+ Data_out_enable = 1\'b0;
+ end
+
+ // DQ buffer (Driver/Receiver)
+ if (Data_in_enable == 1\'b1) begin // Writing Data to Memory
+ // Array buffer
+ case (Bank)
+ 2\'b00 : Dq_dqm = Bank0 [{Row, Col}];
+ 2\'b01 : Dq_dqm = Bank1 [{Row, Col}];
+ 2\'b10 : Dq_dqm = Bank2 [{Row, Col}];
+ 2\'b11 : Dq_dqm = Bank3 [{Row, Col}];
+ endcase
+
+ // Dqm operation
+ if (Dqm[0] == 1\'b0) begin
+ Dq_dqm [ 7 : 0] = Dq [ 7 : 0];
+ end
+ if (Dqm[1] == 1\'b0) begin
+ Dq_dqm [15 : 8] = Dq [15 : 8];
+ end
+
+ // Write to memory
+ case (Bank)
+ 2\'b00 : Bank0 [{Row, Col}] = Dq_dqm;
+ 2\'b01 : Bank1 [{Row, Col}] = Dq_dqm;
+ 2\'b10 : Bank2 [{Row, Col}] = Dq_dqm;
+ 2\'b11 : Bank3 [{Row, Col}] = Dq_dqm;
+ endcase
+
+ // Display debug message
+ if (Dqm !== 2\'b11) begin
+ // Record tWR for manual precharge
+ WR_chkm [Bank] = $time;
+
+ if (Debug) begin
+ $display(""%m : at time %t WRITE: Bank = %d Row = %d, Col = %d, Data = %d"", $time, Bank, Row, Col, Dq_dqm);
+ end
+ end else begin
+ if (Debug) begin
+ $display(""%m : at time %t WRITE: Bank = %d Row = %d, Col = %d, Data = Hi-Z due to DQM"", $time, Bank, Row, Col);
+ end
+ end
+
+ // Advance burst counter subroutine
+ #tHZ Burst_decode;
+
+ end else if (Data_out_enable == 1\'b1) begin // Reading Data from Memory
+ // Array buffer
+ case (Bank)
+ 2\'b00 : Dq_dqm = Bank0[{Row, Col}];
+ 2\'b01 : Dq_dqm = Bank1[{Row, Col}];
+ 2\'b10 : Dq_dqm = Bank2[{Row, Col}];
+ 2\'b11 : Dq_dqm = Bank3[{Row, Col}];
+ endcase
+
+ // Dqm operation
+ if (Dqm_reg0 [0] == 1\'b1) begin
+ Dq_dqm [ 7 : 0] = 8\'bz;
+ end
+ if (Dqm_reg0 [1] == 1\'b1) begin
+ Dq_dqm [15 : 8] = 8\'bz;
+ end
+
+ // Display debug message
+ if (Dqm_reg0 !== 2\'b11) begin
+ Dq_reg = #tAC Dq_dqm; //XXX
+ if (Debug) begin
+ $display(""%m : at time %t READ : Bank = %d Row = %d, Col = %d, Data = %d"", $time, Bank, Row, Col, Dq_reg);
+ end
+ end else begin
+ Dq_reg = #tHZ {data_bits{1\'bz}};
+ if (Debug) begin
+ $display(""%m : at time %t READ : Bank = %d Row = %d, Col = %d, Data = Hi-Z due to DQM"", $time, Bank, Row, Col);
+ end
+ end
+
+ // Advance burst counter subroutine
+ Burst_decode;
+ end
+ end
+
+ // Burst counter decode
+ task Burst_decode;
+ begin
+ // Advance Burst Counter
+ Burst_counter = Burst_counter + 1;
+
+ // Burst Type
+ if (Mode_reg[3] == 1\'b0) begin // Sequential Burst
+ Col_temp = Col + 1;
+ end else if (Mode_reg[3] == 1\'b1) begin // Interleaved Burst
+ Col_temp[2] = Burst_counter[2] ^ Col_brst[2];
+ Col_temp[1] = Burst_counter[1] ^ Col_brst[1];
+ Col_temp[0] = Burst_counter[0] ^ Col_brst[0];
+ end
+
+ // Burst Length
+ if (Burst_length_2) begin // Burst Length = 2
+ Col [0] = Col_temp [0];
+ end else if (Burst_length_4) begin // Burst Length = 4
+ Col [1 : 0] = Col_temp [1 : 0];
+ end else if (Burst_length_8) begin // Burst Length = 8
+ Col [2 : 0] = Col_temp [2 : 0];
+ end else begin // Burst Length = FULL
+ Col = Col_temp;
+ end
+
+ // Burst Read Single Write
+ if (Write_burst_mode == 1\'b1) begin
+ Data_in_enable = 1\'b0;
+ end
+
+ // Data Counter
+ if (Burst_length_1 == 1\'b1) begin
+ if (Burst_counter >= 1) begin
+ Data_in_enable = 1\'b0;
+ Data_out_enable = 1\'b0;
+ end
+ end else if (Burst_length_2 == 1\'b1) begin
+ if (Burst_counter >= 2) begin
+ Data_in_enable = 1\'b0;
+ Data_out_enable = 1\'b0;
+ end
+ end else if (Burst_length_4 == 1\'b1) begin
+ if (Burst_counter >= 4) begin
+ Data_in_enable = 1\'b0;
+ Data_out_enable = 1\'b0;
+ end
+ end else if (Burst_length_8 == 1\'b1) begin
+ if (Burst_counter >= 8) begin
+ Data_in_enable = 1\'b0;
+ Data_out_enable = 1\'b0;
+ end
+ end
+ end
+ endtask
+
+ // Timing Parameters for -7E (133 MHz @ CL2)
+ specify
+ specparam
+ tAH = 0.8, // Addr, Ba Hold Time
+ tAS = 1.5, // Addr, Ba Setup Time
+ tCH = 2.5, // Clock High-Level Width
+ tCL = 2.5, // Clock Low-Level Width
+ tCK = 7.0, // Clock Cycle Time
+ tDH = 0.8, // Data-in Hold Time
+ tDS = 1.5, // Data-in Setup Time
+ tCKH = 0.8, // CKE Hold Time
+ tCKS = 1.5, // CKE Setup Time
+ tCMH = 0.8, // CS#, RAS#, CAS#, WE#, DQM# Hold Time
+ tCMS = 1.5; // CS#, RAS#, CAS#, WE#, DQM# Setup Time
+ $width (posedge Clk, tCH);
+ $width (negedge Clk, tCL);
+ $period (negedge Clk, tCK);
+ $period (posedge Clk, tCK);
+ $setuphold(posedge Clk, Cke, tCKS, tCKH);
+ $setuphold(posedge Clk, Cs_n, tCMS, tCMH);
+ $setuphold(posedge Clk, Cas_n, tCMS, tCMH);
+ $setuphold(posedge Clk, Ras_n, tCMS, tCMH);
+ $setuphold(posedge Clk, We_n, tCMS, tCMH);
+ $setuphold(posedge Clk, Addr, tAS, tAH);
+ $setuphold(posedge Clk, Ba, tAS, tAH);
+ $setuphold(posedge Clk, Dqm, tCMS, tCMH);
+ $setuphold(posedge Dq_chk, Dq, tDS, tDH);
+ endspecify
+
+endmodule
+"
+"/*
+ * 8254 timer simplified for Zet SoC
+ * Copyright (c) 2010 YS
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+/*
+ * This module uses:
+ * - Wishbone interface
+ * - Modes (binary) 2 and 3 only
+ * - Common clock for all 3 Timers (tclk_i)
+ * - Gate input for Timer2 only (gate2_i)
+ * Assumptions:
+ * 1. tclk_i is asynchronous simple wire (1.193182 MHz by default)
+ * 2. gate2_i is synchronous (comes from Wishbone controlled register)
+ * 3. Wishbone clock wb_clk_i is running always and it has much higher
+ * frequency than tclk_i
+ */
+
+`define WB_UNBUFFERED_8254
+
+module timer
+ (
+ // Wishbone slave interface
+ input wb_clk_i,
+ input wb_rst_i,
+ input wb_adr_i,
+ input [1:0] wb_sel_i,
+ input [15:0] wb_dat_i,
+ output reg [15:0] wb_dat_o,
+ input wb_stb_i,
+ input wb_cyc_i,
+ input wb_we_i,
+ output wb_ack_o,
+ output reg wb_tgc_o, // intr
+
+ // CLK
+ input tclk_i, // 1.193182 MHz = (14.31818/12) MHz
+ // SPEAKER
+ input gate2_i,
+ output out2_o
+ );
+
+`ifdef WB_UNBUFFERED_8254
+ wire [15:0] data_ib;
+ wire wr_cyc1;
+ wire rd_cyc1;
+ wire [1:0] datasel;
+`else
+ reg [15:0] data_ib;
+ reg wr_cyc1;
+ reg rd_cyc1, rd_cyc2;
+ reg [1:0] datasel;
+`endif
+
+ wire intr, refresh;
+ reg intr1;
+ //reg [7:0] dat_o;
+
+ wire wrc, wrd0, wrd1, wrd2, rdd0, rdd1, rdd2;
+ wire [7:0] data0;
+ wire [7:0] data1;
+ wire [7:0] data2;
+
+ // Making 1 clock pulse on wb_tgc_o from intr
+ // unnecessary for real 8259A -> subj to remove later
+ always @(posedge wb_clk_i)
+ begin
+ intr1 <= wb_rst_i ? 1'b0 : intr;
+ wb_tgc_o <= wb_rst_i ? 1'b0 : (!intr1 & intr);
+ end
+
+ // 8-bit interface via wb_dat low byte (2-bit [2:1]??? wb_addr_i , no wb_sel_i)
+ /*
+ assign wb_ack_o = wb_stb_i & wb_cyc_i;
+
+ assign wrc = wb_ack_o & wb_we_i & (wb_adr_i == 2'b11);
+
+ assign wrd0 = wb_ack_o & wb_we_i & (wb_adr_i == 2'b00);
+ assign wrd1 = wb_ack_o & wb_we_i & (wb_adr_i == 2'b01);
+ assign wrd2 = wb_ack_o & wb_we_i & (wb_adr_i == 2'b10);
+
+ assign rdd0 = wb_ack_o & ~wb_we_i & (wb_adr_i == 2'b00);
+ assign rdd1 = wb_ack_o & ~wb_we_i & (wb_adr_i == 2'b01);
+ assign rdd2 = wb_ack_o & ~wb_we_i & (wb_adr_i == 2'b10);
+
+ always @(wb_adr_i or data0 or data1 or data2)
+ case (wb_adr_i)
+ 2'b00: wb_dat_o = { 8'h0, data0 };
+ 2'b01: wb_dat_o = { 8'h0, data1 };
+ 2'b10: wb_dat_o = { 8'h0, data2 };
+ endcase
+
+ timer_counter cnt0(0, 6'h36, 16'hFFFF, wb_clk_i, wb_rst_i, wrc, wrd0, rdd0, wb_dat_i, data0, tclk_i, 1'b1, intr); // 16-bit 55 ms Mode 3
+ timer_counter cnt1(1, 6'h14, 16'h0012, wb_clk_i, wb_rst_i, wrc, wrd1, rdd1, wb_dat_i, data1, tclk_i, 1'b1, refresh); // 8-bit 15 us Mode 2
+ timer_counter cnt2(2, 6'h36, 16'h04A9, wb_clk_i, wb_rst_i, wrc, wrd2, rdd2, wb_dat_i, data2, tclk_i, gate2_i, out2_o); // 16-bit 1 ms Mode 3
+ */
+
+ // 16-bit interface via wb_dat both bytes (1-bit wb_addr_i, 2-bit [1:0] wb_sel_i)
+ // assumes opposite wb_sel_i only: 2'b10 or 2'b01
+
+ reg [7:0] data_i;
+ reg [15:0] data_ob;
+
+ always @(datasel or data0 or data1 or data2)
+ case (datasel)
+ 2'b00: data_ob = { 8'h0, data0 };
+ 2'b01: data_ob = { data1, 8'h0 };
+ 2'b10: data_ob = { 8'h0, data2 };
+ 2'b11: data_ob = { 8'h0, 8'h0 }; // not checked yet!
+ endcase
+
+ always @(datasel or data_ib)
+ case (datasel)
+ 2'b00: data_i = data_ib[7:0];
+ 2'b01: data_i = data_ib[15:8];
+ 2'b10: data_i = data_ib[7:0];
+ 2'b11: data_i = data_ib[15:8];
+ endcase
+
+ assign wrc = wr_cyc1 & (datasel == 2'b11);
+
+ assign wrd0 = wr_cyc1 & (datasel == 2'b00);
+ assign wrd1 = wr_cyc1 & (datasel == 2'b01);
+ assign wrd2 = wr_cyc1 & (datasel == 2'b10);
+
+ assign rdd0 = rd_cyc1 & (datasel == 2'b00);
+ assign rdd1 = rd_cyc1 & (datasel == 2'b01);
+ assign rdd2 = rd_cyc1 & (datasel == 2'b10);
+
+ `ifdef WB_UNBUFFERED_8254
+ // 1 clock write, 1 clock read
+
+ assign wb_ack_o = wb_stb_i & wb_cyc_i;
+
+ assign wr_cyc1 = wb_ack_o & wb_we_i;
+ assign rd_cyc1 = wb_ack_o & ~wb_we_i;
+ assign datasel = {wb_adr_i,wb_sel_i[1]};
+
+ //assign wb_dat_o = data_ob;
+ always @(data_ob)
+ wb_dat_o = data_ob;
+ assign data_ib = wb_dat_i;
+
+ `else
+ // 2 clocks write, 3 clocks read
+
+ assign wb_ack_o = wr_cyc1 | rd_cyc2;
+
+ always @(posedge wb_clk_i)
+ begin
+ wr_cyc1 <= (wr_cyc1) ? 1'b0 : wb_stb_i & wb_cyc_i & wb_we_i; // single clock write pulse
+ rd_cyc1 <= (rd_cyc1 | rd_cyc2) ? 1'b0 : wb_stb_i & wb_cyc_i & ~wb_we_i; // single clock read pulse
+ rd_cyc2 <= rd_cyc1; // delayed single clock read pulse
+ datasel <= {wb_adr_i,wb_sel_i[1]};
+
+ wb_dat_o <= data_ob;
+ data_ib <= wb_dat_i;
+ end
+
+ `endif //def WB_UNBUFFERED_8254
+
+ // Module instantiations
+
+ timer_counter cnt0 (
+ .cntnum (2'd0),
+ .cw0 (6'h36), // 16-bit Mode 3
+ .cr0 (16'hFFFF), // 55 ms
+ .clkrw (wb_clk_i),
+ .rst (wb_rst_i),
+ .wrc (wrc),
+ .wrd (wrd0),
+ .rdd (rdd0),
+ .data_i (data_i),
+ .data_o (data0),
+ .clkt (tclk_i),
+ .gate (1'b1),
+ .out (intr)
+ );
+
+ timer_counter cnt1 (
+ .cntnum (2'd1),
+ .cw0 (6'h14), // 8-bit Mode 2
+ .cr0 (16'h0012), // 15 us
+ .clkrw (wb_clk_i),
+ .rst (wb_rst_i),
+ .wrc (wrc),
+ .wrd (wrd1),
+ .rdd (rdd1),
+ .data_i (data_i),
+ .data_o (data1),
+ .clkt (tclk_i),
+ .gate (1'b1),
+ .out (refresh)
+ );
+
+ timer_counter cnt2 (
+ .cntnum (2'd2),
+ .cw0 (6'h36), // 16-bit Mode 3
+ .cr0 (16'h04A9), // 1 ms
+ .clkrw (wb_clk_i),
+ .rst (wb_rst_i),
+ .wrc (wrc),
+ .wrd (wrd2),
+ .rdd (rdd2),
+ .data_i (data_i),
+ .data_o (data2),
+ .clkt (tclk_i),
+ .gate (gate2_i),
+ .out (out2_o)
+ );
+
+endmodule
+"
+"/*
+ * Write memory interface for VGA
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vga_write_iface (
+ // Wishbone common signals
+ input wb_clk_i,
+ input wb_rst_i,
+
+ // Wishbone slave write interface
+ input [16:1] wbs_adr_i,
+ input [ 1:0] wbs_sel_i,
+ input [15:0] wbs_dat_i,
+ input wbs_stb_i,
+ output wbs_ack_o,
+
+ // Wishbone master write to SRAM
+ output [17:1] wbm_adr_o,
+ output [ 1:0] wbm_sel_o,
+ output [15:0] wbm_dat_o,
+ output wbm_stb_o,
+ input wbm_ack_i,
+
+ // VGA configuration registers
+ input memory_mapping1,
+ input [ 1:0] write_mode,
+ input [ 1:0] raster_op,
+ input [ 7:0] bitmask,
+ input [ 3:0] set_reset,
+ input [ 3:0] enable_set_reset,
+ input [ 3:0] map_mask,
+
+ input [7:0] latch0,
+ input [7:0] latch1,
+ input [7:0] latch2,
+ input [7:0] latch3
+ );
+
+ // Registers and nets
+ wire [15:0] latch0_16;
+ wire [15:0] latch1_16;
+ wire [15:0] latch2_16;
+ wire [15:0] latch3_16;
+
+ wire [15:0] lb0;
+ wire [15:0] lb1;
+ wire [15:0] lb2;
+ wire [15:0] lb3;
+
+ wire [15:0] nlb0;
+ wire [15:0] nlb1;
+ wire [15:0] nlb2;
+ wire [15:0] nlb3;
+
+ wire [15:0] alb0;
+ wire [15:0] alb1;
+ wire [15:0] alb2;
+ wire [15:0] alb3;
+
+ wire [15:0] olb0;
+ wire [15:0] olb1;
+ wire [15:0] olb2;
+ wire [15:0] olb3;
+
+ wire [15:0] xlb0;
+ wire [15:0] xlb1;
+ wire [15:0] xlb2;
+ wire [15:0] xlb3;
+
+ wire [15:0] set0;
+ wire [15:0] set1;
+ wire [15:0] set2;
+ wire [15:0] set3;
+
+ wire [15:0] no_set0;
+ wire [15:0] no_set1;
+ wire [15:0] no_set2;
+ wire [15:0] no_set3;
+
+ wire [15:0] no_en0;
+ wire [15:0] no_en1;
+ wire [15:0] no_en2;
+ wire [15:0] no_en3;
+
+ wire [15:0] new_val0;
+ wire [15:0] new_val1;
+ wire [15:0] new_val2;
+ wire [15:0] new_val3;
+/*
+ wire [ 7:0] wr2_d0_0;
+ wire [ 7:0] wr2_d0_1;
+ wire [ 7:0] wr2_d0_2;
+ wire [ 7:0] wr2_d0_3;
+
+ wire [ 7:0] wr2_d1_0;
+ wire [ 7:0] wr2_d1_1;
+ wire [ 7:0] wr2_d1_2;
+ wire [ 7:0] wr2_d1_3;
+*/
+ wire [15:0] val0_write0, val0_write1, val0_write2, val0_write3;
+ wire [15:0] val1_write0, val1_write1, val1_write2, val1_write3;
+ wire [15:0] val0_or0, val0_or1, val0_or2, val0_or3;
+ wire [15:0] val1_or0, val1_or1, val1_or2, val1_or3;
+ wire [15:0] final_wr0, final_wr1, final_wr2, final_wr3;
+
+ wire [15:1] offset;
+ wire [15:0] bitmask16;
+ wire [15:0] dat_mask;
+ wire write_en;
+ wire cont;
+
+ reg [ 1:0] plane;
+ reg [ 3:0] plane_dec;
+
+ // Continuous assignments
+ assign bitmask16 = { bitmask, bitmask };
+ assign dat_mask = wbs_dat_i & bitmask16;
+
+ assign latch0_16 = { latch0, latch0 };
+ assign latch1_16 = { latch1, latch1 };
+ assign latch2_16 = { latch2, latch2 };
+ assign latch3_16 = { latch3, latch3 };
+
+ assign new_val0 = latch0_16 & ~bitmask16;
+ assign new_val1 = latch1_16 & ~bitmask16;
+ assign new_val2 = latch2_16 & ~bitmask16;
+ assign new_val3 = latch3_16 & ~bitmask16;
+
+ assign lb0 = latch0_16 & bitmask16;
+ assign lb1 = latch1_16 & bitmask16;
+ assign lb2 = latch2_16 & bitmask16;
+ assign lb3 = latch3_16 & bitmask16;
+
+ assign nlb0 = ~latch0_16 & bitmask16;
+ assign nlb1 = ~latch1_16 & bitmask16;
+ assign nlb2 = ~latch2_16 & bitmask16;
+ assign nlb3 = ~latch3_16 & bitmask16;
+
+ assign alb0 = (wbs_dat_i & latch0_16) & bitmask16;
+ assign alb1 = (wbs_dat_i & latch1_16) & bitmask16;
+ assign alb2 = (wbs_dat_i & latch2_16) & bitmask16;
+ assign alb3 = (wbs_dat_i & latch3_16) & bitmask16;
+
+ assign olb0 = (wbs_dat_i | latch0_16) & bitmask16;
+ assign olb1 = (wbs_dat_i | latch1_16) & bitmask16;
+ assign olb2 = (wbs_dat_i | latch2_16) & bitmask16;
+ assign olb3 = (wbs_dat_i | latch3_16) & bitmask16;
+
+ assign xlb0 = (wbs_dat_i ^ latch0_16) & bitmask16;
+ assign xlb1 = (wbs_dat_i ^ latch1_16) & bitmask16;
+ assign xlb2 = (wbs_dat_i ^ latch2_16) & bitmask16;
+ assign xlb3 = (wbs_dat_i ^ latch3_16) & bitmask16;
+
+ // write mode 0
+ assign set0 = raster_op[0] ? (raster_op[1] ? nlb0 : lb0 ) : bitmask16;
+ assign set1 = raster_op[0] ? (raster_op[1] ? nlb1 : lb1 ) : bitmask16;
+ assign set2 = raster_op[0] ? (raster_op[1] ? nlb2 : lb2 ) : bitmask16;
+ assign set3 = raster_op[0] ? (raster_op[1] ? nlb3 : lb3 ) : bitmask16;
+
+ assign no_set0 = raster_op[1] ? lb0 : 16'h0;
+ assign no_set1 = raster_op[1] ? lb1 : 16'h0;
+ assign no_set2 = raster_op[1] ? lb2 : 16'h0;
+ assign no_set3 = raster_op[1] ? lb3 : 16'h0;
+
+ assign no_en0 = raster_op[1] ? (raster_op[0] ? xlb0 : olb0)
+ : (raster_op[0] ? alb0 : dat_mask);
+ assign no_en1 = raster_op[1] ? (raster_op[0] ? xlb1 : olb1)
+ : (raster_op[0] ? alb1 : dat_mask);
+ assign no_en2 = raster_op[1] ? (raster_op[0] ? xlb2 : olb2)
+ : (raster_op[0] ? alb2 : dat_mask);
+ assign no_en3 = raster_op[1] ? (raster_op[0] ? xlb3 : olb3)
+ : (raster_op[0] ? alb3 : dat_mask);
+
+ assign val0_or0 = enable_set_reset[0] ?
+ (set_reset[0] ? set0 : no_set0) : no_en0;
+ assign val0_or1 = enable_set_reset[1] ?
+ (set_reset[1] ? set1 : no_set1) : no_en1;
+ assign val0_or2 = enable_set_reset[2] ?
+ (set_reset[2] ? set2 : no_set2) : no_en2;
+ assign val0_or3 = enable_set_reset[3] ?
+ (set_reset[3] ? set3 : no_set3) : no_en3;
+
+ assign val0_write0 = new_val0 | val0_or0;
+ assign val0_write1 = new_val1 | val0_or1;
+ assign val0_write2 = new_val2 | val0_or2;
+ assign val0_write3 = new_val3 | val0_or3;
+
+ // write mode 2
+/*
+ assign wr2_d0_0 = raster_op[1] ? lb0[7:0] : 8'h0;
+ assign wr2_d0_1 = raster_op[1] ? lb1[7:0] : 8'h0;
+ assign wr2_d0_2 = raster_op[1] ? lb2[7:0] : 8'h0;
+ assign wr2_d0_3 = raster_op[1] ? lb3[7:0] : 8'h0;
+
+ assign wr2_d1_0 = raster_op[0] ? (raster_op[1] ? nlb0[7:0] : lb0[7:0])
+ : bitmask;
+ assign wr2_d1_1 = raster_op[0] ? (raster_op[1] ? nlb1[7:0] : lb1[7:0])
+ : bitmask;
+ assign wr2_d1_2 = raster_op[0] ? (raster_op[1] ? nlb2[7:0] : lb2[7:0])
+ : bitmask;
+ assign wr2_d1_3 = raster_op[0] ? (raster_op[1] ? nlb3[7:0] : lb3[7:0])
+ : bitmask;
+
+ assign val1_or0[ 7:0] = wbs_dat_i[ 0] ? wr2_d1_0 : wr2_d0_0;
+ assign val1_or1[ 7:0] = wbs_dat_i[ 1] ? wr2_d1_1 : wr2_d0_1;
+ assign val1_or2[ 7:0] = wbs_dat_i[ 2] ? wr2_d1_2 : wr2_d0_2;
+ assign val1_or3[ 7:0] = wbs_dat_i[ 3] ? wr2_d1_3 : wr2_d0_3;
+ assign val1_or0[15:8] = wbs_dat_i[ 8] ? wr2_d1_0 : wr2_d0_0;
+ assign val1_or1[15:8] = wbs_dat_i[ 9] ? wr2_d1_1 : wr2_d0_1;
+ assign val1_or2[15:8] = wbs_dat_i[10] ? wr2_d1_2 : wr2_d0_2;
+ assign val1_or3[15:8] = wbs_dat_i[11] ? wr2_d1_3 : wr2_d0_3;
+*/
+ assign val1_or0[ 7:0] = wbs_dat_i[ 0] ? bitmask : 8'h0;
+ assign val1_or1[ 7:0] = wbs_dat_i[ 1] ? bitmask : 8'h0;
+ assign val1_or2[ 7:0] = wbs_dat_i[ 2] ? bitmask : 8'h0;
+ assign val1_or3[ 7:0] = wbs_dat_i[ 3] ? bitmask : 8'h0;
+ assign val1_or0[15:8] = wbs_dat_i[ 8] ? bitmask : 8'h0;
+ assign val1_or1[15:8] = wbs_dat_i[ 9] ? bitmask : 8'h0;
+ assign val1_or2[15:8] = wbs_dat_i[10] ? bitmask : 8'h0;
+ assign val1_or3[15:8] = wbs_dat_i[11] ? bitmask : 8'h0;
+
+ assign val1_write0 = new_val0 | val1_or0;
+ assign val1_write1 = new_val1 | val1_or1;
+ assign val1_write2 = new_val2 | val1_or2;
+ assign val1_write3 = new_val3 | val1_or3;
+
+ // Final write
+
+ assign final_wr0 = write_mode[1] ? val1_write0
+ : (write_mode[0] ? latch0_16 : val0_write0);
+ assign final_wr1 = write_mode[1] ? val1_write1
+ : (write_mode[0] ? latch1_16 : val0_write1);
+ assign final_wr2 = write_mode[1] ? val1_write2
+ : (write_mode[0] ? latch2_16 : val0_write2);
+ assign final_wr3 = write_mode[1] ? val1_write3
+ : (write_mode[0] ? latch3_16 : val0_write3);
+
+ assign offset = memory_mapping1 ? { 1'b0, wbs_adr_i[14:1] }
+ : wbs_adr_i[15:1];
+
+ assign wbm_adr_o = { offset, plane };
+ assign wbs_ack_o = (plane==2'b11 && cont);
+ assign wbm_dat_o = plane[1] ? (plane[0] ? final_wr3 : final_wr2)
+ : (plane[0] ? final_wr1 : final_wr0);
+
+ assign write_en = plane[1] ? (plane[0] ? map_mask[3] : map_mask[2])
+ : (plane[0] ? map_mask[1] : map_mask[0]);
+
+ assign wbm_sel_o = wbs_sel_i;
+ assign cont = (wbm_ack_i | !write_en) & wbs_stb_i;
+ assign wbm_stb_o = write_en & wbs_stb_i;
+
+ // plane
+ always @(posedge wb_clk_i)
+ plane <= wb_rst_i ? 2'b00 : (cont ? (plane + 2'b01) : plane);
+
+endmodule
+"
+"/*
+ * Wishbone asynchronous bridge with slave register slice
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module wb_abrg_reg (
+ input sys_rst,
+
+ // Wishbone slave interface
+ input wbs_clk_i,
+ input [19:1] wbs_adr_i,
+ input [15:0] wbs_dat_i,
+ output [15:0] wbs_dat_o,
+ input [ 1:0] wbs_sel_i,
+ input wbs_tga_i,
+ input wbs_stb_i,
+ input wbs_cyc_i,
+ input wbs_we_i,
+ output wbs_ack_o,
+
+ // Wishbone master interface
+ input wbm_clk_i,
+ output reg [19:1] wbm_adr_o,
+ output reg [15:0] wbm_dat_o,
+ input [15:0] wbm_dat_i,
+ output reg [ 1:0] wbm_sel_o,
+ output reg wbm_tga_o,
+ output wbm_stb_o,
+ output wbm_cyc_o,
+ output reg wbm_we_o,
+ input wbm_ack_i
+ );
+
+ // Registers and nets
+ wire wbs_stb;
+ wire init_tr;
+ reg wbm_stb;
+ reg [2:0] sync_stb;
+ reg [2:0] sync_ack;
+ reg ft_stb;
+ reg ft_ack;
+ reg stb_r;
+ reg ack_r;
+
+ reg [19:1] wbm_adr_o_r;
+ reg [15:0] wbm_dat_o_r;
+ reg [ 1:0] wbm_sel_o_r;
+ reg wbs_tga_i_r;
+ reg wbm_tga_o_r;
+ reg wbs_we_i_r;
+ reg wbm_we_o_r;
+ reg [15:0] wbs_dat_o_r;
+ reg [15:0] wbm_dat_i_r;
+
+ wire [19:1] wbs_adr_i_reg;
+ wire [15:0] wbs_dat_i_reg;
+ reg [15:0] wbs_dat_o_reg;
+ wire [ 1:0] wbs_sel_i_reg;
+ wire wbs_tga_i_reg;
+ wire wbs_stb_i_reg;
+ wire wbs_cyc_i_reg;
+ wire wbs_we_i_reg;
+ wire wbs_ack_o_reg;
+
+ // Instances
+ wb_regslice wb_slave_regslice (
+ .clk (wbs_clk_i),
+ .rst (sys_rst),
+
+ // Wishbone slave interface
+ .wbs_adr_i (wbs_adr_i),
+ .wbs_dat_i (wbs_dat_i),
+ .wbs_dat_o (wbs_dat_o),
+ .wbs_sel_i (wbs_sel_i),
+ .wbs_tga_i (wbs_tga_i),
+ .wbs_stb_i (wbs_stb_i),
+ .wbs_cyc_i (wbs_cyc_i),
+ .wbs_we_i (wbs_we_i),
+ .wbs_ack_o (wbs_ack_o),
+
+ // Wishbone master interface
+ .wbm_adr_o (wbs_adr_i_reg),
+ .wbm_dat_o (wbs_dat_i_reg),
+ .wbm_dat_i (wbs_dat_o_reg),
+ .wbm_sel_o (wbs_sel_i_reg),
+ .wbm_tga_o (wbs_tga_i_reg),
+ .wbm_stb_o (wbs_stb_i_reg),
+ .wbm_cyc_o (wbs_cyc_i_reg),
+ .wbm_we_o (wbs_we_i_reg),
+ .wbm_ack_i (wbs_ack_o_reg)
+ );
+
+
+ // Continous assignments
+ assign wbs_stb = wbs_stb_i_reg & wbs_cyc_i_reg;
+
+ // recreate the flag from the level change
+ assign wbs_ack_o_reg = (sync_ack[2] ^ sync_ack[1]);
+ assign wbm_stb_o = wbm_stb;
+ assign wbm_cyc_o = wbm_stb;
+
+ /*
+ * A new wishbone transaction is issued:
+ * . by changing stb from 0 to 1
+ * . by continue asserting stb after ack is received
+ */
+ assign init_tr = ~stb_r & wbs_stb | ack_r & ~wbs_ack_o_reg & wbs_stb;
+
+ // Behaviour
+ // wbm_stb
+ always @(posedge wbm_clk_i)
+ wbm_stb <= sys_rst ? 1'b0
+ : (wbm_stb ? ~wbm_ack_i : sync_stb[2] ^ sync_stb[1]);
+
+ // old stb and ack state
+ always @(posedge wbs_clk_i) stb_r <= wbs_stb;
+ always @(posedge wbs_clk_i) ack_r <= wbs_ack_o_reg;
+
+ always @(posedge wbs_clk_i)
+ ft_stb <= sys_rst ? 1'b0 : (init_tr ? ~ft_stb : ft_stb);
+
+ // synchronize the last level change
+ always @(posedge wbm_clk_i)
+ sync_stb <= sys_rst ? 3'h0 : {sync_stb[1:0], ft_stb};
+
+ // this changes level when a flag is seen
+ always @(posedge wbm_clk_i)
+ ft_ack <= sys_rst ? 1'b0 : (wbm_ack_i ? ~ft_ack : ft_ack);
+
+ // which can then be synched to wbs_clk_i
+ always @(posedge wbs_clk_i)
+ sync_ack <= sys_rst ? 3'h0 : {sync_ack[1:0], ft_ack};
+
+ // rest of the wishbone signals
+ always @(posedge wbm_clk_i)
+ {wbm_adr_o, wbm_adr_o_r} <= {wbm_adr_o_r, wbs_adr_i_reg};
+
+ always @(posedge wbm_clk_i)
+ {wbm_dat_o, wbm_dat_o_r} <= {wbm_dat_o_r, wbs_dat_i_reg};
+
+ always @(posedge wbm_clk_i)
+ {wbm_sel_o, wbm_sel_o_r} <= {wbm_sel_o_r, wbs_sel_i_reg};
+
+ always @(posedge wbs_clk_i) wbs_we_i_r <= wbs_we_i_reg;
+ always @(posedge wbm_clk_i)
+ {wbm_we_o, wbm_we_o_r} <= {wbm_we_o_r, wbs_we_i_r};
+
+ always @(posedge wbs_clk_i) wbs_tga_i_r <= wbs_tga_i_reg;
+ always @(posedge wbm_clk_i)
+ {wbm_tga_o, wbm_tga_o_r} <= {wbm_tga_o_r, wbs_tga_i_r};
+
+ /*
+ * Register input coming from the slave as that can change
+ * after the ack is received
+ */
+ always @(posedge wbm_clk_i)
+ wbm_dat_i_r <= wbm_ack_i ? wbm_dat_i : wbm_dat_i_r;
+
+ always @(posedge wbs_clk_i)
+ {wbs_dat_o_reg, wbs_dat_o_r} <= {wbs_dat_o_r, wbm_dat_i_r};
+
+endmodule
+"
+"/*\r
+ * PS2 Wishbone 8042 compatible keyboard controller\r
+ * Copyright (c) 2009 Zeus Gomez Marmolejo \r
+ * adapted from the opencores keyboard controller from John Clayton\r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+// --------------------------------------------------------------------\r
+// PS2 8042 partially compatible keyboard controller\r
+// (can not receive commands from host)\r
+// --------------------------------------------------------------------\r
+\r
+`define TOTAL_BITS 11\r
+`define RELEASE_CODE 16\'hF0\r
+`define LEFT_SHIFT 16\'h12\r
+`define RIGHT_SHIFT 16\'h59\r
+\r
+module ps2_keyb (\r
+ output released,\r
+ output rx_shifting_done,\r
+ output tx_shifting_done,\r
+ input reset, // Main reset line\r
+ input clk, // Main Clock\r
+ output [7:0] scancode, // scancode\r
+ output rx_output_strobe, // Signals a key presseed\r
+ input ps2_clk_, // PS2 PAD signals\r
+ inout ps2_data_\r
+ );\r
+\r
+ // --------------------------------------------------------------------\r
+ // Parameter declarations, the timer value can be up to (2^bits) inclusive.\r
+ // --------------------------------------------------------------------\r
+ parameter TIMER_60USEC_VALUE_PP = 1920; // Number of sys_clks for 60usec.\r
+ parameter TIMER_60USEC_BITS_PP = 11; // Number of bits needed for timer\r
+ parameter TIMER_5USEC_VALUE_PP = 186; // Number of sys_clks for debounce\r
+ parameter TIMER_5USEC_BITS_PP = 8; // Number of bits needed for timer\r
+ parameter TRAP_SHIFT_KEYS_PP = 0; // Default: No shift key trap.\r
+\r
+ // --------------------------------------------------------------------\r
+ // State encodings, provided as parametersf or flexibility to the one\r
+ // instantiating the module. In general, the default values need not be changed.\r
+ //\r
+ // State ""m1_rx_clk_l"" has been chosen on purpose. Since the inputs ynchronizing\r
+ // flip-flops initially contain zero, it takes one clkfor them to update to reflect\r
+ // the actual (idle = high) status oft he I/O lines from the keyboard. Therefore,\r
+ // choosing 0 for m1_rx_clk_la llows the state machine to transition to m1_rx_clk_h\r
+ // when the true values of the input signals become present at the outputs of the\r
+ // synchronizing flip-flops. This initial transition is harmless, and it\r
+ // eliminates the need for a ""reset"" pulse before the interface can operate.\r
+ // --------------------------------------------------------------------\r
+ parameter m1_rx_clk_h = 1;\r
+ parameter m1_rx_clk_l = 0;\r
+ parameter m1_rx_falling_edge_marker = 13;\r
+ parameter m1_rx_rising_edge_marker = 14;\r
+ parameter m1_tx_force_clk_l = 3;\r
+ parameter m1_tx_first_wait_clk_h = 10;\r
+ parameter m1_tx_first_wait_clk_l = 11;\r
+ parameter m1_tx_reset_timer = 12;\r
+ parameter m1_tx_wait_clk_h = 2;\r
+ parameter m1_tx_clk_h = 4;\r
+ parameter m1_tx_clk_l = 5;\r
+ parameter m1_tx_wait_keyboard_ack = 6;\r
+ parameter m1_tx_done_recovery = 7;\r
+ parameter m1_tx_error_no_keyboard_ack = 8;\r
+ parameter m1_tx_rising_edge_marker = 9;\r
+\r
+ // --------------------------------------------------------------------\r
+ // Nets and registers\r
+ // --------------------------------------------------------------------\r
+ wire rx_output_event;\r
+ //assign tx_shifting_done;\r
+ wire timer_60usec_done;\r
+ wire timer_5usec_done;\r
+ wire [6:0] xt_code;\r
+ reg [7:0] dat_o;\r
+ reg [3:0] bit_count;\r
+ reg [3:0] m1_state;\r
+ reg [3:0] m1_next_state;\r
+ //reg ps2_clk_hi_z; // Without keyboard, high Z equals 1 due to pullups.\r
+ reg ps2_data_hi_z; // Without keyboard, high Z equals 1 due to pullups.\r
+ reg ps2_clk_s; // Synchronous version of this input\r
+ reg ps2_data_s; // Synchronous version of this input\r
+ reg enable_timer_60usec;\r
+ reg enable_timer_5usec;\r
+ reg hold_released; // Holds prior value, cleared at rx_output_strobe\r
+\r
+ reg [TIMER_60USEC_BITS_PP-1:0] timer_60usec_count;\r
+ reg [TIMER_5USEC_BITS_PP-1 :0] timer_5usec_count;\r
+ reg [`TOTAL_BITS-1:0] q_r;\r
+ wire [`TOTAL_BITS-1:0] q;\r
+\r
+ // hack for the F5-F7 key bug\r
+ assign q = (q_r[8:1]==8\'h83)?{q_r[`TOTAL_BITS-1:9],8\'h02,q_r[0]} : q_r;\r
+\r
+ // --------------------------------------------------------------------\r
+ // Module instantiation\r
+ // --------------------------------------------------------------------\r
+ ps2_keyb_xtcodes keyb_xtcodes (\r
+ .at_code (q[7:1]),\r
+ .xt_code (xt_code)\r
+ );\r
+\r
+ // --------------------------------------------------------------------\r
+ // Continuous assignments\r
+ // This signal is high for one clock at the end of the timer count.\r
+ // --------------------------------------------------------------------\r
+ assign rx_shifting_done = (bit_count == `TOTAL_BITS);\r
+ assign tx_shifting_done = (bit_count == `TOTAL_BITS-1);\r
+ assign rx_output_event = (rx_shifting_done && ~released );\r
+ assign rx_output_strobe = (rx_shifting_done && ~released\r
+ && ( (TRAP_SHIFT_KEYS_PP == 0) || ( (q[8:1] != `RIGHT_SHIFT)\r
+ &&(q[8:1] != `LEFT_SHIFT) ) ) );\r
+\r
+ //assign ps2_clk_ = ps2_clk_hi_z ? 1\'bZ : 1\'b0;\r
+ assign ps2_data_ = ps2_data_hi_z ? 1\'bZ : 1\'b0;\r
+ assign timer_60usec_done = (timer_60usec_count == (TIMER_60USEC_VALUE_PP - 1));\r
+ assign timer_5usec_done = (timer_5usec_count == TIMER_5USEC_VALUE_PP - 1);\r
+\r
+ assign scancode = dat_o;\r
+\r
+ // --------------------------------------------------------------------\r
+ // Create the signals which indicate special scan codes received.\r
+ // These are the ""unlatched versions.""\r
+ // assign extended = (q[8:1] == `EXTEND_CODE) && rx_shifting_done;\r
+ // --------------------------------------------------------------------\r
+ assign released = (q[8:1] == `RELEASE_CODE) && rx_shifting_done;\r
+\r
+ // --------------------------------------------------------------------\r
+ // This is the shift register\r
+ // --------------------------------------------------------------------\r
+ always @(posedge clk)\r
+ if(reset) q_r <= 0;\r
+ else \r
+ if((m1_state == m1_rx_falling_edge_marker) ||(m1_state == m1_tx_rising_edge_marker)) q_r <= {ps2_data_s,q_r[`TOTAL_BITS-1:1]};\r
+\r
+ // This is the 60usec timer counter\r
+ always @(posedge clk)\r
+ if(~enable_timer_60usec) timer_60usec_count <= 0;\r
+ else if (~timer_60usec_done) timer_60usec_count <= timer_60usec_count + 10\'d1;\r
+\r
+ // This is the 5usec timer counter\r
+ always @(posedge clk)\r
+ if (~enable_timer_5usec) timer_5usec_count <= 0;\r
+ else if (~timer_5usec_done) timer_5usec_count <= timer_5usec_count + 6\'d1;\r
+\r
+ // --------------------------------------------------------------------\r
+ // Input ""synchronizing"" logic -- synchronizes the inputs to the state\r
+ // machine clock, thus avoiding errors related to spurious state machine transitions.\r
+ //\r
+ // Since the initial state of registers is zero, and the idle state\r
+ // of the ps2_clk and ps2_data lines is ""1"" (due to pullups), the\r
+ // ""sense"" of the ps2_clk_s signal is inverted from the true signal.\r
+ // This allows the state machine to ""come up"" in the correct\r
+ always @(posedge clk) begin\r
+ ps2_clk_s <= ps2_clk_;\r
+ ps2_data_s <= ps2_data_;\r
+ end\r
+\r
+ // State transition logic\r
+ always @(m1_state\r
+ or q\r
+ or tx_shifting_done\r
+ or ps2_clk_s\r
+ or ps2_data_s\r
+ or timer_60usec_done\r
+ or timer_5usec_done\r
+ )\r
+ begin : m1_state_logic\r
+\r
+ // Output signals default to this value,\r
+ // unless changed in a state condition.\r
+ //ps2_clk_hi_z <= 1;\r
+ ps2_data_hi_z <= 1;\r
+ enable_timer_60usec <= 0;\r
+ enable_timer_5usec <= 0;\r
+\r
+ case (m1_state)\r
+\r
+ m1_rx_clk_h :\r
+ begin\r
+ enable_timer_60usec <= 1;\r
+ if (~ps2_clk_s)\r
+ m1_next_state <= m1_rx_falling_edge_marker;\r
+ else m1_next_state <= m1_rx_clk_h;\r
+ end\r
+\r
+ m1_rx_falling_edge_marker :\r
+ begin\r
+ enable_timer_60usec <= 0;\r
+ m1_next_state <= m1_rx_clk_l;\r
+ end\r
+\r
+ m1_rx_rising_edge_marker :\r
+ begin\r
+ enable_timer_60usec <= 0;\r
+ m1_next_state <= m1_rx_clk_h;\r
+ end\r
+\r
+ m1_rx_clk_l :\r
+ begin\r
+ enable_timer_60usec <= 1;\r
+ if (ps2_clk_s)\r
+ m1_next_state <= m1_rx_rising_edge_marker;\r
+ else m1_next_state <= m1_rx_clk_l;\r
+ end\r
+\r
+ m1_tx_reset_timer :\r
+ begin\r
+ enable_timer_60usec <= 0;\r
+ m1_next_state <= m1_tx_force_clk_l;\r
+ end\r
+\r
+ m1_tx_force_clk_l :\r
+ begin\r
+ enable_timer_60usec <= 1;\r
+ //ps2_clk_hi_z <= 0; // Force the ps2_clk line low.\r
+ if (timer_60usec_done)\r
+ m1_next_state <= m1_tx_first_wait_clk_h;\r
+ else m1_next_state <= m1_tx_force_clk_l;\r
+ end\r
+\r
+ m1_tx_first_wait_clk_h :\r
+ begin\r
+ enable_timer_5usec <= 1;\r
+ ps2_data_hi_z <= 0; // Start bit.\r
+ if (~ps2_clk_s && timer_5usec_done)\r
+ m1_next_state <= m1_tx_clk_l;\r
+ else\r
+ m1_next_state <= m1_tx_first_wait_clk_h;\r
+ end\r
+\r
+ // This state must be included because the device might possibly\r
+ // delay for up to 10 milliseconds before beginning its clock pulses.\r
+ // During that waiting time, we cannot drive the data (q[0]) because it\r
+ // is possibly 1, which would cause the keyboard to abort its receive\r
+ // and the expected clocks would then never be generated.\r
+ m1_tx_first_wait_clk_l :\r
+ begin\r
+ ps2_data_hi_z <= 0;\r
+ if (~ps2_clk_s) m1_next_state <= m1_tx_clk_l;\r
+ else m1_next_state <= m1_tx_first_wait_clk_l;\r
+ end\r
+\r
+ m1_tx_wait_clk_h :\r
+ begin\r
+ enable_timer_5usec <= 1;\r
+ ps2_data_hi_z <= q[0];\r
+ if (ps2_clk_s && timer_5usec_done)\r
+ m1_next_state <= m1_tx_rising_edge_marker;\r
+ else\r
+ m1_next_state <= m1_tx_wait_clk_h;\r
+ end\r
+\r
+ m1_tx_rising_edge_marker :\r
+ begin\r
+ ps2_data_hi_z <= q[0];\r
+ m1_next_state <= m1_tx_clk_h;\r
+ end\r
+\r
+ m1_tx_clk_h :\r
+ begin\r
+ ps2_data_hi_z <= q[0];\r
+ if (tx_shifting_done) m1_next_state <= m1_tx_wait_keyboard_ack;\r
+ else if (~ps2_clk_s) m1_next_state <= m1_tx_clk_l;\r
+ else m1_next_state <= m1_tx_clk_h;\r
+ end\r
+\r
+ m1_tx_clk_l :\r
+ begin\r
+ ps2_data_hi_z <= q[0];\r
+ if (ps2_clk_s) m1_next_state <= m1_tx_wait_clk_h;\r
+ else m1_next_state <= m1_tx_clk_l;\r
+ end\r
+\r
+ m1_tx_wait_keyboard_ack :\r
+ begin\r
+ if (~ps2_clk_s && ps2_data_s)\r
+ m1_next_state <= m1_tx_error_no_keyboard_ack;\r
+ else if (~ps2_clk_s && ~ps2_data_s)\r
+ m1_next_state <= m1_tx_done_recovery;\r
+ else m1_next_state <= m1_tx_wait_keyboard_ack;\r
+ end\r
+\r
+ m1_tx_done_recovery :\r
+ begin\r
+ if (ps2_clk_s && ps2_data_s) m1_next_state <= m1_rx_clk_h;\r
+ else m1_next_state <= m1_tx_done_recovery;\r
+ end\r
+\r
+ m1_tx_error_no_keyboard_ack :\r
+ begin\r
+ if (ps2_clk_s && ps2_data_s) m1_next_state <= m1_rx_clk_h;\r
+ else m1_next_state <= m1_tx_error_no_keyboard_ack;\r
+ end\r
+\r
+ default : m1_next_state <= m1_rx_clk_h;\r
+ endcase\r
+ end\r
+\r
+ // State register\r
+ always @(posedge clk)\r
+ begin : m1_state_register\r
+ if(reset) m1_state <= m1_rx_clk_h;\r
+ else m1_state <= m1_next_state;\r
+ end\r
+\r
+ // dat_o - scancode\r
+ always @(posedge clk)\r
+ if(reset) dat_o <= 8\'b0;\r
+ else dat_o <= (rx_output_strobe && q[8:1]) ? (q[8] ? q[8:1] : {hold_released,xt_code}) : dat_o;\r
+\r
+ // This is the bit counter\r
+ always @(posedge clk)\r
+ begin\r
+ if(reset || rx_shifting_done || (m1_state == m1_tx_wait_keyboard_ack) // After tx is done.\r
+ ) bit_count <= 0; // normal reset\r
+ else if (timer_60usec_done && (m1_state == m1_rx_clk_h) && (ps2_clk_s)\r
+ ) bit_count <= 0; // rx watchdog timer reset\r
+ else if ( (m1_state == m1_rx_falling_edge_marker) // increment for rx\r
+ ||(m1_state == m1_tx_rising_edge_marker) // increment for tx\r
+ )\r
+ bit_count <= bit_count + 4\'d1;\r
+ end\r
+\r
+ // Store the special scan code status bits\r
+ // Not the final output, but an intermediate storage place,\r
+ // until the entire set of output data can be assembled.\r
+ always @(posedge clk)\r
+ if(reset || rx_output_event) hold_released <= 0;\r
+ else if (rx_shifting_done && released) hold_released <= 1;\r
+\r
+endmodule\r
+"
+"/*\r
+ * DUT VGA Address Generation\r
+ *\r
+ * VGA FML support\r
+ * Copyright (C) 2013 Charley Picker \r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+//`timescale 1ns/10ps\r
+`timescale 1ns/1ps\r
+\r
+module tb_vga_address;\r
+\r
+ // Registers and nets\r
+ reg clk_50;\r
+ reg rst;\r
+ \r
+ reg enable_sequencer;\r
+ reg enable_crtc;\r
+ \r
+ // Sequencer input signals\r
+ \r
+ reg [9:0] h_count;\r
+ reg horiz_sync_i;\r
+ \r
+ reg [9:0] v_count;\r
+ reg vert_sync;\r
+ \r
+ reg video_on_h_i;\r
+ reg video_on_v;\r
+ \r
+ // CRTC configuration signals\r
+ \r
+ reg [5:0] cur_start;\r
+ reg [5:0] cur_end;\r
+ reg [4:0] vcursor;\r
+ reg [6:0] hcursor;\r
+\r
+ reg [6:0] horiz_total;\r
+ reg [6:0] end_horiz;\r
+ reg [6:0] st_hor_retr;\r
+ reg [4:0] end_hor_retr;\r
+ reg [9:0] vert_total;\r
+ reg [9:0] end_vert;\r
+ reg [9:0] st_ver_retr;\r
+ reg [3:0] end_ver_retr;\r
+ \r
+ reg x_dotclockdiv2;\r
+ \r
+ // CSR slave interface for reading\r
+ wire [17:1] csr_adr_o;\r
+ reg [15:0] csr_dat_i;\r
+ reg csr_ack;\r
+ wire csr_stb_o;\r
+ \r
+ // FML slave interface for reading\r
+ wire [17:1] fml_adr_o;\r
+ reg [15:0] fml_dat_i;\r
+ wire fml_stb_o;\r
+ reg fml_ack;\r
+ wire fml_we = 1\'b0;\r
+ wire fml_dw = 16\'h1234;\r
+ \r
+ wire [3:0] attr_wm;\r
+ wire [3:0] attr_tm;\r
+ wire [3:0] fml_attr_tm;\r
+ wire [7:0] color;\r
+ \r
+ wire video_on_h_tm;\r
+ wire fml_video_on_h_tm;\r
+ wire video_on_h_wm;\r
+ wire video_on_h_gm;\r
+ \r
+ wire horiz_sync_tm;\r
+ wire fml_horiz_sync_tm;\r
+ wire horiz_sync_wm;\r
+ wire horiz_sync_gm;\r
+\r
+ wire [16:1] csr_tm_adr_o;\r
+ wire csr_tm_stb_o;\r
+ wire [16:1] fml_csr_tm_adr_o;\r
+ wire fml_csr_tm_stb_o;\r
+ wire [17:1] csr_wm_adr_o;\r
+ wire csr_wm_stb_o;\r
+ wire [17:1] csr_gm_adr_o;\r
+ wire csr_gm_stb_o;\r
+ \r
+ wire [9:0] hor_disp_end;\r
+ wire [9:0] hor_scan_end;\r
+ wire [9:0] ver_disp_end;\r
+ wire [9:0] ver_sync_beg;\r
+ wire [3:0] ver_sync_end;\r
+ wire [9:0] ver_scan_end;\r
+ \r
+ /* Process FML requests */\r
+ reg [2:0] fml_wcount;\r
+ reg [2:0] fml_rcount;\r
+ reg [3:0] fml_pipe;\r
+ initial begin\r
+\t fml_ack = 1\'b0;\r
+\t fml_wcount = 0;\r
+\t fml_rcount = 0;\r
+ end\r
+ \r
+ always @(posedge clk_50)\r
+ fml_pipe <= rst ? 4\'b0 : { fml_pipe[2:0], fml_csr_tm_stb_o };\r
+\r
+ always @(posedge clk_50) begin\r
+\t if(fml_pipe[1] & (fml_wcount == 0) & (fml_rcount == 0)) begin\r
+\t\t fml_ack <= 1\'b1;\r
+\t\t if(fml_we) begin\r
+\t\t\t //$display(""%t FML W addr %x data %x"", $time, fml_csr_tm_adr_o, fml_dw);\r
+\t\t\t fml_wcount <= 7;\r
+\t\t end else begin\r
+\t\t\t fml_dat_i = 16\'hbeef;\r
+\t\t\t //$display(""%t FML R addr %x data %x"", $time, fml_csr_tm_adr_o, fml_dat_i);\r
+\t\t\t fml_rcount <= 7;\r
+\t\t end\r
+\t end else\r
+\t\t fml_ack <= 1\'b0;\r
+\t if(fml_wcount != 0) begin\r
+\t\t //#1 $display(""%t FML W continuing %x / %d"", $time, fml_dw, fml_wcount);\r
+\t\t fml_wcount <= fml_wcount - 1;\r
+\t end\r
+\t if(fml_rcount != 0) begin\r
+\t\t fml_dat_i = #1 {13\'h1eba, fml_rcount};\r
+\t\t //$display(""%t FML R continuing %x / %d"", $time, fml_dat_i, fml_rcount);\r
+\t\t fml_rcount <= fml_rcount - 1;\r
+\t end\r
+ end\r
+ \r
+ /* Process CSR requests */\r
+ reg [15:0] csr_dat;\r
+ reg [2:0] csr_rcount;\r
+ reg [3:0] csr_pipe;\r
+ initial begin\r
+\t csr_ack = 1\'b0;\t \r
+\t csr_rcount = 0;\r
+ end\r
+ \r
+ always @(posedge clk_50)\r
+ csr_pipe <= rst ? 4\'b0 : { csr_pipe[2:0], csr_tm_stb_o };\r
+\r
+ always @(posedge clk_50) begin\r
+ //if (csr_tm_stb_o)\r
+ //$display(""%t CSR R addr %x"", $time, csr_tm_adr_o);\r
+ if (csr_pipe[1] & (csr_rcount == 0))\r
+ begin\r
+ csr_ack <= 1\'b1;\r
+\t\t csr_dat_i = 16\'hbeef;\r
+\t\t\t //$display(""%t CSR R data %x"", $time, csr_dat_i);\r
+\t\t\t csr_rcount <= 7;\r
+\t\t end else\r
+\t\t csr_ack <= 1\'b0;\t\t\r
+\t if(csr_pipe[1] & (csr_rcount != 0)) begin\r
+\t\t csr_dat_i = #1 {13\'h1eba, csr_rcount};\r
+\t\t //$display(""%t CSR R continuing %x / %d"", $time, csr_dat_i, csr_rcount);\r
+\t\t csr_rcount <= csr_rcount - 1;\r
+\t end\t \r
+ end\r
+ \r
+ // Module instantiations\r
+ vga_text_mode text_mode (\r
+ .clk (clk_50),\r
+ .rst (rst),\r
+ \r
+ //.enable (enable_sequencer),\r
+\r
+ // CSR slave interface for reading\r
+ .csr_adr_o (csr_tm_adr_o),\r
+ .csr_dat_i (csr_dat_i),\r
+ .csr_stb_o (csr_tm_stb_o),\r
+\r
+ .h_count (h_count),\r
+ .v_count (v_count),\r
+ .horiz_sync_i (horiz_sync_i),\r
+ .video_on_h_i (video_on_h_i),\r
+ .video_on_h_o (video_on_h_tm),\r
+\r
+ .cur_start (cur_start),\r
+ .cur_end (cur_end),\r
+ .vcursor (vcursor),\r
+ .hcursor (hcursor),\r
+\r
+ .attr (attr_tm),\r
+ .horiz_sync_o (horiz_sync_tm)\r
+ );\r
+ \r
+ vga_text_mode_fml text_mode_fml (\r
+ .clk (clk_50),\r
+ .rst (rst),\r
+ \r
+ .enable (enable_sequencer),\r
+\r
+ // CSR slave interface for reading\r
+ .fml_adr_o (fml_csr_tm_adr_o),\r
+ .fml_dat_i (fml_dat_i),\r
+ .fml_stb_o (fml_csr_tm_stb_o),\r
+\r
+ .h_count (h_count),\r
+ .v_count (v_count),\r
+ .horiz_sync_i (horiz_sync_i),\r
+ .video_on_h_i (video_on_h_i),\r
+ .video_on_h_o (fml_video_on_h_tm),\r
+\r
+ .cur_start (cur_start),\r
+ .cur_end (cur_end),\r
+ .vcursor (vcursor),\r
+ .hcursor (hcursor),\r
+\r
+ .attr (fml_attr_tm),\r
+ .horiz_sync_o (fml_horiz_sync_tm)\r
+ );\r
+ \r
+ vga_planar planar (\r
+ .clk (clk_50),\r
+ .rst (rst),\r
+ \r
+ //.enable (enable_sequencer),\r
+\r
+ // CSR slave interface for reading\r
+ .csr_adr_o (csr_wm_adr_o),\r
+ .csr_dat_i (csr_dat_i),\r
+ .csr_stb_o (csr_wm_stb_o),\r
+\r
+ .attr_plane_enable (4\'hf),\r
+ .x_dotclockdiv2 (x_dotclockdiv2),\r
+\r
+ .h_count (h_count),\r
+ .v_count (v_count),\r
+ .horiz_sync_i (horiz_sync_i),\r
+ .video_on_h_i (video_on_h_i),\r
+ .video_on_h_o (video_on_h_wm),\r
+\r
+ .attr (attr_wm),\r
+ .horiz_sync_o (horiz_sync_wm)\r
+ );\r
+\r
+ vga_linear linear (\r
+ .clk (clk_50),\r
+ .rst (rst),\r
+ \r
+ //.enable (enable_sequencer),\r
+\r
+ // CSR slave interface for reading\r
+ .csr_adr_o (csr_gm_adr_o),\r
+ .csr_dat_i (csr_dat_i),\r
+ .csr_stb_o (csr_gm_stb_o),\r
+\r
+ .h_count (h_count),\r
+ .v_count (v_count),\r
+ .horiz_sync_i (horiz_sync_i),\r
+ .video_on_h_i (video_on_h_i),\r
+ .video_on_h_o (video_on_h_gm),\r
+\r
+ .color (color),\r
+ .horiz_sync_o (horiz_sync_gm)\r
+ );\r
+ \r
+ // Continuous assignments\r
+ // assign hor_scan_end = { horiz_total[6:2] + 1\'b1, horiz_total[1:0], 3\'h7 };\r
+ assign hor_scan_end = 10\'d799;\r
+ \r
+ // assign hor_disp_end = { end_horiz, 3\'h7 };\r
+ assign hor_disp_end = 10\'d639;\r
+ \r
+ // assign ver_scan_end = vert_total + 10\'d1;\r
+ assign ver_scan_end = 10\'d448;\r
+ \r
+ // assign ver_disp_end = end_vert + 10\'d1;\r
+ assign ver_disp_end = 10\'d400;\r
+ \r
+ assign ver_sync_beg = st_ver_retr;\r
+ \r
+ assign ver_sync_end = end_ver_retr + 4\'d1;\r
+ \r
+ // Behaviour\r
+ // Clock generation\r
+ //always #10 clk_50 <= !clk_50;\r
+ initial clk_50 = 1\'b0;\r
+ always #5 clk_50 = ~clk_50;\r
+ \r
+task waitclock;\r
+begin\r
+\t@(posedge clk_50);\r
+\t#1;\r
+end\r
+endtask\r
+\r
+task resetpixel;\r
+begin\r
+ h_count = 10\'b0;\r
+ horiz_sync_i = 1\'b1;\r
+ v_count = 10\'b0;\r
+ vert_sync = 1\'b1;\r
+ video_on_h_i = 1\'b1;\r
+ video_on_v = 1\'b1;\r
+ $display(""Pixel counter reset to zero"");\r
+end\r
+endtask\r
+\r
+task nextpixel;\r
+begin\r
+ if (enable_crtc)\r
+ begin\r
+ h_count <= (h_count==hor_scan_end) ? 10\'b0 : h_count + 10\'b1;\r
+ horiz_sync_i <= horiz_sync_i ? (h_count[9:3]!=st_hor_retr)\r
+ : (h_count[7:3]==end_hor_retr);\r
+ v_count <= (v_count==ver_scan_end && h_count==hor_scan_end) ? 10\'b0\r
+ : ((h_count==hor_scan_end) ? v_count + 10\'b1 : v_count);\r
+ vert_sync <= vert_sync ? (v_count!=ver_sync_beg)\r
+ : (v_count[3:0]==ver_sync_end);\r
+\r
+ video_on_h_i <= (h_count==hor_scan_end) ? 1\'b1\r
+ : ((h_count==hor_disp_end) ? 1\'b0 : video_on_h_i);\r
+ video_on_v <= (v_count==10\'h0) ? 1\'b1\r
+ : ((v_count==ver_disp_end) ? 1\'b0 : video_on_v);\r
+ end\r
+ waitclock;\r
+ //$display(""h_count = %d, v_count = %d"", h_count, v_count);\r
+end \r
+endtask\r
+ \r
+always begin\r
+ // Initialize to a known state\r
+ rst = 1\'b1; // reset is active \r
+ resetpixel; // Reset pixel counter\r
+ enable_crtc = 1\'b0; // Make sure the crtc is not active\r
+ enable_sequencer = 1\'b0; // Make sure sequencer is not active\r
+ \r
+ waitclock; \r
+ \r
+ rst = 1\'b0;\r
+ \r
+ enable_crtc = 1\'b1; // Enable crtc\r
+ enable_sequencer = 1\'b1; // Enable sequencer \r
+ \r
+ waitclock;\r
+ \r
+ // CRTC configuration signals\r
+ \r
+ cur_start = 5\'d0; // reg [5:0] cur_start,\r
+ cur_end = 5\'d0; // reg [5:0] cur_end,\r
+ vcursor = 4\'d0; // reg [4:0] vcursor,\r
+ hcursor = 6\'d0; // reg [6:0] hcursor,\r
+\r
+ horiz_total = 7\'d639; // reg [6:0] horiz_total,\r
+ end_horiz = 7\'d750; // reg [6:0] end_horiz,\r
+ // st_hor_retr = 7\'d760; // reg [6:0] st_hor_retr,\r
+ st_hor_retr = 7\'d656; // reg [6:0] st_hor_retr,\r
+ // end_hor_retr = 5\'d10; // reg [4:0] end_hor_retr,\r
+ end_hor_retr = 5\'d752; // reg [4:0] end_hor_retr,\r
+ vert_total = 10\'d399; // reg [9:0] vert_total,\r
+ end_vert = 10\'d550; // reg [9:0] end_vert,\r
+ st_ver_retr = 10\'d560; // reg [9:0] st_ver_retr,\r
+ end_ver_retr = 4\'d10; // reg [3:0] end_ver_retr,\r
+ \r
+ x_dotclockdiv2 = 1\'b0; // reg x_dotclockdiv2\r
+ \r
+ //waitclock;\r
+ \r
+ // Total number of pixels to check\r
+ repeat (1000) begin\r
+ begin\r
+ if (attr_tm != fml_attr_tm) begin \r
+ $display(""Attributes attr_tm = %x and fml_attr_tm = %x did not match at (h_count = %d and v_count = %d) at time index %t"" , attr_tm, fml_attr_tm, h_count, v_count, $time); \r
+ end\r
+ if (csr_tm_adr_o != fml_csr_tm_adr_o) begin\r
+ $display(""Address csr_tm_adr_o = %x and fml_csr_tm_adr_o = %x did not match at (h_count = %d and v_count = %d) at time index %t"" , csr_tm_adr_o, fml_csr_tm_adr_o, h_count, v_count, $time); \r
+ end\r
+ if (video_on_h_tm != fml_video_on_h_tm) begin\r
+ $display(""Video_on_h video_on_h_tm = %x and fml_video_on_h_tm = %x did not match at (h_count = %d and v_count = %d) at time index %t"" , csr_tm_adr_o, fml_video_on_h_tm, h_count, v_count, $time);\r
+ end\r
+ if (horiz_sync_tm != fml_horiz_sync_tm) begin\r
+ $display(""Horiz_sync horiz_sync_tm = %x and fml_horiz_sync_tm = %x did not match at (h_count = %d and v_count = %d) at time index %t"" , horiz_sync_tm, fml_horiz_sync_tm, h_count, v_count, $time);\r
+ end\r
+ end\r
+ nextpixel;\r
+ end \r
+ \r
+ $stop;\r
+ \r
+end \r
+\r
+endmodule"
+"/*
+ * 16-bit bitwise rotate module for Zet
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_rxr16 (
+ input [15:0] x,
+ input ci,
+ input [ 4:0] y,
+ input e,
+ output reg [15:0] w,
+ output reg co
+ );
+
+ always @(x or ci or y or e)
+ case (y)
+ default: {co,w} <= {ci,x};
+ 5'd01: {co,w} <= e ? {x[0], ci, x[15:1]} : {ci, x[0], x[15:1]};
+ 5'd02: {co,w} <= e ? {x[ 1:0], ci, x[15: 2]} : {ci, x[ 1:0], x[15: 2]};
+ 5'd03: {co,w} <= e ? {x[ 2:0], ci, x[15: 3]} : {ci, x[ 2:0], x[15: 3]};
+ 5'd04: {co,w} <= e ? {x[ 3:0], ci, x[15: 4]} : {ci, x[ 3:0], x[15: 4]};
+ 5'd05: {co,w} <= e ? {x[ 4:0], ci, x[15: 5]} : {ci, x[ 4:0], x[15: 5]};
+ 5'd06: {co,w} <= e ? {x[ 5:0], ci, x[15: 6]} : {ci, x[ 5:0], x[15: 6]};
+ 5'd07: {co,w} <= e ? {x[ 6:0], ci, x[15: 7]} : {ci, x[ 6:0], x[15: 7]};
+ 5'd08: {co,w} <= e ? {x[ 7:0], ci, x[15: 8]} : {ci, x[ 7:0], x[15: 8]};
+ 5'd09: {co,w} <= e ? {x[ 8:0], ci, x[15: 9]} : {ci, x[ 8:0], x[15: 9]};
+ 5'd10: {co,w} <= e ? {x[ 9:0], ci, x[15:10]} : {ci, x[ 9:0], x[15:10]};
+ 5'd11: {co,w} <= e ? {x[10:0], ci, x[15:11]} : {ci, x[10:0], x[15:11]};
+ 5'd12: {co,w} <= e ? {x[11:0], ci, x[15:12]} : {ci, x[11:0], x[15:12]};
+ 5'd13: {co,w} <= e ? {x[12:0], ci, x[15:13]} : {ci, x[12:0], x[15:13]};
+ 5'd14: {co,w} <= e ? {x[13:0], ci, x[15:14]} : {ci, x[13:0], x[15:14]};
+ 5'd15: {co,w} <= e ? {x[14:0], ci, x[15]} : {ci, x[14:0], x[15]};
+ 5'd16: {co,w} <= {x,ci};
+ endcase
+endmodule
+"
+"/*
+ * Wishbone register slice
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module wb_regslice (
+ input clk,
+ input rst,
+
+ // Wishbone slave interface
+ input [19:1] wbs_adr_i,
+ input [15:0] wbs_dat_i,
+ output reg [15:0] wbs_dat_o,
+ input [ 1:0] wbs_sel_i,
+ input wbs_tga_i,
+ input wbs_stb_i,
+ input wbs_cyc_i,
+ input wbs_we_i,
+ output reg wbs_ack_o,
+
+ // Wishbone master interface
+ output reg [19:1] wbm_adr_o,
+ output reg [15:0] wbm_dat_o,
+ input [15:0] wbm_dat_i,
+ output reg [ 1:0] wbm_sel_o,
+ output reg wbm_tga_o,
+ output reg wbm_stb_o,
+ output reg wbm_cyc_o,
+ output reg wbm_we_o,
+ input wbm_ack_i
+ );
+
+ // Net declarations
+ wire ack_st;
+
+ // Combinational logic
+ assign ack_st = wbm_ack_i | wbs_ack_o;
+
+ // Sequential logic
+ always @(posedge clk)
+ wbm_stb_o <= rst ? 1'b0
+ : (ack_st ? 1'b0 : wbs_stb_i);
+
+ always @(posedge clk)
+ begin
+ wbm_adr_o <= wbs_adr_i;
+ wbm_dat_o <= wbs_dat_i;
+ wbm_sel_o <= wbs_sel_i;
+ wbm_tga_o <= wbs_tga_i;
+ wbm_cyc_o <= wbs_cyc_i;
+ wbm_we_o <= wbs_we_i;
+ end
+
+ always @(posedge clk)
+ begin
+ wbs_dat_o <= wbm_dat_i;
+ wbs_ack_o <= wbm_ack_i;
+ end
+
+endmodule
+"
+"/*
+ * Milkymist VJ SoC
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+module hpdmc_sdrio(
+\tinput sys_clk,
+\t
+\tinput direction,
+\tinput direction_r,
+\tinput [ 1:0] mo,
+\tinput [15:0] dout,
+\toutput reg [15:0] di,
+\t
+\toutput [ 1:0] sdram_dqm,
+\tinout [15:0] sdram_dq
+);
+
+wire [15:0] sdram_data_out;
+assign sdram_dq = direction ? sdram_data_out : 16'hzzzz;
+
+/*
+ * In this case, without DDR primitives and delays, this block
+ * is extremely simple
+ */
+assign sdram_dqm = mo;
+assign sdram_data_out = dout;
+
+ // Behaviour
+ always @(posedge sys_clk) di <= sdram_dq;
+
+endmodule
+"
+"/*
+ * Zet processor top level file
+ * Copyright (c) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`timescale 1ns/10ps
+
+`include ""defines.v""
+
+module zet (
+ // Wishbone master interface
+ input wb_clk_i,
+ input wb_rst_i,
+ input [15:0] wb_dat_i,
+ output [15:0] wb_dat_o,
+ output [19:1] wb_adr_o,
+ output wb_we_o,
+ output wb_tga_o, // io/mem
+ output [ 1:0] wb_sel_o,
+ output wb_stb_o,
+ output wb_cyc_o,
+ input wb_ack_i,
+ input wb_tgc_i, // intr
+ output wb_tgc_o, // inta
+ input nmi,
+ output nmia,
+
+ output [19:0] pc // for debugging purposes
+ );
+
+ // Net declarations
+ wire [15:0] cpu_dat_o;
+ wire cpu_block;
+ wire [19:0] cpu_adr_o;
+
+ wire cpu_byte_o;
+ wire cpu_mem_op;
+ wire cpu_m_io;
+ wire [15:0] cpu_dat_i;
+ wire cpu_we_o;
+ wire [15:0] iid_dat_i;
+
+ // Module instantiations
+ zet_core core (
+ .clk (wb_clk_i),
+ .rst (wb_rst_i),
+
+ .intr (wb_tgc_i),
+ .inta (wb_tgc_o),
+ .nmi (nmi),
+ .nmia (nmia),
+
+ .cpu_adr_o (cpu_adr_o),
+ .iid_dat_i (iid_dat_i),
+ .cpu_dat_i (cpu_dat_i),
+ .cpu_dat_o (cpu_dat_o),
+ .cpu_byte_o (cpu_byte_o),
+ .cpu_block (cpu_block),
+ .cpu_mem_op (cpu_mem_op),
+ .cpu_m_io (cpu_m_io),
+ .cpu_we_o (cpu_we_o),
+
+ .pc (pc)
+ );
+
+ zet_wb_master wb_master (
+ .cpu_byte_o (cpu_byte_o),
+ .cpu_memop (cpu_mem_op),
+ .cpu_m_io (cpu_m_io),
+ .cpu_adr_o (cpu_adr_o),
+ .cpu_block (cpu_block),
+ .cpu_dat_i (cpu_dat_i),
+ .cpu_dat_o (cpu_dat_o),
+ .cpu_we_o (cpu_we_o),
+
+ .wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wb_dat_i (wb_dat_i),
+ .wb_dat_o (wb_dat_o),
+ .wb_adr_o (wb_adr_o),
+ .wb_we_o (wb_we_o),
+ .wb_tga_o (wb_tga_o),
+ .wb_sel_o (wb_sel_o),
+ .wb_stb_o (wb_stb_o),
+ .wb_cyc_o (wb_cyc_o),
+ .wb_ack_i (wb_ack_i)
+ );
+
+ // Assignments
+ assign iid_dat_i = (wb_tgc_o | nmia) ? wb_dat_i : cpu_dat_i;
+
+endmodule
+"
+"/*
+ * Zet SoC top level file for Altera DE1 board
+ * Copyright (C) 2009, 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module kotku (
+ // Clock input
+ input clk_50_,
+
+ // General purpose IO
+ input [7:0] sw_,
+ input key_,
+ output [6:0] hex0_,
+ output [6:0] hex1_,
+ output [6:0] hex2_,
+ output [6:0] hex3_,
+ output [9:0] ledr_,
+ output [7:0] ledg_,
+
+ // flash signals
+ output [21:0] flash_addr_,
+ input [ 7:0] flash_data_,
+ output flash_oe_n_,
+ output flash_ce_n_,
+
+ // sdram signals
+ output [11:0] sdram_addr_,
+ inout [15:0] sdram_data_,
+ output [ 1:0] sdram_ba_,
+ output sdram_ras_n_,
+ output sdram_cas_n_,
+ output sdram_ce_,
+ output sdram_clk_,
+ output sdram_we_n_,
+ output sdram_cs_n_,
+
+ // VGA signals
+ output [ 3:0] tft_lcd_r_,
+ output [ 3:0] tft_lcd_g_,
+ output [ 3:0] tft_lcd_b_,
+ output tft_lcd_hsync_,
+ output tft_lcd_vsync_,
+
+ // UART signals
+ output uart_txd_,
+
+ // PS2 signals
+ input ps2_kclk_, // PS2 keyboard Clock
+ inout ps2_kdat_, // PS2 Keyboard Data
+ inout ps2_mclk_, // PS2 Mouse Clock
+ inout ps2_mdat_, // PS2 Mouse Data
+
+ // SD card signals
+ output sd_sclk_,
+ input sd_miso_,
+ output sd_mosi_,
+ output sd_ss_,
+
+ // I2C for audio codec
+ inout i2c_sdat_,
+ output i2c_sclk_,
+
+ // Audio codec signals
+ input aud_daclrck_,
+ output aud_dacdat_,
+ input aud_bclk_,
+ output aud_xck_
+ );
+
+ // Registers and nets
+ wire clk;
+ wire rst_lck;
+ wire [15:0] dat_o;
+ wire [15:0] dat_i;
+ wire [19:1] adr;
+ wire we;
+ wire tga;
+ wire [ 1:0] sel;
+ wire stb;
+ wire cyc;
+ wire ack;
+ wire lock;
+
+ // wires to BIOS ROM
+ wire [15:0] rom_dat_o;
+ wire [15:0] rom_dat_i;
+ wire rom_tga_i;
+ wire [19:1] rom_adr_i;
+ wire [ 1:0] rom_sel_i;
+ wire rom_we_i;
+ wire rom_cyc_i;
+ wire rom_stb_i;
+ wire rom_ack_o;
+
+ // wires to flash controller
+ wire [15:0] fl_dat_o;
+ wire [15:0] fl_dat_i;
+ wire fl_tga_i;
+ wire [19:1] fl_adr_i;
+ wire [ 1:0] fl_sel_i;
+ wire fl_we_i;
+ wire fl_cyc_i;
+ wire fl_stb_i;
+ wire fl_ack_o;
+
+ // Unused outputs
+ wire flash_we_n_;
+ wire flash_rst_n_;
+ wire [1:0] sdram_dqm_;
+ wire [2:0] s19_17;
+
+ // Unused inputs
+ wire uart_rxd_;
+ wire aud_adcdat_;
+
+ // wires to vga controller
+ wire [15:0] vga_dat_o;
+ wire [15:0] vga_dat_i;
+ wire vga_tga_i;
+ wire [19:1] vga_adr_i;
+ wire [ 1:0] vga_sel_i;
+ wire vga_we_i;
+ wire vga_cyc_i;
+ wire vga_stb_i;
+ wire vga_ack_o;
+
+ // cross clock domain synchronized signals
+ wire [15:0] vga_dat_o_s;
+ wire [15:0] vga_dat_i_s;
+ wire vga_tga_i_s;
+ wire [19:1] vga_adr_i_s;
+ wire [ 1:0] vga_sel_i_s;
+ wire vga_we_i_s;
+ wire vga_cyc_i_s;
+ wire vga_stb_i_s;
+ wire vga_ack_o_s;
+
+ // wires to uart controller
+ wire [15:0] uart_dat_o;
+ wire [15:0] uart_dat_i;
+ wire uart_tga_i;
+ wire [19:1] uart_adr_i;
+ wire [ 1:0] uart_sel_i;
+ wire uart_we_i;
+ wire uart_cyc_i;
+ wire uart_stb_i;
+ wire uart_ack_o;
+
+ // wires to keyboard controller
+ wire [15:0] keyb_dat_o;
+ wire [15:0] keyb_dat_i;
+ wire keyb_tga_i;
+ wire [19:1] keyb_adr_i;
+ wire [ 1:0] keyb_sel_i;
+ wire keyb_we_i;
+ wire keyb_cyc_i;
+ wire keyb_stb_i;
+ wire keyb_ack_o;
+
+ // wires to timer controller
+ wire [15:0] timer_dat_o;
+ wire [15:0] timer_dat_i;
+ wire timer_tga_i;
+ wire [19:1] timer_adr_i;
+ wire [ 1:0] timer_sel_i;
+ wire timer_we_i;
+ wire timer_cyc_i;
+ wire timer_stb_i;
+ wire timer_ack_o;
+
+ // wires to sd controller
+ wire [19:1] sd_adr_i;
+ wire [ 7:0] sd_dat_o;
+ wire [15:0] sd_dat_i;
+ wire sd_tga_i;
+ wire [ 1:0] sd_sel_i;
+ wire sd_we_i;
+ wire sd_cyc_i;
+ wire sd_stb_i;
+ wire sd_ack_o;
+
+ // wires to sd bridge
+ wire [19:1] sd_adr_i_s;
+ wire [15:0] sd_dat_o_s;
+ wire [15:0] sd_dat_i_s;
+ wire sd_tga_i_s;
+ wire [ 1:0] sd_sel_i_s;
+ wire sd_we_i_s;
+ wire sd_cyc_i_s;
+ wire sd_stb_i_s;
+ wire sd_ack_o_s;
+
+ // wires to gpio controller
+ wire [15:0] gpio_dat_o;
+ wire [15:0] gpio_dat_i;
+ wire gpio_tga_i;
+ wire [19:1] gpio_adr_i;
+ wire [ 1:0] gpio_sel_i;
+ wire gpio_we_i;
+ wire gpio_cyc_i;
+ wire gpio_stb_i;
+ wire gpio_ack_o;
+
+ // wires to SDRAM controller
+ wire [19:1] fmlbrg_adr_s;
+ wire [15:0] fmlbrg_dat_w_s;
+ wire [15:0] fmlbrg_dat_r_s;
+ wire [ 1:0] fmlbrg_sel_s;
+ wire fmlbrg_cyc_s;
+ wire fmlbrg_stb_s;
+ wire fmlbrg_tga_s;
+ wire fmlbrg_we_s;
+ wire fmlbrg_ack_s;
+
+ wire [19:1] fmlbrg_adr;
+ wire [15:0] fmlbrg_dat_w;
+ wire [15:0] fmlbrg_dat_r;
+ wire [ 1:0] fmlbrg_sel;
+ wire fmlbrg_cyc;
+ wire fmlbrg_stb;
+ wire fmlbrg_tga;
+ wire fmlbrg_we;
+ wire fmlbrg_ack;
+
+ wire [19:1] csrbrg_adr_s;
+ wire [15:0] csrbrg_dat_w_s;
+ wire [15:0] csrbrg_dat_r_s;
+ wire [ 1:0] csrbrg_sel_s;
+ wire csrbrg_cyc_s;
+ wire csrbrg_stb_s;
+ wire csrbrg_tga_s;
+ wire csrbrg_we_s;
+ wire csrbrg_ack_s;
+
+ wire [19:1] csrbrg_adr;
+ wire [15:0] csrbrg_dat_w;
+ wire [15:0] csrbrg_dat_r;
+ wire [ 1:0] csrbrg_sel;
+ wire csrbrg_tga;
+ wire csrbrg_cyc;
+ wire csrbrg_stb;
+ wire csrbrg_we;
+ wire csrbrg_ack;
+
+ wire sb_cyc_i;
+ wire sb_stb_i;
+
+ wire [ 2:0] csr_a;
+ wire csr_we;
+ wire [15:0] csr_dw;
+ wire [15:0] csr_dr_hpdmc;
+
+ // wires to hpdmc slave interface
+ wire [22:0] fml_adr;
+ wire fml_stb;
+ wire fml_we;
+ wire fml_ack;
+ wire [ 1:0] fml_sel;
+ wire [15:0] fml_di;
+ wire [15:0] fml_do;
+
+ // wires to fml bridge master interface
+ wire [19:0] fml_fmlbrg_adr;
+ wire fml_fmlbrg_stb;
+ wire fml_fmlbrg_we;
+ wire fml_fmlbrg_ack;
+ wire [ 1:0] fml_fmlbrg_sel;
+ wire [15:0] fml_fmlbrg_di;
+ wire [15:0] fml_fmlbrg_do;
+
+ // wires to VGA CPU FML master interface
+ wire [19:0] vga_cpu_fml_adr; // 1MB Memory Address range
+ wire vga_cpu_fml_stb;
+ wire vga_cpu_fml_we;
+ wire vga_cpu_fml_ack;
+ wire [1:0] vga_cpu_fml_sel;
+ wire [15:0] vga_cpu_fml_do;
+ wire [15:0] vga_cpu_fml_di;
+
+ // wires to VGA LCD FML master interface
+ wire [19:0] vga_lcd_fml_adr; // 1MB Memory Address range
+ wire vga_lcd_fml_stb;
+ wire vga_lcd_fml_we;
+ wire vga_lcd_fml_ack;
+ wire [1:0] vga_lcd_fml_sel;
+ wire [15:0] vga_lcd_fml_do;
+ wire [15:0] vga_lcd_fml_di;
+
+ // wires to default stb/ack
+ wire def_cyc_i;
+ wire def_stb_i;
+ wire [15:0] sw_dat_o;
+ wire sdram_clk;
+ wire vga_clk;
+
+ wire [ 7:0] intv;
+ wire [ 2:0] iid;
+ wire intr;
+ wire inta;
+
+ wire nmi_pb;
+ wire nmi;
+ wire nmia;
+
+ wire [19:0] pc;
+ reg [16:0] rst_debounce;
+
+ wire timer_clk;
+ wire timer2_o;
+
+ // Audio only signals
+ wire [ 7:0] aud_dat_o;
+ wire aud_cyc_i;
+ wire aud_ack_o;
+ wire aud_sel_cond;
+
+ // Keyboard-audio shared signals
+ wire [ 7:0] kaud_dat_o;
+ wire kaud_cyc_i;
+ wire kaud_ack_o;
+
+`ifndef SIMULATION
+ /*
+ * Debounce it (counter holds reset for 10.49ms),
+ * and generate power-on reset.
+ */
+ initial rst_debounce <= 17'h1FFFF;
+ reg rst;
+ initial rst <= 1'b1;
+ always @(posedge clk) begin
+ if(~rst_lck) /* reset is active low */
+ rst_debounce <= 17'h1FFFF;
+ else if(rst_debounce != 17'd0)
+ rst_debounce <= rst_debounce - 17'd1;
+ rst <= rst_debounce != 17'd0;
+ end
+`else
+ wire rst;
+ assign rst = !rst_lck;
+`endif
+
+ // Module instantiations
+ pll pll (
+ .inclk0 (clk_50_),
+ .c0 (sdram_clk), // 100 Mhz
+ .c1 (), // 25 Mhz
+ .c2 (clk), // 12.5 Mhz
+ .locked (lock)
+ );
+
+ clk_gen #(
+ .res (21),
+ .phase (21'd100091)
+ ) timerclk (
+ .clk_i (vga_clk), // 25 MHz
+ .rst_i (rst),
+ .clk_o (timer_clk) // 1.193178 MHz (required 1.193182 MHz)
+ );
+
+ clk_gen #(
+ .res (18),
+ .phase (18'd29595)
+ ) audioclk (
+ .clk_i (sdram_clk), // 100 MHz (use highest freq to minimize jitter)
+ .rst_i (rst),
+ .clk_o (aud_xck_) // 11.28960 MHz (required 11.28960 MHz)
+ );
+
+ bootrom bootrom (
+ .clk (clk), // Wishbone slave interface
+ .rst (rst),
+ .wb_dat_i (rom_dat_i),
+ .wb_dat_o (rom_dat_o),
+ .wb_adr_i (rom_adr_i),
+ .wb_we_i (rom_we_i ),
+ .wb_tga_i (rom_tga_i),
+ .wb_stb_i (rom_stb_i),
+ .wb_cyc_i (rom_cyc_i),
+ .wb_sel_i (rom_sel_i),
+ .wb_ack_o (rom_ack_o)
+ );
+
+ flash8 flash8 (
+ // Wishbone slave interface
+ .wb_clk_i (clk), // Main Clock
+ .wb_rst_i (rst), // Reset Line
+ .wb_adr_i (fl_adr_i[1]), // Address lines
+ .wb_sel_i (fl_sel_i), // Select lines
+ .wb_dat_i (fl_dat_i), // Command to send
+ .wb_dat_o (fl_dat_o), // Received data
+ .wb_cyc_i (fl_cyc_i), // Cycle
+ .wb_stb_i (fl_stb_i), // Strobe
+ .wb_we_i (fl_we_i), // Write enable
+ .wb_ack_o (fl_ack_o), // Normal bus termination
+
+ // Pad signals
+ .flash_addr_ (flash_addr_),
+ .flash_data_ (flash_data_),
+ .flash_we_n_ (flash_we_n_),
+ .flash_oe_n_ (flash_oe_n_),
+ .flash_ce_n_ (flash_ce_n_),
+ .flash_rst_n_ (flash_rst_n_)
+ );
+
+ wb_abrgr wb_fmlbrg (
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wbs_clk_i (clk),
+ .wbs_adr_i (fmlbrg_adr_s),
+ .wbs_dat_i (fmlbrg_dat_w_s),
+ .wbs_dat_o (fmlbrg_dat_r_s),
+ .wbs_sel_i (fmlbrg_sel_s),
+ .wbs_tga_i (fmlbrg_tga_s),
+ .wbs_stb_i (fmlbrg_stb_s),
+ .wbs_cyc_i (fmlbrg_cyc_s),
+ .wbs_we_i (fmlbrg_we_s),
+ .wbs_ack_o (fmlbrg_ack_s),
+
+ // Wishbone master interface
+ .wbm_clk_i (sdram_clk),
+ .wbm_adr_o (fmlbrg_adr),
+ .wbm_dat_o (fmlbrg_dat_w),
+ .wbm_dat_i (fmlbrg_dat_r),
+ .wbm_sel_o (fmlbrg_sel),
+ .wbm_tga_o (fmlbrg_tga),
+ .wbm_stb_o (fmlbrg_stb),
+ .wbm_cyc_o (fmlbrg_cyc),
+ .wbm_we_o (fmlbrg_we),
+ .wbm_ack_i (fmlbrg_ack)
+ );
+
+ fmlbrg #(
+ .fml_depth (20), // 8086 can only address 1 MB
+ .cache_depth (10) // 1 Kbyte cache
+ ) fmlbrg (
+ .sys_clk (sdram_clk),
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wb_adr_i (fmlbrg_adr),
+ .wb_cti_i(3'b0),
+ .wb_dat_i (fmlbrg_dat_w),
+ .wb_dat_o (fmlbrg_dat_r),
+ .wb_sel_i (fmlbrg_sel),
+ .wb_cyc_i (fmlbrg_cyc),
+ .wb_stb_i (fmlbrg_stb),
+ .wb_tga_i (fmlbrg_tga),
+ .wb_we_i (fmlbrg_we),
+ .wb_ack_o (fmlbrg_ack),
+
+ // FML master 1 interface
+ .fml_adr (fml_fmlbrg_adr),
+ .fml_stb (fml_fmlbrg_stb),
+ .fml_we (fml_fmlbrg_we),
+ .fml_ack (fml_fmlbrg_ack),
+ .fml_sel (fml_fmlbrg_sel),
+ .fml_do (fml_fmlbrg_do),
+ .fml_di (fml_fmlbrg_di),
+
+ // Direct Cache Bus
+ .dcb_stb(1'b0),
+ .dcb_adr(20'b0),
+ .dcb_dat(),
+ .dcb_hit()
+
+ );
+
+ wb_abrgr wb_csrbrg (
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wbs_clk_i (clk),
+ .wbs_adr_i (csrbrg_adr_s),
+ .wbs_dat_i (csrbrg_dat_w_s),
+ .wbs_dat_o (csrbrg_dat_r_s),
+ .wbs_sel_i (csrbrg_sel_s),
+ .wbs_tga_i (csrbrg_tga_s),
+ .wbs_stb_i (csrbrg_stb_s),
+ .wbs_cyc_i (csrbrg_cyc_s),
+ .wbs_we_i (csrbrg_we_s),
+ .wbs_ack_o (csrbrg_ack_s),
+
+ // Wishbone master interface
+ .wbm_clk_i (sdram_clk),
+ .wbm_adr_o (csrbrg_adr),
+ .wbm_dat_o (csrbrg_dat_w),
+ .wbm_dat_i (csrbrg_dat_r),
+ .wbm_sel_o (csrbrg_sel),
+ .wbm_tga_o (csrbrg_tga),
+ .wbm_stb_o (csrbrg_stb),
+ .wbm_cyc_o (csrbrg_cyc),
+ .wbm_we_o (csrbrg_we),
+ .wbm_ack_i (csrbrg_ack)
+ );
+
+ csrbrg csrbrg (
+ .sys_clk (sdram_clk),
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wb_adr_i (csrbrg_adr[3:1]),
+ .wb_dat_i (csrbrg_dat_w),
+ .wb_dat_o (csrbrg_dat_r),
+ .wb_cyc_i (csrbrg_cyc),
+ .wb_stb_i (csrbrg_stb),
+ .wb_we_i (csrbrg_we),
+ .wb_ack_o (csrbrg_ack),
+
+ // CSR master interface
+ .csr_a (csr_a),
+ .csr_we (csr_we),
+ .csr_do (csr_dw),
+ .csr_di (csr_dr_hpdmc)
+ );
+
+ fmlarb #(
+ .fml_depth (23)
+ ) fmlarb (
+ .sys_clk (sdram_clk),
+ .sys_rst (rst),
+
+ // Master 0 interface - VGA LCD FML (Reserved video memory port has highest priority)
+ .m0_adr ({3'b001, vga_lcd_fml_adr}), // 1 - 2 MB Addressable memory range
+ .m0_stb (vga_lcd_fml_stb),
+ .m0_we (vga_lcd_fml_we),
+ .m0_ack (vga_lcd_fml_ack),
+ .m0_sel (vga_lcd_fml_sel),
+ .m0_di (vga_lcd_fml_do),
+ .m0_do (vga_lcd_fml_di),
+
+ // Master 1 interface - Wishbone FML bridge
+ .m1_adr ({3'b000, fml_fmlbrg_adr}), // 0 - 1 MB Addressable memory range
+ .m1_stb (fml_fmlbrg_stb),
+ .m1_we (fml_fmlbrg_we),
+ .m1_ack (fml_fmlbrg_ack),
+ .m1_sel (fml_fmlbrg_sel),
+ .m1_di (fml_fmlbrg_do),
+ .m1_do (fml_fmlbrg_di),
+
+ // Master 2 interface - VGA CPU FML
+ .m2_adr ({3'b001, vga_cpu_fml_adr}), // 1 - 2 MB Addressable memory range
+ .m2_stb (vga_cpu_fml_stb),
+ .m2_we (vga_cpu_fml_we),
+ .m2_ack (vga_cpu_fml_ack),
+ .m2_sel (vga_cpu_fml_sel),
+ .m2_di (vga_cpu_fml_do),
+ .m2_do (vga_cpu_fml_di),
+
+ // Master 3 interface - not connected
+ .m3_adr ({3'b010, 20'b0}), // 2 - 3 MB Addressable memory range
+ .m3_stb (1'b0),
+ .m3_we (1'b0),
+ .m3_ack (),
+ .m3_sel (2'b00),
+ .m3_di (16'h0000),
+ .m3_do (),
+
+ // Master 4 interface - not connected
+ .m4_adr ({3'b011, 20'b0}), // 3 - 4 MB Addressable memory range
+ .m4_stb (1'b0),
+ .m4_we (1'b0),
+ .m4_ack (),
+ .m4_sel (2'b00),
+ .m4_di (16'h0000),
+ .m4_do (),
+
+ // Master 5 interface - not connected
+ .m5_adr ({3'b100, 20'b0}), // 4 - 5 MB Addressable memory range
+ .m5_stb (1'b0),
+ .m5_we (1'b0),
+ .m5_ack (),
+ .m5_sel (2'b00),
+ .m5_di (16'h0000),
+ .m5_do (),
+
+ // Arbitrer Slave interface - connected to hpdmc
+ .s_adr (fml_adr),
+ .s_stb (fml_stb),
+ .s_we (fml_we),
+ .s_ack (fml_ack),
+ .s_sel (fml_sel),
+ .s_di (fml_di),
+ .s_do (fml_do)
+ );
+
+ hpdmc #(
+ .csr_addr (1'b0),
+ .sdram_depth (23),
+ .sdram_columndepth (8)
+ ) hpdmc (
+ .sys_clk (sdram_clk),
+ .sys_rst (rst),
+
+ // CSR slave interface
+ .csr_a (csr_a),
+ .csr_we (csr_we),
+ .csr_di (csr_dw),
+ .csr_do (csr_dr_hpdmc),
+
+ // FML slave interface
+ .fml_adr (fml_adr),
+ .fml_stb (fml_stb),
+ .fml_we (fml_we),
+ .fml_ack (fml_ack),
+ .fml_sel (fml_sel),
+ .fml_di (fml_do),
+ .fml_do (fml_di),
+
+ // SDRAM pad signals
+ .sdram_cke (sdram_ce_),
+ .sdram_cs_n (sdram_cs_n_),
+ .sdram_we_n (sdram_we_n_),
+ .sdram_cas_n (sdram_cas_n_),
+ .sdram_ras_n (sdram_ras_n_),
+ .sdram_dqm (sdram_dqm_),
+ .sdram_adr (sdram_addr_),
+ .sdram_ba (sdram_ba_),
+ .sdram_dq (sdram_data_)
+ );
+
+ wb_abrgr vga_brg (
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wbs_clk_i (clk),
+ .wbs_adr_i (vga_adr_i_s),
+ .wbs_dat_i (vga_dat_i_s),
+ .wbs_dat_o (vga_dat_o_s),
+ .wbs_sel_i (vga_sel_i_s),
+ .wbs_tga_i (vga_tga_i_s),
+ .wbs_stb_i (vga_stb_i_s),
+ .wbs_cyc_i (vga_cyc_i_s),
+ .wbs_we_i (vga_we_i_s),
+ .wbs_ack_o (vga_ack_o_s),
+
+ // Wishbone master interface
+ .wbm_clk_i (sdram_clk),
+ .wbm_adr_o (vga_adr_i),
+ .wbm_dat_o (vga_dat_i),
+ .wbm_dat_i (vga_dat_o),
+ .wbm_sel_o (vga_sel_i),
+ .wbm_tga_o (vga_tga_i),
+ .wbm_stb_o (vga_stb_i),
+ .wbm_cyc_o (vga_cyc_i),
+ .wbm_we_o (vga_we_i),
+ .wbm_ack_i (vga_ack_o)
+ );
+
+ vga_fml #(
+ .fml_depth (20) // 1MB Memory Address range
+ ) vga (
+ .wb_rst_i (rst),
+
+ // Wishbone slave interface
+ .wb_clk_i (sdram_clk), // 100MHz VGA clock
+ .wb_dat_i (vga_dat_i),
+ .wb_dat_o (vga_dat_o),
+ .wb_adr_i (vga_adr_i[16:1]), // 128K
+ .wb_we_i (vga_we_i),
+ .wb_tga_i (vga_tga_i),
+ .wb_sel_i (vga_sel_i),
+ .wb_stb_i (vga_stb_i),
+ .wb_cyc_i (vga_cyc_i),
+ .wb_ack_o (vga_ack_o),
+
+ // VGA pad signals
+ .vga_red_o (tft_lcd_r_),
+ .vga_green_o (tft_lcd_g_),
+ .vga_blue_o (tft_lcd_b_),
+ .horiz_sync (tft_lcd_hsync_),
+ .vert_sync (tft_lcd_vsync_),
+
+ // VGA CPU FML master interface
+ .vga_cpu_fml_adr(vga_cpu_fml_adr),
+ .vga_cpu_fml_stb(vga_cpu_fml_stb),
+ .vga_cpu_fml_we(vga_cpu_fml_we),
+ .vga_cpu_fml_ack(vga_cpu_fml_ack),
+ .vga_cpu_fml_sel(vga_cpu_fml_sel),
+ .vga_cpu_fml_do(vga_cpu_fml_do),
+ .vga_cpu_fml_di(vga_cpu_fml_di),
+
+ // VGA LCD FML master interface
+ .vga_lcd_fml_adr(vga_lcd_fml_adr),
+ .vga_lcd_fml_stb(vga_lcd_fml_stb),
+ .vga_lcd_fml_we(vga_lcd_fml_we),
+ .vga_lcd_fml_ack(vga_lcd_fml_ack),
+ .vga_lcd_fml_sel(vga_lcd_fml_sel),
+ .vga_lcd_fml_do(vga_lcd_fml_do),
+ .vga_lcd_fml_di(vga_lcd_fml_di),
+
+ .vga_clk(vga_clk)
+
+ );
+
+ // RS232 COM1 Port
+ serial com1 (
+ .wb_clk_i (clk), // Main Clock
+ .wb_rst_i (rst), // Reset Line
+ .wb_adr_i (uart_adr_i[2:1]), // Address lines
+ .wb_sel_i (uart_sel_i), // Select lines
+ .wb_dat_i (uart_dat_i), // Command to send
+ .wb_dat_o (uart_dat_o),
+ .wb_we_i (uart_we_i), // Write enable
+ .wb_stb_i (uart_stb_i),
+ .wb_cyc_i (uart_cyc_i),
+ .wb_ack_o (uart_ack_o),
+ .wb_tgc_o (intv[4]), // Interrupt request
+
+ .rs232_tx (uart_txd_), // UART signals
+ .rs232_rx (uart_rxd_) // serial input/output
+ );
+
+ ps2 ps2 (
+ .wb_clk_i (clk), // Main Clock
+ .wb_rst_i (rst), // Reset Line
+ .wb_adr_i (keyb_adr_i[2:1]), // Address lines
+ .wb_sel_i (keyb_sel_i), // Select lines
+ .wb_dat_i (keyb_dat_i), // Command to send to Ethernet
+ .wb_dat_o (keyb_dat_o),
+ .wb_we_i (keyb_we_i), // Write enable
+ .wb_stb_i (keyb_stb_i),
+ .wb_cyc_i (keyb_cyc_i),
+ .wb_ack_o (keyb_ack_o),
+ .wb_tgk_o (intv[1]), // Keyboard Interrupt request
+ .wb_tgm_o (intv[3]), // Mouse Interrupt request
+
+ .ps2_kbd_clk_ (ps2_kclk_),
+ .ps2_kbd_dat_ (ps2_kdat_),
+ .ps2_mse_clk_ (ps2_mclk_),
+ .ps2_mse_dat_ (ps2_mdat_)
+ );
+
+`ifndef SIMULATION
+ /*
+ * Seems that we have a serious bug in Modelsim that prevents
+ * from simulating when this core is present
+ */
+ speaker speaker (
+ .clk (clk),
+ .rst (rst),
+
+ .wb_dat_i (keyb_dat_i[15:8]),
+ .wb_dat_o (aud_dat_o),
+ .wb_we_i (keyb_we_i),
+ .wb_stb_i (keyb_stb_i),
+ .wb_cyc_i (aud_cyc_i),
+ .wb_ack_o (aud_ack_o),
+
+ .clk_100M (sdram_clk),
+ .clk_25M (vga_clk),
+ .timer2 (timer2_o),
+
+ .i2c_sclk_ (i2c_sclk_),
+ .i2c_sdat_ (i2c_sdat_),
+
+ .aud_adcdat_ (aud_adcdat_),
+ .aud_daclrck_ (aud_daclrck_),
+ .aud_dacdat_ (aud_dacdat_),
+ .aud_bclk_ (aud_bclk_)
+ );
+`else
+ assign aud_dat_o = 16'h0;
+ assign aud_ack_o = keyb_stb_i & aud_cyc_i;
+`endif
+
+ // Selection logic between keyboard and audio ports (port 65h: audio)
+ assign aud_sel_cond = keyb_adr_i[2:1]==2'b00 && keyb_sel_i[1];
+ assign aud_cyc_i = kaud_cyc_i && aud_sel_cond;
+ assign keyb_cyc_i = kaud_cyc_i && !aud_sel_cond;
+ assign kaud_ack_o = aud_cyc_i & aud_ack_o | keyb_cyc_i & keyb_ack_o;
+ assign kaud_dat_o = {8{aud_cyc_i}} & aud_dat_o
+ | {8{keyb_cyc_i}} & keyb_dat_o[15:8];
+
+ timer timer (
+ .wb_clk_i (clk),
+ .wb_rst_i (rst),
+ .wb_adr_i (timer_adr_i[1]),
+ .wb_sel_i (timer_sel_i),
+ .wb_dat_i (timer_dat_i),
+ .wb_dat_o (timer_dat_o),
+ .wb_stb_i (timer_stb_i),
+ .wb_cyc_i (timer_cyc_i),
+ .wb_we_i (timer_we_i),
+ .wb_ack_o (timer_ack_o),
+ .wb_tgc_o (intv[0]),
+ .tclk_i (timer_clk), // 1.193182 MHz = (14.31818/12) MHz
+ .gate2_i (aud_dat_o[0]),
+ .out2_o (timer2_o)
+ );
+
+ simple_pic pic0 (
+ .clk (clk),
+ .rst (rst),
+ .intv (intv),
+ .inta (inta),
+ .intr (intr),
+ .iid (iid)
+ );
+
+ wb_abrgr sd_brg (
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wbs_clk_i (clk),
+ .wbs_adr_i (sd_adr_i_s),
+ .wbs_dat_i (sd_dat_i_s),
+ .wbs_dat_o (sd_dat_o_s),
+ .wbs_sel_i (sd_sel_i_s),
+ .wbs_tga_i (sd_tga_i_s),
+ .wbs_stb_i (sd_stb_i_s),
+ .wbs_cyc_i (sd_cyc_i_s),
+ .wbs_we_i (sd_we_i_s),
+ .wbs_ack_o (sd_ack_o_s),
+
+ // Wishbone master interface
+ .wbm_clk_i (sdram_clk),
+ .wbm_adr_o (sd_adr_i),
+ .wbm_dat_o (sd_dat_i),
+ .wbm_dat_i ({8'h0,sd_dat_o}),
+ .wbm_tga_o (sd_tga_i),
+ .wbm_sel_o (sd_sel_i),
+ .wbm_stb_o (sd_stb_i),
+ .wbm_cyc_o (sd_cyc_i),
+ .wbm_we_o (sd_we_i),
+ .wbm_ack_i (sd_ack_o)
+ );
+
+ sdspi sdspi (
+ // Serial pad signal
+ .sclk (sd_sclk_),
+ .miso (sd_miso_),
+ .mosi (sd_mosi_),
+ .ss (sd_ss_),
+
+ // Wishbone slave interface
+ .wb_clk_i (sdram_clk),
+ .wb_rst_i (rst),
+ .wb_dat_i (sd_dat_i[8:0]),
+ .wb_dat_o (sd_dat_o),
+ .wb_we_i (sd_we_i),
+ .wb_sel_i (sd_sel_i),
+ .wb_stb_i (sd_stb_i),
+ .wb_cyc_i (sd_cyc_i),
+ .wb_ack_o (sd_ack_o)
+ );
+
+ // Switches and leds
+ sw_leds sw_leds (
+ .wb_clk_i (clk),
+ .wb_rst_i (rst),
+
+ // Wishbone slave interface
+ .wb_adr_i (gpio_adr_i[1]),
+ .wb_dat_o (gpio_dat_o),
+ .wb_dat_i (gpio_dat_i),
+ .wb_sel_i (gpio_sel_i),
+ .wb_we_i (gpio_we_i),
+ .wb_stb_i (gpio_stb_i),
+ .wb_cyc_i (gpio_cyc_i),
+ .wb_ack_o (gpio_ack_o),
+
+ // GPIO inputs/outputs
+ .leds_ ({ledr_,ledg_[7:4]}),
+ .sw_ (sw_),
+ .pb_ (key_),
+ .tick (intv[0]),
+ .nmi_pb (nmi_pb) // NMI from pushbutton
+ );
+
+ hex_display hex16 (
+ .num (pc[19:4]),
+ .en (1'b1),
+
+ .hex0 (hex0_),
+ .hex1 (hex1_),
+ .hex2 (hex2_),
+ .hex3 (hex3_)
+ );
+
+ zet zet (
+ .pc (pc),
+
+ // Wishbone master interface
+ .wb_clk_i (clk),
+ .wb_rst_i (rst),
+ .wb_dat_i (dat_i),
+ .wb_dat_o (dat_o),
+ .wb_adr_o (adr),
+ .wb_we_o (we),
+ .wb_tga_o (tga),
+ .wb_sel_o (sel),
+ .wb_stb_o (stb),
+ .wb_cyc_o (cyc),
+ .wb_ack_i (ack),
+ .wb_tgc_i (intr),
+ .wb_tgc_o (inta),
+ .nmi (nmi),
+ .nmia (nmia)
+ );
+
+ wb_switch #(
+ .s0_addr_1 (20'b0_1111_1111_1111_0000_000), // bios boot mem 0xfff00 - 0xfffff
+ .s0_mask_1 (20'b1_1111_1111_1111_0000_000), // bios boot ROM Memory
+
+ .s1_addr_1 (20'b0_1010_0000_0000_0000_000), // mem 0xa0000 - 0xbffff
+ .s1_mask_1 (20'b1_1110_0000_0000_0000_000), // VGA
+
+ .s1_addr_2 (20'b1_0000_0000_0011_1100_000), // io 0x3c0 - 0x3df
+ .s1_mask_2 (20'b1_0000_1111_1111_1110_000), // VGA IO
+
+ .s2_addr_1 (20'b1_0000_0000_0011_1111_100), // io 0x3f8 - 0x3ff
+ .s2_mask_1 (20'b1_0000_1111_1111_1111_100), // RS232 IO
+
+ .s3_addr_1 (20'b1_0000_0000_0000_0110_000), // io 0x60, 0x64
+ .s3_mask_1 (20'b1_0000_1111_1111_1111_101), // Keyboard / Mouse IO
+
+ .s4_addr_1 (20'b1_0000_0000_0001_0000_000), // io 0x100 - 0x101
+ .s4_mask_1 (20'b1_0000_1111_1111_1111_111), // SD Card IO
+
+ .s5_addr_1 (20'b1_0000_1111_0001_0000_000), // io 0xf100 - 0xf103
+ .s5_mask_1 (20'b1_0000_1111_1111_1111_110), // GPIO
+
+ .s6_addr_1 (20'b1_0000_1111_0010_0000_000), // io 0xf200 - 0xf20f
+ .s6_mask_1 (20'b1_0000_1111_1111_1111_000), // CSR Bridge SDRAM Control
+
+ .s7_addr_1 (20'b1_0000_0000_0000_0100_000), // io 0x40 - 0x43
+ .s7_mask_1 (20'b1_0000_1111_1111_1111_110), // Timer control port
+
+ .s8_addr_1 (20'b1_0000_0000_0010_0011_100), // io 0x0238 - 0x023b
+ .s8_mask_1 (20'b1_0000_1111_1111_1111_110), // Flash IO port
+
+ .s9_addr_1 (20'b1_0000_0000_0010_0001_000), // io 0x0210 - 0x021F
+ .s9_mask_1 (20'b1_0000_1111_1111_1111_000), // Sound Blaster
+
+ .sA_addr_1 (20'b1_0000_1111_0011_0000_000), // io 0xf300 - 0xf3ff
+ .sA_mask_1 (20'b1_0000_1111_1111_0000_000), // SDRAM Control
+ .sA_addr_2 (20'b0_0000_0000_0000_0000_000), // mem 0x00000 - 0xfffff
+ .sA_mask_2 (20'b1_0000_0000_0000_0000_000) // Base RAM
+
+ ) wbs (
+
+ // Master interface
+ .m_dat_i (dat_o),
+ .m_dat_o (sw_dat_o),
+ .m_adr_i ({tga,adr}),
+ .m_sel_i (sel),
+ .m_we_i (we),
+ .m_cyc_i (cyc),
+ .m_stb_i (stb),
+ .m_ack_o (ack),
+
+ // Slave 0 interface - bios rom
+ .s0_dat_i (rom_dat_o),
+ .s0_dat_o (rom_dat_i),
+ .s0_adr_o ({rom_tga_i,rom_adr_i}),
+ .s0_sel_o (rom_sel_i),
+ .s0_we_o (rom_we_i),
+ .s0_cyc_o (rom_cyc_i),
+ .s0_stb_o (rom_stb_i),
+ .s0_ack_i (rom_ack_o),
+
+ // Slave 1 interface - vga
+ .s1_dat_i (vga_dat_o_s),
+ .s1_dat_o (vga_dat_i_s),
+ .s1_adr_o ({vga_tga_i_s,vga_adr_i_s}),
+ .s1_sel_o (vga_sel_i_s),
+ .s1_we_o (vga_we_i_s),
+ .s1_cyc_o (vga_cyc_i_s),
+ .s1_stb_o (vga_stb_i_s),
+ .s1_ack_i (vga_ack_o_s),
+
+ // Slave 2 interface - uart
+ .s2_dat_i (uart_dat_o),
+ .s2_dat_o (uart_dat_i),
+ .s2_adr_o ({uart_tga_i,uart_adr_i}),
+ .s2_sel_o (uart_sel_i),
+ .s2_we_o (uart_we_i),
+ .s2_cyc_o (uart_cyc_i),
+ .s2_stb_o (uart_stb_i),
+ .s2_ack_i (uart_ack_o),
+
+ // Slave 3 interface - keyb
+ .s3_dat_i ({kaud_dat_o,keyb_dat_o[7:0]}),
+ .s3_dat_o (keyb_dat_i),
+ .s3_adr_o ({keyb_tga_i,keyb_adr_i}),
+ .s3_sel_o (keyb_sel_i),
+ .s3_we_o (keyb_we_i),
+ .s3_cyc_o (kaud_cyc_i),
+ .s3_stb_o (keyb_stb_i),
+ .s3_ack_i (kaud_ack_o),
+
+ // Slave 4 interface - sd
+ .s4_dat_i (sd_dat_o_s),
+ .s4_dat_o (sd_dat_i_s),
+ .s4_adr_o ({sd_tga_i_s,sd_adr_i_s}),
+ .s4_sel_o (sd_sel_i_s),
+ .s4_we_o (sd_we_i_s),
+ .s4_cyc_o (sd_cyc_i_s),
+ .s4_stb_o (sd_stb_i_s),
+ .s4_ack_i (sd_ack_o_s),
+
+ // Slave 5 interface - gpio
+ .s5_dat_i (gpio_dat_o),
+ .s5_dat_o (gpio_dat_i),
+ .s5_adr_o ({gpio_tga_i,gpio_adr_i}),
+ .s5_sel_o (gpio_sel_i),
+ .s5_we_o (gpio_we_i),
+ .s5_cyc_o (gpio_cyc_i),
+ .s5_stb_o (gpio_stb_i),
+ .s5_ack_i (gpio_ack_o),
+
+ // Slave 6 interface - csr bridge
+ .s6_dat_i (csrbrg_dat_r_s),
+ .s6_dat_o (csrbrg_dat_w_s),
+ .s6_adr_o ({csrbrg_tga_s,csrbrg_adr_s}),
+ .s6_sel_o (csrbrg_sel_s),
+ .s6_we_o (csrbrg_we_s),
+ .s6_cyc_o (csrbrg_cyc_s),
+ .s6_stb_o (csrbrg_stb_s),
+ .s6_ack_i (csrbrg_ack_s),
+
+ // Slave 7 interface - timer
+ .s7_dat_i (timer_dat_o),
+ .s7_dat_o (timer_dat_i),
+ .s7_adr_o ({timer_tga_i,timer_adr_i}),
+ .s7_sel_o (timer_sel_i),
+ .s7_we_o (timer_we_i),
+ .s7_cyc_o (timer_cyc_i),
+ .s7_stb_o (timer_stb_i),
+ .s7_ack_i (timer_ack_o),
+
+ // Slave 8 interface - flash
+ .s8_dat_i (fl_dat_o),
+ .s8_dat_o (fl_dat_i),
+ .s8_adr_o ({fl_tga_i,fl_adr_i}),
+ .s8_sel_o (fl_sel_i),
+ .s8_we_o (fl_we_i),
+ .s8_cyc_o (fl_cyc_i),
+ .s8_stb_o (fl_stb_i),
+ .s8_ack_i (fl_ack_o),
+
+ // Slave 9 interface - not connected
+ .s9_dat_i (),
+ .s9_dat_o (),
+ .s9_adr_o (),
+ .s9_sel_o (),
+ .s9_we_o (),
+ .s9_cyc_o (sb_cyc_i),
+ .s9_stb_o (sb_stb_i),
+ .s9_ack_i (sb_cyc_i && sb_stb_i),
+
+ // Slave A interface - sdram
+ .sA_dat_i (fmlbrg_dat_r_s),
+ .sA_dat_o (fmlbrg_dat_w_s),
+ .sA_adr_o ({fmlbrg_tga_s,fmlbrg_adr_s}),
+ .sA_sel_o (fmlbrg_sel_s),
+ .sA_we_o (fmlbrg_we_s),
+ .sA_cyc_o (fmlbrg_cyc_s),
+ .sA_stb_o (fmlbrg_stb_s),
+ .sA_ack_i (fmlbrg_ack_s),
+
+ // Slave B interface - default
+ .sB_dat_i (16'h0000),
+ .sB_dat_o (),
+ .sB_adr_o (),
+ .sB_sel_o (),
+ .sB_we_o (),
+ .sB_cyc_o (def_cyc_i),
+ .sB_stb_o (def_stb_i),
+ .sB_ack_i (def_cyc_i & def_stb_i)
+ );
+
+ // Continuous assignments
+ assign rst_lck = !sw_[0] & lock;
+
+ assign nmi = nmi_pb;
+ assign dat_i = nmia ? 16'h0002 :
+ (inta ? { 13'b0000_0000_0000_1, iid } :
+ sw_dat_o);
+
+ assign sdram_clk_ = sdram_clk;
+
+ assign ledg_[3:0] = pc[3:0];
+
+endmodule
+"
+"/*
+ * Milkymist SoC
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+`timescale 1ns / 1ps
+
+`define ENABLE_VCD
+
+module tb_fmlbrg();
+
+reg clk;
+initial clk = 1\'b0;
+always #5 clk = ~clk;
+
+reg rst;
+
+reg [19:1] wb_adr_i;
+reg [2:0] wb_cti_i;
+reg [15:0] wb_dat_i;
+wire [15:0] wb_dat_o;
+reg [1:0] wb_sel_i;
+reg wb_cyc_i;
+reg wb_stb_i;
+reg wb_we_i;
+wire wb_ack_o;
+
+wire [19:0] fml_adr;
+wire fml_stb;
+wire fml_we;
+reg fml_ack;
+wire [1:0] fml_sel;
+wire [15:0] fml_dw;
+reg [15:0] fml_dr;
+
+reg dcb_stb;
+reg [19:0] dcb_adr;
+wire [15:0] dcb_dat;
+wire dcb_hit;
+
+/* Process FML requests */
+reg [2:0] fml_wcount;
+reg [2:0] fml_rcount;
+initial begin
+\tfml_ack = 1\'b0;
+\tfml_wcount = 0;
+\tfml_rcount = 0;
+end
+
+always @(posedge clk) begin
+\tif(fml_stb & (fml_wcount == 0) & (fml_rcount == 0)) begin
+\t\tfml_ack <= 1\'b1;
+\t\tif(fml_we) begin
+\t\t\t$display(""%t FML W addr %x data %x"", $time, fml_adr, fml_dw);
+\t\t\tfml_wcount <= 7;
+\t\tend else begin
+\t\t\tfml_dr = 16\'hbeef;
+\t\t\t$display(""%t FML R addr %x data %x"", $time, fml_adr, fml_dr);
+\t\t\tfml_rcount <= 7;
+\t\tend
+\tend else
+\t\tfml_ack <= 1\'b0;
+\tif(fml_wcount != 0) begin
+\t\t#1 $display(""%t FML W continuing %x / %d"", $time, fml_dw, fml_wcount);
+\t\tfml_wcount <= fml_wcount - 1;
+\tend
+\tif(fml_rcount != 0) begin
+\t\tfml_dr = #1 {13\'h1eba, fml_rcount};
+\t\t$display(""%t FML R continuing %x / %d"", $time, fml_dr, fml_rcount);
+\t\tfml_rcount <= fml_rcount - 1;
+\tend
+end
+
+fmlbrg #(
+ .fml_depth (20), // 8086 can only address 1 MB
+ .cache_depth (10) // 1 Kbyte cache
+ ) dut (
+\t.sys_clk(clk),
+\t.sys_rst(rst),
+\t
+\t.wb_adr_i(wb_adr_i),
+\t.wb_cti_i(wb_cti_i),
+\t.wb_dat_i(wb_dat_i),
+\t.wb_dat_o(wb_dat_o),
+\t.wb_sel_i(wb_sel_i),
+\t.wb_cyc_i(wb_cyc_i),
+\t.wb_stb_i(wb_stb_i),
+\t.wb_we_i(wb_we_i),
+\t.wb_ack_o(wb_ack_o),
+\t
+\t.fml_adr(fml_adr),
+\t.fml_stb(fml_stb),
+\t.fml_we(fml_we),
+\t.fml_ack(fml_ack),
+\t.fml_sel(fml_sel),
+\t.fml_do(fml_dw),
+\t.fml_di(fml_dr),
+
+\t.dcb_stb(dcb_stb),
+\t.dcb_adr(dcb_adr),
+\t.dcb_dat(dcb_dat),
+\t.dcb_hit(dcb_hit)
+\t
+);
+
+task waitclock;
+begin
+\t@(posedge clk);
+\t#1;
+end
+endtask
+
+task wbwrite;
+input [19:1] address;
+input [1:0] sel;
+input [15:0] data;
+integer i;
+begin
+\twb_adr_i = address;
+\twb_cti_i = 3\'b000;
+\twb_dat_i = data;
+\twb_sel_i = sel;
+\twb_cyc_i = 1\'b1;
+\twb_stb_i = 1\'b1;
+\twb_we_i = 1\'b1;
+\ti = 0;
+\twhile(~wb_ack_o) begin
+\t\ti = i+1;
+\t\twaitclock;
+\tend
+\twaitclock;
+\t$display(""WB Write: %x=%x sel=%b acked in %d clocks"", address, data, sel, i);
+\twb_adr_i = 19\'hx;
+\twb_cyc_i = 1\'b0;
+\twb_stb_i = 1\'b0;
+\twb_we_i = 1\'b0;
+end
+endtask
+
+task wbread;
+input [19:1] address;
+integer i;
+begin
+\twb_adr_i = address;\t
+\twb_cti_i = 3\'b000;
+\twb_cyc_i = 1\'b1;
+\twb_stb_i = 1\'b1;
+\twb_we_i = 1\'b0;
+\ti = 0;
+\twhile(~wb_ack_o) begin
+\t\ti = i+1;
+\t\twaitclock;
+\tend
+\t$display(""WB Read : %x=%x acked in %d clocks"", address, wb_dat_o, i);
+\twaitclock;
+\twb_adr_i = 19\'hx;
+\twb_cyc_i = 1\'b0;
+\twb_stb_i = 1\'b0;
+\twb_we_i = 1\'b0;
+end
+endtask
+
+task wbwriteburst;
+input [19:1] address;
+input [15:0] data;
+integer i;
+begin
+\twb_adr_i = address;
+\twb_cti_i = 3\'b010;
+\twb_dat_i = data;
+\twb_sel_i = 2\'b11;
+\twb_cyc_i = 1\'b1;
+\twb_stb_i = 1\'b1;
+\twb_we_i = 1\'b1;
+\ti = 0;
+\twhile(~wb_ack_o) begin
+\t\ti = i+1;
+\t\twaitclock;
+\tend
+\twaitclock;
+\t$display(""WB Write: %x=%x acked in %d clocks"", address, data, i);
+\twb_dat_i = data+1;
+\twaitclock;
+\twb_dat_i = data+2;
+\twaitclock;
+\twb_dat_i = data+3;
+\twb_cti_i = 3\'b111;
+\twaitclock;
+\twb_adr_i = 19\'hx;
+\twb_cti_i = 3\'b000;
+\twb_cyc_i = 1\'b0;
+\twb_stb_i = 1\'b0;
+\twb_we_i = 1\'b0;
+end
+endtask
+
+task wbreadburst;
+input [19:1] address;
+integer i;
+begin
+\twb_adr_i = address;
+\twb_cti_i = 3\'b010;
+\twb_cyc_i = 1\'b1;
+\twb_stb_i = 1\'b1;
+\twb_we_i = 1\'b0;
+\ti = 0;
+\twhile(~wb_ack_o) begin
+\t\ti = i+1;
+\t\twaitclock;
+\tend
+\t$display(""WB Read : %x=%x acked in %d clocks"", address, wb_dat_o, i);
+\twaitclock;
+\t$display(""read burst(1): %x"", wb_dat_o);
+\twaitclock;
+\t$display(""read burst(2): %x"", wb_dat_o);
+\twaitclock;
+\twb_cti_i = 3\'b111;
+\t$display(""read burst(3): %x"", wb_dat_o);
+\twaitclock;
+\twb_adr_i = 19\'hx;
+\twb_cti_i = 3\'b000;
+\twb_cyc_i = 1\'b0;
+\twb_stb_i = 1\'b0;
+\twb_we_i = 1\'b0;
+end
+endtask
+
+always begin
+`ifdef ENABLE_VCD
+\t$dumpfile(""fmlbrg.vcd"");
+\t$dumpvars(0, dut);
+`endif
+\trst = 1\'b1;
+\t
+\twb_adr_i = 19\'d0;
+\twb_dat_i = 16\'d0;
+\twb_cyc_i = 1\'b0;
+\twb_stb_i = 1\'b0;
+\twb_we_i = 1\'b0;
+
+\tdcb_stb = 1\'b0;
+\tdcb_adr = 20\'d0;
+\t
+\twaitclock;
+\t
+\trst = 1\'b0;
+\t
+\twaitclock;
+\t
+\t$display(""Testing: read miss"");
+\twbread(19\'h0);
+\t$display(""Testing: write hit"");
+\twbwrite(19\'h0, 2\'b11, 16\'h5678);
+\twbread(19\'h0);
+\t$display(""Testing: read miss on a dirty line"");
+\twbread(19\'h01000);
+\t
+\t$display(""Testing: read hit"");
+\twbread(19\'h01004);
+\t
+\t$display(""Testing: write miss"");
+\twbwrite(19\'h0, 2\'b11, 16\'hface);
+\twbread(27\'h0);
+\twbread(27\'h4);
+\t
+\t$display(""Testing: read burst"");
+\twbreadburst(19\'h40);
+\t
+\t$display(""Testing: write burst"");
+\twbwriteburst(19\'h40, 16\'hcaf0);
+\t
+\t$display(""Testing: read burst"");
+\twbreadburst(19\'h40);
+
+\t$display(""Testing: DCB miss"");
+\tdcb_adr = 20\'hfeba;
+\tdcb_stb = 1\'b1;
+\twaitclock;
+\t$display(""Result: hit=%b dat=%x"", dcb_hit, dcb_dat);
+
+\t$display(""Testing: DCB hit"");
+\tdcb_adr = 20\'h0;
+\tdcb_stb = 1\'b1;
+\twaitclock;
+\t$display(""Result: hit=%b dat=%x"", dcb_hit, dcb_dat);
+\t
+\t$display(""Testing: DCB hit"");
+\tdcb_adr = 20\'h0;
+\tdcb_stb = 1\'b1;
+\twaitclock;
+\t$display(""Result: hit=%b dat=%x"", dcb_hit, dcb_dat);
+\t
+\t$display(""Testing: DCB hit"");
+\tdcb_adr = 20\'h1;
+\tdcb_stb = 1\'b1;
+\twaitclock;
+\t$display(""Result: hit=%b dat=%x"", dcb_hit, dcb_dat);
+\t
+\t$display(""Testing: DCB hit"");
+\tdcb_adr = 20\'h2;
+\tdcb_stb = 1\'b1;
+\twaitclock;
+\t$display(""Result: hit=%b dat=%x"", dcb_hit, dcb_dat);
+\t
+\t$stop;
+end
+
+
+endmodule
+"
+"/*\r
+ * CRTC controller for VGA\r
+ * Copyright (C) 2010 Zeus Gomez Marmolejo \r
+ *\r
+ * VGA FML support\r
+ * Copyright (C) 2013 Charley Picker \r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+module vga_crtc_fml (\r
+ input clk, // 100 Mhz clock\r
+ input rst,\r
+\r
+ input enable_crtc,\r
+\r
+ // CRTC configuration signals\r
+\r
+ input [5:0] cur_start,\r
+ input [5:0] cur_end,\r
+ input [4:0] vcursor,\r
+ input [6:0] hcursor,\r
+\r
+ input [6:0] horiz_total,\r
+ input [6:0] end_horiz,\r
+ input [6:0] st_hor_retr,\r
+ input [4:0] end_hor_retr,\r
+ input [9:0] vert_total,\r
+ input [9:0] end_vert,\r
+ input [9:0] st_ver_retr,\r
+ input [3:0] end_ver_retr,\r
+\r
+ // CRTC output signals\r
+\r
+ output reg [9:0] h_count, // Horizontal pipeline delay is 2 cycles\r
+ output reg horiz_sync_i,\r
+\r
+ output reg [9:0] v_count, // 0 to VER_SCAN_END\r
+ output reg vert_sync,\r
+\r
+ output reg video_on_h_i,\r
+ output reg video_on_v\r
+\r
+ );\r
+\r
+ // Registers and nets\r
+ wire [9:0] hor_disp_end;\r
+ wire [9:0] hor_scan_end;\r
+ wire [9:0] ver_disp_end;\r
+ wire [9:0] ver_sync_beg;\r
+ wire [3:0] ver_sync_end;\r
+ wire [9:0] ver_scan_end;\r
+\r
+ // Continuous assignments\r
+ assign hor_scan_end = { horiz_total[6:2] + 1'b1, horiz_total[1:0], 3'h7 };\r
+ assign hor_disp_end = { end_horiz, 3'h7 };\r
+ assign ver_scan_end = vert_total + 10'd1;\r
+ assign ver_disp_end = end_vert + 10'd1;\r
+ assign ver_sync_beg = st_ver_retr;\r
+ assign ver_sync_end = end_ver_retr + 4'd1;\r
+\r
+ // Sync generation & timing process\r
+ // Generate horizontal and vertical timing signals for video signal\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ h_count <= 10'b0;\r
+ horiz_sync_i <= 1'b1;\r
+ v_count <= 10'b0;\r
+ vert_sync <= 1'b1;\r
+ video_on_h_i <= 1'b1;\r
+ video_on_v <= 1'b1;\r
+ end\r
+ else\r
+ if (enable_crtc)\r
+ begin\r
+ h_count <= (h_count==hor_scan_end) ? 10'b0 : h_count + 10'b1;\r
+ horiz_sync_i <= horiz_sync_i ? (h_count[9:3]!=st_hor_retr)\r
+ : (h_count[7:3]==end_hor_retr);\r
+ v_count <= (v_count==ver_scan_end && h_count==hor_scan_end) ? 10'b0\r
+ : ((h_count==hor_scan_end) ? v_count + 10'b1 : v_count);\r
+ vert_sync <= vert_sync ? (v_count!=ver_sync_beg)\r
+ : (v_count[3:0]==ver_sync_end);\r
+\r
+ video_on_h_i <= (h_count==hor_scan_end) ? 1'b1\r
+ : ((h_count==hor_disp_end) ? 1'b0 : video_on_h_i);\r
+ video_on_v <= (v_count==10'h0) ? 1'b1\r
+ : ((v_count==ver_disp_end) ? 1'b0 : video_on_v);\r
+ end\r
+\r
+endmodule\r
+"
+"/*\r
+ * Linear mode graphics for VGA\r
+ * Copyright (C) 2010 Zeus Gomez Marmolejo \r
+ *\r
+ * VGA FML support\r
+ * Copyright (C) 2013 Charley Picker \r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+module vga_linear_fml (\r
+ input clk,\r
+ input rst,\r
+ \r
+ input enable,\r
+\r
+ // CSR slave interface for reading\r
+ output [17:1] fml_adr_o,\r
+ input [15:0] fml_dat_i,\r
+ output fml_stb_o,\r
+\r
+ input [9:0] h_count,\r
+ input [9:0] v_count,\r
+ input horiz_sync_i,\r
+ input video_on_h_i,\r
+ output video_on_h_o,\r
+\r
+ output [7:0] color,\r
+ output horiz_sync_o\r
+ );\r
+\r
+ // Registers\r
+ reg [ 9:0] row_addr;\r
+ reg [ 6:0] col_addr;\r
+ reg [14:1] word_offset;\r
+ reg [ 1:0] plane_addr;\r
+ reg [ 1:0] plane_addr0;\r
+ reg [ 7:0] color_l;\r
+ \r
+ reg [ 15:0] fml1_dat;\r
+ reg [ 15:0] fml2_dat;\r
+ reg [ 15:0] fml3_dat;\r
+ reg [ 15:0] fml4_dat;\r
+ reg [ 15:0] fml5_dat;\r
+ reg [ 15:0] fml6_dat;\r
+ reg [ 15:0] fml7_dat;\r
+ \r
+ reg [4:0] video_on_h;\r
+ reg [4:0] horiz_sync;\r
+ reg [18:0] pipe; \r
+\r
+ // Continous assignments \r
+ assign fml_adr_o = { 1'b0, word_offset, plane_addr };\r
+ assign fml_stb_o = pipe[1];\r
+ \r
+ assign color = pipe[4] ? fml_dat_i[7:0] : color_l; \r
+ \r
+ assign video_on_h_o = video_on_h[4];\r
+ assign horiz_sync_o = horiz_sync[4];\r
+\r
+ // Behaviour\r
+ // FML 8x16 pipeline count\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ pipe <= 18'b0; \r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ pipe <= { pipe[17:0], (h_count[3:0]==4'h0) };\r
+ end\r
+\r
+ // Load FML 8x16 burst\r
+ always @(posedge clk)\r
+ if (enable)\r
+ begin\r
+ fml1_dat <= pipe[5] ? fml_dat_i[15:0] : fml1_dat;\r
+ fml2_dat <= pipe[6] ? fml_dat_i[15:0] : fml2_dat;\r
+ fml3_dat <= pipe[7] ? fml_dat_i[15:0] : fml3_dat;\r
+ fml4_dat <= pipe[8] ? fml_dat_i[15:0] : fml4_dat;\r
+ fml5_dat <= pipe[9] ? fml_dat_i[15:0] : fml5_dat;\r
+ fml6_dat <= pipe[10] ? fml_dat_i[15:0] : fml6_dat;\r
+ fml7_dat <= pipe[11] ? fml_dat_i[15:0] : fml7_dat;\r
+ end\r
+\r
+ // video_on_h\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ video_on_h <= 5'b0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ video_on_h <= { video_on_h[3:0], video_on_h_i };\r
+ end\r
+\r
+ // horiz_sync\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ horiz_sync <= 5'b0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ horiz_sync <= { horiz_sync[3:0], horiz_sync_i };\r
+ end\r
+\r
+ // Address generation\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ row_addr <= 10'h0;\r
+ col_addr <= 7'h0;\r
+ plane_addr0 <= 2'b00;\r
+ word_offset <= 14'h0;\r
+ plane_addr <= 2'b00;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ // Loading new row_addr and col_addr when h_count[3:0]==4'h0\r
+ // v_count * 5 * 32\r
+ row_addr <= { v_count[8:1], 2'b00 } + v_count[8:1];\r
+ col_addr <= h_count[9:3];\r
+ plane_addr0 <= h_count[2:1];\r
+\r
+ word_offset <= { row_addr + col_addr[6:4], col_addr[3:0] };\r
+ plane_addr <= plane_addr0;\r
+ end\r
+ \r
+ // color_l\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ color_l <= 8'h0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ if (pipe[4])\r
+ color_l <= fml_dat_i[7:0];\r
+ else\r
+ if (pipe[5])\r
+ color_l <= fml_dat_i[7:0];\r
+ else\r
+ if (pipe[7])\r
+ color_l <= fml2_dat[7:0];\r
+ else\r
+ if (pipe[9])\r
+ color_l <= fml3_dat[7:0];\r
+ else\r
+ if (pipe[11])\r
+ color_l <= fml4_dat[7:0];\r
+ else\r
+ if (pipe[13])\r
+ color_l <= fml5_dat[7:0];\r
+ else\r
+ if (pipe[15])\r
+ color_l <= fml6_dat[7:0];\r
+ else\r
+ if (pipe[17])\r
+ color_l <= fml7_dat[7:0];\r
+ end\r
+\r
+endmodule\r
+"
+"/*
+ * Next state calculation for fetch FSM
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_nstate (
+ input [2:0] state,
+ input prefix,
+ input need_modrm,
+ input need_off,
+ input need_imm,
+ input end_seq,
+ input [5:0] ftype,
+ input of,
+ input next_in_opco,
+ input next_in_exec,
+ input block,
+ input div_exc,
+ input tflm,
+ input intr,
+ input iflm,
+ input nmir,
+ input iflss,
+ output [2:0] next_state
+ );
+
+ // Net declarations
+ parameter opcod_st = 3'h0;
+ parameter modrm_st = 3'h1;
+ parameter offse_st = 3'h2;
+ parameter immed_st = 3'h3;
+ parameter execu_st = 3'h4;
+ wire into, end_instr, end_into;
+ wire [2:0] n_state;
+ wire intr_iflm;
+ wire intrs_tni;
+
+ // Assignments
+ assign into = (ftype==6'b111_010);
+ assign end_into = into ? ~of : end_seq;
+ assign end_instr = !div_exc && !intrs_tni && end_into && !next_in_exec;
+ assign intr_iflm = intr & iflm;
+ assign intrs_tni = (tflm | nmir | intr_iflm) & iflss;
+
+ assign n_state = (state == opcod_st) ? (prefix ? opcod_st
+ : (next_in_opco ? opcod_st
+ : (need_modrm ? modrm_st
+ : (need_off ? offse_st
+ : (need_imm ? immed_st : execu_st)))))
+ : (state == modrm_st) ? (need_off ? offse_st
+ : (need_imm ? immed_st : execu_st))
+ : (state == offse_st) ? (need_imm ? immed_st : execu_st)
+ : (state == immed_st) ? (execu_st)
+ /* state == execu_st */ : (end_instr ? opcod_st : execu_st);
+
+ assign next_state = block ? state : n_state;
+endmodule
+"
+"// IS61LV25616 Asynchronous SRAM, 256K x 16 = 4M; speed: 10ns.
+// Note; 1) Please include ""+define+ OEb"" in running script if you want to check
+// timing in the case of OE_ being set.
+// 2) Please specify access time by defining tAC_10 or tAC_12.
+
+`define OEb
+`define tAC_10 //tAC_10 or tAC_12 defines different parameters
+`timescale 1ns/1ns
+
+module is61lv25616 (A, IO, CE_, OE_, WE_, LB_, UB_);
+
+parameter dqbits = 16;
+parameter memdepth = 262143;
+parameter addbits = 18;
+parameter Toha = 2;
+
+parameter Tsa = 2;
+
+`ifdef tAC_10 //if ""`define tAC_10 "" at beginning,sentences below are compiled
+ parameter Taa = 10,
+ Thzce = 3,
+ Thzwe = 5;
+`endif
+
+`ifdef tAC_12 //if ""`define tAC_12 "" at beginning,sentences below are compiled
+ parameter Taa = 12,
+ Thzce = 5,
+ Thzwe = 6;
+`endif
+
+input CE_, OE_, WE_, LB_, UB_;
+input [(addbits - 1) : 0] A;
+inout [(dqbits - 1) : 0] IO;
+
+wire [(dqbits - 1) : 0] dout;
+reg [(dqbits/2 - 1) : 0] bank0 [0 : memdepth];
+reg [(dqbits/2 - 1) : 0] bank1 [0 : memdepth];
+//array to simulate SRAM
+// wire [(dqbits - 1) : 0] memprobe = {bank1[A], bank0[A]};
+
+wire r_en = WE_ & (~CE_) & (~OE_); //WE=1,CE=OE=0 Read
+wire w_en = (~WE_) & (~CE_) & ((~LB_) | (~UB_)); //WE=CE=0,LB or UB=""0"",OE=x Write
+assign #(r_en ? Taa : Thzce) IO = r_en ? dout : 16\'bz;
+
+initial
+ $timeformat (-9, 0.1, "" ns"", 10); //show current simulation time
+
+assign dout [(dqbits/2 - 1) : 0] = LB_ ? 8\'bz : bank0[A];
+assign dout [(dqbits - 1) : (dqbits/2)] = UB_ ? 8\'bz : bank1[A];
+
+always @(A or w_en)
+ begin
+ #Tsa //address setup time
+ if (w_en)
+ #Thzwe
+ begin
+ bank0[A] = LB_ ? bank0[A] : IO [(dqbits/2 - 1) : 0];
+ bank1[A] = UB_ ? bank1[A] : IO [(dqbits - 1) : (dqbits/2)];
+ end
+ end
+
+// Timing Check
+`ifdef tAC_10
+ specify //sepcify delay
+ specparam
+ tSA = 0,
+ tAW = 8,
+ tSCE = 8,
+ tSD = 6,
+ tPWE2 = 10,
+ tPWE1 = 8,
+ tPBW = 8;
+`else
+
+`ifdef tAC_12
+ specify
+ specparam
+ tSA = 0,
+ tAW = 8,
+ tSCE = 8,
+ tSD = 6,
+ tPWE2 = 12,
+ tPWE1 = 8,
+ tPBW = 8;
+`endif
+`endif
+
+ $setup (A, negedge CE_, tSA);
+ $setup (A, posedge CE_, tAW);
+ $setup (IO, posedge CE_, tSD);
+ $setup (A, negedge WE_, tSA);
+ $setup (IO, posedge WE_, tSD);
+ $setup (A, negedge LB_, tSA);
+ $setup (A, negedge UB_, tSA);
+
+ $width (negedge CE_, tSCE);
+ $width (negedge LB_, tPBW);
+ $width (negedge UB_, tPBW);
+ `ifdef OEb
+ $width (negedge WE_, tPWE1);
+ `else
+ $width (negedge WE_, tPWE2);
+ `endif
+
+ endspecify
+
+endmodule"
+"/*
+ * Milkymist VJ SoC
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * adjusted to FML 8x16 by Zeus Gomez Marmolejo
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+module hpdmc_mgmt #(
+\tparameter sdram_depth = 26,
+\tparameter sdram_columndepth = 9,
+\tparameter sdram_addrdepth = sdram_depth-1-1-(sdram_columndepth+2)+1
+) (
+\tinput sys_clk,
+\tinput sdram_rst,
+\t
+\tinput [2:0] tim_rp,
+\tinput [2:0] tim_rcd,
+\tinput [10:0] tim_refi,
+\tinput [3:0] tim_rfc,
+\t
+\tinput stb,
+\tinput we,
+\tinput [sdram_depth-1-1:0] address, /* in 16-bit words */
+\toutput reg ack,
+\t
+\toutput reg read,
+\toutput reg write,
+\toutput [3:0] concerned_bank,
+\tinput read_safe,
+\tinput write_safe,
+\tinput [3:0] precharge_safe,
+\t
+\toutput sdram_cs_n,
+\toutput sdram_we_n,
+\toutput sdram_cas_n,
+\toutput sdram_ras_n,
+\toutput [sdram_addrdepth-1:0] sdram_adr,
+\toutput [1:0] sdram_ba
+);
+
+/*
+ * Address Mapping :
+ * | ROW ADDRESS | BANK NUMBER | COL ADDRESS | for 16-bit words
+ * |depth-1 coldepth+2|coldepth+1 coldepth|coldepth-1 0|
+ * (depth for 16-bit words, which is sdram_depth-1)
+ */
+
+localparam rowdepth = sdram_depth-1-1-(sdram_columndepth+2)+1;
+localparam sdram_addrdepth_o1024 = sdram_addrdepth-11;
+
+wire [sdram_depth-1-1:0] address16 = address;
+
+wire [sdram_columndepth-1:0] col_address = address16[sdram_columndepth-1:0];
+wire [1:0] bank_address = address16[sdram_columndepth+1:sdram_columndepth];
+wire [rowdepth-1:0] row_address = address16[sdram_depth-1-1:sdram_columndepth+2];
+
+reg [3:0] bank_address_onehot;
+always @(*) begin
+\tcase(bank_address)
+\t\t2\'b00: bank_address_onehot <= 4\'b0001;
+\t\t2\'b01: bank_address_onehot <= 4\'b0010;
+\t\t2\'b10: bank_address_onehot <= 4\'b0100;
+\t\t2\'b11: bank_address_onehot <= 4\'b1000;
+\tendcase
+end
+
+/* Track open rows */
+reg [3:0] has_openrow;
+reg [rowdepth-1:0] openrows[0:3];
+reg [3:0] track_close;
+reg [3:0] track_open;
+
+always @(posedge sys_clk) begin
+\tif(sdram_rst) begin
+\t\thas_openrow <= 4\'h0;
+\tend else begin
+\t\thas_openrow <= (has_openrow | track_open) & ~track_close;
+\t\t
+\t\tif(track_open[0]) openrows[0] <= row_address;
+\t\tif(track_open[1]) openrows[1] <= row_address;
+\t\tif(track_open[2]) openrows[2] <= row_address;
+ \t\tif(track_open[3]) openrows[3] <= row_address;
+\tend
+end
+
+/* Bank precharge safety */
+assign concerned_bank = bank_address_onehot;
+wire current_precharge_safe =
+\t (precharge_safe[0] | ~bank_address_onehot[0])
+\t&(precharge_safe[1] | ~bank_address_onehot[1])
+\t&(precharge_safe[2] | ~bank_address_onehot[2])
+\t&(precharge_safe[3] | ~bank_address_onehot[3]);
+
+
+/* Check for page hits */
+wire bank_open = has_openrow[bank_address];
+wire page_hit = bank_open & (openrows[bank_address] == row_address);
+
+/* Address drivers */
+reg sdram_adr_loadrow;
+reg sdram_adr_loadcol;
+reg sdram_adr_loadA10;
+assign sdram_adr =
+\t ({sdram_addrdepth{sdram_adr_loadrow}}\t& row_address)
+\t|({sdram_addrdepth{sdram_adr_loadcol}}\t& col_address)
+\t|({sdram_addrdepth{sdram_adr_loadA10}}
+ & { {sdram_addrdepth_o1024{1\'b0}} , 11\'d1024});
+
+assign sdram_ba = bank_address;
+
+/* Command drivers */
+reg sdram_cs;
+reg sdram_we;
+reg sdram_cas;
+reg sdram_ras;
+assign sdram_cs_n = ~sdram_cs;
+assign sdram_we_n = ~sdram_we;
+assign sdram_cas_n = ~sdram_cas;
+assign sdram_ras_n = ~sdram_ras;
+
+/* Timing counters */
+
+/* The number of clocks we must wait following a PRECHARGE command (usually tRP). */
+reg [2:0] precharge_counter;
+reg reload_precharge_counter;
+wire precharge_done = (precharge_counter == 3\'d0);
+always @(posedge sys_clk) begin
+\tif(reload_precharge_counter)
+\t\tprecharge_counter <= tim_rp;
+\telse if(~precharge_done)
+\t\tprecharge_counter <= precharge_counter - 3\'d1;
+end
+
+/* The number of clocks we must wait following an ACTIVATE command (usually tRCD). */
+reg [2:0] activate_counter;
+reg reload_activate_counter;
+wire activate_done = (activate_counter == 3\'d0);
+always @(posedge sys_clk) begin
+\tif(reload_activate_counter)
+\t\tactivate_counter <= tim_rcd;
+\telse if(~activate_done)
+\t\tactivate_counter <= activate_counter - 3\'d1;
+end
+
+/* The number of clocks we have left before we must refresh one row in the SDRAM array (usually tREFI). */
+reg [10:0] refresh_counter;
+reg reload_refresh_counter;
+wire must_refresh = refresh_counter == 11\'d0;
+always @(posedge sys_clk) begin
+\tif(sdram_rst)
+\t\trefresh_counter <= 11\'d0;
+\telse begin
+\t\tif(reload_refresh_counter)
+\t\t\trefresh_counter <= tim_refi;
+\t\telse if(~must_refresh)
+\t\t\trefresh_counter <= refresh_counter - 11\'d1;
+\tend
+end
+
+/* The number of clocks we must wait following an AUTO REFRESH command (usually tRFC). */
+reg [3:0] autorefresh_counter;
+reg reload_autorefresh_counter;
+wire autorefresh_done = (autorefresh_counter == 4\'d0);
+always @(posedge sys_clk) begin
+\tif(reload_autorefresh_counter)
+\t\tautorefresh_counter <= tim_rfc;
+\telse if(~autorefresh_done)
+\t\tautorefresh_counter <= autorefresh_counter - 4\'d1;
+end
+
+/* FSM that pushes commands into the SDRAM */
+
+reg [3:0] state;
+reg [3:0] next_state;
+
+ localparam [3:0]
+ IDLE\t\t\t= 4\'d0,
+ ACTIVATE\t\t= 4\'d1,
+ READ\t\t\t= 4\'d2,
+ WRITE\t\t\t= 4\'d3,
+ PRECHARGEALL\t\t= 4\'d4,
+ AUTOREFRESH\t\t= 4\'d5,
+ AUTOREFRESH_WAIT\t= 4\'d6;
+
+always @(posedge sys_clk) begin
+\tif(sdram_rst)
+\t\tstate <= IDLE;
+\telse begin
+\t\t//$display(""state: %d -> %d"", state, next_state);
+\t\tstate <= next_state;
+\tend
+end
+
+always @(*) begin
+\tnext_state = state;
+\t
+\treload_precharge_counter = 1\'b0;
+\treload_activate_counter = 1\'b0;
+\treload_refresh_counter = 1\'b0;
+\treload_autorefresh_counter = 1\'b0;
+\t
+\tsdram_cs = 1\'b0;
+\tsdram_we = 1\'b0;
+\tsdram_cas = 1\'b0;
+\tsdram_ras = 1\'b0;
+\t
+\tsdram_adr_loadrow = 1\'b0;
+\tsdram_adr_loadcol = 1\'b0;
+\tsdram_adr_loadA10 = 1\'b0;
+\t
+\ttrack_close = 4\'b0000;
+\ttrack_open = 4\'b0000;
+\t
+\tread = 1\'b0;
+\twrite = 1\'b0;
+\t
+\tack = 1\'b0;
+\t
+\tcase(state)
+\t\tIDLE: begin
+\t\t\tif(must_refresh)
+\t\t\t\tnext_state = PRECHARGEALL;
+\t\t\telse begin
+\t\t\t\tif(stb) begin
+\t\t\t\t\tif(page_hit) begin
+\t\t\t\t\t\tif(we) begin
+\t\t\t\t\t\t\tif(write_safe) begin
+\t\t\t\t\t\t\t\t/* Write */
+\t\t\t\t\t\t\t\tsdram_cs = 1\'b1;
+\t\t\t\t\t\t\t\tsdram_ras = 1\'b0;
+\t\t\t\t\t\t\t\tsdram_cas = 1\'b1;
+\t\t\t\t\t\t\t\tsdram_we = 1\'b1;
+\t\t\t\t\t\t\t\tsdram_adr_loadcol = 1\'b1;
+\t\t\t\t\t\t\t\t
+\t\t\t\t\t\t\t\twrite = 1\'b1;
+\t\t\t\t\t\t\t\tack = 1\'b1;
+\t\t\t\t\t\t\tend
+\t\t\t\t\t\tend else begin
+\t\t\t\t\t\t\tif(read_safe) begin
+\t\t\t\t\t\t\t\t/* Read */
+\t\t\t\t\t\t\t\tsdram_cs = 1\'b1;
+\t\t\t\t\t\t\t\tsdram_ras = 1\'b0;
+\t\t\t\t\t\t\t\tsdram_cas = 1\'b1;
+\t\t\t\t\t\t\t\tsdram_we = 1\'b0;
+\t\t\t\t\t\t\t\tsdram_adr_loadcol = 1\'b1;
+\t\t\t\t\t\t\t\t
+\t\t\t\t\t\t\t\tread = 1\'b1;
+\t\t\t\t\t\t\t\tack = 1\'b1;
+\t\t\t\t\t\t\tend
+\t\t\t\t\t\tend
+\t\t\t\t\tend else begin
+\t\t\t\t\t\tif(bank_open) begin
+\t\t\t\t\t\t\tif(current_precharge_safe) begin
+\t\t\t\t\t\t\t\t/* Precharge Bank */
+\t\t\t\t\t\t\t\tsdram_cs = 1\'b1;
+\t\t\t\t\t\t\t\tsdram_ras = 1\'b1;
+\t\t\t\t\t\t\t\tsdram_cas = 1\'b0;
+\t\t\t\t\t\t\t\tsdram_we = 1\'b1;
+\t\t\t\t\t\t\t\t
+\t\t\t\t\t\t\t\ttrack_close = bank_address_onehot;
+\t\t\t\t\t\t\t\treload_precharge_counter = 1\'b1;
+\t\t\t\t\t\t\t\tnext_state = ACTIVATE;
+\t\t\t\t\t\t\tend
+\t\t\t\t\t\tend else begin
+\t\t\t\t\t\t\t/* Activate */
+\t\t\t\t\t\t\tsdram_cs = 1\'b1;
+\t\t\t\t\t\t\tsdram_ras = 1\'b1;
+\t\t\t\t\t\t\tsdram_cas = 1\'b0;
+\t\t\t\t\t\t\tsdram_we = 1\'b0;
+\t\t\t\t\t\t\tsdram_adr_loadrow = 1\'b1;
+\t\t\t\t
+\t\t\t\t\t\t\ttrack_open = bank_address_onehot;
+\t\t\t\t\t\t\treload_activate_counter = 1\'b1;
+\t\t\t\t\t\t\tif(we)
+\t\t\t\t\t\t\t\tnext_state = WRITE;
+\t\t\t\t\t\t\telse
+\t\t\t\t\t\t\t\tnext_state = READ;
+\t\t\t\t\t\tend
+\t\t\t\t\tend
+\t\t\t\tend
+\t\t\tend
+\t\tend
+\t\t
+\t\tACTIVATE: begin
+\t\t\tif(precharge_done) begin
+\t\t\t\tsdram_cs = 1\'b1;
+\t\t\t\tsdram_ras = 1\'b1;
+\t\t\t\tsdram_cas = 1\'b0;
+\t\t\t\tsdram_we = 1\'b0;
+\t\t\t\tsdram_adr_loadrow = 1\'b1;
+\t\t\t\t
+\t\t\t\ttrack_open = bank_address_onehot;
+\t\t\t\treload_activate_counter = 1\'b1;
+\t\t\t\tif(we)
+\t\t\t\t\tnext_state = WRITE;
+\t\t\t\telse
+\t\t\t\t\tnext_state = READ;
+\t\t\tend
+\t\tend
+\t\tREAD: begin
+\t\t\tif(activate_done) begin
+\t\t\t\tif(read_safe) begin
+\t\t\t\t\tsdram_cs = 1\'b1;
+\t\t\t\t\tsdram_ras = 1\'b0;
+\t\t\t\t\tsdram_cas = 1\'b1;
+\t\t\t\t\tsdram_we = 1\'b0;
+\t\t\t\t\tsdram_adr_loadcol = 1\'b1;
+\t\t\t\t\t
+\t\t\t\t\tread = 1\'b1;
+\t\t\t\t\tack = 1\'b1;
+\t\t\t\t\tnext_state = IDLE;
+\t\t\t\tend
+\t\t\tend
+\t\tend
+\t\tWRITE: begin
+\t\t\tif(activate_done) begin
+\t\t\t\tif(write_safe) begin
+\t\t\t\t\tsdram_cs = 1\'b1;
+\t\t\t\t\tsdram_ras = 1\'b0;
+\t\t\t\t\tsdram_cas = 1\'b1;
+\t\t\t\t\tsdram_we = 1\'b1;
+\t\t\t\t\tsdram_adr_loadcol = 1\'b1;
+\t\t\t\t\t
+\t\t\t\t\twrite = 1\'b1;
+\t\t\t\t\tack = 1\'b1;
+\t\t\t\t\tnext_state = IDLE;
+\t\t\t\tend
+\t\t\tend
+\t\tend
+\t\t
+\t\tPRECHARGEALL: begin
+\t\t\tif(precharge_safe == 4\'b1111) begin
+\t\t\t\tsdram_cs = 1\'b1;
+\t\t\t\tsdram_ras = 1\'b1;
+\t\t\t\tsdram_cas = 1\'b0;
+\t\t\t\tsdram_we = 1\'b1;
+\t\t\t\tsdram_adr_loadA10 = 1\'b1;
+\t
+\t\t\t\treload_precharge_counter = 1\'b1;
+\t\t\t\t
+\t\t\t\ttrack_close = 4\'b1111;
+\t\t\t\t
+\t\t\t\tnext_state = AUTOREFRESH;
+\t\t\tend
+\t\tend
+\t\tAUTOREFRESH: begin
+\t\t\tif(precharge_done) begin
+\t\t\t\tsdram_cs = 1\'b1;
+\t\t\t\tsdram_ras = 1\'b1;
+\t\t\t\tsdram_cas = 1\'b1;
+\t\t\t\tsdram_we = 1\'b0;
+\t\t\t\treload_refresh_counter = 1\'b1;
+\t\t\t\treload_autorefresh_counter = 1\'b1;
+\t\t\t\tnext_state = AUTOREFRESH_WAIT;
+\t\t\tend
+\t\tend
+\t\tAUTOREFRESH_WAIT: begin
+\t\t\tif(autorefresh_done)
+\t\t\t\tnext_state = IDLE;
+\t\tend
+\t\t
+\tendcase
+end
+
+endmodule
+"
+"/*
+ * Milkymist VJ SoC
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * adjusted to FML 8x16 by Zeus Gomez Marmolejo
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+module hpdmc_banktimer(
+\tinput sys_clk,
+\tinput sdram_rst,
+\t
+\tinput tim_cas,
+\tinput [1:0] tim_wr,
+\t
+\tinput read,
+\tinput write,
+\toutput reg precharge_safe
+);
+
+reg [3:0] counter;
+always @(posedge sys_clk) begin
+\tif(sdram_rst) begin
+\t\tcounter <= 4\'d0;
+\t\tprecharge_safe <= 1\'b1;
+\tend else begin
+\t\tif(read) begin
+\t\t\t/* see p.26 of datasheet :
+\t\t\t * ""A Read burst may be followed by, or truncated with, a Precharge command
+\t\t\t * to the same bank. The Precharge command should be issued x cycles after
+\t\t\t * the Read command, where x equals the number of desired data element
+\t\t\t * pairs""
+\t\t\t */
+\t\t\tcounter <= 4\'d8;
+\t\t\tprecharge_safe <= 1\'b0;
+\t\tend else if(write) begin
+\t\t\tcounter <= {2\'b10, tim_wr};
+\t\t\tprecharge_safe <= 1\'b0;
+\t\tend else begin
+\t\t\tif(counter == 4\'b1)
+\t\t\t\tprecharge_safe <= 1\'b1;
+\t\t\tif(~precharge_safe)
+\t\t\t\tcounter <= counter - 4\'b1;
+\t\tend
+\tend
+end
+
+endmodule
+"
+"/*\r
+ * Planar mode graphics for VGA\r
+ * Copyright (C) 2010 Zeus Gomez Marmolejo \r
+ *\r
+ * VGA FML support\r
+ * Copyright (C) 2013 Charley Picker \r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+module vga_planar_fml (\r
+ input clk,\r
+ input rst,\r
+\r
+ input enable,\r
+\r
+ // CSR slave interface for reading\r
+ output [17:1] fml_adr_o,\r
+ input [15:0] fml_dat_i,\r
+ output fml_stb_o,\r
+\r
+ // Controller registers\r
+ input [3:0] attr_plane_enable,\r
+ input x_dotclockdiv2,\r
+\r
+ input [9:0] h_count,\r
+ input [9:0] v_count,\r
+ input horiz_sync_i,\r
+ input video_on_h_i,\r
+ output video_on_h_o,\r
+\r
+ output reg [3:0] attr,\r
+ output horiz_sync_o\r
+ );\r
+\r
+ // Registers and net\r
+ reg [11:0] row_addr;\r
+ reg [ 5:0] col_addr;\r
+ reg [14:0] word_offset;\r
+ reg [ 1:0] plane_addr0;\r
+ reg [ 1:0] plane_addr;\r
+ reg [15:0] plane0;\r
+ reg [15:0] plane0_tmp;\r
+ reg [15:0] plane1;\r
+ reg [15:0] plane1_tmp;\r
+ reg [15:0] plane2;\r
+ reg [15:0] plane2_tmp;\r
+ reg [15:0] plane3;\r
+ reg [ 7:0] bit_mask0;\r
+ reg [ 7:0] bit_mask1;\r
+\r
+ wire [15:0] bit_mask;\r
+ wire v_count0;\r
+\r
+ wire bit3, bit2, bit1, bit0;\r
+\r
+ reg [9:0] video_on_h;\r
+ reg [9:0] horiz_sync;\r
+ reg [7:0] pipe;\r
+\r
+ // Continous assignments\r
+ assign fml_adr_o = { word_offset, plane_addr };\r
+ assign bit_mask = { bit_mask1, bit_mask0 };\r
+\r
+ assign bit0 = |(bit_mask & plane0);\r
+ assign bit1 = |(bit_mask & plane1);\r
+ assign bit2 = |(bit_mask & plane2);\r
+ assign bit3 = |(bit_mask & plane3);\r
+\r
+ assign video_on_h_o = video_on_h[9];\r
+ assign horiz_sync_o = horiz_sync[9];\r
+ assign fml_stb_o = |pipe[4:1];\r
+ assign v_count0 = x_dotclockdiv2 ? 1'b0 : v_count[0];\r
+\r
+ // Behaviour\r
+ // Pipeline count\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ pipe <= 8'b0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ pipe <= { pipe[6:0],\r
+ x_dotclockdiv2 ? (h_count[4:0]==5'h0) : (h_count[3:0]==4'h0) }; \r
+ end\r
+\r
+ // video_on_h\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ video_on_h <= 10'b0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ video_on_h <= { video_on_h[8:0], video_on_h_i };\r
+ end\r
+\r
+ // horiz_sync\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ horiz_sync <= 10'b0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ horiz_sync <= { horiz_sync[8:0], horiz_sync_i };\r
+ end\r
+\r
+ // Address generation\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ row_addr <= 12'h0;\r
+ col_addr <= 6'h0;\r
+ plane_addr0 <= 2'b00;\r
+ word_offset <= 15'h0;\r
+ plane_addr <= 2'b00;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ // Loading new row_addr and col_addr when h_count[3:0]==4'h0\r
+ // v_count * 40 or 22 (depending on x_dotclockdiv2)\r
+ row_addr <= { v_count[9:1], v_count0, 2'b00 } + { v_count[9:1], v_count0 }\r
+ + (x_dotclockdiv2 ? v_count[9:1] : 9'h0);\r
+ col_addr <= x_dotclockdiv2 ? h_count[9:5] : h_count[9:4];\r
+ plane_addr0 <= h_count[1:0];\r
+\r
+ // Load new word_offset at +1\r
+ word_offset <= (x_dotclockdiv2 ? { row_addr, 1'b0 }\r
+ : { row_addr, 3'b000 }) + col_addr;\r
+ plane_addr <= plane_addr0;\r
+ end\r
+\r
+ // Temporary plane data\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ plane0_tmp <= 16'h0;\r
+ plane1_tmp <= 16'h0;\r
+ plane2_tmp <= 16'h0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ // Load plane0 when pipe == 4\r
+ plane0_tmp <= pipe[4] ? fml_dat_i : plane0_tmp;\r
+ plane1_tmp <= pipe[5] ? fml_dat_i : plane1_tmp;\r
+ plane2_tmp <= pipe[6] ? fml_dat_i : plane2_tmp; \r
+ end\r
+\r
+ // Plane data\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ plane0 <= 16'h0;\r
+ plane1 <= 16'h0;\r
+ plane2 <= 16'h0;\r
+ plane3 <= 16'h0;\r
+ end\r
+ else\r
+ if (enable) \r
+ begin\r
+ plane0 <= pipe[7] ? plane0_tmp : plane0;\r
+ plane1 <= pipe[7] ? plane1_tmp : plane1;\r
+ plane2 <= pipe[7] ? plane2_tmp : plane2;\r
+ plane3 <= pipe[7] ? fml_dat_i : plane3;\r
+ end\r
+\r
+ // Bit masks\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ bit_mask0 <= 8'h0;\r
+ bit_mask1 <= 8'h0;\r
+ end\r
+ else\r
+ if (enable) \r
+ begin\r
+ bit_mask0 <= (h_count[0] & x_dotclockdiv2) ? bit_mask0\r
+ : { pipe[7], bit_mask0[7:1] };\r
+ bit_mask1 <= (h_count[0] & x_dotclockdiv2) ? bit_mask1\r
+ : { bit_mask0[0], bit_mask1[7:1] };\r
+ end\r
+\r
+ // attr\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ attr <= 4'h0; \r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ attr <= (attr_plane_enable & { bit3, bit2, bit1, bit0 });\r
+ end \r
+\r
+endmodule"
+"/*
+ * Sound module
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+// --------------------------------------------------------------------
+// Description: Sound module. This is NOT a sound blaster emulator.
+// This module produces simple sounds by implementing a simple interface,
+// The user simply writes a byte of data to the left and/or right channels.
+// Then poll the status register which will raise a flag when ready for the
+// next byte of data. Alternatively, it can generate an interupt to request
+// the next byte.
+//
+// Sound uses 16 I/O addresses 0x0nn0 to 0x0nnF, nn can be anything
+//
+// I/O Address Description
+// ----------- ------------------
+// 0x0210 Left Channel
+// 0x0211 Right Channel
+// 0x0212 High byte of timing increment
+// 0x0213 Low byte of timing increment
+// 0x0215 Control, 0x01 to enable interupt, 0x00 for polled mode
+// 0x0217 Status, 0x80 when ready for next data, else 0x00
+//
+// --------------------------------------------------------------------
+
+module sound (
+ input wb_clk_i,
+ input wb_rst_i,
+ input [ 2:0] wb_adr_i,
+ input [ 1:0] wb_sel_i,
+ input [15:0] wb_dat_i,
+ output [15:0] wb_dat_o,
+ input wb_cyc_i,
+ input wb_stb_i,
+ input wb_we_i,
+ output reg wb_ack_o,
+
+ output audio_l,
+ output audio_r
+ );
+
+ // --------------------------------------------------------------------
+ // Wishbone Handling
+ // --------------------------------------------------------------------
+ reg [7:0] sb_dat_o;
+ wire [3:0] sb_adr_i = {wb_adr_i, wb_sel_i[1]};
+ wire [7:0] sb_dat_i = wb_sel_i[0] ? wb_dat_i[7:0] : wb_dat_i[15:8]; // 16 to 8 bit
+ assign wb_dat_o = {sb_dat_o, sb_dat_o};
+ wire wb_ack_i = wb_stb_i & wb_cyc_i; // Immediate ack
+ wire wr_command = wb_ack_i & wb_we_i; // Wishbone write access, Singal to send
+ wire rd_command = wb_ack_i & ~wb_we_i; // Wishbone write access, Singal to send
+
+ always @(posedge wb_clk_i or posedge wb_rst_i) begin // Synchrounous
+ if(wb_rst_i) wb_ack_o <= 1'b0;
+ else wb_ack_o <= wb_ack_i & ~wb_ack_o; // one clock delay on acknowledge output
+ end
+
+ // --------------------------------------------------------------------
+ // The following table lists the functions of the I/O ports:
+ // I/O Address Description Access
+ // ----------- -------------------
+ // Base + 0 Left channel data, write only
+ // Base + 1 Right channel data, write only
+ // Base + 2 High byte for timer, write only
+ // Base + 3 Low byte for timer, write only
+ // Base + 5 Control, write only
+ // Base + 7 Status, read only
+ // --------------------------------------------------------------------
+ `define REG_CHAN01 4'h0 // W - Channel 1
+ `define REG_CHAN02 4'h1 // W - Channel 1
+ `define REG_TIMERH 4'h2 // W - Timer increment high byte
+ `define REG_TIMERL 4'h3 // W - Timer increment low byte
+ `define REG_CONTRL 4'h5 // W - Control
+ `define REG_STATUS 4'h7 // R - Status
+ // --------------------------------------------------------------------
+
+ // --------------------------------------------------------------------
+ // DefaultTime Constant
+ // --------------------------------------------------------------------
+ `define DSP_DEFAULT_RATE 16'd671 // Default sampling rate is 8Khz
+
+ // --------------------------------------------------------------------
+ // Sound Blaster Register behavior
+ // --------------------------------------------------------------------
+ reg start; // Start the timer
+ reg timeout; // Timer has timed out
+ reg [19:0] timer; // DAC output timer register
+ reg [15:0] time_inc; // DAC output time increment
+ wire [7:0] TMR_STATUS = {timeout, 7'h00};
+
+ always @(posedge wb_clk_i) begin // Synchrounous Logic
+ if(wb_rst_i) begin
+ sb_dat_o <= 8'h00; // Default value
+ end
+ else begin
+ if(rd_command) begin
+ case(sb_adr_i) // Determine which register was read
+ `REG_STATUS: sb_dat_o <= TMR_STATUS; // DSP Read status
+ `REG_TIMERH: sb_dat_o <= time_inc[15:8]; // Read back the timing register
+ `REG_TIMERL: sb_dat_o <= time_inc[ 7:0]; // Read back the timing register
+ default: sb_dat_o <= 8'h00; // Default
+ endcase // End of case
+ end
+ end // End of Reset if
+ end // End Synchrounous always
+
+ always @(posedge wb_clk_i) begin // Synchrounous Logic
+
+ if(wb_rst_i) begin
+ dsp_audio_l <= 8'h80; // default is equivalent to 1/2
+ dsp_audio_r <= 8'h80; // default is equivalent to 1/2
+ start <= 1'b0; // Timer not on
+ timeout <= 1'b0; // Not timed out
+ time_inc <= `DSP_DEFAULT_RATE; // Default value
+ end
+ else begin
+
+ if(wr_command) begin // If a write was requested
+ case(sb_adr_i) // Determine which register was writen to
+ `REG_CHAN01: begin
+ dsp_audio_l <= sb_dat_i; // Get the user data or data
+ start <= 1'b1;
+ timeout <= 1'b0;
+ end
+ `REG_CHAN02: begin
+ dsp_audio_r <= sb_dat_i; // Get the user data or data
+ start <= 1'b1;
+ timeout <= 1'b0;
+ end
+ `REG_TIMERH: time_inc[15:8] <= sb_dat_i; // Get the user data or data
+ `REG_TIMERL: time_inc[ 7:0] <= sb_dat_i; // Get the user data or data
+ default: ; // Default value
+ endcase // End of case
+ end // End of Write Command if
+
+ if(timed_out) begin
+ start <= 1'b0;
+ timeout <= 1'b1;
+ end
+
+ end // End of Reset if
+ end // End Synchrounous always
+
+ // --------------------------------------------------------------------
+ // Audio Timer interrupt Generation Section
+ // DAC Clock set to system clock which is 12,500,000Hz
+ // Interval = DAC_ClK / Incr = 12,500,000 / (1048576 / X ) = 8000Hz
+ // X = 1048576 / (12,500,000 / 8000) = 1048576 / 1562.5
+ // X = 671
+ // --------------------------------------------------------------------
+ wire timed_out = timer[19];
+ always @(posedge wb_clk_i) begin
+ if(wb_rst_i) begin
+ timer <= 20'd0;
+ end
+ else begin
+ if(start) timer <= timer + time_inc;
+ else timer <= 20'd0;
+ end
+ end
+
+ // --------------------------------------------------------------------
+ // PWM CLock Generation Section:
+ // We need to divide down the clock for PWM, dac_clk = 12.5Mhz
+ // then 12,500,000 / 512 = 24,414Hz which is a good sampling rate for audio
+ // 0 = 2
+ // 1 = 4
+ // 2 = 8 1,562,500Hz
+ // 3 = 16
+ // 4 = 32
+ // 5 = 64
+ // 6 = 128
+ // 7 = 256
+ // 8 = 512 24,414Hz
+ // --------------------------------------------------------------------
+ wire pwm_clk;
+ assign pwm_clk = wb_clk_i; // Because it's already at 12.5 Mhz
+
+ // --------------------------------------------------------------------
+ // Audio Generation Section
+ // --------------------------------------------------------------------
+ reg [7:0] dsp_audio_l;
+ reg [7:0] dsp_audio_r;
+ sound_dac8 left (pwm_clk, dsp_audio_l, audio_l); // 8 bit pwm DAC
+ sound_dac8 right(pwm_clk, dsp_audio_r, audio_r); // 8 bit pwm DAC
+
+endmodule
+"
+"/*
+ * Copyright (c) 2009 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`timescale 1ns/10ps
+
+module test_sdspi;
+
+ // Registers and nets
+ wire sclk;
+ reg miso;
+ wire mosi;
+ wire ss;
+
+ reg clk;
+ reg rst;
+ reg [8:0] dat_i;
+ wire [7:0] dat_o;
+ reg we;
+ reg [1:0] sel;
+ reg stb;
+ wire ack;
+ reg [7:0] data;
+
+ reg [7:0] st;
+
+ // Module instantiations
+ sdspi sdspi (
+ // Serial pad signal
+ .sclk (sclk),
+ .miso (miso),
+ .mosi (mosi),
+ .ss (ss),
+
+ // Wishbone slave interface
+ .wb_clk_i (clk),
+ .wb_rst_i (rst),
+ .wb_dat_i (dat_i),
+ .wb_dat_o (dat_o),
+ .wb_we_i (we),
+ .wb_sel_i (sel),
+ .wb_stb_i (stb),
+ .wb_cyc_i (stb),
+ .wb_ack_o (ack)
+ );
+
+ // Behaviour
+ always @(posedge clk)
+ if (rst)
+ begin
+ dat_i <= 9'h0;
+ we <= 1'b0;
+ sel <= 2'b00;
+ stb <= 1'b0;
+ st <= 8'h0;
+ end
+ else
+ case (st)
+ 8'h0:
+ begin
+ dat_i <= 9'h55;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h1;
+ end
+ 8'h1:
+ if (ack) begin
+ dat_i <= 9'hff;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h2;
+ end
+ 8'h2:
+ if (ack) begin
+ dat_i <= 9'h0ff;
+ we <= 1'b1;
+ sel <= 2'b11;
+ stb <= 1'b1;
+ st <= 8'h3;
+ end
+ 8'h3:
+ if (ack) begin
+ dat_i <= 9'h40;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h4;
+ end
+ 8'h4:
+ if (ack) begin
+ dat_i <= 9'h00;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h14;
+ end
+ 8'h14:
+ if (ack) begin
+ dat_i <= 9'h00;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b0;
+ st <= 8'h5;
+ end
+ 8'h5:
+ begin
+ dat_i <= 9'h00;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h6;
+ end
+ 8'h6:
+ if (ack) begin
+ dat_i <= 9'h00;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h7;
+ end
+ 8'h7:
+ if (ack) begin
+ dat_i <= 9'h00;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h8;
+ end
+ 8'h8:
+ if (ack) begin
+ dat_i <= 9'h95;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h9;
+ end
+ 8'h9:
+ if (ack) begin
+ dat_i <= 9'hff;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'd10;
+ end
+ 8'd10:
+ if (ack) begin
+ dat_i <= 9'hff;
+ we <= 1'b0;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'd11;
+ end
+ 8'd11:
+ if (ack) begin
+ dat_i <= 9'hff;
+ we <= 1'b0;
+ sel <= 2'b01;
+ stb <= 1'b0;
+ st <= 8'd12;
+ data <= dat_o;
+ end
+ endcase
+
+ always #40 clk <= !clk;
+
+ initial
+ begin
+ clk <= 1'b0;
+ rst <= 1'b1;
+ miso <= 1'b1;
+ sdspi.clk_div <= 2'b00;
+
+ #400 rst <= 1'b0;
+ end
+
+ initial
+ begin
+ #26440 miso <= 1'b1;
+ #320 miso <= 1'b1;
+ #320 miso <= 1'b1;
+ #320 miso <= 1'b0;
+ #320 miso <= 1'b1;
+ #320 miso <= 1'b0;
+ #320 miso <= 1'b1;
+ #320 miso <= 1'b1;
+
+ end
+endmodule
+"
+"/*
+ * 8-bit rotate module for Zet
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_rxr8 (
+ input [7:0] x,
+ input ci,
+ input [3:0] y,
+ input e,
+ output reg [7:0] w,
+ output reg co
+ );
+
+ always @(x or ci or y or e)
+ case (y)
+ default: {co,w} <= {ci,x};
+ 5'd01: {co,w} <= e ? {x[0], ci, x[7:1]} : {ci, x[0], x[7:1]};
+ 5'd02: {co,w} <= e ? {x[1:0], ci, x[7:2]} : {ci, x[1:0], x[7:2]};
+ 5'd03: {co,w} <= e ? {x[2:0], ci, x[7:3]} : {ci, x[2:0], x[7:3]};
+ 5'd04: {co,w} <= e ? {x[3:0], ci, x[7:4]} : {ci, x[3:0], x[7:4]};
+ 5'd05: {co,w} <= e ? {x[4:0], ci, x[7:5]} : {ci, x[4:0], x[7:5]};
+ 5'd06: {co,w} <= e ? {x[5:0], ci, x[7:6]} : {ci, x[5:0], x[7:6]};
+ 5'd07: {co,w} <= e ? {x[6:0], ci, x[7]} : {ci, x[6:0], x[7]};
+ 5'd08: {co,w} <= {x,ci};
+ endcase
+endmodule
+"
+"/*
+ * Wishbone switch and address decoder
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ * Copyright (C) 2008, 2009 Sebastien Bourdeauducq - http://lekernel.net
+ * Copyright (C) 2000 Johny Chi - chisuhua@yahoo.com.cn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module wb_switch #(
+ parameter s0_addr_1 = 20'h00000, // Default Values
+ parameter s0_mask_1 = 20'h00000,
+ parameter s1_addr_1 = 20'h00000,
+ parameter s1_mask_1 = 20'h00000,
+ parameter s1_addr_2 = 20'h00000,
+ parameter s1_mask_2 = 20'h00000,
+ parameter s2_addr_1 = 20'h00000,
+ parameter s2_mask_1 = 20'h00000,
+ parameter s3_addr_1 = 20'h00000,
+ parameter s3_mask_1 = 20'h00000,
+ parameter s4_addr_1 = 20'h00000,
+ parameter s4_mask_1 = 20'h00000,
+ parameter s5_addr_1 = 20'h00000,
+ parameter s5_mask_1 = 20'h00000,
+ parameter s6_addr_1 = 20'h00000,
+ parameter s6_mask_1 = 20'h00000,
+ parameter s7_addr_1 = 20'h00000,
+ parameter s7_mask_1 = 20'h00000,
+ parameter s8_addr_1 = 20'h00000,
+ parameter s8_mask_1 = 20'h00000,
+ parameter s9_addr_1 = 20'h00000,
+ parameter s9_mask_1 = 20'h00000,
+ parameter sA_addr_1 = 20'h00000,
+ parameter sA_mask_1 = 20'h00000,
+ parameter sA_addr_2 = 20'h00000,
+ parameter sA_mask_2 = 20'h00000
+ )(
+ // Master interface
+ input [15:0] m_dat_i,
+ output [15:0] m_dat_o,
+ input [20:1] m_adr_i,
+ input [ 1:0] m_sel_i,
+ input m_we_i,
+ input m_cyc_i,
+ input m_stb_i,
+ output m_ack_o,
+
+ // Slave 0 interface
+ input [15:0] s0_dat_i,
+ output [15:0] s0_dat_o,
+ output [20:1] s0_adr_o,
+ output [ 1:0] s0_sel_o,
+ output s0_we_o,
+ output s0_cyc_o,
+ output s0_stb_o,
+ input s0_ack_i,
+
+ // Slave 1 interface
+ input [15:0] s1_dat_i,
+ output [15:0] s1_dat_o,
+ output [20:1] s1_adr_o,
+ output [ 1:0] s1_sel_o,
+ output s1_we_o,
+ output s1_cyc_o,
+ output s1_stb_o,
+ input s1_ack_i,
+
+ // Slave 2 interface
+ input [15:0] s2_dat_i,
+ output [15:0] s2_dat_o,
+ output [20:1] s2_adr_o,
+ output [ 1:0] s2_sel_o,
+ output s2_we_o,
+ output s2_cyc_o,
+ output s2_stb_o,
+ input s2_ack_i,
+
+ // Slave 3 interface
+ input [15:0] s3_dat_i,
+ output [15:0] s3_dat_o,
+ output [20:1] s3_adr_o,
+ output [ 1:0] s3_sel_o,
+ output s3_we_o,
+ output s3_cyc_o,
+ output s3_stb_o,
+ input s3_ack_i,
+
+ // Slave 4 interface
+ input [15:0] s4_dat_i,
+ output [15:0] s4_dat_o,
+ output [20:1] s4_adr_o,
+ output [ 1:0] s4_sel_o,
+ output s4_we_o,
+ output s4_cyc_o,
+ output s4_stb_o,
+ input s4_ack_i,
+
+ // Slave 5 interface
+ input [15:0] s5_dat_i,
+ output [15:0] s5_dat_o,
+ output [20:1] s5_adr_o,
+ output [ 1:0] s5_sel_o,
+ output s5_we_o,
+ output s5_cyc_o,
+ output s5_stb_o,
+ input s5_ack_i,
+
+ // Slave 6 interface
+ input [15:0] s6_dat_i,
+ output [15:0] s6_dat_o,
+ output [20:1] s6_adr_o,
+ output [ 1:0] s6_sel_o,
+ output s6_we_o,
+ output s6_cyc_o,
+ output s6_stb_o,
+ input s6_ack_i,
+
+ // Slave 7 interface
+ input [15:0] s7_dat_i,
+ output [15:0] s7_dat_o,
+ output [20:1] s7_adr_o,
+ output [ 1:0] s7_sel_o,
+ output s7_we_o,
+ output s7_cyc_o,
+ output s7_stb_o,
+ input s7_ack_i,
+
+ // Slave 8 interface
+ input [15:0] s8_dat_i,
+ output [15:0] s8_dat_o,
+ output [20:1] s8_adr_o,
+ output [ 1:0] s8_sel_o,
+ output s8_we_o,
+ output s8_cyc_o,
+ output s8_stb_o,
+ input s8_ack_i,
+
+ // Slave 9 interface
+ input [15:0] s9_dat_i,
+ output [15:0] s9_dat_o,
+ output [20:1] s9_adr_o,
+ output [ 1:0] s9_sel_o,
+ output s9_we_o,
+ output s9_cyc_o,
+ output s9_stb_o,
+ input s9_ack_i,
+
+ // Slave A interface - masked default
+ input [15:0] sA_dat_i,
+ output [15:0] sA_dat_o,
+ output [20:1] sA_adr_o,
+ output [ 1:0] sA_sel_o,
+ output sA_we_o,
+ output sA_cyc_o,
+ output sA_stb_o,
+ input sA_ack_i,
+
+ // Slave B interface - default
+ input [15:0] sB_dat_i,
+ output [15:0] sB_dat_o,
+ output [20:1] sB_adr_o,
+ output [ 1:0] sB_sel_o,
+ output sB_we_o,
+ output sB_cyc_o,
+ output sB_stb_o,
+ input sB_ack_i
+
+ );
+
+`define mbusw_ls 20 + 2 + 16 + 1 + 1 + 1 // address + byte select + data + cyc + we + stb
+
+wire [11:0] slave_sel;
+wire [15:0] i_dat_s; // internal shared bus, slave data to master
+wire i_bus_ack; // internal shared bus, ack signal
+
+wire [`mbusw_ls -1:0] i_bus_m; // internal shared bus, master data and control to slave
+
+assign m_dat_o = i_dat_s;
+assign m_ack_o = i_bus_ack;
+
+// Bus Acknowlegement
+assign i_bus_ack = s0_ack_i | s1_ack_i | s2_ack_i | s3_ack_i | s4_ack_i | s5_ack_i | s6_ack_i |
+ s7_ack_i | s8_ack_i | s9_ack_i | sA_ack_i | sB_ack_i;
+
+assign i_dat_s = ({16{slave_sel[ 0]}} & s0_dat_i)
+ |({16{slave_sel[ 1]}} & s1_dat_i)
+ |({16{slave_sel[ 2]}} & s2_dat_i)
+ |({16{slave_sel[ 3]}} & s3_dat_i)
+ |({16{slave_sel[ 4]}} & s4_dat_i)
+ |({16{slave_sel[ 5]}} & s5_dat_i)
+ |({16{slave_sel[ 6]}} & s6_dat_i)
+ |({16{slave_sel[ 7]}} & s7_dat_i)
+ |({16{slave_sel[ 8]}} & s8_dat_i)
+ |({16{slave_sel[ 9]}} & s9_dat_i)
+ |({16{slave_sel[10]}} & sA_dat_i)
+ |({16{slave_sel[11]}} & sB_dat_i)
+ ;
+
+// Bus Selection logic
+assign slave_sel[ 0] = ((m_adr_i & s0_mask_1) == s0_addr_1);
+assign slave_sel[ 1] = ((m_adr_i & s1_mask_1) == s1_addr_1) | ((m_adr_i & s1_mask_2) == s1_addr_2);
+assign slave_sel[ 2] = ((m_adr_i & s2_mask_1) == s2_addr_1);
+assign slave_sel[ 3] = ((m_adr_i & s3_mask_1) == s3_addr_1);
+assign slave_sel[ 4] = ((m_adr_i & s4_mask_1) == s4_addr_1);
+assign slave_sel[ 5] = ((m_adr_i & s5_mask_1) == s5_addr_1);
+assign slave_sel[ 6] = ((m_adr_i & s6_mask_1) == s6_addr_1);
+assign slave_sel[ 7] = ((m_adr_i & s7_mask_1) == s7_addr_1);
+assign slave_sel[ 8] = ((m_adr_i & s8_mask_1) == s8_addr_1);
+assign slave_sel[ 9] = ((m_adr_i & s9_mask_1) == s9_addr_1);
+assign slave_sel[10] = (((m_adr_i & sA_mask_1) == sA_addr_1) | (( m_adr_i & sA_mask_2)== sA_addr_2)) & ~(|slave_sel[9:0]);
+assign slave_sel[11] = ~(|slave_sel[10:0]);
+
+assign i_bus_m = {m_adr_i, m_sel_i, m_dat_i, m_we_i, m_cyc_i, m_stb_i};
+
+assign {s0_adr_o, s0_sel_o, s0_dat_o, s0_we_o, s0_cyc_o} = i_bus_m[`mbusw_ls -1:1]; // slave 0
+assign s0_stb_o = i_bus_m[1] & i_bus_m[0] & slave_sel[0]; // stb_o = cyc_i & stb_i & slave_sel
+
+assign {s1_adr_o, s1_sel_o, s1_dat_o, s1_we_o, s1_cyc_o} = i_bus_m[`mbusw_ls -1:1]; // slave 1
+assign s1_stb_o = i_bus_m[1] & i_bus_m[0] & slave_sel[1];
+
+assign {s2_adr_o, s2_sel_o, s2_dat_o, s2_we_o, s2_cyc_o} = i_bus_m[`mbusw_ls -1:1]; // slave 2
+assign s2_stb_o = i_bus_m[1] & i_bus_m[0] & slave_sel[2];
+
+assign {s3_adr_o, s3_sel_o, s3_dat_o, s3_we_o, s3_cyc_o} = i_bus_m[`mbusw_ls -1:1]; // slave 3
+assign s3_stb_o = i_bus_m[1] & i_bus_m[0] & slave_sel[3];
+
+assign {s4_adr_o, s4_sel_o, s4_dat_o, s4_we_o, s4_cyc_o} = i_bus_m[`mbusw_ls -1:1]; // slave 4
+assign s4_stb_o = i_bus_m[1] & i_bus_m[0] & slave_sel[4];
+
+assign {s5_adr_o, s5_sel_o, s5_dat_o, s5_we_o, s5_cyc_o} = i_bus_m[`mbusw_ls -1:1]; // slave 5
+assign s5_stb_o = i_bus_m[1] & i_bus_m[0] & slave_sel[5];
+
+assign {s6_adr_o, s6_sel_o, s6_dat_o, s6_we_o, s6_cyc_o} = i_bus_m[`mbusw_ls -1:1]; // slave 6
+assign s6_stb_o = i_bus_m[1] & i_bus_m[0] & slave_sel[6];
+
+assign {s7_adr_o, s7_sel_o, s7_dat_o, s7_we_o, s7_cyc_o} = i_bus_m[`mbusw_ls -1:1]; // slave 7
+assign s7_stb_o = i_bus_m[1] & i_bus_m[0] & slave_sel[7];
+
+assign {s8_adr_o, s8_sel_o, s8_dat_o, s8_we_o, s8_cyc_o} = i_bus_m[`mbusw_ls -1:1]; // slave 8
+assign s8_stb_o = i_bus_m[1] & i_bus_m[0] & slave_sel[8];
+
+assign {s9_adr_o, s9_sel_o, s9_dat_o, s9_we_o, s9_cyc_o} = i_bus_m[`mbusw_ls -1:1]; // slave 9
+assign s9_stb_o = i_bus_m[1] & i_bus_m[0] & slave_sel[9];
+
+assign {sA_adr_o, sA_sel_o, sA_dat_o, sA_we_o, sA_cyc_o} = i_bus_m[`mbusw_ls -1:1]; // slave A
+assign sA_stb_o = i_bus_m[1] & i_bus_m[0] & slave_sel[10];
+
+assign {sB_adr_o, sB_sel_o, sB_dat_o, sB_we_o, sB_cyc_o} = i_bus_m[`mbusw_ls -1:1]; // slave B
+assign sB_stb_o = i_bus_m[1] & i_bus_m[0] & slave_sel[11];
+
+endmodule
+"
+"/*\r
+ * Palette register file for VGA\r
+ * Copyright (C) 2010 Zeus Gomez Marmolejo \r
+ *\r
+ * VGA FML support\r
+ * Copyright (C) 2013 Charley Picker \r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+module vga_palette_regs_fml (\r
+ input clk,\r
+\r
+ // VGA read interface\r
+ input [3:0] attr,\r
+ output reg [7:0] index,\r
+\r
+ // CPU interface\r
+ input [3:0] address,\r
+ input write,\r
+ output reg [7:0] read_data,\r
+ input [7:0] write_data\r
+ );\r
+\r
+ // Registers\r
+ reg [7:0] palette [0:15];\r
+\r
+ // Behaviour\r
+ // VGA read interface\r
+ always @(posedge clk) index <= palette[attr];\r
+\r
+ // CPU read interface\r
+ always @(posedge clk) read_data <= palette[address];\r
+\r
+ // CPU write interface\r
+ always @(posedge clk)\r
+ if (write) palette[address] <= write_data;\r
+\r
+endmodule\r
+"
+"/*
+ * Internal RAM for VGA
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vdu_ram_2k_char (
+ input clk,
+ input rst,
+ input we,
+ input [10:0] addr,
+ output [ 7:0] rdata,
+ input [ 7:0] wdata
+ );
+
+ // Registers and nets
+ reg [ 7:0] mem[0:2047];
+ reg [10:0] addr_reg;
+
+ always @(posedge clk)
+ begin
+ if (we) mem[addr] <= wdata;
+ addr_reg <= addr;
+ end
+
+ // Combinatorial logic
+ assign rdata = mem[addr_reg];
+
+ initial $readmemh(""buff_rom.dat"", mem);
+
+endmodule
+
+"
+"/*
+ * Milkymist VJ SoC
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * adjusted to FML 8x16 by Zeus Gomez Marmolejo
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+module hpdmc_datactl(
+\tinput sys_clk,
+\tinput sdram_rst,
+\t
+\tinput read,
+\tinput write,
+\tinput [3:0] concerned_bank,
+\toutput reg read_safe,
+\toutput reg write_safe,
+\toutput [3:0] precharge_safe,
+\t
+\toutput reg ack,
+\toutput reg direction,
+\toutput direction_r,
+\t
+\tinput tim_cas,
+\tinput [1:0] tim_wr
+);
+
+/*
+ * read_safe: whether it is safe to register a Read command
+ * into the SDRAM at the next cycle.
+ */
+
+reg [2:0] read_safe_counter;
+always @(posedge sys_clk) begin
+\tif(sdram_rst) begin
+\t\tread_safe_counter <= 3'd0;
+\t\tread_safe <= 1'b1;
+\tend else begin
+\t\tif(read) begin
+\t\t\tread_safe_counter <= 3'd7;
+\t\t\tread_safe <= 1'b0;
+\t\tend else if(write) begin
+\t\t\t/* after a write, read is unsafe for 9-CL cycles, therefore we load :
+\t\t\t * 7 at CAS Latency 2 (tim_cas = 0)
+\t\t\t * 6 at CAS Latency 3 (tim_cas = 1)
+\t\t\t */
+\t\t\tread_safe_counter <= {2'b11, ~tim_cas};
+\t\t\tread_safe <= 1'b0;
+\t\tend else begin
+\t\t\tif(read_safe_counter == 3'd1)
+\t\t\t\tread_safe <= 1'b1;
+\t\t\tif(~read_safe)
+\t\t\t\tread_safe_counter <= read_safe_counter - 3'd1;
+\t\tend
+\tend
+end
+
+/*
+ * write_safe: whether it is safe to register a Write command
+ * into the SDRAM at the next cycle.
+ */
+
+reg [3:0] write_safe_counter;
+always @(posedge sys_clk) begin
+\tif(sdram_rst) begin
+\t\twrite_safe_counter <= 4'd0;
+\t\twrite_safe <= 1'b1;
+\tend else begin
+\t\tif(read) begin
+\t\t\twrite_safe_counter <= {3'b100, ~tim_cas};
+\t\t\twrite_safe <= 1'b0;
+\t\tend else if(write) begin
+\t\t\twrite_safe_counter <= 4'd7;
+\t\t\twrite_safe <= 1'b0;
+\t\tend else begin
+\t\t\tif(write_safe_counter == 4'd1)
+\t\t\t\twrite_safe <= 1'b1;
+\t\t\tif(~write_safe)
+\t\t\t\twrite_safe_counter <= write_safe_counter - 4'd1;
+\t\tend
+\tend
+end
+
+/* Generate ack signal.
+ * After write is asserted, it should pulse after 2 cycles.
+ * After read is asserted, it should pulse after CL+2 cycles, that is
+ * 4 cycles when tim_cas = 0
+ * 5 cycles when tim_cas = 1
+ */
+
+reg ack_read2;
+reg ack_read1;
+reg ack_read0;
+
+always @(posedge sys_clk) begin
+\tif(sdram_rst) begin
+\t\tack_read2 <= 1'b0;
+\t\tack_read1 <= 1'b0;
+\t\tack_read0 <= 1'b0;
+\tend else begin
+\t\tif(tim_cas) begin
+\t\t\tack_read2 <= read;
+\t\t\tack_read1 <= ack_read2;
+\t\t\tack_read0 <= ack_read1;
+\t\tend else begin
+\t\t\tack_read1 <= read;
+\t\t\tack_read0 <= ack_read1;
+\t\tend
+\tend
+end
+
+reg ack0;
+always @(posedge sys_clk) begin
+\tif(sdram_rst) begin
+\t\tack0 <= 1'b0;
+\t\tack <= 1'b0;
+\tend else begin
+\t\tack0 <= ack_read0;
+\t\tack <= ack0|write;
+\tend
+end
+
+/* during a 8-word write, we drive the pins for 9 cycles
+ * and 1 cycle in advance (first word is invalid)
+ * so that we remove glitches on DQS without resorting
+ * to asynchronous logic.
+ */
+
+/* direction must be glitch-free, as it directly drives the
+ * tri-state enable for DQ and DQS.
+ */
+reg [3:0] counter_writedirection;
+always @(posedge sys_clk) begin
+\tif(sdram_rst) begin
+\t\tcounter_writedirection <= 4'd0;
+\t\tdirection <= 1'b0;
+\tend else begin
+\t\tif(write) begin
+\t\t\tcounter_writedirection <= 4'b1001;
+\t\t\tdirection <= 1'b1;
+\t\tend else begin
+\t\t\tif(counter_writedirection == 4'b0001)
+\t\t\t\tdirection <= 1'b0;
+\t\t\tif(direction)
+\t\t\t\tcounter_writedirection <= counter_writedirection - 4'd1;
+\t\tend
+\tend
+end
+
+assign direction_r = write|(|counter_writedirection);
+
+/* Counters that prevent a busy bank from being precharged */
+hpdmc_banktimer banktimer0(
+\t.sys_clk(sys_clk),
+\t.sdram_rst(sdram_rst),
+\t
+\t.tim_cas(tim_cas),
+\t.tim_wr(tim_wr),
+\t
+\t.read(read & concerned_bank[0]),
+\t.write(write & concerned_bank[0]),
+\t.precharge_safe(precharge_safe[0])
+);
+hpdmc_banktimer banktimer1(
+\t.sys_clk(sys_clk),
+\t.sdram_rst(sdram_rst),
+\t
+\t.tim_cas(tim_cas),
+\t.tim_wr(tim_wr),
+\t
+\t.read(read & concerned_bank[1]),
+\t.write(write & concerned_bank[1]),
+\t.precharge_safe(precharge_safe[1])
+);
+hpdmc_banktimer banktimer2(
+\t.sys_clk(sys_clk),
+\t.sdram_rst(sdram_rst),
+\t
+\t.tim_cas(tim_cas),
+\t.tim_wr(tim_wr),
+\t
+\t.read(read & concerned_bank[2]),
+\t.write(write & concerned_bank[2]),
+\t.precharge_safe(precharge_safe[2])
+);
+hpdmc_banktimer banktimer3(
+\t.sys_clk(sys_clk),
+\t.sdram_rst(sdram_rst),
+\t
+\t.tim_cas(tim_cas),
+\t.tim_wr(tim_wr),
+\t
+\t.read(read & concerned_bank[3]),
+\t.write(write & concerned_bank[3]),
+\t.precharge_safe(precharge_safe[3])
+);
+
+endmodule
+"
+"/*\r
+ * DUT VGA Address Generation\r
+ *\r
+ * VGA FML support\r
+ * Copyright (C) 2013 Charley Picker \r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+//`timescale 1ns/10ps\r
+`timescale 1ns/1ps\r
+\r
+module tb_vga_linear_fml;\r
+\r
+ // Registers and nets\r
+ reg clk_50;\r
+ reg rst;\r
+ \r
+ reg enable_sequencer;\r
+ reg enable_crtc;\r
+ \r
+ // Sequencer input signals\r
+ \r
+ reg [9:0] h_count;\r
+ reg horiz_sync_i;\r
+ \r
+ reg [9:0] v_count;\r
+ reg vert_sync;\r
+ \r
+ reg video_on_h_i;\r
+ reg video_on_v;\r
+ \r
+ // CRTC configuration signals\r
+ \r
+ reg [6:0] horiz_total;\r
+ reg [6:0] end_horiz;\r
+ reg [6:0] st_hor_retr;\r
+ reg [4:0] end_hor_retr;\r
+ reg [9:0] vert_total;\r
+ reg [9:0] end_vert;\r
+ reg [9:0] st_ver_retr;\r
+ reg [3:0] end_ver_retr; \r
+ \r
+ // CSR slave interface for reading\r
+ wire [17:1] csr_adr_o;\r
+ reg [15:0] csr_dat_i;\r
+ reg csr_ack;\r
+ wire csr_stb_o;\r
+ \r
+ // FML slave interface for reading\r
+ wire [17:1] fml_adr_o;\r
+ reg [15:0] fml_dat_i;\r
+ wire fml_stb_o;\r
+ reg fml_ack;\r
+ wire fml_we = 1\'b0;\r
+ wire fml_dw = 16\'h1234;\r
+ \r
+ wire [7:0] fml_color;\r
+ wire [7:0] color;\r
+ \r
+ wire video_on_h_gm;\r
+ wire fml_video_on_h_gm; \r
+ \r
+ wire horiz_sync_gm;\r
+ wire fml_horiz_sync_gm; \r
+\r
+ wire [17:1] csr_gm_adr_o;\r
+ wire [17:1] fml_gm_adr_o;\r
+ wire csr_gm_stb_o;\r
+ \r
+ wire fml_gm_stb_o;\r
+ \r
+ wire [9:0] hor_disp_end;\r
+ wire [9:0] hor_scan_end;\r
+ wire [9:0] ver_disp_end;\r
+ wire [9:0] ver_sync_beg;\r
+ wire [3:0] ver_sync_end;\r
+ wire [9:0] ver_scan_end;\r
+ \r
+ /* Process FML requests */\r
+ reg [2:0] fml_wcount;\r
+ reg [2:0] fml_rcount;\r
+ reg [3:0] fml_pipe;\r
+ initial begin\r
+\t fml_ack = 1\'b0;\r
+\t fml_wcount = 0;\r
+\t fml_rcount = 0;\r
+ end\r
+ \r
+ always @(posedge clk_50)\r
+ fml_pipe <= rst ? 4\'b0 : { fml_pipe[2:0], fml_gm_stb_o };\r
+\r
+ always @(posedge clk_50) begin\r
+\t if(fml_pipe[1] & (fml_wcount == 0) & (fml_rcount == 0)) begin\r
+\t\t fml_ack <= 1\'b1;\r
+\t\t if(fml_we) begin\r
+\t\t\t //$display(""%t FML W addr %x data %x"", $time, fml_gm_adr_o, fml_dw);\r
+\t\t\t fml_wcount <= 7;\r
+\t\t end else begin\r
+\t\t\t //fml_dat_i = 16\'hbeef;\r
+\t\t\t fml_dat_i <= 16\'hbeef;\r
+\t\t\t //$display(""%t FML R addr %x data %x"", $time, fml_gm_adr_o, fml_dat_i);\r
+\t\t\t fml_rcount <= 7;\r
+\t\t end\r
+\t end else\r
+\t\t fml_ack <= 1\'b0;\r
+\t if(fml_wcount != 0) begin\r
+\t\t //#1 $display(""%t FML W continuing %x / %d"", $time, fml_dw, fml_wcount);\r
+\t\t fml_wcount <= fml_wcount - 1;\r
+\t end\r
+\t if(fml_rcount != 0) begin\r
+\t\t //fml_dat_i = #1 {13\'h1eba, fml_rcount};\r
+\t\t fml_dat_i <= {13\'h1eba, fml_rcount};\r
+\t\t //$display(""%t FML R continuing %x / %d"", $time, fml_dat_i, fml_rcount);\r
+\t\t fml_rcount <= fml_rcount - 1;\r
+\t end\r
+ end\r
+ \r
+ /* Process CSR requests */\r
+ reg [15:0] csr_dat;\r
+ reg [2:0] csr_rcount;\r
+ reg [3:0] csr_pipe;\r
+ initial begin\r
+\t csr_ack = 1\'b0;\t \r
+\t csr_rcount = 0;\r
+ end\r
+ \r
+ always @(posedge clk_50)\r
+ csr_pipe <= rst ? 4\'b0 : { csr_pipe[2:0], csr_gm_stb_o };\r
+\r
+ always @(posedge clk_50) begin\r
+ //if (csr_gm_adr_o)\r
+ //$display(""%t CSR R addr %x"", $time, csr_gm_adr_o);\r
+ if (csr_pipe[1] & (csr_rcount == 0))\r
+ begin\r
+ csr_ack <= 1\'b1;\r
+\t\t //csr_dat_i = 16\'hbeef;\r
+\t\t csr_dat_i <= 16\'hbeef;\r
+\t\t\t //$display(""%t CSR R data %x"", $time, csr_dat_i);\r
+\t\t\t csr_rcount <= 7;\r
+\t\t end else\r
+\t\t csr_ack <= 1\'b0;\t\t\r
+\t if(csr_pipe[1] & (csr_rcount != 0)) begin\r
+\t\t //csr_dat_i = #1 {13\'h1eba, csr_rcount};\r
+\t\t csr_dat_i <= {13\'h1eba, csr_rcount};\r
+\t\t //$display(""%t CSR R continuing %x / %d"", $time, csr_dat_i, csr_rcount);\r
+\t\t csr_rcount <= csr_rcount - 1;\r
+\t end\t \r
+ end\r
+ \r
+ // Module instantiations\r
+ vga_linear linear (\r
+ .clk (clk_50),\r
+ .rst (rst),\r
+ \r
+ //.enable (enable_sequencer),\r
+\r
+ // CSR slave interface for reading\r
+ .csr_adr_o (csr_gm_adr_o),\r
+ .csr_dat_i (csr_dat_i),\r
+ .csr_stb_o (csr_gm_stb_o),\r
+\r
+ .h_count (h_count),\r
+ .v_count (v_count),\r
+ .horiz_sync_i (horiz_sync_i),\r
+ .video_on_h_i (video_on_h_i),\r
+ .video_on_h_o (video_on_h_gm),\r
+\r
+ .color (color),\r
+ .horiz_sync_o (horiz_sync_gm)\r
+ );\r
+ \r
+ vga_linear_fml linear_fml (\r
+ .clk (clk_50),\r
+ .rst (rst),\r
+ \r
+ .enable (enable_sequencer),\r
+\r
+ // CSR slave interface for reading\r
+ .fml_adr_o (fml_gm_adr_o),\r
+ .fml_dat_i (fml_dat_i),\r
+ .fml_stb_o (fml_gm_stb_o),\r
+\r
+ .h_count (h_count),\r
+ .v_count (v_count),\r
+ .horiz_sync_i (horiz_sync_i),\r
+ .video_on_h_i (video_on_h_i),\r
+ .video_on_h_o (fml_video_on_h_gm),\r
+\r
+ .color (fml_color),\r
+ .horiz_sync_o (fml_horiz_sync_gm)\r
+ );\r
+ \r
+ \r
+ // Continuous assignments\r
+ // assign hor_scan_end = { horiz_total[6:2] + 1\'b1, horiz_total[1:0], 3\'h7 };\r
+ assign hor_scan_end = 10\'d799;\r
+ \r
+ // assign hor_disp_end = { end_horiz, 3\'h7 };\r
+ assign hor_disp_end = 10\'d639;\r
+ \r
+ // assign ver_scan_end = vert_total + 10\'d1;\r
+ assign ver_scan_end = 10\'d448;\r
+ \r
+ // assign ver_disp_end = end_vert + 10\'d1;\r
+ assign ver_disp_end = 10\'d400;\r
+ \r
+ assign ver_sync_beg = st_ver_retr;\r
+ \r
+ assign ver_sync_end = end_ver_retr + 4\'d1;\r
+ \r
+ // Behaviour\r
+ // Clock generation\r
+ //always #10 clk_50 <= !clk_50;\r
+ initial clk_50 = 1\'b0;\r
+ always #5 clk_50 = ~clk_50;\r
+ \r
+task waitclock;\r
+begin\r
+\t@(posedge clk_50);\r
+\t#1;\r
+end\r
+endtask\r
+\r
+always @(posedge clk_50) begin\r
+ if (rst) begin\r
+ h_count = 10\'b0;\r
+ horiz_sync_i = 1\'b1;\r
+ v_count = 10\'b0;\r
+ vert_sync = 1\'b1;\r
+ video_on_h_i = 1\'b1;\r
+ video_on_v = 1\'b1;\r
+ $display(""Pixel counter reset to zero"");\r
+ end else\r
+ begin\r
+ if (enable_crtc)\r
+ begin\r
+ h_count <= (h_count==hor_scan_end) ? 10\'b0 : h_count + 10\'b1;\r
+ horiz_sync_i <= horiz_sync_i ? (h_count[9:3]!=st_hor_retr)\r
+ : (h_count[7:3]==end_hor_retr);\r
+ v_count <= (v_count==ver_scan_end && h_count==hor_scan_end) ? 10\'b0\r
+ : ((h_count==hor_scan_end) ? v_count + 10\'b1 : v_count);\r
+ vert_sync <= vert_sync ? (v_count!=ver_sync_beg)\r
+ : (v_count[3:0]==ver_sync_end);\r
+\r
+ video_on_h_i <= (h_count==hor_scan_end) ? 1\'b1\r
+ : ((h_count==hor_disp_end) ? 1\'b0 : video_on_h_i);\r
+ video_on_v <= (v_count==10\'h0) ? 1\'b1\r
+ : ((v_count==ver_disp_end) ? 1\'b0 : video_on_v);\r
+ end\r
+ end \r
+end \r
+ \r
+always begin\r
+ // Initialize to a known state\r
+ rst = 1\'b1; // reset is active \r
+ enable_crtc = 1\'b0; // Make sure the crtc is not active\r
+ enable_sequencer = 1\'b0; // Make sure sequencer is not active\r
+ \r
+ waitclock; \r
+ \r
+ rst = 1\'b0;\r
+ \r
+ enable_crtc = 1\'b1; // Enable crtc\r
+ enable_sequencer = 1\'b1; // Enable sequencer \r
+ \r
+ waitclock;\r
+ \r
+ // CRTC configuration signals\r
+ \r
+ horiz_total = 7\'d639; // reg [6:0] horiz_total,\r
+ end_horiz = 7\'d750; // reg [6:0] end_horiz,\r
+ // st_hor_retr = 7\'d760; // reg [6:0] st_hor_retr,\r
+ st_hor_retr = 7\'d656; // reg [6:0] st_hor_retr,\r
+ // end_hor_retr = 5\'d10; // reg [4:0] end_hor_retr,\r
+ end_hor_retr = 5\'d752; // reg [4:0] end_hor_retr,\r
+ vert_total = 10\'d399; // reg [9:0] vert_total,\r
+ end_vert = 10\'d550; // reg [9:0] end_vert,\r
+ st_ver_retr = 10\'d560; // reg [9:0] st_ver_retr,\r
+ end_ver_retr = 4\'d10; // reg [3:0] end_ver_retr,\r
+ \r
+ //waitclock;\r
+ \r
+ // Total number of pixels to check\r
+ repeat (1000) begin\r
+ begin\r
+ if (color != fml_color) begin \r
+ $display(""Attributes color = %x and fml_color = %x did not match at (h_count = %d and v_count = %d) at time index %t"" , color, fml_color, h_count, v_count, $time); \r
+ end\r
+ //if (csr_gm_adr_o != fml_gm_adr_o) begin\r
+ // $display(""Address csr_gm_adr_o = %x and fml_gm_adr_o = %x did not match at (h_count = %d and v_count = %d) at time index %t"" , csr_gm_adr_o, fml_gm_adr_o, h_count, v_count, $time); \r
+ //end\r
+ if (video_on_h_gm != fml_video_on_h_gm) begin\r
+ $display(""Video_on_h video_on_h_gm = %x and fml_video_on_h_gm = %x did not match at (h_count = %d and v_count = %d) at time index %t"" , csr_gm_adr_o, fml_video_on_h_gm, h_count, v_count, $time);\r
+ end\r
+ if (horiz_sync_gm != fml_horiz_sync_gm) begin\r
+ $display(""Horiz_sync horiz_sync_gm = %x and fml_horiz_sync_gm = %x did not match at (h_count = %d and v_count = %d) at time index %t"" , horiz_sync_gm, fml_horiz_sync_gm, h_count, v_count, $time);\r
+ end\r
+ end\r
+ waitclock;\r
+ //nextpixel;\r
+ end \r
+ \r
+ $stop;\r
+ \r
+end \r
+\r
+endmodule"
+"/*
+ * This module accepts incoming data from PS2 interface
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module ps2_mouse_datain (
+ input clk,
+ input reset,
+ input wait_for_incoming_data,
+ input start_receiving_data,
+ input ps2_clk_posedge,
+ input ps2_clk_negedge,
+ input ps2_data,
+ output reg [7:0] received_data,
+ output reg received_data_en // If 1, new data has been received
+ );
+
+ // --------------------------------------------------------------------
+ // Constant Declarations
+ // --------------------------------------------------------------------
+ localparam PS2_STATE_0_IDLE = 3'h0,
+ PS2_STATE_1_WAIT_FOR_DATA = 3'h1,
+ PS2_STATE_2_DATA_IN = 3'h2,
+ PS2_STATE_3_PARITY_IN = 3'h3,
+ PS2_STATE_4_STOP_IN = 3'h4;
+
+ // --------------------------------------------------------------------
+ // Internal wires and registers Declarations
+ // --------------------------------------------------------------------
+ reg [3:0] data_count;
+ reg [7:0] data_shift_reg;
+
+ // State Machine Registers
+ reg [2:0] ns_ps2_receiver;
+ reg [2:0] s_ps2_receiver;
+
+ // --------------------------------------------------------------------
+ // Finite State Machine(s)
+ // --------------------------------------------------------------------
+ always @(posedge clk) begin
+ if (reset == 1'b1) s_ps2_receiver <= PS2_STATE_0_IDLE;
+ else s_ps2_receiver <= ns_ps2_receiver;
+ end
+
+ always @(*) begin // Defaults
+ ns_ps2_receiver = PS2_STATE_0_IDLE;
+
+ case (s_ps2_receiver)
+ PS2_STATE_0_IDLE:
+ begin
+ if((wait_for_incoming_data == 1'b1) && (received_data_en == 1'b0))
+ ns_ps2_receiver = PS2_STATE_1_WAIT_FOR_DATA;
+ else if ((start_receiving_data == 1'b1) && (received_data_en == 1'b0))
+ ns_ps2_receiver = PS2_STATE_2_DATA_IN;
+ else ns_ps2_receiver = PS2_STATE_0_IDLE;
+ end
+ PS2_STATE_1_WAIT_FOR_DATA:
+ begin
+ if((ps2_data == 1'b0) && (ps2_clk_posedge == 1'b1))
+ ns_ps2_receiver = PS2_STATE_2_DATA_IN;
+ else if (wait_for_incoming_data == 1'b0)
+ ns_ps2_receiver = PS2_STATE_0_IDLE;
+ else
+ ns_ps2_receiver = PS2_STATE_1_WAIT_FOR_DATA;
+ end
+ PS2_STATE_2_DATA_IN:
+ begin
+ if((data_count == 3'h7) && (ps2_clk_posedge == 1'b1))
+ ns_ps2_receiver = PS2_STATE_3_PARITY_IN;
+ else
+ ns_ps2_receiver = PS2_STATE_2_DATA_IN;
+ end
+ PS2_STATE_3_PARITY_IN:
+ begin
+ if (ps2_clk_posedge == 1'b1)
+ ns_ps2_receiver = PS2_STATE_4_STOP_IN;
+ else
+ ns_ps2_receiver = PS2_STATE_3_PARITY_IN;
+ end
+ PS2_STATE_4_STOP_IN:
+ begin
+ if (ps2_clk_posedge == 1'b1)
+ ns_ps2_receiver = PS2_STATE_0_IDLE;
+ else
+ ns_ps2_receiver = PS2_STATE_4_STOP_IN;
+ end
+ default:
+ begin
+ ns_ps2_receiver = PS2_STATE_0_IDLE;
+ end
+ endcase
+ end
+
+ // --------------------------------------------------------------------
+ // Sequential logic
+ // --------------------------------------------------------------------
+ always @(posedge clk) begin
+ if (reset == 1'b1) data_count <= 3'h0;
+ else if((s_ps2_receiver == PS2_STATE_2_DATA_IN) && (ps2_clk_posedge == 1'b1))
+ data_count <= data_count + 3'h1;
+ else if(s_ps2_receiver != PS2_STATE_2_DATA_IN)
+ data_count <= 3'h0;
+ end
+
+ always @(posedge clk) begin
+ if(reset == 1'b1) data_shift_reg <= 8'h00;
+ else if((s_ps2_receiver == PS2_STATE_2_DATA_IN) && (ps2_clk_posedge == 1'b1))
+ data_shift_reg <= {ps2_data, data_shift_reg[7:1]};
+ end
+
+ always @(posedge clk) begin
+ if(reset == 1'b1) received_data <= 8'h00;
+ else if(s_ps2_receiver == PS2_STATE_4_STOP_IN)
+ received_data <= data_shift_reg;
+ end
+
+ always @(posedge clk) begin
+ if(reset == 1'b1) received_data_en <= 1'b0;
+ else if((s_ps2_receiver == PS2_STATE_4_STOP_IN) && (ps2_clk_posedge == 1'b1))
+ received_data_en <= 1'b1;
+ else
+ received_data_en <= 1'b0;
+ end
+
+endmodule
+"
+"/*
+ * Add / substract unit for Zet
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_addsub (
+ input [15:0] x,
+ input [15:0] y,
+ output [15:0] out,
+ input [ 2:0] f,
+ input word_op,
+ input cfi,
+ output cfo,
+ output afo,
+ output ofo
+ );
+
+ // Net declarations
+ wire [15:0] op2;
+
+ wire ci;
+ wire cfoadd;
+ wire xs, ys, os;
+
+ // Module instances
+ zet_fulladd16 fulladd16 ( // We instantiate only one adder
+ .x (x), // to have less hardware
+ .y (op2),
+ .ci (ci),
+ .co (cfoadd),
+ .z (out),
+ .s (f[2])
+ );
+
+ // Assignments
+ assign op2 = f[2] ? ~y
+ : ((f[1:0]==2'b11) ? { 8'b0, y[7:0] } : y);
+ assign ci = f[2] & f[1] | f[2] & ~f[0] & ~cfi
+ | f[2] & f[0] | (f==3'b0) & cfi;
+ assign afo = f[1] ? (f[2] ? &out[3:0] : ~|out[3:0] )
+ : (x[4] ^ y[4] ^ out[4]);
+ assign cfo = f[1] ? cfi /* inc, dec */
+ : (word_op ? cfoadd : (x[8]^y[8]^out[8]));
+
+ assign xs = word_op ? x[15] : x[7];
+ assign ys = word_op ? y[15] : y[7];
+ assign os = word_op ? out[15] : out[7];
+ assign ofo = f[2] ? (~xs & ys & os | xs & ~ys & ~os)
+ : (~xs & ~ys & os | xs & ys & ~os);
+endmodule
+"
+"/*
+ * Module for performing other ALU operations
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_othop (x, y, seg, off, iflags, func, word_op, out, oflags);
+ // IO ports
+ input [15:0] x, y, off, seg, iflags;
+ input [2:0] func;
+ input word_op;
+ output [19:0] out;
+ output [8:0] oflags;
+
+ // Net declarations
+ wire [15:0] deff, deff2, outf, clcm, setf, intf, strf;
+ wire [19:0] dcmp, dcmp2;
+ wire dfi;
+
+ // Module instantiations
+ zet_mux8_16 mux8_16 (func, dcmp[15:0], dcmp2[15:0], deff, outf, clcm, setf,
+ intf, strf, out[15:0]);
+ assign out[19:16] = func ? dcmp2[19:16] : dcmp[19:16];
+
+ // Assignments
+ assign dcmp = (seg << 4) + deff;
+ assign dcmp2 = (seg << 4) + deff2;
+ assign deff = x + y + off;
+ assign deff2 = x + y + off + 16'd2;
+ assign outf = y;
+ assign clcm = y[2] ? (y[1] ? /* -1: clc */ {iflags[15:1], 1'b0}
+ : /* 4: cld */ {iflags[15:11], 1'b0, iflags[9:0]})
+ : (y[1] ? /* 2: cli */ {iflags[15:10], 1'b0, iflags[8:0]}
+ : /* 0: cmc */ {iflags[15:1], ~iflags[0]});
+ assign setf = y[2] ? (y[1] ? /* -1: stc */ {iflags[15:1], 1'b1}
+ : /* 4: std */ {iflags[15:11], 1'b1, iflags[9:0]})
+ : (y[1] ? /* 2: sti */ {iflags[15:10], 1'b1, iflags[8:0]}
+ : /* 0: outf */ iflags);
+
+ assign intf = {iflags[15:10], 2'b0, iflags[7:0]};
+ assign dfi = iflags[10];
+ assign strf = dfi ? (x - y) : (x + y);
+
+ assign oflags = word_op ? { out[11:6], out[4], out[2], out[0] }
+ : { iflags[11:8], out[7:6], out[4], out[2], out[0] };
+endmodule
+"
+"//////////////////////////////////////////////////////////////////////////////
+// File name : s29al032d_00.v
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 2005 Spansion, LLC.
+//
+// MODIFICATION HISTORY :
+//
+//
+// version: | author: | mod date: | changes made:
+// V1.0 D.Lukovic 05 May 17 Initial release
+//
+//////////////////////////////////////////////////////////////////////////////
+//
+// PART DESCRIPTION:
+//
+// Library: FLASH
+// Technology: Flash memory
+// Part: s29al032d_00
+//
+// Description: 32Mbit (4M x 8-Bit) Flash Memory
+//
+//
+//
+///////////////////////////////////////////////////////////////////////////////
+// Known Bugs:
+//
+///////////////////////////////////////////////////////////////////////////////
+`timescale 1 ns/1 ns
+
+module s29al032d_00
+(
+ A21 ,
+ A20 ,
+ A19 ,
+ A18 ,
+ A17 ,
+ A16 ,
+ A15 ,
+ A14 ,
+ A13 ,
+ A12 ,
+ A11 ,
+ A10 ,
+ A9 ,
+ A8 ,
+ A7 ,
+ A6 ,
+ A5 ,
+ A4 ,
+ A3 ,
+ A2 ,
+ A1 ,
+ A0 ,
+
+ DQ7 ,
+ DQ6 ,
+ DQ5 ,
+ DQ4 ,
+ DQ3 ,
+ DQ2 ,
+ DQ1 ,
+ DQ0 ,
+
+ CENeg ,
+ OENeg ,
+ WENeg ,
+ RESETNeg ,
+ ACC ,
+ RY
+
+);
+
+////////////////////////////////////////////////////////////////////////
+// Port / Part Pin Declarations
+////////////////////////////////////////////////////////////////////////
+
+ input A21 ;
+ input A20 ;
+ input A19 ;
+ input A18 ;
+ input A17 ;
+ input A16 ;
+ input A15 ;
+ input A14 ;
+ input A13 ;
+ input A12 ;
+ input A11 ;
+ input A10 ;
+ input A9 ;
+ input A8 ;
+ input A7 ;
+ input A6 ;
+ input A5 ;
+ input A4 ;
+ input A3 ;
+ input A2 ;
+ input A1 ;
+ input A0 ;
+
+ inout DQ7 ;
+ inout DQ6 ;
+ inout DQ5 ;
+ inout DQ4 ;
+ inout DQ3 ;
+ inout DQ2 ;
+ inout DQ1 ;
+ inout DQ0 ;
+
+ input CENeg ;
+ input OENeg ;
+ input WENeg ;
+ input RESETNeg ;
+ input ACC ;
+ output RY ;
+
+// interconnect path delay signals
+
+ wire A21_ipd ;
+ wire A20_ipd ;
+ wire A19_ipd ;
+ wire A18_ipd ;
+ wire A17_ipd ;
+ wire A16_ipd ;
+ wire A15_ipd ;
+ wire A14_ipd ;
+ wire A13_ipd ;
+ wire A12_ipd ;
+ wire A11_ipd ;
+ wire A10_ipd ;
+ wire A9_ipd ;
+ wire A8_ipd ;
+ wire A7_ipd ;
+ wire A6_ipd ;
+ wire A5_ipd ;
+ wire A4_ipd ;
+ wire A3_ipd ;
+ wire A2_ipd ;
+ wire A1_ipd ;
+ wire A0_ipd ;
+
+ wire [21 : 0] A;
+ assign A = {
+ A21_ipd,
+ A20_ipd,
+ A19_ipd,
+ A18_ipd,
+ A17_ipd,
+ A16_ipd,
+ A15_ipd,
+ A14_ipd,
+ A13_ipd,
+ A12_ipd,
+ A11_ipd,
+ A10_ipd,
+ A9_ipd,
+ A8_ipd,
+ A7_ipd,
+ A6_ipd,
+ A5_ipd,
+ A4_ipd,
+ A3_ipd,
+ A2_ipd,
+ A1_ipd,
+ A0_ipd };
+
+ wire DQ7_ipd ;
+ wire DQ6_ipd ;
+ wire DQ5_ipd ;
+ wire DQ4_ipd ;
+ wire DQ3_ipd ;
+ wire DQ2_ipd ;
+ wire DQ1_ipd ;
+ wire DQ0_ipd ;
+
+ wire [7 : 0 ] DIn;
+ assign DIn = {DQ7_ipd,
+ DQ6_ipd,
+ DQ5_ipd,
+ DQ4_ipd,
+ DQ3_ipd,
+ DQ2_ipd,
+ DQ1_ipd,
+ DQ0_ipd };
+
+ wire [7 : 0 ] DOut;
+ assign DOut = {DQ7,
+ DQ6,
+ DQ5,
+ DQ4,
+ DQ3,
+ DQ2,
+ DQ1,
+ DQ0 };
+
+ wire CENeg_ipd ;
+ wire OENeg_ipd ;
+ wire WENeg_ipd ;
+ wire RESETNeg_ipd ;
+ wire ACC_ipd ;
+ wire VIO_ipd ;
+
+// internal delays
+
+ reg HANG_out ; // Program/Erase Timing Limit
+ reg HANG_in ;
+ reg START_T1 ; // Start TimeOut
+ reg START_T1_in ;
+ reg CTMOUT ; // Sector Erase TimeOut
+ reg CTMOUT_in ;
+ reg READY_in ;
+ reg READY ; // Device ready after reset
+
+ reg [7 : 0] DOut_zd;
+ wire DQ7_Pass ;
+ wire DQ6_Pass ;
+ wire DQ5_Pass ;
+ wire DQ4_Pass ;
+ wire DQ3_Pass ;
+ wire DQ2_Pass ;
+ wire DQ1_Pass ;
+ wire DQ0_Pass ;
+
+ reg [7 : 0] DOut_Pass;
+ assign {DQ7_Pass,
+ DQ6_Pass,
+ DQ5_Pass,
+ DQ4_Pass,
+ DQ3_Pass,
+ DQ2_Pass,
+ DQ1_Pass,
+ DQ0_Pass } = DOut_Pass;
+
+ reg RY_zd;
+
+ parameter UserPreload = 1\'b0;
+ parameter mem_file_name = ""none"";
+ parameter prot_file_name = ""none"";
+ parameter secsi_file_name = ""none"";
+
+ parameter TimingModel = ""DefaultTimingModel"";
+
+ parameter DelayValues = ""FROM_PLI"";
+ parameter PartID = ""s29al032d"";
+ parameter MaxData = 255;
+ parameter SecSize = 65535;
+ parameter SecNum = 63;
+ parameter HiAddrBit = 21;
+ parameter SecSiSize = 255;
+
+ // powerup
+ reg PoweredUp;
+
+ //FSM control signals
+ reg ULBYPASS ; ////Unlock Bypass Active
+ reg ESP_ACT ; ////Erase Suspend
+ reg OTP_ACT ; ////SecSi Access
+
+ reg PDONE ; ////Prog. Done
+ reg PSTART ; ////Start Programming
+ //Program location is in protected sector
+ reg PERR ;
+
+ reg EDONE ; ////Ers. Done
+ reg ESTART ; ////Start Erase
+ reg ESUSP ; ////Suspend Erase
+ reg ERES ; ////Resume Erase
+ //All sectors selected for erasure are protected
+ reg EERR ;
+
+ //Sectors selected for erasure
+ reg [SecNum:0] Ers_queue; // = SecNum\'b0;
+
+ //Command Register
+ reg write ;
+ reg read ;
+
+ //Sector Address
+ integer SecAddr = 0;
+
+ integer SA = 0;
+
+ //Address within sector
+ integer Address = 0;
+ integer MemAddress = 0;
+ integer SecSiAddr = 0;
+
+ integer AS_ID = 0;
+ integer AS_SecSi_FP = 0;
+ integer AS_ID2 = 0;
+ //A19:A11 Don\'t Care
+ integer Addr ;
+
+ //glitch protection
+ wire gWE_n ;
+ wire gCE_n ;
+ wire gOE_n ;
+
+ reg RST ;
+ reg reseted ;
+
+ integer Mem[0:(SecNum+1)*(SecSize+1)-1];
+ //Sector Protection Status
+ reg [SecNum:0] Sec_Prot;
+
+ // timing check violation
+ reg Viol = 1\'b0;
+ // CFI query address
+ integer SecSi[0:SecSiSize];
+ integer CFI_array[16:79];
+
+ reg FactoryProt = 0;
+
+ integer WBData;
+ integer WBAddr;
+
+ reg oe = 1\'b0;
+ event oe_event;
+
+ event initOK;
+ event MergeE;
+
+ //Status reg.
+ reg[15:0] Status = 8\'b0;
+
+ reg[7:0] old_bit, new_bit;
+ integer old_int, new_int;
+ integer wr_cnt;
+ reg[7:0] temp;
+
+ integer S_ind = 0;
+ integer ind = 0;
+
+ integer i,j,k;
+
+ integer Debug;
+
+ //TPD_XX_DATA
+ time OEDQ_t;
+ time CEDQ_t;
+ time ADDRDQ_t;
+ time OENeg_event;
+ time CENeg_event;
+ time OENeg_posEvent;
+ time CENeg_posEvent;
+ time ADDR_event;
+ reg FROMOE;
+ reg FROMCE;
+ reg FROMADDR;
+ integer OEDQ_01;
+ integer CEDQ_01;
+ integer ADDRDQ_01;
+
+ reg[7:0] TempData;
+
+///////////////////////////////////////////////////////////////////////////////
+//Interconnect Path Delay Section
+///////////////////////////////////////////////////////////////////////////////
+ buf (A21_ipd, A21);
+ buf (A20_ipd, A20);
+ buf (A19_ipd, A19);
+ buf (A18_ipd, A18);
+ buf (A17_ipd, A17);
+ buf (A16_ipd, A16);
+ buf (A15_ipd, A15);
+ buf (A14_ipd, A14);
+ buf (A13_ipd, A13);
+ buf (A12_ipd, A12);
+ buf (A11_ipd, A11);
+ buf (A10_ipd, A10);
+ buf (A9_ipd , A9 );
+ buf (A8_ipd , A8 );
+ buf (A7_ipd , A7 );
+ buf (A6_ipd , A6 );
+ buf (A5_ipd , A5 );
+ buf (A4_ipd , A4 );
+ buf (A3_ipd , A3 );
+ buf (A2_ipd , A2 );
+ buf (A1_ipd , A1 );
+ buf (A0_ipd , A0 );
+
+ buf (DQ7_ipd , DQ7 );
+ buf (DQ6_ipd , DQ6 );
+ buf (DQ5_ipd , DQ5 );
+ buf (DQ4_ipd , DQ4 );
+ buf (DQ3_ipd , DQ3 );
+ buf (DQ2_ipd , DQ2 );
+ buf (DQ1_ipd , DQ1 );
+ buf (DQ0_ipd , DQ0 );
+
+ buf (CENeg_ipd , CENeg );
+ buf (OENeg_ipd , OENeg );
+ buf (WENeg_ipd , WENeg );
+ buf (RESETNeg_ipd , RESETNeg );
+ buf (ACC_ipd , ACC );
+///////////////////////////////////////////////////////////////////////////////
+// Propagation delay Section
+///////////////////////////////////////////////////////////////////////////////
+ nmos (DQ7 , DQ7_Pass , 1);
+ nmos (DQ6 , DQ6_Pass , 1);
+ nmos (DQ5 , DQ5_Pass , 1);
+ nmos (DQ4 , DQ4_Pass , 1);
+ nmos (DQ3 , DQ3_Pass , 1);
+ nmos (DQ2 , DQ2_Pass , 1);
+ nmos (DQ1 , DQ1_Pass , 1);
+ nmos (DQ0 , DQ0_Pass , 1);
+ nmos (RY , 1\'b0 , ~RY_zd);
+
+ wire deg;
+
+ //VHDL VITAL CheckEnable equivalents
+ // Address setup/hold near WE# falling edge
+ wire CheckEnable_A0_WE;
+ assign CheckEnable_A0_WE = ~CENeg && OENeg;
+ // Data setup/hold near WE# rising edge
+ wire CheckEnable_DQ0_WE;
+ assign CheckEnable_DQ0_WE = ~CENeg && OENeg && deg;
+ // Address setup/hold near CE# falling edge
+ wire CheckEnable_A0_CE;
+ assign CheckEnable_A0_CE = ~WENeg && OENeg;
+ // Data setup/hold near CE# rising edge
+ wire CheckEnable_DQ0_CE;
+ assign CheckEnable_DQ0_CE = ~WENeg && OENeg && deg;
+
+specify
+
+ // tipd delays: interconnect path delays , mapped to input port delays.
+ // In Verilog is not necessary to declare any tipd_ delay variables,
+ // they can be taken from SDF file
+ // With all the other delays real delays would be taken from SDF file
+
+ // tpd delays
+ specparam tpd_RESETNeg_DQ0 =1;
+ specparam tpd_A0_DQ0 =1;//tacc ok
+ specparam tpd_CENeg_DQ0 =1;//ok
+ //(tCE,tCE,tDF,-,tDF,-)
+ specparam tpd_OENeg_DQ0 =1;//ok
+ //(tOE,tOE,tDF,-,tDF,-)
+ specparam tpd_WENeg_RY =1; //tBUSY
+ specparam tpd_CENeg_RY =1; //tBUSY
+
+ // tsetup values: setup time
+ specparam tsetup_A0_WENeg =1; //tAS edge \\
+ specparam tsetup_DQ0_WENeg =1; //tDS edge /
+
+ // thold values: hold times
+ specparam thold_A0_WENeg =1; //tAH edge \\
+ specparam thold_DQ0_CENeg =1; //tDH edge /
+ specparam thold_OENeg_WENeg =1; //tOEH edge /
+ specparam thold_CENeg_RESETNeg =1; //tRH edge /
+ specparam thold_WENeg_OENeg =1; //tGHVL edge /
+
+ // tpw values: pulse width
+ specparam tpw_RESETNeg_negedge =1; //tRP
+ specparam tpw_WENeg_negedge =1; //tWP
+ specparam tpw_WENeg_posedge =1; //tWPH
+ specparam tpw_CENeg_negedge =1; //tCP
+ specparam tpw_CENeg_posedge =1; //tCEPH
+ specparam tpw_A0_negedge =1; //tWC tRC ok
+ specparam tpw_A0_posedge =1; //tWC tRC ok
+
+ // tdevice values: values for internal delays
+ //Program Operation
+ specparam tdevice_POB = 9000; //9 us;
+ //Sector Erase Operation
+ specparam tdevice_SEO = 700000000; //700 ms;
+ //Timing Limit Exceeded
+ specparam tdevice_HANG = 400000000; //400 ms;
+ //Erase suspend time
+ specparam tdevice_START_T1 = 20000; //20 us;
+ //sector erase command sequence timeout
+ specparam tdevice_CTMOUT = 50000; //50 us;
+ //device ready after Hardware reset(during embeded algorithm)
+ specparam tdevice_READY = 20000; //20 us; //tReady
+
+ // If tpd values are fetched from specify block, these parameters
+ // must change along with SDF values, SDF values change will NOT
+ // imlicitly apply here !
+ // If you want tpd values to be fetched by the model itself, please
+ // use the PLI routine approach but be shure to set parameter
+ // DelayValues to ""FROM_PLI"" as default
+
+///////////////////////////////////////////////////////////////////////////////
+// Input Port Delays don\'t require Verilog description
+///////////////////////////////////////////////////////////////////////////////
+// Path delays //
+///////////////////////////////////////////////////////////////////////////////
+//for DQ signals
+ if (FROMCE)
+ ( CENeg => DQ0 ) = tpd_CENeg_DQ0;
+ if (FROMCE)
+ ( CENeg => DQ1 ) = tpd_CENeg_DQ0;
+ if (FROMCE)
+ ( CENeg => DQ2 ) = tpd_CENeg_DQ0;
+ if (FROMCE)
+ ( CENeg => DQ3 ) = tpd_CENeg_DQ0;
+ if (FROMCE)
+ ( CENeg => DQ4 ) = tpd_CENeg_DQ0;
+ if (FROMCE)
+ ( CENeg => DQ5 ) = tpd_CENeg_DQ0;
+ if (FROMCE)
+ ( CENeg => DQ6 ) = tpd_CENeg_DQ0;
+ if (FROMCE)
+ ( CENeg => DQ7 ) = tpd_CENeg_DQ0;
+
+ if (FROMOE)
+ ( OENeg => DQ0 ) = tpd_OENeg_DQ0;
+ if (FROMOE)
+ ( OENeg => DQ1 ) = tpd_OENeg_DQ0;
+ if (FROMOE)
+ ( OENeg => DQ2 ) = tpd_OENeg_DQ0;
+ if (FROMOE)
+ ( OENeg => DQ3 ) = tpd_OENeg_DQ0;
+ if (FROMOE)
+ ( OENeg => DQ4 ) = tpd_OENeg_DQ0;
+ if (FROMOE)
+ ( OENeg => DQ5 ) = tpd_OENeg_DQ0;
+ if (FROMOE)
+ ( OENeg => DQ6 ) = tpd_OENeg_DQ0;
+ if (FROMOE)
+ ( OENeg => DQ7 ) = tpd_OENeg_DQ0;
+
+ if (FROMADDR)
+ ( A0 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A0 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A0 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A0 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A0 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A0 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A0 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A0 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A1 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A1 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A1 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A1 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A1 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A1 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A1 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A1 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A2 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A2 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A2 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A2 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A2 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A2 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A2 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A2 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A3 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A3 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A3 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A3 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A3 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A3 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A3 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A3 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A4 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A4 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A4 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A4 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A4 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A4 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A4 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A4 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A5 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A5 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A5 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A5 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A5 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A5 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A5 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A5 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A6 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A6 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A6 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A6 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A6 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A6 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A6 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A6 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A7 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A7 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A7 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A7 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A7 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A7 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A7 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A7 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A8 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A8 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A8 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A8 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A8 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A8 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A8 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A8 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A9 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A9 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A9 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A9 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A9 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A9 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A9 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A9 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A10 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A10 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A10 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A10 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A10 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A10 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A10 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A10 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A11 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A11 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A11 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A11 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A11 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A11 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A11 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A11 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A12 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A12 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A12 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A12 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A12 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A12 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A12 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A12 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A13 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A13 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A13 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A13 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A13 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A13 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A13 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A13 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A14 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A14 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A14 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A14 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A14 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A14 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A14 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A14 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A15 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A15 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A15 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A15 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A15 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A15 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A15 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A15 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A16 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A16 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A16 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A16 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A16 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A16 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A16 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A16 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A17 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A17 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A17 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A17 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A17 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A17 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A17 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A17 => DQ7 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A18 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A18 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A18 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A18 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A18 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A18 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A18 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A18 => DQ7 ) = tpd_A0_DQ0;
+
+ if (FROMADDR)
+ ( A19 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A19 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A19 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A19 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A19 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A19 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A19 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A19 => DQ7 ) = tpd_A0_DQ0;
+
+ if (FROMADDR)
+ ( A20 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A20 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A20 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A20 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A20 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A20 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A20 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A20 => DQ7 ) = tpd_A0_DQ0;
+
+ if (FROMADDR)
+ ( A21 => DQ0 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A21 => DQ1 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A21 => DQ2 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A21 => DQ3 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A21 => DQ4 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A21 => DQ5 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A21 => DQ6 ) = tpd_A0_DQ0;
+ if (FROMADDR)
+ ( A21 => DQ7 ) = tpd_A0_DQ0;
+
+ if (~RESETNeg)
+ ( RESETNeg => DQ0 ) = tpd_RESETNeg_DQ0;
+ if (~RESETNeg)
+ ( RESETNeg => DQ1 ) = tpd_RESETNeg_DQ0;
+ if (~RESETNeg)
+ ( RESETNeg => DQ2 ) = tpd_RESETNeg_DQ0;
+ if (~RESETNeg)
+ ( RESETNeg => DQ3 ) = tpd_RESETNeg_DQ0;
+ if (~RESETNeg)
+ ( RESETNeg => DQ4 ) = tpd_RESETNeg_DQ0;
+ if (~RESETNeg)
+ ( RESETNeg => DQ5 ) = tpd_RESETNeg_DQ0;
+ if (~RESETNeg)
+ ( RESETNeg => DQ6 ) = tpd_RESETNeg_DQ0;
+ if (~RESETNeg)
+ ( RESETNeg => DQ7 ) = tpd_RESETNeg_DQ0;
+
+//for RY signal
+ (WENeg => RY) = tpd_WENeg_RY;
+ (CENeg => RY) = tpd_CENeg_RY;
+
+////////////////////////////////////////////////////////////////////////////////
+// Timing Violation //
+////////////////////////////////////////////////////////////////////////////////
+
+ $setup ( A0 , negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A1 , negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A2 , negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A3 , negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A4 , negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A5 , negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A6 , negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A7 , negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A8 , negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A9 , negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A10, negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A11, negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A12, negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A13, negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A14, negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A15, negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A16, negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A17, negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A18, negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A19, negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A20, negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+ $setup ( A21, negedge CENeg &&& CheckEnable_A0_CE, tsetup_A0_WENeg, Viol);
+
+ $setup ( A0 , negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A1 , negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A2 , negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A3 , negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A4 , negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A5 , negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A6 , negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A7 , negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A8 , negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A9 , negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A10, negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A11, negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A12, negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A13, negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A14, negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A15, negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A16, negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A17, negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A18, negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A19, negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A20, negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+ $setup ( A21, negedge WENeg &&& CheckEnable_A0_WE, tsetup_A0_WENeg, Viol);
+
+ $setup ( DQ0, posedge CENeg&&&CheckEnable_DQ0_CE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ1, posedge CENeg&&&CheckEnable_DQ0_CE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ2, posedge CENeg&&&CheckEnable_DQ0_CE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ3, posedge CENeg&&&CheckEnable_DQ0_CE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ4, posedge CENeg&&&CheckEnable_DQ0_CE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ5, posedge CENeg&&&CheckEnable_DQ0_CE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ6, posedge CENeg&&&CheckEnable_DQ0_CE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ7, posedge CENeg&&&CheckEnable_DQ0_CE, tsetup_DQ0_WENeg, Viol);
+
+ $setup ( DQ0, posedge WENeg&&&CheckEnable_DQ0_WE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ1, posedge WENeg&&&CheckEnable_DQ0_WE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ2, posedge WENeg&&&CheckEnable_DQ0_WE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ3, posedge WENeg&&&CheckEnable_DQ0_WE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ4, posedge WENeg&&&CheckEnable_DQ0_WE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ5, posedge WENeg&&&CheckEnable_DQ0_WE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ6, posedge WENeg&&&CheckEnable_DQ0_WE, tsetup_DQ0_WENeg, Viol);
+ $setup ( DQ7, posedge WENeg&&&CheckEnable_DQ0_WE, tsetup_DQ0_WENeg, Viol);
+
+ $hold ( posedge RESETNeg&&&(CENeg===1), CENeg, thold_CENeg_RESETNeg, Viol);
+ $hold ( posedge RESETNeg&&&(OENeg===1), OENeg, thold_CENeg_RESETNeg, Viol);
+ $hold ( posedge RESETNeg&&&(WENeg===1), WENeg, thold_CENeg_RESETNeg, Viol);
+ $hold ( posedge OENeg, WENeg, thold_WENeg_OENeg, Viol);
+ $hold ( posedge WENeg, OENeg, thold_OENeg_WENeg, Viol);
+
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A0 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A1 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A2 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A3 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A4 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A5 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A6 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A7 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A9 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A10 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A11 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A12 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A13 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A14 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A15 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A16 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A17 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A18 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A19 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A20 , thold_A0_WENeg, Viol);
+ $hold ( negedge CENeg &&& CheckEnable_A0_CE, A21 , thold_A0_WENeg, Viol);
+
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A0 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A1 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A2 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A3 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A4 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A5 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A6 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A7 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A8 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A9 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A10 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A11 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A12 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A13 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A14 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A15 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A16 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A17 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A18 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A19 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A20 , thold_A0_WENeg, Viol);
+ $hold ( negedge WENeg &&& CheckEnable_A0_WE, A21 , thold_A0_WENeg, Viol);
+
+ $hold ( posedge CENeg &&& CheckEnable_DQ0_CE, DQ0, thold_DQ0_CENeg, Viol);
+ $hold ( posedge CENeg &&& CheckEnable_DQ0_CE, DQ1, thold_DQ0_CENeg, Viol);
+ $hold ( posedge CENeg &&& CheckEnable_DQ0_CE, DQ2, thold_DQ0_CENeg, Viol);
+ $hold ( posedge CENeg &&& CheckEnable_DQ0_CE, DQ3, thold_DQ0_CENeg, Viol);
+ $hold ( posedge CENeg &&& CheckEnable_DQ0_CE, DQ4, thold_DQ0_CENeg, Viol);
+ $hold ( posedge CENeg &&& CheckEnable_DQ0_CE, DQ5, thold_DQ0_CENeg, Viol);
+ $hold ( posedge CENeg &&& CheckEnable_DQ0_CE, DQ6, thold_DQ0_CENeg, Viol);
+ $hold ( posedge CENeg &&& CheckEnable_DQ0_CE, DQ7, thold_DQ0_CENeg, Viol);
+
+ $hold ( posedge WENeg &&& CheckEnable_DQ0_WE, DQ0, thold_DQ0_CENeg, Viol);
+ $hold ( posedge WENeg &&& CheckEnable_DQ0_WE, DQ1, thold_DQ0_CENeg, Viol);
+ $hold ( posedge WENeg &&& CheckEnable_DQ0_WE, DQ2, thold_DQ0_CENeg, Viol);
+ $hold ( posedge WENeg &&& CheckEnable_DQ0_WE, DQ3, thold_DQ0_CENeg, Viol);
+ $hold ( posedge WENeg &&& CheckEnable_DQ0_WE, DQ4, thold_DQ0_CENeg, Viol);
+ $hold ( posedge WENeg &&& CheckEnable_DQ0_WE, DQ5, thold_DQ0_CENeg, Viol);
+ $hold ( posedge WENeg &&& CheckEnable_DQ0_WE, DQ6, thold_DQ0_CENeg, Viol);
+ $hold ( posedge WENeg &&& CheckEnable_DQ0_WE, DQ7, thold_DQ0_CENeg, Viol);
+
+ $width (negedge RESETNeg, tpw_RESETNeg_negedge);
+ $width (posedge WENeg, tpw_WENeg_posedge);
+ $width (negedge WENeg, tpw_WENeg_negedge);
+ $width (posedge CENeg, tpw_CENeg_posedge);
+ $width (negedge CENeg, tpw_CENeg_negedge);
+ $width (negedge A0, tpw_A0_negedge);//ok
+ $width (negedge A1, tpw_A0_negedge);//ok
+ $width (negedge A2, tpw_A0_negedge);//ok
+ $width (negedge A3, tpw_A0_negedge);//ok
+ $width (negedge A4, tpw_A0_negedge);//ok
+ $width (negedge A5, tpw_A0_negedge);//ok
+ $width (negedge A6, tpw_A0_negedge);//ok
+ $width (negedge A7, tpw_A0_negedge);//ok
+ $width (negedge A8, tpw_A0_negedge);//ok
+ $width (negedge A9, tpw_A0_negedge);//ok
+ $width (negedge A10, tpw_A0_negedge);//ok
+ $width (negedge A11, tpw_A0_negedge);//ok
+ $width (negedge A12, tpw_A0_negedge);//ok
+ $width (negedge A13, tpw_A0_negedge);//ok
+ $width (negedge A14, tpw_A0_negedge);//ok
+ $width (negedge A15, tpw_A0_negedge);//ok
+ $width (negedge A16, tpw_A0_negedge);//ok
+ $width (negedge A17, tpw_A0_negedge);//ok
+ $width (negedge A18, tpw_A0_negedge);//ok
+ $width (negedge A19, tpw_A0_negedge);//ok
+ $width (negedge A20, tpw_A0_negedge);//ok
+ $width (negedge A21, tpw_A0_negedge);//ok
+ $width (posedge A0, tpw_A0_posedge);//ok
+ $width (posedge A1, tpw_A0_posedge);//ok
+ $width (posedge A2, tpw_A0_posedge);//ok
+ $width (posedge A3, tpw_A0_posedge);//ok
+ $width (posedge A4, tpw_A0_posedge);//ok
+ $width (posedge A5, tpw_A0_posedge);//ok
+ $width (posedge A6, tpw_A0_posedge);//ok
+ $width (posedge A7, tpw_A0_posedge);//ok
+ $width (posedge A8, tpw_A0_posedge);//ok
+ $width (posedge A9, tpw_A0_posedge);//ok
+ $width (posedge A10, tpw_A0_posedge);//ok
+ $width (posedge A11, tpw_A0_posedge);//ok
+ $width (posedge A12, tpw_A0_posedge);//ok
+ $width (posedge A13, tpw_A0_posedge);//ok
+ $width (posedge A14, tpw_A0_posedge);//ok
+ $width (posedge A15, tpw_A0_posedge);//ok
+ $width (posedge A16, tpw_A0_posedge);//ok
+ $width (posedge A17, tpw_A0_posedge);//ok
+ $width (posedge A18, tpw_A0_posedge);//ok
+ $width (posedge A19, tpw_A0_posedge);//ok
+ $width (posedge A20, tpw_A0_posedge);//ok
+ $width (posedge A21, tpw_A0_posedge);//ok
+
+ endspecify
+
+////////////////////////////////////////////////////////////////////////////////
+// Main Behavior Block //
+////////////////////////////////////////////////////////////////////////////////
+
+// FSM states
+ parameter RESET =6\'d0;
+ parameter Z001 =6\'d1;
+ parameter PREL_SETBWB =6\'d2;
+ parameter PREL_ULBYPASS =6\'d3;
+ parameter PREL_ULBYPASS_RESET =6\'d4;
+ parameter AS =6\'d5;
+ parameter A0SEEN =6\'d6;
+ parameter OTP =6\'d7;
+ parameter OTP_Z001 =6\'d8;
+ parameter OTP_PREL =6\'d9;
+ parameter OTP_AS =6\'d10;
+ parameter OTP_AS_CFI =6\'d11;
+ parameter OTP_A0SEEN =6\'d12;
+ parameter C8 =6\'d13;
+ parameter C8_Z001 =6\'d14;
+ parameter C8_PREL =6\'d15;
+ parameter ERS =6\'d16;
+ parameter SERS =6\'d17;
+ parameter ESPS =6\'d18;
+ parameter SERS_EXEC =6\'d19;
+ parameter ESP =6\'d20;
+ parameter ESP_Z001 =6\'d21;
+ parameter ESP_PREL =6\'d22;
+ parameter ESP_A0SEEN =6\'d23;
+ parameter ESP_AS =6\'d24;
+ parameter PGMS =6\'d25;
+ parameter CFI =6\'d26;
+ parameter AS_CFI =6\'d27;
+ parameter ESP_CFI =6\'d28;
+ parameter ESP_AS_CFI =6\'d29;
+
+ reg [5:0] current_state;
+ reg [5:0] next_state;
+
+ reg deq;
+
+ always @(DIn, DOut)
+ begin
+ if (DIn==DOut)
+ deq=1\'b1;
+ else
+ deq=1\'b0;
+ end
+ // check when data is generated from model to avoid setuphold check in
+ // those occasion
+ assign deg =deq;
+
+// initialize memory and load preoload files if any
+ initial
+ begin : NBlck
+ integer i,j;
+ integer tmp1,tmp2,tmp3;
+ integer secure_silicon[0:SecSiSize];
+ reg sector_prot[0:SecNum];
+
+ for (i=0;i<=((SecNum+1)*(SecSize+1)-1);i=i+1)
+ begin
+ Mem[i]=MaxData;
+ end
+ for (i=0;i<=SecSiSize;i=i+1)
+ begin
+ secure_silicon[i]=MaxData;
+ end
+ for (i=0;i<=SecNum;i=i+1)
+ begin
+ sector_prot[i]=0;
+ end
+ if (UserPreload && !(prot_file_name == ""none""))
+ begin
+ //s29al032d_00_prot sector protect file
+ // // - comment
+ // @aa - stands for sector address
+ // (aa is incremented at every load)
+ // b - is 1 for protected sector , 0 for unprotect.
+ $readmemb(prot_file_name,sector_prot);
+ end
+ if (UserPreload && !(mem_file_name == ""none""))
+ begin
+ //s29al032d_00_memory preload file
+ // @aaaaaa - stands for address within last defined sector
+ // dd - is byte to be written at Mem(nn)(aaaaaa++)
+ // (aaaaaa is incremented at every load)
+ $readmemh(mem_file_name,Mem);
+ end
+ if (UserPreload && !(secsi_file_name == ""none""))
+ begin
+ //s29al032d_00_secsi memory preload file
+ // @aaaa - stands for address within last defined sector
+ // dd - is byte to be written at Mem(nn)(aaaa++)
+ // (aaaa is incremented at every load)
+ $readmemh(secsi_file_name,secure_silicon);
+ end
+
+ for (i=0;i<=SecSiSize;i=i+1)
+ begin
+ SecSi[i] = secure_silicon[i];
+ end
+ for (i=0;i<=SecNum;i=i+1)
+ Ers_queue[i] = 0;
+ // every 4-group sectors protect bit must equel
+ for (i=0;i<=SecNum;i=i+1)
+ Sec_Prot[i] = sector_prot[i];
+
+ if ((Sec_Prot[3:0] != 4\'h0 && Sec_Prot[3:0] != 4\'hF)
+ || (Sec_Prot[7:4] != 4\'h0 && Sec_Prot[7:4] != 4\'hF)
+ || (Sec_Prot[11:8] != 4\'h0 && Sec_Prot[11:8] != 4\'hF)
+ || (Sec_Prot[15:12] != 4\'h0 && Sec_Prot[15:12] != 4\'hF)
+ || (Sec_Prot[19:16] != 4\'h0 && Sec_Prot[19:16] != 4\'hF)
+ || (Sec_Prot[23:20] != 4\'h0 && Sec_Prot[23:20] != 4\'hF)
+ || (Sec_Prot[27:24] != 4\'h0 && Sec_Prot[27:24] != 4\'hF)
+ || (Sec_Prot[31:28] != 4\'h0 && Sec_Prot[31:28] != 4\'hF)
+ || (Sec_Prot[35:32] != 4\'h0 && Sec_Prot[35:32] != 4\'hF)
+ || (Sec_Prot[39:36] != 4\'h0 && Sec_Prot[39:36] != 4\'hF)
+ || (Sec_Prot[43:40] != 4\'h0 && Sec_Prot[43:40] != 4\'hF)
+ || (Sec_Prot[47:44] != 4\'h0 && Sec_Prot[47:44] != 4\'hF)
+ || (Sec_Prot[51:48] != 4\'h0 && Sec_Prot[51:48] != 4\'hF)
+ || (Sec_Prot[55:52] != 4\'h0 && Sec_Prot[55:52] != 4\'hF)
+ || (Sec_Prot[59:56] != 4\'h0 && Sec_Prot[59:56] != 4\'hF)
+ || (Sec_Prot[63:60] != 4\'h0 && Sec_Prot[63:60] != 4\'hF))
+
+ $display(""Bad sector protect group preload"");
+
+ WBData = -1;
+
+ end
+
+ //Power Up time 100 ns;
+ initial
+ begin
+ PoweredUp = 1\'b0;
+ #100 PoweredUp = 1\'b1;
+ end
+
+ always @(RESETNeg)
+ begin
+ RST <= #499 RESETNeg;
+ end
+
+ initial
+ begin
+ write = 1\'b0;
+ read = 1\'b0;
+ Addr = 0;
+
+ ULBYPASS = 1\'b0;
+ ESP_ACT = 1\'b0;
+ OTP_ACT = 1\'b0;
+
+ PDONE = 1\'b1;
+ PSTART = 1\'b0;
+
+ PERR = 1\'b0;
+
+ EDONE = 1\'b1;
+ ESTART = 1\'b0;
+ ESUSP = 1\'b0;
+ ERES = 1\'b0;
+
+ EERR = 1\'b0;
+ READY_in = 1\'b0;
+ READY = 1\'b0;
+ end
+
+ always @(posedge START_T1_in)
+ begin:TESTARTT1r
+ #tdevice_START_T1 START_T1 = START_T1_in;
+ end
+ always @(negedge START_T1_in)
+ begin:TESTARTT1f
+ #1 START_T1 = START_T1_in;
+ end
+
+ always @(posedge CTMOUT_in)
+ begin:TCTMOUTr
+ #tdevice_CTMOUT CTMOUT = CTMOUT_in;
+ end
+ always @(negedge CTMOUT_in)
+ begin:TCTMOUTf
+ #1 CTMOUT = CTMOUT_in;
+ end
+
+ always @(posedge READY_in)
+ begin:TREADYr
+ #tdevice_READY READY = READY_in;
+ end
+ always @(negedge READY_in)
+ begin:TREADYf
+ #1 READY = READY_in;
+ end
+ ////////////////////////////////////////////////////////////////////////////
+ //// obtain \'LAST_EVENT information
+ ////////////////////////////////////////////////////////////////////////////
+ always @(negedge OENeg)
+ begin
+ OENeg_event = $time;
+ end
+ always @(negedge CENeg)
+ begin
+ CENeg_event = $time;
+ end
+
+ always @(posedge OENeg)
+ begin
+ OENeg_posEvent = $time;
+ end
+ always @(posedge CENeg)
+ begin
+ CENeg_posEvent = $time;
+ end
+
+ always @(A)
+ begin
+ ADDR_event = $time;
+ end
+
+ ////////////////////////////////////////////////////////////////////////////
+ //// sequential process for reset control and FSM state transition
+ ////////////////////////////////////////////////////////////////////////////
+ always @(negedge RST)
+ begin
+ ESP_ACT = 1\'b0;
+ ULBYPASS = 1\'b0;
+ OTP_ACT = 1\'b0;
+ end
+
+ reg R;
+ reg E;
+ always @(RESETNeg)
+ begin
+ if (PoweredUp)
+ begin
+ //Hardware reset timing control
+ if (~RESETNeg)
+ begin
+ E = 1\'b0;
+ if (~PDONE || ~EDONE)
+ begin
+ //if program or erase in progress
+ READY_in = 1\'b1;
+ R = 1\'b1;
+ end
+ else
+ begin
+ READY_in = 1\'b0;
+ R = 1\'b0; //prog or erase not in progress
+ end
+ end
+ else if (RESETNeg && RST)
+ begin
+ //RESET# pulse < tRP
+ READY_in = 1\'b0;
+ R = 1\'b0;
+ E = 1\'b1;
+ end
+ end
+ end
+
+ always @(next_state or RESETNeg or CENeg or RST or
+ READY or PoweredUp)
+ begin: StateTransition
+
+ if (PoweredUp)
+ begin
+ if (RESETNeg && (~R || (R && READY)))
+ begin
+ current_state = next_state;
+ READY_in = 1\'b0;
+ E = 1\'b0;
+ R = 1\'b0;
+ reseted = 1\'b1;
+ end
+ else if ((~R && ~RESETNeg && ~RST) ||
+ (R && ~RESETNeg && ~RST && ~READY) ||
+ (R && RESETNeg && ~RST && ~READY))
+ begin
+ //no state transition while RESET# low
+ current_state = RESET; //reset start
+ reseted = 1\'b0;
+ end
+ end
+ else
+ begin
+ current_state = RESET; // reset
+ reseted = 1\'b0;
+ E = 1\'b0;
+ R = 1\'b0;
+ end
+ end
+
+// /////////////////////////////////////////////////////////////////////////
+// //Glitch Protection: Inertial Delay does not propagate pulses <5ns
+// /////////////////////////////////////////////////////////////////////////
+ assign #5 gWE_n = WENeg_ipd;
+ assign #5 gCE_n = CENeg_ipd;
+ assign #5 gOE_n = OENeg_ipd;
+
+ ///////////////////////////////////////////////////////////////////////////
+ //Process that reports warning when changes on signals WE#, CE#, OE# are
+ //discarded
+ ///////////////////////////////////////////////////////////////////////////
+ always @(WENeg)
+ begin: PulseWatch1
+ if (gWE_n == WENeg)
+ $display(""Glitch on WE#"");
+ end
+ always @(CENeg)
+ begin: PulseWatch2
+ if (gCE_n == CENeg)
+ $display(""Glitch on CE#"");
+ end
+ always @(OENeg)
+ begin: PulseWatch3
+ if (gOE_n == OENeg)
+ $display(""Glitch on OE#"");
+ end
+
+ //latch address on rising edge and data on falling edge of write
+ always @(gWE_n or gCE_n or gOE_n )
+ begin: write_dc
+ if (RESETNeg!=1\'b0)
+ begin
+ if (~gWE_n && ~gCE_n && gOE_n)
+ write = 1\'b1;
+ else
+ write = 1\'b0;
+ end
+
+ if (gWE_n && ~gCE_n && ~gOE_n)
+ read = 1\'b1;
+ else
+ read = 1\'b0;
+ end
+
+ ///////////////////////////////////////////////////////////////////////////
+ ////Latch address on falling edge of WE# or CE# what ever comes later
+ ////Latch data on rising edge of WE# or CE# what ever comes first
+ //// also Write cycle decode
+ ////////////////////////////////////////////////////////////////////////////
+ integer A_tmp ;
+ integer SA_tmp ;
+ integer A_tmp1 ;
+ integer Mem_tmp;
+ integer AS_addr;
+ reg CE;
+
+ always @(WENeg_ipd)
+ begin
+ if (reseted)
+ begin
+ if (~WENeg_ipd && ~CENeg_ipd && OENeg_ipd )
+ begin
+ A_tmp = A[10:0];
+ SA_tmp = A[HiAddrBit:16];
+ A_tmp1 = A[15:0];
+ Mem_tmp = A;
+ AS_addr = A[21];
+ end
+ end
+ end
+
+ always @(CENeg_ipd)
+ begin
+ if (reseted)
+ begin
+ if (~CENeg_ipd && (WENeg_ipd != OENeg_ipd) )
+ begin
+ A_tmp = A[10:0];
+ SA_tmp = A[HiAddrBit:16];
+ A_tmp1 = A[15:0];
+ Mem_tmp = A;
+ AS_addr = A[21];
+ end
+ if (~CENeg_ipd && WENeg_ipd && ~OENeg_ipd)
+ begin
+ SecAddr = SA_tmp;
+ Address = A_tmp1;
+ MemAddress = Mem_tmp;
+ Addr = A_tmp;
+ end
+ end
+ end
+
+ always @(negedge OENeg_ipd )
+ begin
+ if (reseted)
+ begin
+ if (~OENeg_ipd && WENeg_ipd && ~CENeg_ipd)
+ begin
+ A_tmp = A[10:0];
+ SA_tmp = A[HiAddrBit:16];
+ A_tmp1 = A[15:0];
+ Mem_tmp = A;
+ SecAddr = SA_tmp;
+ Address = A_tmp1;
+ MemAddress = Mem_tmp;
+ Addr = A_tmp;
+ AS_addr = A[21];
+ end
+
+ SecAddr = SA_tmp;
+ Address = A_tmp1;
+ MemAddress = Mem_tmp;
+ CE = CENeg;
+ Addr = A_tmp;
+ end
+ end
+
+ always @(A)
+ begin
+ if (reseted)
+ if (WENeg_ipd && ~CENeg_ipd && ~OENeg_ipd)
+ begin
+ A_tmp = A[10:0];
+ SA_tmp = A[HiAddrBit:16];
+ A_tmp1 = A[15:0];
+ Mem_tmp = A;
+ AS_addr = A[21];
+ SecAddr = SA_tmp;
+ Address = A_tmp1;
+ MemAddress = Mem_tmp;
+ Addr = A_tmp;
+ CE = CENeg;
+ end
+ end
+
+ always @(posedge write)
+ begin
+ SecAddr = SA_tmp;
+ Address = A_tmp1;
+ MemAddress = Mem_tmp;
+ Addr = A_tmp;
+ CE = CENeg;
+ end
+
+///////////////////////////////////////////////////////////////////////////
+// Timing control for the Program Operations
+///////////////////////////////////////////////////////////////////////////
+
+ integer cnt_write = 0;
+ //time elapsed_write ;
+ time duration_write ;
+ //time start_write ;
+ event pdone_event;
+
+ always @(posedge reseted)
+ begin
+ PDONE = 1\'b1;
+ end
+
+ always @(reseted or PSTART)
+ begin
+ if (reseted)
+ begin
+ if (PSTART && PDONE)
+ begin
+ if ((~FactoryProt && OTP_ACT)||
+ ( ~Sec_Prot[SA] &&(~Ers_queue[SA] || ~ESP_ACT )&& ~OTP_ACT))
+ begin
+ duration_write = tdevice_POB + 5;
+ PDONE = 1\'b0;
+ ->pdone_event;
+ end
+ else
+ begin
+ PERR = 1\'b1;
+ PERR <= #1005 1\'b0;
+ end
+ end
+ end
+ end
+
+ always @(pdone_event)
+ begin:pdone_process
+ PDONE = 1\'b0;
+ #duration_write PDONE = 1\'b1;
+ end
+
+/////////////////////////////////////////////////////////////////////////
+// Timing control for the Erase Operations
+/////////////////////////////////////////////////////////////////////////
+ integer cnt_erase = 0;
+ time elapsed_erase;
+ time duration_erase;
+ time start_erase;
+
+ always @(posedge reseted)
+ begin
+ disable edone_process;
+ EDONE = 1\'b1;
+ end
+ event edone_event;
+ always @(reseted or ESTART)
+ begin: erase
+ integer i;
+ if (reseted)
+ begin
+ if (ESTART && EDONE)
+ begin
+ cnt_erase = 0;
+ for (i=0;i<=SecNum;i=i+1)
+ begin
+ if ((Ers_queue[i]==1\'b1) && (Sec_Prot[i]!=1\'b1))
+ cnt_erase = cnt_erase + 1;
+ end
+
+ if (cnt_erase>0)
+ begin
+ elapsed_erase = 0;
+ duration_erase = cnt_erase* tdevice_SEO + 4;
+ ->edone_event;
+ start_erase = $time;
+ end
+ else
+ begin
+ EERR = 1\'b1;
+ EERR <= #100005 1\'b0;
+ end
+ end
+ end
+ end
+
+ always @(edone_event)
+ begin : edone_process
+ EDONE = 1\'b0;
+ #duration_erase EDONE = 1\'b1;
+ end
+
+ always @(reseted or ESUSP)
+ begin
+ if (reseted)
+ if (ESUSP && ~EDONE)
+ begin
+ disable edone_process;
+ elapsed_erase = $time - start_erase;
+ duration_erase = duration_erase - elapsed_erase;
+ EDONE = 1\'b0;
+ end
+ end
+ always @(reseted or ERES)
+ begin
+ if (reseted)
+ if (ERES && ~EDONE)
+ begin
+ start_erase = $time;
+ EDONE = 1\'b0;
+ ->edone_event;
+ end
+ end
+
+// /////////////////////////////////////////////////////////////////////////
+// // Main Behavior Process
+// // combinational process for next state generation
+// /////////////////////////////////////////////////////////////////////////
+ reg PATTERN_1 = 1\'b0;
+ reg PATTERN_2 = 1\'b0;
+ reg A_PAT_1 = 1\'b0;
+ reg A_PAT_2 = 1\'b0;
+ reg A_PAT_3 = 1\'b0;
+ integer DataByte ;
+
+ always @(negedge write)
+ begin
+ DataByte = DIn;
+ PATTERN_1 = DataByte==8\'hAA ;
+ PATTERN_2 = DataByte==8\'h55 ;
+ A_PAT_1 = 1\'b1;
+ A_PAT_2 = Address==16\'hAAA ;
+ A_PAT_3 = Address==16\'h555 ;
+
+ end
+
+ always @(write or reseted)
+ begin: StateGen1
+ if (reseted!=1\'b1)
+ next_state 'b'= current_state;
+ else
+ if (~write)
+ case (current_state)
+ RESET :
+ begin
+ if (PATTERN_1)
+ next_state = Z001;
+ else if ((Addr==8\'h55) && (DataByte==8\'h98))
+ next_state = CFI;
+ else
+ next_state = RESET;
+ end
+
+ CFI:
+ begin
+ if (DataByte==8\'hF0)
+ next_state = RESET;
+ else
+ next_state = CFI;
+ end
+
+ Z001 :
+ begin
+ if (PATTERN_2)
+ next_state = PREL_SETBWB;
+ else
+ next_state = RESET;
+ end
+
+ PREL_SETBWB :
+ begin
+ if (A_PAT_1 && (DataByte==16\'h20))
+ next_state = PREL_ULBYPASS;
+ else if (A_PAT_1 && (DataByte==16\'h90))
+ next_state = AS;
+ else if (A_PAT_1 && (DataByte==16\'hA0))
+ next_state = A0SEEN;
+ else if (A_PAT_1 && (DataByte==16\'h80))
+ next_state = C8;
+ else if (A_PAT_1 && (DataByte==16\'h88))
+ next_state = OTP;
+ else
+ next_state = RESET;
+ end
+
+ PREL_ULBYPASS :
+ begin
+ if (DataByte == 16\'h90 )
+ next_state <= PREL_ULBYPASS_RESET;
+ if (A_PAT_1 && (DataByte == 16\'hA0))
+ next_state = A0SEEN;
+ else
+ next_state = PREL_ULBYPASS;
+ end
+
+ PREL_ULBYPASS_RESET :
+ begin
+ if (DataByte == 16\'h00 )
+ if (ESP_ACT)
+ next_state = ESP;
+ else
+ next_state = RESET;
+ else
+ next_state <= PREL_ULBYPASS;
+ end
+
+ AS :
+ begin
+ if (DataByte==16\'hF0)
+ next_state = RESET;
+ else if ((Addr==8\'h55) && (DataByte==8\'h98))
+ next_state = AS_CFI;
+ else
+ next_state = AS;
+ end
+
+ AS_CFI:
+ begin
+ if (DataByte==8\'hF0)
+ next_state = AS;
+ else
+ next_state = AS_CFI;
+ end
+
+ A0SEEN :
+ begin
+ next_state = PGMS;
+ end
+
+ OTP :
+ begin
+ if (PATTERN_1)
+ next_state = OTP_Z001;
+ else
+ next_state = OTP;
+ end
+
+ OTP_Z001 :
+ begin
+ if (PATTERN_2)
+ next_state = OTP_PREL;
+ else
+ next_state = OTP;
+ end
+
+ OTP_PREL :
+ begin
+ if (A_PAT_1 && (DataByte == 16\'h90))
+ next_state = OTP_AS;
+ else if (A_PAT_1 && (DataByte == 16\'hA0))
+ next_state = OTP_A0SEEN;
+ else
+ next_state = OTP;
+ end
+
+ OTP_AS:
+ begin
+ if (DataByte == 16\'h00)
+ if (ESP_ACT)
+ next_state = ESP;
+ else
+ next_state = RESET;
+ else if (DataByte == 16\'hF0)
+ next_state = OTP;
+ else if (DataByte == 16\'h98)
+ next_state = OTP_AS_CFI;
+ else
+ next_state = OTP_AS;
+ end
+
+ OTP_AS_CFI:
+ begin
+ if (DataByte == 16\'hF0)
+ next_state = OTP_AS;
+ else
+ next_state = OTP_AS_CFI;
+ end
+
+ OTP_A0SEEN :
+ begin
+ if ((SecAddr == 16\'h3F) && (Address <= 16\'hFFFF) &&
+ (Address >= 16\'hFF00))
+ next_state = PGMS;
+ else
+ next_state = OTP;
+ end
+
+ C8 :
+ begin
+ if (PATTERN_1)
+ next_state = C8_Z001;
+ else
+ next_state = RESET;
+ end
+
+ C8_Z001 :
+ begin
+ if (PATTERN_2)
+ next_state = C8_PREL;
+ else
+ next_state = RESET;
+ end
+
+ C8_PREL :
+ begin
+ if (A_PAT_1 && (DataByte==16\'h10))
+ next_state = ERS;
+ else if (DataByte==16\'h30)
+ next_state = SERS;
+ else
+ next_state = RESET;
+ end
+
+ ERS :
+ begin
+ end
+
+ SERS :
+ begin
+ if (~CTMOUT && DataByte == 16\'hB0)
+ next_state = ESP; // ESP according to datasheet
+ else if (DataByte==16\'h30)
+ next_state = SERS;
+ else
+ next_state = RESET;
+ end
+
+ SERS_EXEC :
+ begin
+ end
+
+ ESP :
+ begin
+ if (DataByte == 16\'h30)
+ next_state = SERS_EXEC;
+ else
+ begin
+ if (PATTERN_1)
+ next_state = ESP_Z001;
+ if (Addr == 8\'h55 && DataByte == 8\'h98)
+ next_state = ESP_CFI;
+ end
+ end
+
+ ESP_CFI:
+ begin
+ if (DataByte == 8\'hF0)
+ next_state = ESP;
+ else
+ next_state = ESP_CFI;
+ end
+
+ ESP_Z001 :
+ begin
+ if (PATTERN_2)
+ next_state = ESP_PREL;
+ else
+ next_state = ESP;
+ end
+
+ ESP_PREL :
+ begin
+ if (A_PAT_1 && DataByte == 16\'hA0)
+ next_state = ESP_A0SEEN;
+ else if (A_PAT_1 && DataByte == 16\'h20)
+ next_state <= PREL_ULBYPASS;
+ else if (A_PAT_1 && DataByte == 16\'h88)
+ next_state <= OTP;
+ else if (A_PAT_1 && DataByte == 16\'h90)
+ next_state = ESP_AS;
+ else
+ next_state = ESP;
+ end
+
+ ESP_A0SEEN :
+ begin
+ next_state = PGMS; //set ESP
+ end
+
+ ESP_AS :
+ begin
+ if (DataByte == 16\'hF0)
+ next_state = ESP;
+ else if ((Addr==8\'h55) && (DataByte==8\'h98))
+ next_state = ESP_AS_CFI;
+ end
+
+ ESP_AS_CFI:
+ begin
+ if (DataByte == 8\'hF0)
+ next_state = ESP_AS;
+ else
+ next_state = ESP_AS_CFI;
+ end
+
+ endcase
+ end
+
+ always @(posedge PDONE or negedge PERR)
+ begin: StateGen6
+ if (reseted!=1\'b1)
+ next_state = current_state;
+ else
+ begin
+ if (current_state==PGMS && ULBYPASS)
+ next_state = PREL_ULBYPASS;
+ else if (current_state==PGMS && OTP_ACT)
+ next_state = OTP;
+ else if (current_state==PGMS && ESP_ACT)
+ next_state = ESP;
+ else if (current_state==PGMS)
+ next_state = RESET;
+ end
+ end
+
+ always @(posedge EDONE or negedge EERR)
+ begin: StateGen2
+ if (reseted!=1\'b1)
+ next_state = current_state;
+ else
+ begin
+ if ((current_state==ERS) || (current_state==SERS_EXEC))
+ next_state = RESET;
+ end
+ end
+
+ always @(negedge write or reseted)
+ begin: StateGen7 //ok
+ integer i,j;
+ if (reseted!=1\'b1)
+ next_state = current_state;
+ else
+ begin
+ if (current_state==SERS_EXEC && (write==1\'b0) && (EERR!=1\'b1))
+ if (DataByte==16\'hB0)
+ begin
+ next_state = ESPS;
+ ESUSP = 1\'b1;
+ ESUSP <= #1 1\'b0;
+ end
+ end
+ end
+
+ always @(CTMOUT or reseted)
+ begin: StateGen4
+ if (reseted!=1\'b1)
+ next_state = current_state;
+ else
+ begin
+ if (current_state==SERS && CTMOUT) next_state = SERS_EXEC;
+ end
+ end
+
+ always @(posedge START_T1 or reseted)
+ begin: StateGen5
+ if (reseted!=1\'b1)
+ next_state = current_state;
+ else
+ if (current_state==ESPS && START_T1) next_state = ESP;
+ end
+
+ ///////////////////////////////////////////////////////////////////////////
+ //FSM Output generation and general funcionality
+ ///////////////////////////////////////////////////////////////////////////
+
+ always @(posedge read)
+ begin
+ ->oe_event;
+ end
+ always @(MemAddress)
+ begin
+ if (read)
+ ->oe_event;
+ end
+
+ always @(oe_event)
+ begin
+ oe = 1\'b1;
+ #1 oe = 1\'b0;
+ end
+
+ always @(DOut_zd)
+ begin : OutputGen
+ if (DOut_zd[0] !== 1\'bz)
+ begin
+ CEDQ_t = CENeg_event + CEDQ_01;
+ OEDQ_t = OENeg_event + OEDQ_01;
+ ADDRDQ_t = ADDR_event + ADDRDQ_01;
+ FROMCE = ((CEDQ_t >= OEDQ_t) && ( CEDQ_t >= $time));
+ FROMOE = ((OEDQ_t >= CEDQ_t) && ( OEDQ_t >= $time));
+ FROMADDR = 1\'b1;
+ if ((ADDRDQ_t > $time )&&
+ (((ADDRDQ_t>OEDQ_t)&&FROMOE) ||
+ ((ADDRDQ_t>CEDQ_t)&&FROMCE)))
+ begin
+ TempData = DOut_zd;
+ FROMADDR = 1\'b0;
+ DOut_Pass = 8\'bx;
+ #(ADDRDQ_t - $time) DOut_Pass = TempData;
+ end
+ else
+ begin
+ DOut_Pass = DOut_zd;
+ end
+ end
+ end
+
+ always @(DOut_zd)
+ begin
+ if (DOut_zd[0] === 1\'bz)
+ begin
+ disable OutputGen;
+ FROMCE = 1\'b1;
+ FROMOE = 1\'b1;
+ if ((CENeg_posEvent <= OENeg_posEvent) &&
+ ( CENeg_posEvent + 5 >= $time))
+ FROMOE = 1\'b0;
+ if ((OENeg_posEvent < CENeg_posEvent) &&
+ ( OENeg_posEvent + 5 >= $time))
+ FROMCE = 1\'b0;
+ FROMADDR = 1\'b0;
+ DOut_Pass = DOut_zd;
+ end
+ end
+
+ always @(oe or reseted or current_state)
+ begin
+ if (reseted)
+ begin
+ case (current_state)
+
+ RESET :
+ begin
+ if (oe)
+ MemRead(DOut_zd);
+ end
+
+ AS, ESP_AS, OTP_AS :
+ begin
+ if (oe)
+ begin
+ if (AS_addr == 1\'b0)
+ begin
+ end
+ else
+ AS_ID = 1\'b0;
+ if ((Address[7:0] == 0) && (AS_ID == 1\'b1))
+ DOut_zd = 1;
+ else if ((Address[7:0] == 1) && (AS_ID == 1\'b1))
+ DOut_zd = 8\'hA3;
+ else if ((Address[7:0] == 2) &&
+ (((SecAddr < 32 ) && (AS_ID == 1\'b1))
+ || ((SecAddr > 31 ) && (AS_ID2 == 1\'b1))))
+ begin
+ DOut_zd = 8\'b00000000;
+ DOut_zd[0] = Sec_Prot[SecAddr];
+ end
+ else if ((Address[7:0] == 6) && (AS_SecSi_FP == 1\'b1))
+ begin
+ DOut_zd = 8\'b0;
+ if (FactoryProt)
+ DOut_zd = 16\'h99;
+ else
+ DOut_zd = 16\'h19;
+ end
+ else
+ DOut_zd = 8\'bz;
+ end
+ end
+
+ OTP :
+ begin
+ if (oe)
+ begin
+ if ((SecAddr == 16\'h3F) && (Address <= 16\'hFFFF) &&
+ (Address >= 16\'hFF00))
+ begin
+ SecSiAddr = Address%(SecSiSize +1);
+ if (SecSi[SecSiAddr]==-1)
+ DOut_zd = 8\'bx;
+ else
+ DOut_zd = SecSi[SecSiAddr];
+ end
+ else
+ $display (""Invalid SecSi query address"");
+ end
+ end
+
+ CFI, AS_CFI, ESP_CFI, ESP_AS_CFI, OTP_AS_CFI :
+ begin
+ if (oe)
+ begin
+ DOut_zd = 8\'bZ;
+ if (((MemAddress>=16\'h10) && (MemAddress <= 16\'h3C)) ||
+ ((MemAddress>=16\'h40) && (MemAddress <= 16\'h4F)))
+ begin
+ DOut_zd = CFI_array[MemAddress];
+ end
+ else
+ begin
+ $display (""Invalid CFI query address"");
+ end
+ end
+ end
+
+ ERS :
+ begin
+ if (oe)
+ begin
+ ///////////////////////////////////////////////////////////
+ // read status / embeded erase algorithm - Chip Erase
+ ///////////////////////////////////////////////////////////
+ Status[7] = 1\'b0;
+ Status[6] = ~Status[6]; //toggle
+ Status[5] = 1\'b0;
+ Status[3] = 1\'b1;
+ Status[2] = ~Status[2]; //toggle
+
+ DOut_zd = Status;
+ end
+ end
+
+ SERS :
+ begin
+ if (oe)
+ begin
+ ///////////////////////////////////////////////////////////
+ //read status - sector erase timeout
+ ///////////////////////////////////////////////////////////
+ Status[3] = 1\'b0;
+ Status[7] = 1\'b1;
+ DOut_zd = Status;
+ end
+ end
+
+ ESPS :
+ begin
+ if (oe)
+ begin
+ ///////////////////////////////////////////////////////////
+ //read status / erase suspend timeout - stil erasing
+ ///////////////////////////////////////////////////////////
+ if (Ers_queue[SecAddr]==1\'b1)
+ begin
+ Status[7] = 1\'b0;
+ Status[2] = ~Status[2]; //toggle
+ end
+ else
+ Status[7] = 1\'b1;
+ Status[6] = ~Status[6]; //toggle
+ Status[5] = 1\'b0;
+ Status[3] = 1\'b1;
+ DOut_zd = Status;
+ end
+ end
+
+ SERS_EXEC:
+ begin
+ if (oe)
+ begin
+ ///////////////////////////////////////////////////
+ //read status erase
+ ///////////////////////////////////////////////////
+ if (Ers_queue[SecAddr]==1\'b1)
+ begin
+ Status[7] = 1\'b0;
+ Status[2] = ~Status[2]; //toggle
+ end
+ else
+ Status[7] = 1\'b1;
+ Status[6] = ~Status[6]; //toggle
+ Status[5] = 1\'b0;
+ Status[3] = 1\'b1;
+ DOut_zd = Status;
+ end
+ end
+
+ ESP :
+ begin
+ if (oe)
+ begin
+ ///////////////////////////////////////////////////////////
+ //read
+ ///////////////////////////////////////////////////////////
+
+ if (Ers_queue[SecAddr]!=1\'b1)
+ begin
+ MemRead(DOut_zd);
+ end
+ else
+ begin
+ ///////////////////////////////////////////////////////
+ //read status
+ ///////////////////////////////////////////////////////
+ Status[7] = 1\'b1;
+ // Status[6) No toggle
+ Status[5] = 1\'b0;
+ Status[2] = ~Status[2]; //toggle
+ DOut_zd = Status;
+ end
+ end
+ end
+
+ PGMS :
+ begin
+ if (oe)
+ begin
+ ///////////////////////////////////////////////////////////
+ //read status
+ ///////////////////////////////////////////////////////////
+ Status[6] = ~Status[6]; //toggle
+ Status[5] = 1\'b0;
+ //Status[2) no toggle
+ Status[1] = 1\'b0;
+ DOut_zd = Status;
+ if (SecAddr == SA)
+ DOut_zd[7] = Status[7];
+ else
+ DOut_zd[7] = ~Status[7];
+ end
+
+ end
+ endcase
+ end
+ end
+
+ always @(write or reseted)
+ begin : Output_generation
+ if (reseted)
+ begin
+ case (current_state)
+ RESET :
+ begin
+ ESP_ACT = 1\'b0;
+ ULBYPASS = 1\'b0;
+ OTP_ACT = 1\'b0;
+ if (~write)
+ if (A_PAT_2 && PATTERN_1)
+ AS_SecSi_FP = 1\'b1;
+ else
+ AS_SecSi_FP = 1\'b0;
+ end
+
+ Z001 :
+ begin
+ if (~write)
+ if (A_PAT_3 && PATTERN_2)
+ begin
+ end
+ else
+ AS_SecSi_FP = 1\'b0;
+ end
+
+ PREL_SETBWB :
+ begin
+ if (~write)
+ begin
+ if (A_PAT_1 && (DataByte==16\'h20))
+ ULBYPASS = 1\'b1;
+ else if (A_PAT_1 && (DataByte==16\'h90))
+ begin
+ ULBYPASS = 1\'b0;
+ if (A_PAT_2)
+ begin
+ end
+ else
+ AS_SecSi_FP = 1\'b0;
+ if (AS_addr == 1\'b0)
+ begin
+ AS_ID = 1\'b1;
+ AS_ID2= 1\'b0;
+ end
+ else
+ begin
+ AS_ID = 1\'b0;
+ AS_ID2= 1\'b1;
+ end
+ end
+ else if (A_PAT_1 && (DataByte==16\'h88))
+ begin
+ OTP_ACT = 1;
+ ULBYPASS = 1\'b0;
+ end
+ end
+ end
+
+ PREL_ULBYPASS :
+ begin
+ if (~write)
+ begin
+ ULBYPASS = 1\'b1;
+ if (A_PAT_1 && (DataByte==16\'h90))
+ ULBYPASS = 1\'b0;
+ end
+ end
+
+ PREL_ULBYPASS_RESET :
+ if ((~write) && (DataByte != 16\'h00 ))
+ ULBYPASS = 1\'b1;
+
+ OTP_A0SEEN :
+ begin
+ if (~write)
+ begin
+ if ((SecAddr == 16\'h3F) && (Address <= 16\'hFFFF) &&
+ (Address >= 16\'hFF00))
+ begin
+ SecSiAddr = Address%(SecSiSize +1);
+ OTP_ACT = 1;
+ PSTART = 1\'b1;
+ PSTART <= #1 1\'b0;
+
+ WBAddr = SecSiAddr;
+ SA = SecAddr;
+ temp = DataByte;
+ Status[7] = ~temp[7];
+ WBData = DataByte;
+ end
+ else
+ $display (""Invalid program address in SecSi region:""
+ ,Address);
+ end
+ end
+
+ OTP_PREL :
+ begin
+ if (~write)
+ if (A_PAT_1 && (DataByte==16\'h90))
+ begin
+ ULBYPASS = 1\'b0;
+ if (A_PAT_2)
+ begin
+ end
+ else
+ AS_SecSi_FP = 1\'b0;
+ if (AS_addr == 1\'b0)
+ begin
+ AS_ID = 1\'b1;
+ AS_ID2= 1\'b0;
+ end
+ else
+ begin
+ AS_ID = 1\'b0;
+ AS_ID2= 1\'b1;
+ end
+ end
+
+ end
+
+ OTP_Z001 :
+ begin
+ if (~write)
+ if (A_PAT_3 && PATTERN_2)
+ begin
+ end
+ else
+ AS_SecSi_FP = 1\'b0;
+ end
+
+ OTP :
+ begin
+ if (~write)
+ if (A_PAT_2 && PATTERN_1)
+ AS_SecSi_FP = 1\'b1;
+ else
+ AS_SecSi_FP = 1\'b0;
+ RY_zd = 1;
+ end
+
+ AS :
+ begin
+ if (~write)
+ if (DataByte==16\'hF0)
+ begin
+ AS_SecSi_FP = 1\'b0;
+ AS_ID = 1\'b0;
+ AS_ID2 = 1\'b0;
+ end
+ end
+
+ A0SEEN :
+ begin
+ if (~write)
+ begin
+ PSTART = 1\'b1;
+ PSTART <= #1 1\'b0;
+ WBData = DataByte;
+ WBAddr = Address;
+ SA = SecAddr;
+ Status[7] = ~DataByte[7];
+ end
+ end
+
+ C8 :
+ begin
+ end
+
+ C8_Z001 :
+ begin
+ end
+
+ C8_PREL :
+ begin
+ if (~write)
+ if (A_PAT_1 && (DataByte==16\'h10))
+ begin
+ //Start Chip Erase
+ ESTART = 1\'b1;
+ ESTART <= #1 1\'b0;
+ ESUSP = 1\'b0;
+ ERES = 1\'b0;
+ Ers_queue = ~(0);
+ Status = 8\'b00001000;
+ end
+ else if (DataByte==16\'h30)
+ begin
+ //put selected sector to sec. ers. queue
+ //start timeout
+ Ers_queue = 0;
+ Ers_queue[SecAddr] = 1\'b1;
+ disable TCTMOUTr;
+ CTMOUT_in = 1\'b0;
+ #1 CTMOUT_in <= 1\'b1;
+ end
+ end
+
+ ERS :
+ begin
+ end
+
+ SERS :
+ begin
+ if (~write && ~CTMOUT)
+ begin
+ if (DataByte == 16\'hB0)
+ begin
+ //need to start erase process prior to suspend
+ ESTART = 1\'b1;
+ ESTART = #1 1\'b0;
+ ESUSP = #1 1\'b0;
+ ESUSP = #1 1\'b1;
+ ESUSP <= #2 1\'b0;
+ ERES = 1\'b0;
+ end
+ else if (DataByte==16\'h30)
+ begin
+ disable TCTMOUTr;
+ CTMOUT_in = 1\'b0;
+ #1 CTMOUT_in <= 1\'b1;
+ Ers_queue[SecAddr] = 1\'b1;
+ end
+ end
+ end
+
+ SERS_EXEC :
+ begin
+ if (~write)
+ if (~EDONE && (EERR!=1\'b1) && DataByte==16\'hB0)
+ START_T1_in = 1\'b1;
+ end
+
+ ESP :
+ begin
+ if (~write)
+ begin
+ if (A_PAT_2 && PATTERN_1)
+ AS_SecSi_FP = 1\'b1;
+ else
+ AS_SecSi_FP = 1\'b0;
+ if (DataByte == 16\'h30)
+ begin
+ ERES = 1\'b1;
+ ERES <= #1 1\'b0;
+ end
+ end
+ end
+
+ ESP_Z001 :
+ begin
+ if (~write)
+ if (A_PAT_3 && PATTERN_2)
+ begin
+ end
+ else
+ AS_SecSi_FP = 1\'b0;
+ end
+
+ ESP_PREL :
+ begin
+ if (~write)
+ if (A_PAT_1 && (DataByte==16\'h90))
+ begin
+ ULBYPASS = 1\'b0;
+ if (A_PAT_2)
+ begin
+ end
+ else
+ AS_SecSi_FP = 1\'b0;
+ if (AS_addr == 1\'b0)
+ begin
+ AS_ID = 1\'b1;
+ AS_ID2= 1\'b0;
+ end
+ else
+ begin
+ AS_ID = 1\'b0;
+ AS_ID2= 1\'b1;
+ end
+ end
+ end
+
+ ESP_A0SEEN :
+ begin
+ if (~write)
+ begin
+ ESP_ACT = 1\'b1;
+ PSTART = 1\'b1;
+ PSTART <= #1 1\'b0;
+ WBData = DataByte;
+ WBAddr = Address;
+ SA = SecAddr;
+ Status[7] = ~DataByte[7];
+ end
+ end
+
+ ESP_AS :
+ begin
+ end
+
+ endcase
+ end
+ end
+
+ initial
+ begin
+ ///////////////////////////////////////////////////////////////////////
+ //CFI array data
+ ///////////////////////////////////////////////////////////////////////
+
+ //CFI query identification string
+ for (i=16;i<92;i=i+1)
+ CFI_array[i] = -1;
+
+ CFI_array[16\'h10] = 16\'h51;
+ CFI_array[16\'h11] = 16\'h52;
+ CFI_array[16\'h12] = 16\'h59;
+ CFI_array[16\'h13] = 16\'h02;
+ CFI_array[16\'h14] = 16\'h00;
+ CFI_array[16\'h15] = 16\'h40;
+ CFI_array[16\'h16] = 16\'h00;
+ CFI_array[16\'h17] = 16\'h00;
+ CFI_array[16\'h18] = 16\'h00;
+ CFI_array[16\'h19] = 16\'h00;
+ CFI_array[16\'h1A] = 16\'h00;
+
+ //system interface string
+ CFI_array[16\'h1B] = 16\'h27;
+ CFI_array[16\'h1C] = 16\'h36;
+ CFI_array[16\'h1D] = 16\'h00;
+ CFI_array[16\'h1E] = 16\'h00;
+ CFI_array[16\'h1F] = 16\'h04;
+ CFI_array[16\'h20] = 16\'h00;
+ CFI_array[16\'h21] = 16\'h0A;
+ CFI_array[16\'h22] = 16\'h00;
+ CFI_array[16\'h23] = 16\'h05;
+ CFI_array[16\'h24] = 16\'h00;
+ CFI_array[16\'h25] = 16\'h04;
+ CFI_array[16\'h26] = 16\'h00;
+ //device geometry definition
+ CFI_array[16\'h27] = 16\'h16;
+ CFI_array[16\'h28] = 16\'h00;
+ CFI_array[16\'h29] = 16\'h00;
+ CFI_array[16\'h2A] = 16\'h00;
+ CFI_array[16\'h2B] = 16\'h00;
+ CFI_array[16\'h2C] = 16\'h01;
+ CFI_array[16\'h2D] = 16\'h3F;
+ CFI_array[16\'h2E] = 16\'h00;
+ CFI_array[16\'h2F] = 16\'h00;
+ CFI_array[16\'h30] = 16\'h01;
+ CFI_array[16\'h31] = 16\'h00;
+ CFI_array[16\'h32] = 16\'h00;
+ CFI_array[16\'h33] = 16\'h00;
+ CFI_array[16\'h34] = 16\'h00;
+ CFI_array[16\'h35] = 16\'h00;
+ CFI_array[16\'h36] = 16\'h00;
+ CFI_array[16\'h37] = 16\'h00;
+ CFI_array[16\'h38] = 16\'h00;
+ CFI_array[16\'h39] = 16\'h00;
+ CFI_array[16\'h3A] = 16\'h00;
+ CFI_array[16\'h3B] = 16\'h00;
+ CFI_array[16\'h3C] = 16\'h00;
+
+ //primary vendor-specific extended query
+ CFI_array[16\'h40] = 16\'h50;
+ CFI_array[16\'h41] = 16\'h52;
+ CFI_array[16\'h42] = 16\'h49;
+ CFI_array[16\'h43] = 16\'h31;
+ CFI_array[16\'h44] = 16\'h31;
+ CFI_array[16\'h45] = 16\'h01;
+ CFI_array[16\'h46] = 16\'h02;
+ CFI_array[16\'h47] = 16\'h01;
+ CFI_array[16\'h48] = 16\'h01;
+ CFI_array[16\'h49] = 16\'h04;
+ CFI_array[16\'h4A] = 16\'h00;
+ CFI_array[16\'h4B] = 16\'h00;
+ CFI_array[16\'h4C] = 16\'h00;
+ CFI_array[16\'h4D] = 16\'hB5;
+ CFI_array[16\'h4E] = 16\'hC5;
+ CFI_array[16\'h4F] = 16\'h00;
+
+ end
+
+ always @(current_state or reseted)
+ begin
+ if (reseted)
+ if (current_state==RESET) RY_zd = 1\'b1;
+ if (current_state==PREL_ULBYPASS) RY_zd = 1\'b1;
+ if (current_state==A0SEEN) RY_zd = 1\'b1;
+ if (current_state==ERS) RY_zd = 1\'b0;
+ if (current_state==SERS) RY_zd = 1\'b0;
+ if (current_state==ESPS) RY_zd = 1\'b0;
+ if (current_state==SERS_EXEC) RY_zd = 1\'b0;
+ if (current_state==ESP) RY_zd = 1\'b1;
+ if (current_state==OTP) RY_zd = 1\'b1;
+ if (current_state==ESP_A0SEEN) RY_zd = 1\'b1;
+ if (current_state==PGMS) RY_zd = 1\'b0;
+ end
+
+ always @(EERR or EDONE or current_state)
+ begin : ERS2
+ integer i;
+ integer j;
+ if (current_state==ERS && EERR!=1\'b1)
+ for (i=0;i<=SecNum;i=i+1)
+ begin
+ if (Sec_Prot[i]!=1\'b1)
+ for (j=0;j<=SecSize;j=j+1)
+ Mem[sa(i)+j] = -1;
+ end
+ if (current_state==ERS && EDONE)
+ for (i=0;i<=SecNum;i=i+1)
+ begin
+ if (Sec_Prot[i]!=1\'b1)
+ for (j=0;j<=SecSize;j=j+1)
+ Mem[sa(i)+j] = MaxData;
+ end
+ end
+
+ always @(CTMOUT or current_state)
+ begin : SERS2
+ if (current_state==SERS && CTMOUT)
+ begin
+ CTMOUT_in = 1\'b0;
+ START_T1_in = 1\'b0;
+ ESTART = 1\'b1;
+ ESTART <= #1 1\'b0;
+ ESUSP = 1\'b0;
+ ERES = 1\'b0;
+ end
+ end
+
+ always @(START_T1 or current_state)
+ begin : ESPS2
+ if (current_state==ESPS && START_T1)
+ begin
+ ESP_ACT = 1\'b1;
+ START_T1_in = 1\'b0;
+ end
+ end
+
+ always @(EERR or EDONE or current_state)
+ begin: SERS_EXEC2
+ integer i,j;
+ if (current_state==SERS_EXEC)
+ begin
+ if (EERR!=1\'b1)
+ begin
+ for (i=0;i<=SecNum;i=i+1)
+ begin
+ if (Sec_Prot[i]!=1\'b1 && Ers_queue[i])
+ for (j=0;j<=SecSize;j=j+1)
+ Mem[sa(i)+j] = -1;
+
+ if (EDONE)
+ for (i=0;i<=SecNum;i=i+1)
+ begin
+ if (Sec_Prot[i]!=1\'b1 && Ers_queue[i])
+ for (j=0;j<=SecSize;j=j+1)
+ Mem[sa(i)+j] = MaxData;
+ end
+ end
+ end
+ end
+ end
+
+ always @(current_state or posedge PDONE)
+ begin: PGMS2
+ integer i,j;
+ if (current_state==PGMS)
+ begin
+ if (PERR!=1\'b1)
+ begin
+ new_int = WBData;
+ if (OTP_ACT!=1\'b1) //mem write
+ old_int=Mem[sa(SA) + WBAddr];
+ else
+ old_int=SecSi[WBAddr];
+ new_bit = new_int;
+ if (old_int>-1)
+ begin
+ old_bit = old_int;
+ for(j=0;j<=7;j=j+1)
+ if (~old_bit[j])
+ new_bit[j]=1\'b0;
+ new_int=new_bit;
+ end
+ WBData = new_int;
+ if (OTP_ACT!=1\'b1) //mem write
+ Mem[sa(SA) + WBAddr] = -1;
+ else
+ SecSi[WBAddr] = -1;
+ if (PDONE && ~PSTART)
+ begin
+ if (OTP_ACT!=1\'b1) //mem write
+ Mem[sa(SA) + WBAddr] = WBData;
+ else
+ SecSi[WBAddr] = WBData;
+ WBData= -1;
+ end
+ end
+ end
+ end
+
+ always @(gOE_n or gCE_n or RESETNeg or RST )
+ begin
+ //Output Disable Control
+ if (gOE_n || gCE_n || (~RESETNeg && ~RST))
+ DOut_zd = 8\'bZ;
+ end
+
+ reg BuffInOE , BuffInCE , BuffInADDR;
+ wire BuffOutOE, BuffOutCE, BuffOutADDR;
+
+ BUFFER BUFOE (BuffOutOE, BuffInOE);
+ BUFFER BUFCE (BuffOutCE, BuffInCE);
+ BUFFER BUFADDR (BuffOutADDR, BuffInADDR);
+ initial
+ begin
+ BuffInOE = 1\'b1;
+ BuffInCE = 1\'b1;
+ BuffInADDR = 1\'b1;
+ end
+
+ always @(posedge BuffOutOE)
+ begin
+ OEDQ_01 = $time;
+ end
+ always @(posedge BuffOutCE)
+ begin
+ CEDQ_01 = $time;
+ end
+ always @(posedge BuffOutADDR)
+ begin
+ ADDRDQ_01 = $time;
+ end
+
+ function integer sa;
+ input [7:0] sect;
+ begin
+ sa = sect * (SecSize + 1);
+ end
+ endfunction
+
+ task MemRead;
+ inout[7:0] DOut_zd;
+ begin
+ if (Mem[sa(SecAddr)+Address]==-1)
+ DOut_zd = 8\'bx;
+ else
+ DOut_zd = Mem[sa(SecAddr)+Address];
+ end
+ endtask
+endmodule
+
+module BUFFER (OUT,IN);
+ input IN;
+ output OUT;
+ buf ( OUT, IN);
+endmodule
+"
+"/*
+ * Microcode instruction generator for Zet
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`include ""defines.v""
+
+module zet_micro_data (
+ input [`MICRO_ADDR_WIDTH-1:0] n_micro,
+ input [15:0] off_i,
+ input [15:0] imm_i,
+ input [ 3:0] src,
+ input [ 3:0] dst,
+ input [ 3:0] base,
+ input [ 3:0] index,
+ input [ 1:0] seg,
+ input [ 2:0] fdec,
+ output div,
+ output end_seq,
+
+ output [`IR_SIZE-1:0] ir,
+ output [15:0] off_o,
+ output [15:0] imm_o
+ );
+
+ // Net declarations
+ wire [`MICRO_DATA_WIDTH-1:0] micro_o;
+ wire [ 6:0] ir1;
+ wire [ 1:0] ir0;
+ wire var_s, var_off;
+ wire [1:0] var_a, var_b, var_c, var_d;
+ wire [2:0] var_imm;
+
+ wire [3:0] addr_a, addr_b, addr_c, addr_d;
+ wire [3:0] micro_a, micro_b, micro_c, micro_d;
+ wire [1:0] addr_s, micro_s;
+ wire [2:0] t;
+ wire [2:0] f;
+ wire [2:0] f_rom;
+ wire wr_flag;
+ wire wr_mem;
+ wire wr_rom;
+ wire wr_d;
+
+ // Module instantiations
+ zet_micro_rom micro_rom (n_micro, micro_o);
+
+ // Assignments
+ assign micro_s = micro_o[1:0];
+ assign micro_a = micro_o[5:2];
+ assign micro_b = micro_o[9:6];
+ assign micro_c = micro_o[13:10];
+ assign micro_d = micro_o[17:14];
+ assign wr_flag = micro_o[18];
+ assign wr_mem = micro_o[19];
+ assign wr_rom = micro_o[20];
+ assign ir0 = micro_o[22:21];
+ assign t = micro_o[25:23];
+ assign f_rom = micro_o[28:26];
+ assign ir1 = micro_o[35:29];
+ assign var_s = micro_o[36];
+ assign var_a = micro_o[38:37];
+ assign var_b = micro_o[40:39];
+ assign var_c = micro_o[42:41];
+ assign var_d = micro_o[44:43];
+ assign var_off = micro_o[45];
+ assign var_imm = micro_o[48:46];
+ assign end_seq = micro_o[49];
+
+ assign imm_o = var_imm == 3\'d0 ? (16\'h0000)
+ : (var_imm == 3\'d1 ? (16\'h0002)
+ : (var_imm == 3\'d2 ? (16\'h0004)
+ : (var_imm == 3\'d3 ? off_i
+ : (var_imm == 3\'d4 ? imm_i
+ : (var_imm == 3\'d5 ? 16\'hffff
+ : (var_imm == 3\'d6 ? 16\'b11 : 16\'d1))))));
+
+ assign off_o = var_off ? off_i : 16\'h0000;
+
+ assign addr_a = var_a == 2\'d0 ? micro_a
+ : (var_a == 2\'d1 ? base
+ : (var_a == 2\'d2 ? dst : src ));
+ assign addr_b = var_b == 2\'d0 ? micro_b
+ : (var_b == 2\'d1 ? index : src);
+ assign addr_c = var_c == 2\'d0 ? micro_c
+ : (var_c == 2\'d1 ? dst : src);
+ assign addr_d = var_d == 2\'d0 ? micro_d
+ : (var_d == 2\'d1 ? dst : src);
+ assign addr_s = var_s ? seg : micro_s;
+
+ assign div = (t==3\'d3 && (f_rom[2]|f_rom[1]) && !wr_rom);
+ assign f = (t==3\'d6 && wr_flag || t==3\'d5 && wr_rom) ? fdec : f_rom;
+ assign wr_d = (t==3\'d5 && f==3\'d7) ? 1\'b0 : wr_rom; /* CMP doesn\'t write */
+
+ assign ir = { ir1, f, t, ir0, wr_d, wr_mem, wr_flag, addr_d,
+ addr_c, addr_b, addr_a, addr_s };
+endmodule
+"
+"/*
+ * LCD controller for VGA
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vga_lcd (
+ input clk, // 25 Mhz clock
+ input rst,
+
+ input shift_reg1, // if set: 320x200
+ input graphics_alpha, // if not set: 640x400 text mode
+
+ // CSR slave interface for reading
+ output [17:1] csr_adr_o,
+ input [15:0] csr_dat_i,
+ output csr_stb_o,
+
+ // attribute_ctrl
+ input [3:0] pal_addr,
+ input pal_we,
+ output [7:0] pal_read,
+ input [7:0] pal_write,
+
+ // dac_regs
+ input dac_we,
+ input [1:0] dac_read_data_cycle,
+ input [7:0] dac_read_data_register,
+ output [3:0] dac_read_data,
+ input [1:0] dac_write_data_cycle,
+ input [7:0] dac_write_data_register,
+ input [3:0] dac_write_data,
+
+ // VGA pad signals
+ output reg [3:0] vga_red_o,
+ output reg [3:0] vga_green_o,
+ output reg [3:0] vga_blue_o,
+ output reg horiz_sync,
+ output reg vert_sync,
+
+ // CRTC
+ input [5:0] cur_start,
+ input [5:0] cur_end,
+ input [4:0] vcursor,
+ input [6:0] hcursor,
+
+ input [6:0] horiz_total,
+ input [6:0] end_horiz,
+ input [6:0] st_hor_retr,
+ input [4:0] end_hor_retr,
+ input [9:0] vert_total,
+ input [9:0] end_vert,
+ input [9:0] st_ver_retr,
+ input [3:0] end_ver_retr,
+
+ input x_dotclockdiv2,
+
+ // retrace signals
+ output v_retrace,
+ output vh_retrace
+ );
+
+ // Registers and nets
+ reg video_on_v;
+ reg video_on_h_i;
+ reg [1:0] video_on_h_p;
+ reg [9:0] h_count; // Horizontal pipeline delay is 2 cycles
+ reg [9:0] v_count; // 0 to VER_SCAN_END
+
+ wire [9:0] hor_disp_end;
+ wire [9:0] hor_scan_end;
+ wire [9:0] ver_disp_end;
+ wire [9:0] ver_sync_beg;
+ wire [3:0] ver_sync_end;
+ wire [9:0] ver_scan_end;
+ wire video_on;
+
+ wire [3:0] attr_wm;
+ wire [3:0] attr_tm;
+ wire [3:0] attr;
+ wire [7:0] index;
+ wire [7:0] index_pal;
+ wire [7:0] color;
+ reg [7:0] index_gm;
+
+ wire video_on_h_tm;
+ wire video_on_h_wm;
+ wire video_on_h_gm;
+ wire video_on_h;
+
+ reg horiz_sync_i;
+ reg [1:0] horiz_sync_p;
+ wire horiz_sync_tm;
+ wire horiz_sync_wm;
+ wire horiz_sync_gm;
+
+ wire [16:1] csr_tm_adr_o;
+ wire csr_tm_stb_o;
+ wire [17:1] csr_wm_adr_o;
+ wire csr_wm_stb_o;
+ wire [17:1] csr_gm_adr_o;
+ wire csr_gm_stb_o;
+ wire csr_stb_o_tmp;
+
+ wire [3:0] red;
+ wire [3:0] green;
+ wire [3:0] blue;
+
+ // Module instances
+ vga_text_mode text_mode (
+ .clk (clk),
+ .rst (rst),
+
+ // CSR slave interface for reading
+ .csr_adr_o (csr_tm_adr_o),
+ .csr_dat_i (csr_dat_i),
+ .csr_stb_o (csr_tm_stb_o),
+
+ .h_count (h_count),
+ .v_count (v_count),
+ .horiz_sync_i (horiz_sync_i),
+ .video_on_h_i (video_on_h_i),
+ .video_on_h_o (video_on_h_tm),
+
+ .cur_start (cur_start),
+ .cur_end (cur_end),
+ .vcursor (vcursor),
+ .hcursor (hcursor),
+
+ .attr (attr_tm),
+ .horiz_sync_o (horiz_sync_tm)
+ );
+
+ vga_planar planar (
+ .clk (clk),
+ .rst (rst),
+
+ // CSR slave interface for reading
+ .csr_adr_o (csr_wm_adr_o),
+ .csr_dat_i (csr_dat_i),
+ .csr_stb_o (csr_wm_stb_o),
+
+ .attr_plane_enable (4'hf),
+ .x_dotclockdiv2 (x_dotclockdiv2),
+
+ .h_count (h_count),
+ .v_count (v_count),
+ .horiz_sync_i (horiz_sync_i),
+ .video_on_h_i (video_on_h_i),
+ .video_on_h_o (video_on_h_wm),
+
+ .attr (attr_wm),
+ .horiz_sync_o (horiz_sync_wm)
+ );
+
+ vga_linear linear (
+ .clk (clk),
+ .rst (rst),
+
+ // CSR slave interface for reading
+ .csr_adr_o (csr_gm_adr_o),
+ .csr_dat_i (csr_dat_i),
+ .csr_stb_o (csr_gm_stb_o),
+
+ .h_count (h_count),
+ .v_count (v_count),
+ .horiz_sync_i (horiz_sync_i),
+ .video_on_h_i (video_on_h_i),
+ .video_on_h_o (video_on_h_gm),
+
+ .color (color),
+ .horiz_sync_o (horiz_sync_gm)
+ );
+
+ vga_palette_regs palette_regs (
+ .clk (clk),
+
+ .attr (attr),
+ .index (index_pal),
+
+ .address (pal_addr),
+ .write (pal_we),
+ .read_data (pal_read),
+ .write_data (pal_write)
+ );
+
+ vga_dac_regs dac_regs (
+ .clk (clk),
+
+ .index (index),
+ .red (red),
+ .green (green),
+ .blue (blue),
+
+ .write (dac_we),
+
+ .read_data_cycle (dac_read_data_cycle),
+ .read_data_register (dac_read_data_register),
+ .read_data (dac_read_data),
+
+ .write_data_cycle (dac_write_data_cycle),
+ .write_data_register (dac_write_data_register),
+ .write_data (dac_write_data)
+ );
+
+ // Continuous assignments
+ assign hor_scan_end = { horiz_total[6:2] + 1'b1, horiz_total[1:0], 3'h7 };
+ assign hor_disp_end = { end_horiz, 3'h7 };
+ assign ver_scan_end = vert_total + 10'd1;
+ assign ver_disp_end = end_vert + 10'd1;
+ assign ver_sync_beg = st_ver_retr;
+ assign ver_sync_end = end_ver_retr + 4'd1;
+ assign video_on = video_on_h && video_on_v;
+
+ assign attr = graphics_alpha ? attr_wm : attr_tm;
+ assign index = (graphics_alpha & shift_reg1) ? index_gm : index_pal;
+
+ assign video_on_h = video_on_h_p[1];
+
+ assign csr_adr_o = graphics_alpha ?
+ (shift_reg1 ? csr_gm_adr_o : csr_wm_adr_o) : { 1'b0, csr_tm_adr_o };
+
+ assign csr_stb_o_tmp = graphics_alpha ?
+ (shift_reg1 ? csr_gm_stb_o : csr_wm_stb_o) : csr_tm_stb_o;
+ assign csr_stb_o = csr_stb_o_tmp & (video_on_h_i | video_on_h) & video_on_v;
+
+ assign v_retrace = !video_on_v;
+ assign vh_retrace = v_retrace | !video_on_h;
+
+ // index_gm
+ always @(posedge clk)
+ index_gm <= rst ? 8'h0 : color;
+
+ // Sync generation & timing process
+ // Generate horizontal and vertical timing signals for video signal
+ always @(posedge clk)
+ if (rst)
+ begin
+ h_count <= 10'b0;
+ horiz_sync_i <= 1'b1;
+ v_count <= 10'b0;
+ vert_sync <= 1'b1;
+ video_on_h_i <= 1'b1;
+ video_on_v <= 1'b1;
+ end
+ else
+ begin
+ h_count <= (h_count==hor_scan_end) ? 10'b0 : h_count + 10'b1;
+ horiz_sync_i <= horiz_sync_i ? (h_count[9:3]!=st_hor_retr)
+ : (h_count[7:3]==end_hor_retr);
+ v_count <= (v_count==ver_scan_end && h_count==hor_scan_end) ? 10'b0
+ : ((h_count==hor_scan_end) ? v_count + 10'b1 : v_count);
+ vert_sync <= vert_sync ? (v_count!=ver_sync_beg)
+ : (v_count[3:0]==ver_sync_end);
+
+ video_on_h_i <= (h_count==hor_scan_end) ? 1'b1
+ : ((h_count==hor_disp_end) ? 1'b0 : video_on_h_i);
+ video_on_v <= (v_count==10'h0) ? 1'b1
+ : ((v_count==ver_disp_end) ? 1'b0 : video_on_v);
+ end
+
+ // Horiz sync
+ always @(posedge clk)
+ { horiz_sync, horiz_sync_p } <= rst ? 3'b0
+ : { horiz_sync_p[1:0], graphics_alpha ?
+ (shift_reg1 ? horiz_sync_gm : horiz_sync_wm) : horiz_sync_tm };
+
+ // Video_on pipe
+ always @(posedge clk)
+ video_on_h_p <= rst ? 2'b0 : { video_on_h_p[0],
+ graphics_alpha ? (shift_reg1 ? video_on_h_gm : video_on_h_wm)
+ : video_on_h_tm };
+
+ // Colour signals
+ always @(posedge clk)
+ if (rst)
+ begin
+ vga_red_o <= 4'b0;
+ vga_green_o <= 4'b0;
+ vga_blue_o <= 4'b0;
+ end
+ else
+ begin
+ vga_blue_o <= video_on ? blue : 4'h0;
+ vga_green_o <= video_on ? green : 4'h0;
+ vga_red_o <= video_on ? red : 4'h0;
+ end
+
+endmodule
+"
+"/*\r
+ * LCD controller for VGA\r
+ * Copyright (C) 2010 Zeus Gomez Marmolejo \r
+ *\r
+ * VGA FML support\r
+ * Copyright (C) 2013 Charley Picker \r
+ *\r
+ * Portions of code borrowed from Milkymist SoC \r
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq\r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+module vga_lcd_fml #(\r
+ parameter fml_depth = 20 // 1MB Video Memory\r
+) (\r
+ input clk, // 100 Mhz clock\r
+ input rst,\r
+\r
+ input shift_reg1, // if set: 320x200\r
+ input graphics_alpha, // if not set: 640x400 text mode\r
+\r
+ // VGA LCD FML master interface\r
+ output reg [fml_depth-1:0] fml_adr,\r
+ output reg fml_stb,\r
+ input fml_we,\r
+ input fml_ack,\r
+ output [1:0] fml_sel,\r
+ output [15:0] fml_do,\r
+ input [15:0] fml_di,\r
+\r
+ // VGA LCD Direct Cache Bus\r
+ output reg dcb_stb,\r
+ output [fml_depth-1:0] dcb_adr,\r
+ input [15:0] dcb_dat,\r
+ input dcb_hit,\r
+\r
+ // attribute_ctrl\r
+ input [3:0] pal_addr,\r
+ input pal_we,\r
+ output [7:0] pal_read,\r
+ input [7:0] pal_write,\r
+\r
+ // dac_regs\r
+ input dac_we,\r
+ input [1:0] dac_read_data_cycle,\r
+ input [7:0] dac_read_data_register,\r
+ output [3:0] dac_read_data,\r
+ input [1:0] dac_write_data_cycle,\r
+ input [7:0] dac_write_data_register,\r
+ input [3:0] dac_write_data,\r
+\r
+ // VGA pad signals\r
+ output [3:0] vga_red_o,\r
+ output [3:0] vga_green_o,\r
+ output [3:0] vga_blue_o,\r
+ output horiz_sync,\r
+ output vert_sync,\r
+ \r
+ // Base address of video memory\r
+ input [15:0] start_addr,\r
+\r
+ // CRTC\r
+ input [5:0] cur_start,\r
+ input [5:0] cur_end,\r
+ input [4:0] vcursor,\r
+ input [6:0] hcursor,\r
+\r
+ input [6:0] horiz_total,\r
+ input [6:0] end_horiz,\r
+ input [6:0] st_hor_retr,\r
+ input [4:0] end_hor_retr,\r
+ input [9:0] vert_total,\r
+ input [9:0] end_vert,\r
+ input [9:0] st_ver_retr,\r
+ input [3:0] end_ver_retr,\r
+\r
+ input x_dotclockdiv2,\r
+\r
+ // retrace signals\r
+ output v_retrace,\r
+ output vh_retrace,\r
+\r
+ output vga_clk\r
+\r
+ );\r
+\r
+ // Registers and nets\r
+ // Hookup crtc output stage to sequencer input stage \r
+ wire [9:0] h_count; // Horizontal pipeline delay is 2 cycles\r
+ wire horiz_sync_i;\r
+ wire [9:0] v_count; // 0 to VER_SCAN_END\r
+ wire vert_sync_crtc_o;\r
+ wire video_on_h_i;\r
+ wire video_on_v;\r
+\r
+ // Hookup sequencer output stage to fifo input stage \r
+ wire [11:0] fb_dat_i;\r
+ wire horiz_sync_seq_o;\r
+ wire vert_sync_seq_o;\r
+ wire video_on_h_seq_o;\r
+ wire video_on_v_seq_o;\r
+ wire [7:0] character_seq_o;\r
+\r
+ // Hookup fifo output stage to pal_dac input stage\r
+ wire [11:0] fb_dat_o;\r
+ wire fb_horiz_sync_seq_o;\r
+ wire fb_vert_sync_seq_o;\r
+ wire fb_video_on_h_seq_o;\r
+ wire fb_video_on_v_seq_o;\r
+ wire [7:0] fb_character_seq_o;\r
+\r
+ // Pixel buffer control\r
+ wire read_fifo;\r
+ wire fill_fifo;\r
+ // Number of words stored in the FIFO, 0-63 (64 possible values)\r
+ wire [9:0] fifo_level;\r
+ wire fifo_empty;\r
+ wire fifo_full;\r
+\r
+ // Each stage is controlled by enable signals\r
+ wire en_crtc;\r
+ wire en_sequencer;\r
+ wire en_pal_dac;\r
+\r
+ reg next_crtc_seq_cyc;\r
+ reg next_pal_dac_cyc;\r
+\r
+ // Pixel clock counter \r
+ reg [1:0] pixel_clk_counter;\r
+\r
+ // LCD FSM Registers\r
+ reg fifo_source_cache;\r
+ wire can_burst;\r
+ wire [17:1] lcd_adr;\r
+ wire lcd_stb;\r
+\r
+ // Module instances\r
+ vga_crtc_fml crtc (\r
+ .clk (clk), // 100 Mhz clock\r
+ .rst (rst),\r
+\r
+ .enable_crtc (en_crtc),\r
+\r
+ // CRTC configuration signals\r
+\r
+ .cur_start (cur_start),\r
+ .cur_end (cur_end),\r
+ .vcursor (vcursor),\r
+ .hcursor (hcursor),\r
+\r
+ .horiz_total (horiz_total),\r
+ .end_horiz (end_horiz),\r
+ .st_hor_retr (st_hor_retr),\r
+ .end_hor_retr (end_hor_retr),\r
+ .vert_total (vert_total),\r
+ .end_vert (end_vert),\r
+ .st_ver_retr (st_ver_retr),\r
+ .end_ver_retr (end_ver_retr),\r
+\r
+ // CRTC output signals\r
+\r
+ .h_count (h_count),\r
+ .horiz_sync_i (horiz_sync_i),\r
+\r
+ .v_count (v_count),\r
+ .vert_sync (vert_sync_crtc_o),\r
+\r
+ .video_on_h_i (video_on_h_i),\r
+ .video_on_v (video_on_v)\r
+\r
+ );\r
+\r
+ vga_sequencer_fml sequencer (\r
+ .clk (clk), // 100 Mhz clock\r
+ .rst (rst),\r
+\r
+ .enable_sequencer (en_sequencer),\r
+\r
+ // Sequencer input signals\r
+\r
+ .h_count (h_count),\r
+ .horiz_sync_i (horiz_sync_i),\r
+\r
+ .v_count (v_count),\r
+ .vert_sync (vert_sync_crtc_o),\r
+\r
+ .video_on_h_i (video_on_h_i),\r
+ .video_on_v (video_on_v),\r
+\r
+ // Sequencer configuration signals\r
+\r
+ .shift_reg1 (shift_reg1), // if set: 320x200\r
+ .graphics_alpha (graphics_alpha), // if not set: 640x400 text mode\r
+\r
+ // CSR slave interface for reading\r
+ .fml_adr_o (lcd_adr),\r
+ .fml_dat_i (fifo_source_cache ? dcb_dat : fml_di),\r
+ .fml_stb_o (lcd_stb),\r
+\r
+ // CRTC\r
+ .cur_start (cur_start),\r
+ .cur_end (cur_end),\r
+ .vcursor (vcursor),\r
+ .hcursor (hcursor),\r
+\r
+ .x_dotclockdiv2 (x_dotclockdiv2),\r
+\r
+ // Sequencer output signals\r
+\r
+ .horiz_sync_seq_o (horiz_sync_seq_o),\r
+ .vert_sync_seq_o (vert_sync_seq_o),\r
+ .video_on_h_seq_o (video_on_h_seq_o),\r
+ .video_on_v_seq_o (video_on_v_seq_o),\r
+ .character_seq_o (character_seq_o) \r
+\r
+ );\r
+\r
+ // video-data buffer (temporary store data read from video memory)\r
+ // We want to store at least one scan line (512 pixels x 12 bits per pixel) in the buffer\r
+ vga_fifo #(9, 12) data_fifo (\r
+ .clk ( clk ),\r
+ .aclr ( 1'b1 ),\r
+ .sclr ( rst ),\r
+ .d ( fb_dat_i ),\r
+ .wreq ( fill_fifo ),\r
+ .q ( fb_dat_o ),\r
+ .rreq ( read_fifo ),\r
+ .nword ( fifo_level ),\r
+ .empty ( fifo_empty ),\r
+ .full ( fifo_full ),\r
+ .aempty ( ),\r
+ .afull ( )\r
+ );\r
+\r
+ vga_pal_dac_fml pal_dac (\r
+ .clk (clk), // 100 Mhz clock\r
+ .rst (rst),\r
+\r
+ .enable_pal_dac (en_pal_dac),\r
+\r
+ // VGA PAL/DAC input signals\r
+\r
+ .horiz_sync_pal_dac_i (fb_horiz_sync_seq_o),\r
+ .vert_sync_pal_dac_i (fb_vert_sync_seq_o),\r
+ .video_on_h_pal_dac_i (fb_video_on_h_seq_o),\r
+ .video_on_v_pal_dac_i (fb_video_on_v_seq_o),\r
+ .character_pal_dac_i (fb_character_seq_o),\r
+\r
+ // VGA PAL/DAC configuration signals\r
+\r
+ .shift_reg1 (shift_reg1), // if set: 320x200\r
+ .graphics_alpha (graphics_alpha), // if not set: 640x400 text mode\r
+\r
+ // attribute_ctrl\r
+ .pal_addr (pal_addr),\r
+ .pal_we (pal_we),\r
+ .pal_read (pal_read),\r
+ .pal_write (pal_write),\r
+\r
+ // dac_regs\r
+ .dac_we (dac_we),\r
+ .dac_read_data_cycle (dac_read_data_cycle),\r
+ .dac_read_data_register (dac_read_data_register),\r
+ .dac_read_data (dac_read_data),\r
+ .dac_write_data_cycle (dac_write_data_cycle),\r
+ .dac_write_data_register (dac_write_data_register),\r
+ .dac_write_data (dac_write_data),\r
+\r
+ // VGA PAL/DAC output signals\r
+\r
+ // VGA pad signals\r
+ .vga_red_o (vga_red_o),\r
+ .vga_green_o (vga_green_o),\r
+ .vga_blue_o (vga_blue_o),\r
+ .horiz_sync (horiz_sync),\r
+ .vert_sync (vert_sync),\r
+\r
+ // retrace signals\r
+ .v_retrace (v_retrace),\r
+ .vh_retrace (vh_retrace)\r
+ );\r
+\r
+ // Continuous assignments\r
+\r
+ // The lcd is read only device and these control signals are not used\r
+ assign fml_sel = 2'b11;\r
+ assign fml_do = 16'b0;\r
+\r
+ // Pack sequencer stage output into one wire group\r
+ assign fb_dat_i = { horiz_sync_seq_o,\r
+ vert_sync_seq_o,\r
+ video_on_h_seq_o,\r
+ video_on_v_seq_o,\r
+ character_seq_o[7:0] };\r
+\r
+ // Unpack fb_dat_o back into seperate wires\r
+ assign fb_horiz_sync_seq_o = fb_dat_o [11];\r
+ assign fb_vert_sync_seq_o = fb_dat_o [10];\r
+ assign fb_video_on_h_seq_o = fb_dat_o [9];\r
+ assign fb_video_on_v_seq_o = fb_dat_o [8];\r
+ assign fb_character_seq_o = fb_dat_o [7:0];\r
+\r
+ // Wait until the fifo level is <= 300 (enough room for a 212 pixel burst)\r
+ assign can_burst = fifo_level <= 10'd300;\r
+\r
+ // These signals enable and control when the next crtc/sequencer cycle should occur \r
+ assign en_crtc = next_crtc_seq_cyc;\r
+ assign en_sequencer = next_crtc_seq_cyc;\r
+\r
+ // When the next_crtc_seq_cyc occurs we should place another pixel in fifo\r
+ assign fill_fifo = next_crtc_seq_cyc;\r
+\r
+ // This signal enables and controls when we should read from the fifo\r
+ // We must first wait until something is in the fifo!!!\r
+ assign read_fifo = next_pal_dac_cyc & !fifo_empty;\r
+\r
+ // This signal enables and controls when the next pal_dac cycle should occure\r
+ // We must first wait until something is in the fifo!!!\r
+ assign en_pal_dac = next_pal_dac_cyc & !fifo_empty; // 100 Mhz version\r
+\r
+ // This is the vga_clk signal\r
+ // No matter what happens, we must keep the vga_clk going!!!\r
+ assign vga_clk = next_pal_dac_cyc;\r
+\r
+ // Behaviour\r
+\r
+ /* FML ADDRESS GENERATOR */\r
+ wire next_address;\r
+\r
+ always @(posedge clk) begin\r
+ if(rst) begin\r
+ fml_adr <= {fml_depth{1'b0}};\r
+ end else begin\r
+ if(next_address) begin\r
+ fml_adr[19:0] <= { (lcd_adr + { start_addr[15:1], 2'b00 }), 1'b0 };\r
+ end\r
+ end\r
+ end\r
+\r
+ /* DCB ADDRESS GENERATOR */\r
+ reg [2:0] dcb_index;\r
+\r
+ always @(posedge clk) begin\r
+ if(dcb_stb)\r
+ dcb_index <= dcb_index + 3'd1;\r
+ else\r
+ dcb_index <= fml_adr[2:0];\r
+ end\r
+\r
+ assign dcb_adr = { fml_adr + ( { dcb_index, 1'b0 } ) };\r
+\r
+\r
+ /* CONTROLLER */\r
+ reg [4:0] state;\r
+ reg [4:0] next_state;\r
+ localparam [4:0]\r
+ IDLE = 5'd0,\r
+ DELAY = 5'b1, \r
+ TRYCACHE = 5'd2,\r
+ CACHE1 = 5'd3,\r
+ CACHE2 = 5'd4,\r
+ CACHE3 = 5'd5,\r
+ CACHE4 = 5'd6,\r
+ CACHE5 = 5'd7,\r
+ CACHE6 = 5'd8,\r
+ CACHE7 = 5'd9,\r
+ CACHE8 = 5'd10,\r
+ FML1 = 5'd11,\r
+ FML2 = 5'd12,\r
+ FML3 = 5'd13,\r
+ FML4 = 5'd14,\r
+ FML5 = 5'd15,\r
+ FML6 = 5'd16,\r
+ FML7 = 5'd17,\r
+ FML8 = 5'd18;\r
+\r
+ always @(posedge clk) begin\r
+ if(rst)\r
+ state <= IDLE; \r
+ else\r
+ state <= next_state;\r
+ end\r
+\r
+ reg next_burst;\r
+\r
+ assign next_address = next_burst;\r
+\r
+ always @(*) begin\r
+ next_state = state;\r
+\r
+ next_crtc_seq_cyc = 1'b0;\r
+ next_burst = 1'b0;\r
+\r
+ fml_stb = 1'b0;\r
+\r
+ dcb_stb = 1'b0;\r
+ fifo_source_cache = 1'b0;\r
+\r
+ case(state)\r
+ IDLE: begin\r
+ if (can_burst & !fifo_full) begin\r
+ if (lcd_stb) begin\r
+ /* LCD is requesting another fml burst ! */\r
+ next_burst = 1'b1; // This also calculates final address\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = DELAY;\r
+ end else\r
+ next_crtc_seq_cyc = 1'b1;\r
+ end\r
+ end\r
+ DELAY: begin\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = TRYCACHE;\r
+ end\r
+ /* Try to fetch from L2 first */\r
+ TRYCACHE: begin\r
+ dcb_stb = 1'b1;\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = CACHE1;\r
+ end\r
+ CACHE1: begin\r
+ fifo_source_cache = 1'b1;\r
+ if(dcb_hit) begin\r
+ dcb_stb = 1'b1;\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = CACHE2;\r
+ end else\r
+ next_state = FML1; /* Not in L2 cache, fetch from DRAM */\r
+ end\r
+ /* No need to check for cache hits anymore:\r
+ * - we fetched from the beginning of a line\r
+ * - we fetch exactly a line\r
+ * - we do not release dcb_stb so the cache controller locks the line\r
+ * Therefore, next 7 fetchs always are cache hits.\r
+ */\r
+ CACHE2: begin\r
+ dcb_stb = 1'b1;\r
+ fifo_source_cache = 1'b1;\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = CACHE3;\r
+ end\r
+ CACHE3: begin\r
+ dcb_stb = 1'b1;\r
+ fifo_source_cache = 1'b1;\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = CACHE4;\r
+ end\r
+ CACHE4: begin\r
+ dcb_stb = 1'b1;\r
+ fifo_source_cache = 1'b1;\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = CACHE5;\r
+ end\r
+ CACHE5: begin\r
+ dcb_stb = 1'b1;\r
+ fifo_source_cache = 1'b1;\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = CACHE6;\r
+ end\r
+ CACHE6: begin\r
+ dcb_stb = 1'b1;\r
+ fifo_source_cache = 1'b1;\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = CACHE7;\r
+ end\r
+ CACHE7: begin\r
+ dcb_stb = 1'b1;\r
+ fifo_source_cache = 1'b1;\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = CACHE8;\r
+ end\r
+ CACHE8: begin\r
+ fifo_source_cache = 1'b1;\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = IDLE;\r
+ end\r
+ FML1: begin\r
+ fml_stb = 1'b1;\r
+ if(fml_ack) begin\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = FML2;\r
+ end\r
+ end\r
+ FML2: begin\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = FML3;\r
+ end\r
+ FML3: begin\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = FML4;\r
+ end\r
+ FML4: begin\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = FML5;\r
+ end\r
+ FML5: begin\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = FML6;\r
+ end\r
+ FML6: begin\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = FML7;\r
+ end\r
+ FML7: begin\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = FML8;\r
+ end\r
+ FML8: begin\r
+ next_crtc_seq_cyc = 1'b1;\r
+ next_state = IDLE;\r
+ end\r
+ endcase\r
+ end\r
+\r
+ // Provide counter for pal_dac stage\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ pixel_clk_counter <= 2'b00;\r
+ end\r
+ else\r
+ begin\r
+ if (pixel_clk_counter == 2'd00) // Toggle next_pal_dac_cyc\r
+ next_pal_dac_cyc <=1'b1;\r
+ else next_pal_dac_cyc <= 1'b0;\r
+\r
+ pixel_clk_counter <= pixel_clk_counter + 2'b01; // Roll over every four cycles\r
+ end\r
+\r
+endmodule\r
+"
+"/*
+ * PS2 Mouse without FIFO buffer
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module ps2_mouse_nofifo (
+ input clk,
+ input reset,
+
+ input [7:0] writedata, // data to send
+ input write, // signal to send it
+ input inhibit,
+ output [7:0] readdata, // data read
+ output irq, // signal data has arrived
+
+ output command_was_sent,
+ output error_sending_command,
+ output buffer_overrun_error,
+
+ inout ps2_clk,
+ inout ps2_dat
+ );
+
+ // Unused outputs
+ wire start_receiving_data;
+ wire wait_for_incoming_data;
+
+ // --------------------------------------------------------------------
+ // Internal Modules
+ // --------------------------------------------------------------------
+ ps2_mouse mouse (
+ .clk (clk),
+ .reset (reset),
+
+ .the_command (writedata),
+ .send_command (write),
+
+ .received_data (readdata),
+ .received_data_en (irq),
+ .inhibit (inhibit),
+
+ .command_was_sent (command_was_sent),
+ .error_communication_timed_out (error_sending_command),
+ .start_receiving_data (start_receiving_data),
+ .wait_for_incoming_data (wait_for_incoming_data),
+
+ .ps2_clk (ps2_clk),
+ .ps2_dat (ps2_dat)
+ );
+
+ // Continous assignments
+ assign buffer_overrun_error = error_sending_command;
+
+endmodule
+"
+"/*
+ * Milkymist VJ SoC
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * added stress test by Zeus Gomez Marmolejo
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+`timescale 1ns / 1ps
+
+//`define ENABLE_VCD
+//`define TEST_SOMETRANSFERS
+//`define TEST_RANDOMTRANSFERS
+
+module tb_hpdmc;
+
+/* 100MHz system clock */
+reg clk;
+initial clk = 1\'b0;
+always #5 clk = ~clk;
+
+wire sdram_cke;
+wire sdram_cs_n;
+wire sdram_we_n;
+wire sdram_cas_n;
+wire sdram_ras_n;
+wire [1:0] sdram_dqm;
+wire [11:0] sdram_adr;
+wire [1:0] sdram_ba;
+wire [15:0] sdram_dq;
+
+ // Module instances
+ mt48lc16m16a2 #(
+ .addr_bits (12),
+ .data_bits (16),
+ .col_bits (8),
+ //.mem_sizes (4194303)
+ .mem_sizes (256)
+ ) m (
+ .Dq (sdram_dq),
+ .Addr (sdram_adr),
+ .Ba (sdram_ba),
+ .Clk (clk),
+ .Cke (sdram_cke),
+ .Cs_n (sdram_cs_n),
+ .Ras_n (sdram_ras_n),
+ .Cas_n (sdram_cas_n),
+ .We_n (sdram_we_n),
+ .Dqm (sdram_dqm)
+ );
+
+
+reg rst;
+
+reg [13:0] csr_a;
+reg csr_we;
+reg [31:0] csr_di;
+wire [31:0] csr_do;
+
+reg [22:0] fml_adr;
+reg fml_stb;
+reg fml_we;
+wire fml_ack;
+reg [1:0] fml_sel;
+reg [15:0] fml_di;
+wire [15:0] fml_do;
+
+hpdmc dut(
+\t.sys_clk(clk),
+\t.sys_rst(rst),
+
+\t.csr_a(csr_a),
+\t.csr_we(csr_we),
+\t.csr_di(csr_di),
+\t.csr_do(csr_do),
+\t
+\t.fml_adr(fml_adr),
+\t.fml_stb(fml_stb),
+\t.fml_we(fml_we),
+\t.fml_ack(fml_ack),
+\t.fml_sel(fml_sel),
+\t.fml_di(fml_di),
+\t.fml_do(fml_do),
+\t
+\t.sdram_cke(sdram_cke),
+\t.sdram_cs_n(sdram_cs_n),
+\t.sdram_we_n(sdram_we_n),
+\t.sdram_cas_n(sdram_cas_n),
+\t.sdram_ras_n(sdram_ras_n),
+\t.sdram_dqm(sdram_dqm),
+\t.sdram_adr(sdram_adr),
+\t.sdram_ba(sdram_ba),
+\t.sdram_dq(sdram_dq)
+);
+
+task waitclock;
+begin
+\t@(posedge clk);
+\t#1;
+end
+endtask
+
+task waitnclock;
+input [15:0] n;
+integer i;
+begin
+\tfor(i=0;i 32\'h80000000) begin
+\t\t\twriteburst(addr);
+\t\t\t//writeburst(addr+32\'h20);
+\t\t\t//writeburst(addr+32\'h40);
+\t\tend else begin
+\t\t\treadburst(addr);
+\t\t\t//readburst(addr+32\'h20);
+\t\t\t//readburst(addr+32\'h40);
+\t\tend
+\tend
+\t
+\t$display("""");
+\t$display(""======================================================="");
+\t$display("" Tested: %.0f reads, %.0f writes "", reads, writes);
+\t$display(""======================================================="");
+\t$display("" Average read latency: %f cycles"", read_clocks/reads);
+\t$display("" Average write latency: %f cycles"", write_clocks/writes);
+\t$display(""======================================================="");
+\t$display("" Average read bandwidth: %f MBit/s @ 100MHz"", (4/(4+read_clocks/reads))*64*100);
+\t$display("" Average write bandwidth: %f MBit/s @ 100MHz"", (4/(4+write_clocks/writes))*64*100);
+\t$display(""======================================================="");
+
+`endif
+
+//\t$finish;
+end
+
+endmodule
+
+"
+"/*
+ * 8 bit pwm DAC
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module sound_dac8 (
+ input clk,
+ input [7:0] dac_in,
+ output audio_out
+ );
+
+ reg [8:0] dac_register;
+
+ assign audio_out = dac_register[8];
+
+ always @(posedge clk) dac_register <= dac_register[7:0] + dac_in;
+
+endmodule
+"
+"/*
+ * Single channel counter of 8254 timer simplified for Zet SoC
+ * Copyright (c) 2010 YS
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+/*
+ * This module uses:
+ * - Modes (binary) 2 and 3 only
+ * Assumptions:
+ * 1. clkt is asynchronous simple wire (1.193182 MHz by default)
+ * 2. gate is synchronous (comes from Wishbone controlled register)
+ * 3. clkrw read/write clock (derived from Wishbone clock) is running
+ * always and it has much higher frequency than clkt
+ */
+
+module timer_counter(
+ input [1:0] cntnum, // Counter Number constant 0/1/2
+ input [5:0] cw0, // Initial Control Word constant
+ input [15:0] cr0, // Initial Constant Register constant
+ input clkrw, // Read/Write System Clock
+ input rst, // Reset
+ input wrc, // Write Command 1 clock pulse
+ input wrd, // Write Data 1 clock pulse
+ input rdd, // Read Data full cycle strobe
+ input [7:0] data_i, // Input Data
+ output reg [7:0] data_o, // Output Data
+ input clkt, // Timer Clock (asynchronous to clkrw)
+ input gate, // Timer Gate (synchronous to clkrw)
+ output out // Timer Out (synchronous to clkrw)
+ );
+
+ localparam
+ DATL = 2'd0,
+ DATH = 2'd1,
+ STAT = 2'd2;
+
+ reg [15:0] rCounter; // Timer Counter
+ reg [15:0] rConstant; // Constant Register
+ reg [5:0] rControl; // Control Word Register
+ reg [15:0] rLatchD; // Output Data Latch
+ reg [7:0] rLatchS; // Output State Latch
+ reg bOut;
+ reg bFn;
+
+ reg clcd, clcs; // Latch Data and Latch State command pulses
+
+ reg fWroteLow;
+ reg fWroteHigh;
+
+ reg fCount;
+ reg bCurrentClk;
+ reg bFilterClk1;
+ reg bFilterClk2;
+
+ reg fLatchData;
+ reg fLatchStat;
+
+ reg rdd1;
+ reg [1:0] outmux;
+ reg fToggleHigh;
+
+ wire fReadEnd;
+
+ wire [2:0] rbc_cnt_mask = data_i[3:1];
+
+ wire fMode3 = (rControl[2:1] == 2'b11);
+
+ wire fRWLow = rControl[4];
+ wire fRWHigh = rControl[5];
+
+ assign out = bOut;
+
+ // Write to Control Word Register
+ always @(posedge clkrw)
+ begin
+ if (rst)
+ begin
+ rControl <= cw0;
+ clcd <= 1'b0;
+ clcs <= 1'b0;
+ end
+ else
+ begin
+ if (wrc && data_i[7:6] == cntnum)
+ begin
+ if (data_i[5:4] == 2'b00)
+ clcd <= 1'b1; // CLC
+ else
+ rControl <= data_i[5:0]; // WRC
+ end
+ else if (wrc && data_i[7:6] == 2'b11 && rbc_cnt_mask[cntnum])
+ begin
+ clcd <= ~data_i[5]; // RBC
+ clcs <= ~data_i[4];
+ end
+
+ if (clcd)
+ clcd <= 1'b0; // 1 clock pulse clcd
+
+ if (clcs)
+ clcs <= 1'b0; // 1 clock pulse clcs
+ end
+ end
+
+ // Write to Constant Register
+ always @(posedge clkrw)
+ begin
+ if (rst)
+ begin
+ rConstant <= cr0;
+ fWroteLow <= 1'b0;
+ fWroteHigh <= 1'b0;
+ end
+ else
+ begin
+ if (fWroteHigh || wrc)
+ begin
+ fWroteLow <= 1'b0;
+ fWroteHigh <= 1'b0;
+ end
+ if (wrd) // need 1 clock pulse wrd!!!
+ begin
+ if (!fWroteLow)
+ begin
+ if (fRWLow)
+ rConstant[7:0] <= data_i[7:0];
+ fWroteLow <= 1'b1;
+ if (!fRWHigh)
+ begin
+ rConstant[15:8] <= 8'b00000000;
+ fWroteHigh <= 1'b1;
+ end
+ end
+ if (!fWroteHigh && (fWroteLow || !fRWLow))
+ begin
+ if (fRWHigh)
+ rConstant[15:8] <= data_i[7:0];
+ fWroteHigh <= 1'b1;
+ if (!fRWLow)
+ begin
+ rConstant[7:0] <= 8'b00000000;
+ fWroteLow <= 1'b1;
+ end
+ end
+ end // if (wrd)
+ end
+ end
+
+ // Synchronizing Count Clock with Wishbone Clock
+ always @(posedge clkrw)
+ begin
+ if (rst)
+ begin
+ fCount <= 1'b0;
+ bCurrentClk <= 1'b0;
+ bFilterClk1 <= 1'b0;
+ bFilterClk2 <= 1'b0;
+ end
+ else
+ begin
+ bFilterClk1 <= clkt;
+ bFilterClk2 <= bFilterClk1;
+ if ((bFilterClk1 == bFilterClk2) && (bCurrentClk != bFilterClk2))
+ begin
+ bCurrentClk <= bFilterClk2;
+ if (bCurrentClk == 1'b1) // falling edge of clkt
+ fCount <= 1'b1;
+ end
+ if (fCount)
+ fCount <= 1'b0; // 1 clock pulse fCount
+ end
+ end
+
+ // Timer Counter in mode 2 or mode 3
+ always @(posedge clkrw)
+ begin
+ if (rst)
+ begin
+ bOut <= 1'b1;
+ rCounter <= cr0 & ((cw0[2:1] == 2'b11) ? 16'hFFFE : 16'hFFFF); // (mode==3) ? :
+ bFn <= 1'b0;
+ end
+ else
+ begin
+ if (fWroteHigh)
+ begin
+ rCounter <= rConstant & ((fMode3) ? 16'hFFFE : 16'hFFFF);
+ bOut <= 1'b1;
+ end
+ else if (fCount && gate) // tclk_i && gate_i
+ begin
+ if ((fMode3) ? (bOut == 1'b0 && rCounter == 16'h0002) : (bOut == 1'b0))
+ begin
+ rCounter <= rConstant & ((fMode3) ? 16'hFFFE : 16'hFFFF);
+ bOut <= 1'b1;
+ end
+ else if (fMode3 && bOut == 1'b1 && rCounter == ((rConstant[0]) ? 16'h0000 : 16'h0002))
+ begin
+ rCounter <= rConstant & 16'hFFFE;
+ bOut <= 1'b0;
+ end
+ else if (!fMode3 && rCounter == 16'h0002)
+ bOut <= 1'b0;
+ else
+ rCounter <= rCounter - ((fMode3) ? 16'h0002 : 16'h0001);
+ end
+ end
+ end
+
+ // Output Latch Control
+ always @(posedge clkrw)
+ begin
+ if (rst)
+ begin
+ fLatchData <= 1'b0;
+ fLatchStat <= 1'b0;
+ rLatchD <= 16'b0;
+ rLatchS <= 8'b0;
+ end
+ else
+ begin
+ if (!fLatchData)
+ rLatchD <= rCounter;
+ if (!fLatchStat)
+ rLatchS <= {bOut, bFn, rControl};
+ if (clcd)
+ fLatchData <= 1'b1;
+ if (clcs)
+ fLatchStat <= 1'b1;
+ if (fReadEnd)
+ begin
+ if (fLatchStat)
+ fLatchStat <= 1'b0;
+ else if (fLatchData)
+ fLatchData <= 1'b0;
+ end
+ end
+ end
+
+ // Output Mux
+ always @(outmux or rLatchS or rLatchD)
+ begin
+ case (outmux)
+ STAT: data_o = rLatchS;
+ DATH: data_o = rLatchD[15:8];
+ DATL: data_o = rLatchD[7:0];
+ endcase
+ end
+
+ assign fReadEnd = !rdd && rdd1; // 1 clock pulse after read
+
+ // Read Data/State
+ always @(posedge clkrw)
+ begin
+ if (rst)
+ begin
+ rdd1 <= 1'b0;
+ outmux <= DATL;
+ fToggleHigh <= 1'b0;
+ end
+ else
+ begin
+ // Helper for fReadEnd
+ rdd1 <= rdd;
+
+ // Output Mux Control
+ if (fLatchStat)
+ outmux <= STAT;
+ else if ((fRWHigh && !fRWLow) || (fRWHigh && fToggleHigh))
+ outmux <= DATH;
+ else
+ outmux <= DATL;
+
+ if (wrc)
+ fToggleHigh <= 1'b0;
+ else if (fReadEnd && !fLatchStat)
+ fToggleHigh <= !fToggleHigh;
+ end
+ end
+
+endmodule
+"
+"/*
+ * PC speaker module using WM8731 codec
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module speaker (
+ // Clocks
+ input clk,
+ input rst,
+
+ // Wishbone slave interface
+ input [7:0] wb_dat_i,
+ output reg [7:0] wb_dat_o,
+ input wb_we_i,
+ input wb_stb_i,
+ input wb_cyc_i,
+ output wb_ack_o,
+
+ // Clocks
+ input clk_100M,
+ input clk_25M,
+ input timer2,
+
+ // I2C pad signals
+ output i2c_sclk_,
+ inout i2c_sdat_,
+
+ // Audio codec pad signals
+ input aud_adcdat_,
+ input aud_daclrck_,
+ output aud_dacdat_,
+ input aud_bclk_
+ );
+
+ // Net declaration
+ wire [15:0] audio_r;
+ wire [15:0] audio_l;
+ wire write;
+ wire spk;
+
+ // Module instances
+ speaker_iface iface (
+ .clk_i (clk_100M),
+ .rst_i (rst),
+ .datal_i (audio_l),
+ .datar_i (audio_r),
+ .datal_o (),
+ .datar_o (),
+ .ready_o (),
+ .aud_bclk_i (aud_bclk_),
+ .aud_daclrck_i (aud_daclrck_),
+ .aud_dacdat_o (aud_dacdat_),
+ .aud_adcdat_i (aud_adcdat_)
+ );
+
+ speaker_i2c_av_config i2c_av_config (
+ // Host Side
+ .clk_i (clk_25M),
+ .rst_i (rst),
+
+ // I2C Side
+ .i2c_sclk (i2c_sclk_),
+ .i2c_sdat (i2c_sdat_)
+ );
+
+ // Combinatorial logic
+ // System speaker
+ assign spk = timer2 & wb_dat_o[1];
+
+ // System speaker audio output
+ assign audio_l = {spk, 15'h4000};
+ assign audio_r = {spk, 15'h4000};
+
+ // Wishbone signals
+ assign wb_ack_o = wb_stb_i && wb_cyc_i;
+ assign write = wb_stb_i && wb_cyc_i && wb_we_i;
+
+ // Sequential logic
+ always @(posedge clk)
+ wb_dat_o <= rst ? 8'h0 : (write ? wb_dat_i : wb_dat_o);
+
+endmodule
+"
+"/*
+ * Zet synthesis stub for timing analysis
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module fpga_zet_top (
+ // Wishbone master interface
+ input clk_i,
+ input rst_i,
+ input [15:0] wb_dat_i,
+ output reg [15:0] wb_dat_o,
+ output reg [19:1] wb_adr_o,
+ output reg wb_we_o,
+ output reg wb_tga_o, // io/mem
+ output reg [ 1:0] wb_sel_o,
+ output reg wb_stb_o,
+ output reg wb_cyc_o,
+ input wb_ack_i,
+ input intr,
+ output reg inta,
+ input [ 3:0] iid,
+ output reg [19:0] pc
+ );
+
+ // Registers and nets
+ reg [15:0] wb_dat_i_l;
+ wire [15:0] wb_dat_o_l;
+ wire [19:1] wb_adr_o_l;
+ wire wb_we_o_l;
+ wire wb_tga_o_l; // io/mem
+ wire [ 1:0] wb_sel_o_l;
+ wire wb_stb_o_l;
+ wire wb_cyc_o_l;
+ reg wb_ack_i_l;
+ reg intr_l; // intr
+ wire inta_l; // inta
+ reg [ 3:0] iid_l;
+ wire [19:0] pc_l;
+
+ // Module instances
+ zet zet (
+ .clk_i (clk_i),
+ .rst_i (rst_i),
+
+ // Wishbone master interface
+ .wb_dat_i (wb_dat_i_l),
+ .wb_dat_o (wb_dat_o_l),
+ .wb_adr_o (wb_adr_o_l),
+ .wb_we_o (wb_we_o_l),
+ .wb_tga_o (wb_tga_o_l), // io/mem
+ .wb_sel_o (wb_sel_o_l),
+ .wb_stb_o (wb_stb_o_l),
+ .wb_cyc_o (wb_cyc_o_l),
+ .wb_ack_i (wb_ack_i_l),
+
+ .intr (intr_l), // intr
+ .inta (inta_l), // inta
+
+ .iid (iid_l),
+ .pc (pc_l)
+ );
+
+ always @(posedge clk_i)
+ begin
+ wb_dat_i_l <= wb_dat_i;
+ wb_dat_o <= wb_dat_o_l;
+ wb_adr_o <= wb_adr_o_l;
+ wb_we_o <= wb_we_o_l;
+ wb_tga_o <= wb_tga_o_l;
+ wb_sel_o <= wb_sel_o_l;
+ wb_stb_o <= wb_stb_o_l;
+ wb_cyc_o <= wb_cyc_o_l;
+ wb_ack_i_l <= wb_ack_i;
+ intr_l <= intr;
+ inta <= inta_l;
+ iid_l <= iid;
+ pc <= pc_l;
+ end
+
+endmodule
+"
+"/////////////////////////////////////////////////////////////////////
+//// ////
+//// generic FIFO, uses LFSRs for read/write pointers ////
+//// ////
+//// Author: Richard Herveille ////
+//// richard@asics.ws ////
+//// www.asics.ws ////
+//// ////
+/////////////////////////////////////////////////////////////////////
+//// ////
+//// Copyright (C) 2001, 2002 Richard Herveille ////
+//// richard@asics.ws ////
+//// ////
+//// This source file may be used and distributed without ////
+//// restriction provided that this copyright statement is not ////
+//// removed from the file and that any derivative work contains ////
+//// the original copyright notice and the associated disclaimer.////
+//// ////
+//// THIS SOFTWARE IS PROVIDED ``AS IS\'\' AND WITHOUT ANY ////
+//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
+//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
+//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
+//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
+//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
+//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
+//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
+//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
+//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
+//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
+//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
+//// POSSIBILITY OF SUCH DAMAGE. ////
+//// ////
+/////////////////////////////////////////////////////////////////////
+
+// CVS Log
+//
+// $Id: vga_fifo.v,v 1.8 2003-08-01 11:46:38 rherveille Exp $
+//
+// $Date: 2003-08-01 11:46:38 $
+// $Revision: 1.8 $
+// $Author: rherveille $
+// $Locker: $
+// $State: Exp $
+//
+// Change History:
+// $Log: not supported by cvs2svn $
+// Revision 1.7 2003/05/07 09:48:54 rherveille
+// Fixed some Wishbone RevB.3 related bugs.
+// Changed layout of the core. Blocks are located more logically now.
+// Started work on a dual clocked/double edge 12bit output. Commonly used by external devices like DVI transmitters.
+//
+// Revision 1.6 2002/02/07 05:42:10 rherveille
+// Fixed some bugs discovered by modified testbench
+// Removed / Changed some strange logic constructions
+// Started work on hardware cursor support (not finished yet)
+// Changed top-level name to vga_enh_top.v
+//
+/*
+//synopsys translate_off
+`include ""timescale.v""
+//synopsys translate_on
+*/
+`timescale 1ns / 1ps
+
+
+// set FIFO_RW_CHECK to prevent writing to a full and reading from an empty FIFO
+//`define FIFO_RW_CHECK
+
+// Long Pseudo Random Generators can generate (N^2 -1) combinations. This means
+// 1 FIFO entry is unavailable. This might be a problem, especially for small
+// FIFOs. Setting VGA_FIFO_ALL_ENTRIES creates additional logic that ensures that
+// all FIFO entries are used at the expense of some additional logic.
+`define VGA_FIFO_ALL_ENTRIES
+
+module vga_fifo (
+\tclk,
+\taclr,
+\tsclr,
+\twreq,
+\trreq,
+\td,
+\tq,
+\tnword,
+\tempty,
+\tfull,
+\taempty,
+\tafull
+\t);
+
+\t//
+\t// parameters
+\t//
+\tparameter aw = 3; // no.of entries (in bits; 2^7=128 entries)
+\tparameter dw = 8; // datawidth (in bits)
+
+\t//
+\t// inputs & outputs
+\t//
+\tinput clk; // master clock
+\tinput aclr; // asynchronous active low reset
+\tinput sclr; // synchronous active high reset
+
+\tinput wreq; // write request
+\tinput rreq; // read request
+\tinput [dw:1] d; // data-input
+\toutput [dw:1] q; // data-output
+
+\toutput [aw:0] nword; // number of words in FIFO
+
+\toutput empty; // fifo empty
+\toutput full; // fifo full
+
+\toutput aempty; // fifo asynchronous/almost empty (1 entry left)
+\toutput afull; // fifo asynchronous/almost full (1 entry left)
+
+\treg [aw:0] nword;
+\treg empty, full;
+
+\t//
+\t// Module body
+\t//
+\treg [aw:1] rp, wp;
+\twire [dw:1] ramq;
+\twire fwreq, frreq;
+
+`ifdef VGA_FIFO_ALL_ENTRIES
+\tfunction lsb;
+\t input [aw:1] q;
+\t case (aw)
+\t 2: lsb = ~q[2];
+\t 3: lsb = &q[aw-1:1] ^ ~(q[3] ^ q[2]);
+\t 4: lsb = &q[aw-1:1] ^ ~(q[4] ^ q[3]);
+\t 5: lsb = &q[aw-1:1] ^ ~(q[5] ^ q[3]);
+\t 6: lsb = &q[aw-1:1] ^ ~(q[6] ^ q[5]);
+\t 7: lsb = &q[aw-1:1] ^ ~(q[7] ^ q[6]);
+\t 8: lsb = &q[aw-1:1] ^ ~(q[8] ^ q[6] ^ q[5] ^ q[4]);
+\t 9: lsb = &q[aw-1:1] ^ ~(q[9] ^ q[5]);
+\t 10: lsb = &q[aw-1:1] ^ ~(q[10] ^ q[7]);
+\t 11: lsb = &q[aw-1:1] ^ ~(q[11] ^ q[9]);
+\t 12: lsb = &q[aw-1:1] ^ ~(q[12] ^ q[6] ^ q[4] ^ q[1]);
+\t 13: lsb = &q[aw-1:1] ^ ~(q[13] ^ q[4] ^ q[3] ^ q[1]);
+\t 14: lsb = &q[aw-1:1] ^ ~(q[14] ^ q[5] ^ q[3] ^ q[1]);
+\t 15: lsb = &q[aw-1:1] ^ ~(q[15] ^ q[14]);
+\t 16: lsb = &q[aw-1:1] ^ ~(q[16] ^ q[15] ^ q[13] ^ q[4]);
+\t endcase
+\tendfunction
+`else
+\tfunction lsb;
+\t input [aw:1] q;
+\t case (aw)
+\t 2: lsb = ~q[2];
+\t 3: lsb = ~(q[3] ^ q[2]);
+\t 4: lsb = ~(q[4] ^ q[3]);
+\t 5: lsb = ~(q[5] ^ q[3]);
+\t 6: lsb = ~(q[6] ^ q[5]);
+\t 7: lsb = ~(q[7] ^ q[6]);
+\t 8: lsb = ~(q[8] ^ q[6] ^ q[5] ^ q[4]);
+\t 9: lsb = ~(q[9] ^ q[5]);
+\t 10: lsb = ~(q[10] ^ q[7]);
+\t 11: lsb = ~(q[11] ^ q[9]);
+\t 12: lsb = ~(q[12] ^ q[6] ^ q[4] ^ q[1]);
+\t 13: lsb = ~(q[13] ^ q[4] ^ q[3] ^ q[1]);
+\t 14: lsb = ~(q[14] ^ q[5] ^ q[3] ^ q[1]);
+\t 15: lsb = ~(q[15] ^ q[14]);
+\t 16: lsb = ~(q[16] ^ q[15] ^ q[13] ^ q[4]);
+\t endcase
+\tendfunction
+`endif
+
+`ifdef RW_CHECK
+ assign fwreq = wreq & ~full;
+ assign frreq = rreq & ~empty;
+`else
+ assign fwreq = wreq;
+ assign frreq = rreq;
+`endif
+
+\t//
+\t// hookup read-pointer
+\t//
+\talways @(posedge clk or negedge aclr)
+\t if (~aclr) rp <= #1 0;
+\t else if (sclr) rp <= #1 0;
+\t else if (frreq) rp <= #1 {rp[aw-1:1], lsb(rp)};
+
+\t//
+\t// hookup write-pointer
+\t//
+\talways @(posedge clk or negedge aclr)
+\t if (~aclr) wp <= #1 0;
+\t else if (sclr) wp <= #1 0;
+\t else if (fwreq) wp <= #1 {wp[aw-1:1], lsb(wp)};
+
+
+\t//
+\t// hookup memory-block
+\t//
+\treg [dw:1] mem [(1<
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vga_palette_regs (
+ input clk,
+
+ // VGA read interface
+ input [3:0] attr,
+ output reg [7:0] index,
+
+ // CPU interface
+ input [3:0] address,
+ input write,
+ output reg [7:0] read_data,
+ input [7:0] write_data
+ );
+
+ // Registers
+ reg [7:0] palette [0:15];
+
+ // Behaviour
+ // VGA read interface
+ always @(posedge clk) index <= palette[attr];
+
+ // CPU read interface
+ always @(posedge clk) read_data <= palette[address];
+
+ // CPU write interface
+ always @(posedge clk)
+ if (write) palette[address] <= write_data;
+
+endmodule
+"
+"// megafunction wizard: %ALTPLL%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altpll
+
+// ============================================================
+// File Name: pll.v
+// Megafunction Name(s):
+// \t\t\taltpll
+//
+// Simulation Library Files(s):
+// \t\t\taltera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 13.0.1 Build 232 06/12/2013 SP 1 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2013 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module pll (
+\tinclk0,
+\tc0,
+\tc1,
+\tc4,
+\tlocked);
+
+\tinput\t inclk0;
+\toutput\t c0;
+\toutput\t c1;
+\toutput\t c4;
+\toutput\t locked;
+
+\twire [4:0] sub_wire0;
+\twire sub_wire2;
+\twire [0:0] sub_wire7 = 1\'h0;
+\twire [4:4] sub_wire4 = sub_wire0[4:4];
+\twire [0:0] sub_wire3 = sub_wire0[0:0];
+\twire [1:1] sub_wire1 = sub_wire0[1:1];
+\twire c1 = sub_wire1;
+\twire locked = sub_wire2;
+\twire c0 = sub_wire3;
+\twire c4 = sub_wire4;
+\twire sub_wire5 = inclk0;
+\twire [1:0] sub_wire6 = {sub_wire7, sub_wire5};
+
+\taltpll\taltpll_component (
+\t\t\t\t.inclk (sub_wire6),
+\t\t\t\t.clk (sub_wire0),
+\t\t\t\t.locked (sub_wire2),
+\t\t\t\t.activeclock (),
+\t\t\t\t.areset (1\'b0),
+\t\t\t\t.clkbad (),
+\t\t\t\t.clkena ({6{1\'b1}}),
+\t\t\t\t.clkloss (),
+\t\t\t\t.clkswitch (1\'b0),
+\t\t\t\t.configupdate (1\'b0),
+\t\t\t\t.enable0 (),
+\t\t\t\t.enable1 (),
+\t\t\t\t.extclk (),
+\t\t\t\t.extclkena ({4{1\'b1}}),
+\t\t\t\t.fbin (1\'b1),
+\t\t\t\t.fbmimicbidir (),
+\t\t\t\t.fbout (),
+\t\t\t\t.fref (),
+\t\t\t\t.icdrclk (),
+\t\t\t\t.pfdena (1\'b1),
+\t\t\t\t.phasecounterselect ({4{1\'b1}}),
+\t\t\t\t.phasedone (),
+\t\t\t\t.phasestep (1\'b1),
+\t\t\t\t.phaseupdown (1\'b1),
+\t\t\t\t.pllena (1\'b1),
+\t\t\t\t.scanaclr (1\'b0),
+\t\t\t\t.scanclk (1\'b0),
+\t\t\t\t.scanclkena (1\'b1),
+\t\t\t\t.scandata (1\'b0),
+\t\t\t\t.scandataout (),
+\t\t\t\t.scandone (),
+\t\t\t\t.scanread (1\'b0),
+\t\t\t\t.scanwrite (1\'b0),
+\t\t\t\t.sclkout0 (),
+\t\t\t\t.sclkout1 (),
+\t\t\t\t.vcooverrange (),
+\t\t\t\t.vcounderrange ());
+\tdefparam
+\t\taltpll_component.bandwidth_type = ""AUTO"",
+\t\taltpll_component.clk0_divide_by = 1,
+\t\taltpll_component.clk0_duty_cycle = 50,
+\t\taltpll_component.clk0_multiply_by = 2,
+\t\taltpll_component.clk0_phase_shift = ""0"",
+\t\taltpll_component.clk1_divide_by = 1,
+\t\taltpll_component.clk1_duty_cycle = 50,
+\t\taltpll_component.clk1_multiply_by = 2,
+\t\taltpll_component.clk1_phase_shift = ""-1750"",
+\t\taltpll_component.clk4_divide_by = 4,
+\t\taltpll_component.clk4_duty_cycle = 50,
+\t\taltpll_component.clk4_multiply_by = 1,
+\t\taltpll_component.clk4_phase_shift = ""0"",
+\t\taltpll_component.compensate_clock = ""CLK0"",
+\t\taltpll_component.inclk0_input_frequency = 20000,
+\t\taltpll_component.intended_device_family = ""Cyclone IV E"",
+\t\taltpll_component.lpm_hint = ""CBX_MODULE_PREFIX=pll"",
+\t\taltpll_component.lpm_type = ""altpll"",
+\t\taltpll_component.operation_mode = ""NORMAL"",
+\t\taltpll_component.pll_type = ""AUTO"",
+\t\taltpll_component.port_activeclock = ""PORT_UNUSED"",
+\t\taltpll_component.port_areset = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkbad0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkbad1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkloss = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkswitch = ""PORT_UNUSED"",
+\t\taltpll_component.port_configupdate = ""PORT_UNUSED"",
+\t\taltpll_component.port_fbin = ""PORT_UNUSED"",
+\t\taltpll_component.port_inclk0 = ""PORT_USED"",
+\t\taltpll_component.port_inclk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_locked = ""PORT_USED"",
+\t\taltpll_component.port_pfdena = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasecounterselect = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasedone = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasestep = ""PORT_UNUSED"",
+\t\taltpll_component.port_phaseupdown = ""PORT_UNUSED"",
+\t\taltpll_component.port_pllena = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanaclr = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanclk = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanclkena = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandata = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandataout = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandone = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanread = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanwrite = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk0 = ""PORT_USED"",
+\t\taltpll_component.port_clk1 = ""PORT_USED"",
+\t\taltpll_component.port_clk2 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk3 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk4 = ""PORT_USED"",
+\t\taltpll_component.port_clk5 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena2 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena3 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena4 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena5 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk2 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk3 = ""PORT_UNUSED"",
+\t\taltpll_component.self_reset_on_loss_lock = ""OFF"",
+\t\taltpll_component.width_clock = 5;
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH STRING ""1.000""
+// Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING ""MHz""
+// Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING ""Low""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING ""1""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING ""0""
+// Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CLKLOSS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING ""0""
+// Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING ""c0""
+// Retrieval info: PRIVATE: CUR_FBIN_CLK STRING ""c0""
+// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING ""7""
+// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: DIV_FACTOR1 NUMERIC ""1""
+// Retrieval info: PRIVATE: DIV_FACTOR4 NUMERIC ""1""
+// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING ""50.00000000""
+// Retrieval info: PRIVATE: DUTY_CYCLE1 STRING ""50.00000000""
+// Retrieval info: PRIVATE: DUTY_CYCLE4 STRING ""50.00000000""
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING ""100.000000""
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE1 STRING ""100.000000""
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE4 STRING ""12.500000""
+// Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING ""0""
+// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING ""0""
+// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING ""0""
+// Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC ""1048575""
+// Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING ""1""
+// Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING ""50.000""
+// Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING ""100.000""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone IV E""
+// Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING ""1""
+// Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING ""1""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING ""Not Available""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC ""0""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT1 STRING ""deg""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT4 STRING ""ps""
+// Retrieval info: PRIVATE: MIG_DEVICE_SPEED_GRADE STRING ""Any""
+// Retrieval info: PRIVATE: MIRROR_CLK0 STRING ""0""
+// Retrieval info: PRIVATE: MIRROR_CLK1 STRING ""0""
+// Retrieval info: PRIVATE: MIRROR_CLK4 STRING ""0""
+// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: MULT_FACTOR1 NUMERIC ""1""
+// Retrieval info: PRIVATE: MULT_FACTOR4 NUMERIC ""1""
+// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING ""100.00000000""
+// Retrieval info: PRIVATE: OUTPUT_FREQ1 STRING ""100.00000000""
+// Retrieval info: PRIVATE: OUTPUT_FREQ4 STRING ""12.50000000""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE1 STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE4 STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING ""MHz""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT1 STRING ""MHz""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT4 STRING ""MHz""
+// Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: PHASE_RECONFIG_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING ""0.00000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT1 STRING ""-63.00000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT4 STRING ""0.00000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT_STEP_ENABLED_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT1 STRING ""deg""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT4 STRING ""ps""
+// Retrieval info: PRIVATE: PLL_ADVANCED_PARAM_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC ""1""
+// Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_FBMIMIC_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_TARGET_HARCOPY_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING ""inclk0""
+// Retrieval info: PRIVATE: RECONFIG_FILE STRING ""pll.mif""
+// Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: SELF_RESET_LOCK_LOSS STRING ""0""
+// Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FREQ STRING ""50.000""
+// Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING ""KHz""
+// Retrieval info: PRIVATE: SPREAD_PERCENT STRING ""0.500""
+// Retrieval info: PRIVATE: SPREAD_USE STRING ""0""
+// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING ""0""
+// Retrieval info: PRIVATE: STICKY_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: STICKY_CLK1 STRING ""1""
+// Retrieval info: PRIVATE: STICKY_CLK4 STRING ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING ""0""
+// Retrieval info: PRIVATE: USE_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: USE_CLK1 STRING ""1""
+// Retrieval info: PRIVATE: USE_CLK4 STRING ""1""
+// Retrieval info: PRIVATE: USE_CLKENA0 STRING ""0""
+// Retrieval info: PRIVATE: USE_CLKENA1 STRING ""0""
+// Retrieval info: PRIVATE: USE_CLKENA4 STRING ""0""
+// Retrieval info: PRIVATE: USE_MIL_SPEED_GRADE NUMERIC ""0""
+// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING ""0""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: BANDWIDTH_TYPE STRING ""AUTO""
+// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC ""2""
+// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING ""0""
+// Retrieval info: CONSTANT: CLK1_DIVIDE_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: CLK1_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: CLK1_MULTIPLY_BY NUMERIC ""2""
+// Retrieval info: CONSTANT: CLK1_PHASE_SHIFT STRING ""-1750""
+// Retrieval info: CONSTANT: CLK4_DIVIDE_BY NUMERIC ""4""
+// Retrieval info: CONSTANT: CLK4_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: CLK4_MULTIPLY_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: CLK4_PHASE_SHIFT STRING ""0""
+// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING ""CLK0""
+// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC ""20000""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone IV E""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""altpll""
+// Retrieval info: CONSTANT: OPERATION_MODE STRING ""NORMAL""
+// Retrieval info: CONSTANT: PLL_TYPE STRING ""AUTO""
+// Retrieval info: CONSTANT: PORT_ACTIVECLOCK STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_ARESET STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKBAD0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKBAD1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKLOSS STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKSWITCH STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CONFIGUPDATE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_FBIN STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_INCLK0 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_INCLK1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_LOCKED STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_PFDENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASECOUNTERSELECT STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASEDONE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASESTEP STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASEUPDOWN STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PLLENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANACLR STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANCLK STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANCLKENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDATA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDATAOUT STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDONE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANREAD STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANWRITE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk0 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_clk1 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_clk2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk4 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_clk5 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena4 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena5 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: SELF_RESET_ON_LOSS_LOCK STRING ""OFF""
+// Retrieval info: CONSTANT: WIDTH_CLOCK NUMERIC ""5""
+// Retrieval info: USED_PORT: @clk 0 0 5 0 OUTPUT_CLK_EXT VCC ""@clk[4..0]""
+// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT_CLK_EXT VCC ""c0""
+// Retrieval info: USED_PORT: c1 0 0 0 0 OUTPUT_CLK_EXT VCC ""c1""
+// Retrieval info: USED_PORT: c4 0 0 0 0 OUTPUT_CLK_EXT VCC ""c4""
+// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT_CLK_EXT GND ""inclk0""
+// Retrieval info: USED_PORT: locked 0 0 0 0 OUTPUT GND ""locked""
+// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
+// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
+// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
+// Retrieval info: CONNECT: c1 0 0 0 0 @clk 0 0 1 1
+// Retrieval info: CONNECT: c4 0 0 0 0 @clk 0 0 1 4
+// Retrieval info: CONNECT: locked 0 0 0 0 @locked 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.ppf TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_bb.v FALSE
+// Retrieval info: LIB_FILE: altera_mf
+// Retrieval info: CBX_MODULE_PREFIX: ON
+"
+"/*\r
+ * Sequencer controller for VGA\r
+ * Copyright (C) 2010 Zeus Gomez Marmolejo \r
+ *\r
+ * VGA FML support\r
+ * Copyright (C) 2013 Charley Picker \r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+module vga_sequencer_fml (\r
+ input clk, // 100 Mhz clock\r
+ input rst,\r
+\r
+ input enable_sequencer,\r
+\r
+ // Sequencer input signals\r
+\r
+ input [9:0] h_count,\r
+ input horiz_sync_i,\r
+\r
+ input [9:0] v_count,\r
+ input vert_sync,\r
+\r
+ input video_on_h_i,\r
+ input video_on_v,\r
+\r
+ // Sequencer configuration signals\r
+\r
+ input shift_reg1, // if set: 320x200\r
+ input graphics_alpha, // if not set: 640x400 text mode\r
+\r
+ // CSR slave interface for reading\r
+ output [17:1] fml_adr_o,\r
+ input [15:0] fml_dat_i,\r
+ output fml_stb_o,\r
+\r
+ // CRTC\r
+ input [5:0] cur_start,\r
+ input [5:0] cur_end,\r
+ input [4:0] vcursor,\r
+ input [6:0] hcursor,\r
+\r
+ input x_dotclockdiv2,\r
+\r
+ // Sequencer output signals\r
+\r
+ output horiz_sync_seq_o,\r
+ output vert_sync_seq_o,\r
+ output video_on_h_seq_o,\r
+ output video_on_v_seq_o,\r
+ output [7:0] character_seq_o \r
+\r
+ );\r
+\r
+ // Registers and nets \r
+ reg [1:0] video_on_h_p;\r
+\r
+ wire [3:0] attr_wm;\r
+ wire [3:0] attr_tm;\r
+ wire [7:0] color;\r
+\r
+ wire video_on_h_tm;\r
+ wire video_on_h_wm;\r
+ wire video_on_h_gm;\r
+ wire video_on_h;\r
+\r
+ wire horiz_sync_tm;\r
+ wire horiz_sync_wm;\r
+ wire horiz_sync_gm;\r
+\r
+ wire [16:1] csr_tm_adr_o;\r
+ wire csr_tm_stb_o;\r
+ wire [17:1] csr_wm_adr_o;\r
+ wire csr_wm_stb_o;\r
+ wire [17:1] csr_gm_adr_o;\r
+ wire csr_gm_stb_o;\r
+ wire fml_stb_o_tmp;\r
+\r
+ // Module instances\r
+ vga_text_mode_fml text_mode (\r
+ .clk (clk),\r
+ .rst (rst),\r
+ \r
+ .enable (enable_sequencer),\r
+\r
+ // CSR slave interface for reading\r
+ .fml_adr_o (csr_tm_adr_o),\r
+ .fml_dat_i (fml_dat_i),\r
+ .fml_stb_o (csr_tm_stb_o),\r
+\r
+ .h_count (h_count),\r
+ .v_count (v_count),\r
+ .horiz_sync_i (horiz_sync_i),\r
+ .video_on_h_i (video_on_h_i),\r
+ .video_on_h_o (video_on_h_tm),\r
+\r
+ .cur_start (cur_start),\r
+ .cur_end (cur_end),\r
+ .vcursor (vcursor),\r
+ .hcursor (hcursor),\r
+\r
+ .attr (attr_tm),\r
+ .horiz_sync_o (horiz_sync_tm)\r
+ );\r
+\r
+ vga_planar_fml planar (\r
+ .clk (clk),\r
+ .rst (rst),\r
+\r
+ .enable (enable_sequencer),\r
+\r
+ // CSR slave interface for reading\r
+ .fml_adr_o (csr_wm_adr_o),\r
+ .fml_dat_i (fml_dat_i),\r
+ .fml_stb_o (csr_wm_stb_o),\r
+\r
+ .attr_plane_enable (4'hf),\r
+ .x_dotclockdiv2 (x_dotclockdiv2),\r
+\r
+ .h_count (h_count),\r
+ .v_count (v_count),\r
+ .horiz_sync_i (horiz_sync_i),\r
+ .video_on_h_i (video_on_h_i),\r
+ .video_on_h_o (video_on_h_wm),\r
+\r
+ .attr (attr_wm),\r
+ .horiz_sync_o (horiz_sync_wm)\r
+ );\r
+\r
+ vga_linear_fml linear (\r
+ .clk (clk),\r
+ .rst (rst),\r
+\r
+ .enable (enable_sequencer),\r
+\r
+ // CSR slave interface for reading\r
+ .fml_adr_o (csr_gm_adr_o),\r
+ .fml_dat_i (fml_dat_i),\r
+ .fml_stb_o (csr_gm_stb_o),\r
+\r
+ .h_count (h_count),\r
+ .v_count (v_count),\r
+ .horiz_sync_i (horiz_sync_i),\r
+ .video_on_h_i (video_on_h_i),\r
+ .video_on_h_o (video_on_h_gm),\r
+\r
+ .color (color),\r
+ .horiz_sync_o (horiz_sync_gm)\r
+ );\r
+\r
+ // Continuous assignments\r
+ assign video_on_h = video_on_h_p[1];\r
+\r
+ assign fml_adr_o = graphics_alpha ?\r
+ (shift_reg1 ? csr_gm_adr_o : csr_wm_adr_o) : { 1'b0, csr_tm_adr_o };\r
+\r
+ assign fml_stb_o_tmp = graphics_alpha ?\r
+ (shift_reg1 ? csr_gm_stb_o : csr_wm_stb_o) : csr_tm_stb_o;\r
+ assign fml_stb_o = fml_stb_o_tmp & (video_on_h_i | video_on_h) & video_on_v;\r
+\r
+ // Video mode sequencer horiz_sync that will be passed to next stage\r
+ assign horiz_sync_seq_o = graphics_alpha ?\r
+ (shift_reg1 ? horiz_sync_gm : horiz_sync_wm) : horiz_sync_tm;\r
+\r
+ // Pass through vert_sync to next stage\r
+ assign vert_sync_seq_o = vert_sync;\r
+\r
+ // Video mode sequencer video_on_h that will be passed to next stage\r
+ assign video_on_h_seq_o = graphics_alpha ?\r
+ (shift_reg1 ? video_on_h_gm : video_on_h_wm) : video_on_h_tm;\r
+\r
+ // Pass through video_on_v to next stage\r
+ assign video_on_v_seq_o = video_on_v;\r
+\r
+ // Video mode sequencer character that will be passed to next stage\r
+ assign character_seq_o = graphics_alpha ?\r
+ (shift_reg1 ? color : { 4'b0, attr_wm }) : { 4'b0, attr_tm };\r
+\r
+ // Video_on pipe used only for video_on_h signal \r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ video_on_h_p <= 2'b0;\r
+ end\r
+ else\r
+ if (enable_sequencer)\r
+ begin\r
+ video_on_h_p <= { video_on_h_p[0],\r
+ graphics_alpha ? (shift_reg1 ? video_on_h_gm : video_on_h_wm)\r
+ : video_on_h_tm }; \r
+ end\r
+\r
+endmodule\r
+"
+"/*
+ * Chain 4 memory interface for VGA
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vga_c4_iface (
+ // Wishbone common signals
+ input wb_clk_i,
+ input wb_rst_i,
+
+ // Wishbone slave interface
+ input [16:1] wbs_adr_i,
+ input [ 1:0] wbs_sel_i,
+ input wbs_we_i,
+ input [15:0] wbs_dat_i,
+ output [15:0] wbs_dat_o,
+ input wbs_stb_i,
+ output wbs_ack_o,
+
+ // Wishbone master to SRAM
+ output [17:1] wbm_adr_o,
+ output [ 1:0] wbm_sel_o,
+ output wbm_we_o,
+ output [15:0] wbm_dat_o,
+ input [15:0] wbm_dat_i,
+ output reg wbm_stb_o,
+ input wbm_ack_i
+ );
+
+ // Registers and nets
+ reg plane_low;
+ reg [7:0] dat_low;
+ wire cont;
+
+ // Continuous assignments
+ assign wbs_ack_o = (plane_low & wbm_ack_i);
+ assign wbm_adr_o = { 1'b0, wbs_adr_i[15:2], wbs_adr_i[1], plane_low };
+ assign wbs_dat_o = { wbm_dat_i[7:0], dat_low };
+ assign wbm_sel_o = 2'b01;
+ assign wbm_dat_o = { 8'h0, plane_low ? wbs_dat_i[15:8] : wbs_dat_i[7:0] };
+ assign wbm_we_o = wbs_we_i & ((!plane_low & wbs_sel_i[0])
+ | (plane_low & wbs_sel_i[1]));
+
+ assign cont = wbm_ack_i && wbs_stb_i;
+
+ // Behaviour
+ // wbm_stb_o
+ always @(posedge wb_clk_i)
+ wbm_stb_o <= wb_rst_i ? 1'b0 : (wbm_stb_o ? ~wbs_ack_o : wbs_stb_i);
+
+ // plane_low
+ always @(posedge wb_clk_i)
+ plane_low <= wb_rst_i ? 1'b0 : (cont ? !plane_low : plane_low);
+
+ // dat_low
+ always @(posedge wb_clk_i)
+ dat_low <= wb_rst_i ? 8'h0
+ : ((wbm_ack_i && wbm_stb_o && !plane_low) ? wbm_dat_i[7:0] : dat_low);
+
+endmodule
+"
+"/*
+ * Integer multiply/divide module for Zet
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_muldiv (
+ input [31:0] x, // 16 MSb for division
+ input [15:0] y,
+ output [31:0] o,
+ input [ 2:0] f,
+ input word_op,
+ output cfo,
+ output ofo,
+ input clk,
+ output exc
+ );
+
+ // Net declarations
+ wire as, bs, cfs, cfu;
+ wire [16:0] a, b;
+ wire [33:0] p;
+ wire div0, over, ovf, mint;
+
+ wire [33:0] zi;
+ wire [16:0] di;
+ wire [17:0] q;
+ wire [17:0] s;
+
+ // Module instantiations
+ zet_signmul17 signmul17 (
+ .clk (clk),
+ .a (a),
+ .b (b),
+ .p (p)
+ );
+
+ zet_div_su #(
+ .z_width(34)
+ ) div_su (
+ .clk (clk),
+ .ena (1'b1),
+ .z (zi),
+ .d (di),
+ .q (q),
+ .s (s),
+ .ovf (ovf)
+ );
+
+ // Sign ext. for imul
+ assign as = f[0] & (word_op ? x[15] : x[7]);
+ assign bs = f[0] & (word_op ? y[15] : y[7]);
+ assign a = word_op ? { as, x[15:0] }
+ : { {9{as}}, x[7:0] };
+ assign b = word_op ? { bs, y } : { {9{bs}}, y[7:0] };
+
+ assign zi = f[2] ? { 26'h0, x[7:0] }
+ : (word_op ? (f[0] ? { {2{x[31]}}, x }
+ : { 2'b0, x })
+ : (f[0] ? { {18{x[15]}}, x[15:0] }
+ : { 18'b0, x[15:0] }));
+
+ assign di = word_op ? (f[0] ? { y[15], y } : { 1'b0, y })
+ : (f[0] ? { {9{y[7]}}, y[7:0] }
+ : { 9'h000, y[7:0] });
+
+ assign o = f[2] ? { 16'h0, q[7:0], s[7:0] }
+ : (f[1] ? ( word_op ? {s[15:0], q[15:0]}
+ : {16'h0, s[7:0], q[7:0]})
+ : p[31:0]);
+
+ assign ofo = f[1] ? 1'b0 : cfo;
+ assign cfo = f[1] ? 1'b0 : !(f[0] ? cfs : cfu);
+ assign cfu = word_op ? (o[31:16] == 16'h0)
+ : (o[15:8] == 8'h0);
+ assign cfs = word_op ? (o[31:16] == {16{o[15]}})
+ : (o[15:8] == {8{o[7]}});
+
+ // Exceptions
+ assign over = word_op ? (f[0] ? (q[17:16]!={2{q[15]}})
+ : (q[17:16]!=2'b0) )
+ : (f[0] ? (q[17:8]!={10{q[7]}})
+ : (q[17:8]!=10'h000));
+ assign mint = f[0] & (word_op ? (x==32'h80000000)
+ : (x==16'h8000));
+ assign div0 = ~|di;
+ assign exc = div0 | (!f[2] & (ovf | over | mint));
+endmodule
+"
+"/*
+ * Copyright (c) 2008 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`timescale 1ns/10ps
+
+module zet_jmp_cond (
+ input [4:0] logic_flags,
+ input [3:0] cond,
+ input is_cx,
+ input [15:0] cx,
+ output reg jmp
+ );
+
+ // Net declarations
+ wire of, sf, zf, pf, cf;
+ wire cx_zero;
+
+ // Assignments
+ assign of = logic_flags[4];
+ assign sf = logic_flags[3];
+ assign zf = logic_flags[2];
+ assign pf = logic_flags[1];
+ assign cf = logic_flags[0];
+ assign cx_zero = ~(|cx);
+
+ // Behaviour
+ always @(cond or is_cx or cx_zero or zf or of or cf or sf or pf)
+ if (is_cx) case (cond)
+ 4'b0000: jmp <= cx_zero; /* jcxz */
+ 4'b0001: jmp <= ~cx_zero; /* loop */
+ 4'b0010: jmp <= zf & ~cx_zero; /* loopz */
+ default: jmp <= ~zf & ~cx_zero; /* loopnz */
+ endcase
+ else case (cond)
+ 4'b0000: jmp <= of;
+ 4'b0001: jmp <= ~of;
+ 4'b0010: jmp <= cf;
+ 4'b0011: jmp <= ~cf;
+ 4'b0100: jmp <= zf;
+ 4'b0101: jmp <= ~zf;
+ 4'b0110: jmp <= cf | zf;
+ 4'b0111: jmp <= ~cf & ~zf;
+
+ 4'b1000: jmp <= sf;
+ 4'b1001: jmp <= ~sf;
+ 4'b1010: jmp <= pf;
+ 4'b1011: jmp <= ~pf;
+ 4'b1100: jmp <= (sf ^ of);
+ 4'b1101: jmp <= (sf ^~ of);
+ 4'b1110: jmp <= zf | (sf ^ of);
+ 4'b1111: jmp <= ~zf & (sf ^~ of);
+ endcase
+endmodule
+"
+"/*
+ * Milkymist VJ SoC
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * adjusted to FML 8x16 by Zeus Gomez Marmolejo
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+module hpdmc #(
+ parameter csr_addr = 1\'b0,
+
+ /*
+ * The depth of the SDRAM array, in bytes.
+ * Capacity (in bytes) is 2^sdram_depth.
+ */
+ parameter sdram_depth = 23,
+
+ /*
+ * The number of column address bits of the SDRAM.
+ */
+ parameter sdram_columndepth = 8,
+
+ /*
+ * Address Mapping :
+ * | ROW ADDRESS | BANK NUMBER | COL ADDRESS | for 16-bit words
+ * |depth-1 coldepth+2|coldepth+1 coldepth|coldepth-1 0|
+ * (depth for 16-bit words, which is sdram_depth-1)
+ */
+ parameter sdram_addrdepth = sdram_depth-1-1-(sdram_columndepth+2)+1
+
+ )(
+ input sys_clk,
+\tinput sys_rst,
+\t
+\t/* Control interface */
+\tinput [2:0] csr_a,
+\tinput csr_we,
+\tinput [15:0] csr_di,
+\toutput [15:0] csr_do,
+\t
+\t/* Simple FML 8x16 interface to the memory contents */
+\tinput [sdram_depth-1:0] fml_adr,
+\tinput fml_stb,
+\tinput fml_we,
+\toutput fml_ack,
+\tinput [1:0] fml_sel,
+\tinput [15:0] fml_di,
+\toutput [15:0] fml_do,
+\t
+\t/* SDRAM interface.
+\t * The SDRAM clock should be driven synchronously to the system clock.
+\t * It is not generated inside this core so you can take advantage of
+\t * architecture-dependent clocking resources to generate a clean
+\t * differential clock.
+\t */
+\toutput reg sdram_cke,
+\toutput reg sdram_cs_n,
+\toutput reg sdram_we_n,
+\toutput reg sdram_cas_n,
+\toutput reg sdram_ras_n,
+\toutput reg [sdram_addrdepth-1:0] sdram_adr,
+\toutput reg [1:0] sdram_ba,
+\t
+\toutput [1:0] sdram_dqm,
+\tinout [15:0] sdram_dq
+);
+
+/* Register all control signals, leaving the possibility to use IOB registers */
+wire sdram_cke_r;
+wire sdram_cs_n_r;
+wire sdram_we_n_r;
+wire sdram_cas_n_r;
+wire sdram_ras_n_r;
+wire [sdram_addrdepth-1:0] sdram_adr_r;
+wire [1:0] sdram_ba_r;
+
+always @(posedge sys_clk) begin
+\tsdram_cke <= sdram_cke_r;
+\tsdram_cs_n <= sdram_cs_n_r;
+\tsdram_we_n <= sdram_we_n_r;
+\tsdram_cas_n <= sdram_cas_n_r;
+\tsdram_ras_n <= sdram_ras_n_r;
+\tsdram_ba <= sdram_ba_r;
+\tsdram_adr <= sdram_adr_r;
+end
+
+/* Mux the control signals according to the ""bypass"" selection.
+ * CKE always comes from the control interface.
+ */
+wire bypass;
+
+wire sdram_cs_n_bypass;
+wire sdram_we_n_bypass;
+wire sdram_cas_n_bypass;
+wire sdram_ras_n_bypass;
+wire [sdram_addrdepth-1:0] sdram_adr_bypass;
+wire [1:0] sdram_ba_bypass;
+
+wire sdram_cs_n_mgmt;
+wire sdram_we_n_mgmt;
+wire sdram_cas_n_mgmt;
+wire sdram_ras_n_mgmt;
+wire [sdram_addrdepth-1:0] sdram_adr_mgmt;
+wire [1:0] sdram_ba_mgmt;
+
+assign sdram_cs_n_r = bypass ? sdram_cs_n_bypass : sdram_cs_n_mgmt;
+assign sdram_we_n_r = bypass ? sdram_we_n_bypass : sdram_we_n_mgmt;
+assign sdram_cas_n_r = bypass ? sdram_cas_n_bypass : sdram_cas_n_mgmt;
+assign sdram_ras_n_r = bypass ? sdram_ras_n_bypass : sdram_ras_n_mgmt;
+assign sdram_adr_r = bypass ? sdram_adr_bypass : sdram_adr_mgmt;
+assign sdram_ba_r = bypass ? sdram_ba_bypass : sdram_ba_mgmt;
+
+/* Control interface */
+wire sdram_rst;
+
+wire [2:0] tim_rp;
+wire [2:0] tim_rcd;
+wire tim_cas;
+wire [10:0] tim_refi;
+wire [3:0] tim_rfc;
+wire [1:0] tim_wr;
+
+hpdmc_ctlif #(
+\t.csr_addr (csr_addr),
+\t.sdram_addrdepth (sdram_addrdepth)
+) ctlif (
+\t.sys_clk(sys_clk),
+\t.sys_rst(sys_rst),
+\t
+\t.csr_a(csr_a),
+\t.csr_we(csr_we),
+\t.csr_di(csr_di),
+\t.csr_do(csr_do),
+\t
+\t.bypass(bypass),
+\t.sdram_rst(sdram_rst),
+\t
+\t.sdram_cke(sdram_cke_r),
+\t.sdram_cs_n(sdram_cs_n_bypass),
+\t.sdram_we_n(sdram_we_n_bypass),
+\t.sdram_cas_n(sdram_cas_n_bypass),
+\t.sdram_ras_n(sdram_ras_n_bypass),
+\t.sdram_adr(sdram_adr_bypass),
+\t.sdram_ba(sdram_ba_bypass),
+\t
+\t.tim_rp(tim_rp),
+\t.tim_rcd(tim_rcd),
+\t.tim_cas(tim_cas),
+\t.tim_refi(tim_refi),
+\t.tim_rfc(tim_rfc),
+\t.tim_wr(tim_wr)
+);
+
+/* SDRAM management unit */
+wire mgmt_stb;
+wire mgmt_we;
+wire [sdram_depth-1-1:0] mgmt_address;
+wire mgmt_ack;
+
+wire read;
+wire write;
+wire [3:0] concerned_bank;
+wire read_safe;
+wire write_safe;
+wire [3:0] precharge_safe;
+
+hpdmc_mgmt #(
+\t.sdram_depth(sdram_depth),
+\t.sdram_columndepth(sdram_columndepth)
+) mgmt (
+\t.sys_clk(sys_clk),
+\t.sdram_rst(sdram_rst),
+\t
+\t.tim_rp(tim_rp),
+\t.tim_rcd(tim_rcd),
+\t.tim_refi(tim_refi),
+\t.tim_rfc(tim_rfc),
+\t
+\t.stb(mgmt_stb),
+\t.we(mgmt_we),
+\t.address(mgmt_address),
+\t.ack(mgmt_ack),
+\t
+\t.read(read),
+\t.write(write),
+\t.concerned_bank(concerned_bank),
+\t.read_safe(read_safe),
+\t.write_safe(write_safe),
+\t.precharge_safe(precharge_safe),
+\t
+\t.sdram_cs_n(sdram_cs_n_mgmt),
+\t.sdram_we_n(sdram_we_n_mgmt),
+\t.sdram_cas_n(sdram_cas_n_mgmt),
+\t.sdram_ras_n(sdram_ras_n_mgmt),
+\t.sdram_adr(sdram_adr_mgmt),
+\t.sdram_ba(sdram_ba_mgmt)
+);
+
+/* Bus interface */
+wire data_ack;
+
+hpdmc_busif #(
+\t.sdram_depth(sdram_depth)
+) busif (
+\t.sys_clk(sys_clk),
+\t.sdram_rst(sdram_rst),
+\t
+\t.fml_adr(fml_adr),
+\t.fml_stb(fml_stb),
+\t.fml_we(fml_we),
+\t.fml_ack(fml_ack),
+\t
+\t.mgmt_stb(mgmt_stb),
+\t.mgmt_we(mgmt_we),
+\t.mgmt_address(mgmt_address),
+\t.mgmt_ack(mgmt_ack),
+\t
+\t.data_ack(data_ack)
+);
+
+/* Data path controller */
+wire direction;
+wire direction_r;
+
+hpdmc_datactl datactl(
+\t.sys_clk(sys_clk),
+\t.sdram_rst(sdram_rst),
+\t
+\t.read(read),
+\t.write(write),
+\t.concerned_bank(concerned_bank),
+\t.read_safe(read_safe),
+\t.write_safe(write_safe),
+\t.precharge_safe(precharge_safe),
+\t
+\t.ack(data_ack),
+\t.direction(direction),
+\t.direction_r(direction_r),
+\t
+\t.tim_cas(tim_cas),
+\t.tim_wr(tim_wr)
+);
+
+/* Data path */
+hpdmc_sdrio sdrio(
+\t.sys_clk(sys_clk),
+\t
+\t.direction(direction),
+\t.direction_r(direction_r),
+\t/* Bit meaning is the opposite between
+\t * the FML selection signal and SDRAM DQM pins.
+\t */
+\t.mo(~fml_sel),
+\t.dout(fml_di),
+\t.di(fml_do),
+\t
+\t.sdram_dqm(sdram_dqm),
+\t.sdram_dq(sdram_dq)
+);
+
+endmodule
+"
+"/*
+ * Wishbone master interface module for Zet
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_wb_master (
+ input cpu_byte_o,
+ input cpu_memop,
+ input cpu_m_io,
+ input [19:0] cpu_adr_o,
+ output reg cpu_block,
+ output reg [15:0] cpu_dat_i,
+ input [15:0] cpu_dat_o,
+ input cpu_we_o,
+
+ input wb_clk_i,
+ input wb_rst_i,
+ input [15:0] wb_dat_i,
+ output reg [15:0] wb_dat_o,
+ output reg [19:1] wb_adr_o,
+ output wb_we_o,
+ output wb_tga_o,
+ output reg [ 1:0] wb_sel_o,
+ output reg wb_stb_o,
+ output wb_cyc_o,
+ input wb_ack_i
+ );
+
+ // Register and nets declarations
+ reg [ 1:0] cs; // current state
+ reg [ 1:0] ns; // next state
+ reg [19:1] adr1; // next address (for unaligned acc)
+
+ wire op; // in an operation
+ wire odd_word; // unaligned word
+ wire a0; // address 0 pin
+ wire [15:0] blw; // low byte (sign extended)
+ wire [15:0] bhw; // high byte (sign extended)
+ wire [ 1:0] sel_o; // bus byte select
+
+ // Declare the symbolic names for states
+ localparam [1:0]
+ IDLE = 2'd0,
+ stb1_hi = 2'd1,
+ stb2_hi = 2'd2,
+ bloc_lo = 2'd3;
+
+ // Assignments
+ assign op = (cpu_memop | cpu_m_io);
+ assign odd_word = (cpu_adr_o[0] & !cpu_byte_o);
+ assign a0 = cpu_adr_o[0];
+ assign blw = { {8{wb_dat_i[7]}}, wb_dat_i[7:0] };
+ assign bhw = { {8{wb_dat_i[15]}}, wb_dat_i[15:8] };
+ assign wb_we_o = cpu_we_o;
+ assign wb_tga_o = cpu_m_io;
+ assign sel_o = a0 ? 2'b10 : (cpu_byte_o ? 2'b01 : 2'b11);
+ assign wb_cyc_o = wb_stb_o;
+
+ // Behaviour
+ // cpu_dat_i
+ always @(posedge wb_clk_i)
+ cpu_dat_i <= cpu_we_o ? cpu_dat_i : ((cs == stb1_hi) ?
+ (wb_ack_i ?
+ (a0 ? bhw : (cpu_byte_o ? blw : wb_dat_i))
+ : cpu_dat_i)
+ : ((cs == stb2_hi && wb_ack_i) ?
+ { wb_dat_i[7:0], cpu_dat_i[7:0] }
+ : cpu_dat_i));
+
+ // adr1
+ always @(posedge wb_clk_i)
+ adr1 <= cpu_adr_o[19:1] + 1'b1;
+
+ // wb_adr_o
+ always @(posedge wb_clk_i)
+ wb_adr_o <= (ns==stb2_hi) ? adr1 : cpu_adr_o[19:1];
+
+ // wb_sel_o
+ always @(posedge wb_clk_i)
+ wb_sel_o <= (ns==stb1_hi) ? sel_o : 2'b01;
+
+ // wb_stb_o
+ always @(posedge wb_clk_i)
+ wb_stb_o <= (ns==stb1_hi || ns==stb2_hi);
+
+ // wb_dat_o
+ always @(posedge wb_clk_i)
+ wb_dat_o <= a0 ? { cpu_dat_o[7:0], cpu_dat_o[15:8] }
+ : cpu_dat_o;
+
+ // cpu_block
+ always @(*)
+ case (cs)
+ IDLE: cpu_block <= op;
+ default: cpu_block <= 1'b1;
+ bloc_lo: cpu_block <= wb_ack_i;
+ endcase
+
+ // state machine
+ // cs - current state
+ always @(posedge wb_clk_i)
+ cs <= wb_rst_i ? IDLE : ns;
+
+ // ns - next state
+ always @(*)
+ case (cs)
+ default: ns <= wb_ack_i ? IDLE : (op ? stb1_hi : IDLE);
+ stb1_hi: ns <= wb_ack_i ? (odd_word ? stb2_hi : bloc_lo) : stb1_hi;
+ stb2_hi: ns <= wb_ack_i ? bloc_lo : stb2_hi;
+ bloc_lo: ns <= wb_ack_i ? bloc_lo : IDLE;
+ endcase
+
+endmodule
+"
+"// --------------------------------------------------------------------
+// Copyright (c) 2005 by Terasic Technologies Inc.
+// --------------------------------------------------------------------
+//
+// Permission:
+//
+// Terasic grants permission to use and modify this code for use
+// in synthesis for all Terasic Development Boards and Altrea Development
+// Kits made by Terasic. Other use of this code, including the selling
+// ,duplication, or modification of any portion is strictly prohibited.
+//
+// Disclaimer:
+//
+// This VHDL or Verilog source code is intended as a design reference
+// which illustrates how these types of functions can be implemented.
+// It is the user's responsibility to verify their design for
+// consistency and functionality through the use of formal
+// verification methods. Terasic provides no warranty regarding the use
+// or functionality of this code.
+//
+// --------------------------------------------------------------------
+//
+// Terasic Technologies Inc
+// 356 Fu-Shin E. Rd Sec. 1. JhuBei City,
+// HsinChu County, Taiwan
+// 302
+//
+// web: http://www.terasic.com/
+// email: support@terasic.com
+//
+// --------------------------------------------------------------------
+//
+// Major Functions:i2c controller
+//
+// --------------------------------------------------------------------
+//
+// Revision History :
+// --------------------------------------------------------------------
+// Ver :| Author :| Mod. Date :| Changes Made:
+// V1.0 :| Joe Yang :| 05/07/10 :| Initial Revision
+// --------------------------------------------------------------------
+module speaker_i2c_controller (
+\tCLOCK,
+\tI2C_SCLK,//I2C CLOCK
+ \tI2C_SDAT,//I2C DATA
+\tI2C_DATA,//DATA:[SLAVE_ADDR,SUB_ADDR,DATA]
+\tGO, //GO transfor
+\tEND, //END transfor
+\tW_R, //W_R
+\tACK, //ACK
+\tRESET
+);
+\tinput CLOCK;
+\tinput [23:0]I2C_DATA;\t
+\tinput GO;
+\tinput RESET;\t
+\tinput W_R;
+ \tinout I2C_SDAT;\t
+\toutput I2C_SCLK;
+\toutput END;\t
+\toutput ACK;
+
+
+reg SDO;
+reg SCLK;
+reg END;
+reg [23:0]SD;
+reg [5:0]SD_COUNTER;
+
+wire I2C_SCLK=SCLK | ( ((SD_COUNTER >= 4) & (SD_COUNTER <=30))? ~CLOCK :1'b0 );
+wire I2C_SDAT=SDO?1'bz:1'b0 ;
+
+reg ACK1,ACK2,ACK3;
+wire ACK=ACK1 | ACK2 |ACK3;
+
+ //--I2C COUNTER
+ always @(posedge CLOCK)begin
+ if (RESET)
+ SD_COUNTER <= 6'b111111;
+ else
+ begin
+ if (!GO)
+ SD_COUNTER <= 6'd0;
+ else
+ if (SD_COUNTER < 6'b111111) SD_COUNTER <= SD_COUNTER + 6'b1;
+ end
+ end
+ //----
+
+ always @(posedge CLOCK)
+ begin
+ if (RESET)
+ begin
+ SCLK <= 1'b1;
+ SDO <= 1'b1;
+ ACK1 <= 1'b0;
+ ACK2 <= 1'b0;
+ ACK3 <= 1'b0;
+ END <= 1'b1;
+ end
+ else
+ case (SD_COUNTER)
+ 6'd0:
+ begin
+ ACK1 <= 1'b0;
+ ACK2 <= 1'b0;
+ ACK3 <= 1'b0;
+ END <= 1'b0;
+ SDO <= 1'b1;
+ SCLK <= 1'b1;
+ end
+
+ //start
+ 6'd1:
+ begin
+ SD <= I2C_DATA;
+ SDO <= 1'b0;
+ end
+
+ 6'd2: SCLK <= 1'b0;
+
+ //SLAVE ADDR
+ 6'd3: SDO <= SD[23];
+\t6'd4 : SDO<=SD[22];
+\t6'd5 : SDO<=SD[21];
+\t6'd6 : SDO<=SD[20];
+\t6'd7 : SDO<=SD[19];
+\t6'd8 : SDO<=SD[18];
+\t6'd9 : SDO<=SD[17];
+\t6'd10 : SDO<=SD[16];\t
+\t6'd11 : SDO<=1'b1;//ACK
+
+\t//SUB ADDR
+\t6'd12 : begin SDO<=SD[15]; ACK1<=I2C_SDAT; end
+\t6'd13 : SDO<=SD[14];
+\t6'd14 : SDO<=SD[13];
+\t6'd15 : SDO<=SD[12];
+\t6'd16 : SDO<=SD[11];
+\t6'd17 : SDO<=SD[10];
+\t6'd18 : SDO<=SD[9];
+\t6'd19 : SDO<=SD[8];
+\t6'd20 : SDO<=1'b1;//ACK
+
+\t//DATA
+\t6'd21 : begin SDO<=SD[7]; ACK2<=I2C_SDAT; end
+\t6'd22 : SDO<=SD[6];
+\t6'd23 : SDO<=SD[5];
+\t6'd24 : SDO<=SD[4];
+\t6'd25 : SDO<=SD[3];
+\t6'd26 : SDO<=SD[2];
+\t6'd27 : SDO<=SD[1];
+\t6'd28 : SDO<=SD[0];
+\t6'd29 : SDO<=1'b1;//ACK
+
+\t
+\t//stop
+ 6'd30 : begin SDO<=1'b0;\tSCLK<=1'b0; ACK3<=I2C_SDAT; end\t
+ 6'd31 : SCLK<=1'b1;
+ 6'd32 : begin SDO<=1'b1; END<=1; end
+
+endcase
+end
+
+
+
+endmodule
+"
+"/*
+ * 1-bit 8-way multiplexor
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_mux8_1(sel, in0, in1, in2, in3, in4, in5, in6, in7, out);
+ input [2:0] sel;
+ input in0, in1, in2, in3, in4, in5, in6, in7;
+ output out;
+
+ reg out;
+
+ always @(sel or in0 or in1 or in2 or in3 or in4 or in5 or in6 or in7)
+ case(sel)
+ 3'd0: out = in0;
+ 3'd1: out = in1;
+ 3'd2: out = in2;
+ 3'd3: out = in3;
+ 3'd4: out = in4;
+ 3'd5: out = in5;
+ 3'd6: out = in6;
+ 3'd7: out = in7;
+ endcase
+endmodule
+"
+"/*
+ * Copyright (c) 2009 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`timescale 1ns/10ps
+
+module test_kotku;
+
+ // Registers and nets
+ reg clk_50;
+ wire [9:0] ledr;
+ wire [7:0] ledg;
+ reg [7:0] sw;
+ integer i;
+
+ wire [21:0] flash_addr;
+ wire [ 7:0] flash_data;
+ wire flash_we_n;
+ wire flash_oe_n;
+ wire flash_rst_n;
+ wire flash_ry;
+
+ wire [11:0] sdram_addr;
+ wire [15:0] sdram_data;
+ wire [ 1:0] sdram_ba;
+ wire [ 1:0] sdram_dqm;
+ wire sdram_ras_n;
+ wire sdram_cas_n;
+ wire sdram_ce;
+ wire sdram_clk;
+ wire sdram_we_n;
+ wire sdram_cs_n;
+
+ wire [16:0] sram_addr_;
+ wire [15:0] sram_data_;
+ wire sram_we_n_;
+ wire sram_oe_n_;
+ wire sram_ce_n_;
+ wire [ 1:0] sram_bw_n_;
+
+ // Module instantiations
+ kotku kotku (
+ .clk_50_ (clk_50),
+ .ledr_ (ledr),
+ .ledg_ (ledg),
+ .sw_ (sw),
+
+ // flash signals
+ .flash_addr_ (flash_addr),
+ .flash_data_ (flash_data),
+ .flash_oe_n_ (flash_oe_n),
+
+ // sdram signals
+ .sdram_addr_ (sdram_addr),
+ .sdram_data_ (sdram_data),
+ .sdram_ba_ (sdram_ba),
+ .sdram_ras_n_ (sdram_ras_n),
+ .sdram_cas_n_ (sdram_cas_n),
+ .sdram_ce_ (sdram_ce),
+ .sdram_clk_ (sdram_clk),
+ .sdram_we_n_ (sdram_we_n),
+ .sdram_cs_n_ (sdram_cs_n),
+
+ // sram signals
+ .sram_addr_ (sram_addr_),
+ .sram_data_ (sram_data_),
+ .sram_we_n_ (sram_we_n_),
+ .sram_oe_n_ (sram_oe_n_),
+ .sram_bw_n_ (sram_bw_n_)
+ );
+
+ s29al032d_00 flash (
+ .A21 (flash_addr[21]),
+ .A20 (flash_addr[20]),
+ .A19 (flash_addr[19]),
+ .A18 (flash_addr[18]),
+ .A17 (flash_addr[17]),
+ .A16 (flash_addr[16]),
+ .A15 (flash_addr[15]),
+ .A14 (flash_addr[14]),
+ .A13 (flash_addr[13]),
+ .A12 (flash_addr[12]),
+ .A11 (flash_addr[11]),
+ .A10 (flash_addr[10]),
+ .A9 (flash_addr[ 9]),
+ .A8 (flash_addr[ 8]),
+ .A7 (flash_addr[ 7]),
+ .A6 (flash_addr[ 6]),
+ .A5 (flash_addr[ 5]),
+ .A4 (flash_addr[ 4]),
+ .A3 (flash_addr[ 3]),
+ .A2 (flash_addr[ 2]),
+ .A1 (flash_addr[ 1]),
+ .A0 (flash_addr[ 0]),
+
+ .DQ7 (flash_data[7]),
+ .DQ6 (flash_data[6]),
+ .DQ5 (flash_data[5]),
+ .DQ4 (flash_data[4]),
+ .DQ3 (flash_data[3]),
+ .DQ2 (flash_data[2]),
+ .DQ1 (flash_data[1]),
+ .DQ0 (flash_data[0]),
+
+ .CENeg (1\'b0),
+ .OENeg (flash_oe_n),
+ .WENeg (1\'b1),
+ .RESETNeg (1\'b1),
+ .ACC (1\'b1),
+ .RY (flash_ry)
+ );
+
+ mt48lc16m16a2 sdram (
+ .Dq (sdram_data),
+ .Addr (sdram_addr),
+ .Ba (sdram_ba),
+ .Clk (sdram_clk),
+ .Cke (sdram_ce),
+ .Cs_n (sdram_cs_n),
+ .Ras_n (sdram_ras_n),
+ .Cas_n (sdram_cas_n),
+ .We_n (sdram_we_n),
+ .Dqm (2\'b00)
+ );
+
+ is61lv25616 sram (
+ .A ({1\'b0,sram_addr_}),
+ .IO (sram_data_),
+ .CE_ (1\'b0),
+ .OE_ (sram_oe_n_),
+ .WE_ (sram_we_n_),
+ .LB_ (sram_bw_n_[0]),
+ .UB_ (sram_bw_n_[1])
+ );
+
+ // Behaviour
+ // Clock generation
+ always #10 clk_50 <= !clk_50;
+
+ initial
+ begin
+ $readmemh(""../../../cores/flash/bios.dat"",flash.Mem);
+ $readmemb(""../../../cores/zet/rtl/micro_rom.dat"",
+ kotku.zet.core.micro_data.micro_rom.rom);
+ $readmemh(""../../../cores/vga/rtl/char_rom.dat"",
+ kotku.vga.lcd.text_mode.char_rom.rom);
+// $readmemh(""../../../cores/ps2/rtl/xt_codes.dat"",
+// kotku.ps2.keyb.keyb_xtcodes.rom);
+ $readmemh(""../../../cores/flash/bootrom.dat"",
+ kotku.bootrom.rom);
+
+ clk_50 <= 1\'b0;
+ sw <= 8\'h1;
+ #300 sw <= 8\'h0;
+ end
+
+endmodule
+"
+"/*
+ * Milkymist SoC
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
+ * adjusted to FML 8x16 by Zeus Gomez Marmolejo
+ * updated to include Direct Cache Bus by Charley Picker
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+module fmlbrg_datamem #(
+\tparameter depth = 8
+) (
+\tinput sys_clk,
+
+\t/* Primary port (read-write) */
+\tinput [depth-1:0] a,
+\tinput [1:0] we,
+\tinput [15:0] di,
+\toutput [15:0] dout,
+
+\t/* Secondary port (read-only) */
+\tinput [depth-1:0] a2,
+\toutput [15:0] do2
+);
+
+reg [7:0] ram0[0:(1 << depth)-1];
+reg [7:0] ram1[0:(1 << depth)-1];
+
+wire [7:0] ram0di;
+wire [7:0] ram1di;
+
+wire [7:0] ram0do;
+wire [7:0] ram1do;
+
+wire [7:0] ram0do2;
+wire [7:0] ram1do2;
+
+reg [depth-1:0] a_r;
+reg [depth-1:0] a2_r;
+
+always @(posedge sys_clk) begin
+\ta_r <= a;
+\ta2_r <= a2;
+end
+
+/*
+ * Workaround for a strange Xst 11.4 bug with Spartan-6
+ * We must specify the RAMs in this order, otherwise,
+ * ram1 ""disappears"" from the netlist. The typical
+ * first symptom is a Bitgen DRC failure because of
+ * dangling I/O pins going to the SDRAM.
+ * Problem reported to Xilinx.
+ */
+
+always @(posedge sys_clk) begin
+\tif(we[1])
+\t\tram1[a] <= ram1di;
+end
+assign ram1do = ram1[a_r];
+assign ram1do2 = ram1[a2_r];
+
+always @(posedge sys_clk) begin
+\tif(we[0])
+\t\tram0[a] <= ram0di;
+end
+assign ram0do = ram0[a_r];
+assign ram0do2 = ram0[a2_r];
+
+assign ram0di = di[7:0];
+assign ram1di = di[15:8];
+
+assign dout = {ram1do, ram0do};
+assign do2 = {ram1do2, ram0do2};
+
+endmodule
+"
+"/*
+ * Fetch FSM helper for next state
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_next_or_not (
+ input [1:0] prefix,
+ input [7:1] opcode,
+ input cx_zero,
+ input zf,
+ input ext_int,
+ output next_in_opco,
+ output next_in_exec
+ );
+
+ // Net declarations
+ wire exit_z, cmp_sca, exit_rep, valid_ops;
+
+ // Assignments
+ assign cmp_sca = opcode[2] & opcode[1];
+ assign exit_z = prefix[0] ? /* repz */ (cmp_sca ? ~zf : 1'b0 )
+ : /* repnz */ (cmp_sca ? zf : 1'b0 );
+ assign exit_rep = cx_zero | exit_z;
+ assign valid_ops = (opcode[7:1]==7'b1010_010 // movs
+ || opcode[7:1]==7'b1010_011 // cmps
+ || opcode[7:1]==7'b1010_101 // stos
+ || opcode[7:1]==7'b1010_110 // lods
+ || opcode[7:1]==7'b1010_111); // scas
+ assign next_in_exec = prefix[1] && valid_ops && !exit_rep && !ext_int;
+ assign next_in_opco = prefix[1] && valid_ops && cx_zero;
+endmodule
+"
+"/*\r
+ * Wishbone to FML 8x16 bridge\r
+ * Milkymist SoC\r
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq\r
+ * adjusted to FML 8x16 by Zeus Gomez Marmolejo \r
+ * updated to include Direct Cache Bus by Charley Picker \r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, version 3 of the License.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see .\r
+ */\r
+\r
+module fmlbrg #(\r
+\tparameter fml_depth = 23,\r
+\tparameter cache_depth = 9 // 512 byte cache\t\r
+) (\r
+\tinput sys_clk,\r
+\tinput sys_rst,\r
+\t\r
+\tinput [fml_depth-1:1] wb_adr_i,\r
+\tinput [2:0] wb_cti_i,\r
+\tinput [15:0] wb_dat_i,\r
+\toutput [15:0] wb_dat_o,\r
+\tinput [1:0] wb_sel_i,\r
+\tinput wb_cyc_i,\r
+\tinput wb_stb_i,\r
+\tinput wb_tga_i,\r
+\tinput wb_we_i,\r
+\toutput reg wb_ack_o,\r
+\t\r
+\toutput reg [fml_depth-1:0] fml_adr,\r
+\toutput reg fml_stb,\r
+\toutput reg fml_we,\r
+\tinput fml_ack,\r
+\toutput [1:0] fml_sel,\r
+\toutput [15:0] fml_do,\r
+\tinput [15:0] fml_di,\r
+\r
+\t/* Direct Cache Bus */\r
+\tinput dcb_stb,\r
+\tinput [fml_depth-1:0] dcb_adr,\r
+\toutput [15:0] dcb_dat,\r
+\toutput dcb_hit\r
+);\r
+\r
+/*\r
+ * Line length is the burst length, that is 8*16 bits, or 16 bytes\r
+ * Address split up :\r
+ *\r
+ * | TAG | INDEX | OFFSET |\r
+ * |fml_depth-1 cache_depth|cache_depth-1 4|3 0|\r
+ *\r
+ */\r
+\r
+wire [3:1] offset = wb_adr_i[3:1];\r
+wire [cache_depth-1-4:0] index = wb_adr_i[cache_depth-1:4];\r
+wire [fml_depth-cache_depth-1:0] tag = wb_adr_i[fml_depth-1:cache_depth];\r
+\r
+wire [3:1] dcb_offset = dcb_adr[3:1];\r
+wire [cache_depth-1-4:0] dcb_index = dcb_adr[cache_depth-1:4];\r
+wire [fml_depth-cache_depth-1:0] dcb_tag = dcb_adr[fml_depth-1:cache_depth];\r
+\r
+wire coincidence = index == dcb_index;\r
+\r
+/*\r
+ * TAG MEMORY\r
+ *\r
+ * Addressed by index (length cache_depth-5)\r
+ * Contains valid bit + dirty bit + tag\r
+ */\r
+\r
+wire [cache_depth-1-4:0] tagmem_a;\r
+reg tagmem_we;\r
+wire [fml_depth-cache_depth-1+2:0] tagmem_di;\r
+wire [fml_depth-cache_depth-1+2:0] tagmem_do;\r
+\r
+wire [cache_depth-1-4:0] tagmem_a2;\r
+wire [fml_depth-cache_depth-1+2:0] tagmem_do2;\r
+\r
+fmlbrg_tagmem #(\r
+\t.depth(cache_depth-4),\r
+\t.width(fml_depth-cache_depth+2)\r
+) tagmem (\r
+\t.sys_clk(sys_clk),\r
+\r
+\t.a(tagmem_a),\r
+\t.we(tagmem_we),\r
+\t.di(tagmem_di),\r
+\t.dout(tagmem_do),\r
+\r
+\t.a2(tagmem_a2),\r
+\t.do2(tagmem_do2)\r
+);\r
+\r
+reg index_load;\r
+reg [cache_depth-1-4:0] index_r;\r
+always @(posedge sys_clk) begin\r
+ if(index_load)\r
+ index_r <= index;\r
+end\r
+\r
+assign tagmem_a = index;\r
+\r
+assign tagmem_a2 = dcb_index;\r
+\r
+reg di_valid;\r
+reg di_dirty;\r
+assign tagmem_di = {di_valid, di_dirty, tag};\r
+\r
+wire do_valid;\r
+wire do_dirty;\r
+wire [fml_depth-cache_depth-1:0] do_tag;\r
+wire cache_hit;\r
+\r
+wire do2_valid;\r
+wire [fml_depth-cache_depth-1:0] do2_tag;\r
+\r
+assign do_valid = tagmem_do[fml_depth-cache_depth-1+2];\r
+assign do_dirty = tagmem_do[fml_depth-cache_depth-1+1];\r
+assign do_tag = tagmem_do[fml_depth-cache_depth-1:0];\r
+\r
+assign do2_valid = tagmem_do2[fml_depth-cache_depth-1+2];\r
+assign do2_tag = tagmem_do2[fml_depth-cache_depth-1:0];\r
+\r
+always @(posedge sys_clk)\r
+\tfml_adr <= {do_tag, index, offset, 1\'b0};\r
+\r
+/*\r
+ * DATA MEMORY\r
+ *\r
+ * Addressed by index+offset in 16-bit words (length cache_depth-1)\r
+ * 16-bit memory with 8-bit write granularity\r
+ */\r
+\r
+wire [cache_depth-1-1:0] datamem_a;\r
+reg [1:0] datamem_we;\r
+reg [15:0] datamem_di;\r
+wire [15:0] datamem_do;\r
+\r
+wire [cache_depth-1-1:0] datamem_a2;\r
+wire [15:0] datamem_do2;\r
+\r
+fmlbrg_datamem #(\r
+\t.depth(cache_depth-1)\r
+) datamem (\r
+\t.sys_clk(sys_clk),\r
+\t\r
+\t.a(datamem_a),\r
+\t.we(datamem_we),\r
+\t.di(datamem_di),\r
+\t.dout(datamem_do),\r
+\r
+\t.a2(datamem_a2),\r
+\t.do2(datamem_do2)\r
+);\r
+\r
+reg [2:0] bcounter;\r
+reg [2:0] bcounter_next;\r
+always @(posedge sys_clk) begin\r
+\tif(sys_rst)\r
+\t\tbcounter <= 3\'d0;\r
+\telse\r
+\t\tbcounter <= bcounter_next;\r
+end\r
+\r
+reg [1:0] bcounter_sel;\r
+\r
+localparam BCOUNTER_RESET\t= 2\'d0;\r
+localparam BCOUNTER_KEEP\t= 2\'d1;\r
+localparam BCOUNTER_LOAD\t= 2\'d2;\r
+localparam BCOUNTER_INC\t\t= 2\'d3;\r
+\r
+always @(*) begin\r
+\tcase(bcounter_sel)\r
+\t\tBCOUNTER_RESET: bcounter_next <= 3\'d0;\r
+\t\tBCOUNTER_KEEP: bcounter_next <= bcounter;\r
+\t\tBCOUNTER_LOAD: bcounter_next <= offset;\r
+\t\tBCOUNTER_INC: bcounter_next <= bcounter + 3\'d1;\r
+\t\tdefault: bcounter_next <= 3\'bxxx;\r
+\tendcase\r
+end\r
+\r
+assign datamem_a = { index_load ? index : index_r, bcounter_next };\r
+\r
+assign datamem_a2 = {dcb_index, dcb_offset};\r
+\r
+reg datamem_we_wb;\r
+reg datamem_we_fml;\r
+\r
+always @(*) begin\r
+\tif(datamem_we_fml)\r
+\t\tdatamem_we = 2\'b11;\r
+\telse if(datamem_we_wb)\r
+\t\t datamem_we = {wb_sel_i};\r
+\t\t else datamem_we = 2\'b00;\r
+end\r
+\r
+always @(*) begin\r
+ datamem_di = fml_di;\r
+ if(datamem_we_wb) begin\r
+ if(wb_sel_i[0])\r
+ datamem_di[7:0] = wb_dat_i[7:0];\r
+ if(wb_sel_i[1])\r
+ datamem_di[15:8] = wb_dat_i[15:8];\r
+ end\r
+end\r
+\r
+assign wb_dat_o = datamem_do;\r
+assign fml_do = datamem_do;\r
+assign fml_sel = 2\'b11;\r
+assign dcb_dat = datamem_do2;\r
+\r
+/* FSM */\r
+\r
+reg [fml_depth-cache_depth-1:0] tag_r;\r
+always @(posedge sys_clk)\r
+\ttag_r = tag;\r
+assign cache_hit = do_valid & (do_tag == tag_r);\r
+\r
+reg [4:0] state;\r
+reg [4:0] next_state;\r
+\r
+ localparam [4:0]\r
+ IDLE = 5\'d0,\r
+ TEST_HIT = 5\'d1,\r
+\r
+ WB_BURST = 5\'d2,\r
+\r
+ EVICT = 5\'d3,\r
+ EVICT2 = 5\'d4,\r
+ EVICT3 = 5\'d5,\r
+ EVICT4 = 5\'d6,\r
+ EVICT5 = 5\'d7,\r
+ EVICT6 = 5\'d8,\r
+ EVICT7 = 5\'d9,\r
+ EVICT8 = 5\'d10,\r
+\r
+ REFILL = 5\'d11,\r
+ REFILL_WAIT = 5\'d12,\r
+ REFILL1 = 5\'d13,\r
+ REFILL2 = 5\'d14,\r
+ REFILL3 = 5\'d15,\r
+ REFILL4 = 5\'d16,\r
+ REFILL5 = 5\'d17,\r
+ REFILL6 = 5\'d18,\r
+ REFILL7 = 5\'d19,\r
+ REFILL8 = 5\'d20,\r
+\r
+ TEST_INVALIDATE = 5\'d21,\r
+ INVALIDATE = 5\'d22;\r
+\r
+always @(posedge sys_clk) begin\r
+\tif(sys_rst)\r
+\t\tstate <= IDLE;\r
+\telse begin\r
+\t\t//$display(""state: %d -> %d"", state, next_state);\r
+\t\tstate <= next_state;\r
+\tend\r
+end\r
+\r
+always @(*) begin\r
+\ttagmem_we = 1\'b0;\r
+\tdi_valid = 1\'b0;\r
+\tdi_dirty = 1\'b0;\r
+\t\r
+\tbcounter_sel = BCOUNTER_KEEP;\r
+\t\r
+\tindex_load = 1\'b1;\r
+\t\t\r
+\tdatamem_we_wb = 1\'b0;\r
+\tdatamem_we_fml = 1\'b0;\r
+\t\r
+\twb_ack_o = 1\'b0;\r
+\t\r
+\tfml_stb = 1\'b0;\r
+\tfml_we = 1\'b0;\r
+\t\r
+\tnext_state = state;\r
+\t\r
+\tcase(state)\r
+\t\tIDLE: begin\r
+\t\t\tbcounter_sel = BCOUNTER_LOAD;\r
+\t\t\tif(wb_cyc_i & wb_stb_i) begin\r
+\t\t\t\tif(wb_tga_i)\r
+\t\t\t\t\tnext_state = TEST_INVALIDATE;\r
+\t\t\t\telse\r
+\t\t\t\t\tnext_state = TEST_HIT;\r
+\t\t\tend\r
+\t\tend\r
+\t\tTEST_HIT: begin\r
+\t\t\tif(cache_hit) begin\r
+\t\t\t\twb_ack_o = 1\'b1;\r
+\t\t\t\tif(wb_we_i) begin\r
+\t\t\t\t\tdi_valid = 1\'b1;\r
+\t\t\t\t\tdi_dirty = 1\'b1;\r
+\t\t\t\t\ttagmem_we = 1\'b1;\r
+\t\t\t\t\tdatamem_we_wb = 1\'b1;\r
+\t\t\t\tend\r
+\t\t\t\tif(wb_cti_i == 3\'b010)\r
+\t\t\t\t\tnext_state = WB_BURST;\r
+\t\t\t\telse\r
+\t\t\t\t\tnext_state = IDLE;\r
+\t\t\tend else begin\r
+\t\t\t\tif(do_dirty)\r
+\t\t\t\t\tnext_state = EVICT;\r
+\t\t\t\telse\r
+\t\t\t\t\tnext_state = REFILL;\r
+\t\t\tend\r
+\t\tend\r
+\t\t\r
+\t\tWB_BURST: begin\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tif(wb_we_i)\r
+\t\t\t\tdatamem_we_wb = 1\'b1;\r
+\t\t\twb_ack_o = 1\'b1;\r
+\t\t\tif(wb_cti_i != 3\'b010)\r
+\t\t\t\tnext_state = IDLE;\r
+\t\tend\r
+\t\t\r
+ /*\r
+ * Burst counter has already been loaded.\r
+ * Yes, we evict lines in different order depending\r
+ * on the critical word position of the cache miss\r
+ * inside the line, but who cares :)\r
+ */\t\t\r
+\t\tEVICT: begin\r
+\t\t $display(""Evict"");\r
+\t\t\tfml_stb = 1\'b1;\r
+\t\t\tfml_we = 1\'b1;\r
+\t\t\tif(fml_ack) begin\r
+\t\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\t\tnext_state = EVICT2;\r
+\t\t\tend\r
+\t\tend\r
+\t\tEVICT2: begin\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tnext_state = EVICT3;\r
+\t\tend\r
+\t\tEVICT3: begin\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tnext_state = EVICT4;\r
+\t\tend\r
+\t\tEVICT4: begin\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tnext_state = EVICT5;\r
+\t\tend\r
+\t\tEVICT5: begin\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tnext_state = EVICT6;\r
+\t\tend\r
+\t\tEVICT6: begin\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tnext_state = EVICT7;\r
+\t\tend\r
+\t\tEVICT7: begin\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tnext_state = EVICT8;\r
+\t\tend\r
+\t\tEVICT8: begin\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tif(wb_tga_i)\r
+\t\t\t\tnext_state = INVALIDATE;\r
+\t\t\telse\r
+\t\t\t\tnext_state = REFILL;\r
+\t\tend\r
+\t\t\r
+\t\tREFILL: begin\r
+\t\t /* Write the tag first. This will also set the FML address. */\r
+\t\t\tdi_valid = 1\'b1;\r
+\t\t\tif(wb_we_i)\r
+\t\t\t\tdi_dirty = 1\'b1;\r
+\t\t\telse\r
+\t\t\t\tdi_dirty = 1\'b0;\r
+\t\t\tif(~(dcb_stb & coincidence)) begin\r
+\t\t\t\ttagmem_we = 1\'b1;\r
+\t\t\t\tnext_state = REFILL_WAIT;\r
+\t\t\tend\r
+\t\tend\r
+\t\tREFILL_WAIT: next_state = REFILL1; /* one cycle latency for the FML address */\r
+\t\tREFILL1: begin\r
+\t\t\tbcounter_sel = BCOUNTER_LOAD;\r
+\t\t\tfml_stb = 1\'b1;\r
+ /* Asserting both\r
+ * datamem_we_fml and\r
+ * datamem_we_wb, WB has priority\r
+ */\r
+\t\t\tdatamem_we_fml = 1\'b1;\r
+\t\t\tif(wb_we_i)\r
+ datamem_we_wb = 1\'b1;\r
+\t\t\tif(fml_ack)\r
+\t\t\t\tnext_state = REFILL2;\r
+\t\tend\r
+\t\tREFILL2: begin\r
+\t\t/*\r
+ * For reads, the critical word has just been written to the datamem\r
+ * so by acking the cycle now we get the correct result (because the\r
+ * datamem is a write-first SRAM).\r
+ * For writes, we could have acked the cycle before but it\'s simpler this way.\r
+ * Otherwise, we have the case of a master releasing WE just after ACK,\r
+ * and we must add a reg to tell whether we have a read or a write in REFILL2...\r
+ */\r
+ wb_ack_o = 1\'b1;\r
+ /* Now we must use our copy of index, as the WISHBONE\r
+ * address may change.\r
+ */\r
+ index_load = 1\'b0;\r
+\t\t datamem_we_fml = 1\'b1;\r
+\t\t bcounter_sel = BCOUNTER_INC;\r
+\t\t next_state = REFILL3;\r
+\t\tend\r
+\t\tREFILL3: begin\r
+\t\t index_load = 1\'b0;\r
+\t\t\tdatamem_we_fml = 1\'b1;\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tnext_state = REFILL4;\r
+\t\tend\r
+\t\tREFILL4: begin\r
+\t\t index_load = 1\'b0;\r
+\t\t\tdatamem_we_fml = 1\'b1;\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tnext_state = REFILL5;\r
+\t\tend\r
+\t\tREFILL5: begin\r
+\t\t index_load = 1\'b0;\r
+\t\t\tdatamem_we_fml = 1\'b1;\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tnext_state = REFILL6;\r
+\t\tend\r
+\t\tREFILL6: begin\r
+\t\t index_load = 1\'b0;\r
+\t\t\tdatamem_we_fml = 1\'b1;\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tnext_state = REFILL7;\r
+\t\tend\r
+\t\tREFILL7: begin\r
+\t\t$display(""Refill 7"");\r
+\t\t index_load = 1\'b0;\r
+\t\t\tdatamem_we_fml = 1\'b1;\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tnext_state = REFILL8;\r
+\t\tend\r
+\t\tREFILL8: begin\r
+\t\t index_load = 1\'b0;\r
+\t\t\tdatamem_we_fml = 1\'b1;\r
+\t\t\tbcounter_sel = BCOUNTER_INC;\r
+\t\t\tnext_state = IDLE;\r
+\t\tend\r
+\t\t\r
+\t\tTEST_INVALIDATE: begin\r
+\t\t\tif(do_dirty)\r
+\t\t\t\tnext_state = EVICT;\r
+\t\t\telse\r
+\t\t\t\tnext_state = INVALIDATE;\r
+\t\tend\r
+\t\tINVALIDATE: begin\r
+\t\t\tdi_valid = 1\'b0;\r
+\t\t\tdi_dirty = 1\'b0;\r
+\t\t\ttagmem_we = 1\'b1;\r
+\t\t\twb_ack_o = 1\'b1;\r
+\t\t\tnext_state = IDLE;\r
+\t\tend\r
+\tendcase\r
+end\r
+\r
+/* Do not hit on a line being refilled */\r
+reg dcb_can_hit;\r
+\r
+always @(posedge sys_clk) begin\r
+\tdcb_can_hit <= 1\'b0;\r
+\tif(dcb_stb) begin\r
+\t\tif((state != REFILL_WAIT)\r
+\t\t|| (state != REFILL2)\r
+\t\t|| (state != REFILL3)\r
+\t\t|| (state != REFILL4)\r
+\t\t|| (state != REFILL5)\r
+\t\t|| (state != REFILL6)\r
+\t\t|| (state != REFILL7)\r
+\t\t|| (state != REFILL8))\r
+\t\t\tdcb_can_hit <= 1\'b1;\r
+\t\tif(~coincidence)\r
+\t\t\tdcb_can_hit <= 1\'b1;\r
+\tend\r
+end\r
+\r
+reg [fml_depth-cache_depth-1:0] dcb_tag_r;\r
+always @(posedge sys_clk)\r
+\tdcb_tag_r = dcb_tag;\r
+\r
+assign dcb_hit = dcb_can_hit & do2_valid & (do2_tag == dcb_tag_r);\r
+\r
+endmodule\r
+"
+"/*
+ * Text mode graphics for VGA
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+/*
+ * Pipeline description
+ * h_count[2:0]
+ * 000
+ * 001 col_addr, row_addr
+ * 010 ver_addr, hor_addr
+ * 011 csr_adr_o
+ * 100 csr_adr_i
+ * 101 sram_addr_
+ * 110 csr_dat_o
+ * 111 char_data_out, attr_data_out
+ * 000 vga_shift
+ * 001 vga_blue_o <= vga_shift[7]
+ */
+
+module vga_text_mode (
+ input clk,
+ input rst,
+
+ // CSR slave interface for reading
+ output reg [16:1] csr_adr_o,
+ input [15:0] csr_dat_i,
+ output csr_stb_o,
+
+ input [9:0] h_count,
+ input [9:0] v_count,
+ input horiz_sync_i,
+ input video_on_h_i,
+ output video_on_h_o,
+
+ // CRTC
+ input [5:0] cur_start,
+ input [5:0] cur_end,
+ input [4:0] vcursor,
+ input [6:0] hcursor,
+
+ output reg [3:0] attr,
+ output horiz_sync_o
+ );
+
+ // Registers and nets
+ reg [ 6:0] col_addr;
+ reg [ 4:0] row_addr;
+ reg [ 6:0] hor_addr;
+ reg [ 6:0] ver_addr;
+ wire [10:0] vga_addr;
+
+ wire [11:0] char_addr;
+ wire [ 7:0] char_data_out;
+ reg [ 7:0] attr_data_out;
+ reg [ 7:0] char_addr_in;
+
+ reg [7:0] pipe;
+ wire load_shift;
+
+ reg [9:0] video_on_h;
+ reg [9:0] horiz_sync;
+
+ wire fg_or_bg;
+ wire brown_bg;
+ wire brown_fg;
+
+ reg [ 7:0] vga_shift;
+ reg [ 3:0] fg_colour;
+ reg [ 2:0] bg_colour;
+ reg [22:0] blink_count;
+
+ // Cursor
+ reg cursor_on_v;
+ reg cursor_on_h;
+ reg cursor_on;
+ wire cursor_on1;
+
+ // Module instances
+ vga_char_rom char_rom (
+ .clk (clk),
+ .addr (char_addr),
+ .q (char_data_out)
+ );
+
+ // Continuous assignments
+ assign vga_addr = { 4'b0, hor_addr } + { ver_addr, 4'b0 };
+ assign char_addr = { char_addr_in, v_count[3:0] };
+ assign load_shift = pipe[7];
+ assign video_on_h_o = video_on_h[9];
+ assign horiz_sync_o = horiz_sync[9];
+ assign csr_stb_o = pipe[2];
+
+ assign fg_or_bg = vga_shift[7] ^ cursor_on;
+
+ assign cursor_on1 = cursor_on_h && cursor_on_v;
+
+ // Behaviour
+ // Address generation
+ always @(posedge clk)
+ if (rst)
+ begin
+ col_addr <= 7'h0;
+ row_addr <= 5'h0;
+ ver_addr <= 7'h0;
+ hor_addr <= 7'h0;
+ csr_adr_o <= 16'h0;
+ end
+ else
+ begin
+ // h_count[2:0] == 001
+ col_addr <= h_count[9:3];
+ row_addr <= v_count[8:4];
+
+ // h_count[2:0] == 010
+ ver_addr <= { 2'b00, row_addr } + { row_addr, 2'b00 };
+ // ver_addr = row_addr x 5
+ hor_addr <= col_addr;
+
+ // h_count[2:0] == 011
+ // vga_addr = row_addr * 80 + hor_addr
+ csr_adr_o <= { 5'h0, vga_addr };
+ end
+
+ // cursor
+ always @(posedge clk)
+ if (rst)
+ begin
+ cursor_on_v <= 1'b0;
+ cursor_on_h <= 1'b0;
+ end
+ else
+ begin
+ cursor_on_h <= (h_count[9:3] == hcursor[6:0]);
+ cursor_on_v <= (v_count[8:4] == vcursor[4:0])
+ && ({2'b00, v_count[3:0]} >= cur_start)
+ && ({2'b00, v_count[3:0]} <= cur_end);
+ end
+
+ // Pipeline count
+ always @(posedge clk)
+ pipe <= rst ? 8'b0 : { pipe[6:0], (h_count[2:0]==3'b0) };
+
+ // attr_data_out
+ always @(posedge clk) attr_data_out <= pipe[5] ? csr_dat_i[15:8]
+ : attr_data_out;
+
+ // char_addr_in
+ always @(posedge clk) char_addr_in <= pipe[5] ? csr_dat_i[7:0]
+ : char_addr_in;
+
+ // video_on_h
+ always @(posedge clk)
+ video_on_h <= rst ? 10'b0 : { video_on_h[8:0], video_on_h_i };
+
+ // horiz_sync
+ always @(posedge clk)
+ horiz_sync <= rst ? 10'b0 : { horiz_sync[8:0], horiz_sync_i };
+
+ // blink_count
+ always @(posedge clk)
+ blink_count <= rst ? 23'h0 : (blink_count + 23'h1);
+
+ // Video shift register
+ always @(posedge clk)
+ if (rst)
+ begin
+ fg_colour <= 4'b0;
+ bg_colour <= 3'b0;
+ vga_shift <= 8'h0;
+ end
+ else
+ if (load_shift)
+ begin
+ fg_colour <= attr_data_out[3:0];
+ bg_colour <= attr_data_out[6:4];
+ cursor_on <= (cursor_on1 | attr_data_out[7]) & blink_count[22];
+ vga_shift <= char_data_out;
+ end
+ else vga_shift <= { vga_shift[6:0], 1'b0 };
+
+ // pixel attribute
+ always @(posedge clk)
+ if (rst) attr <= 4'h0;
+ else attr <= fg_or_bg ? fg_colour : { 1'b0, bg_colour };
+
+endmodule
+"
+"/*
+ * Wishbone asynchronous bridge
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module wb_abrg (
+ input sys_rst,
+
+ // Wishbone slave interface
+ input wbs_clk_i,
+ input [19:1] wbs_adr_i,
+ input [15:0] wbs_dat_i,
+ output reg [15:0] wbs_dat_o,
+ input [ 1:0] wbs_sel_i,
+ input wbs_tga_i,
+ input wbs_stb_i,
+ input wbs_cyc_i,
+ input wbs_we_i,
+ output wbs_ack_o,
+
+ // Wishbone master interface
+ input wbm_clk_i,
+ output reg [19:1] wbm_adr_o,
+ output reg [15:0] wbm_dat_o,
+ input [15:0] wbm_dat_i,
+ output reg [ 1:0] wbm_sel_o,
+ output reg wbm_tga_o,
+ output wbm_stb_o,
+ output wbm_cyc_o,
+ output reg wbm_we_o,
+ input wbm_ack_i
+ );
+
+ // Registers and nets
+ wire wbs_stb;
+ wire init_tr;
+ reg wbm_stb;
+ reg [2:0] sync_stb;
+ reg [2:0] sync_ack;
+ reg ft_stb;
+ reg ft_ack;
+ reg stb_r;
+ reg ack_r;
+
+ reg [19:1] wbm_adr_o_r;
+ reg [15:0] wbm_dat_o_r;
+ reg [ 1:0] wbm_sel_o_r;
+ reg wbm_tga_o_r;
+ reg wbm_we_o_r;
+ reg [15:0] wbs_dat_o_r;
+ reg [15:0] wbm_dat_i_r;
+
+ // Continous assignments
+ assign wbs_stb = wbs_stb_i & wbs_cyc_i;
+
+ // recreate the flag from the level change
+ assign wbs_ack_o = (sync_ack[2] ^ sync_ack[1]);
+ assign wbm_stb_o = wbm_stb;
+ assign wbm_cyc_o = wbm_stb;
+
+ /*
+ * A new wishbone transaction is issued:
+ * . by changing stb from 0 to 1
+ * . by continue asserting stb after ack is received
+ */
+ assign init_tr = ~stb_r & wbs_stb | ack_r & ~wbs_ack_o & wbs_stb;
+
+ // Behaviour
+ // wbm_stb
+ always @(posedge wbm_clk_i)
+ wbm_stb <= sys_rst ? 1'b0
+ : (wbm_stb ? ~wbm_ack_i : sync_stb[2] ^ sync_stb[1]);
+
+ // old stb and ack state
+ always @(posedge wbs_clk_i) stb_r <= wbs_stb;
+ always @(posedge wbs_clk_i) ack_r <= wbs_ack_o;
+
+ always @(posedge wbs_clk_i)
+ ft_stb <= sys_rst ? 1'b0 : (init_tr ? ~ft_stb : ft_stb);
+
+ // synchronize the last level change
+ always @(posedge wbm_clk_i)
+ sync_stb <= sys_rst ? 3'h0 : {sync_stb[1:0], ft_stb};
+
+ // this changes level when a flag is seen
+ always @(posedge wbm_clk_i)
+ ft_ack <= sys_rst ? 1'b0 : (wbm_ack_i ? ~ft_ack : ft_ack);
+
+ // which can then be synched to wbs_clk_i
+ always @(posedge wbs_clk_i)
+ sync_ack <= sys_rst ? 3'h0 : {sync_ack[1:0], ft_ack};
+
+ // rest of the wishbone signals
+ always @(posedge wbm_clk_i)
+ {wbm_adr_o, wbm_adr_o_r} <= {wbm_adr_o_r, wbs_adr_i};
+
+ always @(posedge wbm_clk_i)
+ {wbm_dat_o, wbm_dat_o_r} <= {wbm_dat_o_r, wbs_dat_i};
+
+ always @(posedge wbm_clk_i)
+ {wbm_sel_o, wbm_sel_o_r} <= {wbm_sel_o_r, wbs_sel_i};
+
+ always @(posedge wbm_clk_i)
+ {wbm_we_o, wbm_we_o_r} <= {wbm_we_o_r, wbs_we_i};
+
+ always @(posedge wbm_clk_i)
+ {wbm_tga_o, wbm_tga_o_r} <= {wbm_tga_o_r, wbs_tga_i};
+
+ /*
+ * Register input coming from the slave as that can change
+ * after the ack is received
+ */
+ always @(posedge wbm_clk_i)
+ wbm_dat_i_r <= wbm_ack_i ? wbm_dat_i : wbm_dat_i_r;
+
+ always @(posedge wbs_clk_i)
+ {wbs_dat_o, wbs_dat_o_r} <= {wbs_dat_o_r, wbm_dat_i_r};
+
+endmodule
+"
+"/*
+ * 16-bit 8-way multiplexor
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_mux8_16(sel, in0, in1, in2, in3, in4, in5, in6, in7, out);
+ input [2:0] sel;
+ input [15:0] in0, in1, in2, in3, in4, in5, in6, in7;
+ output [15:0] out;
+
+ reg [15:0] out;
+
+ always @(sel or in0 or in1 or in2 or in3 or in4 or in5 or in6 or in7)
+ case(sel)
+ 3'd0: out = in0;
+ 3'd1: out = in1;
+ 3'd2: out = in2;
+ 3'd3: out = in3;
+ 3'd4: out = in4;
+ 3'd5: out = in5;
+ 3'd6: out = in6;
+ 3'd7: out = in7;
+ endcase
+endmodule
+"
+"/*
+ * Arithmetic Logic Unit for Zet
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`timescale 1ns/10ps
+
+module zet_alu (
+ input [31:0] x,
+ input [15:0] y,
+ output [31:0] out,
+ input [ 2:0] t,
+ input [ 2:0] func,
+ input [15:0] iflags,
+ output [ 8:0] oflags,
+ input word_op,
+ input [15:0] seg,
+ input [15:0] off,
+ input clk,
+ output div_exc
+ );
+
+ // Net declarations
+ wire [15:0] add, log, rot;
+ wire [15:0] arl;
+ wire [8:0] othflags;
+ wire [19:0] oth;
+ wire [31:0] cnv, mul;
+ wire af_add, af_cnv, af_arl;
+ wire cf_cnv, cf_add, cf_mul, cf_log, cf_arl, cf_rot;
+ wire of_cnv, of_add, of_mul, of_log, of_arl, of_rot;
+ wire ofi, sfi, zfi, afi, pfi, cfi;
+ wire ofo, sfo, zfo, afo, pfo, cfo;
+ wire flags_unchanged;
+ wire dexc;
+
+ // Module instances
+ zet_addsub addsub (x[15:0], y, add, func, word_op, cfi, cf_add, af_add, of_add);
+
+ zet_conv conv (
+ .x (x[15:0]),
+ .func (func),
+ .out (cnv),
+ .iflags ({afi, cfi}),
+ .oflags ({af_cnv, of_cnv, cf_cnv})
+ );
+
+ zet_muldiv muldiv (
+ .x (x),
+ .y (y),
+ .o (mul),
+ .f (func),
+ .word_op (word_op),
+ .cfo (cf_mul),
+ .ofo (of_mul),
+ .clk (clk),
+ .exc (dexc)
+ );
+
+ zet_bitlog bitlog (
+ .x (x[15:0]),
+ .o (log),
+ .cfo (cf_log),
+ .ofo (of_log)
+ );
+
+ zet_arlog arlog (
+ .x (x[15:0]),
+ .y (y),
+ .f (func),
+ .o (arl),
+ .word_op (word_op),
+ .cfi (cfi),
+ .cfo (cf_arl),
+ .afo (af_arl),
+ .ofo (of_arl)
+ );
+
+ zet_shrot shrot (
+ .x (x[15:0]),
+ .y (y[7:0]),
+ .out (rot),
+ .func (func),
+ .word_op (word_op),
+ .cfi (cfi),
+ .ofi (ofi),
+ .cfo (cf_rot),
+ .ofo (of_rot)
+ );
+
+ zet_othop othop (x[15:0], y, seg, off, iflags, func, word_op, oth, othflags);
+
+ zet_mux8_16 m0(t, {8'd0, y[7:0]}, add, cnv[15:0],
+ mul[15:0], log, arl, rot, oth[15:0], out[15:0]);
+ zet_mux8_16 m1(t, 16'd0, 16'd0, cnv[31:16], mul[31:16],
+ 16'd0, 16'd0, 16'd0, {12'b0,oth[19:16]}, out[31:16]);
+ zet_mux8_1 a1(t, 1'b0, cf_add, cf_cnv, cf_mul, cf_log, cf_arl, cf_rot, 1'b0, cfo);
+ zet_mux8_1 a2(t, 1'b0, af_add, af_cnv, 1'b0, 1'b0, af_arl, afi, 1'b0, afo);
+ zet_mux8_1 a3(t, 1'b0, of_add, of_cnv, of_mul, of_log, of_arl, of_rot, 1'b0, ofo);
+
+ // Flags
+ assign pfo = flags_unchanged ? pfi : ^~ out[7:0];
+ assign zfo = flags_unchanged ? zfi
+ : ((word_op && (t!=3'd2)) ? ~|out[15:0] : ~|out[7:0]);
+ assign sfo = flags_unchanged ? sfi
+ : ((word_op && (t!=3'd2)) ? out[15] : out[7]);
+
+ assign oflags = (t == 3'd7) ? othflags
+ : { ofo, iflags[10:8], sfo, zfo, afo, pfo, cfo };
+
+ assign ofi = iflags[11];
+ assign sfi = iflags[7];
+ assign zfi = iflags[6];
+ assign afi = iflags[4];
+ assign pfi = iflags[2];
+ assign cfi = iflags[0];
+
+ assign flags_unchanged = (t == 3'd4
+ || t == 3'd6 && (!func[2] || func[2]&&y[4:0]==5'h0));
+
+ assign div_exc = func[1] && (t==3'd3) && dexc;
+
+endmodule
+"
+"/*
+ * Microcode ROM for Zet
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`include ""defines.v""
+
+// altera message_off 10030
+// get rid of the warning about
+// not initializing the ROM
+
+module zet_micro_rom (
+ input [`MICRO_ADDR_WIDTH-1:0] addr,
+ output [`MICRO_DATA_WIDTH-1:0] q
+ );
+
+ // Registers, nets and parameters
+ reg [`MICRO_DATA_WIDTH-1:0] rom[0:2**`MICRO_ADDR_WIDTH-1];
+
+ // Assignments
+ assign q = rom[addr];
+
+ // Behaviour
+ initial $readmemb(""micro_rom.dat"", rom);
+endmodule
+"
+"/*
+ * Configuration interface for VGA
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+ /*
+ * 3b4: 0000_0011_1011_0100 crtc_idx (not used in vdu.v)
+ * 3b5: 0000_0011_1011_0101 CRTC (not used in vdu.v)
+ * 3c0: 0000_0011_1100_0000 attribute_ctrl
+ * 3c4: 0000_0011_1100_0100 sequencer.index
+ * 3c5: 0000_0011_1100_0101 sequencer.seq
+ * 3c6: 0000_0011_1100_0110 pel.mask
+ * 3c7: 0000_0011_1100_0111 pel.dac_state
+ * 3c8: 0000_0011_1100_1000 pel.write_data_register
+ * 3c9: 0000_0011_1100_1001 pel.data
+ * 3ce: 0000_0011_1100_1110 graphics_ctrl.index
+ * 3cf: 0000_0011_1100_1111 graphics_ctrl.data
+ * 3d4: 0000_0011_1101_0100 crtc_idx
+ * 3d5: 0000_0011_1101_0101 CRTC
+ * 3da: 0000_0011_1101_1010 Input Status 1 (color emulation modes)
+ * 3db: 0000_0011_1101_1011 not used
+ */
+
+module vga_config_iface (
+ // Wishbone slave signals
+ input wb_clk_i,
+ input wb_rst_i,
+ input [15:0] wb_dat_i,
+ output reg [15:0] wb_dat_o,
+ input [ 4:1] wb_adr_i,
+ input wb_we_i,
+ input [ 1:0] wb_sel_i,
+ input wb_stb_i,
+ output wb_ack_o,
+
+ // VGA configuration registers
+ // sequencer
+ output [3:0] map_mask, // 3c5 (3c4: 2)
+ output x_dotclockdiv2, // 3c5 (3c4: 1)
+ output chain_four, // 3c5 (3c4: 4)
+
+ // graphics_ctrl
+ output shift_reg1, // 3cf (3ce: 5)
+ output graphics_alpha, // 3cf (3ce: 6)
+ output memory_mapping1, // 3cf (3ce: 6)
+ output [1:0] write_mode, // 3cf (3ce: 5)
+ output [1:0] raster_op, // 3cf (3ce: 3)
+ output read_mode, // 3cf (3ce: 5)
+ output [7:0] bitmask, // 3cf (3ce: 8)
+ output [3:0] set_reset, // 3cf (3ce: 0)
+ output [3:0] enable_set_reset, // 3cf (3ce: 1)
+ output [1:0] read_map_select, // 3cf (3ce: 4)
+ output [3:0] color_compare, // 3cf (3ce: 2)
+ output [3:0] color_dont_care, // 3cf (3ce: 7)
+
+ // attribute_ctrl
+ output reg [3:0] pal_addr,
+ output pal_we,
+ input [7:0] pal_read,
+ output [7:0] pal_write,
+
+ // dac_regs
+ output dac_we,
+ output reg [1:0] dac_read_data_cycle,
+ output reg [7:0] dac_read_data_register,
+ input [3:0] dac_read_data,
+ output [1:0] dac_write_data_cycle, // word bypass
+ output [7:0] dac_write_data_register, // word bypass
+ output [3:0] dac_write_data,
+
+ // CRTC
+ output [ 5:0] cur_start,
+ output [ 5:0] cur_end,
+ output [15:0] start_addr,
+ output [ 4:0] vcursor,
+ output [ 6:0] hcursor,
+
+ output [ 6:0] horiz_total,
+ output [ 6:0] end_horiz,
+ output [ 6:0] st_hor_retr,
+ output [ 4:0] end_hor_retr,
+ output [ 9:0] vert_total,
+ output [ 9:0] end_vert,
+ output [ 9:0] st_ver_retr,
+ output [ 3:0] end_ver_retr,
+
+ input v_retrace,
+ input vh_retrace
+ );
+
+ // Registers and nets
+ reg [7:0] graphics_ctrl[0:8];
+ reg [3:0] graph_idx;
+ reg [7:0] CRTC[0:23];
+ reg [7:0] seq[0:4];
+ reg [4:0] crtc_idx;
+ reg [3:0] seq_idx;
+ reg flip_flop;
+ reg h_pal_addr;
+ reg ack_delay;
+ reg [1:0] dac_state;
+
+ reg [1:0] write_data_cycle;
+ reg [7:0] write_data_register;
+
+ integer i;
+
+ wire [3:0] graph_idx_wr;
+ wire [4:0] crtc_idx_wr;
+ wire [3:0] seq_idx_wr;
+ wire wr_graph;
+ wire wr_seq;
+ wire wr_crtc;
+ wire write;
+ wire read;
+ wire [7:0] start_hi;
+ wire [7:0] start_lo;
+ wire rst_flip_flop;
+ wire wr_attr;
+ wire rd_attr;
+ wire wr_pal_addr;
+ wire attr_ctrl_addr;
+ wire pel_adr_rd;
+ wire pel_adr_wr;
+ wire rd_dac;
+ wire dac_addr;
+ wire acc_dac;
+ wire wr_dac;
+
+ // Continuous assignments
+ assign wb_ack_o = (rd_attr | rd_dac) ? ack_delay : wb_stb_i;
+
+ assign seq_idx_wr = (wr_seq && wb_sel_i[0]) ? wb_dat_i[3:0] : seq_idx;
+ assign graph_idx_wr = (wr_graph && wb_sel_i[0]) ? wb_dat_i[3:0] : graph_idx;
+ assign crtc_idx_wr = (wr_crtc && wb_sel_i[0]) ? wb_dat_i[4:0] : crtc_idx;
+
+ assign map_mask = seq[2][3:0];
+ assign x_dotclockdiv2 = seq[1][3];
+ assign chain_four = seq[4][3];
+
+ assign shift_reg1 = graphics_ctrl[5][6];
+ assign graphics_alpha = graphics_ctrl[6][0];
+ assign memory_mapping1 = graphics_ctrl[6][3];
+ assign write_mode = graphics_ctrl[5][1:0];
+ assign raster_op = graphics_ctrl[3][4:3];
+ assign read_mode = graphics_ctrl[5][3];
+ assign bitmask = graphics_ctrl[8];
+ assign set_reset = graphics_ctrl[0][3:0];
+ assign enable_set_reset = graphics_ctrl[1][3:0];
+ assign read_map_select = graphics_ctrl[4][1:0];
+ assign color_compare = graphics_ctrl[2][3:0];
+ assign color_dont_care = graphics_ctrl[7][3:0];
+
+ assign cur_start = CRTC[10][5:0];
+ assign cur_end = CRTC[11][5:0];
+ assign start_hi = CRTC[12];
+ assign start_lo = CRTC[13];
+ assign vcursor = CRTC[14][4:0];
+ assign hcursor = CRTC[15][6:0];
+
+ assign horiz_total = CRTC[0][6:0];
+ assign end_horiz = CRTC[1][6:0];
+ assign st_hor_retr = CRTC[4][6:0];
+ assign end_hor_retr = CRTC[5][4:0];
+ assign vert_total = { CRTC[7][5], CRTC[7][0], CRTC[6] };
+ assign end_vert = { CRTC[7][6], CRTC[7][1], CRTC[18] };
+ assign st_ver_retr = { CRTC[7][7], CRTC[7][2], CRTC[16] };
+ assign end_ver_retr = CRTC[17][3:0];
+
+ assign write = wb_stb_i & wb_we_i;
+ assign read = wb_stb_i & !wb_we_i;
+ assign wr_seq = write & (wb_adr_i==4'h2);
+ assign wr_graph = write & (wb_adr_i==4'h7);
+ assign wr_crtc = write & (wb_adr_i==4'ha);
+
+ assign start_addr = { start_hi, start_lo };
+
+ assign attr_ctrl_addr = (wb_adr_i==4'h0);
+ assign dac_addr = (wb_adr_i==4'h4);
+ assign rst_flip_flop = read && (wb_adr_i==4'hd) && wb_sel_i[0];
+ assign wr_attr = write && attr_ctrl_addr && wb_sel_i[0];
+ assign rd_attr = read && attr_ctrl_addr && wb_sel_i[1];
+ assign wr_pal_addr = wr_attr && !flip_flop;
+
+ assign pel_adr_rd = write && (wb_adr_i==4'h3) && wb_sel_i[1];
+ assign pel_adr_wr = write && dac_addr && wb_sel_i[0];
+
+ assign pal_write = wb_dat_i[7:0];
+ assign pal_we = wr_attr && flip_flop && !h_pal_addr;
+
+ assign acc_dac = dac_addr && wb_sel_i[1];
+ assign rd_dac = (dac_state==2'b11) && read && acc_dac;
+ assign wr_dac = write && acc_dac;
+
+ assign dac_we = write && (wb_adr_i==4'h4) && wb_sel_i[1];
+ assign dac_write_data_cycle = wb_sel_i[0] ? 2'b00 : write_data_cycle;
+ assign dac_write_data = wb_dat_i[13:10];
+ assign dac_write_data_register = wb_sel_i[0] ? wb_dat_i[7:0]
+ : write_data_register;
+
+ // Behaviour
+ // write_data_register
+ always @(posedge wb_clk_i)
+ write_data_register <= wb_rst_i ? 8'h0
+ : (pel_adr_wr ? wb_dat_i[7:0]
+ : (wr_dac && (write_data_cycle==2'b10)) ?
+ (write_data_register + 8'h01) : write_data_register);
+
+ // write_data_cycle
+ always @(posedge wb_clk_i)
+ write_data_cycle <= (wb_rst_i | pel_adr_wr) ? 2'b00
+ : (wr_dac ? (write_data_cycle==2'b10 ? 2'b00
+ : write_data_cycle + 2'b01) : write_data_cycle);
+
+ // dac_read_data_register
+ always @(posedge wb_clk_i)
+ dac_read_data_register <= wb_rst_i ? 8'h00
+ : (pel_adr_rd ? wb_dat_i[15:8]
+ : (rd_dac && !wb_ack_o && (dac_read_data_cycle==2'b10)) ?
+ (dac_read_data_register + 8'h01) : dac_read_data_register);
+
+ // dac_read_data_cycle
+ always @(posedge wb_clk_i)
+ dac_read_data_cycle <= (wb_rst_i | pel_adr_rd) ? 2'b00
+ : (rd_dac && !wb_ack_o ? (dac_read_data_cycle==2'b10 ? 2'b00
+ : dac_read_data_cycle + 2'b01) : dac_read_data_cycle);
+
+ // dac_state
+ always @(posedge wb_clk_i)
+ dac_state <= wb_rst_i ? 2'b01
+ : (pel_adr_rd ? 2'b11 : (pel_adr_wr ? 2'b00 : dac_state));
+
+ // attribute_ctrl.flip_flop
+ always @(posedge wb_clk_i)
+ flip_flop <= (wb_rst_i | rst_flip_flop) ? 1'b0
+ : (wr_attr ? !flip_flop : flip_flop);
+
+ // pal_addr
+ always @(posedge wb_clk_i)
+ { h_pal_addr, pal_addr } <= wb_rst_i ? 5'h0
+ : (wr_pal_addr ? wb_dat_i[4:0] : { h_pal_addr, pal_addr });
+
+ // seq_idx
+ always @(posedge wb_clk_i)
+ seq_idx <= wb_rst_i ? 4'h0 : seq_idx_wr;
+
+ // seq
+ always @(posedge wb_clk_i)
+ if (wr_seq & wb_sel_i[1])
+ seq[seq_idx_wr] <= wb_dat_i[15:8];
+
+ // graph_idx
+ always @(posedge wb_clk_i)
+ graph_idx <= wb_rst_i ? 4'h0 : graph_idx_wr;
+
+ // graphics_ctrl
+ always @(posedge wb_clk_i)
+ if (wr_graph & wb_sel_i[1])
+ graphics_ctrl[graph_idx_wr] <= wb_dat_i[15:8];
+
+ // crtc_idx
+ always @(posedge wb_clk_i)
+ crtc_idx <= wb_rst_i ? 5'h0 : crtc_idx_wr;
+
+ // CRTC
+ always @(posedge wb_clk_i)
+ if (wr_crtc & wb_sel_i[1])
+ CRTC[crtc_idx_wr] <= wb_dat_i[15:8];
+
+ // ack_delay
+ always @(posedge wb_clk_i)
+ ack_delay <= wb_rst_i ? 1'b0
+ : ack_delay ? 1'b0 : wb_stb_i;
+
+ // wb_dat_o
+ always @(*)
+ case (wb_adr_i)
+ 4'h0: wb_dat_o = { pal_read, 3'b001, h_pal_addr, pal_addr };
+ 4'h2: wb_dat_o = { seq[seq_idx], 4'h0, seq_idx };
+ 4'h3: wb_dat_o = { 6'h0, dac_state, 8'hff };
+ 4'h4: wb_dat_o = { 2'b00, dac_read_data, 2'b00, write_data_register };
+ 4'h7: wb_dat_o = { graphics_ctrl[graph_idx], 4'h0, graph_idx };
+ 4'ha: wb_dat_o = { CRTC[crtc_idx], 3'h0, crtc_idx };
+ 4'hd: wb_dat_o = { 12'b0, v_retrace, 2'b0, vh_retrace };
+ default: wb_dat_o = 16'h0;
+ endcase
+/*
+ initial
+ begin
+ for (i=0;i<=8 ;i=i+1) graphics_ctrl[i] = 8'h0;
+ for (i=0;i<=15;i=i+1) CRTC[i] = 8'h0;
+ end
+*/
+endmodule
+"
+"/*
+ * GPIO module to deal with LEDs and switches
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module sw_leds (
+ // Wishbone slave interface
+ input wb_clk_i,
+ input wb_rst_i,
+ input wb_adr_i,
+ output [15:0] wb_dat_o,
+ input [15:0] wb_dat_i,
+ input [ 1:0] wb_sel_i,
+ input wb_we_i,
+ input wb_stb_i,
+ input wb_cyc_i,
+ output wb_ack_o,
+
+ // GPIO inputs/outputs
+ output reg [13:0] leds_,
+ input [ 7:0] sw_,
+ input pb_,
+ input tick,
+ output reg nmi_pb
+ );
+
+ // Registers and nets
+ wire op;
+ reg tick_old;
+ reg tick1;
+ reg nmi_pb_pressed;
+ reg [2:0] nmi_cnt;
+
+ // Continuous assignments
+ assign op = wb_cyc_i & wb_stb_i;
+ assign wb_ack_o = op;
+ assign wb_dat_o = wb_adr_i ? { 2'b00, leds_ }
+ : { 8'h00, sw_ };
+
+ // Behaviour
+ always @(posedge wb_clk_i)
+ leds_ <= wb_rst_i ? 14'h0
+ : ((op & wb_we_i & wb_adr_i) ? wb_dat_i[13:0] : leds_);
+
+ always @(posedge wb_clk_i)
+ begin
+ tick_old <= tick;
+ tick1 <= tick & ~tick_old;
+ end
+
+ always @(posedge wb_clk_i)
+ nmi_pb_pressed <= !pb_;
+
+ always @(posedge wb_clk_i)
+ begin
+ if (wb_rst_i)
+ begin
+ nmi_pb <= 1'b0;
+ nmi_cnt <= 3'b111;
+ end
+ else
+ begin
+ if (nmi_cnt == 3'b111)
+ begin
+ if (nmi_pb_pressed != nmi_pb)
+ begin
+ nmi_pb <= nmi_pb_pressed;
+ nmi_cnt <= nmi_cnt + 3'b001; // nmi_cnt <= 3'b000;
+ end
+ end
+ else if (tick1)
+ nmi_cnt <= nmi_cnt + 3'b001;
+ end
+ end
+
+endmodule
+"
+"/////////////////////////////////////////////////////////////////////
+//// ////
+//// Non-restoring signed by unsigned divider ////
+//// Uses the non-restoring unsigned by unsigned divider ////
+//// ////
+//// Author: Richard Herveille ////
+//// richard@asics.ws ////
+//// www.asics.ws ////
+//// ////
+/////////////////////////////////////////////////////////////////////
+//// ////
+//// Copyright (C) 2002 Richard Herveille ////
+//// richard@asics.ws ////
+//// ////
+//// This source file may be used and distributed without ////
+//// restriction provided that this copyright statement is not ////
+//// removed from the file and that any derivative work contains ////
+//// the original copyright notice and the associated disclaimer.////
+//// ////
+//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
+//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
+//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
+//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
+//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
+//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
+//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
+//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
+//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
+//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
+//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
+//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
+//// POSSIBILITY OF SUCH DAMAGE. ////
+//// ////
+/////////////////////////////////////////////////////////////////////
+
+// CVS Log
+//
+// $Id: div_su.v,v 1.2 2002/10/31 13:54:58 rherveille Exp $
+//
+// $Date: 2002/10/31 13:54:58 $
+// $Revision: 1.2 $
+// $Author: rherveille $
+// $Locker: $
+// $State: Exp $
+//
+// Change History:
+// $Log: div_su.v,v $
+// Revision 1.2 2002/10/31 13:54:58 rherveille
+// Fixed a bug in the remainder output of div_su.v
+//
+// Revision 1.1.1.1 2002/10/29 20:29:09 rherveille
+//
+//
+//
+
+//synopsys translate_off
+`timescale 1ns/10ps
+//synopsys translate_on
+
+module zet_div_su (clk, ena, z, d, q, s, ovf);
+
+ //
+ // parameters
+ //
+ parameter z_width = 16;
+ parameter d_width = z_width /2;
+
+ //
+ // inputs & outputs
+ //
+ input clk; // system clock
+ input ena; // clock enable
+
+ input [z_width-1:0] z; // divident
+ input [d_width-1:0] d; // divisor
+ output [d_width :0] q; // quotient
+ output [d_width :0] s; // remainder
+ output ovf;
+
+ reg [d_width:0] q, s;
+ reg ovf;
+
+ //
+ // variables
+ //
+ reg [z_width -1:0] iz;
+ reg [d_width -1:0] id;
+ reg [d_width +1:0] szpipe, sdpipe;
+
+ wire [d_width -1:0] iq, is;
+ wire idiv0, iovf;
+
+ //
+ // module body
+ //
+
+ // check d, take abs value
+ always @(posedge clk)
+ if (ena)
+ if (d[d_width-1])
+ id <= ~d +1'h1;
+ else
+ id <= d;
+
+ // check z, take abs value
+ always @(posedge clk)
+ if (ena)
+ if (z[z_width-1])
+ iz <= ~z +1'h1;
+ else
+ iz <= z;
+
+ // generate szpipe (z sign bit pipe)
+ integer n;
+ always @(posedge clk)
+ if(ena)
+ begin
+ szpipe[0] <= z[z_width-1];
+
+ for(n=1; n <= d_width+1; n=n+1)
+ szpipe[n] <= szpipe[n-1];
+ end
+
+ // generate sdpipe (d sign bit pipe)
+ integer m;
+ always @(posedge clk)
+ if(ena)
+ begin
+ sdpipe[0] <= d[d_width-1];
+
+ for(m=1; m <= d_width+1; m=m+1)
+ sdpipe[m] <= sdpipe[m-1];
+ end
+
+ // hookup non-restoring divider
+ zet_div_uu #(z_width, d_width)
+ divider (
+ .clk(clk),
+ .ena(ena),
+ .z(iz),
+ .d(id),
+ .q(iq),
+ .s(is),
+ .div0(idiv0),
+ .ovf(iovf)
+ );
+
+ // correct divider results if 'd' was negative
+ always @(posedge clk)
+ if(ena)
+ begin
+ q <= (szpipe[d_width+1]^sdpipe[d_width+1]) ?
+ ((~iq) + 1'h1) : ({1'b0, iq});
+ s <= (szpipe[d_width+1]) ?
+ ((~is) + 1'h1) : ({1'b0, is});
+ end
+
+ // delay flags same as results
+ always @(posedge clk)
+ if(ena)
+ begin
+ ovf <= iovf;
+ end
+endmodule
+"
+"/*\r
+ * PAL/DAC controller for VGA\r
+ * Copyright (C) 2010 Zeus Gomez Marmolejo \r
+ *\r
+ * VGA FML support\r
+ * Copyright (C) 2013 Charley Picker \r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+module vga_pal_dac_fml (\r
+ input clk, // 100 Mhz clock\r
+ input rst,\r
+\r
+ input enable_pal_dac,\r
+\r
+ // VGA PAL/DAC input signals\r
+\r
+ input horiz_sync_pal_dac_i,\r
+ input vert_sync_pal_dac_i,\r
+ input video_on_h_pal_dac_i,\r
+ input video_on_v_pal_dac_i,\r
+ input [7:0] character_pal_dac_i,\r
+\r
+ // VGA PAL/DAC configuration signals\r
+\r
+ input shift_reg1, // if set: 320x200\r
+ input graphics_alpha, // if not set: 640x400 text mode\r
+\r
+ // attribute_ctrl\r
+ input [3:0] pal_addr,\r
+ input pal_we,\r
+ output [7:0] pal_read,\r
+ input [7:0] pal_write,\r
+\r
+ // dac_regs\r
+ input dac_we,\r
+ input [1:0] dac_read_data_cycle,\r
+ input [7:0] dac_read_data_register,\r
+ output [3:0] dac_read_data,\r
+ input [1:0] dac_write_data_cycle,\r
+ input [7:0] dac_write_data_register,\r
+ input [3:0] dac_write_data,\r
+\r
+ // VGA PAL/DAC output signals\r
+\r
+ // VGA pad signals\r
+ output reg [3:0] vga_red_o,\r
+ output reg [3:0] vga_green_o,\r
+ output reg [3:0] vga_blue_o,\r
+ output reg horiz_sync,\r
+ output vert_sync,\r
+\r
+ // retrace signals\r
+ output v_retrace,\r
+ output vh_retrace\r
+ );\r
+\r
+ // Registers and nets\r
+ wire video_on_v;\r
+ reg [1:0] video_on_h_p;\r
+\r
+ wire video_on;\r
+\r
+ wire [3:0] attr;\r
+ wire [7:0] index;\r
+ wire [7:0] index_pal;\r
+ reg [7:0] index_gm;\r
+\r
+ wire video_on_h;\r
+\r
+ reg [1:0] horiz_sync_p;\r
+ \r
+ wire [3:0] red;\r
+ wire [3:0] green;\r
+ wire [3:0] blue;\r
+\r
+ // Module instances\r
+\r
+ vga_palette_regs_fml palette_regs (\r
+ .clk (clk),\r
+\r
+ .attr (attr),\r
+ .index (index_pal),\r
+\r
+ .address (pal_addr),\r
+ .write (pal_we),\r
+ .read_data (pal_read),\r
+ .write_data (pal_write)\r
+ );\r
+\r
+ vga_dac_regs_fml dac_regs (\r
+ .clk (clk),\r
+\r
+ .index (index),\r
+ .red (red),\r
+ .green (green),\r
+ .blue (blue),\r
+\r
+ .write (dac_we),\r
+\r
+ .read_data_cycle (dac_read_data_cycle),\r
+ .read_data_register (dac_read_data_register),\r
+ .read_data (dac_read_data),\r
+\r
+ .write_data_cycle (dac_write_data_cycle),\r
+ .write_data_register (dac_write_data_register),\r
+ .write_data (dac_write_data)\r
+ );\r
+\r
+ // Continuous assignments\r
+ assign video_on_v = video_on_v_pal_dac_i;\r
+ assign vert_sync = vert_sync_pal_dac_i;\r
+\r
+ assign video_on = video_on_h && video_on_v;\r
+\r
+ assign attr = character_pal_dac_i[3:0];\r
+ assign index = (graphics_alpha & shift_reg1) ? index_gm : index_pal;\r
+\r
+ assign video_on_h = video_on_h_p[1];\r
+\r
+ assign v_retrace = !video_on_v;\r
+ assign vh_retrace = v_retrace | !video_on_h;\r
+\r
+ // index_gm\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ index_gm <= 8'h0;\r
+ end\r
+ else\r
+ if (enable_pal_dac)\r
+ begin\r
+ index_gm <= character_pal_dac_i;\r
+ end\r
+\r
+ // Horiz sync\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ { horiz_sync, horiz_sync_p } <= 3'b0;\r
+ end\r
+ else\r
+ if (enable_pal_dac)\r
+ begin\r
+ { horiz_sync, horiz_sync_p } <= { horiz_sync_p[1:0], horiz_sync_pal_dac_i }; \r
+ end\r
+\r
+ // Video_on pipe\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ video_on_h_p <= 2'b0;\r
+ end\r
+ else\r
+ if (enable_pal_dac)\r
+ begin\r
+ video_on_h_p <= { video_on_h_p[0], video_on_h_pal_dac_i };\r
+ end\r
+\r
+ // Colour signals\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ vga_red_o <= 4'b0;\r
+ vga_green_o <= 4'b0;\r
+ vga_blue_o <= 4'b0;\r
+ end\r
+ else\r
+ if (enable_pal_dac)\r
+ begin\r
+ vga_blue_o <= video_on ? blue : 4'h0;\r
+ vga_green_o <= video_on ? green : 4'h0;\r
+ vga_red_o <= video_on ? red : 4'h0;\r
+ end\r
+\r
+endmodule\r
+"
+"/*
+ * Copyright (c) 2009 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module hex_display (
+ input [15:0] num,
+ input en,
+
+ output [6:0] hex0,
+ output [6:0] hex1,
+ output [6:0] hex2,
+ output [6:0] hex3
+ );
+
+ // Module instantiations
+ seg_7 hex_group0 (
+ .num (num[3:0]),
+ .en (en),
+ .seg (hex0)
+ );
+
+ seg_7 hex_group1 (
+ .num (num[7:4]),
+ .en (en),
+ .seg (hex1)
+ );
+
+ seg_7 hex_group2 (
+ .num (num[11:8]),
+ .en (en),
+ .seg (hex2)
+ );
+
+ seg_7 hex_group3 (
+ .num (num[15:12]),
+ .en (en),
+ .seg (hex3)
+ );
+
+endmodule
+"
+"/*
+ * Copyright (c) 2008 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`timescale 1ns/10ps
+
+`include ""defines.v""
+
+module zet_regfile (
+ output [15:0] a,
+ output [15:0] b,
+ output [15:0] c,
+ output [15:0] cs,
+ output [15:0] ip,
+ input [31:0] d,
+ output [15:0] s,
+
+ output reg [8:0] flags,
+
+ input wr,
+ input wrfl,
+ input wrhi,
+ input clk,
+ input rst,
+ input [ 3:0] addr_a,
+ input [ 3:0] addr_b,
+ input [ 3:0] addr_c,
+ input [ 3:0] addr_d,
+ input [ 1:0] addr_s,
+ input [ 8:0] iflags,
+ input word_op,
+ input a_byte,
+ input b_byte,
+ input c_byte,
+ output cx_zero,
+ input wr_ip0
+ );
+
+ // Net declarations
+ reg [15:0] r[15:0];
+ wire [7:0] a8, b8, c8;
+ wire [3:0] addr_a_8;
+ wire [3:0] addr_b_8;
+ wire [3:0] addr_c_8;
+
+ // Assignments
+ assign addr_a_8 = { 2\'b00, addr_a[1:0] };
+ assign addr_b_8 = { 2\'b00, addr_b[1:0] };
+ assign addr_c_8 = { 2\'b00, addr_c[1:0] };
+
+ assign a = (a_byte & ~addr_a[3]) ? { {8{a8[7]}}, a8} : r[addr_a];
+ assign a8 = addr_a[2] ? r[addr_a_8][15:8] : r[addr_a][7:0];
+
+ assign b = (b_byte & ~addr_b[3]) ? { {8{b8[7]}}, b8} : r[addr_b];
+ assign b8 = addr_b[2] ? r[addr_b_8][15:8] : r[addr_b][7:0];
+
+ assign c = (c_byte & ~addr_c[3]) ? { {8{c8[7]}}, c8} : r[addr_c];
+ assign c8 = addr_c[2] ? r[addr_c_8][15:8] : r[addr_c][7:0];
+
+ assign s = r[{2\'b10,addr_s}];
+
+ assign cs = r[9];
+ assign cx_zero = (addr_d==4\'d1) ? (d==16\'d0) : (r[1]==16\'d0);
+
+ assign ip = r[15];
+
+ // Behaviour
+ always @(posedge clk)
+ if (rst) begin
+ r[0] <= 16\'d0; r[1] <= 16\'d0;
+ r[2] <= 16\'d0; r[3] <= 16\'d0;
+ r[4] <= 16\'d0; r[5] <= 16\'d0;
+ r[6] <= 16\'d0; r[7] <= 16\'d0;
+ r[8] <= 16\'d0; r[9] <= 16\'hf000;
+ r[10] <= 16\'d0; r[11] <= 16\'d0;
+ r[12] <= 16\'d0; r[13] <= 16\'d0;
+ r[14] <= 16\'d0; r[15] <= 16\'hfff0;
+ flags <= 9\'d0;
+ end else
+ begin
+ if (wr) begin
+ if (word_op | addr_d[3:2]==2\'b10)
+ r[addr_d] <= word_op ? d[15:0] : {{8{d[7]}},d[7:0]};
+ else if (addr_d[3]~^addr_d[2]) r[addr_d][7:0] <= d[7:0];
+ else r[{2\'b0,addr_d[1:0]}][15:8] <= d[7:0];
+ end
+ if (wrfl) flags <= iflags;
+ if (wrhi) r[4\'d2] <= d[31:16];
+ if (wr_ip0) r[14] <= ip;
+ end
+endmodule"
+"/*
+ * Super Simple Priority Interrupt Controller
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module simple_pic (
+ input clk,
+ input rst,
+ input [7:0] intv,
+ input inta,
+ output intr,
+ output reg [2:0] iid
+ );
+
+ // Registers
+ reg [7:0] irr;
+ reg inta_r;
+ reg int3_r;
+ reg int4_r;
+
+ // Continuous assignments, note that only IRQs 0,1,3 & 4 are driven atm
+ assign intr = irr[4] | irr[3] | irr[1] | irr[0];
+
+ // Behaviour of inta_r
+ always @(posedge clk) inta_r <= inta;
+
+ // irr
+ always @(posedge clk)
+ irr[0] <= rst ? 1'b0 : (intv[0] | irr[0] & !(iid == 3'b000 && inta_r && !inta));
+
+ always @(posedge clk)
+ irr[1] <= rst ? 1'b0 : (intv[1] | irr[1] & !(iid == 3'b001 && inta_r && !inta));
+
+ always @(posedge clk)
+ irr[3] <= rst ? 1'b0 : ((intv[3] && !int3_r) | irr[3] & !(iid == 3'b011 && inta_r && !inta));
+ always @(posedge clk) int3_r <= rst ? 1'b0 : intv[3]; // int3_r
+
+ always @(posedge clk)
+ irr[4] <= rst ? 1'b0 : ((intv[4] && !int4_r) | irr[4] & !(iid == 3'b100 && inta_r && !inta));
+ always @(posedge clk) int4_r <= rst ? 1'b0 : intv[4]; // int4_r
+
+ always @(posedge clk) // iid
+ iid <= rst ? 3'b0 : (inta ? iid :
+ (irr[0] ? 3'b000 :
+ (irr[1] ? 3'b001 :
+ (irr[3] ? 3'b011 :
+ (irr[4] ? 3'b100 :
+ 3'b000
+ )))));
+
+endmodule
+"
+"/*
+ * Read memory interface for VGA
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vga_read_iface (
+ // Wishbone common signals
+ input wb_clk_i,
+ input wb_rst_i,
+
+ // Wishbone slave read interface
+ input [16:1] wbs_adr_i,
+ input [ 1:0] wbs_sel_i,
+ output [15:0] wbs_dat_o,
+ input wbs_stb_i,
+ output wbs_ack_o,
+
+ // Wishbone master read to SRAM
+ output [17:1] wbm_adr_o,
+ input [15:0] wbm_dat_i,
+ output reg wbm_stb_o,
+ input wbm_ack_i,
+
+ // VGA configuration registers
+ input memory_mapping1,
+ input read_mode,
+ input [1:0] read_map_select,
+ input [3:0] color_compare,
+ input [3:0] color_dont_care,
+
+ output [7:0] latch0,
+ output [7:0] latch1,
+ output [7:0] latch2,
+ output [7:0] latch3
+ );
+
+ // Registers and nets
+ reg [ 1:0] plane;
+ reg latch_sel;
+ reg [15:0] latch [0:3];
+
+ wire [15:1] offset;
+ wire [15:0] dat_o0, dat_o1;
+ wire [15:0] out_l0, out_l1, out_l2, out_l3;
+ wire cont;
+
+ // Continous assignments
+ assign latch0 = latch_sel ? latch[0][15:8] : latch[0][7:0];
+ assign latch1 = latch_sel ? latch[1][15:8] : latch[1][7:0];
+ assign latch2 = latch_sel ? latch[2][15:8] : latch[2][7:0];
+ assign latch3 = latch_sel ? latch[3][15:8] : latch[3][7:0];
+
+ assign wbm_adr_o = { offset, plane };
+ assign wbs_ack_o = (plane==2'b11 && wbm_ack_i);
+ assign offset = memory_mapping1 ? { 1'b0, wbs_adr_i[14:1] }
+ : wbs_adr_i[15:1];
+ assign wbs_dat_o = read_mode ? dat_o1 : dat_o0;
+ assign dat_o0 = (read_map_select==2'b11) ? wbm_dat_i
+ : latch[read_map_select];
+ assign dat_o1 = ~(out_l0 | out_l1 | out_l2 | out_l3);
+
+ assign out_l0 = (latch[0] ^ { 16{color_compare[0]} })
+ & { 16{color_dont_care[0]} };
+ assign out_l1 = (latch[1] ^ { 16{color_compare[1]} })
+ & { 16{color_dont_care[1]} };
+ assign out_l2 = (latch[2] ^ { 16{color_compare[2]} })
+ & { 16{color_dont_care[2]} };
+ assign out_l3 = (wbm_dat_i ^ { 16{color_compare[3]} })
+ & { 16{color_dont_care[3]} };
+
+ assign cont = wbm_ack_i && wbs_stb_i;
+
+ // Behaviour
+ // latch_sel
+ always @(posedge wb_clk_i)
+ latch_sel <= wb_rst_i ? 1'b0
+ : (wbs_stb_i ? wbs_sel_i[1] : latch_sel);
+
+ // wbm_stb_o
+ always @(posedge wb_clk_i)
+ wbm_stb_o <= wb_rst_i ? 1'b0 : (wbm_stb_o ? ~wbs_ack_o : wbs_stb_i);
+
+ // plane
+ always @(posedge wb_clk_i)
+ plane <= wb_rst_i ? 2'b00 : (cont ? (plane + 2'b01) : plane);
+
+ // Latch load
+ always @(posedge wb_clk_i)
+ if (wb_rst_i)
+ begin
+ latch[0] <= 8'h0;
+ latch[1] <= 8'h0;
+ latch[2] <= 8'h0;
+ latch[3] <= 8'h0;
+ end
+ else if (wbm_ack_i && wbm_stb_o) latch[plane] <= wbm_dat_i;
+
+endmodule
+"
+"/*
+ * Linear mode graphics for VGA
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vga_linear (
+ input clk,
+ input rst,
+
+ // CSR slave interface for reading
+ output [17:1] csr_adr_o,
+ input [15:0] csr_dat_i,
+ output csr_stb_o,
+
+ input [9:0] h_count,
+ input [9:0] v_count,
+ input horiz_sync_i,
+ input video_on_h_i,
+ output video_on_h_o,
+
+ output [7:0] color,
+ output horiz_sync_o
+ );
+
+ // Registers
+ reg [ 9:0] row_addr;
+ reg [ 6:0] col_addr;
+ reg [14:1] word_offset;
+ reg [ 1:0] plane_addr;
+ reg [ 1:0] plane_addr0;
+ reg [ 7:0] color_l;
+
+ reg [4:0] video_on_h;
+ reg [4:0] horiz_sync;
+ reg [5:0] pipe;
+ reg [15:0] word_color;
+
+ // Continous assignments
+ assign csr_adr_o = { word_offset, plane_addr, 1'b0 };
+ assign csr_stb_o = pipe[1];
+
+ assign color = pipe[4] ? csr_dat_i[7:0] : color_l;
+
+ assign video_on_h_o = video_on_h[4];
+ assign horiz_sync_o = horiz_sync[4];
+
+ // Behaviour
+ // Pipeline count
+ always @(posedge clk)
+ pipe <= rst ? 6'b0 : { pipe[4:0], ~h_count[0] };
+
+ // video_on_h
+ always @(posedge clk)
+ video_on_h <= rst ? 5'b0 : { video_on_h[3:0], video_on_h_i };
+
+ // horiz_sync
+ always @(posedge clk)
+ horiz_sync <= rst ? 5'b0 : { horiz_sync[3:0], horiz_sync_i };
+
+ // Address generation
+ always @(posedge clk)
+ if (rst)
+ begin
+ row_addr <= 10'h0;
+ col_addr <= 7'h0;
+ plane_addr0 <= 2'b00;
+ word_offset <= 14'h0;
+ plane_addr <= 2'b00;
+ end
+ else
+ begin
+ // Loading new row_addr and col_addr when h_count[3:0]==4'h0
+ // v_count * 5 * 32
+ row_addr <= { v_count[8:1], 2'b00 } + v_count[8:1];
+ col_addr <= h_count[9:3];
+ plane_addr0 <= h_count[2:1];
+
+ word_offset <= { row_addr + col_addr[6:4], col_addr[3:0] };
+ plane_addr <= plane_addr0;
+ end
+
+ // color_l
+ always @(posedge clk)
+ color_l <= rst ? 8'h0 : (pipe[4] ? csr_dat_i[7:0] : color_l);
+
+endmodule
+"
+"/*
+ * 16-bit full adder
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_fulladd16 (
+ input [15:0] x,
+ input [15:0] y,
+ input ci,
+ output co,
+ output [15:0] z,
+ input s
+ );
+
+ // Continuous assignments
+ assign {co,z} = {1'b0, x} + {s, y} + ci;
+endmodule
+"
+"`timescale 10ns/100ps
+
+module test_zet;
+
+ // Net declarations
+ wire [15:0] dat_o;
+ wire [15:0] mem_dat_i, io_dat_i, dat_i;
+ wire [19:1] adr;
+ wire we;
+ wire tga;
+ wire [ 1:0] sel;
+ wire stb;
+ wire cyc;
+ wire ack, mem_ack, io_ack;
+ wire inta;
+ wire nmia;
+ wire [19:0] pc;
+
+ reg clk;
+ reg rst;
+
+ reg [15:0] io_reg;
+
+ reg intr;
+
+ // Module instantiations
+ memory mem0 (
+ .wb_clk_i (clk),
+ .wb_rst_i (rst),
+ .wb_dat_i (dat_o),
+ .wb_dat_o (mem_dat_i),
+ .wb_adr_i (adr),
+ .wb_we_i (we),
+ .wb_sel_i (sel),
+ .wb_stb_i (stb & !tga),
+ .wb_cyc_i (cyc & !tga),
+ .wb_ack_o (mem_ack)
+ );
+
+ zet zet (
+ .wb_clk_i (clk),
+ .wb_rst_i (rst),
+ .wb_dat_i (dat_i),
+ .wb_dat_o (dat_o),
+ .wb_adr_o (adr),
+ .wb_we_o (we),
+ .wb_tga_o (tga),
+ .wb_sel_o (sel),
+ .wb_stb_o (stb),
+ .wb_cyc_o (cyc),
+ .wb_ack_i (ack),
+ .wb_tgc_i (1\'b0),
+ .wb_tgc_o (inta),
+ .nmi (1\'b0),
+ .nmia (nmia),
+ .pc (pc)
+ );
+
+ // Assignments
+ assign io_dat_i = (adr[15:1]==15\'h5b) ? { io_reg[7:0], 8\'h0 }
+ : ((adr[15:1]==15\'h5c) ? { 8\'h0, io_reg[15:8] } : 16\'h0);
+ assign dat_i = inta ? 16\'d3 : (tga ? io_dat_i : mem_dat_i);
+
+ assign ack = tga ? io_ack : mem_ack;
+ assign io_ack = stb;
+
+ // Behaviour
+ // IO Stub
+ always @(posedge clk)
+ if (adr[15:1]==15\'h5b && sel[1] && cyc && stb)
+ io_reg[7:0] <= dat_o[15:8];
+ else if (adr[15:1]==15\'h5c & sel[0] && cyc && stb)
+ io_reg[15:8] <= dat_o[7:0];
+
+ always #4 clk = ~clk; // 12.5 Mhz
+
+ initial
+ begin
+ intr <= 1\'b0;
+ clk <= 1\'b1;
+ rst <= 1\'b0;
+ #5 rst <= 1\'b1;
+ #5 rst <= 1\'b0;
+
+ #1000 intr <= 1\'b1;
+ //@(posedge inta)
+ @(posedge clk) intr <= 1\'b0;
+ end
+
+ initial
+ begin
+ $readmemh(""data.rtlrom"", mem0.ram, 19\'h78000);
+ $readmemb(""../rtl/micro_rom.dat"",
+ zet.core.micro_data.micro_rom.rom);
+ end
+endmodule
+"
+"/*
+ * Opcode decoder lookup table for Zet
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`include ""defines.v""
+
+module zet_opcode_deco (
+ input [7:0] op,
+ input [7:0] modrm,
+ input rep,
+ input [2:0] sovr_pr,
+
+ output reg [`MICRO_ADDR_WIDTH-1:0] seq_addr,
+ output reg need_modrm,
+ output reg need_off,
+ output reg need_imm,
+ output off_size,
+ output reg imm_size,
+
+ output reg [3:0] src,
+ output reg [3:0] dst,
+ output [3:0] base,
+ output [3:0] index,
+ output [1:0] seg
+ );
+
+ // Net declarations
+ wire [1:0] mod;
+ wire [2:0] regm;
+ wire [2:0] rm;
+ wire d, b, sm, dm;
+ wire off_size_mod, need_off_mod;
+ wire [2:0] srcm, dstm;
+ wire off_size_from_mod;
+
+ // Module instantiations
+ zet_memory_regs memory_regs (rm, mod, sovr_pr, base, index, seg);
+
+ // Assignments
+ assign mod = modrm[7:6];
+ assign regm = modrm[5:3];
+ assign rm = modrm[2:0];
+ assign d = op[1];
+ assign dstm = d ? regm : rm;
+ assign sm = d & (mod != 2\'b11);
+ assign dm = ~d & (mod != 2\'b11);
+ assign srcm = d ? rm : regm;
+ assign b = ~op[0];
+ assign off_size_mod = (base == 4\'b1100 && index == 4\'b1100) ? 1\'b1 : mod[1];
+ assign need_off_mod = (base == 4\'b1100 && index == 4\'b1100) || ^mod;
+ assign off_size_from_mod = !op[7] | (!op[5] & !op[4]) | (op[6] & op[4]);
+ assign off_size = !off_size_from_mod | off_size_mod;
+
+ // Behaviour
+ always @(op or dm or b or need_off_mod or srcm or sm or dstm
+ or mod or rm or regm or rep or modrm)
+ casex (op)
+ 8\'b00xx_x00x: // add/or/adc/sbb/and/sub/xor/cmp r->r, r->m
+ begin
+ seq_addr <= (mod==2\'b11) ? (b ? `LOGRRB : `LOGRRW)
+ : (b ? `LOGRMB : `LOGRMW);
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ dst <= { 1\'b0, dstm };
+ src <= { 1\'b0, srcm };
+ end
+
+ 8\'b00xx_x01x: // add/or/adc/sbb/and/sub/xor/cmp r->r, m->r
+ begin
+ seq_addr <= (mod==2\'b11) ? (b ? `LOGRRB : `LOGRRW)
+ : (b ? `LOGMRB : `LOGMRW);
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ dst <= { 1\'b0, dstm };
+ src <= { 1\'b0, srcm };
+ end
+
+ 8\'b00xx_x10x: // add/or/adc/sbb/and/sub/xor/cmp i->r
+ begin
+ seq_addr <= b ? `LOGIRB : `LOGIRW;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= ~b;
+ dst <= 4\'b0;
+ src <= 4\'b0;
+ end
+
+ 8\'b000x_x110: // push seg
+ begin
+ seq_addr <= `PUSHR;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= { 2\'b10, op[4:3] };
+ dst <= 4\'b0;
+ end
+
+ 8\'b000x_x111: // pop seg
+ begin
+ seq_addr <= `POPR;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= { 2\'b10, op[4:3] };
+ end
+
+ 8\'b0010_0111: // daa
+ begin
+ seq_addr <= `DAA;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ dst <= 4\'b0;
+ src <= 4\'b0;
+ end
+
+ 8\'b0010_1111: // das
+ begin
+ seq_addr <= `DAS;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ dst <= 4\'b0;
+ src <= 4\'b0;
+ end
+
+ 8\'b0011_0111: // aaa
+ begin
+ seq_addr <= `AAA;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ dst <= 4\'b0;
+ src <= 4\'b0;
+ end
+
+ 8\'b0011_1111: // aas
+ begin
+ seq_addr <= `AAS;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ dst <= 4\'b0;
+ src <= 4\'b0;
+ end
+
+ 8\'b0100_0xxx: // inc
+ begin
+ seq_addr <= `INCRW;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ dst <= 4\'b0;
+ src <= { 1\'b0, op[2:0] };
+ end
+
+ 8\'b0100_1xxx: // dec
+ begin
+ seq_addr <= `DECRW;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ dst <= 4\'b0;
+ src <= { 1\'b0, op[2:0] };
+ end
+
+ 8\'b0101_0xxx: // push reg
+ begin
+ seq_addr <= `PUSHR;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= { 1\'b0, op[2:0] };
+ dst <= 4\'b0;
+ end
+
+ 8\'b0101_1xxx: // pop reg
+ begin
+ seq_addr <= `POPR;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= { 1\'b0, op[2:0] };
+ end
+
+ 8\'b0110_0000: // pusha
+ begin
+ seq_addr <= `PUSHA;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b0110_0001: // popa
+ begin
+ seq_addr <= `POPA;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b0110_10x0: // push imm
+ begin
+ seq_addr <= `PUSHI;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= !op[1];
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b0110_10x1: // imul imm
+ begin
+ seq_addr <= (mod==2\'b11) ? `IMULIR : `IMULIM;
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b1;
+ imm_size <= !op[1];
+ src <= { 1\'b0, rm };
+ dst <= { 1\'b0, regm };
+ end
+
+ 8\'b0111_xxxx: // jcc
+ begin
+ seq_addr <= `JCC;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b0;
+ src <= { op[3:0] };
+ dst <= 4\'b0;
+ end
+
+ 8\'b1000_00xx: // add/or/adc/sbb/and/sub/xor/cmp imm
+ begin
+ seq_addr <= (mod==2\'b11) ? (b ? `LOGIRB : `LOGIRW)
+ : (b ? `LOGIMB : `LOGIMW);
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b1;
+ imm_size <= !op[1] & op[0];
+ dst <= { 1\'b0, modrm[2:0] };
+ src <= 4\'b0;
+ end
+
+ 8\'b1000_010x: // test r->r, r->m
+ begin
+ seq_addr <= (mod==2\'b11) ? (b ? `TSTRRB : `TSTRRW)
+ : (b ? `TSTMRB : `TSTMRW);
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ dst <= { 1\'b0, srcm };
+ src <= { 1\'b0, dstm };
+ end
+
+ 8\'b1000_011x: // xchg
+ begin
+ seq_addr <= (mod==2\'b11) ? (b ? `XCHRRB : `XCHRRW)
+ : (b ? `XCHRMB : `XCHRMW);
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ dst <= { 1\'b0, dstm };
+ src <= { 1\'b0, srcm };
+ end
+ 8\'b1000_10xx: // mov: r->r, r->m, m->r
+ begin
+ if (dm) // r->m
+ begin
+ seq_addr <= b ? `MOVRMB : `MOVRMW;
+ need_off <= need_off_mod;
+ src <= { 1\'b0, srcm };
+ dst <= 4\'b0;
+ end
+ else if(sm) // m->r
+ begin
+ seq_addr <= b ? `MOVMRB : `MOVMRW;
+ need_off <= need_off_mod;
+ src <= 4\'b0;
+ dst <= { 1\'b0, dstm };
+ end
+ else // r->r
+ begin
+ seq_addr <= b ? `MOVRRB : `MOVRRW;
+ need_off <= 1\'b0;
+ dst <= { 1\'b0, dstm };
+ src <= { 1\'b0, srcm };
+ end
+ need_imm <= 1\'b0;
+ need_modrm <= 1\'b1;
+ imm_size <= 1\'b0;
+ end
+
+ 8\'b1000_1100: // mov: s->m, s->r
+ begin
+ if (dm) // s->m
+ begin
+ seq_addr <= `MOVRMW;
+ need_off <= need_off_mod;
+ src <= { 1\'b1, srcm };
+ dst <= 4\'b0;
+ end
+ else // s->r
+ begin
+ seq_addr <= `MOVRRW;
+ need_off <= 1\'b0;
+ src <= { 1\'b1, srcm };
+ dst <= { 1\'b0, dstm };
+ end
+ need_imm <= 1\'b0;
+ need_modrm <= 1\'b1;
+ imm_size <= 1\'b0;
+ end
+
+ 8\'b1000_1101: // lea
+ begin
+ seq_addr <= `LEA;
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= { 1\'b0, srcm };
+ dst <= 4\'b0;
+ end
+
+ 8\'b1000_1110: // mov: m->s, r->s
+ begin
+ if (sm) // m->s
+ begin
+ seq_addr <= `MOVMRW;
+ need_off <= need_off_mod;
+ src <= 4\'b0;
+ dst <= { 1\'b1, dstm };
+ end
+ else // r->s
+ begin
+ seq_addr <= `MOVRRW;
+ need_off <= 1\'b0;
+ src <= { 1\'b0, srcm };
+ dst <= { 1\'b1, dstm };
+ end
+ need_modrm <= 1\'b1;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ end
+
+ 8\'b1000_1111: // pop mem or (pop reg non-standard)
+ begin
+ seq_addr <= (mod==2\'b11) ? `POPR : `POPM;
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= { 1\'b0, rm };
+ end
+
+ 8\'b1001_0xxx: // nop, xchg acum
+ begin
+ seq_addr <= `XCHRRW;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0000;
+ dst <= { 1\'b0, op[2:0] };
+ end
+
+ 8\'b1001_1000: // cbw
+ begin
+ seq_addr <= `CBW;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ dst <= 4\'b0;
+ src <= 4\'b0;
+ end
+
+ 8\'b1001_1001: // cwd
+ begin
+ seq_addr <= `CWD;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ dst <= 4\'b0;
+ src <= 4\'b0;
+ end
+
+ 8\'b1001_1010: // call different seg
+ begin
+ seq_addr <= `CALLF;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b1;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b1;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1001_1011: // wait
+ begin
+ seq_addr <= `NOP;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1001_1100: // pushf
+ begin
+ seq_addr <= `PUSHF;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1001_1101: // popf
+ begin
+ seq_addr <= `POPF;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1001_1110: // sahf
+ begin
+ seq_addr <= `SAHF;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1001_1111: // lahf
+ begin
+ seq_addr <= `LAHF;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1010_000x: // mov: m->a
+ begin
+ seq_addr <= b ? `MOVMAB : `MOVMAW;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b1;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1010_001x: // mov: a->m
+ begin
+ seq_addr <= b ? `MOVAMB : `MOVAMW;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b1;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1010_010x: // movs
+ begin
+ seq_addr <= rep ? (b ? `MOVSBR : `MOVSWR) : (b ? `MOVSB : `MOVSW);
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1010_011x: // cmps
+ begin
+ seq_addr <= rep ? (b ? `CMPSBR : `CMPSWR) : (b ? `CMPSB : `CMPSW);
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1010_100x: // test i->r
+ begin
+ seq_addr <= b ? `TSTIRB : `TSTIRW;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= ~b;
+ dst <= 4\'b0;
+ src <= 4\'b0;
+ end
+
+ 8\'b1010_101x: // stos
+ begin
+ seq_addr <= rep ? (b ? `STOSBR : `STOSWR) : (b ? `STOSB : `STOSW);
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1010_110x: // lods
+ begin
+ seq_addr <= rep ? (b ? `LODSBR : `LODSWR) : (b ? `LODSB : `LODSW);
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1010_111x: // scas
+ begin
+ seq_addr <= rep ? (b ? `SCASBR : `SCASWR) : (b ? `SCASB : `SCASW);
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1011_xxxx: // mov: i->r
+ begin
+ seq_addr <= op[3] ? `MOVIRW : `MOVIRB;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= op[3];
+
+ src <= 4\'b0;
+ dst <= { 1\'b0, op[2:0] };
+ end
+
+ 8\'b1100_000x: // ror/rol/rcr/rcl/sal/shl/sar/shr imm8/imm16
+ begin
+ seq_addr <= (mod==2\'b11) ? (b ? `RSHIRB : `RSHIRW)
+ : (b ? `RSHIMB : `RSHIMW);
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b0;
+ src <= rm;
+ dst <= rm;
+ end
+
+ 8\'b1100_0010: // ret near with value
+ begin
+ seq_addr <= `RETNV;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b1;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1100_0011: // ret near
+ begin
+ seq_addr <= `RETN0;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1100_0100: // les
+ begin
+ seq_addr <= `LES;
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= { 1\'b0, srcm };
+ dst <= 4\'b0;
+ end
+
+ 8\'b1100_0101: // lds
+ begin
+ seq_addr <= `LDS;
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= { 1\'b0, srcm };
+ dst <= 4\'b0;
+ end
+
+ 8\'b1100_011x: // mov: i->m (or i->r non-standard)
+ begin
+ seq_addr <= (mod==2\'b11) ? (b ? `MOVIRB : `MOVIRW)
+ : (b ? `MOVIMB : `MOVIMW);
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b1;
+ imm_size <= ~b;
+
+ src <= 4\'b0;
+ dst <= { 1\'b0, rm };
+ end
+
+ 8\'b1100_1000: // enter
+ begin
+ seq_addr <= `ENTER;
+ need_modrm <= 1\'b0;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1100_1001: // leave
+ begin
+ seq_addr <= `LEAVE;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1100_1010: // ret far with value
+ begin
+ seq_addr <= `RETFV;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b1;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1100_1011: // ret far
+ begin
+ seq_addr <= `RETF0;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1100_1100: // int 3
+ begin
+ seq_addr <= `INT3;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1100_1101: // int
+ begin
+ seq_addr <= `INT;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1100_1110: // into
+ begin
+ seq_addr <= `INTO;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1100_1111: // iret
+ begin
+ seq_addr <= `IRET;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1101_00xx: // sal/shl
+ begin
+ seq_addr <= (mod==2\'b11) ? (op[1] ? (b ? `RSHCRB : `RSHCRW)
+ : (b ? `RSH1RB : `RSH1RW))
+ : (op[1] ? (b ? `RSHCMB : `RSHCMW)
+ : (b ? `RSH1MB : `RSH1MW));
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= rm;
+ dst <= rm;
+ end
+
+ 8\'b1101_0100: // aam
+ begin
+ seq_addr <= `AAM;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1101_0101: // aad
+ begin
+ seq_addr <= `AAD;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1101_0111: // xlat
+ begin
+ seq_addr <= `XLAT;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1101_1xxx: // esc
+ begin
+ seq_addr <= (mod==2\'b11) ? `ESCRW : `ESCMW;
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= { 1\'b0, modrm[2:0] };
+ dst <= 4\'b0;
+ end
+
+ 8\'b1110_0000: // loopne
+ begin
+ seq_addr <= `LOOPNE;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1110_0001: // loope
+ begin
+ seq_addr <= `LOOPE;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1110_0010: // loop
+ begin
+ seq_addr <= `LOOP;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1110_0011: // jcxz
+ begin
+ seq_addr <= `JCXZ;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1110_010x: // in imm
+ begin
+ seq_addr <= b ? `INIB : `INIW;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1110_011x: // out imm
+ begin
+ seq_addr <= b ? `OUTIB : `OUTIW;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1110_1000: // call same segment
+ begin
+ seq_addr <= `CALLN;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b1;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1110_10x1: // jmp direct
+ begin
+ seq_addr <= `JMPI;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b1;
+ imm_size <= ~op[1];
+
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1110_1010: // jmp indirect different segment
+ begin
+ seq_addr <= `LJMPI;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b1;
+ need_imm <= 1\'b1;
+ imm_size <= 1\'b1;
+
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1110_110x: // in dx
+ begin
+ seq_addr <= b ? `INRB : `INRW;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1110_111x: // out dx
+ begin
+ seq_addr <= b ? `OUTRB : `OUTRW;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1111_0100: // hlt
+ begin
+ seq_addr <= `NOP; // hlt processing is in zet_core.v
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1111_0101: // cmc
+ begin
+ seq_addr <= `CMC;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1111_011x: // test, not, neg, mul, imul
+ begin
+ case (regm)
+ 3\'b000: seq_addr <= (mod==2\'b11) ?
+ (b ? `TSTIRB : `TSTIRW) : (b ? `TSTIMB : `TSTIMW);
+ 3\'b010: seq_addr <= (mod==2\'b11) ?
+ (b ? `NOTRB : `NOTRW) : (b ? `NOTMB : `NOTMW);
+ 3\'b011: seq_addr <= (mod==2\'b11) ?
+ (b ? `NEGRB : `NEGRW) : (b ? `NEGMB : `NEGMW);
+ 3\'b100: seq_addr <= (mod==2\'b11) ?
+ (b ? `MULRB : `MULRW) : (b ? `MULMB : `MULMW);
+ 3\'b101: seq_addr <= (mod==2\'b11) ?
+ (b ? `IMULRB : `IMULRW) : (b ? `IMULMB : `IMULMW);
+ 3\'b110: seq_addr <= (mod==2\'b11) ?
+ (b ? `DIVRB : `DIVRW) : (b ? `DIVMB : `DIVMW);
+ 3\'b111: seq_addr <= (mod==2\'b11) ?
+ (b ? `IDIVRB : `IDIVRW) : (b ? `IDIVMB : `IDIVMW);
+ default: seq_addr <= `INVOP;
+ endcase
+
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= (regm == 3\'b000); // imm on test
+ imm_size <= ~b;
+ dst <= { 1\'b0, modrm[2:0] };
+ src <= { 1\'b0, modrm[2:0] };
+ end
+
+ 8\'b1111_1000: // clc
+ begin
+ seq_addr <= `CLC;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1111_1001: // stc
+ begin
+ seq_addr <= `STC;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1111_1010: // cli
+ begin
+ seq_addr <= `CLI;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1111_1011: // sti
+ begin
+ seq_addr <= `STI;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1111_1100: // cld
+ begin
+ seq_addr <= `CLD;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1111_1101: // std
+ begin
+ seq_addr <= `STD;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ 8\'b1111_1110: // inc
+ begin
+ case (regm)
+ 3\'b000: seq_addr <= (mod==2\'b11) ? `INCRB : `INCMB;
+ 3\'b001: seq_addr <= (mod==2\'b11) ? `DECRB : `DECMB;
+ default: seq_addr <= `INVOP;
+ endcase
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+
+ src <= { 1\'b0, rm };
+ dst <= 4\'b0;
+ end
+
+ 8\'b1111_1111:
+ begin
+ case (regm)
+ 3\'b000: seq_addr <= (mod==2\'b11) ? `INCRW : `INCMW;
+ 3\'b001: seq_addr <= (mod==2\'b11) ? `DECRW : `DECMW;
+ 3\'b010: seq_addr <= (mod==2\'b11) ? `CALLNR : `CALLNM;
+ 3\'b011: seq_addr <= `CALLFM;
+ 3\'b100: seq_addr <= (mod==2\'b11) ? `JMPR : `JMPM;
+ 3\'b101: seq_addr <= `LJMPM;
+ 3\'b110: seq_addr <= (mod==2\'b11) ? `PUSHR : `PUSHM;
+ default: seq_addr <= `INVOP;
+ endcase
+ need_modrm <= 1\'b1;
+ need_off <= need_off_mod;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+
+ src <= { 1\'b0, rm };
+ dst <= 4\'b0;
+ end
+
+ default: // invalid opcode
+ begin
+ seq_addr <= `INVOP;
+ need_modrm <= 1\'b0;
+ need_off <= 1\'b0;
+ need_imm <= 1\'b0;
+ imm_size <= 1\'b0;
+ src <= 4\'b0;
+ dst <= 4\'b0;
+ end
+
+ endcase
+
+endmodule
+"
+"/////////////////////////////////////////////////////////////////////
+//// ////
+//// Non-restoring unsigned divider ////
+//// ////
+//// Author: Richard Herveille ////
+//// richard@asics.ws ////
+//// www.asics.ws ////
+//// ////
+/////////////////////////////////////////////////////////////////////
+//// ////
+//// Copyright (C) 2002 Richard Herveille ////
+//// richard@asics.ws ////
+//// ////
+//// This source file may be used and distributed without ////
+//// restriction provided that this copyright statement is not ////
+//// removed from the file and that any derivative work contains ////
+//// the original copyright notice and the associated disclaimer.////
+//// ////
+//// THIS SOFTWARE IS PROVIDED ``AS IS\'\' AND WITHOUT ANY ////
+//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
+//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
+//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
+//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
+//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
+//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
+//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
+//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
+//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
+//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
+//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
+//// POSSIBILITY OF SUCH DAMAGE. ////
+//// ////
+/////////////////////////////////////////////////////////////////////
+
+// CVS Log
+//
+// $Id: div_uu.v,v 1.3 2003/09/17 13:08:53 rherveille Exp $
+//
+// $Date: 2003/09/17 13:08:53 $
+// $Revision: 1.3 $
+// $Author: rherveille $
+// $Locker: $
+// $State: Exp $
+//
+// Change History:
+// $Log: div_uu.v,v $
+// Revision 1.3 2003/09/17 13:08:53 rherveille
+// Fixed a bug in the remainder output. Changed a hard value into the required parameter.
+// Fixed a bug in the testbench.
+//
+// Revision 1.2 2002/10/31 13:54:58 rherveille
+// Fixed a bug in the remainder output of div_su.v
+//
+// Revision 1.1.1.1 2002/10/29 20:29:10 rherveille
+//
+//
+//
+
+//synopsys translate_off
+`timescale 1ns/10ps
+//synopsys translate_on
+
+module zet_div_uu(clk, ena, z, d, q, s, div0, ovf);
+
+\t//
+\t// parameters
+\t//
+\tparameter z_width = 16;
+\tparameter d_width = z_width /2;
+\t
+\t//
+\t// inputs & outputs
+\t//
+\tinput clk; // system clock
+\tinput ena; // clock enable
+
+\tinput [z_width -1:0] z; // divident
+\tinput [d_width -1:0] d; // divisor
+\toutput [d_width -1:0] q; // quotient
+\toutput [d_width -1:0] s; // remainder
+\toutput div0;
+\toutput ovf;
+\treg [d_width-1:0] q;
+\treg [d_width-1:0] s;
+\treg div0;
+\treg ovf;
+
+\t//\t
+\t// functions
+\t//
+\tfunction [z_width:0] gen_s;
+\t\tinput [z_width:0] si;
+\t\tinput [z_width:0] di;
+\tbegin
+\t if(si[z_width])
+\t gen_s = {si[z_width-1:0], 1\'b0} + di;
+\t else
+\t gen_s = {si[z_width-1:0], 1\'b0} - di;
+\tend
+\tendfunction
+
+\tfunction [d_width-1:0] gen_q;
+\t\tinput [d_width-1:0] qi;
+\t\tinput [z_width:0] si;
+\tbegin
+\t gen_q = {qi[d_width-2:0], ~si[z_width]};
+\tend
+\tendfunction
+
+\tfunction [d_width-1:0] assign_s;
+\t\tinput [z_width:0] si;
+\t\tinput [z_width:0] di;
+\t\treg [z_width:0] tmp;
+\tbegin
+\t if(si[z_width])
+\t tmp = si + di;
+\t else
+\t tmp = si;
+
+\t assign_s = tmp[z_width-1:z_width-d_width];
+\tend
+\tendfunction
+
+\t//
+\t// variables
+\t//
+\treg [d_width-1:0] q_pipe [d_width-1:0];
+\treg [z_width:0] s_pipe [d_width:0];
+\treg [z_width:0] d_pipe [d_width:0];
+
+\treg [d_width:0] div0_pipe, ovf_pipe;
+\t//
+\t// perform parameter checks
+\t//
+\t// synopsys translate_off
+\tinitial
+\tbegin
+\t if(d_width !== z_width / 2)
+\t $display(""div.v parameter error (d_width != z_width/2)."");
+\tend
+\t// synopsys translate_on
+
+\tinteger n0, n1, n2, n3;
+
+\t// generate divisor (d) pipe
+\talways @(d)
+\t d_pipe[0] <= {1\'b0, d, {(z_width-d_width){1\'b0}} };
+
+\talways @(posedge clk)
+\t if(ena)
+\t for(n0=1; n0 <= d_width; n0=n0+1)
+\t d_pipe[n0] <= d_pipe[n0-1];
+
+\t// generate internal remainder pipe
+\talways @(z)
+\t s_pipe[0] <= z;
+
+\talways @(posedge clk)
+\t if(ena)
+\t for(n1=1; n1 <= d_width; n1=n1+1)
+\t s_pipe[n1] <= gen_s(s_pipe[n1-1], d_pipe[n1-1]);
+
+\t// generate quotient pipe
+\talways @(posedge clk)
+\t q_pipe[0] <= 0;
+
+\talways @(posedge clk)
+\t if(ena)
+\t for(n2=1; n2 < d_width; n2=n2+1)
+\t q_pipe[n2] <= gen_q(q_pipe[n2-1], s_pipe[n2]);
+
+
+\t// flags (divide_by_zero, overflow)
+\talways @(z or d)
+\tbegin
+\t ovf_pipe[0] <= !(z[z_width-1:d_width] < d);
+\t div0_pipe[0] <= ~|d;
+\tend
+
+\talways @(posedge clk)
+\t if(ena)
+\t for(n3=1; n3 <= d_width; n3=n3+1)
+\t begin
+\t ovf_pipe[n3] <= ovf_pipe[n3-1];
+\t div0_pipe[n3] <= div0_pipe[n3-1];
+\t end
+
+\t// assign outputs
+\talways @(posedge clk)
+\t if(ena)
+\t ovf <= ovf_pipe[d_width];
+
+\talways @(posedge clk)
+\t if(ena)
+\t div0 <= div0_pipe[d_width];
+
+\talways @(posedge clk)
+\t if(ena)
+\t q <= gen_q(q_pipe[d_width-1], s_pipe[d_width]);
+
+\talways @(posedge clk)
+\t if(ena)
+\t s <= assign_s(s_pipe[d_width], d_pipe[d_width]);
+endmodule
+
+
+
+"
+"/*
+ * Fetch & Decode module for Zet
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`timescale 1ns/10ps
+
+`include ""defines.v""
+
+module zet_fetch (
+ input clk,
+ input rst,
+
+ // to decode
+ output [7:0] opcode,
+ output [7:0] modrm,
+ output rep,
+ output exec_st,
+ output ld_base,
+ output reg [2:0] sop_l,
+
+ // from decode
+ input need_modrm,
+ input need_off,
+ input need_imm,
+ input off_size,
+ input imm_size,
+ input ext_int,
+ input end_seq,
+
+ // to microcode
+ output reg [15:0] off_l,
+ output reg [15:0] imm_l,
+
+ // from microcode
+ input [5:0] ftype,
+
+ // to exec
+ output [15:0] imm_f,
+
+ input [15:0] cs,
+ input [15:0] ip,
+ input of,
+ input zf,
+ input cx_zero,
+ input [15:0] data,
+ output [19:0] pc,
+ output bytefetch,
+ input block,
+ input div_exc,
+ input tflm,
+ output wr_ip0,
+ input intr,
+ input iflm,
+ input nmir,
+ input iflss
+ );
+
+ // Registers, nets and parameters
+ parameter opcod_st = 3\'h0;
+ parameter modrm_st = 3\'h1;
+ parameter offse_st = 3\'h2;
+ parameter immed_st = 3\'h3;
+ parameter execu_st = 3\'h4;
+
+ reg [2:0] state;
+ wire [2:0] next_state;
+
+ wire prefix, repz_pr, sovr_pr, lock_pr;
+ wire next_in_opco, next_in_exec;
+
+ reg [7:0] opcode_l, modrm_l;
+ reg [1:0] pref_l;
+ reg lock_l;
+
+ // Module instantiation
+ zet_next_or_not next_or_not(pref_l, opcode[7:1], cx_zero, zf, ext_int, next_in_opco,
+ next_in_exec);
+ zet_nstate nstate (state, prefix, need_modrm, need_off, need_imm, end_seq,
+ ftype, of, next_in_opco, next_in_exec, block, div_exc,
+ tflm, intr, iflm, nmir, iflss, next_state);
+
+ // Assignments
+ assign pc = (cs << 4) + ip;
+
+ assign opcode = (state == opcod_st) ? data[7:0] : opcode_l;
+ assign modrm = (state == modrm_st) ? data[7:0] : modrm_l;
+ assign bytefetch = (state == offse_st) ? ~off_size
+ : ((state == immed_st) ? ~imm_size : 1\'b1);
+ assign exec_st = (state == execu_st);
+ assign imm_f = ((state == offse_st) & off_size
+ | (state == immed_st) & imm_size) ? 16\'d2
+ : 16\'d1;
+ assign wr_ip0 = (state == opcod_st) && !pref_l[1] && !sop_l[2] && !lock_l;
+
+ assign sovr_pr = (opcode[7:5]==3\'b001 && opcode[2:0]==3\'b110);
+ assign repz_pr = (opcode[7:1]==7\'b1111_001);
+ assign lock_pr = (opcode[7:0]==8\'b1111_0000);
+ assign prefix = sovr_pr || repz_pr || lock_pr;
+ assign ld_base = (next_state == execu_st);
+ assign rep = pref_l[1];
+
+ // Behaviour
+ always @(posedge clk)
+ if (rst)
+ begin
+ state <= execu_st;
+ opcode_l <= `OP_NOP;
+ end
+ else if (!block)
+ case (next_state)
+ default: // opcode or prefix
+ begin
+ case (state)
+ opcod_st:
+ begin // There has been a prefix
+ pref_l <= repz_pr ? { 1\'b1, opcode[0] }
+ // clear prefixes on next instr
+ : next_in_opco ? 2\'b0 : pref_l;
+ sop_l <= sovr_pr ? { 1\'b1, opcode[4:3] }
+ // clear prefixes on next instr
+ : next_in_opco ? 3\'b0 : sop_l;
+ lock_l <= lock_pr ? 1\'b1
+ // clear prefixes on next instr
+ : next_in_opco ? 1\'b0 : lock_l;
+ end
+ default: begin pref_l <= 2\'b0; sop_l <= 3\'b0; lock_l <= 1\'b0; end
+ endcase
+ state <= opcod_st;
+ off_l <= 16\'d0;
+ modrm_l <= 8\'b0000_0110;
+ end
+
+ modrm_st: // modrm
+ begin
+ opcode_l <= data[7:0];
+ state <= modrm_st;
+ end
+
+ offse_st: // offset
+ begin
+ case (state)
+ opcod_st: opcode_l <= data[7:0];
+ default: modrm_l <= data[7:0];
+ endcase
+ state <= offse_st;
+ end
+
+ immed_st: // immediate
+ begin
+ case (state)
+ opcod_st: opcode_l <= data[7:0];
+ modrm_st: modrm_l <= data[7:0];
+ default: off_l <= data;
+ endcase
+ state <= immed_st;
+ end
+
+ execu_st: // execute
+ begin
+ case (state)
+ opcod_st: opcode_l <= data[7:0];
+ modrm_st: modrm_l <= data[7:0];
+ offse_st: off_l <= data;
+ immed_st: imm_l <= data;
+ endcase
+ state <= execu_st;
+ end
+ endcase
+endmodule
+"
+"/*
+ * PC speaker module without any codec
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module speaker (
+ // Clocks
+ input clk,
+ input rst,
+
+ // Wishbone slave interface
+ input [7:0] wb_dat_i,
+ output reg [7:0] wb_dat_o,
+ input wb_we_i,
+ input wb_stb_i,
+ input wb_cyc_i,
+ output wb_ack_o,
+
+ // Timer clock
+ input timer2,
+
+ // Speaker pad signal
+ output speaker_
+ );
+
+ // Net declarations
+ wire write;
+ wire spk;
+
+ // Combinatorial logic
+ // System speaker
+ assign speaker_ = timer2 & wb_dat_o[1];
+
+ // Wishbone signals
+ assign wb_ack_o = wb_stb_i && wb_cyc_i;
+ assign write = wb_stb_i && wb_cyc_i && wb_we_i;
+
+ // Sequential logic
+ always @(posedge clk)
+ wb_dat_o <= rst ? 8'h0 : (write ? wb_dat_i : wb_dat_o);
+
+endmodule
+"
+"/*
+ * Zet processor core
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`include ""defines.v""
+
+module zet_core (
+ input clk,
+ input rst,
+
+ // interrupts
+ input intr,
+ output inta,
+ input nmi,
+ output nmia,
+
+ // interface to wishbone
+ output [19:0] cpu_adr_o,
+ input [15:0] iid_dat_i,
+ input [15:0] cpu_dat_i,
+ output [15:0] cpu_dat_o,
+ output cpu_byte_o,
+ input cpu_block,
+ output cpu_mem_op,
+ output cpu_m_io,
+ output cpu_we_o,
+
+ output [19:0] pc // for debugging purposes
+ );
+
+ // Net declarations
+ wire [`IR_SIZE-1:0] ir;
+ wire [15:0] off;
+ wire [15:0] imm;
+ wire wr_ip0;
+
+ wire [15:0] cs;
+ wire [15:0] ip;
+ wire of;
+ wire zf;
+ wire ifl;
+ wire iflm;
+ wire tfl;
+ wire tflm;
+ wire iflss;
+ wire wr_ss;
+ wire cx_zero;
+ wire div_exc;
+
+ wire [19:0] addr_exec;
+ wire byte_fetch;
+ wire byte_exec;
+
+ // wire decode - microcode
+ wire [`MICRO_ADDR_WIDTH-1:0] seq_addr;
+ wire [3:0] src;
+ wire [3:0] dst;
+ wire [3:0] base;
+ wire [3:0] index;
+ wire [1:0] seg;
+ wire end_seq;
+ wire [2:0] fdec;
+ wire div;
+
+ // wires fetch - decode
+ wire [7:0] opcode;
+ wire [7:0] modrm;
+ wire rep;
+ wire exec_st;
+ wire ld_base;
+ wire [2:0] sop_l;
+
+ wire need_modrm;
+ wire need_off;
+ wire need_imm;
+ wire off_size;
+ wire imm_size;
+ wire ext_int;
+
+ // wires fetch - microcode
+ wire [15:0] off_l;
+ wire [15:0] imm_l;
+ wire [15:0] imm_d;
+ wire [`IR_SIZE-1:0] rom_ir;
+ wire [5:0] ftype;
+
+ // wires fetch - exec
+ wire [15:0] imm_f;
+
+ // wires and regs for hlt
+ wire block_or_hlt;
+ wire hlt_op;
+ wire hlt_in;
+ wire hlt_out;
+
+ reg hlt_op_old;
+ reg hlt;
+
+ // regs for nmi
+ reg nmir;
+ reg nmi_old;
+ reg nmia_old;
+
+ // Module instantiations
+ zet_fetch fetch (
+ .clk (clk),
+ .rst (rst),
+
+ // to decode
+ .opcode (opcode),
+ .modrm (modrm),
+ .rep (rep),
+ .exec_st (exec_st),
+ .ld_base (ld_base),
+ .sop_l (sop_l),
+
+ // from decode
+ .need_modrm (need_modrm),
+ .need_off (need_off),
+ .need_imm (need_imm),
+ .off_size (off_size),
+ .imm_size (imm_size),
+ .ext_int (ext_int),
+ .end_seq (end_seq),
+
+ // to microcode
+ .off_l (off_l),
+ .imm_l (imm_l),
+
+ // from microcode
+ .ftype (ftype),
+
+ // to exec
+ .imm_f (imm_f),
+ .wr_ip0 (wr_ip0),
+
+ // from exec
+ .cs (cs),
+ .ip (ip),
+ .of (of),
+ .zf (zf),
+ .iflm (iflm),
+ .tflm (tflm),
+ .iflss (iflss),
+ .cx_zero (cx_zero),
+ .div_exc (div_exc),
+
+ // to wb
+ .data (cpu_dat_i),
+ .pc (pc),
+ .bytefetch (byte_fetch),
+ .block (block_or_hlt),
+ .intr (intr),
+ .nmir (nmir)
+ );
+
+ zet_decode decode (
+ .clk (clk),
+ .rst (rst),
+
+ .opcode (opcode),
+ .modrm (modrm),
+ .rep (rep),
+ .block (block_or_hlt),
+ .exec_st (exec_st),
+ .div_exc (div_exc),
+ .ld_base (ld_base),
+ .div (div),
+ .tfl (tfl),
+ .tflm (tflm),
+
+ .need_modrm (need_modrm),
+ .need_off (need_off),
+ .need_imm (need_imm),
+ .off_size (off_size),
+ .imm_size (imm_size),
+
+ .sop_l (sop_l),
+ .intr (intr),
+ .ifl (ifl),
+ .iflm (iflm),
+ .inta (inta),
+ .ext_int (ext_int),
+ .nmir (nmir),
+ .nmia (nmia),
+ .wr_ss (wr_ss),
+ .iflss (iflss),
+
+ .seq_addr (seq_addr),
+ .src (src),
+ .dst (dst),
+ .base (base),
+ .index (index),
+ .seg (seg),
+ .f (fdec),
+
+ .end_seq (end_seq)
+ );
+
+ zet_micro_data micro_data (
+ // from decode
+ .n_micro (seq_addr),
+ .off_i (off_l),
+ .imm_i (imm_l),
+ .src (src),
+ .dst (dst),
+ .base (base),
+ .index (index),
+ .seg (seg),
+ .fdec (fdec),
+ .div (div),
+ .end_seq (end_seq),
+
+ // to exec
+ .ir (rom_ir),
+ .off_o (off),
+ .imm_o (imm_d)
+ );
+
+ zet_exec exec (
+ .clk (clk),
+ .rst (rst),
+
+ // from fetch
+ .ir (ir),
+ .off (off),
+ .imm (imm),
+ .wrip0 (wr_ip0),
+
+ // to fetch
+ .cs (cs),
+ .ip (ip),
+ .of (of),
+ .zf (zf),
+ .ifl (ifl),
+ .tfl (tfl),
+ .cx_zero (cx_zero),
+ .div_exc (div_exc),
+
+ .wr_ss (wr_ss),
+
+ // from wb
+ .memout (iid_dat_i),
+ .wr_data (cpu_dat_o),
+ .addr (addr_exec),
+ .we (cpu_we_o),
+ .m_io (cpu_m_io),
+ .byteop (byte_exec),
+ .block (block_or_hlt)
+ );
+
+ // Assignments
+ assign cpu_adr_o = exec_st ? addr_exec : pc;
+ assign cpu_byte_o = exec_st ? byte_exec : byte_fetch;
+ assign cpu_mem_op = ir[`MEM_OP];
+
+ assign ir = exec_st ? rom_ir : `ADD_IP;
+ assign imm = exec_st ? imm_d : imm_f;
+ assign ftype = rom_ir[28:23];
+
+ assign hlt_op = ((opcode == `OP_HLT) && exec_st);
+ assign hlt_in = (hlt_op && !hlt_op_old && !hlt_out);
+ assign hlt_out = (intr & ifl) | nmir;
+ assign block_or_hlt = cpu_block | hlt | hlt_in;
+
+ // Behaviour
+ always @(posedge clk)
+ if (rst)
+ hlt_op_old <= 1\'b0;
+ else
+ if (hlt_op)
+ hlt_op_old <= 1\'b1;
+ else
+ hlt_op_old <= 1\'b0;
+
+ always @(posedge clk)
+ if (rst)
+ hlt <= 1\'b0;
+ else
+ if (hlt_in)
+ hlt <= 1\'b1;
+ else if (hlt_out)
+ hlt <= 1\'b0;
+
+ always @(posedge clk)
+ if (rst)
+ begin
+ nmir <= 1\'b0;
+ nmi_old <= 1\'b0;
+ nmia_old <= 1\'b0;
+ end
+ else
+ begin
+ nmi_old <= nmi;
+ nmia_old <= nmia;
+ if (nmi & ~nmi_old)
+ nmir <= 1\'b1;
+ else if (nmia_old)
+ nmir <= 1\'b0;
+ end
+
+endmodule
+"
+"/*\r
+ * Text mode graphics for VGA\r
+ * Copyright (C) 2010 Zeus Gomez Marmolejo \r
+ *\r
+ * VGA FML support\r
+ * Copyright (C) 2013 Charley Picker \r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+/*\r
+ * Pipeline description\r
+ * h_count[3:0]\r
+ * 000\r
+ * 001 col_addr, row_addr\r
+ * 010 ver_addr, hor_addr\r
+ * 011 csr_adr_o\r
+ * 100 csr_adr_i\r
+ * 101 sram_addr_\r
+ * 110 csr_dat_o\r
+ * 111 char_data_out, attr_data_out\r
+ * 000 vga_shift\r
+ * 001 vga_blue_o <= vga_shift[7]\r
+ */\r
+\r
+module vga_text_mode_fml (\r
+ input clk,\r
+ input rst,\r
+ \r
+ input enable,\r
+\r
+ // CSR slave interface for reading\r
+ output reg [16:1] fml_adr_o,\r
+ input [15:0] fml_dat_i,\r
+ output fml_stb_o,\r
+\r
+ input [9:0] h_count,\r
+ input [9:0] v_count,\r
+ input horiz_sync_i,\r
+ input video_on_h_i,\r
+ output video_on_h_o,\r
+\r
+ // CRTC\r
+ input [5:0] cur_start,\r
+ input [5:0] cur_end,\r
+ input [4:0] vcursor,\r
+ input [6:0] hcursor,\r
+\r
+ output reg [3:0] attr,\r
+ output horiz_sync_o\r
+ );\r
+\r
+ // Registers and nets\r
+ reg [ 6:0] col_addr;\r
+ reg [ 4:0] row_addr;\r
+ reg [ 6:0] hor_addr;\r
+ reg [ 6:0] ver_addr;\r
+ wire [10:0] vga_addr;\r
+\r
+ reg [ 15:0] fml1_dat;\r
+\r
+ wire [11:0] char_addr;\r
+ wire [ 7:0] char_data_out;\r
+ reg [ 7:0] attr_data_out;\r
+ reg [ 7:0] char_addr_in;\r
+\r
+ reg [15:0] pipe;\r
+ wire load_shift;\r
+\r
+ reg [7:0] video_on_h;\r
+ reg [7:0] horiz_sync;\r
+\r
+ wire fg_or_bg;\r
+ wire brown_bg;\r
+ wire brown_fg;\r
+\r
+ reg [ 7:0] vga_shift;\r
+ reg [ 3:0] fg_colour;\r
+ reg [ 2:0] bg_colour;\r
+ reg [22:0] blink_count;\r
+\r
+ // Cursor\r
+ reg cursor_on_v;\r
+ reg cursor_on_h;\r
+ reg cursor_on;\r
+ wire cursor_on1;\r
+\r
+ // Module instances\r
+ vga_char_rom char_rom (\r
+ .clk (clk),\r
+ .addr (char_addr),\r
+ .q (char_data_out)\r
+ );\r
+\r
+ // Continuous assignments\r
+ assign vga_addr = { 4'b0, hor_addr } + { ver_addr, 4'b0 };\r
+ assign char_addr = { char_addr_in, v_count[3:0] };\r
+ assign load_shift = pipe[7] | pipe[15];\r
+ assign video_on_h_o = video_on_h[7];\r
+ assign horiz_sync_o = horiz_sync[7];\r
+ assign fml_stb_o = pipe[2];\r
+\r
+ assign fg_or_bg = vga_shift[7] ^ cursor_on;\r
+\r
+ assign cursor_on1 = cursor_on_h && cursor_on_v;\r
+\r
+ // Behaviour\r
+ // Address generation\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ col_addr <= 7'h0;\r
+ row_addr <= 5'h0;\r
+ ver_addr <= 7'h0;\r
+ hor_addr <= 7'h0;\r
+ fml_adr_o <= 16'h0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ // h_count[2:0] == 001\r
+ col_addr <= h_count[9:3];\r
+ row_addr <= v_count[8:4];\r
+\r
+ // h_count[2:0] == 010\r
+ ver_addr <= { 2'b00, row_addr } + { row_addr, 2'b00 };\r
+ // ver_addr = row_addr x 5\r
+ hor_addr <= col_addr;\r
+\r
+ // h_count[2:0] == 011\r
+ // vga_addr = row_addr * 80 + hor_addr\r
+ fml_adr_o <= { 3'h0, vga_addr, 2'b00 };\r
+ end\r
+\r
+ // cursor\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ cursor_on_v <= 1'b0;\r
+ cursor_on_h <= 1'b0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ cursor_on_h <= (h_count[9:3] == hcursor[6:0]);\r
+ cursor_on_v <= (v_count[8:4] == vcursor[4:0])\r
+ && ({2'b00, v_count[3:0]} >= cur_start)\r
+ && ({2'b00, v_count[3:0]} <= cur_end);\r
+ end\r
+\r
+ // FML 8x16 pipeline count\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ pipe <= 15'b0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ pipe <= { pipe[14:0], (h_count[3:0]==3'b0) };\r
+ end\r
+\r
+ // Load FML 8x16 burst\r
+ always @(posedge clk)\r
+ if (enable)\r
+ begin\r
+ fml1_dat <= pipe[9] ? fml_dat_i[15:0] : fml1_dat;\r
+ end\r
+\r
+ // attr_data_out\r
+ always @(posedge clk)\r
+ if (enable)\r
+ begin\r
+ if (pipe[5])\r
+ attr_data_out <= fml_dat_i[15:8];\r
+ else\r
+ if (pipe[13])\r
+ attr_data_out <= fml1_dat[15:8];\r
+ end\r
+\r
+ // char_addr_in\r
+ always @(posedge clk)\r
+ if (enable)\r
+ begin\r
+ if (pipe[5])\r
+ char_addr_in <= fml_dat_i[7:0];\r
+ else\r
+ if (pipe[13])\r
+ char_addr_in <= fml1_dat[7:0];\r
+ end\r
+\r
+ // video_on_h\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ video_on_h <= 8'b0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ video_on_h <= { video_on_h[6:0], video_on_h_i };\r
+ end\r
+\r
+ // horiz_sync\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ horiz_sync <= 8'b0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ horiz_sync <= { horiz_sync[6:0], horiz_sync_i };\r
+ end\r
+\r
+ // blink_count\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ blink_count <= 23'h0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ blink_count <= (blink_count + 23'h1);\r
+ end\r
+\r
+ // Video shift register\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ fg_colour <= 4'b0;\r
+ bg_colour <= 3'b0;\r
+ vga_shift <= 8'h0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ if (load_shift)\r
+ begin\r
+ fg_colour <= attr_data_out[3:0];\r
+ bg_colour <= attr_data_out[6:4];\r
+ cursor_on <= (cursor_on1 | attr_data_out[7]) & blink_count[22];\r
+ vga_shift <= char_data_out;\r
+ end\r
+ else vga_shift <= { vga_shift[6:0], 1'b0 };\r
+ end\r
+\r
+ // pixel attribute\r
+ always @(posedge clk)\r
+ if (rst)\r
+ begin\r
+ attr <= 4'h0;\r
+ end\r
+ else\r
+ if (enable)\r
+ begin\r
+ attr <= fg_or_bg ? fg_colour : { 1'b0, bg_colour };\r
+ end\r
+\r
+endmodule\r
+"
+"/*
+ * DE1/DE2 Audio Interface (WM8731 audio chip)
+ * Copyright (c) 2010 YS
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+/*
+ * - aud_xck should be generated and sent to audio chip externally
+ * - Setup in I2C_AV_Config.v:
+ * SET_FORMAT: 16'h0E42 (Slave / I2S / 16 bit)
+ * - aud_xck = 11.2896 MHz
+ * MCLK = aud_xck = 11.2896 MHz
+ * SAMPLE_CTRL: 16'h1020 (fs=44.1kHz / MCLK=256fs)
+ * - aud_xck = 5.6448 MHz
+ * MCLK = aud_xck = 5.6448 MHz
+ * SAMPLE_CTRL: 16'h103C (fs=44.1kHz / MCLK=128fs)
+ * - aud_xck = 11.2896 MHz
+ * MCLK = aud_xck/2 = 5.6448 MHz
+ * SAMPLE_CTRL: 16'h107C (fs=44.1kHz / MCLK=128fs)
+ * - clk_i should be much faster than aud_bclk_i
+ * - suppose in slave mode aud_daclrck_i == aud_adclrck_i, otherwise
+ * aud_adclrck_i may need separate processing and ready_o should
+ * be splitted into readydac_o and readyadc_o
+ * - ADC part is not tested
+ */
+
+module speaker_iface
+ (
+ // Main system interface
+ input clk_i,
+ input rst_i,
+ input signed [15:0] datal_i,
+ input signed [15:0] datar_i,
+ output reg signed [15:0] datal_o,
+ output reg signed [15:0] datar_o,
+
+ output reg ready_o,
+// output reg readydac_o, // not used
+// output reg readyadc_o, // not used
+
+ // Audio interface
+ input aud_bclk_i,
+ input aud_daclrck_i,
+ output reg aud_dacdat_o,
+ input aud_adcdat_i
+ );
+
+ reg fBCLK_HL;
+// reg fBCLK_LH;
+ reg bCurrentClk;
+ reg bFilterClk1;
+ reg bFilterClk2;
+
+ reg bDACLRCK_old;
+ reg bDACLRCK;
+
+ reg [15:0] rDAC;
+ reg [15:0] rADC;
+
+ reg fADCReady;
+
+ // Synchronizing BCLK with clk_i
+ always @(posedge clk_i or posedge rst_i)
+ begin
+ if (rst_i)
+ begin
+ fBCLK_HL <= 1'b0;
+// fBCLK_LH <= 1'b0;
+ bCurrentClk <= 1'b0;
+ bFilterClk1 <= 1'b0;
+ bFilterClk2 <= 1'b0;
+ end
+ else
+ begin
+ bFilterClk1 <= aud_bclk_i;
+ bFilterClk2 <= bFilterClk1;
+ if ((bFilterClk1 == bFilterClk2) && (bCurrentClk != bFilterClk2))
+ begin
+ bCurrentClk <= bFilterClk2;
+ if (bCurrentClk == 1'b1)
+ fBCLK_HL <= 1'b1; // falling edge of aud_bclk_i
+// else
+// fBCLK_LH <= 1'b1; // rising edge of aud_bclk_i
+ end
+ if (fBCLK_HL)
+ fBCLK_HL <= 1'b0; // 1 clock pulse fBCLK_HL
+// if (fBCLK_LH)
+// fBCLK_LH <= 1'b0; // 1 clock pulse fBCLK_LH
+ end
+ end
+
+ // Filtering aud_daclrck_i
+ always @(posedge clk_i)
+ bDACLRCK <= aud_daclrck_i;
+
+ // Processsing BCLK
+ always @(posedge clk_i)
+ begin
+ if (fBCLK_HL)
+ begin
+ bDACLRCK_old <= bDACLRCK;
+ if (bDACLRCK != bDACLRCK_old)
+ begin
+ // DAC write
+ rDAC <= (bDACLRCK) ? datar_i : datal_i;
+ aud_dacdat_o <= 1'b0;
+ // ADC read
+ if (bDACLRCK)
+ datal_o <= rADC;
+ else
+ datar_o <= rADC;
+ rADC <= 16'h0001;
+ fADCReady <= 1'b0;
+ // ready pulse
+ ready_o <= ~bDACLRCK;
+ end
+ else
+ begin
+ //DAC shift
+ { aud_dacdat_o, rDAC } <= { rDAC, 1'b0 };
+ // ADC shift
+ if (!fADCReady)
+ { fADCReady, rADC} <= { rADC, aud_adcdat_i };
+ end
+ end
+ else if (ready_o)
+ ready_o <= 1'b0; // 1 clock ready_o pulse
+ end
+
+endmodule"
+"/*
+ * Milkymist VJ SoC
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * adjusted to FML 8x16 by Zeus Gomez Marmolejo
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/* Simple FML interface for HPDMC */
+
+module hpdmc_busif #(
+\tparameter sdram_depth = 23
+) (
+\tinput sys_clk,
+\tinput sdram_rst,
+\t
+\tinput [sdram_depth-1:0] fml_adr,
+\tinput fml_stb,
+\tinput fml_we,
+\toutput fml_ack,
+\t
+\toutput mgmt_stb,
+\toutput mgmt_we,
+\toutput [sdram_depth-1-1:0] mgmt_address, /* in 16-bit words */
+\tinput mgmt_ack,
+\t
+\tinput data_ack
+);
+
+reg mgmt_stb_en;
+
+assign mgmt_stb = fml_stb & mgmt_stb_en;
+assign mgmt_we = fml_we;
+assign mgmt_address = fml_adr[sdram_depth-1:1];
+
+assign fml_ack = data_ack;
+
+always @(posedge sys_clk) begin
+\tif(sdram_rst)
+\t\tmgmt_stb_en = 1'b1;
+\telse begin
+\t\tif(mgmt_ack)
+\t\t\tmgmt_stb_en = 1'b0;
+\t\tif(data_ack)
+\t\t\tmgmt_stb_en = 1'b1;
+\tend
+end
+
+endmodule
+"
+"/*
+ * VGA top level file
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vga (
+ // Wishbone signals
+ input wb_clk_i, // 25 Mhz VDU clock
+ input wb_rst_i,
+ input [15:0] wb_dat_i,
+ output [15:0] wb_dat_o,
+ input [16:1] wb_adr_i,
+ input wb_we_i,
+ input wb_tga_i,
+ input [ 1:0] wb_sel_i,
+ input wb_stb_i,
+ input wb_cyc_i,
+ output wb_ack_o,
+
+ // VGA pad signals
+ output [ 3:0] vga_red_o,
+ output [ 3:0] vga_green_o,
+ output [ 3:0] vga_blue_o,
+ output horiz_sync,
+ output vert_sync,
+
+ // CSR SRAM master interface
+ output [17:1] csrm_adr_o,
+ output [ 1:0] csrm_sel_o,
+ output csrm_we_o,
+ output [15:0] csrm_dat_o,
+ input [15:0] csrm_dat_i
+ );
+
+
+ // Registers and nets
+ //
+ // csr address
+ reg [17:1] csr_adr_i;
+ reg csr_stb_i;
+
+ // Config wires
+ wire [15:0] conf_wb_dat_o;
+ wire conf_wb_ack_o;
+
+ // Mem wires
+ wire [15:0] mem_wb_dat_o;
+ wire mem_wb_ack_o;
+
+ // LCD wires
+ wire [17:1] csr_adr_o;
+ wire [15:0] csr_dat_i;
+ wire csr_stb_o;
+ wire v_retrace;
+ wire vh_retrace;
+ wire w_vert_sync;
+
+ // VGA configuration registers
+ wire shift_reg1;
+ wire graphics_alpha;
+ wire memory_mapping1;
+ wire [ 1:0] write_mode;
+ wire [ 1:0] raster_op;
+ wire read_mode;
+ wire [ 7:0] bitmask;
+ wire [ 3:0] set_reset;
+ wire [ 3:0] enable_set_reset;
+ wire [ 3:0] map_mask;
+ wire x_dotclockdiv2;
+ wire chain_four;
+ wire [ 1:0] read_map_select;
+ wire [ 3:0] color_compare;
+ wire [ 3:0] color_dont_care;
+
+ // Wishbone master to SRAM
+ wire [17:1] wbm_adr_o;
+ wire [ 1:0] wbm_sel_o;
+ wire wbm_we_o;
+ wire [15:0] wbm_dat_o;
+ wire [15:0] wbm_dat_i;
+ wire wbm_stb_o;
+ wire wbm_ack_i;
+
+ wire stb;
+
+ // CRT wires
+ wire [ 5:0] cur_start;
+ wire [ 5:0] cur_end;
+ wire [15:0] start_addr;
+ wire [ 4:0] vcursor;
+ wire [ 6:0] hcursor;
+ wire [ 6:0] horiz_total;
+ wire [ 6:0] end_horiz;
+ wire [ 6:0] st_hor_retr;
+ wire [ 4:0] end_hor_retr;
+ wire [ 9:0] vert_total;
+ wire [ 9:0] end_vert;
+ wire [ 9:0] st_ver_retr;
+ wire [ 3:0] end_ver_retr;
+
+ // attribute_ctrl wires
+ wire [3:0] pal_addr;
+ wire pal_we;
+ wire [7:0] pal_read;
+ wire [7:0] pal_write;
+
+ // dac_regs wires
+ wire dac_we;
+ wire [1:0] dac_read_data_cycle;
+ wire [7:0] dac_read_data_register;
+ wire [3:0] dac_read_data;
+ wire [1:0] dac_write_data_cycle;
+ wire [7:0] dac_write_data_register;
+ wire [3:0] dac_write_data;
+
+ // Module instances
+ //
+ vga_config_iface config_iface (
+ .wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+ .wb_dat_i (wb_dat_i),
+ .wb_dat_o (conf_wb_dat_o),
+ .wb_adr_i (wb_adr_i[4:1]),
+ .wb_we_i (wb_we_i),
+ .wb_sel_i (wb_sel_i),
+ .wb_stb_i (stb & wb_tga_i),
+ .wb_ack_o (conf_wb_ack_o),
+
+ .shift_reg1 (shift_reg1),
+ .graphics_alpha (graphics_alpha),
+ .memory_mapping1 (memory_mapping1),
+ .write_mode (write_mode),
+ .raster_op (raster_op),
+ .read_mode (read_mode),
+ .bitmask (bitmask),
+ .set_reset (set_reset),
+ .enable_set_reset (enable_set_reset),
+ .map_mask (map_mask),
+ .x_dotclockdiv2 (x_dotclockdiv2),
+ .chain_four (chain_four),
+ .read_map_select (read_map_select),
+ .color_compare (color_compare),
+ .color_dont_care (color_dont_care),
+
+ .pal_addr (pal_addr),
+ .pal_we (pal_we),
+ .pal_read (pal_read),
+ .pal_write (pal_write),
+
+ .dac_we (dac_we),
+ .dac_read_data_cycle (dac_read_data_cycle),
+ .dac_read_data_register (dac_read_data_register),
+ .dac_read_data (dac_read_data),
+ .dac_write_data_cycle (dac_write_data_cycle),
+ .dac_write_data_register (dac_write_data_register),
+ .dac_write_data (dac_write_data),
+
+ .cur_start (cur_start),
+ .cur_end (cur_end),
+ .start_addr (start_addr),
+ .vcursor (vcursor),
+ .hcursor (hcursor),
+
+ .horiz_total (horiz_total),
+ .end_horiz (end_horiz),
+ .st_hor_retr (st_hor_retr),
+ .end_hor_retr (end_hor_retr),
+ .vert_total (vert_total),
+ .end_vert (end_vert),
+ .st_ver_retr (st_ver_retr),
+ .end_ver_retr (end_ver_retr),
+
+ .v_retrace (v_retrace),
+ .vh_retrace (vh_retrace)
+ );
+
+ vga_lcd lcd (
+ .clk (wb_clk_i),
+ .rst (wb_rst_i),
+
+ .shift_reg1 (shift_reg1),
+ .graphics_alpha (graphics_alpha),
+
+ .pal_addr (pal_addr),
+ .pal_we (pal_we),
+ .pal_read (pal_read),
+ .pal_write (pal_write),
+
+ .dac_we (dac_we),
+ .dac_read_data_cycle (dac_read_data_cycle),
+ .dac_read_data_register (dac_read_data_register),
+ .dac_read_data (dac_read_data),
+ .dac_write_data_cycle (dac_write_data_cycle),
+ .dac_write_data_register (dac_write_data_register),
+ .dac_write_data (dac_write_data),
+
+ .csr_adr_o (csr_adr_o),
+ .csr_dat_i (csr_dat_i),
+ .csr_stb_o (csr_stb_o),
+
+ .vga_red_o (vga_red_o),
+ .vga_green_o (vga_green_o),
+ .vga_blue_o (vga_blue_o),
+ .horiz_sync (horiz_sync),
+ .vert_sync (w_vert_sync),
+
+ .cur_start (cur_start),
+ .cur_end (cur_end),
+ .vcursor (vcursor),
+ .hcursor (hcursor),
+
+ .horiz_total (horiz_total),
+ .end_horiz (end_horiz),
+ .st_hor_retr (st_hor_retr),
+ .end_hor_retr (end_hor_retr),
+ .vert_total (vert_total),
+ .end_vert (end_vert),
+ .st_ver_retr (st_ver_retr),
+ .end_ver_retr (end_ver_retr),
+
+ .x_dotclockdiv2 (x_dotclockdiv2),
+
+ .v_retrace (v_retrace),
+ .vh_retrace (vh_retrace)
+ );
+
+ vga_cpu_mem_iface cpu_mem_iface (
+ .wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+
+ .wbs_adr_i (wb_adr_i),
+ .wbs_sel_i (wb_sel_i),
+ .wbs_we_i (wb_we_i),
+ .wbs_dat_i (wb_dat_i),
+ .wbs_dat_o (mem_wb_dat_o),
+ .wbs_stb_i (stb & !wb_tga_i),
+ .wbs_ack_o (mem_wb_ack_o),
+
+ .wbm_adr_o (wbm_adr_o),
+ .wbm_sel_o (wbm_sel_o),
+ .wbm_we_o (wbm_we_o),
+ .wbm_dat_o (wbm_dat_o),
+ .wbm_dat_i (wbm_dat_i),
+ .wbm_stb_o (wbm_stb_o),
+ .wbm_ack_i (wbm_ack_i),
+
+ .chain_four (chain_four),
+ .memory_mapping1 (memory_mapping1),
+ .write_mode (write_mode),
+ .raster_op (raster_op),
+ .read_mode (read_mode),
+ .bitmask (bitmask),
+ .set_reset (set_reset),
+ .enable_set_reset (enable_set_reset),
+ .map_mask (map_mask),
+ .read_map_select (read_map_select),
+ .color_compare (color_compare),
+ .color_dont_care (color_dont_care)
+ );
+
+ vga_mem_arbitrer mem_arbitrer (
+ .clk_i (wb_clk_i),
+ .rst_i (wb_rst_i),
+
+ .wb_adr_i (wbm_adr_o),
+ .wb_sel_i (wbm_sel_o),
+ .wb_we_i (wbm_we_o),
+ .wb_dat_i (wbm_dat_o),
+ .wb_dat_o (wbm_dat_i),
+ .wb_stb_i (wbm_stb_o),
+ .wb_ack_o (wbm_ack_i),
+
+ .csr_adr_i (csr_adr_i),
+ .csr_dat_o (csr_dat_i),
+ .csr_stb_i (csr_stb_i),
+
+ .csrm_adr_o (csrm_adr_o),
+ .csrm_sel_o (csrm_sel_o),
+ .csrm_we_o (csrm_we_o),
+ .csrm_dat_o (csrm_dat_o),
+ .csrm_dat_i (csrm_dat_i)
+ );
+
+ // Continous assignments
+ assign wb_dat_o = wb_tga_i ? conf_wb_dat_o : mem_wb_dat_o;
+ assign wb_ack_o = wb_tga_i ? conf_wb_ack_o : mem_wb_ack_o;
+ assign stb = wb_stb_i & wb_cyc_i;
+ assign vert_sync = ~graphics_alpha ^ w_vert_sync;
+
+ // Behaviour
+ // csr_adr_i
+ always @(posedge wb_clk_i)
+ csr_adr_i <= wb_rst_i ? 17'h0 : csr_adr_o + start_addr[15:1];
+
+ // csr_stb_i
+ always @(posedge wb_clk_i)
+ csr_stb_i <= wb_rst_i ? 1'b0 : csr_stb_o;
+
+endmodule
+"
+"/*
+ * Wishbone Flash RAM core for Altera DE0 board
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module flash16 (
+ // Wishbone slave interface
+ input wb_clk_i,
+ input wb_rst_i,
+ input [15:0] wb_dat_i,
+ output [15:0] wb_dat_o,
+ input wb_we_i,
+ input wb_adr_i, // Wishbone address line
+ input [ 1:0] wb_sel_i,
+ input wb_stb_i,
+ input wb_cyc_i,
+ output wb_ack_o,
+
+ // Pad signals
+ output [21:0] flash_addr_,
+ input [15:0] flash_data_,
+ output flash_we_n_,
+ output flash_oe_n_,
+ output flash_ce_n_,
+ output flash_rst_n_
+ );
+
+ // Registers and nets
+ wire op;
+ wire wr_command;
+ reg [21:0] address;
+
+ // Combinatorial logic
+ assign op = wb_stb_i & wb_cyc_i;
+
+ assign flash_rst_n_ = 1'b1;
+ assign flash_we_n_ = 1'b1;
+ assign flash_oe_n_ = !op;
+ assign flash_ce_n_ = !op;
+
+ assign flash_addr_ = address;
+ assign wr_command = op & wb_we_i; // Wishbone write access Signal
+
+ assign wb_ack_o = op;
+ assign wb_dat_o = flash_data_;
+
+ // --------------------------------------------------------------------
+ // Register addresses and defaults
+ // --------------------------------------------------------------------
+ `define FLASH_ALO 1'h0 // Lower 16 bits of address lines
+ `define FLASH_AHI 1'h1 // Upper 6 bits of address lines
+ always @(posedge wb_clk_i) // Synchrounous
+ if(wb_rst_i)
+ address <= 22'h000000; // Interupt Enable default
+ else
+ if(wr_command) // If a write was requested
+ case(wb_adr_i) // Determine which register was writen to
+ `FLASH_ALO: address[15: 0] <= wb_dat_i;
+ `FLASH_AHI: address[21:16] <= wb_dat_i[5:0];
+ default: ; // Default
+ endcase // End of case
+
+endmodule
+"
+"/*
+ * Zet SoC top level file for Altera DE0 board
+ * Copyright (C) 2009, 2010 Zeus Gomez Marmolejo
+ * Video SDRAM Additions by Charley Picker
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module kotku (
+ // Clock input
+ input clk_50_,
+
+ // General purpose IO
+ input [7:0] sw_,
+ input key_,
+ output [6:0] hex0_,
+ output [6:0] hex1_,
+ output [6:0] hex2_,
+ output [6:0] hex3_,
+ output [9:0] ledg_,
+
+ // flash signals
+ output [21:0] flash_addr_,
+ input [15:0] flash_data_,
+ output flash_oe_n_,
+ output flash_ce_n_,
+
+ // sdram signals
+ output [11:0] sdram_addr_,
+ inout [15:0] sdram_data_,
+ output [ 1:0] sdram_ba_,
+ output sdram_ras_n_,
+ output sdram_cas_n_,
+ output sdram_ce_,
+ output sdram_clk_,
+ output sdram_we_n_,
+ output sdram_cs_n_,
+
+ // VGA signals
+ output [ 3:0] tft_lcd_r_,
+ output [ 3:0] tft_lcd_g_,
+ output [ 3:0] tft_lcd_b_,
+ output tft_lcd_hsync_,
+ output tft_lcd_vsync_,
+
+ // UART signals
+ output uart_txd_,
+
+ // PS2 signals
+ input ps2_kclk_, // PS2 keyboard Clock
+ inout ps2_kdat_, // PS2 Keyboard Data
+ inout ps2_mclk_, // PS2 Mouse Clock
+ inout ps2_mdat_, // PS2 Mouse Data
+
+ // SD card signals
+ output sd_sclk_,
+ input sd_miso_,
+ output sd_mosi_,
+ output sd_ss_,
+
+ // To expansion header
+ output chassis_spk_,
+ output speaker_l_, // Speaker output, left channel
+ output speaker_r_ // Speaker output, right channel
+ );
+
+ // Registers and nets
+ wire clk;
+ wire rst_lck;
+ wire [15:0] dat_o;
+ wire [15:0] dat_i;
+ wire [19:1] adr;
+ wire we;
+ wire tga;
+ wire [ 1:0] sel;
+ wire stb;
+ wire cyc;
+ wire ack;
+ wire lock;
+
+ // wires to BIOS ROM
+ wire [15:0] rom_dat_o;
+ wire [15:0] rom_dat_i;
+ wire rom_tga_i;
+ wire [19:1] rom_adr_i;
+ wire [ 1:0] rom_sel_i;
+ wire rom_we_i;
+ wire rom_cyc_i;
+ wire rom_stb_i;
+ wire rom_ack_o;
+
+ // Unused outputs
+ wire flash_we_n_;
+ wire flash_rst_n_;
+ wire [1:0] sdram_dqm_;
+ wire [7:0] leds_;
+
+ // Unused inputs
+ wire uart_rxd_;
+
+ // wires to flash controller
+ wire [15:0] fl_dat_o;
+ wire [15:0] fl_dat_i;
+ wire fl_tga_i;
+ wire [19:1] fl_adr_i;
+ wire [ 1:0] fl_sel_i;
+ wire fl_we_i;
+ wire fl_cyc_i;
+ wire fl_stb_i;
+ wire fl_ack_o;
+
+ // wires to vga controller
+ wire [15:0] vga_dat_o;
+ wire [15:0] vga_dat_i;
+ wire vga_tga_i;
+ wire [19:1] vga_adr_i;
+ wire [ 1:0] vga_sel_i;
+ wire vga_we_i;
+ wire vga_cyc_i;
+ wire vga_stb_i;
+ wire vga_ack_o;
+
+ // cross clock domain synchronized signals
+ wire [15:0] vga_dat_o_s;
+ wire [15:0] vga_dat_i_s;
+ wire vga_tga_i_s;
+ wire [19:1] vga_adr_i_s;
+ wire [ 1:0] vga_sel_i_s;
+ wire vga_we_i_s;
+ wire vga_cyc_i_s;
+ wire vga_stb_i_s;
+ wire vga_ack_o_s;
+
+ // wires to uart controller
+ wire [15:0] uart_dat_o;
+ wire [15:0] uart_dat_i;
+ wire uart_tga_i;
+ wire [19:1] uart_adr_i;
+ wire [ 1:0] uart_sel_i;
+ wire uart_we_i;
+ wire uart_cyc_i;
+ wire uart_stb_i;
+ wire uart_ack_o;
+
+ // wires for Sound module
+ wire [19:1] wb_sb_adr_i; // Sound Address
+ wire [15:0] wb_sb_dat_i; // Sound
+ wire [15:0] wb_sb_dat_o; // Sound
+ wire [ 1:0] wb_sb_sel_i; // Sound
+ wire wb_sb_cyc_i; // Sound
+ wire wb_sb_stb_i; // Sound
+ wire wb_sb_we_i; // Sound
+ wire wb_sb_ack_o; // Sound
+ wire wb_sb_tga_i; // Sound
+
+ // wires to keyboard controller
+ wire [15:0] keyb_dat_o;
+ wire [15:0] keyb_dat_i;
+ wire keyb_tga_i;
+ wire [19:1] keyb_adr_i;
+ wire [ 1:0] keyb_sel_i;
+ wire keyb_we_i;
+ wire keyb_cyc_i;
+ wire keyb_stb_i;
+ wire keyb_ack_o;
+
+ // wires to timer controller
+ wire [15:0] timer_dat_o;
+ wire [15:0] timer_dat_i;
+ wire timer_tga_i;
+ wire [19:1] timer_adr_i;
+ wire [ 1:0] timer_sel_i;
+ wire timer_we_i;
+ wire timer_cyc_i;
+ wire timer_stb_i;
+ wire timer_ack_o;
+
+ // wires to sd controller
+ wire [19:1] sd_adr_i;
+ wire [ 7:0] sd_dat_o;
+ wire [15:0] sd_dat_i;
+ wire sd_tga_i;
+ wire [ 1:0] sd_sel_i;
+ wire sd_we_i;
+ wire sd_cyc_i;
+ wire sd_stb_i;
+ wire sd_ack_o;
+
+ // wires to sd bridge
+ wire [19:1] sd_adr_i_s;
+ wire [15:0] sd_dat_o_s;
+ wire [15:0] sd_dat_i_s;
+ wire sd_tga_i_s;
+ wire [ 1:0] sd_sel_i_s;
+ wire sd_we_i_s;
+ wire sd_cyc_i_s;
+ wire sd_stb_i_s;
+ wire sd_ack_o_s;
+
+ // wires to gpio controller
+ wire [15:0] gpio_dat_o;
+ wire [15:0] gpio_dat_i;
+ wire gpio_tga_i;
+ wire [19:1] gpio_adr_i;
+ wire [ 1:0] gpio_sel_i;
+ wire gpio_we_i;
+ wire gpio_cyc_i;
+ wire gpio_stb_i;
+ wire gpio_ack_o;
+
+ // wires to SDRAM controller
+ wire [19:1] fmlbrg_adr_s;
+ wire [15:0] fmlbrg_dat_w_s;
+ wire [15:0] fmlbrg_dat_r_s;
+ wire [ 1:0] fmlbrg_sel_s;
+ wire fmlbrg_cyc_s;
+ wire fmlbrg_stb_s;
+ wire fmlbrg_tga_s;
+ wire fmlbrg_we_s;
+ wire fmlbrg_ack_s;
+
+ wire [19:1] fmlbrg_adr;
+ wire [15:0] fmlbrg_dat_w;
+ wire [15:0] fmlbrg_dat_r;
+ wire [ 1:0] fmlbrg_sel;
+ wire fmlbrg_cyc;
+ wire fmlbrg_stb;
+ wire fmlbrg_tga;
+ wire fmlbrg_we;
+ wire fmlbrg_ack;
+
+ wire [19:1] csrbrg_adr_s;
+ wire [15:0] csrbrg_dat_w_s;
+ wire [15:0] csrbrg_dat_r_s;
+ wire [ 1:0] csrbrg_sel_s;
+ wire csrbrg_cyc_s;
+ wire csrbrg_stb_s;
+ wire csrbrg_tga_s;
+ wire csrbrg_we_s;
+ wire csrbrg_ack_s;
+
+ wire [19:1] csrbrg_adr;
+ wire [15:0] csrbrg_dat_w;
+ wire [15:0] csrbrg_dat_r;
+ wire [ 1:0] csrbrg_sel;
+ wire csrbrg_tga;
+ wire csrbrg_cyc;
+ wire csrbrg_stb;
+ wire csrbrg_we;
+ wire csrbrg_ack;
+
+ wire [ 2:0] csr_a;
+ wire csr_we;
+ wire [15:0] csr_dw;
+ wire [15:0] csr_dr_hpdmc;
+
+ // wires to hpdmc slave interface
+ wire [22:0] fml_adr;
+ wire fml_stb;
+ wire fml_we;
+ wire fml_ack;
+ wire [ 1:0] fml_sel;
+ wire [15:0] fml_di;
+ wire [15:0] fml_do;
+
+ // wires to fml bridge master interface
+ wire [19:0] fml_fmlbrg_adr;
+ wire fml_fmlbrg_stb;
+ wire fml_fmlbrg_we;
+ wire fml_fmlbrg_ack;
+ wire [ 1:0] fml_fmlbrg_sel;
+ wire [15:0] fml_fmlbrg_di;
+ wire [15:0] fml_fmlbrg_do;
+
+ // wires to VGA CPU FML master interface
+ wire [19:0] vga_cpu_fml_adr; // 1MB Memory Address range
+ wire vga_cpu_fml_stb;
+ wire vga_cpu_fml_we;
+ wire vga_cpu_fml_ack;
+ wire [1:0] vga_cpu_fml_sel;
+ wire [15:0] vga_cpu_fml_do;
+ wire [15:0] vga_cpu_fml_di;
+
+ // wires to VGA LCD FML master interface
+ wire [19:0] vga_lcd_fml_adr; // 1MB Memory Address range
+ wire vga_lcd_fml_stb;
+ wire vga_lcd_fml_we;
+ wire vga_lcd_fml_ack;
+ wire [1:0] vga_lcd_fml_sel;
+ wire [15:0] vga_lcd_fml_do;
+ wire [15:0] vga_lcd_fml_di;
+
+ // wires to default stb/ack
+ wire def_cyc_i;
+ wire def_stb_i;
+ wire [15:0] sw_dat_o;
+ wire sdram_clk;
+ wire vga_clk;
+
+ wire [ 7:0] intv;
+ wire [ 2:0] iid;
+ wire intr;
+ wire inta;
+
+ wire nmi_pb;
+ wire nmi;
+ wire nmia;
+
+ wire [19:0] pc;
+ reg [16:0] rst_debounce;
+
+ wire timer_clk;
+ wire timer2_o;
+
+ // Audio only signals
+ wire [ 7:0] aud_dat_o;
+ wire aud_cyc_i;
+ wire aud_ack_o;
+ wire aud_sel_cond;
+
+ // Keyboard-audio shared signals
+ wire [ 7:0] kaud_dat_o;
+ wire kaud_cyc_i;
+ wire kaud_ack_o;
+
+`ifndef SIMULATION
+ /*
+ * Debounce it (counter holds reset for 10.49ms),
+ * and generate power-on reset.
+ */
+ initial rst_debounce <= 17'h1FFFF;
+ reg rst;
+ initial rst <= 1'b1;
+ always @(posedge clk) begin
+ if(~rst_lck) /* reset is active low */
+ rst_debounce <= 17'h1FFFF;
+ else if(rst_debounce != 17'd0)
+ rst_debounce <= rst_debounce - 17'd1;
+ rst <= rst_debounce != 17'd0;
+ end
+`else
+ wire rst;
+ assign rst = !rst_lck;
+`endif
+
+ // Module instantiations
+ pll pll (
+ .inclk0 (clk_50_),
+ .c0 (sdram_clk), // 100 Mhz
+ .c1 (), // 25 Mhz
+ .c2 (clk), // 12.5 Mhz
+ .locked (lock)
+ );
+
+ clk_gen #(
+ .res (21),
+ .phase (21'd100091)
+ ) timerclk (
+ .clk_i (vga_clk), // 25 MHz
+ .rst_i (rst),
+ .clk_o (timer_clk) // 1.193178 MHz (required 1.193182 MHz)
+ );
+
+ bootrom bootrom (
+ .clk (clk), // Wishbone slave interface
+ .rst (rst),
+ .wb_dat_i (rom_dat_i),
+ .wb_dat_o (rom_dat_o),
+ .wb_adr_i (rom_adr_i),
+ .wb_we_i (rom_we_i ),
+ .wb_tga_i (rom_tga_i),
+ .wb_stb_i (rom_stb_i),
+ .wb_cyc_i (rom_cyc_i),
+ .wb_sel_i (rom_sel_i),
+ .wb_ack_o (rom_ack_o)
+ );
+
+ flash16 flash16 (
+ // Wishbone slave interface
+ .wb_clk_i (clk), // Main Clock
+ .wb_rst_i (rst), // Reset Line
+ .wb_adr_i (fl_adr_i[1]), // Address lines
+ .wb_sel_i (fl_sel_i), // Select lines
+ .wb_dat_i (fl_dat_i), // Command to send
+ .wb_dat_o (fl_dat_o), // Received data
+ .wb_cyc_i (fl_cyc_i), // Cycle
+ .wb_stb_i (fl_stb_i), // Strobe
+ .wb_we_i (fl_we_i), // Write enable
+ .wb_ack_o (fl_ack_o), // Normal bus termination
+
+ // Pad signals
+ .flash_addr_ (flash_addr_),
+ .flash_data_ (flash_data_),
+ .flash_we_n_ (flash_we_n_),
+ .flash_oe_n_ (flash_oe_n_),
+ .flash_ce_n_ (flash_ce_n_),
+ .flash_rst_n_ (flash_rst_n_)
+ );
+
+ wb_abrgr wb_fmlbrg (
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wbs_clk_i (clk),
+ .wbs_adr_i (fmlbrg_adr_s),
+ .wbs_dat_i (fmlbrg_dat_w_s),
+ .wbs_dat_o (fmlbrg_dat_r_s),
+ .wbs_sel_i (fmlbrg_sel_s),
+ .wbs_tga_i (fmlbrg_tga_s),
+ .wbs_stb_i (fmlbrg_stb_s),
+ .wbs_cyc_i (fmlbrg_cyc_s),
+ .wbs_we_i (fmlbrg_we_s),
+ .wbs_ack_o (fmlbrg_ack_s),
+
+ // Wishbone master interface
+ .wbm_clk_i (sdram_clk),
+ .wbm_adr_o (fmlbrg_adr),
+ .wbm_dat_o (fmlbrg_dat_w),
+ .wbm_dat_i (fmlbrg_dat_r),
+ .wbm_sel_o (fmlbrg_sel),
+ .wbm_tga_o (fmlbrg_tga),
+ .wbm_stb_o (fmlbrg_stb),
+ .wbm_cyc_o (fmlbrg_cyc),
+ .wbm_we_o (fmlbrg_we),
+ .wbm_ack_i (fmlbrg_ack)
+ );
+
+ fmlbrg #(
+ .fml_depth (20), // 8086 can only address 1 MB
+ .cache_depth (10) // 1 Kbyte cache
+ ) fmlbrg (
+ .sys_clk (sdram_clk),
+ .sys_rst (rst),
+\t
+\t // Wishbone slave interface
+ .wb_adr_i (fmlbrg_adr),
+\t .wb_cti_i(3'b0),
+ .wb_dat_i (fmlbrg_dat_w),
+ .wb_dat_o (fmlbrg_dat_r),
+ .wb_sel_i (fmlbrg_sel),
+ .wb_cyc_i (fmlbrg_cyc),
+ .wb_stb_i (fmlbrg_stb),
+ .wb_tga_i (fmlbrg_tga),
+ .wb_we_i (fmlbrg_we),
+ .wb_ack_o (fmlbrg_ack),
+
+ // FML master 1 interface
+ .fml_adr (fml_fmlbrg_adr),
+ .fml_stb (fml_fmlbrg_stb),
+ .fml_we (fml_fmlbrg_we),
+ .fml_ack (fml_fmlbrg_ack),
+ .fml_sel (fml_fmlbrg_sel),
+ .fml_do (fml_fmlbrg_do),
+ .fml_di (fml_fmlbrg_di),
+\t
+\t // Direct Cache Bus
+\t .dcb_stb(1'b0),
+\t .dcb_adr(20'b0),
+\t .dcb_dat(),
+\t .dcb_hit()
+\t
+ );
+
+ wb_abrgr wb_csrbrg (
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wbs_clk_i (clk),
+ .wbs_adr_i (csrbrg_adr_s),
+ .wbs_dat_i (csrbrg_dat_w_s),
+ .wbs_dat_o (csrbrg_dat_r_s),
+ .wbs_sel_i (csrbrg_sel_s),
+ .wbs_tga_i (csrbrg_tga_s),
+ .wbs_stb_i (csrbrg_stb_s),
+ .wbs_cyc_i (csrbrg_cyc_s),
+ .wbs_we_i (csrbrg_we_s),
+ .wbs_ack_o (csrbrg_ack_s),
+
+ // Wishbone master interface
+ .wbm_clk_i (sdram_clk),
+ .wbm_adr_o (csrbrg_adr),
+ .wbm_dat_o (csrbrg_dat_w),
+ .wbm_dat_i (csrbrg_dat_r),
+ .wbm_sel_o (csrbrg_sel),
+ .wbm_tga_o (csrbrg_tga),
+ .wbm_stb_o (csrbrg_stb),
+ .wbm_cyc_o (csrbrg_cyc),
+ .wbm_we_o (csrbrg_we),
+ .wbm_ack_i (csrbrg_ack)
+ );
+
+ csrbrg csrbrg (
+ .sys_clk (sdram_clk),
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wb_adr_i (csrbrg_adr[3:1]),
+ .wb_dat_i (csrbrg_dat_w),
+ .wb_dat_o (csrbrg_dat_r),
+ .wb_cyc_i (csrbrg_cyc),
+ .wb_stb_i (csrbrg_stb),
+ .wb_we_i (csrbrg_we),
+ .wb_ack_o (csrbrg_ack),
+
+ // CSR master interface
+ .csr_a (csr_a),
+ .csr_we (csr_we),
+ .csr_do (csr_dw),
+ .csr_di (csr_dr_hpdmc)
+ );
+
+ fmlarb #(
+ .fml_depth (23)
+ ) fmlarb (
+ .sys_clk (sdram_clk),
+\t.sys_rst (rst),
+\t
+\t// Master 0 interface - VGA LCD FML (Reserved video memory port has highest priority)
+\t.m0_adr ({3'b001, vga_lcd_fml_adr}), // 1 - 2 MB Addressable memory range
+\t.m0_stb (vga_lcd_fml_stb),
+\t.m0_we (vga_lcd_fml_we),
+\t.m0_ack (vga_lcd_fml_ack),
+\t.m0_sel (vga_lcd_fml_sel),
+\t.m0_di (vga_lcd_fml_do),
+\t.m0_do (vga_lcd_fml_di),
+\t\t
+\t// Master 1 interface - Wishbone FML bridge
+\t.m1_adr ({3'b000, fml_fmlbrg_adr}), // 0 - 1 MB Addressable memory range
+\t.m1_stb (fml_fmlbrg_stb),
+\t.m1_we (fml_fmlbrg_we),
+\t.m1_ack (fml_fmlbrg_ack),
+\t.m1_sel (fml_fmlbrg_sel),
+\t.m1_di (fml_fmlbrg_do),
+\t.m1_do (fml_fmlbrg_di),
+\t
+\t// Master 2 interface - VGA CPU FML
+\t.m2_adr ({3'b001, vga_cpu_fml_adr}), // 1 - 2 MB Addressable memory range
+\t.m2_stb (vga_cpu_fml_stb),
+\t.m2_we (vga_cpu_fml_we),
+\t.m2_ack (vga_cpu_fml_ack),
+\t.m2_sel (vga_cpu_fml_sel),
+\t.m2_di (vga_cpu_fml_do),
+\t.m2_do (vga_cpu_fml_di),
+\t
+\t// Master 3 interface - not connected
+\t.m3_adr ({3'b010, 20'b0}), // 2 - 3 MB Addressable memory range
+\t.m3_stb (1'b0),
+\t.m3_we (1'b0),
+\t.m3_ack (),
+\t.m3_sel (2'b00),
+\t.m3_di (16'h0000),
+\t.m3_do (),
+\t
+\t// Master 4 interface - not connected
+\t.m4_adr ({3'b011, 20'b0}), // 3 - 4 MB Addressable memory range
+\t.m4_stb (1'b0),
+\t.m4_we (1'b0),
+\t.m4_ack (),
+\t.m4_sel (2'b00),
+\t.m4_di (16'h0000),
+\t.m4_do (),
+\t
+\t// Master 5 interface - not connected
+\t.m5_adr ({3'b100, 20'b0}), // 4 - 5 MB Addressable memory range
+\t.m5_stb (1'b0),
+\t.m5_we (1'b0),
+\t.m5_ack (),
+\t.m5_sel (2'b00),
+\t.m5_di (16'h0000),
+\t.m5_do (),
+\t
+\t// Arbitrer Slave interface - connected to hpdmc
+\t.s_adr (fml_adr),
+\t.s_stb (fml_stb),
+\t.s_we (fml_we),
+\t.s_ack (fml_ack),
+\t.s_sel (fml_sel),
+\t.s_di (fml_di),
+\t.s_do (fml_do)
+ );
+
+ hpdmc #(
+ .csr_addr (1'b0),
+ .sdram_depth (23),
+ .sdram_columndepth (8)
+ ) hpdmc (
+ .sys_clk (sdram_clk),
+ .sys_rst (rst),
+
+ // CSR slave interface
+ .csr_a (csr_a),
+ .csr_we (csr_we),
+ .csr_di (csr_dw),
+ .csr_do (csr_dr_hpdmc),
+
+ // FML slave interface
+ .fml_adr (fml_adr),
+ .fml_stb (fml_stb),
+ .fml_we (fml_we),
+ .fml_ack (fml_ack),
+ .fml_sel (fml_sel),
+ .fml_di (fml_do),
+ .fml_do (fml_di),
+
+ // SDRAM pad signals
+ .sdram_cke (sdram_ce_),
+ .sdram_cs_n (sdram_cs_n_),
+ .sdram_we_n (sdram_we_n_),
+ .sdram_cas_n (sdram_cas_n_),
+ .sdram_ras_n (sdram_ras_n_),
+ .sdram_dqm (sdram_dqm_),
+ .sdram_adr (sdram_addr_),
+ .sdram_ba (sdram_ba_),
+ .sdram_dq (sdram_data_)
+ );
+
+ wb_abrg vga_brg (
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wbs_clk_i (clk),
+ .wbs_adr_i (vga_adr_i_s),
+ .wbs_dat_i (vga_dat_i_s),
+ .wbs_dat_o (vga_dat_o_s),
+ .wbs_sel_i (vga_sel_i_s),
+ .wbs_tga_i (vga_tga_i_s),
+ .wbs_stb_i (vga_stb_i_s),
+ .wbs_cyc_i (vga_cyc_i_s),
+ .wbs_we_i (vga_we_i_s),
+ .wbs_ack_o (vga_ack_o_s),
+
+ // Wishbone master interface
+ .wbm_clk_i (sdram_clk),
+ .wbm_adr_o (vga_adr_i),
+ .wbm_dat_o (vga_dat_i),
+ .wbm_dat_i (vga_dat_o),
+ .wbm_sel_o (vga_sel_i),
+ .wbm_tga_o (vga_tga_i),
+ .wbm_stb_o (vga_stb_i),
+ .wbm_cyc_o (vga_cyc_i),
+ .wbm_we_o (vga_we_i),
+ .wbm_ack_i (vga_ack_o)
+ );
+
+ vga_fml #(
+ .fml_depth (20) // 1MB Memory Address range
+ ) vga (
+ .wb_rst_i (rst),
+
+ // Wishbone slave interface
+ .wb_clk_i (sdram_clk), // 100MHz VGA clock
+ .wb_dat_i (vga_dat_i),
+ .wb_dat_o (vga_dat_o),
+ .wb_adr_i (vga_adr_i[16:1]), // 128K
+ .wb_we_i (vga_we_i),
+ .wb_tga_i (vga_tga_i),
+ .wb_sel_i (vga_sel_i),
+ .wb_stb_i (vga_stb_i),
+ .wb_cyc_i (vga_cyc_i),
+ .wb_ack_o (vga_ack_o),
+
+ // VGA pad signals
+ .vga_red_o (tft_lcd_r_),
+ .vga_green_o (tft_lcd_g_),
+ .vga_blue_o (tft_lcd_b_),
+ .horiz_sync (tft_lcd_hsync_),
+ .vert_sync (tft_lcd_vsync_),
+
+ // VGA CPU FML master interface
+ .vga_cpu_fml_adr(vga_cpu_fml_adr),
+ .vga_cpu_fml_stb(vga_cpu_fml_stb),
+ .vga_cpu_fml_we(vga_cpu_fml_we),
+ .vga_cpu_fml_ack(vga_cpu_fml_ack),
+ .vga_cpu_fml_sel(vga_cpu_fml_sel),
+ .vga_cpu_fml_do(vga_cpu_fml_do),
+ .vga_cpu_fml_di(vga_cpu_fml_di),
+
+ // VGA LCD FML master interface
+ .vga_lcd_fml_adr(vga_lcd_fml_adr),
+ .vga_lcd_fml_stb(vga_lcd_fml_stb),
+ .vga_lcd_fml_we(vga_lcd_fml_we),
+ .vga_lcd_fml_ack(vga_lcd_fml_ack),
+ .vga_lcd_fml_sel(vga_lcd_fml_sel),
+ .vga_lcd_fml_do(vga_lcd_fml_do),
+ .vga_lcd_fml_di(vga_lcd_fml_di),
+
+ .vga_clk(vga_clk)
+
+ );
+
+ // RS232 COM1 Port
+ serial com1 (
+ .wb_clk_i (clk), // Main Clock
+ .wb_rst_i (rst), // Reset Line
+ .wb_adr_i (uart_adr_i[2:1]), // Address lines
+ .wb_sel_i (uart_sel_i), // Select lines
+ .wb_dat_i (uart_dat_i), // Command to send
+ .wb_dat_o (uart_dat_o),
+ .wb_we_i (uart_we_i), // Write enable
+ .wb_stb_i (uart_stb_i),
+ .wb_cyc_i (uart_cyc_i),
+ .wb_ack_o (uart_ack_o),
+ .wb_tgc_o (intv[4]), // Interrupt request
+
+ .rs232_tx (uart_txd_), // UART signals
+ .rs232_rx (uart_rxd_) // serial input/output
+ );
+
+ // Sound Module Instantiation
+ sound sound (
+ .wb_clk_i (clk), // Main Clock
+ .wb_rst_i (rst), // Reset Line
+ .wb_dat_i (wb_sb_dat_i), // Command to send
+ .wb_dat_o (wb_sb_dat_o), // Received data
+ .wb_cyc_i (wb_sb_cyc_i), // Cycle
+ .wb_stb_i (wb_sb_stb_i), // Strobe
+ .wb_adr_i (wb_sb_adr_i[3:1]), // Address lines
+ .wb_sel_i (wb_sb_sel_i), // Select lines
+ .wb_we_i (wb_sb_we_i), // Write enable
+ .wb_ack_o (wb_sb_ack_o), // Normal bus termination
+
+ .audio_l (speaker_l_), // Audio Output Left Channel
+ .audio_r (speaker_r_) // Audio Output Right Channel
+ );
+
+ ps2 ps2 (
+ .wb_clk_i (clk), // Main Clock
+ .wb_rst_i (rst), // Reset Line
+ .wb_adr_i (keyb_adr_i[2:1]), // Address lines
+ .wb_sel_i (keyb_sel_i), // Select lines
+ .wb_dat_i (keyb_dat_i), // Command to send to Ethernet
+ .wb_dat_o (keyb_dat_o),
+ .wb_we_i (keyb_we_i), // Write enable
+ .wb_stb_i (keyb_stb_i),
+ .wb_cyc_i (keyb_cyc_i),
+ .wb_ack_o (keyb_ack_o),
+ .wb_tgk_o (intv[1]), // Keyboard Interrupt request
+ .wb_tgm_o (intv[3]), // Mouse Interrupt request
+
+ .ps2_kbd_clk_ (ps2_kclk_),
+ .ps2_kbd_dat_ (ps2_kdat_),
+ .ps2_mse_clk_ (ps2_mclk_),
+ .ps2_mse_dat_ (ps2_mdat_)
+ );
+
+ speaker speaker (
+ .clk (clk),
+ .rst (rst),
+
+ .wb_dat_i (keyb_dat_i[15:8]),
+ .wb_dat_o (aud_dat_o),
+ .wb_we_i (keyb_we_i),
+ .wb_stb_i (keyb_stb_i),
+ .wb_cyc_i (aud_cyc_i),
+ .wb_ack_o (aud_ack_o),
+
+ .timer2 (timer2_o),
+
+ .speaker_ (chassis_spk_)
+ );
+
+ // Selection logic between keyboard and audio ports (port 65h: audio)
+ assign aud_sel_cond = keyb_adr_i[2:1]==2'b00 && keyb_sel_i[1];
+ assign aud_cyc_i = kaud_cyc_i && aud_sel_cond;
+ assign keyb_cyc_i = kaud_cyc_i && !aud_sel_cond;
+ assign kaud_ack_o = aud_cyc_i & aud_ack_o | keyb_cyc_i & keyb_ack_o;
+ assign kaud_dat_o = {8{aud_cyc_i}} & aud_dat_o
+ | {8{keyb_cyc_i}} & keyb_dat_o[15:8];
+
+ timer timer (
+ .wb_clk_i (clk),
+ .wb_rst_i (rst),
+ .wb_adr_i (timer_adr_i[1]),
+ .wb_sel_i (timer_sel_i),
+ .wb_dat_i (timer_dat_i),
+ .wb_dat_o (timer_dat_o),
+ .wb_stb_i (timer_stb_i),
+ .wb_cyc_i (timer_cyc_i),
+ .wb_we_i (timer_we_i),
+ .wb_ack_o (timer_ack_o),
+ .wb_tgc_o (intv[0]),
+ .tclk_i (timer_clk), // 1.193182 MHz = (14.31818/12) MHz
+ .gate2_i (aud_dat_o[0]),
+ .out2_o (timer2_o)
+ );
+
+ simple_pic pic0 (
+ .clk (clk),
+ .rst (rst),
+ .intv (intv),
+ .inta (inta),
+ .intr (intr),
+ .iid (iid)
+ );
+
+ wb_abrgr sd_brg (
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wbs_clk_i (clk),
+ .wbs_adr_i (sd_adr_i_s),
+ .wbs_dat_i (sd_dat_i_s),
+ .wbs_dat_o (sd_dat_o_s),
+ .wbs_sel_i (sd_sel_i_s),
+ .wbs_tga_i (sd_tga_i_s),
+ .wbs_stb_i (sd_stb_i_s),
+ .wbs_cyc_i (sd_cyc_i_s),
+ .wbs_we_i (sd_we_i_s),
+ .wbs_ack_o (sd_ack_o_s),
+
+ // Wishbone master interface
+ .wbm_clk_i (sdram_clk),
+ .wbm_adr_o (sd_adr_i),
+ .wbm_dat_o (sd_dat_i),
+ .wbm_dat_i ({8'h0,sd_dat_o}),
+ .wbm_tga_o (sd_tga_i),
+ .wbm_sel_o (sd_sel_i),
+ .wbm_stb_o (sd_stb_i),
+ .wbm_cyc_o (sd_cyc_i),
+ .wbm_we_o (sd_we_i),
+ .wbm_ack_i (sd_ack_o)
+ );
+
+ sdspi sdspi (
+ // Serial pad signal
+ .sclk (sd_sclk_),
+ .miso (sd_miso_),
+ .mosi (sd_mosi_),
+ .ss (sd_ss_),
+
+ // Wishbone slave interface
+ .wb_clk_i (sdram_clk),
+ .wb_rst_i (rst),
+ .wb_dat_i (sd_dat_i[8:0]),
+ .wb_dat_o (sd_dat_o),
+ .wb_we_i (sd_we_i),
+ .wb_sel_i (sd_sel_i),
+ .wb_stb_i (sd_stb_i),
+ .wb_cyc_i (sd_cyc_i),
+ .wb_ack_o (sd_ack_o)
+ );
+
+ // Switches and leds
+ sw_leds sw_leds (
+ .wb_clk_i (clk),
+ .wb_rst_i (rst),
+
+ // Wishbone slave interface
+ .wb_adr_i (gpio_adr_i[1]),
+ .wb_dat_o (gpio_dat_o),
+ .wb_dat_i (gpio_dat_i),
+ .wb_sel_i (gpio_sel_i),
+ .wb_we_i (gpio_we_i),
+ .wb_stb_i (gpio_stb_i),
+ .wb_cyc_i (gpio_cyc_i),
+ .wb_ack_o (gpio_ack_o),
+
+ // GPIO inputs/outputs
+ .leds_ ({leds_,ledg_[9:4]}),
+ .sw_ (sw_),
+ .pb_ (key_),
+ .tick (intv[0]),
+ .nmi_pb (nmi_pb) // NMI from pushbutton
+ );
+
+ hex_display hex16 (
+ .num (pc[19:4]),
+ .en (1'b1),
+
+ .hex0 (hex0_),
+ .hex1 (hex1_),
+ .hex2 (hex2_),
+ .hex3 (hex3_)
+ );
+
+ zet zet (
+ .pc (pc),
+
+ // Wishbone master interface
+ .wb_clk_i (clk),
+ .wb_rst_i (rst),
+ .wb_dat_i (dat_i),
+ .wb_dat_o (dat_o),
+ .wb_adr_o (adr),
+ .wb_we_o (we),
+ .wb_tga_o (tga),
+ .wb_sel_o (sel),
+ .wb_stb_o (stb),
+ .wb_cyc_o (cyc),
+ .wb_ack_i (ack),
+ .wb_tgc_i (intr),
+ .wb_tgc_o (inta),
+ .nmi (nmi),
+ .nmia (nmia)
+ );
+
+ wb_switch #(
+ .s0_addr_1 (20'b0_1111_1111_1111_0000_000), // bios boot mem 0xfff00 - 0xfffff
+ .s0_mask_1 (20'b1_1111_1111_1111_0000_000), // bios boot ROM Memory
+
+ .s1_addr_1 (20'b0_1010_0000_0000_0000_000), // mem 0xa0000 - 0xbffff
+ .s1_mask_1 (20'b1_1110_0000_0000_0000_000), // VGA
+
+ .s1_addr_2 (20'b1_0000_0000_0011_1100_000), // io 0x3c0 - 0x3df
+ .s1_mask_2 (20'b1_0000_1111_1111_1110_000), // VGA IO
+
+ .s2_addr_1 (20'b1_0000_0000_0011_1111_100), // io 0x3f8 - 0x3ff
+ .s2_mask_1 (20'b1_0000_1111_1111_1111_100), // RS232 IO
+
+ .s3_addr_1 (20'b1_0000_0000_0000_0110_000), // io 0x60, 0x64
+ .s3_mask_1 (20'b1_0000_1111_1111_1111_101), // Keyboard / Mouse IO
+
+ .s4_addr_1 (20'b1_0000_0000_0001_0000_000), // io 0x100 - 0x101
+ .s4_mask_1 (20'b1_0000_1111_1111_1111_111), // SD Card IO
+
+ .s5_addr_1 (20'b1_0000_1111_0001_0000_000), // io 0xf100 - 0xf103
+ .s5_mask_1 (20'b1_0000_1111_1111_1111_110), // GPIO
+
+ .s6_addr_1 (20'b1_0000_1111_0010_0000_000), // io 0xf200 - 0xf20f
+ .s6_mask_1 (20'b1_0000_1111_1111_1111_000), // CSR Bridge SDRAM Control
+
+ .s7_addr_1 (20'b1_0000_0000_0000_0100_000), // io 0x40 - 0x43
+ .s7_mask_1 (20'b1_0000_1111_1111_1111_110), // Timer control port
+
+ .s8_addr_1 (20'b1_0000_0000_0010_0011_100), // io 0x0238 - 0x023b
+ .s8_mask_1 (20'b1_0000_1111_1111_1111_110), // Flash IO port
+
+ .s9_addr_1 (20'b1_0000_0000_0010_0001_000), // io 0x0210 - 0x021F
+ .s9_mask_1 (20'b1_0000_1111_1111_1111_000), // Sound Blaster
+
+ .sA_addr_1 (20'b1_0000_1111_0011_0000_000), // io 0xf300 - 0xf3ff
+ .sA_mask_1 (20'b1_0000_1111_1111_0000_000), // SDRAM Control
+ .sA_addr_2 (20'b0_0000_0000_0000_0000_000), // mem 0x00000 - 0xfffff
+ .sA_mask_2 (20'b1_0000_0000_0000_0000_000) // Base RAM
+
+ ) wbs (
+
+ // Master interface
+ .m_dat_i (dat_o),
+ .m_dat_o (sw_dat_o),
+ .m_adr_i ({tga,adr}),
+ .m_sel_i (sel),
+ .m_we_i (we),
+ .m_cyc_i (cyc),
+ .m_stb_i (stb),
+ .m_ack_o (ack),
+
+ // Slave 0 interface - bios rom
+ .s0_dat_i (rom_dat_o),
+ .s0_dat_o (rom_dat_i),
+ .s0_adr_o ({rom_tga_i,rom_adr_i}),
+ .s0_sel_o (rom_sel_i),
+ .s0_we_o (rom_we_i),
+ .s0_cyc_o (rom_cyc_i),
+ .s0_stb_o (rom_stb_i),
+ .s0_ack_i (rom_ack_o),
+
+ // Slave 1 interface - vga
+ .s1_dat_i (vga_dat_o_s),
+ .s1_dat_o (vga_dat_i_s),
+ .s1_adr_o ({vga_tga_i_s,vga_adr_i_s}),
+ .s1_sel_o (vga_sel_i_s),
+ .s1_we_o (vga_we_i_s),
+ .s1_cyc_o (vga_cyc_i_s),
+ .s1_stb_o (vga_stb_i_s),
+ .s1_ack_i (vga_ack_o_s),
+
+ // Slave 2 interface - uart
+ .s2_dat_i (uart_dat_o),
+ .s2_dat_o (uart_dat_i),
+ .s2_adr_o ({uart_tga_i,uart_adr_i}),
+ .s2_sel_o (uart_sel_i),
+ .s2_we_o (uart_we_i),
+ .s2_cyc_o (uart_cyc_i),
+ .s2_stb_o (uart_stb_i),
+ .s2_ack_i (uart_ack_o),
+
+ // Slave 3 interface - keyb
+ .s3_dat_i ({kaud_dat_o,keyb_dat_o[7:0]}),
+ .s3_dat_o (keyb_dat_i),
+ .s3_adr_o ({keyb_tga_i,keyb_adr_i}),
+ .s3_sel_o (keyb_sel_i),
+ .s3_we_o (keyb_we_i),
+ .s3_cyc_o (kaud_cyc_i),
+ .s3_stb_o (keyb_stb_i),
+ .s3_ack_i (kaud_ack_o),
+
+ // Slave 4 interface - sd
+ .s4_dat_i (sd_dat_o_s),
+ .s4_dat_o (sd_dat_i_s),
+ .s4_adr_o ({sd_tga_i_s,sd_adr_i_s}),
+ .s4_sel_o (sd_sel_i_s),
+ .s4_we_o (sd_we_i_s),
+ .s4_cyc_o (sd_cyc_i_s),
+ .s4_stb_o (sd_stb_i_s),
+ .s4_ack_i (sd_ack_o_s),
+
+ // Slave 5 interface - gpio
+ .s5_dat_i (gpio_dat_o),
+ .s5_dat_o (gpio_dat_i),
+ .s5_adr_o ({gpio_tga_i,gpio_adr_i}),
+ .s5_sel_o (gpio_sel_i),
+ .s5_we_o (gpio_we_i),
+ .s5_cyc_o (gpio_cyc_i),
+ .s5_stb_o (gpio_stb_i),
+ .s5_ack_i (gpio_ack_o),
+
+ // Slave 6 interface - csr bridge
+ .s6_dat_i (csrbrg_dat_r_s),
+ .s6_dat_o (csrbrg_dat_w_s),
+ .s6_adr_o ({csrbrg_tga_s,csrbrg_adr_s}),
+ .s6_sel_o (csrbrg_sel_s),
+ .s6_we_o (csrbrg_we_s),
+ .s6_cyc_o (csrbrg_cyc_s),
+ .s6_stb_o (csrbrg_stb_s),
+ .s6_ack_i (csrbrg_ack_s),
+
+ // Slave 7 interface - timer
+ .s7_dat_i (timer_dat_o),
+ .s7_dat_o (timer_dat_i),
+ .s7_adr_o ({timer_tga_i,timer_adr_i}),
+ .s7_sel_o (timer_sel_i),
+ .s7_we_o (timer_we_i),
+ .s7_cyc_o (timer_cyc_i),
+ .s7_stb_o (timer_stb_i),
+ .s7_ack_i (timer_ack_o),
+
+ // Slave 8 interface - flash
+ .s8_dat_i (fl_dat_o),
+ .s8_dat_o (fl_dat_i),
+ .s8_adr_o ({fl_tga_i,fl_adr_i}),
+ .s8_sel_o (fl_sel_i),
+ .s8_we_o (fl_we_i),
+ .s8_cyc_o (fl_cyc_i),
+ .s8_stb_o (fl_stb_i),
+ .s8_ack_i (fl_ack_o),
+
+ // Slave 9 interface - sb16
+ .s9_dat_i (wb_sb_dat_o),
+ .s9_dat_o (wb_sb_dat_i),
+ .s9_adr_o ({wb_sb_tga_i,wb_sb_adr_i}),
+ .s9_sel_o (wb_sb_sel_i),
+ .s9_we_o (wb_sb_we_i),
+ .s9_cyc_o (wb_sb_cyc_i),
+ .s9_stb_o (wb_sb_stb_i),
+ .s9_ack_i (wb_sb_ack_o),
+
+ // Slave A interface - sdram
+ .sA_dat_i (fmlbrg_dat_r_s),
+ .sA_dat_o (fmlbrg_dat_w_s),
+ .sA_adr_o ({fmlbrg_tga_s,fmlbrg_adr_s}),
+ .sA_sel_o (fmlbrg_sel_s),
+ .sA_we_o (fmlbrg_we_s),
+ .sA_cyc_o (fmlbrg_cyc_s),
+ .sA_stb_o (fmlbrg_stb_s),
+ .sA_ack_i (fmlbrg_ack_s),
+
+ // Slave B interface - default
+ .sB_dat_i (16'h0000),
+ .sB_dat_o (),
+ .sB_adr_o (),
+ .sB_sel_o (),
+ .sB_we_o (),
+ .sB_cyc_o (def_cyc_i),
+ .sB_stb_o (def_stb_i),
+ .sB_ack_i (def_cyc_i & def_stb_i)
+ );
+
+ // Continuous assignments
+ assign rst_lck = !sw_[0] & lock;
+
+ assign nmi = nmi_pb;
+ assign dat_i = nmia ? 16'h0002 :
+ (inta ? { 13'b0000_0000_0000_1, iid } :
+ sw_dat_o);
+
+ assign sdram_clk_ = sdram_clk;
+
+ assign ledg_[3:0] = pc[3:0];
+
+endmodule
+"
+"/*
+ * Wishbone Compatible Text only VGA core
+ * Copyright (c) 2008,2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vdu (
+ input wb_clk_i, // 25 Mhz VDU clock
+
+ // Wishbone slave interface
+ input wb_rst_i,
+ input [15:0] wb_dat_i,
+ output reg [15:0] wb_dat_o,
+ input [19:1] wb_adr_i,
+ input wb_we_i,
+ input wb_tga_i,
+ input [ 1:0] wb_sel_i,
+ input wb_stb_i,
+ input wb_cyc_i,
+ output wb_ack_o,
+
+ // VGA pad signals
+ output reg [ 1:0] vga_red_o,
+ output reg [ 1:0] vga_green_o,
+ output reg [ 1:0] vga_blue_o,
+ output reg horiz_sync,
+ output reg vert_sync
+ );
+
+ // Net, registers and parameters
+ // Synchronization constants, these values are taken from:
+ // http://tinyvga.com/vga-timing/640x400@70Hz
+
+ parameter HOR_DISP_END = 10'd639; // Last horizontal pixel displayed
+ parameter HOR_SYNC_BEG = 10'd655; // Start of horizontal synch pulse
+ parameter HOR_SYNC_END = 10'd751; // End of Horizontal Synch pulse
+ parameter HOR_SCAN_END = 10'd799; // Last pixel in scan line
+ parameter HOR_DISP_CHR = 80; // Number of characters displayed per row
+ parameter HOR_VIDEO_ON = 10'd7; // When to start displaying characters
+ parameter HOR_VIDEO_OFF = 10'd647; // When to stop displaying characters
+
+ parameter VER_DISP_END = 9'd400; // last row displayed
+ parameter VER_SYNC_BEG = 9'd411; // start of vertical synch pulse
+ parameter VER_SYNC_END = 9'd413; // end of vertical synch pulse
+ parameter VER_SCAN_END = 9'd448; // Last scan row in the frame
+ parameter VER_DISP_CHR = 5'd25; // Number of character rows displayed
+
+ reg cursor_on_v;
+ reg cursor_on_h;
+ reg video_on_v;
+ reg video_on_h;
+ reg [9:0] h_count;
+ reg [8:0] v_count; // 0 to VER_SCAN_END
+ reg [22:0] blink_count;
+
+ // Character generator ROM
+ wire [11:0] char_addr;
+ wire [7:0] char_data_out;
+
+ // Control registers
+ reg [3:0] reg_adr;
+ reg [6:0] reg_hcursor; // 80 columns
+ reg [4:0] reg_vcursor; // 25 rows
+ reg [3:0] reg_cur_start;
+ reg [3:0] reg_cur_end;
+
+ wire wr_adr;
+ wire wr_reg;
+ wire write;
+ wire wr_hcursor;
+ wire wr_vcursor;
+ wire wr_cur_start;
+ wire wr_cur_end;
+
+ // Video shift register
+ reg [7:0] vga_shift;
+ reg [2:0] vga_fg_colour;
+ reg [2:0] vga_bg_colour;
+ reg cursor_on;
+ wire cursor_on1;
+ reg video_on;
+ wire video_on1;
+
+ // vga character ram access bus
+ reg [6:0] col_addr; // 0 to 79
+ reg [4:0] row_addr; // 0 to 49 (25 * 2 -1)
+ reg [6:0] col1_addr; // 0 to 79
+ reg [4:0] row1_addr; // 0 to 49 (25 * 2 - 1)
+ reg [6:0] hor_addr; // 0 to 79
+ reg [6:0] ver_addr; // 0 to 124
+ reg vga0_we;
+ reg vga0_rw, vga1_rw, vga2_rw, vga3_rw, vga4_rw, vga5_rw;
+ reg vga1_we;
+ reg vga2_we;
+ reg buff_we;
+ reg [7:0] buff_data_in;
+ reg attr_we;
+ reg [7:0] attr_data_in;
+ reg [10:0] buff_addr;
+ reg [10:0] attr0_addr;
+ reg attr0_we;
+ reg [10:0] buff0_addr;
+ reg buff0_we;
+ reg [10:0] attr_addr;
+ reg intense;
+ wire [7:0] vga_data_out;
+ wire [7:0] attr_data_out;
+ wire [10:0] vga_addr; // 2K byte character buffer
+ wire [15:0] out_data;
+ wire fg_or_bg;
+ wire stb;
+ wire brown_bg;
+ wire brown_fg;
+ wire [15:0] status_reg1;
+ wire vh_retrace;
+ wire v_retrace;
+
+ // Module instantiation
+ vdu_char_rom char_rom (
+ .clk (wb_clk_i),
+ .addr (char_addr),
+ .q (char_data_out)
+ );
+
+ vdu_ram_2k_char ram_2k_char (
+ .clk (wb_clk_i),
+ .rst (wb_rst_i),
+ .we (buff_we),
+ .addr (buff_addr),
+ .wdata (buff_data_in),
+ .rdata (vga_data_out)
+ );
+
+ vdu_ram_2k_attr ram_2k_attr (
+ .clk (wb_clk_i),
+ .rst (wb_rst_i),
+ .we (attr_we),
+ .addr (attr_addr),
+ .wdata (attr_data_in),
+ .rdata (attr_data_out)
+ );
+
+ // Assignments
+ assign video_on1 = video_on_h && video_on_v;
+ assign cursor_on1 = cursor_on_h && cursor_on_v;
+ assign char_addr = { vga_data_out, v_count[3:0] };
+ assign vga_addr = { 4'b0, hor_addr} + { ver_addr, 4'b0 };
+ assign out_data = {attr_data_out, vga_data_out};
+
+ assign stb = wb_stb_i && wb_cyc_i;
+
+ assign fg_or_bg = vga_shift[7] ^ cursor_on;
+ assign brown_fg = (vga_fg_colour==3'd6) && !intense;
+ assign brown_bg = (vga_bg_colour==3'd6);
+
+ // Control registers
+ assign write = wb_tga_i & wb_stb_i & wb_cyc_i & wb_we_i;
+ assign wr_adr = write & wb_sel_i[0];
+ assign wr_reg = write & wb_sel_i[1];
+ assign wr_hcursor = wr_reg & (reg_adr==4'hf);
+ assign wr_vcursor = wr_reg & (reg_adr==4'he);
+ assign wr_cur_start = wr_reg & (reg_adr==4'ha);
+ assign wr_cur_end = wr_reg & (reg_adr==4'hb);
+
+ assign v_retrace = !video_on_v;
+ assign vh_retrace = v_retrace | !video_on_h;
+ assign status_reg1 = { 11'b0, v_retrace, 3'b0, vh_retrace };
+ assign wb_ack_o = stb & (wb_tga_i ? 1'b1 : vga5_rw);
+
+ // Behaviour - CPU write interface
+ always @(posedge wb_clk_i)
+ if(wb_rst_i) begin
+ attr0_addr <= 11'b0;
+ attr0_we <= 1'b0;
+ attr_data_in <= 8'h0;
+ buff0_addr <= 11'b0;
+ buff0_we <= 1'b0;
+ buff_data_in <= 8'h0;
+ end
+ else begin
+ if(stb && !wb_tga_i) begin
+ // 1111 1111 1100 0000 0000
+ // 0xa0000 - 0xbffff 9876 5432 1098 7654 3210
+ // if(wb_adr_i[19:12] & 8'h18) begin
+ // 0xB8000 - 0xBFFFF = 1011_1000_xxxx_xxxx_xxxs
+ attr0_addr <= wb_adr_i[11:1];
+ buff0_addr <= wb_adr_i[11:1];
+
+ attr0_we <= wb_we_i & wb_sel_i[1];
+ buff0_we <= wb_we_i & wb_sel_i[0];
+ // end
+
+ attr_data_in <= wb_dat_i[15:8];
+ buff_data_in <= wb_dat_i[7:0];
+ end
+ end
+
+ // CPU read interface
+ always @(posedge wb_clk_i)
+ wb_dat_o <= wb_rst_i ? 16'h0 : (wb_tga_i ? status_reg1
+ : (vga4_rw ? out_data : wb_dat_o));
+
+ // Control registers
+ always @(posedge wb_clk_i)
+ reg_adr <= wb_rst_i ? 4'h0
+ : (wr_adr ? wb_dat_i[3:0] : reg_adr);
+
+ always @(posedge wb_clk_i)
+ reg_hcursor <= wb_rst_i ? 7'h0
+ : (wr_hcursor ? wb_dat_i[14:8] : reg_hcursor);
+
+ always @(posedge wb_clk_i)
+ reg_vcursor <= wb_rst_i ? 5'h0
+ : (wr_vcursor ? wb_dat_i[12:8] : reg_vcursor);
+
+ always @(posedge wb_clk_i)
+ reg_cur_start <= wb_rst_i ? 4'he
+ : (wr_cur_start ? wb_dat_i[11:8] : reg_cur_start);
+
+ always @(posedge wb_clk_i)
+ reg_cur_end <= wb_rst_i ? 4'hf
+ : (wr_cur_end ? wb_dat_i[11:8] : reg_cur_end);
+
+ // Sync generation & timing process
+ // Generate horizontal and vertical timing signals for video signal
+ always @(posedge wb_clk_i)
+ if(wb_rst_i) begin
+ h_count <= 10'b0;
+ horiz_sync <= 1'b1;
+ v_count <= 9'b0;
+ vert_sync <= 1'b1;
+ video_on_h <= 1'b1;
+ video_on_v <= 1'b1;
+ cursor_on_h <= 1'b0;
+ cursor_on_v <= 1'b0;
+ blink_count <= 22'b0;
+ end
+ else begin
+ h_count <= (h_count==HOR_SCAN_END) ? 10'b0 : h_count + 10'b1;
+ horiz_sync <= (h_count==HOR_SYNC_BEG) ? 1'b0 : ((h_count==HOR_SYNC_END) ? 1'b1 : horiz_sync);
+ v_count <= (v_count==VER_SCAN_END && h_count==HOR_SCAN_END) ? 9'b0 : ((h_count==HOR_SYNC_END) ? v_count + 9'b1 : v_count);
+ vert_sync <= (v_count==VER_SYNC_BEG) ? 1'b0 : ((v_count==VER_SYNC_END) ? 1'b1 : vert_sync);
+ video_on_h <= (h_count==HOR_VIDEO_ON) ? 1'b1 : ((h_count==HOR_VIDEO_OFF) ? 1'b0 : video_on_h);
+ video_on_v <= (v_count==9'h0) ? 1'b1 : ((v_count==VER_DISP_END) ? 1'b0 : video_on_v);
+ cursor_on_h <= (h_count[9:3] == reg_hcursor[6:0]);
+ cursor_on_v <= (v_count[8:4] == reg_vcursor[4:0]) && (v_count[3:0] >= reg_cur_start) && (v_count[3:0] <= reg_cur_end);
+ blink_count <= blink_count + 22'd1;
+ end
+
+ // Video memory access
+ always @(posedge wb_clk_i)
+ if(wb_rst_i) begin
+ vga0_we <= 1'b0;
+ vga0_rw <= 1'b1;
+ row_addr <= 5'b0;
+ col_addr <= 7'b0;
+
+ vga1_we <= 1'b0;
+ vga1_rw <= 1'b1;
+ row1_addr <= 5'b0;
+ col1_addr <= 7'b0;
+
+ vga2_we <= 1'b0;
+ vga2_rw <= 1'b0;
+ vga3_rw <= 1'b0;
+ vga4_rw <= 1'b0;
+ vga5_rw <= 1'b0;
+ ver_addr <= 7'b0;
+ hor_addr <= 7'b0;
+
+ buff_addr <= 10'b0;
+ attr_addr <= 10'b0;
+ buff_we <= 1'b0;
+ attr_we <= 1'b0;
+ end
+ else begin // on h_count = 0 initiate character write
+ case (h_count[2:0]) // all other cycles are reads
+ 3'b000: // pipeline character write
+ begin
+ vga0_we <= wb_we_i;
+ vga0_rw <= stb;
+ end
+ default: // other 6 cycles free
+ begin
+ vga0_we <= 1'b0;
+ vga0_rw <= 1'b0;
+ col_addr <= h_count[9:3];
+ row_addr <= v_count[8:4];
+ end
+ endcase
+
+ // on vdu_clk + 1 round off row address
+ // row1_addr = (row_addr % 80)
+ vga1_we <= vga0_we;
+ vga1_rw <= vga0_rw;
+ row1_addr <= (row_addr < VER_DISP_CHR) ? row_addr : row_addr - VER_DISP_CHR;
+ col1_addr <= col_addr;
+
+ // on vdu_clk + 2 calculate vertical address
+ // ver_addr = (row_addr % 80) x 5
+ vga2_we <= vga1_we;
+ vga2_rw <= vga1_rw;
+ ver_addr <= { 2'b00, row1_addr } + { row1_addr, 2'b00 }; // x5
+ hor_addr <= col1_addr;
+
+ // on vdu_clk + 3 calculate memory address
+ // vga_addr = (row_addr % 80) * 80 + hor_addr
+ buff_addr <= vga2_rw ? buff0_addr : vga_addr;
+ attr_addr <= vga2_rw ? attr0_addr : vga_addr;
+ buff_we <= vga2_rw ? (buff0_we & vga2_we) : 1'b0;
+ attr_we <= vga2_rw ? (attr0_we & vga2_we) : 1'b0;
+ vga3_rw <= vga2_rw;
+ vga4_rw <= vga3_rw;
+ vga5_rw <= vga4_rw;
+ end
+
+ // Video shift register
+ always @(posedge wb_clk_i)
+ if(wb_rst_i) begin
+ video_on <= 1'b0;
+ cursor_on <= 1'b0;
+ vga_bg_colour <= 3'b000;
+ vga_fg_colour <= 3'b111;
+ vga_shift <= 8'b00000000;
+ vga_red_o <= 1'b0;
+ vga_green_o <= 1'b0;
+ vga_blue_o <= 1'b0;
+ end
+ else begin
+ if(h_count[2:0] == 3'b000) begin
+ video_on <= video_on1;
+ cursor_on <= (cursor_on1 | attr_data_out[7]) & blink_count[22];
+ vga_fg_colour <= attr_data_out[2:0];
+ vga_bg_colour <= attr_data_out[6:4];
+ intense <= attr_data_out[3];
+ vga_shift <= char_data_out;
+ end
+ else vga_shift <= { vga_shift[6:0], 1'b0 };
+
+ // Colour mask is
+ // 7 6 5 4 3 2 1 0
+ // X BR BG BB X FR FG FB
+ vga_blue_o <= video_on ? (fg_or_bg ? { vga_fg_colour[0], intense } : { vga_bg_colour[0], 1'b0 }) : 2'b0;
+
+ // Green color exception with color brown
+ // http://en.wikipedia.org/wiki/Color_Graphics_Adapter#With_an_RGBI_monitor
+ vga_green_o <= video_on ? (fg_or_bg ? (brown_fg ? 2'b01 : { vga_fg_colour[1], intense })
+ : (brown_bg ? 2'b01 : { vga_bg_colour[1], 1'b0 })) : 2'b0;
+ vga_red_o <= video_on ? (fg_or_bg ? { vga_fg_colour[2], intense } : { vga_bg_colour[2], 1'b0 }) : 2'b0;
+ end
+endmodule
+"
+"/*
+ * Wishbone Compatible RS232 core
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module serial (
+ // Wishbone slave interface
+ input wb_clk_i, // Clock Input
+ input wb_rst_i, // Reset Input
+ input [15:0] wb_dat_i, // Command to send to mouse
+ output [15:0] wb_dat_o, // Received data
+ input wb_cyc_i, // Cycle
+ input wb_stb_i, // Strobe
+ input [ 1:0] wb_adr_i, // Wishbone address lines
+ input [ 1:0] wb_sel_i, // Wishbone Select lines
+ input wb_we_i, // Write enable
+ output reg wb_ack_o, // Normal bus termination
+ output wb_tgc_o, // Interrupt request
+
+ output rs232_tx, // RS232 output
+ input rs232_rx // RS232 input
+ );
+
+ // --------------------------------------------------------------------
+ // This section is a simple WB interface
+ // --------------------------------------------------------------------
+ reg [7:0] dat_o;
+ wire [7:0] dat_i;
+ wire [2:0] UART_Addr;
+ wire wb_ack_i;
+ wire wr_command;
+ wire rd_command;
+
+ // Unused output
+ wire rxd_endofpacket;
+
+ // --------------------------------------------------------------------
+ // Wires for Interrupt Enable Register (IER)
+ // --------------------------------------------------------------------
+ wire EDAI;
+ wire ETXH;
+ //wire ERLS = ier[2]; // Enable Receive Line Status Interrupt
+ wire EMSI;
+ wire [7:0] INTE;
+
+ // --------------------------------------------------------------------
+ // Wires for Interrupt Identification Register (IIR)
+ // --------------------------------------------------------------------
+ reg IPEN; // 0 if intereupt pending
+ reg IPEND; // Interupt pending
+ reg [1:0] INTID; // Interrupt ID Bits
+ wire [7:0] ISTAT;
+
+ // --------------------------------------------------------------------
+ // Wires for Line Status Register (LSR)
+ // --------------------------------------------------------------------
+ wire TSRE;
+ wire PE;
+ wire BI;
+ wire FE;
+ wire OR;
+ reg rx_rden; // Receive data enable
+ reg DR; // Data Ready
+ reg THRE; // Transmitter Holding Register Empty
+ wire [7:0] LSTAT;
+
+ // --------------------------------------------------------------------
+ // Wires for Modem Control Register (MCR)
+ // --------------------------------------------------------------------
+ wire DTR;
+ wire RTS;
+ wire OUT1;
+ wire OUT2;
+ wire LOOP;
+ wire [7:0] MCON;
+
+ // --------------------------------------------------------------------
+ // Wires for Modem Status Register (MSR)
+ // --------------------------------------------------------------------
+ wire RLSD;
+ wire RI;
+ wire DSR;
+ wire CTS;
+ wire DRLSD;
+ wire TERI;
+ wire DDSR;
+ wire DCTS;
+ wire [7:0] MSTAT;
+
+ // --------------------------------------------------------------------
+ // Wires for Line Control Register (LCRR)
+ // --------------------------------------------------------------------
+ wire [7:0] LCON;
+ wire dlab;
+
+ // --------------------------------------------------------------------
+ // 8250A Registers
+ // --------------------------------------------------------------------
+ wire [7:0] output_data; // Wired to receiver
+ reg [7:0] input_data; // Transmit register
+ reg [3:0] ier; // Interrupt enable register
+ reg [7:0] lcr; // Line Control register
+ reg [7:0] mcr; // Modem Control register
+ reg [7:0] dll; // Data latch register low
+ reg [7:0] dlh; // Data latch register high
+
+ // --------------------------------------------------------------------
+ // Instantiate the UART
+ // --------------------------------------------------------------------
+ //reg rx_read; // Signal to read next byte in the buffer
+ wire rx_drdy; // Indicates new data has come in
+ wire rx_idle; // Indicates Receiver is idle
+ wire rx_over; // Indicates buffer over run error
+ reg tx_send; // Signal to send data
+ wire to_error; // Indicates a transmit error occured
+ wire tx_done;
+ wire tx_busy; // Signal transmitter is busy
+
+ // --------------------------------------------------------------------
+ // Baud Clock Generator
+ // --------------------------------------------------------------------
+ wire [18:0] Baudiv;
+ wire Baud1Tick;
+ wire Baud8Tick;
+ reg [18:0] BaudAcc1;
+ reg [15:0] BaudAcc8;
+ wire [18:0] BaudInc;
+
+ always @(posedge wb_clk_i or posedge wb_rst_i) begin // Synchrounous
+ if (wb_rst_i) wb_ack_o <= 1'b0;
+ else wb_ack_o <= wb_ack_i & ~wb_ack_o; // one clock delay on acknowledge output
+ end
+
+ // --------------------------------------------------------------------
+ // This section is a simple 8250 Emulator that front ends the UART
+ // --------------------------------------------------------------------
+
+ // --------------------------------------------------------------------
+ // Register addresses and defaults
+ // --------------------------------------------------------------------
+ `define UART_RG_TR 3'h0 // RW - Transmit / Receive register
+ `define UART_RG_IE 3'h1 // RW - Interrupt enable
+ `define UART_RG_II 3'h2 // R - Interrupt identification (no fifo on 8250)
+ `define UART_RG_LC 3'h3 // RW - Line Control
+ `define UART_RG_MC 3'h4 // W - Modem control
+ `define UART_RG_LS 3'h5 // R - Line status
+ `define UART_RG_MS 3'h6 // R - Modem status
+ `define UART_RG_SR 3'h7 // RW - Scratch register
+
+ `define UART_DL_LSB 8'h60 // Divisor latch least significant byte, hard coded to 9600 baud
+ `define UART_DL_MSB 8'h00 // Divisor latch most significant byte
+ `define UART_IE_DEF 8'h00 // Interupt Enable default
+ `define UART_LC_DEF 8'h03 // Line Control default
+ `define UART_MC_DEF 8'h00 // Line Control default
+
+ // --------------------------------------------------------------------
+ // UART Interrupt Behavior
+ // --------------------------------------------------------------------
+ always @(posedge wb_clk_i or posedge wb_rst_i) begin // Synchrounous
+ if(wb_rst_i) begin
+ IPEN <= 1'b1; // Interupt Enable default
+ IPEND <= 1'b0; // Interupt pending
+ INTID <= 2'b00; // Interupt ID
+ end
+ else begin
+ if(DR & EDAI) begin // If enabled
+ IPEN <= 1'b0; // Set latch (inverted)
+ IPEND <= 1'b1; // Indicates an Interupt is pending
+ INTID <= 2'b10; // Set Interupt ID
+ end
+
+ if(THRE & ETXH) begin // If enabled
+ IPEN <= 1'b0; // Set latch (inverted)
+ IPEND <= 1'b1; // Indicates an Interupt is pending
+ INTID <= 2'b01; // Set Interupt ID
+ end
+
+ if((CTS | DSR | RI |RLSD) && EMSI) begin // If enabled
+ IPEN <= 1'b0; // Set latch (inverted)
+ IPEND <= 1'b1; // Indicates an Interupt is pending
+ INTID <= 2'b00; // Interupt ID
+ end
+
+ if(rd_command) // If a read was requested
+ case(UART_Addr) // Determine which register was read
+ `UART_RG_TR: IPEN <= 1'b1; // Resets interupt flag
+ `UART_RG_II: IPEN <= 1'b1; // Resets interupt flag
+ `UART_RG_MS: IPEN <= 1'b1; // Resets interupt flag
+ default: ; // Do nothing if anything else
+ endcase // End of case
+
+ if(wr_command) // If a write was requested
+ case(UART_Addr) // Determine which register was writen to
+ `UART_RG_TR: IPEN <= 1'b1; // Resets interupt flag;
+ default: ; // Do nothing if anything else
+ endcase // End of case
+
+ if(IPEN & IPEND) begin
+ INTID <= 2'b00; // user has cleared the Interupt
+ IPEND <= 1'b0; // Interupt pending
+ end
+ end
+ end // Synchrounous always
+
+ // --------------------------------------------------------------------
+ // UART Line Status Behavior
+ // --------------------------------------------------------------------
+ always @(posedge wb_clk_i or posedge wb_rst_i) begin // Synchrounous
+ if(wb_rst_i) begin
+ // rx_read <= 1'b0; // Singal to get the data out of the buffer
+ rx_rden <= 1'b1; // Singal to get the data out of the buffer
+ DR <= 1'b0; // Indicates data is waiting to be read
+ THRE <= 1'b0; // Transmitter holding register is empty
+ end
+ else begin
+ if(rx_drdy) begin // If enabled
+ DR <= 1'b1; // Indicates data is waiting to be read
+ if(rx_rden) /*rx_read <= 1'b1*/; // If reading enabled, request another byte
+ else begin // of data out of the buffer, else..
+ //rx_read <= 1'b0; // on next clock, do not request anymore
+ rx_rden <= 1'b0; // block your fifo from reading
+ end // until ready
+ end
+
+ if(tx_done) begin // If enabled
+ THRE <= 1'b1; // Transmitter holding register is empty
+ end
+
+ if(IPEN && IPEND) begin // If the user has cleared the and there is not one pending
+ rx_rden <= 1'b1; // User has digested that byte, now enable reading some more
+ DR <= 1'b0; // interrupt, then clear
+ THRE <= 1'b0; // the flags in the Line status register
+ end
+ end
+ end
+
+ // --------------------------------------------------------------------
+ // UART Register behavior
+ // --------------------------------------------------------------------
+ always @(posedge wb_clk_i or posedge wb_rst_i) begin // Synchrounous
+ if(wb_rst_i) begin
+ dat_o <= 8'h00; // Default value
+ end
+ else
+ if(rd_command) begin
+ case(UART_Addr) // Determine which register was read
+ `UART_RG_TR: dat_o <= dlab ? dll : output_data;
+ `UART_RG_IE: dat_o <= dlab ? dlh : INTE;
+ `UART_RG_II: dat_o <= ISTAT; // Interupt ID
+ `UART_RG_LC: dat_o <= LCON; // Line control
+ `UART_RG_MC: dat_o <= MCON; // Modem Control Register
+ `UART_RG_LS: dat_o <= LSTAT; // Line status
+ `UART_RG_MS: dat_o <= MSTAT; // Modem Status
+ `UART_RG_SR: dat_o <= 8'h00; // No Scratch register
+ default: dat_o <= 8'h00; // Default
+ endcase // End of case
+ end
+ end // Synchrounous always
+
+ always @(posedge wb_clk_i or posedge wb_rst_i) begin // Synchrounous
+ if(wb_rst_i) begin
+ dll <= `UART_DL_LSB; // Set default to 9600 baud
+ dlh <= `UART_DL_MSB; // Set default to 9600 baud
+ ier <= 4'h01; // Interupt Enable default
+ lcr <= 8'h03; // Default value
+ mcr <= 8'h00; // Default value
+ end
+ else if(wr_command) begin // If a write was requested
+ case(UART_Addr) // Determine which register was writen to
+ `UART_RG_TR: if(dlab) dll <= dat_i; else input_data <= dat_i;
+ `UART_RG_IE: if(dlab) dlh <= dat_i; else ier <= dat_i[3:0];
+ `UART_RG_II: ; // Read only register
+ `UART_RG_LC: lcr <= dat_i; // Line Control
+ `UART_RG_MC: mcr <= dat_i; // Modem Control Register
+ `UART_RG_LS: ; // Read only register
+ `UART_RG_MS: ; // Read only register
+ `UART_RG_SR: ; // No scratch register
+ default: ; // Default
+ endcase // End of case
+ end
+ end // Synchrounous always
+
+ // --------------------------------------------------------------------
+ // Transmit behavior
+ // --------------------------------------------------------------------
+ always @(posedge wb_clk_i or posedge wb_rst_i) begin // Synchrounous
+ if(wb_rst_i) tx_send <= 1'b0; // Default value
+ else tx_send <= (wr_command && (UART_Addr == `UART_RG_TR) && !dlab);
+ end // Synchrounous always
+
+ serial_arx arx (
+ .clk (wb_clk_i),
+ .baud8tick (Baud8Tick),
+ .rxd (rs232_rx),
+ .rxd_data_ready (rx_drdy),
+ .rxd_data (output_data),
+ .rxd_endofpacket (rxd_endofpacket),
+ .rxd_idle (rx_idle)
+ );
+
+ serial_atx atx (
+ .clk (wb_clk_i),
+ .baud1tick (Baud1Tick),
+ .txd (rs232_tx),
+ .txd_start (tx_send),
+ .txd_data (input_data),
+ .txd_busy (tx_busy)
+ );
+
+ // --------------------------------------------------------------------
+ // 1.8432Mhz Baud Clock Generator:
+ // This module generates the standard 1.8432Mhz Baud Clock. Using this clock
+ // The Baud Rate Generator below can then derive all the standard
+ // Bauds. Make the accumulator 1 more bit for carry out than what is
+ // Needed. Example: Main Clock = 12.5Mhz = 12,500,000 Hence
+ // 1024/151 = 6.78, => 12,500,000 / 6.78 = 1,843,261.72 , .003% error, Good !
+ // so the accumulator should be 11 bits (log2(1024) +1
+ //
+ // --------------------------------------------------------------------
+ // Baud Rate Generator:
+ // Once we have our little 1.8432Mhz Baud Clock, deriving the bauds is
+ // simple simon. Just divide by 16 to get the 1x baud for transmitting
+ // and divide by 2 to get the 8x oversampling clock for receiving.
+ //
+ // Baud Clock = 1.8432Mhz
+ // Divisor = 16
+ //
+ // Baud Divsr %Error
+ // ------ ----- -----
+ // 50 2304 0.000%
+ // 75 1536 0.000%
+ // 110 1047 0.026%
+ // 150 768 0.000%
+ // 300 384 0.000%
+ // 600 192 0.000%
+ // 1200 96 0.000%
+ // 2400 48 0.000%
+ // 4800 24 0.000%
+ // 7200 16 0.000%
+ // 9600 12 0.000%
+ // 14400 8 0.000%
+ // 19200 6 0.000%
+ // 28800 4 0.000%
+ // 38400 3 0.000%
+ // 57600 2 0.000%
+ // 115200 1 0.000%
+ //
+ // --------------------------------------------------------------------
+
+ always @(posedge wb_clk_i)
+ BaudAcc1 <= {1'b0, BaudAcc1[17:0]} + BaudInc;
+ always @(posedge wb_clk_i)
+ BaudAcc8 <= {1'b0, BaudAcc8[14:0]} + BaudInc[15:0];
+
+ // Combinatorial logic
+ assign dat_i = wb_sel_i[0] ? wb_dat_i[7:0] : wb_dat_i[15:8]; // 8 to 16 bit WB
+ assign wb_dat_o = wb_sel_i[0] ? {8'h00, dat_o} : {dat_o, 8'h00}; // 8 to 16 bit WB
+ assign UART_Addr = {wb_adr_i, wb_sel_i[1]}; // Computer UART Address
+ assign wb_ack_i = wb_stb_i & wb_cyc_i; // Immediate ack
+ assign wr_command = wb_ack_i & wb_we_i; // WISHBONE write access, Singal to send
+ assign rd_command = wb_ack_i & ~wb_we_i; // WISHBONE write access, Singal to send
+ assign wb_tgc_o = ~IPEN; // If ==0 - new data has been received
+
+ assign EDAI = ier[0]; // Enable Data Available Interrupt
+ assign ETXH = ier[1]; // Enable Tx Holding Register Empty Interrupt
+ assign EMSI = ier[3]; // Enable Modem Status Interrupt
+ assign INTE = {4'b0000, ier};
+ assign ISTAT = { 5'b0000_0,INTID,IPEN};
+ assign TSRE = tx_done; // Tx Shift Register Empty
+ assign PE = 1'b0; // Parity Error
+ assign BI = 1'b0; // Break Interrupt, hard coded off
+ assign FE = to_error; // Framing Error, hard coded off
+ assign OR = rx_over; // Overrun Error, hard coded off
+ assign LSTAT = {1'b0,TSRE,THRE,BI,FE,PE,OR,DR};
+
+ assign DTR = mcr[0];
+ assign RTS = mcr[1];
+ assign OUT1 = mcr[2];
+ assign OUT2 = mcr[3];
+ assign LOOP = mcr[4];
+ assign MCON = {3'b000, mcr[4:0]};
+ assign RLSD = LOOP ? OUT2 : 1'b0; // Received Line Signal Detect
+ assign RI = LOOP ? OUT1 : 1'b1; // Ring Indicator
+ assign DSR = LOOP ? DTR : 1'b0; // Data Set Ready
+ assign CTS = LOOP ? RTS : 1'b0; // Clear To Send
+ assign DRLSD = 1'b0; // Delta Rx Line Signal Detect
+ assign TERI = 1'b0; // Trailing Edge Ring Indicator
+ assign DDSR = 1'b0; // Delta Data Set Ready
+ assign DCTS = 1'b0; // Delta Clear to Send
+ assign MSTAT = {RLSD,RI,DSR,CTS,DCTS,DDSR,TERI,DRLSD};
+
+ assign LCON = lcr; // Data Latch Address Bit
+ assign dlab = lcr[7]; // Data Latch Address Bit
+ assign tx_done = ~tx_busy; // Signal command finished sending
+ assign rx_over = 1'b0;
+ assign to_error = 1'b0;
+
+ assign Baudiv = {3'b000,dlh,dll};
+ assign Baud1Tick = BaudAcc1[18];
+ assign BaudInc = 19'd2416/Baudiv;
+
+endmodule
+"
+"/*
+ * Milkymist VJ SoC
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+module csrbrg(
+\tinput sys_clk,
+\tinput sys_rst,
+\t
+\t/* WB */
+\tinput [3:1] wb_adr_i,
+\tinput [15:0] wb_dat_i,
+\toutput reg [15:0] wb_dat_o,
+\tinput wb_cyc_i,
+\tinput wb_stb_i,
+\tinput wb_we_i,
+\toutput reg wb_ack_o,
+\t
+\t/* CSR */
+\toutput reg [2:0] csr_a,
+\toutput reg csr_we,
+\toutput reg [15:0] csr_do,
+\tinput [15:0] csr_di
+);
+
+/* Datapath: WB <- CSR */
+always @(posedge sys_clk) begin
+\twb_dat_o <= csr_di;
+end
+
+/* Datapath: CSR -> WB */
+reg next_csr_we;
+always @(posedge sys_clk) begin
+\tcsr_a <= wb_adr_i[3:1];
+\tcsr_we <= next_csr_we;
+\tcsr_do <= wb_dat_i;
+end
+
+/* Controller */
+
+reg [1:0] state;
+reg [1:0] next_state;
+
+parameter IDLE\t\t= 2'd0;
+parameter DELAYACK1\t= 2'd1;
+parameter DELAYACK2\t= 2'd2;
+parameter ACK\t\t= 2'd3;
+
+always @(posedge sys_clk) begin
+\tif(sys_rst)
+\t\tstate <= IDLE;
+\telse
+\t\tstate <= next_state;
+end
+
+always @(*) begin
+\tnext_state = state;
+\t
+\twb_ack_o = 1'b0;
+\tnext_csr_we = 1'b0;
+\t
+\tcase(state)
+\t\tIDLE: begin
+\t\t\tif(wb_cyc_i & wb_stb_i) begin
+\t\t\t\t/* We have a request for us */
+\t\t\t\tnext_csr_we = wb_we_i;
+\t\t\t\tif(wb_we_i)
+\t\t\t\t\tnext_state = ACK;
+\t\t\t\telse
+\t\t\t\t\tnext_state = DELAYACK1;
+\t\t\tend
+\t\tend
+\t\tDELAYACK1: next_state = DELAYACK2;
+\t\tDELAYACK2: next_state = ACK;
+\t\tACK: begin
+\t\t\twb_ack_o = 1'b1;
+\t\t\tnext_state = IDLE;
+\t\tend
+\tendcase
+end
+
+endmodule
+"
+"// --------------------------------------------------------------------
+// Copyright (c) 2005 by Terasic Technologies Inc.
+// --------------------------------------------------------------------
+//
+// Permission:
+//
+// Terasic grants permission to use and modify this code for use
+// in synthesis for all Terasic Development Boards and Altrea Development
+// Kits made by Terasic. Other use of this code, including the selling
+// ,duplication, or modification of any portion is strictly prohibited.
+//
+// Disclaimer:
+//
+// This VHDL or Verilog source code is intended as a design reference
+// which illustrates how these types of functions can be implemented.
+// It is the user's responsibility to verify their design for
+// consistency and functionality through the use of formal
+// verification methods. Terasic provides no warranty regarding the use
+// or functionality of this code.
+//
+// --------------------------------------------------------------------
+//
+// Terasic Technologies Inc
+// 356 Fu-Shin E. Rd Sec. 1. JhuBei City,
+// HsinChu County, Taiwan
+// 302
+//
+// web: http://www.terasic.com/
+// email: support@terasic.com
+//
+// --------------------------------------------------------------------
+
+//`define I2C_VIDEO
+
+module speaker_i2c_av_config ( // Host Side
+ clk_i,
+ rst_i,
+ // I2C Side
+ i2c_sclk,
+ i2c_sdat );
+// Host Side
+input clk_i;
+input rst_i;
+// I2C Side
+output i2c_sclk;
+inout i2c_sdat;
+// Internal Registers/Wires
+reg [15:0] mI2C_CLK_DIV;
+reg [23:0] mI2C_DATA;
+reg mI2C_CTRL_CLK;
+reg mI2C_GO;
+wire mI2C_END;
+wire mI2C_ACK;
+reg [15:0] LUT_DATA;
+reg [5:0] LUT_INDEX;
+reg [3:0] mSetup_ST;
+
+// Clock Setting
+parameter CLK_Freq = 25000000; // 25 MHz
+parameter I2C_Freq = 20000; // 20 KHz
+// LUT Data Number
+`ifdef I2C_VIDEO
+parameter LUT_SIZE = 50;
+`else
+parameter LUT_SIZE = 10;
+`endif
+// Audio Data Index
+parameter SET_LIN_L = 0;
+parameter SET_LIN_R = 1;
+parameter SET_HEAD_L = 2;
+parameter SET_HEAD_R = 3;
+parameter A_PATH_CTRL = 4;
+parameter D_PATH_CTRL = 5;
+parameter POWER_ON = 6;
+parameter SET_FORMAT = 7;
+parameter SAMPLE_CTRL = 8;
+parameter SET_ACTIVE = 9;
+`ifdef I2C_VIDEO
+// Video Data Index
+parameter SET_VIDEO = 10;
+`endif
+
+///////////////////// I2C Control Clock ////////////////////////
+always@(posedge clk_i)
+begin
+ if(rst_i)
+ begin
+ mI2C_CTRL_CLK <= 0;
+ mI2C_CLK_DIV <= 0;
+ end
+ else
+ begin
+ if( mI2C_CLK_DIV < (CLK_Freq/I2C_Freq) )
+ mI2C_CLK_DIV <= mI2C_CLK_DIV+16'h1;
+ else
+ begin
+ mI2C_CLK_DIV <= 0;
+ mI2C_CTRL_CLK <= ~mI2C_CTRL_CLK;
+ end
+ end
+end
+////////////////////////////////////////////////////////////////////
+speaker_i2c_controller i2c_controller ( .CLOCK(mI2C_CTRL_CLK), // Controller Work Clock
+ .I2C_SCLK(i2c_sclk), // I2C CLOCK
+ .I2C_SDAT(i2c_sdat), // I2C DATA
+ .I2C_DATA(mI2C_DATA), // DATA:[SLAVE_ADDR,SUB_ADDR,DATA]
+ .GO(mI2C_GO), // GO transfor
+ .END(mI2C_END), // END transfor
+ .ACK(mI2C_ACK), // ACK
+ .RESET(rst_i),
+ .W_R (1'b0)
+ );
+////////////////////////////////////////////////////////////////////
+////////////////////// Config Control ////////////////////////////
+always@(posedge mI2C_CTRL_CLK)
+begin
+ if(rst_i)
+ begin
+ LUT_INDEX <= 0;
+ mSetup_ST <= 0;
+ mI2C_GO <= 0;
+ end
+ else
+ begin
+ if(LUT_INDEX=SET_VIDEO)
+ mI2C_DATA <= {8'h40,LUT_DATA};
+ else
+`endif
+ mI2C_DATA <= {8'h34,LUT_DATA};
+ mI2C_GO <= 1;
+ mSetup_ST <= 1;
+ end
+ 1: begin
+ if(mI2C_END)
+ begin
+ if(!mI2C_ACK)
+ mSetup_ST <= 2;
+ else
+ mSetup_ST <= 0;
+ mI2C_GO <= 0;
+ end
+ end
+ 2: begin
+ LUT_INDEX <= LUT_INDEX+6'h1;
+ mSetup_ST <= 0;
+ end
+ endcase
+ end
+ end
+end
+////////////////////////////////////////////////////////////////////
+///////////////////// Config Data LUT //////////////////////////
+always
+begin
+ case(LUT_INDEX)
+ // Audio Config Data
+ SET_LIN_L : LUT_DATA <= 16'h001A;
+ SET_LIN_R : LUT_DATA <= 16'h021A;
+ SET_HEAD_L : LUT_DATA <= 16'h047B;
+ SET_HEAD_R : LUT_DATA <= 16'h067B;
+ A_PATH_CTRL : LUT_DATA <= 16'h08F8;
+ D_PATH_CTRL : LUT_DATA <= 16'h0A06;
+ POWER_ON : LUT_DATA <= 16'h0C00;
+ SET_FORMAT : LUT_DATA <= 16'h0E42;
+ SAMPLE_CTRL : LUT_DATA <= 16'h107C;
+ SET_ACTIVE : LUT_DATA <= 16'h1201;
+`ifdef I2C_VIDEO
+ // Video Config Data
+ SET_VIDEO+0 : LUT_DATA <= 16'h1500;
+ SET_VIDEO+1 : LUT_DATA <= 16'h1741;
+ SET_VIDEO+2 : LUT_DATA <= 16'h3a16;
+ SET_VIDEO+3 : LUT_DATA <= 16'h5004;
+ SET_VIDEO+4 : LUT_DATA <= 16'hc305;
+ SET_VIDEO+5 : LUT_DATA <= 16'hc480;
+ SET_VIDEO+6 : LUT_DATA <= 16'h0e80;
+ SET_VIDEO+7 : LUT_DATA <= 16'h5020;
+ SET_VIDEO+8 : LUT_DATA <= 16'h5218;
+ SET_VIDEO+9 : LUT_DATA <= 16'h58ed;
+ SET_VIDEO+10: LUT_DATA <= 16'h77c5;
+ SET_VIDEO+11: LUT_DATA <= 16'h7c93;
+ SET_VIDEO+12: LUT_DATA <= 16'h7d00;
+ SET_VIDEO+13: LUT_DATA <= 16'hd048;
+ SET_VIDEO+14: LUT_DATA <= 16'hd5a0;
+ SET_VIDEO+15: LUT_DATA <= 16'hd7ea;
+ SET_VIDEO+16: LUT_DATA <= 16'he43e;
+ SET_VIDEO+17: LUT_DATA <= 16'hea0f;
+ SET_VIDEO+18: LUT_DATA <= 16'h3112;
+ SET_VIDEO+19: LUT_DATA <= 16'h3281;
+ SET_VIDEO+20: LUT_DATA <= 16'h3384;
+ SET_VIDEO+21: LUT_DATA <= 16'h37A0;
+ SET_VIDEO+22: LUT_DATA <= 16'he580;
+ SET_VIDEO+23: LUT_DATA <= 16'he603;
+ SET_VIDEO+24: LUT_DATA <= 16'he785;
+ SET_VIDEO+25: LUT_DATA <= 16'h5000;
+ SET_VIDEO+26: LUT_DATA <= 16'h5100;
+ SET_VIDEO+27: LUT_DATA <= 16'h0050;
+ SET_VIDEO+28: LUT_DATA <= 16'h1000;
+ SET_VIDEO+29: LUT_DATA <= 16'h0402;
+ SET_VIDEO+30: LUT_DATA <= 16'h0b00;
+ SET_VIDEO+31: LUT_DATA <= 16'h0a20;
+ SET_VIDEO+32: LUT_DATA <= 16'h1100;
+ SET_VIDEO+33: LUT_DATA <= 16'h2b00;
+ SET_VIDEO+34: LUT_DATA <= 16'h2c8c;
+ SET_VIDEO+35: LUT_DATA <= 16'h2df2;
+ SET_VIDEO+36: LUT_DATA <= 16'h2eee;
+ SET_VIDEO+37: LUT_DATA <= 16'h2ff4;
+ SET_VIDEO+38: LUT_DATA <= 16'h30d2;
+ SET_VIDEO+39: LUT_DATA <= 16'h0e05;
+`endif
+ default: LUT_DATA <= 16'h0000;
+ endcase
+end
+////////////////////////////////////////////////////////////////////
+endmodule"
+"/*
+ * Copyright (c) 2009 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`timescale 1ns/10ps
+
+module test_sdspi (
+ input clk_50_,
+ input sw0_,
+ output reg [7:0] ledg_,
+
+ // SD card signals
+ output sd_sclk_,
+ input sd_miso_,
+ output sd_mosi_,
+ output sd_ss_
+ );
+
+ // Registers and nets
+ wire clk;
+ wire sys_clk;
+ reg [1:0] clk_div;
+ wire lock;
+ wire rst;
+ reg [8:0] dat_i;
+ wire [7:0] dat_o;
+ reg we;
+ reg [1:0] sel;
+ reg stb;
+ wire ack;
+
+ reg [7:0] st;
+ reg [7:0] cnt;
+
+ // Module instantiations
+ pll pll (
+ .inclk0 (clk_50_),
+ .c2 (sys_clk),
+ .locked (lock)
+ );
+
+ sdspi sdspi (
+ // Serial pad signal
+ .sclk (sd_sclk_),
+ .miso (sd_miso_),
+ .mosi (sd_mosi_),
+ .ss (sd_ss_),
+
+ // Wishbone slave interface
+ .wb_clk_i (clk),
+ .wb_rst_i (rst),
+ .wb_dat_i (dat_i),
+ .wb_dat_o (dat_o),
+ .wb_we_i (we),
+ .wb_sel_i (sel),
+ .wb_stb_i (stb),
+ .wb_cyc_i (stb),
+ .wb_ack_o (ack)
+ );
+
+ // Continuous assignments
+ assign clk = clk_div[1];
+ assign rst = sw0_ | !lock;
+
+ // Behaviour
+ always @(posedge clk)
+ if (rst)
+ begin
+ dat_i <= 9'h0;
+ we <= 1'b0;
+ sel <= 2'b00;
+ stb <= 1'b0;
+ st <= 8'h0;
+ cnt <= 8'd90;
+ end
+ else
+ case (st)
+ 8'h0:
+ begin
+ dat_i <= 9'hff;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h1;
+ end
+ 8'h1:
+ if (ack) begin
+ dat_i <= 9'hff;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= (cnt==8'd0) ? 8'h2 : 8'h1;
+ cnt <= cnt - 8'd1;
+ end
+ 8'h2:
+ if (ack) begin
+ dat_i <= 9'h0ff;
+ we <= 1'b1;
+ sel <= 2'b11;
+ stb <= 1'b1;
+ st <= 8'h3;
+ end
+ 8'h3:
+ if (ack) begin
+ dat_i <= 9'h40;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h4;
+ end
+ 8'h4:
+ if (ack) begin
+ dat_i <= 9'h00;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h5;
+ end
+ 8'h5:
+ if (ack) begin
+ dat_i <= 9'h00;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h6;
+ end
+ 8'h6:
+ if (ack) begin
+ dat_i <= 9'h00;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h7;
+ end
+ 8'h7:
+ if (ack) begin
+ dat_i <= 9'h00;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h8;
+ end
+ 8'h8:
+ if (ack) begin
+ dat_i <= 9'h95;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h49;
+ end
+ 8'h49:
+ if (ack) begin
+ dat_i <= 9'h95;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b0;
+ st <= 8'h50;
+ cnt <= 8'd4;
+ end
+ 8'h50:
+ begin
+ dat_i <= 9'h95;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b0;
+ st <= (cnt==8'd0) ? 8'h9 : 8'h50;
+ cnt <= cnt - 8'd1;
+ end
+ 8'h9:
+ begin
+ dat_i <= 9'hff;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'h52;
+ end
+ 8'h52:
+ if (ack) begin
+ dat_i <= 9'h95;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b0;
+ st <= 8'h53;
+ cnt <= 8'd7;
+ end
+ 8'h53:
+ begin
+ dat_i <= 9'h95;
+ we <= 1'b1;
+ sel <= 2'b01;
+ stb <= 1'b0;
+ st <= (cnt==8'd0) ? 8'd10 : 8'h53;
+ cnt <= cnt - 8'd1;
+ end
+ 8'd10:
+ begin
+ dat_i <= 9'hff;
+ we <= 1'b0;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'd11;
+ end
+ 8'd11:
+ if (ack) begin
+ dat_i <= 9'hff;
+ we <= 1'b0;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'd12;
+ end
+ 8'd12:
+ if (ack) begin
+ dat_i <= 9'hff;
+ we <= 1'b0;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'd13;
+ end
+ 8'd13:
+ if (ack) begin
+ dat_i <= 9'hff;
+ we <= 1'b0;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'd14;
+ end
+ 8'd14:
+ if (ack) begin
+ dat_i <= 9'hff;
+ we <= 1'b0;
+ sel <= 2'b01;
+ stb <= 1'b1;
+ st <= 8'd15;
+ end
+ endcase
+/*
+ always #5 clk <= !clk;
+
+ initial
+ begin
+ clk <= 1'b0;
+ rst <= 1'b1;
+ miso <= 1'b1;
+
+ #100 rst <= 1'b0;
+
+ #935 miso <= 1'b0;
+ #10 miso <= 1'b0;
+ #10 miso <= 1'b0;
+ #10 miso <= 1'b0;
+ #10 miso <= 1'b0;
+ #10 miso <= 1'b0;
+ #10 miso <= 1'b0;
+ #10 miso <= 1'b1;
+ end
+ */
+
+ // clk_div
+ always @(posedge sys_clk) clk_div <= clk_div + 2'd1;
+
+endmodule
+"
+"/*
+ * Copyright (c) 2009 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module seg_7 (
+ input [3:0] num,
+ input en,
+ output reg [6:0] seg
+ );
+
+ // Behaviour
+ always @(num or en)
+ if (!en) seg <= 7'h3f;
+ else
+ case (num)
+ 4'h0: seg <= {1'b1,1'b0,1'b0,1'b0,1'b0,1'b0,1'b0};
+ 4'h1: seg <= {1'b1,1'b1,1'b1,1'b1,1'b0,1'b0,1'b1};
+ 4'h2: seg <= {1'b0,1'b1,1'b0,1'b0,1'b1,1'b0,1'b0};
+ 4'h3: seg <= {1'b0,1'b1,1'b1,1'b0,1'b0,1'b0,1'b0};
+ 4'h4: seg <= {1'b0,1'b0,1'b1,1'b1,1'b0,1'b0,1'b1};
+ 4'h5: seg <= {1'b0,1'b0,1'b1,1'b0,1'b0,1'b1,1'b0};
+ 4'h6: seg <= {1'b0,1'b0,1'b0,1'b0,1'b0,1'b1,1'b0};
+ 4'h7: seg <= {1'b1,1'b1,1'b1,1'b1,1'b0,1'b0,1'b0};
+ 4'h8: seg <= {1'b0,1'b0,1'b0,1'b0,1'b0,1'b0,1'b0};
+ 4'h9: seg <= {1'b0,1'b0,1'b1,1'b0,1'b0,1'b0,1'b0};
+ 4'ha: seg <= {1'b0,1'b0,1'b0,1'b1,1'b0,1'b0,1'b0};
+ 4'hb: seg <= {1'b0,1'b0,1'b0,1'b0,1'b0,1'b1,1'b1};
+ 4'hc: seg <= {1'b0,1'b1,1'b0,1'b0,1'b1,1'b1,1'b1};
+ 4'hd: seg <= {1'b0,1'b1,1'b0,1'b0,1'b0,1'b0,1'b1};
+ 4'he: seg <= {1'b0,1'b0,1'b0,1'b0,1'b1,1'b1,1'b0};
+ 4'hf: seg <= {1'b0,1'b0,1'b0,1'b1,1'b1,1'b1,1'b0};
+ endcase
+
+endmodule
+"
+"/*
+ * This module sends commands to the PS2 interface
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module ps2_mouse_cmdout (
+ input clk,
+ input reset,
+ input [7:0] the_command,
+ input send_command,
+ input ps2_clk_posedge,
+ input ps2_clk_negedge,
+ input inhibit,
+ inout ps2_clk,
+ inout ps2_dat,
+ output reg command_was_sent,
+ output reg error_communication_timed_out
+ );
+
+ // --------------------------------------------------------------------
+ // Parameter Declarations , 1/12.5mhz => 0.08us
+ // --------------------------------------------------------------------
+ parameter CLOCK_CYCLES_FOR_101US = 1262; // Timing info for initiating
+ parameter NUMBER_OF_BITS_FOR_101US = 13; // Host-to-Device communication
+ parameter COUNTER_INCREMENT_FOR_101US = 13'h0001; // when using a 12.5MHz system clock
+ parameter CLOCK_CYCLES_FOR_15MS = 187500; // Timing info for start of
+ parameter NUMBER_OF_BITS_FOR_15MS = 20; // transmission error when
+ parameter COUNTER_INCREMENT_FOR_15MS = 20'h00001; // using a 12.5MHz system clock
+ parameter CLOCK_CYCLES_FOR_2MS = 25000; // Timing info for sending
+ parameter NUMBER_OF_BITS_FOR_2MS = 17; // data error when
+ parameter COUNTER_INCREMENT_FOR_2MS = 17'h00001; // using a 12.5MHz system clock
+
+ // --------------------------------------------------------------------
+ // Constant Declarations
+ // --------------------------------------------------------------------
+ parameter PS2_STATE_0_IDLE = 3'h0,
+ PS2_STATE_1_INITIATE_COMMUNICATION = 3'h1,
+ PS2_STATE_2_WAIT_FOR_CLOCK = 3'h2,
+ PS2_STATE_3_TRANSMIT_DATA = 3'h3,
+ PS2_STATE_4_TRANSMIT_STOP_BIT = 3'h4,
+ PS2_STATE_5_RECEIVE_ACK_BIT = 3'h5,
+ PS2_STATE_6_COMMAND_WAS_SENT = 3'h6,
+ PS2_STATE_7_TRANSMISSION_ERROR = 3'h7;
+
+ // --------------------------------------------------------------------
+ // Internal wires and registers Declarations
+ // --------------------------------------------------------------------
+ reg [3:0] cur_bit; // Internal Registers
+ reg [8:0] ps2_command;
+
+ reg [NUMBER_OF_BITS_FOR_101US:1] command_initiate_counter;
+
+ reg [NUMBER_OF_BITS_FOR_15MS:1] waiting_counter;
+ reg [NUMBER_OF_BITS_FOR_2MS:1] transfer_counter;
+
+ reg [2:0] ns_ps2_transmitter; // State Machine Registers
+ reg [2:0] s_ps2_transmitter;
+
+ // --------------------------------------------------------------------
+ // Finite State Machine(s)
+ // --------------------------------------------------------------------
+ always @(posedge clk) begin
+ if(reset == 1'b1) s_ps2_transmitter <= PS2_STATE_0_IDLE;
+ else s_ps2_transmitter <= ns_ps2_transmitter;
+ end
+
+ always @(*) begin // Defaults
+ ns_ps2_transmitter = PS2_STATE_0_IDLE;
+
+ case (s_ps2_transmitter)
+ PS2_STATE_0_IDLE:
+ begin
+ if (send_command == 1'b1) ns_ps2_transmitter = PS2_STATE_1_INITIATE_COMMUNICATION;
+ else ns_ps2_transmitter = PS2_STATE_0_IDLE;
+ end
+ PS2_STATE_1_INITIATE_COMMUNICATION:
+ begin
+ if (command_initiate_counter == CLOCK_CYCLES_FOR_101US)
+ ns_ps2_transmitter = PS2_STATE_2_WAIT_FOR_CLOCK;
+ else
+ ns_ps2_transmitter = PS2_STATE_1_INITIATE_COMMUNICATION;
+ end
+ PS2_STATE_2_WAIT_FOR_CLOCK:
+ begin
+ if (ps2_clk_negedge == 1'b1)
+ ns_ps2_transmitter = PS2_STATE_3_TRANSMIT_DATA;
+ else if (waiting_counter == CLOCK_CYCLES_FOR_15MS)
+ ns_ps2_transmitter = PS2_STATE_7_TRANSMISSION_ERROR;
+ else
+ ns_ps2_transmitter = PS2_STATE_2_WAIT_FOR_CLOCK;
+ end
+ PS2_STATE_3_TRANSMIT_DATA:
+ begin
+ if ((cur_bit == 4'd8) && (ps2_clk_negedge == 1'b1))
+ ns_ps2_transmitter = PS2_STATE_4_TRANSMIT_STOP_BIT;
+ else if (transfer_counter == CLOCK_CYCLES_FOR_2MS)
+ ns_ps2_transmitter = PS2_STATE_7_TRANSMISSION_ERROR;
+ else
+ ns_ps2_transmitter = PS2_STATE_3_TRANSMIT_DATA;
+ end
+ PS2_STATE_4_TRANSMIT_STOP_BIT:
+ begin
+ if (ps2_clk_negedge == 1'b1)
+ ns_ps2_transmitter = PS2_STATE_5_RECEIVE_ACK_BIT;
+ else if (transfer_counter == CLOCK_CYCLES_FOR_2MS)
+ ns_ps2_transmitter = PS2_STATE_7_TRANSMISSION_ERROR;
+ else
+ ns_ps2_transmitter = PS2_STATE_4_TRANSMIT_STOP_BIT;
+ end
+ PS2_STATE_5_RECEIVE_ACK_BIT:
+ begin
+ if (ps2_clk_posedge == 1'b1)
+ ns_ps2_transmitter = PS2_STATE_6_COMMAND_WAS_SENT;
+ else if (transfer_counter == CLOCK_CYCLES_FOR_2MS)
+ ns_ps2_transmitter = PS2_STATE_7_TRANSMISSION_ERROR;
+ else
+ ns_ps2_transmitter = PS2_STATE_5_RECEIVE_ACK_BIT;
+ end
+ PS2_STATE_6_COMMAND_WAS_SENT:
+ begin
+ if (send_command == 1'b0)
+ ns_ps2_transmitter = PS2_STATE_0_IDLE;
+ else
+ ns_ps2_transmitter = PS2_STATE_6_COMMAND_WAS_SENT;
+ end
+ PS2_STATE_7_TRANSMISSION_ERROR:
+ begin
+ if (send_command == 1'b0)
+ ns_ps2_transmitter = PS2_STATE_0_IDLE;
+ else
+ ns_ps2_transmitter = PS2_STATE_7_TRANSMISSION_ERROR;
+ end
+ default:
+ begin
+ ns_ps2_transmitter = PS2_STATE_0_IDLE;
+ end
+ endcase
+ end
+
+ // --------------------------------------------------------------------
+ // Sequential logic
+ // --------------------------------------------------------------------
+ always @(posedge clk) begin
+ if(reset == 1'b1) ps2_command <= 9'h000;
+ else if(s_ps2_transmitter == PS2_STATE_0_IDLE)
+ ps2_command <= {(^the_command) ^ 1'b1, the_command};
+ end
+
+ always @(posedge clk) begin
+ if(reset == 1'b1) command_initiate_counter <= {NUMBER_OF_BITS_FOR_101US{1'b0}};
+ else if((s_ps2_transmitter == PS2_STATE_1_INITIATE_COMMUNICATION) &&
+ (command_initiate_counter != CLOCK_CYCLES_FOR_101US))
+ command_initiate_counter <=
+ command_initiate_counter + COUNTER_INCREMENT_FOR_101US;
+ else if(s_ps2_transmitter != PS2_STATE_1_INITIATE_COMMUNICATION)
+ command_initiate_counter <= {NUMBER_OF_BITS_FOR_101US{1'b0}};
+ end
+
+ always @(posedge clk) begin
+ if(reset == 1'b1) waiting_counter <= {NUMBER_OF_BITS_FOR_15MS{1'b0}};
+ else if((s_ps2_transmitter == PS2_STATE_2_WAIT_FOR_CLOCK) &&
+ (waiting_counter != CLOCK_CYCLES_FOR_15MS))
+ waiting_counter <= waiting_counter + COUNTER_INCREMENT_FOR_15MS;
+ else if(s_ps2_transmitter != PS2_STATE_2_WAIT_FOR_CLOCK)
+ waiting_counter <= {NUMBER_OF_BITS_FOR_15MS{1'b0}};
+ end
+
+ always @(posedge clk) begin
+ if(reset == 1'b1) transfer_counter <= {NUMBER_OF_BITS_FOR_2MS{1'b0}};
+ else begin
+ if((s_ps2_transmitter == PS2_STATE_3_TRANSMIT_DATA) ||
+ (s_ps2_transmitter == PS2_STATE_4_TRANSMIT_STOP_BIT) ||
+ (s_ps2_transmitter == PS2_STATE_5_RECEIVE_ACK_BIT))
+ begin
+ if(transfer_counter != CLOCK_CYCLES_FOR_2MS)
+ transfer_counter <= transfer_counter + COUNTER_INCREMENT_FOR_2MS;
+ end
+ else transfer_counter <= {NUMBER_OF_BITS_FOR_2MS{1'b0}};
+ end
+ end
+
+ always @(posedge clk) begin
+ if(reset == 1'b1) cur_bit <= 4'h0;
+ else if((s_ps2_transmitter == PS2_STATE_3_TRANSMIT_DATA) &&
+ (ps2_clk_negedge == 1'b1))
+ cur_bit <= cur_bit + 4'h1;
+ else if(s_ps2_transmitter != PS2_STATE_3_TRANSMIT_DATA)
+ cur_bit <= 4'h0;
+ end
+
+ always @(posedge clk) begin
+ if(reset == 1'b1) command_was_sent <= 1'b0;
+ else if(s_ps2_transmitter == PS2_STATE_6_COMMAND_WAS_SENT)
+ command_was_sent <= 1'b1;
+ else if(send_command == 1'b0) command_was_sent <= 1'b0;
+ end
+
+ always @(posedge clk) begin
+ if(reset == 1'b1) error_communication_timed_out <= 1'b0;
+ else if(s_ps2_transmitter == PS2_STATE_7_TRANSMISSION_ERROR)
+ error_communication_timed_out <= 1'b1;
+ else if(send_command == 1'b0)
+ error_communication_timed_out <= 1'b0;
+ end
+
+ // --------------------------------------------------------------------
+ // Combinational logic
+ // --------------------------------------------------------------------
+ assign ps2_clk = (s_ps2_transmitter == PS2_STATE_1_INITIATE_COMMUNICATION || inhibit) ? 1'b0 : 1'bz;
+
+ assign ps2_dat = (s_ps2_transmitter == PS2_STATE_3_TRANSMIT_DATA) ? ps2_command[cur_bit] :
+ (s_ps2_transmitter == PS2_STATE_2_WAIT_FOR_CLOCK) ? 1'b0 :
+ ((s_ps2_transmitter == PS2_STATE_1_INITIATE_COMMUNICATION) &&
+ (command_initiate_counter[NUMBER_OF_BITS_FOR_101US] == 1'b1)) ? 1'b0 : 1'bz;
+
+endmodule
+
+"
+"/*
+ * Bitwise 8 and 16 bit shifter and rotator for Zet
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_shrot (
+ input [15:0] x,
+ input [ 7:0] y,
+ output [15:0] out,
+ input [ 2:0] func, // 0: rol, 1: ror, 2: rcl, 3: rcr,
+ // 4: shl/sal, 5: shr, 6: sar
+ input word_op,
+ input cfi,
+ input ofi,
+ output cfo,
+ output ofo
+ );
+
+ // Net declarations
+ wire [4:0] ror16;
+ wire [4:0] rol16;
+ wire [4:0] rcr16;
+ wire [4:0] rcl16;
+ wire [4:0] rot16;
+
+ wire [15:0] sal;
+ wire [15:0] sar;
+ wire [15:0] shr;
+ wire [15:0] sal16;
+ wire [15:0] sar16;
+ wire [15:0] shr16;
+
+ wire [7:0] sal8;
+ wire [7:0] sar8;
+ wire [7:0] shr8;
+
+ wire [3:0] ror8;
+ wire [3:0] rol8;
+ wire [3:0] rcr8;
+ wire [3:0] rcl8;
+ wire [3:0] rot8;
+
+ wire [ 7:0] outr8;
+ wire [15:0] outr16;
+ wire [15:0] rot;
+
+ wire cor8;
+ wire cor16;
+ wire unchanged;
+
+ wire ofo_sal;
+ wire ofo_sar;
+ wire ofo_shr;
+ wire cfo_sal;
+ wire cfo_sal8;
+ wire cfo_sal16;
+ wire cfo_sar;
+ wire cfo_sar8;
+ wire cfo_sar16;
+ wire cfo_shr;
+ wire cfo_shr8;
+ wire cfo_shr16;
+
+ wire ofor;
+ wire cfor;
+
+ // Module instantiation
+ zet_rxr8 rxr8 (
+ .x (x[7:0]),
+ .ci (cfi),
+ .y (rot8),
+ .e (func[1]),
+ .w (outr8),
+ .co (cor8)
+ );
+
+ zet_rxr16 rxr16 (
+ .x (x),
+ .ci (cfi),
+ .y (rot16),
+ .e (func[1]),
+ .w (outr16),
+ .co (cor16)
+ );
+
+ // Continous assignments
+ assign unchanged = word_op ? (y[4:0]==8'b0)
+ : (y[3:0]==4'b0);
+
+ // rotates
+ assign ror16 = { 1'b0, y[3:0] };
+ assign rol16 = { 1'b0, -y[3:0] };
+ assign ror8 = { 1'b0, y[2:0] };
+ assign rol8 = { 1'b0, -y[2:0] };
+
+ assign rcr16 = (y[4:0] <= 5'd16) ? y[4:0] : { 1'b0, y[3:0] - 4'b1 };
+ assign rcl16 = (y[4:0] <= 5'd17) ? 5'd17 - y[4:0] : 5'd2 - y[4:0];
+ assign rcr8 = y[3:0] <= 4'd8 ? y[3:0] : { 1'b0, y[2:0] - 3'b1 };
+ assign rcl8 = y[3:0] <= 4'd9 ? 4'd9 - y[3:0] : 4'd2 - y[3:0];
+
+ assign rot8 = func[1] ? (func[0] ? rcr8 : rcl8 )
+ : (func[0] ? ror8 : rol8 );
+ assign rot16 = func[1] ? (func[0] ? rcr16 : rcl16 )
+ : (func[0] ? ror16 : rol16 );
+
+ assign rot = word_op ? outr16 : { x[15:8], outr8 };
+
+ // shifts
+ assign { cfo_sal16, sal16 } = x << y;
+ assign { sar16, cfo_sar16 } = (y > 5'd16) ? 17'h1ffff
+ : (({x,1'b0} >> y) | (x[15] ? (17'h1ffff << (17 - y))
+ : 17'h0));
+ assign { shr16, cfo_shr16 } = ({x,1'b0} >> y);
+
+ assign { cfo_sal8, sal8 } = x[7:0] << y;
+ assign { sar8, cfo_sar8 } = (y > 5'd8) ? 9'h1ff
+ : (({x[7:0],1'b0} >> y) | (x[7] ? (9'h1ff << (9 - y))
+ : 9'h0));
+ assign { shr8, cfo_shr8 } = ({x[7:0],1'b0} >> y);
+
+ assign sal = word_op ? sal16 : { 8'd0, sal8 };
+ assign shr = word_op ? shr16 : { 8'd0, shr8 };
+ assign sar = word_op ? sar16 : { {8{sar8[7]}}, sar8 };
+
+ // overflows
+ assign ofor = func[0] ? // right
+ (word_op ? out[15]^out[14] : out[7]^out[6])
+ : // left
+ (word_op ? cfo^out[15] : cfo^out[7]);
+
+ assign ofo_sal = word_op ? (out[15] != cfo) : (out[7] != cfo);
+ assign ofo_sar = 1'b0;
+ assign ofo_shr = word_op ? x[15] : x[7];
+
+ assign ofo = unchanged ? ofi
+ : (func[2] ? (func[1] ? ofo_sar : (func[0] ? ofo_shr : ofo_sal))
+ : ofor);
+
+ // carries
+ assign cfor = func[1] ? (word_op ? cor16 : cor8)
+ : (func[0] ? (word_op ? out[15] : out[7])
+ : out[0]);
+
+ assign cfo_sal = word_op ? cfo_sal16 : cfo_sal8;
+ assign cfo_shr = word_op ? cfo_shr16 : cfo_shr8;
+ assign cfo_sar = word_op ? cfo_sar16 : cfo_sar8;
+
+ assign cfo = unchanged ? cfi
+ : (func[2] ? (func[1] ? cfo_sar
+ : (func[0] ? cfo_shr : cfo_sal))
+ : cfor);
+
+ // output
+ assign out = func[2] ? (func[1] ? sar : (func[0] ? shr : sal)) : rot;
+endmodule
+"
+"// megafunction wizard: %ALTPLL%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altpll
+
+// ============================================================
+// File Name: pll.v
+// Megafunction Name(s):
+// \t\t\taltpll
+//
+// Simulation Library Files(s):
+// \t\t\taltera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 13.0.1 Build 232 06/12/2013 SP 1 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2013 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module pll (
+\tinclk0,
+\tc0,
+\tc2,
+\tlocked);
+
+\tinput\t inclk0;
+\toutput\t c0;
+\toutput\t c2;
+\toutput\t locked;
+
+\twire sub_wire0;
+\twire [5:0] sub_wire1;
+\twire [0:0] sub_wire6 = 1\'h0;
+\twire locked = sub_wire0;
+\twire [2:2] sub_wire3 = sub_wire1[2:2];
+\twire [0:0] sub_wire2 = sub_wire1[0:0];
+\twire c0 = sub_wire2;
+\twire c2 = sub_wire3;
+\twire sub_wire4 = inclk0;
+\twire [1:0] sub_wire5 = {sub_wire6, sub_wire4};
+
+\taltpll\taltpll_component (
+\t\t\t\t.inclk (sub_wire5),
+\t\t\t\t.locked (sub_wire0),
+\t\t\t\t.clk (sub_wire1),
+\t\t\t\t.activeclock (),
+\t\t\t\t.areset (1\'b0),
+\t\t\t\t.clkbad (),
+\t\t\t\t.clkena ({6{1\'b1}}),
+\t\t\t\t.clkloss (),
+\t\t\t\t.clkswitch (1\'b0),
+\t\t\t\t.configupdate (1\'b0),
+\t\t\t\t.enable0 (),
+\t\t\t\t.enable1 (),
+\t\t\t\t.extclk (),
+\t\t\t\t.extclkena ({4{1\'b1}}),
+\t\t\t\t.fbin (1\'b1),
+\t\t\t\t.fbmimicbidir (),
+\t\t\t\t.fbout (),
+\t\t\t\t.fref (),
+\t\t\t\t.icdrclk (),
+\t\t\t\t.pfdena (1\'b1),
+\t\t\t\t.phasecounterselect ({4{1\'b1}}),
+\t\t\t\t.phasedone (),
+\t\t\t\t.phasestep (1\'b1),
+\t\t\t\t.phaseupdown (1\'b1),
+\t\t\t\t.pllena (1\'b1),
+\t\t\t\t.scanaclr (1\'b0),
+\t\t\t\t.scanclk (1\'b0),
+\t\t\t\t.scanclkena (1\'b1),
+\t\t\t\t.scandata (1\'b0),
+\t\t\t\t.scandataout (),
+\t\t\t\t.scandone (),
+\t\t\t\t.scanread (1\'b0),
+\t\t\t\t.scanwrite (1\'b0),
+\t\t\t\t.sclkout0 (),
+\t\t\t\t.sclkout1 (),
+\t\t\t\t.vcooverrange (),
+\t\t\t\t.vcounderrange ());
+\tdefparam
+\t\taltpll_component.clk0_divide_by = 1,
+\t\taltpll_component.clk0_duty_cycle = 50,
+\t\taltpll_component.clk0_multiply_by = 2,
+\t\taltpll_component.clk0_phase_shift = ""-2917"",
+\t\taltpll_component.clk2_divide_by = 4,
+\t\taltpll_component.clk2_duty_cycle = 50,
+\t\taltpll_component.clk2_multiply_by = 1,
+\t\taltpll_component.clk2_phase_shift = ""0"",
+\t\taltpll_component.compensate_clock = ""CLK0"",
+\t\taltpll_component.gate_lock_counter = 1048575,
+\t\taltpll_component.gate_lock_signal = ""YES"",
+\t\taltpll_component.inclk0_input_frequency = 20000,
+\t\taltpll_component.intended_device_family = ""Cyclone II"",
+\t\taltpll_component.invalid_lock_multiplier = 5,
+\t\taltpll_component.lpm_hint = ""CBX_MODULE_PREFIX=pll"",
+\t\taltpll_component.lpm_type = ""altpll"",
+\t\taltpll_component.operation_mode = ""NORMAL"",
+\t\taltpll_component.port_activeclock = ""PORT_UNUSED"",
+\t\taltpll_component.port_areset = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkbad0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkbad1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkloss = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkswitch = ""PORT_UNUSED"",
+\t\taltpll_component.port_configupdate = ""PORT_UNUSED"",
+\t\taltpll_component.port_fbin = ""PORT_UNUSED"",
+\t\taltpll_component.port_inclk0 = ""PORT_USED"",
+\t\taltpll_component.port_inclk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_locked = ""PORT_USED"",
+\t\taltpll_component.port_pfdena = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasecounterselect = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasedone = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasestep = ""PORT_UNUSED"",
+\t\taltpll_component.port_phaseupdown = ""PORT_UNUSED"",
+\t\taltpll_component.port_pllena = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanaclr = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanclk = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanclkena = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandata = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandataout = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandone = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanread = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanwrite = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk0 = ""PORT_USED"",
+\t\taltpll_component.port_clk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk2 = ""PORT_USED"",
+\t\taltpll_component.port_clk3 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk4 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk5 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena2 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena3 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena4 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena5 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk2 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk3 = ""PORT_UNUSED"",
+\t\taltpll_component.valid_lock_multiplier = 1;
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH STRING ""1.000""
+// Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING ""MHz""
+// Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING ""Low""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING ""1""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_CUSTOM STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING ""0""
+// Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CLKLOSS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING ""1""
+// Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING ""0""
+// Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING ""c0""
+// Retrieval info: PRIVATE: CUR_FBIN_CLK STRING ""e0""
+// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING ""Any""
+// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: DIV_FACTOR2 NUMERIC ""4""
+// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING ""50.00000000""
+// Retrieval info: PRIVATE: DUTY_CYCLE2 STRING ""50.00000000""
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING ""100.000000""
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE2 STRING ""12.500000""
+// Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING ""0""
+// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING ""0""
+// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING ""1""
+// Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC ""1048575""
+// Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING ""1""
+// Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING ""50.000""
+// Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING ""100.000""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""
+// Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING ""1""
+// Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING ""1""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING ""Not Available""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC ""0""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT2 STRING ""ps""
+// Retrieval info: PRIVATE: MIG_DEVICE_SPEED_GRADE STRING ""Any""
+// Retrieval info: PRIVATE: MIRROR_CLK0 STRING ""0""
+// Retrieval info: PRIVATE: MIRROR_CLK2 STRING ""0""
+// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: MULT_FACTOR2 NUMERIC ""1""
+// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING ""100.00000000""
+// Retrieval info: PRIVATE: OUTPUT_FREQ2 STRING ""10000000.00000000""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE2 STRING ""0""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING ""MHz""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT2 STRING ""MHz""
+// Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: PHASE_RECONFIG_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING ""-2.91666700""
+// Retrieval info: PRIVATE: PHASE_SHIFT2 STRING ""0.00000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT_STEP_ENABLED_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING ""ns""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT2 STRING ""ps""
+// Retrieval info: PRIVATE: PLL_ADVANCED_PARAM_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC ""1""
+// Retrieval info: PRIVATE: PLL_ENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_FBMIMIC_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_TARGET_HARCOPY_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING ""inclk0""
+// Retrieval info: PRIVATE: RECONFIG_FILE STRING ""pll.mif""
+// Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: SELF_RESET_LOCK_LOSS STRING ""0""
+// Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FREQ STRING ""50.000""
+// Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING ""KHz""
+// Retrieval info: PRIVATE: SPREAD_PERCENT STRING ""0.500""
+// Retrieval info: PRIVATE: SPREAD_USE STRING ""0""
+// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING ""0""
+// Retrieval info: PRIVATE: STICKY_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: STICKY_CLK2 STRING ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING ""0""
+// Retrieval info: PRIVATE: USE_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: USE_CLK2 STRING ""1""
+// Retrieval info: PRIVATE: USE_CLKENA0 STRING ""0""
+// Retrieval info: PRIVATE: USE_CLKENA2 STRING ""0""
+// Retrieval info: PRIVATE: USE_MIL_SPEED_GRADE NUMERIC ""0""
+// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING ""0""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC ""2""
+// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING ""-2917""
+// Retrieval info: CONSTANT: CLK2_DIVIDE_BY NUMERIC ""4""
+// Retrieval info: CONSTANT: CLK2_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: CLK2_MULTIPLY_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: CLK2_PHASE_SHIFT STRING ""0""
+// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING ""CLK0""
+// Retrieval info: CONSTANT: GATE_LOCK_COUNTER NUMERIC ""1048575""
+// Retrieval info: CONSTANT: GATE_LOCK_SIGNAL STRING ""YES""
+// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC ""20000""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""
+// Retrieval info: CONSTANT: INVALID_LOCK_MULTIPLIER NUMERIC ""5""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""altpll""
+// Retrieval info: CONSTANT: OPERATION_MODE STRING ""NORMAL""
+// Retrieval info: CONSTANT: PORT_ACTIVECLOCK STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_ARESET STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKBAD0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKBAD1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKLOSS STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKSWITCH STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CONFIGUPDATE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_FBIN STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_INCLK0 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_INCLK1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_LOCKED STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_PFDENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASECOUNTERSELECT STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASEDONE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASESTEP STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASEUPDOWN STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PLLENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANACLR STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANCLK STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANCLKENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDATA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDATAOUT STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDONE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANREAD STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANWRITE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk0 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_clk1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk2 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_clk3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk4 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk5 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena4 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena5 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: VALID_LOCK_MULTIPLIER NUMERIC ""1""
+// Retrieval info: USED_PORT: @clk 0 0 6 0 OUTPUT_CLK_EXT VCC ""@clk[5..0]""
+// Retrieval info: USED_PORT: @extclk 0 0 4 0 OUTPUT_CLK_EXT VCC ""@extclk[3..0]""
+// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT_CLK_EXT VCC ""c0""
+// Retrieval info: USED_PORT: c2 0 0 0 0 OUTPUT_CLK_EXT VCC ""c2""
+// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT_CLK_EXT GND ""inclk0""
+// Retrieval info: USED_PORT: locked 0 0 0 0 OUTPUT GND ""locked""
+// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
+// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
+// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
+// Retrieval info: CONNECT: c2 0 0 0 0 @clk 0 0 1 2
+// Retrieval info: CONNECT: locked 0 0 0 0 @locked 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.ppf TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.bsf TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_bb.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_waveforms.html FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_wave*.jpg FALSE
+// Retrieval info: LIB_FILE: altera_mf
+// Retrieval info: CBX_MODULE_PREFIX: ON
+"
+"/*\r
+ * VGA top level file\r
+ * Copyright (C) 2010 Zeus Gomez Marmolejo \r
+ *\r
+ * VGA FML support\r
+ * Copyright (C) 2013 Charley Picker \r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+ \r
+module vga_fml #(\r
+ parameter fml_depth = 20 // 1MB Video Memory\r
+) (\r
+ // Wishbone signals\r
+ input wb_clk_i, // 100 Mhz VDU clock\r
+ input wb_rst_i,\r
+ input [15:0] wb_dat_i,\r
+ output [15:0] wb_dat_o,\r
+ input [16:1] wb_adr_i,\r
+ input wb_we_i,\r
+ input wb_tga_i,\r
+ input [ 1:0] wb_sel_i,\r
+ input wb_stb_i,\r
+ input wb_cyc_i,\r
+ output wb_ack_o,\r
+\r
+ // VGA pad signals\r
+ output [ 3:0] vga_red_o,\r
+ output [ 3:0] vga_green_o,\r
+ output [ 3:0] vga_blue_o,\r
+ output horiz_sync,\r
+ output vert_sync,\r
+\r
+ // VGA CPU FML master interface\r
+ output [fml_depth-1:0] vga_cpu_fml_adr,\r
+ output vga_cpu_fml_stb,\r
+ output vga_cpu_fml_we,\r
+ input vga_cpu_fml_ack,\r
+ output [1:0] vga_cpu_fml_sel,\r
+ output [15:0] vga_cpu_fml_do,\r
+ input [15:0] vga_cpu_fml_di,\r
+\r
+ // VGA LCD FML master interface\r
+ output [fml_depth-1:0] vga_lcd_fml_adr,\r
+ output vga_lcd_fml_stb,\r
+ output vga_lcd_fml_we,\r
+ input vga_lcd_fml_ack,\r
+ output [1:0] vga_lcd_fml_sel,\r
+ output [15:0] vga_lcd_fml_do,\r
+ input [15:0] vga_lcd_fml_di,\r
+\r
+ output vga_clk\r
+\r
+ );\r
+\r
+\r
+ // Registers and nets\r
+ \r
+ // Config wires\r
+ wire [15:0] conf_wb_dat_o;\r
+ wire conf_wb_ack_o;\r
+\r
+ // Mem wires\r
+ wire [15:0] mem_wb_dat_o;\r
+ wire mem_wb_ack_o;\r
+\r
+ // LCD wires\r
+ wire v_retrace;\r
+ wire vh_retrace;\r
+ wire w_vert_sync;\r
+ \r
+ // VGA LCD Direct Cache Bus\r
+ wire vga_lcd_dcb_stb;\r
+ wire [fml_depth-1:0] vga_lcd_dcb_adr;\r
+ wire [15:0] vga_lcd_dcb_dat;\r
+ wire vga_lcd_dcb_hit;\r
+\r
+ // VGA configuration registers\r
+ wire shift_reg1;\r
+ wire graphics_alpha;\r
+ wire memory_mapping1;\r
+ wire [ 1:0] write_mode;\r
+ wire [ 1:0] raster_op;\r
+ wire read_mode;\r
+ wire [ 7:0] bitmask;\r
+ wire [ 3:0] set_reset;\r
+ wire [ 3:0] enable_set_reset;\r
+ wire [ 3:0] map_mask;\r
+ wire x_dotclockdiv2;\r
+ wire chain_four;\r
+ wire [ 1:0] read_map_select;\r
+ wire [ 3:0] color_compare;\r
+ wire [ 3:0] color_dont_care;\r
+\r
+ // Wishbone master to SDRAM\r
+ wire [17:1] wbm_adr_o;\r
+ wire [ 1:0] wbm_sel_o;\r
+ wire wbm_we_o;\r
+ wire [15:0] wbm_dat_o;\r
+ wire [15:0] wbm_dat_i;\r
+ wire wbm_stb_o;\r
+ wire wbm_ack_i;\r
+\r
+ wire stb;\r
+\r
+ // CRT wires\r
+ wire [ 5:0] cur_start;\r
+ wire [ 5:0] cur_end;\r
+ wire [15:0] start_addr;\r
+ wire [ 4:0] vcursor;\r
+ wire [ 6:0] hcursor;\r
+ wire [ 6:0] horiz_total;\r
+ wire [ 6:0] end_horiz;\r
+ wire [ 6:0] st_hor_retr;\r
+ wire [ 4:0] end_hor_retr;\r
+ wire [ 9:0] vert_total;\r
+ wire [ 9:0] end_vert;\r
+ wire [ 9:0] st_ver_retr;\r
+ wire [ 3:0] end_ver_retr;\r
+\r
+ // attribute_ctrl wires\r
+ wire [3:0] pal_addr;\r
+ wire pal_we;\r
+ wire [7:0] pal_read;\r
+ wire [7:0] pal_write;\r
+\r
+ // dac_regs wires\r
+ wire dac_we;\r
+ wire [1:0] dac_read_data_cycle;\r
+ wire [7:0] dac_read_data_register;\r
+ wire [3:0] dac_read_data;\r
+ wire [1:0] dac_write_data_cycle;\r
+ wire [7:0] dac_write_data_register;\r
+ wire [3:0] dac_write_data;\r
+\r
+ // Module instances\r
+ //\r
+ vga_config_iface config_iface (\r
+ .wb_clk_i (wb_clk_i),\r
+ .wb_rst_i (wb_rst_i),\r
+ .wb_dat_i (wb_dat_i),\r
+ .wb_dat_o (conf_wb_dat_o),\r
+ .wb_adr_i (wb_adr_i[4:1]),\r
+ .wb_we_i (wb_we_i),\r
+ .wb_sel_i (wb_sel_i),\r
+ .wb_stb_i (stb & wb_tga_i),\r
+ .wb_ack_o (conf_wb_ack_o),\r
+\r
+ .shift_reg1 (shift_reg1),\r
+ .graphics_alpha (graphics_alpha),\r
+ .memory_mapping1 (memory_mapping1),\r
+ .write_mode (write_mode),\r
+ .raster_op (raster_op),\r
+ .read_mode (read_mode),\r
+ .bitmask (bitmask),\r
+ .set_reset (set_reset),\r
+ .enable_set_reset (enable_set_reset),\r
+ .map_mask (map_mask),\r
+ .x_dotclockdiv2 (x_dotclockdiv2),\r
+ .chain_four (chain_four),\r
+ .read_map_select (read_map_select),\r
+ .color_compare (color_compare),\r
+ .color_dont_care (color_dont_care),\r
+\r
+ .pal_addr (pal_addr),\r
+ .pal_we (pal_we),\r
+ .pal_read (pal_read),\r
+ .pal_write (pal_write),\r
+\r
+ .dac_we (dac_we),\r
+ .dac_read_data_cycle (dac_read_data_cycle),\r
+ .dac_read_data_register (dac_read_data_register),\r
+ .dac_read_data (dac_read_data),\r
+ .dac_write_data_cycle (dac_write_data_cycle),\r
+ .dac_write_data_register (dac_write_data_register),\r
+ .dac_write_data (dac_write_data),\r
+\r
+ .cur_start (cur_start),\r
+ .cur_end (cur_end),\r
+ .start_addr (start_addr),\r
+ .vcursor (vcursor),\r
+ .hcursor (hcursor),\r
+\r
+ .horiz_total (horiz_total),\r
+ .end_horiz (end_horiz),\r
+ .st_hor_retr (st_hor_retr),\r
+ .end_hor_retr (end_hor_retr),\r
+ .vert_total (vert_total),\r
+ .end_vert (end_vert),\r
+ .st_ver_retr (st_ver_retr),\r
+ .end_ver_retr (end_ver_retr),\r
+\r
+ .v_retrace (v_retrace),\r
+ .vh_retrace (vh_retrace)\r
+ );\r
+\r
+ vga_lcd_fml #(\r
+ .fml_depth (fml_depth) // 1MB Memeory address range\r
+ ) lcd (\r
+ .clk (wb_clk_i),\r
+ .rst (wb_rst_i),\r
+\r
+ .shift_reg1 (shift_reg1),\r
+ .graphics_alpha (graphics_alpha),\r
+\r
+ .pal_addr (pal_addr),\r
+ .pal_we (pal_we),\r
+ .pal_read (pal_read),\r
+ .pal_write (pal_write),\r
+\r
+ .dac_we (dac_we),\r
+ .dac_read_data_cycle (dac_read_data_cycle),\r
+ .dac_read_data_register (dac_read_data_register),\r
+ .dac_read_data (dac_read_data),\r
+ .dac_write_data_cycle (dac_write_data_cycle),\r
+ .dac_write_data_register (dac_write_data_register),\r
+ .dac_write_data (dac_write_data),\r
+\r
+ // VGA LCD FML master interface\r
+ .fml_adr (vga_lcd_fml_adr),\r
+ .fml_stb (vga_lcd_fml_stb),\r
+ .fml_we (vga_lcd_fml_we),\r
+ .fml_ack (vga_lcd_fml_ack),\r
+ .fml_sel (vga_lcd_fml_sel),\r
+ .fml_do (vga_lcd_fml_do),\r
+ .fml_di (vga_lcd_fml_di),\r
+\r
+ // VGA LCD Direct Cache Bus\r
+ .dcb_stb(vga_lcd_dcb_stb),\r
+ .dcb_adr(vga_lcd_dcb_adr),\r
+ .dcb_dat(vga_lcd_dcb_dat),\r
+ .dcb_hit(vga_lcd_dcb_hit),\r
+\r
+ .vga_red_o (vga_red_o),\r
+ .vga_green_o (vga_green_o),\r
+ .vga_blue_o (vga_blue_o),\r
+ .horiz_sync (horiz_sync),\r
+ .vert_sync (w_vert_sync),\r
+ \r
+ .start_addr (start_addr),\r
+\r
+ .cur_start (cur_start),\r
+ .cur_end (cur_end),\r
+ .vcursor (vcursor),\r
+ .hcursor (hcursor),\r
+\r
+ .horiz_total (horiz_total),\r
+ .end_horiz (end_horiz),\r
+ .st_hor_retr (st_hor_retr),\r
+ .end_hor_retr (end_hor_retr),\r
+ .vert_total (vert_total),\r
+ .end_vert (end_vert),\r
+ .st_ver_retr (st_ver_retr),\r
+ .end_ver_retr (end_ver_retr),\r
+\r
+ .x_dotclockdiv2 (x_dotclockdiv2),\r
+\r
+ .v_retrace (v_retrace),\r
+ .vh_retrace (vh_retrace),\r
+\r
+ .vga_clk(vga_clk)\r
+ );\r
+\r
+ vga_cpu_mem_iface cpu_mem_iface (\r
+ .wb_clk_i (wb_clk_i),\r
+ .wb_rst_i (wb_rst_i),\r
+\r
+ .wbs_adr_i (wb_adr_i),\r
+ .wbs_sel_i (wb_sel_i),\r
+ .wbs_we_i (wb_we_i),\r
+ .wbs_dat_i (wb_dat_i),\r
+ .wbs_dat_o (mem_wb_dat_o),\r
+ .wbs_stb_i (stb & !wb_tga_i),\r
+ .wbs_ack_o (mem_wb_ack_o),\r
+\r
+ .wbm_adr_o (wbm_adr_o),\r
+ .wbm_sel_o (wbm_sel_o),\r
+ .wbm_we_o (wbm_we_o),\r
+ .wbm_dat_o (wbm_dat_o),\r
+ .wbm_dat_i (wbm_dat_i),\r
+ .wbm_stb_o (wbm_stb_o),\r
+ .wbm_ack_i (wbm_ack_i),\r
+\r
+ .chain_four (chain_four),\r
+ .memory_mapping1 (memory_mapping1),\r
+ .write_mode (write_mode),\r
+ .raster_op (raster_op),\r
+ .read_mode (read_mode),\r
+ .bitmask (bitmask),\r
+ .set_reset (set_reset),\r
+ .enable_set_reset (enable_set_reset),\r
+ .map_mask (map_mask),\r
+ .read_map_select (read_map_select),\r
+ .color_compare (color_compare),\r
+ .color_dont_care (color_dont_care)\r
+ );\r
+\r
+ fmlbrg #(\r
+ .fml_depth (fml_depth), // 1MB Memory address range\r
+ .cache_depth (5) // 32 byte cache\r
+ ) vgafmlbrg (\r
+ .sys_clk (wb_clk_i),\r
+ .sys_rst (wb_rst_i),\r
+\r
+ // Wishbone slave interface\r
+ .wb_adr_i ({ 2'b0, wbm_adr_o }),\r
+ .wb_cti_i (3'b0),\r
+ .wb_dat_i (wbm_dat_o),\r
+ .wb_dat_o (wbm_dat_i),\r
+ .wb_sel_i (wbm_sel_o),\r
+ .wb_cyc_i (wbm_stb_o),\r
+ .wb_stb_i (wbm_stb_o),\r
+ .wb_tga_i (1'b0),\r
+ .wb_we_i (wbm_we_o),\r
+ .wb_ack_o (wbm_ack_i), \r
+\r
+ // VGA CPU FML master interface\r
+ .fml_adr (vga_cpu_fml_adr),\r
+ .fml_stb (vga_cpu_fml_stb),\r
+ .fml_we (vga_cpu_fml_we),\r
+ .fml_ack (vga_cpu_fml_ack),\r
+ .fml_sel (vga_cpu_fml_sel),\r
+ .fml_do (vga_cpu_fml_do),\r
+ .fml_di (vga_cpu_fml_di),\r
+\r
+ // VGA LCD Direct Cache Bus\t \r
+ .dcb_stb (vga_lcd_dcb_stb),\r
+ .dcb_adr (vga_lcd_dcb_adr),\r
+ .dcb_dat (vga_lcd_dcb_dat),\r
+ .dcb_hit (vga_lcd_dcb_hit)\r
+\r
+ );\r
+\r
+ // Continous assignments\r
+ assign wb_dat_o = wb_tga_i ? conf_wb_dat_o : mem_wb_dat_o;\r
+ assign wb_ack_o = wb_tga_i ? conf_wb_ack_o : mem_wb_ack_o;\r
+ assign stb = wb_stb_i & wb_cyc_i;\r
+ assign vert_sync = ~graphics_alpha ^ w_vert_sync;\r
+\r
+endmodule\r
+"
+"/*
+ * Zet SoC top level file for Altera DE2-115 board
+ * Copyright (C) 2009, 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module kotku (
+ // Clock input
+ input clk_50_,
+
+ // General purpose IO
+ input [7:0] sw_,
+ input key_,
+ output [6:0] hex0_,
+ output [6:0] hex1_,
+ output [6:0] hex2_,
+ output [6:0] hex3_,
+ output [9:0] ledr_,
+ output [7:0] ledg_,
+
+ // flash signals
+ output [22:0] flash_addr_,
+ input [ 7:0] flash_data_,
+ output flash_oe_n_,
+ output flash_ce_n_,
+
+ // sdram signals
+ output [11:0] sdram_addr_,
+ inout [15:0] sdram_data_,
+ output [ 1:0] sdram_ba_,
+ output sdram_ras_n_,
+ output sdram_cas_n_,
+ output sdram_ce_,
+ output sdram_clk_,
+ output sdram_we_n_,
+ output sdram_cs_n_,
+
+ // VGA signals
+ output [ 3:0] tft_lcd_r_,
+ output [ 3:0] tft_lcd_g_,
+ output [ 3:0] tft_lcd_b_,
+ output tft_lcd_hsync_,
+ output tft_lcd_vsync_,
+ output tft_lcd_clk_,
+
+ // UART signals
+ output uart_txd_,
+
+ // PS2 signals
+ input ps2_kclk_, // PS2 keyboard Clock
+ inout ps2_kdat_, // PS2 Keyboard Data
+ inout ps2_mclk_, // PS2 Mouse Clock
+ inout ps2_mdat_, // PS2 Mouse Data
+
+ // SD card signals
+ output sd_sclk_,
+ input sd_miso_,
+ output sd_mosi_,
+ output sd_ss_,
+
+ // I2C for audio codec
+ inout i2c_sdat_,
+ output i2c_sclk_,
+
+ // Audio codec signals
+ input aud_daclrck_,
+ output aud_dacdat_,
+ input aud_bclk_,
+ output aud_xck_
+ );
+
+ // Registers and nets
+ wire clk;
+ wire rst_lck;
+ wire [15:0] dat_o;
+ wire [15:0] dat_i;
+ wire [19:1] adr;
+ wire we;
+ wire tga;
+ wire [ 1:0] sel;
+ wire stb;
+ wire cyc;
+ wire ack;
+ wire lock;
+
+ // wires to BIOS ROM
+ wire [15:0] rom_dat_o;
+ wire [15:0] rom_dat_i;
+ wire rom_tga_i;
+ wire [19:1] rom_adr_i;
+ wire [ 1:0] rom_sel_i;
+ wire rom_we_i;
+ wire rom_cyc_i;
+ wire rom_stb_i;
+ wire rom_ack_o;
+
+ // wires to flash controller
+ wire [15:0] fl_dat_o;
+ wire [15:0] fl_dat_i;
+ wire fl_tga_i;
+ wire [19:1] fl_adr_i;
+ wire [ 1:0] fl_sel_i;
+ wire fl_we_i;
+ wire fl_cyc_i;
+ wire fl_stb_i;
+ wire fl_ack_o;
+
+ // Unused outputs
+ wire flash_we_n_;
+ wire flash_rst_n_;
+ wire [1:0] sdram_dqm_;
+ wire a12;
+ wire [2:0] s19_17;
+
+ // Unused inputs
+ wire uart_rxd_;
+ wire aud_adcdat_;
+
+ // wires to vga controller
+ wire [15:0] vga_dat_o;
+ wire [15:0] vga_dat_i;
+ wire vga_tga_i;
+ wire [19:1] vga_adr_i;
+ wire [ 1:0] vga_sel_i;
+ wire vga_we_i;
+ wire vga_cyc_i;
+ wire vga_stb_i;
+ wire vga_ack_o;
+
+ // cross clock domain synchronized signals
+ wire [15:0] vga_dat_o_s;
+ wire [15:0] vga_dat_i_s;
+ wire vga_tga_i_s;
+ wire [19:1] vga_adr_i_s;
+ wire [ 1:0] vga_sel_i_s;
+ wire vga_we_i_s;
+ wire vga_cyc_i_s;
+ wire vga_stb_i_s;
+ wire vga_ack_o_s;
+
+ // wires to uart controller
+ wire [15:0] uart_dat_o;
+ wire [15:0] uart_dat_i;
+ wire uart_tga_i;
+ wire [19:1] uart_adr_i;
+ wire [ 1:0] uart_sel_i;
+ wire uart_we_i;
+ wire uart_cyc_i;
+ wire uart_stb_i;
+ wire uart_ack_o;
+
+ // wires to keyboard controller
+ wire [15:0] keyb_dat_o;
+ wire [15:0] keyb_dat_i;
+ wire keyb_tga_i;
+ wire [19:1] keyb_adr_i;
+ wire [ 1:0] keyb_sel_i;
+ wire keyb_we_i;
+ wire keyb_cyc_i;
+ wire keyb_stb_i;
+ wire keyb_ack_o;
+
+ // wires to timer controller
+ wire [15:0] timer_dat_o;
+ wire [15:0] timer_dat_i;
+ wire timer_tga_i;
+ wire [19:1] timer_adr_i;
+ wire [ 1:0] timer_sel_i;
+ wire timer_we_i;
+ wire timer_cyc_i;
+ wire timer_stb_i;
+ wire timer_ack_o;
+
+ // wires to sd controller
+ wire [19:1] sd_adr_i;
+ wire [ 7:0] sd_dat_o;
+ wire [15:0] sd_dat_i;
+ wire sd_tga_i;
+ wire [ 1:0] sd_sel_i;
+ wire sd_we_i;
+ wire sd_cyc_i;
+ wire sd_stb_i;
+ wire sd_ack_o;
+
+ // wires to sd bridge
+ wire [19:1] sd_adr_i_s;
+ wire [15:0] sd_dat_o_s;
+ wire [15:0] sd_dat_i_s;
+ wire sd_tga_i_s;
+ wire [ 1:0] sd_sel_i_s;
+ wire sd_we_i_s;
+ wire sd_cyc_i_s;
+ wire sd_stb_i_s;
+ wire sd_ack_o_s;
+
+ // wires to gpio controller
+ wire [15:0] gpio_dat_o;
+ wire [15:0] gpio_dat_i;
+ wire gpio_tga_i;
+ wire [19:1] gpio_adr_i;
+ wire [ 1:0] gpio_sel_i;
+ wire gpio_we_i;
+ wire gpio_cyc_i;
+ wire gpio_stb_i;
+ wire gpio_ack_o;
+
+ // wires to SDRAM controller
+ wire [19:1] fmlbrg_adr_s;
+ wire [15:0] fmlbrg_dat_w_s;
+ wire [15:0] fmlbrg_dat_r_s;
+ wire [ 1:0] fmlbrg_sel_s;
+ wire fmlbrg_cyc_s;
+ wire fmlbrg_stb_s;
+ wire fmlbrg_tga_s;
+ wire fmlbrg_we_s;
+ wire fmlbrg_ack_s;
+
+ wire [19:1] fmlbrg_adr;
+ wire [15:0] fmlbrg_dat_w;
+ wire [15:0] fmlbrg_dat_r;
+ wire [ 1:0] fmlbrg_sel;
+ wire fmlbrg_cyc;
+ wire fmlbrg_stb;
+ wire fmlbrg_tga;
+ wire fmlbrg_we;
+ wire fmlbrg_ack;
+
+ wire [19:1] csrbrg_adr_s;
+ wire [15:0] csrbrg_dat_w_s;
+ wire [15:0] csrbrg_dat_r_s;
+ wire [ 1:0] csrbrg_sel_s;
+ wire csrbrg_cyc_s;
+ wire csrbrg_stb_s;
+ wire csrbrg_tga_s;
+ wire csrbrg_we_s;
+ wire csrbrg_ack_s;
+
+ wire [19:1] csrbrg_adr;
+ wire [15:0] csrbrg_dat_w;
+ wire [15:0] csrbrg_dat_r;
+ wire [ 1:0] csrbrg_sel;
+ wire csrbrg_tga;
+ wire csrbrg_cyc;
+ wire csrbrg_stb;
+ wire csrbrg_we;
+ wire csrbrg_ack;
+
+ wire sb_cyc_i;
+ wire sb_stb_i;
+
+ wire [ 2:0] csr_a;
+ wire csr_we;
+ wire [15:0] csr_dw;
+ wire [15:0] csr_dr_hpdmc;
+
+ // wires to hpdmc slave interface
+ wire [25:0] fml_adr;
+ wire fml_stb;
+ wire fml_we;
+ wire fml_ack;
+ wire [ 1:0] fml_sel;
+ wire [15:0] fml_di;
+ wire [15:0] fml_do;
+
+ // wires to fml bridge master interface
+ wire [19:0] fml_fmlbrg_adr;
+ wire fml_fmlbrg_stb;
+ wire fml_fmlbrg_we;
+ wire fml_fmlbrg_ack;
+ wire [ 1:0] fml_fmlbrg_sel;
+ wire [15:0] fml_fmlbrg_di;
+ wire [15:0] fml_fmlbrg_do;
+
+ // wires to VGA CPU FML master interface
+ wire [19:0] vga_cpu_fml_adr; // 1MB Memory Address range
+ wire vga_cpu_fml_stb;
+ wire vga_cpu_fml_we;
+ wire vga_cpu_fml_ack;
+ wire [1:0] vga_cpu_fml_sel;
+ wire [15:0] vga_cpu_fml_do;
+ wire [15:0] vga_cpu_fml_di;
+
+ // wires to VGA LCD FML master interface
+ wire [19:0] vga_lcd_fml_adr; // 1MB Memory Address range
+ wire vga_lcd_fml_stb;
+ wire vga_lcd_fml_we;
+ wire vga_lcd_fml_ack;
+ wire [1:0] vga_lcd_fml_sel;
+ wire [15:0] vga_lcd_fml_do;
+ wire [15:0] vga_lcd_fml_di;
+
+ // wires to default stb/ack
+ wire def_cyc_i;
+ wire def_stb_i;
+ wire [15:0] sw_dat_o;
+ wire sdram_clk;
+ wire vga_clk;
+
+ wire [ 7:0] intv;
+ wire [ 2:0] iid;
+ wire intr;
+ wire inta;
+
+ wire nmi_pb;
+ wire nmi;
+ wire nmia;
+
+ wire [19:0] pc;
+ reg [16:0] rst_debounce;
+
+ wire timer_clk;
+ wire timer2_o;
+
+ // Audio only signals
+ wire [ 7:0] aud_dat_o;
+ wire aud_cyc_i;
+ wire aud_ack_o;
+ wire aud_sel_cond;
+
+ // Keyboard-audio shared signals
+ wire [ 7:0] kaud_dat_o;
+ wire kaud_cyc_i;
+ wire kaud_ack_o;
+
+`ifndef SIMULATION
+ /*
+ * Debounce it (counter holds reset for 10.49ms),
+ * and generate power-on reset.
+ */
+ initial rst_debounce <= 17'h1FFFF;
+ reg rst;
+ initial rst <= 1'b1;
+ always @(posedge clk) begin
+ if(~rst_lck) /* reset is active low */
+ rst_debounce <= 17'h1FFFF;
+ else if(rst_debounce != 17'd0)
+ rst_debounce <= rst_debounce - 17'd1;
+ rst <= rst_debounce != 17'd0;
+ end
+`else
+ wire rst;
+ assign rst = !rst_lck;
+`endif
+
+ // Module instantiations
+ pll pll (
+ .inclk0 (clk_50_),
+ .c0 (sdram_clk), // 100 Mhz
+ .c1 (sdram_clk_), // to SDRAM chip
+ .c2 (), // 25 Mhz - vga_clk generated inside of vga
+ .c3 (), // 25 Mhz - tft_lcd_clk_ generated inside of vga
+ .c4 (clk), // 12.5 Mhz
+ .locked (lock)
+ );
+
+ clk_gen #(
+ .res (21),
+ .phase (21'd100091)
+ ) timerclk (
+ .clk_i (vga_clk), // 25 MHz
+ .rst_i (rst),
+ .clk_o (timer_clk) // 1.193178 MHz (required 1.193182 MHz)
+ );
+
+ clk_gen #(
+ .res (18),
+ .phase (18'd29595)
+ ) audioclk (
+ .clk_i (sdram_clk), // 100 MHz (use highest freq to minimize jitter)
+ .rst_i (rst),
+ .clk_o (aud_xck_) // 11.28960 MHz (required 11.28960 MHz)
+ );
+
+ bootrom bootrom (
+ .clk (clk), // Wishbone slave interface
+ .rst (rst),
+ .wb_dat_i (rom_dat_i),
+ .wb_dat_o (rom_dat_o),
+ .wb_adr_i (rom_adr_i),
+ .wb_we_i (rom_we_i ),
+ .wb_tga_i (rom_tga_i),
+ .wb_stb_i (rom_stb_i),
+ .wb_cyc_i (rom_cyc_i),
+ .wb_sel_i (rom_sel_i),
+ .wb_ack_o (rom_ack_o)
+ );
+
+ flash8_r2 flash8_r2 (
+ // Wishbone slave interface
+ .wb_clk_i (clk), // Main Clock
+ .wb_rst_i (rst), // Reset Line
+ .wb_adr_i (fl_adr_i[1]), // Address lines
+ .wb_sel_i (fl_sel_i), // Select lines
+ .wb_dat_i (fl_dat_i), // Command to send
+ .wb_dat_o (fl_dat_o), // Received data
+ .wb_cyc_i (fl_cyc_i), // Cycle
+ .wb_stb_i (fl_stb_i), // Strobe
+ .wb_we_i (fl_we_i), // Write enable
+ .wb_ack_o (fl_ack_o), // Normal bus termination
+
+ // Pad signals
+ .flash_addr_ (flash_addr_),
+ .flash_data_ (flash_data_),
+ .flash_we_n_ (flash_we_n_),
+ .flash_oe_n_ (flash_oe_n_),
+ .flash_ce_n_ (flash_ce_n_),
+ .flash_rst_n_ (flash_rst_n_)
+ );
+
+ wb_abrgr wb_fmlbrg (
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wbs_clk_i (clk),
+ .wbs_adr_i (fmlbrg_adr_s),
+ .wbs_dat_i (fmlbrg_dat_w_s),
+ .wbs_dat_o (fmlbrg_dat_r_s),
+ .wbs_sel_i (fmlbrg_sel_s),
+ .wbs_tga_i (fmlbrg_tga_s),
+ .wbs_stb_i (fmlbrg_stb_s),
+ .wbs_cyc_i (fmlbrg_cyc_s),
+ .wbs_we_i (fmlbrg_we_s),
+ .wbs_ack_o (fmlbrg_ack_s),
+
+ // Wishbone master interface
+ .wbm_clk_i (sdram_clk),
+ .wbm_adr_o (fmlbrg_adr),
+ .wbm_dat_o (fmlbrg_dat_w),
+ .wbm_dat_i (fmlbrg_dat_r),
+ .wbm_sel_o (fmlbrg_sel),
+ .wbm_tga_o (fmlbrg_tga),
+ .wbm_stb_o (fmlbrg_stb),
+ .wbm_cyc_o (fmlbrg_cyc),
+ .wbm_we_o (fmlbrg_we),
+ .wbm_ack_i (fmlbrg_ack)
+ );
+
+ fmlbrg #(
+ .fml_depth (20), // 8086 can only address 1 MB
+ .cache_depth (10) // 1 Kbyte cache
+ ) fmlbrg (
+ .sys_clk (sdram_clk),
+ .sys_rst (rst),
+\t
+\t // Wishbone slave interface
+ .wb_adr_i (fmlbrg_adr),
+\t .wb_cti_i(3'b0),
+ .wb_dat_i (fmlbrg_dat_w),
+ .wb_dat_o (fmlbrg_dat_r),
+ .wb_sel_i (fmlbrg_sel),
+ .wb_cyc_i (fmlbrg_cyc),
+ .wb_stb_i (fmlbrg_stb),
+ .wb_tga_i (fmlbrg_tga),
+ .wb_we_i (fmlbrg_we),
+ .wb_ack_o (fmlbrg_ack),
+
+ // FML master 1 interface
+ .fml_adr (fml_fmlbrg_adr),
+ .fml_stb (fml_fmlbrg_stb),
+ .fml_we (fml_fmlbrg_we),
+ .fml_ack (fml_fmlbrg_ack),
+ .fml_sel (fml_fmlbrg_sel),
+ .fml_do (fml_fmlbrg_do),
+ .fml_di (fml_fmlbrg_di),
+\t
+\t // Direct Cache Bus
+\t .dcb_stb(1'b0),
+\t .dcb_adr(20'b0),
+\t .dcb_dat(),
+\t .dcb_hit()
+\t
+ );
+
+ wb_abrgr wb_csrbrg (
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wbs_clk_i (clk),
+ .wbs_adr_i (csrbrg_adr_s),
+ .wbs_dat_i (csrbrg_dat_w_s),
+ .wbs_dat_o (csrbrg_dat_r_s),
+ .wbs_sel_i (csrbrg_sel_s),
+ .wbs_tga_i (csrbrg_tga_s),
+ .wbs_stb_i (csrbrg_stb_s),
+ .wbs_cyc_i (csrbrg_cyc_s),
+ .wbs_we_i (csrbrg_we_s),
+ .wbs_ack_o (csrbrg_ack_s),
+
+ // Wishbone master interface
+ .wbm_clk_i (sdram_clk),
+ .wbm_adr_o (csrbrg_adr),
+ .wbm_dat_o (csrbrg_dat_w),
+ .wbm_dat_i (csrbrg_dat_r),
+ .wbm_sel_o (csrbrg_sel),
+ .wbm_tga_o (csrbrg_tga),
+ .wbm_stb_o (csrbrg_stb),
+ .wbm_cyc_o (csrbrg_cyc),
+ .wbm_we_o (csrbrg_we),
+ .wbm_ack_i (csrbrg_ack)
+ );
+
+ csrbrg csrbrg (
+ .sys_clk (sdram_clk),
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wb_adr_i (csrbrg_adr[3:1]),
+ .wb_dat_i (csrbrg_dat_w),
+ .wb_dat_o (csrbrg_dat_r),
+ .wb_cyc_i (csrbrg_cyc),
+ .wb_stb_i (csrbrg_stb),
+ .wb_we_i (csrbrg_we),
+ .wb_ack_o (csrbrg_ack),
+
+ // CSR master interface
+ .csr_a (csr_a),
+ .csr_we (csr_we),
+ .csr_do (csr_dw),
+ .csr_di (csr_dr_hpdmc)
+ );
+
+ fmlarb #(
+ .fml_depth (26)
+ ) fmlarb (
+ .sys_clk (sdram_clk),
+\t.sys_rst (rst),
+\t
+\t// Master 0 interface - VGA LCD FML (Reserved video memory port has highest priority)
+\t.m0_adr ({6'b000_001, vga_lcd_fml_adr}), // 1 - 2 MB Addressable memory range
+\t.m0_stb (vga_lcd_fml_stb),
+\t.m0_we (vga_lcd_fml_we),
+\t.m0_ack (vga_lcd_fml_ack),
+\t.m0_sel (vga_lcd_fml_sel),
+\t.m0_di (vga_lcd_fml_do),
+\t.m0_do (vga_lcd_fml_di),
+\t\t
+\t// Master 1 interface - Wishbone FML bridge
+\t.m1_adr ({6'b000_000, fml_fmlbrg_adr}), // 0 - 1 MB Addressable memory range
+\t.m1_stb (fml_fmlbrg_stb),
+\t.m1_we (fml_fmlbrg_we),
+\t.m1_ack (fml_fmlbrg_ack),
+\t.m1_sel (fml_fmlbrg_sel),
+\t.m1_di (fml_fmlbrg_do),
+\t.m1_do (fml_fmlbrg_di),
+\t
+\t// Master 2 interface - VGA CPU FML
+\t.m2_adr ({6'b000_001, vga_cpu_fml_adr}), // 1 - 2 MB Addressable memory range
+\t.m2_stb (vga_cpu_fml_stb),
+\t.m2_we (vga_cpu_fml_we),
+\t.m2_ack (vga_cpu_fml_ack),
+\t.m2_sel (vga_cpu_fml_sel),
+\t.m2_di (vga_cpu_fml_do),
+\t.m2_do (vga_cpu_fml_di),
+\t
+\t// Master 3 interface - not connected
+\t.m3_adr ({6'b000_010, 20'b0}), // 2 - 3 MB Addressable memory range
+\t.m3_stb (1'b0),
+\t.m3_we (1'b0),
+\t.m3_ack (),
+\t.m3_sel (2'b00),
+\t.m3_di (16'h0000),
+\t.m3_do (),
+\t
+\t// Master 4 interface - not connected
+\t.m4_adr ({6'b000_011, 20'b0}), // 3 - 4 MB Addressable memory range
+\t.m4_stb (1'b0),
+\t.m4_we (1'b0),
+\t.m4_ack (),
+\t.m4_sel (2'b00),
+\t.m4_di (16'h0000),
+\t.m4_do (),
+\t
+\t// Master 5 interface - not connected
+\t.m5_adr ({6'b000_100, 20'b0}), // 4 - 5 MB Addressable memory range
+\t.m5_stb (1'b0),
+\t.m5_we (1'b0),
+\t.m5_ack (),
+\t.m5_sel (2'b00),
+\t.m5_di (16'h0000),
+\t.m5_do (),
+\t
+\t// Arbitrer Slave interface - connected to hpdmc
+\t.s_adr (fml_adr),
+\t.s_stb (fml_stb),
+\t.s_we (fml_we),
+\t.s_ack (fml_ack),
+\t.s_sel (fml_sel),
+\t.s_di (fml_di),
+\t.s_do (fml_do)
+ );
+
+ hpdmc #(
+ .csr_addr (1'b0),
+ .sdram_depth (26),
+ .sdram_columndepth (10)
+ ) hpdmc (
+ .sys_clk (sdram_clk),
+ .sys_rst (rst),
+
+ // CSR slave interface
+ .csr_a (csr_a),
+ .csr_we (csr_we),
+ .csr_di (csr_dw),
+ .csr_do (csr_dr_hpdmc),
+
+ // FML slave interface
+ .fml_adr (fml_adr),
+ .fml_stb (fml_stb),
+ .fml_we (fml_we),
+ .fml_ack (fml_ack),
+ .fml_sel (fml_sel),
+ .fml_di (fml_do),
+ .fml_do (fml_di),
+
+ // SDRAM pad signals
+ .sdram_cke (sdram_ce_),
+ .sdram_cs_n (sdram_cs_n_),
+ .sdram_we_n (sdram_we_n_),
+ .sdram_cas_n (sdram_cas_n_),
+ .sdram_ras_n (sdram_ras_n_),
+ .sdram_dqm (sdram_dqm_),
+ .sdram_adr ({a12,sdram_addr_}),
+ .sdram_ba (sdram_ba_),
+ .sdram_dq (sdram_data_)
+ );
+
+ wb_abrg vga_brg (
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wbs_clk_i (clk),
+ .wbs_adr_i (vga_adr_i_s),
+ .wbs_dat_i (vga_dat_i_s),
+ .wbs_dat_o (vga_dat_o_s),
+ .wbs_sel_i (vga_sel_i_s),
+ .wbs_tga_i (vga_tga_i_s),
+ .wbs_stb_i (vga_stb_i_s),
+ .wbs_cyc_i (vga_cyc_i_s),
+ .wbs_we_i (vga_we_i_s),
+ .wbs_ack_o (vga_ack_o_s),
+
+ // Wishbone master interface
+ .wbm_clk_i (sdram_clk),
+ .wbm_adr_o (vga_adr_i),
+ .wbm_dat_o (vga_dat_i),
+ .wbm_dat_i (vga_dat_o),
+ .wbm_sel_o (vga_sel_i),
+ .wbm_tga_o (vga_tga_i),
+ .wbm_stb_o (vga_stb_i),
+ .wbm_cyc_o (vga_cyc_i),
+ .wbm_we_o (vga_we_i),
+ .wbm_ack_i (vga_ack_o)
+ );
+
+ vga_fml #(
+ .fml_depth (20) // 1MB Memory Address range
+ ) vga (
+ .wb_rst_i (rst),
+
+ // Wishbone slave interface
+ .wb_clk_i (sdram_clk), // 100MHz VGA clock
+ .wb_dat_i (vga_dat_i),
+ .wb_dat_o (vga_dat_o),
+ .wb_adr_i (vga_adr_i[16:1]), // 128K
+ .wb_we_i (vga_we_i),
+ .wb_tga_i (vga_tga_i),
+ .wb_sel_i (vga_sel_i),
+ .wb_stb_i (vga_stb_i),
+ .wb_cyc_i (vga_cyc_i),
+ .wb_ack_o (vga_ack_o),
+
+ // VGA pad signals
+ .vga_red_o (tft_lcd_r_),
+ .vga_green_o (tft_lcd_g_),
+ .vga_blue_o (tft_lcd_b_),
+ .horiz_sync (tft_lcd_hsync_),
+ .vert_sync (tft_lcd_vsync_),
+
+ // VGA CPU FML master interface
+ .vga_cpu_fml_adr(vga_cpu_fml_adr),
+ .vga_cpu_fml_stb(vga_cpu_fml_stb),
+ .vga_cpu_fml_we(vga_cpu_fml_we),
+ .vga_cpu_fml_ack(vga_cpu_fml_ack),
+ .vga_cpu_fml_sel(vga_cpu_fml_sel),
+ .vga_cpu_fml_do(vga_cpu_fml_do),
+ .vga_cpu_fml_di(vga_cpu_fml_di),
+
+ // VGA LCD FML master interface
+ .vga_lcd_fml_adr(vga_lcd_fml_adr),
+ .vga_lcd_fml_stb(vga_lcd_fml_stb),
+ .vga_lcd_fml_we(vga_lcd_fml_we),
+ .vga_lcd_fml_ack(vga_lcd_fml_ack),
+ .vga_lcd_fml_sel(vga_lcd_fml_sel),
+ .vga_lcd_fml_do(vga_lcd_fml_do),
+ .vga_lcd_fml_di(vga_lcd_fml_di),
+
+ .vga_clk(vga_clk)
+
+ );
+
+ // RS232 COM1 Port
+ serial com1 (
+ .wb_clk_i (clk), // Main Clock
+ .wb_rst_i (rst), // Reset Line
+ .wb_adr_i (uart_adr_i[2:1]), // Address lines
+ .wb_sel_i (uart_sel_i), // Select lines
+ .wb_dat_i (uart_dat_i), // Command to send
+ .wb_dat_o (uart_dat_o),
+ .wb_we_i (uart_we_i), // Write enable
+ .wb_stb_i (uart_stb_i),
+ .wb_cyc_i (uart_cyc_i),
+ .wb_ack_o (uart_ack_o),
+ .wb_tgc_o (intv[4]), // Interrupt request
+
+ .rs232_tx (uart_txd_), // UART signals
+ .rs232_rx (uart_rxd_) // serial input/output
+ );
+
+ ps2 ps2 (
+ .wb_clk_i (clk), // Main Clock
+ .wb_rst_i (rst), // Reset Line
+ .wb_adr_i (keyb_adr_i[2:1]), // Address lines
+ .wb_sel_i (keyb_sel_i), // Select lines
+ .wb_dat_i (keyb_dat_i), // Command to send to Ethernet
+ .wb_dat_o (keyb_dat_o),
+ .wb_we_i (keyb_we_i), // Write enable
+ .wb_stb_i (keyb_stb_i),
+ .wb_cyc_i (keyb_cyc_i),
+ .wb_ack_o (keyb_ack_o),
+ .wb_tgk_o (intv[1]), // Keyboard Interrupt request
+ .wb_tgm_o (intv[3]), // Mouse Interrupt request
+
+ .ps2_kbd_clk_ (ps2_kclk_),
+ .ps2_kbd_dat_ (ps2_kdat_),
+ .ps2_mse_clk_ (ps2_mclk_),
+ .ps2_mse_dat_ (ps2_mdat_)
+ );
+
+`ifndef SIMULATION
+ /*
+ * Seems that we have a serious bug in Modelsim that prevents
+ * from simulating when this core is present
+ */
+ speaker speaker (
+ .clk (clk),
+ .rst (rst),
+
+ .wb_dat_i (keyb_dat_i[15:8]),
+ .wb_dat_o (aud_dat_o),
+ .wb_we_i (keyb_we_i),
+ .wb_stb_i (keyb_stb_i),
+ .wb_cyc_i (aud_cyc_i),
+ .wb_ack_o (aud_ack_o),
+
+ .clk_100M (sdram_clk),
+ .clk_25M (vga_clk),
+ .timer2 (timer2_o),
+
+ .i2c_sclk_ (i2c_sclk_),
+ .i2c_sdat_ (i2c_sdat_),
+
+ .aud_adcdat_ (aud_adcdat_),
+ .aud_daclrck_ (aud_daclrck_),
+ .aud_dacdat_ (aud_dacdat_),
+ .aud_bclk_ (aud_bclk_)
+ );
+`else
+ assign aud_dat_o = 16'h0;
+ assign aud_ack_o = keyb_stb_i & aud_cyc_i;
+`endif
+
+ // Selection logic between keyboard and audio ports (port 65h: audio)
+ assign aud_sel_cond = keyb_adr_i[2:1]==2'b00 && keyb_sel_i[1];
+ assign aud_cyc_i = kaud_cyc_i && aud_sel_cond;
+ assign keyb_cyc_i = kaud_cyc_i && !aud_sel_cond;
+ assign kaud_ack_o = aud_cyc_i & aud_ack_o | keyb_cyc_i & keyb_ack_o;
+ assign kaud_dat_o = {8{aud_cyc_i}} & aud_dat_o
+ | {8{keyb_cyc_i}} & keyb_dat_o[15:8];
+
+ timer timer (
+ .wb_clk_i (clk),
+ .wb_rst_i (rst),
+ .wb_adr_i (timer_adr_i[1]),
+ .wb_sel_i (timer_sel_i),
+ .wb_dat_i (timer_dat_i),
+ .wb_dat_o (timer_dat_o),
+ .wb_stb_i (timer_stb_i),
+ .wb_cyc_i (timer_cyc_i),
+ .wb_we_i (timer_we_i),
+ .wb_ack_o (timer_ack_o),
+ .wb_tgc_o (intv[0]),
+ .tclk_i (timer_clk), // 1.193182 MHz = (14.31818/12) MHz
+ .gate2_i (aud_dat_o[0]),
+ .out2_o (timer2_o)
+ );
+
+ simple_pic pic0 (
+ .clk (clk),
+ .rst (rst),
+ .intv (intv),
+ .inta (inta),
+ .intr (intr),
+ .iid (iid)
+ );
+
+ wb_abrgr sd_brg (
+ .sys_rst (rst),
+
+ // Wishbone slave interface
+ .wbs_clk_i (clk),
+ .wbs_adr_i (sd_adr_i_s),
+ .wbs_dat_i (sd_dat_i_s),
+ .wbs_dat_o (sd_dat_o_s),
+ .wbs_sel_i (sd_sel_i_s),
+ .wbs_tga_i (sd_tga_i_s),
+ .wbs_stb_i (sd_stb_i_s),
+ .wbs_cyc_i (sd_cyc_i_s),
+ .wbs_we_i (sd_we_i_s),
+ .wbs_ack_o (sd_ack_o_s),
+
+ // Wishbone master interface
+ .wbm_clk_i (sdram_clk),
+ .wbm_adr_o (sd_adr_i),
+ .wbm_dat_o (sd_dat_i),
+ .wbm_dat_i ({8'h0,sd_dat_o}),
+ .wbm_tga_o (sd_tga_i),
+ .wbm_sel_o (sd_sel_i),
+ .wbm_stb_o (sd_stb_i),
+ .wbm_cyc_o (sd_cyc_i),
+ .wbm_we_o (sd_we_i),
+ .wbm_ack_i (sd_ack_o)
+ );
+
+ sdspi sdspi (
+ // Serial pad signal
+ .sclk (sd_sclk_),
+ .miso (sd_miso_),
+ .mosi (sd_mosi_),
+ .ss (sd_ss_),
+
+ // Wishbone slave interface
+ .wb_clk_i (sdram_clk),
+ .wb_rst_i (rst),
+ .wb_dat_i (sd_dat_i[8:0]),
+ .wb_dat_o (sd_dat_o),
+ .wb_we_i (sd_we_i),
+ .wb_sel_i (sd_sel_i),
+ .wb_stb_i (sd_stb_i),
+ .wb_cyc_i (sd_cyc_i),
+ .wb_ack_o (sd_ack_o)
+ );
+
+ // Switches and leds
+ sw_leds sw_leds (
+ .wb_clk_i (clk),
+ .wb_rst_i (rst),
+
+ // Wishbone slave interface
+ .wb_adr_i (gpio_adr_i[1]),
+ .wb_dat_o (gpio_dat_o),
+ .wb_dat_i (gpio_dat_i),
+ .wb_sel_i (gpio_sel_i),
+ .wb_we_i (gpio_we_i),
+ .wb_stb_i (gpio_stb_i),
+ .wb_cyc_i (gpio_cyc_i),
+ .wb_ack_o (gpio_ack_o),
+
+ // GPIO inputs/outputs
+ .leds_ ({ledr_,ledg_[7:4]}),
+ .sw_ (sw_),
+ .pb_ (key_),
+ .tick (intv[0]),
+ .nmi_pb (nmi_pb) // NMI from pushbutton
+ );
+
+ hex_display hex16 (
+ .num (pc[19:4]),
+ .en (1'b1),
+
+ .hex0 (hex0_),
+ .hex1 (hex1_),
+ .hex2 (hex2_),
+ .hex3 (hex3_)
+ );
+
+ zet zet (
+ .pc (pc),
+
+ // Wishbone master interface
+ .wb_clk_i (clk),
+ .wb_rst_i (rst),
+ .wb_dat_i (dat_i),
+ .wb_dat_o (dat_o),
+ .wb_adr_o (adr),
+ .wb_we_o (we),
+ .wb_tga_o (tga),
+ .wb_sel_o (sel),
+ .wb_stb_o (stb),
+ .wb_cyc_o (cyc),
+ .wb_ack_i (ack),
+ .wb_tgc_i (intr),
+ .wb_tgc_o (inta),
+ .nmi (nmi),
+ .nmia (nmia)
+ );
+
+ wb_switch #(
+ .s0_addr_1 (20'b0_1111_1111_1111_0000_000), // bios boot mem 0xfff00 - 0xfffff
+ .s0_mask_1 (20'b1_1111_1111_1111_0000_000), // bios boot ROM Memory
+
+ .s1_addr_1 (20'b0_1010_0000_0000_0000_000), // mem 0xa0000 - 0xbffff
+ .s1_mask_1 (20'b1_1110_0000_0000_0000_000), // VGA
+
+ .s1_addr_2 (20'b1_0000_0000_0011_1100_000), // io 0x3c0 - 0x3df
+ .s1_mask_2 (20'b1_0000_1111_1111_1110_000), // VGA IO
+
+ .s2_addr_1 (20'b1_0000_0000_0011_1111_100), // io 0x3f8 - 0x3ff
+ .s2_mask_1 (20'b1_0000_1111_1111_1111_100), // RS232 IO
+
+ .s3_addr_1 (20'b1_0000_0000_0000_0110_000), // io 0x60, 0x64
+ .s3_mask_1 (20'b1_0000_1111_1111_1111_101), // Keyboard / Mouse IO
+
+ .s4_addr_1 (20'b1_0000_0000_0001_0000_000), // io 0x100 - 0x101
+ .s4_mask_1 (20'b1_0000_1111_1111_1111_111), // SD Card IO
+
+ .s5_addr_1 (20'b1_0000_1111_0001_0000_000), // io 0xf100 - 0xf103
+ .s5_mask_1 (20'b1_0000_1111_1111_1111_110), // GPIO
+
+ .s6_addr_1 (20'b1_0000_1111_0010_0000_000), // io 0xf200 - 0xf20f
+ .s6_mask_1 (20'b1_0000_1111_1111_1111_000), // CSR Bridge SDRAM Control
+
+ .s7_addr_1 (20'b1_0000_0000_0000_0100_000), // io 0x40 - 0x43
+ .s7_mask_1 (20'b1_0000_1111_1111_1111_110), // Timer control port
+
+ .s8_addr_1 (20'b1_0000_0000_0010_0011_100), // io 0x0238 - 0x023b
+ .s8_mask_1 (20'b1_0000_1111_1111_1111_110), // Flash IO port
+
+ .s9_addr_1 (20'b1_0000_0000_0010_0001_000), // io 0x0210 - 0x021F
+ .s9_mask_1 (20'b1_0000_1111_1111_1111_000), // Sound Blaster
+
+ .sA_addr_1 (20'b1_0000_1111_0011_0000_000), // io 0xf300 - 0xf3ff
+ .sA_mask_1 (20'b1_0000_1111_1111_0000_000), // SDRAM Control
+ .sA_addr_2 (20'b0_0000_0000_0000_0000_000), // mem 0x00000 - 0xfffff
+ .sA_mask_2 (20'b1_0000_0000_0000_0000_000) // Base RAM
+
+ ) wbs (
+
+ // Master interface
+ .m_dat_i (dat_o),
+ .m_dat_o (sw_dat_o),
+ .m_adr_i ({tga,adr}),
+ .m_sel_i (sel),
+ .m_we_i (we),
+ .m_cyc_i (cyc),
+ .m_stb_i (stb),
+ .m_ack_o (ack),
+
+ // Slave 0 interface - bios rom
+ .s0_dat_i (rom_dat_o),
+ .s0_dat_o (rom_dat_i),
+ .s0_adr_o ({rom_tga_i,rom_adr_i}),
+ .s0_sel_o (rom_sel_i),
+ .s0_we_o (rom_we_i),
+ .s0_cyc_o (rom_cyc_i),
+ .s0_stb_o (rom_stb_i),
+ .s0_ack_i (rom_ack_o),
+
+ // Slave 1 interface - vga
+ .s1_dat_i (vga_dat_o_s),
+ .s1_dat_o (vga_dat_i_s),
+ .s1_adr_o ({vga_tga_i_s,vga_adr_i_s}),
+ .s1_sel_o (vga_sel_i_s),
+ .s1_we_o (vga_we_i_s),
+ .s1_cyc_o (vga_cyc_i_s),
+ .s1_stb_o (vga_stb_i_s),
+ .s1_ack_i (vga_ack_o_s),
+
+ // Slave 2 interface - uart
+ .s2_dat_i (uart_dat_o),
+ .s2_dat_o (uart_dat_i),
+ .s2_adr_o ({uart_tga_i,uart_adr_i}),
+ .s2_sel_o (uart_sel_i),
+ .s2_we_o (uart_we_i),
+ .s2_cyc_o (uart_cyc_i),
+ .s2_stb_o (uart_stb_i),
+ .s2_ack_i (uart_ack_o),
+
+ // Slave 3 interface - keyb
+ .s3_dat_i ({kaud_dat_o,keyb_dat_o[7:0]}),
+ .s3_dat_o (keyb_dat_i),
+ .s3_adr_o ({keyb_tga_i,keyb_adr_i}),
+ .s3_sel_o (keyb_sel_i),
+ .s3_we_o (keyb_we_i),
+ .s3_cyc_o (kaud_cyc_i),
+ .s3_stb_o (keyb_stb_i),
+ .s3_ack_i (kaud_ack_o),
+
+ // Slave 4 interface - sd
+ .s4_dat_i (sd_dat_o_s),
+ .s4_dat_o (sd_dat_i_s),
+ .s4_adr_o ({sd_tga_i_s,sd_adr_i_s}),
+ .s4_sel_o (sd_sel_i_s),
+ .s4_we_o (sd_we_i_s),
+ .s4_cyc_o (sd_cyc_i_s),
+ .s4_stb_o (sd_stb_i_s),
+ .s4_ack_i (sd_ack_o_s),
+
+ // Slave 5 interface - gpio
+ .s5_dat_i (gpio_dat_o),
+ .s5_dat_o (gpio_dat_i),
+ .s5_adr_o ({gpio_tga_i,gpio_adr_i}),
+ .s5_sel_o (gpio_sel_i),
+ .s5_we_o (gpio_we_i),
+ .s5_cyc_o (gpio_cyc_i),
+ .s5_stb_o (gpio_stb_i),
+ .s5_ack_i (gpio_ack_o),
+
+ // Slave 6 interface - csr bridge
+ .s6_dat_i (csrbrg_dat_r_s),
+ .s6_dat_o (csrbrg_dat_w_s),
+ .s6_adr_o ({csrbrg_tga_s,csrbrg_adr_s}),
+ .s6_sel_o (csrbrg_sel_s),
+ .s6_we_o (csrbrg_we_s),
+ .s6_cyc_o (csrbrg_cyc_s),
+ .s6_stb_o (csrbrg_stb_s),
+ .s6_ack_i (csrbrg_ack_s),
+
+ // Slave 7 interface - timer
+ .s7_dat_i (timer_dat_o),
+ .s7_dat_o (timer_dat_i),
+ .s7_adr_o ({timer_tga_i,timer_adr_i}),
+ .s7_sel_o (timer_sel_i),
+ .s7_we_o (timer_we_i),
+ .s7_cyc_o (timer_cyc_i),
+ .s7_stb_o (timer_stb_i),
+ .s7_ack_i (timer_ack_o),
+
+ // Slave 8 interface - flash
+ .s8_dat_i (fl_dat_o),
+ .s8_dat_o (fl_dat_i),
+ .s8_adr_o ({fl_tga_i,fl_adr_i}),
+ .s8_sel_o (fl_sel_i),
+ .s8_we_o (fl_we_i),
+ .s8_cyc_o (fl_cyc_i),
+ .s8_stb_o (fl_stb_i),
+ .s8_ack_i (fl_ack_o),
+
+ // Slave 9 interface - not connected
+ .s9_dat_i (),
+ .s9_dat_o (),
+ .s9_adr_o (),
+ .s9_sel_o (),
+ .s9_we_o (),
+ .s9_cyc_o (sb_cyc_i),
+ .s9_stb_o (sb_stb_i),
+ .s9_ack_i (sb_cyc_i && sb_stb_i),
+
+ // Slave A interface - sdram
+ .sA_dat_i (fmlbrg_dat_r_s),
+ .sA_dat_o (fmlbrg_dat_w_s),
+ .sA_adr_o ({fmlbrg_tga_s,fmlbrg_adr_s}),
+ .sA_sel_o (fmlbrg_sel_s),
+ .sA_we_o (fmlbrg_we_s),
+ .sA_cyc_o (fmlbrg_cyc_s),
+ .sA_stb_o (fmlbrg_stb_s),
+ .sA_ack_i (fmlbrg_ack_s),
+
+ // Slave B interface - default
+ .sB_dat_i (16'h0000),
+ .sB_dat_o (),
+ .sB_adr_o (),
+ .sB_sel_o (),
+ .sB_we_o (),
+ .sB_cyc_o (def_cyc_i),
+ .sB_stb_o (def_stb_i),
+ .sB_ack_i (def_cyc_i & def_stb_i)
+ );
+
+ // Continuous assignments
+ assign rst_lck = !sw_[0] & lock;
+
+ assign nmi = nmi_pb;
+ assign dat_i = nmia ? 16'h0002 :
+ (inta ? { 13'b0000_0000_0000_1, iid } :
+ sw_dat_o);
+
+ // Required de2-115 adv7123 vga dac clock
+ assign tft_lcd_clk_ = vga_clk;
+
+ assign ledg_[3:0] = pc[3:0];
+
+endmodule
+"
+"/*
+ * Milkymist SoC
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
+ * adjusted to FML 8x16 by Charley Picker
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+module fmlarb #(
+\tparameter fml_depth = 26
+) (
+\tinput sys_clk,
+\tinput sys_rst,
+\t
+\t/* Interface 0 has higher priority than the others */
+\tinput [fml_depth-1:0] m0_adr,
+\tinput m0_stb,
+\tinput m0_we,
+\toutput m0_ack,
+\tinput [1:0] m0_sel,
+\tinput [15:0] m0_di,
+\toutput [15:0] m0_do,
+\t
+\tinput [fml_depth-1:0] m1_adr,
+\tinput m1_stb,
+\tinput m1_we,
+\toutput m1_ack,
+\tinput [1:0] m1_sel,
+\tinput [15:0] m1_di,
+\toutput [15:0] m1_do,
+\t
+\tinput [fml_depth-1:0] m2_adr,
+\tinput m2_stb,
+\tinput m2_we,
+\toutput m2_ack,
+\tinput [1:0] m2_sel,
+\tinput [15:0] m2_di,
+\toutput [15:0] m2_do,
+\t
+\tinput [fml_depth-1:0] m3_adr,
+\tinput m3_stb,
+\tinput m3_we,
+\toutput m3_ack,
+\tinput [1:0] m3_sel,
+\tinput [15:0] m3_di,
+\toutput [15:0] m3_do,
+
+\tinput [fml_depth-1:0] m4_adr,
+\tinput m4_stb,
+\tinput m4_we,
+\toutput m4_ack,
+\tinput [1:0] m4_sel,
+\tinput [15:0] m4_di,
+\toutput [15:0] m4_do,
+
+\tinput [fml_depth-1:0] m5_adr,
+\tinput m5_stb,
+\tinput m5_we,
+\toutput m5_ack,
+\tinput [1:0] m5_sel,
+\tinput [15:0] m5_di,
+\toutput [15:0] m5_do,
+\t
+\toutput reg [fml_depth-1:0] s_adr,
+\toutput reg s_stb,
+\toutput reg s_we,
+\tinput s_ack,
+\toutput reg [1:0] s_sel,
+\tinput [15:0] s_di,
+\toutput reg [15:0] s_do
+);
+
+assign m0_do = s_di;
+assign m1_do = s_di;
+assign m2_do = s_di;
+assign m3_do = s_di;
+assign m4_do = s_di;
+assign m5_do = s_di;
+
+reg [2:0] master;
+reg [2:0] next_master;
+
+always @(posedge sys_clk) begin
+\tif(sys_rst)
+\t\tmaster <= 3'd0;
+\telse
+\t\tmaster <= next_master;
+end
+
+/* Decide the next master */
+always @(*) begin
+\t/* By default keep our current master */
+\tnext_master = master;
+\t
+\tcase(master)
+\t\t3'd0: if(~m0_stb | s_ack) begin
+\t\t\tif(m1_stb) next_master = 3'd1;
+\t\t\telse if(m2_stb) next_master = 3'd2;
+\t\t\telse if(m3_stb) next_master = 3'd3;
+\t\t\telse if(m4_stb) next_master = 3'd4;
+\t\t\telse if(m5_stb) next_master = 3'd5;
+\t\tend
+\t\t3'd1: if(~m1_stb | s_ack) begin
+\t\t\tif(m0_stb) next_master = 3'd0;
+\t\t\telse if(m3_stb) next_master = 3'd3;
+\t\t\telse if(m4_stb) next_master = 3'd4;
+\t\t\telse if(m5_stb) next_master = 3'd5;
+\t\t\telse if(m2_stb) next_master = 3'd2;
+\t\tend
+\t\t3'd2: if(~m2_stb | s_ack) begin
+\t\t\tif(m0_stb) next_master = 3'd0;
+\t\t\telse if(m3_stb) next_master = 3'd3;
+\t\t\telse if(m4_stb) next_master = 3'd4;
+\t\t\telse if(m5_stb) next_master = 3'd5;
+\t\t\telse if(m1_stb) next_master = 3'd1;
+\t\tend
+\t\t3'd3: if(~m3_stb | s_ack) begin
+\t\t\tif(m0_stb) next_master = 3'd0;
+\t\t\telse if(m4_stb) next_master = 3'd4;
+\t\t\telse if(m5_stb) next_master = 3'd5;
+\t\t\telse if(m1_stb) next_master = 3'd1;
+\t\t\telse if(m2_stb) next_master = 3'd2;
+\t\tend
+\t\t3'd4: if(~m4_stb | s_ack) begin
+\t\t\tif(m0_stb) next_master = 3'd0;
+\t\t\telse if(m5_stb) next_master = 3'd5;
+\t\t\telse if(m1_stb) next_master = 3'd1;
+\t\t\telse if(m2_stb) next_master = 3'd2;
+\t\t\telse if(m3_stb) next_master = 3'd3;
+\t\tend
+\t\tdefault: if(~m5_stb | s_ack) begin // 3'd5
+\t\t\tif(m0_stb) next_master = 3'd0;
+\t\t\telse if(m1_stb) next_master = 3'd1;
+\t\t\telse if(m2_stb) next_master = 3'd2;
+\t\t\telse if(m3_stb) next_master = 3'd3;
+\t\t\telse if(m4_stb) next_master = 3'd4;
+\t\tend
+\tendcase
+end
+
+/* Generate ack signals */
+assign m0_ack = (master == 3'd0) & s_ack;
+assign m1_ack = (master == 3'd1) & s_ack;
+assign m2_ack = (master == 3'd2) & s_ack;
+assign m3_ack = (master == 3'd3) & s_ack;
+assign m4_ack = (master == 3'd4) & s_ack;
+assign m5_ack = (master == 3'd5) & s_ack;
+
+/* Mux control signals */
+always @(*) begin
+\tcase(master)
+\t\t3'd0: begin
+\t\t\ts_adr = m0_adr;
+\t\t\ts_stb = m0_stb;
+\t\t\ts_we = m0_we;
+\t\tend
+\t\t3'd1: begin
+\t\t\ts_adr = m1_adr;
+\t\t\ts_stb = m1_stb;
+\t\t\ts_we = m1_we;
+\t\tend
+\t\t3'd2: begin
+\t\t\ts_adr = m2_adr;
+\t\t\ts_stb = m2_stb;
+\t\t\ts_we = m2_we;
+\t\tend
+\t\t3'd3: begin
+\t\t\ts_adr = m3_adr;
+\t\t\ts_stb = m3_stb;
+\t\t\ts_we = m3_we;
+\t\tend
+\t\t3'd4: begin
+\t\t\ts_adr = m4_adr;
+\t\t\ts_stb = m4_stb;
+\t\t\ts_we = m4_we;
+\t\tend
+\t\tdefault: begin // 3'd5
+\t\t\ts_adr = m5_adr;
+\t\t\ts_stb = m5_stb;
+\t\t\ts_we = m5_we;
+\t\tend
+\tendcase
+end
+
+/* Mux data write signals */
+
+wire write_burst_start = s_we & s_ack;
+
+reg [2:0] wmaster;
+reg [2:0] burst_counter;
+
+always @(posedge sys_clk) begin
+\tif(sys_rst) begin
+\t\twmaster <= 3'd0;
+\t\tburst_counter <= 3'd0;
+\tend else begin
+\t\tif(|burst_counter)
+\t\t\tburst_counter <= burst_counter - 3'd1;
+\t\tif(write_burst_start)
+\t\t\tburst_counter <= 3'd6;
+\t\tif(~write_burst_start & ~(|burst_counter))
+\t\t\twmaster <= next_master;
+\tend
+end
+
+always @(*) begin
+\tcase(wmaster)
+\t\t3'd0: begin
+\t\t\ts_do = m0_di;
+\t\t\ts_sel = m0_sel;
+\t\tend
+\t\t3'd1: begin
+\t\t\ts_do = m1_di;
+\t\t\ts_sel = m1_sel;
+\t\tend
+\t\t3'd2: begin
+\t\t\ts_do = m2_di;
+\t\t\ts_sel = m2_sel;
+\t\tend
+\t\t3'd3: begin
+\t\t\ts_do = m3_di;
+\t\t\ts_sel = m3_sel;
+\t\tend
+\t\t3'd4: begin
+\t\t\ts_do = m4_di;
+\t\t\ts_sel = m4_sel;
+\t\tend
+\t\tdefault: begin // 3'd5
+\t\t\ts_do = m5_di;
+\t\t\ts_sel = m5_sel;
+\t\tend
+\tendcase
+end
+
+endmodule
+"
+"/*
+ * Integer conversion module for Zet
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_conv (
+ input [15:0] x,
+ input [ 2:0] func,
+ output [31:0] out,
+ input [ 1:0] iflags, // afi, cfi
+ output [ 2:0] oflags // afo, ofo, cfo
+ );
+
+ // Net declarations
+ wire afi, cfi;
+ wire ofo, afo, cfo;
+ wire [15:0] aaa, aas;
+ wire [ 7:0] daa, tmpdaa, das, tmpdas;
+ wire [15:0] cbw, cwd;
+
+ wire acond, dcond;
+ wire tmpcf;
+
+ // Module instances
+ zet_mux8_16 mux8_16 (func, cbw, aaa, aas, 16'd0,
+ cwd, {x[15:8], daa}, {x[15:8], das}, 16'd0, out[15:0]);
+
+ // Assignments
+ assign aaa = (acond ? (x + 16'h0106) : x) & 16'hff0f;
+ assign aas = (acond ? (x - 16'h0106) : x) & 16'hff0f;
+
+ assign tmpdaa = acond ? (x[7:0] + 8'h06) : x[7:0];
+ assign daa = dcond ? (tmpdaa + 8'h60) : tmpdaa;
+ assign tmpdas = acond ? (x[7:0] - 8'h06) : x[7:0];
+ assign das = dcond ? (tmpdas - 8'h60) : tmpdas;
+
+ assign cbw = { { 8{x[ 7]}}, x[7:0] };
+ assign { out[31:16], cwd } = { {16{x[15]}}, x };
+
+ assign acond = ((x[7:0] & 8'h0f) > 8'h09) | afi;
+ assign dcond = (x[7:0] > 8'h99) | cfi;
+
+ assign afi = iflags[1];
+ assign cfi = iflags[0];
+
+ assign afo = acond;
+ assign ofo = 1'b0;
+ assign tmpcf = (x[7:0] < 8'h06) | cfi;
+ assign cfo = func[2] ? (dcond ? 1'b1 : (acond & tmpcf))
+ : acond;
+
+ assign oflags = { afo, ofo, cfo };
+endmodule
+"
+"/*
+ * RS-232 asynchronous TX module
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module serial_atx (
+ input clk,
+ input txd_start,
+ input baud1tick, // Desired baud rate
+ input [7:0] txd_data,
+ output reg txd, // Put together the start, data and stop bits
+ output txd_busy
+ );
+
+ // Transmitter state machine
+ parameter RegisterInputData = 1; // in RegisterInputData mode, the input doesn't have to stay valid while the character is been transmitted
+ reg [3:0] state;
+ wire BaudTick = txd_busy ? baud1tick : 1'b0;
+ wire txd_ready;
+
+ reg [7:0] txd_dataReg;
+
+ // Continuous assignments
+ assign txd_ready = (state==0);
+ assign txd_busy = ~txd_ready;
+
+ always @(posedge clk) if(txd_ready & txd_start) txd_dataReg <= txd_data;
+ wire [7:0] txd_dataD = RegisterInputData ? txd_dataReg : txd_data;
+
+ always @(posedge clk)
+ case(state)
+ 4'b0000: if(txd_start) state <= 4'b0001;
+ 4'b0001: if(BaudTick) state <= 4'b0100;
+ 4'b0100: if(BaudTick) state <= 4'b1000; // start
+ 4'b1000: if(BaudTick) state <= 4'b1001; // bit 0
+ 4'b1001: if(BaudTick) state <= 4'b1010; // bit 1
+ 4'b1010: if(BaudTick) state <= 4'b1011; // bit 2
+ 4'b1011: if(BaudTick) state <= 4'b1100; // bit 3
+ 4'b1100: if(BaudTick) state <= 4'b1101; // bit 4
+ 4'b1101: if(BaudTick) state <= 4'b1110; // bit 5
+ 4'b1110: if(BaudTick) state <= 4'b1111; // bit 6
+ 4'b1111: if(BaudTick) state <= 4'b0010; // bit 7
+ 4'b0010: if(BaudTick) state <= 4'b0011; // stop1
+ 4'b0011: if(BaudTick) state <= 4'b0000; // stop2
+ default: if(BaudTick) state <= 4'b0000;
+ endcase
+
+ reg muxbit; // Output mux
+ always @( * )
+ case(state[2:0])
+ 3'd0: muxbit <= txd_dataD[0];
+ 3'd1: muxbit <= txd_dataD[1];
+ 3'd2: muxbit <= txd_dataD[2];
+ 3'd3: muxbit <= txd_dataD[3];
+ 3'd4: muxbit <= txd_dataD[4];
+ 3'd5: muxbit <= txd_dataD[5];
+ 3'd6: muxbit <= txd_dataD[6];
+ 3'd7: muxbit <= txd_dataD[7];
+ endcase
+
+ always @(posedge clk) txd <= (state<4) | (state[3] & muxbit); // register the output to make it glitch free
+
+endmodule
+
+"
+"/*
+ * Decoder for x86 memory access registers
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_memory_regs (
+ input [2:0] rm,
+ input [1:0] mod,
+ input [2:0] sovr_pr,
+
+ output reg [3:0] base,
+ output reg [3:0] index,
+ output [1:0] seg
+ );
+
+ // Register declaration
+ reg [1:0] s;
+
+ // Continuous assignments
+ assign seg = sovr_pr[2] ? sovr_pr[1:0] : s;
+
+ // Behaviour
+ always @(rm or mod)
+ case (rm)
+ 3'b000: begin base <= 4'b0011; index <= 4'b0110; s <= 2'b11; end
+ 3'b001: begin base <= 4'b0011; index <= 4'b0111; s <= 2'b11; end
+ 3'b010: begin base <= 4'b0101; index <= 4'b0110; s <= 2'b10; end
+ 3'b011: begin base <= 4'b0101; index <= 4'b0111; s <= 2'b10; end
+ 3'b100: begin base <= 4'b1100; index <= 4'b0110; s <= 2'b11; end
+ 3'b101: begin base <= 4'b1100; index <= 4'b0111; s <= 2'b11; end
+ 3'b110: begin base <= mod ? 4'b0101 : 4'b1100; index <= 4'b1100;
+ s <= mod ? 2'b10 : 2'b11; end
+ 3'b111: begin base <= 4'b0011; index <= 4'b1100; s <= 2'b11; end
+ endcase
+endmodule
+"
+"// megafunction wizard: %ALTPLL%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altpll
+
+// ============================================================
+// File Name: pll.v
+// Megafunction Name(s):
+// \t\t\taltpll
+//
+// Simulation Library Files(s):
+// \t\t\taltera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 13.0.1 Build 232 06/12/2013 SP 1 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2013 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module pll (
+\tinclk0,
+\tc0,
+\tc2,
+\tlocked);
+
+\tinput\t inclk0;
+\toutput\t c0;
+\toutput\t c2;
+\toutput\t locked;
+
+\twire sub_wire0;
+\twire [5:0] sub_wire1;
+\twire [0:0] sub_wire6 = 1\'h0;
+\twire locked = sub_wire0;
+\twire [2:2] sub_wire3 = sub_wire1[2:2];
+\twire [0:0] sub_wire2 = sub_wire1[0:0];
+\twire c0 = sub_wire2;
+\twire c2 = sub_wire3;
+\twire sub_wire4 = inclk0;
+\twire [1:0] sub_wire5 = {sub_wire6, sub_wire4};
+
+\taltpll\taltpll_component (
+\t\t\t\t.inclk (sub_wire5),
+\t\t\t\t.locked (sub_wire0),
+\t\t\t\t.clk (sub_wire1),
+\t\t\t\t.activeclock (),
+\t\t\t\t.areset (1\'b0),
+\t\t\t\t.clkbad (),
+\t\t\t\t.clkena ({6{1\'b1}}),
+\t\t\t\t.clkloss (),
+\t\t\t\t.clkswitch (1\'b0),
+\t\t\t\t.configupdate (1\'b0),
+\t\t\t\t.enable0 (),
+\t\t\t\t.enable1 (),
+\t\t\t\t.extclk (),
+\t\t\t\t.extclkena ({4{1\'b1}}),
+\t\t\t\t.fbin (1\'b1),
+\t\t\t\t.fbmimicbidir (),
+\t\t\t\t.fbout (),
+\t\t\t\t.fref (),
+\t\t\t\t.icdrclk (),
+\t\t\t\t.pfdena (1\'b1),
+\t\t\t\t.phasecounterselect ({4{1\'b1}}),
+\t\t\t\t.phasedone (),
+\t\t\t\t.phasestep (1\'b1),
+\t\t\t\t.phaseupdown (1\'b1),
+\t\t\t\t.pllena (1\'b1),
+\t\t\t\t.scanaclr (1\'b0),
+\t\t\t\t.scanclk (1\'b0),
+\t\t\t\t.scanclkena (1\'b1),
+\t\t\t\t.scandata (1\'b0),
+\t\t\t\t.scandataout (),
+\t\t\t\t.scandone (),
+\t\t\t\t.scanread (1\'b0),
+\t\t\t\t.scanwrite (1\'b0),
+\t\t\t\t.sclkout0 (),
+\t\t\t\t.sclkout1 (),
+\t\t\t\t.vcooverrange (),
+\t\t\t\t.vcounderrange ());
+\tdefparam
+\t\taltpll_component.clk0_divide_by = 1,
+\t\taltpll_component.clk0_duty_cycle = 50,
+\t\taltpll_component.clk0_multiply_by = 2,
+\t\taltpll_component.clk0_phase_shift = ""-2917"",
+\t\taltpll_component.clk2_divide_by = 4,
+\t\taltpll_component.clk2_duty_cycle = 50,
+\t\taltpll_component.clk2_multiply_by = 1,
+\t\taltpll_component.clk2_phase_shift = ""0"",
+\t\taltpll_component.compensate_clock = ""CLK0"",
+\t\taltpll_component.gate_lock_counter = 1048575,
+\t\taltpll_component.gate_lock_signal = ""YES"",
+\t\taltpll_component.inclk0_input_frequency = 20000,
+\t\taltpll_component.intended_device_family = ""Cyclone II"",
+\t\taltpll_component.invalid_lock_multiplier = 5,
+\t\taltpll_component.lpm_hint = ""CBX_MODULE_PREFIX=pll"",
+\t\taltpll_component.lpm_type = ""altpll"",
+\t\taltpll_component.operation_mode = ""NORMAL"",
+\t\taltpll_component.port_activeclock = ""PORT_UNUSED"",
+\t\taltpll_component.port_areset = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkbad0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkbad1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkloss = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkswitch = ""PORT_UNUSED"",
+\t\taltpll_component.port_configupdate = ""PORT_UNUSED"",
+\t\taltpll_component.port_fbin = ""PORT_UNUSED"",
+\t\taltpll_component.port_inclk0 = ""PORT_USED"",
+\t\taltpll_component.port_inclk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_locked = ""PORT_USED"",
+\t\taltpll_component.port_pfdena = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasecounterselect = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasedone = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasestep = ""PORT_UNUSED"",
+\t\taltpll_component.port_phaseupdown = ""PORT_UNUSED"",
+\t\taltpll_component.port_pllena = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanaclr = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanclk = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanclkena = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandata = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandataout = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandone = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanread = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanwrite = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk0 = ""PORT_USED"",
+\t\taltpll_component.port_clk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk2 = ""PORT_USED"",
+\t\taltpll_component.port_clk3 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk4 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk5 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena2 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena3 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena4 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena5 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk2 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk3 = ""PORT_UNUSED"",
+\t\taltpll_component.valid_lock_multiplier = 1;
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH STRING ""1.000""
+// Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING ""MHz""
+// Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING ""Low""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING ""1""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_CUSTOM STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING ""0""
+// Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CLKLOSS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING ""1""
+// Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING ""0""
+// Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING ""c0""
+// Retrieval info: PRIVATE: CUR_FBIN_CLK STRING ""e0""
+// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING ""Any""
+// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: DIV_FACTOR2 NUMERIC ""4""
+// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING ""50.00000000""
+// Retrieval info: PRIVATE: DUTY_CYCLE2 STRING ""50.00000000""
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING ""100.000000""
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE2 STRING ""12.500000""
+// Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING ""0""
+// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING ""0""
+// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING ""1""
+// Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC ""1048575""
+// Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING ""1""
+// Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING ""50.000""
+// Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING ""100.000""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""
+// Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING ""1""
+// Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING ""1""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING ""Not Available""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC ""0""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT2 STRING ""ps""
+// Retrieval info: PRIVATE: MIG_DEVICE_SPEED_GRADE STRING ""Any""
+// Retrieval info: PRIVATE: MIRROR_CLK0 STRING ""0""
+// Retrieval info: PRIVATE: MIRROR_CLK2 STRING ""0""
+// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: MULT_FACTOR2 NUMERIC ""1""
+// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING ""100.00000000""
+// Retrieval info: PRIVATE: OUTPUT_FREQ2 STRING ""10000000.00000000""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE2 STRING ""0""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING ""MHz""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT2 STRING ""MHz""
+// Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: PHASE_RECONFIG_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING ""-2.91666700""
+// Retrieval info: PRIVATE: PHASE_SHIFT2 STRING ""0.00000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT_STEP_ENABLED_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING ""ns""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT2 STRING ""ps""
+// Retrieval info: PRIVATE: PLL_ADVANCED_PARAM_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC ""1""
+// Retrieval info: PRIVATE: PLL_ENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_FBMIMIC_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_TARGET_HARCOPY_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING ""inclk0""
+// Retrieval info: PRIVATE: RECONFIG_FILE STRING ""pll.mif""
+// Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: SELF_RESET_LOCK_LOSS STRING ""0""
+// Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FREQ STRING ""50.000""
+// Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING ""KHz""
+// Retrieval info: PRIVATE: SPREAD_PERCENT STRING ""0.500""
+// Retrieval info: PRIVATE: SPREAD_USE STRING ""0""
+// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING ""0""
+// Retrieval info: PRIVATE: STICKY_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: STICKY_CLK2 STRING ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING ""0""
+// Retrieval info: PRIVATE: USE_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: USE_CLK2 STRING ""1""
+// Retrieval info: PRIVATE: USE_CLKENA0 STRING ""0""
+// Retrieval info: PRIVATE: USE_CLKENA2 STRING ""0""
+// Retrieval info: PRIVATE: USE_MIL_SPEED_GRADE NUMERIC ""0""
+// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING ""0""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC ""2""
+// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING ""-2917""
+// Retrieval info: CONSTANT: CLK2_DIVIDE_BY NUMERIC ""4""
+// Retrieval info: CONSTANT: CLK2_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: CLK2_MULTIPLY_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: CLK2_PHASE_SHIFT STRING ""0""
+// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING ""CLK0""
+// Retrieval info: CONSTANT: GATE_LOCK_COUNTER NUMERIC ""1048575""
+// Retrieval info: CONSTANT: GATE_LOCK_SIGNAL STRING ""YES""
+// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC ""20000""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""
+// Retrieval info: CONSTANT: INVALID_LOCK_MULTIPLIER NUMERIC ""5""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""altpll""
+// Retrieval info: CONSTANT: OPERATION_MODE STRING ""NORMAL""
+// Retrieval info: CONSTANT: PORT_ACTIVECLOCK STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_ARESET STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKBAD0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKBAD1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKLOSS STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKSWITCH STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CONFIGUPDATE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_FBIN STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_INCLK0 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_INCLK1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_LOCKED STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_PFDENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASECOUNTERSELECT STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASEDONE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASESTEP STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASEUPDOWN STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PLLENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANACLR STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANCLK STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANCLKENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDATA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDATAOUT STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDONE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANREAD STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANWRITE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk0 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_clk1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk2 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_clk3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk4 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk5 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena4 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena5 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: VALID_LOCK_MULTIPLIER NUMERIC ""1""
+// Retrieval info: USED_PORT: @clk 0 0 6 0 OUTPUT_CLK_EXT VCC ""@clk[5..0]""
+// Retrieval info: USED_PORT: @extclk 0 0 4 0 OUTPUT_CLK_EXT VCC ""@extclk[3..0]""
+// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT_CLK_EXT VCC ""c0""
+// Retrieval info: USED_PORT: c2 0 0 0 0 OUTPUT_CLK_EXT VCC ""c2""
+// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT_CLK_EXT GND ""inclk0""
+// Retrieval info: USED_PORT: locked 0 0 0 0 OUTPUT GND ""locked""
+// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
+// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
+// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
+// Retrieval info: CONNECT: c2 0 0 0 0 @clk 0 0 1 2
+// Retrieval info: CONNECT: locked 0 0 0 0 @locked 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.ppf TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.bsf TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_bb.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_waveforms.html FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_wave*.jpg FALSE
+// Retrieval info: LIB_FILE: altera_mf
+// Retrieval info: CBX_MODULE_PREFIX: ON
+"
+"/*
+ * Arithmetic and logical operations for Zet
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_arlog (
+ input [15:0] x,
+ input [15:0] y,
+ input [ 2:0] f,
+ output [15:0] o,
+ input word_op,
+ input cfi,
+ output cfo,
+ output afo,
+ output ofo
+ );
+
+ // Net declarations
+ wire [15:0] op2;
+ wire [15:0] outadd;
+ wire [15:0] outlog;
+
+ wire ci;
+ wire cfoadd;
+ wire log;
+ wire xs;
+ wire ys;
+ wire os;
+
+ // Module instances
+ zet_fulladd16 fulladd16 ( // We instantiate only one adder
+ .x (x), // to have less hardware
+ .y (op2),
+ .ci (ci),
+ .co (cfoadd),
+ .z (outadd),
+ .s (f[0])
+ );
+
+ // Assignemnts
+ assign op2 = f[0] ? ~y /* sbb,sub,cmp */
+ : y; /* add, adc */
+
+ assign ci = f[2] | ~f[2] & f[1] & (!f[0] & cfi
+ | f[0] & ~cfi);
+
+ assign log = f[2:0]==3'd1 || f[2:0]==3'd4 || f[2:0]==3'd6;
+ assign afo = !log & (x[4] ^ y[4] ^ outadd[4]);
+ assign cfo = !log & (word_op ? cfoadd : (x[8]^y[8]^outadd[8]));
+
+ assign xs = word_op ? x[15] : x[7];
+ assign ys = word_op ? y[15] : y[7];
+ assign os = word_op ? outadd[15] : outadd[7];
+ assign ofo = !log &
+ (f[0] ? (~xs & ys & os | xs & ~ys & ~os)
+ : (~xs & ~ys & os | xs & ys & ~os));
+
+ assign outlog = f[2] ? (f[1] ? x^y : x&y) : x|y;
+ assign o = log ? outlog : outadd;
+
+endmodule
+"
+"/*\r
+ * Zet SoC top level file for Altera DE2 board\r
+ * Copyright (C) 2009, 2010 Zeus Gomez Marmolejo \r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+module kotku (\r
+ // Clock input\r
+ input clk_50_,\r
+\r
+ // General purpose IO\r
+ input [7:0] sw_,\r
+ input key_,\r
+ output [6:0] hex0_,\r
+ output [6:0] hex1_,\r
+ output [6:0] hex2_,\r
+ output [6:0] hex3_,\r
+ output [9:0] ledr_,\r
+ output [7:0] ledg_,\r
+\r
+ // flash signals\r
+ output [21:0] flash_addr_,\r
+ input [ 7:0] flash_data_,\r
+ output flash_oe_n_,\r
+ output flash_ce_n_,\r
+\r
+ // sdram signals\r
+ output [11:0] sdram_addr_,\r
+ inout [15:0] sdram_data_,\r
+ output [ 1:0] sdram_ba_,\r
+ output sdram_ras_n_,\r
+ output sdram_cas_n_,\r
+ output sdram_ce_,\r
+ output sdram_clk_,\r
+ output sdram_we_n_,\r
+ output sdram_cs_n_,\r
+\r
+ // VGA signals\r
+ output [ 3:0] tft_lcd_r_,\r
+ output [ 3:0] tft_lcd_g_,\r
+ output [ 3:0] tft_lcd_b_,\r
+ output tft_lcd_hsync_,\r
+ output tft_lcd_vsync_,\r
+ output tft_lcd_clk_,\r
+\r
+ // UART signals\r
+ output uart_txd_,\r
+\r
+ // PS2 signals\r
+ input ps2_kclk_, // PS2 keyboard Clock\r
+ inout ps2_kdat_, // PS2 Keyboard Data\r
+ inout ps2_mclk_, // PS2 Mouse Clock\r
+ inout ps2_mdat_, // PS2 Mouse Data\r
+\r
+ // SD card signals\r
+ output sd_sclk_,\r
+ input sd_miso_,\r
+ output sd_mosi_,\r
+ output sd_ss_,\r
+\r
+ // I2C for audio codec\r
+ inout i2c_sdat_,\r
+ output i2c_sclk_,\r
+\r
+ // Audio codec signals\r
+ input aud_daclrck_,\r
+ output aud_dacdat_,\r
+ input aud_bclk_,\r
+ output aud_xck_\r
+ );\r
+\r
+ // Registers and nets\r
+ wire clk;\r
+ wire rst_lck;\r
+ wire [15:0] dat_o;\r
+ wire [15:0] dat_i;\r
+ wire [19:1] adr;\r
+ wire we;\r
+ wire tga;\r
+ wire [ 1:0] sel;\r
+ wire stb;\r
+ wire cyc;\r
+ wire ack;\r
+ wire lock;\r
+\r
+ // wires to BIOS ROM\r
+ wire [15:0] rom_dat_o;\r
+ wire [15:0] rom_dat_i;\r
+ wire rom_tga_i;\r
+ wire [19:1] rom_adr_i;\r
+ wire [ 1:0] rom_sel_i;\r
+ wire rom_we_i;\r
+ wire rom_cyc_i;\r
+ wire rom_stb_i;\r
+ wire rom_ack_o;\r
+\r
+ // wires to flash controller\r
+ wire [15:0] fl_dat_o;\r
+ wire [15:0] fl_dat_i;\r
+ wire fl_tga_i;\r
+ wire [19:1] fl_adr_i;\r
+ wire [ 1:0] fl_sel_i;\r
+ wire fl_we_i;\r
+ wire fl_cyc_i;\r
+ wire fl_stb_i;\r
+ wire fl_ack_o;\r
+\r
+ // Unused outputs\r
+ wire flash_we_n_;\r
+ wire flash_rst_n_;\r
+ wire [1:0] sdram_dqm_;\r
+ wire [2:0] s19_17;\r
+\r
+ // Unused inputs\r
+ wire uart_rxd_;\r
+ wire aud_adcdat_;\r
+\r
+ // wires to vga controller\r
+ wire [15:0] vga_dat_o;\r
+ wire [15:0] vga_dat_i;\r
+ wire vga_tga_i;\r
+ wire [19:1] vga_adr_i;\r
+ wire [ 1:0] vga_sel_i;\r
+ wire vga_we_i;\r
+ wire vga_cyc_i;\r
+ wire vga_stb_i;\r
+ wire vga_ack_o;\r
+\r
+ // cross clock domain synchronized signals\r
+ wire [15:0] vga_dat_o_s;\r
+ wire [15:0] vga_dat_i_s;\r
+ wire vga_tga_i_s;\r
+ wire [19:1] vga_adr_i_s;\r
+ wire [ 1:0] vga_sel_i_s;\r
+ wire vga_we_i_s;\r
+ wire vga_cyc_i_s;\r
+ wire vga_stb_i_s;\r
+ wire vga_ack_o_s;\r
+\r
+ // wires to uart controller\r
+ wire [15:0] uart_dat_o;\r
+ wire [15:0] uart_dat_i;\r
+ wire uart_tga_i;\r
+ wire [19:1] uart_adr_i;\r
+ wire [ 1:0] uart_sel_i;\r
+ wire uart_we_i;\r
+ wire uart_cyc_i;\r
+ wire uart_stb_i;\r
+ wire uart_ack_o;\r
+\r
+ // wires to keyboard controller\r
+ wire [15:0] keyb_dat_o;\r
+ wire [15:0] keyb_dat_i;\r
+ wire keyb_tga_i;\r
+ wire [19:1] keyb_adr_i;\r
+ wire [ 1:0] keyb_sel_i;\r
+ wire keyb_we_i;\r
+ wire keyb_cyc_i;\r
+ wire keyb_stb_i;\r
+ wire keyb_ack_o;\r
+\r
+ // wires to timer controller\r
+ wire [15:0] timer_dat_o;\r
+ wire [15:0] timer_dat_i;\r
+ wire timer_tga_i;\r
+ wire [19:1] timer_adr_i;\r
+ wire [ 1:0] timer_sel_i;\r
+ wire timer_we_i;\r
+ wire timer_cyc_i;\r
+ wire timer_stb_i;\r
+ wire timer_ack_o;\r
+\r
+ // wires to sd controller\r
+ wire [19:1] sd_adr_i;\r
+ wire [ 7:0] sd_dat_o;\r
+ wire [15:0] sd_dat_i;\r
+ wire sd_tga_i;\r
+ wire [ 1:0] sd_sel_i;\r
+ wire sd_we_i;\r
+ wire sd_cyc_i;\r
+ wire sd_stb_i;\r
+ wire sd_ack_o;\r
+\r
+ // wires to sd bridge\r
+ wire [19:1] sd_adr_i_s;\r
+ wire [15:0] sd_dat_o_s;\r
+ wire [15:0] sd_dat_i_s;\r
+ wire sd_tga_i_s;\r
+ wire [ 1:0] sd_sel_i_s;\r
+ wire sd_we_i_s;\r
+ wire sd_cyc_i_s;\r
+ wire sd_stb_i_s;\r
+ wire sd_ack_o_s;\r
+\r
+ // wires to gpio controller\r
+ wire [15:0] gpio_dat_o;\r
+ wire [15:0] gpio_dat_i;\r
+ wire gpio_tga_i;\r
+ wire [19:1] gpio_adr_i;\r
+ wire [ 1:0] gpio_sel_i;\r
+ wire gpio_we_i;\r
+ wire gpio_cyc_i;\r
+ wire gpio_stb_i;\r
+ wire gpio_ack_o;\r
+\r
+ // wires to SDRAM controller\r
+ wire [19:1] fmlbrg_adr_s;\r
+ wire [15:0] fmlbrg_dat_w_s;\r
+ wire [15:0] fmlbrg_dat_r_s;\r
+ wire [ 1:0] fmlbrg_sel_s;\r
+ wire fmlbrg_cyc_s;\r
+ wire fmlbrg_stb_s;\r
+ wire fmlbrg_tga_s;\r
+ wire fmlbrg_we_s;\r
+ wire fmlbrg_ack_s;\r
+\r
+ wire [19:1] fmlbrg_adr;\r
+ wire [15:0] fmlbrg_dat_w;\r
+ wire [15:0] fmlbrg_dat_r;\r
+ wire [ 1:0] fmlbrg_sel;\r
+ wire fmlbrg_cyc;\r
+ wire fmlbrg_stb;\r
+ wire fmlbrg_tga;\r
+ wire fmlbrg_we;\r
+ wire fmlbrg_ack;\r
+\r
+ wire [19:1] csrbrg_adr_s;\r
+ wire [15:0] csrbrg_dat_w_s;\r
+ wire [15:0] csrbrg_dat_r_s;\r
+ wire [ 1:0] csrbrg_sel_s;\r
+ wire csrbrg_cyc_s;\r
+ wire csrbrg_stb_s;\r
+ wire csrbrg_tga_s;\r
+ wire csrbrg_we_s;\r
+ wire csrbrg_ack_s;\r
+\r
+ wire [19:1] csrbrg_adr;\r
+ wire [15:0] csrbrg_dat_w;\r
+ wire [15:0] csrbrg_dat_r;\r
+ wire [ 1:0] csrbrg_sel;\r
+ wire csrbrg_tga;\r
+ wire csrbrg_cyc;\r
+ wire csrbrg_stb;\r
+ wire csrbrg_we;\r
+ wire csrbrg_ack;\r
+\r
+ wire sb_cyc_i;\r
+ wire sb_stb_i;\r
+\r
+ wire [ 2:0] csr_a;\r
+ wire csr_we;\r
+ wire [15:0] csr_dw;\r
+ wire [15:0] csr_dr_hpdmc;\r
+\r
+ // wires to hpdmc slave interface \r
+ wire [22:0] fml_adr;\r
+ wire fml_stb;\r
+ wire fml_we;\r
+ wire fml_ack;\r
+ wire [ 1:0] fml_sel;\r
+ wire [15:0] fml_di;\r
+ wire [15:0] fml_do;\r
+\r
+ // wires to fml bridge master interface \r
+ wire [19:0] fml_fmlbrg_adr;\r
+ wire fml_fmlbrg_stb;\r
+ wire fml_fmlbrg_we;\r
+ wire fml_fmlbrg_ack;\r
+ wire [ 1:0] fml_fmlbrg_sel;\r
+ wire [15:0] fml_fmlbrg_di;\r
+ wire [15:0] fml_fmlbrg_do;\r
+\r
+ // wires to VGA CPU FML master interface\r
+ wire [19:0] vga_cpu_fml_adr; // 1MB Memory Address range\r
+ wire vga_cpu_fml_stb;\r
+ wire vga_cpu_fml_we;\r
+ wire vga_cpu_fml_ack;\r
+ wire [1:0] vga_cpu_fml_sel;\r
+ wire [15:0] vga_cpu_fml_do;\r
+ wire [15:0] vga_cpu_fml_di;\r
+\r
+ // wires to VGA LCD FML master interface\r
+ wire [19:0] vga_lcd_fml_adr; // 1MB Memory Address range\r
+ wire vga_lcd_fml_stb;\r
+ wire vga_lcd_fml_we;\r
+ wire vga_lcd_fml_ack;\r
+ wire [1:0] vga_lcd_fml_sel;\r
+ wire [15:0] vga_lcd_fml_do;\r
+ wire [15:0] vga_lcd_fml_di;\r
+\r
+ // wires to default stb/ack\r
+ wire def_cyc_i;\r
+ wire def_stb_i;\r
+ wire [15:0] sw_dat_o;\r
+ wire sdram_clk;\r
+ wire vga_clk;\r
+\r
+ wire [ 7:0] intv;\r
+ wire [ 2:0] iid;\r
+ wire intr;\r
+ wire inta;\r
+\r
+ wire nmi_pb;\r
+ wire nmi;\r
+ wire nmia;\r
+\r
+ wire [19:0] pc;\r
+ reg [16:0] rst_debounce;\r
+\r
+ wire timer_clk;\r
+ wire timer2_o;\r
+\r
+ // Audio only signals\r
+ wire [ 7:0] aud_dat_o;\r
+ wire aud_cyc_i;\r
+ wire aud_ack_o;\r
+ wire aud_sel_cond;\r
+\r
+ // Keyboard-audio shared signals\r
+ wire [ 7:0] kaud_dat_o;\r
+ wire kaud_cyc_i;\r
+ wire kaud_ack_o;\r
+\r
+`ifndef SIMULATION\r
+ /*\r
+ * Debounce it (counter holds reset for 10.49ms),\r
+ * and generate power-on reset.\r
+ */\r
+ initial rst_debounce <= 17'h1FFFF;\r
+ reg rst;\r
+ initial rst <= 1'b1;\r
+ always @(posedge clk) begin\r
+ if(~rst_lck) /* reset is active low */\r
+ rst_debounce <= 17'h1FFFF;\r
+ else if(rst_debounce != 17'd0)\r
+ rst_debounce <= rst_debounce - 17'd1;\r
+ rst <= rst_debounce != 17'd0;\r
+ end\r
+`else\r
+ wire rst;\r
+ assign rst = !rst_lck;\r
+`endif\r
+\r
+ // Module instantiations\r
+ pll pll (\r
+ .inclk0 (clk_50_),\r
+ .c0 (sdram_clk), // 100 Mhz\r
+ .c1 (), // 25 Mhz\r
+ .c2 (clk), // 12.5 Mhz\r
+ .locked (lock)\r
+ );\r
+\r
+ clk_gen #(\r
+ .res (21),\r
+ .phase (21'd100091)\r
+ ) timerclk (\r
+ .clk_i (vga_clk), // 25 MHz\r
+ .rst_i (rst),\r
+ .clk_o (timer_clk) // 1.193178 MHz (required 1.193182 MHz)\r
+ );\r
+\r
+ clk_gen #(\r
+ .res (18),\r
+ .phase (18'd29595)\r
+ ) audioclk (\r
+ .clk_i (sdram_clk), // 100 MHz (use highest freq to minimize jitter)\r
+ .rst_i (rst),\r
+ .clk_o (aud_xck_) // 11.28960 MHz (required 11.28960 MHz)\r
+ );\r
+\r
+ bootrom bootrom (\r
+ .clk (clk), // Wishbone slave interface\r
+ .rst (rst),\r
+ .wb_dat_i (rom_dat_i),\r
+ .wb_dat_o (rom_dat_o),\r
+ .wb_adr_i (rom_adr_i),\r
+ .wb_we_i (rom_we_i ),\r
+ .wb_tga_i (rom_tga_i),\r
+ .wb_stb_i (rom_stb_i),\r
+ .wb_cyc_i (rom_cyc_i),\r
+ .wb_sel_i (rom_sel_i),\r
+ .wb_ack_o (rom_ack_o)\r
+ );\r
+\r
+ flash8 flash8 (\r
+ // Wishbone slave interface\r
+ .wb_clk_i (clk), // Main Clock\r
+ .wb_rst_i (rst), // Reset Line\r
+ .wb_adr_i (fl_adr_i[1]), // Address lines\r
+ .wb_sel_i (fl_sel_i), // Select lines\r
+ .wb_dat_i (fl_dat_i), // Command to send\r
+ .wb_dat_o (fl_dat_o), // Received data\r
+ .wb_cyc_i (fl_cyc_i), // Cycle\r
+ .wb_stb_i (fl_stb_i), // Strobe\r
+ .wb_we_i (fl_we_i), // Write enable\r
+ .wb_ack_o (fl_ack_o), // Normal bus termination\r
+\r
+ // Pad signals\r
+ .flash_addr_ (flash_addr_),\r
+ .flash_data_ (flash_data_),\r
+ .flash_we_n_ (flash_we_n_),\r
+ .flash_oe_n_ (flash_oe_n_),\r
+ .flash_ce_n_ (flash_ce_n_),\r
+ .flash_rst_n_ (flash_rst_n_)\r
+ );\r
+\r
+ wb_abrgr wb_fmlbrg (\r
+ .sys_rst (rst),\r
+\r
+ // Wishbone slave interface\r
+ .wbs_clk_i (clk),\r
+ .wbs_adr_i (fmlbrg_adr_s),\r
+ .wbs_dat_i (fmlbrg_dat_w_s),\r
+ .wbs_dat_o (fmlbrg_dat_r_s),\r
+ .wbs_sel_i (fmlbrg_sel_s),\r
+ .wbs_tga_i (fmlbrg_tga_s),\r
+ .wbs_stb_i (fmlbrg_stb_s),\r
+ .wbs_cyc_i (fmlbrg_cyc_s),\r
+ .wbs_we_i (fmlbrg_we_s),\r
+ .wbs_ack_o (fmlbrg_ack_s),\r
+\r
+ // Wishbone master interface\r
+ .wbm_clk_i (sdram_clk),\r
+ .wbm_adr_o (fmlbrg_adr),\r
+ .wbm_dat_o (fmlbrg_dat_w),\r
+ .wbm_dat_i (fmlbrg_dat_r),\r
+ .wbm_sel_o (fmlbrg_sel),\r
+ .wbm_tga_o (fmlbrg_tga),\r
+ .wbm_stb_o (fmlbrg_stb),\r
+ .wbm_cyc_o (fmlbrg_cyc),\r
+ .wbm_we_o (fmlbrg_we),\r
+ .wbm_ack_i (fmlbrg_ack)\r
+ );\r
+\r
+ fmlbrg #(\r
+ .fml_depth (20), // 8086 can only address 1 MB\r
+ .cache_depth (10) // 1 Kbyte cache\r
+ ) fmlbrg (\r
+ .sys_clk (sdram_clk),\r
+ .sys_rst (rst),\r
+\r
+ // Wishbone slave interface\r
+ .wb_adr_i (fmlbrg_adr),\r
+ .wb_cti_i(3'b0),\r
+ .wb_dat_i (fmlbrg_dat_w),\r
+ .wb_dat_o (fmlbrg_dat_r),\r
+ .wb_sel_i (fmlbrg_sel),\r
+ .wb_cyc_i (fmlbrg_cyc),\r
+ .wb_stb_i (fmlbrg_stb),\r
+ .wb_tga_i (fmlbrg_tga),\r
+ .wb_we_i (fmlbrg_we),\r
+ .wb_ack_o (fmlbrg_ack),\r
+\r
+ // FML master 1 interface\r
+ .fml_adr (fml_fmlbrg_adr),\r
+ .fml_stb (fml_fmlbrg_stb),\r
+ .fml_we (fml_fmlbrg_we),\r
+ .fml_ack (fml_fmlbrg_ack),\r
+ .fml_sel (fml_fmlbrg_sel),\r
+ .fml_do (fml_fmlbrg_do),\r
+ .fml_di (fml_fmlbrg_di),\r
+\r
+ // Direct Cache Bus\r
+ .dcb_stb(1'b0),\r
+ .dcb_adr(20'b0),\r
+ .dcb_dat(),\r
+ .dcb_hit()\r
+\r
+ );\r
+\r
+ wb_abrgr wb_csrbrg (\r
+ .sys_rst (rst),\r
+\r
+ // Wishbone slave interface\r
+ .wbs_clk_i (clk),\r
+ .wbs_adr_i (csrbrg_adr_s),\r
+ .wbs_dat_i (csrbrg_dat_w_s),\r
+ .wbs_dat_o (csrbrg_dat_r_s),\r
+ .wbs_sel_i (csrbrg_sel_s),\r
+ .wbs_tga_i (csrbrg_tga_s),\r
+ .wbs_stb_i (csrbrg_stb_s),\r
+ .wbs_cyc_i (csrbrg_cyc_s),\r
+ .wbs_we_i (csrbrg_we_s),\r
+ .wbs_ack_o (csrbrg_ack_s),\r
+\r
+ // Wishbone master interface\r
+ .wbm_clk_i (sdram_clk),\r
+ .wbm_adr_o (csrbrg_adr),\r
+ .wbm_dat_o (csrbrg_dat_w),\r
+ .wbm_dat_i (csrbrg_dat_r),\r
+ .wbm_sel_o (csrbrg_sel),\r
+ .wbm_tga_o (csrbrg_tga),\r
+ .wbm_stb_o (csrbrg_stb),\r
+ .wbm_cyc_o (csrbrg_cyc),\r
+ .wbm_we_o (csrbrg_we),\r
+ .wbm_ack_i (csrbrg_ack)\r
+ );\r
+\r
+ csrbrg csrbrg (\r
+ .sys_clk (sdram_clk),\r
+ .sys_rst (rst),\r
+\r
+ // Wishbone slave interface\r
+ .wb_adr_i (csrbrg_adr[3:1]),\r
+ .wb_dat_i (csrbrg_dat_w),\r
+ .wb_dat_o (csrbrg_dat_r),\r
+ .wb_cyc_i (csrbrg_cyc),\r
+ .wb_stb_i (csrbrg_stb),\r
+ .wb_we_i (csrbrg_we),\r
+ .wb_ack_o (csrbrg_ack),\r
+\r
+ // CSR master interface\r
+ .csr_a (csr_a),\r
+ .csr_we (csr_we),\r
+ .csr_do (csr_dw),\r
+ .csr_di (csr_dr_hpdmc)\r
+ );\r
+\r
+ fmlarb #(\r
+ .fml_depth (23)\r
+ ) fmlarb (\r
+ .sys_clk (sdram_clk),\r
+ .sys_rst (rst),\r
+\r
+ // Master 0 interface - VGA LCD FML (Reserved video memory port has highest priority)\r
+ .m0_adr ({3'b001, vga_lcd_fml_adr}), // 1 - 2 MB Addressable memory range\r
+ .m0_stb (vga_lcd_fml_stb),\r
+ .m0_we (vga_lcd_fml_we),\r
+ .m0_ack (vga_lcd_fml_ack),\r
+ .m0_sel (vga_lcd_fml_sel),\r
+ .m0_di (vga_lcd_fml_do),\r
+ .m0_do (vga_lcd_fml_di),\r
+\r
+ // Master 1 interface - Wishbone FML bridge\r
+ .m1_adr ({3'b000, fml_fmlbrg_adr}), // 0 - 1 MB Addressable memory range\r
+ .m1_stb (fml_fmlbrg_stb),\r
+ .m1_we (fml_fmlbrg_we),\r
+ .m1_ack (fml_fmlbrg_ack),\r
+ .m1_sel (fml_fmlbrg_sel),\r
+ .m1_di (fml_fmlbrg_do),\r
+ .m1_do (fml_fmlbrg_di),\r
+\r
+ // Master 2 interface - VGA CPU FML\r
+ .m2_adr ({3'b001, vga_cpu_fml_adr}), // 1 - 2 MB Addressable memory range\r
+ .m2_stb (vga_cpu_fml_stb),\r
+ .m2_we (vga_cpu_fml_we),\r
+ .m2_ack (vga_cpu_fml_ack),\r
+ .m2_sel (vga_cpu_fml_sel),\r
+ .m2_di (vga_cpu_fml_do),\r
+ .m2_do (vga_cpu_fml_di),\r
+\r
+ // Master 3 interface - not connected\r
+ .m3_adr ({3'b010, 20'b0}), // 2 - 3 MB Addressable memory range\r
+ .m3_stb (1'b0),\r
+ .m3_we (1'b0),\r
+ .m3_ack (),\r
+ .m3_sel (2'b00),\r
+ .m3_di (16'h0000),\r
+ .m3_do (),\r
+\r
+ // Master 4 interface - not connected\r
+ .m4_adr ({3'b011, 20'b0}), // 3 - 4 MB Addressable memory range\r
+ .m4_stb (1'b0),\r
+ .m4_we (1'b0),\r
+ .m4_ack (),\r
+ .m4_sel (2'b00),\r
+ .m4_di (16'h0000),\r
+ .m4_do (),\r
+\r
+ // Master 5 interface - not connected\r
+ .m5_adr ({3'b100, 20'b0}), // 4 - 5 MB Addressable memory range\r
+ .m5_stb (1'b0),\r
+ .m5_we (1'b0),\r
+ .m5_ack (),\r
+ .m5_sel (2'b00),\r
+ .m5_di (16'h0000),\r
+ .m5_do (),\r
+\r
+ // Arbitrer Slave interface - connected to hpdmc\r
+ .s_adr (fml_adr),\r
+ .s_stb (fml_stb),\r
+ .s_we (fml_we),\r
+ .s_ack (fml_ack),\r
+ .s_sel (fml_sel),\r
+ .s_di (fml_di),\r
+ .s_do (fml_do)\r
+ );\r
+\r
+ hpdmc #(\r
+ .csr_addr (1'b0),\r
+ .sdram_depth (23),\r
+ .sdram_columndepth (8)\r
+ ) hpdmc (\r
+ .sys_clk (sdram_clk),\r
+ .sys_rst (rst),\r
+\r
+ // CSR slave interface\r
+ .csr_a (csr_a),\r
+ .csr_we (csr_we),\r
+ .csr_di (csr_dw),\r
+ .csr_do (csr_dr_hpdmc),\r
+\r
+ // FML slave interface\r
+ .fml_adr (fml_adr),\r
+ .fml_stb (fml_stb),\r
+ .fml_we (fml_we),\r
+ .fml_ack (fml_ack),\r
+ .fml_sel (fml_sel),\r
+ .fml_di (fml_do),\r
+ .fml_do (fml_di),\r
+\r
+ // SDRAM pad signals\r
+ .sdram_cke (sdram_ce_),\r
+ .sdram_cs_n (sdram_cs_n_),\r
+ .sdram_we_n (sdram_we_n_),\r
+ .sdram_cas_n (sdram_cas_n_),\r
+ .sdram_ras_n (sdram_ras_n_),\r
+ .sdram_dqm (sdram_dqm_),\r
+ .sdram_adr (sdram_addr_),\r
+ .sdram_ba (sdram_ba_),\r
+ .sdram_dq (sdram_data_)\r
+ );\r
+\r
+ wb_abrgr vga_brg (\r
+ .sys_rst (rst),\r
+\r
+ // Wishbone slave interface\r
+ .wbs_clk_i (clk),\r
+ .wbs_adr_i (vga_adr_i_s),\r
+ .wbs_dat_i (vga_dat_i_s),\r
+ .wbs_dat_o (vga_dat_o_s),\r
+ .wbs_sel_i (vga_sel_i_s),\r
+ .wbs_tga_i (vga_tga_i_s),\r
+ .wbs_stb_i (vga_stb_i_s),\r
+ .wbs_cyc_i (vga_cyc_i_s),\r
+ .wbs_we_i (vga_we_i_s),\r
+ .wbs_ack_o (vga_ack_o_s),\r
+\r
+ // Wishbone master interface\r
+ .wbm_clk_i (sdram_clk),\r
+ .wbm_adr_o (vga_adr_i),\r
+ .wbm_dat_o (vga_dat_i),\r
+ .wbm_dat_i (vga_dat_o),\r
+ .wbm_sel_o (vga_sel_i),\r
+ .wbm_tga_o (vga_tga_i),\r
+ .wbm_stb_o (vga_stb_i),\r
+ .wbm_cyc_o (vga_cyc_i),\r
+ .wbm_we_o (vga_we_i),\r
+ .wbm_ack_i (vga_ack_o)\r
+ );\r
+\r
+ vga_fml #(\r
+ .fml_depth (20) // 1MB Memory Address range\r
+ ) vga (\r
+ .wb_rst_i (rst),\r
+\r
+ // Wishbone slave interface\r
+ .wb_clk_i (sdram_clk), // 100MHz VGA clock\r
+ .wb_dat_i (vga_dat_i),\r
+ .wb_dat_o (vga_dat_o),\r
+ .wb_adr_i (vga_adr_i[16:1]), // 128K\r
+ .wb_we_i (vga_we_i),\r
+ .wb_tga_i (vga_tga_i),\r
+ .wb_sel_i (vga_sel_i),\r
+ .wb_stb_i (vga_stb_i),\r
+ .wb_cyc_i (vga_cyc_i),\r
+ .wb_ack_o (vga_ack_o),\r
+\r
+ // VGA pad signals\r
+ .vga_red_o (tft_lcd_r_),\r
+ .vga_green_o (tft_lcd_g_),\r
+ .vga_blue_o (tft_lcd_b_),\r
+ .horiz_sync (tft_lcd_hsync_),\r
+ .vert_sync (tft_lcd_vsync_),\r
+\r
+ // VGA CPU FML master interface\r
+ .vga_cpu_fml_adr(vga_cpu_fml_adr),\r
+ .vga_cpu_fml_stb(vga_cpu_fml_stb),\r
+ .vga_cpu_fml_we(vga_cpu_fml_we),\r
+ .vga_cpu_fml_ack(vga_cpu_fml_ack),\r
+ .vga_cpu_fml_sel(vga_cpu_fml_sel),\r
+ .vga_cpu_fml_do(vga_cpu_fml_do),\r
+ .vga_cpu_fml_di(vga_cpu_fml_di),\r
+\r
+ // VGA LCD FML master interface\r
+ .vga_lcd_fml_adr(vga_lcd_fml_adr),\r
+ .vga_lcd_fml_stb(vga_lcd_fml_stb),\r
+ .vga_lcd_fml_we(vga_lcd_fml_we),\r
+ .vga_lcd_fml_ack(vga_lcd_fml_ack),\r
+ .vga_lcd_fml_sel(vga_lcd_fml_sel),\r
+ .vga_lcd_fml_do(vga_lcd_fml_do),\r
+ .vga_lcd_fml_di(vga_lcd_fml_di),\r
+\r
+ .vga_clk(vga_clk)\r
+\r
+ );\r
+\r
+ // RS232 COM1 Port\r
+ serial com1 (\r
+ .wb_clk_i (clk), // Main Clock\r
+ .wb_rst_i (rst), // Reset Line\r
+ .wb_adr_i (uart_adr_i[2:1]), // Address lines\r
+ .wb_sel_i (uart_sel_i), // Select lines\r
+ .wb_dat_i (uart_dat_i), // Command to send\r
+ .wb_dat_o (uart_dat_o),\r
+ .wb_we_i (uart_we_i), // Write enable\r
+ .wb_stb_i (uart_stb_i),\r
+ .wb_cyc_i (uart_cyc_i),\r
+ .wb_ack_o (uart_ack_o),\r
+ .wb_tgc_o (intv[4]), // Interrupt request\r
+\r
+ .rs232_tx (uart_txd_), // UART signals\r
+ .rs232_rx (uart_rxd_) // serial input/output\r
+ );\r
+\r
+ ps2 ps2 (\r
+ .wb_clk_i (clk), // Main Clock\r
+ .wb_rst_i (rst), // Reset Line\r
+ .wb_adr_i (keyb_adr_i[2:1]), // Address lines\r
+ .wb_sel_i (keyb_sel_i), // Select lines\r
+ .wb_dat_i (keyb_dat_i), // Command to send to Ethernet\r
+ .wb_dat_o (keyb_dat_o),\r
+ .wb_we_i (keyb_we_i), // Write enable\r
+ .wb_stb_i (keyb_stb_i),\r
+ .wb_cyc_i (keyb_cyc_i),\r
+ .wb_ack_o (keyb_ack_o),\r
+ .wb_tgk_o (intv[1]), // Keyboard Interrupt request\r
+ .wb_tgm_o (intv[3]), // Mouse Interrupt request\r
+\r
+ .ps2_kbd_clk_ (ps2_kclk_),\r
+ .ps2_kbd_dat_ (ps2_kdat_),\r
+ .ps2_mse_clk_ (ps2_mclk_),\r
+ .ps2_mse_dat_ (ps2_mdat_)\r
+ );\r
+\r
+`ifndef SIMULATION\r
+ /*\r
+ * Seems that we have a serious bug in Modelsim that prevents\r
+ * from simulating when this core is present\r
+ */\r
+ speaker speaker (\r
+ .clk (clk),\r
+ .rst (rst),\r
+\r
+ .wb_dat_i (keyb_dat_i[15:8]),\r
+ .wb_dat_o (aud_dat_o),\r
+ .wb_we_i (keyb_we_i),\r
+ .wb_stb_i (keyb_stb_i),\r
+ .wb_cyc_i (aud_cyc_i),\r
+ .wb_ack_o (aud_ack_o),\r
+\r
+ .clk_100M (sdram_clk),\r
+ .clk_25M (vga_clk),\r
+ .timer2 (timer2_o),\r
+\r
+ .i2c_sclk_ (i2c_sclk_),\r
+ .i2c_sdat_ (i2c_sdat_),\r
+\r
+ .aud_adcdat_ (aud_adcdat_),\r
+ .aud_daclrck_ (aud_daclrck_),\r
+ .aud_dacdat_ (aud_dacdat_),\r
+ .aud_bclk_ (aud_bclk_)\r
+ );\r
+`else\r
+ assign aud_dat_o = 16'h0;\r
+ assign aud_ack_o = keyb_stb_i & aud_cyc_i;\r
+`endif\r
+\r
+ // Selection logic between keyboard and audio ports (port 65h: audio)\r
+ assign aud_sel_cond = keyb_adr_i[2:1]==2'b00 && keyb_sel_i[1];\r
+ assign aud_cyc_i = kaud_cyc_i && aud_sel_cond;\r
+ assign keyb_cyc_i = kaud_cyc_i && !aud_sel_cond;\r
+ assign kaud_ack_o = aud_cyc_i & aud_ack_o | keyb_cyc_i & keyb_ack_o;\r
+ assign kaud_dat_o = {8{aud_cyc_i}} & aud_dat_o\r
+ | {8{keyb_cyc_i}} & keyb_dat_o[15:8];\r
+\r
+ timer timer (\r
+ .wb_clk_i (clk),\r
+ .wb_rst_i (rst),\r
+ .wb_adr_i (timer_adr_i[1]),\r
+ .wb_sel_i (timer_sel_i),\r
+ .wb_dat_i (timer_dat_i),\r
+ .wb_dat_o (timer_dat_o),\r
+ .wb_stb_i (timer_stb_i),\r
+ .wb_cyc_i (timer_cyc_i),\r
+ .wb_we_i (timer_we_i),\r
+ .wb_ack_o (timer_ack_o),\r
+ .wb_tgc_o (intv[0]),\r
+ .tclk_i (timer_clk), // 1.193182 MHz = (14.31818/12) MHz\r
+ .gate2_i (aud_dat_o[0]),\r
+ .out2_o (timer2_o)\r
+ );\r
+\r
+ simple_pic pic0 (\r
+ .clk (clk),\r
+ .rst (rst),\r
+ .intv (intv),\r
+ .inta (inta),\r
+ .intr (intr),\r
+ .iid (iid)\r
+ );\r
+\r
+ wb_abrgr sd_brg (\r
+ .sys_rst (rst),\r
+\r
+ // Wishbone slave interface\r
+ .wbs_clk_i (clk),\r
+ .wbs_adr_i (sd_adr_i_s),\r
+ .wbs_dat_i (sd_dat_i_s),\r
+ .wbs_dat_o (sd_dat_o_s),\r
+ .wbs_sel_i (sd_sel_i_s),\r
+ .wbs_tga_i (sd_tga_i_s),\r
+ .wbs_stb_i (sd_stb_i_s),\r
+ .wbs_cyc_i (sd_cyc_i_s),\r
+ .wbs_we_i (sd_we_i_s),\r
+ .wbs_ack_o (sd_ack_o_s),\r
+\r
+ // Wishbone master interface\r
+ .wbm_clk_i (sdram_clk),\r
+ .wbm_adr_o (sd_adr_i),\r
+ .wbm_dat_o (sd_dat_i),\r
+ .wbm_dat_i ({8'h0,sd_dat_o}),\r
+ .wbm_tga_o (sd_tga_i),\r
+ .wbm_sel_o (sd_sel_i),\r
+ .wbm_stb_o (sd_stb_i),\r
+ .wbm_cyc_o (sd_cyc_i),\r
+ .wbm_we_o (sd_we_i),\r
+ .wbm_ack_i (sd_ack_o)\r
+ );\r
+\r
+ sdspi sdspi (\r
+ // Serial pad signal\r
+ .sclk (sd_sclk_),\r
+ .miso (sd_miso_),\r
+ .mosi (sd_mosi_),\r
+ .ss (sd_ss_),\r
+\r
+ // Wishbone slave interface\r
+ .wb_clk_i (sdram_clk),\r
+ .wb_rst_i (rst),\r
+ .wb_dat_i (sd_dat_i[8:0]),\r
+ .wb_dat_o (sd_dat_o),\r
+ .wb_we_i (sd_we_i),\r
+ .wb_sel_i (sd_sel_i),\r
+ .wb_stb_i (sd_stb_i),\r
+ .wb_cyc_i (sd_cyc_i),\r
+ .wb_ack_o (sd_ack_o)\r
+ );\r
+\r
+ // Switches and leds\r
+ sw_leds sw_leds (\r
+ .wb_clk_i (clk),\r
+ .wb_rst_i (rst),\r
+\r
+ // Wishbone slave interface\r
+ .wb_adr_i (gpio_adr_i[1]),\r
+ .wb_dat_o (gpio_dat_o),\r
+ .wb_dat_i (gpio_dat_i),\r
+ .wb_sel_i (gpio_sel_i),\r
+ .wb_we_i (gpio_we_i),\r
+ .wb_stb_i (gpio_stb_i),\r
+ .wb_cyc_i (gpio_cyc_i),\r
+ .wb_ack_o (gpio_ack_o),\r
+\r
+ // GPIO inputs/outputs\r
+ .leds_ ({ledr_,ledg_[7:4]}),\r
+ .sw_ (sw_),\r
+ .pb_ (key_),\r
+ .tick (intv[0]),\r
+ .nmi_pb (nmi_pb) // NMI from pushbutton\r
+ );\r
+\r
+ hex_display hex16 (\r
+ .num (pc[19:4]),\r
+ .en (1'b1),\r
+\r
+ .hex0 (hex0_),\r
+ .hex1 (hex1_),\r
+ .hex2 (hex2_),\r
+ .hex3 (hex3_)\r
+ );\r
+\r
+ zet zet (\r
+ .pc (pc),\r
+\r
+ // Wishbone master interface\r
+ .wb_clk_i (clk),\r
+ .wb_rst_i (rst),\r
+ .wb_dat_i (dat_i),\r
+ .wb_dat_o (dat_o),\r
+ .wb_adr_o (adr),\r
+ .wb_we_o (we),\r
+ .wb_tga_o (tga),\r
+ .wb_sel_o (sel),\r
+ .wb_stb_o (stb),\r
+ .wb_cyc_o (cyc),\r
+ .wb_ack_i (ack),\r
+ .wb_tgc_i (intr),\r
+ .wb_tgc_o (inta),\r
+ .nmi (nmi),\r
+ .nmia (nmia)\r
+ );\r
+\r
+ wb_switch #(\r
+ .s0_addr_1 (20'b0_1111_1111_1111_0000_000), // bios boot mem 0xfff00 - 0xfffff\r
+ .s0_mask_1 (20'b1_1111_1111_1111_0000_000), // bios boot ROM Memory\r
+\r
+ .s1_addr_1 (20'b0_1010_0000_0000_0000_000), // mem 0xa0000 - 0xbffff\r
+ .s1_mask_1 (20'b1_1110_0000_0000_0000_000), // VGA\r
+\r
+ .s1_addr_2 (20'b1_0000_0000_0011_1100_000), // io 0x3c0 - 0x3df\r
+ .s1_mask_2 (20'b1_0000_1111_1111_1110_000), // VGA IO\r
+\r
+ .s2_addr_1 (20'b1_0000_0000_0011_1111_100), // io 0x3f8 - 0x3ff\r
+ .s2_mask_1 (20'b1_0000_1111_1111_1111_100), // RS232 IO\r
+\r
+ .s3_addr_1 (20'b1_0000_0000_0000_0110_000), // io 0x60, 0x64\r
+ .s3_mask_1 (20'b1_0000_1111_1111_1111_101), // Keyboard / Mouse IO\r
+\r
+ .s4_addr_1 (20'b1_0000_0000_0001_0000_000), // io 0x100 - 0x101\r
+ .s4_mask_1 (20'b1_0000_1111_1111_1111_111), // SD Card IO\r
+\r
+ .s5_addr_1 (20'b1_0000_1111_0001_0000_000), // io 0xf100 - 0xf103\r
+ .s5_mask_1 (20'b1_0000_1111_1111_1111_110), // GPIO\r
+\r
+ .s6_addr_1 (20'b1_0000_1111_0010_0000_000), // io 0xf200 - 0xf20f\r
+ .s6_mask_1 (20'b1_0000_1111_1111_1111_000), // CSR Bridge SDRAM Control\r
+\r
+ .s7_addr_1 (20'b1_0000_0000_0000_0100_000), // io 0x40 - 0x43\r
+ .s7_mask_1 (20'b1_0000_1111_1111_1111_110), // Timer control port\r
+\r
+ .s8_addr_1 (20'b1_0000_0000_0010_0011_100), // io 0x0238 - 0x023b\r
+ .s8_mask_1 (20'b1_0000_1111_1111_1111_110), // Flash IO port\r
+\r
+ .s9_addr_1 (20'b1_0000_0000_0010_0001_000), // io 0x0210 - 0x021F\r
+ .s9_mask_1 (20'b1_0000_1111_1111_1111_000), // Sound Blaster\r
+\r
+ .sA_addr_1 (20'b1_0000_1111_0011_0000_000), // io 0xf300 - 0xf3ff\r
+ .sA_mask_1 (20'b1_0000_1111_1111_0000_000), // SDRAM Control\r
+ .sA_addr_2 (20'b0_0000_0000_0000_0000_000), // mem 0x00000 - 0xfffff\r
+ .sA_mask_2 (20'b1_0000_0000_0000_0000_000) // Base RAM\r
+\r
+ ) wbs (\r
+\r
+ // Master interface\r
+ .m_dat_i (dat_o),\r
+ .m_dat_o (sw_dat_o),\r
+ .m_adr_i ({tga,adr}),\r
+ .m_sel_i (sel),\r
+ .m_we_i (we),\r
+ .m_cyc_i (cyc),\r
+ .m_stb_i (stb),\r
+ .m_ack_o (ack),\r
+\r
+ // Slave 0 interface - bios rom\r
+ .s0_dat_i (rom_dat_o),\r
+ .s0_dat_o (rom_dat_i),\r
+ .s0_adr_o ({rom_tga_i,rom_adr_i}),\r
+ .s0_sel_o (rom_sel_i),\r
+ .s0_we_o (rom_we_i),\r
+ .s0_cyc_o (rom_cyc_i),\r
+ .s0_stb_o (rom_stb_i),\r
+ .s0_ack_i (rom_ack_o),\r
+\r
+ // Slave 1 interface - vga\r
+ .s1_dat_i (vga_dat_o_s),\r
+ .s1_dat_o (vga_dat_i_s),\r
+ .s1_adr_o ({vga_tga_i_s,vga_adr_i_s}),\r
+ .s1_sel_o (vga_sel_i_s),\r
+ .s1_we_o (vga_we_i_s),\r
+ .s1_cyc_o (vga_cyc_i_s),\r
+ .s1_stb_o (vga_stb_i_s),\r
+ .s1_ack_i (vga_ack_o_s),\r
+\r
+ // Slave 2 interface - uart\r
+ .s2_dat_i (uart_dat_o),\r
+ .s2_dat_o (uart_dat_i),\r
+ .s2_adr_o ({uart_tga_i,uart_adr_i}),\r
+ .s2_sel_o (uart_sel_i),\r
+ .s2_we_o (uart_we_i),\r
+ .s2_cyc_o (uart_cyc_i),\r
+ .s2_stb_o (uart_stb_i),\r
+ .s2_ack_i (uart_ack_o),\r
+\r
+ // Slave 3 interface - keyb\r
+ .s3_dat_i ({kaud_dat_o,keyb_dat_o[7:0]}),\r
+ .s3_dat_o (keyb_dat_i),\r
+ .s3_adr_o ({keyb_tga_i,keyb_adr_i}),\r
+ .s3_sel_o (keyb_sel_i),\r
+ .s3_we_o (keyb_we_i),\r
+ .s3_cyc_o (kaud_cyc_i),\r
+ .s3_stb_o (keyb_stb_i),\r
+ .s3_ack_i (kaud_ack_o),\r
+\r
+ // Slave 4 interface - sd\r
+ .s4_dat_i (sd_dat_o_s),\r
+ .s4_dat_o (sd_dat_i_s),\r
+ .s4_adr_o ({sd_tga_i_s,sd_adr_i_s}),\r
+ .s4_sel_o (sd_sel_i_s),\r
+ .s4_we_o (sd_we_i_s),\r
+ .s4_cyc_o (sd_cyc_i_s),\r
+ .s4_stb_o (sd_stb_i_s),\r
+ .s4_ack_i (sd_ack_o_s),\r
+\r
+ // Slave 5 interface - gpio\r
+ .s5_dat_i (gpio_dat_o),\r
+ .s5_dat_o (gpio_dat_i),\r
+ .s5_adr_o ({gpio_tga_i,gpio_adr_i}),\r
+ .s5_sel_o (gpio_sel_i),\r
+ .s5_we_o (gpio_we_i),\r
+ .s5_cyc_o (gpio_cyc_i),\r
+ .s5_stb_o (gpio_stb_i),\r
+ .s5_ack_i (gpio_ack_o),\r
+\r
+ // Slave 6 interface - csr bridge\r
+ .s6_dat_i (csrbrg_dat_r_s),\r
+ .s6_dat_o (csrbrg_dat_w_s),\r
+ .s6_adr_o ({csrbrg_tga_s,csrbrg_adr_s}),\r
+ .s6_sel_o (csrbrg_sel_s),\r
+ .s6_we_o (csrbrg_we_s),\r
+ .s6_cyc_o (csrbrg_cyc_s),\r
+ .s6_stb_o (csrbrg_stb_s),\r
+ .s6_ack_i (csrbrg_ack_s),\r
+\r
+ // Slave 7 interface - timer\r
+ .s7_dat_i (timer_dat_o),\r
+ .s7_dat_o (timer_dat_i),\r
+ .s7_adr_o ({timer_tga_i,timer_adr_i}),\r
+ .s7_sel_o (timer_sel_i),\r
+ .s7_we_o (timer_we_i),\r
+ .s7_cyc_o (timer_cyc_i),\r
+ .s7_stb_o (timer_stb_i),\r
+ .s7_ack_i (timer_ack_o),\r
+\r
+ // Slave 8 interface - flash\r
+ .s8_dat_i (fl_dat_o),\r
+ .s8_dat_o (fl_dat_i),\r
+ .s8_adr_o ({fl_tga_i,fl_adr_i}),\r
+ .s8_sel_o (fl_sel_i),\r
+ .s8_we_o (fl_we_i),\r
+ .s8_cyc_o (fl_cyc_i),\r
+ .s8_stb_o (fl_stb_i),\r
+ .s8_ack_i (fl_ack_o),\r
+\r
+ // Slave 9 interface - not connected\r
+ .s9_dat_i (),\r
+ .s9_dat_o (),\r
+ .s9_adr_o (),\r
+ .s9_sel_o (),\r
+ .s9_we_o (),\r
+ .s9_cyc_o (sb_cyc_i),\r
+ .s9_stb_o (sb_stb_i),\r
+ .s9_ack_i (sb_cyc_i && sb_stb_i),\r
+\r
+ // Slave A interface - sdram\r
+ .sA_dat_i (fmlbrg_dat_r_s),\r
+ .sA_dat_o (fmlbrg_dat_w_s),\r
+ .sA_adr_o ({fmlbrg_tga_s,fmlbrg_adr_s}),\r
+ .sA_sel_o (fmlbrg_sel_s),\r
+ .sA_we_o (fmlbrg_we_s),\r
+ .sA_cyc_o (fmlbrg_cyc_s),\r
+ .sA_stb_o (fmlbrg_stb_s),\r
+ .sA_ack_i (fmlbrg_ack_s),\r
+\r
+ // Slave B interface - default\r
+ .sB_dat_i (16'h0000),\r
+ .sB_dat_o (),\r
+ .sB_adr_o (),\r
+ .sB_sel_o (),\r
+ .sB_we_o (),\r
+ .sB_cyc_o (def_cyc_i),\r
+ .sB_stb_o (def_stb_i),\r
+ .sB_ack_i (def_cyc_i & def_stb_i)\r
+ );\r
+\r
+ // Continuous assignments\r
+ assign rst_lck = !sw_[0] & lock;\r
+\r
+ assign nmi = nmi_pb;\r
+ assign dat_i = nmia ? 16'h0002 :\r
+ (inta ? { 13'b0000_0000_0000_1, iid } :\r
+ sw_dat_o);\r
+\r
+ assign sdram_clk_ = sdram_clk;\r
+\r
+ // Required de2 adv7123 vga dac clock\r
+ assign\ttft_lcd_clk_ = vga_clk;\r
+\r
+ assign ledg_[3:0] = pc[3:0];\r
+\r
+endmodule\r
+"
+"/*
+ * Bitwise logical operations for Zet
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_bitlog (
+ input [15:0] x,
+ output [15:0] o,
+ output cfo,
+ output ofo
+ );
+
+ // Assignments
+ assign o = ~x; // Now we only do NEG
+
+ assign cfo = 1'b0;
+ assign ofo = 1'b0;
+
+endmodule
+"
+"/*
+ * Wishbone Flash RAM core for Altera DE2 board (90ns registered)
+ * Copyright (c) 2009 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module flash8_r2 (
+ // Wishbone slave interface
+ input wb_clk_i,
+ input wb_rst_i,
+ input [15:0] wb_dat_i,
+ output reg [15:0] wb_dat_o,
+ input wb_we_i,
+ input wb_adr_i,
+ input [ 1:0] wb_sel_i,
+ input wb_stb_i,
+ input wb_cyc_i,
+ output reg wb_ack_o,
+
+ // Pad signals
+ output reg [22:0] flash_addr_,
+ input [ 7:0] flash_data_,
+ output flash_we_n_,
+ output reg flash_oe_n_,
+ output reg flash_ce_n_,
+ output flash_rst_n_
+ );
+
+ // Registers and nets
+ wire op;
+ wire wr_command;
+ wire flash_addr0;
+ reg [21:0] address;
+
+ wire word;
+ wire op_word;
+ reg [ 3:0] st;
+ reg [ 7:0] lb;
+
+ // Combinatorial logic
+ assign op = wb_stb_i & wb_cyc_i;
+ assign word = wb_sel_i==2'b11;
+ assign op_word = op & word & !wb_we_i;
+
+ assign flash_rst_n_ = 1'b1;
+ assign flash_we_n_ = 1'b1;
+
+ assign flash_addr0 = (wb_sel_i==2'b10) | (word & |st[2:1]);
+ assign wr_command = op & wb_we_i; // Wishbone write access Signal
+
+ // Behaviour
+ // flash_addr_
+ always @(posedge wb_clk_i)
+ flash_addr_ <= { address, flash_addr0 };
+
+ // flash_oe_n_
+ always @(posedge wb_clk_i)
+ flash_oe_n_ <= !(op & !wb_we_i);
+
+ // flash_ce_n_
+ always @(posedge wb_clk_i)
+ flash_ce_n_ <= !(op & !wb_we_i);
+
+ // wb_dat_o
+ always @(posedge wb_clk_i)
+ wb_dat_o <= wb_rst_i ? 16'h0
+ : (st[2] ? (wb_sel_i[1] ? { flash_data_, lb }
+ : { 8'h0, flash_data_ })
+ : wb_dat_o);
+
+ // wb_ack_o
+ always @(posedge wb_clk_i)
+ wb_ack_o <= wb_rst_i ? 1'b0
+ : (wb_ack_o ? 1'b0 : (op & (wb_we_i ? 1'b1 : st[2])));
+
+ // st - state
+ always @(posedge wb_clk_i)
+ st <= wb_rst_i ? 4'h0
+ : (op & st==4'h0 ? (word ? 4'b0001 : 4'b0100)
+ : { st[2:0], 1'b0 });
+
+ // lb - low byte
+ always @(posedge wb_clk_i)
+ lb <= wb_rst_i ? 8'h0 : (op_word & st[1] ? flash_data_ : 8'h0);
+
+ // --------------------------------------------------------------------
+ // Register addresses and defaults
+ // --------------------------------------------------------------------
+ `define FLASH_ALO 1'h0 // Lower 16 bits of address lines
+ `define FLASH_AHI 1'h1 // Upper 6 bits of address lines
+ always @(posedge wb_clk_i) // Synchrounous
+ if(wb_rst_i)
+ address <= 22'h000000; // Interupt Enable default
+ else
+ if(wr_command) // If a write was requested
+ case(wb_adr_i) // Determine which register was writen to
+ `FLASH_ALO: address[15: 0] <= wb_dat_i;
+ `FLASH_AHI: address[21:16] <= wb_dat_i[5:0];
+ default: ; // Default
+ endcase // End of case
+
+endmodule
+"
+"// megafunction wizard: %ALTPLL%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altpll
+
+// ============================================================
+// File Name: pll.v
+// Megafunction Name(s):
+// \t\t\taltpll
+//
+// Simulation Library Files(s):
+// \t\t\taltera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 13.0.1 Build 232 06/12/2013 SP 1 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2013 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module pll (
+\tinclk0,
+\tc0,
+\tc2,
+\tlocked);
+
+\tinput\t inclk0;
+\toutput\t c0;
+\toutput\t c2;
+\toutput\t locked;
+
+\twire sub_wire0;
+\twire [5:0] sub_wire1;
+\twire [0:0] sub_wire6 = 1\'h0;
+\twire locked = sub_wire0;
+\twire [2:2] sub_wire3 = sub_wire1[2:2];
+\twire [0:0] sub_wire2 = sub_wire1[0:0];
+\twire c0 = sub_wire2;
+\twire c2 = sub_wire3;
+\twire sub_wire4 = inclk0;
+\twire [1:0] sub_wire5 = {sub_wire6, sub_wire4};
+
+\taltpll\taltpll_component (
+\t\t\t\t.inclk (sub_wire5),
+\t\t\t\t.locked (sub_wire0),
+\t\t\t\t.clk (sub_wire1),
+\t\t\t\t.activeclock (),
+\t\t\t\t.areset (1\'b0),
+\t\t\t\t.clkbad (),
+\t\t\t\t.clkena ({6{1\'b1}}),
+\t\t\t\t.clkloss (),
+\t\t\t\t.clkswitch (1\'b0),
+\t\t\t\t.configupdate (1\'b0),
+\t\t\t\t.enable0 (),
+\t\t\t\t.enable1 (),
+\t\t\t\t.extclk (),
+\t\t\t\t.extclkena ({4{1\'b1}}),
+\t\t\t\t.fbin (1\'b1),
+\t\t\t\t.fbmimicbidir (),
+\t\t\t\t.fbout (),
+\t\t\t\t.fref (),
+\t\t\t\t.icdrclk (),
+\t\t\t\t.pfdena (1\'b1),
+\t\t\t\t.phasecounterselect ({4{1\'b1}}),
+\t\t\t\t.phasedone (),
+\t\t\t\t.phasestep (1\'b1),
+\t\t\t\t.phaseupdown (1\'b1),
+\t\t\t\t.pllena (1\'b1),
+\t\t\t\t.scanaclr (1\'b0),
+\t\t\t\t.scanclk (1\'b0),
+\t\t\t\t.scanclkena (1\'b1),
+\t\t\t\t.scandata (1\'b0),
+\t\t\t\t.scandataout (),
+\t\t\t\t.scandone (),
+\t\t\t\t.scanread (1\'b0),
+\t\t\t\t.scanwrite (1\'b0),
+\t\t\t\t.sclkout0 (),
+\t\t\t\t.sclkout1 (),
+\t\t\t\t.vcooverrange (),
+\t\t\t\t.vcounderrange ());
+\tdefparam
+\t\taltpll_component.clk0_divide_by = 1,
+\t\taltpll_component.clk0_duty_cycle = 50,
+\t\taltpll_component.clk0_multiply_by = 2,
+\t\taltpll_component.clk0_phase_shift = ""-2920"",
+\t\taltpll_component.clk2_divide_by = 4,
+\t\taltpll_component.clk2_duty_cycle = 50,
+\t\taltpll_component.clk2_multiply_by = 1,
+\t\taltpll_component.clk2_phase_shift = ""0"",
+\t\taltpll_component.compensate_clock = ""CLK0"",
+\t\taltpll_component.gate_lock_counter = 1048575,
+\t\taltpll_component.gate_lock_signal = ""YES"",
+\t\taltpll_component.inclk0_input_frequency = 20000,
+\t\taltpll_component.intended_device_family = ""Cyclone II"",
+\t\taltpll_component.invalid_lock_multiplier = 5,
+\t\taltpll_component.lpm_hint = ""CBX_MODULE_PREFIX=pll"",
+\t\taltpll_component.lpm_type = ""altpll"",
+\t\taltpll_component.operation_mode = ""NORMAL"",
+\t\taltpll_component.port_activeclock = ""PORT_UNUSED"",
+\t\taltpll_component.port_areset = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkbad0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkbad1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkloss = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkswitch = ""PORT_UNUSED"",
+\t\taltpll_component.port_configupdate = ""PORT_UNUSED"",
+\t\taltpll_component.port_fbin = ""PORT_UNUSED"",
+\t\taltpll_component.port_inclk0 = ""PORT_USED"",
+\t\taltpll_component.port_inclk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_locked = ""PORT_USED"",
+\t\taltpll_component.port_pfdena = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasecounterselect = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasedone = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasestep = ""PORT_UNUSED"",
+\t\taltpll_component.port_phaseupdown = ""PORT_UNUSED"",
+\t\taltpll_component.port_pllena = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanaclr = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanclk = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanclkena = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandata = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandataout = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandone = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanread = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanwrite = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk0 = ""PORT_USED"",
+\t\taltpll_component.port_clk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk2 = ""PORT_USED"",
+\t\taltpll_component.port_clk3 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk4 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk5 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena2 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena3 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena4 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena5 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk2 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk3 = ""PORT_UNUSED"",
+\t\taltpll_component.valid_lock_multiplier = 1;
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH STRING ""1.000""
+// Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING ""MHz""
+// Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING ""Low""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING ""1""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_CUSTOM STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING ""0""
+// Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CLKLOSS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING ""1""
+// Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING ""0""
+// Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING ""c0""
+// Retrieval info: PRIVATE: CUR_FBIN_CLK STRING ""e0""
+// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING ""Any""
+// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: DIV_FACTOR2 NUMERIC ""4""
+// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING ""50.00000000""
+// Retrieval info: PRIVATE: DUTY_CYCLE2 STRING ""50.00000000""
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING ""100.000000""
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE2 STRING ""12.500000""
+// Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING ""0""
+// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING ""0""
+// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING ""1""
+// Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC ""1048575""
+// Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING ""1""
+// Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING ""50.000""
+// Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING ""100.000""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""
+// Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING ""1""
+// Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING ""1""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING ""Not Available""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC ""0""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT2 STRING ""ps""
+// Retrieval info: PRIVATE: MIG_DEVICE_SPEED_GRADE STRING ""Any""
+// Retrieval info: PRIVATE: MIRROR_CLK0 STRING ""0""
+// Retrieval info: PRIVATE: MIRROR_CLK2 STRING ""0""
+// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: MULT_FACTOR2 NUMERIC ""1""
+// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING ""100.00000000""
+// Retrieval info: PRIVATE: OUTPUT_FREQ2 STRING ""10000000.00000000""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE2 STRING ""0""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING ""MHz""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT2 STRING ""MHz""
+// Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: PHASE_RECONFIG_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING ""-2.92000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT2 STRING ""0.00000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT_STEP_ENABLED_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING ""ns""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT2 STRING ""ps""
+// Retrieval info: PRIVATE: PLL_ADVANCED_PARAM_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC ""1""
+// Retrieval info: PRIVATE: PLL_ENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_FBMIMIC_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_TARGET_HARCOPY_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING ""inclk0""
+// Retrieval info: PRIVATE: RECONFIG_FILE STRING ""pll.mif""
+// Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: SELF_RESET_LOCK_LOSS STRING ""0""
+// Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FREQ STRING ""50.000""
+// Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING ""KHz""
+// Retrieval info: PRIVATE: SPREAD_PERCENT STRING ""0.500""
+// Retrieval info: PRIVATE: SPREAD_USE STRING ""0""
+// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING ""0""
+// Retrieval info: PRIVATE: STICKY_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: STICKY_CLK2 STRING ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING ""0""
+// Retrieval info: PRIVATE: USE_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: USE_CLK2 STRING ""1""
+// Retrieval info: PRIVATE: USE_CLKENA0 STRING ""0""
+// Retrieval info: PRIVATE: USE_CLKENA2 STRING ""0""
+// Retrieval info: PRIVATE: USE_MIL_SPEED_GRADE NUMERIC ""0""
+// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING ""0""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC ""2""
+// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING ""-2920""
+// Retrieval info: CONSTANT: CLK2_DIVIDE_BY NUMERIC ""4""
+// Retrieval info: CONSTANT: CLK2_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: CLK2_MULTIPLY_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: CLK2_PHASE_SHIFT STRING ""0""
+// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING ""CLK0""
+// Retrieval info: CONSTANT: GATE_LOCK_COUNTER NUMERIC ""1048575""
+// Retrieval info: CONSTANT: GATE_LOCK_SIGNAL STRING ""YES""
+// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC ""20000""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone II""
+// Retrieval info: CONSTANT: INVALID_LOCK_MULTIPLIER NUMERIC ""5""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""altpll""
+// Retrieval info: CONSTANT: OPERATION_MODE STRING ""NORMAL""
+// Retrieval info: CONSTANT: PORT_ACTIVECLOCK STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_ARESET STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKBAD0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKBAD1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKLOSS STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKSWITCH STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CONFIGUPDATE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_FBIN STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_INCLK0 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_INCLK1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_LOCKED STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_PFDENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASECOUNTERSELECT STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASEDONE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASESTEP STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASEUPDOWN STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PLLENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANACLR STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANCLK STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANCLKENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDATA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDATAOUT STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDONE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANREAD STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANWRITE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk0 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_clk1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk2 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_clk3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk4 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk5 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena4 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena5 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: VALID_LOCK_MULTIPLIER NUMERIC ""1""
+// Retrieval info: USED_PORT: @clk 0 0 6 0 OUTPUT_CLK_EXT VCC ""@clk[5..0]""
+// Retrieval info: USED_PORT: @extclk 0 0 4 0 OUTPUT_CLK_EXT VCC ""@extclk[3..0]""
+// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT_CLK_EXT VCC ""c0""
+// Retrieval info: USED_PORT: c2 0 0 0 0 OUTPUT_CLK_EXT VCC ""c2""
+// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT_CLK_EXT GND ""inclk0""
+// Retrieval info: USED_PORT: locked 0 0 0 0 OUTPUT GND ""locked""
+// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
+// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
+// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
+// Retrieval info: CONNECT: c2 0 0 0 0 @clk 0 0 1 2
+// Retrieval info: CONNECT: locked 0 0 0 0 @locked 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.ppf TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll.bsf TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_bb.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_waveforms.html FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_wave*.jpg FALSE
+// Retrieval info: LIB_FILE: altera_mf
+// Retrieval info: CBX_MODULE_PREFIX: ON
+"
+"/*
+ * Milkymist SoC
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
+ * adjusted to FML 8x16 by Zeus Gomez Marmolejo
+ * updated to include Direct Cache Bus by Charley Picker
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+module fmlbrg_tagmem #(
+\tparameter depth = 2,
+\tparameter width = 2
+) (
+\tinput sys_clk,
+
+\t/* Primary port (read-write) */
+\tinput [depth-1:0] a,
+\tinput we,
+\tinput [width-1:0] di,
+\toutput [width-1:0] dout,
+
+\t/* Secondary port (read-only) */
+\tinput [depth-1:0] a2,
+\toutput [width-1:0] do2
+);
+
+reg [width-1:0] tags[0:(1 << depth)-1];
+
+reg [depth-1:0] a_r;
+reg [depth-1:0] a2_r;
+
+always @(posedge sys_clk) begin
+\ta_r <= a;
+\ta2_r <= a2;
+end
+
+always @(posedge sys_clk) begin
+\tif(we)
+\t\ttags[a] <= di;
+end
+
+assign dout = tags[a_r];
+assign do2 = tags[a2_r];
+
+// synthesis translate_off
+integer i;
+initial begin
+\tfor(i=0;i<(1 << depth);i=i+1)
+\t\ttags[i] = 0;
+end
+// synthesis translate_on
+
+endmodule
+"
+"/*
+ * Wishbone Flash RAM core for Altera DE1 board
+ * Copyright (c) 2009 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module flash8 (
+ // Wishbone slave interface
+ input wb_clk_i,
+ input wb_rst_i,
+ input [15:0] wb_dat_i,
+ output [15:0] wb_dat_o,
+ input wb_we_i,
+ input wb_adr_i,
+ input [ 1:0] wb_sel_i,
+ input wb_stb_i,
+ input wb_cyc_i,
+ output wb_ack_o,
+
+ // Pad signals
+ output [21:0] flash_addr_,
+ input [ 7:0] flash_data_,
+ output flash_we_n_,
+ output flash_oe_n_,
+ output flash_ce_n_,
+ output flash_rst_n_
+ );
+
+ // Registers and nets
+ wire op;
+ wire wr_command;
+ reg [20:0] address;
+
+ wire word;
+ wire op_word;
+ reg st;
+ reg [ 7:0] lb;
+
+ // Combinatorial logic
+ assign op = wb_stb_i & wb_cyc_i;
+ assign word = wb_sel_i==2'b11;
+ assign op_word = op & word & !wb_we_i;
+
+ assign flash_rst_n_ = 1'b1;
+ assign flash_we_n_ = 1'b1;
+ assign flash_oe_n_ = !op;
+ assign flash_ce_n_ = !op;
+
+ assign flash_addr_[21:1] = address;
+ assign flash_addr_[0] = (wb_sel_i==2'b10) | (word & st);
+ assign wr_command = op & wb_we_i; // Wishbone write access Signal
+
+ assign wb_ack_o = op & (op_word ? st : 1'b1);
+ assign wb_dat_o = wb_sel_i[1] ? { flash_data_, lb }
+ : { 8'h0, flash_data_ };
+
+ // Behaviour
+ // st - state
+ always @(posedge wb_clk_i)
+ st <= wb_rst_i ? 1'b0 : op_word;
+
+ // lb - low byte
+ always @(posedge wb_clk_i)
+ lb <= wb_rst_i ? 8'h0 : (op_word ? flash_data_ : 8'h0);
+
+ // --------------------------------------------------------------------
+ // Register addresses and defaults
+ // --------------------------------------------------------------------
+ `define FLASH_ALO 1'h0 // Lower 16 bits of address lines
+ `define FLASH_AHI 1'h1 // Upper 6 bits of address lines
+ always @(posedge wb_clk_i) // Synchrounous
+ if(wb_rst_i)
+ address <= 21'h000000; // Interupt Enable default
+ else
+ if(wr_command) // If a write was requested
+ case(wb_adr_i) // Determine which register was writen to
+ `FLASH_ALO: address[15: 0] <= wb_dat_i;
+ `FLASH_AHI: address[20:16] <= wb_dat_i[4:0];
+ default: ; // Default
+ endcase // End of case
+
+endmodule
+"
+"/*
+ * Milkymist VJ SoC
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ * adjusted to FML 8x16 by Zeus Gomez Marmolejo
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+module hpdmc_ctlif #(
+\tparameter csr_addr = 1'b0,
+\tparameter sdram_addrdepth = 12
+) (
+\tinput sys_clk,
+\tinput sys_rst,
+\t
+\tinput [ 2:0] csr_a,
+\tinput csr_we,
+\tinput [15:0] csr_di,
+\toutput reg [15:0] csr_do,
+\t
+\toutput reg bypass,
+\toutput reg sdram_rst,
+\t
+\toutput reg sdram_cke,
+\toutput reg sdram_cs_n,
+\toutput reg sdram_we_n,
+\toutput reg sdram_cas_n,
+\toutput reg sdram_ras_n,
+\toutput reg [sdram_addrdepth-1:0] sdram_adr,
+\toutput [ 1:0] sdram_ba,
+\t
+\t/* Clocks we must wait following a PRECHARGE command (usually tRP). */
+\toutput reg [2:0] tim_rp,
+\t/* Clocks we must wait following an ACTIVATE command (usually tRCD). */
+\toutput reg [2:0] tim_rcd,
+\t/* CAS latency, 0 = 2 */
+\toutput reg tim_cas,
+\t/* Auto-refresh period (usually tREFI). */
+\toutput reg [10:0] tim_refi,
+\t/* Clocks we must wait following an AUTO REFRESH command (usually tRFC). */
+\toutput reg [3:0] tim_rfc,
+\t/* Clocks we must wait following the last word written to the SDRAM (usually tWR). */
+\toutput reg [1:0] tim_wr
+);
+
+ localparam low_addr_bits16 = 16 - sdram_addrdepth;
+ localparam low_addr_bits12 = sdram_addrdepth - 12;
+
+wire csr_selected = csr_a[2] == csr_addr;
+
+// We assume sdram_ba will be always zero, so we can truncate the bus to 16 bits
+assign sdram_ba = 2'b00;
+
+always @(posedge sys_clk) begin
+\tif(sys_rst) begin
+\t\tcsr_do <= 16'd0;
+\t
+\t\tbypass <= 1'b1;
+\t\tsdram_rst <= 1'b1;
+\t\t
+\t\tsdram_cke <= 1'b0;
+\t\tsdram_adr <= {sdram_addrdepth{1'd0}};
+\t\t
+\t\ttim_rp <= 3'd2;
+\t\ttim_rcd <= 3'd2;
+\t\ttim_cas <= 1'b0;
+\t\ttim_refi <= 11'd740;
+\t\ttim_rfc <= 4'd8;
+\t\ttim_wr <= 2'd2;
+\tend else begin
+\t\tsdram_cs_n <= 1'b1;
+\t\tsdram_we_n <= 1'b1;
+\t\tsdram_cas_n <= 1'b1;
+\t\tsdram_ras_n <= 1'b1;
+\t\t
+\t\tcsr_do <= 16'd0;
+\t\tif(csr_selected) begin
+\t\t\tif(csr_we) begin
+\t\t\t\tcase(csr_a[1:0])
+\t\t\t\t\t2'b00: begin
+\t\t\t\t\t\tbypass <= csr_di[0];
+\t\t\t\t\t\tsdram_rst <= csr_di[1];
+\t\t\t\t\t\tsdram_cke <= csr_di[2];
+\t\t\t\t\tend
+\t\t\t\t\t2'b01: begin
+\t\t\t\t\t\tsdram_cs_n <= ~csr_di[0];
+\t\t\t\t\t\tsdram_we_n <= ~csr_di[1];
+\t\t\t\t\t\tsdram_cas_n <= ~csr_di[2];
+\t\t\t\t\t\tsdram_ras_n <= ~csr_di[3];
+\t\t\t\t\t\tsdram_adr <= { {low_addr_bits12{1'b0}}, csr_di[15:4]};
+\t\t\t\t\tend
+\t\t\t\t\t2'b10: begin
+\t\t\t\t\t\ttim_rp <= csr_di[2:0];
+\t\t\t\t\t\ttim_rcd <= csr_di[5:3];
+\t\t\t\t\t\ttim_cas <= csr_di[6];
+\t\t\t\t\t\ttim_rfc <= csr_di[10:7];
+\t\t\t\t\t\ttim_wr <= csr_di[12:11];
+\t\t\t\t\tend
+ 2'b11: begin
+\t\t\t\t\t\ttim_refi <= csr_di[10:0];
+ end
+\t\t\t\tendcase
+\t\t\tend
+\t\t\tcase(csr_a[1:0])
+\t\t\t\t2'b00: csr_do <= {sdram_cke, sdram_rst, bypass};
+\t\t\t\t2'b01: csr_do <= {sdram_adr, {low_addr_bits16{1'b0}} };
+\t\t\t\t2'b10: csr_do <= {tim_wr, tim_rfc, tim_cas, tim_rcd, tim_rp};
+ 2'b11: csr_do <= {5'd0, tim_refi};
+\t\t\tendcase
+\t\tend
+\tend
+end
+
+endmodule
+"
+"/*
+ * RS-232 asynchronous RX module
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module serial_arx (
+ input clk,
+ input rxd,
+ input baud8tick, // Desired baud rate
+
+ output reg [7:0] rxd_data,
+ output reg rxd_data_ready, // on clock pulse when rxd_data is valid
+
+ // We also detect if a gap occurs in the received stream of
+ // characters whuich can be useful if multiple characters are
+ // sent in burst so that multiple characters can be treated as a ""packet""
+ output reg rxd_endofpacket, // one clock pulse, when no more data
+ // is received (rxd_idle is going high)
+ output rxd_idle // no data is being received
+ );
+
+ reg [1:0] rxd_sync_inv; // we invert rxd, so that the idle becomes ""0"", to prevent a phantom character to be received at startup
+ always @(posedge clk) if(baud8tick) rxd_sync_inv <= {rxd_sync_inv[0], ~rxd};
+
+ reg [1:0] rxd_cnt_inv;
+ reg rxd_bit_inv;
+
+ always @(posedge clk)
+ if(baud8tick) begin
+ if( rxd_sync_inv[1] && rxd_cnt_inv!=2\'b11) rxd_cnt_inv <= rxd_cnt_inv + 2\'h1;
+ else
+ if(~rxd_sync_inv[1] && rxd_cnt_inv!=2\'b00) rxd_cnt_inv <= rxd_cnt_inv - 2\'h1;
+ if(rxd_cnt_inv==2\'b00) rxd_bit_inv <= 1\'b0;
+ else
+ if(rxd_cnt_inv==2\'b11) rxd_bit_inv <= 1\'b1;
+ end
+
+ reg [3:0] state;
+ reg [3:0] bit_spacing;
+
+ // ""next_bit"" controls when the data sampling occurs depending on how noisy the rxd is, different
+ // values might work better with a clean connection, values from 8 to 11 work
+ wire next_bit = (bit_spacing==4\'d10);
+
+ always @(posedge clk)
+ if(state==0)bit_spacing <= 4\'b0000;
+ else
+ if(baud8tick) bit_spacing <= {bit_spacing[2:0] + 4\'b0001} | {bit_spacing[3], 3\'b000};
+
+ always @(posedge clk)
+ if(baud8tick)
+ case(state)
+ 4\'b0000: if(rxd_bit_inv)state <= 4\'b1000; // start bit found?
+ 4\'b1000: if(next_bit) state <= 4\'b1001; // bit 0
+ 4\'b1001: if(next_bit) state <= 4\'b1010; // bit 1
+ 4\'b1010: if(next_bit) state <= 4\'b1011; // bit 2
+ 4\'b1011: if(next_bit) state <= 4\'b1100; // bit 3
+ 4\'b1100: if(next_bit) state <= 4\'b1101; // bit 4
+ 4\'b1101: if(next_bit) state <= 4\'b1110; // bit 5
+ 4\'b1110: if(next_bit) state <= 4\'b1111; // bit 6
+ 4\'b1111: if(next_bit) state <= 4\'b0001; // bit 7
+ 4\'b0001: if(next_bit) state <= 4\'b0000; // stop bit
+ default: state <= 4\'b0000;
+ endcase
+
+ always @(posedge clk)
+ if(baud8tick && next_bit && state[3]) rxd_data <= {~rxd_bit_inv, rxd_data[7:1]};
+
+ //reg rxd_data_error;
+ always @(posedge clk)
+ begin
+ rxd_data_ready <= (baud8tick && next_bit && state==4\'b0001 && ~rxd_bit_inv); // ready only if the stop bit is received
+ //rxd_data_error <= (baud8tick && next_bit && state==4\'b0001 && rxd_bit_inv); // error if the stop bit is not received
+ end
+
+ reg [4:0] gap_count;
+ always @(posedge clk) if (state!=0) gap_count<=5\'h00; else if(baud8tick & ~gap_count[4]) gap_count <= gap_count + 5\'h01;
+ assign rxd_idle = gap_count[4];
+ always @(posedge clk) rxd_endofpacket <= baud8tick & (gap_count==5\'h0F);
+
+endmodule
+"
+"/*
+ * Instruction decoder for Zet
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`include ""defines.v""
+
+module zet_decode (
+ input clk,
+ input rst,
+ input [7:0] opcode,
+ input [7:0] modrm,
+ input rep,
+ input block,
+ input exec_st,
+ input div_exc,
+ input ld_base,
+ input div,
+ input tfl,
+ output tflm,
+
+ output need_modrm,
+ output need_off,
+ output need_imm,
+ output off_size,
+ output imm_size,
+
+ input [2:0] sop_l,
+
+ input intr,
+ input ifl,
+ output iflm,
+ output reg inta,
+ output reg ext_int,
+ input nmir,
+ output reg nmia,
+ input wr_ss,
+ output iflss,
+
+ // to microcode
+ output [`MICRO_ADDR_WIDTH-1:0] seq_addr,
+ output [3:0] src,
+ output [3:0] dst,
+ output [3:0] base,
+ output [3:0] index,
+ output [1:0] seg,
+ output [2:0] f,
+
+ // from microcode
+ input end_seq
+ );
+
+ // Net declarations
+ wire [`MICRO_ADDR_WIDTH-1:0] base_addr;
+ reg [`MICRO_ADDR_WIDTH-1:0] seq;
+ reg dive;
+ reg tfle;
+ reg tfld;
+ reg ifld;
+ reg iflssd;
+ reg old_ext_int;
+
+ reg [4:0] div_cnt;
+
+ // Module instantiations
+ zet_opcode_deco opcode_deco (opcode, modrm, rep, sop_l, base_addr, need_modrm,
+ need_off, need_imm, off_size, imm_size, src, dst,
+ base, index, seg);
+
+ // Assignments
+ assign seq_addr = (tfle ? `INTT : (dive ? `INTD
+ : (ext_int ? (rep ? `EINTP : `EINT) : base_addr))) + seq;
+
+ assign f = opcode[7] ? modrm[5:3] : opcode[5:3];
+
+ assign iflm = ifl & ifld;
+ assign tflm = tfl & tfld;
+
+ assign iflss = !wr_ss & iflssd;
+
+ // Behaviour
+ always @(posedge clk)
+ ifld <= rst ? 1\'b0 : (exec_st ? ifld : ifl);
+
+ always @(posedge clk)
+ tfld <= rst ? 1\'b0 : (exec_st ? tfld : tfl);
+
+ always @(posedge clk)
+ if (rst)
+ iflssd <= 1\'b0;
+ else
+ begin
+ if (!exec_st)
+ iflssd <= 1\'b1;
+ else if (wr_ss)
+ iflssd <= 1\'b0;
+ end
+
+ // seq
+ always @(posedge clk)
+ seq <= rst ? `MICRO_ADDR_WIDTH\'d0
+ : block ? seq
+ : end_seq ? `MICRO_ADDR_WIDTH\'d0
+ : |div_cnt ? seq
+ : exec_st ? (seq + `MICRO_ADDR_WIDTH\'d1) : `MICRO_ADDR_WIDTH\'d0;
+
+ // div_cnt - divisor counter
+ always @(posedge clk)
+ div_cnt <= rst ? 5\'d0
+ : ((div & exec_st) ? (div_cnt==5\'d0 ? 5\'d18 : div_cnt - 5\'d1) : 5\'d0);
+
+ // dive
+ always @(posedge clk)
+ if (rst) dive <= 1\'b0;
+ else dive <= block ? dive
+ : (div_exc ? 1\'b1 : (dive ? !end_seq : 1\'b0));
+
+ // tfle
+ always @(posedge clk)
+ if (rst) tfle <= 1\'b0;
+ else tfle <= block ? tfle
+ : ((((tflm & !tfle) & iflss) & exec_st & end_seq) ? 1\'b1 : (tfle ? !end_seq : 1\'b0));
+
+ // ext_int
+ always @(posedge clk)
+ if (rst) ext_int <= 1\'b0;
+ else ext_int <= block ? ext_int
+ : ((((nmir | (intr & iflm)) & iflss) & exec_st & end_seq) ? 1\'b1
+ : (ext_int ? !end_seq : 1\'b0));
+
+ // old_ext_int
+ always @(posedge clk) old_ext_int <= rst ? 1\'b0 : ext_int;
+
+ // inta
+ always @(posedge clk)
+ inta <= rst ? 1\'b0 : (!nmir & (!old_ext_int & ext_int));
+
+ // nmia
+ always @(posedge clk)
+ nmia <= rst ? 1\'b0 : (nmir & (!old_ext_int & ext_int));
+
+endmodule
+"
+"/*
+ * Memory arbitrer for VGA
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vga_mem_arbitrer (
+ input clk_i,
+ input rst_i,
+
+ // Wishbone slave 1
+ input [17:1] wb_adr_i,
+ input [ 1:0] wb_sel_i,
+ input wb_we_i,
+ input [15:0] wb_dat_i,
+ output [15:0] wb_dat_o,
+ input wb_stb_i,
+ output wb_ack_o,
+
+ // CSR slave 1
+ input [17:1] csr_adr_i,
+ output [15:0] csr_dat_o,
+ input csr_stb_i,
+
+ // CSR master
+ output [17:1] csrm_adr_o,
+ output [ 1:0] csrm_sel_o,
+ output csrm_we_o,
+ output [15:0] csrm_dat_o,
+ input [15:0] csrm_dat_i
+ );
+
+ // Registers
+ reg [1:0] wb_ack;
+ wire wb_ack_r;
+ wire wb_ack_w;
+
+ // Continous assignments
+ assign csrm_adr_o = csr_stb_i ? csr_adr_i : wb_adr_i;
+ assign csrm_sel_o = csr_stb_i ? 2'b11 : wb_sel_i;
+ assign csrm_we_o = wb_stb_i & !csr_stb_i & wb_we_i;
+ assign csrm_dat_o = wb_dat_i;
+
+ assign wb_dat_o = csrm_dat_i;
+ assign csr_dat_o = csrm_dat_i;
+
+ assign wb_ack_r = wb_ack[1];
+ assign wb_ack_w = wb_stb_i & !csr_stb_i;
+ assign wb_ack_o = wb_we_i ? wb_ack_w : wb_ack_r;
+
+ // Behaviour
+ always @(posedge clk_i)
+ wb_ack <= rst_i ? 2'b00
+ : { wb_ack[0], (wb_stb_i & !csr_stb_i & !(|wb_ack)) };
+
+endmodule
+"
+"/*
+ * Character ROM for text mode fonts
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+// altera message_off 10030
+// get rid of the warning about
+// not initializing the ROM
+module vga_char_rom (
+ input clk,
+ input [11:0] addr,
+ output reg [ 7:0] q
+ );
+
+ // Registers, nets and parameters
+ reg [7:0] rom[0:4095];
+
+ // Behaviour
+ always @(posedge clk) q <= rom[addr];
+
+ initial $readmemh(""char_rom.dat"", rom);
+endmodule
+"
+"/*
+ * Wishbone Compatible BIOS ROM core using megafunction ROM
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+// The following is to get rid of the warning about not initializing the ROM
+// altera message_off 10030
+
+module bootrom (
+ input clk,
+ input rst,
+
+ // Wishbone slave interface
+ input [15:0] wb_dat_i,
+ output [15:0] wb_dat_o,
+ input [19:1] wb_adr_i,
+ input wb_we_i,
+ input wb_tga_i,
+ input wb_stb_i,
+ input wb_cyc_i,
+ input [ 1:0] wb_sel_i,
+ output wb_ack_o
+ );
+
+ // Net declarations
+ reg [15:0] rom[0:127]; // Instantiate the ROM
+
+ wire [ 6:0] rom_addr;
+ wire stb;
+
+ // Combinatorial logic
+ assign rom_addr = wb_adr_i[7:1];
+ assign stb = wb_stb_i & wb_cyc_i;
+ assign wb_ack_o = stb;
+ assign wb_dat_o = rom[rom_addr];
+
+ initial $readmemh(""bootrom.dat"", rom);
+
+endmodule
+"
+"
+`timescale 1ns/10ps
+
+module memory (
+ // Wishbone slave interface
+ input wb_clk_i,
+ input wb_rst_i,
+ input [15:0] wb_dat_i,
+ output [15:0] wb_dat_o,
+ input [19:1] wb_adr_i,
+ input wb_we_i,
+ input [ 1:0] wb_sel_i,
+ input wb_stb_i,
+ input wb_cyc_i,
+ output wb_ack_o
+ );
+
+ // Registers and nets
+ reg [15:0] ram[0:2**19-1];
+
+ wire we;
+ wire [7:0] bhw, blw;
+
+ // Assignments
+ assign wb_dat_o = ram[wb_adr_i];
+ assign wb_ack_o = wb_stb_i;
+ assign we = wb_we_i & wb_stb_i & wb_cyc_i;
+
+ assign bhw = wb_sel_i[1] ? wb_dat_i[15:8]
+ : ram[wb_adr_i][15:8];
+ assign blw = wb_sel_i[0] ? wb_dat_i[7:0]
+ : ram[wb_adr_i][7:0];
+
+ // Behaviour
+ always @(posedge wb_clk_i)
+ if (we) ram[wb_adr_i] <= { bhw, blw };
+
+endmodule
+"
+"/*
+ * Internal RAM for VGA
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vdu_ram_2k_attr (
+ input clk,
+ input rst,
+ input we,
+ input [10:0] addr,
+ output [ 7:0] rdata,
+ input [ 7:0] wdata
+ );
+
+ // Registers and nets
+ reg [ 7:0] mem[0:2047];
+ reg [10:0] addr_reg;
+
+ always @(posedge clk)
+ begin
+ if (we) mem[addr] <= wdata;
+ addr_reg <= addr;
+ end
+
+ // Combinatorial logic
+ assign rdata = mem[addr_reg];
+
+ initial $readmemh(""attr_rom.dat"", mem);
+
+endmodule
+
+"
+"/*
+ * DAC register file for VGA
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vga_dac_regs (
+ input clk,
+
+ // VGA read interface
+ input [7:0] index,
+ output reg [3:0] red,
+ output reg [3:0] green,
+ output reg [3:0] blue,
+
+ // CPU interface
+ input write,
+
+ // CPU read interface
+ input [1:0] read_data_cycle,
+ input [7:0] read_data_register,
+ output reg [3:0] read_data,
+
+ // CPU write interface
+ input [1:0] write_data_cycle,
+ input [7:0] write_data_register,
+ input [3:0] write_data
+ );
+
+ // Registers, nets and parameters
+ reg [3:0] red_dac [0:255];
+ reg [3:0] green_dac [0:255];
+ reg [3:0] blue_dac [0:255];
+
+ // Behaviour
+ // VGA read interface
+ always @(posedge clk)
+ begin
+ red <= red_dac[index];
+ green <= green_dac[index];
+ blue <= blue_dac[index];
+ end
+
+ // CPU read interface
+ always @(posedge clk)
+ case (read_data_cycle)
+ 2'b00: read_data <= red_dac[read_data_register];
+ 2'b01: read_data <= green_dac[read_data_register];
+ 2'b10: read_data <= blue_dac[read_data_register];
+ default: read_data <= 4'h0;
+ endcase
+
+ // CPU write interface
+ always @(posedge clk)
+ if (write)
+ case (write_data_cycle)
+ 2'b00: red_dac[write_data_register] <= write_data;
+ 2'b01: green_dac[write_data_register] <= write_data;
+ 2'b10: blue_dac[write_data_register] <= write_data;
+ endcase
+
+endmodule
+"
+"/*\r
+ * DUT VGA LCD FML\r
+ *\r
+ * VGA FML support\r
+ * Copyright (C) 2013 Charley Picker \r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+//`timescale 1ns/10ps\r
+`timescale 1ns/1ps\r
+\r
+module tb_vga_lcd_fml;\r
+\r
+ // Registers and nets\r
+ reg clk_100;\r
+ reg rst;\r
+ \r
+ reg shift_reg1; // if set: 320x200\r
+ reg graphics_alpha; // if not set: 640x400 text mode\r
+\r
+ // VGA LCD FML master interface\r
+ wire [20-1:0] fml_adr;\r
+ wire fml_stb;\r
+ reg fml_we;\r
+ reg fml_ack;\r
+ wire [1:0] fml_sel;\r
+ wire [15:0] fml_do;\r
+ reg [15:0] fml_di;\r
+ \r
+ // VGA LCD Direct Cache Bus\r
+ wire dcb_stb;\r
+ wire [20-1:0] dcb_adr;\r
+ reg [15:0] dcb_dat;\r
+ reg dcb_hit;\r
+\t\r
+ // attribute_ctrl\r
+ reg [3:0] pal_addr;\r
+ reg pal_we;\r
+ wire [7:0] pal_read;\r
+ reg [7:0] pal_write;\r
+\r
+ // dac_regs\r
+ reg dac_we;\r
+ reg [1:0] dac_read_data_cycle;\r
+ reg [7:0] dac_read_data_register;\r
+ wire [3:0] dac_read_data;\r
+ reg [1:0] dac_write_data_cycle;\r
+ reg [7:0] dac_write_data_register;\r
+ reg [3:0] dac_write_data;\r
+\r
+ // VGA pad signals\r
+ wire [3:0] vga_red_o;\r
+ wire [3:0] vga_green_o;\r
+ wire [3:0] vga_blue_o;\r
+ wire horiz_sync;\r
+ wire vert_sync;\r
+ \r
+ // Base address of video memory\r
+ reg [15:0] start_addr;\r
+\r
+ // CRTC\r
+ reg [5:0] cur_start;\r
+ reg [5:0] cur_end;\r
+ reg [4:0] vcursor;\r
+ reg [6:0] hcursor;\r
+\r
+ reg [6:0] horiz_total;\r
+ reg [6:0] end_horiz;\r
+ reg [6:0] st_hor_retr;\r
+ reg [4:0] end_hor_retr;\r
+ reg [9:0] vert_total;\r
+ reg [9:0] end_vert;\r
+ reg [9:0] st_ver_retr;\r
+ reg [3:0] end_ver_retr;\r
+\r
+ reg x_dotclockdiv2;\r
+\r
+ // retrace signals\r
+ wire v_retrace;\r
+ wire vh_retrace;\r
+ \r
+ wire vga_clk;\r
+ \r
+ /* Process FML requests */\r
+ reg [2:0] fml_wcount;\r
+ reg [2:0] fml_rcount;\r
+ reg [3:0] fml_pipe;\r
+ initial begin\r
+\t fml_ack = 1\'b0;\r
+\t fml_wcount = 0;\r
+\t fml_rcount = 0;\r
+ end\r
+ \r
+ always @(posedge clk_100)\r
+ fml_pipe <= rst ? 4\'b0 : { fml_pipe[2:0], fml_stb };\r
+\r
+ always @(posedge clk_100) begin\r
+\t if(fml_stb & (fml_wcount == 0) & (fml_rcount == 0)) begin\r
+\t\t fml_ack <= 1\'b1;\r
+\t\t if(fml_we) begin\r
+\t\t\t //$display(""%t FML W addr %x data %x"", $time, fml_adr, fml_dw);\r
+\t\t\t fml_wcount <= 7;\r
+\t\t end else begin\r
+\t\t\t fml_di = 16\'hbeef;\r
+\t\t\t //$display(""%t FML R addr %x data %x"", $time, fml_adr, fml_di);\r
+\t\t\t fml_rcount <= 7;\r
+\t\t end\r
+\t end else\r
+\t\t fml_ack <= 1\'b0;\r
+\t if(fml_wcount != 0) begin\r
+\t\t //#1 $display(""%t FML W continuing %x / %d"", $time, fml_dw, fml_wcount);\r
+\t\t fml_wcount <= fml_wcount - 1;\r
+\t end\r
+\t if(fml_rcount != 0) begin\r
+\t\t //fml_di = #1 {13\'h1eba, fml_rcount};\r
+\t\t fml_di = {13\'h1eba, fml_rcount};\r
+\t\t //$display(""%t FML R continuing %x / %d"", $time, fml_di, fml_rcount);\r
+\t\t fml_rcount <= fml_rcount - 1;\r
+\t end\r
+ end\r
+ \r
+ /* Process DCB requests */\r
+ //reg [15:0] dcb_dat;\r
+ reg [2:0] dcb_rcount;\r
+ reg [3:0] dcb_pipe;\r
+ initial begin\r
+\t dcb_hit = 1\'b0;\t \r
+\t dcb_rcount = 0;\r
+ end\r
+ \r
+ always @(posedge clk_100)\r
+ dcb_pipe <= rst ? 4\'b0 : { dcb_pipe[2:0], dcb_stb };\r
+\r
+ always @(posedge clk_100) begin\r
+ //if (dcb_stb)\r
+ //$display(""%t DCB R addr %x"", $time, dcb_adr);\r
+ if (dcb_stb & (dcb_rcount == 0))\r
+ begin\r
+ dcb_hit <= 1\'b1;\r
+ //dcb_hit <= 1\'b0;\r
+\t\t dcb_dat = 16\'hbeef;\r
+\t\t\t //$display(""%t DCB R addr %x data %x"", $time, dcb_adr, dcb_dat);\r
+\t\t\t dcb_rcount <= 7;\r
+\t\t end else\r
+\t\t dcb_hit <= 1\'b0;\t\t\r
+\t if(dcb_stb & (dcb_rcount != 0)) begin\r
+\t\t //dcb_dat = #1 {13\'h1eba, dcb_rcount};\r
+\t\t dcb_dat = {13\'h1eba, dcb_rcount};\r
+\t\t //$display(""%t DCB R continuing %x / %d"", $time, dcb_dat, dcb_rcount);\r
+\t\t dcb_rcount <= dcb_rcount - 1;\r
+\t end\t \r
+ end\r
+ \r
+ // Module instantiations\r
+ vga_lcd_fml #(\r
+ .fml_depth (20) // 8086 can only address 1 MB \r
+ ) dut (\r
+ .clk(clk_100), // 100 Mhz clock\r
+ .rst(rst),\r
+\r
+ .shift_reg1(shift_reg1), // if set: 320x200\r
+ .graphics_alpha(graphics_alpha), // if not set: 640x400 text mode\r
+\r
+ // VGA LCD FML master interface\r
+ .fml_adr(fml_adr),\r
+ .fml_stb(fml_stb),\r
+ .fml_we(fml_we),\r
+ .fml_ack(fml_ack),\r
+ .fml_sel(fml_sel),\r
+ .fml_do(fml_do),\r
+ .fml_di(fml_di),\r
+ \r
+ // VGA LCD Direct Cache Bus\r
+ .dcb_stb(dcb_stb),\r
+ .dcb_adr(dcb_adr),\r
+ .dcb_dat(dcb_dat),\r
+ .dcb_hit(dcb_hit),\r
+\r
+ // attribute_ctrl\r
+ .pal_addr(pal_addr),\r
+ .pal_we(pal_we),\r
+ .pal_read(pal_read),\r
+ .pal_write(pal_write),\r
+\r
+ // dac_regs\r
+ .dac_we(dac_we),\r
+ .dac_read_data_cycle(dac_read_data_cycle),\r
+ .dac_read_data_register(dac_read_data_register),\r
+ .dac_read_data(dac_read_data),\r
+ .dac_write_data_cycle(dac_write_data_cycle),\r
+ .dac_write_data_register(dac_write_data_register),\r
+ .dac_write_data(dac_write_data),\r
+\r
+ // VGA pad signals\r
+ .vga_red_o(vga_red_o),\r
+ .vga_green_o(vga_green_o),\r
+ .vga_blue_o(vga_blue_o),\r
+ .horiz_sync(horiz_sync),\r
+ .vert_sync(vert_sync),\r
+ \r
+ // Base address of video memory\r
+ .start_addr(start_addr),\r
+\r
+ // CRTC\r
+ .cur_start(cur_start),\r
+ .cur_end(cur_end),\r
+ .vcursor(vcursor),\r
+ .hcursor(hcursor),\r
+\r
+ .horiz_total(horiz_total),\r
+ .end_horiz(end_horiz),\r
+ .st_hor_retr(st_hor_retr),\r
+ .end_hor_retr(end_hor_retr),\r
+ .vert_total(vert_total),\r
+ .end_vert(end_vert),\r
+ .st_ver_retr(st_ver_retr),\r
+ .end_ver_retr(end_ver_retr),\r
+\r
+ .x_dotclockdiv2(x_dotclockdiv2),\r
+\r
+ // retrace signals\r
+ .v_retrace(v_retrace),\r
+ .vh_retrace(vh_retrace),\r
+ \r
+ .vga_clk(vga_clk)\r
+ );\r
+ \r
+ // Continuous assignments\r
+ \r
+ \r
+ // Behaviour\r
+ // Clock generation\r
+ //always #10 clk_100 <= !clk_100;\r
+ initial clk_100 = 1\'b0;\r
+ always #5 clk_100 = ~clk_100;\r
+ \r
+task waitclock;\r
+begin\r
+\t@(posedge clk_100);\r
+\t#1;\r
+end\r
+endtask\r
+\r
+always begin\r
+ // Initialize to a known state\r
+ rst = 1\'b1; // reset is active \r
+ \r
+ waitclock; \r
+ \r
+ rst = 1\'b0;\r
+ \r
+ waitclock;\r
+ \r
+ /* \r
+ // Set Text Mode\r
+ shift_reg1 = 1\'b0; // if set: 320x200\r
+ graphics_alpha = 1\'b0; // if not set: 640x400 text mode\r
+ */\r
+ \r
+ \r
+ \r
+ // Set Linear Mode\r
+ shift_reg1 = 1\'b1; // if set: 320x200\r
+ graphics_alpha = 1\'b1; // if not set: 640x400 text mode\r
+ \r
+ \r
+ // Base address of video memory\r
+ start_addr = 16\'h1000; \r
+ \r
+ // CRTC configuration signals\r
+ \r
+ cur_start = 5\'d0; // reg [5:0] cur_start,\r
+ cur_end = 5\'d0; // reg [5:0] cur_end,\r
+ vcursor = 4\'d0; // reg [4:0] vcursor,\r
+ hcursor = 6\'d0; // reg [6:0] hcursor,\r
+ \r
+ \r
+ horiz_total = 7\'d79; // reg [6:0] horiz_total,\r
+ //horiz_total = 7\'d639; // reg [6:0] horiz_total,\r
+ end_horiz = 7\'d750; // reg [6:0] end_horiz,\r
+ st_hor_retr = 7\'d760; // reg [6:0] st_hor_retr,\r
+ st_hor_retr = 7\'d656; // reg [6:0] st_hor_retr,\r
+ //end_hor_retr = 5\'d10; // reg [4:0] end_hor_retr,\r
+ end_hor_retr = 5\'d750; // reg [4:0] end_hor_retr,\r
+ end_hor_retr = 5\'d752; // reg [4:0] end_hor_retr,\r
+ vert_total = 10\'d399; // reg [9:0] vert_total,\r
+ end_vert = 10\'d550; // reg [9:0] end_vert,\r
+ st_ver_retr = 10\'d560; // reg [9:0] st_ver_retr,\r
+ //end_ver_retr = 4\'d10; // reg [3:0] end_ver_retr,\r
+ end_ver_retr = 4\'d750; // reg [3:0] end_ver_retr,\r
+ \r
+ x_dotclockdiv2 = 1\'b0; // reg x_dotclockdiv2\r
+ \r
+ repeat (20000) begin\r
+ waitclock;\r
+ end\r
+ \r
+ $stop;\r
+ \r
+end \r
+\r
+endmodule"
+"/*
+ * Microcode execution stage for Zet
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`timescale 1ns/10ps
+
+`include ""defines.v""
+
+module zet_exec (
+ input clk,
+ input rst,
+
+ input [`IR_SIZE-1:0] ir,
+ input [15:0] off,
+ input [15:0] imm,
+ output [15:0] cs,
+ output [15:0] ip,
+ output of,
+ output zf,
+ output cx_zero,
+ input [15:0] memout,
+
+ output [15:0] wr_data,
+ output [19:0] addr,
+ output we,
+ output m_io,
+ output byteop,
+ input block,
+ output div_exc,
+ input wrip0,
+
+ output ifl,
+ output tfl,
+ output wr_ss
+ );
+
+ // Net declarations
+ wire [15:0] c;
+ wire [15:0] omemalu;
+ wire [ 3:0] addr_a;
+ wire [ 3:0] addr_c;
+ wire [ 3:0] addr_d;
+ wire [ 8:0] flags;
+ wire [15:0] a, b, s, alu_iflags, bus_b;
+ wire [31:0] aluout;
+ wire [3:0] addr_b;
+ wire [2:0] t, func;
+ wire [1:0] addr_s;
+ wire wrfl, high, memalu, r_byte, c_byte;
+ wire wr, wr_reg;
+ wire wr_cnd;
+ wire jmp;
+ wire b_imm;
+ wire [8:0] iflags, oflags;
+ wire [4:0] logic_flags;
+ wire alu_word;
+ wire a_byte;
+ wire b_byte;
+ wire wr_high;
+ wire dive;
+
+ // Module instances
+ zet_alu alu( {c, a }, bus_b, aluout, t, func, alu_iflags, oflags,
+ alu_word, s, off, clk, dive);
+ zet_regfile regfile (
+ a, b, c, cs, ip, {aluout[31:16], omemalu}, s, flags, wr_reg, wrfl,
+ wr_high, clk, rst, addr_a, addr_b, addr_c, addr_d, addr_s, iflags,
+ ~byteop, a_byte, b_byte, c_byte, cx_zero, wrip0);
+ zet_jmp_cond jmp_cond (logic_flags, addr_b, addr_c[0], c, jmp);
+
+ // Assignments
+ assign addr_s = ir[1:0];
+ assign addr_a = ir[5:2];
+ assign addr_b = ir[9:6];
+ assign addr_c = ir[13:10];
+ assign addr_d = ir[17:14];
+ assign wrfl = ir[18];
+ assign we = ir[19];
+ assign wr = ir[20];
+ assign wr_cnd = ir[21];
+ assign high = ir[22];
+ assign t = ir[25:23];
+ assign func = ir[28:26];
+ assign byteop = ir[29];
+ assign memalu = ir[30];
+ assign m_io = ir[32];
+ assign b_imm = ir[33];
+ assign r_byte = ir[34];
+ assign c_byte = ir[35];
+
+ assign omemalu = memalu ? aluout[15:0] : memout;
+ assign bus_b = b_imm ? imm : b;
+
+ assign addr = aluout[19:0];
+ assign wr_data = c;
+ assign wr_reg = (wr | (jmp & wr_cnd)) && !block && !div_exc;
+ assign wr_high = high && !block && !div_exc;
+ assign of = flags[8];
+ assign ifl = flags[6];
+ assign tfl = flags[5];
+ assign zf = flags[3];
+
+ assign iflags = oflags;
+ assign alu_iflags = { 4\'b1111, flags[8:3], 1\'b0, flags[2], 1\'b0, flags[1],
+ 1\'b1, flags[0] };
+ assign logic_flags = { flags[8], flags[4], flags[3], flags[1], flags[0] };
+
+ assign alu_word = (t==3\'b011) ? ~r_byte : ~byteop;
+ assign a_byte = (t==3\'b011 && func[1]) ? 1\'b0 : r_byte;
+ assign b_byte = r_byte;
+ assign div_exc = dive && wr;
+
+ assign wr_ss = (addr_d == 4\'b1010) && wr;
+
+endmodule
+"
+"/*
+ * Memory interface for VGA
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vga_cpu_mem_iface (
+ // Wishbone common signals
+ input wb_clk_i,
+ input wb_rst_i,
+
+ // Wishbone slave interface
+ input [16:1] wbs_adr_i,
+ input [ 1:0] wbs_sel_i,
+ input wbs_we_i,
+ input [15:0] wbs_dat_i,
+ output [15:0] wbs_dat_o,
+ input wbs_stb_i,
+ output wbs_ack_o,
+
+ // Wishbone master to SRAM
+ output [17:1] wbm_adr_o,
+ output [ 1:0] wbm_sel_o,
+ output wbm_we_o,
+ output [15:0] wbm_dat_o,
+ input [15:0] wbm_dat_i,
+ output wbm_stb_o,
+ input wbm_ack_i,
+
+ // VGA configuration registers
+ input chain_four,
+ input memory_mapping1,
+ input [ 1:0] write_mode,
+ input [ 1:0] raster_op,
+ input read_mode,
+ input [ 7:0] bitmask,
+ input [ 3:0] set_reset,
+ input [ 3:0] enable_set_reset,
+ input [ 3:0] map_mask,
+ input [ 1:0] read_map_select,
+ input [ 3:0] color_compare,
+ input [ 3:0] color_dont_care
+ );
+
+ // Registers and nets
+ wire read_stb;
+ wire write_stb;
+ wire rd_wbs_ack_o;
+ wire [15:0] rd_wbs_dat_o;
+ wire wr_wbs_ack_o;
+ wire [17:1] rd_wbm_adr_o;
+ wire [17:1] wr_wbm_adr_o;
+ wire rd_wbm_stb_o;
+ wire wr_wbm_stb_o;
+ wire rd_wbm_ack_i;
+ wire [ 1:0] wr_wbm_sel_o;
+ wire [15:0] wr_wbm_dat_o;
+ wire wr_wbm_ack_i;
+
+ wire [15:0] wbs_dat_o_c;
+ wire wbs_stb_i_c;
+ wire wbs_ack_o_c;
+
+ wire [17:1] wbm_adr_o_c;
+ wire [ 1:0] wbm_sel_o_c;
+ wire wbm_we_o_c;
+ wire [15:0] wbm_dat_o_c;
+ wire wbm_stb_o_c;
+ wire wbm_ack_i_c;
+
+ wire [7:0] latch0, latch1, latch2, latch3;
+
+ // Module instances
+ vga_read_iface read_iface (
+ .wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+
+ .wbs_adr_i (wbs_adr_i),
+ .wbs_sel_i (wbs_sel_i),
+ .wbs_dat_o (rd_wbs_dat_o),
+ .wbs_stb_i (read_stb),
+ .wbs_ack_o (rd_wbs_ack_o),
+
+ .wbm_adr_o (rd_wbm_adr_o),
+ .wbm_dat_i (wbm_dat_i),
+ .wbm_stb_o (rd_wbm_stb_o),
+ .wbm_ack_i (rd_wbm_ack_i),
+
+ .memory_mapping1 (memory_mapping1),
+ .read_mode (read_mode),
+ .read_map_select (read_map_select),
+ .color_compare (color_compare),
+ .color_dont_care (color_dont_care),
+
+ .latch0 (latch0),
+ .latch1 (latch1),
+ .latch2 (latch2),
+ .latch3 (latch3)
+ );
+
+ vga_write_iface write_iface (
+ .wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+
+ .wbs_adr_i (wbs_adr_i),
+ .wbs_sel_i (wbs_sel_i),
+ .wbs_dat_i (wbs_dat_i),
+ .wbs_stb_i (write_stb),
+ .wbs_ack_o (wr_wbs_ack_o),
+
+ .wbm_adr_o (wr_wbm_adr_o),
+ .wbm_sel_o (wr_wbm_sel_o),
+ .wbm_dat_o (wr_wbm_dat_o),
+ .wbm_stb_o (wr_wbm_stb_o),
+ .wbm_ack_i (wr_wbm_ack_i),
+
+ .memory_mapping1 (memory_mapping1),
+ .write_mode (write_mode),
+ .raster_op (raster_op),
+ .bitmask (bitmask),
+ .set_reset (set_reset),
+ .enable_set_reset (enable_set_reset),
+ .map_mask (map_mask),
+
+ .latch0 (latch0),
+ .latch1 (latch1),
+ .latch2 (latch2),
+ .latch3 (latch3)
+ );
+
+ vga_c4_iface c4_iface (
+ .wb_clk_i (wb_clk_i),
+ .wb_rst_i (wb_rst_i),
+
+ .wbs_adr_i (wbs_adr_i),
+ .wbs_sel_i (wbs_sel_i),
+ .wbs_we_i (wbs_we_i),
+ .wbs_dat_i (wbs_dat_i),
+ .wbs_dat_o (wbs_dat_o_c),
+ .wbs_stb_i (wbs_stb_i_c),
+ .wbs_ack_o (wbs_ack_o_c),
+
+ .wbm_adr_o (wbm_adr_o_c),
+ .wbm_sel_o (wbm_sel_o_c),
+ .wbm_we_o (wbm_we_o_c),
+ .wbm_dat_o (wbm_dat_o_c),
+ .wbm_dat_i (wbm_dat_i),
+ .wbm_stb_o (wbm_stb_o_c),
+ .wbm_ack_i (wbm_ack_i_c)
+ );
+
+ // Continuous assignments
+ assign read_stb = wbs_stb_i & !wbs_we_i & !chain_four;
+ assign write_stb = wbs_stb_i & wbs_we_i & !chain_four;
+ assign rd_wbm_ack_i = !wbs_we_i & wbm_ack_i & !chain_four;
+ assign wr_wbm_ack_i = wbs_we_i & wbm_ack_i & !chain_four;
+
+ assign wbs_ack_o = chain_four ? wbs_ack_o_c
+ : (wbs_we_i ? wr_wbs_ack_o : rd_wbs_ack_o);
+ assign wbs_dat_o = chain_four ? wbs_dat_o_c : rd_wbs_dat_o;
+ assign wbm_adr_o = chain_four ? wbm_adr_o_c
+ : (wbs_we_i ? wr_wbm_adr_o : rd_wbm_adr_o);
+ assign wbm_stb_o = chain_four ? wbm_stb_o_c
+ : (wbs_we_i ? wr_wbm_stb_o : rd_wbm_stb_o);
+ assign wbm_sel_o = chain_four ? wbm_sel_o_c : wr_wbm_sel_o;
+ assign wbm_dat_o = chain_four ? wbm_dat_o_c : wr_wbm_dat_o;
+
+ assign wbm_we_o = chain_four & wbm_we_o_c
+ | !chain_four & wbs_we_i;
+
+ assign wbs_stb_i_c = chain_four & wbs_stb_i;
+ assign wbm_ack_i_c = chain_four & wbm_ack_i;
+endmodule
+"
+"/*
+ * Copyright (c) 2008 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+`include ""rom_def.v""
+
+`define IR_SIZE 36
+`define MEM_OP 31
+`define ADD_IP `IR_SIZE\'bx__0__1__0__1__10_001_001__0__01__0__0_1111_xxxx_xxxx_1111_xx
+`define OP_NOP 8\'h90
+`define OP_HLT 8\'hF4
+
+//`define DEBUG 1
+//`define DEBUG_TRACE 1
+"
+"/*
+ * Wishbone Compatible PS2 core
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module ps2 (
+ // Wishbone slave interface
+ input wb_clk_i, // Clock Input
+ input wb_rst_i, // Reset Input
+ input [15:0] wb_dat_i, // Command to send to mouse
+ output [15:0] wb_dat_o, // Received data
+ input wb_cyc_i, // Cycle
+ input wb_stb_i, // Strobe
+ input [ 2:1] wb_adr_i, // Wishbone address lines
+ input [ 1:0] wb_sel_i, // Wishbone Select lines
+ input wb_we_i, // Write enable
+ output wb_ack_o, // Normal bus termination
+ output wb_tgk_o, // Interrupt request
+ output wb_tgm_o, // Interrupt request
+
+ input ps2_kbd_clk_, // PS2 Keyboard Clock, Bidirectional
+ inout ps2_kbd_dat_, // PS2 Keyboard Data, Bidirectional
+ inout ps2_mse_clk_, // PS2 Mouse Clock, Bidirectional
+ inout ps2_mse_dat_ // PS2 Mouse Data, Bidirectional
+ );
+
+ // --------------------------------------------------------------------
+ // --------------------------------------------------------------------
+ // This section is a simple WB interface
+ // --------------------------------------------------------------------
+ // --------------------------------------------------------------------
+ wire [7:0] dat_i;
+ wire [2:0] wb_ps2_addr;
+ wire wb_ack_i;
+ wire write_i;
+ wire read_i;
+
+ // --------------------------------------------------------------------
+ // --------------------------------------------------------------------
+ // This section is a simple front end for the PS2 Mouse, it is NOT 100%
+ // 8042 compliant but is hopefully close enough to work for most apps.
+ // There are two variants in common use, the AT style and the PS2 style
+ // Interface, this is an implementation of the PS2 style which seems to be
+ // The most common. Reference: http://www.computer-engineering.org/ps2keyboard/
+ //
+ // |7|6|5|4|3|2|1|0| PS2 Status Register
+ // | | | | | | | `-- PS_IBF - Input Buffer Full-- 0: Empty, No unread input at port, 1: Data available for host to read
+ // | | | | | | `---- PS_OBF - Output Buffer Full-- 0: Output Buffer Empty, 1: data in buffer being processed
+ // | | | | | `------ PS_SYS - System flag-- POST read this to determine if power-on reset, 0: in reset, 1: BAT code received - System has already beed initialized
+ // | | | | `-------- PS_A2 - Address line A2-- Used internally by kbd controller, 0: A2 = 0 - Port 0x60 was last written to, 1: A2 = 1 - Port 0x64 was last written to
+ // | | | `---------- PS_INH - Inhibit flag-- Indicates if kbd communication is inhibited; 0: Keyboard Clock = 0 - Keyboard is inhibited , 1: Keyboard Clock = 1 - Keyboard is not inhibited
+ // | | `------------ PS_MOBF - Mouse Output Buffer Full; 0: Output buffer empty, 1: Output buffer full
+ // | `-------------- PS_TO - General Timout-- Indicates timeout during command write or response. (Same as TxTO + RxTO.)
+ // `---------------- RX_PERR - Parity Error-- Indicates communication error with keyboard (possibly noisy/loose connection)
+ //
+ // |7|6|5|4|3|2|1|0| PS2 Control Byte
+ // | | | | | | | `-- PS_INT - Input Buffer Full Interrupt-- When set, IRQ 1 is generated when data is available in the input buffer.
+ // | | | | | | `---- PS_INT2 - Mouse Input Buffer Full Interrupt - When set, IRQ 12 is generated when mouse data is available.
+ // | | | | | `------ PS_SYSF - System Flag-- Used to manually set/clear SYS flag in Status register.
+ // | | | | `-------- - No assignment
+ // | | | `---------- PS_EN - Disable keyboard-- Disables/enables keyboard interface
+ // | | `------------ PS_EN2 - Disable Mouse-- Disables/enables mouse interface
+ // | `-------------- PS_XLAT - Translate Scan Codes - Enables/disables translation to set 1 scan codes
+ // `---------------- - No assignment
+ //
+ // --------------------------------------------------------------------
+
+
+ // --------------------------------------------------------------------
+ // Status Register and Wires
+ // --------------------------------------------------------------------
+ wire PS_IBF;
+ wire PS_OBF;
+ wire PS_SYS;
+ wire PS_A2;
+ wire PS_INH;
+ wire PS_MOBF;
+ wire PS_TO;
+ wire RX_PERR;
+ wire [7:0] PS_STAT;
+
+ // --------------------------------------------------------------------
+ // Control Register and Wires
+ // --------------------------------------------------------------------
+ reg [7:0] PS_CNTL; // Control Register
+ wire PS_INT;
+ wire PS_INT2;
+
+ wire DAT_SEL;
+ wire DAT_wr;
+ wire DAT_rd;
+
+ wire CMD_SEL;
+ wire CMD_wr;
+ wire CMD_rdc;
+ wire CMD_wrc;
+ wire CMD_mwr;
+ wire CMD_tst;
+ wire CMD_mit;
+
+ wire [7:0] dat_o;
+ wire [7:0] d_dat_o;
+ wire [7:0] r_dat_o;
+ wire [7:0] t_dat_o;
+ wire [7:0] i_dat_o;
+ wire [7:0] p_dat_o;
+ wire [7:0] ps_tst_o;
+ wire [7:0] ps_mit_o;
+
+ wire cmd_msnd;
+
+ wire IBF;
+
+ reg cnt_r_flag; // Read Control lines flag
+ reg cnt_w_flag; // Write to Control lines flag
+ reg cmd_w_msnd; // Signal to send to mouse flag
+ reg cmd_r_test; // Signal to send test flag
+ reg cmd_r_mint; // Signal to send test flag
+
+ reg MSE_INT; // Mouse Receive interrupt signal
+ wire PS_READ;
+
+ wire [7:0] MSE_dat_o; // Receive Register
+ wire [7:0] MSE_dat_i;
+ wire MSE_RDY; // Signal data received
+ wire MSE_DONE; // Signal command finished sending
+ wire MSE_TOER; // Indicates a Transmit error occured
+ wire MSE_OVER; // Indicates buffer over run error
+ wire MSE_SEND;
+
+ wire KBD_INT;
+ wire [7:0] KBD_dat_o;
+ wire KBD_Txdone;
+ wire KBD_Rxdone;
+
+ // Unused output
+ wire released;
+
+/*
+ * We comment this out as they are never read
+ *
+ wire PS_SYSF = PS_CNTL[2]; // 0: Power-on value - Tells POST to perform power-on tests/initialization. 1: BAT code received - Tells POST to perform ""warm boot"" tests/initiailization.
+ wire PS_EN = PS_CNTL[4]; // 0: Enable - Keyboard interface enabled. 1: Disable - All keyboard communication is disabled.
+ wire PS_EN2 = PS_CNTL[5]; // 0: Enable - Auxillary PS/2 device interface enabled 1: Disable - Auxillary PS/2 device interface disabled
+ wire PS_XLAT = PS_CNTL[6]; // 0: Translation disabled - Data appears at input buffer exactly as read from keyboard 1: Translation enabled - Scan codes translated to set 1 before put in input buffer
+*/
+`define default_cntl 8\'b0100_0111
+
+ // --------------------------------------------------------------------
+ // Behaviour for Command Register
+ // The PS2 has this funky command byte structure:
+ //
+ // - If you write 0x60 to 0x64 port and they next byte you write to port 0x60
+ // is stored as the command byte (nice and confusing).
+ //
+ // - If you write 0x20 to port 0x64, the next byte you read from port
+ // 0x60 is the command byte read back.
+ //
+ // - If you read from 0x64, you get the status
+ //
+ // - if you read 0x60, that is either mouse or keyboard data, depending
+ // on the last command sent
+ //
+ // - if you write data to 0x60, either mouse or keyboard data is transmitted
+ // to either the mouse or keyboard depending on the last command.
+ //
+ // Right now, we do not allow sending data to the keyboard, that maybe
+ // will change later on.
+ //
+ // --------------------------------------------------------------------
+ // Controller Commands:
+ // ,------------------------ - Currently Supported Command
+ // |
+ // 0x20 X Read control lines - Next byte read from 0x60 is control line info
+ // 0x60 X Write to control lines - Next byte writen to 0x60 is control line info
+ // 0x90-0x9F _ Write to output port - Writes command\'s lower nibble to lower nibble of output port
+ // 0xA1 _ Get version number - Returns firmware version number.
+ // 0xA4 _ Get password - Returns 0xFA if password exists; otherwise, 0xF1.
+ // 0xA5 _ Set password - Set the new password by sending a null-terminated string of scan codes as this command\'s parameter.
+ // 0xA6 _ Check password - Compares keyboard input with current password.
+ // 0xA7 _ Disable mouse interface - PS/2 mode only. Similar to ""Disable keyboard interface"" (0xAD) command.
+ // 0xA8 _ Enable mouse interface - PS/2 mode only. Similar to ""Enable keyboard interface"" (0xAE) command.
+ // 0xA9 X Mouse interface test - Returns 0x00 if okay, 0x01 if Clock line stuck low, 0x02 if clock line stuck high, 0x03 if data line stuck low, and 0x04 if data line stuck high.
+ // 0xAA X Controller self-test - Returns 0x55 if okay.
+ // 0xAB _ Keyboard interface test - Returns 0x00 if okay, 0x01 if Clock line stuck low, 0x02 if clock line stuck high, 0x03 if data line stuck low, and 0x04 if data line stuck high.
+ // 0xAD _ Disable keybrd interface- Sets bit 4 of command byte and disables all communication with keyboard.
+ // 0xAE _ Enable keybrd interface - Clears bit 4 of command byte and re-enables communication with keyboard.
+ // 0xAF _ Get version
+ // 0xC0 _ Read input port - Returns values on input port (see Input Port definition.)
+ // 0xC1 _ Copy input port LSn - PS/2 mode only. Copy input port\'s low nibble to Status register (see Input Port definition)
+ // 0xC2 _ Copy input port MSn - PS/2 mode only. Copy input port\'s high nibble to Status register (see Input Port definition.)
+ // 0xD0 _ Read output port - Returns values on output port (see Output Port definition.)
+ // 0xD1 _ Write output port - Write parameter to output port (see Output Port definition.)
+ // 0xD2 _ Write keyboard buffer - Parameter written to input buffer as if received from keyboard.
+ // 0xD3 _ Write mouse buffer - Parameter written to input buffer as if received from mouse.
+ // 0xD4 X Write mouse Device - Sends parameter to the auxillary PS/2 device.
+ // 0xE0 _ Read test port - Returns values on test port (see Test Port definition.)
+ // 0xF0-0xFF _ Pulse output port - Pulses command\'s lower nibble onto lower nibble of output port (see Output Port definition.)
+ // --------------------------------------------------------------------
+`define PS2_CMD_A9 8\'hA9 // Mouse Interface test
+`define PS2_CMD_AA 8\'hAA // Controller self test
+`define PS2_CMD_D4 8\'hD4 // Write to mouse
+`define PS2_CNT_RD 8\'h20 // Read command byte
+`define PS2_CNT_WR 8\'h60 // Write control byte
+
+`define PS2_DAT_REG 3\'b000 // 0x60 - RW Transmit / Receive register
+`define PS2_CMD_REG 3\'b100 // 0x64 - RW - Status / command register
+
+ // --------------------------------------------------------------------
+ // Command Behavior
+ // --------------------------------------------------------------------
+ // --------------------------------------------------------------------
+ // Behavior of Control Register
+ // --------------------------------------------------------------------
+ always @(posedge wb_clk_i) begin // Synchrounous
+ if(wb_rst_i) begin
+ PS_CNTL <= `default_cntl; // Set initial default value
+ cnt_r_flag <= 1\'b0; // Reset the flag
+ cnt_w_flag <= 1\'b0; // Reset the flag
+ cmd_w_msnd <= 1\'b0; // Reset the flag
+ cmd_r_test <= 1\'b0; // Reset the flag
+ cmd_r_mint <= 1\'b0; // Reset the flag
+ end
+ else
+ if(CMD_rdc) begin
+ cnt_r_flag <= 1\'b1; // signal next read from 0x60 is control info
+ end
+ else
+ if(CMD_wrc) begin
+ cnt_w_flag <= 1\'b1; // signal next write to 0x60 is control info
+ cmd_w_msnd <= 1\'b0; // Reset the flag
+ end
+ else
+ if(CMD_mwr) begin
+ cmd_w_msnd <= 1\'b1; // signal next write to 0x60 is mouse info
+ end
+ else
+ if(CMD_tst) begin
+ cmd_r_test <= 1\'b1; // signal next read from 0x60 is test info
+ end
+ else
+ if(CMD_mit) begin
+ cmd_r_mint <= 1\'b1; // signal next read from 0x60 is test info
+ end
+ else
+ if(DAT_rd) begin
+ if(cnt_r_flag) cnt_r_flag <= 1\'b0; // Reset the flag
+ if(cmd_r_test) cmd_r_test <= 1\'b0; // Reset the flag
+ if(cmd_r_mint) cmd_r_mint <= 1\'b0; // Reset the flag
+ end
+ else
+ if(DAT_wr) begin
+ if(cnt_w_flag) begin
+ PS_CNTL <= dat_i; // User requested to write control info
+ cnt_w_flag <= 1\'b0; // Reset the flag
+ end
+ end
+
+ if(cmd_w_msnd && MSE_DONE) cmd_w_msnd <= 1\'b0; // Reset the flag
+ end // Synchrounous always
+
+ // --------------------------------------------------------------------
+ // Mouse Transceiver Section
+ // --------------------------------------------------------------------
+
+ // --------------------------------------------------------------------
+ // Mouse Receive Interrupt behavior
+ // --------------------------------------------------------------------
+ always @(posedge wb_clk_i or posedge wb_rst_i) begin // Synchrounous
+ if(wb_rst_i) MSE_INT <= 1\'b0; // Default value
+ else begin
+ if(MSE_RDY) MSE_INT <= 1\'b1; // Latch interrupt
+ if(PS_READ) MSE_INT <= 1\'b0; // Clear interrupt
+ end
+ end // Synchrounous always
+
+ // --------------------------------------------------------------------
+ // Instantiate the PS2 UART for MOUSE
+ // --------------------------------------------------------------------
+ ps2_mouse_nofifo mouse_nofifo (
+ .clk (wb_clk_i),
+ .reset (wb_rst_i),
+ .ps2_clk (ps2_mse_clk_),
+ .ps2_dat (ps2_mse_dat_),
+
+ .writedata (MSE_dat_i), // data to send
+ .write (MSE_SEND), // signal to send it
+ .command_was_sent (MSE_DONE), // Done sending
+
+ .readdata (MSE_dat_o), // data read
+ .irq (MSE_RDY), // signal data has arrived and is ready to be read
+ .inhibit (MSE_INT),
+
+ .error_sending_command (MSE_TOER), // Time out error
+ .buffer_overrun_error (MSE_OVER) // Buffer over run error
+ );
+
+ // --------------------------------------------------------------------
+ // Keyboard Receiver Section
+ // --------------------------------------------------------------------
+
+ // --------------------------------------------------------------------
+ // Instantiate the PS2 UART for KEYBOARD
+ // --------------------------------------------------------------------
+ ps2_keyb #(
+ .TIMER_60USEC_VALUE_PP (750),
+ .TIMER_60USEC_BITS_PP (10),
+ .TIMER_5USEC_VALUE_PP (60),
+ .TIMER_5USEC_BITS_PP (6)
+ ) keyb (
+ .clk (wb_clk_i),
+ .reset (wb_rst_i),
+
+ .rx_shifting_done (KBD_Rxdone), // done receivign
+ .tx_shifting_done (KBD_Txdone), // done transmiting
+
+ .scancode (KBD_dat_o), // scancode
+ .rx_output_strobe (KBD_INT), // Signals a key presseed
+ .released (released),
+
+ .ps2_clk_ (ps2_kbd_clk_), // PS2 PAD signals
+ .ps2_data_ (ps2_kbd_dat_)
+ );
+
+ // Combinatorial logic
+ assign dat_i = wb_sel_i[0] ? wb_dat_i[7:0] : wb_dat_i[15:8]; // 8 to 16 bit WB
+ assign wb_dat_o = wb_sel_i[0] ? {8\'h00, dat_o} : {dat_o, 8\'h00}; // 8 to 16 bit WB
+ assign wb_ps2_addr = {wb_adr_i, wb_sel_i[1]}; // Compute Address
+ assign wb_ack_i = wb_stb_i & wb_cyc_i; // Immediate ack
+ assign wb_ack_o = wb_ack_i;
+ assign write_i = wb_ack_i & wb_we_i; // WISHBONE write access, Singal to send
+ assign read_i = wb_ack_i & ~wb_we_i; // WISHBONE write access, Singal to send
+ assign wb_tgm_o = MSE_INT & PS_INT2; // Mouse Receive interupts ocurred
+ assign wb_tgk_o = KBD_INT & PS_INT; // Keyboard Receive interupts ocurred
+
+ assign PS_IBF = IBF; // 0: Empty, No unread input at port, 1: Full, New input can be read from port 0x60
+ assign PS_OBF = KBD_Txdone; // 0: Ok to write to port 0x60 1: Full, Don\'t write to port 0x60
+ assign PS_SYS = 1\'b1; // 1: Always 1 cuz this is fpga so will always be initialized
+ assign PS_A2 = 1\'b0; // 0: A2 = 0 - Port 0x60 was last written to, 1: A2 = 1 - Port 0x64 was last written to
+ assign PS_INH = 1\'b1; // 0: Keyboard Clock = 0 - Keyboard is inhibited , 1: Keyboard Clock = 1 - Keyboard is not inhibited
+ assign PS_MOBF = MSE_DONE; // 0: Buffer empty - Okay to write to auxillary device\'s output buffer, 1: Output buffer full - Don\'t write to port auxillary device\'s output buffer
+ assign PS_TO = MSE_TOER; // 0: No Error - Keyboard received and responded to last command, 1: Timeout Error - See TxTO and RxTO for more information.
+ assign RX_PERR = MSE_OVER; // 0: No Error - Odd parity received and proper command response recieved, 1: Parity Error - Even parity received or 0xFE received as command response.
+ assign PS_STAT = {RX_PERR, PS_TO, PS_MOBF, PS_INH, PS_A2, PS_SYS, PS_OBF, PS_IBF}; // Status Register
+ assign PS_INT = PS_CNTL[0]; // 0: IBF Interrupt Disabled, 1: IBF Interrupt Enabled - Keyboard driver at software int 0x09 handles input.
+ assign PS_INT2 = PS_CNTL[1]; // 0: Auxillary IBF Interrupt Disabled, 1: Auxillary IBF Interrupt Enabled
+
+ assign DAT_SEL = (wb_ps2_addr == `PS2_DAT_REG);
+ assign DAT_wr = DAT_SEL && write_i;
+ assign DAT_rd = DAT_SEL && read_i;
+
+ assign CMD_SEL = (wb_ps2_addr == `PS2_CMD_REG);
+ assign CMD_wr = CMD_SEL && write_i;
+ assign CMD_rdc = CMD_wr && (dat_i == `PS2_CNT_RD); // Request to read control info
+ assign CMD_wrc = CMD_wr && (dat_i == `PS2_CNT_WR); // Request to write control info
+ assign CMD_mwr = CMD_wr && (dat_i == `PS2_CMD_D4); // Signal to transmit data to mouse
+ assign CMD_tst = CMD_wr && (dat_i == `PS2_CMD_AA); // User requested self test
+ assign CMD_mit = CMD_wr && (dat_i == `PS2_CMD_A9); // User mouse interface test
+
+ assign dat_o = d_dat_o; // Select register
+ assign d_dat_o = DAT_SEL ? r_dat_o : PS_STAT; // Select register
+ assign r_dat_o = cnt_r_flag ? PS_CNTL : t_dat_o; // return control or data
+ assign t_dat_o = cmd_r_test ? ps_tst_o : i_dat_o; // return control or data
+ assign i_dat_o = cmd_r_mint ? ps_mit_o : p_dat_o; // return control or data
+ assign p_dat_o = MSE_INT ? MSE_dat_o : KBD_dat_o; // defer to mouse
+ assign ps_tst_o = 8\'h55; // Controller self test
+ assign ps_mit_o = 8\'h00; // Controller self test
+ assign cmd_msnd = cmd_w_msnd && DAT_wr; // OK to write to mouse
+ assign IBF = MSE_INT || KBD_INT || cnt_r_flag || cmd_r_test || cmd_r_mint;
+ assign PS_READ = DAT_rd && !(cnt_r_flag || cmd_r_test || cmd_r_mint);
+ assign MSE_dat_i = dat_i; // Transmit register
+ assign MSE_SEND = cmd_msnd; // Signal to transmit data
+
+endmodule
+
+"
+"/*
+ * VGA CSR interface for SRAM
+ * Copyright (c) 2009 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module csr_sram (
+ input sys_clk,
+
+ // CSR slave interface
+ input [17:1] csr_adr_i,
+ input [ 1:0] csr_sel_i,
+ input csr_we_i,
+ input [15:0] csr_dat_i,
+ output reg [15:0] csr_dat_o,
+
+ // Pad signals
+ output [19:0] sram_addr_,
+ inout [15:0] sram_data_,
+ output reg sram_we_n_,
+ output reg sram_oe_n_,
+ output sram_ce_n_,
+ output reg [ 1:0] sram_bw_n_
+ );
+
+ // Registers and nets
+ reg [15:0] ww;
+ reg [16:0] sram_addr;
+
+ // Continuous assingments
+ assign sram_data_ = sram_we_n_ ? 16'hzzzz : ww;
+ assign sram_ce_n_ = 1'b0;
+ assign sram_addr_ = { 3'b0, sram_addr };
+
+ // Behaviour
+ // ww
+ always @(posedge sys_clk) ww <= csr_dat_i;
+
+ // sram_addr
+ always @(posedge sys_clk) sram_addr <= csr_adr_i;
+
+ // sram_we_n_
+ always @(posedge sys_clk) sram_we_n_ <= !csr_we_i;
+
+ // sram_bw_n_
+ always @(posedge sys_clk) sram_bw_n_ <= ~csr_sel_i;
+
+ // sram_oe_n_
+ always @(posedge sys_clk) sram_oe_n_ <= csr_we_i;
+
+ // csr_dat_o
+ always @(posedge sys_clk) csr_dat_o <= sram_data_;
+endmodule
+"
+"/*
+ * PS2 Wishbone 8042 compatible keyboard controller
+ * Copyright (c) 2009 Zeus Gomez Marmolejo
+ * adapted from the opencores keyboard controller from John Clayton
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+// altera message_off 10030
+// get rid of the warning about
+// not initializing the ROM
+
+module ps2_keyb_xtcodes (
+ // input clk,
+ input [6:0] at_code,
+ output [6:0] xt_code
+ );
+
+ // Registers, nets and parameters
+ reg [7:0] rom[0:2**7-1];
+
+ assign xt_code = rom[at_code][6:0];
+
+ // Behaviour
+/*
+ always @(posedge clk)
+ xt_code <= rom[at_code][6:0];
+*/
+ initial $readmemh(""xt_codes.dat"", rom);
+endmodule
+"
+"/*
+ * Planar mode graphics for VGA
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module vga_planar (
+ input clk,
+ input rst,
+
+ // CSR slave interface for reading
+ output [17:1] csr_adr_o,
+ input [15:0] csr_dat_i,
+ output csr_stb_o,
+
+ // Controller registers
+ input [3:0] attr_plane_enable,
+ input x_dotclockdiv2,
+
+ input [9:0] h_count,
+ input [9:0] v_count,
+ input horiz_sync_i,
+ input video_on_h_i,
+ output video_on_h_o,
+
+ output reg [3:0] attr,
+ output horiz_sync_o
+ );
+
+ // Registers and net
+ reg [11:0] row_addr;
+ reg [ 5:0] col_addr;
+ reg [14:0] word_offset;
+ reg [ 1:0] plane_addr0;
+ reg [ 1:0] plane_addr;
+ reg [15:0] plane0;
+ reg [15:0] plane0_tmp;
+ reg [15:0] plane1;
+ reg [15:0] plane1_tmp;
+ reg [15:0] plane2;
+ reg [15:0] plane2_tmp;
+ reg [15:0] plane3;
+ reg [ 7:0] bit_mask0;
+ reg [ 7:0] bit_mask1;
+
+ wire [15:0] bit_mask;
+ wire v_count0;
+
+ wire bit3, bit2, bit1, bit0;
+
+ reg [9:0] video_on_h;
+ reg [9:0] horiz_sync;
+ reg [7:0] pipe;
+
+ // Continous assignments
+ assign csr_adr_o = { word_offset, plane_addr };
+ assign bit_mask = { bit_mask1, bit_mask0 };
+
+ assign bit0 = |(bit_mask & plane0);
+ assign bit1 = |(bit_mask & plane1);
+ assign bit2 = |(bit_mask & plane2);
+ assign bit3 = |(bit_mask & plane3);
+
+ assign video_on_h_o = video_on_h[9];
+ assign horiz_sync_o = horiz_sync[9];
+ assign csr_stb_o = |pipe[4:1];
+ assign v_count0 = x_dotclockdiv2 ? 1'b0 : v_count[0];
+
+ // Behaviour
+ // Pipeline count
+ always @(posedge clk)
+ pipe <= rst ? 8'b0 : { pipe[6:0],
+ x_dotclockdiv2 ? (h_count[4:0]==5'h0) : (h_count[3:0]==4'h0) };
+
+ // video_on_h
+ always @(posedge clk)
+ video_on_h <= rst ? 10'b0 : { video_on_h[8:0], video_on_h_i };
+
+ // horiz_sync
+ always @(posedge clk)
+ horiz_sync <= rst ? 10'b0 : { horiz_sync[8:0], horiz_sync_i };
+
+ // Address generation
+ always @(posedge clk)
+ if (rst)
+ begin
+ row_addr <= 12'h0;
+ col_addr <= 6'h0;
+ plane_addr0 <= 2'b00;
+ word_offset <= 15'h0;
+ plane_addr <= 2'b00;
+ end
+ else
+ begin
+ // Loading new row_addr and col_addr when h_count[3:0]==4'h0
+ // v_count * 40 or 22 (depending on x_dotclockdiv2)
+ row_addr <= { v_count[9:1], v_count0, 2'b00 } + { v_count[9:1], v_count0 }
+ + (x_dotclockdiv2 ? v_count[9:1] : 9'h0);
+ col_addr <= x_dotclockdiv2 ? h_count[9:5] : h_count[9:4];
+ plane_addr0 <= h_count[1:0];
+
+ // Load new word_offset at +1
+ word_offset <= (x_dotclockdiv2 ? { row_addr, 1'b0 }
+ : { row_addr, 3'b000 }) + col_addr;
+ plane_addr <= plane_addr0;
+ end
+
+ // Temporary plane data
+ always @(posedge clk)
+ if (rst)
+ begin
+ plane0_tmp <= 16'h0;
+ plane1_tmp <= 16'h0;
+ plane2_tmp <= 16'h0;
+ end
+ else
+ begin
+ // Load plane0 when pipe == 4
+ plane0_tmp <= pipe[4] ? csr_dat_i : plane0_tmp;
+ plane1_tmp <= pipe[5] ? csr_dat_i : plane1_tmp;
+ plane2_tmp <= pipe[6] ? csr_dat_i : plane2_tmp;
+ end
+
+ // Plane data
+ always @(posedge clk)
+ if (rst)
+ begin
+ plane0 <= 16'h0;
+ plane1 <= 16'h0;
+ plane2 <= 16'h0;
+ plane3 <= 16'h0;
+ end
+ else
+ begin
+ plane0 <= pipe[7] ? plane0_tmp : plane0;
+ plane1 <= pipe[7] ? plane1_tmp : plane1;
+ plane2 <= pipe[7] ? plane2_tmp : plane2;
+ plane3 <= pipe[7] ? csr_dat_i : plane3;
+ end
+
+ // Bit masks
+ always @(posedge clk)
+ if (rst)
+ begin
+ bit_mask0 <= 8'h0;
+ bit_mask1 <= 8'h0;
+ end
+ else
+ begin
+ bit_mask0 <= (h_count[0] & x_dotclockdiv2) ? bit_mask0
+ : { pipe[7], bit_mask0[7:1] };
+ bit_mask1 <= (h_count[0] & x_dotclockdiv2) ? bit_mask1
+ : { bit_mask0[0], bit_mask1[7:1] };
+ end
+
+ // attr
+ always @(posedge clk)
+ attr <= rst ? 4'h0 : (attr_plane_enable & { bit3, bit2, bit1, bit0 });
+
+endmodule
+"
+"/*
+ * Milkymist VJ SoC
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+module tb_csrbrg();
+
+reg sys_clk;
+reg sys_rst;
+
+reg [31:0] wb_adr_i;
+reg [31:0] wb_dat_i;
+wire [31:0] wb_dat_o;
+reg wb_cyc_i;
+reg wb_stb_i;
+reg wb_we_i;
+wire wb_ack_o;
+
+wire [13:0] csr_a;
+wire csr_we;
+wire [31:0] csr_do;
+reg [31:0] csr_di;
+
+/* 100MHz system clock */
+initial sys_clk = 1\'b0;
+always #5 sys_clk = ~sys_clk;
+
+csrbrg dut(
+\t.sys_clk(sys_clk),
+\t.sys_rst(sys_rst),
+\t
+\t.wb_adr_i(wb_adr_i),
+\t.wb_dat_i(wb_dat_i),
+\t.wb_dat_o(wb_dat_o),
+\t.wb_cyc_i(wb_cyc_i),
+\t.wb_stb_i(wb_stb_i),
+\t.wb_we_i(wb_we_i),
+\t.wb_ack_o(wb_ack_o),
+\t
+\t/* CSR bus master */
+\t.csr_a(csr_a),
+\t.csr_we(csr_we),
+\t.csr_do(csr_do),
+\t.csr_di(csr_di)
+);
+
+task waitclock;
+begin
+\t@(posedge sys_clk);
+\t#1;
+end
+endtask
+
+task wbwrite;
+input [31:0] address;
+input [31:0] data;
+integer i;
+begin
+\twb_adr_i = address;
+\twb_dat_i = data;
+\twb_cyc_i = 1\'b1;
+\twb_stb_i = 1\'b1;
+\twb_we_i = 1\'b1;
+\ti = 0;
+\twhile(~wb_ack_o) begin
+\t\ti = i+1;
+\t\twaitclock;
+\tend
+\twaitclock;
+\t$display(""WB Write: %x=%x acked in %d clocks"", address, data, i);
+\twb_cyc_i = 1\'b0;
+\twb_stb_i = 1\'b0;
+\twb_we_i = 1\'b0;
+end
+endtask
+
+task wbread;
+input [31:0] address;
+integer i;
+begin
+\twb_adr_i = address;
+\twb_cyc_i = 1\'b1;
+\twb_stb_i = 1\'b1;
+\twb_we_i = 1\'b0;
+\ti = 0;
+\twhile(~wb_ack_o) begin
+\t\ti = i+1;
+\t\twaitclock;
+\tend
+\t$display(""WB Read : %x=%x acked in %d clocks"", address, wb_dat_o, i);
+\twaitclock;
+\twb_cyc_i = 1\'b0;
+\twb_stb_i = 1\'b0;
+\twb_we_i = 1\'b0;
+end
+endtask
+
+
+/* Simulate CSR slave */
+reg [31:0] csr1;
+reg [31:0] csr2;
+wire csr_selected = (csr_a[13:10] == 4\'ha);
+always @(posedge sys_clk) begin
+\tif(csr_selected) begin
+\t\tif(csr_we) begin
+\t\t\t$display(""Writing %x to CSR %x"", csr_do, csr_a[0]);
+\t\t\tcase(csr_a[0])
+\t\t\t\t1\'b0: csr1 <= csr_do;
+\t\t\t\t1\'b1: csr2 <= csr_do;
+\t\t\tendcase
+\t\tend
+\t\tcase(csr_a[0])
+\t\t\t1\'b0: csr_di <= csr1;
+\t\t\t1\'b1: csr_di <= csr2;
+\t\tendcase
+\tend else
+\t\t/* we must set data to 0 to be able to use a distributed OR topology
+\t\t * in the slaves->master datapath.
+\t\t */
+\t\tcsr_di <= 32\'d0;
+end
+
+always begin
+\t/* Reset / Initialize our logic */
+\tsys_rst = 1\'b1;
+\t
+\twb_adr_i = 32\'d0;
+\twb_dat_i = 32\'d0;
+\twb_cyc_i = 1\'b0;
+\twb_stb_i = 1\'b0;
+\twb_we_i = 1\'b0;
+\t
+\twaitclock;
+\t
+\tsys_rst = 1\'b0;
+\t
+\twaitclock;
+\t
+\t/* Try some transfers */
+\twbwrite(32\'h0000a000, 32\'hcafebabe);
+\twbwrite(32\'h0000a004, 32\'habadface);
+\twbread(32\'h0000a000);
+\twbread(32\'h0000a004);
+\t
+\t$finish;
+end
+
+endmodule
+"
+"/*
+ * Wishbone asynchronous bridge with TGA and WE regslice
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module wb_abrgr (
+ input sys_rst,
+
+ // Wishbone slave interface
+ input wbs_clk_i,
+ input [19:1] wbs_adr_i,
+ input [15:0] wbs_dat_i,
+ output reg [15:0] wbs_dat_o,
+ input [ 1:0] wbs_sel_i,
+ input wbs_tga_i,
+ input wbs_stb_i,
+ input wbs_cyc_i,
+ input wbs_we_i,
+ output wbs_ack_o,
+
+ // Wishbone master interface
+ input wbm_clk_i,
+ output reg [19:1] wbm_adr_o,
+ output reg [15:0] wbm_dat_o,
+ input [15:0] wbm_dat_i,
+ output reg [ 1:0] wbm_sel_o,
+ output reg wbm_tga_o,
+ output wbm_stb_o,
+ output wbm_cyc_o,
+ output reg wbm_we_o,
+ input wbm_ack_i
+ );
+
+ // Registers and nets
+ wire wbs_stb;
+ wire init_tr;
+ reg wbm_stb;
+ reg [2:0] sync_stb;
+ reg [2:0] sync_ack;
+ reg ft_stb;
+ reg ft_ack;
+ reg stb_r;
+ reg ack_r;
+
+ reg [19:1] wbm_adr_o_r;
+ reg [15:0] wbm_dat_o_r;
+ reg [ 1:0] wbm_sel_o_r;
+ reg wbs_tga_i_r;
+ reg wbm_tga_o_r;
+ reg wbs_we_i_r;
+ reg wbm_we_o_r;
+ reg [15:0] wbs_dat_o_r;
+ reg [15:0] wbm_dat_i_r;
+
+ // Continous assignments
+ assign wbs_stb = wbs_stb_i & wbs_cyc_i;
+
+ // recreate the flag from the level change
+ assign wbs_ack_o = (sync_ack[2] ^ sync_ack[1]);
+ assign wbm_stb_o = wbm_stb;
+ assign wbm_cyc_o = wbm_stb;
+
+ /*
+ * A new wishbone transaction is issued:
+ * . by changing stb from 0 to 1
+ * . by continue asserting stb after ack is received
+ */
+ assign init_tr = ~stb_r & wbs_stb | ack_r & ~wbs_ack_o & wbs_stb;
+
+ // Behaviour
+ // wbm_stb
+ always @(posedge wbm_clk_i)
+ wbm_stb <= sys_rst ? 1'b0
+ : (wbm_stb ? ~wbm_ack_i : sync_stb[2] ^ sync_stb[1]);
+
+ // old stb and ack state
+ always @(posedge wbs_clk_i) stb_r <= wbs_stb;
+ always @(posedge wbs_clk_i) ack_r <= wbs_ack_o;
+
+ always @(posedge wbs_clk_i)
+ ft_stb <= sys_rst ? 1'b0 : (init_tr ? ~ft_stb : ft_stb);
+
+ // synchronize the last level change
+ always @(posedge wbm_clk_i)
+ sync_stb <= sys_rst ? 3'h0 : {sync_stb[1:0], ft_stb};
+
+ // this changes level when a flag is seen
+ always @(posedge wbm_clk_i)
+ ft_ack <= sys_rst ? 1'b0 : (wbm_ack_i ? ~ft_ack : ft_ack);
+
+ // which can then be synched to wbs_clk_i
+ always @(posedge wbs_clk_i)
+ sync_ack <= sys_rst ? 3'h0 : {sync_ack[1:0], ft_ack};
+
+ // rest of the wishbone signals
+ always @(posedge wbm_clk_i)
+ {wbm_adr_o, wbm_adr_o_r} <= {wbm_adr_o_r, wbs_adr_i};
+
+ always @(posedge wbm_clk_i)
+ {wbm_dat_o, wbm_dat_o_r} <= {wbm_dat_o_r, wbs_dat_i};
+
+ always @(posedge wbm_clk_i)
+ {wbm_sel_o, wbm_sel_o_r} <= {wbm_sel_o_r, wbs_sel_i};
+
+ always @(posedge wbs_clk_i) wbs_we_i_r <= wbs_we_i;
+ always @(posedge wbm_clk_i)
+ {wbm_we_o, wbm_we_o_r} <= {wbm_we_o_r, wbs_we_i_r};
+
+ always @(posedge wbs_clk_i) wbs_tga_i_r <= wbs_tga_i;
+ always @(posedge wbm_clk_i)
+ {wbm_tga_o, wbm_tga_o_r} <= {wbm_tga_o_r, wbs_tga_i_r};
+
+ /*
+ * Register input coming from the slave as that can change
+ * after the ack is received
+ */
+ always @(posedge wbm_clk_i)
+ wbm_dat_i_r <= wbm_ack_i ? wbm_dat_i : wbm_dat_i_r;
+
+ always @(posedge wbs_clk_i)
+ {wbs_dat_o, wbs_dat_o_r} <= {wbs_dat_o_r, wbm_dat_i_r};
+
+endmodule
+"
+"/*
+ * PS2 Mouse Interface
+ * Copyright (C) 2010 Donna Polehn
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module ps2_mouse (
+ input clk, // Clock Input
+ input reset, // Reset Input
+ inout ps2_clk, // PS2 Clock, Bidirectional
+ inout ps2_dat, // PS2 Data, Bidirectional
+ input inhibit,
+
+ input [7:0] the_command, // Command to send to mouse
+ input send_command, // Signal to send
+ output command_was_sent, // Signal command finished sending
+ output error_communication_timed_out,
+
+ output [7:0] received_data, // Received data
+ output received_data_en, // If 1 - new data has been received
+ output start_receiving_data,
+ output wait_for_incoming_data
+ );
+
+ // --------------------------------------------------------------------
+ // Internal wires and registers Declarations
+ // --------------------------------------------------------------------
+ wire ps2_clk_posedge; // Internal Wires
+ wire ps2_clk_negedge;
+
+ reg [7:0] idle_counter; // Internal Registers
+ reg ps2_clk_reg;
+ reg ps2_data_reg;
+ reg last_ps2_clk;
+
+ reg [2:0] ns_ps2_transceiver; // State Machine Registers
+ reg [2:0] s_ps2_transceiver;
+
+ // --------------------------------------------------------------------
+ // Constant Declarations
+ // --------------------------------------------------------------------
+ localparam PS2_STATE_0_IDLE = 3'h0, // states
+ PS2_STATE_1_DATA_IN = 3'h1,
+ PS2_STATE_2_COMMAND_OUT = 3'h2,
+ PS2_STATE_3_END_TRANSFER = 3'h3,
+ PS2_STATE_4_END_DELAYED = 3'h4;
+
+ // --------------------------------------------------------------------
+ // Finite State Machine(s)
+ // --------------------------------------------------------------------
+ always @(posedge clk) begin
+ if(reset == 1'b1) s_ps2_transceiver <= PS2_STATE_0_IDLE;
+ else s_ps2_transceiver <= ns_ps2_transceiver;
+ end
+
+ always @(*) begin
+ ns_ps2_transceiver = PS2_STATE_0_IDLE; // Defaults
+
+ case (s_ps2_transceiver)
+ PS2_STATE_0_IDLE:
+ begin
+ if((idle_counter == 8'hFF) && (send_command == 1'b1))
+ ns_ps2_transceiver = PS2_STATE_2_COMMAND_OUT;
+ else if ((ps2_data_reg == 1'b0) && (ps2_clk_posedge == 1'b1))
+ ns_ps2_transceiver = PS2_STATE_1_DATA_IN;
+ else ns_ps2_transceiver = PS2_STATE_0_IDLE;
+ end
+ PS2_STATE_1_DATA_IN:
+ begin
+ // if((received_data_en == 1'b1) && (ps2_clk_posedge == 1'b1))
+ if((received_data_en == 1'b1)) ns_ps2_transceiver = PS2_STATE_0_IDLE;
+ else ns_ps2_transceiver = PS2_STATE_1_DATA_IN;
+ end
+ PS2_STATE_2_COMMAND_OUT:
+ begin
+ if((command_was_sent == 1'b1) || (error_communication_timed_out == 1'b1))
+ ns_ps2_transceiver = PS2_STATE_3_END_TRANSFER;
+ else ns_ps2_transceiver = PS2_STATE_2_COMMAND_OUT;
+ end
+ PS2_STATE_3_END_TRANSFER:
+ begin
+ if(send_command == 1'b0) ns_ps2_transceiver = PS2_STATE_0_IDLE;
+ else if((ps2_data_reg == 1'b0) && (ps2_clk_posedge == 1'b1))
+ ns_ps2_transceiver = PS2_STATE_4_END_DELAYED;
+ else ns_ps2_transceiver = PS2_STATE_3_END_TRANSFER;
+ end
+ PS2_STATE_4_END_DELAYED:
+ begin
+ if(received_data_en == 1'b1) begin
+ if(send_command == 1'b0) ns_ps2_transceiver = PS2_STATE_0_IDLE;
+ else ns_ps2_transceiver = PS2_STATE_3_END_TRANSFER;
+ end
+ else ns_ps2_transceiver = PS2_STATE_4_END_DELAYED;
+ end
+
+ default:
+ ns_ps2_transceiver = PS2_STATE_0_IDLE;
+ endcase
+ end
+
+ // --------------------------------------------------------------------
+ // Sequential logic
+ // --------------------------------------------------------------------
+ always @(posedge clk) begin
+ if(reset == 1'b1) begin
+ last_ps2_clk <= 1'b1;
+ ps2_clk_reg <= 1'b1;
+ ps2_data_reg <= 1'b1;
+ end
+ else begin
+ last_ps2_clk <= ps2_clk_reg;
+ ps2_clk_reg <= ps2_clk;
+ ps2_data_reg <= ps2_dat;
+ end
+ end
+
+ always @(posedge clk) begin
+ if(reset == 1'b1) idle_counter <= 6'h00;
+ else if((s_ps2_transceiver == PS2_STATE_0_IDLE) && (idle_counter != 8'hFF))
+ idle_counter <= idle_counter + 6'h01;
+ else if (s_ps2_transceiver != PS2_STATE_0_IDLE)
+ idle_counter <= 6'h00;
+ end
+
+ // --------------------------------------------------------------------
+ // Combinational logic
+ // --------------------------------------------------------------------
+ assign ps2_clk_posedge = ((ps2_clk_reg == 1'b1) && (last_ps2_clk == 1'b0)) ? 1'b1 : 1'b0;
+ assign ps2_clk_negedge = ((ps2_clk_reg == 1'b0) && (last_ps2_clk == 1'b1)) ? 1'b1 : 1'b0;
+
+ assign start_receiving_data = (s_ps2_transceiver == PS2_STATE_1_DATA_IN);
+ assign wait_for_incoming_data = (s_ps2_transceiver == PS2_STATE_3_END_TRANSFER);
+
+ // --------------------------------------------------------------------
+ // Internal Modules
+ // --------------------------------------------------------------------
+ ps2_mouse_cmdout mouse_cmdout (
+ .clk (clk), // Inputs
+ .reset (reset),
+ .the_command (the_command),
+ .send_command (send_command),
+ .inhibit (inhibit),
+ .ps2_clk_posedge (ps2_clk_posedge),
+ .ps2_clk_negedge (ps2_clk_negedge),
+ .ps2_clk (ps2_clk), // Bidirectionals
+ .ps2_dat (ps2_dat),
+ .command_was_sent (command_was_sent), // Outputs
+ .error_communication_timed_out (error_communication_timed_out)
+ );
+
+ ps2_mouse_datain mouse_datain (
+ .clk (clk), // Inputs
+ .reset (reset),
+ .wait_for_incoming_data (wait_for_incoming_data),
+ .start_receiving_data (start_receiving_data),
+ .ps2_clk_posedge (ps2_clk_posedge),
+ .ps2_clk_negedge (ps2_clk_negedge),
+ .ps2_data (ps2_data_reg),
+ .received_data (received_data), // Outputs
+ .received_data_en (received_data_en)
+ );
+
+endmodule
+
+"
+"/*
+ * Altera Quartus II multiplier inference module
+ * Copyright (C) 2008-2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module zet_signmul17 (
+ input clk,
+
+ input signed [16:0] a,
+ input signed [16:0] b,
+ output reg signed [33:0] p
+ );
+
+ // Behaviour
+ always @(posedge clk) p <= a * b;
+endmodule
+"
+"/*
+ * Phase accumulator clock generator:
+ * Output Frequency Fo = Fc * N / 2^bits
+ * Output Jitter = 1/Fc
+ *
+ * Copyright (c) 2009,2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+module clk_gen #(
+ parameter res = 20, // bits - bit resolution
+ parameter phase = 1 // N - phase value for the counter
+ )(
+ input clk_i, // Fc - input frequency
+ input rst_i,
+ output clk_o // Fo - output frequency
+ );
+
+ // Registers and nets
+ reg [res-1:0] cnt;
+
+ // Continuous assignments
+ assign clk_o = cnt[res-1];
+
+ // Behaviour
+ always @(posedge clk_i)
+ cnt <= rst_i ? {res{1'b0}} : (cnt + phase);
+
+endmodule
+"
+"/*
+ * Character ROM for text mode fonts
+ * Copyright (C) 2010 Zeus Gomez Marmolejo
+ *
+ * This file is part of the Zet processor. This processor is free
+ * hardware; you can redistribute it and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Zet; see the file COPYING. If not, see
+ * .
+ */
+
+// altera message_off 10030
+// get rid of the warning about
+// not initializing the ROM
+module vdu_char_rom (
+ input clk,
+ input [11:0] addr,
+ output reg [ 7:0] q
+ );
+
+ // Registers, nets and parameters
+ reg [7:0] rom[0:4095];
+
+ // Behaviour
+ always @(posedge clk) q <= rom[addr];
+
+ initial $readmemh(""char_rom.dat"", rom);
+endmodule
+"
+"/*\r
+ * DAC register file for VGA\r
+ * Copyright (C) 2010 Zeus Gomez Marmolejo \r
+ *\r
+ * VGA FML support\r
+ * Copyright (C) 2013 Charley Picker \r
+ *\r
+ * This file is part of the Zet processor. This processor is free\r
+ * hardware; you can redistribute it and/or modify it under the terms of\r
+ * the GNU General Public License as published by the Free Software\r
+ * Foundation; either version 3, or (at your option) any later version.\r
+ *\r
+ * Zet is distrubuted in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r
+ * License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Zet; see the file COPYING. If not, see\r
+ * .\r
+ */\r
+\r
+module vga_dac_regs_fml (\r
+ input clk,\r
+\r
+ // VGA read interface\r
+ input [7:0] index,\r
+ output reg [3:0] red,\r
+ output reg [3:0] green,\r
+ output reg [3:0] blue,\r
+\r
+ // CPU interface\r
+ input write,\r
+\r
+ // CPU read interface\r
+ input [1:0] read_data_cycle,\r
+ input [7:0] read_data_register,\r
+ output reg [3:0] read_data,\r
+\r
+ // CPU write interface\r
+ input [1:0] write_data_cycle,\r
+ input [7:0] write_data_register,\r
+ input [3:0] write_data\r
+ );\r
+\r
+ // Registers, nets and parameters\r
+ reg [3:0] red_dac [0:255];\r
+ reg [3:0] green_dac [0:255];\r
+ reg [3:0] blue_dac [0:255];\r
+\r
+ // Behaviour\r
+ // VGA read interface\r
+ always @(posedge clk)\r
+ begin\r
+ red <= red_dac[index];\r
+ green <= green_dac[index];\r
+ blue <= blue_dac[index];\r
+ end\r
+\r
+ // CPU read interface\r
+ always @(posedge clk)\r
+ case (read_data_cycle)\r
+ 2'b00: read_data <= red_dac[read_data_register];\r
+ 2'b01: read_data <= green_dac[read_data_register];\r
+ 2'b10: read_data <= blue_dac[read_data_register];\r
+ default: read_data <= 4'h0;\r
+ endcase\r
+\r
+ // CPU write interface\r
+ always @(posedge clk)\r
+ if (write)\r
+ case (write_data_cycle)\r
+ 2'b00: red_dac[write_data_register] <= write_data;\r
+ 2'b01: green_dac[write_data_register] <= write_data;\r
+ 2'b10: blue_dac[write_data_register] <= write_data;\r
+ endcase\r
+\r
+endmodule\r
+"
+"module subtractor_csel(a, b, diff_out, carry_out);
+\tinput [31:0] a, b;
+\toutput [31:0] diff_out;
+\toutput carry_out;
+\twire [31:0] not_b, diff_out;
+\twire carry_out;
+\t
+\tbitwise_not\t\tnegate_b(b, not_b);
+\tadder_csel\t\tsubtraction(a, not_b, 1, diff_out, carry_out);
+\t
+endmodule //end 32-bit subtraction
+
+module adder_csel(a, b, carry_in, sum_out, carry_out);
+\tinput [31:0] a, b;
+\tinput carry_in;
+\toutput [31:0] sum_out;
+\toutput carry_out;
+\twire [31:0] temp_out_0, temp_out_1, sum_out;
+\twire [21:0] carries;
+\twire carry_out;
+\t
+\tripple_carry_adder\t\trca_0(a[3:0], b[3:0], carry_in, sum_out[3:0], carries[0]);
+
+\tgenvar i, j;
+\tgenerate
+\t\tfor (i=1; i<8; i=i+1) begin: carry_select_block_loop
+\t\t\tripple_carry_adder\t\trca_1(a[((4*i)+3):(4*i)], b[((4*i)+3):(4*i)], 0, temp_out_0[((4*i)+3):(4*i)], carries[(3*i)-2]);
+\t\t\tripple_carry_adder\t\trca_2(a[((4*i)+3):(4*i)], b[((4*i)+3):(4*i)], 1, temp_out_1[((4*i)+3):(4*i)], carries[(3*i)-1]);
+\t\t\t
+\t\t\tfor (j=(4*i); j<((4*i)+4); j=j+1) begin: sum_mux_loop
+\t\t\t\tmux2_1\t\tsum_mux(temp_out_0[j], temp_out_1[j], carries[(3*i)-3], sum_out[j]);
+\t\t\tend
+\t\t\t
+\t\t\tmux2_1\t\tcarry_mux(carries[(3*i)-2], carries[(3*i)-1], carries[(3*i)-3], carries[(3*i)]);
+\t\tend
+\tendgenerate
+\t
+\tassign carry_out = carries[21];
+\t
+endmodule //end 32-bit carry select adder
+
+module ripple_carry_adder(a, b, c_in, s, c_out);
+\tinput [3:0] a, b;
+\tinput c_in;
+\toutput [3:0] s;
+\toutput c_out;
+\twire [4:0] carries;
+\twire [3:0] s;
+\twire c_out;
+\t
+\tassign carries[0] = c_in;
+\t\t
+\tgenvar i;
+ \tgenerate
+\t\tfor (i=0; i<4; i=i+1) begin: rca_loop_1
+\t\t\tfull_adder\t\trcadder(a[i], b[i], carries[i], s[i], carries[i+1]);
+\t\tend
+\tendgenerate
+
+\tassign c_out = carries[4];
+\t
+endmodule //end 4-bit ripple carry adder
+
+module full_adder(a, b, c_in, s, c_out);
+\tinput a, b, c_in;
+\toutput s, c_out;
+\twire [2:0] inter_out;
+\twire s, c_out;
+\t
+\txor(inter_out[0], a, b);
+\tand(inter_out[1], a, b);
+\tand(inter_out[2], inter_out[0], c_in);
+\txor(s, inter_out[0], c_in);
+\tor(c_out, inter_out[1], inter_out[2]);
+
+endmodule //end 1-bit full adder
+
+module mux2_1(a, b, select, out);
+\tinput a, b, select;
+\toutput out;
+\twire not_select, out;
+\twire [1:0] inter_out;
+\t
+\tnot(not_select, select);
+\tand(inter_out[0], not_select, a);
+\tand(inter_out[1], select, b);
+\tor(out, inter_out[0], inter_out[1]);
+\t
+endmodule //end 2:1 mux
+
+//end adder + supporting modules
+
+module arithmetic_right_shift(a, shift, lsb, out);
+\tinput [31:0] a;
+\tinput [4:0] shift;
+\tinput lsb;
+\toutput [31:0] out;
+\twire [31:0] out, pre_shift, post_shift;
+\t
+\tbit_reversal\t\t\treverse_0(a, pre_shift);
+\tlogical_left_shift\t\tshifter(pre_shift, shift, lsb, post_shift);
+\tbit_reversal\t\t\treverse_1(post_shift, out);
+\t
+endmodule //end 32-bit arithmetic right shift
+\t
+module bit_reversal(a, out);
+\tinput [31:0] a;
+\toutput [31:0] out;
+\twire [31:0] out, temp;
+\t
+\tassign temp = a;
+\tgenvar i;
+\tgenerate
+\t\tfor(i=0; i<32; i=i+1) begin: reversal_loop
+\t\t\tassign out[i] = temp[31-i];
+\t\tend
+\tendgenerate
+\t
+endmodule //end 32-bit input bit reverser
+
+module logical_left_shift(a, shift, lsb, out);
+\tinput [31:0] a;
+\tinput [4:0] shift;
+\tinput lsb;
+\toutput [31:0] out;
+\twire [31:0] out;
+\twire [31:0] mux_wire [4:0];
+\twire [31:0] shift_wire [4:0];
+\t
+\tsll_16\t\ts16(a, lsb, shift_wire[4]);
+\ttsb_mux \tm16(a, shift_wire[4], shift[4], mux_wire[4]);
+\t
+\tsll_8 \t\ts8(mux_wire[4], lsb, shift_wire[3]);
+\ttsb_mux \tm8(mux_wire[4], shift_wire[3], shift[3], mux_wire[3]);
+\t
+\tsll_4 \t\ts4(mux_wire[3], lsb, shift_wire[2]);
+\ttsb_mux \tm4(mux_wire[3], shift_wire[2], shift[2], mux_wire[2]);
+\t
+\tsll_2 \t\ts2(mux_wire[2], lsb, shift_wire[1]);
+\ttsb_mux \tm2(mux_wire[2], shift_wire[1], shift[1], mux_wire[1]);
+\t
+\tsll_1 \t\ts1(mux_wire[1], lsb, shift_wire[0]);
+\ttsb_mux \tm1(mux_wire[1], shift_wire[0], shift[0], mux_wire[0]);
+\t
+\tassign out = mux_wire[0];
+
+endmodule //end 32-bit logical left barrel shifter
+
+module sll_16(a, lsb, out);
+\tinput [31:0] a;
+\tinput lsb;
+\toutput[31:0] out;
+\twire [31:0] out;
+\t
+\tgenvar i;
+\tgenerate
+\t\tfor(i=16; i<32; i=i+1) begin: shift_sixteen_loop
+\t\t\tassign out[i] = a[i-16];
+\t\tend
+\tendgenerate
+\t
+\tgenvar j;
+\tgenerate
+\t\tfor(j=0; j<16; j=j+1) begin: shift_sixteen_sub_loop
+\t\t\tassign out[j] = lsb;
+\t\tend
+\tendgenerate
+
+endmodule //end 16-bit logical left shift
+
+module sll_8(a, lsb, out);
+\tinput [31:0] a;
+\tinput lsb;
+\toutput[31:0] out;
+\twire [31:0] out;
+\t
+\tgenvar i;
+\tgenerate
+\t\tfor(i=8; i<32; i=i+1) begin: shift_eight_loop
+\t\t\tassign out[i] = a[i-8];
+\t\tend
+\tendgenerate
+\t
+\tgenvar j;
+\tgenerate
+\t\tfor(j=0; j<8; j=j+1) begin: shift_eight_sub_loop
+\t\t\tassign out[j] = lsb;
+\t\tend
+\tendgenerate
+
+endmodule //end 8-bit logical left shift
+
+module sll_4(a, lsb, out);
+\tinput [31:0] a;
+\tinput lsb;
+\toutput[31:0] out;
+\twire [31:0] out;
+\t
+\tgenvar i;
+\tgenerate
+\t\tfor(i=4; i<32; i=i+1) begin: shift_four_loop
+\t\t\tassign out[i] = a[i-4];
+\t\tend
+\tendgenerate
+\t
+\tassign out[0] = lsb;
+\tassign out[1] = lsb;
+\tassign out[2] = lsb;
+\tassign out[3] = lsb;
+
+endmodule //end 4-bit logical left shift
+
+module sll_2(a, lsb, out);
+\tinput [31:0] a;
+\tinput lsb;
+\toutput[31:0] out;
+\twire [31:0] out;
+\t
+\tgenvar i;
+\tgenerate
+\t\tfor(i=2; i<32; i=i+1) begin: shift_two_loop
+\t\t\tassign out[i] = a[i-2];
+\t\tend
+\tendgenerate
+\t
+\tassign out[0] = lsb;
+\tassign out[1] = lsb;
+
+endmodule //end 2-bit logical left shift
+
+module sll_1(a, lsb, out);
+\tinput [31:0] a;
+\tinput lsb;
+\toutput [31:0] out;
+\twire [31:0] out;
+\t
+\tgenvar i;
+\tgenerate
+\t\tfor(i=1; i<32; i=i+1) begin: shift_one_loop
+\t\t\tassign out[i] = a[i-1];
+\t\tend
+\tendgenerate
+\t
+\tassign out[0] = lsb;
+
+endmodule //end 1-bit logical left shift
+\t
+module tsb_mux(a, b, select, out);
+\tinput [31:0] a, b;
+\tinput select;
+\toutput [31:0] out;
+\twire not_select;
+\t
+\tnot(not_select, select);
+\ttsb \tbuffer_a(a, not_select, out);
+\ttsb \tbuffer_b(b, select, out);
+\t
+endmodule //end mux based on tri-state buffers
+\t
+module tsb(in, enable, out);
+\tinput [31:0] in;
+\tinput enable;
+\toutput [31:0] out;
+\twire [31:0] in, out;
+\twire enable;
+\t
+\tassign out = (enable) ? in : 32'bz;
+\t
+endmodule //end 32-bit tri-state buffer
+
+//end barrel shifter + supporting modules
+
+module bitwise_and(a, b, out);
+\tinput [31:0] a, b;
+\toutput [31:0] out;
+\twire [31:0] out;
+\t
+\tgenvar i;
+\tgenerate
+\t\tfor(i=0; i<32; i=i+1) begin: and_loop
+\t\t\tand(out[i], a[i], b[i]);
+\t\tend
+\tendgenerate
+
+endmodule //end 32-bit bitwise AND
+
+module bitwise_or(a, b, out);
+\tinput [31:0] a, b;
+\toutput [31:0] out;
+\twire [31:0] out;
+\t
+\tgenvar i;
+\tgenerate
+\t\tfor(i=0; i<32; i=i+1) begin: or_loop
+\t\t\tor(out[i], a[i], b[i]);
+\t\tend
+\tendgenerate
+\t
+endmodule //end 32-bit bitwise OR
+
+module bitwise_not(in, out);
+\tinput [31:0] in;
+\toutput [31:0] out;
+\twire [31:0] out;
+\t
+\tgenvar i;
+\tgenerate
+\t\tfor(i=0; i<32; i=i+1) begin: not_loop
+\t\t\tassign out[i] = ~in[i];
+\t\tend
+\tendgenerate
+
+endmodule //end 32-bit bitwise NOT
+
+//end bitwise operators
+
+module equal_or_less(in, equal, less);
+ input [31:0] in;
+ output equal, less;
+ wire equal, less;
+
+ or(equal, in[31], in[30], in[29], in[28], in[27], in[26], in[25], in[24],
+\t\t\tin[23], in[22], in[21], in[20], in[19], in[18], in[17], in[16],
+\t\t\tin[15], in[14], in[13], in[12], in[11], in[10], in[9] , in[8] ,
+\t\t\tin[7] , in[6] , in[5] , in[4] , in[3] , in[2] , in[1] , in[0]);
+\t\t\t\t
+ assign less = in[31];
+
+endmodule //end shorthand comparator module
+
+module tsb_1bit(in, enable, out);
+\tinput in, enable;
+\toutput out;
+\twire in, enable, out;
+\t
+\tassign out = (enable) ? in : 1'bz;
+\t
+endmodule //end 1-bit tri-state buffer
+\t
+//end comparison modules
+
+module opcode_decoder(code_in, code_out);
+\tinput [4:0] code_in;
+\toutput [5:0] code_out;
+\twire [5:0] code_out;
+\t
+\tand(code_out[0], ~code_in[0], ~code_in[1], ~code_in[2], ~code_in[3], ~code_in[4]); //add
+\tand(code_out[1], code_in[0], ~code_in[1], ~code_in[2], ~code_in[3], ~code_in[4]); //subtract
+\tand(code_out[2], ~code_in[0], code_in[1], ~code_in[2], ~code_in[3], ~code_in[4]); //and
+\tand(code_out[3], code_in[0], code_in[1], ~code_in[2], ~code_in[3], ~code_in[4]); //or
+\tand(code_out[4], ~code_in[0], ~code_in[1], code_in[2], ~code_in[3], ~code_in[4]); //sll
+\tand(code_out[5], code_in[0], ~code_in[1], code_in[2], ~code_in[3], ~code_in[4]); //sra
+\t
+endmodule //end alu-opcode decoder
+
+module alu(data_operandA, data_operandB, ctrl_ALUopcode, ctrl_shiftamt, data_result, isNotEqual, isLessThan);
+ input [31:0] data_operandA, data_operandB;
+ input [4:0] ctrl_ALUopcode, ctrl_shiftamt;
+ output [31:0] data_result;
+ output isNotEqual, isLessThan;
+
+ wire [5:0] decoded_op;
+ wire csum_out, cdif_out;
+ wire [31:0] results [5:0];
+ wire equal, less;
+
+ opcode_decoder\t\t\t\t\talu_decoder(ctrl_ALUopcode, decoded_op);
+
+ adder_csel\t\t\t\t\t\talu_adder(data_operandA, data_operandB, 0, results[0], csum_out);
+ subtractor_csel\t\t\t\t\talu_subtract(data_operandA, data_operandB, results[1], cdif_out);
+ bitwise_and\t\t\t\t\t\talu_and(data_operandA, data_operandB, results[2]);
+ bitwise_or\t\t\t\t\t\talu_or(data_operandA, data_operandB, results[3]);
+ logical_left_shift\t\t\t\t\tleft_shift_l(data_operandA, ctrl_shiftamt, 0, results[4]);
+ arithmetic_right_shift\t\t\t\tright_shift_a(data_operandA, ctrl_shiftamt, data_operandA[31], results[5]);
+ equal_or_less\t\t\t\t\tquick_compare(results[1], equal, less);
+
+ tsb\t\t\tbuffer_add(results[0], decoded_op[0], data_result);
+ tsb\t\t\tbuffer_sub(results[1], decoded_op[1], data_result);
+ tsb\t\t\tbuffer_and(results[2], decoded_op[2], data_result);
+ tsb\t\t\tbuffer_or (results[3], decoded_op[3], data_result);
+ tsb\t\t\tbuffer_sll(results[4], decoded_op[4], data_result);
+ tsb\t\t\tbuffer_sra(results[5], decoded_op[5], data_result);
+ tsb_1bit\t\tbuffer_equal(equal, decoded_op[1], isNotEqual);
+ tsb_1bit\t\tbuffer_less (less , decoded_op[1], isLessThan);
+
+endmodule"
+"module tsb(in, enable, out);
+\tinput [31:0] in;
+\tinput enable;
+\toutput [31:0] out;
+\twire [31:0] in, out;
+\twire enable;
+\t
+\tassign out = (enable) ? in : 32'bz;
+\t
+endmodule //end tri-state buffer
+
+module dff_sr(in, enable, clock, reset, out);
+\tinput in, enable, clock, reset;
+\toutput out;
+\treg out;
+\t
+\talways @ (posedge clock or posedge reset) begin
+\t\tif (reset) begin
+\t\t\tout <= 1'b0;
+\t\tend
+\t\telse if (enable) begin
+\t\t\tout <= in;
+\t\tend\t
+\tend
+endmodule //end d flip flop w/ asynchronous reset
+
+module read_decoder(in, out);
+\tinput [4:0] in;
+\toutput [31:0] out;
+\t
+\twire [4:0] in;
+\twire [31:0] out;
+\t
+\tand(out[0], ~in[0], ~in[1], ~in[2], ~in[3], ~in[4]);
+\tand(out[1], in[0], ~in[1], ~in[2], ~in[3], ~in[4]);
+\tand(out[2], ~in[0], in[1], ~in[2], ~in[3], ~in[4]);
+\tand(out[3], in[0], in[1], ~in[2], ~in[3], ~in[4]);
+\tand(out[4], ~in[0], ~in[1], in[2], ~in[3], ~in[4]);
+\tand(out[5], in[0], ~in[1], in[2], ~in[3], ~in[4]);
+\tand(out[6], ~in[0], in[1], in[2], ~in[3], ~in[4]);
+\tand(out[7], in[0], in[1], in[2], ~in[3], ~in[4]);
+\tand(out[8], ~in[0], ~in[1], ~in[2], in[3], ~in[4]);
+\tand(out[9], in[0], ~in[1], ~in[2], in[3], ~in[4]);
+\t
+\tand(out[10], ~in[0], in[1], ~in[2], in[3], ~in[4]);
+\tand(out[11], in[0], in[1], ~in[2], in[3], ~in[4]);
+\tand(out[12], ~in[0], ~in[1], in[2], in[3], ~in[4]);
+\tand(out[13], in[0], ~in[1], in[2], in[3], ~in[4]);
+\tand(out[14], ~in[0], in[1], in[2], in[3], ~in[4]);
+\tand(out[15], in[0], in[1], in[2], in[3], ~in[4]);
+\tand(out[16], ~in[0], ~in[1], ~in[2], ~in[3], in[4]);
+\tand(out[17], in[0], ~in[1], ~in[2], ~in[3], in[4]);
+\tand(out[18], ~in[0], in[1], ~in[2], ~in[3], in[4]);
+\tand(out[19], in[0], in[1], ~in[2], ~in[3], in[4]);
+\tand(out[20], ~in[0], ~in[1], in[2], ~in[3], in[4]);
+\t
+\tand(out[21], in[0], ~in[1], in[2], ~in[3], in[4]);
+\tand(out[22], ~in[0], in[1], in[2], ~in[3], in[4]);
+\tand(out[23], in[0], in[1], in[2], ~in[3], in[4]);
+\tand(out[24], ~in[0], ~in[1], ~in[2], in[3], in[4]);
+\tand(out[25], in[0], ~in[1], ~in[2], in[3], in[4]);
+\tand(out[26], ~in[0], in[1], ~in[2], in[3], in[4]);
+\tand(out[27], in[0], in[1], ~in[2], in[3], in[4]);
+\tand(out[28], ~in[0], ~in[1], in[2], in[3], in[4]);
+\tand(out[29], in[0], ~in[1], in[2], in[3], in[4]);
+\tand(out[30], ~in[0], in[1], in[2], in[3], in[4]);
+\tand(out[31], in[0], in[1], in[2], in[3], in[4]);
+\t
+endmodule //end read-decoder for tri-state buffer banks
+
+module write_decoder(in, enable, out);
+\tinput [4:0] in;
+\tinput enable;
+\toutput [31:0] out;
+\t
+\twire [4:0] in;
+\twire enable;
+\twire [31:0] out;
+\t
+\tand(out[0], ~in[0], ~in[1], ~in[2], ~in[3], ~in[4], enable);
+\tand(out[1], in[0], ~in[1], ~in[2], ~in[3], ~in[4], enable);
+\tand(out[2], ~in[0], in[1], ~in[2], ~in[3], ~in[4], enable);
+\tand(out[3], in[0], in[1], ~in[2], ~in[3], ~in[4], enable);
+\tand(out[4], ~in[0], ~in[1], in[2], ~in[3], ~in[4], enable);
+\tand(out[5], in[0], ~in[1], in[2], ~in[3], ~in[4], enable);
+\tand(out[6], ~in[0], in[1], in[2], ~in[3], ~in[4], enable);
+\tand(out[7], in[0], in[1], in[2], ~in[3], ~in[4], enable);
+\tand(out[8], ~in[0], ~in[1], ~in[2], in[3], ~in[4], enable);
+\tand(out[9], in[0], ~in[1], ~in[2], in[3], ~in[4], enable);
+\t
+\tand(out[10], ~in[0], in[1], ~in[2], in[3], ~in[4], enable);
+\tand(out[11], in[0], in[1], ~in[2], in[3], ~in[4], enable);
+\tand(out[12], ~in[0], ~in[1], in[2], in[3], ~in[4], enable);
+\tand(out[13], in[0], ~in[1], in[2], in[3], ~in[4], enable);
+\tand(out[14], ~in[0], in[1], in[2], in[3], ~in[4], enable);
+\tand(out[15], in[0], in[1], in[2], in[3], ~in[4], enable);
+\tand(out[16], ~in[0], ~in[1], ~in[2], ~in[3], in[4], enable);
+\tand(out[17], in[0], ~in[1], ~in[2], ~in[3], in[4], enable);
+\tand(out[18], ~in[0], in[1], ~in[2], ~in[3], in[4], enable);
+\tand(out[19], in[0], in[1], ~in[2], ~in[3], in[4], enable);
+\tand(out[20], ~in[0], ~in[1], in[2], ~in[3], in[4], enable);
+\t
+\tand(out[21], in[0], ~in[1], in[2], ~in[3], in[4], enable);
+\tand(out[22], ~in[0], in[1], in[2], ~in[3], in[4], enable);
+\tand(out[23], in[0], in[1], in[2], ~in[3], in[4], enable);
+\tand(out[24], ~in[0], ~in[1], ~in[2], in[3], in[4], enable);
+\tand(out[25], in[0], ~in[1], ~in[2], in[3], in[4], enable);
+\tand(out[26], ~in[0], in[1], ~in[2], in[3], in[4], enable);
+\tand(out[27], in[0], in[1], ~in[2], in[3], in[4], enable);
+\tand(out[28], ~in[0], ~in[1], in[2], in[3], in[4], enable);
+\tand(out[29], in[0], ~in[1], in[2], in[3], in[4], enable);
+\tand(out[30], ~in[0], in[1], in[2], in[3], in[4], enable);
+\tand(out[31], in[0], in[1], in[2], in[3], in[4], enable);
+
+endmodule //end write decoder for registers
+
+module register(in, enable, clock, reset, out);
+ input [31:0] in;
+ input enable, clock, reset;
+ output [31:0] out;
+
+ wire [31:0] in;
+ wire enable, clock, reset;
+
+ genvar i;
+ generate
+\tfor (i=0; i<32; i=i+1) begin: dff_loop_32
+\t\tdff_sr\t\tasync_dff(in[i], enable, clock, reset, out[i]);
+\tend
+ endgenerate
+
+endmodule //end 32-bit wide register
+
+module register_file(clock, ctrl_writeEnable, ctrl_reset, ctrl_writeReg, ctrl_readRegA, ctrl_readRegB, data_writeReg, data_readRegA, data_readRegB);
+ input clock, ctrl_writeEnable, ctrl_reset;
+ input [4:0] ctrl_writeReg, ctrl_readRegA, ctrl_readRegB;
+ input [31:0] data_writeReg;
+ output [31:0] data_readRegA, data_readRegB;
+
+ // enable wire for register
+ wire [31:0] decoded_writeReg;
+
+ // register output wires
+ wire [31:0] wire_array [31:0];
+
+ // wires choosing tri-states
+ wire [31:0] decoded_tsb_setA;
+ wire [31:0] decoded_tsb_setB;
+
+ // write decoder
+ write_decoder\t\twrite_decoder(ctrl_writeReg, ctrl_writeEnable, decoded_writeReg);
+
+ // read decoders
+ read_decoder \t\tread_decoderA(ctrl_readRegA, decoded_tsb_setA);
+ read_decoder \t\tread_decoderB(ctrl_readRegB, decoded_tsb_setB);
+
+ // 32 registers and 64 tri-state-buffers in sets of 32, with register outputs fed into tsbs
+ genvar a;
+ generate
+\tfor (a=0; a<32; a=a+1) begin: register_loop_32
+\t\tregister \tregister(data_writeReg, decoded_writeReg[a], clock, ctrl_reset, wire_array[a]);
+\t\ttsb \ttri_stateA(wire_array[a], decoded_tsb_setA[a], data_readRegA);
+\t\ttsb \ttri_stateB(wire_array[a], decoded_tsb_setB[a], data_readRegB);
+\tend
+ endgenerate
+
+endmodule"
+"always @(negedge reset or posedge clk) begin
+ if (reset == 0) begin
+ d_out <= 16'h0000;
+ d_out_mem[resetcount] <= d_out;
+ laststoredvalue <= d_out;
+ end else begin
+ d_out <= d_out + 1'b1;
+ end
+end
+
+always @(bufreadaddr)
+ bufreadval = d_out_mem[bufreadaddr];"
+"always @(negedge reset or posedge clk) begin
+ if (reset == 0) begin
+ d_out <= 16'h0000;
+ d_out_mem[resetcount] <= d_out;
+ laststoredvalue <= d_out;
+ end else begin
+ d_out <= d_out + 1'b1;
+ end
+end
+
+always @(bufreadaddr)
+ bufreadval = d_out_mem[bufreadaddr];"
+"always @(negedge reset or posedge clk) begin
+ if (reset == 0) begin
+ d_out <= 16'h0000;
+ d_out_mem[resetcount] <= d_out;
+ laststoredvalue <= d_out;
+ end else begin
+ d_out <= d_out + 1'b1;
+ end
+end
+
+always @(bufreadaddr)
+ bufreadval = d_out_mem[bufreadaddr];"
+"// megafunction wizard: %FIFO%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: dcfifo
+
+// ============================================================
+// File Name: buffer.v
+// Megafunction Name(s):
+// \t\t\tdcfifo
+//
+// Simulation Library Files(s):
+// \t\t\taltera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 13.1.4 Build 182 03/12/2014 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2014 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module buffer (
+\taclr,
+\tdata,
+\trdclk,
+\trdreq,
+\twrclk,
+\twrreq,
+\tq,
+\trdempty,
+\twrfull);
+
+\tinput\t aclr;
+\tinput\t[7:0] data;
+\tinput\t rdclk;
+\tinput\t rdreq;
+\tinput\t wrclk;
+\tinput\t wrreq;
+\toutput\t[7:0] q;
+\toutput\t rdempty;
+\toutput\t wrfull;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_off
+`endif
+\ttri0\t aclr;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_on
+`endif
+
+\twire sub_wire0;
+\twire [7:0] sub_wire1;
+\twire sub_wire2;
+\twire wrfull = sub_wire0;
+\twire [7:0] q = sub_wire1[7:0];
+\twire rdempty = sub_wire2;
+
+\tdcfifo\tdcfifo_component (
+\t\t\t\t.rdclk (rdclk),
+\t\t\t\t.wrclk (wrclk),
+\t\t\t\t.wrreq (wrreq),
+\t\t\t\t.aclr (aclr),
+\t\t\t\t.data (data),
+\t\t\t\t.rdreq (rdreq),
+\t\t\t\t.wrfull (sub_wire0),
+\t\t\t\t.q (sub_wire1),
+\t\t\t\t.rdempty (sub_wire2),
+\t\t\t\t.rdfull (),
+\t\t\t\t.rdusedw (),
+\t\t\t\t.wrempty (),
+\t\t\t\t.wrusedw ());
+\tdefparam
+\t\tdcfifo_component.intended_device_family = ""Cyclone IV E"",
+\t\tdcfifo_component.lpm_numwords = 64,
+\t\tdcfifo_component.lpm_showahead = ""OFF"",
+\t\tdcfifo_component.lpm_type = ""dcfifo"",
+\t\tdcfifo_component.lpm_width = 8,
+\t\tdcfifo_component.lpm_widthu = 6,
+\t\tdcfifo_component.overflow_checking = ""ON"",
+\t\tdcfifo_component.rdsync_delaypipe = 5,
+\t\tdcfifo_component.read_aclr_synch = ""OFF"",
+\t\tdcfifo_component.underflow_checking = ""ON"",
+\t\tdcfifo_component.use_eab = ""ON"",
+\t\tdcfifo_component.write_aclr_synch = ""OFF"",
+\t\tdcfifo_component.wrsync_delaypipe = 5;
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: AlmostEmpty NUMERIC ""0""
+// Retrieval info: PRIVATE: AlmostEmptyThr NUMERIC ""-1""
+// Retrieval info: PRIVATE: AlmostFull NUMERIC ""0""
+// Retrieval info: PRIVATE: AlmostFullThr NUMERIC ""-1""
+// Retrieval info: PRIVATE: CLOCKS_ARE_SYNCHRONIZED NUMERIC ""0""
+// Retrieval info: PRIVATE: Clock NUMERIC ""4""
+// Retrieval info: PRIVATE: Depth NUMERIC ""64""
+// Retrieval info: PRIVATE: Empty NUMERIC ""1""
+// Retrieval info: PRIVATE: Full NUMERIC ""1""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone IV E""
+// Retrieval info: PRIVATE: LE_BasedFIFO NUMERIC ""0""
+// Retrieval info: PRIVATE: LegacyRREQ NUMERIC ""1""
+// Retrieval info: PRIVATE: MAX_DEPTH_BY_9 NUMERIC ""0""
+// Retrieval info: PRIVATE: OVERFLOW_CHECKING NUMERIC ""0""
+// Retrieval info: PRIVATE: Optimize NUMERIC ""2""
+// Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC ""0""
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING ""0""
+// Retrieval info: PRIVATE: UNDERFLOW_CHECKING NUMERIC ""0""
+// Retrieval info: PRIVATE: UsedW NUMERIC ""1""
+// Retrieval info: PRIVATE: Width NUMERIC ""8""
+// Retrieval info: PRIVATE: dc_aclr NUMERIC ""1""
+// Retrieval info: PRIVATE: diff_widths NUMERIC ""0""
+// Retrieval info: PRIVATE: msb_usedw NUMERIC ""0""
+// Retrieval info: PRIVATE: output_width NUMERIC ""8""
+// Retrieval info: PRIVATE: rsEmpty NUMERIC ""1""
+// Retrieval info: PRIVATE: rsFull NUMERIC ""0""
+// Retrieval info: PRIVATE: rsUsedW NUMERIC ""0""
+// Retrieval info: PRIVATE: sc_aclr NUMERIC ""0""
+// Retrieval info: PRIVATE: sc_sclr NUMERIC ""0""
+// Retrieval info: PRIVATE: wsEmpty NUMERIC ""0""
+// Retrieval info: PRIVATE: wsFull NUMERIC ""1""
+// Retrieval info: PRIVATE: wsUsedW NUMERIC ""0""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone IV E""
+// Retrieval info: CONSTANT: LPM_NUMWORDS NUMERIC ""64""
+// Retrieval info: CONSTANT: LPM_SHOWAHEAD STRING ""OFF""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""dcfifo""
+// Retrieval info: CONSTANT: LPM_WIDTH NUMERIC ""8""
+// Retrieval info: CONSTANT: LPM_WIDTHU NUMERIC ""6""
+// Retrieval info: CONSTANT: OVERFLOW_CHECKING STRING ""ON""
+// Retrieval info: CONSTANT: RDSYNC_DELAYPIPE NUMERIC ""5""
+// Retrieval info: CONSTANT: READ_ACLR_SYNCH STRING ""OFF""
+// Retrieval info: CONSTANT: UNDERFLOW_CHECKING STRING ""ON""
+// Retrieval info: CONSTANT: USE_EAB STRING ""ON""
+// Retrieval info: CONSTANT: WRITE_ACLR_SYNCH STRING ""OFF""
+// Retrieval info: CONSTANT: WRSYNC_DELAYPIPE NUMERIC ""5""
+// Retrieval info: USED_PORT: aclr 0 0 0 0 INPUT GND ""aclr""
+// Retrieval info: USED_PORT: data 0 0 8 0 INPUT NODEFVAL ""data[7..0]""
+// Retrieval info: USED_PORT: q 0 0 8 0 OUTPUT NODEFVAL ""q[7..0]""
+// Retrieval info: USED_PORT: rdclk 0 0 0 0 INPUT NODEFVAL ""rdclk""
+// Retrieval info: USED_PORT: rdempty 0 0 0 0 OUTPUT NODEFVAL ""rdempty""
+// Retrieval info: USED_PORT: rdreq 0 0 0 0 INPUT NODEFVAL ""rdreq""
+// Retrieval info: USED_PORT: wrclk 0 0 0 0 INPUT NODEFVAL ""wrclk""
+// Retrieval info: USED_PORT: wrfull 0 0 0 0 OUTPUT NODEFVAL ""wrfull""
+// Retrieval info: USED_PORT: wrreq 0 0 0 0 INPUT NODEFVAL ""wrreq""
+// Retrieval info: CONNECT: @aclr 0 0 0 0 aclr 0 0 0 0
+// Retrieval info: CONNECT: @data 0 0 8 0 data 0 0 8 0
+// Retrieval info: CONNECT: @rdclk 0 0 0 0 rdclk 0 0 0 0
+// Retrieval info: CONNECT: @rdreq 0 0 0 0 rdreq 0 0 0 0
+// Retrieval info: CONNECT: @wrclk 0 0 0 0 wrclk 0 0 0 0
+// Retrieval info: CONNECT: @wrreq 0 0 0 0 wrreq 0 0 0 0
+// Retrieval info: CONNECT: q 0 0 8 0 @q 0 0 8 0
+// Retrieval info: CONNECT: rdempty 0 0 0 0 @rdempty 0 0 0 0
+// Retrieval info: CONNECT: wrfull 0 0 0 0 @wrfull 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL buffer.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL buffer.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL buffer.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL buffer.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL buffer_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL buffer_bb.v TRUE
+// Retrieval info: LIB_FILE: altera_mf
+"
+"// megafunction wizard: %ALTPLL%VBB%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altpll
+
+// ============================================================
+// File Name: pll_clock.v
+// Megafunction Name(s):
+// \t\t\taltpll
+//
+// Simulation Library Files(s):
+// \t\t\taltera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 13.1.4 Build 182 03/12/2014 SJ Web Edition
+// ************************************************************
+
+//Copyright (C) 1991-2014 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+module pll_clock (
+\tareset,
+\tinclk0,
+\tc0,
+\tlocked);
+
+\tinput\t areset;
+\tinput\t inclk0;
+\toutput\t c0;
+\toutput\t locked;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_off
+`endif
+\ttri0\t areset;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_on
+`endif
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH STRING ""1.000""
+// Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING ""MHz""
+// Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING ""Low""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING ""1""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING ""0""
+// Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CLKLOSS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING ""0""
+// Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING ""c0""
+// Retrieval info: PRIVATE: CUR_FBIN_CLK STRING ""c0""
+// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING ""6""
+// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING ""50.00000000""
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING ""100.000000""
+// Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING ""0""
+// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING ""0""
+// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING ""0""
+// Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC ""1048575""
+// Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING ""1""
+// Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING ""50.000""
+// Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING ""100.000""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone IV E""
+// Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING ""1""
+// Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING ""1""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING ""Not Available""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC ""0""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: MIG_DEVICE_SPEED_GRADE STRING ""Any""
+// Retrieval info: PRIVATE: MIRROR_CLK0 STRING ""0""
+// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING ""100.00000000""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING ""MHz""
+// Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: PHASE_RECONFIG_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING ""0.00000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT_STEP_ENABLED_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: PLL_ADVANCED_PARAM_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING ""1""
+// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC ""1""
+// Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_FBMIMIC_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_TARGET_HARCOPY_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING ""inclk0""
+// Retrieval info: PRIVATE: RECONFIG_FILE STRING ""pll_clock.mif""
+// Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: SELF_RESET_LOCK_LOSS STRING ""1""
+// Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FREQ STRING ""50.000""
+// Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING ""KHz""
+// Retrieval info: PRIVATE: SPREAD_PERCENT STRING ""0.500""
+// Retrieval info: PRIVATE: SPREAD_USE STRING ""0""
+// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING ""0""
+// Retrieval info: PRIVATE: STICKY_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING ""0""
+// Retrieval info: PRIVATE: USE_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: USE_CLKENA0 STRING ""0""
+// Retrieval info: PRIVATE: USE_MIL_SPEED_GRADE NUMERIC ""0""
+// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING ""0""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: BANDWIDTH_TYPE STRING ""AUTO""
+// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC ""2""
+// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING ""0""
+// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING ""CLK0""
+// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC ""20000""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone IV E""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""altpll""
+// Retrieval info: CONSTANT: OPERATION_MODE STRING ""NORMAL""
+// Retrieval info: CONSTANT: PLL_TYPE STRING ""AUTO""
+// Retrieval info: CONSTANT: PORT_ACTIVECLOCK STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_ARESET STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_CLKBAD0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKBAD1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKLOSS STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKSWITCH STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CONFIGUPDATE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_FBIN STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_INCLK0 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_INCLK1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_LOCKED STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_PFDENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASECOUNTERSELECT STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASEDONE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASESTEP STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASEUPDOWN STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PLLENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANACLR STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANCLK STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANCLKENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDATA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDATAOUT STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDONE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANREAD STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANWRITE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk0 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_clk1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk4 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk5 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena4 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena5 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: SELF_RESET_ON_LOSS_LOCK STRING ""ON""
+// Retrieval info: CONSTANT: WIDTH_CLOCK NUMERIC ""5""
+// Retrieval info: USED_PORT: @clk 0 0 5 0 OUTPUT_CLK_EXT VCC ""@clk[4..0]""
+// Retrieval info: USED_PORT: areset 0 0 0 0 INPUT GND ""areset""
+// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT_CLK_EXT VCC ""c0""
+// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT_CLK_EXT GND ""inclk0""
+// Retrieval info: USED_PORT: locked 0 0 0 0 OUTPUT GND ""locked""
+// Retrieval info: CONNECT: @areset 0 0 0 0 areset 0 0 0 0
+// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
+// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
+// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
+// Retrieval info: CONNECT: locked 0 0 0 0 @locked 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock.ppf TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock_bb.v TRUE
+// Retrieval info: LIB_FILE: altera_mf
+// Retrieval info: CBX_MODULE_PREFIX: ON
+"
+"/*
+# reset.v - System reset counter, count down for 32 clocks
+#
+# Copyright (C) 2014 Binary Logic (nhi.phan.logic at gmail.com).
+#
+# This file is part of the Virtual JTAG UART toolkit
+#
+# Virtual UART is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+*/
+
+//=======================================================
+// System reset timer
+//=======================================================
+`include ""system_include.v""
+
+module reset (
+
+\t//////////// CLOCK //////////
+\tinput clk_i,
+
+\t//////////// reset signal //////////
+\toutput nreset_o
+);
+
+reg [3:0] reset_counter = 4\'b1111;
+
+// Reset is LOW until reset counter is 0, then goes high and stays high
+assign nreset_o = (reset_counter == 1\'b0);
+
+always @(posedge clk_i)
+begin
+\tif( reset_counter > 1\'b0 ) reset_counter = reset_counter - 1\'b1;
+end
+
+endmodule
+"
+"// megafunction wizard: %ALTPLL%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altpll
+
+// ============================================================
+// File Name: pll_clock.v
+// Megafunction Name(s):
+// \t\t\taltpll
+//
+// Simulation Library Files(s):
+// \t\t\taltera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 13.1.4 Build 182 03/12/2014 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2014 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module pll_clock (
+\tareset,
+\tinclk0,
+\tc0,
+\tlocked);
+
+\tinput\t areset;
+\tinput\t inclk0;
+\toutput\t c0;
+\toutput\t locked;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_off
+`endif
+\ttri0\t areset;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_on
+`endif
+
+\twire sub_wire0;
+\twire [4:0] sub_wire1;
+\twire [0:0] sub_wire5 = 1\'h0;
+\twire locked = sub_wire0;
+\twire [0:0] sub_wire2 = sub_wire1[0:0];
+\twire c0 = sub_wire2;
+\twire sub_wire3 = inclk0;
+\twire [1:0] sub_wire4 = {sub_wire5, sub_wire3};
+
+\taltpll\taltpll_component (
+\t\t\t\t.areset (areset),
+\t\t\t\t.inclk (sub_wire4),
+\t\t\t\t.locked (sub_wire0),
+\t\t\t\t.clk (sub_wire1),
+\t\t\t\t.activeclock (),
+\t\t\t\t.clkbad (),
+\t\t\t\t.clkena ({6{1\'b1}}),
+\t\t\t\t.clkloss (),
+\t\t\t\t.clkswitch (1\'b0),
+\t\t\t\t.configupdate (1\'b0),
+\t\t\t\t.enable0 (),
+\t\t\t\t.enable1 (),
+\t\t\t\t.extclk (),
+\t\t\t\t.extclkena ({4{1\'b1}}),
+\t\t\t\t.fbin (1\'b1),
+\t\t\t\t.fbmimicbidir (),
+\t\t\t\t.fbout (),
+\t\t\t\t.fref (),
+\t\t\t\t.icdrclk (),
+\t\t\t\t.pfdena (1\'b1),
+\t\t\t\t.phasecounterselect ({4{1\'b1}}),
+\t\t\t\t.phasedone (),
+\t\t\t\t.phasestep (1\'b1),
+\t\t\t\t.phaseupdown (1\'b1),
+\t\t\t\t.pllena (1\'b1),
+\t\t\t\t.scanaclr (1\'b0),
+\t\t\t\t.scanclk (1\'b0),
+\t\t\t\t.scanclkena (1\'b1),
+\t\t\t\t.scandata (1\'b0),
+\t\t\t\t.scandataout (),
+\t\t\t\t.scandone (),
+\t\t\t\t.scanread (1\'b0),
+\t\t\t\t.scanwrite (1\'b0),
+\t\t\t\t.sclkout0 (),
+\t\t\t\t.sclkout1 (),
+\t\t\t\t.vcooverrange (),
+\t\t\t\t.vcounderrange ());
+\tdefparam
+\t\taltpll_component.bandwidth_type = ""AUTO"",
+\t\taltpll_component.clk0_divide_by = 1,
+\t\taltpll_component.clk0_duty_cycle = 50,
+\t\taltpll_component.clk0_multiply_by = 2,
+\t\taltpll_component.clk0_phase_shift = ""0"",
+\t\taltpll_component.compensate_clock = ""CLK0"",
+\t\taltpll_component.inclk0_input_frequency = 20000,
+\t\taltpll_component.intended_device_family = ""Cyclone IV E"",
+\t\taltpll_component.lpm_hint = ""CBX_MODULE_PREFIX=pll_clock"",
+\t\taltpll_component.lpm_type = ""altpll"",
+\t\taltpll_component.operation_mode = ""NORMAL"",
+\t\taltpll_component.pll_type = ""AUTO"",
+\t\taltpll_component.port_activeclock = ""PORT_UNUSED"",
+\t\taltpll_component.port_areset = ""PORT_USED"",
+\t\taltpll_component.port_clkbad0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkbad1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkloss = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkswitch = ""PORT_UNUSED"",
+\t\taltpll_component.port_configupdate = ""PORT_UNUSED"",
+\t\taltpll_component.port_fbin = ""PORT_UNUSED"",
+\t\taltpll_component.port_inclk0 = ""PORT_USED"",
+\t\taltpll_component.port_inclk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_locked = ""PORT_USED"",
+\t\taltpll_component.port_pfdena = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasecounterselect = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasedone = ""PORT_UNUSED"",
+\t\taltpll_component.port_phasestep = ""PORT_UNUSED"",
+\t\taltpll_component.port_phaseupdown = ""PORT_UNUSED"",
+\t\taltpll_component.port_pllena = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanaclr = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanclk = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanclkena = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandata = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandataout = ""PORT_UNUSED"",
+\t\taltpll_component.port_scandone = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanread = ""PORT_UNUSED"",
+\t\taltpll_component.port_scanwrite = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk0 = ""PORT_USED"",
+\t\taltpll_component.port_clk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk2 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk3 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk4 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clk5 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena2 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena3 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena4 = ""PORT_UNUSED"",
+\t\taltpll_component.port_clkena5 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk0 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk1 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk2 = ""PORT_UNUSED"",
+\t\taltpll_component.port_extclk3 = ""PORT_UNUSED"",
+\t\taltpll_component.self_reset_on_loss_lock = ""ON"",
+\t\taltpll_component.width_clock = 5;
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING ""0""
+// Retrieval info: PRIVATE: BANDWIDTH STRING ""1.000""
+// Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING ""MHz""
+// Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING ""Low""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING ""1""
+// Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING ""0""
+// Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CLKLOSS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING ""0""
+// Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING ""0""
+// Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING ""c0""
+// Retrieval info: PRIVATE: CUR_FBIN_CLK STRING ""c0""
+// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING ""6""
+// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING ""50.00000000""
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING ""100.000000""
+// Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING ""0""
+// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING ""0""
+// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING ""0""
+// Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC ""1048575""
+// Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING ""1""
+// Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING ""50.000""
+// Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING ""100.000""
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING ""1""
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING ""MHz""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone IV E""
+// Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING ""1""
+// Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING ""1""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING ""Not Available""
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC ""0""
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: MIG_DEVICE_SPEED_GRADE STRING ""Any""
+// Retrieval info: PRIVATE: MIRROR_CLK0 STRING ""0""
+// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC ""1""
+// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING ""100.00000000""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING ""1""
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING ""MHz""
+// Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: PHASE_RECONFIG_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING ""0.00000000""
+// Retrieval info: PRIVATE: PHASE_SHIFT_STEP_ENABLED_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING ""deg""
+// Retrieval info: PRIVATE: PLL_ADVANCED_PARAM_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING ""1""
+// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC ""1""
+// Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_FBMIMIC_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING ""0""
+// Retrieval info: PRIVATE: PLL_TARGET_HARCOPY_CHECK NUMERIC ""0""
+// Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING ""inclk0""
+// Retrieval info: PRIVATE: RECONFIG_FILE STRING ""pll_clock.mif""
+// Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING ""0""
+// Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: SELF_RESET_LOCK_LOSS STRING ""1""
+// Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING ""0""
+// Retrieval info: PRIVATE: SPREAD_FREQ STRING ""50.000""
+// Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING ""KHz""
+// Retrieval info: PRIVATE: SPREAD_PERCENT STRING ""0.500""
+// Retrieval info: PRIVATE: SPREAD_USE STRING ""0""
+// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING ""0""
+// Retrieval info: PRIVATE: STICKY_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC ""1""
+// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING ""1""
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING ""0""
+// Retrieval info: PRIVATE: USE_CLK0 STRING ""1""
+// Retrieval info: PRIVATE: USE_CLKENA0 STRING ""0""
+// Retrieval info: PRIVATE: USE_MIL_SPEED_GRADE NUMERIC ""0""
+// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING ""0""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: BANDWIDTH_TYPE STRING ""AUTO""
+// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC ""1""
+// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC ""50""
+// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC ""2""
+// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING ""0""
+// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING ""CLK0""
+// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC ""20000""
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone IV E""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""altpll""
+// Retrieval info: CONSTANT: OPERATION_MODE STRING ""NORMAL""
+// Retrieval info: CONSTANT: PLL_TYPE STRING ""AUTO""
+// Retrieval info: CONSTANT: PORT_ACTIVECLOCK STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_ARESET STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_CLKBAD0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKBAD1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKLOSS STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CLKSWITCH STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_CONFIGUPDATE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_FBIN STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_INCLK0 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_INCLK1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_LOCKED STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_PFDENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASECOUNTERSELECT STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASEDONE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASESTEP STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PHASEUPDOWN STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_PLLENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANACLR STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANCLK STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANCLKENA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDATA STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDATAOUT STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANDONE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANREAD STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_SCANWRITE STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk0 STRING ""PORT_USED""
+// Retrieval info: CONSTANT: PORT_clk1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk4 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clk5 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena4 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_clkena5 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk0 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk1 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk2 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: PORT_extclk3 STRING ""PORT_UNUSED""
+// Retrieval info: CONSTANT: SELF_RESET_ON_LOSS_LOCK STRING ""ON""
+// Retrieval info: CONSTANT: WIDTH_CLOCK NUMERIC ""5""
+// Retrieval info: USED_PORT: @clk 0 0 5 0 OUTPUT_CLK_EXT VCC ""@clk[4..0]""
+// Retrieval info: USED_PORT: areset 0 0 0 0 INPUT GND ""areset""
+// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT_CLK_EXT VCC ""c0""
+// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT_CLK_EXT GND ""inclk0""
+// Retrieval info: USED_PORT: locked 0 0 0 0 OUTPUT GND ""locked""
+// Retrieval info: CONNECT: @areset 0 0 0 0 areset 0 0 0 0
+// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
+// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
+// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
+// Retrieval info: CONNECT: locked 0 0 0 0 @locked 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock.ppf TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL pll_clock_bb.v TRUE
+// Retrieval info: LIB_FILE: altera_mf
+// Retrieval info: CBX_MODULE_PREFIX: ON
+"
+"//=======================================================
+// Standard Include
+//=======================================================
+
+`timescale 1ns/1ns
+`ifdef MODEL_TECH
+\t`define UNDER_TEST
+`endif
+"
+"// megafunction wizard: %FIFO%VBB%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: dcfifo
+
+// ============================================================
+// File Name: buffer.v
+// Megafunction Name(s):
+// \t\t\tdcfifo
+//
+// Simulation Library Files(s):
+// \t\t\taltera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 13.1.4 Build 182 03/12/2014 SJ Web Edition
+// ************************************************************
+
+//Copyright (C) 1991-2014 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+module buffer (
+\taclr,
+\tdata,
+\trdclk,
+\trdreq,
+\twrclk,
+\twrreq,
+\tq,
+\trdempty,
+\twrfull);
+
+\tinput\t aclr;
+\tinput\t[7:0] data;
+\tinput\t rdclk;
+\tinput\t rdreq;
+\tinput\t wrclk;
+\tinput\t wrreq;
+\toutput\t[7:0] q;
+\toutput\t rdempty;
+\toutput\t wrfull;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_off
+`endif
+\ttri0\t aclr;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_on
+`endif
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: AlmostEmpty NUMERIC ""0""
+// Retrieval info: PRIVATE: AlmostEmptyThr NUMERIC ""-1""
+// Retrieval info: PRIVATE: AlmostFull NUMERIC ""0""
+// Retrieval info: PRIVATE: AlmostFullThr NUMERIC ""-1""
+// Retrieval info: PRIVATE: CLOCKS_ARE_SYNCHRONIZED NUMERIC ""0""
+// Retrieval info: PRIVATE: Clock NUMERIC ""4""
+// Retrieval info: PRIVATE: Depth NUMERIC ""64""
+// Retrieval info: PRIVATE: Empty NUMERIC ""1""
+// Retrieval info: PRIVATE: Full NUMERIC ""1""
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone IV E""
+// Retrieval info: PRIVATE: LE_BasedFIFO NUMERIC ""0""
+// Retrieval info: PRIVATE: LegacyRREQ NUMERIC ""1""
+// Retrieval info: PRIVATE: MAX_DEPTH_BY_9 NUMERIC ""0""
+// Retrieval info: PRIVATE: OVERFLOW_CHECKING NUMERIC ""0""
+// Retrieval info: PRIVATE: Optimize NUMERIC ""2""
+// Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC ""0""
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING ""0""
+// Retrieval info: PRIVATE: UNDERFLOW_CHECKING NUMERIC ""0""
+// Retrieval info: PRIVATE: UsedW NUMERIC ""1""
+// Retrieval info: PRIVATE: Width NUMERIC ""8""
+// Retrieval info: PRIVATE: dc_aclr NUMERIC ""1""
+// Retrieval info: PRIVATE: diff_widths NUMERIC ""0""
+// Retrieval info: PRIVATE: msb_usedw NUMERIC ""0""
+// Retrieval info: PRIVATE: output_width NUMERIC ""8""
+// Retrieval info: PRIVATE: rsEmpty NUMERIC ""1""
+// Retrieval info: PRIVATE: rsFull NUMERIC ""0""
+// Retrieval info: PRIVATE: rsUsedW NUMERIC ""0""
+// Retrieval info: PRIVATE: sc_aclr NUMERIC ""0""
+// Retrieval info: PRIVATE: sc_sclr NUMERIC ""0""
+// Retrieval info: PRIVATE: wsEmpty NUMERIC ""0""
+// Retrieval info: PRIVATE: wsFull NUMERIC ""1""
+// Retrieval info: PRIVATE: wsUsedW NUMERIC ""0""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING ""Cyclone IV E""
+// Retrieval info: CONSTANT: LPM_NUMWORDS NUMERIC ""64""
+// Retrieval info: CONSTANT: LPM_SHOWAHEAD STRING ""OFF""
+// Retrieval info: CONSTANT: LPM_TYPE STRING ""dcfifo""
+// Retrieval info: CONSTANT: LPM_WIDTH NUMERIC ""8""
+// Retrieval info: CONSTANT: LPM_WIDTHU NUMERIC ""6""
+// Retrieval info: CONSTANT: OVERFLOW_CHECKING STRING ""ON""
+// Retrieval info: CONSTANT: RDSYNC_DELAYPIPE NUMERIC ""5""
+// Retrieval info: CONSTANT: READ_ACLR_SYNCH STRING ""OFF""
+// Retrieval info: CONSTANT: UNDERFLOW_CHECKING STRING ""ON""
+// Retrieval info: CONSTANT: USE_EAB STRING ""ON""
+// Retrieval info: CONSTANT: WRITE_ACLR_SYNCH STRING ""OFF""
+// Retrieval info: CONSTANT: WRSYNC_DELAYPIPE NUMERIC ""5""
+// Retrieval info: USED_PORT: aclr 0 0 0 0 INPUT GND ""aclr""
+// Retrieval info: USED_PORT: data 0 0 8 0 INPUT NODEFVAL ""data[7..0]""
+// Retrieval info: USED_PORT: q 0 0 8 0 OUTPUT NODEFVAL ""q[7..0]""
+// Retrieval info: USED_PORT: rdclk 0 0 0 0 INPUT NODEFVAL ""rdclk""
+// Retrieval info: USED_PORT: rdempty 0 0 0 0 OUTPUT NODEFVAL ""rdempty""
+// Retrieval info: USED_PORT: rdreq 0 0 0 0 INPUT NODEFVAL ""rdreq""
+// Retrieval info: USED_PORT: wrclk 0 0 0 0 INPUT NODEFVAL ""wrclk""
+// Retrieval info: USED_PORT: wrfull 0 0 0 0 OUTPUT NODEFVAL ""wrfull""
+// Retrieval info: USED_PORT: wrreq 0 0 0 0 INPUT NODEFVAL ""wrreq""
+// Retrieval info: CONNECT: @aclr 0 0 0 0 aclr 0 0 0 0
+// Retrieval info: CONNECT: @data 0 0 8 0 data 0 0 8 0
+// Retrieval info: CONNECT: @rdclk 0 0 0 0 rdclk 0 0 0 0
+// Retrieval info: CONNECT: @rdreq 0 0 0 0 rdreq 0 0 0 0
+// Retrieval info: CONNECT: @wrclk 0 0 0 0 wrclk 0 0 0 0
+// Retrieval info: CONNECT: @wrreq 0 0 0 0 wrreq 0 0 0 0
+// Retrieval info: CONNECT: q 0 0 8 0 @q 0 0 8 0
+// Retrieval info: CONNECT: rdempty 0 0 0 0 @rdempty 0 0 0 0
+// Retrieval info: CONNECT: wrfull 0 0 0 0 @wrfull 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL buffer.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL buffer.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL buffer.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL buffer.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL buffer_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL buffer_bb.v TRUE
+// Retrieval info: LIB_FILE: altera_mf
+"
+"/*
+# DE0_Comm.v - Connect all the pieces, system clock, heartbeat LED, FSM
+#
+# Copyright (C) 2014 Binary Logic (nhi.phan.logic at gmail.com).
+#
+# This file is part of the Virtual JTAG UART toolkit
+#
+# Virtual UART is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+*/
+
+//=======================================================
+// DE0 Top Module
+//=======================================================
+`include ""system_include.v""
+
+module DE0_Comm(
+
+\t//////////// CLOCK //////////
+\tinput CLOCK_50,
+
+\t// Only included if we\'re running with ModelSim
+\t`ifdef UNDER_TEST
+\t\t// Async reset
+\t\tinput areset,
+\t`endif
+\t
+\t//////////// LED //////////
+\toutput [7:0] LED
+);
+
+//=======================================================
+// REG/WIRE declarations
+//=======================================================
+
+// System signals
+wire sysclk, reset_n;
+
+// Heartbeat signals
+wire heartbeat;
+
+
+//=======================================================
+// Outputs
+//=======================================================
+
+assign LED = {7\'b0,heartbeat};
+
+//=======================================================
+// Structural coding
+//=======================================================
+
+// System clock
+pll_clock\tclock (
+\t.inclk0 ( CLOCK_50 ),
+\t.c0 ( sysclk ),
+\t
+\t// Only included if we\'re running with ModelSim
+\t`ifdef UNDER_TEST
+\t\t.areset( areset ),
+\t`else
+\t\t.areset(),
+\t`endif
+\t
+\t.locked ( )
+\t);
+
+// Reset timer
+reset reset(
+\t.clk_i( sysclk ),
+\t.nreset_o( reset_n )
+\t);
+
+// Heartbeat function
+heartbeat hb(
+\t.clk_i( sysclk ),
+\t.nreset_i( reset_n ),
+\t.heartbeat_o( heartbeat )
+\t);
+
+// The finite state machine for sending data through JTAG
+fsm_app app(
+\t.clk_i(sysclk),
+\t.nreset_i(reset_n)
+\t);
+\t
+//=======================================================
+// Procedural coding
+//=======================================================
+\t
+endmodule
+"
+"//=======================================================
+// DE0 Test Module
+//=======================================================
+`include ""system_include.v""
+
+module testbed ();
+
+\treg clk = 0;
+\treg areset = 0;
+\twire [7:0] LED;
+\t
+\tDE0_Comm uut(
+\t\t.CLOCK_50(clk),
+`ifdef UNDER_TEST
+\t\t.areset( areset ),
+`endif
+\t\t.LED( LED )
+\t);
+
+\tinitial begin
+\t\t#0 areset = 0;
+\t\t#1 areset = 1;
+\t\t#2 areset = 0;
+\tend
+\t
+\talways begin
+\t\t#10 clk = !clk;
+\tend
+
+endmodule
+"
+"//=======================================================
+// Module description
+//=======================================================
+`include ""system_include.v""
+
+module XXXX(
+
+\t//////////// CLOCK //////////
+\tinput XXX,
+
+\t// Only included if we\'re running with ModelSim
+\t`ifdef UNDER_TEST
+\t\t// Async reset
+\t\tinput YYY,
+\t`endif
+\t
+\t//////////// LED //////////
+\toutput ZZZ
+);
+
+//=======================================================
+// REG/WIRE declarations
+//=======================================================
+
+//=======================================================
+// Outputs
+//=======================================================
+
+//=======================================================
+// Structural coding
+//=======================================================
+
+//=======================================================
+// Procedural coding
+//=======================================================
+\t
+endmodule
+"
+"/*
+# jtag_uart.v - This module provides an 8-bit parallel FIFO interface to
+#\t\t\t\t\t\tthe Altera Virtual JTAG module.
+#
+# Description: Follows the design pattern recommended in Altera\'s Virtual
+#\t\tJTAG Megafunction user guide. Links the VJTAG to two 64-byte FIFO\'s
+#
+# Copyright (C) 2014 Binary Logic (nhi.phan.logic at gmail.com).
+#
+# This file is part of the Virtual JTAG UART toolkit
+#
+# Virtual UART is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+*/
+
+`include ""system_include.v""
+
+module jtag_uart(
+\tinput clk_i,
+\tinput nreset_i,
+\tinput nwr_i,
+\tinput [7:0] data_i,
+\tinput rd_i,
+\toutput [7:0] data_o,
+\toutput txmt,
+\toutput txfl,
+\toutput rxmt,
+\toutput rxfl
+);
+
+//=======================================================
+// JTAG Command Table
+//=======================================================
+`define TX\t\t2\'b00
+`define RX \t2\'b01
+`define STATUS 2\'b10
+`define BYPASS 2\'b11
+//=======================================================
+// REG/WIRE declarations
+//=======================================================
+// Virtual JTAG signals, see Altera\'s Virtual JTAG Megafunction user guide for infoo
+wire
+\t[1:0] ir_out, ir_in;
+
+wire
+\ttdo,
+\ttck,
+\ttdi,
+\tvirtual_state_cdr,
+\tvirtual_state_sdr,
+\tvirtual_state_udr,
+\tvirtual_state_uir;
+
+// VJTAG registers
+wire [7:0] out_data;\t\t\t\t// Output buffer signals
+reg [7:0] shift_buffer = 0;\t// Internal buffer for shifting in/out
+reg cdr_delayed;\t\t\t\t\t// Capture data register delayed by half a clock cycle
+reg sdr_delayed;\t\t\t\t\t// shift data register delayed by half a clock cycle
+reg [1:0] bypass;\t\t\t\t\t// Bypass register
+reg TXmt, TXfl, \t\t\t\t\t// Transmit empty, full signals
+\tRXmt, RXfl;\t\t\t\t\t\t// Receive empty, full signals
+
+// Stored instruction register, default to bypass
+reg [1:0] ir = `BYPASS;
+
+// Buffer management signals
+wire out_full, out_empty;
+wire in_full, in_empty;
+
+//=======================================================
+// Outputs
+//=======================================================
+
+assign ir_out = ir_in;\t// Just pass the IR out
+// If the capture instruction register points to the bypass register then output
+// the bypass register, or the shift register
+assign tdo = (ir == `BYPASS) ? bypass[0] : shift_buffer[0];
+assign txmt = TXmt;
+assign txfl = TXfl;
+assign rxmt = RXmt;
+assign rxfl = RXfl;
+
+//=======================================================
+// Structural coding
+//=======================================================
+
+// Virtual JTAG - prep signals are on rising edge TCK, output on falling edge
+// This connects to the internal signal trap hub - see the VJTAG MF User Guide
+vjtag vjtag(
+\t.ir_out(ir_out),
+\t.tdo(tdo),
+\t.ir_in(ir_in),
+\t.tck(tck),
+\t.tdi(tdi),
+\t.virtual_state_cdr(virtual_state_cdr),
+\t.virtual_state_cir(),
+\t.virtual_state_e1dr(),
+\t.virtual_state_e2dr(),
+\t.virtual_state_pdr(),
+\t.virtual_state_sdr(virtual_state_sdr),
+\t.virtual_state_udr(virtual_state_udr),
+\t.virtual_state_uir(virtual_state_uir)
+\t);
+
+// Output buffer FIFO, write clock is system clock
+// read clock is the VJTAG TCK clock
+buffer out(
+\t.aclr(!nreset_i),
+\t// Write signals
+\t.data(data_i),
+\t.wrclk(clk_i),
+\t.wrreq(!nwr_i),
+\t.wrfull(out_full),
+\t// Read signals
+\t.rdclk(!tck),
+\t.rdreq(virtual_state_cdr & (ir == `TX)),\t
+\t.q(out_data),
+\t.rdempty(out_empty)
+\t);
+
+// Input buffer FIFO, write clock is VJTAG TCK clock
+// read clock is the system clock
+buffer in(
+\t.aclr(!nreset_i),
+\t// Write signals
+\t.data(shift_buffer),
+\t.wrclk(!tck),
+\t.wrreq(virtual_state_udr & (ir == 2\'h1)),
+\t.wrfull(in_full),
+\t// Read signals
+\t.rdclk(!clk_i),
+\t.rdreq(rd_i),
+\t.q(data_o),
+\t.rdempty(in_empty)
+\t);
+
+//=======================================================
+// Procedural coding
+//=======================================================
+
+// Set the full/empty signals
+always @(posedge tck)
+begin
+\tTXmt = out_empty;
+\tRXfl = in_full;
+end
+
+// Set the full/empty signals
+always @(posedge clk_i)
+begin
+\tTXfl = out_full;
+\tRXmt = in_empty;
+end
+
+// VJTAG Controls for UART output
+always @(negedge tck)
+begin
+\t// Delay the CDR signal by one half clock cycle
+\tcdr_delayed = virtual_state_cdr;
+\tsdr_delayed = virtual_state_sdr;
+end
+
+// Capture the instruction provided
+always @(negedge tck)
+begin
+\tif( virtual_state_uir ) ir = ir_in;
+end
+
+// Data is clocked out on the falling edge, rising edge is for prep
+always @(posedge tck)
+begin
+\tcase( ir )
+\t\t// Process output
+\t\t`TX :
+\t\t\tbegin
+\t\t\t\tif( cdr_delayed )
+\t\t\t\t\tshift_buffer = out_data;
+\t\t\t\telse
+\t\t\t\t\tif( sdr_delayed )\t
+\t\t\t\t\t\tshift_buffer = {tdi,shift_buffer[7:1]};
+\t\t\tend
+\t\t// Process input
+\t\t`RX :
+\t\t\tbegin
+\t\t\t\tif( sdr_delayed )\t
+\t\t\t\t\tshift_buffer = {tdi,shift_buffer[7:1]};
+\t\t\tend
+\t\t// Process status request (only 4 bits are required to be shifted)
+\t\t`STATUS :
+\t\t\tbegin
+\t\t\t\tif( cdr_delayed )
+\t\t\t\t\tshift_buffer = {4\'b0000, RXfl, RXmt, TXfl, TXmt};
+\t\t\t\telse
+\t\t\t\tif( sdr_delayed )\t
+\t\t\t\t\tshift_buffer = {tdi,shift_buffer[7:1]};
+\t\t\tend
+\t\t// Process input
+\t\tdefault:\t// Bypass 2\'b11
+\t\t\tbegin
+\t\t\t\tif( sdr_delayed )\t
+\t\t\t\t\tbypass = {tdi,bypass[1:1]};
+\t\t\tend
+\tendcase
+\t
+end
+\t
+endmodule
+"
+"/*
+# fsm_app.v - Finite state machine to send out an example test, and process inputs
+#
+# Description: Finite state machine to exercise the JTAG UART.
+#\t\tNote that this ignores the full/empty signals, so don\'t fill the buffer!
+#
+# Copyright (C) 2014 Binary Logic (nhi.phan.logic at gmail.com).
+#
+# This file is part of the Virtual JTAG UART toolkit
+#
+# Virtual UART is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+*/
+
+//=======================================================
+// Application to put characters in the output stream and echo input
+//=======================================================
+`include ""system_include.v""
+
+module fsm_app(
+\tinput clk_i,
+\tinput nreset_i
+);
+
+// FSM States
+parameter S_INIT = 0, S_STROBE = 1, S_CNT = 2, S_WAIT = 3, S_READ = 4, S_SETTLE = 5, S_WRITE = 6;
+
+//=======================================================
+// REG/WIRE declarations
+//=======================================================
+reg [2:0] state;
+reg [7:0] data_out;
+reg wr, rd;
+wire [7:0] data_in;
+wire txmt, txfl, rxmt, rxfl;
+
+//=======================================================
+// Outputs
+//=======================================================
+
+//=======================================================
+// Structural coding
+//=======================================================
+// JTag Interface
+jtag_uart uart(
+\t.clk_i( clk_i ),
+\t.nreset_i(nreset_i),
+\t.nwr_i(wr),
+\t.data_i(data_out),
+\t.rd_i(rd),
+\t.data_o(data_in),
+\t.txmt(txmt),
+\t.txfl(txfl),
+\t.rxmt(rxmt),
+\t.rxfl(rxfl)
+\t);
+
+//=======================================================
+// Procedural coding
+//=======================================================
+
+always @(posedge clk_i)
+begin
+\tif( !nreset_i )
+\tbegin
+\t\tstate = S_INIT;
+\t\twr = 1\'b1;
+\t\trd = 1\'b0;
+\tend else begin
+\t\tcase( state )
+\t\t\tS_INIT :
+\t\t\t\tbegin
+\t\t\t\t\tdata_out = 65;
+\t\t\t\t\twr = 1\'b1;
+\t\t\t\t\trd = 1\'b0;
+\t\t\t\t\tstate = S_STROBE;
+\t\t\t\tend
+\t\t\tS_STROBE:
+\t\t\t\tbegin
+\t\t\t\t\twr = 1\'b0;
+\t\t\t\t\tstate = S_CNT;
+\t\t\t\tend
+\t\t\tS_CNT:
+\t\t\t\tbegin
+\t\t\t\t\twr = 1\'b1;
+\t\t\t\t\tdata_out = data_out + 1\'b1;
+\t\t\t\t\tif( data_out <= 90 )
+\t\t\t\t\t\tstate = S_STROBE;
+\t\t\t\t\telse
+\t\t\t\t\t\tstate = S_WAIT;
+\t\t\t\tend
+\t\t\tS_WAIT :
+\t\t\t\tif( !rxmt )
+\t\t\t\tbegin
+\t\t\t\t\trd = 1\'b1;
+\t\t\t\t\tstate = S_READ;
+\t\t\t\tend
+\t\t\t\telse begin
+\t\t\t\t\twr = 1\'b1;
+\t\t\t\t\trd = 1\'b0;
+\t\t\t\t\tstate = S_WAIT;
+\t\t\t\tend
+\t\t\tS_READ :
+\t\t\t\tbegin
+\t\t\t\t\trd = 1\'b0;
+\t\t\t\t\tdata_out = data_in;
+\t\t\t\t\tstate = S_SETTLE;
+\t\t\t\tend
+\t\t\tS_SETTLE :
+\t\t\t\tbegin
+\t\t\t\t\twr = 1\'b0;
+\t\t\t\t\tstate = S_WRITE;
+\t\t\t\tend
+\t\t\tS_WRITE :
+\t\t\t\tbegin
+\t\t\t\t\twr = 1\'b1;
+\t\t\t\t\tstate = S_WAIT;
+\t\t\t\tend
+\t\t\tdefault:
+\t\t\t\tstate = S_INIT;
+\t\tendcase
+\tend
+end
+\t
+endmodule
+"
+"/*
+# heartbeat.v - Simple heartbeat module - not necessary for the UART
+#\t\t\t\t\t\tbut nice to know the config is loaded properly :)
+#
+# Copyright (C) 2014 Binary Logic (nhi.phan.logic at gmail.com).
+#
+# This file is part of the Virtual JTAG UART toolkit
+#
+# Virtual UART is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+*/
+
+//=======================================================
+// Heartbeat module
+//=======================================================
+`include ""system_include.v""
+
+//=======================================================
+// Module definition
+//=======================================================
+module heartbeat(
+\tinput clk_i,
+\tinput nreset_i,
+\toutput heartbeat_o
+);
+
+//=======================================================
+// Registers
+//=======================================================
+reg [26:0] cntr;
+reg heartbeat;
+
+//=======================================================
+// Output assignments
+//=======================================================
+
+assign heartbeat_o = heartbeat;
+
+//=======================================================
+// Procedural logic
+//=======================================================
+
+always @(posedge clk_i)
+begin
+\tif (!nreset_i)
+\tbegin
+\t\tcntr = 0;
+\t\theartbeat = 0;
+\tend else\tbegin
+\t\tcntr = cntr + 1\'b1;
+\t\tif( cntr == 27\'d100000000 )
+\t\tbegin
+\t\t\tcntr = 0;
+\t\t\theartbeat = !heartbeat;
+\t\tend
+\tend
+end
+
+
+endmodule
+"
+"// megafunction wizard: %Virtual JTAG%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: sld_virtual_jtag
+
+// ============================================================
+// File Name: vjtag.v
+// Megafunction Name(s):
+// \t\t\tsld_virtual_jtag
+//
+// Simulation Library Files(s):
+// \t\t\t
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 13.1.4 Build 182 03/12/2014 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2014 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module vjtag (
+\tir_out,
+\ttdo,
+\tir_in,
+\ttck,
+\ttdi,
+\tvirtual_state_cdr,
+\tvirtual_state_cir,
+\tvirtual_state_e1dr,
+\tvirtual_state_e2dr,
+\tvirtual_state_pdr,
+\tvirtual_state_sdr,
+\tvirtual_state_udr,
+\tvirtual_state_uir);
+
+\tinput\t[1:0] ir_out;
+\tinput\t tdo;
+\toutput\t[1:0] ir_in;
+\toutput\t tck;
+\toutput\t tdi;
+\toutput\t virtual_state_cdr;
+\toutput\t virtual_state_cir;
+\toutput\t virtual_state_e1dr;
+\toutput\t virtual_state_e2dr;
+\toutput\t virtual_state_pdr;
+\toutput\t virtual_state_sdr;
+\toutput\t virtual_state_udr;
+\toutput\t virtual_state_uir;
+
+\twire sub_wire0;
+\twire sub_wire1;
+\twire [1:0] sub_wire2;
+\twire sub_wire3;
+\twire sub_wire4;
+\twire sub_wire5;
+\twire sub_wire6;
+\twire sub_wire7;
+\twire sub_wire8;
+\twire sub_wire9;
+\twire sub_wire10;
+\twire virtual_state_cir = sub_wire0;
+\twire virtual_state_pdr = sub_wire1;
+\twire [1:0] ir_in = sub_wire2[1:0];
+\twire tdi = sub_wire3;
+\twire virtual_state_udr = sub_wire4;
+\twire tck = sub_wire5;
+\twire virtual_state_e1dr = sub_wire6;
+\twire virtual_state_uir = sub_wire7;
+\twire virtual_state_cdr = sub_wire8;
+\twire virtual_state_e2dr = sub_wire9;
+\twire virtual_state_sdr = sub_wire10;
+
+\tsld_virtual_jtag\tsld_virtual_jtag_component (
+\t\t\t\t.ir_out (ir_out),
+\t\t\t\t.tdo (tdo),
+\t\t\t\t.virtual_state_cir (sub_wire0),
+\t\t\t\t.virtual_state_pdr (sub_wire1),
+\t\t\t\t.ir_in (sub_wire2),
+\t\t\t\t.tdi (sub_wire3),
+\t\t\t\t.virtual_state_udr (sub_wire4),
+\t\t\t\t.tck (sub_wire5),
+\t\t\t\t.virtual_state_e1dr (sub_wire6),
+\t\t\t\t.virtual_state_uir (sub_wire7),
+\t\t\t\t.virtual_state_cdr (sub_wire8),
+\t\t\t\t.virtual_state_e2dr (sub_wire9),
+\t\t\t\t.virtual_state_sdr (sub_wire10)
+\t\t\t\t// synopsys translate_off
+\t\t\t\t,
+\t\t\t\t.jtag_state_cdr (),
+\t\t\t\t.jtag_state_cir (),
+\t\t\t\t.jtag_state_e1dr (),
+\t\t\t\t.jtag_state_e1ir (),
+\t\t\t\t.jtag_state_e2dr (),
+\t\t\t\t.jtag_state_e2ir (),
+\t\t\t\t.jtag_state_pdr (),
+\t\t\t\t.jtag_state_pir (),
+\t\t\t\t.jtag_state_rti (),
+\t\t\t\t.jtag_state_sdr (),
+\t\t\t\t.jtag_state_sdrs (),
+\t\t\t\t.jtag_state_sir (),
+\t\t\t\t.jtag_state_sirs (),
+\t\t\t\t.jtag_state_tlr (),
+\t\t\t\t.jtag_state_udr (),
+\t\t\t\t.jtag_state_uir (),
+\t\t\t\t.tms ()
+\t\t\t\t// synopsys translate_on
+\t\t\t\t);
+\tdefparam
+\t\tsld_virtual_jtag_component.sld_auto_instance_index = ""NO"",
+\t\tsld_virtual_jtag_component.sld_instance_index = 0,
+\t\tsld_virtual_jtag_component.sld_ir_width = 2,
+\t\tsld_virtual_jtag_component.sld_sim_action = ""((0,2,0,4),(0,1,1,2),(0,2,12,8),(0,2,34,8),(0,2,56,8),(0,1,0,2),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8))"",
+\t\tsld_virtual_jtag_component.sld_sim_n_scan = 41,
+\t\tsld_virtual_jtag_component.sld_sim_total_length = 312;
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone IV E""
+// Retrieval info: PRIVATE: show_jtag_state STRING ""0""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: SLD_AUTO_INSTANCE_INDEX STRING ""NO""
+// Retrieval info: CONSTANT: SLD_INSTANCE_INDEX NUMERIC ""0""
+// Retrieval info: CONSTANT: SLD_IR_WIDTH NUMERIC ""2""
+// Retrieval info: CONSTANT: SLD_SIM_ACTION STRING ""((0,2,0,4),(0,1,1,2),(0,2,12,8),(0,2,34,8),(0,2,56,8),(0,1,0,2),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8))""
+// Retrieval info: CONSTANT: SLD_SIM_N_SCAN NUMERIC ""41""
+// Retrieval info: CONSTANT: SLD_SIM_TOTAL_LENGTH NUMERIC ""312""
+// Retrieval info: USED_PORT: ir_in 0 0 2 0 OUTPUT NODEFVAL ""ir_in[1..0]""
+// Retrieval info: USED_PORT: ir_out 0 0 2 0 INPUT NODEFVAL ""ir_out[1..0]""
+// Retrieval info: USED_PORT: tck 0 0 0 0 OUTPUT NODEFVAL ""tck""
+// Retrieval info: USED_PORT: tdi 0 0 0 0 OUTPUT NODEFVAL ""tdi""
+// Retrieval info: USED_PORT: tdo 0 0 0 0 INPUT NODEFVAL ""tdo""
+// Retrieval info: USED_PORT: virtual_state_cdr 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_cdr""
+// Retrieval info: USED_PORT: virtual_state_cir 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_cir""
+// Retrieval info: USED_PORT: virtual_state_e1dr 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_e1dr""
+// Retrieval info: USED_PORT: virtual_state_e2dr 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_e2dr""
+// Retrieval info: USED_PORT: virtual_state_pdr 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_pdr""
+// Retrieval info: USED_PORT: virtual_state_sdr 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_sdr""
+// Retrieval info: USED_PORT: virtual_state_udr 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_udr""
+// Retrieval info: USED_PORT: virtual_state_uir 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_uir""
+// Retrieval info: CONNECT: @ir_out 0 0 2 0 ir_out 0 0 2 0
+// Retrieval info: CONNECT: @tdo 0 0 0 0 tdo 0 0 0 0
+// Retrieval info: CONNECT: ir_in 0 0 2 0 @ir_in 0 0 2 0
+// Retrieval info: CONNECT: tck 0 0 0 0 @tck 0 0 0 0
+// Retrieval info: CONNECT: tdi 0 0 0 0 @tdi 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_cdr 0 0 0 0 @virtual_state_cdr 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_cir 0 0 0 0 @virtual_state_cir 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_e1dr 0 0 0 0 @virtual_state_e1dr 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_e2dr 0 0 0 0 @virtual_state_e2dr 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_pdr 0 0 0 0 @virtual_state_pdr 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_sdr 0 0 0 0 @virtual_state_sdr 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_udr 0 0 0 0 @virtual_state_udr 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_uir 0 0 0 0 @virtual_state_uir 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL vjtag.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL vjtag.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL vjtag.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL vjtag.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL vjtag_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL vjtag_bb.v TRUE
+"
+"// megafunction wizard: %Virtual JTAG%VBB%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: sld_virtual_jtag
+
+// ============================================================
+// File Name: vjtag.v
+// Megafunction Name(s):
+// \t\t\tsld_virtual_jtag
+//
+// Simulation Library Files(s):
+// \t\t\t
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 13.1.4 Build 182 03/12/2014 SJ Web Edition
+// ************************************************************
+
+//Copyright (C) 1991-2014 Altera Corporation
+//Your use of Altera Corporation\'s design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+module vjtag (
+\tir_out,
+\ttdo,
+\tir_in,
+\ttck,
+\ttdi,
+\tvirtual_state_cdr,
+\tvirtual_state_cir,
+\tvirtual_state_e1dr,
+\tvirtual_state_e2dr,
+\tvirtual_state_pdr,
+\tvirtual_state_sdr,
+\tvirtual_state_udr,
+\tvirtual_state_uir);
+
+\tinput\t[1:0] ir_out;
+\tinput\t tdo;
+\toutput\t[1:0] ir_in;
+\toutput\t tck;
+\toutput\t tdi;
+\toutput\t virtual_state_cdr;
+\toutput\t virtual_state_cir;
+\toutput\t virtual_state_e1dr;
+\toutput\t virtual_state_e2dr;
+\toutput\t virtual_state_pdr;
+\toutput\t virtual_state_sdr;
+\toutput\t virtual_state_udr;
+\toutput\t virtual_state_uir;
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING ""Cyclone IV E""
+// Retrieval info: PRIVATE: show_jtag_state STRING ""0""
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: SLD_AUTO_INSTANCE_INDEX STRING ""NO""
+// Retrieval info: CONSTANT: SLD_INSTANCE_INDEX NUMERIC ""0""
+// Retrieval info: CONSTANT: SLD_IR_WIDTH NUMERIC ""2""
+// Retrieval info: CONSTANT: SLD_SIM_ACTION STRING ""((0,2,0,4),(0,1,1,2),(0,2,12,8),(0,2,34,8),(0,2,56,8),(0,1,0,2),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8),(0,2,0,8))""
+// Retrieval info: CONSTANT: SLD_SIM_N_SCAN NUMERIC ""41""
+// Retrieval info: CONSTANT: SLD_SIM_TOTAL_LENGTH NUMERIC ""312""
+// Retrieval info: USED_PORT: ir_in 0 0 2 0 OUTPUT NODEFVAL ""ir_in[1..0]""
+// Retrieval info: USED_PORT: ir_out 0 0 2 0 INPUT NODEFVAL ""ir_out[1..0]""
+// Retrieval info: USED_PORT: tck 0 0 0 0 OUTPUT NODEFVAL ""tck""
+// Retrieval info: USED_PORT: tdi 0 0 0 0 OUTPUT NODEFVAL ""tdi""
+// Retrieval info: USED_PORT: tdo 0 0 0 0 INPUT NODEFVAL ""tdo""
+// Retrieval info: USED_PORT: virtual_state_cdr 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_cdr""
+// Retrieval info: USED_PORT: virtual_state_cir 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_cir""
+// Retrieval info: USED_PORT: virtual_state_e1dr 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_e1dr""
+// Retrieval info: USED_PORT: virtual_state_e2dr 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_e2dr""
+// Retrieval info: USED_PORT: virtual_state_pdr 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_pdr""
+// Retrieval info: USED_PORT: virtual_state_sdr 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_sdr""
+// Retrieval info: USED_PORT: virtual_state_udr 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_udr""
+// Retrieval info: USED_PORT: virtual_state_uir 0 0 0 0 OUTPUT NODEFVAL ""virtual_state_uir""
+// Retrieval info: CONNECT: @ir_out 0 0 2 0 ir_out 0 0 2 0
+// Retrieval info: CONNECT: @tdo 0 0 0 0 tdo 0 0 0 0
+// Retrieval info: CONNECT: ir_in 0 0 2 0 @ir_in 0 0 2 0
+// Retrieval info: CONNECT: tck 0 0 0 0 @tck 0 0 0 0
+// Retrieval info: CONNECT: tdi 0 0 0 0 @tdi 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_cdr 0 0 0 0 @virtual_state_cdr 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_cir 0 0 0 0 @virtual_state_cir 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_e1dr 0 0 0 0 @virtual_state_e1dr 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_e2dr 0 0 0 0 @virtual_state_e2dr 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_pdr 0 0 0 0 @virtual_state_pdr 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_sdr 0 0 0 0 @virtual_state_sdr 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_udr 0 0 0 0 @virtual_state_udr 0 0 0 0
+// Retrieval info: CONNECT: virtual_state_uir 0 0 0 0 @virtual_state_uir 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL vjtag.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL vjtag.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL vjtag.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL vjtag.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL vjtag_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL vjtag_bb.v TRUE
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_misc_plugin_init;
+\t\t\tstardict_misc_plugin_on_mainwin_finish;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_netdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_virtualdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_tts_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_virtualdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_parsedata_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_tts_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_parsedata_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_virtualdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_virtualdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_parsedata_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_specialdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_parsedata_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_virtualdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_virtualdict_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"{
+\tglobal:
+\t\textern ""C"" {
+\t\t\tstardict_plugin_init;
+\t\t\tstardict_plugin_exit;
+\t\t\tstardict_parsedata_plugin_init;
+\t\t};
+\tlocal:
+\t\t*;
+};
+"
+"`timescale 1ns / 1ps
+`define intN 8
+`include ""primitives.v""
+`include ""algorithm_gcd.v""
+
+module top(
+ input clk,
+ input [15:0] in,
+ output [15:0] out
+ );
+
+ reg `intT a;
+ reg `intT b;
+ wire `intT a_in = in[7:0];
+ wire `intT b_in = in[15:8];
+ wire `intT c;
+ reg in_valid;
+
+ always @(posedge clk) begin
+ if(a != a_in || b != b_in)
+ begin
+ a <= a_in;
+ b <= b_in;
+ `set(in_valid);
+ end
+ else
+ begin
+ `reset(in_valid);
+ end
+ end
+
+ wire gcd_in_ready;
+ `inst_sync(algorithm_gcd, gcd, #())(`sync(in_valid, `true), .in0(a), .in1(b), .out0(c));
+
+ assign out = {in_valid, gcd_out_valid, ~gcd_in_ready, 5\'d0, c};
+
+endmodule
+"
+"`timescale 1ns / 1ps
+`define intN 16
+`include ""primitives.v""
+`include ""tests_fibl.v""
+
+module tests_fibl_tb;
+
+ reg `intT a;
+ wire `intT b;
+
+ `testbench(tests_fibl_tb, 30)
+
+ `in_ready(tests_fibl);
+ `inst_sync(tests_fibl, tests_fibl, #())(`sync(in_valid, out_ready), .in0(a), .out0(b));
+
+ initial begin
+ a = 21;
+ `start;
+
+ `wait_for(tests_fibl_out_valid);
+ $display(""b = %b (%d)"", b, b);
+ $finish;
+ end
+
+endmodule // tests_fibl_tb
+"
+"`timescale 1ns / 1ps
+`define intN 8
+`include ""primitives.v""
+`include ""tests_repeat_int.v""
+
+module tests_repeat_int_tb;
+
+ `reg(simple, `intN, dIn);
+ `wire(stream, `intN, sOut);
+ assign sOut_ready = out_ready;
+
+ `testbench(tests_repeat_int_tb, 100)
+
+ `in_ready(repeat_int);
+ `inst_sync(tests_repeat_int, repeat_int, #())(`sync(in_valid, out_ready), `in(simple, 0, dIn), `out(stream, 0, sOut));
+
+ initial begin
+ dIn = 42;
+ `start;
+
+ #1; dIn = 0;
+
+ #5; $display(""sOut = %b (%d)"", sOut, sOut);
+
+ $finish;
+ end
+
+endmodule
+"
+"`include ""tests_collatz_swbut.v""
+
+module tests_collatz_swbut_tb;
+ reg clk = 0;
+ wire [15:0] in = 16\'b1000_0000_0000_0001;
+ wire [15:0] out;
+
+ always begin
+ #0.5 clk = !clk;
+ end
+
+ initial begin
+ $dumpfile(`dumpfile);
+ $dumpvars(0, tests_collatz_swbut_tb);
+
+ #100000;
+ $finish;
+ end
+
+ top top(.clk(clk), .in(in), .out(out));
+endmodule
+"
+"`timescale 1ns / 1ps
+`define intN 32
+`define addrN 4
+`include ""primitives.v""
+`include ""tests_stream_compute_fn.v""
+`include ""array.v""
+
+module tests_stream_compute_fn_tb;
+
+ localparam N = 16;
+
+ `wire(Array, (`addrN, `intN), arr);
+ wire `intT res;
+ integer write_seed = 21;
+ integer read_seed = 42;
+
+ `reg(stream, `intN, sRA);
+ `wire(stream, `intN, sR);
+ `reg(stream, `intN, sWA);
+ `reg(stream, `intN, sW);
+ `wire(stream, 1, sB);
+ `wire(stream, 1, sC);
+
+ assign sR_ready = out_ready;
+ assign sB_ready = out_ready;
+ assign sC_ready = out_ready;
+
+ integer counter = 0;
+
+ `testbench(tests_stream_compute_fn_tb, 15.45)
+
+ // Use bit 31 to indicate that data is invalid
+ array #(.N(N), .INIT_ADDR(0), .INIT(0))
+ array(.clk(clk),
+ `out(Array, 0, arr));
+
+ `in_ready(inst);
+ `inst_sync(tests_stream_compute_fn, inst, #())(
+ `sync(in_valid, out_ready),
+ `in(Array, 0, arr),
+ `in(stream, 1, sRA),
+ `in(stream, 2, sWA),
+ `in(stream, 3, sW),
+ `out(stream, 0, sR),
+ `out(null_stream, 1, sB),
+ `out(null_stream, 2, sC));
+
+ integer i;
+ integer start_time = 0;
+ integer max_time = 0;
+ integer write_time = 0;
+ integer max_addr = 0;
+ initial begin
+ sRA = 0;
+ sRA_valid = `false;
+ sWA = 0;
+ sWA_valid = `false;
+ sW = 0;
+ sW_valid = `false;
+ `start;
+
+ // write some data
+ for(i = 0; i < N; i = i + 1) begin
+ start_time = counter;
+ sWA = i;
+ sWA_valid = `true;
+ sW = i + 1;
+ sW_valid = `true;
+ `wait_for(sWA_ready && sW_ready);
+ write_time = counter - start_time;
+ if(write_time > max_time) begin
+ max_time = write_time;
+ max_addr = i;
+ end
+ if($random(write_seed) & 1) begin
+ sWA_valid = `false;
+ sW_valid = `false;
+ @(posedge clk);
+ sWA_valid = `true;
+ sW_valid = `true;
+ end
+ end
+ sWA_valid = `false;
+ sW_valid = `false;
+ `wait_for(sRA >= N-1 && sR_valid);
+ nrst = `false;
+ #2;
+ $display(""done @ %d"", counter);
+ $display(""max write time = %d @ %d"", max_time, max_addr);
+ $finish;
+ end
+
+always @(posedge clk) begin
+ counter <= counter + 1;
+ if(sRA_ready) begin
+ sRA_valid <= $random(read_seed);
+ end
+ if(sR_valid & sR[31]) begin
+ $display(""arr(%d) = %d"", sRA, sR[30:0]);
+ sRA <= sRA + 1;
+ end
+end
+
+endmodule // tests_stream_compute_fn_tb
+"
+"`timescale 1ns / 1ps
+`define intN 8
+`include ""primitives.v""
+`include ""algorithm_gcd.v""
+
+module algorithm_gcd_tb;
+
+ reg `intT a;
+ reg `intT b;
+ wire `intT c;
+
+ `testbench(algorithm_gcd_tb, 20)
+
+ `in_ready(gcd);
+ `inst_sync(algorithm_gcd, gcd, #())(`sync(in_valid, out_ready), .in0(a), .in1(b), .out0(c));
+
+ initial begin
+ a = 21;
+ b = 35;
+ `start;
+
+ `wait_for(gcd_out_valid);
+ $display(""c = %b (%d)"", c, c);
+ $finish;
+ end
+
+endmodule // gcd_tb
+"
+"`timescale 1ns / 1ps
+`define intN 8
+`define addrN 8
+`include ""primitives.v""
+`include ""io_stream_read_write_array.v""
+`include ""array.v""
+
+module io_stream_read_write_array_tb;
+
+ localparam N = 255;
+
+ `wire(Array, (`addrN, `intN), arr);
+ wire `intT res;
+ integer write_seed = 21;
+ integer read_seed = 42;
+
+ `reg(stream, `intN, sRA);
+ `wire(stream, `intN, sR);
+ `reg(stream, `intN, sWA);
+ `reg(stream, `intN, sW);
+ `wire(stream, 1, sB);
+ reg `intT sRA_next;
+
+ assign sR_ready = out_ready;
+ assign sB_ready = out_ready;
+
+ `testbench(io_stream_read_write_array_tb, 1000)
+
+ array #(.N(N))
+ array(.clk(clk),
+ `out(Array, 0, arr));
+
+ `in_ready(inst);
+ `inst_sync(io_stream_read_write_array, inst, #())(
+ `sync(in_valid, out_ready),
+ `in(Array, 0, arr),
+ `in(stream, 1, sRA),
+ `in(stream, 2, sWA),
+ `in(stream, 3, sW),
+ `out(stream, 0, sR),
+ `out(null_stream, 1, sB));
+
+ reg `addrT i;
+ initial begin
+ sRA = 0;
+ sRA_next = 0;
+ sRA_valid = `true;
+ sWA = 0;
+ sWA_valid = `false;
+ sW = 0;
+ sW_valid = `false;
+ `start;
+
+ // write some data
+ for(i = 0; i < N; i = i + 1) begin
+ sWA = i;
+ sWA_valid = `true;
+ sW = (i * 7) & 8\'h7f;
+ sW_valid = `true;
+ `wait_for(sWA_ready && sW_ready);
+ if($random(write_seed) & 1) begin
+ sWA_valid = `false;
+ sW_valid = `false;
+ @(posedge clk);
+ sWA_valid = `true;
+ sW_valid = `true;
+ end
+ end
+ sWA_valid = `false;
+ sW_valid = `false;
+ sWA = N;
+ `wait_for(sRA == N-1 && sR_valid);
+ nrst = `false;
+ #2;
+ $display(""done"");
+ $finish;
+ end
+
+always @(posedge clk) begin
+ if(sRA_ready) begin
+ if(sRA_next < sWA & ($random(read_seed) & 1)) begin
+ sRA <= sRA_next;
+ sRA_next <= sRA_next + 1;
+ end
+ end
+ if(sR_valid & sR != ((sRA * 7) & 8\'h7f))
+ $display(""MISMATCH arr(%d) = %d"", sRA, sR);
+end
+
+endmodule // io_stream_read_write_array_tb
+"
+"`timescale 1ns / 1ps
+`define intN 32
+`define addrN 9
+`include ""primitives.v""
+
+`define axi_module tests_axil_map_w
+`include ""tests_axil_map_w.v""
+
+`include ""array.v""
+
+module tests_axi_lite_slave_top
+(
+ input wire s_axi_aclk,
+ input wire s_axi_aresetn,
+ input wire [8:0] s_axi_awaddr,
+ input wire s_axi_awvalid,
+ output wire s_axi_awready,
+ input wire [31:0] s_axi_wdata,
+ input wire [3:0] s_axi_wstrb,
+ input wire s_axi_wvalid,
+ output wire s_axi_wready,
+ output wire [1:0] s_axi_bresp,
+ output wire s_axi_bvalid,
+ input wire s_axi_bready,
+ input wire [8:0] s_axi_araddr,
+ input wire s_axi_arvalid,
+ output wire s_axi_arready,
+ output wire [31:0] s_axi_rdata,
+ output wire [1:0] s_axi_rresp,
+ output wire s_axi_rvalid,
+ input wire s_axi_rready
+);
+
+ wire clk = s_axi_aclk;
+ wire nrst = s_axi_aresetn;
+
+ `wire(Array, (`addrN, `intN), arr);
+
+ array #(.N(64))
+ arr(.clk(clk),
+ `out(Array, 0, arr));
+
+ `wire(stream, `addrN, ar);
+ `wire(stream, `addrN, aw);
+ `wire(stream, `intN , w);
+ `wire(stream, `intN , r);
+ `wire(null_stream, 0, b);
+
+ wire inst_in_ready;
+ `inst_sync(`id(`axi_module), inst, #())(
+ `sync(`true, `true),
+ `in(Array, 0, arr),
+ `in(stream, 1, ar),
+ `in(stream, 2, aw),
+ `in(stream, 3, w),
+ `out(stream, 0, r),
+ `out(null_stream, 1, b));
+
+`define from_axi_hs(stream) \\
+ assign stream``_valid = s_axi_``stream``valid; \\
+ assign s_axi_``stream``ready = stream``_ready
+
+`define from_axi(stream, signal, shift) \\
+ assign stream = s_axi_``stream``signal >> shift; \\
+ `from_axi_hs(stream)
+
+`define to_axi_hs(stream) \\
+ assign s_axi_``stream``valid = stream``_valid; \\
+ assign stream``_ready = s_axi_``stream``ready
+
+`define to_axi(stream, signal) \\
+ assign s_axi_``stream``signal = stream; \\
+ `to_axi_hs(stream)
+
+ `from_axi(ar, addr, 2);
+ `from_axi(aw, addr, 2);
+ `from_axi(w, data, 0);
+ `to_axi(r, data);
+ `to_axi_hs(b);
+
+ assign s_axi_wstrb = 4\'b1111;
+ assign s_axi_bresp = 2\'b00; // OKAY
+ assign s_axi_rresp = 2\'b00; // OKAY
+
+endmodule // tests_axi_lite_slave_top
+"
+"`timescale 1ns / 1ps
+`define intN 8
+`define addrN 8
+`include ""primitives.v""
+`include ""io_stream_read_array.v""
+`include ""array.v""
+
+module io_stream_read_array_tb;
+
+ `wire(Array, (`addrN, `intN), arr);
+ `reg(stream, `intN, sIn);
+ `wire(stream, `intN, sOut);
+ assign sOut_ready = out_ready;
+
+ `testbench(io_stream_read_array_tb, 100)
+
+ array array(.clk(clk),
+ `out(Array, 0, arr));
+
+ `in_ready(inst);
+ `inst_sync(io_stream_read_array, inst, #())(
+ `sync(in_valid, out_ready),
+ `in(Array, 0, arr),
+ `in(stream, 1, sIn),
+ `out(stream, 0, sOut));
+
+ initial begin
+ `start;
+ sIn = 0;
+ sIn_valid = `true;
+ end
+
+ always @(posedge clk) begin
+ if(sIn_ready & sIn_valid) begin
+ sIn <= (sIn + 1) % 16;
+ end
+ if(sOut_valid) begin
+ $display(""out0 = %d"", sOut);
+ if(sOut == 15) begin
+ $display(""done"");
+ $finish;
+ end
+ end
+ end
+
+endmodule // io_stream_read_array_tb
+"
+"`timescale 1ns / 1ps
+`define intN 8
+`include ""primitives.v""
+`include ""tests_zip_add.v""
+
+module tests_zip_add_tb;
+
+ `reg(stream, `intN, sInA);
+ `reg(stream, `intN, sInB);
+ `wire(stream, `intN, sOut);
+ assign sOut_ready = out_ready;
+
+ `testbench(tests_zip_add_tb, 100)
+
+ `in_ready(zip_add);
+ `inst_sync(tests_zip_add, zip_add, #())(
+ `sync(in_valid, out_ready),
+ `in(stream, 0, sInA),
+ `in(stream, 1, sInB),
+ `out(stream, 0, sOut));
+
+ always @(posedge clk) begin
+ if(sInA_valid) begin
+ if(sInA_ready) sInA <= sInA + 1;
+ if(sInB_ready) sInB <= sInB + 2;
+ sInB_valid <= !sInB_valid;
+ end
+ if(sOut_valid) begin
+ $display(""sInA = %b (%d), sInB = %b (%d), sOut = %b (%d)"",
+ sInA, sInA, sInB, sInB, sOut, sOut);
+ end
+ end
+
+ initial begin
+ `start;
+ sInA = 0;
+ sInB = 0;
+ sInA_valid = `true;
+ sInB_valid = `true;
+
+ #10;
+ $finish;
+ end
+
+endmodule
+"
+"`timescale 1ns / 1ps
+`define intN 32
+`define addrN 9
+`include ""primitives.v""
+
+`define axi_module tests_stream_compute_fn
+`include ""tests_stream_compute_fn.v""
+
+`include ""array.v""
+
+module tests_axi_lite_slave_top
+(
+ input wire s_axi_aclk,
+ input wire s_axi_aresetn,
+ input wire `addrT s_axi_awaddr,
+ input wire s_axi_awvalid,
+ output wire s_axi_awready,
+ input wire `intT s_axi_wdata,
+ input wire [3:0] s_axi_wstrb,
+ input wire s_axi_wvalid,
+ output wire s_axi_wready,
+ output wire [1:0] s_axi_bresp,
+ output wire s_axi_bvalid,
+ input wire s_axi_bready,
+ input wire `addrT s_axi_araddr,
+ input wire s_axi_arvalid,
+ output wire s_axi_arready,
+ output wire `intT s_axi_rdata,
+ output wire [1:0] s_axi_rresp,
+ output wire s_axi_rvalid,
+ input wire s_axi_rready
+);
+
+ wire clk = s_axi_aclk;
+ wire nrst = s_axi_aresetn;
+
+ `wire(Array, (`addrN, `intN), arr);
+
+ array #(.N(2048))
+ arr(.clk(clk),
+ `out(Array, 0, arr));
+
+ `wire(stream, `addrN, ar);
+ `wire(stream, `addrN, aw);
+ `wire(stream, `intN , w);
+ `wire(stream, `intN , r);
+ `wire(null_stream, 0, b);
+
+ wire inst_in_ready;
+ `inst_sync(`id(`axi_module), inst, #())(
+ `sync(`true, `true),
+ `in(Array, 0, arr),
+ `in(stream, 1, ar),
+ `in(stream, 2, aw),
+ `in(stream, 3, w),
+ `out(stream, 0, r),
+ `out(null_stream, 1, b));
+
+`define from_axi_hs(stream) \\
+ assign stream``_valid = s_axi_``stream``valid; \\
+ assign s_axi_``stream``ready = stream``_ready
+
+`define from_axi(stream, signal, shift) \\
+ assign stream = s_axi_``stream``signal >> shift; \\
+ `from_axi_hs(stream)
+
+`define to_axi_hs(stream) \\
+ assign s_axi_``stream``valid = stream``_valid; \\
+ assign stream``_ready = s_axi_``stream``ready
+
+`define to_axi(stream, signal) \\
+ assign s_axi_``stream``signal = stream; \\
+ `to_axi_hs(stream)
+
+ `from_axi(ar, addr, 2);
+ `from_axi(aw, addr, 2);
+ `from_axi(w, data, 0);
+ `to_axi(r, data);
+ `to_axi_hs(b);
+
+ assign s_axi_wstrb = 4\'b1111;
+ assign s_axi_bresp = 2\'b00; // OKAY
+ assign s_axi_rresp = 2\'b00; // OKAY
+
+endmodule // tests_axi_lite_slave_top
+"
+"`timescale 1ns / 1ps
+`define intN 8
+`include ""primitives.v""
+`include ""tests_dup_map.v""
+
+module tests_dup_map_tb;
+
+ `reg(stream, `intN, sIn);
+ `wire(stream, `intN, sOut);
+ assign sOut_ready = out_ready;
+
+ `testbench(tests_dup_map_tb, 100)
+
+ `in_ready(dup_map);
+ `inst_sync(tests_dup_map, dup_map, #())(`sync(in_valid, out_ready), `in(stream, 0, sIn), `out(stream, 0, sOut));
+
+ always @(posedge clk) begin
+ if(sIn_ready) sIn <= sIn + 1;
+ end
+
+ initial begin
+ `start;
+ sIn = 0;
+ sIn_valid = `true;
+
+ #20;
+ // TODO: print a result
+ $finish;
+ end
+
+endmodule
+"
+"`timescale 1ns / 1ps
+`define intN 8
+`define addrN 8
+`include ""primitives.v""
+`include ""tests_three_reads.v""
+`include ""array.v""
+
+module tests_three_reads_tb;
+
+ `wire(Array, (`addrN, `intN), arr_in);
+ `wire(Array, (`addrN, `intN), arr_out);
+ `reg(simple, `addrN, addr1);
+ `reg(simple, `addrN, addr2);
+ `reg(simple, `addrN, addr3);
+ `wire(simple, `intN, data1);
+ `wire(simple, `intN, data2);
+ `wire(simple, `intN, data3);
+
+ `testbench(tests_three_reads_tb, 100)
+
+ array arr(.clk(clk),
+ `out(Array, 0, arr_in));
+ assign `to_bus(arr_out) = 0;
+
+ `in_ready(inst);
+ `inst_sync(tests_three_reads, inst, #())(
+ `sync(in_valid, out_ready),
+ `in(Array, 0, arr_in),
+ `in(simple, 1, addr1),
+ `in(simple, 2, addr2),
+ `in(simple, 3, addr3),
+ `out(Array, 0, arr_out),
+ `out(simple, 1, data1),
+ `out(simple, 2, data2),
+ `out(simple, 3, data3));
+
+ initial begin
+ addr1 = 1;
+ addr2 = 2;
+ addr3 = 3;
+ out_ready = `false;
+ `start;
+
+ `wait_for(inst_out_valid);
+ $display(""data = %d, %d, %d"", data1, data2, data3);
+ @(posedge clk);
+ $finish;
+ end
+
+endmodule // tests_three_reads_tb
+"
+"`timescale 1ns / 1ps
+`define intN 8
+`include ""primitives.v""
+`include ""tests_map_add1.v""
+
+module tests_map_add1_tb;
+
+ `reg(stream, `intN, sIn);
+ `wire(stream, `intN, sOut);
+ assign sOut_ready = out_ready;
+
+ `testbench(tests_map_add1_tb, 20)
+
+ `in_ready(map_add1);
+ `inst_sync(tests_map_add1, map_add1, #())(`sync(in_valid, out_ready), `in(stream, 0, sIn), `out(stream, 0, sOut));
+
+ always @(posedge clk) begin
+ if(sIn_ready) sIn <= sIn + 1;
+ if(sOut_valid) $display(""sIn = %b (%d), sOut = %b (%d)"", sIn, sIn, sOut, sOut);
+ end
+
+ initial begin
+ `start;
+ sIn = 0;
+ sIn_valid = `true;
+
+ #10;
+ $finish;
+ end
+
+endmodule
+"
+"`ifndef __DEFINE__
+`define __DEFINE__
+
+`ifndef intN
+ `define intN 32
+`endif
+
+`ifndef symN
+ `define symN 1
+`endif
+
+`ifndef anyN
+ `define anyN `intN
+`endif
+
+`ifndef addrN
+ `define addrN 16
+`endif
+
+`define intT [`intN-1:0]
+`define symT [`symN-1:0]
+`define anyT [`anyN-1:0]
+`define addrT [`addrN-1:0]
+
+`define sync_ports \\
+ input wire clk, input wire nrst, \\
+ input wire in_valid, output wire in_ready, \\
+ output wire out_valid, input wire out_ready
+
+`define id(x) x
+
+`define concat_(a, b) `id(a)``_``b
+
+`define stringify(x) `""x`""
+
+`define rename(dst, src) wire src; assign dst = src
+
+`define top_sync(ready) \\
+ assign in_ready = ready
+
+`define loop_sync(ready) \\
+ reg active = `false; \\
+ assign in_ready = ~active & ready
+
+`define sync_wire(name) `concat_(`current_inst, name)
+
+`define inst(t, n, p) \\
+ `define current_inst n \\
+ t p t``_``n
+
+`define inst_sync(t, n, p) \\
+ `define current_inst n \\
+ wire `sync_wire(out_valid); \\
+ t p t``_``n
+
+`define apply(f, x) `f x
+
+`define start_block(name) \\
+`define block name \\
+
+`define end_block(name) \\
+`undef block \\
+
+`define sync(valid, ready) \\
+ .clk(clk), \\
+ .nrst(nrst), \\
+ .in_valid(valid), \\
+ .out_valid(`sync_wire(out_valid)), \\
+ .in_ready(`sync_wire(in_ready)), \\
+ .out_ready(ready)
+
+`define fst_(x, y) (x)
+`define snd_(x, y) (y)
+`define fst(p) `fst_``p
+`define snd(p) `snd_``p
+
+`define input(type, N, index) `input_``type(N, index)
+`define input_simple(N, index) input wire [N-1:0] `id(in)``index
+`define output(type, N, index) `output_``type(N, index)
+`define output_simple(N, index) output wire [N-1:0] `id(out)``index
+`define in(type, index, name) `in_``type(index, name)
+`define out(type, index, name) `out_``type(index, name)
+`define in_simple(index, name) .`id(in)``index(name)
+`define out_simple(index, name) .`id(out)``index(name)
+`define alias(type, N, name, index) `alias_``type(N, name, index)
+`define alias_simple(N, name, other) wire [N-1:0] name = other
+`define variable(type, N, name, in) `variable_``type(N, name, in)
+`define variable_simple(N, name, in) reg [N-1:0] name
+`define wire(type, N, name) `wire_``type(N, name)
+`define wire_simple(N, name) wire [N-1:0] name
+`define reg(type, N, name) `reg_``type(N, name)
+`define reg_simple(N, name) reg [N-1:0] name
+`define const(type, N, name, val) `const_``type(N, name, val)
+`define const_simple(N, name, val) localparam [N-1:0] name = val
+
+`define input_stream(N, index) input wire [N-1:0] in``index, input wire in``index``_valid, output wire in``index``_ready
+`define output_stream(N, index) output wire [N-1:0] out``index, output wire out``index``_valid, input wire out``index``_ready
+`define output_null_stream(N, index) output wire out``index``_valid, input wire out``index``_ready
+`define in_stream(index, name) .in``index(name), .in``index``_valid(name``_valid), .in``index``_ready(name``_ready)
+`define in_dup_stream(index, name) .in``index(name), .in``index``_valid(`concat_(`current_inst, name``_valid)), .in``index``_ready(`concat_(`current_inst, name``_ready))
+`define in_null_stream(index, name) .in``index``_valid(name``_valid), .in``index``_ready(name``_ready)
+`define in_dup_null_stream(index, name) .in``index``_valid(`concat_(`current_inst, name``_valid)), .in``index``_ready(`concat_(`current_inst, name``_ready))
+`define out_stream(index, name) .out``index(name), .out``index``_valid(name``_valid), .out``index``_ready(name``_ready)
+`define out_null_stream(index, name) .out``index``_valid(name``_valid), .out``index``_ready(name``_ready)
+`define alias_stream(N, name, other) \\
+ wire [N-1:0] name = other; \\
+ wire name``_valid = other``_valid; wire name``_ready; \\
+ assign other``_ready = name``_ready
+`define variable_stream(N, name, in) \\
+ wire [N-1:0] name = in; \\
+ reg name``_valid_reg; \\
+ wire name``_valid = in``_valid; \\
+ `rename(in``_ready, name``_ready)
+`define wire_stream(N, name) wire [N-1:0] name; wire name``_valid; wire name``_ready
+`define wire_null_stream(N, name) wire name``_valid; wire name``_ready
+`define reg_stream(N, name) reg [N-1:0] name; reg name``_valid; wire name``_ready
+`define const_stream(N, name, val) localparam [N-1:0] name = val; localparam name``_valid = `true
+`define const_nil(name) localparam name = 0; localparam name``_valid = `true; wire name``_ready
+`define null_const_nil(name) localparam name``_valid = `true; wire name``_ready
+
+`define in_alias(name, other) wire name; assign other = name
+`define in_alias_vec(name, other) wire [$bits(other)-1:0] name; assign other = name
+
+`define assign_stream(inst, name) \\
+`in_alias(inst``_``name``_ready, name``_ready); \\
+ wire inst``_``name``_valid = name``_valid
+
+`define assign_Array(inst, name) \\
+ `assign_stream(inst, name); \\
+ `in_alias_vec(inst``_``name``_addr, name``_addr); \\
+ `in_alias_vec(inst``_``name``_di, name``_di); \\
+ `in_alias(inst``_``name``_we, name``_we)
+
+/* ------------------------------------------------------ *
+ ARRAY BUS
+ * ------------------------------------------------------ *
+ addr: address (*)
+ we: write enable (*)
+ di: data in (*)
+ (no suffix): data out
+ valid: data out is valid
+ ready: ready for data
+
+ NOTES:
+ -> when not ready, pass back signals:
+ addr, we, di, and ready
+ -> (*) => must be valid when ready
+ -> addr, we & di must be terminated low
+ to allow OR\'ing and selecting with valid
+ * ------------------------------------------------------ */
+
+// master
+`define input_Array(N, index) \\
+ output wire [`fst(N)-1:0] in``index``_addr, \\
+ output wire in``index``_we, \\
+ output wire [`snd(N)-1:0] in``index``_di, \\
+ input wire [`snd(N)-1:0] in``index, \\
+ input wire in``index``_valid, \\
+ output wire in``index``_ready
+
+// slave
+`define output_Array(N, index) \\
+ input wire [`fst(N)-1:0] out``index``_addr, \\
+ input wire out``index``_we, \\
+ input wire [`snd(N)-1:0] out``index``_di, \\
+ output wire [`snd(N)-1:0] out``index, \\
+ output wire out``index``_valid, \\
+ input wire out``index``_ready
+
+`define in_Array(index, name) \\
+ .in``index``_addr(name``_addr), \\
+ .in``index``_we(name``_we), \\
+ .in``index``_di(name``_di), \\
+ .in``index(name), \\
+ .in``index``_valid(name``_valid), \\
+ .in``index``_ready(name``_ready)
+
+`define in_dup_Array(index, name) \\
+ .in``index``_addr(`concat_(`current_inst, name``_addr)), \\
+ .in``index``_we(`concat_(`current_inst, name``_we)), \\
+ .in``index``_di(`concat_(`current_inst, name``_di)), \\
+ .in``index(name), \\
+ .in``index``_valid(`concat_(`current_inst, name``_valid)), \\
+ .in``index``_ready(`concat_(`current_inst, name``_ready))
+
+`define out_Array(index, name) \\
+ .out``index``_addr(name``_addr), \\
+ .out``index``_we(name``_we), \\
+ .out``index``_di(name``_di), \\
+ .out``index(name), \\
+ .out``index``_valid(name``_valid), \\
+ .out``index``_ready(name``_ready)
+
+`define wire_Array(N, name) \\
+ wire [`fst(N)-1:0] name``_addr; \\
+ wire name``_we; \\
+ wire [`snd(N)-1:0] name``_di; \\
+ wire [`snd(N)-1:0] name; \\
+ wire name``_valid; \\
+ wire name``_ready
+
+`define alias_Array(N, name, other) \\
+ wire [`fst(N)-1:0] name``_addr; \\
+ assign other``_addr = name``_addr; \\
+ wire name``_we; \\
+ assign other``_we = name``_we; \\
+ wire [`snd(N)-1:0] name``_di; \\
+ assign other``_di = name``_di; \\
+ wire [`snd(N)-1:0] name = other; \\
+ wire name``_valid = other``_valid; \\
+ wire name``_ready; \\
+ assign other``_ready = name``_ready
+
+`define to_bus(name) {name``_addr, name``_we, name``_di, name``_ready}
+
+`define true 1\'b1
+`define false 1\'b0
+`define nil (~(`intN\'d0))
+
+`define assert(n, x) \\
+ `define current_inst n \\
+ wire `sync_wire(out_valid) = (x)
+
+`define set(x) x <= `true
+`define reset(x) x <= `false
+
+`define valid(x) (! (& x))
+
+`define returned_to(name) (returned && return_addr == label_``name)
+
+// make sure all labels are declared
+`default_nettype none
+
+`define testbench(tb_name, timeout) \\
+ reg in_valid = 0; \\
+ reg out_ready = 1; \\
+ reg nrst = 0; \\
+ reg clk = 0; \\
+ reg start = 0; \\
+ always begin \\
+ #0.5 clk = !clk; \\
+ end \\
+ initial begin \\
+ $dumpfile(`dumpfile); \\
+ $dumpvars(0, tb_name); \\
+ # timeout; \\
+ $display(""timed out""); \\
+ $finish; \\
+ end \\
+ always @(posedge clk) begin \\
+ if(in_ready & in_valid) begin \\
+ `reset(in_valid); \\
+ end \\
+ end
+
+`define wait_for(valid) \\
+ @(posedge clk); \\
+ while(!(valid)) @(posedge clk)
+
+`define in_ready(inst) \\
+ wire inst``_in_ready; \\
+ wire in_ready = inst``_in_ready
+
+`define start \\
+ @(posedge clk); \\
+ nrst = `false; \\
+ @(posedge clk); \\
+ nrst = `true; \\
+ @(posedge clk); \\
+ #0.01 in_valid = `true
+
+`endif
+
+`define dup_signals_stream(N, inst, name) \\
+ wire inst``_``name``_valid; \\
+ wire inst``_``name``_ready
+
+`define dup_signals_Array(N, inst, name) \\
+ wire inst``_``name``_valid; \\
+ wire inst``_``name``_ready; \\
+ wire [`fst(N)-1:0] inst``_``name``_addr; \\
+ wire [`snd(N)-1:0] inst``_``name``_di; \\
+ wire inst``_``name``_we
+
+`define dup_signals(type, N, inst, name) `dup_signals_``type(N, inst, name)
+"
+"`timescale 1ns / 1ps
+`define intN 16
+`include ""primitives.v""
+`include ""tests_fib.v""
+
+module tests_fib_tb;
+
+ reg `intT a;
+ wire `intT b;
+
+ `testbench(tests_fib_tb, 2000)
+
+ `in_ready(tests_fib);
+ `inst_sync(tests_fib, tests_fib, #())(`sync(in_valid, out_ready), .in0(a), .out0(b));
+
+ initial begin
+ a = 10;
+ `start;
+
+ `wait_for(tests_fib_out_valid);
+ $display(""b = %b (%d)"", b, b);
+ $finish;
+ end
+
+endmodule // tests_fib_tb
+"
+"`timescale 1ns / 1ps
+`define intN 27
+`include ""primitives.v""
+`include ""tests_collatz.v""
+
+module top(
+ input clk,
+ input [15:0] in,
+ output [15:0] out
+ );
+
+ reg `intT a = 0;
+ wire `intT a_in = {12\'h0, in[14:0]};
+ wire `intT b;
+ reg [26:0] div = 0;
+ reg [14:0] out_reg = 0;
+ reg in_valid;
+ reg out_ready;
+ wire collatz_in_ready;
+ localparam nrst = `true;
+
+ `inst_sync(tests_collatz, collatz, #())(`sync(in_valid, out_ready), .in0(a), .out0(b));
+
+ assign out = {~collatz_in_ready, out_reg};
+ initial out_ready = `true;
+ initial in_valid = `false;
+
+ always @(posedge clk) begin
+ if(collatz_out_valid) begin
+ out_reg <= b[14:0];
+ end
+ else if(collatz_in_ready) begin
+ if(in[15]) begin
+ div <= div + 1;
+ if(div[26:12] == in[14:0]) begin
+ a <= a + 1;
+ div <= 0;
+ `set(in_valid);
+ end
+ end
+ else if(a != a_in) begin
+ a <= a_in;
+ `set(in_valid);
+ end
+ end
+ if(in_valid) begin
+ `reset(in_valid);
+ end
+ end
+
+endmodule
+"
+"`timescale 1ns / 1ps
+`define intN 8
+`define addrN 8
+`include ""primitives.v""
+`include ""tests_three_writes.v""
+`include ""array.v""
+
+module tests_three_writes_tb;
+
+ `wire(Array, (`addrN, `intN), arr_in);
+ `wire(Array, (`addrN, `intN), arr_out);
+ `reg(simple, `addrN, addr1);
+ `reg(simple, `addrN, addr2);
+ `reg(simple, `addrN, addr3);
+ `reg(simple, `intN, data1);
+ `reg(simple, `intN, data2);
+ `reg(simple, `intN, data3);
+
+ `testbench(tests_three_writes_tb, 20)
+
+ array arr(.clk(clk),
+ `out(Array, 0, arr_in));
+ assign `to_bus(arr_out) = 1;
+
+ always @(posedge clk) begin
+ if(arr_in_valid & arr_in_we & arr_in_ready) begin
+ $display(""arr[%d] <= %d"", arr_in_addr, arr_in_di);
+ end
+ end
+
+ `in_ready(inst);
+ `inst_sync(tests_three_writes, inst, #())(
+ `sync(in_valid, out_ready),
+ `in(Array, 0, arr_in),
+ `in(simple, 1, addr1),
+ `in(simple, 2, data1),
+ `in(simple, 3, addr2),
+ `in(simple, 4, data2),
+ `in(simple, 5, addr3),
+ `in(simple, 6, data3),
+ `out(Array, 0, arr_out));
+
+ initial begin
+ addr1 = 1;
+ data1 = 10;
+ addr2 = 2;
+ data2 = 20;
+ addr3 = 3;
+ data3 = 30;
+ `start;
+
+ `wait_for(arr_out_valid);
+ @(posedge clk);
+ $finish;
+ end
+
+endmodule // tests_three_writes_tb
+"
+"`timescale 1ns / 1ps
+`define intN 8
+`define addrN 8
+`include ""primitives.v""
+`include ""tests_add_array_at.v""
+`include ""array.v""
+
+module tests_add_array_at_tb;
+
+ reg `intT addr;
+ reg `intT val;
+
+ `wire(Array, (`addrN, `intN), arr_in);
+ `wire(Array, (`addrN, `intN), arr_out);
+
+ wire `intT res;
+ assign `to_bus(arr_out) = 0;
+
+ `testbench(tests_add_array_at_tb, 100)
+
+ array arr(.clk(clk),
+ `out(Array, 0, arr_in));
+
+ `in_ready(inst);
+ `inst_sync(tests_add_array_at, inst, #())(
+ `sync(in_valid, out_ready),
+ `in(Array, 0, arr_in),
+ `in(simple, 1, addr),
+ `in(simple, 2, val),
+ `out(Array, 0, arr_out),
+ `out(simple, 1, res));
+
+ initial begin
+ addr = 3;
+ val = 42;
+ `start;
+
+ `wait_for(inst_out_valid);
+ $display(""res = %d"", res);
+ $finish;
+ end
+
+endmodule // tests_add_array_at_tb
+"
+"`timescale 1ns / 1ps
+`define intN 32
+`define addrN 10
+`include ""primitives.v""
+`include ""tests_axil_map_w.v""
+`include ""array.v""
+
+module tests_axil_map_w_tb;
+
+ localparam N = 1024;
+
+ `wire(Array, (`addrN, `intN), arr);
+ wire `intT res;
+ integer write_seed = 21;
+ integer read_seed = 42;
+
+ `reg(stream, `intN, sRA);
+ `wire(stream, `intN, sR);
+ `reg(stream, `intN, sWA);
+ `reg(stream, `intN, sW);
+ `wire(stream, 1, sB);
+ reg `intT sRA_next;
+
+ assign sR_ready = out_ready;
+ assign sB_ready = out_ready;
+
+ `testbench(tests_axil_map_w_tb, 5000)
+
+ array #(.N(N))
+ array(.clk(clk),
+ `out(Array, 0, arr));
+
+ `in_ready(inst);
+ `inst_sync(tests_axil_map_w, inst, #())(
+ `sync(in_valid, out_ready),
+ `in(Array, 0, arr),
+ `in(stream, 1, sRA),
+ `in(stream, 2, sWA),
+ `in(stream, 3, sW),
+ `out(stream, 0, sR),
+ `out(null_stream, 1, sB));
+
+ integer i;
+ initial begin
+ sRA = 0;
+ sRA_next = 0;
+ sRA_valid = `false;
+ sWA = 0;
+ sWA_valid = `false;
+ sW = 0;
+ sW_valid = `false;
+ `start;
+
+ // write some data
+ for(i = 0; i < N; i = i + 1) begin
+ sWA = i;
+ sWA_valid = `true;
+ sW = i;
+ sW_valid = `true;
+ `wait_for(sWA_ready && sW_ready);
+ if($random(write_seed) & 1) begin
+ sWA_valid = `false;
+ sW_valid = `false;
+ @(posedge clk);
+ sWA_valid = `true;
+ sW_valid = `true;
+ end
+ sRA_valid = `true;
+ end
+ sWA_valid = `false;
+ sW_valid = `false;
+ sWA = N;
+ `wait_for(sRA == N-1 && sR_valid);
+ nrst = `false;
+ #2;
+ $display(""done"");
+ $finish;
+ end
+
+always @(posedge clk) begin
+ if(sRA_ready) begin
+ if(sRA_next < sWA & ($random(read_seed) & 1)) begin
+ sRA <= sRA_next;
+ sRA_next <= sRA_next + 1;
+ end
+ end
+ if(sR_valid & sR != sRA + 3)
+ $display(""MISMATCH arr(%d) = %d"", sRA, sR);
+end
+
+endmodule // tests_axil_map_w_tb
+"
+"module array (
+ input wire clk,
+ `output(Array, (`addrN, `intN), 0)
+);
+ parameter N = 16;
+ parameter INIT_ADDR = 1;
+ parameter INIT = 0;
+
+ reg `intT data[0:N-1];
+
+ integer i;
+ initial begin
+ for(i = 0; i < N; i = i + 1) begin
+ data[i] = INIT_ADDR ? i : INIT;
+ end
+ end
+
+ assign out0_valid = out0_ready;
+
+ // async read
+ assign out0 = data[out0_addr];
+
+ // sync write
+ always @(posedge clk) begin
+ if(out0_valid && out0_we) begin
+ data[out0_addr] <= out0_di;
+ end
+ end
+endmodule
+"
+"`timescale 1ns / 1ps
+`define intN 16
+`include ""primitives.v""
+`include ""tests_fibl.v""
+
+module top(
+ input clk,
+ input [15:0] in,
+ output [15:0] out
+ );
+
+ reg `intT a = 0;
+ wire `intT a_in = in[4:0];
+ wire `intT b;
+ reg [26:0] div = 0;
+ reg in_valid;
+
+ assign out = b;
+
+ always @(posedge clk) begin
+ if(in[15]) begin
+ div <= div + 1;
+ if(div == 0) begin
+ if(a == 24) begin
+ a <= 0;
+ end
+ else begin
+ a <= a + 1;
+ end
+ `set(in_valid);
+ end
+ else begin
+ `reset(in_valid);
+ end
+ end
+ else if(a != a_in && a_in <= 24)
+ begin
+ a <= a_in;
+ `set(in_valid);
+ end
+ else
+ begin
+ `reset(in_valid);
+ end
+ end
+
+ `inst_sync(tests_fibl, fibl, #())(`sync(in_valid, `true), .in0(a), .out0(b));
+
+endmodule
+"
+"`timescale 1ns / 1ps
+`define intN 8
+`include ""primitives.v""
+`include ""algorithm_sum.v""
+
+module algorithm_sum_tb;
+
+ `reg(stream, `intN, sIn);
+ `wire(simple, `intN, sum);
+
+ `testbench(algorithm_sum_tb, 20)
+
+ `in_ready(sum_inst);
+ `inst_sync(algorithm_sum, sum_inst, #())(`sync(in_valid, out_ready), `in(stream, 0, sIn), `out(simple, 0, sum));
+
+ initial begin
+ sIn = 0;
+ `start;
+
+ #1; sIn = 1; sIn_valid = `true;
+ #1; sIn = 2;
+ #1; sIn = 3;
+ #1; sIn = 8\'hff;
+
+ `wait_for(sum_inst_out_valid);
+ $display(""sum = %b (%d)"", sum, sum);
+ $finish;
+ end
+
+endmodule
+"
+"`timescale 1ns / 1ps
+`define intN 27
+`include ""primitives.v""
+`include ""tests_collatz.v""
+
+module tests_collatz_tb;
+
+ reg `intT a;
+ wire `intT b;
+
+ `testbench(tests_collatz_tb, 200)
+
+ `in_ready(tests_collatz);
+ `inst_sync(tests_collatz, tests_collatz, #())(`sync(in_valid, out_ready), .in0(a), .out0(b));
+
+ initial begin
+ a = 27;
+ `start;
+
+ `wait_for(tests_collatz_out_valid);
+ $display(""b = %b (%d)"", b, b);
+ $finish;
+ end
+
+endmodule // tests_collatz_tb
+"
+"`timescale 1ns / 1ps
+`define intN 16
+`include ""primitives.v""
+`include ""tests_fact.v""
+
+module tests_fact_tb;
+
+ reg `intT a;
+ wire `intT b;
+
+ `testbench(tests_fact_tb, 50)
+
+ `in_ready(tests_fact);
+ `inst_sync(tests_fact, tests_fact, #())(`sync(in_valid, out_ready), .in0(a), .out0(b));
+
+ initial begin
+ a = 8;
+ `start;
+
+ `wait_for(tests_fact_out_valid);
+ $display(""b = %b (%d)"", b, b);
+ $finish;
+ end
+
+endmodule // tests_fact_tb
+"
+"`include ""define.v""
+
+`define primitive_op1(name, op, inT, outT) \\
+module __primitive_``name`` #( \\
+ parameter in0N = `inT``N, \\
+ parameter out0N = `outT``N \\
+)( \\
+ `input(simple, in0N, 0), \\
+ `output(simple, out0N, 0) \\
+); \\
+ assign out0 = op in0; \\
+endmodule
+
+`define primitive_op2(name, op, inT, outT) \\
+module __primitive_``name`` #( \\
+ parameter in0N = `inT``N, \\
+ parameter in1N = `inT``N, \\
+ parameter out0N = `outT``N \\
+)( \\
+ `input(simple, in0N, 0), \\
+ `input(simple, in1N, 1), \\
+ `output(simple, out0N, 0) \\
+); \\
+ assign out0 = in0 op in1; \\
+endmodule
+
+`primitive_op2(eq, ==, int, sym)
+`primitive_op2(neq, !=, int, sym)
+`primitive_op2(mod, %, int, int)
+`primitive_op2(div, /, int, int)
+`primitive_op1(not, !, sym, sym)
+`primitive_op2(mul, *, int, int)
+`primitive_op2(add, +, int, int)
+`primitive_op2(sub, -, int, int)
+`primitive_op2(shiftl, <<, int, int)
+`primitive_op2(shiftr, >>, int, int)
+`primitive_op2(gt, >, int, sym)
+`primitive_op2(gte, >=, int, sym)
+`primitive_op2(lt, <, int, sym)
+`primitive_op2(lte, <=, int, sym)
+`primitive_op1(complement, ~, int, int)
+`primitive_op2(bitand, &, int, int)
+`primitive_op2(bitor, |, int, int)
+`primitive_op2(bitxor, ^, int, int)
+
+module __primitive_ap01 #(
+ parameter in0N = `intN,
+ parameter out1N = `intN,
+ parameter out0N = 0
+)(
+ `sync_ports,
+ `input(stream, in0N, 0),
+ `output(stream, out0N, 0),
+ `output(simple, out1N, 1)
+);
+ assign out0 = in0 >> out1N;
+ assign out1 = in0;
+ assign out0_valid = in0_valid;
+ assign out_valid = in0_valid && `valid(out1);
+ assign in0_ready = out0_ready & out_ready;
+ assign in_ready = `true;
+
+endmodule
+
+module __primitive_ap02 #(
+ parameter in0N = `intN,
+ parameter out1N = `intN,
+ parameter out2N = `intN,
+ parameter out0N = 0
+)(
+ `sync_ports,
+ `input(stream, in0N, 0),
+ `output(stream, out0N, 0),
+ `output(simple, out1N, 1),
+ `output(simple, out2N, 2)
+);
+ assign out0 = in0 >> (out1N + out2N);
+ assign out1 = in0 >> out2N;
+ assign out2 = in0;
+ assign out0_valid = in0_valid;
+ assign out_valid = in0_valid && `valid(out1) && `valid(out2);
+ assign in0_ready = out0_ready & out_ready;
+ assign in_ready = `true;
+
+endmodule
+
+/* ------------------------------------------------------ *
+ NOTE ON READY/VALID DEPENDENCIES
+ * ------------------------------------------------------ *
+
+ `in_ready` can depend on `in_valid` asynchronously,
+ but `out_valid` cannot depend on `out_ready`.
+
+ This is to prevent loops, so that the
+ flow is from source to sink and back.
+
+ * ------------------------------------------------------ */
+
+module __primitive_ap20 #(
+ parameter in0N = `intN,
+ parameter in1N = `intN,
+ parameter in2N = `intN,
+ parameter out0N = in0N + in1N + in2N
+)(
+ `sync_ports,
+ `input(simple, in0N, 0),
+ `input(simple, in1N, 1),
+ `input(stream, in2N, 2),
+ `output(stream, out0N, 0)
+);
+ assign out0 = { in0, in1, in2 };
+ assign out0_valid = in_valid & in2_valid;
+ assign in2_ready = out0_ready;
+ assign in_ready = in_valid & out0_ready;
+ assign out_valid = `true;
+
+endmodule
+
+module __primitive_pushr1 #(
+ parameter in0N = `intN,
+ parameter in1N = `intN,
+ parameter out0N = `intN
+)(
+ `sync_ports,
+ `input(stream, in0N, 0),
+ `input(simple, in1N, 1),
+ `output(stream, out0N, 0)
+);
+ assign out0 = { in0, in1 };
+ assign out0_valid = in_valid & in0_valid;
+ assign in0_ready = out0_ready;
+ assign in_ready = in_valid & out0_ready;
+ assign out_valid = `true;
+
+endmodule
+
+module __primitive_pushr2 #(
+ parameter in0N = `intN,
+ parameter in1N = `intN,
+ parameter in2N = `intN,
+ parameter out0N = in0N + in1N + in2N
+)(
+ `sync_ports,
+ `input(stream, in0N, 0),
+ `input(simple, in1N, 1),
+ `input(simple, in2N, 2),
+ `output(stream, out0N, 0)
+);
+ assign out0 = { in0, in1, in2 };
+ assign out0_valid = in_valid & in0_valid;
+ assign in0_ready = out0_ready;
+ assign in_ready = in_valid & out0_ready;
+ assign out_valid = `true;
+
+endmodule
+
+module transparent_buffer #(
+ parameter N = `intN
+)(
+ input wire clk,
+ input wire nrst,
+ `input(stream, N, 0),
+ `output(stream, N, 0)
+);
+ reg [N-1:0] data;
+ reg data_valid;
+
+ assign in0_ready = !data_valid | out0_ready;
+ assign out0_valid = data_valid | in0_valid;
+ assign out0 = !data_valid ? in0 : data; // transparent when ready & valid
+
+ always @(posedge clk) begin
+ if(!nrst) begin // reset
+ `reset(data_valid);
+ end
+ else begin
+ if(!in0_valid && out0_ready) begin // drain
+ `reset(data_valid);
+ end
+ else if(in0_valid && !out0_ready) begin // fill
+ data <= in0;
+ if(!out0_ready) `set(data_valid);
+ end
+ end
+ end
+endmodule
+
+module __primitive_read_array #(
+ parameter in0AN = `addrN,
+ parameter in0DN = `intN,
+ parameter in1N = `intN,
+ parameter out1N = `intN,
+ parameter out0AN = `addrN,
+ parameter out0DN = `intN
+)(
+ `sync_ports,
+ `input(Array, (in0AN, in0DN), 0),
+ `input(simple, in1N, 1),
+ `output(Array, (out0AN, out0DN), 0),
+ `output(simple, out1N, 1)
+);
+ reg pending;
+ wire buf_ready;
+
+ // three-way setup:
+ // 1. <- ready
+ // 2. -> valid (active)
+ // 3. <- addr, we, di (success)
+ wire active = in_valid & buf_ready & !pending & nrst;
+ wire success = active & in0_valid;
+
+ assign in0_addr = success ? in1 : out0_addr;
+ assign in0_we = !success & out0_we;
+ assign in0_di = out0_di;
+ assign out0 = in0;
+
+ assign in0_ready = active | out0_ready;
+ assign out0_valid = !active & in0_valid;
+ assign in_ready = active & in0_valid;
+
+ transparent_buffer #(.N(out1N))
+ buffer(.clk(clk),
+ .nrst(nrst),
+ .in0(in0),
+ .in0_valid(in0_valid & !pending),
+ .in0_ready(buf_ready),
+ .out0(out1),
+ .out0_valid(out_valid),
+ .out0_ready(out_ready));
+
+ always @(posedge clk) begin
+ if(!nrst) `reset(pending);
+ else if(in_ready) pending <= out0_ready;
+ end
+
+endmodule
+
+module __primitive_write_array #(
+ parameter in0AN = `addrN,
+ parameter in0DN = `intN,
+ parameter in1N = `intN,
+ parameter in2N = `intN,
+ parameter out0AN = `addrN,
+ parameter out0DN = `intN
+)(
+ `sync_ports,
+ `input(Array, (in0AN, in0DN), 0),
+ `input(simple, in1N, 1),
+ `input(simple, in2N, 2),
+ `output(Array, (out0AN, out0DN), 0)
+);
+ reg pending;
+
+ // three-way setup:
+ // 1. <- ready
+ // 2. -> valid (active)
+ // 3. <- addr, we, di (success)
+ wire active = in_valid & !pending & nrst;
+ wire success = active & in0_valid;
+
+ assign in0_addr = success ? in1 : out0_addr;
+ assign in0_we = success | out0_we;
+ assign in0_di = success ? in2 : out0_di;
+ assign out0 = in0;
+ assign out_valid = `true;
+
+ assign in0_ready = active | out0_ready;
+ assign out0_valid = !active & in0_valid;
+ assign in_ready = active & in0_valid;
+
+ always @(posedge clk) begin
+ if(!nrst) `reset(pending);
+ else if(in_ready) pending <= out0_ready;
+ end
+
+endmodule
+
+module dup_stream #(
+ parameter N = 1
+)(
+ input wire clk,
+ input wire in_valid,
+ output wire in_ready,
+ output wire [N-1:0] out_valid,
+ input wire [N-1:0] out_ready
+);
+ generate
+ if(N == 1) begin
+ assign in_ready = out_ready[0];
+ assign out_valid[0] = in_valid;
+ end
+ else begin
+ reg [0:N-1] pending_prev;
+ assign in_ready = ~| pending;
+ assign out_valid = in_valid ? pending_prev : 0;
+ wire [0:N-1] pending = pending_prev & ~out_ready;
+
+ always @(posedge clk) begin
+ pending_prev <= in_ready ? ~0 : pending;
+ end
+ end
+ endgenerate
+endmodule
+
+module dup_Array #(
+ parameter N = 1
+)(
+ input wire clk,
+ input wire in_valid,
+ output wire in_ready,
+ output wire [0:N-1] out_valid,
+ input wire [0:N-1] out_ready
+);
+ generate
+ if(N == 1) begin
+ assign in_ready = out_ready;
+ assign out_valid = in_valid;
+ end
+ else begin
+ reg [0:N-1] done;
+ assign in_ready = | out_ready;
+ assign out_valid = in_valid ? pending & ~(pending - 1) : 0; // select MSB
+ wire [0:N-1] pending = out_ready & ~done;
+
+ always @(posedge clk) begin
+ done <= pending & ~out_valid ? done | out_valid : 0;
+ end
+ end
+ endgenerate
+endmodule
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cmn/vga_sync/vga_sync.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Outputs HSYNC and VSYNC signals to control 640x480@60Hz VGA output. x/y outputs indicates the
+* current {x, y} pixel position being displayed.
+*
+* Note: VSYNC/HSYNC signals are latched for stability, introducing a 1 CLK delay. The RGB
+* generation circuit must be aware of this, and should latch its output as well.
+***************************************************************************************************/
+
+module vga_sync
+(
+ input wire clk, // 100Mhz clock signal
+ output wire hsync, // HSYNC VGA control output
+ output wire vsync, // VSYNC VGA control output
+ output wire en, // Indicates when RGB generation circuit should enable (x,y valid)
+ output wire [9:0] x, // Current X position being displayed
+ output wire [9:0] y, // Current Y position being displayed (top = 0)
+ output wire [9:0] x_next, // Next X position to be displayed next clock
+ output wire [9:0] y_next // Next Y position to be displayed
+);
+
+//
+// VGA signal timing parameters. Taken from http://tinyvga.com/vga-timing/640x480@60Hz. Note
+// that this circuit uses a 25MHz clock instead of specified 25.175MHz clock. Most displays can
+// cope with this out of spec behavior.
+//
+localparam H_DISP = 640; // Number of displayable columns
+localparam H_FP = 16; // Horizontal front porch in pixel clocks
+localparam H_RT = 96; // Horizontal retrace (hsync pulse) in pixel clocks
+localparam H_BP = 48; // Horizontal back porch in pixel clocks
+localparam V_DISP = 480; // Number of displayable rows
+localparam V_FP = 10; // Vertical front porch in lines
+localparam V_RT = 2; // Vertical retrace (vsync pulse) in lines
+localparam V_BP = 29; // Vertical back porch in lines
+
+// FF for mod-4 counter. Used to generate a 25MHz pixel enable signal.
+reg [1:0] q_mod4_cnt;
+wire [1:0] d_mod4_cnt;
+
+// Horizontal and vertical counters. Used relative to timings specified in pixels or lines, above.
+// Equivalent to x,y position when in the displayable region.
+reg [9:0] q_hcnt, q_vcnt;
+wire [9:0] d_hcnt, d_vcnt;
+
+// Output signal FFs.
+reg q_hsync, q_vsync, q_en;
+wire d_hsync, d_vsync, d_en;
+
+// FF update logic.
+always @(posedge clk)
+ begin
+ q_mod4_cnt <= d_mod4_cnt;
+ q_hcnt <= d_hcnt;
+ q_vcnt <= d_vcnt;
+ q_hsync <= d_hsync;
+ q_vsync <= d_vsync;
+ q_en <= d_en;
+ end
+
+wire pix_pulse; // 1 clk tick per-pixel
+wire line_pulse; // 1 clk tick per-line (reset to h-pos 0)
+wire screen_pulse; // 1 clk tick per-screen (reset to v-pos 0)
+
+assign d_mod4_cnt = q_mod4_cnt + 2\'h1;
+
+assign pix_pulse = (q_mod4_cnt == 0);
+assign line_pulse = pix_pulse && (q_hcnt == (H_DISP + H_FP + H_RT + H_BP - 1));
+assign screen_pulse = line_pulse && (q_vcnt == (V_DISP + V_FP + V_RT + V_BP - 1));
+
+assign d_hcnt = (line_pulse) ? 10\'h000 : ((pix_pulse) ? q_hcnt + 10\'h001 : q_hcnt);
+assign d_vcnt = (screen_pulse) ? 10\'h000 : ((line_pulse) ? q_vcnt + 10\'h001 : q_vcnt);
+
+assign d_hsync = (q_hcnt >= (H_DISP + H_FP)) && (q_hcnt < (H_DISP + H_FP + H_RT));
+assign d_vsync = (q_vcnt >= (V_DISP + V_FP)) && (q_vcnt < (V_DISP + V_FP + V_RT));
+
+assign d_en = (q_hcnt < H_DISP) && (q_vcnt < V_DISP);
+
+// Assign output wires to appropriate FFs.
+assign hsync = q_hsync;
+assign vsync = q_vsync;
+assign x = q_hcnt;
+assign y = q_vcnt;
+assign x_next = d_hcnt;
+assign y_next = (y == (V_DISP + V_FP + V_RT + V_BP - 10\'h001)) ? 10\'h000 : (q_vcnt + 10\'h001);
+assign en = q_en;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cpu/apu/apu_frame_counter.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* APU frame counter sub-block.
+***************************************************************************************************/
+
+module apu_frame_counter
+(
+ input wire clk_in, // system clock signal
+ input wire rst_in, // reset signal
+ input wire cpu_cycle_pulse_in, // 1 clk pulse on every cpu cycle
+ input wire apu_cycle_pulse_in, // 1 clk pulse on every apu cycle
+ input wire [1:0] mode_in, // mode ([0] = IRQ inhibit, [1] = sequence mode)
+ input wire mode_wr_in, // update mode
+ output reg e_pulse_out, // envelope and linear counter pulse (~240 Hz)
+ output reg l_pulse_out, // length counter and sweep pulse (~120 Hz)
+ output reg f_pulse_out // frame pulse (~60Hz, should drive IRQ)
+);
+
+reg [14:0] q_apu_cycle_cnt, d_apu_cycle_cnt;
+reg q_seq_mode, d_seq_mode;
+reg q_irq_inhibit, d_irq_inhibit;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_apu_cycle_cnt <= 15\'h0000;
+ q_seq_mode <= 1\'b0;
+ q_irq_inhibit <= 1\'b0;
+ end
+ else
+ begin
+ q_apu_cycle_cnt <= d_apu_cycle_cnt;
+ q_seq_mode <= d_seq_mode;
+ q_irq_inhibit <= d_irq_inhibit;
+ end
+ end
+
+always @*
+ begin
+ d_apu_cycle_cnt = q_apu_cycle_cnt;
+ d_seq_mode = (mode_wr_in) ? mode_in[1] : q_seq_mode;
+ d_irq_inhibit = (mode_wr_in) ? mode_in[0] : q_irq_inhibit;
+
+ e_pulse_out = 1\'b0;
+ l_pulse_out = 1\'b0;
+ f_pulse_out = 1\'b0;
+
+ if (apu_cycle_pulse_in)
+ begin
+ d_apu_cycle_cnt = q_apu_cycle_cnt + 15\'h0001;
+
+ if ((q_apu_cycle_cnt == 15\'h0E90) || (q_apu_cycle_cnt == 15\'h2BB1))
+ begin
+ e_pulse_out = 1\'b1;
+ end
+ else if (q_apu_cycle_cnt == 15\'h1D20)
+ begin
+ e_pulse_out = 1\'b1;
+ l_pulse_out = 1\'b1;
+ end
+ else if (!q_seq_mode && (q_apu_cycle_cnt == 15\'h3A42))
+ begin
+ e_pulse_out = 1\'b1;
+ l_pulse_out = 1\'b1;
+ f_pulse_out = ~q_irq_inhibit;
+
+ d_apu_cycle_cnt = 15\'h0000;
+ end
+ else if ((q_apu_cycle_cnt == 15\'h48d0))
+ begin
+ e_pulse_out = q_seq_mode;
+ l_pulse_out = q_seq_mode;
+
+ d_apu_cycle_cnt = 15\'h0000;
+ end
+ end
+
+ if (cpu_cycle_pulse_in && mode_wr_in)
+ d_apu_cycle_cnt = 15\'h48d0;
+ end
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cpu/apu/apu.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Audio Processing Unit.
+***************************************************************************************************/
+
+module apu
+(
+ input wire clk_in, // system clock signal
+ input wire rst_in, // reset signal
+ input wire [ 3:0] mute_in, // disable specific audio channels
+ input wire [15:0] a_in, // addr input bus
+ input wire [ 7:0] d_in, // data input bus
+ input wire r_nw_in, // read/write select
+ output wire audio_out, // pwm audio output
+ output wire [ 7:0] d_out // data output bus
+);
+
+localparam [15:0] PULSE0_CHANNEL_CNTL_MMR_ADDR = 16\'h4000;
+localparam [15:0] PULSE1_CHANNEL_CNTL_MMR_ADDR = 16\'h4004;
+localparam [15:0] TRIANGLE_CHANNEL_CNTL_MMR_ADDR = 16\'h4008;
+localparam [15:0] NOISE_CHANNEL_CNTL_MMR_ADDR = 16\'h400C;
+localparam [15:0] STATUS_MMR_ADDR = 16\'h4015;
+localparam [15:0] FRAME_COUNTER_CNTL_MMR_ADDR = 16\'h4017;
+
+// CPU cycle pulse. Ideally this would be generated in rp2a03 and shared by the apu and cpu.
+reg [5:0] q_clk_cnt;
+wire [5:0] d_clk_cnt;
+wire cpu_cycle_pulse;
+wire apu_cycle_pulse;
+wire e_pulse;
+wire l_pulse;
+wire f_pulse;
+reg q_pulse0_en;
+wire d_pulse0_en;
+reg q_pulse1_en;
+wire d_pulse1_en;
+reg q_triangle_en;
+wire d_triangle_en;
+reg q_noise_en;
+wire d_noise_en;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_clk_cnt <= 6\'h00;
+ q_pulse0_en <= 1\'b0;
+ q_pulse1_en <= 1\'b0;
+ q_triangle_en <= 1\'b0;
+ q_noise_en <= 1\'b0;
+ end
+ else
+ begin
+ q_clk_cnt <= d_clk_cnt;
+ q_pulse0_en <= d_pulse0_en;
+ q_pulse1_en <= d_pulse1_en;
+ q_triangle_en <= d_triangle_en;
+ q_noise_en <= d_noise_en;
+ end
+ end
+
+assign d_clk_cnt = (q_clk_cnt == 6\'h37) ? 6\'h00 : q_clk_cnt + 6\'h01;
+assign d_pulse0_en = (~r_nw_in && (a_in == STATUS_MMR_ADDR)) ? d_in[0] : q_pulse0_en;
+assign d_pulse1_en = (~r_nw_in && (a_in == STATUS_MMR_ADDR)) ? d_in[1] : q_pulse1_en;
+assign d_triangle_en = (~r_nw_in && (a_in == STATUS_MMR_ADDR)) ? d_in[2] : q_triangle_en;
+assign d_noise_en = (~r_nw_in && (a_in == STATUS_MMR_ADDR)) ? d_in[3] : q_noise_en;
+
+assign cpu_cycle_pulse = (q_clk_cnt == 6\'h00);
+
+
+apu_div #(.PERIOD_BITS(1)) apu_pulse_gen(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .pulse_in(cpu_cycle_pulse),
+ .reload_in(1\'b0),
+ .period_in(1\'b1),
+ .pulse_out(apu_cycle_pulse)
+);
+
+//
+// Frame counter.
+//
+wire frame_counter_mode_wr;
+
+apu_frame_counter apu_frame_counter_blk(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .cpu_cycle_pulse_in(cpu_cycle_pulse),
+ .apu_cycle_pulse_in(apu_cycle_pulse),
+ .mode_in(d_in[7:6]),
+ .mode_wr_in(frame_counter_mode_wr),
+ .e_pulse_out(e_pulse),
+ .l_pulse_out(l_pulse),
+ .f_pulse_out(f_pulse)
+);
+
+assign frame_counter_mode_wr = ~r_nw_in && (a_in == FRAME_COUNTER_CNTL_MMR_ADDR);
+
+//
+// Pulse 0 channel.
+//
+wire [3:0] pulse0_out;
+wire pulse0_active;
+wire pulse0_wr;
+
+apu_pulse #(.CHANNEL(0)) apu_pulse0_blk(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .en_in(q_pulse0_en),
+ .cpu_cycle_pulse_in(cpu_cycle_pulse),
+ .lc_pulse_in(l_pulse),
+ .eg_pulse_in(e_pulse),
+ .a_in(a_in[1:0]),
+ .d_in(d_in),
+ .wr_in(pulse0_wr),
+ .pulse_out(pulse0_out),
+ .active_out(pulse0_active)
+);
+
+assign pulse0_wr = ~r_nw_in && (a_in[15:2] == PULSE0_CHANNEL_CNTL_MMR_ADDR[15:2]);
+
+//
+// Pulse 1 channel.
+//
+wire [3:0] pulse1_out;
+wire pulse1_active;
+wire pulse1_wr;
+
+apu_pulse #(.CHANNEL(1)) apu_pulse1_blk(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .en_in(q_pulse1_en),
+ .cpu_cycle_pulse_in(cpu_cycle_pulse),
+ .lc_pulse_in(l_pulse),
+ .eg_pulse_in(e_pulse),
+ .a_in(a_in[1:0]),
+ .d_in(d_in),
+ .wr_in(pulse1_wr),
+ .pulse_out(pulse1_out),
+ .active_out(pulse1_active)
+);
+
+assign pulse1_wr = ~r_nw_in && (a_in[15:2] == PULSE1_CHANNEL_CNTL_MMR_ADDR[15:2]);
+
+//
+// Triangle channel.
+//
+wire [3:0] triangle_out;
+wire triangle_active;
+wire triangle_wr;
+
+apu_triangle apu_triangle_blk(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .en_in(q_triangle_en),
+ .cpu_cycle_pulse_in(cpu_cycle_pulse),
+ .lc_pulse_in(l_pulse),
+ .eg_pulse_in(e_pulse),
+ .a_in(a_in[1:0]),
+ .d_in(d_in),
+ .wr_in(triangle_wr),
+ .triangle_out(triangle_out),
+ .active_out(triangle_active)
+);
+
+assign triangle_wr = ~r_nw_in && (a_in[15:2] == TRIANGLE_CHANNEL_CNTL_MMR_ADDR[15:2]);
+
+//
+// Noise channel.
+//
+wire [3:0] noise_out;
+wire noise_active;
+wire noise_wr;
+
+apu_noise apu_noise_blk(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .en_in(q_noise_en),
+ .apu_cycle_pulse_in(apu_cycle_pulse),
+ .lc_pulse_in(l_pulse),
+ .eg_pulse_in(e_pulse),
+ .a_in(a_in[1:0]),
+ .d_in(d_in),
+ .wr_in(noise_wr),
+ .noise_out(noise_out),
+ .active_out(noise_active)
+);
+
+assign noise_wr = ~r_nw_in && (a_in[15:2] == NOISE_CHANNEL_CNTL_MMR_ADDR[15:2]);
+
+//
+// Mixer.
+//
+apu_mixer apu_mixer_blk(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .mute_in(mute_in),
+ .pulse0_in(pulse0_out),
+ .pulse1_in(pulse1_out),
+ .triangle_in(triangle_out),
+ .noise_in(noise_out),
+ .audio_out(audio_out)
+);
+
+assign d_out = (r_nw_in && (a_in == STATUS_MMR_ADDR)) ?
+ { 4\'b0000, noise_active, triangle_active, pulse1_active, pulse0_active } : 8\'h00;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cmn/block_ram/block_ram.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Various generic, inferred block ram descriptors.
+***************************************************************************************************/
+
+// Dual port RAM with synchronous read. Modified version of listing 12.4 in ""FPGA Prototyping by
+// Verilog Examples,"" itself a modified version of XST 8.11 v_rams_11.
+module dual_port_ram_sync
+#(
+ parameter ADDR_WIDTH = 6,
+ parameter DATA_WIDTH = 8
+)
+(
+ input wire clk,
+ input wire we,
+ input wire [ADDR_WIDTH-1:0] addr_a,
+ input wire [ADDR_WIDTH-1:0] addr_b,
+ input wire [DATA_WIDTH-1:0] din_a,
+ output wire [DATA_WIDTH-1:0] dout_a,
+ output wire [DATA_WIDTH-1:0] dout_b
+);
+
+reg [DATA_WIDTH-1:0] ram [2**ADDR_WIDTH-1:0];
+reg [ADDR_WIDTH-1:0] q_addr_a;
+reg [ADDR_WIDTH-1:0] q_addr_b;
+
+always @(posedge clk)
+ begin
+ if (we)
+ ram[addr_a] <= din_a;
+ q_addr_a <= addr_a;
+ q_addr_b <= addr_b;
+ end
+
+assign dout_a = ram[q_addr_a];
+assign dout_b = ram[q_addr_b];
+
+endmodule
+
+// Single port RAM with synchronous read.
+module single_port_ram_sync
+#(
+ parameter ADDR_WIDTH = 6,
+ parameter DATA_WIDTH = 8
+)
+(
+ input wire clk,
+ input wire we,
+ input wire [ADDR_WIDTH-1:0] addr_a,
+ input wire [DATA_WIDTH-1:0] din_a,
+ output wire [DATA_WIDTH-1:0] dout_a
+);
+
+reg [DATA_WIDTH-1:0] ram [2**ADDR_WIDTH-1:0];
+reg [ADDR_WIDTH-1:0] q_addr_a;
+
+always @(posedge clk)
+ begin
+ if (we)
+ ram[addr_a] <= din_a;
+ q_addr_a <= addr_a;
+ end
+
+assign dout_a = ram[q_addr_a];
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cmn/uart/uart_tx.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* UART transmitter.
+***************************************************************************************************/
+
+module uart_tx
+#(
+ parameter DATA_BITS = 8,
+ parameter STOP_BITS = 1,
+ parameter PARITY_MODE = 1, // 0 = NONE, 1 = ODD, 2 = EVEN
+ parameter BAUD_CLK_OVERSAMPLE_RATE = 16
+)
+(
+ input wire clk, // System clock
+ input wire reset, // Reset signal
+ input wire baud_clk_tick, // 1 tick per OVERSAMPLE_RATE baud clks
+ input wire tx_start, // Signal requesting trasmission start
+ input wire [DATA_BITS-1:0] tx_data, // Data to be transmitted
+ output wire tx_done_tick, // Transfer done signal
+ output wire tx // TX transmission wire
+);
+
+localparam [5:0] STOP_OVERSAMPLE_TICKS = STOP_BITS * BAUD_CLK_OVERSAMPLE_RATE;
+
+// Symbolic state representations.
+localparam [4:0] S_IDLE = 5\'h01,
+ S_START = 5\'h02,
+ S_DATA = 5\'h04,
+ S_PARITY = 5\'h08,
+ S_STOP = 5\'h10;
+
+// Registers
+reg [4:0] q_state, d_state;
+reg [3:0] q_baud_clk_tick_cnt, d_baud_clk_tick_cnt;
+reg [DATA_BITS-1:0] q_data, d_data;
+reg [2:0] q_data_bit_idx, d_data_bit_idx;
+reg q_parity_bit, d_parity_bit;
+reg q_tx, d_tx;
+reg q_tx_done_tick, d_tx_done_tick;
+
+always @(posedge clk, posedge reset)
+ begin
+ if (reset)
+ begin
+ q_state <= S_IDLE;
+ q_baud_clk_tick_cnt <= 0;
+ q_data <= 0;
+ q_data_bit_idx <= 0;
+ q_tx <= 1\'b1;
+ q_tx_done_tick <= 1\'b0;
+ q_parity_bit <= 1\'b0;
+ end
+ else
+ begin
+ q_state <= d_state;
+ q_baud_clk_tick_cnt <= d_baud_clk_tick_cnt;
+ q_data <= d_data;
+ q_data_bit_idx <= d_data_bit_idx;
+ q_tx <= d_tx;
+ q_tx_done_tick <= d_tx_done_tick;
+ q_parity_bit <= d_parity_bit;
+ end
+ end
+
+always @*
+ begin
+ // Default most state to remain unchanged.
+ d_state = q_state;
+ d_data = q_data;
+ d_data_bit_idx = q_data_bit_idx;
+ d_parity_bit = q_parity_bit;
+
+ // Increment the tick counter if the baud clk counter ticked.
+ d_baud_clk_tick_cnt = (baud_clk_tick) ? (q_baud_clk_tick_cnt + 4\'h1) : q_baud_clk_tick_cnt;
+
+ d_tx_done_tick = 1\'b0;
+ d_tx = 1\'b1;
+
+ case (q_state)
+ S_IDLE:
+ begin
+ // Detect tx_start signal from client, latch data, and begin transmission. Don\'t latch
+ // during done_tick.
+ if (tx_start && ~q_tx_done_tick)
+ begin
+ d_state = S_START;
+ d_baud_clk_tick_cnt = 0;
+ d_data = tx_data;
+
+ if (PARITY_MODE == 1)
+ d_parity_bit = ~^tx_data;
+ else if (PARITY_MODE == 2)
+ d_parity_bit = ~tx_data;
+ end
+ end
+
+ S_START:
+ begin
+ // Send low signal to indicate start bit. When done, move to data transmission.
+ d_tx = 1\'b0;
+ if (baud_clk_tick && (q_baud_clk_tick_cnt == (BAUD_CLK_OVERSAMPLE_RATE - 1)))
+ begin
+ d_state = S_DATA;
+ d_baud_clk_tick_cnt = 0;
+ d_data_bit_idx = 0;
+ end
+ end
+
+ S_DATA:
+ begin
+ // Transmit current low data bit. After OVERSAMPLE_RATE ticks, shift the data reg
+ // and move on to the next bit. After DATA_BITS bits, move to stop bit state.
+ d_tx = q_data[0];
+ if (baud_clk_tick && (q_baud_clk_tick_cnt == (BAUD_CLK_OVERSAMPLE_RATE - 1)))
+ begin
+ d_data = q_data >> 1;
+ d_data_bit_idx = q_data_bit_idx + 3\'h1;
+ d_baud_clk_tick_cnt = 0;
+
+ if (q_data_bit_idx == (DATA_BITS - 1))
+ begin
+ if (PARITY_MODE == 0)
+ d_state = S_STOP;
+ else
+ d_state = S_PARITY;
+ end
+ end
+ end
+
+ S_PARITY:
+ begin
+ // Send parity bit.
+ d_tx = q_parity_bit;
+ if (baud_clk_tick && (q_baud_clk_tick_cnt == (BAUD_CLK_OVERSAMPLE_RATE - 1)))
+ begin
+ d_state = S_STOP;
+ d_baud_clk_tick_cnt = 0;
+ end
+ end
+
+ S_STOP:
+ begin
+ // Issue stop bit.
+ if (baud_clk_tick && (q_baud_clk_tick_cnt == (STOP_OVERSAMPLE_TICKS - 1)))
+ begin
+ d_state = S_IDLE;
+ d_tx_done_tick = 1\'b1;
+ end
+ end
+ endcase
+end
+
+assign tx = q_tx;
+assign tx_done_tick = q_tx_done_tick;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cpu/rp2a03.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Implementation of the RP2A03 chip for an fpga-based NES emulator. Contains a MOS-6502 CPU
+* core, APU, sprite DMA engine, and joypad control logic.
+***************************************************************************************************/
+
+module rp2a03
+(
+ input wire clk_in, // system clock
+ input wire rst_in, // system reset
+
+ // CPU signals.
+ input wire rdy_in, // ready signal
+ input wire [ 7:0] d_in, // data input bus
+ input wire nnmi_in, // /nmi interrupt signal (active low)
+ input wire nres_in, // /res interrupt signal (active low)
+ output wire [ 7:0] d_out, // data output bus
+ output wire [15:0] a_out, // address bus
+ output wire r_nw_out, // read/write select (write low)
+ output wire brk_out, // debug break signal
+
+ // Joypad signals.
+ input wire jp_data1_in, // joypad 1 input signal
+ input wire jp_data2_in, // joypad 2 input signal
+ output wire jp_clk, // joypad output clk signal
+ output wire jp_latch, // joypad output latch signal
+
+ // Audio signals.
+ input wire [ 3:0] mute_in, // disable autio channels
+ output wire audio_out, // pwm audio output
+
+ // HCI interface.
+ input wire [ 3:0] dbgreg_sel_in, // dbg reg select
+ input wire [ 7:0] dbgreg_d_in, // dbg reg data in
+ input wire dbgreg_wr_in, // dbg reg write select
+ output wire [ 7:0] dbgreg_d_out // dbg reg data out
+);
+
+//
+// CPU: central processing unit block.
+//
+wire cpu_ready;
+wire [ 7:0] cpu_din;
+wire cpu_nirq;
+wire [ 7:0] cpu_dout;
+wire [15:0] cpu_a;
+wire cpu_r_nw;
+
+cpu cpu_blk(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .ready_in(cpu_ready),
+ .dbgreg_sel_in(dbgreg_sel_in),
+ .dbgreg_in(dbgreg_d_in),
+ .dbgreg_wr_in(dbgreg_wr_in),
+ .d_in(cpu_din),
+ .nnmi_in(nnmi_in),
+ .nres_in(nres_in),
+ .nirq_in(cpu_nirq),
+ .d_out(cpu_dout),
+ .a_out(cpu_a),
+ .r_nw_out(cpu_r_nw),
+ .brk_out(brk_out),
+ .dbgreg_out(dbgreg_d_out)
+);
+
+//
+// APU: audio processing unit block.
+//
+wire [7:0] audio_dout;
+
+apu apu_blk(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .mute_in(mute_in),
+ .a_in(cpu_a),
+ .d_in(cpu_dout),
+ .r_nw_in(cpu_r_nw),
+ .audio_out(audio_out),
+ .d_out(audio_dout)
+);
+
+//
+// JP: joypad controller block.
+//
+wire [7:0] jp_dout;
+
+jp jp_blk(
+ .clk(clk_in),
+ .rst(rst_in),
+ .wr(~cpu_r_nw),
+ .addr(cpu_a),
+ .din(cpu_dout[0]),
+ .jp_data1(jp_data1_in),
+ .jp_data2(jp_data2_in),
+ .jp_clk(jp_clk),
+ .jp_latch(jp_latch),
+ .dout(jp_dout)
+);
+
+//
+// SPRDMA: sprite dma controller block.
+//
+wire sprdma_active;
+wire [15:0] sprdma_a;
+wire [ 7:0] sprdma_dout;
+wire sprdma_r_nw;
+
+sprdma sprdma_blk(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .cpumc_a_in(cpu_a),
+ .cpumc_din_in(cpu_dout),
+ .cpumc_dout_in(cpu_din),
+ .cpu_r_nw_in(cpu_r_nw),
+ .active_out(sprdma_active),
+ .cpumc_a_out(sprdma_a),
+ .cpumc_d_out(sprdma_dout),
+ .cpumc_r_nw_out(sprdma_r_nw)
+);
+
+assign cpu_ready = rdy_in & !sprdma_active;
+assign cpu_din = d_in | jp_dout | audio_dout;
+assign cpu_nirq = 1\'b1;
+
+assign d_out = (sprdma_active) ? sprdma_dout : cpu_dout;
+assign a_out = (sprdma_active) ? sprdma_a : cpu_a;
+assign r_nw_out = (sprdma_active) ? sprdma_r_nw : cpu_r_nw;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cpu/apu/apu_div.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* APU divider; building block used by several other APU components. Outputs a pulse every n input
+* pulses, where n is the divider\'s period. It contains a counter which is decremented on the
+* arrival of each pulse. When the counter reaches 0, it is reloaded with the period and an output
+* pulse is generated. A divider can also be forced to reload its counter immediately, but this
+* does not output a pulse. When a divider\'s period is changed, the current count is not affected.
+*
+* apu_div_const is a variation on apu_div that has an immutable period.
+***************************************************************************************************/
+
+module apu_div
+#(
+ parameter PERIOD_BITS = 16
+)
+(
+ input wire clk_in, // system clock signal
+ input wire rst_in, // reset signal
+ input wire pulse_in, // input pulse
+ input wire reload_in, // reset counter to period_in (no pulse_out generated)
+ input wire [PERIOD_BITS-1:0] period_in, // new period value
+ output wire pulse_out // divided output pulse
+);
+
+reg [PERIOD_BITS-1:0] q_cnt;
+wire [PERIOD_BITS-1:0] d_cnt;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ q_cnt <= 0;
+ else
+ q_cnt <= d_cnt;
+ end
+
+assign d_cnt = (reload_in || (pulse_in && (q_cnt == 0))) ? period_in :
+ (pulse_in) ? q_cnt - 1\'h1 : q_cnt;
+assign pulse_out = pulse_in && (q_cnt == 0);
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/wram.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Work RAM module; implements 2KB of on-board WRAM as fpga block RAM.
+***************************************************************************************************/
+
+module wram
+(
+ input wire clk_in, // system clock
+ input wire en_in, // chip enable
+ input wire r_nw_in, // read/write select (read: 0, write: 1)
+ input wire [10:0] a_in, // memory address
+ input wire [ 7:0] d_in, // data input
+ output wire [ 7:0] d_out // data output
+);
+
+wire wram_bram_we;
+wire [7:0] wram_bram_dout;
+
+single_port_ram_sync #(.ADDR_WIDTH(11),
+ .DATA_WIDTH(8)) wram_bram(
+ .clk(clk_in),
+ .we(wram_bram_we),
+ .addr_a(a_in),
+ .din_a(d_in),
+ .dout_a(wram_bram_dout)
+);
+
+assign wram_bram_we = (en_in) ? ~r_nw_in : 1\'b0;
+assign d_out = (en_in) ? wram_bram_dout : 8\'h00;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/ppu/ppu_bg.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Background/playfield PPU sub-block.
+***************************************************************************************************/
+
+module ppu_bg
+(
+ input wire clk_in, // 100MHz system clock signal
+ input wire rst_in, // reset signal
+ input wire en_in, // enable background
+ input wire ls_clip_in, // clip background in left 8 pixels
+ input wire [ 2:0] fv_in, // fine vertical scroll reg value
+ input wire [ 4:0] vt_in, // vertical tile scroll reg value
+ input wire v_in, // vertical name table selection reg value
+ input wire [ 2:0] fh_in, // fine horizontal scroll reg value
+ input wire [ 4:0] ht_in, // horizontal tile scroll reg value
+ input wire h_in, // horizontal name table selection reg value
+ input wire s_in, // playfield pattern table selection reg value
+ input wire [ 9:0] nes_x_in, // nes x coordinate
+ input wire [ 9:0] nes_y_in, // nes y coordinate
+ input wire [ 9:0] nes_y_next_in, // next line\'s nes y coordinate
+ input wire pix_pulse_in, // pulse signal one clock immediately before nes x changes
+ input wire [ 7:0] vram_d_in, // vram data input bus
+ input wire ri_upd_cntrs_in, // update counters from scroll regs (after 0x2006 write)
+ input wire ri_inc_addr_in, // increment scroll regs for 0x2007 ri access
+ input wire ri_inc_addr_amt_in, // amount to inc addr on ri_inc_addr_in (1 or 32 bytes)
+ output reg [13:0] vram_a_out, // vram address bus for bg or ri 0x2007 access
+ output wire [ 3:0] palette_idx_out // background palette idx for the current pixel
+);
+
+//
+// Background registers.
+//
+reg [ 2:0] q_fvc, d_fvc; // fine vertical scroll counter
+reg [ 4:0] q_vtc, d_vtc; // vertical tile index counter
+reg q_vc, d_vc; // vertical name table selection counter
+reg [ 4:0] q_htc, d_htc; // horizontal tile index counter
+reg q_hc, d_hc; // horizontal name table selection counter
+
+reg [ 7:0] q_par, d_par; // picture address register (holds tile index)
+reg [ 1:0] q_ar, d_ar; // tile attribute value latch (bits 3 and 2)
+reg [ 7:0] q_pd0, d_pd0; // palette data 0 (bit 0 for tile)
+reg [ 7:0] q_pd1, d_pd1; // palette data 1 (bit 1 for tile)
+
+reg [ 8:0] q_bg_bit3_shift, d_bg_bit3_shift; // shift register with per-pixel bg palette idx bit 3
+reg [ 8:0] q_bg_bit2_shift, d_bg_bit2_shift; // shift register with per-pixel bg palette idx bit 2
+reg [15:0] q_bg_bit1_shift, d_bg_bit1_shift; // shift register with per-pixel bg palette idx bit 1
+reg [15:0] q_bg_bit0_shift, d_bg_bit0_shift; // shift register with per-pixel bg palette idx bit 0
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_fvc <= 2\'h0;
+ q_vtc <= 5\'h00;
+ q_vc <= 1\'h0;
+ q_htc <= 5\'h00;
+ q_hc <= 1\'h0;
+ q_par <= 8\'h00;
+ q_ar <= 2\'h0;
+ q_pd0 <= 8\'h00;
+ q_pd1 <= 8\'h00;
+ q_bg_bit3_shift <= 9\'h000;
+ q_bg_bit2_shift <= 9\'h000;
+ q_bg_bit1_shift <= 16\'h0000;
+ q_bg_bit0_shift <= 16\'h0000;
+ end
+ else
+ begin
+ q_fvc <= d_fvc;
+ q_vtc <= d_vtc;
+ q_vc <= d_vc;
+ q_htc <= d_htc;
+ q_hc <= d_hc;
+ q_par <= d_par;
+ q_ar <= d_ar;
+ q_pd0 <= d_pd0;
+ q_pd1 <= d_pd1;
+ q_bg_bit3_shift <= d_bg_bit3_shift;
+ q_bg_bit2_shift <= d_bg_bit2_shift;
+ q_bg_bit1_shift <= d_bg_bit1_shift;
+ q_bg_bit0_shift <= d_bg_bit0_shift;
+ end
+ end
+
+//
+// Scroll counter management.
+//
+reg upd_v_cntrs;
+reg upd_h_cntrs;
+reg inc_v_cntrs;
+reg inc_h_cntrs;
+
+always @*
+ begin
+ // Default to original values.
+ d_fvc = q_fvc;
+ d_vc = q_vc;
+ d_hc = q_hc;
+ d_vtc = q_vtc;
+ d_htc = q_htc;
+
+ if (ri_inc_addr_in)
+ begin
+ // If the VRAM address increment bit (2000.2) is clear (inc. amt. = 1), all the scroll
+ // counters are daisy-chained (in the order of HT, VT, H, V, FV) so that the carry out of
+ // each counter controls the next counter\'s clock rate. The result is that all 5 counters
+ // function as a single 15-bit one. Any access to 2007 clocks the HT counter here.
+ //
+ // If the VRAM address increment bit is set (inc. amt. = 32), the only difference is that
+ // the HT counter is no longer being clocked, and the VT counter is now being clocked by
+ // access to 2007.
+ if (ri_inc_addr_amt_in)
+ { d_fvc, d_vc, d_hc, d_vtc } = { q_fvc, q_vc, q_hc, q_vtc } + 10\'h001;
+ else
+ { d_fvc, d_vc, d_hc, d_vtc, d_htc } = { q_fvc, q_vc, q_hc, q_vtc, q_htc } + 15\'h0001;
+ end
+ else
+ begin
+ if (inc_v_cntrs)
+ begin
+ // The vertical scroll counter is 9 bits, and is made up by daisy-chaining FV to VT, and
+ // VT to V. FV is clocked by the PPU\'s horizontal blanking impulse, and therefore will
+ // increment every scanline. VT operates here as a divide-by-30 counter, and will only
+ // generate a carry condition when the count increments from 29 to 30 (the counter will
+ // also reset). Dividing by 30 is neccessary to prevent attribute data in the name
+ // tables from being used as tile index data.
+ if ({ q_vtc, q_fvc } == { 5\'b1_1101, 3\'b111 })
+ { d_vc, d_vtc, d_fvc } = { ~q_vc, 8\'h00 };
+ else
+ { d_vc, d_vtc, d_fvc } = { q_vc, q_vtc, q_fvc } + 9\'h001;
+ end
+
+ if (inc_h_cntrs)
+ begin
+ // The horizontal scroll counter consists of 6 bits, and is made up by daisy-chaining the
+ // HT counter to the H counter. The HT counter is then clocked every 8 pixel dot clocks
+ // (or every 8/3 CPU clock cycles).
+ { d_hc, d_htc } = { q_hc, q_htc } + 6\'h01;
+ end
+
+ // Counter loading. There are 2 conditions that update all 5 PPU scroll counters with the
+ // contents of the latches adjacent to them. The first is after a write to 2006/2. The
+ // second, is at the beginning of scanline 20, when the PPU starts rendering data for the
+ // first time in a frame (this update won\'t happen if all rendering is disabled via 2001.3
+ // and 2001.4).
+ //
+ // There is one condition that updates the H & HT counters, and that is at the end of the
+ // horizontal blanking period of a scanline. Again, image rendering must be occuring for
+ // this update to be effective.
+ if (upd_v_cntrs || ri_upd_cntrs_in)
+ begin
+ d_vc = v_in;
+ d_vtc = vt_in;
+ d_fvc = fv_in;
+ end
+
+ if (upd_h_cntrs || ri_upd_cntrs_in)
+ begin
+ d_hc = h_in;
+ d_htc = ht_in;
+ end
+ end
+ end
+
+//
+// VRAM address derivation logic.
+//
+localparam [2:0] VRAM_A_SEL_RI = 3\'h0,
+ VRAM_A_SEL_NT_READ = 3\'h1,
+ VRAM_A_SEL_AT_READ = 3\'h2,
+ VRAM_A_SEL_PT0_READ = 3\'h3,
+ VRAM_A_SEL_PT1_READ = 3\'h4;
+
+reg [2:0] vram_a_sel;
+
+always @*
+ begin
+ case (vram_a_sel)
+ VRAM_A_SEL_NT_READ:
+ vram_a_out = { 2\'b10, q_vc, q_hc, q_vtc, q_htc };
+ VRAM_A_SEL_AT_READ:
+ vram_a_out = { 2\'b10, q_vc, q_hc, 4\'b1111, q_vtc[4:2], q_htc[4:2] };
+ VRAM_A_SEL_PT0_READ:
+ vram_a_out = { 1\'b0, s_in, q_par, 1\'b0, q_fvc };
+ VRAM_A_SEL_PT1_READ:
+ vram_a_out = { 1\'b0, s_in, q_par, 1\'b1, q_fvc };
+ default:
+ vram_a_out = { q_fvc[1:0], q_vc, q_hc, q_vtc, q_htc };
+ endcase
+ end
+
+//
+// Background palette index derivation logic.
+//
+wire clip;
+
+always @*
+ begin
+ // Default to original value.
+ d_par = q_par;
+ d_ar = q_ar;
+ d_pd0 = q_pd0;
+ d_pd1 = q_pd1;
+ d_bg_bit3_shift = q_bg_bit3_shift;
+ d_bg_bit2_shift = q_bg_bit2_shift;
+ d_bg_bit1_shift = q_bg_bit1_shift;
+ d_bg_bit0_shift = q_bg_bit0_shift;
+
+ upd_v_cntrs = 1\'b0;
+ inc_v_cntrs = 1\'b0;
+ upd_h_cntrs = 1\'b0;
+ inc_h_cntrs = 1\'b0;
+
+ vram_a_sel = VRAM_A_SEL_RI;
+
+ if (en_in && ((nes_y_in < 239) || (nes_y_next_in == 0)))
+ begin
+ if (pix_pulse_in && (nes_x_in == 319))
+ begin
+ upd_h_cntrs = 1\'b1;
+
+ if (nes_y_next_in != nes_y_in)
+ begin
+ if (nes_y_next_in == 0)
+ upd_v_cntrs = 1\'b1;
+ else
+ inc_v_cntrs = 1\'b1;
+ end
+ end
+
+ if ((nes_x_in < 256) || ((nes_x_in >= 320 && nes_x_in < 336)))
+ begin
+ if (pix_pulse_in)
+ begin
+ d_bg_bit3_shift = { q_bg_bit3_shift[8], q_bg_bit3_shift[8:1] };
+ d_bg_bit2_shift = { q_bg_bit2_shift[8], q_bg_bit2_shift[8:1] };
+ d_bg_bit1_shift = { 1\'b0, q_bg_bit1_shift[15:1] };
+ d_bg_bit0_shift = { 1\'b0, q_bg_bit0_shift[15:1] };
+ end
+
+ if (pix_pulse_in && (nes_x_in[2:0] == 3\'h7))
+ begin
+ inc_h_cntrs = 1\'b1;
+
+ d_bg_bit3_shift[8] = q_ar[1];
+ d_bg_bit2_shift[8] = q_ar[0];
+
+ d_bg_bit1_shift[15] = q_pd1[0];
+ d_bg_bit1_shift[14] = q_pd1[1];
+ d_bg_bit1_shift[13] = q_pd1[2];
+ d_bg_bit1_shift[12] = q_pd1[3];
+ d_bg_bit1_shift[11] = q_pd1[4];
+ d_bg_bit1_shift[10] = q_pd1[5];
+ d_bg_bit1_shift[ 9] = q_pd1[6];
+ d_bg_bit1_shift[ 8] = q_pd1[7];
+
+ d_bg_bit0_shift[15] = q_pd0[0];
+ d_bg_bit0_shift[14] = q_pd0[1];
+ d_bg_bit0_shift[13] = q_pd0[2];
+ d_bg_bit0_shift[12] = q_pd0[3];
+ d_bg_bit0_shift[11] = q_pd0[4];
+ d_bg_bit0_shift[10] = q_pd0[5];
+ d_bg_bit0_shift[ 9] = q_pd0[6];
+ d_bg_bit0_shift[ 8] = q_pd0[7];
+ end
+
+ case (nes_x_in[2:0])
+ 3\'b000:
+ begin
+ vram_a_sel = VRAM_A_SEL_NT_READ;
+ d_par = vram_d_in;
+ end
+ 3\'b001:
+ begin
+ vram_a_sel = VRAM_A_SEL_AT_READ;
+ d_ar = vram_d_in >> { q_vtc[1], q_htc[1], 1\'b0 };
+ end
+ 3\'b010:
+ begin
+ vram_a_sel = VRAM_A_SEL_PT0_READ;
+ d_pd0 = vram_d_in;
+ end
+ 3\'b011:
+ begin
+ vram_a_sel = VRAM_A_SEL_PT1_READ;
+ d_pd1 = vram_d_in;
+ end
+ endcase
+ end
+ end
+ end
+
+assign clip = ls_clip_in && (nes_x_in >= 10\'h000) && (nes_x_in < 10\'h008);
+assign palette_idx_out = (!clip && en_in) ? { q_bg_bit3_shift[fh_in],
+ q_bg_bit2_shift[fh_in],
+ q_bg_bit1_shift[fh_in],
+ q_bg_bit0_shift[fh_in] } : 4\'h0;
+
+endmodule
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/ppu/ppu_vga.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* VGA output PPU sub-block.
+***************************************************************************************************/
+
+module ppu_vga
+(
+ input wire clk_in, // 100MHz system clock signal
+ input wire rst_in, // reset signal
+ input wire [5:0] sys_palette_idx_in, // system palette index (selects output color)
+ output wire hsync_out, // vga hsync signal
+ output wire vsync_out, // vga vsync signal
+ output wire [2:0] r_out, // vga red signal
+ output wire [2:0] g_out, // vga green signal
+ output wire [1:0] b_out, // vga blue signal
+ output wire [9:0] nes_x_out, // nes x coordinate
+ output wire [9:0] nes_y_out, // nes y coordinate
+ output wire [9:0] nes_y_next_out, // next line\'s nes y coordinate
+ output wire pix_pulse_out, // 1 clk pulse prior to nes_x update
+ output wire vblank_out // indicates a vblank is occuring (no PPU vram access)
+);
+
+// Display dimensions (640x480).
+localparam [9:0] DISPLAY_W = 10\'h280,
+ DISPLAY_H = 10\'h1E0;
+
+// NES screen dimensions (256x240).
+localparam [9:0] NES_W = 10\'h100,
+ NES_H = 10\'h0F0;
+
+// Border color (surrounding NES screen).
+localparam [7:0] BORDER_COLOR = 8\'h49;
+
+//
+// VGA_SYNC: VGA synchronization control block.
+//
+wire sync_en; // vga enable signal
+wire [9:0] sync_x; // current vga x coordinate
+wire [9:0] sync_y; // current vga y coordinate
+wire [9:0] sync_x_next; // vga x coordinate for next clock
+wire [9:0] sync_y_next; // vga y coordinate for next line
+
+vga_sync vga_sync_blk(
+ .clk(clk_in),
+ .hsync(hsync_out),
+ .vsync(vsync_out),
+ .en(sync_en),
+ .x(sync_x),
+ .y(sync_y),
+ .x_next(sync_x_next),
+ .y_next(sync_y_next)
+);
+
+//
+// Registers.
+//
+reg [7:0] q_rgb; // output color latch (1 clk delay required by vga_sync)
+reg [7:0] d_rgb;
+reg q_vblank; // current vblank state
+wire d_vblank;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_rgb <= 8\'h00;
+ q_vblank <= 1\'h0;
+ end
+ else
+ begin
+ q_rgb <= d_rgb;
+ q_vblank <= d_vblank;
+ end
+ end
+
+//
+// Coord and timing signals.
+//
+wire [9:0] nes_x_next; // nes x coordinate for next clock
+wire border; // indicates we are displaying a vga pixel outside the nes extents
+
+assign nes_x_out = (sync_x - 10\'h040) >> 1;
+assign nes_y_out = sync_y >> 1;
+assign nes_x_next = (sync_x_next - 10\'h040) >> 1;
+assign nes_y_next_out = sync_y_next >> 1;
+assign border = (nes_x_out >= NES_W) || (nes_y_out < 8) || (nes_y_out >= (NES_H - 8));
+
+//
+// Lookup RGB values based on sys_palette_idx.
+//
+always @*
+ begin
+ if (!sync_en)
+ begin
+ d_rgb = 8\'h00;
+ end
+ else if (border)
+ begin
+ d_rgb = BORDER_COLOR;
+ end
+ else
+ begin
+ // Lookup RGB values based on sys_palette_idx. Table is an approximation of the NES
+ // system palette. Taken from http://nesdev.parodius.com/NESTechFAQ.htm#nessnescompat.
+ case (sys_palette_idx_in)
+ 6\'h00: d_rgb = { 3\'h3, 3\'h3, 2\'h1 };
+ 6\'h01: d_rgb = { 3\'h1, 3\'h0, 2\'h2 };
+ 6\'h02: d_rgb = { 3\'h0, 3\'h0, 2\'h2 };
+ 6\'h03: d_rgb = { 3\'h2, 3\'h0, 2\'h2 };
+ 6\'h04: d_rgb = { 3\'h4, 3\'h0, 2\'h1 };
+ 6\'h05: d_rgb = { 3\'h5, 3\'h0, 2\'h0 };
+ 6\'h06: d_rgb = { 3\'h5, 3\'h0, 2\'h0 };
+ 6\'h07: d_rgb = { 3\'h3, 3\'h0, 2\'h0 };
+ 6\'h08: d_rgb = { 3\'h2, 3\'h1, 2\'h0 };
+ 6\'h09: d_rgb = { 3\'h0, 3\'h2, 2\'h0 };
+ 6\'h0a: d_rgb = { 3\'h0, 3\'h2, 2\'h0 };
+ 6\'h0b: d_rgb = { 3\'h0, 3\'h1, 2\'h0 };
+ 6\'h0c: d_rgb = { 3\'h0, 3\'h1, 2\'h1 };
+ 6\'h0d: d_rgb = { 3\'h0, 3\'h0, 2\'h0 };
+ 6\'h0e: d_rgb = { 3\'h0, 3\'h0, 2\'h0 };
+ 6\'h0f: d_rgb = { 3\'h0, 3\'h0, 2\'h0 };
+
+ 6\'h10: d_rgb = { 3\'h5, 3\'h5, 2\'h2 };
+ 6\'h11: d_rgb = { 3\'h0, 3\'h3, 2\'h3 };
+ 6\'h12: d_rgb = { 3\'h1, 3\'h1, 2\'h3 };
+ 6\'h13: d_rgb = { 3\'h4, 3\'h0, 2\'h3 };
+ 6\'h14: d_rgb = { 3\'h5, 3\'h0, 2\'h2 };
+ 6\'h15: d_rgb = { 3\'h7, 3\'h0, 2\'h1 };
+ 6\'h16: d_rgb = { 3\'h6, 3\'h1, 2\'h0 };
+ 6\'h17: d_rgb = { 3\'h6, 3\'h2, 2\'h0 };
+ 6\'h18: d_rgb = { 3\'h4, 3\'h3, 2\'h0 };
+ 6\'h19: d_rgb = { 3\'h0, 3\'h4, 2\'h0 };
+ 6\'h1a: d_rgb = { 3\'h0, 3\'h5, 2\'h0 };
+ 6\'h1b: d_rgb = { 3\'h0, 3\'h4, 2\'h0 };
+ 6\'h1c: d_rgb = { 3\'h0, 3\'h4, 2\'h2 };
+ 6\'h1d: d_rgb = { 3\'h0, 3\'h0, 2\'h0 };
+ 6\'h1e: d_rgb = { 3\'h0, 3\'h0, 2\'h0 };
+ 6\'h1f: d_rgb = { 3\'h0, 3\'h0, 2\'h0 };
+
+ 6\'h20: d_rgb = { 3\'h7, 3\'h7, 2\'h3 };
+ 6\'h21: d_rgb = { 3\'h1, 3\'h5, 2\'h3 };
+ 6\'h22: d_rgb = { 3\'h2, 3\'h4, 2\'h3 };
+ 6\'h23: d_rgb = { 3\'h5, 3\'h4, 2\'h3 };
+ 6\'h24: d_rgb = { 3\'h7, 3\'h3, 2\'h3 };
+ 6\'h25: d_rgb = { 3\'h7, 3\'h3, 2\'h2 };
+ 6\'h26: d_rgb = { 3\'h7, 3\'h3, 2\'h1 };
+ 6\'h27: d_rgb = { 3\'h7, 3\'h4, 2\'h0 };
+ 6\'h28: d_rgb = { 3\'h7, 3\'h5, 2\'h0 };
+ 6\'h29: d_rgb = { 3\'h4, 3\'h6, 2\'h0 };
+ 6\'h2a: d_rgb = { 3\'h2, 3\'h6, 2\'h1 };
+ 6\'h2b: d_rgb = { 3\'h2, 3\'h7, 2\'h2 };
+ 6\'h2c: d_rgb = { 3\'h0, 3\'h7, 2\'h3 };
+ 6\'h2d: d_rgb = { 3\'h0, 3\'h0, 2\'h0 };
+ 6\'h2e: d_rgb = { 3\'h0, 3\'h0, 2\'h0 };
+ 6\'h2f: d_rgb = { 3\'h0, 3\'h0, 2\'h0 };
+
+ 6\'h30: d_rgb = { 3\'h7, 3\'h7, 2\'h3 };
+ 6\'h31: d_rgb = { 3\'h5, 3\'h7, 2\'h3 };
+ 6\'h32: d_rgb = { 3\'h6, 3\'h6, 2\'h3 };
+ 6\'h33: d_rgb = { 3\'h6, 3\'h6, 2\'h3 };
+ 6\'h34: d_rgb = { 3\'h7, 3\'h6, 2\'h3 };
+ 6\'h35: d_rgb = { 3\'h7, 3\'h6, 2\'h3 };
+ 6\'h36: d_rgb = { 3\'h7, 3\'h5, 2\'h2 };
+ 6\'h37: d_rgb = { 3\'h7, 3\'h6, 2\'h2 };
+ 6\'h38: d_rgb = { 3\'h7, 3\'h7, 2\'h2 };
+ 6\'h39: d_rgb = { 3\'h7, 3\'h7, 2\'h2 };
+ 6\'h3a: d_rgb = { 3\'h5, 3\'h7, 2\'h2 };
+ 6\'h3b: d_rgb = { 3\'h5, 3\'h7, 2\'h3 };
+ 6\'h3c: d_rgb = { 3\'h4, 3\'h7, 2\'h3 };
+ 6\'h3d: d_rgb = { 3\'h0, 3\'h0, 2\'h0 };
+ 6\'h3e: d_rgb = { 3\'h0, 3\'h0, 2\'h0 };
+ 6\'h3f: d_rgb = { 3\'h0, 3\'h0, 2\'h0 };
+ endcase
+ end
+ end
+
+assign { r_out, g_out, b_out } = q_rgb;
+assign pix_pulse_out = nes_x_next != nes_x_out;
+
+// Clear the VBLANK signal immediately before starting processing of the pre-0 garbage line. From
+// here. Set the vblank approximately 2270 CPU cycles before it will be cleared. This is done
+// in order to pass vbl_clear_time.nes. It eats into the visible portion of the playfield, but we
+// currently hide that portion of the screen anyway.
+assign d_vblank = ((sync_x == 730) && (sync_y == 477)) ? 1\'b1 :
+ ((sync_x == 64) && (sync_y == 519)) ? 1\'b0 : q_vblank;
+
+assign vblank_out = q_vblank;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cart/cart.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Cartridge emulator for an fpga-based NES emulator. This block provides access to cartridge
+* memories (PRG-ROM, CHR-ROM) and emulates mapper functionality in order to play emulation ROMs.
+* The intention is that this interface could be re-implemented on top of a hardware NES
+* cartridge, where almost all of the work would pass through directly.
+***************************************************************************************************/
+
+module cart
+(
+ input wire clk_in, // system clock signal
+
+ // Mapper config data.
+ input wire [39:0] cfg_in, // cartridge config (from iNES header)
+ input wire cfg_upd_in, // pulse signal on cfg_in update
+
+ // PRG-ROM interface.
+ input wire prg_nce_in, // prg-rom chip enable (active low)
+ input wire [14:0] prg_a_in, // prg-rom address
+ input wire prg_r_nw_in, // prg-rom read/write select
+ input wire [ 7:0] prg_d_in, // prg-rom data in
+ output wire [ 7:0] prg_d_out, // prg-rom data out
+
+ // CHR-ROM interface.
+ input wire [13:0] chr_a_in, // chr-rom address
+ input wire chr_r_nw_in, // chr-rom read/write select
+ input wire [ 7:0] chr_d_in, // chr-rom data in
+ output wire [ 7:0] chr_d_out, // chr-rom data out
+ output wire ciram_nce_out, // vram chip enable (active low)
+ output wire ciram_a10_out // vram a10 value (controls mirroring)
+);
+
+wire prgrom_bram_we;
+wire [14:0] prgrom_bram_a;
+wire [7:0] prgrom_bram_dout;
+
+// Block ram instance for PRG-ROM memory range (0x8000 - 0xFFFF). Will eventually be
+// replaced with SRAM.
+single_port_ram_sync #(.ADDR_WIDTH(15),
+ .DATA_WIDTH(8)) prgrom_bram(
+ .clk(clk_in),
+ .we(prgrom_bram_we),
+ .addr_a(prgrom_bram_a),
+ .din_a(prg_d_in),
+ .dout_a(prgrom_bram_dout)
+);
+
+assign prgrom_bram_we = (~prg_nce_in) ? ~prg_r_nw_in : 1\'b0;
+assign prg_d_out = (~prg_nce_in) ? prgrom_bram_dout : 8\'h00;
+assign prgrom_bram_a = (cfg_in[33]) ? prg_a_in[14:0] : { 1\'b0, prg_a_in[13:0] };
+
+wire chrrom_pat_bram_we;
+wire [7:0] chrrom_pat_bram_dout;
+
+// Block ram instance for ""CHR Pattern Table"" memory range (0x0000 - 0x1FFF).
+single_port_ram_sync #(.ADDR_WIDTH(13),
+ .DATA_WIDTH(8)) chrrom_pat_bram(
+ .clk(clk_in),
+ .we(chrrom_pat_bram_we),
+ .addr_a(chr_a_in[12:0]),
+ .din_a(chr_d_in),
+ .dout_a(chrrom_pat_bram_dout)
+);
+
+assign ciram_nce_out = ~chr_a_in[13];
+assign ciram_a10_out = (cfg_in[16]) ? chr_a_in[10] : chr_a_in[11];
+assign chrrom_pat_bram_we = (ciram_nce_out) ? ~chr_r_nw_in : 1\'b0;
+assign chr_d_out = (ciram_nce_out) ? chrrom_pat_bram_dout : 8\'h00;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cpu/apu/apu_length_counter.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* APU length counter; building block used by several other APU components. Provides automatic
+* duration control for the NES APU waveform channels. Once loaded with a value, it can optionally
+* count down and silence the channel when it reaches zero.
+***************************************************************************************************/
+
+module apu_length_counter
+(
+ input wire clk_in, // system clock signal
+ input wire rst_in, // reset signal
+ input wire en_in, // enable signal (from $4015)
+ input wire halt_in, // disable length decrement
+ input wire length_pulse_in, // length pulse from frame counter
+ input wire [4:0] length_in, // new length value
+ input wire length_wr_in, // update length to length_in
+ output wire en_out // length counter is non-0
+);
+
+reg [7:0] q_length, d_length;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_length <= 8\'h00;
+ end
+ else
+ begin
+ q_length <= d_length;
+ end
+ end
+
+always @*
+ begin
+ d_length = q_length;
+
+ if (!en_in)
+ begin
+ d_length = 8\'h00;
+ end
+ else if (length_wr_in)
+ begin
+ case (length_in)
+ 5\'h00: d_length = 8\'h0A;
+ 5\'h01: d_length = 8\'hFE;
+ 5\'h02: d_length = 8\'h14;
+ 5\'h03: d_length = 8\'h02;
+ 5\'h04: d_length = 8\'h28;
+ 5\'h05: d_length = 8\'h04;
+ 5\'h06: d_length = 8\'h50;
+ 5\'h07: d_length = 8\'h06;
+ 5\'h08: d_length = 8\'hA0;
+ 5\'h09: d_length = 8\'h08;
+ 5\'h0A: d_length = 8\'h3C;
+ 5\'h0B: d_length = 8\'h0A;
+ 5\'h0C: d_length = 8\'h0E;
+ 5\'h0D: d_length = 8\'h0C;
+ 5\'h0E: d_length = 8\'h1A;
+ 5\'h0F: d_length = 8\'h0E;
+ 5\'h10: d_length = 8\'h0C;
+ 5\'h11: d_length = 8\'h10;
+ 5\'h12: d_length = 8\'h18;
+ 5\'h13: d_length = 8\'h12;
+ 5\'h14: d_length = 8\'h30;
+ 5\'h15: d_length = 8\'h14;
+ 5\'h16: d_length = 8\'h60;
+ 5\'h17: d_length = 8\'h16;
+ 5\'h18: d_length = 8\'hC0;
+ 5\'h19: d_length = 8\'h18;
+ 5\'h1A: d_length = 8\'h48;
+ 5\'h1B: d_length = 8\'h1A;
+ 5\'h1C: d_length = 8\'h10;
+ 5\'h1D: d_length = 8\'h1C;
+ 5\'h1E: d_length = 8\'h20;
+ 5\'h1F: d_length = 8\'h1E;
+ endcase
+ end
+ else if (length_pulse_in && !halt_in && (q_length != 8\'h00))
+ begin
+ d_length = q_length - 8\'h01;
+ end
+ end
+
+assign en_out = (q_length != 8\'h00);
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cpu/cpu.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* 6502 core implementation.
+***************************************************************************************************/
+
+module cpu
+(
+ input wire clk_in, // 100MHz system clock
+ input wire rst_in, // reset signal
+ input wire ready_in, // ready signal
+
+ // Interrupt lines.
+ input wire nnmi_in, // /nmi interrupt signal (active low)
+ input wire nres_in, // /res interrupt signal (console reset, active low)
+ input wire nirq_in, // /irq intterupt signal (active low)
+
+ // Memory bus.
+ input wire [ 7:0] d_in, // data input bus
+ output wire [ 7:0] d_out, // data output bus
+ output wire [15:0] a_out, // address bus
+ output reg r_nw_out, // R/!W signal
+
+ // Debug support.
+ input wire [ 3:0] dbgreg_sel_in, // dbg reg select
+ input wire [ 7:0] dbgreg_in, // dbg reg write input
+ input wire dbgreg_wr_in, // dbg reg rd/wr select
+ output reg [ 7:0] dbgreg_out, // dbg reg read output
+ output reg brk_out // debug break signal
+);
+
+// dbgreg_sel defines. Selects register for read/write through the debugger block.
+`define REGSEL_PCL 0
+`define REGSEL_PCH 1
+`define REGSEL_AC 2
+`define REGSEL_X 3
+`define REGSEL_Y 4
+`define REGSEL_P 5
+`define REGSEL_S 6
+
+// Opcodes.
+localparam [7:0] ADC_ABS = 8\'h6D, ADC_ABSX = 8\'h7D, ADC_ABSY = 8\'h79, ADC_IMM = 8\'h69,
+ ADC_INDX = 8\'h61, ADC_INDY = 8\'h71, ADC_ZP = 8\'h65,
+ ADC_ZPX = 8\'h75,
+ AND_ABS = 8\'h2D, AND_ABSX = 8\'h3D, AND_ABSY = 8\'h39, AND_IMM = 8\'h29,
+ AND_INDX = 8\'h21, AND_INDY = 8\'h31, AND_ZP = 8\'h25,
+ AND_ZPX = 8\'h35,
+ ASL_ABS = 8\'h0E, ASL_ABSX = 8\'h1E, ASL_ACC = 8\'h0A, ASL_ZP = 8\'h06,
+ ASL_ZPX = 8\'h16,
+ BCC = 8\'h90,
+ BCS = 8\'hB0,
+ BEQ = 8\'hF0,
+ BIT_ABS = 8\'h2C, BIT_ZP = 8\'h24,
+ BMI = 8\'h30,
+ BNE = 8\'hD0,
+ BPL = 8\'h10,
+ BRK = 8\'h00,
+ BVC = 8\'h50,
+ BVS = 8\'h70,
+ CLC = 8\'h18,
+ CLD = 8\'hD8,
+ CLI = 8\'h58,
+ CLV = 8\'hB8,
+ CMP_ABS = 8\'hCD, CMP_ABSX = 8\'hDD, CMP_ABSY = 8\'hD9, CMP_IMM = 8\'hC9,
+ CMP_INDX = 8\'hC1, CMP_INDY = 8\'hD1, CMP_ZP = 8\'hC5,
+ CMP_ZPX = 8\'hD5,
+ CPX_ABS = 8\'hEC, CPX_IMM = 8\'hE0, CPX_ZP = 8\'hE4,
+ CPY_ABS = 8\'hCC, CPY_IMM = 8\'hC0, CPY_ZP = 8\'hC4,
+ DEC_ABS = 8\'hCE, DEC_ABSX = 8\'hDE, DEC_ZP = 8\'hC6, DEC_ZPX = 8\'hD6,
+ DEX = 8\'hCA,
+ DEY = 8\'h88,
+ EOR_ABS = 8\'h4D, EOR_ABSX = 8\'h5D, EOR_ABSY = 8\'h59, EOR_IMM = 8\'h49,
+ EOR_INDX = 8\'h41, EOR_INDY = 8\'h51, EOR_ZP = 8\'h45,
+ EOR_ZPX = 8\'h55,
+ HLT = 8\'h02,
+ INC_ABS = 8\'hEE, INC_ABSX = 8\'hFE, INC_ZP = 8\'hE6, INC_ZPX = 8\'hF6,
+ INX = 8\'hE8,
+ INY = 8\'hC8,
+ JMP_ABS = 8\'h4C, JMP_IND = 8\'h6C,
+ JSR = 8\'h20,
+ LDA_ABS = 8\'hAD, LDA_ABSX = 8\'hBD, LDA_ABSY = 8\'hB9, LDA_IMM = 8\'hA9,
+ LDA_INDX = 8\'hA1, LDA_INDY = 8\'hB1, LDA_ZP = 8\'hA5,
+ LDA_ZPX = 8\'hB5,
+ LDX_ABS = 8\'hAE, LDX_ABSY = 8\'hBE, LDX_IMM = 8\'hA2, LDX_ZP = 8\'hA6,
+ LDX_ZPY = 8\'hB6,
+ LDY_ABS = 8\'hAC, LDY_ABSX = 8\'hBC, LDY_IMM = 8\'hA0, LDY_ZP = 8\'hA4,
+ LDY_ZPX = 8\'hB4,
+ LSR_ABS = 8\'h4E, LSR_ABSX = 8\'h5E, LSR_ACC = 8\'h4A, LSR_ZP = 8\'h46,
+ LSR_ZPX = 8\'h56,
+ NOP = 8\'hEA,
+ ORA_ABS = 8\'h0D, ORA_ABSX = 8\'h1D, ORA_ABSY = 8\'h19, ORA_IMM = 8\'h09,
+ ORA_INDX = 8\'h01, ORA_INDY = 8\'h11, ORA_ZP = 8\'h05,
+ ORA_ZPX = 8\'h15,
+ PHA = 8\'h48,
+ PHP = 8\'h08,
+ PLA = 8\'h68,
+ PLP = 8\'h28,
+ ROL_ABS = 8\'h2E, ROL_ABSX = 8\'h3E, ROL_ACC = 8\'h2A, ROL_ZP = 8\'h26,
+ ROL_ZPX = 8\'h36,
+ ROR_ABS = 8\'h6E, ROR_ABSX = 8\'h7E, ROR_ACC = 8\'h6A, ROR_ZP = 8\'h66,
+ ROR_ZPX = 8\'h76,
+ RTI = 8\'h40,
+ RTS = 8\'h60,
+ SAX_ABS = 8\'h8F, SAX_INDX = 8\'h83, SAX_ZP = 8\'h87, SAX_ZPY = 8\'h97,
+ SBC_ABS = 8\'hED, SBC_ABSX = 8\'hFD, SBC_ABSY = 8\'hF9, SBC_IMM = 8\'hE9,
+ SBC_INDX = 8\'hE1, SBC_INDY = 8\'hF1, SBC_ZP = 8\'hE5,
+ SBC_ZPX = 8\'hF5,
+ SEC = 8\'h38,
+ SED = 8\'hF8,
+ SEI = 8\'h78,
+ STA_ABS = 8\'h8D, STA_ABSX = 8\'h9D, STA_ABSY = 8\'h99, STA_INDX = 8\'h81,
+ STA_INDY = 8\'h91, STA_ZP = 8\'h85, STA_ZPX = 8\'h95,
+ STX_ABS = 8\'h8E, STX_ZP = 8\'h86, STX_ZPY = 8\'h96,
+ STY_ABS = 8\'h8C, STY_ZP = 8\'h84, STY_ZPX = 8\'h94,
+ TAX = 8\'hAA,
+ TAY = 8\'hA8,
+ TSX = 8\'hBA,
+ TXA = 8\'h8A,
+ TXS = 8\'h9A,
+ TYA = 8\'h98;
+
+// Macro to check if a value is a valid opcode.
+`define IS_VALID_OPCODE(op) \\
+ (((op) == ADC_ABS ) || ((op) == ADC_ABSX) || ((op) == ADC_ABSY) || ((op) == ADC_IMM ) || \\
+ ((op) == ADC_INDX) || ((op) == ADC_INDY) || ((op) == ADC_ZP ) || ((op) == ADC_ZPX ) || \\
+ ((op) == AND_ABS ) || ((op) == AND_ABSX) || ((op) == AND_ABSY) || ((op) == AND_IMM ) || \\
+ ((op) == AND_INDX) || ((op) == AND_INDY) || ((op) == AND_ZP ) || ((op) == AND_ZPX ) || \\
+ ((op) == ASL_ABS ) || ((op) == ASL_ABSX) || ((op) == ASL_ACC ) || ((op) == ASL_ZP ) || \\
+ ((op) == ASL_ZPX ) || ((op) == BCC ) || ((op) == BCS ) || ((op) == BEQ ) || \\
+ ((op) == BIT_ABS ) || ((op) == BIT_ZP ) || ((op) == BMI ) || ((op) == BNE ) || \\
+ ((op) == BPL ) || ((op) == BRK ) || ((op) == BVC ) || ((op) == BVS ) || \\
+ ((op) == CLC ) || ((op) == CLD ) || ((op) == CLI ) || ((op) == CLV ) || \\
+ ((op) == CMP_ABS ) || ((op) == CMP_ABSX) || ((op) == CMP_ABSY) || ((op) == CMP_IMM ) || \\
+ ((op) == CMP_INDX) || ((op) == CMP_INDY) || ((op) == CMP_ZP ) || ((op) == CMP_ZPX ) || \\
+ ((op) == CPX_ABS ) || ((op) == CPX_IMM ) || ((op) == CPX_ZP ) || ((op) == CPY_ABS ) || \\
+ ((op) == CPY_IMM ) || ((op) == CPY_ZP ) || ((op) == DEC_ABS ) || ((op) == DEC_ABSX) || \\
+ ((op) == DEC_ZP ) || ((op) == DEC_ZPX ) || ((op) == DEX ) || ((op) == DEY ) || \\
+ ((op) == EOR_ABS ) || ((op) == EOR_ABSX) || ((op) == EOR_ABSY) || ((op) == EOR_IMM ) || \\
+ ((op) == EOR_INDX) || ((op) == EOR_INDY) || ((op) == EOR_ZP ) || ((op) == EOR_ZPX ) || \\
+ ((op) == HLT ) || ((op) == INC_ABS ) || ((op) == INC_ABSX) || ((op) == INC_ZP ) || \\
+ ((op) == INC_ZPX ) || ((op) == INX ) || ((op) == INY ) || ((op) == JMP_ABS ) || \\
+ ((op) == JMP_IND ) || ((op) == JSR ) || ((op) == LDA_ABS ) || ((op) == LDA_ABSX) || \\
+ ((op) == LDA_ABSY) || ((op) == LDA_IMM ) || ((op) == LDA_INDX) || ((op) == LDA_INDY) || \\
+ ((op) == LDA_ZP ) || ((op) == LDA_ZPX ) || ((op) == LDX_ABS ) || ((op) == LDX_ABSY) || \\
+ ((op) == LDX_IMM ) || ((op) == LDX_ZP ) || ((op) == LDX_ZPY ) || ((op) == LDY_ABS ) || \\
+ ((op) == LDY_ABSX) || ((op) == LDY_IMM ) || ((op) == LDY_ZP ) || ((op) == LDY_ZPX ) || \\
+ ((op) == LSR_ABS ) || ((op) == LSR_ABSX) || ((op) == LSR_ACC ) || ((op) == LSR_ZP ) || \\
+ ((op) == LSR_ZPX ) || ((op) == NOP ) || ((op) == ORA_ABS ) || ((op) == ORA_ABSX) || \\
+ ((op) == ORA_ABSY) || ((op) == ORA_IMM ) || ((op) == ORA_INDX) || ((op) == ORA_INDY) || \\
+ ((op) == ORA_ZP ) || ((op) == ORA_ZPX ) || ((op) == PHA ) || ((op) == PHP ) || \\
+ ((op) == PLA ) || ((op) == PLP ) || ((op) == ROL_ABS ) || ((op) == ROL_ABSX) || \\
+ ((op) == ROL_ACC ) || ((op) == ROL_ZP ) || ((op) == ROL_ZPX ) || ((op) == ROR_ABS ) || \\
+ ((op) == ROR_ABSX) || ((op) == ROR_ACC ) || ((op) == ROR_ZP ) || ((op) == ROR_ZPX ) || \\
+ ((op) == RTI ) || ((op) == RTS ) || ((op) == SAX_ABS ) || ((op) == SAX_INDX) || \\
+ ((op) == SAX_ZP ) || ((op) == SAX_ZPY ) || ((op) == SBC_ABS ) || ((op) == SBC_ABSX) || \\
+ ((op) == SBC_ABSY) || ((op) == SBC_IMM ) || ((op) == SBC_INDX) || ((op) == SBC_INDY) || \\
+ ((op) == SBC_ZP ) || ((op) == SBC_ZPX ) || ((op) == SEC ) || ((op) == SED ) || \\
+ ((op) == SEI ) || ((op) == STA_ABS ) || ((op) == STA_ABSX) || ((op) == STA_ABSY) || \\
+ ((op) == STA_INDX) || ((op) == STA_INDY) || ((op) == STA_ZP ) || ((op) == STA_ZPX ) || \\
+ ((op) == STX_ABS ) || ((op) == STX_ZP ) || ((op) == STX_ZPY ) || ((op) == STY_ABS ) || \\
+ ((op) == STY_ZP ) || ((op) == STY_ZPX ) || ((op) == TAX ) || ((op) == TAY ) || \\
+ ((op) == TSX ) || ((op) == TXA ) || ((op) == TXS ) || ((op) == TYA ))
+
+// Timing generation cycle states.
+localparam [2:0] T0 = 3\'h0,
+ T1 = 3\'h1,
+ T2 = 3\'h2,
+ T3 = 3\'h3,
+ T4 = 3\'h4,
+ T5 = 3\'h5,
+ T6 = 3\'h6;
+
+// Interrupt types.
+localparam [1:0] INTERRUPT_RST = 2\'h0,
+ INTERRUPT_NMI = 2\'h1,
+ INTERRUPT_IRQ = 2\'h2,
+ INTERRUPT_BRK = 2\'h3;
+
+// User registers.
+reg [7:0] q_ac; // accumulator register
+wire [7:0] d_ac;
+reg [7:0] q_x; // x index register
+wire [7:0] d_x;
+reg [7:0] q_y; // y index register
+wire [7:0] d_y;
+
+// Processor status register.
+wire [7:0] p; // full processor status reg, grouped from the following FFs
+reg q_c; // carry flag
+wire d_c;
+reg q_d; // decimal mode flag
+wire d_d;
+reg q_i; // interrupt disable flag
+wire d_i;
+reg q_n; // negative flag
+wire d_n;
+reg q_v; // overflow flag
+wire d_v;
+reg q_z; // zero flag
+wire d_z;
+
+// Internal registers.
+reg [7:0] q_abh; // address bus high register
+wire [7:0] d_abh;
+reg [7:0] q_abl; // address bus low register
+wire [7:0] d_abl;
+reg q_acr; // internal carry latch
+reg [7:0] q_add; // adder hold register
+reg [7:0] d_add;
+reg [7:0] q_ai; // alu input register a
+wire [7:0] d_ai;
+reg [7:0] q_bi; // alu input register b
+wire [7:0] d_bi;
+reg [7:0] q_dl; // input data latch
+wire [7:0] d_dl;
+reg [7:0] q_dor; // data output register
+wire [7:0] d_dor;
+reg [7:0] q_ir; // instruction register
+reg [7:0] d_ir;
+reg [7:0] q_pch; // program counter high register
+wire [7:0] d_pch;
+reg [7:0] q_pcl; // program counter low register
+wire [7:0] d_pcl;
+reg [7:0] q_pchs; // program counter high select register
+wire [7:0] d_pchs;
+reg [7:0] q_pcls; // program counter low select register
+wire [7:0] d_pcls;
+reg [7:0] q_pd; // pre-decode register
+wire [7:0] d_pd;
+reg [7:0] q_s; // stack pointer register
+wire [7:0] d_s;
+reg [2:0] q_t; // timing cycle register
+reg [2:0] d_t;
+
+// Internal buses.
+wire [7:0] adl; // ADL bus
+wire [7:0] adh_in, // ADH bus
+ adh_out;
+wire [7:0] db_in, // DB bus
+ db_out;
+wire [7:0] sb_in, // SB bus
+ sb_out;
+
+//
+// Internal control signals. These names are all taken directly from the original 6502 block
+// diagram.
+//
+
+// ADL bus drive enables.
+wire add_adl; // output adder hold register to adl bus
+wire dl_adl; // output dl reg to adl bus
+wire pcl_adl; // output pcl reg to adl bus
+wire s_adl; // output s reg to adl bus
+
+// ADH bus drive enables.
+wire dl_adh; // output dl reg to adh bus
+wire pch_adh; // output pch reg to adh bus
+wire zero_adh0; // output 0 to bit 0 of adh bus
+wire zero_adh17; // output 0 to bits 1-7 of adh bus
+
+// DB bus drive enables.
+wire ac_db; // output ac reg to db bus
+wire dl_db; // output dl reg to db bus
+wire p_db; // output p reg to db bus
+wire pch_db; // output pch reg to db bus
+wire pcl_db; // output pcl reg to db bus
+
+// SB bus drive enables.
+wire ac_sb; // output ac reg to sb bus
+wire add_sb; // output add reg to sb bus
+wire x_sb; // output x reg to sb bus
+wire y_sb; // output y reg to sb bus
+wire s_sb; // output s reg to sb bus
+
+// Pass MOSFET controls.
+wire sb_adh; // controls sb/adh pass mosfet
+wire sb_db; // controls sb/db pass mosfet
+
+// Register LOAD controls.
+wire adh_abh; // latch adh bus value in abh reg
+wire adl_abl; // latch adl bus value in abl reg
+wire sb_ac; // latch sb bus value in ac reg
+wire adl_add; // latch adl bus value in bi reg
+wire db_add; // latch db bus value in bi reg
+wire invdb_add; // latch ~db value in bi reg
+wire sb_add; // latch sb bus value in ai reg
+wire zero_add; // latch 0 into ai reg
+wire adh_pch; // latch adh bus value in pch reg
+wire adl_pcl; // latch adl bus value in pcl reg
+wire sb_s; // latch sb bus value in s reg
+wire sb_x; // latch sb bus value in x reg
+wire sb_y; // latch sb bus value in y reg
+
+// Processor status controls.
+wire acr_c; // latch acr into c status reg
+wire db0_c; // latch db[0] into c status reg
+wire ir5_c; // latch ir[5] into c status reg
+wire db3_d; // latch db[3] into d status reg
+wire ir5_d; // latch ir[5] into d status reg
+wire db2_i; // latch db[2] into i status reg
+wire ir5_i; // latch ir[5] into i status reg
+wire db7_n; // latch db[7] into n status reg
+wire avr_v; // latch avr into v status reg
+wire db6_v; // latch db[6] into v status reg
+wire zero_v; // latch 0 into v status reg
+wire db1_z; // latch db[1] into z status reg
+wire dbz_z; // latch ~|db into z status reg
+
+// Misc. controls.
+wire i_pc; // increment pc
+
+// ALU controls, signals.
+wire ands; // perform bitwise and on alu
+wire eors; // perform bitwise xor on alu
+wire ors; // perform bitwise or on alu
+wire sums; // perform addition on alu
+wire srs; // perform right bitshift
+wire addc; // carry in
+reg acr; // carry out
+reg avr; // overflow out
+
+//
+// Ready Control.
+//
+wire rdy; // internal, modified ready signal.
+reg q_ready; // latch external ready signal to delay 1 clk so top-level addr muxing can complete
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ q_ready <= 1\'b0;
+ else
+ q_ready <= ready_in;
+ end
+
+assign rdy = ready_in && q_ready;
+
+//
+// Clock phase generation logic.
+//
+reg [5:0] q_clk_phase;
+wire [5:0] d_clk_phase;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ q_clk_phase <= 6\'h01;
+ else if (rdy)
+ q_clk_phase <= d_clk_phase;
+
+ // If the debugger writes a PC register, this is a partial reset: the cycle is set to
+ // T0, and the clock phase should be set to the beginning of the 4 clock cycle.
+ else if (dbgreg_wr_in && ((dbgreg_sel_in == `REGSEL_PCH) || (dbgreg_sel_in == `REGSEL_PCL)))
+ q_clk_phase <= 6\'h01;
+ end
+
+assign d_clk_phase = (q_clk_phase == 6\'h37) ? 6\'h00 : q_clk_phase + 6\'h01;
+
+//
+// Interrupt and Reset Control.
+//
+reg [1:0] q_irq_sel, d_irq_sel; // interrupt selected for service
+
+reg q_rst; // rst interrupt needs to be serviced
+wire d_rst;
+reg q_nres; // latch last nres input signal for falling edge detection
+reg q_nmi; // nmi interrupt needs to be serviced
+wire d_nmi;
+reg q_nnmi; // latch last nnmi input signal for falling edge detection
+
+reg clear_rst; // clear rst interrupt
+reg clear_nmi; // clear nmi interrupt
+reg force_noinc_pc; // override stage-0 PC increment
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_irq_sel <= INTERRUPT_RST;
+ q_rst <= 1\'b0;
+ q_nres <= 1\'b1;
+ q_nmi <= 1\'b0;
+ q_nnmi <= 1\'b1;
+ end
+ else if (q_clk_phase == 6\'h00)
+ begin
+ q_irq_sel <= d_irq_sel;
+ q_rst <= d_rst;
+ q_nres <= nres_in;
+ q_nmi <= d_nmi;
+ q_nnmi <= nnmi_in;
+ end
+ end
+
+assign d_rst = (clear_rst) ? 1\'b0 :
+ (!nres_in && q_nres) ? 1\'b1 :
+ q_rst;
+assign d_nmi = (clear_nmi) ? 1\'b0 :
+ (!nnmi_in && q_nnmi) ? 1\'b1 :
+ q_nmi;
+
+//
+// Update phase-1 clocked registers.
+//
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_ac <= 8\'h00;
+ q_x <= 8\'h00;
+ q_y <= 8\'h00;
+ q_c <= 1\'b0;
+ q_d <= 1\'b0;
+ q_i <= 1\'b0;
+ q_n <= 1\'b0;
+ q_v <= 1\'b0;
+ q_z <= 1\'b0;
+ q_abh <= 8\'h80;
+ q_abl <= 8\'h00;
+ q_acr <= 1\'b0;
+ q_ai <= 8\'h00;
+ q_bi <= 8\'h00;
+ q_dor <= 8\'h00;
+ q_ir <= NOP;
+ q_pchs <= 8\'h80;
+ q_pcls <= 8\'h00;
+ q_s <= 8\'hFF;
+ q_t <= T1;
+ end
+ else if (rdy && (q_clk_phase == 6\'h00))
+ begin
+ q_ac <= d_ac;
+ q_x <= d_x;
+ q_y <= d_y;
+ q_c <= d_c;
+ q_d <= d_d;
+ q_i <= d_i;
+ q_n <= d_n;
+ q_v <= d_v;
+ q_z <= d_z;
+ q_abh <= d_abh;
+ q_abl <= d_abl;
+ q_acr <= acr;
+ q_ai <= d_ai;
+ q_bi <= d_bi;
+ q_dor <= d_dor;
+ q_ir <= d_ir;
+ q_pchs <= d_pchs;
+ q_pcls <= d_pcls;
+ q_s <= d_s;
+ q_t <= d_t;
+ end
+ else if (!rdy)
+ begin
+ // Update registers based on debug register write packets.
+ if (dbgreg_wr_in)
+ begin
+ q_ac <= (dbgreg_sel_in == `REGSEL_AC) ? dbgreg_in : q_ac;
+ q_x <= (dbgreg_sel_in == `REGSEL_X) ? dbgreg_in : q_x;
+ q_y <= (dbgreg_sel_in == `REGSEL_Y) ? dbgreg_in : q_y;
+ q_c <= (dbgreg_sel_in == `REGSEL_P) ? dbgreg_in[0] : q_c;
+ q_d <= (dbgreg_sel_in == `REGSEL_P) ? dbgreg_in[3] : q_d;
+ q_i <= (dbgreg_sel_in == `REGSEL_P) ? dbgreg_in[2] : q_i;
+ q_n <= (dbgreg_sel_in == `REGSEL_P) ? dbgreg_in[7] : q_n;
+ q_v <= (dbgreg_sel_in == `REGSEL_P) ? dbgreg_in[6] : q_v;
+ q_z <= (dbgreg_sel_in == `REGSEL_P) ? dbgreg_in[1] : q_z;
+
+ // Treat the debugger writing PC registers as a partial reset. Set the cycle to T0,
+ // and setup the address bus so the first opcode fill be fetched as soon as rdy is
+ // asserted again.
+ q_pchs <= (dbgreg_sel_in == `REGSEL_PCH) ? dbgreg_in : q_pchs;
+ q_pcls <= (dbgreg_sel_in == `REGSEL_PCL) ? dbgreg_in : q_pcls;
+ q_abh <= (dbgreg_sel_in == `REGSEL_PCH) ? dbgreg_in : q_abh;
+ q_abl <= (dbgreg_sel_in == `REGSEL_PCL) ? dbgreg_in : q_abl;
+ q_t <= ((dbgreg_sel_in == `REGSEL_PCH) || (dbgreg_sel_in == `REGSEL_PCL)) ? T0 : q_t;
+ end
+ end
+ end
+
+//
+// Update phase-2 clocked registers.
+//
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_pcl <= 8\'h00;
+ q_pch <= 8\'h80;
+ q_dl <= 8\'h00;
+ q_pd <= 8\'h00;
+ q_add <= 8\'h00;
+ end
+ else if (rdy && (q_clk_phase == 6\'h1C))
+ begin
+ q_pcl <= d_pcl;
+ q_pch <= d_pch;
+ q_dl <= d_dl;
+ q_pd <= d_pd;
+ q_add <= d_add;
+ end
+ else if (!rdy && dbgreg_wr_in)
+ begin
+ // Update registers based on debug register write packets.
+ q_pcl <= (dbgreg_sel_in == `REGSEL_PCL) ? dbgreg_in : q_pcl;
+ q_pch <= (dbgreg_sel_in == `REGSEL_PCH) ? dbgreg_in : q_pch;
+ end
+ end
+
+//
+// Timing Generation Logic
+//
+always @*
+ begin
+ d_t = T0;
+ d_irq_sel = q_irq_sel;
+ force_noinc_pc = 1\'b0;
+
+ case (q_t)
+ T0:
+ d_t = T1;
+ T1:
+ begin
+ // These instructions are in their last cycle but do not prefetch.
+ if ((q_ir == CLC) || (q_ir == CLD) || (q_ir == CLI) || (q_ir == CLV) ||
+ (q_ir == HLT) || (q_ir == LDA_IMM) || (q_ir == LDX_IMM) || (q_ir == LDY_IMM) ||
+ (q_ir == NOP) || (q_ir == SEC) || (q_ir == SED) || (q_ir == SEI) ||
+ (q_ir == TAX) || (q_ir == TAY) || (q_ir == TSX) || (q_ir == TXA) ||
+ (q_ir == TXS) || (q_ir == TYA))
+ begin
+ d_t = T0;
+ end
+
+ // Check for not-taken branches. These instructions must setup the not-taken PC during
+ // T1, and we can move to T0 of the next instruction.
+ else if (((q_ir == BCC) && q_c) || ((q_ir == BCS) && !q_c) ||
+ ((q_ir == BPL) && q_n) || ((q_ir == BMI) && !q_n) ||
+ ((q_ir == BVC) && q_v) || ((q_ir == BVS) && !q_v) ||
+ ((q_ir == BNE) && q_z) || ((q_ir == BEQ) && !q_z))
+ begin
+ d_t = T0;
+ end
+
+ else
+ begin
+ d_t = T2;
+ end
+ end
+ T2:
+ begin
+ // These instructions prefetch the next opcode during their final cycle.
+ if ((q_ir == ADC_IMM) || (q_ir == AND_IMM) || (q_ir == ASL_ACC) || (q_ir == CMP_IMM) ||
+ (q_ir == CPX_IMM) || (q_ir == CPY_IMM) || (q_ir == DEX) || (q_ir == DEY) ||
+ (q_ir == EOR_IMM) || (q_ir == INX) || (q_ir == INY) || (q_ir == LSR_ACC) ||
+ (q_ir == ORA_IMM) || (q_ir == ROL_ACC) || (q_ir == ROR_ACC) || (q_ir == SBC_IMM))
+ begin
+ d_t = T1;
+ end
+
+ // These instructions are in their last cycle but do not prefetch.
+ else if ((q_ir == JMP_ABS) || (q_ir == LDA_ZP) || (q_ir == LDX_ZP) || (q_ir == LDY_ZP) ||
+ (q_ir == SAX_ZP) || (q_ir == STA_ZP) || (q_ir == STX_ZP) || (q_ir == STY_ZP))
+ begin
+ d_t = T0;
+ end
+
+ // For ops using relative absolute addressing modes, we can skip stage 3 if the result
+ // doesn\'t cross a page boundary (i.e., don\'t need to add 1 to the high byte).
+ else if (!acr && ((q_ir == ADC_ABSX) || (q_ir == ADC_ABSY) || (q_ir == AND_ABSX) ||
+ (q_ir == AND_ABSY) || (q_ir == CMP_ABSX) || (q_ir == CMP_ABSY) ||
+ (q_ir == EOR_ABSX) || (q_ir == EOR_ABSY) || (q_ir == LDA_ABSX) ||
+ (q_ir == LDA_ABSY) || (q_ir == ORA_ABSX) || (q_ir == ORA_ABSY) ||
+ (q_ir == SBC_ABSX) || (q_ir == SBC_ABSY)))
+ begin
+ d_t = T4;
+ end
+
+ // For relative addressing ops (branches), we can skip stage 3 if the new PC doesn\'t
+ // cross a page boundary (forward or backward).
+ else if ((acr == q_ai[7]) && ((q_ir == BCC) || (q_ir == BCS) || (q_ir == BEQ) ||
+ (q_ir == BMI) || (q_ir == BNE) || (q_ir == BPL) ||
+ (q_ir == BVC) || (q_ir == BVS)))
+ begin
+ d_t = T0;
+ end
+
+ else
+ begin
+ d_t = T3;
+ end
+ end
+ T3:
+ begin
+ // These instructions prefetch the next opcode during their final cycle.
+ if ((q_ir == ADC_ZP) || (q_ir == AND_ZP) || (q_ir == BIT_ZP) || (q_ir == CMP_ZP) ||
+ (q_ir == CPX_ZP) || (q_ir == CPY_ZP) || (q_ir == EOR_ZP) || (q_ir == ORA_ZP) ||
+ (q_ir == PHA) || (q_ir == PHP) || (q_ir == SBC_ZP))
+ begin
+ d_t = T1;
+ end
+
+ // These instructions are in their last cycle but do not prefetch.
+ else if ((q_ir == BCC) || (q_ir == BCS) || (q_ir == BEQ) ||
+ (q_ir == BMI) || (q_ir == BNE) || (q_ir == BPL) ||
+ (q_ir == BVC) || (q_ir == BVS) || (q_ir == LDA_ABS) ||
+ (q_ir == LDA_ZPX) || (q_ir == LDX_ABS) || (q_ir == LDX_ZPY) ||
+ (q_ir == LDY_ABS) || (q_ir == LDY_ZPX) || (q_ir == PLA) ||
+ (q_ir == PLP) || (q_ir == SAX_ABS) || (q_ir == SAX_ZPY) ||
+ (q_ir == STA_ABS) || (q_ir == STA_ZPX) || (q_ir == STX_ABS) ||
+ (q_ir == STX_ZPY) || (q_ir == STY_ABS) || (q_ir == STY_ZPX))
+ begin
+ d_t = T0;
+ end
+
+ // For loads using (indirect),Y addressing modes, we can skip stage 4 if the result
+ // doesn\'t cross a page boundary (i.e., don\'t need to add 1 to the high byte).
+ else if (!acr && ((q_ir == ADC_INDY) || (q_ir == AND_INDY) || (q_ir == CMP_INDY) ||
+ (q_ir == EOR_INDY) || (q_ir == LDA_INDY) ||
+ (q_ir == ORA_INDY) || (q_ir == SBC_INDY)))
+ begin
+ d_t = T5;
+ end
+
+ else
+ begin
+ d_t = T4;
+ end
+ end
+ T4:
+ begin
+ // These instructions prefetch the next opcode during their final cycle.
+ if ((q_ir == ADC_ABS) || (q_ir == ADC_ZPX) || (q_ir == AND_ABS) || (q_ir == AND_ZPX) ||
+ (q_ir == BIT_ABS) || (q_ir == CMP_ABS) || (q_ir == CMP_ZPX) || (q_ir == CPX_ABS) ||
+ (q_ir == CPY_ABS) || (q_ir == EOR_ABS) || (q_ir == EOR_ZPX) || (q_ir == ORA_ABS) ||
+ (q_ir == ORA_ZPX) || (q_ir == SBC_ABS) || (q_ir == SBC_ZPX))
+ begin
+ d_t = T1;
+ end
+
+ // These instructions are in their last cycle but do not prefetch.
+ else if ((q_ir == ASL_ZP) || (q_ir == DEC_ZP) || (q_ir == INC_ZP) ||
+ (q_ir == JMP_IND) || (q_ir == LDA_ABSX) || (q_ir == LDA_ABSY) ||
+ (q_ir == LDX_ABSY) || (q_ir == LDY_ABSX) || (q_ir == LSR_ZP) ||
+ (q_ir == ROL_ZP) || (q_ir == ROR_ZP) || (q_ir == STA_ABSX) ||
+ (q_ir == STA_ABSY))
+ begin
+ d_t = T0;
+ end
+
+ else
+ begin
+ d_t = T5;
+ end
+ end
+ T5:
+ begin
+ // These instructions prefetch the next opcode during their final cycle.
+ if ((q_ir == ADC_ABSX) || (q_ir == ADC_ABSY) || (q_ir == AND_ABSX) ||
+ (q_ir == AND_ABSY) || (q_ir == CMP_ABSX) || (q_ir == CMP_ABSY) ||
+ (q_ir == EOR_ABSX) || (q_ir == EOR_ABSY) || (q_ir == ORA_ABSX) ||
+ (q_ir == ORA_ABSY) || (q_ir == SBC_ABSX) || (q_ir == SBC_ABSY))
+ begin
+ d_t = T1;
+ end
+
+ // These instructions are in their last cycle but do not prefetch.
+ else if ((q_ir == ASL_ABS) || (q_ir == ASL_ZPX) || (q_ir == DEC_ABS) ||
+ (q_ir == DEC_ZPX) || (q_ir == INC_ABS) || (q_ir == INC_ZPX) ||
+ (q_ir == JSR) || (q_ir == LDA_INDX) || (q_ir == LDA_INDY) ||
+ (q_ir == LSR_ABS) || (q_ir == LSR_ZPX) || (q_ir == ROL_ABS) ||
+ (q_ir == ROL_ZPX) || (q_ir == ROR_ABS) || (q_ir == ROR_ZPX) ||
+ (q_ir == RTI) || (q_ir == RTS) || (q_ir == SAX_INDX) ||
+ (q_ir == STA_INDX) || (q_ir == STA_INDY))
+ begin
+ d_t = T0;
+ end
+
+ else
+ begin
+ d_t = T6;
+ end
+ end
+ T6:
+ begin
+ // These instructions prefetch the next opcode during their final cycle.
+ if ((q_ir == ADC_INDX) || (q_ir == ADC_INDY) || (q_ir == AND_INDX) ||
+ (q_ir == AND_INDY) || (q_ir == CMP_INDX) || (q_ir == CMP_INDY) ||
+ (q_ir == EOR_INDX) || (q_ir == EOR_INDY) || (q_ir == ORA_INDX) ||
+ (q_ir == ORA_INDY) || (q_ir == SBC_INDX) || (q_ir == SBC_INDY))
+ begin
+ d_t = T1;
+ end
+
+ else
+ begin
+ d_t = T0;
+ end
+ end
+ endcase
+
+ // Update IR register on cycle 1, otherwise retain current IR.
+ if (d_t == T1)
+ begin
+ if (q_rst || q_nmi || !nirq_in)
+ begin
+ d_ir = BRK;
+ force_noinc_pc = 1\'b1;
+
+ if (q_rst)
+ d_irq_sel = INTERRUPT_RST;
+ else if (q_nmi)
+ d_irq_sel = INTERRUPT_NMI;
+ else
+ d_irq_sel = INTERRUPT_IRQ;
+ end
+ else
+ begin
+ d_ir = q_pd;
+ d_irq_sel = INTERRUPT_BRK;
+ end
+ end
+ else
+ begin
+ d_ir = q_ir;
+ end
+ end
+
+//
+// Decode ROM output signals. Corresponds to 130 bit bus coming out of the Decode ROM in the
+// block diagram, although the details of implementation will differ.
+//
+
+// PC and program stream controls.
+reg load_prg_byte; // put PC on addr bus and increment PC (adh, adl)
+reg load_prg_byte_noinc; // put PC on addr bus only (adh, adl)
+reg incpc_noload; // increment PC only (-)
+reg alusum_to_pch; // load pch with ai+bi (adh, sb)
+reg dl_to_pch; // load pch with current data latch register (adh)
+reg alusum_to_pcl; // load pcl with ai+bi (adl)
+reg s_to_pcl; // load pcl with s (adl)
+
+// Instruction-specific controls. Typically triggers the meat of a particular operation that
+// occurs regardless of addressing mode.
+reg adc_op; // final cycle of an adc inst (db, sb)
+reg and_op; // final cycle of an and inst (db, sb)
+reg asl_acc_op; // perform asl_acc inst (db, sb)
+reg asl_mem_op; // perform meat of asl inst for memory addressing modes (db, sb)
+reg bit_op; // final cycle of a bit inst (db, sb)
+reg cmp_op; // final cycle of a cmp inst (db, sb)
+reg clc_op; // clear carry bit (-)
+reg cld_op; // clear decimal mode bit (-)
+reg cli_op; // clear interrupt disable bit (-)
+reg clv_op; // clear overflow bit (-)
+reg dec_op; // perform meat of dec inst (db, sb)
+reg dex_op; // final cycle of a dex inst (db, sb)
+reg dey_op; // final cycle of a dey inst (db, sb)
+reg eor_op; // final cycle of an eor inst (db, sb)
+reg inc_op; // perform meat of inc inst (db, sb)
+reg inx_op; // final cycle of an inx inst (db, sb)
+reg iny_op; // final cycle of an iny inst (db, sb)
+reg lda_op; // final cycle of an lda inst (db, sb)
+reg ldx_op; // final cycle of an ldx inst (db, sb)
+reg ldy_op; // final cycle of an ldy inst (db, sb)
+reg lsr_acc_op; // perform lsr_acc inst (db, sb)
+reg lsr_mem_op; // perform meat of lsr inst for memory addressing modes (db, sb)
+reg ora_op; // final cycle of an ora inst (db, sb)
+reg rol_acc_op; // perform rol_acc inst (db, sb)
+reg rol_mem_op; // perform meat of rol inst for memory addressing modes (db, sb)
+reg ror_acc_op; // perform ror_acc inst (db, sb)
+reg ror_mem_op; // perform meat of ror inst for memory addressing modes (db, sb)
+reg sec_op; // set carry bit (-)
+reg sed_op; // set decimal mode bit (-)
+reg sei_op; // set interrupt disable bit (-)
+reg tax_op; // transfer ac to x (db, sb)
+reg tay_op; // transfer ac to y (db, sb)
+reg tsx_op; // transfer s to x (db, sb)
+reg txa_op; // transfer x to z (db, sb)
+reg txs_op; // transfer x to s (db, sb)
+reg tya_op; // transfer y to a (db, sb)
+
+// DOR (data output register) load controls.
+reg ac_to_dor; // load current ac value into dor (db)
+reg p_to_dor; // load current p value into dor (db)
+reg pch_to_dor; // load current pch value into dor (db)
+reg pcl_to_dor; // load current pcl value into dor (db)
+reg x_to_dor; // load current x value into dor (db, sb)
+reg y_to_dor; // load current y value into dor (db, sb)
+
+// AB (address bus hold registers) load controls.
+reg aluinc_to_abh; // load abh with ai+bi+1 (adh, sb)
+reg alusum_to_abh; // load abh with ai+bi (adh, sb)
+reg dl_to_abh; // load abh with dl (adh)
+reg ff_to_abh; // load abh with 8\'hff (adh)
+reg one_to_abh; // load abh with 8\'h01 (adh)
+reg zero_to_abh; // load abh with 8\'h00 (adh)
+reg aluinc_to_abl; // load abl with ai+bi+1 (adl)
+reg alusum_to_abl; // load abl with ai+bi (adl)
+reg dl_to_abl; // load abl with dl (adl)
+reg fa_to_abl; // load abl with 8\'hfa (adl)
+reg fb_to_abl; // load abl with 8\'hfb (adl)
+reg fc_to_abl; // load abl with 8\'hfc (adl)
+reg fd_to_abl; // load abl with 8\'hfd (adl)
+reg fe_to_abl; // load abl with 8\'hfe (adl)
+reg ff_to_abl; // load abl with 8\'hff (adl)
+reg s_to_abl; // load abl with s (adl)
+
+// AI/BI (ALU input registers) load controls.
+reg ac_to_ai; // load ai with ac (sb)
+reg dl_to_ai; // load ai with dl (db, sb)
+reg one_to_ai; // load ai with 1 (adh, sb)
+reg neg1_to_ai; // load ai with -1 (sb)
+reg s_to_ai; // load ai with s (sb)
+reg x_to_ai; // load ai with x (sb)
+reg y_to_ai; // load ai with y (sb)
+reg zero_to_ai; // load ai with 0 (sb)
+reg ac_to_bi; // load bi with ac (db)
+reg aluinc_to_bi; // load bi with ai+bi+1 (adl)
+reg alusum_to_bi; // load bi with ai+bi (adl)
+reg dl_to_bi; // load bi with dl (db)
+reg invdl_to_bi; // load bi with ~dl (db)
+reg neg1_to_bi; // load bi with -1 (db)
+reg pch_to_bi; // load bi with pch (db)
+reg pcl_to_bi; // load bi with pcl (adl)
+reg s_to_bi; // load bi with s (adl)
+reg x_to_bi; // load bi with x (db, sb)
+reg y_to_bi; // load bi with y (db, sb)
+
+// Stack related controls.
+reg aluinc_to_s; // load ai+bi+1 into s (sb)
+reg alusum_to_s; // load ai+bi into s (sb)
+reg dl_to_s; // load s with current data latch register (db, sb)
+
+// Process status register controls.
+reg dl_bits67_to_p; // latch bits 6 and 7 into P V and N bits (db)
+reg dl_to_p; // load dl into p (db)
+reg one_to_i; // used to supress irqs while processing an interrupt
+
+// Sets all decode ROM output signals to the specified value (0 for init, X for con\'t care states.
+`define SET_ALL_CONTROL_SIGNALS(val) \\
+ load_prg_byte = (val); \\
+ load_prg_byte_noinc = (val); \\
+ incpc_noload = (val); \\
+ alusum_to_pch = (val); \\
+ dl_to_pch = (val); \\
+ alusum_to_pcl = (val); \\
+ s_to_pcl = (val); \\
+ \\
+ adc_op = (val); \\
+ and_op = (val); \\
+ asl_acc_op = (val); \\
+ asl_mem_op = (val); \\
+ bit_op = (val); \\
+ cmp_op = (val); \\
+ clc_op = (val); \\
+ cld_op = (val); \\
+ cli_op = (val); \\
+ clv_op = (val); \\
+ dec_op = (val); \\
+ dex'b""_op = (val); \\
+ dey_op = (val); \\
+ eor_op = (val); \\
+ inc_op = (val); \\
+ inx_op = (val); \\
+ iny_op = (val); \\
+ lda_op = (val); \\
+ ldx_op = (val); \\
+ ldy_op = (val); \\
+ lsr_acc_op = (val); \\
+ lsr_mem_op = (val); \\
+ ora_op = (val); \\
+ rol_acc_op = (val); \\
+ rol_mem_op = (val); \\
+ ror_acc_op = (val); \\
+ ror_mem_op = (val); \\
+ sec_op = (val); \\
+ sed_op = (val); \\
+ sei_op = (val); \\
+ tax_op = (val); \\
+ tay_op = (val); \\
+ tsx_op = (val); \\
+ txa_op = (val); \\
+ txs_op = (val); \\
+ tya_op = (val); \\
+ \\
+ ac_to_dor = (val); \\
+ p_to_dor = (val); \\
+ pch_to_dor = (val); \\
+ pcl_to_dor = (val); \\
+ x_to_dor = (val); \\
+ y_to_dor = (val); \\
+ \\
+ aluinc_to_abh = (val); \\
+ alusum_to_abh = (val); \\
+ dl_to_abh = (val); \\
+ ff_to_abh = (val); \\
+ one_to_abh = (val); \\
+ zero_to_abh = (val); \\
+ aluinc_to_abl = (val); \\
+ alusum_to_abl = (val); \\
+ dl_to_abl = (val); \\
+ fa_to_abl = (val); \\
+ fb_to_abl = (val); \\
+ fc_to_abl = (val); \\
+ fd_to_abl = (val); \\
+ fe_to_abl = (val); \\
+ ff_to_abl = (val); \\
+ s_to_abl = (val); \\
+ \\
+ ac_to_ai = (val); \\
+ dl_to_ai = (val); \\
+ one_to_ai = (val); \\
+ neg1_to_ai = (val); \\
+ s_to_ai = (val); \\
+ x_to_ai = (val); \\
+ y_to_ai = (val); \\
+ zero_to_ai = (val); \\
+ ac_to_bi = (val); \\
+ aluinc_to_bi = (val); \\
+ alusum_to_bi = (val); \\
+ dl_to_bi = (val); \\
+ invdl_to_bi = (val); \\
+ neg1_to_bi = (val); \\
+ pch_to_bi = (val); \\
+ pcl_to_bi = (val); \\
+ s_to_bi = (val); \\
+ x_to_bi = (val); \\
+ y_to_bi = (val); \\
+ \\
+ aluinc_to_s = (val); \\
+ alusum_to_s = (val); \\
+ dl_to_s = (val); \\
+ \\
+ dl_to_p = (val); \\
+ dl_bits67_to_p = (val); \\
+ one_to_i = (val);
+
+//
+// Decode ROM logic.
+//
+always @*
+ begin
+ // Default all control signals to 0.
+ `SET_ALL_CONTROL_SIGNALS(1'b0)
+
+ // Defaults for output signals.
+ r_nw_out = 1'b1;
+ brk_out = 1'b0;
+ clear_rst = 1'b0;
+ clear_nmi = 1'b0;
+
+ if (q_t == T0)
+ begin
+ load_prg_byte = 1'b1;
+ end
+ else if (q_t == T1)
+ begin
+ case (q_ir)
+ ADC_ABS, AND_ABS, ASL_ABS, BIT_ABS, CMP_ABS, CPX_ABS, CPY_ABS, DEC_ABS, EOR_ABS,
+ INC_ABS, JMP_ABS, JMP_IND, LDA_ABS, LDX_ABS, LDY_ABS, LSR_ABS,
+ ORA_ABS, ROL_ABS, ROR_ABS, SAX_ABS, SBC_ABS,
+ STA_ABS, STX_ABS, STY_ABS:
+ begin
+ load_prg_byte = 1'b1;
+ zero_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ ADC_ABSX, AND_ABSX, ASL_ABSX, CMP_ABSX, DEC_ABSX, EOR_ABSX, INC_ABSX,
+ LDA_ABSX, LDY_ABSX, LSR_ABSX, ORA_ABSX, ROL_ABSX,
+ ROR_ABSX, SBC_ABSX, STA_ABSX:
+ begin
+ load_prg_byte = 1'b1;
+ x_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ ADC_ABSY, AND_ABSY, CMP_ABSY, EOR_ABSY, LDA_ABSY, LDX_ABSY,
+ ORA_ABSY, SBC_ABSY, STA_ABSY:
+ begin
+ load_prg_byte = 1'b1;
+ y_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ ADC_IMM, AND_IMM, EOR_IMM, ORA_IMM:
+ begin
+ load_prg_byte = 1'b1;
+ ac_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ ADC_INDX, AND_INDX, CMP_INDX, EOR_INDX, LDA_INDX, ORA_INDX,
+ SAX_INDX, SBC_INDX, STA_INDX,
+ ADC_ZPX, AND_ZPX, ASL_ZPX, CMP_ZPX, DEC_ZPX,
+ EOR_ZPX, INC_ZPX, LDA_ZPX, LDY_ZPX,
+ LSR_ZPX, ORA_ZPX, ROL_ZPX, ROR_ZPX, SBC_ZPX,
+ STA_ZPX, STY_ZPX:
+ begin
+ x_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ ADC_INDY, AND_INDY, CMP_INDY, EOR_INDY, LDA_INDY, ORA_INDY,
+ SBC_INDY, STA_INDY:
+ begin
+ zero_to_abh = 1'b1;
+ dl_to_abl = 1'b1;
+ zero_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ ADC_ZP, AND_ZP, ASL_ZP, BIT_ZP, CMP_ZP, CPX_ZP, CPY_ZP, DEC_ZP,
+ EOR_ZP, INC_ZP, LDA_ZP, LDX_ZP, LDY_ZP, LSR_ZP, ORA_ZP,
+ ROL_ZP, ROR_ZP, SBC_ZP:
+ begin
+ zero_to_abh = 1'b1;
+ dl_to_abl = 1'b1;
+ end
+ ASL_ACC, LSR_ACC, ROL_ACC, ROR_ACC:
+ begin
+ ac_to_ai = 1'b1;
+ ac_to_bi = 1'b1;
+ end
+ BCC, BCS, BEQ, BMI, BNE, BPL, BVC, BVS:
+ begin
+ load_prg_byte = 1'b1;
+ dl_to_ai = 1'b1;
+ pcl_to_bi = 1'b1;
+ end
+ BRK:
+ begin
+ if (q_irq_sel == INTERRUPT_BRK)
+ incpc_noload = 1'b1;
+ pch_to_dor = 1'b1;
+ one_to_abh = 1'b1;
+ s_to_abl = 1'b1;
+ neg1_to_ai = 1'b1;
+ s_to_bi = 1'b1;
+ end
+ CLC:
+ clc_op = 1'b1;
+ CLD:
+ cld_op = 1'b1;
+ CLI:
+ cli_op = 1'b1;
+ CLV:
+ clv_op = 1'b1;
+ CMP_IMM, SBC_IMM:
+ begin
+ load_prg_byte = 1'b1;
+ ac_to_ai = 1'b1;
+ invdl_to_bi = 1'b1;
+ end
+ CPX_IMM:
+ begin
+ load_prg_byte = 1'b1;
+ x_to_ai = 1'b1;
+ invdl_to_bi = 1'b1;
+ end
+ CPY_IMM:
+ begin
+ load_prg_byte = 1'b1;
+ y_to_ai = 1'b1;
+ invdl_to_bi = 1'b1;
+ end
+ DEX:
+ begin
+ x_to_ai = 1'b1;
+ neg1_to_bi = 1'b1;
+ end
+ DEY:
+ begin
+ y_to_ai = 1'b1;
+ neg1_to_bi = 1'b1;
+ end
+ HLT:
+ begin
+ // The HLT instruction asks hci to deassert the rdy signal, effectively pausing the
+ // cpu and allowing the debug block to inspect the internal state.
+ brk_out = (q_clk_phase == 6'h01) && rdy;
+ end
+ INX:
+ begin
+ zero_to_ai = 1'b1;
+ x_to_bi = 1'b1;
+ end
+ INY:
+ begin
+ zero_to_ai = 1'b1;
+ y_to_bi = 1'b1;
+ end
+ JSR:
+ begin
+ incpc_noload = 1'b1;
+ one_to_abh = 1'b1;
+ s_to_abl = 1'b1;
+ s_to_bi = 1'b1;
+ dl_to_s = 1'b1;
+ end
+ LDX_ZPY, SAX_ZPY, STX_ZPY:
+ begin
+ y_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ LDA_IMM:
+ begin
+ load_prg_byte = 1'b1;
+ lda_op = 1'b1;
+ end
+ LDX_IMM:
+ begin
+ load_prg_byte = 1'b1;
+ ldx_op = 1'b1;
+ end
+ LDY_IMM:
+ begin
+ load_prg_byte = 1'b1;
+ ldy_op = 1'b1;
+ end
+ PHA:
+ begin
+ ac_to_dor = 1'b1;
+ one_to_abh = 1'b1;
+ s_to_abl = 1'b1;
+ end
+ PHP:
+ begin
+ p_to_dor = 1'b1;
+ one_to_abh = 1'b1;
+ s_to_abl = 1'b1;
+ end
+ PLA, PLP, RTI, RTS:
+ begin
+ zero_to_ai = 1'b1;
+ s_to_bi = 1'b1;
+ end
+ SEC:
+ sec_op = 1'b1;
+ SED:
+ sed_op = 1'b1;
+ SEI:
+ sei_op = 1'b1;
+ SAX_ZP:
+ begin
+ ac_to_dor = 1'b1;
+ x_to_dor = 1'b1;
+ zero_to_abh = 1'b1;
+ dl_to_abl = 1'b1;
+ end
+ STA_ZP:
+ begin
+ ac_to_dor = 1'b1;
+ zero_to_abh = 1'b1;
+ dl_to_abl = 1'b1;
+ end
+ STX_ZP:
+ begin
+ x_to_dor = 1'b1;
+ zero_to_abh = 1'b1;
+ dl_to_abl = 1'b1;
+ end
+ STY_ZP:
+ begin
+ y_to_dor = 1'b1;
+ zero_to_abh = 1'b1;
+ dl_to_abl = 1'b1;
+ end
+ TAX:
+ tax_op = 1'b1;
+ TAY:
+ tay_op = 1'b1;
+ TSX:
+ tsx_op = 1'b1;
+ TXA:
+ txa_op = 1'b1;
+ TXS:
+ txs_op = 1'b1;
+ TYA:
+ tya_op = 1'b1;
+ endcase
+ end
+ else if (q_t == T2)
+ begin
+ case (q_ir)
+ ADC_ABS, AND_ABS, ASL_ABS, BIT_ABS, CMP_ABS, CPX_ABS, CPY_ABS, DEC_ABS, EOR_ABS,
+ INC_ABS, LDA_ABS, LDX_ABS, LDY_ABS, LSR_ABS, ORA_ABS,
+ ROL_ABS, ROR_ABS, SBC_ABS,
+ JMP_IND:
+ begin
+ dl_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ ADC_ABSX, AND_ABSX, ASL_ABSX, CMP_ABSX, DEC_ABSX, EOR_ABSX, INC_ABSX,
+ LDA_ABSX, LDY_ABSX, LSR_ABSX, ORA_ABSX, ROL_ABSX,
+ ROR_ABSX, SBC_ABSX, STA_ABSX,
+ ADC_ABSY, AND_ABSY, CMP_ABSY, EOR_ABSY, LDA_ABSY,
+ LDX_ABSY, ORA_ABSY, SBC_ABSY,
+ STA_ABSY:
+ begin
+ dl_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ zero_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ ADC_IMM, SBC_IMM:
+ begin
+ load_prg_byte = 1'b1;
+ adc_op = 1'b1;
+ end
+ ADC_INDX, AND_INDX, CMP_INDX, EOR_INDX, LDA_INDX, ORA_INDX,
+ SAX_INDX, SBC_INDX, STA_INDX,
+ ADC_ZPX, AND_ZPX, ASL_ZPX, CMP_ZPX, DEC_ZPX,
+ EOR_ZPX, INC_ZPX, LDA_ZPX, LDY_ZPX,
+ LSR_ZPX, ORA_ZPX, ROL_ZPX, ROR_ZPX, SBC_ZPX,
+ LDX_ZPY:
+ begin
+ zero_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ ADC_INDY, AND_INDY, CMP_INDY, EOR_INDY, LDA_INDY, ORA_INDY,
+ SBC_INDY, STA_INDY:
+ begin
+ zero_to_abh = 1'b1;
+ aluinc_to_abl = 1'b1;
+ y_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ ADC_ZP, AND_ZP, EOR_ZP, ORA_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ ac_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ AND_IMM:
+ begin
+ load_prg_byte = 1'b1;
+ and_op = 1'b1;
+ end
+ ASL_ACC:
+ begin
+ load_prg_byte = 1'b1;
+ asl_acc_op = 1'b1;
+ end
+ ASL_ZP, LSR_ZP, ROL_ZP, ROR_ZP:
+ begin
+ dl_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ LSR_ACC:
+ begin
+ load_prg_byte = 1'b1;
+ lsr_acc_op = 1'b1;
+ end
+ BCC, BCS, BEQ, BMI, BNE, BPL, BVC, BVS:
+ begin
+ alusum_to_pcl = 1'b1;
+ alusum_to_abl = 1'b1;
+ if (q_ai[7])
+ neg1_to_ai = 1'b1;
+ else
+ one_to_ai = 1'b1;
+ pch_to_bi = 1'b1;
+ end
+ BIT_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ ac_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ dl_bits67_to_p = 1'b1;
+ end
+ BRK:
+ begin
+ pcl_to_dor = 1'b1;
+ alusum_to_abl = 1'b1;
+ alusum_to_bi = 1'b1;
+ r_nw_out = 1'b0;
+ end
+ CMP_IMM, CPX_IMM, CPY_IMM:
+ begin
+ load_prg_byte = 1'b1;
+ cmp_op = 1'b1;
+ end
+ CMP_ZP, SBC_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ ac_to_ai = 1'b1;
+ invdl_to_bi = 1'b1;
+ end
+ CPX_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ x_to_ai = 1'b1;
+ invdl_to_bi = 1'b1;
+ end
+ CPY_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ y_to_ai = 1'b1;
+ invdl_to_bi = 1'b1;
+ end
+ DEC_ZP:
+ begin
+ neg1_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ DEX:
+ begin
+ load_prg_byte = 1'b1;
+ dex_op = 1'b1;
+ end
+ DEY:
+ begin
+ load_prg_byte = 1'b1;
+ dey_op = 1'b1;
+ end
+ EOR_IMM:
+ begin
+ load_prg_byte = 1'b1;
+ eor_op = 1'b1;
+ end
+ INC_ZP:
+ begin
+ zero_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ INX:
+ begin
+ load_prg_byte = 1'b1;
+ inx_op = 1'b1;
+ end
+ INY:
+ begin
+ load_prg_byte = 1'b1;
+ iny_op = 1'b1;
+ end
+ JMP_ABS:
+ begin
+ dl_to_pch = 1'b1;
+ alusum_to_pcl = 1'b1;
+ dl_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ JSR:
+ begin
+ pch_to_dor = 1'b1;
+ neg1_to_ai = 1'b1;
+ end
+ LDA_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ lda_op = 1'b1;
+ end
+ LDX_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ ldx_op = 1'b1;
+ end
+ LDY_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ ldy_op = 1'b1;
+ end
+ ORA_IMM:
+ begin
+ load_prg_byte = 1'b1;
+ ora_op = 1'b1;
+ end
+ PHA, PHP:
+ begin
+ load_prg_byte_noinc = 1'b1;
+ s_to_ai = 1'b1;
+ neg1_to_bi = 1'b1;
+ r_nw_out = 1'b0;
+ end
+ PLA, PLP:
+ begin
+ one_to_abh = 1'b1;
+ aluinc_to_abl = 1'b1;
+ aluinc_to_s = 1'b1;
+ end
+ ROL_ACC:
+ begin
+ load_prg_byte = 1'b1;
+ rol_acc_op = 1'b1;
+ end
+ ROR_ACC:
+ begin
+ load_prg_byte = 1'b1;
+ ror_acc_op = 1'b1;
+ end
+ RTI, RTS:
+ begin
+ one_to_abh = 1'b1;
+ aluinc_to_abl = 1'b1;
+ aluinc_to_bi = 1'b1;
+ end
+ SAX_ABS:
+ begin
+ ac_to_dor = 1'b1;
+ x_to_dor = 1'b1;
+ dl_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ SAX_ZP, STA_ZP, STX_ZP, STY_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ r_nw_out = 1'b0;
+ end
+ SAX_ZPY:
+ begin
+ ac_to_dor = 1'b1;
+ x_to_dor = 1'b1;
+ zero_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ STA_ABS:
+ begin
+ ac_to_dor = 1'b1;
+ dl_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ STA_ZPX:
+ begin
+ ac_to_dor = 1'b1;
+ zero_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ STX_ABS:
+ begin
+ x_to_dor = 1'b1;
+ dl_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ STX_ZPY:
+ begin
+ x_to_dor = 1'b1;
+ zero_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ STY_ABS:
+ begin
+ y_to_dor = 1'b1;
+ dl_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ STY_ZPX:
+ begin
+ y_to_dor = 1'b1;
+ zero_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ endcase
+ end
+ else if (q_t == T3)
+ begin
+ case (q_ir)
+ ADC_ABS, AND_ABS, EOR_ABS, ORA_ABS,
+ ADC_ZPX, AND_ZPX, EOR_ZPX, ORA_ZPX:
+ begin
+ load_prg_byte = 1'b1;
+ ac_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ ADC_ABSX, AND_ABSX, ASL_ABSX, CMP_ABSX, DEC_ABSX, EOR_ABSX, INC_ABSX,
+ LDA_ABSX, LDY_ABSX, LSR_ABSX, ORA_ABSX, ROL_ABSX,
+ ROR_ABSX, SBC_ABSX,
+ ADC_ABSY, AND_ABSY, CMP_ABSY, EOR_ABSY, LDA_ABSY,
+ LDX_ABSY, ORA_ABSY, SBC_ABSY:
+ begin
+ aluinc_to_abh = q_acr;
+ end
+ ADC_INDX, AND_INDX, CMP_INDX, EOR_INDX, LDA_INDX, ORA_INDX,
+ SAX_INDX, STA_INDX, SBC_INDX:
+ begin
+ zero_to_abh = 1'b1;
+ aluinc_to_abl = 1'b1;
+ zero_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ ADC_INDY, AND_INDY, CMP_INDY, EOR_INDY, LDA_INDY, ORA_INDY,
+ SBC_INDY, STA_INDY:
+ begin
+ dl_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ zero_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ ADC_ZP, SBC_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ adc_op = 1'b1;
+ end
+ AND_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ and_op = 1'b1;
+ end
+ ASL_ABS, LSR_ABS, ROL_ABS, ROR_ABS,
+ ASL_ZPX, LSR_ZPX, ROL_ZPX, ROR_ZPX:
+ begin
+ dl_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ ASL_ZP:
+ asl_mem_op = 1'b1;
+ BCC, BCS, BEQ, BMI, BNE, BPL, BVC, BVS:
+ begin
+ alusum_to_pch = 1'b1;
+ alusum_to_abh = 1'b1;
+ end
+ BIT_ABS:
+ begin
+ load_prg_byte = 1'b1;
+ ac_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ dl_bits67_to_p = 1'b1;
+ end
+ BIT_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ bit_op = 1'b1;
+ end
+ BRK:
+ begin
+ p_to_dor = 1'b1;
+ alusum_to_abl = 1'b1;
+ alusum_to_bi = 1'b1;
+ r_nw_out = 1'b0;
+ end
+ CMP_ABS, SBC_ABS,
+ CMP_ZPX, SBC_ZPX:
+ begin
+ load_prg_byte = 1'b1;
+ ac_to_ai = 1'b1;
+ invdl_to_bi = 1'b1;
+ end
+ CMP_ZP, CPX_ZP, CPY_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ cmp_op = 1'b1;
+ end
+ CPX_ABS:
+ begin
+ load_prg_byte = 1'b1;
+ x_to_ai = 1'b1;
+ invdl_to_bi = 1'b1;
+ end
+ CPY_ABS:
+ begin
+ load_prg_byte = 1'b1;
+ y_to_ai = 1'b1;
+ invdl_to_bi = 1'b1;
+ end
+ DEC_ABS,
+ DEC_ZPX:
+ begin
+ neg1_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ DEC_ZP:
+ dec_op = 1'b1;
+ EOR_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ eor_op = 1'b1;
+ end
+ INC_ABS,
+ INC_ZPX:
+ begin
+ zero_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ INC_ZP:
+ inc_op = 1'b1;
+ JMP_IND:
+ begin
+ aluinc_to_abl = 1'b1;
+ zero_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ JSR:
+ begin
+ pcl_to_dor = 1'b1;
+ alusum_to_abl = 1'b1;
+ alusum_to_bi = 1'b1;
+ r_nw_out = 1'b0;
+ end
+ LDA_ABS, LDA_ZPX:
+ begin
+ load_prg_byte = 1'b1;
+ lda_op = 1'b1;
+ end
+ LDX_ABS, LDX_ZPY:
+ begin
+ load_prg_byte = 1'b1;
+ ldx_op = 1'b1;
+ end
+ LDY_ABS, LDY_ZPX:
+ begin
+ load_prg_byte = 1'b1;
+ ldy_op = 1'b1;
+ end
+ LSR_ZP:
+ lsr_mem_op = 1'b1;
+ ORA_ZP:
+ begin
+ load_prg_byte = 1'b1;
+ ora_op = 1'b1;
+ end
+ PHA, PHP:
+ begin
+ load_prg_byte = 1'b1;
+ alusum_to_s = 1'b1;
+ end
+ PLA:
+ begin
+ load_prg_byte_noinc = 1'b1;
+ lda_op = 1'b1;
+ end
+ PLP:
+ begin
+ load_prg_byte_noinc = 1'b1;
+ dl_to_p = 1'b1;
+ end
+ ROL_ZP:
+ rol_mem_op = 1'b1;
+ ROR_ZP:
+ ror_mem_op = 1'b1;
+ RTI:
+ begin
+ aluinc_to_abl = 1'b1;
+ aluinc_to_bi = 1'b1;
+ dl_to_p = 1'b1;
+ end
+ RTS:
+ begin
+ aluinc_to_abl = 1'b1;
+ dl_to_s = 1'b1;
+ end
+ SAX_ABS, STA_ABS, STX_ABS, STY_ABS,
+ STA_ZPX, STY_ZPX,
+ SAX_ZPY, STX_ZPY:
+ begin
+ load_prg_byte = 1'b1;
+ r_nw_out = 1'b0;
+ end
+ STA_ABSX,
+ STA_ABSY:
+ begin
+ ac_to_dor = 1'b1;
+ aluinc_to_abh = q_acr;
+ end
+ endcase
+ end
+ else if (q_t == T4)
+ begin
+ case (q_ir)
+ ADC_ABS, SBC_ABS,
+ ADC_ZPX, SBC_ZPX:
+ begin
+ load_prg_byte = 1'b1;
+ adc_op = 1'b1;
+ end
+ ADC_ABSX, AND_ABSX, EOR_ABSX, ORA_ABSX,
+ ADC_ABSY, AND_ABSY, EOR_ABSY, ORA_ABSY:
+ begin
+ load_prg_byte = 1'b1;
+ ac_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ ADC_INDX, AND_INDX, CMP_INDX, EOR_INDX, LDA_INDX, ORA_INDX,
+ SBC_INDX:
+ begin
+ dl_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ ADC_INDY, AND_INDY, CMP_INDY, EOR_INDY, LDA_INDY, ORA_INDY,
+ SBC_INDY:
+ begin
+ aluinc_to_abh = q_acr;
+ end
+ AND_ABS,
+ AND_ZPX:
+ begin
+ load_prg_byte = 1'b1;
+ and_op = 1'b1;
+ end
+ ASL_ABS,
+ ASL_ZPX:
+ asl_mem_op = 1'b1;
+ ASL_ZP, DEC_ZP, INC_ZP, LSR_ZP, ROL_ZP, ROR_ZP,
+ STA_ABSX,
+ STA_ABSY:
+ begin
+ load_prg_byte = 1'b1;
+ r_nw_out = 1'b0;
+ end
+ ASL_ABSX, LSR_ABSX, ROL_ABSX, ROR_ABSX:
+ begin
+ dl_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ BIT_ABS:
+ begin
+ load_prg_byte = 1'b1;
+ bit_op = 1'b1;
+ end
+ BRK:
+ begin
+ ff_to_abh = 1'b1;
+ r_nw_out = 1'b0;
+ one_to_i = 1'b1;
+ case (q_irq_sel)
+ INTERRUPT_RST: fc_to_abl = 1'b1;
+ INTERRUPT_NMI: fa_to_abl = 1'b1;
+ INTERRUPT_IRQ, INTERRUPT_BRK: fe_to_abl = 1'b1;
+ endcase
+ end
+ CMP_ABS, CPX_ABS, CPY_ABS,
+ CMP_ZPX:
+ begin
+ load_prg_byte = 1'b1;
+ cmp_op = 1'b1;
+ end
+ CMP_ABSX, SBC_ABSX,
+ CMP_ABSY, SBC_ABSY:
+ begin
+ load_prg_byte = 1'b1;
+ ac_to_ai = 1'b1;
+ invdl_to_bi = 1'b1;
+ end
+ DEC_ABS,
+ DEC_ZPX:
+ dec_op = 1'b1;
+ DEC_ABSX:
+ begin
+ neg1_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ EOR_ABS,
+ EOR_ZPX:
+ begin
+ load_prg_byte = 1'b1;
+ eor_op = 1'b1;
+ end
+ INC_ABS,
+ INC_ZPX:
+ inc_op = 1'b1;
+ INC_ABSX:
+ begin
+ zero_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ JMP_IND:
+ begin
+ dl_to_pch = 1'b1;
+ alusum_to_pcl = 1'b1;
+ dl_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ JSR:
+ begin
+ load_prg_byte_noinc = 1'b1;
+ r_nw_out = 1'b0;
+ end
+ LDA_ABSX,
+ LDA_ABSY:
+ begin
+ load_prg_byte = 1'b1;
+ lda_op = 1'b1;
+ end
+ LDX_ABSY:
+ begin
+ load_prg_byte = 1'b1;
+ ldx_op = 1'b1;
+ end
+ LDY_ABSX:
+ begin
+ load_prg_byte = 1'b1;
+ ldy_op = 1'b1;
+ end
+ LSR_ABS,
+ LSR_ZPX:
+ lsr_mem_op = 1'b1;
+ ORA_ABS,
+ ORA_ZPX:
+ begin
+ load_prg_byte = 1'b1;
+ ora_op = 1'b1;
+ end
+ ROL_ABS,
+ ROL_ZPX:
+ rol_mem_op = 1'b1;
+ ROR_ABS,
+ ROR_ZPX:
+ ror_mem_op = 1'b1;
+ RTI:
+ begin
+ aluinc_to_abl = 1'b1;
+ dl_to_s = 1'b1;
+ end
+ RTS:
+ begin
+ dl_to_pch = 1'b1;
+ s_to_pcl = 1'b1;
+ aluinc_to_s = 1'b1;
+ end
+ SAX_INDX:
+ begin
+ ac_to_dor = 1'b1;
+ x_to_dor = 1'b1;
+ dl_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ STA_INDX:
+ begin
+ ac_to_dor = 1'b1;
+ dl_to_abh = 1'b1;
+ alusum_to_abl = 1'b1;
+ end
+ STA_INDY:
+ begin
+ ac_to_dor = 1'b1;
+ aluinc_to_abh = q_acr;
+ end
+ endcase
+ end
+ else if (q_t == T5)
+ begin
+ case (q_ir)
+ ADC_ABSX, SBC_ABSX,
+ ADC_ABSY, SBC_ABSY:
+ begin
+ load_prg_byte = 1'b1;
+ adc_op = 1'b1;
+ end
+ ADC_INDX, AND_INDX, EOR_INDX, ORA_INDX,
+ ADC_INDY, AND_INDY, EOR_INDY, ORA_INDY:
+ begin
+ load_prg_byte = 1'b1;
+ ac_to_ai = 1'b1;
+ dl_to_bi = 1'b1;
+ end
+ AND_ABSX,
+ AND_ABSY:
+ begin
+ load_prg_byte = 1'b1;
+ and_op = 1'b1;
+ end
+ ASL_ABS, DEC_ABS, INC_ABS, LSR_ABS, ROL_ABS, ROR_ABS,
+ ASL_ZPX, DEC_ZPX, INC_ZPX, LSR_ZPX, ROL_ZPX, ROR_ZPX,
+ SAX_INDX, STA_INDX,
+ STA_INDY:
+ begin
+ load_prg_byte = 1'b1;
+ r_nw_out = 1'b0;
+ end
+ ASL_ABSX:
+ asl_mem_op = 1'b1;
+ BRK:
+ begin
+ ff_to_abh = 1'b1;
+ dl_to_s = 1'b1;
+ case (q_irq_sel)
+ INTERRUPT_RST: fd_to_abl = 1'b1;
+ INTERRUPT_NMI: fb_to_abl = 1'b1;
+ INTERRUPT_IRQ, INTERRUPT_BRK: ff_to_abl = 1'b1;
+ endcase
+ end
+ CMP_ABSX,
+ CMP_ABSY:
+ begin
+ load_prg_byte = 1'b1;
+ cmp_op = 1'b1;
+ end
+ CMP_INDX, SBC_INDX,
+ CMP_INDY, SBC_INDY:
+ begin
+ load_prg_byte = 1'b1;
+ ac_to_ai = 1'b1;
+ invdl_to_bi = 1'b1;
+ end
+ DEC_ABSX:
+ dec_op = 1'b1;
+ EOR_ABSX,
+ EOR_ABSY:
+ begin
+ load_prg_byte = 1'b1;
+ eor_op = 1'b1;
+ end
+ INC_ABSX:
+ inc_op = 1'b1;
+ JSR:
+ begin
+ dl_to_pch = 1'b1;
+ s_to_pcl = 1'b1;
+ dl_to_abh = 1'b1;
+ s_to_abl = 1'b1;
+ alusum_to_s = 1'b1;
+ end
+ LDA_INDX,
+ LDA_INDY:
+ begin
+ load_prg_byte = 1'b1;
+ lda_op = 1'b1;
+ end
+ LSR_ABSX:
+ lsr_mem_op = 1'b1;
+ ORA_ABSX,
+ ORA_ABSY:
+ begin
+ load_prg_byte = 1'b1;
+ ora_op = 1'b1;
+ end
+ ROL_ABSX:
+ rol_mem_op = 1'b1;
+ ROR_ABSX:
+ ror_mem_op = 1'b1;
+ RTI:
+ begin
+ dl_to_pch = 1'b1;
+ s_to_pcl = 1'b1;
+ dl_to_abh = 1'b1;
+ s_to_abl = 1'b1;
+ aluinc_to_s = 1'b1;
+ end
+ RTS:
+ load_prg_byte = 1'b1;
+ endcase
+ end
+ else if (q_t == T6)
+ begin
+ case (q_ir)
+ ADC_INDX, SBC_INDX,
+ ADC_INDY, SBC_INDY:
+ begin
+ load_prg_byte = 1'b1;
+ adc_op = 1'b1;
+ end
+ AND_INDX,
+ AND_INDY:
+ begin
+ load_prg_byte = 1'b1;
+ and_op = 1'b1;
+ end
+ ASL_ABSX, DEC_ABSX, INC_ABSX, LSR_ABSX, ROL_ABSX, ROR_ABSX:
+ begin
+ load_prg_byte = 1'b1;
+ r_nw_out = 1'b0;
+ end
+ BRK:
+ begin
+ dl_to_pch = 1'b1;
+ s_to_pcl = 1'b1;
+ dl_to_abh = 1'b1;
+ s_to_abl = 1'b1;
+ alusum_to_s = 1'b1;
+
+ case (q_irq_sel)
+ INTERRUPT_RST: clear_rst = 1'b1;
+ INTERRUPT_NMI: clear_nmi = 1'b1;
+ endcase
+ end
+ CMP_INDX,
+ CMP_INDY:
+ begin
+ load_prg_byte = 1'b1;
+ cmp_op = 1'b1;
+ end
+ EOR_INDX,
+ EOR_INDY:
+ begin
+ load_prg_byte = 1'b1;
+ eor_op = 1'b1;
+ end
+ ORA_INDX,
+ ORA_INDY:
+ begin
+ load_prg_byte = 1'b1;
+ ora_op = 1'b1;
+ end
+ endcase
+ end
+ end
+
+//
+// ALU
+//
+always @*
+ begin
+ acr = 1'b0;
+ avr = 1'b0;
+
+ if (ands)
+ d_add = q_ai & q_bi;
+ else if (eors)
+ d_add = q_ai ^ q_bi;
+ else if (ors)
+ d_add = q_ai | q_bi;
+ else if (sums)
+ begin
+ { acr, d_add } = q_ai + q_bi + addc;
+ avr = ((q_ai[7] ^ q_bi[7]) ^ d_add[7]) ^ acr;
+ end
+ else if (srs)
+ { d_add, acr } = { addc, q_bi };
+ else
+ d_add = q_add;
+ end
+
+//
+// Random Control Logic
+//
+assign add_adl = aluinc_to_abl | aluinc_to_bi | alusum_to_abl |
+ alusum_to_bi | alusum_to_pcl;
+assign dl_adl = dl_to_abl;
+assign pcl_adl = load_prg_byte | load_prg_byte_noinc |
+ pcl_to_bi;
+assign s_adl = s_to_abl | s_to_bi | s_to_pcl;
+assign zero_adl0 = fa_to_abl | fc_to_abl | fe_to_abl;
+assign zero_adl1 = fc_to_abl | fd_to_abl;
+assign zero_adl2 = fa_to_abl | fb_to_abl;
+assign dl_adh = dl_to_abh | dl_to_pch;
+assign pch_adh = load_prg_byte | load_prg_byte_noinc;
+assign zero_adh0 = zero_to_abh;
+assign zero_adh17 = one_to_abh | one_to_ai | zero_to_abh;
+assign ac_db = ac_to_bi | ac_to_dor;
+assign dl_db = dl_to_ai | dl_to_bi |
+ dl_to_p | dl_to_s | invdl_to_bi |
+ lda_op | ldx_op | ldy_op;
+assign p_db = p_to_dor;
+assign pch_db = pch_to_bi | pch_to_dor;
+assign pcl_db = pcl_to_dor;
+assign ac_sb = ac_to_ai | tax_op | tay_op;
+assign add_sb = adc_op | aluinc_to_abh |
+ aluinc_to_s | alusum_to_abh | alusum_to_pch |
+ alusum_to_s | and_op |
+ asl_acc_op | asl_mem_op | bit_op |
+ cmp_op | dec_op | dex_op |
+ dey_op | eor_op | inc_op |
+ inx_op | iny_op | lsr_acc_op |
+ lsr_mem_op | ora_op | rol_acc_op |
+ rol_mem_op | ror_acc_op | ror_mem_op;
+assign x_sb = txa_op | txs_op | x_to_ai |
+ x_to_bi | x_to_dor;
+assign y_sb = tya_op | y_to_ai | y_to_bi |
+ y_to_dor;
+assign s_sb = s_to_ai | tsx_op;
+assign sb_adh = aluinc_to_abh | alusum_to_abh | alusum_to_pch |
+ one_to_ai | one_to_i;
+assign sb_db = adc_op |
+ and_op | asl_acc_op |
+ asl_mem_op | bit_op | cmp_op |
+ dl_to_s | dec_op | dex_op |
+ dey_op | dl_to_ai | eor_op |
+ inc_op | inx_op | iny_op |
+ lda_op | ldx_op | ldy_op |
+ lsr_acc_op | lsr_mem_op | one_to_i |
+ ora_op | rol_acc_op | rol_mem_op |
+ ror_acc_op | ror_mem_op | tax_op |
+ tay_op | tsx_op | txa_op |
+ tya_op | x_to_bi | x_to_dor |
+ y_to_bi | y_to_dor;
+assign adh_abh = aluinc_to_abh | alusum_to_abh | dl_to_abh |
+ ff_to_abh | load_prg_byte | load_prg_byte_noinc |
+ one_to_abh | zero_to_abh;
+assign adl_abl = aluinc_to_abl | alusum_to_abl | dl_to_abl |
+ fa_to_abl | fb_to_abl | fc_to_abl |
+ fd_to_abl | fe_to_abl | ff_to_abl |
+ load_prg_byte | load_prg_byte_noinc |
+ s_to_abl;
+assign adl_add = aluinc_to_bi | alusum_to_bi | pcl_to_bi |
+ s_to_bi;
+assign db_add = ac_to_bi | dl_to_bi |
+ neg1_to_bi | pch_to_bi | x_to_bi |
+ y_to_bi;
+assign invdb_add = invdl_to_bi;
+assign sb_s = aluinc_to_s | alusum_to_s | dl_to_s |
+ txs_op;
+assign zero_add = zero_to_ai;
+assign sb_ac = adc_op | and_op |
+ asl_acc_op | eor_op |
+ lda_op | lsr_acc_op | ora_op |
+ rol_acc_op | ror_acc_op | txa_op |
+ tya_op;
+assign sb_add = ac_to_ai | dl_to_ai | neg1_to_ai |
+ one_to_ai | s_to_ai | x_to_ai |
+ y_to_ai;
+assign adh_pch = alusum_to_pch | dl_to_pch;
+assign adl_pcl = alusum_to_pcl | s_to_pcl;
+assign sb_x = dex_op | inx_op | ldx_op |
+ tax_op | tsx_op;
+assign sb_y = dey_op | iny_op | ldy_op |
+ tay_op;
+assign acr_c = adc_op | asl_acc_op | asl_mem_op |
+ cmp_op | lsr_acc_op | lsr_mem_op |
+ rol_acc_op | rol_mem_op | ror_acc_op |
+ ror_mem_op;
+assign db0_c = dl_to_p;
+assign ir5_c = clc_op | sec_op;
+assign db3_d = dl_to_p;
+assign ir5_d = cld_op | sed_op;
+assign db2_i = dl_to_p | one_to_i;
+assign ir5_i = cli_op | sei_op;
+assign db7_n = adc_op | and_op |
+ asl_acc_op | asl_mem_op |
+ cmp_op | dec_op | dex_op |
+ dey_op | dl_bits67_to_p | dl_to_p |
+ eor_op | inc_op | inx_op |
+ iny_op | lda_op | ldx_op |
+ ldy_op | lsr_acc_op | lsr_mem_op |
+ ora_op | rol_acc_op | rol_mem_op |
+ ror_acc_op | ror_mem_op | tax_op |
+ tay_op | tsx_op | txa_op |
+ tya_op;
+assign avr_v = adc_op;
+assign db6_v = dl_bits67_to_p | dl_to_p;
+assign zero_v = clv_op;
+assign db1_z = dl_to_p;
+assign dbz_z = adc_op | and_op |
+ asl_acc_op | asl_mem_op |
+ bit_op | cmp_op | dec_op |
+ dex_op | dey_op | eor_op |
+ inc_op | inx_op | iny_op |
+ lda_op | ldx_op | ldy_op |
+ lsr_acc_op | lsr_mem_op | ora_op |
+ rol_acc_op | rol_mem_op | ror_acc_op |
+ ror_mem_op | tax_op | tay_op |
+ tsx_op | txa_op | tya_op;
+assign ands = and_op | bit_op;
+assign eors = eor_op;
+assign ors = ora_op;
+assign sums = adc_op | aluinc_to_abh | aluinc_to_abl |
+ aluinc_to_bi | aluinc_to_s |
+ alusum_to_abh | alusum_to_abl | alusum_to_bi |
+ alusum_to_pch | alusum_to_pcl | alusum_to_s |
+ asl_acc_op | asl_mem_op | cmp_op |
+ dec_op | dex_op | dey_op |
+ inc_op | inx_op | iny_op |
+ rol_acc_op | rol_mem_op;
+assign srs = lsr_acc_op | lsr_mem_op |
+ ror_acc_op | ror_mem_op;
+
+assign addc = (adc_op | rol_acc_op | rol_mem_op | ror_acc_op | ror_mem_op) ? q_c :
+ aluinc_to_abh | aluinc_to_abl | aluinc_to_bi |
+ aluinc_to_s | cmp_op |
+ inc_op | inx_op | iny_op;
+assign i_pc = (incpc_noload | load_prg_byte) & !force_noinc_pc;
+
+//
+// Update internal buses. Use in/out to replicate pass mosfets and avoid using internal
+// tristate buffers.
+//
+assign adh_in[7:1] = (dl_adh) ? q_dl[7:1] :
+ (pch_adh) ? q_pch[7:1] :
+ (zero_adh17) ? 7'h00 : 7'h7F;
+assign adh_in[0] = (dl_adh) ? q_dl[0] :
+ (pch_adh) ? q_pch[0] :
+ (zero_adh0) ? 1'b0 : 1'b1;
+
+assign adl[7:3] = (add_adl) ? q_add[7:3] :
+ (dl_adl) ? q_dl[7:3] :
+ (pcl_adl) ? q_pcl[7:3] :
+ (s_adl) ? q_s[7:3] : 5'h1F;
+assign adl[2] = (add_adl) ? q_add[2] :
+ (dl_adl) ? q_dl[2] :
+ (pcl_adl) ? q_pcl[2] :
+ (s_adl) ? q_s[2] :
+ (zero_adl2) ? 1'b0 : 1'b1;
+assign adl[1] = (add_adl) ? q_add[1] :
+ (dl_adl) ? q_dl[1] :
+ (pcl_adl) ? q_pcl[1] :
+ (s_adl) ? q_s[1] :
+ (zero_adl1) ? 1'b0 : 1'b1;
+assign adl[0] = (add_adl) ? q_add[0] :
+ (dl_adl) ? q_dl[0] :
+ (pcl_adl) ? q_pcl[0] :
+ (s_adl) ? q_s[0] :
+ (zero_adl0) ? 1'b0 : 1'b1;
+
+assign db_in = 8'hFF & ({8{~ac_db}} | q_ac) &
+ ({8{~dl_db}} | q_dl) &
+ ({8{~p_db}} | p) &
+ ({8{~pch_db}} | q_pch) &
+ ({8{~pcl_db}} | q_pcl);
+
+assign sb_in = 8'hFF & ({8{~ac_sb}} | q_ac) &
+ ({8{~add_sb}} | q_add) &
+ ({8{~s_sb}} | q_s) &
+ ({8{~x_sb}} | q_x) &
+ ({8{~y_sb}} | q_y);
+
+assign adh_out = (sb_adh & sb_db) ? (adh_in & sb_in & db_in) :
+ (sb_adh) ? (adh_in & sb_in) :
+ (adh_in);
+assign db_out = (sb_db & sb_adh) ? (db_in & sb_in & adh_in) :
+ (sb_db) ? (db_in & sb_in) :
+ (db_in);
+assign sb_out = (sb_adh & sb_db) ? (sb_in & db_in & adh_in) :
+ (sb_db) ? (sb_in & db_in) :
+ (sb_adh) ? (sb_in & adh_in) :
+ (sb_in);
+
+//
+// Assign next FF states.
+//
+assign d_ac = (sb_ac) ? sb_out : q_ac;
+assign d_x = (sb_x) ? sb_out : q_x;
+assign d_y = (sb_y) ? sb_out : q_y;
+assign d_c = (acr_c) ? acr :
+ (db0_c) ? db_out[0] :
+ (ir5_c) ? q_ir[5] : q_c;
+assign d_d = (db3_d) ? db_out[3] :
+ (ir5_d) ? q_ir[5] : q_d;
+assign d_i = (db2_i) ? db_out[2] :
+ (ir5_i) ? q_ir[5] : q_i;
+assign d_n = (db7_n) ? db_out[7] : q_n;
+assign d_v = (avr_v) ? avr :
+ (db6_v) ? db_out[6] :
+ (zero_v) ? 1'b0 : q_v;
+assign d_z = (db1_z) ? db_out[1] :
+ (dbz_z) ? ~|db_out : q_z;
+assign d_abh = (adh_abh) ? adh_out : q_abh;
+assign d_abl = (adl_abl) ? adl : q_abl;
+assign d_ai = (sb_add) ? sb_out :
+ (zero_add) ? 8'h0 : q_ai;
+assign d_bi = (adl_add) ? adl :
+ (db_add) ? db_out :
+ (invdb_add) ? ~db_out : q_bi;
+assign d_dl = (r_nw_out) ? d_in : q_dl;
+assign d_dor = db_out;
+assign d_pd = (r_nw_out) ? d_in : q_pd;
+assign d_s = (sb_s) ? sb_out : q_s;
+
+assign d_pchs = (adh_pch) ? adh_out : q_pch;
+assign d_pcls = (adl_pcl) ? adl : q_pcl;
+assign { d_pch, d_pcl } = (i_pc) ? { q_pchs, q_pcls } + 16'h0001 : { q_pchs, q_pcls };
+
+// Combine full processor status register.
+assign p = { q_n, q_v, 1'b1, (q_irq_sel == INTERRUPT_BRK), q_d, q_i, q_z, q_c };
+
+//
+// Assign output signals.
+//
+assign d_out = q_dor;
+assign a_out = { q_abh, q_abl };
+
+always @*
+ begin
+ case (dbgreg_sel_in)
+ `REGSEL_AC: dbgreg_out = q_ac;
+ `REGSEL_X: dbgreg_out = q_x;
+ `REGSEL_Y: dbgreg_out = q_y;
+ `REGSEL_P: dbgreg_out = p;
+ `REGSEL_PCH: dbgreg_out = q_pch;
+ `REGSEL_PCL: dbgreg_out = q_pcl;
+ `REGSEL_S: dbgreg_out = q_s;
+ default: dbgreg_out = 8'hxx;
+ endcase
+ end
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cpu/apu/apu_noise.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* APU noise channel.
+***************************************************************************************************/
+
+module apu_noise
+(
+ input wire clk_in, // system clock signal
+ input wire rst_in, // reset signal
+ input wire en_in, // enable (via $4015)
+ input wire apu_cycle_pulse_in, // 1 clk pulse on every apu cycle
+ input wire lc_pulse_in, // 1 clk pulse for every length counter decrement
+ input wire eg_pulse_in, // 1 clk pulse for every env gen update
+ input wire [1:0] a_in, // control register addr (i.e. $400C - $400F)
+ input wire [7:0] d_in, // control register write value
+ input wire wr_in, // enable control register write
+ output wire [3:0] noise_out, // noise channel output
+ output wire active_out // noise channel active (length counter > 0)
+);
+
+//
+// Envelope
+//
+wire envelope_generator_wr;
+wire envelope_generator_restart;
+wire [3:0] envelope_generator_out;
+
+apu_envelope_generator envelope_generator(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .eg_pulse_in(eg_pulse_in),
+ .env_in(d_in[5:0]),
+ .env_wr_in(envelope_generator_wr),
+ .env_restart(envelope_generator_restart),
+ .env_out(envelope_generator_out)
+);
+
+assign envelope_generator_wr = wr_in && (a_in == 2\'b00);
+assign envelope_generator_restart = wr_in && (a_in == 2\'b11);
+
+//
+// Timer
+//
+reg [10:0] q_timer_period;
+wire [10:0] d_timer_period;
+wire timer_pulse;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ q_timer_period <= 11\'h000;
+ else
+ q_timer_period <= d_timer_period;
+ end
+
+apu_div #(.PERIOD_BITS(12)) timer(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .pulse_in(apu_cycle_pulse_in),
+ .reload_in(1\'b0),
+ .period_in({ q_timer_period, 1\'b0 }),
+ .pulse_out(timer_pulse)
+);
+
+assign d_timer_period = (!wr_in || (a_in != 2\'b10)) ? q_timer_period :
+ (d_in[3:0] == 4\'h0) ? 11\'h002 :
+ (d_in[3:0] == 4\'h1) ? 11\'h004 :
+ (d_in[3:0] == 4\'h2) ? 11\'h008 :
+ (d_in[3:0] == 4\'h3) ? 11\'h010 :
+ (d_in[3:0] == 4\'h4) ? 11\'h020 :
+ (d_in[3:0] == 4\'h5) ? 11\'h030 :
+ (d_in[3:0] == 4\'h6) ? 11\'h040 :
+ (d_in[3:0] == 4\'h7) ? 11\'h050 :
+ (d_in[3:0] == 4\'h8) ? 11\'h065 :
+ (d_in[3:0] == 4\'h9) ? 11\'h07F :
+ (d_in[3:0] == 4\'hA) ? 11\'h0BE :
+ (d_in[3:0] == 4\'hB) ? 11\'h0FE :
+ (d_in[3:0] == 4\'hC) ? 11\'h17D :
+ (d_in[3:0] == 4\'hD) ? 11\'h1FC :
+ (d_in[3:0] == 4\'hE) ? 11\'h3F9 :
+ 11\'h7F2;
+
+//
+// Shift Register
+//
+reg [14:0] q_lfsr;
+wire [14:0] d_lfsr;
+reg q_mode;
+wire d_mode;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_lfsr <= 15\'h0001;
+ q_mode <= 1\'b0;
+ end
+ else
+ begin
+ q_lfsr <= d_lfsr;
+ q_mode <= d_mode;
+ end
+ end
+
+assign d_lfsr = (timer_pulse) ? { q_lfsr[0] ^ ((q_mode) ? q_lfsr[6] : q_lfsr[1]), q_lfsr[14:1] } :
+ q_lfsr;
+
+assign d_mode = (wr_in && (a_in == 2\'b10)) ? d_in[7] : q_mode;
+
+//
+// Length Counter
+//
+reg q_length_counter_halt;
+wire d_length_counter_halt;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ q_length_counter_halt <= 1\'b0;
+ else
+ q_length_counter_halt <= d_length_counter_halt;
+ end
+
+assign d_length_counter_halt = (wr_in && (a_in == 2\'b00)) ? d_in[5] : q_length_counter_halt;
+
+wire length_counter_wr;
+wire length_counter_en;
+
+apu_length_counter length_counter(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .en_in(en_in),
+ .halt_in(q_length_counter_halt),
+ .length_pulse_in(lc_pulse_in),
+ .length_in(d_in[7:3]),
+ .length_wr_in(length_counter_wr),
+ .en_out(length_counter_en)
+);
+
+assign length_counter_wr = wr_in && (a_in == 2\'b11);
+
+//
+// Output
+//
+assign noise_out = (q_lfsr[0] && length_counter_en) ? envelope_generator_out : 4\'h0;
+assign active_out = length_counter_en;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cpu/apu/apu_envelope_generator.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* APU length counter; building block used by several other APU components. Provides automatic
+* duration control for the NES APU waveform channels. Once loaded with a value, it can optionally
+* count down and silence the channel when it reaches zero.
+***************************************************************************************************/
+
+module apu_envelope_generator
+(
+ input wire clk_in, // system clock signal
+ input wire rst_in, // reset signal
+ input wire eg_pulse_in, // 1 clk pulse for every env gen update
+ input wire [5:0] env_in, // envelope value (e.g., via $4000)
+ input wire env_wr_in, // envelope value write
+ input wire env_restart, // envelope restart
+ output wire [3:0] env_out // output volume
+);
+
+reg [5:0] q_reg;
+wire [5:0] d_reg;
+reg [3:0] q_cnt, d_cnt;
+reg q_start_flag, d_start_flag;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_reg <= 6\'h00;
+ q_cnt <= 4\'h0;
+ q_start_flag <= 1\'b0;
+ end
+ else
+ begin
+ q_reg <= d_reg;
+ q_cnt <= d_cnt;
+ q_start_flag <= d_start_flag;
+ end
+ end
+
+reg divider_pulse_in;
+reg divider_reload;
+wire divider_pulse_out;
+
+apu_div #(.PERIOD_BITS(4)) divider(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .pulse_in(divider_pulse_in),
+ .reload_in(divider_reload),
+ .period_in(q_reg[3:0]),
+ .pulse_out(divider_pulse_out)
+);
+
+always @*
+ begin
+ d_cnt = q_cnt;
+ d_start_flag = q_start_flag;
+
+ divider_pulse_in = 1\'b0;
+ divider_reload = 1\'b0;
+
+ // When the divider outputs a clock, one of two actions occurs: If the counter is non-zero, it
+ // is decremented, otherwise if the loop flag is set, the counter is loaded with 15.
+ if (divider_pulse_out)
+ begin
+ divider_reload = 1\'b1;
+
+ if (q_cnt != 4\'h0)
+ d_cnt = q_cnt - 4\'h1;
+ else if (q_reg[5])
+ d_cnt = 4\'hF;
+ end
+
+ // When clocked by the frame counter, one of two actions occurs: if the start flag is clear,
+ // the divider is clocked, otherwise the start flag is cleared, the counter is loaded with 15,
+ // and the divider\'s period is immediately reloaded.
+ if (eg_pulse_in)
+ begin
+ if (q_start_flag == 1\'b0)
+ begin
+ divider_pulse_in = 1\'b1;
+ end
+ else
+ begin
+ d_start_flag = 1\'b0;
+ d_cnt = 4\'hF;
+ end
+ end
+
+ if (env_restart)
+ d_start_flag = 1\'b1;
+ end
+
+assign d_reg = (env_wr_in) ? env_in : q_reg;
+
+// The envelope unit\'s volume output depends on the constant volume flag: if set, the envelope
+// parameter directly sets the volume, otherwise the counter\'s value is the current volume.
+assign env_out = (q_reg[4]) ? q_reg[3:0] : q_cnt;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cpu/jp.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Joypad controller block.
+***************************************************************************************************/
+
+module jp
+(
+ input wire clk, // 100MHz system clock signal
+ input wire rst, // reset signal
+ input wire wr, // write enable signal
+ input wire [15:0] addr, // 16-bit memory address
+ input wire din, // data input bus
+ input wire jp_data1, // joypad 1 input signal
+ input wire jp_data2, // joypad 2 input signal
+ output wire jp_clk, // joypad output clk signal
+ output wire jp_latch, // joypad output latch signal
+ output reg [ 7:0] dout // data output bus
+);
+
+//
+// FFs for tracking/reading current controller state.
+//
+reg [7:0] q_jp1_state, d_jp1_state;
+reg [7:0] q_jp2_state, d_jp2_state;
+reg q_jp_clk, d_jp_clk;
+reg q_jp_latch, d_jp_latch;
+reg [8:0] q_cnt, d_cnt;
+
+always @(posedge clk)
+ begin
+ if (rst)
+ begin
+ q_jp1_state <= 8\'h00;
+ q_jp2_state <= 8\'h00;
+ q_jp_clk <= 1\'b0;
+ q_jp_latch <= 1\'b0;
+ q_cnt <= 9\'h00;
+ end
+ else
+ begin
+ q_jp1_state <= d_jp1_state;
+ q_jp2_state <= d_jp2_state;
+ q_jp_clk <= d_jp_clk;
+ q_jp_latch <= d_jp_latch;
+ q_cnt <= d_cnt;
+ end
+ end
+
+wire [2:0] state_idx;
+
+always @*
+ begin
+ // Default most FFs to current state.
+ d_jp1_state = q_jp1_state;
+ d_jp2_state = q_jp2_state;
+ d_jp_clk = q_jp_clk;
+ d_jp_latch = q_jp_latch;
+
+ d_cnt = q_cnt + 9\'h001;
+
+ // Drive LATCH signal to latch current controller state and return state of A button. Pulse
+ // clock 7 more times to read other 7 buttons. Controller states are active low.
+ if (q_cnt[5:1] == 5\'h00)
+ begin
+ d_jp1_state[state_idx] = ~jp_data1;
+ d_jp2_state[state_idx] = ~jp_data2;
+
+ if (q_cnt[8:1] == 8\'h00)
+ d_jp_latch = 1\'b1;
+ else
+ d_jp_clk = 1\'b1;
+ end
+ else if (q_cnt[5:1] == 5\'h10)
+ begin
+ d_jp_clk = 1\'b0;
+ d_jp_latch = 1\'b0;
+ end
+ end
+
+assign state_idx = q_cnt[8:6] - 3\'h1;
+assign jp_latch = q_jp_latch;
+assign jp_clk = q_jp_clk;
+
+localparam [15:0] JOYPAD1_MMR_ADDR = 16\'h4016;
+localparam [15:0] JOYPAD2_MMR_ADDR = 16\'h4017;
+
+localparam S_STROBE_WROTE_0 = 1\'b0,
+ S_STROBE_WROTE_1 = 1\'b1;
+
+//
+// FFs for managing MMR interface for reading joypad state.
+//
+reg [15:0] q_addr;
+reg [ 8:0] q_jp1_read_state, d_jp1_read_state;
+reg [ 8:0] q_jp2_read_state, d_jp2_read_state;
+reg q_strobe_state, d_strobe_state;
+
+always @(posedge clk)
+ begin
+ if (rst)
+ begin
+ q_addr <= 16\'h0000;
+ q_jp1_read_state <= 9\'h000;
+ q_jp2_read_state <= 9\'h000;
+ q_strobe_state <= S_STROBE_WROTE_0;
+ end
+ else
+ begin
+ q_addr <= addr;
+ q_jp1_read_state <= d_jp1_read_state;
+ q_jp2_read_state <= d_jp2_read_state;
+ q_strobe_state <= d_strobe_state;
+ end
+ end
+
+always @*
+ begin
+ dout = 8\'h00;
+
+ // Default FFs to current state.
+ d_jp1_read_state = q_jp1_read_state;
+ d_jp2_read_state = q_jp2_read_state;
+ d_strobe_state = q_strobe_state;
+
+ if (addr[15:1] == JOYPAD1_MMR_ADDR[15:1])
+ begin
+ dout = { 7\'h00, ((addr[0]) ? q_jp2_read_state[0] : q_jp1_read_state[0]) };
+
+ // Only update internal state one time per read/write.
+ if (addr != q_addr)
+ begin
+ // App must write 0x4016 to 1 then to 0 in order to reset and begin reading the joypad
+ // state.
+ if (wr && !addr[0])
+ begin
+ if ((q_strobe_state == S_STROBE_WROTE_0) && (din == 1\'b1))
+ begin
+ d_strobe_state = S_STROBE_WROTE_1;
+ end
+ else if ((q_strobe_state == S_STROBE_WROTE_1) && (din == 1\'b0))
+ begin
+ d_strobe_state = S_STROBE_WROTE_0;
+ d_jp1_read_state = { q_jp1_state, 1\'b0 };
+ d_jp2_read_state = { q_jp2_state, 1\'b0 };
+ end
+ end
+
+ // Shift appropriate jp read state on every read. After 8 reads, all subsequent reads
+ // should be 1.
+ else if (!wr && !addr[0])
+ d_jp1_read_state = { 1\'b1, q_jp1_read_state[8:1] };
+ else if (!wr && addr[0])
+ d_jp2_read_state = { 1\'b1, q_jp2_read_state[8:1] };
+ end
+ end
+ end
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cmn/fifo/fifo.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Circular first in first out buffer implementation.
+***************************************************************************************************/
+
+module fifo
+#(
+ parameter DATA_BITS = 8,
+ parameter ADDR_BITS = 3
+)
+(
+ input wire clk, // 50MHz system clock
+ input wire reset, // Reset signal
+ input wire rd_en, // Read enable, pop front of queue
+ input wire wr_en, // Write enable, add wr_data to end of queue
+ input wire [DATA_BITS-1:0] wr_data, // Data to be written on wr_en
+ output wire [DATA_BITS-1:0] rd_data, // Current front of fifo data
+ output wire full, // FIFO is full (writes invalid)
+ output wire empty // FIFO is empty (reads invalid)
+);
+
+reg [ADDR_BITS-1:0] q_rd_ptr;
+wire [ADDR_BITS-1:0] d_rd_ptr;
+reg [ADDR_BITS-1:0] q_wr_ptr;
+wire [ADDR_BITS-1:0] d_wr_ptr;
+reg q_empty;
+wire d_empty;
+reg q_full;
+wire d_full;
+
+reg [DATA_BITS-1:0] q_data_array [2**ADDR_BITS-1:0];
+wire [DATA_BITS-1:0] d_data;
+
+wire rd_en_prot;
+wire wr_en_prot;
+
+// FF update logic. Synchronous reset.
+always @(posedge clk)
+ begin
+ if (reset)
+ begin
+ q_rd_ptr <= 0;
+ q_wr_ptr <= 0;
+ q_empty <= 1\'b1;
+ q_full <= 1\'b0;
+ end
+ else
+ begin
+ q_rd_ptr <= d_rd_ptr;
+ q_wr_ptr <= d_wr_ptr;
+ q_empty <= d_empty;
+ q_full <= d_full;
+ q_data_array[q_wr_ptr] <= d_data;
+ end
+ end
+
+// Derive ""protected"" read/write signals.
+assign rd_en_prot = (rd_en && !q_empty);
+assign wr_en_prot = (wr_en && !q_full);
+
+// Handle writes.
+assign d_wr_ptr = (wr_en_prot) ? q_wr_ptr + 1\'h1 : q_wr_ptr;
+assign d_data = (wr_en_prot) ? wr_data : q_data_array[q_wr_ptr];
+
+// Handle reads.
+assign d_rd_ptr = (rd_en_prot) ? q_rd_ptr + 1\'h1 : q_rd_ptr;
+
+wire [ADDR_BITS-1:0] addr_bits_wide_1;
+assign addr_bits_wide_1 = 1;
+
+// Detect empty state:
+// 1) We were empty before and there was no write.
+// 2) We had one entry and there was a read.
+assign d_empty = ((q_empty && !wr_en_prot) ||
+ (((q_wr_ptr - q_rd_ptr) == addr_bits_wide_1) && rd_en_prot));
+
+// Detect full state:
+// 1) We were full before and there was no read.
+// 2) We had n-1 entries and there was a write.
+assign d_full = ((q_full && !rd_en_prot) ||
+ (((q_rd_ptr - q_wr_ptr) == addr_bits_wide_1) && wr_en_prot));
+
+// Assign output signals to appropriate FFs.
+assign rd_data = q_data_array[q_rd_ptr];
+assign full = q_full;
+assign empty = q_empty;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cmn/uart/uart.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* UART controller. Universal Asynchronous Receiver/Transmitter control module for an RS-232
+* (serial) port.
+***************************************************************************************************/
+
+`include ""uart_baud_clk.v""
+`include ""uart_rx.v""
+`include ""uart_tx.v""
+
+`include ""../fifo/fifo.v""
+
+module uart
+#(
+ parameter SYS_CLK_FREQ = 50000000,
+ parameter BAUD_RATE = 19200,
+ parameter DATA_BITS = 8,
+ parameter STOP_BITS = 1,
+ parameter PARITY_MODE = 0 // 0 = none, 1 = odd, 2 = even
+)
+(
+ input wire clk, // System clk
+ input wire reset, // Reset signal
+ input wire rx, // RS-232 rx pin
+ input wire [DATA_BITS-1:0] tx_data, // Data to be transmitted when wr_en is 1
+ input wire rd_en, // Pops current read FIFO front off the queue
+ input wire wr_en, // Write tx_data over serial connection
+ output wire tx, // RS-232 tx pin
+ output wire [DATA_BITS-1:0] rx_data, // Data currently at front of read FIFO
+ output wire rx_empty, // 1 if there is no more read data available
+ output wire tx_full, // 1 if the transmit FIFO cannot accept more requests
+ output wire parity_err // 1 if a parity error has been detected
+);
+
+localparam BAUD_CLK_OVERSAMPLE_RATE = 16;
+
+wire baud_clk_tick;
+
+wire [DATA_BITS-1:0] rx_fifo_wr_data;
+wire rx_done_tick;
+wire rx_parity_err;
+
+wire [DATA_BITS-1:0] tx_fifo_rd_data;
+wire tx_done_tick;
+wire tx_fifo_empty;
+
+// Store parity error in a flip flop as persistent state.
+reg q_rx_parity_err;
+wire d_rx_parity_err;
+
+always @(posedge clk, posedge reset)
+ begin
+ if (reset)
+ q_rx_parity_err <= 1\'b0;
+ else
+ q_rx_parity_err <= d_rx_parity_err;
+ end
+
+assign parity_err = q_rx_parity_err;
+assign d_rx_parity_err = q_rx_parity_err || rx_parity_err;
+
+// BAUD clock module
+uart_baud_clk #(.SYS_CLK_FREQ(SYS_CLK_FREQ),
+ .BAUD(BAUD_RATE),
+ .BAUD_CLK_OVERSAMPLE_RATE(BAUD_CLK_OVERSAMPLE_RATE)) uart_baud_clk_blk
+(
+ .clk(clk),
+ .reset(reset),
+ .baud_clk_tick(baud_clk_tick)
+);
+
+// RX (receiver) module
+uart_rx #(.DATA_BITS(DATA_BITS),
+ .STOP_BITS(STOP_BITS),
+ .PARITY_MODE(PARITY_MODE),
+ .BAUD_CLK_OVERSAMPLE_RATE(BAUD_CLK_OVERSAMPLE_RATE)) uart_rx_blk
+(
+ .clk(clk),
+ .reset(reset),
+ .baud_clk_tick(baud_clk_tick),
+ .rx(rx),
+ .rx_data(rx_fifo_wr_data),
+ .rx_done_tick(rx_done_tick),
+ .parity_err(rx_parity_err)
+);
+
+// TX (transmitter) module
+uart_tx #(.DATA_BITS(DATA_BITS),
+ .STOP_BITS(STOP_BITS),
+ .PARITY_MODE(PARITY_MODE),
+ .BAUD_CLK_OVERSAMPLE_RATE(BAUD_CLK_OVERSAMPLE_RATE)) uart_tx_blk
+(
+ .clk(clk),
+ .reset(reset),
+ .baud_clk_tick(baud_clk_tick),
+ .tx_start(~tx_fifo_empty),
+ .tx_data(tx_fifo_rd_data),
+ .tx_done_tick(tx_done_tick),
+ .tx(tx)
+);
+
+// RX FIFO
+fifo #(.DATA_BITS(DATA_BITS),
+ .ADDR_BITS(3)) uart_rx_fifo
+(
+ .clk(clk),
+ .reset(reset),
+ .rd_en(rd_en),
+ .wr_en(rx_done_tick),
+ .wr_data(rx_fifo_wr_data),
+ .rd_data(rx_data),
+ .empty(rx_empty),
+ .full()
+);
+
+// TX FIFO
+fifo #(.DATA_BITS(DATA_BITS),
+ .ADDR_BITS(3)) uart_tx_fifo
+(
+ .clk(clk),
+ .reset(reset),
+ .rd_en(tx_done_tick),
+ .wr_en(wr_en),
+ .wr_data(tx_data),
+ .rd_data(tx_fifo_rd_data),
+ .empty(tx_fifo_empty),
+ .full(tx_full)
+);
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cmn/uart/uart_baud_clk.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Generates a tick signal at OVERSAMPLE_RATE times the baud rate. Should be fed to the uart_rx
+* and uart_tx blocks.
+***************************************************************************************************/
+
+module uart_baud_clk
+#(
+ parameter SYS_CLK_FREQ = 50000000,
+ parameter BAUD = 19200,
+ parameter BAUD_CLK_OVERSAMPLE_RATE = 16
+)
+(
+ input wire clk,
+ input wire reset,
+ output wire baud_clk_tick
+);
+
+localparam [15:0] CLKS_PER_OVERSAMPLE_TICK = (SYS_CLK_FREQ / BAUD) / BAUD_CLK_OVERSAMPLE_RATE;
+
+// Registers
+reg [15:0] q_cnt;
+wire [15:0] d_cnt;
+
+always @(posedge clk, posedge reset)
+ begin
+ if (reset)
+ q_cnt <= 0;
+ else
+ q_cnt <= d_cnt;
+ end
+
+assign d_cnt = (q_cnt == (CLKS_PER_OVERSAMPLE_TICK - 1)) ? 16\'h0000 : (q_cnt + 16\'h0001);
+assign baud_clk_tick = (q_cnt == (CLKS_PER_OVERSAMPLE_TICK - 1)) ? 1\'b1 : 1\'b0;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cpu/sprdma.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Sprite DMA control block.
+***************************************************************************************************/
+
+module sprdma
+(
+ input wire clk_in, // 100MHz system clock signal
+ input wire rst_in, // reset signal
+ input wire [15:0] cpumc_a_in, // cpu address bus in (to snoop cpu writes of 0x4014)
+ input wire [ 7:0] cpumc_din_in, // cpumc din bus in (to snoop cpu writes of 0x4014)
+ input wire [ 7:0] cpumc_dout_in, // cpumc dout bus in (to receive sprdma read data)
+ input wire cpu_r_nw_in, // cpu write enable (to snoop cpu writes of 0x4014)
+ output wire active_out, // high when sprdma is active (de-assert cpu ready signal)
+ output reg [15:0] cpumc_a_out, // cpu address bus out (for dma cpu mem reads/writes)
+ output reg [ 7:0] cpumc_d_out, // cpu data bus out (for dma mem writes)
+ output reg cpumc_r_nw_out // cpu r_nw signal out (for dma mem writes)
+);
+
+// Symbolic state representations.
+localparam [1:0] S_READY = 2\'h0,
+ S_ACTIVE = 2\'h1,
+ S_COOLDOWN = 2\'h2;
+
+reg [ 1:0] q_state, d_state; // current fsm state
+reg [15:0] q_addr, d_addr; // current cpu address to be copied to sprite ram
+reg [ 1:0] q_cnt, d_cnt; // counter to manage stages of dma copies
+reg [ 7:0] q_data, d_data; // latch for data read from cpu mem
+
+// Update FF state.
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_state <= S_READY;
+ q_addr <= 16\'h0000;
+ q_cnt <= 2\'h0;
+ q_data <= 8\'h00;
+ end
+ else
+ begin
+ q_state <= d_state;
+ q_addr <= d_addr;
+ q_cnt <= d_cnt;
+ q_data <= d_data;
+ end
+ end
+
+always @*
+ begin
+ // Default regs to current state.
+ d_state = q_state;
+ d_addr = q_addr;
+ d_cnt = q_cnt;
+ d_data = q_data;
+
+ // Default to no memory action.
+ cpumc_a_out = 16\'h00;
+ cpumc_d_out = 8\'h00;
+ cpumc_r_nw_out = 1\'b1;
+
+ if (q_state == S_READY)
+ begin
+ // Detect write to 0x4014 to begin DMA.
+ if ((cpumc_a_in == 16\'h4014) && !cpu_r_nw_in)
+ begin
+ d_state = S_ACTIVE;
+ d_addr = { cpumc_din_in, 8\'h00 };
+ end
+ end
+ else if (q_state == S_ACTIVE)
+ begin
+ case (q_cnt)
+ 2\'h0:
+ begin
+ cpumc_a_out = q_addr;
+ d_cnt = 2\'h1;
+ end
+ 2\'h1:
+ begin
+ cpumc_a_out = q_addr;
+ d_data = cpumc_dout_in;
+ d_cnt = 2\'h2;
+ end
+ 2\'h2:
+ begin
+ cpumc_a_out = 16\'h2004;
+ cpumc_d_out = q_data;
+ cpumc_r_nw_out = 1\'b0;
+ d_cnt = 2\'h0;
+
+ if (q_addr[7:0] == 8\'hff)
+ d_state = S_COOLDOWN;
+ else
+ d_addr = q_addr + 16\'h0001;
+ end
+ endcase
+ end
+ else if (q_state == S_COOLDOWN)
+ begin
+ if (cpu_r_nw_in)
+ d_state = S_READY;
+ end
+ end
+
+assign active_out = (q_state == S_ACTIVE);
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/ppu/ppu_spr.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Sprite PPU sub-block.
+***************************************************************************************************/
+
+module ppu_spr
+(
+ input wire clk_in, // 100MHz system clock signal
+ input wire rst_in, // reset signal
+ input wire en_in, // enable sprites
+ input wire ls_clip_in, // clip sprites in left 8 pixels
+ input wire spr_h_in, // select 8/16 pixel high sprites
+ input wire spr_pt_sel_in, // sprite palette table select
+ input wire [ 7:0] oam_a_in, // sprite ram address
+ input wire [ 7:0] oam_d_in, // sprite ram data in
+ input wire oam_wr_in, // sprite ram write enable
+ input wire [ 9:0] nes_x_in, // nes x coordinate
+ input wire [ 9:0] nes_y_in, // nes y coordinate
+ input wire [ 9:0] nes_y_next_in, // next line\'s nes y coordinate
+ input wire pix_pulse_in, // pulse signal one clock immediately before nes x changes
+ input wire [ 7:0] vram_d_in, // vram data in for pattern table reads
+ output wire [ 7:0] oam_d_out, // sprite ram data out
+ output wire overflow_out, // more than 8 sprites on one scanline in current frame
+ output wire [ 3:0] palette_idx_out, // final sprite palette index
+ output wire primary_out, // final sprite is the primary object (sprite 0)
+ output wire priority_out, // final sprite priority (foreground/background)
+ output reg [13:0] vram_a_out, // vram address bus for pattern table reads
+ output reg vram_req_out // indicates sprite block needs vram ownership
+);
+
+// OAM: Object Attribute Memory (256 entries, 4 bytes per entry)
+//
+// byte bits desc
+// ---- ---- ----
+// 0 7:0 scanline coordinate minus one of object\'s top pixel row.
+// 1 7:0 tile index number. Bit 0 here controls pattern table selection when reg 0x2000[5]5 = 1.
+// 2 0 palette select low bit
+// 1 palette select high bit
+// 5 object priority (> playfield\'s if 0; < playfield\'s if 1)
+// 6 apply bit reversal to fetched object pattern table data
+// 7 invert the 3/4-bit (8/16 scanlines/object mode) scanline address used to access an object
+// tile
+// 3 7:0 scanline pixel coordinate of most left-hand side of object.
+reg [7:0] m_oam [255:0];
+
+always @(posedge clk_in)
+ begin
+ if (oam_wr_in)
+ m_oam[oam_a_in] <= oam_d_in;
+ end
+
+// STM: Sprite Temporary Memory
+//
+// bits desc
+// ------- -----
+// 24 primary object flag (is sprite 0?)
+// 23 : 16 tile index
+// 15 : 8 x coordinate
+// 7 : 6 palette select bits
+// 5 object priority
+// 4 apply bit reversal to fetched object pattern table data (horizontal invert)
+// 3 : 0 range comparison result (sprite row)
+reg [24:0] m_stm [7:0];
+
+reg [24:0] stm_din;
+reg [ 2:0] stm_a;
+reg stm_wr;
+
+always @(posedge clk_in)
+ begin
+ if (stm_wr)
+ m_stm[stm_a] <= stm_din;
+ end
+
+// SBM: Sprite Buffer Memory
+//
+// bits desc
+// ------- -----
+// 27 primary object flag (is sprite 0?)
+// 26 priority
+// 25 - 24 palette select (bit 3-2)
+// 23 - 16 pattern data bit 1
+// 15 - 8 pattern data bit 0
+// 7 - 0 x-start
+reg [27:0] m_sbm [7:0];
+
+reg [27:0] sbm_din;
+reg [ 2:0] sbm_a;
+reg sbm_wr;
+
+always @(posedge clk_in)
+ begin
+ if (sbm_wr)
+ m_sbm[sbm_a] <= sbm_din;
+ end
+
+//
+// In-range object evaluation (line N-1, fetch phases 1-128).
+//
+reg [3:0] q_in_rng_cnt, d_in_rng_cnt; // number of objects on the next scanline
+reg q_spr_overflow, d_spr_overflow; // signals more than 8 objects on a scanline this frame
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_in_rng_cnt <= 4\'h0;
+ q_spr_overflow <= 1\'h0;
+ end
+ else
+ begin
+ q_in_rng_cnt <= d_in_rng_cnt;
+ q_spr_overflow <= d_spr_overflow;
+ end
+ end
+
+wire [5:0] oam_rd_idx; // oam entry selector
+wire [7:0] oam_rd_y; // cur oam entry y coordinate
+wire [7:0] oam_rd_tile_idx; // cur oam entry tile index
+wire oam_rd_v_inv; // cur oam entry vertical inversion state
+wire oam_rd_h_inv; // cur oam entry horizontal inversion state
+wire oam_rd_priority; // cur oam entry priority
+wire [1:0] oam_rd_ps; // cur oam entry palette select
+wire [7:0] oam_rd_x; // cur oam entry x coordinate
+
+wire [8:0] rng_cmp_res; // 9-bit comparison result for in-range check
+wire in_rng; // indicates whether current object is in-range
+
+assign oam_rd_idx = nes_x_in[7:2];
+
+assign oam_rd_y = m_oam[{ oam_rd_idx, 2\'b00 }] + 8\'h01;
+assign oam_rd_tile_idx = m_oam[{ oam_rd_idx, 2\'b01 }];
+assign oam_rd_v_inv = m_oam[{ oam_rd_idx, 2\'b10 }] >> 3\'h7;
+assign oam_rd_h_inv = m_oam[{ oam_rd_idx, 2\'b10 }] >> 3\'h6;
+assign oam_rd_priority = m_oam[{ oam_rd_idx, 2\'b10 }] >> 3\'h5;
+assign oam_rd_ps = m_oam[{ oam_rd_idx, 2\'b10 }];
+assign oam_rd_x = m_oam[{ oam_rd_idx, 2\'b11 }];
+
+assign rng_cmp_res = nes_y_next_in - oam_rd_y;
+assign in_rng = (~|rng_cmp_res[8:4]) & (~rng_cmp_res[3] | spr_h_in);
+
+always @*
+ begin
+ d_in_rng_cnt = q_in_rng_cnt;
+
+ // Reset the sprite overflow flag at the beginning of each frame. Otherwise, set the flag if
+ // any scanline in this frame has intersected more than 8 sprites.
+ if ((nes_y_next_in == 0) && (nes_x_in == 0))
+ d_spr_overflow = 1\'b0;
+ else
+ d_spr_overflow = q_spr_overflow || q_in_rng_cnt[3];
+
+ stm_a = q_in_rng_cnt[2:0];
+ stm_wr = 1\'b0;
+
+ stm_din[ 24] = ~|oam_rd_idx;
+ stm_din[23:16] = oam_rd_tile_idx;
+ stm_din[15: 8] = oam_rd_x;
+ stm_din[ 7: 6] = oam_rd_ps;
+ stm_din[ 5] = oam_rd_priority;
+ stm_din[ 4] = oam_rd_h_inv;
+ stm_din[ 3: 0] = (oam_rd_v_inv) ? ~rng_cmp_res[3:0] : rng_cmp_res[3:0];
+
+ if (en_in && pix_pulse_in && (nes_y_next_in < 239))
+ begin
+ if (nes_x_in == 320)
+ begin
+ // Reset the in-range count and sprite 0 in-rnage flag at the end of each scanline.
+ d_in_rng_cnt = 4\'h0;
+ end
+ else if ((nes_x_in < 256) && (nes_x_in[1:0] == 2\'h0) && in_rng && !q_in_rng_cnt[3])
+ begin
+ // Current object is in range, and there are less than 8 in-range objects found
+ // so far. Update the STM and increment the in-range counter.
+ stm_wr = 1\'b1;
+ d_in_rng_cnt = q_in_rng_cnt + 4\'h1;
+ end
+ end
+ end
+
+//
+// Object pattern fetch (fetch phases 129-160).
+//
+reg [7:0] q_pd0, d_pd0;
+reg [7:0] q_pd1, d_pd1;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_pd1 <= 8\'h00;
+ q_pd0 <= 8\'h00;
+ end
+ else
+ begin
+ q_pd1 <= d_pd1;
+ q_pd0 <= d_pd0;
+ end
+ end
+
+wire [2:0] stm_rd_idx;
+wire stm_rd_primary;
+wire [7:0] stm_rd_tile_idx;
+wire [7:0] stm_rd_x;
+wire [1:0] stm_rd_ps;
+wire stm_rd_priority;
+wire stm_rd_h_inv;
+wire [3:0] stm_rd_obj_row;
+
+assign stm_rd_idx = nes_x_in[5:3];
+assign stm_rd_primary = m_stm[stm_rd_idx] >> 24;
+assign stm_rd_tile_idx = m_stm[stm_rd_idx] >> 16;
+assign stm_rd_x = m_stm[stm_rd_idx] >> 8;
+assign stm_rd_ps = m_stm[stm_rd_idx] >> 6;
+assign stm_rd_priority = m_stm[stm_rd_idx] >> 5;
+assign stm_rd_h_inv = m_stm[stm_rd_idx] >> 4;
+assign stm_rd_obj_row = m_stm[stm_rd_idx];
+
+always @*
+ begin
+ d_pd1 = q_pd1;
+ d_pd0 = q_pd0;
+
+ sbm_a = stm_rd_idx;
+ sbm_wr = 1\'b0;
+ sbm_din = 28\'h000;
+
+ vram_req_out = 1\'b0;
+
+ if (spr_h_in)
+ vram_a_out = { 1\'b0,
+ stm_rd_tile_idx[0],
+ stm_rd_tile_idx[7:1],
+ stm_rd_obj_row[3],
+ nes_x_in[1],
+ stm_rd_obj_row[2:0] };
+ else
+ vram_a_out = { 1\'b0,
+ spr_pt_sel_in,
+ stm_rd_tile_idx,
+ nes_x_in[1],
+ stm_rd_obj_row[2:0] };
+
+ if (en_in && (nes_y_next_in < 239) && (nes_x_in >= 256) && (nes_x_in < 320))
+ begin
+ if (stm_rd_idx < q_in_rng_cnt)
+ begin
+ case (nes_x_in[2:1])
+ 2\'h0:
+ begin
+ vram_req_out = 1\'b1;
+
+ if (stm_rd_h_inv)
+ begin
+ d_pd0 = vram_d_in;
+ end
+ else
+ begin
+ d_pd0[0] = vram_d_in[7];
+ d_pd0[1] = vram_d_in[6];
+ d_pd0[2] = vram_d_in[5];
+ d_pd0[3] = vram_d_in[4];
+ d_pd0[4] = vram_d_in[3];
+ d_pd0[5] = vram_d_in[2];
+ d_pd0[6] = vram_d_in[1];
+ d_pd0[7] = vram_d_in[0];
+ end
+ end
+ 2\'h1:
+ begin
+ vram_req_out = 1\'b1;
+
+ if (stm_rd_h_inv)
+ begin
+ d_pd1 = vram_d_in;
+ end
+ else
+ begin
+ d_pd1[0] = vram_d_in[7];
+ d_pd1[1] = vram_d_in[6];
+ d_pd1[2] = vram_d_in[5];
+ d_pd1[3] = vram_d_in[4];
+ d_pd1[4] = vram_d_in[3];
+ d_pd1[5] = vram_d_in[2];
+ d_pd1[6] = vram_d_in[1];
+ d_pd1[7] = vram_d_in[0];
+ end
+ end
+ 2\'h2:
+ begin
+ sbm_din = { stm_rd_primary, stm_rd_priority, stm_rd_ps, q_pd1, q_pd0, stm_rd_x };
+ sbm_wr = 1\'b1;
+ end
+ endcase
+ end
+ else
+ begin
+ sbm_din = 28\'h0000000;
+ sbm_wr = 1\'b1;
+ end
+ end
+ end
+
+//
+// Object prioritization and output (line N, fetch phases 1-128).
+//
+reg [7:0] q_obj0_pd1_shift, d_obj0_pd1_shift;
+reg [7:0] q_obj1_pd1_shift, d_obj1_pd1_shift;
+reg [7:0] q_obj2_pd1_shift, d_obj2_pd1_shift;
+reg [7:0] q_obj3_pd1_shift, d_obj3_pd1_shift;
+reg [7:0] q_obj4_pd1_shift, d_obj4_pd1_shift;
+reg [7:0] q_obj5_pd1_shift, d_obj5_pd1_shift;
+reg [7:0] q_obj6_pd1_shift, d_obj6_pd1_shift;
+reg [7:0] q_obj7_pd1_shift, d_obj7_pd1_shift;
+reg [7:0] q_obj0_pd0_shift, d_obj0_pd0_shift;
+reg [7:0] q_obj1_pd0_shift, d_obj1_pd0_shift;
+reg [7:0] q_obj2_pd0_shift, d_obj2_pd0_shift;
+reg [7:0] q_obj3_pd0_shift, d_obj3_pd0_shift;
+reg [7:0] q_obj4_pd0_shift, d_obj4_pd0_shift;
+reg [7:0] q_obj5_pd0_shift, d_obj5_pd0_shift;
+reg [7:0] q_obj6_pd0_shift, d_obj6_pd0_shift;
+reg [7:0] q_obj7_pd0_shift, d_obj7_pd0_shift;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_obj0_pd1_shift <= 8\'h00;
+ q_obj1_pd1_shift <= 8\'h00;
+ q_obj2_pd1_shift <= 8\'h00;
+ q_obj3_pd1_shift <= 8\'h00;
+ q_obj4_pd1_shift <= 8\'h00;
+ q_obj5_pd1_shift <= 8\'h00;
+ q_obj6_pd1_shift <= 8\'h00;
+ q_obj7_pd1_shift <= 8\'h00;
+ q_obj0_pd0_shift <= 8\'h00;
+ q_obj1_pd0_shift <= 8\'h00;
+ q_obj2_pd0_shift <= 8\'h00;
+ q_obj3_pd0_shift <= 8\'h00;
+ q_obj4_pd0_shift <= 8\'h00;
+ q_obj5_pd0_shift <= 8\'h00;
+ q_obj6_pd0_shift <= 8\'h00;
+ q_obj7_pd0_shift <= 8\'h00;
+ end
+ else
+ begin
+ q_obj0_pd1_shift <= d_obj0_pd1_shift;
+ q_obj1_pd1_shift <= d_obj1_pd1_shift;
+ q_obj2_pd1_shift <= d_obj2_pd1_shift;
+ q_obj3_pd1_shift <= d_obj3_pd1_shift;
+ q_obj4_pd1_shift <= d_obj4_pd1_shift;
+ q_obj5_pd1_shift <= d_obj5_pd1_shift;
+ q_obj6_pd1_shift <= d_obj6_pd1_shift;
+ q_obj7_pd1_shift <= d_obj7_pd1_shift;
+ q_obj0_pd0_shift <= d_obj0_pd0_shift;
+ q_obj1_pd0_shift <= d_obj1_pd0_shift;
+ q_obj2_pd0_shift <= d_obj2_pd0_shift;
+ q_obj3_pd0_shift <= d_obj3_pd0_shift;
+ q_obj4_pd0_shift <= d_obj4_pd0_shift;
+ q_obj5_pd0_shift <= d_obj5_pd0_shift;
+ q_obj6_pd0_shift <= d_obj6_pd0_shift;
+ q_obj7_pd0_shift <= d_obj7_pd0_shift;
+ end
+ end
+
+wire sbm_rd_obj0_primary;
+wire sbm_rd_obj0_priority;
+wire [1:0] sbm_rd_obj0_ps;
+wire [7:0] sbm_rd_obj0_pd1;
+wire [7:0] sbm_rd_obj0_pd0;
+wire [7:0] sbm_rd_obj0_x;
+wire sbm_rd_obj1_primary;
+wire sbm_rd_obj1_priority;
+wire [1:0] sbm_rd_obj1_ps;
+wire [7:0] sbm_rd_obj1_pd1;
+wire [7:0] sbm_rd_obj1_pd0;
+wire [7:0] sbm_rd_obj1_x;
+wire sbm_rd_obj2_primary;
+wire sbm_rd_obj2_priority;
+wire [1:0] sbm_rd_obj2_ps;
+wire [7:0] sbm_rd_obj2_pd1;
+wire [7:0] sbm_rd_obj2_pd0;
+wire [7:0] sbm_rd_obj2_x;
+wire sbm_rd_obj3_primary;
+wire sbm_rd_obj3_priority;
+wire [1:0] sbm_rd_obj3_ps;
+wire [7:0] sbm_rd_obj3_pd1;
+wire [7:0] sbm_rd_obj3_pd0;
+wire [7:0] sbm_rd_obj3_x;
+wire sbm_rd_obj4_primary;
+wire sbm_rd_obj4_priority;
+wire [1:0] sbm_rd_obj4_ps;
+wire [7:0] sbm_rd_obj4_pd1;
+wire [7:0] sbm_rd_obj4_pd0;
+wire [7:0] sbm_rd_obj4_x;
+wire sbm_rd_obj5_primary;
+wire sbm_rd_obj5_priority;
+wire [1:0] sbm_rd_obj5_ps;
+wire [7:0] sbm_rd_obj5_pd1;
+wire [7:0] sbm_rd_obj5_pd0;
+wire [7:0] sbm_rd_obj5_x;
+wire sbm_rd_obj6_primary;
+wire sbm_rd_obj6_priority;
+wire [1:0] sbm_rd_obj6_ps;
+wire [7:0] sbm_rd_obj6_pd1;
+wire [7:0] sbm_rd_obj6_pd0;
+wire [7:0] sbm_rd_obj6_x;
+wire sbm_rd_obj7_primary;
+wire sbm_rd_obj7_priority;
+wire [1:0] sbm_rd_obj7_ps;
+wire [7:0] sbm_rd_obj7_pd1;
+wire [7:0] sbm_rd_obj7_pd0;
+wire [7:0] sbm_rd_obj7_x;
+
+
+assign sbm_rd_obj0_primary = m_sbm[0] >> 27;
+assign sbm_rd_obj0_priority = m_sbm[0] >> 26;
+assign sbm_rd_obj0_ps = m_sbm[0] >> 24;
+assign sbm_rd_obj0_pd1 = m_sbm[0] >> 16;
+assign sbm_rd_obj0_pd0 = m_sbm[0] >> 8;
+assign sbm_rd_obj0_x = m_sbm[0];
+assign sbm_rd_obj1_primary = m_sbm[1] >> 27;
+assign sbm_rd_obj1_priority = m_sbm[1] >> 26;
+assign sbm_rd_obj1_ps = m_sbm[1] >> 24;
+assign sbm_rd_obj1_pd1 = m_sbm[1] >> 16;
+assign sbm_rd_obj1_pd0 = m_sbm[1] >> 8;
+assign sbm_rd_obj1_x = m_sbm[1];
+assign sbm_rd_obj2_primary = m_sbm[2] >> 27;
+assign sbm_rd_obj2_priority = m_sbm[2] >> 26;
+assign sbm_rd_obj2_ps = m_sbm[2] >> 24;
+assign sbm_rd_obj2_pd1 = m_sbm[2] >> 16;
+assign sbm_rd_obj2_pd0 = m_sbm[2] >> 8;
+assign sbm_rd_obj2_x = m_sbm[2];
+assign sbm_rd_obj3_primary = m_sbm[3] >> 27;
+assign sbm_rd_obj3_priority = m_sbm[3] >> 26;
+assign sbm_rd_obj3_ps = m_sbm[3] >> 24;
+assign sbm_rd_obj3_pd1 = m_sbm[3] >> 16;
+assign sbm_rd_obj3_pd0 = m_sbm[3] >> 8;
+assign sbm_rd_obj3_x = m_sbm[3];
+assign sbm_rd_obj4_primary = m_sbm[4] >> 27;
+assign sbm_rd_obj4_priority = m_sbm[4] >> 26;
+assign sbm_rd_obj4_ps = m_sbm[4] >> 24;
+assign sbm_rd_obj4_pd1 = m_sbm[4] >> 16;
+assign sbm_rd_obj4_pd0 = m_sbm[4] >> 8;
+assign sbm_rd_obj4_x = m_sbm[4];
+assign sbm_rd_obj5_primary = m_sbm[5] >> 27;
+assign sbm_rd_obj5_priority = m_sbm[5] >> 26;
+assign sbm_rd_obj5_ps = m_sbm[5] >> 24;
+assign sbm_rd_obj5_pd1 = m_sbm[5] >> 16;
+assign sbm_rd_obj5_pd0 = m_sbm[5] >> 8;
+assign sbm_rd_obj5_x = m_sbm[5];
+assign sbm_rd_obj6_primary = m_sbm[6] >> 27;
+assign sbm_rd_obj6_priority = m_sbm[6] >> 26;
+assign sbm_rd_obj6_ps = m_sbm[6] >> 24;
+assign sbm_rd_obj6_pd1 = m_sbm[6] >> 16;
+assign sbm_rd_obj6_pd0 = m_sbm[6] >> 8;
+assign sbm_rd_obj6_x = m_sbm[6];
+assign sbm_rd_obj7_primary = m_sbm[7] >> 27;
+assign sbm_rd_obj7_priority = m_sbm[7] >> 26;
+assign sbm_rd_obj7_ps = m_sbm[7] >> 24;
+assign sbm_rd_obj7_pd1 = m_sbm[7] >> 16;
+assign sbm_rd_obj7_pd0 = m_sbm[7] >> 8;
+assign sbm_rd_obj7_x = m_sbm[7];
+
+always @*
+ begin
+ d_obj0_pd1_shift = q_obj0_pd1_shift;
+ d_obj1_pd1_shift = q_obj1_pd1_shift;
+ d_obj2_pd1_shift = q_obj2_pd1_shift;
+ d_obj3_pd1_shift = q_obj3_pd1_shift;
+ d_obj4_pd1_shift = q_obj4_pd1_shift;
+ d_obj5_pd1_shift = q_obj5_pd1_shift;
+ d_obj6_pd1_shift = q_obj6_pd1_shift;
+ d_obj7_pd1_shift = q_obj7_pd1_shift;
+ d_obj0_pd0_shift = q_obj0_pd0_shift;
+ d_obj1_pd0_shift = q_obj1_pd0_shift;
+ d_obj2_pd0_shift = q_obj2_pd0_shift;
+ d_obj3_pd0_shift = q_obj3_pd0_shift;
+ d_obj4_pd0_shift = q_obj4_pd0_shift;
+ d_obj5_pd0_shift = q_obj5_pd0_shift;
+ d_obj6_pd0_shift = q_obj6_pd0_shift;
+ d_obj7_pd0_shift = q_obj7_pd0_shift;
+
+ if (en_in && (nes_y_in < 239))
+ begin
+ if (pix_pulse_in)
+ begin
+ d_obj0_pd1_shift = { 1\'b0, q_obj0_pd1_shift[7:1] };
+ d_obj0_pd0_shift = { 1\'b0, q_obj0_pd0_shift[7:1] };
+ end
+ else if ((nes_x_in - sbm_rd_obj0_x) == 8\'h00)
+ begin
+ d_obj0_pd1_shift = sbm_rd_obj0_pd1;
+ d_obj0_pd0_shift = sbm_rd_obj0_pd0;
+ end
+
+ if (pix_pulse_in)
+ begin
+ d_obj1_pd1_shift = { 1\'b0, q_obj1_pd1_shift[7:1] };
+ d_obj1_pd0_shift = { 1\'b0, q_obj1_pd0_shift[7:1] };
+ end
+ else if ((nes_x_in - sbm_rd_obj1_x) == 8\'h00)
+ begin
+ d_obj1_pd1_shift = sbm_rd_obj1_pd1;
+ d_obj1_pd0_shift = sbm_rd_obj1_pd0;
+ end
+
+ if (pix_pulse_in)
+ begin
+ d_obj2_pd1_shift = { 1\'b0, q_obj2_pd1_shift[7:1] };
+ d_obj2_pd0_shift = { 1\'b0, q_obj2_pd0_shift[7:1] };
+ end
+ else if ((nes_x_in - sbm_rd_obj2_x) == 8\'h00)
+ begin
+ d_obj2_pd1_shift = sbm_rd_obj2_pd1;
+ d_obj2_pd0_shift = sbm_rd_obj2_pd0;
+ end
+
+ if (pix_pulse_in)
+ begin
+ d_obj3_pd1_shift = { 1\'b0, q_obj3_pd1_shift[7:1] };
+ d_obj3_pd0_shift = { 1\'b0, q_obj3_pd0_shift[7:1] };
+ end
+ else if ((nes_x_in - sbm_rd_obj3_x) == 8\'h00)
+ begin
+ d_obj3_pd1_shift = sbm_rd_obj3_pd1;
+ d_obj3_pd0_shift = sbm_rd_obj3_pd0;
+ end
+
+ if (pix_pulse_in)
+ begin
+ d_obj4_pd1_shift = { 1\'b0, q_obj4_pd1_shift[7:1] };
+ d_obj4_pd0_shift = { 1\'b0, q_obj4_pd0_shift[7:1] };
+ end
+ else if ((nes_x_in - sbm_rd_obj4_x) == 8\'h00)
+ begin
+ d_obj4_pd1_shift = sbm_rd_obj4_pd1;
+ d_obj4_pd0_shift = sbm_rd_obj4_pd0;
+ end
+
+ if (pix_pulse_in)
+ begin
+ d_obj5_pd1_shift = { 1\'b0, q_obj5_pd1_shift[7:1] };
+ d_obj5_pd0_shift = { 1\'b0, q_obj5_pd0_shift[7:1] };
+ end
+ else if ((nes_x_in - sbm_rd_obj5_x) == 8\'h00)
+ begin
+ d_obj5_pd1_shift = sbm_rd_obj5_pd1;
+ d_obj5_pd0_shift = sbm_rd_obj5_pd0;
+ end
+
+ if (pix_pulse_in)
+ begin
+ d_obj6_pd1_shift = { 1\'b0, q_obj6_pd1_shift[7:1] };
+ d_obj6_pd0_shift = { 1\'b0, q_obj6_pd0_shift[7:1] };
+ end
+ else if ((nes_x_in - sbm_rd_obj6_x) == 8\'h00)
+ begin
+ d_obj6_pd1_shift = sbm_rd_obj6_pd1;
+ d_obj6_pd0_shift = sbm_rd_obj6_pd0;
+ end
+
+ if (pix_pulse_in)
+ begin
+ d_obj7_pd1_shift = { 1\'b0, q_obj7_pd1_shift[7:1] };
+ d_obj7_pd0_shift = { 1\'b0, q_obj7_pd0_shift[7:1] };
+ end
+ else if ((nes_x_in - sbm_rd_obj7_x) == 8\'h00)
+ begin
+ d_obj7_pd1_shift = sbm_rd_obj7_pd1;
+ d_obj7_pd0_shift = sbm_rd_obj7_pd0;
+ end
+ end
+ end
+
+assign { primary_out, priority_out, palette_idx_out } =
+ (!en_in || (ls_clip_in && (nes_x_in >= 10\'h000) && (nes_x_in < 10\'h008))) ?
+ 6\'h00 :
+ ({ q_obj0_pd1_shift[0], q_obj0_pd0_shift[0] } != 0) ?
+ { sbm_rd_obj0_primary, sbm_rd_obj0_priority, sbm_rd_obj0_ps, q_obj0_pd1_shift[0], q_obj0_pd0_shift[0] } :
+ ({ q_obj1_pd1_shift[0], q_obj1_pd0_shift[0] } != 0) ?
+ { sbm_rd_obj1_primary, sbm_rd_obj1_priority, sbm_rd_obj1_ps, q_obj1_pd1_shift[0], q_obj1_pd0_shift[0] } :
+ ({ q_obj2_pd1_shift[0], q_obj2_pd0_shift[0] } != 0) ?
+ { sbm_rd_obj2_primary, sbm_rd_obj2_priority, sbm_rd_obj2_ps, q_obj2_pd1_shift[0], q_obj2_pd0_shift[0] } :
+ ({ q_obj3_pd1_shift[0], q_obj3_pd0_shift[0] } != 0) ?
+ { sbm_rd_obj3_primary, sbm_rd_obj3_priority, sbm_rd_obj3_ps, q_obj3_pd1_shift[0], q_obj3_pd0_shift[0] } :
+ ({ q_obj4_pd1_shift[0], q_obj4_pd0_shift[0] } != 0) ?
+ { sbm_rd_obj4_primary, sbm_rd_obj4_priority, sbm_rd_obj4_ps, q_obj4_pd1_shift[0], q_obj4_pd0_shift[0] } :
+ ({ q_obj5_pd1_shift[0], q_obj5_pd0_shift[0] } != 0) ?
+ { sbm_rd_obj5_primary, sbm_rd_obj5_priority, sbm_rd_obj5_ps, q_obj5_pd1_shift[0], q_obj5_pd0_shift[0] } :
+ ({ q_obj6_pd1_shift[0], q_obj6_pd0_shift[0] } != 0) ?
+ { sbm_rd_obj6_primary, sbm_rd_obj6_priority, sbm_rd_obj6_ps, q_obj6_pd1_shift[0], q_obj6_pd0_shift[0] } :
+ ({ q_obj7_pd1_shift[0], q_obj7_pd0_shift[0] } != 0) ?
+ { sbm_rd_obj7_primary, sbm_rd_obj7_priority, sbm_rd_obj7_ps, q_obj7_pd1_shift[0], q_obj7_pd0_shift[0] } : 6\'b0000;
+
+assign oam_d_out = m_oam[oam_a_in];
+assign overflow_out = q_spr_overflow;
+
+endmodule
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/vram.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Video RAM module; implements 2KB of on-board VRAM as fpga block RAM.
+***************************************************************************************************/
+
+module vram
+(
+ input wire clk_in, // system clock
+ input wire en_in, // chip enable
+ input wire r_nw_in, // read/write select (read: 0, write: 1)
+ input wire [10:0] a_in, // memory address
+ input wire [ 7:0] d_in, // data input
+ output wire [ 7:0] d_out // data output
+);
+
+wire vram_bram_we;
+wire [7:0] vram_bram_dout;
+
+single_port_ram_sync #(.ADDR_WIDTH(11),
+ .DATA_WIDTH(8)) vram_bram(
+ .clk(clk_in),
+ .we(vram_bram_we),
+ .addr_a(a_in),
+ .din_a(d_in),
+ .dout_a(vram_bram_dout)
+);
+
+assign vram_bram_we = (en_in) ? ~r_nw_in : 1\'b0;
+assign d_out = (en_in) ? vram_bram_dout : 8\'h00;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/nes_top.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Top level module for an fpga-based Nintendo Entertainment System emulator.
+***************************************************************************************************/
+
+module nes_top
+(
+ input wire CLK_100MHZ, // 100MHz system clock signal
+ input wire BTN_SOUTH, // reset push button
+ input wire BTN_EAST, // console reset
+ input wire RXD, // rs-232 rx signal
+ input wire [3:0] SW, // switches
+ input wire NES_JOYPAD_DATA1, // joypad 1 input signal
+ input wire NES_JOYPAD_DATA2, // joypad 2 input signal
+ output wire TXD, // rs-232 tx signal
+ output wire VGA_HSYNC, // vga hsync signal
+ output wire VGA_VSYNC, // vga vsync signal
+ output wire [2:0] VGA_RED, // vga red signal
+ output wire [2:0] VGA_GREEN, // vga green signal
+ output wire [1:0] VGA_BLUE, // vga blue signal
+ output wire NES_JOYPAD_CLK, // joypad output clk signal
+ output wire NES_JOYPAD_LATCH, // joypad output latch signal
+ output wire AUDIO // pwm output audio channel
+);
+
+//
+// System Memory Buses
+//
+wire [ 7:0] cpumc_din;
+wire [15:0] cpumc_a;
+wire cpumc_r_nw;
+
+wire [ 7:0] ppumc_din;
+wire [13:0] ppumc_a;
+wire ppumc_wr;
+
+//
+// RP2A03: Main processing chip including CPU, APU, joypad control, and sprite DMA control.
+//
+wire rp2a03_rdy;
+wire [ 7:0] rp2a03_din;
+wire rp2a03_nnmi;
+wire [ 7:0] rp2a03_dout;
+wire [15:0] rp2a03_a;
+wire rp2a03_r_nw;
+wire rp2a03_brk;
+wire [ 3:0] rp2a03_dbgreg_sel;
+wire [ 7:0] rp2a03_dbgreg_din;
+wire rp2a03_dbgreg_wr;
+wire [ 7:0] rp2a03_dbgreg_dout;
+
+rp2a03 rp2a03_blk(
+ .clk_in(CLK_100MHZ),
+ .rst_in(BTN_SOUTH),
+ .rdy_in(rp2a03_rdy),
+ .d_in(rp2a03_din),
+ .nnmi_in(rp2a03_nnmi),
+ .nres_in(~BTN_EAST),
+ .d_out(rp2a03_dout),
+ .a_out(rp2a03_a),
+ .r_nw_out(rp2a03_r_nw),
+ .brk_out(rp2a03_brk),
+ .jp_data1_in(NES_JOYPAD_DATA1),
+ .jp_data2_in(NES_JOYPAD_DATA2),
+ .jp_clk(NES_JOYPAD_CLK),
+ .jp_latch(NES_JOYPAD_LATCH),
+ .mute_in(SW),
+ .audio_out(AUDIO),
+ .dbgreg_sel_in(rp2a03_dbgreg_sel),
+ .dbgreg_d_in(rp2a03_dbgreg_din),
+ .dbgreg_wr_in(rp2a03_dbgreg_wr),
+ .dbgreg_d_out(rp2a03_dbgreg_dout)
+);
+
+//
+// CART: cartridge emulator
+//
+wire cart_prg_nce;
+wire [ 7:0] cart_prg_dout;
+wire [ 7:0] cart_chr_dout;
+wire cart_ciram_nce;
+wire cart_ciram_a10;
+wire [39:0] cart_cfg;
+wire cart_cfg_upd;
+
+cart cart_blk(
+ .clk_in(CLK_100MHZ),
+ .cfg_in(cart_cfg),
+ .cfg_upd_in(cart_cfg_upd),
+ .prg_nce_in(cart_prg_nce),
+ .prg_a_in(cpumc_a[14:0]),
+ .prg_r_nw_in(cpumc_r_nw),
+ .prg_d_in(cpumc_din),
+ .prg_d_out(cart_prg_dout),
+ .chr_a_in(ppumc_a),
+ .chr_r_nw_in(~ppumc_wr),
+ .chr_d_in(ppumc_din),
+ .chr_d_out(cart_chr_dout),
+ .ciram_nce_out(cart_ciram_nce),
+ .ciram_a10_out(cart_ciram_a10)
+);
+
+assign cart_prg_nce = ~cpumc_a[15];
+
+//
+// WRAM: internal work ram
+//
+wire wram_en;
+wire [7:0] wram_dout;
+
+wram wram_blk(
+ .clk_in(CLK_100MHZ),
+ .en_in(wram_en),
+ .r_nw_in(cpumc_r_nw),
+ .a_in(cpumc_a[10:0]),
+ .d_in(cpumc_din),
+ .d_out(wram_dout)
+);
+
+assign wram_en = (cpumc_a[15:13] == 0);
+
+//
+// VRAM: internal video ram
+//
+wire [10:0] vram_a;
+wire [ 7:0] vram_dout;
+
+vram vram_blk(
+ .clk_in(CLK_100MHZ),
+ .en_in(~cart_ciram_nce),
+ .r_nw_in(~ppumc_wr),
+ .a_in(vram_a),
+ .d_in(ppumc_din),
+ .d_out(vram_dout)
+);
+
+//
+// PPU: picture processing unit block.
+//
+wire [ 2:0] ppu_ri_sel; // ppu register interface reg select
+wire ppu_ri_ncs; // ppu register interface enable
+wire ppu_ri_r_nw; // ppu register interface read/write select
+wire [ 7:0] ppu_ri_din; // ppu register interface data input
+wire [ 7:0] ppu_ri_dout; // ppu register interface data output
+
+wire [13:0] ppu_vram_a; // ppu video ram address bus
+wire ppu_vram_wr; // ppu video ram read/write select
+wire [ 7:0] ppu_vram_din; // ppu video ram data bus (input)
+wire [ 7:0] ppu_vram_dout; // ppu video ram data bus (output)
+
+wire ppu_nvbl; // ppu /VBL signal.
+
+// PPU snoops the CPU address bus for register reads/writes. Addresses 0x2000-0x2007
+// are mapped to the PPU register space, with every 8 bytes mirrored through 0x3FFF.
+assign ppu_ri_sel = cpumc_a[2:0];
+assign ppu_ri_ncs = (cpumc_a[15:13] == 3\'b001) ? 1\'b0 : 1\'b1;
+assign ppu_ri_r_nw = cpumc_r_nw;
+assign ppu_ri_din = cpumc_din;
+
+ppu ppu_blk(
+ .clk_in(CLK_100MHZ),
+ .rst_in(BTN_SOUTH),
+ .ri_sel_in(ppu_ri_sel),
+ .ri_ncs_in(ppu_ri_ncs),
+ .ri_r_nw_in(ppu_ri_r_nw),
+ .ri_d_in(ppu_ri_din),
+ .vram_d_in(ppu_vram_din),
+ .hsync_out(VGA_HSYNC),
+ .vsync_out(VGA_VSYNC),
+ .r_out(VGA_RED),
+ .g_out(VGA_GREEN),
+ .b_out(VGA_BLUE),
+ .ri_d_out(ppu_ri_dout),
+ .nvbl_out(ppu_nvbl),
+ .vram_a_out(ppu_vram_a),
+ .vram_d_out(ppu_vram_dout),
+ .vram_wr_out(ppu_vram_wr)
+);
+
+assign vram_a = { cart_ciram_a10, ppumc_a[9:0] };
+
+//
+// HCI: host communication interface block. Interacts with NesDbg software through serial port.
+//
+wire hci_active;
+wire [ 7:0] hci_cpu_din;
+wire [ 7:0] hci_cpu_dout;
+wire [15:0] hci_cpu_a;
+wire hci_cpu_r_nw;
+wire [ 7:0] hci_ppu_vram_din;
+wire [ 7:0] hci_ppu_vram_dout;
+wire [15:0] hci_ppu_vram_a;
+wire hci_ppu_vram_wr;
+
+hci hci_blk(
+ .clk(CLK_100MHZ),
+ .rst(BTN_SOUTH),
+ .rx(RXD),
+ .brk(rp2a03_brk),
+ .cpu_din(hci_cpu_din),
+ .cpu_dbgreg_in(rp2a03_dbgreg_dout),
+ .ppu_vram_din(hci_ppu_vram_din),
+ .tx(TXD),
+ .active(hci_active),
+ .cpu_r_nw(hci_cpu_r_nw),
+ .cpu_a(hci_cpu_a),
+ .cpu_dout(hci_cpu_dout),
+ .cpu_dbgreg_sel(rp2a03_dbgreg_sel),
+ .cpu_dbgreg_out(rp2a03_dbgreg_din),
+ .cpu_dbgreg_wr(rp2a03_dbgreg_wr),
+ .ppu_vram_wr(hci_ppu_vram_wr),
+ .ppu_vram_a(hci_ppu_vram_a),
+ .ppu_vram_dout(hci_ppu_vram_dout),
+ .cart_cfg(cart_cfg),
+ .cart_cfg_upd(cart_cfg_upd)
+);
+
+// Mux cpumc signals from rp2a03 or hci blk, depending on debug break state (hci_active).
+assign rp2a03_rdy = (hci_active) ? 1\'b0 : 1\'b1;
+assign cpumc_a = (hci_active) ? hci_cpu_a : rp2a03_a;
+assign cpumc_r_nw = (hci_active) ? hci_cpu_r_nw : rp2a03_r_nw;
+assign cpumc_din = (hci_active) ? hci_cpu_dout : rp2a03_dout;
+
+assign rp2a03_din = cart_prg_dout | wram_dout | ppu_ri_dout;
+assign hci_cpu_din = cart_prg_dout | wram_dout | ppu_ri_dout;
+
+// Mux ppumc signals from ppu or hci blk, depending on debug break state (hci_active).
+assign ppumc_a = (hci_active) ? hci_ppu_vram_a[13:0] : ppu_vram_a;
+assign ppumc_wr = (hci_active) ? hci_ppu_vram_wr : ppu_vram_wr;
+assign ppumc_din = (hci_active) ? hci_ppu_vram_dout : ppu_vram_dout;
+
+assign ppu_vram_din = cart_chr_dout | vram_dout;
+assign hci_ppu_vram_din = cart_chr_dout | vram_dout;
+
+// Issue NMI interupt on PPU vertical blank.
+assign rp2a03_nnmi = ppu_nvbl;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/ppu/ppu_ri.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* External register interface PPU sub-block.
+***************************************************************************************************/
+
+module ppu_ri
+(
+ input wire clk_in, // 100MHz system clock signal
+ input wire rst_in, // reset signal
+ input wire [ 2:0] sel_in, // register interface reg select
+ input wire ncs_in, // register interface enable (active low)
+ input wire r_nw_in, // register interface read/write select
+ input wire [ 7:0] cpu_d_in, // register interface data in from cpu
+ input wire [13:0] vram_a_in, // current vram address
+ input wire [ 7:0] vram_d_in, // data in from vram
+ input wire [ 7:0] pram_d_in, // data in from palette ram
+ input wire vblank_in, // high during vertical blank
+ input wire [ 7:0] spr_ram_d_in, // sprite ram data (for 0x2004 reads)
+ input wire spr_overflow_in, // more than 8 sprites hit on a scanline during last frame
+ input wire spr_pri_col_in, // primary object collision in last frame
+ output wire [ 7:0] cpu_d_out, // register interface data out to cpu
+ output reg [ 7:0] vram_d_out, // data out to vram
+ output reg vram_wr_out, // rd/wr select for vram ops
+ output reg pram_wr_out, // rd/wr select for palette ram ops
+ output wire [ 2:0] fv_out, // fine vertical scroll register
+ output wire [ 4:0] vt_out, // vertical tile scroll register
+ output wire v_out, // vertical name table selection register
+ output wire [ 2:0] fh_out, // fine horizontal scroll register
+ output wire [ 4:0] ht_out, // horizontal tile scroll register
+ output wire h_out, // horizontal name table selection register
+ output wire s_out, // playfield pattern table selection register
+ output reg inc_addr_out, // increment vmem addr (due to ri mem access)
+ output wire inc_addr_amt_out, // amount to increment vmem addr by (0x2002.7)
+ output wire nvbl_en_out, // enable nmi on vertical blank
+ output wire vblank_out, // current 2002.7 value for nmi
+ output wire bg_en_out, // enable background rendering
+ output wire spr_en_out, // enable sprite rendering
+ output wire bg_ls_clip_out, // clip playfield from left screen column (8 pixels)
+ output wire spr_ls_clip_out, // clip sprites from left screen column (8 pixels)
+ output wire spr_h_out, // 8/16 scanline sprites
+ output wire spr_pt_sel_out, // pattern table select for sprites (0x2000.3)
+ output wire upd_cntrs_out, // copy PPU registers to PPU counters
+ output wire [ 7:0] spr_ram_a_out, // sprite ram address (for 0x2004 reads/writes)
+ output reg [ 7:0] spr_ram_d_out, // sprite ram data (for 0x2004 writes)
+ output reg spr_ram_wr_out // sprite ram write enable (for 0x2004 writes)
+);
+
+//
+// Scroll Registers
+//
+reg [2:0] q_fv, d_fv; // fine vertical scroll latch
+reg [4:0] q_vt, d_vt; // vertical tile index latch
+reg q_v, d_v; // vertical name table selection latch
+reg [2:0] q_fh, d_fh; // fine horizontal scroll latch
+reg [4:0] q_ht, d_ht; // horizontal tile index latch
+reg q_h, d_h; // horizontal name table selection latch
+reg q_s, d_s; // playfield pattern table selection latch
+
+//
+// Output Latches
+//
+reg [7:0] q_cpu_d_out, d_cpu_d_out; // output data bus latch for 0x2007 reads
+reg q_upd_cntrs_out, d_upd_cntrs_out; // output latch for upd_cntrs_out
+
+//
+// External State Registers
+//
+reg q_nvbl_en, d_nvbl_en; // 0x2000[7]: enables an NMI interrupt on vblank
+reg q_spr_h, d_spr_h; // 0x2000[5]: select 8/16 scanline high sprites
+reg q_spr_pt_sel, d_spr_pt_sel; // 0x2000[3]: sprite pattern table select
+reg q_addr_incr, d_addr_incr; // 0x2000[2]: amount to increment addr on 0x2007 access.
+ // 0: 1 byte, 1: 32 bytes.
+reg q_spr_en, d_spr_en; // 0x2001[4]: enables sprite rendering
+reg q_bg_en, d_bg_en; // 0x2001[3]: enables background rendering
+reg q_spr_ls_clip, d_spr_ls_clip; // 0x2001[2]: left side screen column (8 pixel) object clipping
+reg q_bg_ls_clip, d_bg_ls_clip; // 0x2001[1]: left side screen column (8 pixel) bg clipping
+reg q_vblank, d_vblank; // 0x2002[7]: indicates a vblank is occurring
+
+//
+// Internal State Registers
+//
+reg q_byte_sel, d_byte_sel; // tracks if next 0x2005/0x2006 write is high or low byte
+reg [7:0] q_rd_buf, d_rd_buf; // internal latch for buffered 0x2007 reads
+reg q_rd_rdy, d_rd_rdy; // controls q_rd_buf updates
+reg [7:0] q_spr_ram_a, d_spr_ram_a; // sprite ram pointer (set on 0x2003 write)
+
+reg q_ncs_in; // last ncs signal (to detect falling edges)
+reg q_vblank_in; // last vblank_in signal (to detect falling edges)
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_fv <= 2\'h0;
+ q_vt <= 5\'h00;
+ q_v <= 1\'h0;
+ q_fh <= 3\'h0;
+ q_ht <= 5\'h00;
+ q_h <= 1\'h0;
+ q_s <= 1\'h0;
+ q_cpu_d_out <= 8\'h00;
+ q_upd_cntrs_out <= 1\'h0;
+ q_nvbl_en <= 1\'h0;
+ q_spr_h <= 1\'h0;
+ q_spr_pt_sel <= 1\'h0;
+ q_addr_incr <= 1\'h0;
+ q_spr_en <= 1\'h0;
+ q_bg_en <= 1\'h0;
+ q_spr_ls_clip <= 1\'h0;
+ q_bg_ls_clip <= 1\'h0;
+ q_vblank <= 1\'h0;
+ q_byte_sel <= 1\'h0;
+ q_rd_buf <= 8\'h00;
+ q_rd_rdy <= 1\'h0;
+ q_spr_ram_a <= 8\'h00;
+ q_ncs_in <= 1\'h1;
+ q_vblank_in <= 1\'h0;
+ end
+ else
+ begin
+ q_fv <= d_fv;
+ q_vt <= d_vt;
+ q_v <= d_v;
+ q_fh <= d_fh;
+ q_ht <= d_ht;
+ q_h <= d_h;
+ q_s <= d_s;
+ q_cpu_d_out <= d_cpu_d_out;
+ q_upd_cntrs_out <= d_upd_cntrs_out;
+ q_nvbl_en <= d_nvbl_en;
+ q_spr_h <= d_spr_h;
+ q_spr_pt_sel <= d_spr_pt_sel;
+ q_addr_incr <= d_addr_incr;
+ q_spr_en <= d_spr_en;
+ q_bg_en <= d_bg_en;
+ q_spr_ls_clip <= d_spr_ls_clip;
+ q_bg_ls_clip <= d_bg_ls_clip;
+ q_vblank <= d_vblank;
+ q_byte_sel <= d_byte_sel;
+ q_rd_buf <= d_rd_buf;
+ q_rd_rdy <= d_rd_rdy;
+ q_spr_ram_a <= d_spr_ram_a;
+ q_ncs_in <= ncs_in;
+ q_vblank_in <= vblank_in;
+ end
+ end
+
+always @*
+ begin
+ // Default most state to its original value.
+ d_fv = q_fv;
+ d_vt = q_vt;
+ d_v = q_v;
+ d_fh = q_fh;
+ d_ht = q_ht;
+ d_h = q_h;
+ d_s = q_s;
+ d_cpu_d_out = q_cpu_d_out;
+ d_nvbl_en = q_nvbl_en;
+ d_spr_h = q_spr_h;
+ d_spr_pt_sel = q_spr_pt_sel;
+ d_addr_incr = q_addr_incr;
+ d_spr_en = q_spr_en;
+ d_bg_en = q_bg_en;
+ d_spr_ls_clip = q_spr_ls_clip;
+ d_bg_ls_clip = q_bg_ls_clip;
+ d_byte_sel = q_byte_sel;
+ d_spr_ram_a = q_spr_ram_a;
+
+ // Update the read buffer if a new read request is ready. This happens one cycle after a read
+ // of 0x2007.
+ d_rd_buf = (q_rd_rdy) ? vram_d_in : q_rd_buf;
+ d_rd_rdy = 1\'b0;
+
+ // Request a PPU counter update only after second write to 0x2006.
+ d_upd_cntrs_out = 1\'b0;
+
+ // Set the vblank status bit on a rising vblank edge. Clear it if vblank is false. Can also
+ // be cleared by reading 0x2002.
+ d_vblank = (~q_vblank_in & vblank_in) ? 1\'b1 :
+ (~vblank_in) ? 1\'b0 : q_vblank;
+
+ // Only request memory writes on write of 0x2007.
+ vram_wr_out = 1\'b0;
+ vram_d_out = 8\'h00;
+ pram_wr_out = 1\'b0;
+
+ // Only request VRAM addr increment on access of 0x2007.
+ inc_addr_out = 1\'b0;
+
+ spr_ram_d_out = 8\'h00;
+ spr_ram_wr_out = 1\'b0;
+
+ // Only evaluate RI reads/writes on /CS falling edges. This prevents executing the same
+ // command multiple times because the CPU runs at a slower clock rate than the PPU.
+ if (q_ncs_in & ~ncs_in)
+ begin
+ if (r_nw_in)
+ begin
+ // External register read.
+ case (sel_in)
+ 3\'h2: // 0x2002
+ begin
+ d_cpu_d_out = { q_vblank, spr_pri_col_in, spr_overflow_in, 5\'b00000 };
+ d_byte_sel = 1\'b0;
+ d_vblank = 1\'b0;
+ end
+ 3\'h4: // 0x2004
+ begin
+ d_cpu_d_out = spr_ram_d_in;
+ end
+ 3\'h7: // 0x2007
+ begin
+ d_cpu_d_out = (vram_a_in[13:8] == 6\'h3F) ? pram_d_in : q_rd_buf;
+ d_rd_rdy = 1\'b1;
+ inc_addr_out = 1\'b1;
+ end
+ endcase
+ end
+ else
+ begin
+ // External register write.
+ case (sel_in)
+ 3\'h0: // 0x2000
+ begin
+ d_nvbl_en = cpu_d_in[7];
+ d_spr_h = cpu_d_in[5];
+ d_s = cpu_d_in[4];
+ d_spr_pt_sel = cpu_d_in[3];
+ d_addr_incr = cpu_d_in[2];
+ d_v = cpu_d_in[1];
+ d_h = cpu_d_in[0];
+ end
+ 3\'h1: // 0x2001
+ begin
+ d_spr_en = cpu_d_in[4];
+ d_bg_en = cpu_d_in[3];
+ d_spr_ls_clip = ~cpu_d_in[2];
+ d_bg_ls_clip = ~cpu_d_in[1];
+ end
+ 3\'h3: // 0x2003
+ begin
+ d_spr_ram_a = cpu_d_in;
+ end
+ 3\'h4: // 0x2004
+ begin
+ spr_ram_d_out = cpu_d_in;
+ spr_ram_wr_out = 1\'b1;
+ d_spr_ram_a = q_spr_ram_a + 8\'h01;
+ end
+ 3\'h5: // 0x2005
+ begin
+ d_byte_sel = ~q_byte_sel;
+ if (~q_byte_sel)
+ begin
+ // First write.
+ d_fh = cpu_d_in[2:0];
+ d_ht = cpu_d_in[7:3];
+ end
+ else
+ begin
+ // Second write.
+ d_fv = cpu_d_in[2:0];
+ d_vt = cpu_d_in[7:3];
+ end
+ end
+ 3\'h6: // 0x2006
+ begin
+ d_byte_sel = ~q_byte_sel;
+ if (~q_byte_sel)
+ begin
+ // First write.
+ d_fv = { 1\'b0, cpu_d_in[5:4] };
+ d_v = cpu_d_in[3];
+ d_h = cpu_d_in[2];
+ d_vt[4:3] = cpu_d_in[1:0];
+ end
+ else
+ begin
+ // Second write.
+ d_vt[2:0] = cpu_d_in[7:5];
+ d_ht = cpu_d_in[4:0];
+ d_upd_cntrs_out = 1\'b1;
+ end
+ end
+ 3\'h7: // 0x2007
+ begin
+ if (vram_a_in[13:8] == 6\'h3F)
+ pram_wr_out = 1\'b1;
+ else
+ vram_wr_out = 1\'b1;
+
+ vram_d_out = cpu_d_in;
+ inc_addr_out = 1\'b1;
+ end
+ endcase
+ end
+ end
+ end
+
+assign cpu_d_out = (~ncs_in & r_nw_in) ? q_cpu_d_out : 8\'h00;
+assign fv_out = q_fv;
+assign vt_out = q_vt;
+assign v_out = q_v;
+assign fh_out = q_fh;
+assign ht_out = q_ht;
+assign h_out = q_h;
+assign s_out = q_s;
+assign inc_addr_amt_out = q_addr_incr;
+assign nvbl_en_out = q_nvbl_en;
+assign vblank_out = q_vblank;
+assign bg_en_out = q_bg_en;
+assign spr_en_out = q_spr_en;
+assign bg_ls_clip_out = q_bg_ls_clip;
+assign spr_ls_clip_out = q_spr_ls_clip;
+assign spr_h_out = q_spr_h;
+assign spr_pt_sel_out = q_spr_pt_sel;
+assign upd_cntrs_out = q_upd_cntrs_out;
+assign spr_ram_a_out = q_spr_ram_a;
+
+endmodule
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cpu/apu/apu_triangle.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* APU triangle channel.
+***************************************************************************************************/
+
+module apu_triangle
+(
+ input wire clk_in, // system clock signal
+ input wire rst_in, // reset signal
+ input wire en_in, // enable (via $4015)
+ input wire cpu_cycle_pulse_in, // 1 clk pulse on every cpu cycle
+ input wire lc_pulse_in, // 1 clk pulse for every length counter decrement
+ input wire eg_pulse_in, // 1 clk pulse for every env gen update
+ input wire [1:0] a_in, // control register addr (i.e. $400C - $400F)
+ input wire [7:0] d_in, // control register write value
+ input wire wr_in, // enable control register write
+ output wire [3:0] triangle_out, // triangle channel output
+ output wire active_out // triangle channel active (length counter > 0)
+);
+
+//
+// Timer
+//
+reg [10:0] q_timer_period;
+wire [10:0] d_timer_period;
+wire timer_pulse;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ q_timer_period <= 11\'h000;
+ else
+ q_timer_period <= d_timer_period;
+ end
+
+apu_div #(.PERIOD_BITS(11)) timer(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .pulse_in(cpu_cycle_pulse_in),
+ .reload_in(1\'b0),
+ .period_in(q_timer_period),
+ .pulse_out(timer_pulse)
+);
+
+assign d_timer_period = (wr_in && (a_in == 2\'b10)) ? { q_timer_period[10:8], d_in[7:0] } :
+ (wr_in && (a_in == 2\'b11)) ? { d_in[2:0], q_timer_period[7:0] } :
+ q_timer_period;
+
+//
+// Linear Counter
+//
+reg q_linear_counter_halt;
+wire d_linear_counter_halt;
+reg [7:0] q_linear_counter_cntl;
+wire [7:0] d_linear_counter_cntl;
+reg [6:0] q_linear_counter_val;
+wire [6:0] d_linear_counter_val;
+wire linear_counter_en;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_linear_counter_halt <= 1\'b0;
+ q_linear_counter_cntl <= 8\'h00;
+ q_linear_counter_val <= 7\'h00;
+ end
+ else
+ begin
+ q_linear_counter_halt <= d_linear_counter_halt;
+ q_linear_counter_cntl <= d_linear_counter_cntl;
+ q_linear_counter_val <= d_linear_counter_val;
+ end
+ end
+
+assign d_linear_counter_cntl = (wr_in && (a_in == 2\'b00)) ? d_in : q_linear_counter_cntl;
+
+assign d_linear_counter_val =
+ (eg_pulse_in && q_linear_counter_halt) ? q_linear_counter_cntl[6:0] :
+ (eg_pulse_in && (q_linear_counter_val != 7\'h00)) ? q_linear_counter_val - 7\'h01 :
+ q_linear_counter_val;
+
+assign d_linear_counter_halt =
+ (wr_in && (a_in == 2\'b11)) ? 1\'b1 :
+ (eg_pulse_in && !q_linear_counter_cntl[7]) ? 1\'b0 :
+ q_linear_counter_halt;
+
+assign linear_counter_en = |q_linear_counter_val;
+
+//
+// Length Counter
+//
+reg q_length_counter_halt;
+wire d_length_counter_halt;
+
+wire length_counter_wr;
+wire length_counter_en;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ q_length_counter_halt <= 1\'b0;
+ else
+ q_length_counter_halt <= d_length_counter_halt;
+ end
+
+apu_length_counter length_counter(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .en_in(en_in),
+ .halt_in(q_length_counter_halt),
+ .length_pulse_in(lc_pulse_in),
+ .length_in(d_in[7:3]),
+ .length_wr_in(length_counter_wr),
+ .en_out(length_counter_en)
+);
+
+assign d_length_counter_halt = (wr_in && (a_in == 2\'b00)) ? d_in[7] : q_length_counter_halt;
+assign length_counter_wr = wr_in && (a_in == 2\'b11);
+
+//
+// Sequencer
+//
+reg [4:0] q_seq;
+wire [4:0] d_seq;
+wire [3:0] seq_out;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ q_seq <= 5\'h0;
+ else
+ q_seq <= d_seq;
+ end
+
+assign d_seq = (active_out && timer_pulse) ? q_seq + 5\'h01 : q_seq;
+assign seq_out = (q_seq[4]) ? q_seq[3:0] : ~q_seq[3:0];
+
+assign active_out = linear_counter_en && length_counter_en;
+assign triangle_out = seq_out;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cmn/uart/uart_rx.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* UART receiver.
+***************************************************************************************************/
+
+module uart_rx
+#(
+ parameter DATA_BITS = 8,
+ parameter STOP_BITS = 1,
+ parameter PARITY_MODE = 1, // 0 = NONE, 1 = ODD, 2 = EVEN
+ parameter BAUD_CLK_OVERSAMPLE_RATE = 16
+)
+(
+ input wire clk, // System clock
+ input wire reset, // Reset signal
+ input wire baud_clk_tick, // 1 tick per OVERSAMPLE_RATE baud clks
+ input wire rx, // RX transmission wire
+ output wire [DATA_BITS-1:0] rx_data, // Output data
+ output wire rx_done_tick, // Output rdy signal
+ output wire parity_err // Asserted for one clk on parity error
+);
+
+localparam [5:0] STOP_OVERSAMPLE_TICKS = STOP_BITS * BAUD_CLK_OVERSAMPLE_RATE;
+
+// Symbolic state representations.
+localparam [4:0] S_IDLE = 5\'h01,
+ S_START = 5\'h02,
+ S_DATA = 5\'h04,
+ S_PARITY = 5\'h08,
+ S_STOP = 5\'h10;
+
+// Registers
+reg [4:0] q_state, d_state;
+reg [3:0] q_oversample_tick_cnt, d_oversample_tick_cnt;
+reg [DATA_BITS-1:0] q_data, d_data;
+reg [2:0] q_data_bit_idx, d_data_bit_idx;
+reg q_done_tick, d_done_tick;
+reg q_parity_err, d_parity_err;
+reg q_rx;
+
+always @(posedge clk, posedge reset)
+ begin
+ if (reset)
+ begin
+ q_state <= S_IDLE;
+ q_oversample_tick_cnt <= 0;
+ q_data <= 0;
+ q_data_bit_idx <= 0;
+ q_done_tick <= 1\'b0;
+ q_parity_err <= 1\'b0;
+ q_rx <= 1\'b1;
+ end
+ else
+ begin
+ q_state <= d_state;
+ q_oversample_tick_cnt <= d_oversample_tick_cnt;
+ q_data <= d_data;
+ q_data_bit_idx <= d_data_bit_idx;
+ q_done_tick <= d_done_tick;
+ q_parity_err <= d_parity_err;
+ q_rx <= rx;
+ end
+ end
+
+always @*
+ begin
+ // Default most state to remain unchanged.
+ d_state = q_state;
+ d_data = q_data;
+ d_data_bit_idx = q_data_bit_idx;
+
+ // Increment the tick counter if the baud_clk counter ticked.
+ d_oversample_tick_cnt = (baud_clk_tick) ? q_oversample_tick_cnt + 4\'h1 : q_oversample_tick_cnt;
+
+ // Default the done signal and parity err to 0.
+ d_done_tick = 1\'b0;
+ d_parity_err = 1\'b0;
+
+ case (q_state)
+ S_IDLE:
+ begin
+ // Detect incoming data when rx goes low (start bit).
+ if (~q_rx)
+ begin
+ d_state = S_START;
+ d_oversample_tick_cnt = 0;
+ end
+ end
+
+ S_START:
+ begin
+ // Wait for BAUD_CLK_OVERSAMPLE_RATE / 2 ticks to get ""centered"" in the start bit signal.
+ if (baud_clk_tick && (q_oversample_tick_cnt == ((BAUD_CLK_OVERSAMPLE_RATE - 1) / 2)))
+ begin
+ d_state = S_DATA;
+ d_oversample_tick_cnt = 0;
+ d_data_bit_idx = 0;
+ end
+ end
+
+ S_DATA:
+ begin
+ // Every BAUD_CLK_OVERSAMPLE_RATE clocks, sample rx and shift its value into the data reg.
+ if (baud_clk_tick && (q_oversample_tick_cnt == (BAUD_CLK_OVERSAMPLE_RATE - 1)))
+ begin
+ d_data = { q_rx, q_data[DATA_BITS-1:1] };
+ d_oversample_tick_cnt = 0;
+
+ if (q_data_bit_idx == (DATA_BITS - 1))
+ begin
+ if (PARITY_MODE == 0)
+ d_state = S_STOP;
+ else
+ d_state = S_PARITY;
+ end
+ else
+ d_data_bit_idx = q_data_bit_idx + 3\'h1;
+ end
+ end
+
+ S_PARITY:
+ begin
+ if (baud_clk_tick && (q_oversample_tick_cnt == (BAUD_CLK_OVERSAMPLE_RATE - 1)))
+ begin
+ if (PARITY_MODE == 1)
+ d_parity_err = (q_rx != ~^q_data);
+ else
+ d_parity_err = (q_rx != ^q_data);
+
+ d_state = S_STOP;
+ d_oversample_tick_cnt = 0;
+ end
+ end
+
+ S_STOP:
+ begin
+ // Wait for stop bit before returning to idle. Signal done_tick.
+ if (baud_clk_tick && (q_oversample_tick_cnt == STOP_OVERSAMPLE_TICKS - 1))
+ begin
+ d_state = S_IDLE;
+ d_done_tick = 1\'b1;
+ end
+ end
+ endcase
+end
+
+assign rx_data = q_data;
+assign rx_done_tick = q_done_tick;
+assign parity_err = q_parity_err;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/ppu/ppu.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Picture processing unit block.
+***************************************************************************************************/
+
+module ppu
+(
+ input wire clk_in, // 100MHz system clock signal
+ input wire rst_in, // reset signal
+ input wire [ 2:0] ri_sel_in, // register interface reg select
+ input wire ri_ncs_in, // register interface enable
+ input wire ri_r_nw_in, // register interface read/write select
+ input wire [ 7:0] ri_d_in, // register interface data in
+ input wire [ 7:0] vram_d_in, // video memory data bus (input)
+ output wire hsync_out, // vga hsync signal
+ output wire vsync_out, // vga vsync signal
+ output wire [ 2:0] r_out, // vga red signal
+ output wire [ 2:0] g_out, // vga green signal
+ output wire [ 1:0] b_out, // vga blue signal
+ output wire [ 7:0] ri_d_out, // register interface data out
+ output wire nvbl_out, // /VBL (low during vertical blank)
+ output wire [13:0] vram_a_out, // video memory address bus
+ output wire [ 7:0] vram_d_out, // video memory data bus (output)
+ output wire vram_wr_out // video memory read/write select
+);
+
+//
+// PPU_VGA: VGA output block.
+//
+wire [5:0] vga_sys_palette_idx;
+wire [9:0] vga_nes_x;
+wire [9:0] vga_nes_y;
+wire [9:0] vga_nes_y_next;
+wire vga_pix_pulse;
+wire vga_vblank;
+
+ppu_vga ppu_vga_blk(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .sys_palette_idx_in(vga_sys_palette_idx),
+ .hsync_out(hsync_out),
+ .vsync_out(vsync_out),
+ .r_out(r_out),
+ .g_out(g_out),
+ .b_out(b_out),
+ .nes_x_out(vga_nes_x),
+ .nes_y_out(vga_nes_y),
+ .nes_y_next_out(vga_nes_y_next),
+ .pix_pulse_out(vga_pix_pulse),
+ .vblank_out(vga_vblank)
+);
+
+//
+// PPU_RI: PPU register interface block.
+//
+wire [7:0] ri_vram_din;
+wire [7:0] ri_pram_din;
+wire [7:0] ri_spr_ram_din;
+wire ri_spr_overflow;
+wire ri_spr_pri_col;
+wire [7:0] ri_vram_dout;
+wire ri_vram_wr;
+wire ri_pram_wr;
+wire [2:0] ri_fv;
+wire [4:0] ri_vt;
+wire ri_v;
+wire [2:0] ri_fh;
+wire [4:0] ri_ht;
+wire ri_h;
+wire ri_s;
+wire ri_inc_addr;
+wire ri_inc_addr_amt;
+wire ri_nvbl_en;
+wire ri_vblank;
+wire ri_bg_en;
+wire ri_spr_en;
+wire ri_bg_ls_clip;
+wire ri_spr_ls_clip;
+wire ri_spr_h;
+wire ri_spr_pt_sel;
+wire ri_upd_cntrs;
+wire [7:0] ri_spr_ram_a;
+wire [7:0] ri_spr_ram_dout;
+wire ri_spr_ram_wr;
+
+ppu_ri ppu_ri_blk(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .sel_in(ri_sel_in),
+ .ncs_in(ri_ncs_in),
+ .r_nw_in(ri_r_nw_in),
+ .cpu_d_in(ri_d_in),
+ .vram_a_in(vram_a_out),
+ .vram_d_in(ri_vram_din),
+ .pram_d_in(ri_pram_din),
+ .vblank_in(vga_vblank),
+ .spr_ram_d_in(ri_spr_ram_din),
+ .spr_overflow_in(ri_spr_overflow),
+ .spr_pri_col_in(ri_spr_pri_col),
+ .cpu_d_out(ri_d_out),
+ .vram_d_out(ri_vram_dout),
+ .vram_wr_out(ri_vram_wr),
+ .pram_wr_out(ri_pram_wr),
+ .fv_out(ri_fv),
+ .vt_out(ri_vt),
+ .v_out(ri_v),
+ .fh_out(ri_fh),
+ .ht_out(ri_ht),
+ .h_out(ri_h),
+ .s_out(ri_s),
+ .inc_addr_out(ri_inc_addr),
+ .inc_addr_amt_out(ri_inc_addr_amt),
+ .nvbl_en_out(ri_nvbl_en),
+ .vblank_out(ri_vblank),
+ .bg_en_out(ri_bg_en),
+ .spr_en_out(ri_spr_en),
+ .bg_ls_clip_out(ri_bg_ls_clip),
+ .spr_ls_clip_out(ri_spr_ls_clip),
+ .spr_h_out(ri_spr_h),
+ .spr_pt_sel_out(ri_spr_pt_sel),
+ .upd_cntrs_out(ri_upd_cntrs),
+ .spr_ram_a_out(ri_spr_ram_a),
+ .spr_ram_d_out(ri_spr_ram_dout),
+ .spr_ram_wr_out(ri_spr_ram_wr)
+);
+
+//
+// PPU_BG: PPU backgroud/playfield generator block.
+//
+wire [13:0] bg_vram_a;
+wire [ 3:0] bg_palette_idx;
+
+ppu_bg ppu_bg_blk(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .en_in(ri_bg_en),
+ .ls_clip_in(ri_bg_ls_clip),
+ .fv_in(ri_fv),
+ .vt_in(ri_vt),
+ .v_in(ri_v),
+ .fh_in(ri_fh),
+ .ht_in(ri_ht),
+ .h_in(ri_h),
+ .s_in(ri_s),
+ .nes_x_in(vga_nes_x),
+ .nes_y_in(vga_nes_y),
+ .nes_y_next_in(vga_nes_y_next),
+ .pix_pulse_in(vga_pix_pulse),
+ .vram_d_in(vram_d_in),
+ .ri_upd_cntrs_in(ri_upd_cntrs),
+ .ri_inc_addr_in(ri_inc_addr),
+ .ri_inc_addr_amt_in(ri_inc_addr_amt),
+ .vram_a_out(bg_vram_a),
+ .palette_idx_out(bg_palette_idx)
+);
+
+//
+// PPU_SPR: PPU sprite generator block.
+//
+wire [3:0] spr_palette_idx;
+wire spr_primary;
+wire spr_priority;
+wire [13:0] spr_vram_a;
+wire spr_vram_req;
+
+ppu_spr ppu_spr_blk(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .en_in(ri_spr_en),
+ .ls_clip_in(ri_spr_ls_clip),
+ .spr_h_in(ri_spr_h),
+ .spr_pt_sel_in(ri_spr_pt_sel),
+ .oam_a_in(ri_spr_ram_a),
+ .oam_d_in(ri_spr_ram_dout),
+ .oam_wr_in(ri_spr_ram_wr),
+ .nes_x_in(vga_nes_x),
+ .nes_y_in(vga_nes_y),
+ .nes_y_next_in(vga_nes_y_next),
+ .pix_pulse_in(vga_pix_pulse),
+ .vram_d_in(vram_d_in),
+ .oam_d_out(ri_spr_ram_din),
+ .overflow_out(ri_spr_overflow),
+ .palette_idx_out(spr_palette_idx),
+ .primary_out(spr_primary),
+ .priority_out(spr_priority),
+ .vram_a_out(spr_vram_a),
+ .vram_req_out(spr_vram_req)
+);
+
+//
+// Vidmem interface.
+//
+reg [5:0] palette_ram [31:0]; // internal palette RAM. 32 entries, 6-bits per entry.
+
+`define PRAM_A(addr) ((addr & 5\'h03) ? addr : (addr & 5\'h0f))
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ palette_ram[`PRAM_A(5\'h00)] <= 6\'h09;
+ palette_ram[`PRAM_A(5\'h01)] <= 6\'h01;
+ palette_ram[`PRAM_A(5\'h02)] <= 6\'h00;
+ palette_ram[`PRAM_A(5\'h03)] <= 6\'h01;
+ palette_ram[`PRAM_A(5\'h04)] <= 6\'h00;
+ palette_ram[`PRAM_A(5\'h05)] <= 6\'h02;
+ palette_ram[`PRAM_A(5\'h06)] <= 6\'h02;
+ palette_ram[`PRAM_A(5\'h07)] <= 6\'h0d;
+ palette_ram[`PRAM_A(5\'h08)] <= 6\'h08;
+ palette_ram[`PRAM_A(5\'h09)] <= 6\'h10;
+ palette_ram[`PRAM_A(5\'h0a)] <= 6\'h08;
+ palette_ram[`PRAM_A(5\'h0b)] <= 6\'h24;
+ palette_ram[`PRAM_A(5\'h0c)] <= 6\'h00;
+ palette_ram[`PRAM_A(5\'h0d)] <= 6\'h00;
+ palette_ram[`PRAM_A(5\'h0e)] <= 6\'h04;
+ palette_ram[`PRAM_A(5\'h0f)] <= 6\'h2c;
+ palette_ram[`PRAM_A(5\'h11)] <= 6\'h01;
+ palette_ram[`PRAM_A(5\'h12)] <= 6\'h34;
+ palette_ram[`PRAM_A(5\'h13)] <= 6\'h03;
+ palette_ram[`PRAM_A(5\'h15)] <= 6\'h04;
+ palette_ram[`PRAM_A(5\'h16)] <= 6\'h00;
+ palette_ram[`PRAM_A(5\'h17)] <= 6\'h14;
+ palette_ram[`PRAM_A(5\'h19)] <= 6\'h3a;
+ palette_ram[`PRAM_A(5\'h1a)] <= 6\'h00;
+ palette_ram[`PRAM_A(5\'h1b)] <= 6\'h02;
+ palette_ram[`PRAM_A(5\'h1d)] <= 6\'h20;
+ palette_ram[`PRAM_A(5\'h1e)] <= 6\'h2c;
+ palette_ram[`PRAM_A(5\'h1f)] <= 6\'h08;
+ end
+ else if (ri_pram_wr)
+ palette_ram[`PRAM_A(vram_a_out[4:0])] <= ri_vram_dout[5:0];
+ end
+
+assign ri_vram_din = vram_d_in;
+assign ri_pram_din = palette_ram[`PRAM_A(vram_a_out[4:0])];
+
+assign vram_a_out = (spr_vram_req) ? spr_vram_a : bg_vram_a;
+assign vram_d_out = ri_vram_dout;
+assign vram_wr_out = ri_vram_wr;
+
+//
+// Multiplexer. Final system palette index derivation.
+//
+reg q_pri_obj_col;
+wire d_pri_obj_col;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ q_pri_obj_col <= 1\'b0;
+ else
+ q_pri_obj_col <= d_pri_obj_col;
+ end
+
+wire spr_foreground;
+wire spr_trans;
+wire bg_trans;
+
+assign spr_foreground = ~spr_priority;
+assign spr_trans = ~|spr_palette_idx[1:0];
+assign bg_trans = ~|bg_palette_idx[1:0];
+
+assign d_pri_obj_col = (vga_nes_y_next == 0) ? 1\'b0 :
+ (spr_primary && !spr_trans && !bg_trans) ? 1\'b1 : q_pri_obj_col;
+
+assign vga_sys_palette_idx =
+ ((spr_foreground || bg_trans) && !spr_trans) ? palette_ram[{ 1\'b1, spr_palette_idx }] :
+ (!bg_trans) ? palette_ram[{ 1\'b0, bg_palette_idx }] :
+ palette_ram[5\'h00];
+
+assign ri_spr_pri_col = q_pri_obj_col;
+
+//
+// Assign miscellaneous output signals.
+//
+assign nvbl_out = ~(ri_vblank & ri_nvbl_en);
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/hci/hci.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* Host communication interface. Accepts packets over a serial connection, interacts with the rest
+* of the hw system as specified, and returns the specified data.
+***************************************************************************************************/
+
+module hci
+(
+ input wire clk, // 100MHz system clock signal
+ input wire rst, // reset signal
+ input wire rx, // rs-232 rx signal
+ input wire brk, // signal for cpu-intiated debug break
+ input wire [ 7:0] cpu_din, // cpu data bus (D) [input]
+ input wire [ 7:0] cpu_dbgreg_in, // cpu debug register read bus
+ input wire [ 7:0] ppu_vram_din, // ppu data bus [input]
+ output wire tx, // rs-232 tx signal
+ output wire active, // dbg block is active (disable CPU)
+ output reg cpu_r_nw, // cpu R/!W pin
+ output wire [15:0] cpu_a, // cpu A bus (A)
+ output reg [ 7:0] cpu_dout, // cpu data bus (D) [output]
+ output reg [ 3:0] cpu_dbgreg_sel, // selects cpu register to read/write through cpu_dbgreg_in
+ output reg [ 7:0] cpu_dbgreg_out, // cpu register write value for debug reg writes
+ output reg cpu_dbgreg_wr, // selects cpu register read/write mode
+ output reg ppu_vram_wr, // ppu memory write enable signal
+ output wire [15:0] ppu_vram_a, // ppu memory address
+ output wire [ 7:0] ppu_vram_dout, // ppu data bus [output]
+ output wire [39:0] cart_cfg, // cartridge config data (from iNES header)
+ output wire cart_cfg_upd // pulse on cart_cfg update so cart can reset
+);
+
+// Debug packet opcodes.
+localparam [7:0] OP_ECHO = 8\'h00,
+ OP_CPU_MEM_RD = 8\'h01,
+ OP_CPU_MEM_WR = 8\'h02,
+ OP_DBG_BRK = 8\'h03,
+ OP_DBG_RUN = 8\'h04,
+ OP_CPU_REG_RD = 8\'h05,
+ OP_CPU_REG_WR = 8\'h06,
+ OP_QUERY_DBG_BRK = 8\'h07,
+ OP_QUERY_ERR_CODE = 8\'h08,
+ OP_PPU_MEM_RD = 8\'h09,
+ OP_PPU_MEM_WR = 8\'h0A,
+ OP_PPU_DISABLE = 8\'h0B,
+ OP_CART_SET_CFG = 8\'h0C;
+
+// Error code bit positions.
+localparam DBG_UART_PARITY_ERR = 0,
+ DBG_UNKNOWN_OPCODE = 1;
+
+// Symbolic state representations.
+localparam [4:0] S_DISABLED = 5\'h00,
+ S_DECODE = 5\'h01,
+ S_ECHO_STG_0 = 5\'h02,
+ S_ECHO_STG_1 = 5\'h03,
+ S_CPU_MEM_RD_STG_0 = 5\'h04,
+ S_CPU_MEM_RD_STG_1 = 5\'h05,
+ S_CPU_MEM_WR_STG_0 = 5\'h06,
+ S_CPU_MEM_WR_STG_1 = 5\'h07,
+ S_CPU_REG_RD = 5\'h08,
+ S_CPU_REG_WR_STG_0 = 5\'h09,
+ S_CPU_REG_WR_STG_1 = 5\'h0A,
+ S_QUERY_ERR_CODE = 5\'h0B,
+ S_PPU_MEM_RD_STG_0 = 5\'h0C,
+ S_PPU_MEM_RD_STG_1 = 5\'h0D,
+ S_PPU_MEM_WR_STG_0 = 5\'h0E,
+ S_PPU_MEM_WR_STG_1 = 5\'h0F,
+ S_PPU_DISABLE = 5\'h10,
+ S_CART_SET_CFG_STG_0 = 5\'h11,
+ S_CART_SET_CFG_STG_1 = 5\'h12;
+
+reg [ 4:0] q_state, d_state;
+reg [ 2:0] q_decode_cnt, d_decode_cnt;
+reg [16:0] q_execute_cnt, d_execute_cnt;
+reg [15:0] q_addr, d_addr;
+reg [ 1:0] q_err_code, d_err_code;
+reg [39:0] q_cart_cfg, d_cart_cfg;
+reg q_cart_cfg_upd, d_cart_cfg_upd;
+
+// UART output buffer FFs.
+reg [7:0] q_tx_data, d_tx_data;
+reg q_wr_en, d_wr_en;
+
+// UART input signals.
+reg rd_en;
+wire [7:0] rd_data;
+wire rx_empty;
+wire tx_full;
+wire parity_err;
+
+// Update FF state.
+always @(posedge clk)
+ begin
+ if (rst)
+ begin
+ q_state <= S_DECODE;
+ q_decode_cnt <= 0;
+ q_execute_cnt <= 0;
+ q_addr <= 16\'h0000;
+ q_err_code <= 0;
+ q_cart_cfg <= 40\'h0000000000;
+ q_cart_cfg_upd <= 1\'b0;
+ q_tx_data <= 8\'h00;
+ q_wr_en <= 1\'b0;
+ end
+ else
+ begin
+ q_state <= d_state;
+ q_decode_cnt <= d_decode_cnt;
+ q_execute_cnt <= d_execute_cnt;
+ q_addr <= d_addr;
+ q_err_code <= d_err_code;
+ q_cart_cfg <= d_cart_cfg;
+ q_cart_cfg_upd <= d_cart_cfg_upd;
+ q_tx_data <= d_tx_data;
+ q_wr_en <= d_wr_en;
+ end
+ end
+
+// Instantiate the serial controller block.
+uart #(.SYS_CLK_FREQ(100000000),
+ .BAUD_RATE(38400),
+ .DATA_BITS(8),
+ .STOP_BITS(1),
+ .PARITY_MODE(1)) uart_blk
+(
+ .clk(clk),
+ .reset(rst),
+ .rx(rx),
+ .tx_data(q_tx_data),
+ .rd_en(rd_en),
+ .wr_en(q_wr_en),
+ .tx(tx),
+ .rx_data(rd_data),
+ .rx_empty(rx_empty),
+ .tx_full(tx_full),
+ .parity_err(parity_err)
+);
+
+always @*
+ begin
+ // Setup default FF updates.
+ d_state = q_state;
+ d_decode_cnt = q_decode_cnt;
+ d_execute_cnt = q_execute_cnt;
+ d_addr = q_addr;
+ d_err_code = q_err_code;
+ d_cart_cfg = q_cart_cfg;
+ d_cart_cfg_upd = 1\'b0;
+
+ rd_en = 1\'b0;
+ d_tx_data = 8\'h00;
+ d_wr_en = 1\'b0;
+
+ // Setup default output regs.
+ cpu_r_nw = 1\'b1;
+ cpu_dout = rd_data;
+ cpu_dbgreg_sel = 0;
+ cpu_dbgreg_out = 0;
+ cpu_dbgreg_wr = 1\'b0;
+ ppu_vram_wr = 1\'b0;
+
+ if (parity_err)
+ d_err_code[DBG_UART_PARITY_ERR] = 1\'b1;
+
+ case (q_state)
+ S_DISABLED:
+ begin
+ if (brk)
+ begin
+ // Received CPU initiated break. Begin active debugging.
+ d_state = S_DECODE;
+ end
+ else if (!rx_empty)
+ begin
+ rd_en = 1\'b1; // pop opcode off uart fifo
+
+ if (rd_data == OP_DBG_BRK)
+ begin
+ d_state = S_DECODE;
+ end
+ else if (rd_data == OP_QUERY_DBG_BRK)
+ begin
+ d_tx_data = 8\'h00; // Write ""0"" over UART to indicate we are not in a debug break
+ d_wr_en = 1\'b1;
+ end
+ end
+ end
+ S_DECODE:
+ begin
+ if (!rx_empty)
+ begin
+ rd_en = 1\'b1; // pop opcode off uart fifo
+ d_decode_cnt = 0; // start decode count at 0 for decode stage
+
+ // Move to appropriate decode stage based on opcode.
+ case (rd_data)
+ OP_ECHO: d_state = S_ECHO_STG_0;
+ OP_CPU_MEM_RD: d_state = S_CPU_MEM_RD_STG_0;
+ OP_CPU_MEM_WR: d_state = S_CPU_MEM_WR_STG_0;
+ OP_DBG_BRK: d_state = S_DECODE;
+ OP_CPU_REG_RD: d_state = S_CPU_REG_RD;
+ OP_CPU_REG_WR: d_state = S_CPU_REG_WR_STG_0;
+ OP_QUERY_ERR_CODE: d_state = S_QUERY_ERR_CODE;
+ OP_PPU_MEM_RD: d_state = S_PPU_MEM_RD_STG_0;
+ OP_PPU_MEM_WR: d_state = S_PPU_MEM_WR_STG_0;
+ OP_PPU_DISABLE: d_state = S_PPU_DISABLE;
+ OP_CART_SET_CFG: d_state = S_CART_SET_CFG_STG_0;
+ OP_DBG_RUN:
+ begin
+ d_state = S_DISABLED;
+ end
+ OP_QUERY_DBG_BRK:
+ begin
+ d_tx_data = 8\'h01; // Write ""1"" over UART to indicate we are in a debug break
+ d_wr_en = 1\'b1;
+ end
+ default:
+ begin
+ // Invalid opcode. Ignore, but set error code.
+ d_err_code[DBG_UNKNOWN_OPCODE] = 1\'b1;
+ d_state = S_DECODE;
+ end
+ endcase
+ end
+ end
+
+ // --- ECHO ---
+ // OP_CODE
+ // CNT_LO
+ // CNT_HI
+ // DATA
+ S_ECHO_STG_0:
+ begin
+ if (!rx_empty)
+ begin
+ rd_en = 1\'b1; // pop packet byte off uart fifo
+ d_decode_cnt = q_decode_cnt + 3\'h1; // advance to next decode stage
+ if (q_decode_cnt == 0)
+ begin
+ // Read CNT_LO into low bits of execute count.
+ d_execute_cnt = rd_data;
+ end
+ else
+ begin
+ // Read CNT_HI into high bits of execute count.
+ d_execute_cnt = { rd_data, q_execute_cnt[7:0] };
+ d_state = (d_execute_cnt) ? S_ECHO_STG_1 : S_DECODE;
+ end
+ end
+ end
+ S_ECHO_STG_1:
+ begin
+ if (!rx_empty)
+ begin
+ rd_en = 1\'b1; // pop packet byte off uart fifo
+ d_execute_cnt = q_execute_cnt - 17\'h00001; // advance to next execute stage
+
+ // Echo packet DATA byte over uart.
+ d_tx_data = rd_data;
+ d_wr_en = 1\'b1;
+
+ // After last byte of packet, return to decode stage.
+ if (d_execute_cnt == 0)
+ d_state = S_DECODE;
+ end
+ end
+
+ // --- CPU_MEM_RD ---
+ // OP_CODE
+ // ADDR_LO
+ // ADDR_HI
+ // CNT_LO
+ // CNT_HI
+ S_CPU_MEM_RD_STG_0:
+ begin
+ if (!rx_empty)
+ begin
+ rd_en = 1\'b1; // pop packet byte off uart fifo
+ d_decode_cnt = q_decode_cnt + 3\'h1; // advance to next decode stage
+ if (q_decode_cnt == 0)
+ begin
+ // Read ADDR_LO into low bits of addr.
+ d_addr = rd_data;
+ end
+ else if (q_decode_cnt == 1)
+ begin
+ // Read ADDR_HI into high bits of addr.
+ d_addr = { rd_data, q_addr[7:0] };
+ end
+ else if (q_decode_cnt == 2)
+ begin
+ // Read CNT_LO into low bits of execute count.
+ d_execute_cnt = rd_data;
+ end
+ else
+ begin
+ // Read CNT_HI into high bits of execute count. Execute count is shifted by 1:
+ // use 2 clock cycles per byte read.
+ d_execute_cnt = { rd_data, q_execute_cnt[7:0], 1\'b0 };
+ d_state = (d_execute_cnt) ? S_CPU_MEM_RD_STG_1 : S_DECODE;
+ end
+ end
+ end
+ S_CPU_MEM_RD_STG_1:
+ begin
+ if (~q_execute_cnt[0])
+ begin
+ // Dummy cycle. Allow memory read 1 cycle to return result, and allow uart tx fifo
+ // 1 cycle to update tx_full setting.
+ d_execute_cnt = q_execute_cnt - 17\'h00001;
+ end
+ else
+ begin
+ if (!tx_full)
+ begin
+ d_execute_cnt = q_execute_cnt - 17\'h00001; // advance to next execute stage
+ d_tx_data = cpu_din; // write data from cpu D bus
+ d_wr_en = 1\'b1; // request uart write
+
+ d_addr = q_addr + 16\'h0001; // advance to next byte
+
+ // After last byte is written to uart, return to decode stage.
+ if (d_execute_cnt == 0)
+ d_state = S_DECODE;
+ end
+ end
+ end
+
+ // --- CPU_MEM_WR ---
+ // OP_CODE
+ // ADDR_LO
+ // ADDR_HI
+ // CNT_LO
+ // CNT_HI
+ // DATA
+ S_CPU_MEM_WR_STG_0:
+ begin
+ if (!rx_empty)
+ begin
+ rd_en = 1\'b1; // pop packet byte off uart fifo
+ d_decode_cnt = q_decode_cnt + 3\'h1; // advance to next decode stage
+ if (q_decode_cnt == 0)
+ begin
+ // Read ADDR_LO into low bits of addr.
+ d_addr = rd_data;
+ end
+ else if (q_decode_cnt == 1)
+ begin
+ // Read ADDR_HI into high bits of addr.
+ d_addr = { rd_data, q_addr[7:0] };
+ end
+ else if (q_decode_cnt == 2)
+ begin
+ // Read CNT_LO into low bits of execute count.
+ d_execute_cnt = rd_data;
+ end
+ else
+ begin
+ // Read CNT_HI into high bits of execute count.
+ d_execute_cnt = { rd_data, q_execute_cnt[7:0] };
+ d_state = (d_execute_cnt) ? S_CPU_MEM_WR_STG_1 : S_DECODE;
+ end
+ end
+ end
+ S_CPU_MEM_WR_STG_1:
+ begin
+ if (!rx_empty)
+ begin
+ rd_en = 1\'b1; // pop packet byte off uart fifo
+ d_execute_cnt = q_execute_cnt - 17\'h00001; // advance to next execute stage
+ d_addr = q_addr + 16\'h0001; // advance to next byte
+
+ cpu_r_nw = 1\'b0;
+
+ // After last byte is written to memory, return to decode stage.
+ if (d_execute_cnt == 0)
+ d_state = S_DECODE;
+ end
+ end
+
+ // --- CPU_REG_RD ---
+ // OP_CODE
+ // REG_SEL
+ S_CPU_REG_RD:
+ begin
+ if (!rx_empty && !tx_full)
+ begin
+ rd_en = 1\'b1; // pop REG_SEL byte off uart fifo
+ cpu_dbgreg_sel = rd_data[3:0]; // select CPU reg based on REG_SEL
+ d_tx_data = cpu_dbgreg_in; // send reg read results to uart
+ d_wr_en = 1\'b1; // request uart write
+
+ d_state = S_DECODE;
+ end
+ end
+
+ // --- CPU_REG_WR ---
+ // OP_CODE
+ // REG_SEL
+ // DATA
+ S_CPU_REG_WR_STG_0:
+ begin
+ if (!rx_empty)
+ begin
+ rd_en = 1\'b1;
+ d_addr = rd_data;
+ d_state = S_CPU_REG_WR_STG_1;
+ end
+ end
+ S_CPU_REG_WR_STG_1:
+ begin
+ if (!rx_empty)
+ begin
+ rd_en = 1\'b1;
+ cpu_dbgreg_sel = q_addr[3:0];
+ cpu_dbgreg_wr = 1\'b1;
+ cpu_dbgreg_out = rd_data;
+ d_state = S_DECODE;
+ end
+ end
+
+ // --- QUERY_ERR_CODE ---
+ // OP_CODE
+ S_QUERY_ERR_CODE:
+ begin
+ if (!tx_full)
+ begin
+ d_tx_data = q_err_code; // write current error code
+ d_wr_en = 1\'b1; // request uart write
+ d_state = S_DECODE;
+ end
+ end
+
+ // --- PPU_MEM_RD ---
+ // OP_CODE
+ // ADDR_LO
+ // ADDR_HI
+ // CNT_LO
+ // CNT_HI
+ S_PPU_MEM_RD_STG_0:
+ begin
+ if (!rx_empty)
+ begin
+ rd_en = 1\'b1; // pop packet byte off uart fifo
+ d_decode_cnt = q_decode_cnt + 3\'h1; // advance to next decode stage
+ if (q_decode_cnt == 0)
+ begin
+ // Read ADDR_LO into low bits of addr.
+ d_addr = rd_data;
+ end
+ else if (q_decode_cnt == 1)
+ begin
+ // Read ADDR_HI into high bits of addr.
+ d_addr = { rd_data, q_addr[7:0] };
+ end
+ else if (q_decode_cnt == 2)
+ begin
+ // Read CNT_LO into low bits of execute count.
+ d_execute_cnt = rd_data;
+ end
+ else
+ begin
+ // Read CNT_HI into high bits of execute count. Execute count is shifted by 1:
+ // use 2 clock cycles per byte read.
+ d_execute_cnt = { rd_data, q_execute_cnt[7:0], 1\'b0 };
+ d_state = (d_execute_cnt) ? S_PPU_MEM_RD_STG_1 : S_DECODE;
+ end
+ end
+ end
+ S_PPU_MEM_RD_STG_1:
+ begin
+ if (~q_execute_cnt[0])
+ begin
+ // Dummy cycle. Allow memory read 1 cycle to return result, and allow uart tx fifo
+ // 1 cycle to update tx_full setting.
+ d_execute_cnt = q_execute_cnt - 17\'h00001;
+ end
+ else
+ begin
+ if (!tx_full)
+ begin
+ d_execute_cnt = q_execute_cnt - 17\'h00001; // advance to next execute stage
+ d_tx_data = ppu_vram_din; // write data from ppu D bus
+ d_wr_en = 1\'b1; // request uart write
+
+ d_addr = q_addr + 16\'h0001; // advance to next byte
+
+ // After last byte is written to uart, return to decode stage.
+ if (d_execute_cnt == 0)
+ d_state = S_DECODE;
+ end
+ end
+ end
+
+ // --- PPU_MEM_WR ---
+ // OP_CODE
+ // ADDR_LO
+ // ADDR_HI
+ // CNT_LO
+ // CNT_HI
+ // DATA
+ S_PPU_MEM_WR_STG_0:
+ begin
+ if (!rx_empty)
+ begin
+ rd_en = 1\'b1; // pop packet byte off uart fifo
+ d_decode_cnt = q_decode_cnt + 3\'h1; // advance to next decode stage
+ if (q_decode_cnt == 0)
+ begin
+ // Read ADDR_LO into low bits of addr.
+ d_addr = rd_data;
+ end
+ else if (q_decode_cnt == 1)
+ begin
+ // Read ADDR_HI into high bits of addr.
+ d_addr = { rd_data, q_addr[7:0] };
+ end
+ else if (q_decode_cnt == 2)
+ begin
+ // Read CNT_LO into low bits of execute count.
+ d_execute_cnt = rd_data;
+ end
+ else
+ begin
+ // Read CNT_HI into high bits of execute count.
+ d_execute_cnt = { rd_data, q_execute_cnt[7:0] };
+ d_state = (d_execute_cnt) ? S_PPU_MEM_WR_STG_1 : S_DECODE;
+ end
+ end
+ end
+ S_PPU_MEM_WR_STG_1:
+ begin
+ if (!rx_empty)
+ begin
+ rd_en = 1\'b1; // pop packet byte off uart fifo
+ d_execute_cnt = q_execute_cnt - 17\'h00001; // advance to next execute stage
+ d_addr = q_addr + 16\'h0001; // advance to next byte
+
+ ppu_vram_wr = 1\'b1;
+
+ // After last byte is written to memory, return to decode stage.
+ if (d_execute_cnt == 0)
+ d_state = S_DECODE;
+ end
+ end
+
+ // --- PPU_DISABLE ---
+ // OP_CODE
+ S_PPU_DISABLE:
+ begin
+ d_decode_cnt = q_decode_cnt + 3\'h1; // advance to next decode stage
+
+ if (q_decode_cnt == 0)
+ begin
+ d_addr = 16\'h2000;
+ end
+ else if (q_decode_cnt == 1)
+ begin
+ // Write 0x2000 to 0.
+ cpu_r_nw = 1\'b0;
+ cpu_dout = 8\'h00;
+
+ // Set addr to 0x0000 for one cycle (due to PPU quirk only recognizing register
+ // interface reads/writes when address bits [15-13] change from 3\'b001 from another
+ // value.
+ d_addr = 16\'h0000;
+ end
+ else if (q_decode_cnt == 2)
+ begin
+ d_addr = 16\'h2001;
+ end
+ else if (q_decode_cnt == 3)
+ begin
+ // Write 0x2000 to 0.
+ cpu_r_nw = 1\'b0;
+ cpu_dout = 8\'h00;
+
+ // Set addr to 0x0000 for one cycle (due to PPU quirk only recognizing register
+ // interface reads/writes when address bits [15-13] change from 3\'b001 from another
+ // value.
+ d_addr = 16\'h0000;
+ end
+ else if (q_decode_cnt == 4)
+ begin
+ d_addr = 16\'h2002;
+ end
+ else if (q_decode_cnt == 5)
+ begin
+ // Read 0x2002 to reset PPU byte pointer.
+ d_addr = 16\'h0000;
+ d_state = S_DECODE;
+ end
+ end
+
+ // --- CART_SET_CFG ---
+ // OP_CODE
+ // iNES byte 4 (16KB PRG-ROM bank count)
+ // iNES byte 5 (8KB CHR-ROM bank count)
+ // iNES byte 6 (ROM Control Byte 1)
+ // iNES byte 7 (ROM Control Byte 2)
+ // iNES byte 8 (8KB RAM bank count)
+ S_CART_SET_CFG_STG_0:
+ begin
+ d_execute_cnt = 16\'h0004;
+ d_state = S_CART_SET_CFG_STG_1;
+ end
+ S_CART_SET_CFG_STG_1:
+ begin
+ if (!rx_empty)
+ begin
+ rd_en = 1\'b1; // pop packet byte off uart fifo
+ d_execute_cnt = q_execute_cnt - 17\'h00001; // advance to next execute stage
+
+ d_cart_cfg = { q_cart_cfg[31:0], rd_data };
+
+ // After last byte of packet, return to decode stage.
+ if (q_execute_cnt == 0)
+ begin
+ d_state = S_DECODE;
+ d_cart_cfg_upd = 1\'b1;
+ end
+ end
+ end
+ endcase
+ end
+
+assign cpu_a = q_addr;
+assign active = (q_state != S_DISABLED);
+assign ppu_vram_a = q_addr;
+assign ppu_vram_dout = rd_data;
+assign cart_cfg = q_cart_cfg;
+assign cart_cfg_upd = q_cart_cfg_upd;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cpu/apu/apu_mixer.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* APU mixer.
+***************************************************************************************************/
+
+module apu_mixer
+(
+ input wire clk_in, // system clock signal
+ input wire rst_in, // reset signal
+ input wire [3:0] mute_in, // mute specific channels
+ input wire [3:0] pulse0_in, // pulse 0 channel input
+ input wire [3:0] pulse1_in, // pulse 1 channel input
+ input wire [3:0] triangle_in, // triangle channel input
+ input wire [3:0] noise_in, // noise channel input
+ output wire audio_out // mixed audio output
+);
+
+wire [3:0] pulse0;
+wire [3:0] pulse1;
+wire [3:0] triangle;
+wire [3:0] noise;
+
+reg [4:0] pulse_in_total;
+reg [5:0] pulse_out;
+
+reg [6:0] tnd_in_total;
+reg [5:0] tnd_out;
+
+reg [5:0] mixed_out;
+
+always @*
+ begin
+ pulse_in_total = pulse0 + pulse1;
+
+ case (pulse_in_total)
+ 5\'h00: pulse_out = 6\'h00;
+ 5\'h01: pulse_out = 6\'h01;
+ 5\'h02: pulse_out = 6\'h01;
+ 5\'h03: pulse_out = 6\'h02;
+ 5\'h04: pulse_out = 6\'h03;
+ 5\'h05: pulse_out = 6\'h03;
+ 5\'h06: pulse_out = 6\'h04;
+ 5\'h07: pulse_out = 6\'h05;
+ 5\'h08: pulse_out = 6\'h05;
+ 5\'h09: pulse_out = 6\'h06;
+ 5\'h0A: pulse_out = 6\'h07;
+ 5\'h0B: pulse_out = 6\'h07;
+ 5\'h0C: pulse_out = 6\'h08;
+ 5\'h0D: pulse_out = 6\'h08;
+ 5\'h0E: pulse_out = 6\'h09;
+ 5\'h0F: pulse_out = 6\'h09;
+ 5\'h10: pulse_out = 6\'h0A;
+ 5\'h11: pulse_out = 6\'h0A;
+ 5\'h12: pulse_out = 6\'h0B;
+ 5\'h13: pulse_out = 6\'h0B;
+ 5\'h14: pulse_out = 6\'h0C;
+ 5\'h15: pulse_out = 6\'h0C;
+ 5\'h16: pulse_out = 6\'h0D;
+ 5\'h17: pulse_out = 6\'h0D;
+ 5\'h18: pulse_out = 6\'h0E;
+ 5\'h19: pulse_out = 6\'h0E;
+ 5\'h1A: pulse_out = 6\'h0F;
+ 5\'h1B: pulse_out = 6\'h0F;
+ 5\'h1C: pulse_out = 6\'h0F;
+ 5\'h1D: pulse_out = 6\'h10;
+ 5\'h1E: pulse_out = 6\'h10;
+ default: pulse_out = 6\'bxxxxxx;
+ endcase
+
+ tnd_in_total = { triangle, 1\'b0 } + { 1\'b0, triangle } + { noise, 1\'b0 };
+
+ case (tnd_in_total)
+ 7\'h00: tnd_out = 6\'h00;
+ 7\'h01: tnd_out = 6\'h01;
+ 7\'h02: tnd_out = 6\'h01;
+ 7\'h03: tnd_out = 6\'h02;
+ 7\'h04: tnd_out = 6\'h03;
+ 7\'h05: tnd_out = 6\'h03;
+ 7\'h06: tnd_out = 6\'h04;
+ 7\'h07: tnd_out = 6\'h05;
+ 7\'h08: tnd_out = 6\'h05;
+ 7\'h09: tnd_out = 6\'h06;
+ 7\'h0A: tnd_out = 6\'h07;
+ 7\'h0B: tnd_out = 6\'h07;
+ 7\'h0C: tnd_out = 6\'h08;
+ 7\'h0D: tnd_out = 6\'h08;
+ 7\'h0E: tnd_out = 6\'h09;
+ 7\'h0F: tnd_out = 6\'h09;
+ 7\'h10: tnd_out = 6\'h0A;
+ 7\'h11: tnd_out = 6\'h0A;
+ 7\'h12: tnd_out = 6\'h0B;
+ 7\'h13: tnd_out = 6\'h0B;
+ 7\'h14: tnd_out = 6\'h0C;
+ 7\'h15: tnd_out = 6\'h0C;
+ 7\'h16: tnd_out = 6\'h0D;
+ 7\'h17: tnd_out = 6\'h0D;
+ 7\'h18: tnd_out = 6\'h0E;
+ 7\'h19: tnd_out = 6\'h0E;
+ 7\'h1A: tnd_out = 6\'h0F;
+ 7\'h1B: tnd_out = 6\'h0F;
+ 7\'h1C: tnd_out = 6\'h0F;
+ 7\'h1D: tnd_out = 6\'h10;
+ 7\'h1E: tnd_out = 6\'h10;
+ 7\'h1F: tnd_out = 6\'h11;
+ 7\'h20: tnd_out = 6\'h11;
+ 7\'h21: tnd_out = 6\'h11;
+ 7\'h22: tnd_out = 6\'h12;
+ 7\'h23: tnd_out = 6\'h12;
+ 7\'h24: tnd_out = 6\'h12;
+ 7\'h25: tnd_out = 6\'h13;
+ 7\'h26: tnd_out = 6\'h13;
+ 7\'h27: tnd_out = 6\'h14;
+ 7\'h28: tnd_out = 6\'h14;
+ 7\'h29: tnd_out = 6\'h14;
+ 7\'h2A: tnd_out = 6\'h15;
+ 7\'h2B: tnd_out = 6\'h15;
+ 7\'h2C: tnd_out = 6\'h15;
+ 7\'h2D: tnd_out = 6\'h15;
+ 7\'h2E: tnd_out = 6\'h16;
+ 7\'h2F: tnd_out = 6\'h16;
+ 7\'h30: tnd_out = 6\'h16;
+ 7\'h31: tnd_out = 6\'h17;
+ 7\'h32: tnd_out = 6\'h17;
+ 7\'h33: tnd_out = 6\'h17;
+ 7\'h34: tnd_out = 6\'h17;
+ 7\'h35: tnd_out = 6\'h18;
+ 7\'h36: tnd_out = 6\'h18;
+ 7\'h37: tnd_out = 6\'h18;
+ 7\'h38: tnd_out = 6\'h19;
+ 7\'h39: tnd_out = 6\'h19;
+ 7\'h3A: tnd_out = 6\'h19;
+ 7\'h3B: tnd_out = 6\'h19;
+ 7\'h3C: tnd_out = 6\'h1A;
+ 7\'h3D: tnd_out = 6\'h1A;
+ 7\'h3E: tnd_out = 6\'h1A;
+ 7\'h3F: tnd_out = 6\'h1A;
+ 7\'h40: tnd_out = 6\'h1B;
+ 7\'h41: tnd_out = 6\'h1B;
+ 7\'h42: tnd_out = 6\'h1B;
+ 7\'h43: tnd_out = 6\'h1B;
+ 7\'h44: tnd_out = 6\'h1B;
+ 7\'h45: tnd_out = 6\'h1C;
+ 7\'h46: tnd_out = 6\'h1C;
+ 7\'h47: tnd_out = 6\'h1C;
+ 7\'h48: tnd_out = 6\'h1C;
+ 7\'h49: tnd_out = 6\'h1C;
+ 7\'h4A: tnd_out = 6\'h1D;
+ 7\'h4B: tnd_out = 6\'h1D;
+ default: tnd_out = 6\'bxxxxxx;
+ endcase
+
+ mixed_out = pulse_out + tnd_out;
+ end
+
+//
+// Pulse width modulation.
+//
+reg [5:0] q_pwm_cnt;
+wire [5:0] d_pwm_cnt;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_pwm_cnt <= 6\'h0;
+ end
+ else
+ begin
+ q_pwm_cnt <= d_pwm_cnt;
+ end
+ end
+
+assign d_pwm_cnt = q_pwm_cnt + 4\'h1;
+
+assign pulse0 = (mute_in[0]) ? 4\'h0 : pulse0_in;
+assign pulse1 = (mute_in[1]) ? 4\'h0 : pulse1_in;
+assign triangle = (mute_in[2]) ? 4\'h0 : triangle_in;
+assign noise = (mute_in[3]) ? 4\'h0 : noise_in;
+
+assign audio_out = mixed_out > q_pwm_cnt;
+
+endmodule
+
+"
+"/***************************************************************************************************
+** fpga_nes/hw/src/cpu/apu/apu_pulse.v
+*
+* Copyright (c) 2012, Brian Bennett
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
+* and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* APU noise channel.
+***************************************************************************************************/
+
+module apu_pulse
+#(
+ parameter [0:0] CHANNEL = 1\'b0 // Pulse channel 0 or 1
+)
+(
+ input wire clk_in, // system clock signal
+ input wire rst_in, // reset signal
+ input wire en_in, // enable (via $4015)
+ input wire cpu_cycle_pulse_in, // 1 clk pulse on every cpu cycle
+ input wire lc_pulse_in, // 1 clk pulse for every length counter decrement
+ input wire eg_pulse_in, // 1 clk pulse for every env gen update
+ input wire [1:0] a_in, // control register addr (i.e. $400C - $400F)
+ input wire [7:0] d_in, // control register write value
+ input wire wr_in, // enable control register write
+ output wire [3:0] pulse_out, // pulse channel output
+ output wire active_out // pulse channel active (length counter > 0)
+);
+
+//
+// Envelope
+//
+wire envelope_generator_wr;
+wire envelope_generator_restart;
+wire [3:0] envelope_generator_out;
+
+apu_envelope_generator envelope_generator(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .eg_pulse_in(eg_pulse_in),
+ .env_in(d_in[5:0]),
+ .env_wr_in(envelope_generator_wr),
+ .env_restart(envelope_generator_restart),
+ .env_out(envelope_generator_out)
+);
+
+assign envelope_generator_wr = wr_in && (a_in == 2\'b00);
+assign envelope_generator_restart = wr_in && (a_in == 2\'b11);
+
+//
+// Timer
+//
+reg [10:0] q_timer_period, d_timer_period;
+wire timer_pulse;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ q_timer_period <= 11\'h000;
+ else
+ q_timer_period <= d_timer_period;
+ end
+
+apu_div #(.PERIOD_BITS(12)) timer(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .pulse_in(cpu_cycle_pulse_in),
+ .reload_in(1\'b0),
+ .period_in({ q_timer_period, 1\'b0 }),
+ .pulse_out(timer_pulse)
+);
+
+//
+// Sequencer
+//
+wire [3:0] sequencer_out;
+
+reg [1:0] q_duty;
+wire [1:0] d_duty;
+
+reg [2:0] q_sequencer_cnt;
+wire [2:0] d_sequencer_cnt;
+
+wire seq_bit;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_duty <= 2\'h0;
+ q_sequencer_cnt <= 3\'h0;
+ end
+ else
+ begin
+ q_duty <= d_duty;
+ q_sequencer_cnt <= d_sequencer_cnt;
+ end
+ end
+
+assign d_duty = (wr_in && (a_in == 2\'b00)) ? d_in[7:6] : q_duty;
+assign d_sequencer_cnt = (timer_pulse) ? q_sequencer_cnt - 3\'h1 : q_sequencer_cnt;
+
+assign seq_bit = (q_duty == 2\'h0) ? &q_sequencer_cnt[2:0] :
+ (q_duty == 2\'h1) ? &q_sequencer_cnt[2:1] :
+ (q_duty == 2\'h2) ? q_sequencer_cnt[2] : ~&q_sequencer_cnt[2:1];
+
+assign sequencer_out = (seq_bit) ? envelope_generator_out : 4\'h0;
+
+//
+// Sweep
+//
+reg q_sweep_reload;
+wire d_sweep_reload;
+reg [7:0] q_sweep_reg;
+wire [7:0] d_sweep_reg;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_sweep_reg <= 8\'h00;
+ q_sweep_reload <= 1\'b0;
+ end
+ else
+ begin
+ q_sweep_reg <= d_sweep_reg;
+ q_sweep_reload <= d_sweep_reload;
+ end
+ end
+
+assign d_sweep_reg = (wr_in && (a_in == 2\'b01)) ? d_in : q_sweep_reg;
+assign d_sweep_reload = (wr_in && (a_in == 2\'b01)) ? 1\'b1 :
+ (lc_pulse_in) ? 1\'b0 : q_sweep_reload;
+
+wire sweep_divider_reload;
+wire sweep_divider_pulse;
+
+reg sweep_silence;
+reg [11:0] sweep_target_period;
+
+apu_div #(.PERIOD_BITS(3)) sweep_divider(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .pulse_in(lc_pulse_in),
+ .reload_in(sweep_divider_reload),
+ .period_in(q_sweep_reg[6:4]),
+ .pulse_out(sweep_divider_pulse)
+);
+
+assign sweep_divider_reload = lc_pulse_in & q_sweep_reload;
+
+always @*
+ begin
+ sweep_target_period =
+ (!q_sweep_reg[3]) ? q_timer_period + (q_timer_period >> q_sweep_reg[2:0]) :
+ q_timer_period + ~(q_timer_period >> q_sweep_reg[2:0]) + CHANNEL;
+
+ sweep_silence = (q_timer_period[10:3] == 8\'h00) || sweep_target_period[11];
+
+ if (wr_in && (a_in == 2\'b10))
+ d_timer_period = { q_timer_period[10:8], d_in };
+ else if (wr_in && (a_in == 2\'b11))
+ d_timer_period = { d_in[2:0], q_timer_period[7:0] };
+ else if (sweep_divider_pulse && q_sweep_reg[7] && !sweep_silence && (q_sweep_reg[2:0] != 3\'h0))
+ d_timer_period = sweep_target_period[10:0];
+ else
+ d_timer_period = q_timer_period;
+ end
+
+//
+// Length Counter
+//
+reg q_length_counter_halt;
+wire d_length_counter_halt;
+
+always @(posedge clk_in)
+ begin
+ if (rst_in)
+ begin
+ q_length_counter_halt <= 1\'b0;
+ end
+ else
+ begin
+ q_length_counter_halt <= d_length_counter_halt;
+ end
+ end
+
+assign d_length_counter_halt = (wr_in && (a_in == 2\'b00)) ? d_in[5] : q_length_counter_halt;
+
+wire length_counter_wr;
+wire length_counter_en;
+
+apu_length_counter length_counter(
+ .clk_in(clk_in),
+ .rst_in(rst_in),
+ .en_in(en_in),
+ .halt_in(q_length_counter_halt),
+ .length_pulse_in(lc_pulse_in),
+ .length_in(d_in[7:3]),
+ .length_wr_in(length_counter_wr),
+ .en_out(length_counter_en)
+);
+
+assign length_counter_wr = wr_in && (a_in == 2\'b11);
+
+assign pulse_out = (length_counter_en && !sweep_silence) ? sequencer_out : 4\'h0;
+assign active_out = length_counter_en;
+
+endmodule
+
+"
+"/*
+ * In Verilog, the following two lines are both valid syntax:
+ *
+ * `define GUEST
+ * `define GUEST
+ *
+ * The first defines ""GUEST"" as existing, but with no assigned
+ * value. The second defines ""GUEST"" as existing with an
+ * assigned value. Ctags55 correctly handles both cases, but
+ * Ctags551 - Ctags554 only handles the `define with value
+ * correctly. Here is some test code to demonstrate this:
+ */
+`define HOSTA
+`define HOSTB
+`define HOSTC
+`define HOSTD
+
+`define GUESTA 1
+`define GUESTB 2
+`define GUESTC 3
+`define GUESTD 4
+/*
+ * Ctags55 correctly generates a tag for all `defines in the
+ * code, but Ctags554 does not generate tags for ""HOSTB""
+ * or ""HOSTD"".
+ */
+"
+"/*
+Bugs item #762027, was opened at 2003-06-27 18:32
+Message generated for change (Tracker Item Submitted) made by Item Submitter
+You can respond by visiting:
+https://sourceforge.net/tracker/?func=detail&atid=106556&aid=762027&group_id=6556
+
+Category: None
+Group: None
+Status: Open
+Resolution: None
+Priority: 5
+Submitted By: cdic (cdic)
+Assigned to: Nobody/Anonymous (nobody)
+Summary: multi-line definition w/o back-slash will be missing
+
+Initial Comment:
+There is a small bug (language verilog):
+*/
+ wire N_84, N_83; // is ok.
+
+ wire N_84,
+ N_83; // then N_83 will be missing in tags.
+/*
+Thanks for fixing it.
+
+cdic
+*/
+"
+"parameter ramaddr_0 = {1'b1,9'd0};
+"
+"// http://www.eg.bucknell.edu/~cs320/1995-fall/verilog-manual.html#RTFToC33
+
+// Digital model of a traffic light
+// By Dan Hyde August 10, 1995
+module traffic;
+parameter on = 1, off = 0, red_tics = 35,
+ amber_tics = 3, green_tics = 20;
+reg clock, red, amber, green;
+
+// will stop the simulation after 1000 time units
+initial begin: stop_at
+ #1000; $stop;
+end
+
+// initialize the lights and set up monitoring of registers
+initial begin: Init
+ red = off; amber = off; green = off;
+ $display("" Time green amber red"");
+ $monitor(""%3d %b %b %b"", $time, green, amber, red);
+end
+
+// task to wait for \'tics\' positive edge clocks
+// before turning light off
+task light;
+ output color;
+ input [31:0] tics;
+ begin
+ repeat(tics) // wait to detect tics positive edges on clock
+ @(posedge clock);
+ color = off;
+ end
+endtask
+
+// waveform for clock period of 2 time units
+always begin: clock_wave
+ #1 clock = 0;
+ #1 clock = 1;
+end
+
+always begin: main_process
+ red = on;
+ light(red, red_tics); // call task to wait
+ green = on;
+ light(green, green_tics);
+ amber = on;
+ light(amber, amber_tics);
+end
+
+endmodule
+"
+"// File example.v
+//
+// Below is an example of a comment that is mis-parsed by exuberant ctags.
+// It uses the multi-line comment format, i.e. /* ... */ except that in
+// this case, the character sequence immediately preceeding the closing
+// delimiter is an asterisk. (Any even number of asterisks would have the
+// same problem.
+// The line immediately afterwards is used to demonstrate the problem.
+// the module name 'wahoo' isn't recognised, because the parser mistakenly
+// thinks we are still in a multi-line comment.
+/*
+ * I am a multi-line comment
+ * I happen to end in a strange
+ * (but legal) way: **/
+module wahoo ()
+begin
+end
+"
+"/*
+*
+**/
+module top(outsig, insig);
+output outsig;
+input insig;
+assign outsig = insig;
+endmodule
+"
+"/**************************************************************************
+****
+* test task one
+* the line below has 53 asteriks
+*****************************************************/
+task pass_task_1;
+begin
+end
+endtask
+
+/**************************************************************************
+****
+* test task one
+* the line below has 54 asteriks
+******************************************************/
+task fail_task_2;
+begin
+end
+endtask
+
+/**************************************************************************
+****
+* test function one
+* the line below has 53 asteriks
+*****************************************************/
+function pass_func_1;
+begin
+end
+endfunction
+
+/**************************************************************************
+****
+* test function two
+* the line below has 54 asteriks
+******************************************************/
+function fail_func_2;
+begin
+end
+endfunction
+
+/**************************************************************************
+****
+* test function one
+* the line below has 53 asteriks
+*****************************************************/
+`define pass_define_1 1'b1;
+
+/**************************************************************************
+****
+* test function two
+* the line below has 54 asteriks
+******************************************************/
+`define fail_define_2 1'b1;
+"
+"// somewhat contrived, but i came across a real-life file that caused this
+// crash.
+value=
+hello/
+world;
+"
+"// Taken from http://www.europa.com/~celiac/fsm_samp.html
+
+// These are the symbolic names for states
+parameter [1:0] //synopsys enum state_info
+ S0 = 2'h0,
+ S1 = 2'h1,
+ S2 = 2'h2,
+ S3 = 2'h3;
+
+// These are the current state and next state variables
+reg [1:0] /* synopsys enum state_info */ state;
+reg [1:0] /* synopsys enum state_info */ next_state;
+
+
+// synopsys state_vector state
+
+always @ (state or y or x)
+begin
+ next_state = state;
+ case (state) // synopsys full_case parallel_case
+ S0: begin
+ if (x) begin
+ next_state = S1;
+ end
+ else begin
+
+ next_state = S2;
+ end
+ end
+ S1: begin
+ if (y) begin
+ next_state = S2;
+ end
+ else begin
+ next_state = S0;
+ end
+ end
+ S2: begin
+ if (x & y) begin
+ next_state = S3;
+ end
+ else begin
+ next_state = S0;
+ end
+ end
+ S3: begin
+ next_state = S0;
+ end
+ endcase
+end
+
+
+always @ (posedge clk or posedge reset)
+begin
+ if (reset) begin
+ state <= S0;
+ end
+ else begin
+ state <= next_state;
+ end
+end
+"
+"`timescale 1ns / 1ps
+
+module test_spi;
+
+// Inputs
+reg clk;
+reg miso;
+reg[7:0] data_in;
+reg ready_send;
+reg rst;
+
+// Outputs
+wire mosi;
+wire sclk;
+wire ss;
+wire busy;
+wire[7:0] data_out;
+
+// Instantiate the Unit Under Test (UUT)
+spi uut (
+ .clk (clk ),
+ .miso (miso ),
+ .data_in (data_in ),
+ .ready_send (ready_send),
+ .rst (rst ),
+ .mosi (mosi ),
+ .sclk (sclk ),
+ .ss (ss ),
+ .busy (busy ),
+ .data_out (data_out )
+);
+
+
+
+initial begin
+ // Initialize Inputs
+ clk = 0;
+ miso = 0;
+ rst = 1;
+ // Wait for two clocks for the global reset to finish
+ @(posedge clk);
+ @(posedge clk);
+
+ rst = 0;
+ data_in = 8'b00010011; // 13
+ ready_send = 1;
+ @(busy == 1);
+ ready_send = 0;
+ #1;
+ // 37 8'b00110111
+ miso = 0;
+ @(negedge sclk); miso = 0;
+ @(negedge sclk); miso = 1;
+ @(negedge sclk); miso = 1;
+ @(negedge sclk); miso = 0;
+ @(negedge sclk); miso = 1;
+ @(negedge sclk); miso = 1;
+ @(negedge sclk); miso = 1;
+ @(busy == 0);
+
+ @(posedge clk);
+ @(posedge clk);
+ @(posedge clk);
+ $finish;
+
+end
+
+always #5 clk = ! clk;
+
+endmodule
+
+"
+"`timescale 1ns / 1ps
+
+module spi_amba_connector(
+ input clk,
+ input rst,
+
+ input hwrite,
+ input [31:0] hwdata,
+ input [31:0] haddr,
+ input hsel,
+ output [31:0] hrdata,
+
+ input [ 7:0] spi_data_out,
+ input spi_busy,
+ output reg [ 7:0] spi_data_in,
+ output reg spi_ready_send
+);
+
+reg [7:0] spi_data_out_reg;
+reg [7:0] spi_data_in_reg;
+
+assign hrdata = {{25'b0, phase || spi_busy || spi_ready_send, spi_busy ? spi_data_out_reg : spi_data_out}};
+
+localparam IDLE = 0, DATA = 1;
+
+reg phase;
+
+
+always @(posedge clk) begin
+ if (rst) begin
+ spi_data_in <= 0;
+ spi_ready_send <= 0;
+ phase <= 0;
+ end else if (spi_ready_send && spi_busy) begin
+ spi_ready_send <= 0;
+ end else if (!spi_ready_send && !spi_busy) begin
+ if (!phase) begin
+ if (hsel && haddr[15:0] == 'h0000 && hwrite) phase <= 1;
+ end else begin
+ spi_data_out_reg <= spi_data_in;
+ spi_data_in <= spi_data_in_reg;
+ spi_ready_send <= 1;
+ phase <= 0;
+ end
+ end
+end
+
+always @(negedge clk) begin
+ if (phase) spi_data_in_reg <= hwdata[7:0];
+end
+
+endmodule
+"
+"
+`timescale 1ns / 1ps
+
+module spi #(
+ parameter clk_divisor=8 // SCLK shall be this many
+ // times slower than CLK;
+ // can only be an even number.
+)
+(
+ input clk, // Processor clock
+ input rst, // Processor reset
+
+ input [7:0] data_in, // Data to be transferred
+ output reg[7:0] data_out, // Received data
+ input ready_send, // Initialize transfer
+ output busy, // Transaction is in progress
+
+ input miso, // Master in slave out
+ output mosi, // Master out slave in
+ output sclk, // SPI clock
+ output ss // Slave select
+);
+
+reg[ 3:0] sctr;
+reg[ 7:0] data_in_reg;
+
+reg[31:0] ctr;
+
+assign ss = sctr == 0;
+assign sclk = !sctr[0] || ss;
+assign mosi = data_in_reg[sctr >> 1];
+assign busy = !ss;
+
+always @(posedge clk) begin
+ if (rst) begin
+ sctr <= 0;
+ ctr <= 0;
+ data_out <= 0;
+ end else if (ready_send && !sctr) begin
+ data_in_reg <= data_in;
+ sctr <= 15;
+ ctr <= 0;
+ end else if (sctr && ctr + 1 == clk_divisor >> 1) begin
+ ctr <= 0;
+ if (sctr[0])
+ data_out[sctr >> 1] <= miso;
+ sctr <= sctr - 1;
+ end else if (sctr) begin
+ ctr <= ctr + 1;
+ end
+end
+
+endmodule
+"
+"module quantum(
+ input clk,
+ input rst,
+ input hwrite,
+ input [31:0] hwdata,
+ input [31:0] haddr,
+ input hsel,
+ output reg[31:0] hrdata,
+
+ output[127:0] data,
+ input [127:0] ro_data
+);
+
+reg[15:0] dataA[7:0];
+
+assign data = {dataA[7], dataA[6], dataA[5], dataA[4],
+\tdataA[3], dataA[2], dataA[1], dataA[0]};
+
+wire[15:0] rodataA[7:0];
+
+assign {rodataA[7], rodataA[6], rodataA[5], rodataA[4],
+\trodataA[3], rodataA[2], rodataA[1], rodataA[0]} = {
+\tro_data[127:112], ro_data[111:96],
+\tro_data[95 :80], ro_data[79:64],
+\tro_data[63 :48], ro_data[47:32],
+\tro_data[31 :16], ro_data[15:0]
+};
+
+reg ctr;
+reg write;
+
+wire[2:0] raddr = haddr[4:2];
+
+always @(*) begin
+\tif (haddr[15:0] >= 'h20 && haddr[15:0] < 'h40) begin
+\t\thrdata = rodataA[raddr];
+\tend else if (haddr[15:0] < 'h20) begin
+\t\thrdata = dataA[raddr];
+\tend else begin
+ hrdata = 0;
+ end
+end
+
+always @(posedge clk) begin
+\tif (rst) begin
+\t\tctr <= 0;
+\t\twrite <= 0;
+\tend else if (ctr) begin
+\t\tctr <= 0;
+\t\tif (write && haddr[15:0] < 'h20)
+\t\t\tdataA[raddr] <= hwdata;
+\tend else begin
+\t\tctr <= hsel;
+\t\twrite <= hwrite;
+\tend
+end
+
+endmodule
+
+"
+"`timescale 1ns / 1ps
+
+module test_amba;
+
+// Inputs
+reg clk;
+reg miso;
+//reg[7:0] data_in;
+//reg ready_send;
+reg rst;
+reg \t\t hwrite;
+reg[31:0] hwdata;
+reg[31:0] haddr;
+reg \t hsel;
+
+// Outputs
+wire mosi;
+wire sclk;
+wire ss;
+//wire busy;
+//wire[7:0] data_out;
+wire[31:0] hrdata;
+
+// amba_connector - - spi
+wire [7:0] spi_data_out;
+wire spi_busy;
+wire [7:0] spi_data_in;
+wire spi_ready_send;
+
+// Instantiate the Unit Under Test (UUT)
+spi uut (
+ .clk (clk ),
+ .miso (miso ),
+ .data_in (spi_data_in ),
+ .ready_send (spi_ready_send),
+ .rst (rst ),
+ .mosi (mosi ),
+ .sclk (sclk ),
+ .ss (ss ),
+ .busy (spi_busy ),
+ .data_out (spi_data_out )
+);
+
+spi_amba_connector amba_uut (
+ .clk (clk ),
+ .rst (rst ),
+ .hwrite (hwrite ),
+ .hwdata (hwdata ),
+ .haddr (haddr ),
+ .hsel (hsel ),
+\t .hrdata (hrdata ),
+ .spi_data_out (spi_data_out ),
+ .spi_busy (spi_busy ),
+ .spi_data_in (spi_data_in ),
+ .spi_ready_send (spi_ready_send)
+);
+
+
+
+initial begin
+ // Initialize Inputs
+ clk = 0;
+ miso = 0;
+ rst = 1;
+ // Wait for two clocks for the global reset to finish
+ @(posedge clk);
+ @(posedge clk);
+ rst = 0;
+\t
+\t // AHB-Lite Write
+\t
+\t // Address phase
+\t hwrite = 1;
+\t haddr = 'h00000000;
+\t hsel = 1;
+\t
+\t // Data phase
+\t @(posedge clk);
+\t hwdata = 'h00000013;
+\t hwrite = 0;
+\t
+\t // SPI reads at the same time
+\t @(spi_busy == 1);
+\t miso = 0;
+ @(negedge sclk); miso = 0;
+ @(negedge sclk); miso = 1;
+ @(negedge sclk); miso = 1;
+ @(negedge sclk); miso = 0;
+ @(negedge sclk); miso = 1;
+ @(negedge sclk); miso = 1;
+ @(negedge sclk); miso = 1;
+
+\t @(spi_busy == 0);
+\t hsel=0;
+\t
+\t // AHB-Lite Read
+\t
+\t // Address phase
+\t @(posedge clk);
+\t haddr = 'h00000004;
+\t hsel = 1;
+\t hwrite = 0;
+\t
+\t // Data phase
+\t @(posedge clk);
+\t @(posedge clk);
+\t @(posedge clk);
+\t /*#50;
+\t hsel = 0;
+ @(spi_busy == 0);
+\t miso = 0;
+\t hwrite = 1;
+\t hwdata = 'h00000014;
+\t haddr = 'h00000000;
+\t hsel = 1;
+\t @(spi_busy == 1);
+\t miso = 1;
+ @(negedge sclk); miso = 0;
+ @(negedge sclk); miso = 0;
+ @(negedge sclk); miso = 0;
+ @(negedge sclk); miso = 1;
+ @(negedge sclk); miso = 0;
+ @(negedge sclk); miso = 0;
+ @(negedge sclk); miso = 0;
+\t #50;
+\t hwrite = 0;
+\t hsel=0;
+\t @(spi_busy == 0);
+\t #10;
+\t haddr = 'h00000004;
+\t hsel = 1;
+\t #50;
+\t hsel = 0;
+
+ @(posedge clk);
+ @(posedge clk);*/
+ @(posedge clk);
+ $finish;
+
+end
+
+always #5 clk = ! clk;
+
+endmodule
+
+"
+"module v7_emac_controller
+ (
+ // asynchronous reset
+ input glbl_rst,
+
+ // 200MHz clock input from board
+ input clkin200,
+
+ output phy_resetn,
+
+ //added SGMII serial data and reference clock ports
+ input gtrefclk_p, // Differential +ve of reference clock for MGT: 125MHz, very high quality.
+ input gtrefclk_n, // Differential -ve of reference clock for MGT: 125MHz, very high quality.
+ output txp, // Differential +ve of serial transmission from PMA to PMD.
+ output txn, // Differential -ve of serial transmission from PMA to PMD.
+ input rxp, // Differential +ve for serial reception from PMD to PMA.
+ input rxn, // Differential -ve for serial reception from PMD to PMA.
+
+ output synchronization_done,
+ output linkup,
+
+
+ // MDIO Interface
+ //---------------
+ input mdio_i,
+\t\toutput mdio_o,
+\t\toutput mdio_t,
+ output mdc,
+
+\t\t
+ // Receiver (AXI-S) Interface
+ //----------------------------------------
+ output rx_fifo_clk,
+ output rx_fifo_rstn,
+ output [7:0] rx_axis_fifo_tdata,
+ output rx_axis_fifo_tvalid,
+ input rx_axis_fifo_tready,
+ output rx_axis_fifo_tlast,
+
+
+ // Transmitter (AXI-S) Interface
+ //-------------------------------------------
+ output tx_fifo_clk,
+ output tx_fifo_rstn,
+ input [7:0] tx_axis_fifo_tdata,
+ input tx_axis_fifo_tvalid,
+ output tx_axis_fifo_tready,
+ input tx_axis_fifo_tlast,
+ input loop_back_en,
+ output o_tx_mac_count
+\t\t
+ );
+
+endmodule"
+"module mapper(
+input i_clk,
+input i_rst,
+input i_data_valid,
+output o_data_rdy,
+input [63:0] i_data,
+output [31:0] o_count
+);
+
+assign o_count = word_count;
+
+
+wire char_valid;
+wire [7:0] char;
+reg [127:0] in_word;
+wire [127:0] word;
+reg [31:0] word_count;
+\t
+
+assign word = 128'h68656c6c6F0000000000000000000000;
+
+
+always @(posedge i_clk)
+begin
+ if(i_rst)
+\t begin
+\t in_word <= 128'd0;
+\t\t word_count <= 0;
+\t end
+ else if(char_valid & (char >= 97 & char <= 122))
+\t in_word <= {char,in_word[127:8]};
+\t else if(char_valid)
+\t begin
+\t in_word <= 128'd0;
+\t\t if(word == in_word)
+\t\t word_count <= word_count + 1;
+\t end\t
+end
+
+fifo_128_8 mapper_fifo (
+ .i_clk(i_clk),
+ .i_rst_n(!i_rst),
+ .i_slv_valid(i_data_valid),
+ .o_slv_rdy(o_data_rdy),
+ .i_slv_data(i_data),
+ .o_mst_data(char),
+ .o_mst_valid(char_valid),
+ .i_mst_rdy(1'b1)
+);
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2008 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : %version
+// \\ \\ Application : MIG
+// / / Filename : round_robin_arb.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : 7-Series
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+// A simple round robin arbiter implemented in a not so simple
+// way. Two things make this special. First, it takes width as
+// a parameter and secondly it\'s constructed in a way to work with
+// restrictions synthesis programs.
+//
+// Consider each req/grant pair to be a
+// ""channel"". The arbiter computes a grant response to a request
+// on a channel by channel basis.
+//
+// The arbiter implementes a ""round robin"" algorithm. Ie, the granting
+// process is totally fair and symmetric. Each requester is given
+// equal priority. If all requests are asserted, the arbiter will
+// work sequentially around the list of requesters, giving each a grant.
+//
+// Grant priority is based on the ""last_master"". The last_master
+// vector stores the channel receiving the most recent grant. The
+// next higher numbered channel (wrapping around to zero) has highest
+// priority in subsequent cycles. Relative priority wraps around
+// the request vector with the last_master channel having lowest priority.
+//
+// At the highest implementation level, a per channel inhibit signal is computed.
+// This inhibit is bit-wise AND\'ed with the incoming requests to
+// generate the grant.
+//
+// There will be at most a single grant per state. The logic
+// of the arbiter depends on this.
+//
+// Once a grant is given, it is stored as the last_master. The
+// last_master vector is initialized at reset to the zero\'th channel.
+// Although the particular channel doesn\'t matter, it does matter
+// that the last_master contains a valid grant pattern.
+//
+// The heavy lifting is in computing the per channel inhibit signals.
+// This is accomplished in the generate statement.
+//
+// The first ""for"" loop in the generate statement steps through the channels.
+//
+// The second ""for"" loop steps through the last mast_master vector
+// for each channel. For each last_master bit, an inh_group is generated.
+// Following the end of the second ""for"" loop, the inh_group signals are OR\'ed
+// together to generate the overall inhibit bit for the channel.
+//
+// For a four bit wide arbiter, this is what\'s generated for channel zero:
+//
+// inh_group[1] = last_master[0] && |req[3:1]; // any other req inhibits
+// inh_group[2] = last_master[1] && |req[3:2]; // req[3], or req[2] inhibit
+// inh_group[3] = last_master[2] && |req[3:3]; // only req[3] inhibits
+//
+// For req[0], last_master[3] is ignored because channel zero is highest priority
+// if last_master[3] is true.
+//
+
+
+`timescale 1ps/1ps
+
+module mig_7series_v1_8_round_robin_arb
+ #(
+ parameter TCQ = 100,
+ parameter WIDTH = 3
+ )
+ (
+ /*AUTOARG*/
+ // Outputs
+ grant_ns, grant_r,
+ // Inputs
+ clk, rst, req, disable_grant, current_master, upd_last_master
+ );
+
+ input clk;
+ input rst;
+
+ input [WIDTH-1:0] req;
+
+ wire [WIDTH-1:0] last_master_ns;
+
+ reg [WIDTH*2-1:0] dbl_last_master_ns;
+ always @(/*AS*/last_master_ns)
+ dbl_last_master_ns = {last_master_ns, last_master_ns};
+ reg [WIDTH*2-1:0] dbl_req;
+ always @(/*AS*/req) dbl_req = {req, req};
+
+ reg [WIDTH-1:0] inhibit = {WIDTH{1\'b0}};
+
+ genvar i;
+ genvar j;
+ generate
+ for (i = 0; i < WIDTH; i = i + 1) begin : channel
+ wire [WIDTH-1:1] inh_group;
+ for (j = 0; j < (WIDTH-1); j = j + 1) begin : last_master
+ assign inh_group[j+1] =
+ dbl_last_master_ns[i+j] && |dbl_req[i+WIDTH-1:i+j+1];
+ end
+ always @(/*AS*/inh_group) inhibit[i] = |inh_group;
+ end
+ endgenerate
+
+ input disable_grant;
+ output wire [WIDTH-1:0] grant_ns;
+ assign grant_ns = req & ~inhibit & {WIDTH{~disable_grant}};
+
+ output reg [WIDTH-1:0] grant_r;
+ always @(posedge clk) grant_r <= #TCQ grant_ns;
+
+ input [WIDTH-1:0] current_master;
+ input upd_last_master;
+ reg [WIDTH-1:0] last_master_r;
+ localparam ONE = 1 << (WIDTH - 1); //Changed form \'1\' to fix the CR #544024
+ //A \'1\' in the LSB of the last_master_r
+ //signal gives a low priority to req[0]
+ //after reset. To avoid this made MSB as
+ //\'1\' at reset.
+ assign last_master_ns = rst
+ ? ONE[0+:WIDTH]
+ : upd_last_master
+ ? current_master
+ : last_master_r;
+ always @(posedge clk) last_master_r <= #TCQ last_master_ns;
+
+`ifdef MC_SVA
+ grant_is_one_hot_zero:
+ assert property (@(posedge clk) (rst || $onehot0(grant_ns)));
+ last_master_r_is_one_hot:
+ assert property (@(posedge clk) (rst || $onehot(last_master_r)));
+`endif
+
+endmodule
+"
+"//--------------------------------------------------------------------------------
+// Project : SWITCH
+// File : ethernet_top.v
+// Version : 0.2
+// Author : Shreejith S, Vipin K
+//
+// Description: Ethernet Controller Top File
+//
+//--------------------------------------------------------------------------------
+
+
+
+module v7_ethernet_top
+(
+ // asynchronous reset
+ input glbl_rst,
+
+ // 200MHz clock input from board
+ input i_clk_200,
+
+ output phy_resetn,
+
+ //added SGMII serial data and reference clock ports
+ input gtrefclk_p, // Differential +ve of reference clock for MGT: 125MHz, very high quality.
+ input gtrefclk_n, // Differential -ve of reference clock for MGT: 125MHz, very high quality.
+ output txp, // Differential +ve of serial transmission from PMA to PMD.
+ output txn, // Differential -ve of serial transmission from PMA to PMD.
+ input rxp, // Differential +ve for serial reception from PMD to PMA.
+ input rxn, // Differential -ve for serial reception from PMD to PMA.
+
+ output synchronization_done,
+ output linkup,
+
+ // MDIO Interface
+ //---------------
+ input mdio_i,
+\t output mdio_o,
+\t output mdio_t,
+ output mdc,
+
+//Reg file
+ input i_enet_enable, // Enable the ethernet core
+ input i_enet_loopback, // Enable loopback mode
+ input [31:0] i_enet_ddr_source_addr, // Where is data for ethernet
+ input [31:0] i_enet_ddr_dest_addr, // Where to store ethernet data
+ input [31:0] i_enet_rcv_data_size, // How much data should be received from enet
+ input [31:0] i_enet_snd_data_size, // How much data should be sent through enet
+ output [31:0] o_enet_rx_cnt, // Ethernet RX Performance Counter
+ output [31:0] o_enet_tx_cnt, // Ethernet TX Performance Counter
+ output o_enet_rx_done, // Ethernet RX Completed
+ output o_enet_tx_done, // Ethernet TX Completed
+
+//To DDR controller
+ output o_ddr_wr_req,
+ output o_ddr_rd_req,
+ output [255:0] o_ddr_wr_data,
+ output [31:0] o_ddr_wr_be,
+ output [31:0] o_ddr_wr_addr,
+ output [31:0] o_ddr_rd_addr,
+ input [255:0] i_ddr_rd_data,
+ input i_ddr_wr_ack,
+ input i_ddr_rd_ack,
+ input i_ddr_rd_data_valid
+);
+
+
+
+wire [63:0] enet_wr_data;
+wire [63:0] enet_rd_data;
+
+v7_ethernet_controller_top ect
+(
+ .glbl_rst(glbl_rst),
+ .clkin200(i_clk_200),
+
+ .phy_resetn(phy_resetn),
+
+ .gtrefclk_p(gtrefclk_p),
+ .gtrefclk_n(gtrefclk_n),
+ .txp(txp),
+ .txn(txn),
+ .rxp(rxp),
+ .rxn(rxn),
+
+ .synchronization_done(synchronization_done),
+ .linkup(linkup),
+
+
+ .mdio_i(mdio_i),
+ .mdio_t(mdio_t),
+ .mdio_o(mdio_o),
+ .mdc(mdc),
+
+ .enet_loopback(i_enet_loopback),
+ .enet_wr_clk(i_clk_200),
+ .enet_wr_data_valid(enet_wr_data_valid),
+ .enet_wr_data(enet_wr_data),
+ .enet_wr_rdy(enet_wr_rdy),
+ .enet_rd_clk(i_clk_200),
+ .enet_rd_rdy(enet_rd_rdy),
+ .enet_rd_data(enet_rd_data),
+ .enet_rd_data_valid(enet_rd_data_valid),
+ .if_enable(enet_enable),
+\t .o_tx_mac_count(tx_mac_count)
+ );
+\t
+\t
+\t
+\t enet_ddr_ctrl edc (
+ .i_clk(i_clk_200),
+ .i_rst(glbl_rst),
+ .i_enet_enable(i_enet_enable),
+ .i_enet_ddr_source_addr(i_enet_ddr_source_addr),
+ .i_enet_ddr_dest_addr(i_enet_ddr_dest_addr),
+ .i_enet_rcv_data_size(i_enet_rcv_data_size),
+ .i_enet_snd_data_size(i_enet_snd_data_size),
+ .o_enet_enable(enet_enable),
+ .i_enet_data_avail(enet_rd_data_valid),
+ .o_enet_rx_cnt(o_enet_rx_cnt),
+ .o_enet_tx_cnt(o_enet_tx_cnt),
+ .o_enet_rx_done(o_enet_rx_done),
+ .o_enet_tx_done(o_enet_tx_done),
+ .o_core_ready(enet_rd_rdy),
+ .i_data(enet_rd_data),
+ .o_data(enet_wr_data),
+ .o_core_data_avail(enet_wr_data_valid),
+ .i_enet_ready(enet_wr_rdy),
+ .o_ddr_wr_req(o_ddr_wr_req),
+ .o_ddr_rd_req(o_ddr_rd_req),
+ .o_ddr_wr_data(o_ddr_wr_data),
+ .o_ddr_wr_be(o_ddr_wr_be),
+ .o_ddr_wr_addr(o_ddr_wr_addr),
+ .o_ddr_rd_addr(o_ddr_rd_addr),
+ .i_ddr_rd_data(i_ddr_rd_data),
+ .i_ddr_wr_ack(i_ddr_wr_ack),
+ .i_ddr_rd_ack(i_ddr_rd_ack),
+ .i_ddr_rd_data_valid(i_ddr_rd_data_valid),
+\t .i_tx_mac_count(tx_mac_count)
+ );
+
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2008 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : %version
+// \\ \\ Application : MIG
+// / / Filename : ecc_merge_enc.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : 7-Series
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+`timescale 1ps/1ps
+
+module mig_7series_v1_8_ecc_merge_enc
+ #(
+ parameter TCQ = 100,
+ parameter PAYLOAD_WIDTH = 64,
+ parameter CODE_WIDTH = 72,
+ parameter DATA_BUF_ADDR_WIDTH = 4,
+ parameter DATA_BUF_OFFSET_WIDTH = 1,
+ parameter DATA_WIDTH = 64,
+ parameter DQ_WIDTH = 72,
+ parameter ECC_WIDTH = 8,
+ parameter nCK_PER_CLK = 4
+ )
+ (
+ /*AUTOARG*/
+ // Outputs
+ mc_wrdata, mc_wrdata_mask,
+ // Inputs
+ clk, rst, wr_data, wr_data_mask, rd_merge_data, h_rows, raw_not_ecc
+ );
+
+ input clk;
+ input rst;
+
+ input [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] wr_data;
+ input [2*nCK_PER_CLK*DATA_WIDTH/8-1:0] wr_data_mask;
+ input [2*nCK_PER_CLK*DATA_WIDTH-1:0] rd_merge_data;
+
+ reg [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] wr_data_r;
+ reg [2*nCK_PER_CLK*DATA_WIDTH/8-1:0] wr_data_mask_r;
+ reg [2*nCK_PER_CLK*DATA_WIDTH-1:0] rd_merge_data_r;
+
+ always @(posedge clk) wr_data_r <= #TCQ wr_data;
+ always @(posedge clk) wr_data_mask_r <= #TCQ wr_data_mask;
+ always @(posedge clk) rd_merge_data_r <= #TCQ rd_merge_data;
+
+ // Merge new data with memory read data.
+ wire [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] merged_data;
+ genvar h;
+ genvar i;
+ generate
+ for (h=0; h<2*nCK_PER_CLK; h=h+1) begin : merge_data_outer
+ for (i=0; i DATA_WIDTH)
+ assign merged_data[(h+1)*PAYLOAD_WIDTH-1-:PAYLOAD_WIDTH-DATA_WIDTH]=
+ wr_data[(h+1)*PAYLOAD_WIDTH-1-:PAYLOAD_WIDTH-DATA_WIDTH];
+
+ end
+ endgenerate
+
+ // Generate ECC and overlay onto mc_wrdata.
+ input [CODE_WIDTH*ECC_WIDTH-1:0] h_rows;
+ input [2*nCK_PER_CLK-1:0] raw_not_ecc;
+ reg [2*nCK_PER_CLK-1:0] raw_not_ecc_r;
+ always @(posedge clk) raw_not_ecc_r <= #TCQ raw_not_ecc;
+ output reg [2*nCK_PER_CLK*DQ_WIDTH-1:0] mc_wrdata;
+ reg [2*nCK_PER_CLK*DQ_WIDTH-1:0] mc_wrdata_c;
+ genvar j;
+ integer k;
+ generate
+ for (j=0; j<2*nCK_PER_CLK; j=j+1) begin : ecc_word
+ always @(/*AS*/h_rows or merged_data or raw_not_ecc_r) begin
+ mc_wrdata_c[j*DQ_WIDTH+:DQ_WIDTH] =
+ {{DQ_WIDTH-PAYLOAD_WIDTH{1\'b0}},
+ merged_data[j*PAYLOAD_WIDTH+:PAYLOAD_WIDTH]};
+ for (k=0; k1; clogb2=clogb2+1)
+ size = size >> 1;
+ end
+ endfunction // clogb2
+
+ input clk;
+ input rst;
+
+// Activate wait state machine.
+ input bm_end;
+ reg bm_end_r1;
+ always @(posedge clk) bm_end_r1 <= #TCQ bm_end;
+
+ reg col_wait_r;
+
+ input pass_open_bank_r;
+ input sending_row;
+ reg act_wait_r_lcl;
+ input rcv_open_bank;
+ wire start_rcd_lcl = act_wait_r_lcl && sending_row;
+ output wire start_rcd;
+ assign start_rcd = start_rcd_lcl;
+ wire act_wait_ns = rst ||
+ ((act_wait_r_lcl && ~start_rcd_lcl && ~rcv_open_bank) ||
+ bm_end_r1 || (pass_open_bank_r && bm_end));
+ always @(posedge clk) act_wait_r_lcl <= #TCQ act_wait_ns;
+ output wire act_wait_r;
+ assign act_wait_r = act_wait_r_lcl;
+
+// RCD timer
+//
+// When CWL is even, CAS commands are issued on slot 0 and RAS commands are
+// issued on slot 1. This implies that the RCD can never expire in the same
+// cycle as the RAS (otherwise the CAS for a given transaction would precede
+// the RAS). Similarly, this can also cause premature expiration for longer
+// RCD. An offset must be added to RCD before translating it to the FPGA clock
+// domain. In this mode, CAS are on the first DRAM clock cycle corresponding to
+// a given FPGA cycle. In 2:1 mode add 2 to generate this offset aligned to
+// the FPGA cycle. Likewise, add 4 to generate an aligned offset in 4:1 mode.
+//
+// When CWL is odd, RAS commands are issued on slot 0 and CAS commands are
+// issued on slot 1. There is a natural 1 cycle seperation between RAS and CAS
+// in the DRAM clock domain so the RCD can expire in the same FPGA cycle as the
+// RAS command. In 2:1 mode, there are only 2 slots so direct translation
+// correctly places the CAS with respect to the corresponding RAS. In 4:1 mode,
+// there are two slots after CAS, so 2 is added to shift the timer into the
+// next FPGA cycle for cases that can\'t expire in the current cycle.
+//
+// In 2T mode, the offset from ROW to COL commands is fixed at 2. In 2:1 mode,
+// It is sufficient to translate to the half-rate domain and add the remainder.
+// In 4:1 mode, we must translate to the quarter-rate domain and add an
+// additional fabric cycle only if the remainder exceeds the fixed offset of 2
+
+ localparam nRCD_CLKS =
+ nCK_PER_CLK == 1 ?
+ nRCD :
+ nCK_PER_CLK == 2 ?
+ ADDR_CMD_MODE == ""2T"" ?
+ (nRCD/2) + (nRCD%2) :
+ CWL % 2 ?
+ (nRCD/2) :
+ (nRCD+2) / 2 :
+// (nCK_PER_CLK == 4)
+ ADDR_CMD_MODE == ""2T"" ?
+ (nRCD/4) + (nRCD%4 > 2 ? 1 : 0) :
+ CWL % 2 ?
+ (nRCD-2 ? (nRCD-2) / 4 + 1 : 1) :
+ nRCD/4 + 1;
+
+ localparam nRCD_CLKS_M2 = (nRCD_CLKS-2 <0) ? 0 : nRCD_CLKS-2;
+ localparam RCD_TIMER_WIDTH = clogb2(nRCD_CLKS_M2+1);
+ localparam ZERO = 0;
+ localparam ONE = 1;
+ reg [RCD_TIMER_WIDTH-1:0] rcd_timer_r = {RCD_TIMER_WIDTH{1\'b0}};
+ reg end_rcd;
+ reg rcd_active_r = 1\'b0;
+
+ generate
+ if (nRCD_CLKS <= 2) begin : rcd_timer_leq_2
+ always @(/*AS*/start_rcd_lcl) end_rcd = start_rcd_lcl;
+ end
+ else if (nRCD_CLKS > 2) begin : rcd_timer_gt_2
+ reg [RCD_TIMER_WIDTH-1:0] rcd_timer_ns;
+ always @(/*AS*/rcd_timer_r or rst or start_rcd_lcl) begin
+ if (rst) rcd_timer_ns = ZERO[RCD_TIMER_WIDTH-1:0];
+ else begin
+ rcd_timer_ns = rcd_timer_r;
+ if (start_rcd_lcl) rcd_timer_ns = nRCD_CLKS_M2[RCD_TIMER_WIDTH-1:0];
+ else if (|rcd_timer_r) rcd_timer_ns =
+ rcd_timer_r - ONE[RCD_TIMER_WIDTH-1:0];
+ end
+ end
+ always @(posedge clk) rcd_timer_r <= #TCQ rcd_timer_ns;
+ wire end_rcd_ns = (rcd_timer_ns == ONE[RCD_TIMER_WIDTH-1:0]);
+ always @(posedge clk) end_rcd = end_rcd_ns;
+ wire rcd_active_ns = |rcd_timer_ns;
+ always @(posedge clk) rcd_active_r <= #TCQ rcd_active_ns;
+ end
+ endgenerate
+
+// Figure out if the read that\'s completing is for an RMW for
+// this bank machine. Delay by a state if CWL != 8 since the
+// data is not ready in the RMW buffer for the early write
+// data fetch that happens with ECC and CWL != 8.
+// Create a state bit indicating we\'re waiting for the read
+// half of the rmw to complete.
+ input sending_col;
+ input rd_wr_r;
+ input req_wr_r;
+ input [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr;
+ input [DATA_BUF_ADDR_WIDTH-1:0] req_data_buf_addr_r;
+ input phy_rddata_valid;
+ input rd_rmw;
+ reg rmw_rd_done = 1\'b0;
+ reg rd_half_rmw_lcl = 1\'b0;
+ output wire rd_half_rmw;
+ assign rd_half_rmw = rd_half_rmw_lcl;
+ reg rmw_wait_r = 1\'b0;
+ generate
+ if (ECC != ""OFF"") begin : rmw_on
+// Delay phy_rddata_valid and rd_rmw by one cycle to align them
+// to req_data_buf_addr_r so that rmw_wait_r clears properly
+ reg phy_rddata_valid_r;
+ reg rd_rmw_r;
+ always @(posedge clk) begin
+ phy_rddata_valid_r <= #TCQ phy_rddata_valid;
+ rd_rmw_r <= #TCQ rd_rmw;
+ end
+ wire my_rmw_rd_ns = phy_rddata_valid_r && rd_rmw_r &&
+ (rd_data_addr == req_data_buf_addr_r);
+ if (CWL == 8) always @(my_rmw_rd_ns) rmw_rd_done = my_rmw_rd_ns;
+ else always @(posedge clk) rmw_rd_done = #TCQ my_rmw_rd_ns;
+ always @(/*AS*/rd_wr_r or req_wr_r) rd_half_rmw_lcl = req_wr_r && rd_wr_r;
+ wire rmw_wait_ns = ~rst &&
+ ((rmw_wait_r && ~rmw_rd_done) || (rd_half_rmw_lcl && sending_col));
+ always @(posedge clk) rmw_wait_r <= #TCQ rmw_wait_ns;
+ end
+ endgenerate
+
+// column wait state machine.
+ wire col_wait_ns = ~rst && ((col_wait_r && ~sending_col) || end_rcd
+ || rcv_open_bank || (rmw_rd_done && rmw_wait_r));
+ always @(posedge clk) col_wait_r <= #TCQ col_wait_ns;
+
+// Set up various RAS timer parameters, wires, etc.
+
+ localparam TWO = 2;
+ output reg [RAS_TIMER_WIDTH-1:0] ras_timer_ns;
+ reg [RAS_TIMER_WIDTH-1:0] ras_timer_r;
+ input [(2*(RAS_TIMER_WIDTH*nBANK_MACHS))-1:0] ras_timer_ns_in;
+ input [(nBANK_MACHS*2)-1:0] rb_hit_busies_r;
+
+// On a bank pass, select the RAS timer from the passing bank machine.
+ reg [RAS_TIMER_WIDTH-1:0] passed_ras_timer;
+ integer i;
+ always @(/*AS*/ras_timer_ns_in or rb_hit_busies_r) begin
+ passed_ras_timer = {RAS_TIMER_WIDTH{1\'b0}};
+ for (i=ID+1; i<(ID+nBANK_MACHS); i=i+1)
+ if (rb_hit_busies_r[i])
+ passed_ras_timer = ras_timer_ns_in[i*RAS_TIMER_WIDTH+:RAS_TIMER_WIDTH];
+ end
+
+// RAS and (reused for) WTP timer. When an open bank is passed, this
+// timer is passed to the new owner. The existing RAS prevents
+// an activate from occuring too early.
+
+
+ wire start_wtp_timer = sending_col && ~rd_wr_r;
+ input idle_r;
+
+ always @(/*AS*/bm_end_r1 or ras_timer_r or rst or start_rcd_lcl
+ or start_wtp_timer) begin
+ if (bm_end_r1 || rst) ras_timer_ns = ZERO[RAS_TIMER_WIDTH-1:0];
+ else begin
+ ras_timer_ns = ras_timer_r;
+ if (start_rcd_lcl) ras_timer_ns =
+ nRAS_CLKS[RAS_TIMER_WIDTH-1:0] - TWO[RAS_TIMER_WIDTH-1:0];
+ if (start_wtp_timer) ras_timer_ns =
+ // As the timer is being reused, it is essential to compare
+ // before new value is loaded.
+ (ras_timer_r <= (nWTP_CLKS-2)) ? nWTP_CLKS[RAS_TIMER_WIDTH-1:0] - TWO[RAS_TIMER_WIDTH-1:0]
+ : ras_timer_r - ONE[RAS_TIMER_WIDTH-1:0];
+ if (|ras_timer_r && ~start_wtp_timer) ras_timer_ns =
+ ras_timer_r - ONE[RAS_TIMER_WIDTH-1:0];
+ end
+ end // always @ (...
+
+ wire [RAS_TIMER_WIDTH-1:0] ras_timer_passed_ns = rcv_open_bank
+ ? passed_ras_timer
+ : ras_timer_ns;
+ always @(posedge clk) ras_timer_r <= #TCQ ras_timer_passed_ns;
+
+ wire ras_timer_zero_ns = (ras_timer_ns == ZERO[RAS_TIMER_WIDTH-1:0]);
+ reg ras_timer_zero_r;
+ always @(posedge clk) ras_timer_zero_r <= #TCQ ras_timer_zero_ns;
+
+// RTP timer. Unless 2T mode, add one for 2:1 mode. This accounts for loss of
+// one DRAM CK due to column command to row command fixed offset. In 2T mode,
+// Add the remainder. In 4:1 mode, the fixed offset is -2. Add 2 unless in 2T
+// mode, in which case we add 1 if the remainder exceeds the fixed offset.
+ localparam nRTP_CLKS = (nCK_PER_CLK == 1)
+ ? nRTP :
+ (nCK_PER_CLK == 2)
+ ? (nRTP/2) + ((ADDR_CMD_MODE == ""2T"") ? nRTP%2 : 1) :
+ (nRTP/4) + ((ADDR_CMD_MODE == ""2T"") ? (nRTP%4 > 2 ? 2 : 1) : 2);
+ localparam nRTP_CLKS_M1 = ((nRTP_CLKS-1) <= 0) ? 0 : nRTP_CLKS-1;
+ localparam RTP_TIMER_WIDTH = clogb2(nRTP_CLKS_M1 + 1);
+ reg [RTP_TIMER_WIDTH-1:0] rtp_timer_ns;
+ reg [RTP_TIMER_WIDTH-1:0] rtp_timer_r;
+ wire sending_col_not_rmw_rd = sending_col && ~rd_half_rmw_lcl;
+ always @(/*AS*/pass_open_bank_r or rst or rtp_timer_r
+ or sending_col_not_rmw_rd) begin
+ rtp_timer_ns = rtp_timer_r;
+ if (rst || pass_open_bank_r)
+ rtp_timer_ns = ZERO[RTP_TIMER_WIDTH-1:0];
+ else begin
+ if (sending_col_not_rmw_rd)
+ rtp_timer_ns = nRTP_CLKS_M1[RTP_TIMER_WIDTH-1:0];
+ if (|rtp_timer_r) rtp_timer_ns = rtp_timer_r - ONE[RTP_TIMER_WIDTH-1:0];
+ end
+ end
+ always @(posedge clk) rtp_timer_r <= #TCQ rtp_timer_ns;
+
+ wire end_rtp_lcl = ~pass_open_bank_r &&
+ ((rtp_timer_r == ONE[RTP_TIMER_WIDTH-1:0]) ||
+ ((nRTP_CLKS_M1 == 0) && sending_col_not_rmw_rd));
+ output wire end_rtp;
+ assign end_rtp = end_rtp_lcl;
+
+// Optionally implement open page mode timer.
+ localparam OP_WIDTH = clogb2(nOP_WAIT + 1);
+ output wire bank_wait_in_progress;
+ output wire start_pre_wait;
+ input passing_open_bank;
+ input low_idle_cnt_r;
+ output wire op_exit_req;
+ input op_exit_grant;
+ input tail_r;
+ output reg pre_wait_r;
+
+ generate
+ if (nOP_WAIT == 0) begin : op_mode_disabled
+ assign bank_wait_in_progress = sending_col_not_rmw_rd || |rtp_timer_r ||
+ (pre_wait_r && ~ras_timer_zero_r);
+ assign start_pre_wait = end_rtp_lcl;
+ assign op_exit_req = 1\'b0;
+ end
+ else begin : op_mode_enabled
+ reg op_wait_r;
+ assign bank_wait_in_progress = sending_col || |rtp_timer_r ||
+ (pre_wait_r && ~ras_timer_zero_r) ||
+ op_wait_r;
+ wire op_active = ~rst && ~passing_open_bank && ((end_rtp_lcl && tail_r)
+ || op_wait_r);
+ wire op_wait_ns = ~op_exit_grant && op_active;
+ always @(posedge clk) op_wait_r <= #TCQ op_wait_ns;
+ assign start_pre_wait = op_exit_grant ||
+ (end_rtp_lcl && ~tail_r && ~passing_open_bank);
+ if (nOP_WAIT == -1)
+ assign op_exit_req = (low_idle_cnt_r && op_active);
+ else begin : op_cnt
+ reg [OP_WIDTH-1:0] op_cnt_r;
+ wire [OP_WIDTH-1:0] op_cnt_ns =
+ (passing_open_bank || op_exit_grant || rst)
+ ? ZERO[OP_WIDTH-1:0]
+ : end_rtp_lcl
+ ? nOP_WAIT[OP_WIDTH-1:0]
+ : |op_cnt_r
+ ? op_cnt_r - ONE[OP_WIDTH-1:0]
+ : op_cnt_r;
+ always @(posedge clk) op_cnt_r <= #TCQ op_cnt_ns;
+ assign op_exit_req = (low_idle_cnt_r && op_active) ||
+ (op_wait_r && ~|op_cnt_r);
+ end
+ end
+ endgenerate
+
+ output allow_auto_pre;
+ wire allow_auto_pre = act_wait_r_lcl || rcd_active_r ||
+ (col_wait_r && ~sending_col);
+
+// precharge wait state machine.
+ input auto_pre_r;
+ wire start_pre;
+ input pass_open_bank_ns;
+ wire pre_wait_ns = ~rst && (~pass_open_bank_ns &&
+ (start_pre_wait || (pre_wait_r && ~start_pre)));
+ always @(posedge clk) pre_wait_r <= #TCQ pre_wait_ns;
+ wire pre_request = pre_wait_r && ras_timer_zero_r && ~auto_pre_r;
+
+// precharge timer.
+ localparam nRP_CLKS = (nCK_PER_CLK == 1) ? nRP :
+ (nCK_PER_CLK == 2) ? ((nRP/2) + (nRP%2)) :
+ /*(nCK_PER_CLK == 4)*/ ((nRP/4) + ((nRP%4) ? 1 : 0));
+
+// Subtract two because there are a minimum of two fabric states from
+// end of RP timer until earliest possible arb to send act.
+ localparam nRP_CLKS_M2 = (nRP_CLKS-2 < 0) ? 0 : nRP_CLKS-2;
+ localparam RP_TIMER_WIDTH = clogb2(nRP_CLKS_M2 + 1);
+
+ input sending_pre;
+ output rts_pre;
+
+ generate
+
+ if((nCK_PER_CLK == 4) && (ADDR_CMD_MODE != ""2T"")) begin
+
+ assign start_pre = pre_wait_r && ras_timer_zero_r &&
+ (sending_pre || auto_pre_r);
+
+ assign rts_pre = ~sending_pre && pre_request;
+
+ end
+
+ else begin
+
+ assign start_pre = pre_wait_r && ras_timer_zero_r &&
+ (sending_row || auto_pre_r);
+
+ assign rts_pre = 1\'b0;
+
+ end
+
+ endgenerate
+
+ reg [RP_TIMER_WIDTH-1:0] rp_timer_r = ZERO[RP_TIMER_WIDTH-1:0];
+
+ generate
+ if (nRP_CLKS_M2 > ZERO) begin : rp_timer
+ reg [RP_TIMER_WIDTH-1:0] rp_timer_ns;
+ always @(/*AS*/rp_timer_r or rst or start_pre)
+ if (rst) rp_timer_ns = ZERO[RP_TIMER_WIDTH-1:0];
+ else begin
+ rp_timer_ns = rp_timer_r;
+ if (start_pre) rp_timer_ns = nRP_CLKS_M2[RP_TIMER_WIDTH-1:0];
+ else if (|rp_timer_r) rp_timer_ns =
+ rp_timer_r - ONE[RP_TIMER_WIDTH-1:0];
+ end
+ always @(posedge clk) rp_timer_r <= #TCQ rp_timer_ns;
+ end // block: rp_timer
+ endgenerate
+
+ output wire precharge_bm_end;
+ assign precharge_bm_end = (rp_timer_r == ONE[RP_TIMER_WIDTH-1:0]) ||
+ (start_pre && (nRP_CLKS_M2 == ZERO));
+
+// Compute RRD related activate inhibit.
+// Compare this bank machine\'s rank with others, then
+// select result based on grant. An alternative is to
+// select the just issued rank with the grant and simply
+// compare against this bank machine\'s rank. However, this
+// serializes the selection of the rank and the compare processes.
+// As implemented below, the compare occurs first, then the
+// selection based on grant. This is faster.
+
+ input [RANK_WIDTH-1:0] req_rank_r;
+ input [(RANK_WIDTH*nBANK_MACHS*2)-1:0] req_rank_r_in;
+
+ reg inhbt_act_rrd;
+ input [(nBANK_MACHS*2)-1:0] start_rcd_in;
+
+ generate
+ integer j;
+ if (RANKS == 1)
+ always @(/*AS*/req_rank_r or req_rank_r_in or start_rcd_in) begin
+ inhbt_act_rrd = 1\'b0;
+ for (j=(ID+1); j<(ID+nBANK_MACHS); j=j+1)
+ inhbt_act_rrd = inhbt_act_rrd || start_rcd_in[j];
+ end
+ else begin
+ always @(/*AS*/req_rank_r or req_rank_r_in or start_rcd_in) begin
+ inhbt_act_rrd = 1\'b0;
+ for (j=(ID+1); j<(ID+nBANK_MACHS); j=j+1)
+ inhbt_act_rrd = inhbt_act_rrd ||
+ (start_rcd_in[j] &&
+ (req_rank_r_in[(j*RANK_WIDTH)+:RANK_WIDTH] == req_rank_r));
+ end
+ end
+
+ endgenerate
+
+// Extract the activate command inhibit for the rank associated
+// with this request. FAW and RRD are computed separately so that
+// gate level timing can be carefully managed.
+ input [RANKS-1:0] inhbt_act_faw_r;
+ wire my_inhbt_act_faw = inhbt_act_faw_r[req_rank_r];
+
+ input wait_for_maint_r;
+ input head_r;
+ wire act_req = ~idle_r && head_r && act_wait_r && ras_timer_zero_r &&
+ ~wait_for_maint_r;
+
+// Implement simple starvation avoidance for act requests. Precharge
+// requests don\'t need this because they are never gated off by
+// timing events such as inhbt_act_rrd. Priority request timeout
+// is fixed at a single trip around the round robin arbiter.
+
+ input sent_row;
+ wire rts_act_denied = act_req && sent_row && ~sending_row;
+
+ reg [BM_CNT_WIDTH-1:0] act_starve_limit_cntr_ns;
+ reg [BM_CNT_WIDTH-1:0] act_starve_limit_cntr_r;
+
+ generate
+ if (BM_CNT_WIDTH > 1) // Number of Bank Machs > 2
+ begin :BM_MORE_THAN_2
+ always @(/*AS*/act_req or act_starve_limit_cntr_r or rts_act_denied)
+ begin
+ act_starve_limit_cntr_ns = act_starve_limit_cntr_r;
+ if (~act_req)
+ act_starve_limit_cntr_ns = {BM_CNT_WIDTH{1\'b0}};
+ else
+ if (rts_act_denied && &act_starve_limit_cntr_r)
+ act_starve_limit_cntr_ns = act_starve_limit_cntr_r +
+ {{BM_CNT_WIDTH-1{1\'b0}}, 1\'b1};
+ end
+ end
+ else // Number of Bank Machs == 2
+ begin :BM_EQUAL_2
+ always @(/*AS*/act_req or act_starve_limit_cntr_r or rts_act_denied)
+ begin
+ act_starve_limit_cntr_ns = act_starve_limit_cntr_r;
+ if (~act_req)
+ act_starve_limit_cntr_ns = {BM_CNT_WIDTH{1\'b0}};
+ else
+ if (rts_act_denied && &act_starve_limit_cntr_r)
+ act_starve_limit_cntr_ns = act_starve_limit_cntr_r +
+ {1\'b1};
+ end
+ end
+ endgenerate
+
+ always @(posedge clk) act_starve_limit_cntr_r <=
+ #TCQ act_starve_limit_cntr_ns;
+
+ reg demand_act_priority_r;
+ wire demand_act_priority_ns = act_req &&
+ (demand_act_priority_r || (rts_act_denied && &act_starve_limit_cntr_r));
+ always @(posedge clk) demand_act_priority_r <= #TCQ demand_act_priority_ns;
+
+`ifdef MC_SVA
+ cover_demand_act_priority:
+ cover property (@(posedge clk) (~rst && demand_act_priority_r));
+`endif
+
+ output wire demand_act_priority;
+ assign demand_act_priority = demand_act_priority_r && ~sending_row;
+
+// compute act_demanded from other demand_act_priorities
+ input [(nBANK_MACHS*2)-1:0] demand_act_priority_in;
+ reg act_demanded = 1\'b0;
+ generate
+ if (nBANK_MACHS > 1) begin : compute_act_demanded
+ always @(demand_act_priority_in[`BM_SHARED_BV])
+ act_demanded = |demand_act_priority_in[`BM_SHARED_BV];
+ end
+ endgenerate
+
+ wire row_demand_ok = demand_act_priority_r || ~act_demanded;
+
+// Generate the Request To Send row arbitation signal.
+ output wire rts_row;
+
+ generate
+
+ if((nCK_PER_CLK == 4) && (ADDR_CMD_MODE != ""2T""))
+ assign rts_row = ~sending_row && row_demand_ok &&
+ (act_req && ~my_inhbt_act_faw && ~inhbt_act_rrd);
+ else
+ assign rts_row = ~sending_row && row_demand_ok &&
+ ((act_req && ~my_inhbt_act_faw && ~inhbt_act_rrd) ||
+ pre_request);
+ endgenerate
+
+`ifdef MC_SVA
+ four_activate_window_wait:
+ cover property (@(posedge clk)'b'
+ (~rst && ~sending_row && act_req && my_inhbt_act_faw));
+ ras_ras_delay_wait:
+ cover property (@(posedge clk)
+ (~rst && ~sending_row && act_req && inhbt_act_rrd));
+`endif
+
+// Provide rank machines early knowledge that this bank machine is
+// going to send an activate to the rank. In this way, the rank
+// machines just need to use the sending_row wire to figure out if
+// they need to keep track of the activate.
+ output reg [RANKS-1:0] act_this_rank_r;
+ reg [RANKS-1:0] act_this_rank_ns;
+ always @(/*AS*/act_wait_r or req_rank_r) begin
+ act_this_rank_ns = {RANKS{1\'b0}};
+ for (i = 0; i < RANKS; i = i + 1)
+ act_this_rank_ns[i] = act_wait_r && (i[RANK_WIDTH-1:0] == req_rank_r);
+ end
+ always @(posedge clk) act_this_rank_r <= #TCQ act_this_rank_ns;
+
+
+// Generate request to send column command signal.
+
+ input order_q_zero;
+ wire req_bank_rdy_ns = order_q_zero && col_wait_r;
+ reg req_bank_rdy_r;
+ always @(posedge clk) req_bank_rdy_r <= #TCQ req_bank_rdy_ns;
+
+// Determine is we have been denied a column command request.
+ input sent_col;
+ wire rts_col_denied = req_bank_rdy_r && sent_col && ~sending_col;
+
+// Implement a starvation limit counter. Count the number of times a
+// request to send a column command has been denied.
+ localparam STARVE_LIMIT_CNT = STARVE_LIMIT * nBANK_MACHS;
+ localparam STARVE_LIMIT_WIDTH = clogb2(STARVE_LIMIT_CNT);
+ reg [STARVE_LIMIT_WIDTH-1:0] starve_limit_cntr_r;
+ reg [STARVE_LIMIT_WIDTH-1:0] starve_limit_cntr_ns;
+ always @(/*AS*/col_wait_r or rts_col_denied or starve_limit_cntr_r)
+ if (~col_wait_r)
+ starve_limit_cntr_ns = {STARVE_LIMIT_WIDTH{1\'b0}};
+ else
+ if (rts_col_denied && (starve_limit_cntr_r != STARVE_LIMIT_CNT-1))
+ starve_limit_cntr_ns = starve_limit_cntr_r +
+ {{STARVE_LIMIT_WIDTH-1{1\'b0}}, 1\'b1};
+ else starve_limit_cntr_ns = starve_limit_cntr_r;
+ always @(posedge clk) starve_limit_cntr_r <= #TCQ starve_limit_cntr_ns;
+
+ input q_has_rd;
+ input q_has_priority;
+
+// Decide if this bank machine should demand priority. Priority is demanded
+// when starvation limit counter is reached, or a bit in the request.
+ wire starved = ((starve_limit_cntr_r == (STARVE_LIMIT_CNT-1)) &&
+ rts_col_denied);
+ input req_priority_r;
+ input idle_ns;
+ reg demand_priority_r;
+ wire demand_priority_ns = ~idle_ns && col_wait_ns &&
+ (demand_priority_r ||
+ (order_q_zero &&
+ (req_priority_r || q_has_priority)) ||
+ (starved && (q_has_rd || ~req_wr_r)));
+
+ always @(posedge clk) demand_priority_r <= #TCQ demand_priority_ns;
+
+`ifdef MC_SVA
+ wire rdy_for_priority = ~rst && ~demand_priority_r && ~idle_ns &&
+ col_wait_ns;
+ req_triggers_demand_priority:
+ cover property (@(posedge clk)
+ (rdy_for_priority && req_priority_r && ~q_has_priority && ~starved));
+ q_priority_triggers_demand_priority:
+ cover property (@(posedge clk)
+ (rdy_for_priority && ~req_priority_r && q_has_priority && ~starved));
+ wire not_req_or_q_rdy_for_priority =
+ rdy_for_priority && ~req_priority_r && ~q_has_priority;
+ starved_req_triggers_demand_priority:
+ cover property (@(posedge clk)
+ (not_req_or_q_rdy_for_priority && starved && ~q_has_rd && ~req_wr_r));
+ starved_q_triggers_demand_priority:
+ cover property (@(posedge clk)
+ (not_req_or_q_rdy_for_priority && starved && q_has_rd && req_wr_r));
+`endif
+
+// compute demanded from other demand_priorities
+ input [(nBANK_MACHS*2)-1:0] demand_priority_in;
+ reg demanded = 1\'b0;
+ generate
+ if (nBANK_MACHS > 1) begin : compute_demanded
+ always @(demand_priority_in[`BM_SHARED_BV]) demanded =
+ |demand_priority_in[`BM_SHARED_BV];
+ end
+ endgenerate
+
+
+// In order to make sure that there is no starvation amongst a possibly
+// unlimited stream of priority requests, add a second stage to the demand
+// priority signal. If there are no other requests demanding priority, then
+// go ahead and assert demand_priority. If any other requests are asserting
+// demand_priority, hold off asserting demand_priority until these clear, then
+// assert demand priority. Its possible to get multiple requests asserting
+// demand priority simultaneously, but that\'s OK. Those requests will be
+// serviced, demanded will fall, and another group of requests will be
+// allowed to assert demand_priority.
+
+ reg demanded_prior_r;
+ wire demanded_prior_ns = demanded &&
+ (demanded_prior_r || ~demand_priority_r);
+ always @(posedge clk) demanded_prior_r <= #TCQ demanded_prior_ns;
+
+ output wire demand_priority;
+ assign demand_priority = demand_priority_r && ~demanded_prior_r &&
+ ~sending_col;
+
+`ifdef MC_SVA
+ demand_priority_gated:
+ cover property (@(posedge clk) (demand_priority_r && ~demand_priority));
+ generate
+ if (nBANK_MACHS >1) multiple_demand_priority:
+ cover property (@(posedge clk)
+ ($countones(demand_priority_in[`BM_SHARED_BV]) > 1));
+ endgenerate
+`endif
+
+ wire demand_ok = demand_priority_r || ~demanded;
+
+ // Figure out if the request in this bank machine matches the current rank
+ // configuration.
+ input rnk_config_strobe;
+ input rnk_config_kill_rts_col;
+ input rnk_config_valid_r;
+ input [RANK_WIDTH-1:0] rnk_config;
+ output wire rtc;
+
+ wire rnk_config_match = rnk_config_valid_r && (rnk_config == req_rank_r);
+ assign rtc = ~rnk_config_match && ~rnk_config_kill_rts_col && order_q_zero && col_wait_r && demand_ok;
+
+// Using rank state provided by the rank machines, figure out if
+// a read requests should wait for WTR or RTW.
+ input [RANKS-1:0] inhbt_rd;
+ wire my_inhbt_rd = inhbt_rd[req_rank_r];
+ input [RANKS-1:0] inhbt_wr;
+ wire my_inhbt_wr = inhbt_wr[req_rank_r];
+ wire allow_rw = ~rd_wr_r ? ~my_inhbt_wr : ~my_inhbt_rd;
+
+// DQ bus timing constraints.
+ input dq_busy_data;
+
+// Column command is ready to arbitrate, except for databus restrictions.
+ wire col_rdy = (col_wait_r || ((nRCD_CLKS <= 1) && end_rcd) ||
+ (rcv_open_bank && nCK_PER_CLK == 2 && DRAM_TYPE==""DDR2"" && BURST_MODE == ""4"") ||
+ (rcv_open_bank && nCK_PER_CLK == 4 && BURST_MODE == ""8"")) &&
+ order_q_zero;
+
+// Column command is ready to arbitrate for sending a write. Used
+// to generate early wr_data_addr for ECC mode.
+ output wire col_rdy_wr;
+ assign col_rdy_wr = col_rdy && ~rd_wr_r;
+
+// Figure out if we\'re ready to send a column command based on all timing
+// constraints.
+// if timing is an issue.
+ wire col_cmd_rts = col_rdy && ~dq_busy_data && allow_rw && rnk_config_match;
+
+`ifdef MC_SVA
+ col_wait_for_order_q: cover property
+ (@(posedge clk)
+ (~rst && col_wait_r && ~order_q_zero && ~dq_busy_data &&
+ allow_rw));
+ col_wait_for_dq_busy: cover property
+ (@(posedge clk)
+ (~rst && col_wait_r && order_q_zero && dq_busy_data &&
+ allow_rw));
+ col_wait_for_allow_rw: cover property
+ (@(posedge clk)
+ (~rst && col_wait_r && order_q_zero && ~dq_busy_data &&
+ ~allow_rw));
+`endif
+
+// Implement flow control for the command and control FIFOs and for the data
+// FIFO during writes
+ input phy_mc_ctl_full;
+ input phy_mc_cmd_full;
+ input phy_mc_data_full;
+
+ // Register ctl_full and cmd_full
+ reg phy_mc_ctl_full_r = 1\'b0;
+ reg phy_mc_cmd_full_r = 1\'b0;
+ always @(posedge clk)
+ if(rst) begin
+ phy_mc_ctl_full_r <= #TCQ 1\'b0;
+ phy_mc_cmd_full_r <= #TCQ 1\'b0;
+ end else begin
+ phy_mc_ctl_full_r <= #TCQ phy_mc_ctl_full;
+ phy_mc_cmd_full_r <= #TCQ phy_mc_cmd_full;
+ end
+
+ // register output data pre-fifo almost full condition and fold in WR status
+ reg ofs_rdy_r = 1\'b0;
+ always @(posedge clk)
+ if(rst)
+ ofs_rdy_r <= #TCQ 1\'b0;
+ else
+ ofs_rdy_r <= #TCQ ~phy_mc_cmd_full_r && ~phy_mc_ctl_full_r && ~(phy_mc_data_full && ~rd_wr_r);
+
+// Disable priority feature for one state after a config to insure
+// forward progress on the just installed io config.
+ reg override_demand_r;
+ wire override_demand_ns = rnk_config_strobe || rnk_config_kill_rts_col;
+ always @(posedge clk) override_demand_r <= override_demand_ns;
+ output wire rts_col;
+ assign rts_col = ~sending_col && (demand_ok || override_demand_r) &&
+ col_cmd_rts && ofs_rdy_r;
+
+// As in act_this_rank, wr/rd_this_rank informs rank machines
+// that this bank machine is doing a write/rd. Removes logic
+// after the grant.
+ reg [RANKS-1:0] wr_this_rank_ns;
+ reg [RANKS-1:0] rd_this_rank_ns;
+ always @(/*AS*/rd_wr_r or req_rank_r) begin
+ wr_this_rank_ns = {RANKS{1\'b0}};
+ rd_this_rank_ns = {RANKS{1\'b0}};
+ for (i=0; i1; clogb2=clogb2+1)
+ size = size >> 1;
+ end
+ endfunction // clogb2
+
+// Determine if this rank has been activated. act_this_rank_r is a
+// registered bit vector from individual bank machines indicating the
+// corresponding bank machine is sending
+// an activate. Timing is improved with this method.
+
+ input [nBANK_MACHS-1:0] sending_row;
+ input [RANK_BM_BV_WIDTH-1:0] act_this_rank_r;
+ reg act_this_rank;
+ integer i;
+ always @(/*AS*/act_this_rank_r or sending_row) begin
+ act_this_rank = 1\'b0;
+ for (i=0; i 4. The additional RRD inhibit is worked into
+// the inhbt_faw signal.
+
+ localparam nADD_RRD = nRRD - ((nCK_PER_CLK == 1) ? 2 : 4);
+ localparam nRRD_CLKS = (nCK_PER_CLK == 1)
+ ? nADD_RRD
+ : ((nADD_RRD/2) + (nADD_RRD%2));
+ localparam ADD_RRD_CNTR_WIDTH = clogb2(nRRD_CLKS + /*idle state*/ 1);
+
+ reg add_rrd_inhbt = 1\'b0;
+ generate
+ if (nADD_RRD > 0) begin :add_rdd
+ reg[ADD_RRD_CNTR_WIDTH-1:0] add_rrd_ns;
+ reg[ADD_RRD_CNTR_WIDTH-1:0] add_rrd_r;
+ always @(/*AS*/act_this_rank or add_rrd_r or rst) begin
+ add_rrd_ns = add_rrd_r;
+ if (rst) add_rrd_ns = {ADD_RRD_CNTR_WIDTH{1\'b0}};
+ else
+ if (act_this_rank)
+ add_rrd_ns = nRRD_CLKS[0+:ADD_RRD_CNTR_WIDTH];
+ else if (|add_rrd_r) add_rrd_ns =
+ add_rrd_r - {{ADD_RRD_CNTR_WIDTH-1{1\'b0}}, 1\'b1};
+ end
+ always @(posedge clk) add_rrd_r <= #TCQ add_rrd_ns;
+ always @(/*AS*/add_rrd_ns) add_rrd_inhbt = |add_rrd_ns;
+ end
+ endgenerate
+
+
+// Compute inhbt_act_faw_r. Only allow a limited number of activates
+// in a window. Both the number of activates and the window are
+// configurable. This depends on the RRD mechanism to prevent
+// two consecutive activates to the same rank.
+//
+// Subtract three from the specified nFAW. Subtract three because:
+// -Zero for the delay into the SRL is really one state.
+// -Sending_row is used to trigger the delay. Sending_row is one
+// state delayed from the arb.
+// -inhbt_act_faw_r is registered to make timing work, hence the
+// generation needs to be one state early.
+
+ localparam nFAW_CLKS = (nCK_PER_CLK == 1)
+ ? nFAW
+ : ((nFAW/2) + (nFAW%2));
+
+ output reg inhbt_act_faw_r;
+ generate
+ begin : inhbt_act_faw
+ wire act_delayed;
+ wire [4:0] shift_depth = nFAW_CLKS[4:0] - 5\'d3;
+
+ SRLC32E #(.INIT(32\'h00000000) ) SRLC32E0
+ (.Q(act_delayed), // SRL data output
+ .Q31(), // SRL cascade output pin
+ .A(shift_depth), // 5-bit shift depth select input
+ .CE(1\'b1), // Clock enable input
+ .CLK(clk), // Clock input
+ .D(act_this_rank) // SRL data input
+ );
+
+ reg [2:0] faw_cnt_ns;
+ reg [2:0] faw_cnt_r;
+ reg inhbt_act_faw_ns;
+ always @(/*AS*/act_delayed or act_this_rank or add_rrd_inhbt
+ or faw_cnt_r or rst) begin
+ if (rst) faw_cnt_ns = 3\'b0;
+ else begin
+ faw_cnt_ns = faw_cnt_r;
+ if (act_this_rank) faw_cnt_ns = faw_cnt_r + 3\'b1;
+ if (act_delayed) faw_cnt_ns = faw_cnt_ns - 3\'b1;
+ end
+ inhbt_act_faw_ns = (faw_cnt_ns == 3\'h4) || add_rrd_inhbt;
+ end
+ always @(posedge clk) faw_cnt_r <= #TCQ faw_cnt_ns;
+ always @(posedge clk) inhbt_act_faw_r <= #TCQ inhbt_act_faw_ns;
+ end // block: inhbt_act_faw
+ endgenerate
+
+
+// In the DRAM spec, tWTR starts from CK following the end of the data
+// burst. Since we don\'t directly have that spec, the wtr timer is
+// based on when the CAS write command is sent to the DRAM.
+//
+// To compute the wtr timer value, first compute the time from
+// first data of the write to the first data of the read. This
+// is data_time + nWTR + CL.
+//
+// Now note that dfi_rddata_en and dfi_wrdata_en have a equal
+// delays to data on the DQ bus. If we compute the minimum dfi_wrdata_en
+// to dfi_rddata_en value we can compare it to the required data
+// to data delay computed above and determine if we need to
+// implement the wtr timer. (currently not implemented)
+//
+// Two is subtracted from the required wtr time since the timer
+// starts two states after the arbitration cycle.
+
+ localparam ONE = 1;
+ localparam CASWR2CASRD = ((BURST_MODE == ""4"") ? 2 : 4) + nWTR + CL;
+ localparam CASWR2CASRD_CLKS = (nCK_PER_CLK == 1)
+ ? CASWR2CASRD
+ : ((CASWR2CASRD / 2) + (CASWR2CASRD %2));
+ localparam WTR_CNT_WIDTH = clogb2(CASWR2CASRD_CLKS - /*-2 max cnt*/ 1);
+ localparam TWO = 2;
+
+
+ input [nBANK_MACHS-1:0] sending_col;
+ input [RANK_BM_BV_WIDTH-1:0] wr_this_rank_r;
+ output reg inhbt_rd_r;
+ output reg wtr_inhbt_config_r;
+
+ generate
+ begin : wtr_timer
+
+ reg write_this_rank;
+ always @(/*AS*/sending_col or wr_this_rank_r) begin
+ write_this_rank = 1\'b0;
+ for (i = 0; i < nBANK_MACHS; i = i + 1)
+ write_this_rank =
+ write_this_rank || (sending_col[i] && wr_this_rank_r[(i*RANKS)+ID]);
+ end
+
+ reg [WTR_CNT_WIDTH-1:0] wtr_cnt_r;
+ reg [WTR_CNT_WIDTH-1:0] wtr_cnt_ns;
+
+ always @(/*AS*/rst or write_this_rank or wtr_cnt_r)
+ if (rst) wtr_cnt_ns = {WTR_CNT_WIDTH{1\'b0}};
+ else begin
+ wtr_cnt_ns = wtr_cnt_r;
+ if (write_this_rank) wtr_cnt_ns =
+ CASWR2CASRD_CLKS[WTR_CNT_WIDTH-1:0] - TWO[WTR_CNT_WIDTH-1:0];
+ else if (|wtr_cnt_r) wtr_cnt_ns = wtr_cnt_r - ONE[WTR_CNT_WIDTH-1:0];
+ end
+
+ wire inhbt_rd_ns = |wtr_cnt_ns;
+ wire wtr_inhbt_config_ns = wtr_cnt_ns >= TWO[WTR_CNT_WIDTH-1:0];
+
+ always @(posedge clk) wtr_cnt_r <= #TCQ wtr_cnt_ns;
+ always @(posedge clk) inhbt_rd_r <= #TCQ inhbt_rd_ns;
+ always @(posedge clk) wtr_inhbt_config_r <= #TCQ wtr_inhbt_config_ns;
+
+ end
+ endgenerate
+
+
+// Refresh request generation. Implement a ""refresh bank"". Referred
+// to as pullin-in refresh in the JEDEC spec.
+// The refresh_rank_r counter increments when a refresh to this
+// rank has been decoded. In the up direction, the count saturates
+// at nREFRESH_BANK. As specified in the JEDEC spec, nREFRESH_BANK
+// is normally eight. The counter decrements with each refresh_tick,
+// saturating at zero. A refresh will be requests when the rank is
+// not busy and refresh_rank_r != nREFRESH_BANK, or refresh_rank_r
+// equals zero.
+
+ localparam REFRESH_BANK_WIDTH = clogb2(nREFRESH_BANK + 1);
+
+ input app_ref_req;
+ input dfi_init_complete;
+ input [(RANKS*nBANK_MACHS)-1:0] rank_busy_r;
+ input refresh_tick;
+ input insert_maint_r1;
+ input maint_zq_r;
+ input [RANK_WIDTH-1:0] maint_rank_r;
+ output wire refresh_request;
+
+ generate begin : refresh_generation
+ reg my_rank_busy;
+ always @(/*AS*/rank_busy_r) begin
+ my_rank_busy = 1\'b0;
+ for (i=0; i < nBANK_MACHS; i=i+1)
+ my_rank_busy = my_rank_busy || rank_busy_r[(i*RANKS)+ID];
+ end
+
+ wire my_refresh =
+ insert_maint_r1 && ~maint_zq_r && (maint_rank_r == ID[RANK_WIDTH-1:0]);
+
+ reg [REFRESH_BANK_WIDTH-1:0] refresh_bank_r;
+ reg [REFRESH_BANK_WIDTH-1:0] refresh_bank_ns;
+ always @(/*AS*/app_ref_req or dfi_init_complete or my_refresh
+ or refresh_bank_r or refresh_tick)
+ if (~dfi_init_complete)
+ if (REFRESH_TIMER_DIV == 0)
+ refresh_bank_ns = nREFRESH_BANK[0+:REFRESH_BANK_WIDTH];
+ else refresh_bank_ns = {REFRESH_BANK_WIDTH{1\'b0}};
+ else
+ case ({my_refresh, refresh_tick, app_ref_req})
+ 3\'b000, 3\'b110, 3\'b101, 3\'b111 : refresh_bank_ns = refresh_bank_r;
+ 3\'b010, 3\'b001, 3\'b011 : refresh_bank_ns =
+ (|refresh_bank_r)?
+ refresh_bank_r - ONE[0+:REFRESH_BANK_WIDTH]:
+ refresh_bank_r;
+ 3\'b100 : refresh_bank_ns =
+ refresh_bank_r + ONE[0+:REFRESH_BANK_WIDTH];
+ endcase // case ({my_refresh, refresh_tick})
+ always @(posedge clk) refresh_bank_r <= #TCQ refresh_bank_ns;
+
+ `ifdef MC_SVA
+ refresh_bank_overflow: assert property (@(posedge clk)
+ (rst || (refresh_bank_r <= nREFRESH_BANK)));
+ refresh_bank_underflow: assert property (@(posedge clk)
+ (rst || ~(~|refresh_bank_r && ~my_refresh && refresh_tick)));
+ refresh_hi_priority: cover property (@(posedge clk)
+ (rst && ~|refresh_bank_ns && (refresh_bank_r ==
+ ONE[0+:REFRESH_BANK_WIDTH])));
+ refresh_bank_full: cover property (@(posedge clk)
+ (rst && (refresh_bank_r ==
+ nREFRESH_BANK[0+:REFRESH_BANK_WIDTH])));
+ `endif
+
+ assign refresh_request = dfi_init_complete &&
+ (~|refresh_bank_r ||
+ ((refresh_bank_r != nREFRESH_BANK[0+:REFRESH_BANK_WIDTH]) && ~my_rank_busy));
+
+ end
+ endgenerate
+
+// Periodic read request generation.
+
+ localparam PERIODIC_RD_TIMER_WIDTH = clogb2(PERIODIC_RD_TIMER_DIV + /*idle state*/ 1);
+
+ input app_periodic_rd_req;
+ input maint_prescaler_tick_r;
+ output periodic_rd_request;
+ input clear_periodic_rd_request;
+ input [RANK_BM_BV_WIDTH-1:0] rd_this_rank_r;
+
+ generate begin : periodic_rd_generation
+ if ( PHASE_DETECT != ""OFF"" ) begin //to enable periodic reads
+ reg read_this_rank;
+ always @(/*AS*/rd_this_rank_r or sending_col) begin
+ read_this_rank = 1\'b0;
+ for (i = 0; i < nBANK_MACHS; i = i + 1)
+ read_this_rank =
+ read_this_rank || (sending_col[i] && rd_this_rank_r[(i*RANKS)+ID]);
+ end
+
+ reg [PERIODIC_RD_TIMER_WIDTH-1:0] periodic_rd_timer_r;
+ reg [PERIODIC_RD_TIMER_WIDTH-1:0] periodic_rd_timer_ns;
+ always @(/*AS*/dfi_init_complete or maint_prescaler_tick_r
+ or periodic_rd_timer_r or read_this_rank) begin
+ periodic_rd_timer_ns = periodic_rd_timer_r;
+ if (~dfi_init_complete)
+ periodic_rd_timer_ns = {PERIODIC_RD_TIMER_WIDTH{1\'b0}};
+ else if (read_this_rank)
+ periodic_rd_timer_ns =
+ PERIODIC_RD_TIMER_DIV[0+:PERIODIC_RD_TIMER_WIDTH];
+ else if (|periodic_rd_timer_r && maint_prescaler_tick_r)
+ periodic_rd_timer_ns =
+ periodic_rd_timer_r - ONE[0+:PERIODIC_RD_TIMER_WIDTH];
+ end
+ always @(posedge clk) periodic_rd_timer_r <= #TCQ periodic_rd_timer_ns;
+
+ wire periodic_rd_timer_one = maint_prescaler_tick_r &&
+ (periodic_rd_timer_r == ONE[0+:PERIODIC_RD_TIMER_WIDTH]);
+
+ reg periodic_rd_request_r;
+ wire periodic_rd_request_ns = ~rst &&
+ ((app_periodic_rd_req && dfi_init_complete) ||
+ ((PERIODIC_RD_TIMER_DIV != 0) && ~dfi_init_complete) ||
+ (~(read_this_rank || clear_periodic_rd_request) &&
+ (periodic_rd_request_r || periodic_rd_timer_one)));
+ always @(posedge clk) periodic_rd_request_r <=
+ #TCQ periodic_rd_request_ns;
+
+
+ `ifdef MC_SVA
+ read_clears_periodic_rd_request: cover property (@(posedge clk)
+ (rst && (periodic_rd_request_r && read_this_rank)));
+ `endif
+
+ assign periodic_rd_request = dfi_init_complete && periodic_rd_request_r;
+ end else
+ assign periodic_rd_request = 1\'b0; //to disable periodic reads
+
+ end
+ endgenerate
+
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2008-2009 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : 3.91
+// \\ \\ Application : MIG
+// / / Filename : mem_intfc.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Aug 03 2009
+// \\___\\/\\___\\
+//
+//Device : Virtex-6
+//Design Name : DDR3 SDRAM
+//Purpose : Top level memory interface block. Instantiates a clock
+// and reset generator, the memory controller, the phy and
+// the user interface blocks.
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+`timescale 1 ps / 1 ps
+
+module mem_intfc #
+ (
+ parameter TCQ = 100,
+ parameter PAYLOAD_WIDTH = 64,
+ parameter ADDR_CMD_MODE = ""1T"",
+ parameter AL = ""0"", // Additive Latency option
+ parameter BANK_WIDTH = 3, // # of bank bits
+ parameter BM_CNT_WIDTH = 2, // Bank machine counter width
+ parameter BURST_MODE = ""8"", // Burst length
+ parameter BURST_TYPE = ""SEQ"", // Burst type
+ parameter CK_WIDTH = 1, // # of CK/CK# outputs to memory
+ parameter CL = 5,
+ parameter COL_WIDTH = 12, // column address width
+ parameter CMD_PIPE_PLUS1 = ""ON"", // add pipeline stage between MC and PHY
+ parameter CS_WIDTH = 1, // # of unique CS outputs
+ parameter CKE_WIDTH = 1, // # of cke outputs
+ parameter CWL = 5,
+ parameter DATA_WIDTH = 64,
+ parameter DATA_BUF_ADDR_WIDTH = 8,
+ parameter DATA_BUF_OFFSET_WIDTH = 1,
+// parameter DELAY_WR_DATA_CNTRL = 0, //This parameter is made as MC local parameter
+ parameter DM_WIDTH = 8, // # of DM (data mask)
+ parameter DQ_CNT_WIDTH = 6, // = ceil(log2(DQ_WIDTH))
+ parameter DQ_WIDTH = 64, // # of DQ (data)
+ parameter DQS_CNT_WIDTH = 3, // = ceil(log2(DQS_WIDTH))
+ parameter DQS_WIDTH = 8, // # of DQS (strobe)
+ parameter DRAM_TYPE = ""DDR3"",
+ parameter DRAM_WIDTH = 8, // # of DQ per DQS
+ parameter ECC = ""OFF"",
+ parameter ECC_TEST_FI_XOR = ""OFF"",
+ parameter ECC_WIDTH = 8,
+ parameter MC_ERR_ADDR_WIDTH = 31,
+ parameter nAL = 0, // Additive latency (in clk cyc)
+ parameter nBANK_MACHS = 4,
+ parameter nCK_PER_CLK = 2, // # of memory CKs per fabric CLK
+ parameter nCS_PER_RANK = 1, // # of unique CS outputs per rank
+ parameter ORDERING = ""NORM"",
+ parameter PHASE_DETECT = ""OFF"" , // to phy_top
+ parameter IBUF_LPWR_MODE = ""OFF"", // to phy_top
+ parameter IODELAY_HP_MODE = ""ON"", // to phy_top
+ parameter IODELAY_GRP = ""IODELAY_MIG"", //to phy_top
+ parameter OUTPUT_DRV = ""HIGH"" , // to phy_top
+ parameter REG_CTRL = ""OFF"" , // to phy_top
+ parameter RTT_NOM = ""60"" , // to phy_top
+ parameter RTT_WR = ""120"" , // to phy_top
+ parameter STARVE_LIMIT = 2,
+ parameter tCK = 2500, // pS
+ parameter tFAW = 40000, // pS
+ parameter tPRDI = 1_000_000, // pS
+ parameter tRAS = 37500, // pS
+ parameter tRCD = 12500, // pS
+ parameter tREFI = 7800000, // pS
+ parameter tRFC = 110000, // pS
+ parameter tRP = 12500, // pS
+ parameter tRRD = 10000, // pS
+ parameter tRTP = 7500, // pS
+ parameter tWTR = 7500, // pS
+ parameter tZQI = 128_000_000, // nS
+ parameter tZQCS = 64, // CKs
+ parameter WRLVL = ""OFF"" , // to phy_top
+ parameter DEBUG_PORT = ""OFF"" , // to phy_top
+ parameter CAL_WIDTH = ""HALF"" , // to phy_top
+ // calibration Address. The address given below will be used for calibration
+ // read and write operations.
+ parameter CALIB_ROW_ADD = 16\'h0000,// Calibration row address
+ parameter CALIB_COL_ADD = 12\'h000, // Calibration column address
+ parameter CALIB_BA_ADD = 3\'h0, // Calibration bank address
+ parameter RANK_WIDTH = 1,
+ parameter RANKS = 4,
+ parameter ROW_WIDTH = 16, // DRAM address bus width
+ parameter [7:0] SLOT_0_CONFIG = 8\'b0000_0001,
+ parameter [7:0] SLOT_1_CONFIG = 8\'b0000_0000,
+ parameter SIM_BYPASS_INIT_CAL = ""OFF"",
+ parameter REFCLK_FREQ = 300.0,
+ parameter nDQS_COL0 = DQS_WIDTH,
+ parameter nDQS_COL1 = 0,
+ parameter nDQS_COL2 = 0,
+ parameter nDQS_COL3 = 0,
+ parameter DQS_LOC_COL0 = 144\'h11100F0E0D0C0B0A09080706050403020100,
+ parameter DQS_LOC_COL1 = 0,
+ parameter DQS_LOC_COL2 = 0,
+ parameter DQS_LOC_COL3 = 0,
+ parameter USE_DM_PORT = 1 // DM instantation enable
+ )
+ (/*AUTOARG*/
+ // Outputs
+ wr_data_offset, wr_data_en, wr_data_addr, rd_data_offset, rd_data_en,
+ rd_data_addr, ddr_we_n, ddr_parity, ddr_reset_n, ddr_ras_n, ddr_odt, ddr_dm,
+ ddr_cs_n, ddr_cke, ddr_ck, ddr_ck_n, ddr_cas_n, ddr_ba, ddr_addr,
+ bank_mach_next, accept, accept_ns, rd_data, rd_data_end,
+ pd_PSEN, pd_PSINCDEC, dfi_init_complete,
+ ecc_single, ecc_multiple, ecc_err_addr,
+ dbg_wrlvl_start, dbg_wrlvl_done, dbg_wrlvl_err,
+ dbg_wl_dqs_inverted, dbg_wr_calib_clk_delay,
+ dbg_wl_odelay_dqs_tap_cnt, dbg_wl_odelay_dq_tap_cnt,
+ dbg_tap_cnt_during_wrlvl, dbg_wl_edge_detect_valid,
+ dbg_rd_data_edge_detect, dbg_rdlvl_start, dbg_rdlvl_done, dbg_rdlvl_err,
+ dbg_cpt_first_edge_cnt, dbg_cpt_second_edge_cnt, dbg_rd_bitslip_cnt,
+ dbg_rd_clkdly_cnt, dbg_rd_active_dly, dbg_rddata, dbg_cpt_tap_cnt,
+ dbg_rsync_tap_cnt, dbg_dqs_tap_cnt, dbg_dq_tap_cnt,
+ dbg_phy_pd, dbg_phy_read, dbg_phy_rdlvl, dbg_phy_top,
+ // Inouts
+ ddr_dq, ddr_dqs, ddr_dqs_n,
+ // Inputs
+ use_addr, size, rst, row, rank, hi_priority, data_buf_addr,
+ col, cmd, clk_mem, clk, clk_rd_base, bank, wr_data, wr_data_mask,
+ pd_PSDONE, slot_0_present, slot_1_present, correct_en, raw_not_ecc,
+ fi_xor_we, fi_xor_wrdata,
+ dbg_wr_dqs_tap_set, dbg_wr_dq_tap_set, dbg_wr_tap_set_en,
+ dbg_idel_up_all, dbg_idel_down_all, dbg_idel_up_cpt, dbg_idel_down_cpt,
+ dbg_idel_up_rsync, dbg_idel_down_rsync,
+ dbg_sel_idel_cpt, dbg_sel_all_idel_cpt,
+ dbg_sel_idel_rsync, dbg_sel_all_idel_rsync,
+ dbg_pd_off, dbg_pd_maintain_off, dbg_pd_maintain_0_only,
+ dbg_pd_inc_cpt, dbg_pd_dec_cpt, dbg_pd_inc_dqs, dbg_pd_dec_dqs,
+ dbg_pd_disab_hyst, dbg_pd_disab_hyst_0, dbg_pd_msb_sel, dbg_pd_byte_sel,
+ dbg_inc_rd_fps, dbg_dec_rd_fps
+ );
+
+ /*AUTOINPUT*/
+ // Beginning of automatic inputs (from unused autoinst inputs)
+ input [BANK_WIDTH-1:0] bank; // To mc0 of mc.v
+ input clk; // To mc0 of mc.v, ...
+ input clk_mem; // To phy_top0 of phy_top.v
+ input clk_rd_base;
+ input [2:0] cmd; // To mc0 of mc.v
+ input [COL_WIDTH-1:0] col; // To mc0 of mc.v
+ input correct_en;
+ input [DATA_BUF_ADDR_WIDTH-1:0] data_buf_addr; // To mc0 of mc.v
+
+ input dbg_dec_rd_fps;
+ input dbg_idel_down_all;
+ input dbg_idel_down_cpt;
+ input dbg_idel_down_rsync;
+ input dbg_idel_up_all;
+ input dbg_idel_up_cpt;
+ input dbg_idel_up_rsync;
+ input dbg_inc_rd_fps;
+ input [DQS_CNT_WIDTH-1:0] dbg_pd_byte_sel;
+ input dbg_pd_dec_cpt;
+ input dbg_pd_dec_dqs;
+ input dbg_pd_inc_cpt;
+ input dbg_pd_inc_dqs;
+ input dbg_pd_off;
+ input dbg_pd_maintain_off;
+ input dbg_pd_maintain_0_only;
+ input dbg_pd_disab_hyst;
+ input dbg_pd_disab_hyst_0;
+ input [3:0] dbg_pd_msb_sel;
+ input dbg_sel_all_idel_cpt;
+ input dbg_sel_all_idel_rsync;
+ input [DQS_CNT_WIDTH-1:0] dbg_sel_idel_cpt;
+ input [DQS_CNT_WIDTH-1:0] dbg_sel_idel_rsync;
+ input [5*DQS_WIDTH-1:0] dbg_wr_dq_tap_set;
+ input [5*DQS_WIDTH-1:0] dbg_wr_dqs_tap_set;
+ input dbg_wr_tap_set_en;
+ input hi_priority; // To mc0 of mc.v
+ input pd_PSDONE; // To phy_top0 of phy_top.v
+ input [RANK_WIDTH-1:0] rank; // To mc0 of mc.v
+ input [3:0] raw_not_ecc;
+ input [DQ_WIDTH/8-1:0] fi_xor_we; // to mc0 of mc.v
+ input [DQ_WIDTH-1:0] fi_xor_wrdata; // to mc0 of mc.v
+ input [ROW_WIDTH-1:0] row; // To mc0 of mc.v
+ input rst; // To mc0 of mc.v, ...
+ input size; // To mc0 of mc.v
+ input [7:0] slot_0_present; // To mc0 of mc.v
+ input [7:0] slot_1_present; // To mc0 of mc.v
+ input use_addr; // To mc0 of mc.v
+ input [(4*PAYLOAD_WIDTH)-1:0] wr_data;
+ input [(4*(DATA_WIDTH/8))-1:0] wr_data_mask;
+ // End of automatics
+
+ /*AUTOOUTPUT*/
+ // Beginning of automatic outputs (from unused autoinst outputs)
+ output accept; // From mc0 of mc.v
+ output accept_ns; // From mc0 of mc.v
+ output [BM_CNT_WIDTH-1:0] bank_mach_next; // From mc0 of mc.v
+ output [5*DQS_WIDTH-1:0] dbg_cpt_first_edge_cnt;
+ output [5*DQS_WIDTH-1:0] dbg_cpt_second_edge_cnt;
+ output [5*DQS_WIDTH-1:0] dbg_cpt_tap_cnt;
+ output [5*DQS_WIDTH-1:0] dbg_dq_tap_cnt;
+ output [5*DQS_WIDTH-1:0] dbg_dqs_tap_cnt;
+ output [4:0] dbg_rd_active_dly;
+ output [3*DQS_WIDTH-1:0] dbg_rd_bitslip_cnt;
+ output [2*DQS_WIDTH-1:0] dbg_rd_clkdly_cnt;
+ output [DQS_WIDTH-1:0] dbg_rd_data_edge_detect;
+ output [4*DQ_WIDTH-1:0] dbg_rddata;
+ output [1:0] dbg_rdlvl_done;
+ output [1:0] dbg_rdlvl_err;
+ output [1:0] dbg_rdlvl_start;
+ output [4:0] dbg_tap_cnt_during_wrlvl;
+ output [DQS_WIDTH-1:0] dbg_wl_dqs_inverted;
+ output dbg_wl_edge_detect_valid;
+ output [5*DQS_WIDTH-1:0] dbg_wl_odelay_dq_tap_cnt;
+ output [5*DQS_WIDTH-1:0] dbg_wl_odelay_dqs_tap_cnt;
+ output [2*DQS_WIDTH-1:0] dbg_wr_calib_clk_delay;
+ output dbg_wrlvl_done;
+ output dbg_wrlvl_err;
+ output dbg_wrlvl_start;
+ output [ROW_WIDTH-1:0] ddr_addr; // From phy_top0 of phy_top.v
+ output [BANK_WIDTH-1:0] ddr_ba; // From phy_top0 of phy_top.v
+ output ddr_cas_n; // From phy_top0 of phy_top.v
+ output [CK_WIDTH-1:0] ddr_ck_n; // From phy_top0 of phy_top.v
+ output [CK_WIDTH-1:0] ddr_ck ; // From phy_top0 of phy_top.v
+ output [CKE_WIDTH-1:0] ddr_cke; // From phy_top0 of phy_top.v
+ output [CS_WIDTH*nCS_PER_RANK-1:0] ddr_cs_n; // From phy_top0 of phy_top.v
+ output [DM_WIDTH-1:0] ddr_dm; // From phy_top0 of phy_top.v
+ output [CS_WIDTH*nCS_PER_RANK-1:0] ddr_odt; // From phy_top0 of phy_top.v
+ output ddr_ras_n; // From phy_top0 of phy_top.v
+ output ddr_reset_n; // From phy_top0 of phy_top.v
+ output ddr_parity;
+ output ddr_we_n; // From phy_top0 of phy_top.v
+ output dfi_init_complete;
+ output [MC_ERR_ADDR_WIDTH-1:0] ecc_err_addr;
+ output [3:0] ecc_multiple;
+ output [3:0] ecc_single;
+ output pd_PSEN; // From phy_top0 of phy_top.v
+ output pd_PSINCDEC; // From phy_top0 of phy_top.v
+ output [255:0] dbg_phy_pd;
+ output [255:0] dbg_phy_read;
+ output [255:0] dbg_phy_rdlvl;
+ output [255:0] dbg_phy_top;
+ output [(4*PAYLOAD_WIDTH)-1:0] rd_data;
+ output [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr;// From mc0 of mc.v
+ output rd_data_en; // From mc0 of mc.v
+ output rd_data_end; // From mc0 of mc.v
+ output [DATA_BUF_OFFSET_WIDTH-1:0] rd_data_offset;// From mc0 of mc.v
+ output [19:0] dbg_rsync_tap_cnt;
+ output [DATA_BUF_ADDR_WIDTH-1:0] wr_data_addr;// From mc0 of mc.v
+ output wr_data_en; // From mc0 of mc.v
+ output [DATA_BUF_OFFSET_WIDTH-1:0] wr_data_offset;// From mc0 of mc.v
+ // End of automatics
+
+ /*AUTOINOUT*/
+ // Beginning of automatic inouts (from unused autoinst inouts)
+ inout [DQ_WIDTH-1:0] ddr_dq; // To/From phy_top0 of phy_top.v
+ inout [DQS_WIDTH-1:0] ddr_dqs_n; // To/From phy_top0 of phy_top.v
+ inout [DQS_WIDTH-1:0] ddr_dqs ; // To/From phy_top0 of phy_top.v
+ // End of automatics
+
+ localparam nSLOTS = 1 + (|SLOT_1_CONFIG ? 1 : 0);
+ localparam SLOT_0_CONFIG_MC = (nSLOTS == 2)? 8\'b0000_0101 : 8\'b0000_1111;
+ localparam SLOT_1_CONFIG_MC = (nSLOTS == 2)? 8\'b0000_1010 : 8\'b0000_0000;
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire [ROW_WIDTH-1:0] dfi_address0; // From mc0 of mc.v
+ wire [ROW_WIDTH-1:0] dfi_address1; // From mc0 of mc.v
+ wire [BANK_WIDTH-1:0] dfi_bank0; // From mc0 of mc.v
+ wire [BANK_WIDTH-1:0] dfi_bank1; // From mc0 of mc.v
+ wire dfi_cas_n0; // From mc0 of mc.v
+ wire dfi_cas_n1; // From mc0 of mc.v
+ wire [(CS_WIDTH*nCS_PER_RANK)-1:0] dfi_cs_n0; // From mc0 of mc.v
+ wire [(CS_WIDTH*nCS_PER_RANK)-1:0] dfi_cs_n1; // From mc0 of mc.v
+ wire [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_nom0;
+ wire [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_nom1;
+ reg [CS_WIDTH*nCS_PER_RANK-1:0] dfi_odt0_tmp;
+ reg [CS_WIDTH*nCS_PER_RANK-1:0] dfi_odt1_tmp;
+ wire [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_wr0;
+ wire [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_wr1;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_nom0_r;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_nom0_r1;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_nom0_r2;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_nom0_r3;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_nom1_r;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_nom1_r1;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_nom1_r2;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_nom1_r3;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_wr0_r;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_wr0_r1;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_wr0_r2;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_wr0_r3;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_wr1_r;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_wr1_r1;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_wr1_r2;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_wr1_r3;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_nom0_w;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_nom1_w;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_wr0_w;
+ reg [nSLOTS*nCS_PER_RANK-1:0] dfi_odt_wr1_w;
+ wire [CS_WIDTH*nCS_PER_RANK-1:0] dfi_odt0;
+ wire [CS_WIDTH*nCS_PER_RANK-1:0] dfi_odt1;
+ wire dfi_dram_clk_disable; // From mc0 of mc.v
+ wire dfi_ras_n0; // From mc0 of mc.v
+ wire dfi_ras_n1; // From mc0 of mc.v
+ wire [DQS_WIDTH-1:0] dfi_rddata_en;
+ wire dfi_rddata_valid; // From phy_top0 of phy_top.v
+ wire dfi_reset_n; // From mc0 of mc.v
+ wire dfi_we_n0; // From mc0 of mc.v
+ wire dfi_we_n1; // From mc0 of mc.v
+ wire [DQS_WIDTH-1:0] dfi_wrdata_en;
+ wire [RANK_WIDTH:0] io_config; // From mc0 of mc.v
+ wire io_config_strobe; // From mc0 of mc.v
+ wire [4*DQ_WIDTH-1:0] dfi_rddata;
+ wire [4*DQ_WIDTH-1:0] dfi_wrdata;
+ wire [4*DQ_WIDTH/8-1:0] dfi_wrdata_mask;
+
+ reg [7:0] slot_0_present_mc;
+ reg [7:0] slot_1_present_mc;
+
+ // End of automatics
+
+ reg user_periodic_rd_req = 1\'b0;
+ reg user_ref_req = 1\'b0;
+ reg user_zq_req = 1\'b0;
+
+ // assigning CWL = CL -1 for DDR2. DDR2 customers will not know anything
+ // about CWL. There is also nCWL parameter. Need to clean it up.
+ localparam CWL_T = (DRAM_TYPE == ""DDR3"") ? CWL : CL-1;
+
+ // ODT assignment from mc to phy_top based on slot config and slot present
+ // Assuming CS_WIDTH equals number of ranks configured
+ // For single slot systems slot_1_present input will be ignored
+ // Assuming component interfaces to be single slot system
+ assign dfi_odt0 = dfi_odt0_tmp;
+ assign dfi_odt1 = dfi_odt1_tmp;
+
+
+ // staging the odt from phy for delaying it based on CWL.
+
+ always @(posedge clk)begin
+ dfi_odt_nom0_r <= #TCQ dfi_odt_nom0;
+ dfi_odt_nom0_r1 <= #TCQ dfi_odt_nom0_r;
+ dfi_odt_nom0_r2 <= #TCQ dfi_odt_nom0_r1;
+ dfi_odt_nom0_r3 <= #TCQ dfi_odt_nom0_r2;
+ dfi_odt_nom1_r <= #TCQ dfi_odt_nom1;
+ dfi_odt_nom1_r1 <= #TCQ dfi_odt_nom1_r;
+ dfi_odt_nom1_r2 <= #TCQ dfi_odt_nom1_r1;
+ dfi_odt_nom1_r3 <= #TCQ dfi_odt_nom1_r2;
+
+ dfi_odt_wr0_r <= #TCQ dfi_odt_wr0;
+ dfi_odt_wr0_r1 <= #TCQ dfi_odt_wr0_r;
+ dfi_odt_wr0_r2 <= #TCQ dfi_odt_wr0_r1;
+ dfi_odt_wr0_r3 <= #TCQ dfi_odt_wr0_r2;
+ dfi_odt_wr1_r <= #TCQ dfi_odt_wr1;
+ dfi_odt_wr1_r1 <= #TCQ dfi_odt_wr1_r;
+ dfi_odt_wr1_r2 <= #TCQ dfi_odt_wr1_r1;
+ dfi_odt_wr1_r3 <= #TCQ dfi_odt_wr1_r2;
+ end // always @ (posedge clk)
+
+ generate
+ if(CWL >= 7)begin
+ always @(posedge clk) begin
+ dfi_odt_nom0_w = dfi_odt_nom0;
+ dfi_odt_nom1_w = dfi_odt_nom1;
+ dfi_odt_wr0_w = dfi_odt_wr0;
+ dfi_odt_wr1_w = dfi_odt_wr1;
+ end
+ end else begin
+ always@(*) begin
+ dfi_odt_nom0_w = dfi_odt_nom0;
+ dfi_odt_nom1_w = dfi_odt_nom1;
+ dfi_odt_wr0_w = dfi_odt_wr0;
+ dfi_odt_wr1_w = dfi_odt_wr1;
+ end
+ end
+ endgenerate
+
+
+ generate
+ if (nSLOTS == 1) begin: gen_single_slot_odt
+ always @ (slot_0_present[0] or slot_0_present[1]
+ or slot_0_present[2] or slot_0_present[3]
+ or dfi_odt_nom0_w or dfi_odt_nom1_w
+ or dfi_odt_wr0_w or dfi_odt_wr1_w) begin
+ slot_0_present_mc = slot_0_present;
+ slot_1_present_mc = slot_1_present;
+ dfi_odt0_tmp = {CS_WIDTH*nCS_PER_RANK{1\'b0}};
+ dfi_odt1_tmp = {CS_WIDTH*nCS_PER_RANK{1\'b0}};
+ dfi_odt0_tmp[nCS_PER_RANK-1:0] = dfi_odt_wr0_w[nCS_PER_RANK-1:0]
+ | dfi_odt_nom0_w[nCS_PER_RANK-1:0];
+ dfi_odt1_tmp[nCS_PER_RANK-1:0]= dfi_odt_wr1_w[nCS_PER_RANK-1:0]
+ | dfi_odt_nom1_w[nCS_PER_RANK-1:0];
+ end
+ end else if (nSLOTS == 2) begin: gen_dual_slot_odt
+ //ODT assignment fixed for nCS_PER_RANK =1. Need to change for others
+ always @ (slot_0_present[0] or slot_0_present[1]
+ or slot_1_present[0] or slot_1_present[1]
+ or dfi_odt_nom0_w or dfi_odt_nom1_w
+ or dfi_odt_wr0_w or dfi_odt_wr1_w) begin
+
+ dfi_odt0_tmp = {CS_WIDTH*nCS_PER_RANK{1\'b0}};
+ dfi_odt1_tmp = {CS_WIDTH*nCS_PER_RANK{1\'b0}};
+ case ({slot_0_present[0],slot_0_present[1],
+ slot_1_present[0],slot_1_present[1]})
+ //Two slot configuration, one slot present, single rank
+ 4\'b1000: begin
+ dfi_odt0_tmp[0] = dfi_odt_nom0_w[0];
+ dfi_odt1_tmp[0] = dfi_odt_nom1_w[0];
+ slot_0_present_mc = 8\'b0000_0001;
+ slot_1_present_mc = 8\'b0000_0000;
+ end
+ 4\'b0010: begin
+ dfi_odt0_tmp[0] = dfi_odt_nom0_w[1];
+ dfi_odt1_tmp[0] = dfi_odt_nom1_w[1];
+ slot_0_present_mc = 8\'b0000_0000;
+ slot_1_present_mc = 8\'b0000_0010;
+ end
+ // Two slot configuration, one slot present, dual rank
+ 4\'b1100: begin
+ dfi_odt0_tmp[0] = dfi_odt_wr0_w[0];
+ dfi_odt0_tmp[1] = dfi_odt_nom0_w[0];
+ dfi_odt1_tmp[0] = dfi_odt_wr1_w[0];
+ dfi_odt1_tmp[1] = dfi_odt_nom1_w[0];
+ slot_0_present_mc = 8\'b0000_0101;
+ slot_1_present_mc = 8\'b0000_0000;
+ end
+ 4\'b0011: begin
+ dfi_odt0_tmp[1] = dfi_odt_nom0_w[1];
+ dfi_odt0_tmp[0] = dfi_odt_wr0_w[1];
+ dfi_odt1_tmp[1] = dfi_odt_nom1_w[1];
+ dfi_odt1_tmp[0] = dfi_odt_wr1_w[1];
+ slot_0_present_mc = 8\'b0000_0000;
+ slot_1_present_mc = 8\'b0000_1010;
+ end
+ // Two slot configuration, one rank per slot
+ 4\'b1010: begin
+ dfi_odt0_tmp[1:0] = {dfi_odt_nom0_w[1], dfi_odt_nom0_w[0]};
+ dfi_odt1_tmp[1:0] = {dfi_odt_nom1_w[1], dfi_odt_nom1_w[0]};
+ slot_0_present_mc = 8\'b0000_0001;
+ slot_1_present_mc = 8\'b0000_0010;
+ end
+ // Two Slots - One slot with dual rank and the other with single rank
+ 4\'b1011: begin
+ dfi_odt0_tmp[1:0] = {dfi_odt_wr0_w[1], dfi_odt_nom0_w[0]};
+ dfi_odt0_tmp[2] = dfi_odt_nom0_w[1];
+ dfi_odt1_tmp[1:0] = {dfi_odt_wr1_w[1], dfi_odt_nom1_w[0]};
+ dfi_odt1_tmp[2] = dfi_odt_nom1_w[1];
+ slot_0_present_mc = 8\'b0000_0001;
+ slot_1_present_mc = 8\'b0000_1010;
+ end
+ 4\'b1110: begin
+ dfi_odt0_tmp[2:0] = {dfi_odt_nom0_w[1], dfi_odt_nom0_w[0],
+ dfi_odt_wr0_w[0]};
+ dfi_odt1_tmp[2:0] = { dfi_odt_nom1_w[1], dfi_odt_nom1_w[0],
+ dfi_odt_wr1_w[0]};
+ slot_0_present_mc = 8\'b0000_0101;
+ slot_1_present_mc = 8\'b0000_0010;
+ end
+ // Two Slots - two ranks per slot
+ 4\'b1111: begin
+ dfi_odt0_tmp = {dfi_odt_nom0_w[1], dfi_odt_wr0_w[1],
+ dfi_odt_nom0_w[0], dfi_odt_wr0_w[0]};
+ dfi_odt1_tmp = {dfi_odt_nom1_w[1], dfi_odt_wr1_w[1],
+ dfi_odt_nom1_w[0], dfi_odt_wr1_w[0]};
+ slot_0_present_mc = 8\'b0000_0101;
+ slot_1_present_mc = 8\'b0000_1010;
+ end
+ endcase
+ end
+ end
+ endgenerate
+
+ mc #
+ (/*AUTOINSTPARAM_disabled*/
+ // Parameters
+ .TCQ(TCQ),
+ .PAYLOAD_WIDTH (PAYLOAD_WIDTH),
+ .MC_ERR_ADDR_WIDTH (MC_ERR_ADDR_WIDTH),
+ .ADDR_CMD_MODE (ADDR_CMD_MODE),
+ .BANK_WIDTH (BANK_WIDTH),
+ .BM_CNT_WIDTH (BM_CNT_WIDTH),
+ .BURST_MODE (BURST_MODE),
+ .COL_WIDTH (COL_WIDTH),
+ .CMD_PIPE_PLUS1 (CMD_PIPE_PLUS1),
+ .CS_WIDTH (CS_WIDTH),
+ .DATA_WIDTH (DATA_WIDTH),
+ .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH),
+ .DATA_BUF_OFFSET_WIDTH (DATA_BUF_OFFSET_WIDTH),
+ //.DELAY_WR_DATA_CNTRL (DELAY_WR_DATA_CNTRL),
+ .DRAM_TYPE (DRAM_TYPE),
+ .DQS_WIDTH (DQS_WIDTH),
+ .DQ_WIDTH (DQ_WIDTH),
+ .ECC (ECC),
+ .ECC_TEST_FI_XOR (ECC_TEST_FI_XOR),
+ .ECC_WIDTH (ECC_WIDTH),
+ .nBANK_MACHS (nBANK_MACHS),
+ .nCK_PER_CLK (nCK_PER_CLK),
+ .nSLOTS (nSLOTS),
+ .CL (CL),
+ .nCS_PER_RANK (nCS_PER_RANK),
+ .CWL (CWL_T),
+ .ORDERING (ORDERING),
+ .RANK_WIDTH (RANK_WIDTH),
+ .RANKS (RANKS),
+ .PHASE_DETECT (PHASE_DETECT), //to controll periodic reads
+ .ROW_WIDTH (ROW_WIDTH),
+ .RTT_NOM (RTT_NOM),
+ .RTT_WR (RTT_WR),
+ .STARVE_LIMIT (STARVE_LIMIT),
+ .SLOT_0_CONFIG (SLOT_0_CONFIG_MC),
+ .SLOT_1_CONFIG (SLOT_1_CONFIG_MC),
+ .tCK (tCK),
+ .tFAW (tFAW),
+ .tPRDI (tPRDI),
+ .tRAS (tRAS),
+ .tRCD (tRCD),
+ .tREFI (tREFI),
+ .tRFC (tRFC),
+ .tRP (tRP),
+ .tRRD (tRRD),
+ .tRTP (tRTP),
+ .tWTR (tWTR),
+ .tZQI (tZQI),
+ .tZQCS (tZQCS))
+ mc0
+ (.app_periodic_rd_req (1\'b0),
+ .app_ref_req (1\'b0),
+ .app_zq_req (1\'b0),
+ .dfi_rddata_en (dfi_rddata_en[DQS_WIDTH-1:0]),
+ .dfi_wrdata_en (dfi_wrdata_en[DQS_WIDTH-1:0]),
+ .dfi_odt_nom0 (dfi_odt_nom0),
+ .dfi_odt_wr0 (dfi_odt_wr0),
+ .dfi_odt_nom1 (dfi_odt_nom1),
+ .dfi_odt_wr1 (dfi_odt_wr1),
+ .ecc_single (ecc_single),
+ .ecc_multiple (ecc_multiple),
+ .ecc_err_addr (ecc_err_addr),
+ /*AUTOINST*/
+ // Outputs
+ .accept (accept),
+ .accept_ns (accept_ns),
+ .bank_mach_next (bank_mach_next[BM_CNT_WIDTH-1:0]),
+ .dfi_address0 (dfi_address0[ROW_WIDTH-1:0]),
+ .dfi_address1 (dfi_address1[ROW_WIDTH-1:0]),
+ .dfi_bank0 (dfi_bank0[BANK_WIDTH-1:0]),
+ .dfi_bank1 (dfi_bank1[BANK_WIDTH-1:0]),
+ .dfi_cas_n0 (dfi_cas_n0),
+ .dfi_cas_n1 (dfi_cas_n1),
+ .dfi_cs_n0 (dfi_cs_n0[(CS_WIDTH*nCS_PER_RANK)-1:0]),
+ .dfi_cs_n1 (dfi_cs_n1[(CS_WIDTH*nCS_PER_RANK)-1:0]),
+ .dfi_ras_n0 (dfi_ras_n0),
+ .dfi_ras_n1 (dfi_ras_n1),
+ .dfi_we_n0 (dfi_we_n0),
+ .dfi_we_n1 (dfi_we_n1),
+ .io_config (io_config[RANK_WIDTH:0]),
+ .io_config_strobe (io_config_strobe),
+ .rd_data_addr (rd_data_addr[DATA_BUF_ADDR_WIDTH-1:0]),
+ .rd_data_en (rd_data_en),
+ .rd_data_end (rd_data_end),
+ .rd_data_offset (rd_data_offset[DATA_BUF_OFFSET_WIDTH-1:0]),
+ .wr_data_addr (wr_data_addr[DATA_BUF_ADDR_WIDTH-1:0]),
+ .wr_data_en (wr_data_en),
+ .wr_data_offset (wr_data_offset[DATA_BUF_OFFSET_WIDTH-1:0]),
+ .dfi_dram_clk_disable (dfi_dram_clk_disable),
+ .dfi_reset_n (dfi_reset_n),
+ .dfi_rddata (dfi_rddata[4*DQ_WIDTH-1:0]),
+ .dfi_wrdata (dfi_wrdata[4*DQ_WIDTH-1:0]),
+ .dfi_wrdata_mask (dfi_wrdata_mask[4*DQ_WIDTH/8-1:0]),
+ .rd_data (rd_data[4*PAYLOAD_WIDTH-1:0]),
+ .wr_data (wr_data[4*PAYLOAD_WIDTH-1:0]),
+ .wr_data_mask (wr_data_mask[4*DATA_WIDTH/8-1:0]),
+ // Inputs
+ .correct_en (correct_en),
+ .bank (bank[BANK_WIDTH-1:0]),
+ .clk (clk),
+ .cmd (cmd[2:0]),
+ .col (col[COL_WIDTH-1:0]),
+ .data_buf_addr (data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]),
+ .dfi_init_complete (dfi_init_complete),
+ .dfi_rddata_valid (dfi_rddata_valid),
+ .hi_priority (hi_priority),
+ .rank (rank[RANK_WIDTH-1:0]),
+ .raw_not_ecc (raw_not_ecc[3:0]),
+ .fi_xor_we (fi_xor_we),
+ .fi_xor_wrdata (fi_xor_wrdata),
+ .row (row[ROW_WIDTH-1:0]),
+ .rst (rst),
+ .size (size),
+ .slot_0_present (slot_0_present_mc[7:0]),
+ .slot_1_present (slot_1_present_mc[7:0]),
+ .use_addr (use_addr));
+
+ // following calculations should be moved inside PHY
+ // odt bus should be added to PHY.
+ localparam CLK_PERIOD = tCK * nCK_PER_CLK;
+ localparam nCL = CL;
+ localparam nCWL = CWL_T;
+`ifdef MC_SVA
+ ddr2_improper_CL: assert property
+ (@(posedge clk) (~((DRAM_TYPE == ""DDR2"") && ((CL > 6) || (CL < 3)))));
+ // Not needed after the CWL fix for DDR2
+ // ddr2_improper_CWL: assert property
+ // (@(posedge clk) (~((DRAM_TYPE == ""DDR2"") && ((CL - CWL) != 1))));
+`endif
+
+ phy_top #
+ (
+ .TCQ (TCQ),
+ .REFCLK_FREQ (REFCLK_FREQ),
+ .nCS_PER_RANK (nCS_PER_RANK),
+ .CAL_WIDTH (CAL_WIDTH),
+ .CALIB_ROW_ADD (CALIB_ROW_ADD),
+ .CALIB_COL_ADD (CALIB_COL_ADD),
+ .CALIB_BA_ADD (CALIB_BA_ADD),
+ .CS_WIDTH (CS_WIDTH),
+ .nCK_PER_CLK (nCK_PER_CLK),
+ .CKE_WIDTH (CKE_WIDTH),
+ .DRAM_TYPE (DRAM_TYPE),
+ .SLOT_0_CONFIG (SLOT_0_CONFIG),
+ .SLOT_1_CONFIG (SLOT_1_CONFIG),
+ .CLK_PERIOD (CLK_PERIOD),
+ .BANK_WIDTH (BANK_WIDTH),
+ .CK_WIDTH (CK_WIDTH),
+ .COL_WIDTH (COL_WIDTH),
+ .DM_WIDTH (DM_WIDTH),
+ .DQ_CNT_WIDTH (DQ_CNT_WIDTH),
+ .DQ_WIDTH (DQ_WIDTH),
+ .DQS_CNT_WIDTH (DQS_CNT_WIDTH),
+ .DQS_WIDTH (DQS_WIDTH),
+ .DRAM_WIDTH (DRAM_WIDTH),
+ .ROW_WIDTH (ROW_WIDTH),
+ .RANK_WIDTH (RANK_WIDTH),
+ .AL (AL),
+ .BURST_MODE (BURST_MODE),
+ .BURST_TYPE (BURST_TYPE),
+ .nAL (nAL),
+ .nCL (nCL),
+ .nCWL (nCWL),
+ .tRFC (tRFC),
+ .OUTPUT_DRV (OUTPUT_DRV),
+ .REG_CTRL (REG_CTRL),
+ .RTT_NOM (RTT_NOM),
+ .RTT_WR (RTT_WR),
+ .WRLVL (WRLVL),
+ .PHASE_DETECT (PHASE_DETECT),
+ .IODELAY_HP_MODE (IODELAY_HP_MODE),
+ .IODELAY_GRP (IODELAY_GRP),
+ // Prevent the following simulation-related parameters from
+ // being overridden for synthesis - for synthesis only the
+ // default values of these parameters should be used
+ // synthesis translate_off
+ .SIM_BYPASS_INIT_CAL (SIM_BYPASS_INIT_CAL),
+ // synthesis translate_on
+ .nDQS_COL0 (nDQS_COL0),
+ .nDQS_COL1 (nDQS_COL1),
+ .nDQS_COL2 (nDQS_COL2),
+ .nDQS_COL3 (nDQS_COL3),
+ .DQS_LOC_COL0 (DQS_LOC_COL0),
+ .DQS_LOC_COL1 (DQS_LOC_COL1),
+ .DQS_LOC_COL2 (DQS_LOC_COL2),
+ .DQS_LOC_COL3 (DQS_LOC_COL3),
+ .USE_DM_PORT (USE_DM_PORT),
+ .DEBUG_PORT (DEBUG_PORT)
+ )
+ phy_top0
+ (
+ /*AUTOINST*/
+ // Outputs
+ .dfi_rddata (dfi_rddata),
+ .dfi_rddata_valid (dfi_rddata_valid),
+ .dfi_init_complete (dfi_init_complete),
+ .ddr_ck_p (ddr_ck),
+ .ddr_ck_n (ddr_ck_n),
+ .ddr_addr (ddr_addr),
+ .ddr_ba (ddr_ba),
+ .ddr_ras_n (ddr_ras_n),
+ .ddr_cas_n (ddr_cas_n),
+ .ddr_we_n (ddr_we_n),
+ .ddr_cs_n (ddr_cs_n),
+ .ddr_cke (ddr_cke),
+ .ddr_odt (ddr_odt),
+ .ddr_reset_n (ddr_reset_n),
+ .ddr_parity (ddr_parity),
+ .ddr_dm (ddr_dm),
+ .pd_PSEN (pd_PSEN),
+ .pd_PSINCDEC (pd_PSINCDEC),
+ .dbg_wrlvl_start (dbg_wrlvl_start),
+ .dbg_wrlvl_done (dbg_wrlvl_done),
+ .dbg_wrlvl_err (dbg_wrlvl_err),
+ .dbg_wl_dqs_inverted (dbg_wl_dqs_inverted),
+ .dbg_wr_calib_clk_delay (dbg_wr_calib_clk_delay),
+ .dbg_wl_odelay_dqs_tap_cnt (dbg_wl_odelay_dqs_tap_cnt),
+ .dbg_wl_odelay_dq_tap_cnt (dbg_wl_odelay_dq_tap_cnt),
+ .dbg_tap_cnt_during_wrlvl (dbg_tap_cnt_during_wrlvl),
+ .dbg_wl_edge_detect_valid (dbg_wl_edge_detect_valid),
+ .dbg_rd_data_edge_detect (dbg_rd_data_edge_detect),
+ .dbg_rdlvl_start (dbg_rdlvl_start),
+ .dbg_rdlvl_done (dbg_rdlvl_done),
+ .dbg_rdlvl_err (dbg_rdlvl_err),
+ .dbg_cpt_first_edge_cnt (dbg_cpt_first_edge_cnt),
+ .dbg_cpt_second_edge_cnt (dbg_cpt_second_edge_cnt),
+ .dbg_rd_bitslip_cnt (dbg_rd_bitslip_cnt),
+ .dbg_rd_clkdly_cnt (dbg_rd_clkdly_cnt),
+ .dbg_rd_active_dly (dbg_rd_active_dly),
+ .dbg_rd_data (dbg_rddata),
+ .dbg_cpt_tap_cnt (dbg_cpt_tap_cnt),
+ .dbg_rsync_tap_cnt (dbg_rsync_tap_cnt),
+ .dbg_dqs_tap_cnt (dbg_dqs_tap_cnt),
+ .dbg_dq_tap_cnt (dbg_dq_tap_cnt),
+ .dbg_phy_pd (dbg_phy_pd),
+ .dbg_phy_read (dbg_phy_read),
+ .dbg_phy_rdlvl (dbg_phy_rdlvl),
+ .dbg_phy_top (dbg_phy_top),
+ // Inouts
+ .ddr_dqs_p (ddr_dqs),
+ .ddr_dqs_n (ddr_dqs_n),
+ .ddr_dq (ddr_dq),
+ // Inputs
+ .clk_mem (clk_mem),
+ .clk (clk),
+ .clk_rd_base (clk_rd_base),
+ .rst (rst),
+ .slot_0_present (slot_0_present),
+ .slot_1_present (slot_1_present),
+ .dfi_address0 (dfi_address0),
+ .dfi_address1 (dfi_address1),
+ .dfi_bank0 (dfi_bank0),
+ .dfi_bank1 (dfi_bank1),
+ .dfi_cas_n0 (dfi_cas_n0),
+ .dfi_cas_n1 (dfi_cas_n1),
+ .dfi_cke0 ({CKE_WIDTH{1\'b1}}),
+ .dfi_cke1 ({CKE_WIDTH{1\'b1}}),
+ .dfi_cs_n0 (dfi_cs_n0),
+ .dfi_cs_n1 (dfi_cs_n1),
+ .dfi_odt0 (dfi_odt0),
+ .dfi_odt1 (dfi_odt1),
+ .dfi_ras_n0 (dfi_ras_n0),
+ .dfi_'b'ras_n1 (dfi_ras_n1),
+ .dfi_reset_n (dfi_reset_n),
+ .dfi_we_n0 (dfi_we_n0),
+ .dfi_we_n1 (dfi_we_n1),
+ .dfi_wrdata_en (dfi_wrdata_en[0]),
+ .dfi_wrdata (dfi_wrdata),
+ .dfi_wrdata_mask (dfi_wrdata_mask),
+ .dfi_rddata_en (dfi_rddata_en[0]),
+ .dfi_dram_clk_disable (dfi_dram_clk_disable),
+ .io_config_strobe (io_config_strobe),
+ .io_config (io_config),
+ .pd_PSDONE (pd_PSDONE),
+ .dbg_wr_dqs_tap_set (dbg_wr_dqs_tap_set),
+ .dbg_wr_dq_tap_set (dbg_wr_dq_tap_set),
+ .dbg_wr_tap_set_en (dbg_wr_tap_set_en),
+ .dbg_idel_up_all (dbg_idel_up_all),
+ .dbg_idel_down_all (dbg_idel_down_all),
+ .dbg_idel_up_cpt (dbg_idel_up_cpt),
+ .dbg_idel_down_cpt (dbg_idel_down_cpt),
+ .dbg_idel_up_rsync (dbg_idel_up_rsync),
+ .dbg_idel_down_rsync (dbg_idel_down_rsync),
+ .dbg_sel_idel_cpt (dbg_sel_idel_cpt),
+ .dbg_sel_all_idel_cpt (dbg_sel_all_idel_cpt),
+ .dbg_sel_idel_rsync (dbg_sel_idel_rsync),
+ .dbg_sel_all_idel_rsync (dbg_sel_all_idel_rsync),
+ .dbg_pd_off (dbg_pd_off),
+ .dbg_pd_maintain_off (dbg_pd_maintain_off),
+ .dbg_pd_maintain_0_only (dbg_pd_maintain_0_only),
+ .dbg_pd_inc_cpt (dbg_pd_inc_cpt),
+ .dbg_pd_dec_cpt (dbg_pd_dec_cpt),
+ .dbg_pd_inc_dqs (dbg_pd_inc_dqs),
+ .dbg_pd_dec_dqs (dbg_pd_dec_dqs),
+ .dbg_pd_disab_hyst (dbg_pd_disab_hyst),
+ .dbg_pd_disab_hyst_0 (dbg_pd_disab_hyst_0),
+ .dbg_pd_msb_sel (dbg_pd_msb_sel),
+ .dbg_pd_byte_sel (dbg_pd_byte_sel),
+ .dbg_inc_rd_fps (dbg_inc_rd_fps),
+ .dbg_dec_rd_fps (dbg_dec_rd_fps)
+ );
+
+endmodule // mem_intfc
+
+// Local Variables:
+// verilog-library-directories:(""."" ""../phy"" ""../controller"")
+// End:
+"
+"//--------------------------------------------------------------------------------
+// Project : SWITCH
+// File : reset_sync.v
+// Version : 0.2
+// Author : Shreejith S
+//
+// Description: Synchronous Reset Generation - XILINX
+//
+//-----------------------------------------------------------------------------
+//
+// (c) Copyright 2006-2008 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//------------------------------------------------------------------------------
+// Description: Both flip-flops have the same asynchronous reset signal.
+// Together the flops create a minimum of a 1 clock period
+// duration pulse which is used for synchronous reset.
+//
+// The flops are placed, using RLOCs, into the same slice.
+
+`timescale 1ps/1ps
+
+module reset_sync #(
+ parameter INITIALISE = 2\'b11
+)
+(
+ input reset_in,
+ input clk,
+ input enable,
+ output reset_out
+);
+
+
+wire reset_stage1;
+wire reset_stage2;
+
+ (* ASYNC_REG = ""TRUE"", RLOC = ""X0Y0"", INIT = ""1"" *)
+ FDPE #(
+ .INIT (INITIALISE[0])
+ ) reset_sync1 (
+ .C (clk),
+ .CE (enable),
+ .PRE(reset_in),
+ .D (1\'b0),
+ .Q (reset_stage1)
+ );
+
+ (* ASYNC_REG = ""TRUE"", RLOC = ""X0Y0"", INIT = ""1"" *)
+ FDPE #(
+ .INIT (INITIALISE[1])
+ ) reset_sync2 (
+ .C (clk),
+ .CE (enable),
+ .PRE(reset_in),
+ .D (reset_stage1),
+ .Q (reset_stage2)
+ );
+
+
+assign reset_out = reset_stage2;
+
+
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//
+// (c) Copyright 2009-2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//-----------------------------------------------------------------------------
+// Project : Virtex-6 Integrated Block for PCI Express
+// File : axi_basic_tx_thrtl_ctl.v
+// Version : 2.4
+//----------------------------------------------------------------------------//
+// File: axi_basic_tx_thrtl_ctl.v //
+// //
+// Description: //
+// TX throttle controller. Anticipates back-pressure from PCIe block and //
+// preemptively back-pressures user design (packet boundary throttling). //
+// //
+// Notes: //
+// Optional notes section. //
+// //
+// Hierarchical: //
+// axi_basic_top //
+// axi_basic_tx //
+// axi_basic_tx_thrtl_ctl //
+// //
+//----------------------------------------------------------------------------//
+
+`timescale 1ps/1ps
+
+module axi_basic_tx_thrtl_ctl #(
+ parameter C_DATA_WIDTH = 128, // RX/TX interface data width
+ parameter C_FAMILY = ""X7"", // Targeted FPGA family
+ parameter C_ROOT_PORT = ""FALSE"", // PCIe block is in root port mode
+ parameter TCQ = 1 // Clock to Q time
+ ) (
+
+ // AXI TX
+ //-----------
+ input [C_DATA_WIDTH-1:0] s_axis_tx_tdata, // TX data from user
+ input s_axis_tx_tvalid, // TX data is valid
+ input [3:0] s_axis_tx_tuser, // TX user signals
+ input s_axis_tx_tlast, // TX data is last
+
+ // User Misc.
+ //-----------
+ input user_turnoff_ok, // Turnoff OK from user
+ input user_tcfg_gnt, // Send cfg OK from user
+
+ // TRN TX
+ //-----------
+ input [5:0] trn_tbuf_av, // TX buffers available
+ input trn_tdst_rdy, // TX destination ready
+
+ // TRN Misc.
+ //-----------
+ input trn_tcfg_req, // TX config request
+ output trn_tcfg_gnt, // TX config grant
+ input trn_lnk_up, // PCIe link up
+
+ // 7 Series/Virtex6 PM
+ //-----------
+ input [2:0] cfg_pcie_link_state, // Encoded PCIe link state
+
+ // Virtex6 PM
+ //-----------
+ input cfg_pm_send_pme_to, // PM send PME turnoff msg
+ input [1:0] cfg_pmcsr_powerstate, // PMCSR power state
+ input [31:0] trn_rdllp_data, // RX DLLP data
+ input trn_rdllp_src_rdy, // RX DLLP source ready
+
+ // Virtex6/Spartan6 PM
+ //-----------
+ input cfg_to_turnoff, // Turnoff request
+ output reg cfg_turnoff_ok, // Turnoff grant
+
+ // System
+ //-----------
+ output reg tready_thrtl, // TREADY to pipeline
+ input user_clk, // user clock from block
+ input user_rst // user reset from block
+);
+
+
+// Thrtl user when TBUF hits this val
+localparam TBUF_AV_MIN = (C_DATA_WIDTH == 128) ? 5 :
+ (C_DATA_WIDTH == 64) ? 1 : 0;
+
+// Pause user when TBUF hits this val
+localparam TBUF_AV_GAP = TBUF_AV_MIN + 1;
+
+// GAP pause time - the latency from the time a packet is accepted on the TRN
+// interface to the time trn_tbuf_av from the Block will decrement.
+localparam TBUF_GAP_TIME = (C_DATA_WIDTH == 128) ? 4 : 1;
+
+// Latency time from when tcfg_gnt is asserted to when PCIe block will throttle
+localparam TCFG_LATENCY_TIME = 2\'d2;
+
+// Number of pipeline stages to delay trn_tcfg_gnt. For V6 128-bit only
+localparam TCFG_GNT_PIPE_STAGES = 3;
+
+// Throttle condition registers and constants
+reg lnk_up_thrtl;
+wire lnk_up_trig;
+wire lnk_up_exit;
+
+reg tbuf_av_min_thrtl;
+wire tbuf_av_min_trig;
+
+reg tbuf_av_gap_thrtl;
+reg [2:0] tbuf_gap_cnt;
+wire tbuf_av_gap_trig;
+wire tbuf_av_gap_exit;
+wire gap_trig_tlast;
+wire gap_trig_decr;
+reg [5:0] tbuf_av_d;
+
+reg tcfg_req_thrtl;
+reg [1:0] tcfg_req_cnt;
+reg trn_tdst_rdy_d;
+wire tcfg_req_trig;
+wire tcfg_req_exit;
+reg tcfg_gnt_log;
+
+wire pre_throttle;
+wire reg_throttle;
+wire exit_crit;
+reg reg_tcfg_gnt;
+reg trn_tcfg_req_d;
+reg tcfg_gnt_pending;
+wire wire_to_turnoff;
+reg reg_turnoff_ok;
+
+reg tready_thrtl_mux;
+
+localparam LINKSTATE_L0 = 3\'b000;
+localparam LINKSTATE_PPM_L1 = 3\'b001;
+localparam LINKSTATE_PPM_L1_TRANS = 3\'b101;
+localparam LINKSTATE_PPM_L23R_TRANS = 3\'b110;
+localparam PM_ENTER_L1 = 8\'h20;
+localparam POWERSTATE_D0 = 2\'b00;
+
+reg ppm_L1_thrtl;
+wire ppm_L1_trig;
+wire ppm_L1_exit;
+reg [2:0] cfg_pcie_link_state_d;
+reg trn_rdllp_src_rdy_d;
+
+reg ppm_L23_thrtl;
+wire ppm_L23_trig;
+reg cfg_turnoff_ok_pending;
+
+reg reg_tlast;
+
+// Throttle control state machine states and registers
+localparam IDLE = 0;
+localparam THROTTLE = 1;
+reg cur_state;
+reg next_state;
+
+reg reg_axi_in_pkt;
+wire axi_in_pkt;
+wire axi_pkt_ending;
+wire axi_throttled;
+wire axi_thrtl_ok;
+wire tx_ecrc_pause;
+
+//----------------------------------------------------------------------------//
+// THROTTLE REASON: PCIe link is down //
+// - When to throttle: trn_lnk_up deasserted //
+// - When to stop: trn_tdst_rdy assesrted //
+//----------------------------------------------------------------------------//
+assign lnk_up_trig = !trn_lnk_up;
+assign lnk_up_exit = trn_tdst_rdy;
+
+always @(posedge user_clk) begin
+ if(user_rst) begin
+ lnk_up_thrtl <= #TCQ 1\'b1;
+ end
+ else begin
+ if(lnk_up_trig) begin
+ lnk_up_thrtl <= #TCQ 1\'b1;
+ end
+ else if(lnk_up_exit) begin
+ lnk_up_thrtl <= #TCQ 1\'b0;
+ end
+ end
+end
+
+
+//----------------------------------------------------------------------------//
+// THROTTLE REASON: Transmit buffers depleted //
+// - When to throttle: trn_tbuf_av falls to 0 //
+// - When to stop: trn_tbuf_av rises above 0 again //
+//----------------------------------------------------------------------------//
+assign tbuf_av_min_trig = (trn_tbuf_av <= TBUF_AV_MIN);
+
+always @(posedge user_clk) begin
+ if(user_rst) begin
+ tbuf_av_min_thrtl <= #TCQ 1\'b0;
+ end
+ else begin
+ if(tbuf_av_min_trig) begin
+ tbuf_av_min_thrtl <= #TCQ 1\'b1;
+ end
+
+ // The exit condition for tbuf_av_min_thrtl is !tbuf_av_min_trig
+ else begin
+ tbuf_av_min_thrtl <= #TCQ 1\'b0;
+ end
+ end
+end
+
+
+//----------------------------------------------------------------------------//
+// THROTTLE REASON: Transmit buffers getting low //
+// - When to throttle: trn_tbuf_av falls below ""gap"" threshold TBUF_AV_GAP //
+// - When to stop: after TBUF_GAP_TIME cycles elapse //
+// //
+// If we\'re about to run out of transmit buffers, throttle the user for a //
+// few clock cycles to give the PCIe block time to catch up. This is //
+// needed to compensate for latency in decrementing trn_tbuf_av in the PCIe //
+// Block transmit path. //
+//----------------------------------------------------------------------------//
+
+// Detect two different scenarios for buffers getting low:
+// 1) If we see a TLAST. a new packet has been inserted into the buffer, and
+// we need to pause and let that packet ""soak in""
+assign gap_trig_tlast = (trn_tbuf_av <= TBUF_AV_GAP) &&
+ s_axis_tx_tvalid && tready_thrtl && s_axis_tx_tlast;
+
+// 2) Any time tbug_avail decrements to the TBUF_AV_GAP threshold, we need to
+// pause and make sure no other packets are about to soak in and cause the
+// buffer availability to drop further.
+assign gap_trig_decr = (trn_tbuf_av == (TBUF_AV_GAP)) &&
+ (tbuf_av_d == (TBUF_AV_GAP+1));
+
+assign gap_trig_tcfg = (tcfg_req_thrtl && tcfg_req_exit);
+assign tbuf_av_gap_trig = gap_trig_tlast || gap_trig_decr || gap_trig_tcfg;
+assign tbuf_av_gap_exit = (tbuf_gap_cnt == 0);
+
+always @(posedge user_clk) begin
+ if(user_rst) begin
+ tbuf_av_gap_thrtl <= #TCQ 1\'b0;
+ tbuf_gap_cnt <= #TCQ 3\'h0;
+ tbuf_av_d <= #TCQ 6\'h00;
+ end
+ else begin
+ if(tbuf_av_gap_trig) begin
+ tbuf_av_gap_thrtl <= #TCQ 1\'b1;
+ end
+ else if(tbuf_av_gap_exit) begin
+ tbuf_av_gap_thrtl <= #TCQ 1\'b0;
+ end
+
+ // tbuf gap counter:
+ // This logic controls the length of the throttle condition when tbufs are
+ // getting low.
+ if(tbuf_av_gap_thrtl && (cur_state == THROTTLE)) begin
+ if(tbuf_gap_cnt > 0) begin
+ tbuf_gap_cnt <= #TCQ tbuf_gap_cnt - 3\'d1;
+ end
+ end
+ else begin
+ tbuf_gap_cnt <= #TCQ TBUF_GAP_TIME;
+ end
+
+ tbuf_av_d <= #TCQ trn_tbuf_av;
+ end
+end
+
+
+//----------------------------------------------------------------------------//
+// THROTTLE REASON: Block needs to send a CFG response //
+// - When to throttle: trn_tcfg_req and user_tcfg_gnt asserted //
+// - When to stop: after trn_tdst_rdy transitions to unasserted //
+// //
+// If the block needs to send a response to a CFG packet, this will cause //
+// the subsequent deassertion of trn_tdst_rdy. When the user design permits, //
+// grant permission to the block to service request and throttle the user. //
+//----------------------------------------------------------------------------//
+assign tcfg_req_trig = trn_tcfg_req && reg_tcfg_gnt;
+assign tcfg_req_exit = (tcfg_req_cnt == 2\'d0) && !trn_tdst_rdy_d &&
+ trn_tdst_rdy;
+always @(posedge user_clk) begin
+ if(user_rst) begin
+ tcfg_req_thrtl <= #TCQ 1\'b0;
+ trn_tcfg_req_d <= #TCQ 1\'b0;
+ trn_tdst_rdy_d <= #TCQ 1\'b1;
+ reg_tcfg_gnt <= #TCQ 1\'b0;
+ tcfg_req_cnt <= #TCQ 2\'d0;
+ tcfg_gnt_pending <= #TCQ 1\'b0;
+ end
+ else begin
+ if(tcfg_req_trig) begin
+ tcfg_req_thrtl <= #TCQ 1\'b1;
+ end
+ else if(tcfg_req_exit) begin
+ tcfg_req_thrtl <= #TCQ 1\'b0;
+ end
+
+ // We need to wait the appropriate amount of time for the tcfg_gnt to
+ // ""sink in"" to the PCIe block. After that, we know that the PCIe block will
+ // not reassert trn_tdst_rdy until the CFG request has been serviced. If a
+ // new request is being service (tcfg_gnt_log == 1), then reset the timer.
+ if((trn_tcfg_req && !trn_tcfg_req_d) || tcfg_gnt_pending) begin
+ tcfg_req_cnt <= #TCQ TCFG_LATENCY_TIME;
+ end
+ else begin
+ if(tcfg_req_cnt > 0) begin
+ tcfg_req_cnt <= #TCQ tcfg_req_cnt - 2\'d1;
+ end
+ end
+
+ // Make sure tcfg_gnt_log pulses once for one clock cycle for every
+ // cfg packet request.
+ if(trn_tcfg_req && !trn_tcfg_req_d) begin
+ tcfg_gnt_pending <= #TCQ 1\'b1;
+ end
+ else if(tcfg_gnt_log) begin
+ tcfg_gnt_pending <= #TCQ 1\'b0;
+ end
+
+ trn_tcfg_req_d <= #TCQ trn_tcfg_req;
+ trn_tdst_rdy_d <= #TCQ trn_tdst_rdy;
+ reg_tcfg_gnt <= #TCQ user_tcfg_gnt;
+ end
+end
+
+
+//----------------------------------------------------------------------------//
+// THROTTLE REASON: Block needs to transition to low power state PPM L1 //
+// - When to throttle: appropriate low power state signal asserted //
+// (architecture dependent) //
+// - When to stop: cfg_pcie_link_state goes to proper value (C_ROOT_PORT //
+// dependent) //
+// //
+// If the block needs to transition to PM state PPM L1, we need to finish //
+// up what we\'re doing and throttle immediately. //
+//----------------------------------------------------------------------------//
+generate
+ // PPM L1 signals for 7 Series in RC mode
+ if((C_FAMILY == ""X7"") && (C_ROOT_PORT == ""TRUE"")) begin : x7_L1_thrtl_rp
+ assign ppm_L1_trig = (cfg_pcie_link_state_d == LINKSTATE_L0) &&
+ (cfg_pcie_link_state == LINKSTATE_PPM_L1_TRANS);
+ assign ppm_L1_exit = cfg_pcie_link_state == LINKSTATE_PPM_L1;
+ end
+
+ // PPM L1 signals for 7 Series in EP mode
+ else if((C_FAMILY == ""X7"") && (C_ROOT_PORT == ""FALSE"")) begin : x7_L1_thrtl_ep
+ assign ppm_L1_trig = (cfg_pcie_link_state_d == LINKSTATE_L0) &&
+ (cfg_pcie_link_state == LINKSTATE_PPM_L1_TRANS);
+ assign ppm_L1_exit = cfg_pcie_link_state == LINKSTATE_L0;
+ end
+
+ // PPM L1 signals for V6 in RC mode
+ else if((C_FAMILY == ""V6"") && (C_ROOT_PORT == ""TRUE"")) begin : v6_L1_thrtl_rp
+ assign ppm_L1_trig = (trn_rdllp_data[31:24] == PM_ENTER_L1) &&
+ trn_rdllp_src_rdy && !trn_rdllp_src_rdy_d;
+ assign ppm_L1_exit = cfg_pcie_link_state == LINKSTATE_PPM_L1;
+ end
+
+ // PPM L1 signals for V6 in EP mode
+ else if((C_FAMILY == ""V6"") && (C_ROOT_PORT == ""FALSE"")) begin : v6_L1_thrtl_ep
+ assign ppm_L1_trig = (cfg_pmcsr_powerstate != POWERSTATE_D0);
+ assign ppm_L1_exit = cfg_pcie_link_state == LINKSTATE_L0;
+ end
+
+ // PPM L1 detection not supported for S6
+ else begin : s6_L1_thrtl
+ assign ppm_L1_trig = 1\'b0;
+ assign ppm_L1_exit = 1\'b1;
+ end
+endgenerate
+
+always @(posedge user_clk) begin
+ if(user_rst) begin
+ ppm_L1_thrtl <= #TCQ 1\'b0;
+ cfg_pcie_link_state_d <= #TCQ 3\'b0;
+ trn_rdllp_src_rdy_d <= #TCQ 1\'b0;
+ end
+ else begin
+ if(ppm_L1_trig) begin
+ ppm_L1_thrtl <= #TCQ 1\'b1;
+ end
+ else if(ppm_L1_exit) begin
+ ppm_L1_thrtl <= #TCQ 1\'b0;
+ end
+ cfg_pcie_link_state_d <= #TCQ cfg_pcie_link_state;
+ trn_rdllp_src_rdy_d <= #TCQ trn_rdllp_src_rdy;
+ end
+end
+
+
+//----------------------------------------------------------------------------//
+// THROTTLE REASON: Block needs to transition to low power state PPM L2/3 //
+// - When to throttle: appropriate PM signal indicates a transition to //
+// L2/3 is pending or in progress (family and role dependent) //
+// - When to stop: never (the only path out of L2/3 is a full reset) //
+// //
+// If the block needs to transition to PM state PPM L2/3, we need to finish //
+// up what we\'re doing and throttle when the user gives permission. //
+//----------------------------------------------------------------------------//
+generate
+ // PPM L2/3 signals for 7 Series in RC mode
+ if((C_FAMILY == ""X7"") && (C_ROOT_PORT == ""TRUE"")) begin : x7_L23_thrtl_rp
+ assign ppm_L23_trig = (cfg_pcie_link_state_d == LINKSTATE_PPM_L23R_TRANS);
+ assign wire_to_turnoff = 1\'b0;
+ end
+
+ // PPM L2/3 signals for V6 in RC mode
+ else if((C_FAMILY == ""V6"") && (C_ROOT_PORT == ""TRUE"")) begin : v6_L23_thrtl_rp
+ assign ppm_L23_trig = cfg_pm_send_pme_to;
+ assign wire_to_turnoff = 1\'b0;
+ end
+
+ // PPM L2/3 signals in EP mode
+ else begin : L23_thrtl_ep
+ assign ppm_L23_trig = wire_to_turnoff && reg_turnoff_ok;
+
+ // PPM L2/3 signals for 7 Series in EP mode
+ // For 7 Series, cfg_to_turnoff pulses once when a turnoff request is
+ // outstanding, so we need a ""sticky"" register that grabs the request.
+ if(C_FAMILY == ""X7"") begin : x7_L23_thrtl_ep
+ reg reg_to_turnoff;
+
+ always @(posedge user_clk) begin
+ if(user_rst) begin
+ reg_to_turnoff <= #TCQ 1\'b0;
+ end
+ else begin
+ if(cfg_to_turnoff) begin
+ reg_to_turnoff <= #TCQ 1\'b1;
+ end
+ end
+ end
+
+ assign wire_to_turnoff = reg_to_turnoff;
+ end
+
+ // PPM L2/3 signals for V6/S6 in EP mode
+ // In V6 and S6, the to_turnoff signal asserts and remains asserted until
+ // turnoff_ok is asserted, so a sticky reg is not necessary.
+ else begin : v6_s6_L23_thrtl_ep
+ assign wire_to_turnoff = cfg_to_turnoff;
+ end
+
+ always @(posedge user_clk) begin
+ if(user_rst) begin
+ reg_turnoff_ok <= #TCQ 1\'b0;
+ end
+ else begin
+ reg_turnoff_ok <= #TCQ user_turnoff_ok;
+ end
+ end
+ end
+endgenerate
+
+always @(posedge user_clk) begin
+ if(user_rst) begin
+ ppm_L23_thrtl <= #TCQ 1\'b0;
+ cfg_turnoff_ok_pending <= #TCQ 1\'b0;
+ end
+ else begin
+ if(ppm_L23_trig) begin
+ ppm_L23_thrtl <= #TCQ 1\'b1;
+ end
+
+ // Make sure cfg_turnoff_ok pulses once for one clock cycle for every
+ // turnoff request.
+ if(ppm_L23_trig && !ppm_L23_thrtl) begin
+ cfg_turnoff_ok_pending <= #TCQ 1\'b1;
+ end
+ else if(cfg_turnoff_ok) begin
+ cfg_turnoff_ok_pending <= #TCQ 1\'b0;
+ end
+ end
+end
+
+
+//----------------------------------------------------------------------------//
+// Create axi_thrtl_ok. This signal determines if it\'s OK to throttle the //
+// user design on the AXI interface. Since TREADY is registered, this signal //
+// needs to assert on the cycle ~before~ we actually intend to throttle. //
+// The only time it\'s OK to throttle when TVALID is asserted is on the first //
+// beat of a new packet. Therefore, assert axi_thrtl_ok if one of the //
+// is true: //
+// 1) The user is not in a packet and is not starting one //
+// 2) The user is just finishing a packet //
+// 3) We\'re already throttled, so it\'s OK to continue throttling //
+//----------------------------------------------------------------------------//
+always @(posedge user_clk) begin
+ if(user_rst) begin
+ reg_axi_in_pkt <= #TCQ 1\'b0;
+ end
+ else begin
+ if(s_axis_tx_tvalid && s_axis_tx_tlast) begin
+ reg_axi_in_pkt <= #TCQ 1\'b0;
+ end
+ else if(tready_thrtl && s_axis_tx_tvalid) begin
+ reg_axi_in_pkt <= #TCQ 1\'b1;
+ end
+ end
+end
+
+assign axi_in_pkt = s_axis_tx_tvalid || reg_axi_in_pkt;
+assign axi_pkt_ending = s_axis_tx_tvalid && s_axis_tx_tlast;
+assign axi_throttled = !tready_thrtl;
+assign axi_thrtl_ok = !axi_in_pkt || axi_pkt_ending || axi_throttled;
+
+
+//----------------------------------------------------------------------------//
+// Throttle CTL State Machine: //
+// Throttle user design when a throttle trigger (or triggers) occur. //
+// Keep user throttled until all exit criteria have been met. //
+//----------------------------------------------------------------------------//
+
+// Immediate throttle signal. Used to ""pounce"" on a throttle opportunity when
+// we\'re seeking one
+assign pre_throttle = tbuf_av_min_trig || tbuf_av_gap_trig || lnk_up_trig
+ || tcfg_req_trig || ppm_L1_trig || ppm_L23_trig;
+
+
+// Registered throttle signals. Used to control throttle state machine
+assign reg_throttle = tbuf_av_min_thrtl || tbuf_av_gap_thrtl || lnk_up_thrtl
+ || tcfg_req_thrtl || ppm_L1_thrtl || ppm_L23_thrtl;
+
+assign exit_crit = !tbuf_av_min_thrtl && !tbuf_av_gap_thrtl && !lnk_up_thrtl
+ && !tcfg_req_thrtl && !ppm_L1_thrtl && !ppm_L23_thrtl;
+
+always @(*) begin
+ case(cur_state)
+ // IDLE: in this state we\'re waiting for a trigger event to occur. As
+ // soon as an event occurs and the user isn\'t transmitting a packet, we
+ // throttle the PCIe block and the user and next state is THROTTLE.
+ IDLE: begin
+ if(reg_throttle && axi_thrtl_ok) begin
+ // Throttle user
+ tready_thrtl_mux = 1\'b0;
+ next_state = THROTTLE;
+
+ // Assert appropriate grant signal depending on the throttle type.
+ if(tcfg_req_thrtl) begin
+ tcfg_gnt_log = 1\'b1; // For cfg request, grant the request
+ cfg_turnoff_ok = 1\'b0; //
+ end
+ else if(ppm_L23_thrtl) begin
+ tcfg_gnt_log = 1\'b0; //
+ cfg_turnoff_ok = 1\'b1; // For PM request, permit transition
+ end
+ else begin
+ tcfg_gnt_log = 1\'b0; // Otherwise do nothing
+ cfg_turnoff_ok = 1\'b0; //
+ end
+ end
+
+ // If there\'s not throttle event, do nothing
+ else begin
+ // Throttle user as soon as possible
+ tready_thrtl_mux = !(axi_thrtl_ok && pre_throttle);
+ next_state = IDLE;
+
+ tcfg_gnt_log = 1\'b0;
+ cfg_turnoff_ok = 1\'b0;
+ end
+ end
+
+ // THROTTLE: in this state the user is throttle and we\'re waiting for
+ // exit criteria, which tells us that the throttle event is over. When
+ // the exit criteria is satisfied, de-throttle the user and next state
+ // is IDLE.
+ THROTTLE: begin
+ if(exit_crit) begin
+ // Dethrottle user
+ tready_thrtl_mux = !pre_throttle;
+ next_state = IDLE;
+ end
+ else begin
+ // Throttle user
+ tready_thrtl_mux = 1\'b0;
+ next_state = THROTTLE;
+ end
+
+ // Assert appropriate grant signal depending on the throttle type.
+ if(tcfg_req_thrtl && tcfg_gnt_pending) begin
+ tcfg_gnt_log = 1\'b1; // For cfg request, grant the request
+ cfg_turnoff_ok = 1\'b0; //
+ end
+ else if(cfg_turnoff_ok_pending) begin
+ tcfg_gnt_log = 1\'b0; //
+ cfg_turnoff_ok = 1\'b1; // For PM request, permit transition
+ end
+ else begin
+ tcfg_gnt_log = 1\'b0; // Otherwise do nothing
+ cfg_turnoff_ok = 1\'b0; //
+ end
+ end
+
+ default: begin
+ tready_thrtl_mux = 1\'b0;
+ next_state = IDLE;
+ tcfg_gnt_log = 1\'b0;
+ cfg_turnoff_ok = 1\'b0;
+ end
+ endcase
+end
+
+// Synchronous logic
+always @(posedge user_clk) begin
+ if(user_rst) begin
+ // Throttle user by default until link comes up
+ cur_state <= #TCQ THROTTLE;
+
+ reg_tlast <= #TCQ 1\'b0;
+
+ tready_thrtl <= #TCQ 1\'b0;
+ end
+ else begin
+ cur_state <= #TCQ next_state;
+
+ tready_thrtl <= #TCQ tready_thrtl_mux && !tx_ecrc_pause;
+ reg_tlast <= #TCQ s_axis_tx_tlast;
+ end
+end
+
+// For X7, the PCIe block will generate the ECRC for a packet if trn_tecrc_gen
+// is asserted at SOF. In this case, the Block needs an extra data beat to
+// calculate the ECRC, but only if the following conditions are met:
+// 1) there is no empty DWORDS at the end of the packet
+// (i.e. packet length % C_DATA_WIDTH == 0)
+//
+// 2) There isn\'t a ECRC in the TLP already, as indicated by the TD bit in the
+// TLP header
+//
+// If both conditions are met, the Block will stall the TRN interface for one
+// data beat after EOF. We need to predict this stall and preemptively stall the
+// User for one beat.
+generate
+ if(C_FAMILY == ""X7"") begin : ecrc_pause_enabled
+ wire tx_ecrc_pkt;
+ reg reg_tx_ecrc_pkt;
+
+ wire [1:0] packet_fmt;
+ wire packet_td;
+ wire [2:0] header_len;
+ wire [9:0] payload_len;
+ wire [13:0] packet_len;
+ wire pause_needed;
+
+ // Grab necessary packet fields
+ assign packet_fmt = s_axis_tx_tdata[30:29];
+ assign packet_td = s_axis_tx_tdata[15];
+
+ // Calculate total packet length
+ assign header_len = packet_fmt[0] ? 3\'d4 : 3\'d3;
+ assign payload_len = packet_fmt[1] ? s_axis_tx_tdata[9:0] : 10\'h0;
+ assign packet_len = {10\'h000, header_len} + {4\'h0, payload_len};
+
+
+ // Determine if packet a ECRC pause is needed
+ if(C_DATA_WIDTH == 128) begin : packet_len_check_128
+ assign pause_needed = (packet_len[1:0] == 2\'b00) && !packet_td;
+ end
+ else begin : packet_len_check_64
+ assign pause_needed = (packet_len[0] == 1\'b0) && !packet_td;
+ end
+
+
+ // Create flag to alert TX pipeline to insert a stall
+ assign tx_ecrc_pkt = s_axis_tx_tuser[0] && pause_needed &&
+ tready_thrtl && s_axis_tx_tvalid && !reg_axi_in_pkt;
+
+ always @(posedge user_clk) begin
+ if(user_rst) begin
+ reg_tx_ecrc_pkt <= #TCQ 1\'b0;
+ end
+ else begin
+ if(tx_ecrc_pkt && !s_axis_tx_tlast) begin
+ reg_tx_ecrc_pkt <= #TCQ 1\'b1;
+ end
+ else if(tready_thrtl && s_axis_tx_tvalid && s_axis_tx_tlast) begin
+ reg_tx_ecrc_pkt <= #TCQ 1\'b0;
+ end
+ end
+ end
+
+
+ // Insert the stall now
+ assign tx_ecrc_pause = ((tx_ecrc_pkt || reg_tx_ecrc_pkt) &&
+ s_axis_tx_tlast && s_axis_tx_tvalid && tready_thrtl);
+
+ end
+ else begin : ecrc_pause_disabled
+ assign tx_ecrc_pause = 1\'b0;
+ end
+endgenerate
+
+
+// Logic for 128-bit single cycle bug fix.
+// This tcfg_gnt pipeline addresses an issue with 128-bit V6 designs where a
+// single cycle packet transmitted simultaneously with an assertion of tcfg_gnt
+// from AXI Basic causes the packet to be dropped. The packet drop occurs
+// because the 128-bit shim doesn\'t know about the tcfg_req/gnt, and therefor
+// isn\'t expecting trn_tdst_rdy to go low. Since the 128-bit shim does throttle
+// prediction just as we do, it ignores the value of trn_tdst_rdy, and
+// ultimately drops the packet when transmitting the packet to the block.
+generate
+ if(C_DATA_WIDTH == 128 && C_FAMILY == ""V6"") begin : tcfg_gnt_pipeline
+ genvar stage;
+ reg tcfg_gnt_pipe [TCFG_GNT_PIPE_STAGES:0];
+
+ // Create a configurable depth FF delay pipeline
+ for(stage = 0; stage < TCFG_GNT_PIPE_STAGES; stage = stage + 1)
+ begin : tcfg_gnt_pipeline_stage
+
+ always @(posedge user_clk) begin
+ if(user_rst) begin
+ tcfg_gnt_pipe[stage] <= #TCQ 1\'b0;
+ end
+ else begin
+ // For stage 0, insert the actual tcfg_gnt signal from logic
+ if(stage == 0) begin
+ tcfg_gnt_pipe[stage] <= #TCQ tcfg_gnt_log;
+ end
+
+ // For stages 1+, chain together
+ else begin
+ tcfg_gnt_pipe[stage] <= #TCQ tcfg_gnt_pipe[stage - 1];
+ end
+ end
+ end
+
+ // tcfg_gnt output to block assigned the last pipeline stage
+ assign trn_tcfg_gnt = tcfg_gnt_pipe[TCFG_GNT_PIPE_STAGES-1];
+ end
+ end
+ else begin : tcfg_gnt_no_pipeline
+
+ // For all other architectures, no pipeline delay needed for tcfg_gnt
+ assign trn_tcfg_gnt = tcfg_gnt_log;
+ end
+endgenerate
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2008 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : %version
+// \\ \\ Application : MIG
+// / / Filename : bank_mach.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : 7-Series
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+// Top level bank machine block. A structural block instantiating the configured
+// individual bank machines, and a common block that computes various items shared
+// by all bank machines.
+
+`timescale 1ps/1ps
+
+module mig_7series_v1_8_bank_mach #
+ (
+ parameter TCQ = 100,
+ parameter EVEN_CWL_2T_MODE = ""OFF"",
+ parameter ADDR_CMD_MODE = ""1T"",
+ parameter BANK_WIDTH = 3,
+ parameter BM_CNT_WIDTH = 2,
+ parameter BURST_MODE = ""8"",
+ parameter COL_WIDTH = 12,
+ parameter CS_WIDTH = 4,
+ parameter CL = 5,
+ parameter CWL = 5,
+ parameter DATA_BUF_ADDR_WIDTH = 8,
+ parameter DRAM_TYPE = ""DDR3"",
+ parameter EARLY_WR_DATA_ADDR = ""OFF"",
+ parameter ECC = ""OFF"",
+ parameter LOW_IDLE_CNT = 1,
+ parameter nBANK_MACHS = 4,
+ parameter nCK_PER_CLK = 2,
+ parameter nCS_PER_RANK = 1,
+ parameter nOP_WAIT = 0,
+ parameter nRAS = 20,
+ parameter nRCD = 5,
+ parameter nRFC = 44,
+ parameter nRTP = 4,
+ parameter CKE_ODT_AUX = ""FALSE"", //Parameter to turn on/off the aux_out signal
+ parameter nRP = 10,
+ parameter nSLOTS = 2,
+ parameter nWR = 6,
+ parameter nXSDLL = 512,
+ parameter ORDERING = ""NORM"",
+ parameter RANK_BM_BV_WIDTH = 16,
+ parameter RANK_WIDTH = 2,
+ parameter RANKS = 4,
+ parameter ROW_WIDTH = 16,
+ parameter RTT_NOM = ""40"",
+ parameter RTT_WR = ""120"",
+ parameter STARVE_LIMIT = 2,
+ parameter SLOT_0_CONFIG = 8\'b0000_0101,
+ parameter SLOT_1_CONFIG = 8\'b0000_1010,
+ parameter tZQCS = 64
+ )
+ (/*AUTOARG*/
+ // Outputs
+ output accept, // From bank_common0 of bank_common.v
+ output accept_ns, // From bank_common0 of bank_common.v
+ output [BM_CNT_WIDTH-1:0] bank_mach_next, // From bank_common0 of bank_common.v
+ output [ROW_WIDTH-1:0] col_a, // From arb_mux0 of arb_mux.v
+ output [BANK_WIDTH-1:0] col_ba, // From arb_mux0 of arb_mux.v
+ output [DATA_BUF_ADDR_WIDTH-1:0] col_data_buf_addr,// From arb_mux0 of arb_mux.v
+ output col_periodic_rd, // From arb_mux0 of arb_mux.v
+ output [RANK_WIDTH-1:0] col_ra, // From arb_mux0 of arb_mux.v
+ output col_rmw, // From arb_mux0 of arb_mux.v
+ output col_rd_wr,
+ output [ROW_WIDTH-1:0] col_row, // From arb_mux0 of arb_mux.v
+ output col_size, // From arb_mux0 of arb_mux.v
+ output [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr,// From arb_mux0 of arb_mux.v
+ output wire [nCK_PER_CLK-1:0] mc_ras_n,
+ output wire [nCK_PER_CLK-1:0] mc_cas_n,
+ output wire [nCK_PER_CLK-1:0] mc_we_n,
+ output wire [nCK_PER_CLK*ROW_WIDTH-1:0] mc_address,
+ output wire [nCK_PER_CLK*BANK_WIDTH-1:0] mc_bank,
+ output wire [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] mc_cs_n,
+ output wire [1:0] mc_odt,
+ output wire [nCK_PER_CLK-1:0] mc_cke,
+ output wire [3:0] mc_aux_out0,
+ output wire [3:0] mc_aux_out1,
+ output [2:0] mc_cmd,
+ output [5:0] mc_data_offset,
+ output [5:0] mc_data_offset_1,
+ output [5:0] mc_data_offset_2,
+ output [1:0] mc_cas_slot,
+ output insert_maint_r1, // From arb_mux0 of arb_mux.v
+ output maint_wip_r, // From bank_common0 of bank_common.v
+ output wire [nBANK_MACHS-1:0] sending_row,
+ output wire [nBANK_MACHS-1:0] sending_col,
+ output wire sent_col,
+ output wire sent_col_r,
+ output periodic_rd_ack_r,
+ output wire [RANK_BM_BV_WIDTH-1:0] act_this_rank_r,
+ output wire [RANK_BM_BV_WIDTH-1:0] wr_this_rank_r,
+ output wire [RANK_BM_BV_WIDTH-1:0] rd_this_rank_r,
+ output wire [(RANKS*nBANK_MACHS)-1:0] rank_busy_r,
+ output idle,
+
+ // Inputs
+ input [BANK_WIDTH-1:0] bank, // To bank0 of bank_cntrl.v
+ input [6*RANKS-1:0] calib_rddata_offset,
+ input [6*RANKS-1:0] calib_rddata_offset_1,
+ input [6*RANKS-1:0] calib_rddata_offset_2,
+ input clk, // To bank0 of bank_cntrl.v, ...
+ input [2:0] cmd, // To bank0 of bank_cntrl.v, ...
+ input [COL_WIDTH-1:0] col, // To bank0 of bank_cntrl.v
+ input [DATA_BUF_ADDR_WIDTH-1:0] data_buf_addr,// To bank0 of bank_cntrl.v
+ input init_calib_complete, // To bank_common0 of bank_common.v
+ input phy_rddata_valid, // To bank0 of bank_cntrl.v
+ input dq_busy_data, // To bank0 of bank_cntrl.v
+ input hi_priority, // To bank0 of bank_cntrl.v, ...
+ input [RANKS-1:0] inhbt_act_faw_r, // To bank0 of bank_cntrl.v
+ input [RANKS-1:0] inhbt_rd, // To bank0 of bank_cntrl.v
+ input [RANKS-1:0] inhbt_wr, // To bank0 of bank_cntrl.v
+ input [RANK_WIDTH-1:0] maint_rank_r, // To bank0 of bank_cntrl.v, ...
+ input maint_req_r, // To bank0 of bank_cntrl.v, ...
+ input maint_zq_r, // To bank0 of bank_cntrl.v, ...
+ input maint_sre_r, // To bank0 of bank_cntrl.v, ...
+ input maint_srx_r, // To bank0 of bank_cntrl.v, ...
+ input periodic_rd_r, // To bank_common0 of bank_common.v
+ input [RANK_WIDTH-1:0] periodic_rd_rank_r, // To bank0 of bank_cntrl.v
+ input phy_mc_ctl_full,
+ input phy_mc_cmd_full,
+ input phy_mc_data_full,
+ input [RANK_WIDTH-1:0] rank, // To bank0 of bank_cntrl.v
+ input [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr, // To bank0 of bank_cntrl.v
+ input rd_rmw, // To bank0 of bank_cntrl.v
+ input [ROW_WIDTH-1:0] row, // To bank0 of bank_cntrl.v
+ input rst, // To bank0 of bank_cntrl.v, ...
+ input size, // To bank0 of bank_cntrl.v
+ input [7:0] slot_0_present, // To bank_common0 of bank_common.v, ...
+ input [7:0] slot_1_present, // To bank_common0 of bank_common.v, ...
+ input use_addr
+ );
+
+ function integer clogb2 (input integer size); // ceiling logb2
+ begin
+ size = size - 1;
+ for (clogb2=1; size>1; clogb2=clogb2+1)
+ size = size >> 1;
+ end
+ endfunction // clogb2
+
+ localparam RANK_VECT_INDX = (nBANK_MACHS *RANK_WIDTH) - 1;
+ localparam BANK_VECT_INDX = (nBANK_MACHS * BANK_WIDTH) - 1;
+ localparam ROW_VECT_INDX = (nBANK_MACHS * ROW_WIDTH) - 1;
+ localparam DATA_BUF_ADDR_VECT_INDX = (nBANK_MACHS * DATA_BUF_ADDR_WIDTH) - 1;
+ localparam nRAS_CLKS = (nCK_PER_CLK == 1) ? nRAS : (nCK_PER_CLK == 2) ? ((nRAS/2) + (nRAS % 2)) : ((nRAS/4) + ((nRAS%4) ? 1 : 0));
+ localparam nWTP = CWL + ((BURST_MODE == ""4"") ? 2 : 4) + nWR;
+// Unless 2T mode, add one to nWTP_CLKS for 2:1 mode. This accounts for loss of
+// one DRAM CK due to column command to row command fixed offset. In 2T mode,
+// Add the remainder. In 4:1 mode, the fixed offset is -2. Add 2 unless in 2T
+// mode, in which case we add 1 if the remainder exceeds the fixed offset.
+ localparam nWTP_CLKS = (nCK_PER_CLK == 1)
+ ? nWTP :
+ (nCK_PER_CLK == 2)
+ ? (nWTP/2) + ((ADDR_CMD_MODE == ""2T"") ? nWTP%2 : 1) :
+ (nWTP/4) + ((ADDR_CMD_MODE == ""2T"") ? (nWTP%4 > 2 ? 2 : 1) : 2);
+ localparam RAS_TIMER_WIDTH = clogb2(((nRAS_CLKS > nWTP_CLKS)
+ ? nRAS_CLKS
+ : nWTP_CLKS) - 1);
+
+ /*AUTOINPUT*/
+ // Beginning of automatic inputs (from unused autoinst inputs)
+
+ // End of automatics
+
+ /*AUTOOUTPUT*/
+ // Beginning of automatic outputs (from unused autoinst outputs)
+
+ // End of automatics
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire accept_internal_r; // From bank_common0 of bank_common.v
+ wire accept_req; // From bank_common0 of bank_common.v
+ wire adv_order_q; // From bank_common0 of bank_common.v
+ wire [BM_CNT_WIDTH-1:0] idle_cnt; // From bank_common0 of bank_common.v
+ wire insert_maint_r; // From bank_common0 of bank_common.v
+ wire low_idle_cnt_r; // From bank_common0 of bank_common.v
+ wire maint_idle; // From bank_common0 of bank_common.v
+ wire [BM_CNT_WIDTH-1:0] order_cnt; // From bank_common0 of bank_common.v
+ wire periodic_rd_insert; // From bank_common0 of bank_common.v
+ wire [BM_CNT_WIDTH-1:0] rb_hit_busy_cnt; // From bank_common0 of bank_common.v
+ wire sent_row; // From arb_mux0 of arb_mux.v
+ wire was_priority; // From bank_common0 of bank_common.v
+ wire was_wr; // From bank_common0 of bank_common.v
+ // End of automatics
+
+ wire [RANK_WIDTH-1:0] rnk_config;
+ wire rnk_config_strobe;
+ wire rnk_config_kill_rts_col;
+ wire rnk_config_valid_r;
+
+ wire [nBANK_MACHS-1:0] rts_row;
+ wire [nBANK_MACHS-1:0] rts_col;
+ wire [nBANK_MACHS-1:0] rts_pre;
+ wire [nBANK_MACHS-1:0] col_rdy_wr;
+ wire [nBANK_MACHS-1:0] rtc;
+ wire [nBANK_MACHS-1:0] sending_pre;
+
+ wire [DATA_BUF_ADDR_VECT_INDX:0] req_data_buf_addr_r;
+ wire [nBANK_MACHS-1:0] req_size_r;
+ wire [RANK_VECT_INDX:0] req_rank_r;
+ wire [BANK_VECT_INDX:0] req_bank_r;
+ wire [ROW_VECT_INDX:0] req_row_r;
+ wire [ROW_VECT_INDX:0] col_addr;
+ wire [nBANK_MACHS-1:0] req_periodic_rd_r;
+ wire [nBANK_MACHS-1:0] req_wr_r;
+ wire [nBANK_MACHS-1:0] rd_wr_r;
+ wire [nBANK_MACHS-1:0] req_ras;
+ wire [nBANK_MACHS-1:0] req_cas;
+ wire [ROW_VECT_INDX:0] row_addr;
+ wire [nBANK_MACHS-1:0] row_cmd_wr;
+ wire [nBANK_MACHS-1:0] demand_priority;
+ wire [nBANK_MACHS-1:0] demand_act_priority;
+
+ wire [nBANK_MACHS-1:0] idle_ns;
+ wire [nBANK_MACHS-1:0] rb_hit_busy_r;
+ wire [nBANK_MACHS-1:0] bm_end;
+ wire [nBANK_MACHS-1:0] passing_open_bank;
+ wire [nBANK_MACHS-1:0] ordered_r;
+ wire [nBANK_MACHS-1:0] ordered_issued;
+ wire [nBANK_MACHS-1:0] rb_hit_busy_ns;
+ wire [nBANK_MACHS-1:0] maint_hit;
+ wire [nBANK_MACHS-1:0] idle_r;
+ wire [nBANK_MACHS-1:0] head_r;
+ wire [nBANK_MACHS-1:0] start_rcd;
+
+ wire [nBANK_MACHS-1:0] end_rtp;
+ wire [nBANK_MACHS-1:0] op_exit_req;
+ wire [nBANK_MACHS-1:0] op_exit_grant;
+ wire [nBANK_MACHS-1:0] start_pre_wait;
+
+ wire [(RAS_TIMER_WIDTH*nBANK_MACHS)-1:0] ras_timer_ns;
+
+ genvar ID;
+ generate for (ID=0; IDout delay (sim only)
+ parameter nCK_PER_CLK = 2, // # of memory clocks per CLK
+ parameter nCL = 5, // Read CAS latency
+ parameter AL = ""0"",
+ parameter nCWL = 5, // Write CAS latency
+ parameter DRAM_TYPE = ""DDR3"", // Memory I/F type: ""DDR3"", ""DDR2""
+ parameter RANKS = 1, // # of memory ranks in the system
+ parameter DQS_CNT_WIDTH = 3, // = ceil(log2(DQS_WIDTH))
+ parameter DQS_WIDTH = 8, // # of DQS (strobe)
+ parameter DRAM_WIDTH = 8, // # of DQ per DQS
+ parameter REG_CTRL = ""ON"", // ""ON"" for registered DIMM
+ parameter SIM_CAL_OPTION = ""NONE"", // Performs all calibration steps
+ parameter NUM_DQSFOUND_CAL = 3, // Number of times to iterate
+ parameter N_CTL_LANES = 3, // Number of control byte lanes
+ parameter HIGHEST_LANE = 12, // Sum of byte lanes (Data + Ctrl)
+ parameter HIGHEST_BANK = 3, // Sum of I/O Banks
+ parameter BYTE_LANES_B0 = 4\'b1111,
+ parameter BYTE_LANES_B1 = 4\'b0000,
+ parameter BYTE_LANES_B2 = 4\'b0000,
+ parameter BYTE_LANES_B3 = 4\'b0000,
+ parameter BYTE_LANES_B4 = 4\'b0000,
+ parameter DATA_CTL_B0 = 4\'hc,
+ parameter DATA_CTL_B1 = 4\'hf,
+ parameter DATA_CTL_B2 = 4\'hf,
+ parameter DATA_CTL_B3 = 4\'hf,
+ parameter DATA_CTL_B4 = 4\'hf
+ )
+ (
+ input clk,
+ input rst,
+ input dqsfound_retry,
+ // From phy_init
+ input pi_dqs_found_start,
+ input detect_pi_found_dqs,
+ input prech_done,
+ // DQSFOUND per Phaser_IN
+ input [HIGHEST_LANE-1:0] pi_dqs_found_lanes,
+
+ output reg [HIGHEST_BANK-1:0] pi_rst_stg1_cal,
+
+ // To phy_init
+ output [5:0] rd_data_offset_0,
+ output [5:0] rd_data_offset_1,
+ output [5:0] rd_data_offset_2,
+ output pi_dqs_found_rank_done,
+ output pi_dqs_found_done,
+ output reg pi_dqs_found_err,
+ output [6*RANKS-1:0] rd_data_offset_ranks_0,
+ output [6*RANKS-1:0] rd_data_offset_ranks_1,
+ output [6*RANKS-1:0] rd_data_offset_ranks_2,
+ output reg dqsfound_retry_done,
+ output reg dqs_found_prech_req,
+ //To MC
+ output [6*RANKS-1:0] rd_data_offset_ranks_mc_0,
+ output [6*RANKS-1:0] rd_data_offset_ranks_mc_1,
+ output [6*RANKS-1:0] rd_data_offset_ranks_mc_2,
+
+ input [8:0] po_counter_read_val,
+ output rd_data_offset_cal_done,
+ output fine_adjust_done,
+ output [N_CTL_LANES-1:0] fine_adjust_lane_cnt,
+ output reg ck_po_stg2_f_indec,
+ output reg ck_po_stg2_f_en,
+ output [255:0] dbg_dqs_found_cal
+ );
+
+
+ // For non-zero AL values
+ localparam nAL = (AL == ""CL-1"") ? nCL - 1 : 0;
+
+ // Adding the register dimm latency to write latency
+ localparam CWL_M = (REG_CTRL == ""ON"") ? nCWL + nAL + 1 : nCWL + nAL;
+
+ // Added to reduce simulation time
+ localparam LATENCY_FACTOR = 13;
+
+ localparam NUM_READS = (SIM_CAL_OPTION == ""NONE"") ? 7 : 1;
+
+ localparam [19:0] DATA_PRESENT = {(DATA_CTL_B4[3] & BYTE_LANES_B4[3]),
+ (DATA_CTL_B4[2] & BYTE_LANES_B4[2]),
+ (DATA_CTL_B4[1] & BYTE_LANES_B4[1]),
+ (DATA_CTL_B4[0] & BYTE_LANES_B4[0]),
+ (DATA_CTL_B3[3] & BYTE_LANES_B3[3]),
+ (DATA_CTL_B3[2] & BYTE_LANES_B3[2]),
+ (DATA_CTL_B3[1] & BYTE_LANES_B3[1]),
+ (DATA_CTL_B3[0] & BYTE_LANES_B3[0]),
+ (DATA_CTL_B2[3] & BYTE_LANES_B2[3]),
+ (DATA_CTL_B2[2] & BYTE_LANES_B2[2]),
+ (DATA_CTL_B2[1] & BYTE_LANES_B2[1]),
+ (DATA_CTL_B2[0] & BYTE_LANES_B2[0]),
+ (DATA_CTL_B1[3] & BYTE_LANES_B1[3]),
+ (DATA_CTL_B1[2] & BYTE_LANES_B1[2]),
+ (DATA_CTL_B1[1] & BYTE_LANES_B1[1]),
+ (DATA_CTL_B1[0] & BYTE_LANES_B1[0]),
+ (DATA_CTL_B0[3] & BYTE_LANES_B0[3]),
+ (DATA_CTL_B0[2] & BYTE_LANES_B0[2]),
+ (DATA_CTL_B0[1] & BYTE_LANES_B0[1]),
+ (DATA_CTL_B0[0] & BYTE_LANES_B0[0])};
+
+ localparam FINE_ADJ_IDLE = 4\'h0;
+ localparam RST_POSTWAIT = 4\'h1;
+ localparam RST_POSTWAIT1 = 4\'h2;
+ localparam RST_WAIT = 4\'h3;
+ localparam FINE_ADJ_INIT = 4\'h4;
+ localparam FINE_INC = 4\'h5;
+ localparam FINE_INC_WAIT = 4\'h6;
+ localparam FINE_INC_PREWAIT = 4\'h7;
+ localparam DETECT_PREWAIT = 4\'h8;
+ localparam DETECT_DQSFOUND = 4\'h9;
+ localparam PRECH_WAIT = 4\'hA;
+ localparam FINE_DEC = 4\'hB;
+ localparam FINE_DEC_WAIT = 4\'hC;
+ localparam FINE_DEC_PREWAIT = 4\'hD;
+ localparam FINAL_WAIT = 4\'hE;
+ localparam FINE_ADJ_DONE = 4\'hF;
+
+
+ integer k,l,m,n,p,q,r,s;
+
+ reg dqs_found_start_r;
+ reg [6*HIGHEST_BANK-1:0] rd_byte_data_offset[0:RANKS-1];
+ reg rank_done_r;
+ reg rank_done_r1;
+ reg dqs_found_done_r;
+ (* ASYNC_REG = ""TRUE"" *) reg [HIGHEST_LANE-1:0] pi_dqs_found_lanes_r1;
+ (* ASYNC_REG = ""TRUE"" *) reg [HIGHEST_LANE-1:0] pi_dqs_found_lanes_r2;
+ (* ASYNC_REG = ""TRUE"" *) reg [HIGHEST_LANE-1:0] pi_dqs_found_lanes_r3;
+ reg init_dqsfound_done_r;
+ reg init_dqsfound_done_r1;
+ reg init_dqsfound_done_r2;
+ reg init_dqsfound_done_r3;
+ reg init_dqsfound_done_r4;
+ reg init_dqsfound_done_r5;
+ reg [1:0] rnk_cnt_r;
+ reg [2:0 ] final_do_index[0:RANKS-1];
+ reg [5:0 ] final_do_max[0:RANKS-1];
+ reg [6*HIGHEST_BANK-1:0] final_data_offset[0:RANKS-1];
+ reg [6*HIGHEST_BANK-1:0] final_data_offset_mc[0:RANKS-1];
+ reg [HIGHEST_BANK-1:0] pi_rst_stg1_cal_r;
+ reg [HIGHEST_BANK-1:0] pi_rst_stg1_cal_r1;
+ reg [10*HIGHEST_BANK-1:0] retry_cnt;
+ reg dqsfound_retry_r1;
+ wire [4*HIGHEST_BANK-1:0] pi_dqs_found_lanes_int;
+ reg [HIGHEST_BANK-1:0] pi_dqs_found_all_bank;
+ reg [HIGHEST_BANK-1:0] pi_dqs_found_all_bank_r;
+ reg [HIGHEST_BANK-1:0] pi_dqs_found_any_bank;
+ reg [HIGHEST_BANK-1:0] pi_dqs_found_any_bank_r;
+ reg [HIGHEST_BANK-1:0] pi_dqs_found_err_r;
+
+ // CK/Control byte lanes fine adjust stage
+ reg fine_adjust;
+ reg [N_CTL_LANES-1:0] ctl_lane_cnt;
+ reg [3:0] fine_adj_state_r;
+ reg fine_adjust_done_r;
+ reg rst_dqs_find;
+ reg rst_dqs_find_r1;
+ reg rst_dqs_find_r2;
+ reg [5:0] init_dec_cnt;
+ reg [5:0] dec_cnt;
+ reg [5:0] inc_cnt;
+ reg final_dec_done;
+ reg init_dec_done;
+ reg first_fail_detect;
+ reg second_fail_detect;
+ reg [5:0] first_fail_taps;
+ reg [5:0] second_fail_taps;
+ reg [5:0] stable_pass_cnt;
+ reg [3:0] detect_rd_cnt;
+
+
+
+
+ //***************************************************************************
+ // Debug signals
+ //
+ //***************************************************************************
+ assign dbg_dqs_found_cal[5:0] = first_fail_taps;
+ assign dbg_dqs_found_cal[11:6] = second_fail_taps;
+ assign dbg_dqs_found_cal[12] = first_fail_detect;
+ assign dbg_dqs_found_cal[13] = second_fail_detect;
+ assign dbg_dqs_found_cal[14] = fine_adjust_done_r;
+
+
+ assign pi_dqs_found_rank_done = rank_done_r;
+ assign pi_dqs_found_done = dqs_found_done_r;
+
+ generate
+ genvar rnk_cnt;
+ if (HIGHEST_BANK == 3) begin // Three Bank Interface
+ for (rnk_cnt = 0; rnk_cnt < RANKS; rnk_cnt = rnk_cnt + 1) begin: rnk_loop
+ assign rd_data_offset_ranks_0[6*rnk_cnt+:6] = final_data_offset[rnk_cnt][5:0];
+ assign rd_data_offset_ranks_1[6*rnk_cnt+:6] = final_data_offset[rnk_cnt][11:6];
+ assign rd_data_offset_ranks_2[6*rnk_cnt+:6] = final_data_offset[rnk_cnt][17:12];
+ assign rd_data_offset_ranks_mc_0[6*rnk_cnt+:6] = final_data_offset_mc[rnk_cnt][5:0];
+ assign rd_data_offset_ranks_mc_1[6*rnk_cnt+:6] = final_data_offset_mc[rnk_cnt][11:6];
+ assign rd_data_offset_ranks_mc_2[6*rnk_cnt+:6] = final_data_offset_mc[rnk_cnt][17:12];
+ end
+ end else if (HIGHEST_BANK == 2) begin // Two Bank Interface
+ for (rnk_cnt = 0; rnk_cnt < RANKS; rnk_cnt = rnk_cnt + 1) begin: rnk_loop
+ assign rd_data_offset_ranks_0[6*rnk_cnt+:6] = final_data_offset[rnk_cnt][5:0];
+ assign rd_data_offset_ranks_1[6*rnk_cnt+:6] = final_data_offset[rnk_cnt][11:6];
+ assign rd_data_offset_ranks_2[6*rnk_cnt+:6] = \'d0;
+ assign rd_data_offset_ranks_mc_0[6*rnk_cnt+:6] = final_data_offset_mc[rnk_cnt][5:0];
+ assign rd_data_offset_ranks_mc_1[6*rnk_cnt+:6] = final_data_offset_mc[rnk_cnt][11:6];
+ assign rd_data_offset_ranks_mc_2[6*rnk_cnt+:6] = \'d0;
+ end
+ end else begin // Single Bank Interface
+ for (rnk_cnt = 0; rnk_cnt < RANKS; rnk_cnt = rnk_cnt + 1) begin: rnk_loop
+ assign rd_data_offset_ranks_0[6*rnk_cnt+:6] = final_data_offset[rnk_cnt][5:0];
+ assign rd_data_offset_ranks_1[6*rnk_cnt+:6] = \'d0;
+ assign rd_data_offset_ranks_2[6*rnk_cnt+:6] = \'d0;
+ assign rd_data_offset_ranks_mc_0[6*rnk_cnt+:6] = final_data_offset_mc[rnk_cnt][5:0];
+ assign rd_data_offset_ranks_mc_1[6*rnk_cnt+:6] = \'d0;
+ assign rd_data_offset_ranks_mc_2[6*rnk_cnt+:6] = \'d0;
+ end
+ end
+ endgenerate
+
+ // final_data_offset is used during write calibration and during
+ // normal operation. One rd_data_offset value per rank for entire
+ // interface
+ generate
+ if (HIGHEST_BANK == 3) begin // Three I/O Bank interface
+ assign rd_data_offset_0 = (~init_dqsfound_done_r2) ? rd_byte_data_offset[rnk_cnt_r][0+:6] :
+ final_data_offset[rnk_cnt_r][0+:6];
+ assign rd_data_offset_1 = (~init_dqsfound_done_r2) ? rd_byte_data_offset[rnk_cnt_r][6+:6] :
+ final_data_offset[rnk_cnt_r][6+:6];
+ assign rd_data_offset_2 = (~init_dqsfound_done_r2) ? rd_byte_data_offset[rnk_cnt_r][12+:6] :
+ final_data_offset[rnk_cnt_r][12+:6];
+ end else if (HIGHEST_BANK == 2) begin // Two I/O Bank interface
+ assign rd_data_offset_0 = (~init_dqsfound_done_r2) ? rd_byte_data_offset[rnk_cnt_r][0+:6] :
+ final_data_offset[rnk_cnt_r][0+:6];
+ assign rd_data_offset_1 = (~init_dqsfound_done_r2) ? rd_byte_data_offset[rnk_cnt_r][6+:6] :
+ final_data_offset[rnk_cnt_r][6+:6];
+ assign rd_data_offset_2 = \'d0;
+ end else begin
+ assign rd_data_offset_0 = (~init_dqsfound_done_r2) ? rd_byte_data_offset[rnk_cnt_r][0+:6] :
+ final_data_offset[rnk_cnt_r][0+:6];
+ assign rd_data_offset_1 = \'d0;
+ assign rd_data_offset_2 = \'d0;
+ end
+ endgenerate
+
+ assign rd_data_offset_cal_done = init_dqsfound_done_r;
+ assign fine_adjust_lane_cnt = ctl_lane_cnt;
+
+ //**************************************************************************
+ // DQSFOUND all and any generation
+ // pi_dqs_found_all_bank[x] asserted when all Phaser_INs in Bankx are
+ // asserted
+ // pi_dqs_found_any_bank[x] asserted when at least one Phaser_IN in Bankx
+ // is asserted
+ //**************************************************************************
+
+ generate
+ if ((HIGHEST_LANE == 4) || (HIGHEST_LANE == 8) || (HIGHEST_LANE == 12))
+ assign pi_dqs_found_lanes_int = pi_dqs_found_lanes_r3;
+ else if ((HIGHEST_LANE == 7) || (HIGHEST_LANE == 11))
+ assign pi_dqs_found_lanes_int = {1\'b0, pi_dqs_found_lanes_r3};
+ else if ((HIGHEST_LANE == 6) || (HIGHEST_LANE == 10))
+ assign pi_dqs_found_lanes_int = {2\'b00, pi_dqs_found_lanes_r3};
+ else if ((HIGHEST_LANE == 5) || (HIGHEST_LANE == 9))
+ assign pi_dqs_found_lanes_int = {3\'b000, pi_dqs_found_lanes_r3};
+ endgenerate
+
+ always @(posedge clk) begin
+ if (rst) begin
+ for (k = 0; k < HIGHEST_BANK; k = k + 1) begin: rst_pi_dqs_found
+ pi_dqs_found_all_bank[k] <= #TCQ \'b0;
+ pi_dqs_found_any_bank[k] <= #TCQ \'b0;
+ end
+ end else if (pi_dqs_found_start) begin
+ for (p = 0; p < HIGHEST_BANK; p = p +1) begin: assign_pi_dqs_found
+ pi_dqs_found_all_bank[p] <= #TCQ (!DATA_PRESENT[4*p+0] | pi_dqs_found_lanes_int[4*p+0]) &
+ (!DATA_PRESENT[4*p+1] | pi_dqs_found_lanes_int[4*p+1]) &
+ (!DATA_PRESENT[4*p+2] | pi_dqs_found_lanes_int[4*p+2]) &
+ (!DATA_PRESENT[4*p+3] | pi_dqs_found_lanes_int[4*p+3]);
+ pi_dqs_found_any_bank[p] <= #TCQ (DATA_PRESENT[4*p+0] & pi_dqs_found_lanes_int[4*p+0]) |
+ (DATA_PRESENT[4*p+1] & pi_dqs_found_lanes_int[4*p+1]) |
+ (DATA_PRESENT[4*p+2] & pi_dqs_found_lanes_int[4*p+2]) |
+ (DATA_PRESENT[4*p+3] & pi_dqs_found_lanes_int[4*p+3]);
+ end
+ end
+ end
+
+
+ always @(posedge clk) begin
+ pi_dqs_found_all_bank_r <= #TCQ pi_dqs_found_all_bank;
+ pi_dqs_found_any_bank_r <= #TCQ pi_dqs_found_any_bank;
+ end
+
+//*****************************************************************************
+// Counter to increase number of 4 back-to-back reads per rd_data_offset and
+// per CK/A/C tap value
+//*****************************************************************************
+
+ always @(posedge clk) begin
+ if (rst || (detect_rd_cnt == \'d0))
+\t detect_rd_cnt <= #TCQ NUM_READS;
+\telse if (detect_pi_found_dqs && (detect_rd_cnt > \'d0))
+\t detect_rd_cnt <= #TCQ detect_rd_cnt - 1;
+ end
+
+ //**************************************************************************
+ // Adjust Phaser_Out stage 2 taps on CK/Address/Command/Controls
+ //
+ //**************************************************************************
+
+ assign fine_adjust_done = fine_adjust_done_r;
+
+ always @(posedge clk) begin
+ rst_dqs_find_r1 <= #TCQ rst_dqs_find;
+\t rst_dqs_find_r2 <= #TCQ rst_dqs_find_r1;
+ end
+
+ always @(posedge clk) begin
+ if(rst)begin
+ fine_adjust <= #TCQ 1\'b0;
+ ctl_lane_cnt <= #TCQ \'d0;
+ fine_adj_state_r <= #TCQ FINE_ADJ_IDLE;
+ fine_adjust_done_r <= #TCQ 1\'b0;
+ ck_po_stg2_f_indec <= #TCQ 1\'b0;
+ ck_po_stg2_f_en <= #TCQ 1\'b0;
+ rst_dqs_find <= #TCQ 1\'b0;
+ init_dec_cnt <= #TCQ \'d31;
+ dec_cnt <= #TCQ \'d0;
+ inc_cnt <= #TCQ \'d0;
+ init_dec_done <= #TCQ 1\'b0;
+ final_dec_done <= #TCQ 1\'b0;
+ first_fail_detect <= #TCQ 1\'b0;
+ second_fail_detect <= #TCQ 1\'b0;
+ first_fail_taps <= #TCQ \'d0;
+ second_fail_taps <= #TCQ \'d0;
+ stable_pass_cnt <= #TCQ \'d0;
+ dqs_found_prech_req<= #TCQ 1\'b0;
+ end else begin
+ case (fine_adj_state_r)
+
+ FINE_ADJ_IDLE: begin
+ if (init_dqsfound_done_r5) begin
+ if (SIM_CAL_OPTION == ""FAST_CAL"") begin
+ fine_adjust <= #TCQ 1\'b1;
+ fine_adj_state_r <= #TCQ FINE_ADJ_DONE;
+ rst_dqs_find <= #TCQ 1\'b0;
+ end else begin
+ fine_adjust <= #TCQ 1\'b1;
+ fine_adj_state_r <= #TCQ RST_WAIT;
+ rst_dqs_find <= #TCQ 1\'b1;
+ end
+ end
+ end
+
+ RST_WAIT: begin
+ if (~(|pi_dqs_found_any_bank) && rst_dqs_find_r2) begin
+ rst_dqs_find <= #TCQ 1\'b0;
+ if (|init_dec_cnt)
+ fine_adj_state_r <= #TCQ FINE_DEC_PREWAIT;
+ else if (final_dec_done)
+ fine_adj_state_r <= #TCQ FINE_ADJ_DONE;
+ else
+ fine_adj_state_r <= #TCQ RST_POSTWAIT;
+ end
+ end
+
+ RST_POSTWAIT: begin
+ fine_adj_state_r <= #TCQ RST_POSTWAIT1;
+ end
+
+ RST_POSTWAIT1: begin
+ fine_adj_state_r <= #TCQ FINE_ADJ_INIT;
+ end
+
+ FINE_ADJ_INIT: begin
+ //if (detect_pi_found_dqs && (inc_cnt < \'d63))
+ fine_adj_state_r <= #TCQ FINE_INC;
+ end
+
+ FINE_INC: begin
+ fine_adj_state_r <= #TCQ FINE_INC_WAIT;
+ ck_po_stg2_f_indec <= #TCQ 1\'b1;
+ ck_po_stg2_f_en <= #TCQ 1\'b1;
+ if (ctl_lane_cnt == N_CTL_LANES-1)
+ inc_cnt <= #TCQ inc_cnt + 1;
+ end
+
+ FINE_INC_WAIT: begin
+ ck_po_stg2_f_indec <= #TCQ 1\'b0;
+ ck_po_stg2_f_en <= #TCQ 1\'b0;
+ if (ctl_lane_cnt != N_CTL_LANES-1) begin
+ ctl_lane_cnt <= #TCQ ctl_lane_cnt + 1;
+ fine_adj_state_r <= #TCQ FINE_INC_PREWAIT;
+ end else if (ctl_lane_cnt == N_CTL_LANES-1) begin
+ ctl_lane_cnt <= #TCQ \'d0;
+ fine_adj_state_r <= #TCQ DETECT_PREWAIT;
+ end
+ end
+
+ FINE_INC_PREWAIT: begin
+ fine_adj_state_r <= #TCQ FINE_INC;
+ end
+
+ DETECT_PREWAIT: begin
+ if (detect_pi_found_dqs && (detect_rd_cnt == \'d1))
+ fine_adj_state_r <= #TCQ DETECT_DQSFOUND;
+\t\t\t else
+\t\t\t fine_adj_state_r <= #TCQ DETECT_PREWAIT;
+ end
+
+ DETECT_DQSFOUND: begin
+ if (detect_pi_found_dqs && ~(&pi_dqs_found_all_bank)) begin
+ stable_pass_cnt <= #TCQ \'d0;
+ if (~first_fail_detect && (inc_cnt == \'d63)) begin
+ // First failing tap detected at 63 taps
+ // then decrement to 31
+ first_fail_detect <= #TCQ 1\'b1;
+ first_fail_taps <= #TCQ inc_cnt;
+ fine_adj_state_r <= #TCQ FINE_DEC;
+ dec_cnt <= #TCQ \'d32;
+ end else if (~first_fail_detect && (inc_cnt > \'d30) && (stable_pass_cnt > \'d29)) begin
+ // First failing tap detected at greater than 30 taps
+ // then stop looking for second edge and decrement
+ first_fail_detect <= #TCQ 1\'b1;
+ first_fail_taps <= #TCQ inc_cnt;
+ fine_adj_state_r <= #TCQ FINE_DEC;
+ dec_cnt <= #TCQ (inc_cnt>>1) + 1;\t\t\t\t
+\t\t\t end else if (~first_fail_detect || (first_fail_detect && (stable_pass_cnt < \'d30) && (inc_cnt <= \'d32))) begin
+ // First failing tap detected, continue incrementing
+ // until either second failing tap detected or 63
+ first_fail_detect <= #TCQ 1\'b1;
+ first_fail_taps <= #TCQ inc_cnt;
+ rst_dqs_find <= #TCQ 1\'b1;
+ if ((inc_cnt == \'d12) || (inc_cnt == \'d24)) begin
+ dqs_found_prech_req <= #TCQ 1\'b1;
+ fine_adj_state_r <= #TCQ PRECH_WAIT;
+ end else
+ fine_adj_state_r <= #TCQ RST_WAIT;
+ end else if (first_fail_detect && (inc_cnt > \'d32) && (inc_cnt < \'d63) && (stable_pass_cnt < \'d30)) begin
+ // Consecutive 30 taps of passing region was not found
+ // continue incrementing
+ first_fail_detect <= #TCQ 1\'b1;
+ first_fail_taps <= #TCQ inc_cnt;
+ rst_dqs_find <= #TCQ 1\'b1;
+ if ((inc_cnt == \'d36) || (inc_cnt == \'d48) || (inc_cnt == \'d60)) begin
+ dqs_found_prech_req <= #TCQ 1\'b1;
+ fine_adj_state_r <= #TCQ PRECH_WAIT;
+ end else
+ fine_adj_state_r <= #TCQ RST_WAIT;
+ end else if (first_fail_detect && (inc_cnt == \'d63)) begin
+ if (stable_pass_cnt < \'d30) begin
+ // Consecutive 30 taps of passing region was not found
+ // from tap 0 to 63 so decrement back to 31
+ first_fail_detect <= #TCQ 1\'b1;
+ first_fail_taps <= #TCQ inc_cnt;
+ fine_adj_state_r <= #TCQ FINE_DEC;
+ dec_cnt <= #TCQ \'d32;
+ end else begin
+ // Consecutive 30 taps of passing region was found
+ // between first_fail_taps and 63
+ fine_adj_state_r <= #TCQ FINE_DEC;
+ dec_cnt <= #TCQ ((inc_cnt - first_fail_taps)>>1);
+ end
+ end else begin
+ // Second failing tap detected, decrement to center of
+ // failing taps
+ second_fail_detect <= #TCQ 1\'b1;
+ second_fail_taps <= #TCQ inc_cnt;
+ dec_cnt <= #TCQ ((inc_cnt - first_fail_taps)>>1);
+ fine_adj_state_r <= #TCQ FINE_DEC;
+ end
+ end else if (detect_pi_found_dqs && (&pi_dqs_found_all_bank)) begin
+ stable_pass_cnt <= #TCQ stable_pass_cnt + 1;
+ if ((inc_cnt == \'d12) || (inc_cnt == \'d24) || (inc_cnt == \'d36) ||
+ (inc_cnt == \'d48) || (inc_cnt == \'d60)) begin
+ dqs_found_prech_req <= #TCQ 1\'b1;
+ fine_adj_state_r <= #TCQ PRECH_WAIT;
+ end else if (inc_cnt < \'d63) begin
+ rst_dqs_find <= #TCQ 1\'b1;
+ fine_adj_state_r <= #TCQ RST_WAIT;
+ end else begin
+ fine_adj_state_r <= #TCQ FINE_DEC;
+ if (~first_fail_detect || (first_fail_taps > \'d33))
+ // No failing taps detected, decrement by 31
+ dec_cnt <= #TCQ \'d32;
+ //else if (first_fail_detect && (stable_pass_cnt > \'d28))
+ // // First failing tap detected between 0 and 34
+ // // decrement midpoint between 63 and failing tap
+ // dec_cnt <= #TCQ ((inc_cnt - first_fail_taps)>>1);
+ else
+ // First failing tap detected
+ // decrement to midpoint between 63 and failing tap
+ dec_cnt <= #TCQ ((inc_cnt - first_fail_taps)>>1);
+ end
+ end
+ end
+
+ PRECH_WAIT: begin
+ if (prech_done) begin
+ dqs_found_prech_req <= #TCQ 1\'b0;
+ rst_dqs_find <= #TCQ 1\'b1;
+ fine_adj_state_r <= #TCQ RST_WAIT;
+ end
+ end
+
+
+ FINE_DEC: begin
+ fine_adj_state_r <= #TCQ FINE_DEC_WAIT;
+ ck_po_stg2_f_indec <= #TCQ 1\'b0;
+ ck_po_stg2_f_en <= #TCQ 1\'b1;
+ if ((ctl_lane_cnt == N_CTL_LANES-1) && (init_dec_cnt > \'d0))
+ init_dec_cnt <= #TCQ init_dec_cnt - 1;
+ else if ((ctl_lane_cnt == N_CTL_LANES-1) && (dec_cnt > \'d0))
+ dec_cnt <= #TCQ dec_cnt - 1;
+ end
+
+ FINE_DEC_WAIT: begin
+ ck_po_stg2_f_indec <= #TCQ 1\'b0;
+ ck_po_stg2_f_en <= #TCQ 1\'b0;
+ if (ctl_lane_cnt != N_CTL_LANES-1) begin
+ ctl_lane_cnt <= #TCQ ctl_lane_cnt + 1;
+ fine_adj_state_r <= #TCQ FINE_DEC_PREWAIT;
+ end else if (ctl_lane_cnt == N_CTL_LANES-1) begin
+ ctl_lane_cnt <= #TCQ \'d0;
+ if ((dec_cnt > \'d0) || (init_dec_cnt > \'d0))
+ fine_adj_state_r <= #TCQ FINE_DEC_PREWAIT;
+ else begin
+ fine_adj_state_r <= #TCQ FINAL_WAIT;
+ if ((init_dec_cnt == \'d0) && ~init_dec_done)
+ init_dec_done <= #TCQ 1\'b1;
+ else
+ final_dec_done <= #TCQ 1\'b1;
+ end
+ end
+ end
+
+ FINE_DEC_PREWAIT: begin
+ fine_adj_state_r <= #TCQ FINE_DEC;
+ end
+
+ FINAL_WAIT: begin
+ rst_dqs_find <= #TCQ 1\'b1;
+ fine_adj_state_r <= #TCQ RST_WAIT;
+ end
+
+ FINE_ADJ_DONE: begin
+ if (&pi_dqs_found_all_bank) begin
+ fine_adjust_done_r <= #TCQ 1\'b1;
+ rst_dqs_find <= #TCQ 1\'b0;
+ fine_adj_state_r <= #TCQ FINE_ADJ_DONE;
+ end
+ end
+
+ endcase
+ end
+ end
+
+
+
+
+//*****************************************************************************
+
+
+ always@(posedge clk)
+ dqs_found_start_r <= #TCQ pi_dqs_found_start;
+
+
+ always @(posedge clk) begin
+ if (rst)
+ rnk_cnt_r <= #TCQ 2\'b00;
+ else if (init_dqsfound_done_r)
+ rnk_cnt_r <= #TCQ rnk_cnt_r;
+ else if (rank_done_r)
+ rnk_cnt_r <= #TCQ rnk_cnt_r + 1;
+ end
+
+ //*****************************************************************
+ // Read data_offset calibration done signal
+ //*****************************************************************
+
+ always @(posedge clk) begin
+ if (rst || (|pi_rst_stg1_cal_r))
+ init_dqsfound_done_r <= #TCQ 1\'b0;
+ else if (&pi_dqs_found_all_bank) begin
+ if (rnk_cnt_r == RANKS-1)
+ init_dqsfound_done_r <= #TCQ 1\'b1;
+ else
+ init_dqsfound_done_r <= #TCQ 1\'b0;
+ end
+ end
+
+ always @(posedge clk) begin
+ if (rst ||
+ (init_dqsfound_done_r && (rnk_cnt_r == RANKS-1)))
+ rank_done_r <= #TCQ 1\'b0;
+ else if (&pi_dqs_found_all_bank && ~(&pi_dqs_found_all_bank_r))
+ rank_done_r <= #TCQ 1\'b1;
+ else
+ rank_done_r <= #TCQ 1\'b0;
+ end
+
+ always @(posedge clk) begin
+ pi_dqs_found_lanes_r1 <= #TCQ pi_dqs_found_lanes;
+ pi_dqs_found_lanes_r2 <= #TCQ pi_dqs_found_lanes_r1;
+ pi_dqs_found_lanes_r3 <= #TCQ pi_dqs_found_lanes_r2;
+ init_dqsfound_done_r1 <= #TCQ init_dqsfound_done_r;
+ init_dqsfound_done_r2 <= #TCQ init_dqsfound_done_r1;
+ init_dqsfound_done_r3 <= #TCQ init_dqsfound_done_r2;
+ init_dqsfound_done_r4 <= #TCQ init_dqsfound_done_r3;
+ init_dqsfound_done_r5 <= #TCQ init_dqsfound_done_r4;
+ rank_done_r1 <= #TCQ rank_done_r;
+ dqsfound_retry_r1 <= #TCQ dqsfound_retry;
+ end
+
+
+ always @(posedge clk) begin
+ if (rst)
+ dqs_found_done_r <= #TCQ 1\'b0;
+ else if (&pi_dqs_found_all_bank && (rnk_cnt_r == RANKS-1) && init_dqsfound_done_r1 &&
+ (fine_adj_state_r == FINE_ADJ_DONE))
+ dqs_found_done_r <= #TCQ 1\'b1;
+ else
+ dqs_found_done_r <= #TCQ 1\'b0;
+ end
+
+
+ generate
+ if (HIGHEST_BANK == 3) begin // Three I/O Bank interface
+
+ // Reset read data offset calibration in all DQS Phaser_INs
+ // in a Bank after the read data offset value for a rank is determined
+ // or if within a Bank DQSFOUND is not asserted for all DQSs
+ always @(posedge clk) begin
+ if (rst || pi_rst_stg1_cal_r1[0] || fine_adjust)
+ pi_rst_stg1_cal_r[0] <= #TCQ 1\'b0;
+ else if ((pi_dqs_found_start && ~dqs_found_start_r) ||
+ //(dqsfound_retry[0]) ||
+ (pi_dqs_found_any_bank_r[0] && ~pi_dqs_found_all_bank[0]) ||
+ (rd_byte_data_offset[rnk_cnt_r][0+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ pi_rst_stg1_cal_r[0] <= #TCQ 1\'b1;
+ end
+
+ always @(posedge clk) begin
+ if (rst || pi_rst_stg1_cal_r1[1] || fine_adjust)
+ pi_rst_stg1_cal_r[1] <= #TCQ 1\'b0;
+ else if ((pi_dqs_found_start && ~dqs_found_start_r) ||
+ //(dqsfound_retry[1]) ||
+ (pi_dqs_found_any_bank_r[1] && ~pi_dqs_found_all_bank[1]) ||
+ (rd_byte_data_offset[rnk_cnt_r][6+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ pi_rst_stg1_cal_r[1] <= #TCQ 1\'b1;
+ end
+
+ always @(posedge clk) begin
+ if (rst || pi_rst_stg1_cal_r1[2] || fine_adjust)
+ pi_rst_stg1_cal_r[2] <= #TCQ 1\'b0;
+ else if ((pi_dqs_found_start && ~dqs_found_start_r) ||
+ //(dqsfound_retry[2]) ||
+ (pi_dqs_found_any_bank_r[2] && ~pi_dqs_found_all_bank[2]) ||
+ (rd_byte_data_offset[rnk_cnt_r][12+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ pi_rst_stg1_cal_r[2] <= #TCQ 1\'b1;
+ end
+
+ always @(posedge clk) begin
+ if (rst || fine_adjust)
+ pi_rst_stg1_cal_r1[0] <= #TCQ 1\'b0;
+ else if (pi_rst_stg1_cal_r[0])
+ pi_rst_stg1_cal_r1[0] <= #TCQ 1\'b1;
+ else if (~pi_dqs_found_any_bank_r[0] && ~pi_dqs_found_all_bank[0])
+ pi_rst_stg1_cal_r1[0] <= #TCQ 1\'b0;
+ end
+
+ always @(posedge clk) begin
+ if (rst || fine_adjust)
+ pi_rst_stg1_cal_r1[1] <= #TCQ 1\'b0;
+ else if (pi_rst_stg1_cal_r[1])
+ pi_rst_stg1_cal_r1[1] <= #TCQ 1\'b1;
+ else if (~pi_dqs_found_any_bank_r[1] && ~pi_dqs_found_all_bank[1])
+ pi_rst_stg1_cal_r1[1] <= #TCQ 1\'b0;
+ end
+
+ always @(posedge clk) begin
+ if (rst || fine_adjust)
+ pi_rst_stg1_cal_r1[2] <= #TCQ 1\'b0;
+ else if (pi_rst_stg1_cal_r[2])
+ pi_rst_stg1_cal_r1[2] <= #TCQ 1\'b1;
+ else if (~pi_dqs_found_any_bank_r[2] && ~pi_dqs_found_all_bank[2])
+ pi_rst_stg1_cal_r1[2] <= #TCQ 1\'b0;
+ end
+
+ //*****************************************************************************
+ // Retry counter to track number of DQSFOUND retries
+ //*****************************************************************************
+
+ always @(posedge clk) begin
+ if (rst || rank_done_r)
+ retry_cnt[0+:10] <= #TCQ \'b0;
+ else if ((rd_byte_data_offset[rnk_cnt_r][0+:6] > (nCL + nAL + LATENCY_FACTOR - 1)) &&
+ ~pi_dqs_found_all_bank[0])
+ retry_cnt[0+:10] <= #TCQ retry_cnt[0+:10] + 1;
+ else
+ retry_cnt[0+:10] <= #TCQ retry_cnt[0+:10];
+ end
+\t
+\t always @(posedge clk) begin
+ if (rst || rank_done_r)
+ retry_cnt[10+:10] <= #TCQ \'b0;
+ else if ((rd_byte_data_offset[rnk_cnt_r][6+:6] > (nCL + nAL + LATENCY_FACTOR - 1)) &&
+ ~pi_dqs_found_all_bank[1])
+ retry_cnt[10+:10] <= #TCQ retry_cnt[10+:10] + 1;
+ else
+ retry_cnt[10+:10] <= #TCQ retry_cnt[10+:10];
+ end
+\t
+\t always @(posedge clk) begin
+ if (rst || rank_done_r)
+ retry_cnt[20+:10] <= #TCQ \'b0;
+ else if ((rd_byte_data_offset[rnk_cnt_r][12+:6] > (nCL + nAL + LATENCY_FACTOR - 1)) &&
+ ~pi_dqs_found_all_bank[2])
+ retry_cnt[20+:10] <= #TCQ retry_cnt[20+:10] + 1;
+ else
+ retry_cnt[20+:10] <= #TCQ retry_cnt[20+:10];
+ end
+
+ // Error generation in case pi_dqs_found_all_bank
+ // is not asserted
+ always @(posedge clk) begin
+ if (rst)
+ pi_dqs_found_err_r[0] <= #TCQ 1\'b0;
+ else if (~pi_dqs_found_all_bank[0] && (retry_cnt[0+:10] == NUM_DQSFOUND_CAL) &&
+ (rd_byte_data_offset[rnk_cnt_r][0+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ pi_dqs_found_err_r[0] <= #TCQ 1\'b1;
+ end
+
+ always @(posedge clk) begin
+ if (rst)
+ pi_dqs_found_err_r[1] <= #TCQ 1\'b0;
+ else if (~pi_dqs_found_all_bank[1] && (retry_cnt[10+:10] == NUM_DQSFOUND_CAL) &&
+ (rd_byte_data_offset[rnk_cnt_r][6+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ pi_dqs_found_err_r[1] <= #TCQ 1\'b1;
+ end
+
+ always @(posedge clk) begin
+ if (rst)
+ pi_dqs_found_err_r[2] <= #TCQ 1\'b0;
+ else if (~pi_dqs_found_all_bank[2] && (retry_cnt[20+:10] == NUM_DQSFOUND_CAL) &&
+ (rd_byte_data_offset[rnk_cnt_r][12+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ pi_dqs_found_err_r[2] <= #TCQ 1\'b1;
+ end
+
+ // Read data offset value for all DQS in a Bank
+ always @(posedge clk) begin
+ if (rst) begin
+ for (q = 0; q < RANKS; q = q + 1) begin: three_bank0_rst_loop
+ rd_byte_data_offset[q][0+:6] <= #TCQ nCL + nAL - 2;
+ end
+ end else if ((rank_done_r1 && ~init_dqsfound_done_r) ||
+\t\t (rd_byte_data_offset[rnk_cnt_r][0+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ rd_byte_data_offset[rnk_cnt_r][0+:6] <= #TCQ nCL + nAL - 2;
+ else if (dqs_found_start_r && ~pi_dqs_found_all_bank[0] &&
+ //(rd_byte_data_offset[rnk_cnt_r][0+:6] < (nCL + nAL + LATENCY_FACTOR)) &&
+ (detect_pi_found_dqs && (detect_rd_cnt == \'d1)) && ~init_dqsfound_done_r && ~fine_adjust)
+ rd_byte_data_offset[rnk_cnt_r][0+:6]
+ <= #TCQ rd_byte_data_offset[rnk_cnt_r][0+:6] + 1;
+ end
+
+ always @(posedge clk) begin
+ if (rst) begin
+ for (r = 0; r < RANKS; r = r + 1) begin: three_bank1_rst_loop
+ rd_byte_data_offset[r][6+:6] <= #TCQ nCL + nAL - 2;
+ end
+ end else if ((rank_done_r1 && ~init_dqsfound_done_r) ||
+\t\t (rd_byte_data_offset[rnk_cnt_r][6+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ rd_byte_data_offset[rnk_cnt_r][6+:6] <= #TCQ nCL + nAL - 2;
+ else if (dqs_found_start_r && ~pi_dqs_found_all_bank[1] &&
+ //(rd_byte_data_offset[rnk_cnt_r][6+:6] < (nCL + nAL + LATENCY_FACTOR)) &&
+ (detect_pi_found_dqs && (detect_rd_cnt == \'d1)) && ~init_dqsfound_done_r && ~fine_adjust)
+ rd_byte_data_offset[rnk_cnt_r][6+:6]
+ <= #TCQ rd_byte_data_offset[rnk_cnt_r][6+:6] + 1;
+ end
+
+ always @(posedge clk) begin
+ if (rst) begin
+ for (s = 0; s < RANKS; s = s + 1) begin: three_bank2_rst_loop
+ rd_byte_data_offset[s][12+:6] <= #TCQ nCL + nAL - 2;
+ end
+ end else if ((rank_done_r1 && ~init_dqsfound_done_r) ||
+\t\t (rd_byte_data_offset[rnk_cnt_r][12+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ rd_byte_data_offset[rnk_cnt_r][12+:6] <= #TCQ nCL + nAL - 2;
+ else if (dqs_found_start_r && ~pi_dqs_found_all_bank[2] &&
+ //(rd_byte_data_offset[rnk_cnt_r][12+:6] < (nCL + nAL + LATENCY_FACTOR)) &&
+ (detect_pi_found_dqs && (detect_rd_cnt == \'d1)) && ~init_dqsfound_done_r && ~fine_adjust)
+ rd_byte_data_offset[rnk_cnt_r][12+:6]
+ <= #TCQ rd_byte_data_offset[rnk_cnt_r][12+:6] + 1;
+ end
+
+//*****************************************************************************
+// Two I/O Bank Interface
+//*****************************************************************************
+ end else if (HIGHEST_BANK == 2) begin // Two I/O Bank interface
+
+ // Reset read data offset calibration in all DQS Phaser_INs
+ // in a Bank after the read data offset value for a rank is determined
+ // or if within a Bank DQSFOUND is not asserted for all DQSs
+ always @(posedge clk) begin
+ if (rst || pi_rst_stg1_cal_r1[0] || fine_adjust)
+ pi_rst_stg1_cal_r[0] <= #TCQ 1\'b0;
+ else if ((pi_dqs_found_start && ~dqs_found_start_r) ||
+ //(dqsfound_retry[0]) ||
+ (pi_dqs_found_any_bank_r[0] && ~pi_dqs_found_all_bank[0]) ||
+ (rd_byte_data_offset[rnk_cnt_r][0+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ pi_rst_stg1_cal_r[0] <= #TCQ 1\'b1;
+ end
+
+ always @(posedge clk) begin
+ if (rst || pi_rst_stg1_cal_r1[1] || fine_adjust)
+ pi_rst_stg1_cal_r[1] <= #TCQ 1\'b0;
+ else if ((pi_dqs_found_start && ~dqs_found_start_r) ||
+ //(dqsfound_retry[1]) ||
+ (pi_dqs_found_any_bank_r[1] && ~pi_dqs_found_all_bank[1]) ||
+ (rd_byte_data_offset[rnk_cnt_r][6+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ pi_rst_stg1_cal_r[1] <= #TCQ 1\'b1;
+ end
+
+ always @(posedge clk) begin
+ if (rst || fine_adjust)
+ pi_rst_stg1_cal_r1[0] <= #TCQ 1\'b0;
+ else if (pi_rst_stg1_cal_r[0])
+ pi_rst_stg1_cal_r1[0] <= #TCQ 1\'b1;
+ else if (~pi_dqs_found_any_bank_r[0] && ~pi_dqs_found_all_bank[0])
+ pi_rst_stg1_cal_r1[0] <= #TCQ 1\'b0;
+ end
+
+ always @(posedge clk) begin
+ if (rst || fine_adjust)
+ pi_rst_stg1_cal_r1[1] <= #TCQ 1\'b0;
+ else if (pi_rst_stg1_cal_r[1])
+ pi_rst_stg1_cal_r1[1] <= #TCQ 1\'b1;
+ else if (~pi_dqs_found_any_bank_r[1] && ~pi_dqs_found_all_bank[1])
+ pi_rst_stg1_cal_r1[1] <= #TCQ 1\'b0;
+ end
+
+ //*****************************************************************************
+ // Retry counter to track number of DQSFOUND retries
+ //*****************************************************************************
+
+ always @(posedge clk) begin
+ if (rst || rank_done_r)
+ retry_cnt[0+:10] <= #TCQ \'b0;
+ else if ((rd_byte_data_offset[rnk_cnt_r][0+:6] > (nCL + nAL + LATENCY_FACTOR - 1)) &&
+ ~pi_dqs_found_all_bank[0])
+ retry_cnt[0+:10] <= #TCQ retry_cnt[0+:10] + 1;
+ else
+ retry_cnt[0+:10] <= #TCQ retry_cnt[0+:10];
+ end
+\t
+\t always @(posedge clk) begin
+ if (rst || rank_done_r)
+ retry_cnt[10+:10] <= #TCQ \'b0;
+ else if ((rd_byte_data_offset[rnk_cnt_r][6+:6] > (nCL + nAL + LATENCY_FACTOR - 1)) &&
+ ~pi_dqs_found_all_bank[1])
+ retry_cnt[10+:10] <= #TCQ retry_cnt[10+:10] + 1;
+ else
+ retry_cnt[10+:10] <= #TCQ retry_cnt[10+:10];
+ end
+
+
+ // Error generation in case pi_dqs_found_all_bank
+ // is not asserted
+ always @(posedge clk) begin
+ if (rst)
+ pi_dqs_found_err_r[0] <= #TCQ 1\'b0;
+ else if (~pi_dqs_found_all_bank[0] && (retry_cnt[0+:10] == NUM_DQSFOUND_CAL) &&
+ (rd_byte_data_offset[rnk_cnt_r][0+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ pi_dqs_found_err_r[0] <= #TCQ 1\'b1;
+ end
+
+ always @(posedge clk) begin
+ if (rst)
+ pi_dqs_found_err_r[1] <= #TCQ 1\'b0;
+ else if (~pi_dqs_found_all_bank[1] && (retry_cnt[10+:10] == NUM_DQSFOUND_CAL) &&
+ (rd_byte_data_offset[rnk_cnt_r][6+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ pi_dqs_found_err_r[1] <= #TCQ 1\'b1;
+ end
+
+
+ // Read data offset value for all DQS in a Bank
+ always @(posedge clk) begin
+ if (rst) begin
+ for (q = 0; q < RANKS; q = q + 1) begin: two_bank0_rst_loop
+ rd_byte_data_offset[q][0+:6] <= #TCQ nCL + nAL - 2;
+ end
+ end else if ((rank_done_r1 && ~init_dqsfound_done_r) ||
+\t\t (rd_byte_data_offset[rnk_cnt_r][0+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ rd_byte_data_offset[rnk_cnt_r][0+:6] <= #TCQ nCL + nAL - 2;
+ else if (dqs_found_start_r && ~pi_dqs_found_all_bank[0] &&
+ //(rd_byte_data_offset[rnk_cnt_r][0+:6] < (nCL + nAL + LATENCY_FACTOR)) &&
+ (detect_pi_found_dqs && (detect_rd_cnt == \'d1)) && ~init_dqsfound_done_r && ~fine_adjust)
+ rd_byte_data_offset[rnk_cnt_r][0+:6]
+ <= #TCQ rd_byte_data_offset[rnk_cnt_r][0+:6] + 1;
+ end
+
+ always @(posedge clk) begin
+ if (rst) begin
+ for (r = 0; r < RANKS; r = r + 1) begin: two_bank1_rst_loop
+ rd_byte_data_offset[r][6+:6] <= #TCQ nCL + nAL - 2;
+ end
+ end else if ((rank_done_r1 && ~init_dqsfound_done_r) ||
+\t\t (rd_byte_data_offset[rnk_cnt_r][6+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ rd_byte_data_offset[rnk_cnt_r][6+:6] <= #TCQ nCL + nAL - 2;
+ else if (dqs_found_start_r && ~pi_dqs_found_all_bank[1] &&
+ //(rd_byte_data_offset[rnk_cnt_r][6+:6] < (nCL + nAL + LATENCY_FACTOR)) &&
+ (detect_pi_found_dqs && (detect_rd_cnt == \'d1)) && ~init_dqsfound_done_r && ~fine_adjust)
+ rd_byte_data_offset[rnk_cnt_r][6+:6]
+ <= #TCQ rd_byte_data_offset[rnk_cnt_r][6+:6] + 1;
+ end
+//*****************************************************************************
+// One I/O Bank Interface
+//*****************************************************************************
+ end else begin // One I/O Bank Interface
+
+ // Read data offset value for all DQS in Bank0
+ always @(posedge clk) begin
+ if (rst) begin
+ for (l = 0; l < RANKS; l = l + 1) begin: bank_rst_loop
+ rd_byte_data_offset[l] <= #TCQ nCL + nAL - 2;
+ end
+ end else if ((rank_done_r1 && ~init_dqsfound_done_r) ||
+\t\t (rd_byte_data_offset[rnk_cnt_r] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ rd_byte_data_offset[rnk_cnt_r] <= #TCQ nCL + nAL - 2;
+ else if (dqs_found_start_r && ~pi_dqs_found_all_bank[0] &&
+ //(rd_byte_data_offset[rnk_cnt_r] < (nCL + nAL + LATENCY_FACTOR)) &&
+ (detect_pi_found_dqs && (detect_rd_cnt == \'d1)) && ~init_dqsfound_done_r && ~fine_adjust)
+ rd_byte_data_offset[rnk_cnt_r]
+ <= #TCQ rd_byte_data_offset[rnk_cnt_r] + 1;
+ end
+
+ // Reset read data offset calibration in all DQS Phaser_INs
+ // in a Bank after the read data offset value for a rank is determined
+ // or if within a Bank DQSFOUND is not asserted for all DQSs
+ always @(posedge clk) begin
+ if (rst || pi_rst_stg1_cal_r1[0] || fine_adjust)
+ pi_rst_stg1_cal_r[0] <= #TCQ 1\'b0;
+ else if ((pi_dqs_found_start && ~dqs_found_start_r) ||
+ //(dqsfound_retry[0]) ||
+ (pi_dqs_found_any_bank_r[0] && ~pi_dqs_found_all_bank[0]) ||
+ (rd_byte_data_offset[rnk_cnt_r][0+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ pi_rst_stg1_cal_r[0] <= #TCQ 1\'b1;
+ end
+
+ always @(posedge clk) begin
+ if (rst || fine_adjust)
+ pi_rst_stg1_cal_r1[0] <= #TCQ 1\'b0;
+ else if (pi_rst_stg1_cal_r[0])
+ pi_rst_stg1_cal_r1[0] <= #TCQ 1\'b1;
+ else if (~pi_dqs_found_any_bank_r[0] && ~pi_dqs_found_all_bank[0])
+ pi_rst_stg1_cal_r1[0] <= #TCQ 1\'b0;
+ end
+
+ //*****************************************************************************
+ // Retry counter to track number of DQSFOUND retries
+ //*****************************************************************************
+
+ always @(posedge clk) begin
+ if (rst || rank_done_r)
+ retry_cnt[0+:10] <= #TCQ \'b0;
+ else if ((rd_byte_data_offset[rnk_cnt_r][0+:6] > (nCL + nAL + LATENCY_FACTOR - 1)) &&
+ ~pi_dqs_found_all_bank[0])
+ retry_cnt[0+:10] <= #TCQ retry_cnt[0+:10] + 1;
+ else
+ retry_cnt[0+:10] <= #TCQ retry_cnt[0+:10];
+ end
+
+
+ // Error generation in case pi_dqs_found_all_bank
+ // is not asserted even with 3 dqfound retries
+ always @(posedge clk) begin
+ if (rst)
+ pi_dqs_found_err_r[0] <= #TCQ 1\'b0;
+ else if (~pi_dqs_found_all_bank[0] && (retry_cnt[0+:10] == NUM_DQSFOUND_CAL) &&
+ (rd_byte_data_offset[rnk_cnt_r][0+:6] > (nCL + nAL + LATENCY_FACTOR - 1)))
+ pi_dqs_found_err_r[0] <= #TCQ 1\'b1;
+ end
+
+ end
+ endgenerate
+
+ always @(posedge clk) begin
+ if (rst)
+ pi_rst_stg1_cal <= #TCQ {HIGHEST_BANK{1\'b0}};
+ else if (rst_dqs_find)
+ pi_rst_stg1_cal <= #TCQ {HIGHEST_BANK{1\'b1}};
+ else
+ pi_rst_stg1_cal <= #TCQ pi_rst_stg1_cal_r;
+ end
+
+
+
+ // Final read data offset value to be used during write calibration and
+ // normal operation
+ generate
+ genvar i;
+ genvar j;
+ for (i = 0; i < RANKS; i = i + 1) begin: rank_final_loop
+ reg [5:0] final_do_cand [RANKS-1:0];
+ // combinatorially select the candidate offset for the bank
+ // indexed by final_do_index
+ if (HIGHEST_BANK == 3) begin
+ always @(*) begin
+ case (final_do_index[i])
+\t 3\'b000: final_do_cand[i] = final_data_offset[i][5:0];
+\t 3\'b001: final_do_cand[i] = final_data_offset[i][11:6];
+\t 3\'b010: final_do_cand[i] = final_data_offset[i][17:12];
+\t default: final_do_cand[i] = \'d0;
+\t endcase
+ end
+ end else if (HIGHEST_BANK == 2) begin
+ always @(*) begin
+ case (final_do_index[i])
+\t 3\'b000: final_do_cand[i] = final_data_offset[i][5:0];
+\t 3\'b001: final_do_cand[i] = final_data_offset[i][11:6];
+\t 3\'b010: final_do_cand[i] = \'d0;
+\t default: final_do_cand[i] = \'d0;
+\t endcase
+ end
+ end else begin
+ always @(*) begin
+ case (final_do_index[i])
+\t 3\'b000: final_do_cand[i] = final_data_offset[i][5:0];
+\t 3\'b001: final_do_cand[i] = \'d0;
+\t 3\'b010: final_do_cand[i] = \'d0;
+\t default: final_do_cand[i] = \'d0;
+\t endcase
+ end
+ end
+
+ always @(posedge clk or posedge rst) begin
+ if (rst)
+\t final_do_max[i] <= #TCQ 0;
+\t else begin
+\t final_do_max[i] <= #TCQ final_do_max[i]; // default
+ case (final_do_index[i])
+\t 3\'b000: if ( | DATA_PRESENT[3:0])
+\t if (final_do_max[i] < final_do_cand[i])
+\t if (CWL_M % 2) // odd latency CAS slot 1
+\t\t final_do_max[i] <= #TCQ final_do_cand[i] - 1;
+\t\t else
+\t\t final_do_max[i] <= #TCQ final_do_cand[i];
+\t 3\'b001: if ( | DATA_PRESENT[7:4])
+\t if (final_do_max[i] < final_do_cand[i])
+\t\t if (CWL_M % 2) // odd latency CAS slot 1
+\t\t final_do_max[i] <= #TCQ final_do_cand[i] - 1;
+\t\t else
+\t\t final_do_max[i] <= #TCQ final_do_cand[i];
+\t 3\'b010: if ( | DATA_PRESENT[11:8])
+\t if (final_do_max[i] < final_do_cand[i])
+\t\t if (CWL_M % 2) // odd latency CAS slot 1
+\t\t final_do_max[i] <= #TCQ final_do_cand[i] - 1;
+\t\t else
+\t\t final_do_max[i] <= #TCQ final_do_cand[i];
+ default:
+\t final_do_max[i] <= #TCQ final_do_max[i];
+\t endcase
+\t end
+\tend
+
+\talways @(posedge clk)
+\t if (rst) begin
+\t final_do_index[i] <= #TCQ 0;
+\t end
+\t else begin
+\t final_do_index[i] <= #TCQ final_do_index[i] + 1;
+\t end
+
+ for (j = 0; j < HIGHEST_BANK; j = j + 1) begin: bank_final_loop
+
+ always @(posedge clk) begin
+ if (rst) begin
+ final_data_offset[i][6*j+:6] <= #TCQ \'b0;
+\t end
+ else begin
+\t //if (dqsfound_retry[j])
+ // final_data_offset[i][6*j+:6] <= #TCQ rd_byte_data_offset[i][6*j+:6];
+ //else
+ if (init_dqsfound_done_r && ~init_dqsfound_done_r1) begin
+\t if ( DATA_PRESENT [ j*4+:4] != 0) begin // has a data lane
+ final_data_offset[i][6*j+:6] <= #TCQ rd_byte_data_offset[i][6*j+:6];
+ if (CWL_M % 2) // odd latency CAS slot 1
+ final_data_offset_mc[i][6*j+:6] <= #TCQ rd_byte_data_offset[i][6*j+:6] - 1;
+ else // even latency CAS slot 0
+ final_data_offset_mc[i][6*j+:6] <= #TCQ rd_byte_data_offset[i][6*j+:6];
+ end
+\t end
+ else if (init_dqsfound_done_r5 ) begin
+\t if ( DATA_PRESENT [ j*4+:4] == 0) begin // all control lanes
+ final_data_offset[i][6*j+:6] <= #TCQ final_do_max[i];
+ final_data_offset_mc[i][6*j+:6] <= #TCQ final_do_max[i];
+ end\t
+ end
+\t end
+ end
+ end
+ end
+ endgenerate
+
+
+ // Error generation in case pi_found_dqs signal from Phaser_IN
+ // is not asserted when a common rddata_offset value is used
+
+ always @(posedge clk) begin
+ pi_dqs_found_err <= #TCQ |pi_dqs_found_err_r;
+ end
+
+
+
+endmodule
+
+
+
+
+
+
+"
+"//*****************************************************************************
+// (c) Copyright 2008 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : %version
+// \\ \\ Application : MIG
+// / / Filename : rank_cntrl.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : 7-Series
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+//*****************************************************************************
+// This block is responsible for managing various rank level timing
+// parameters. For now, only Four Activate Window (FAW) and Write
+// To Read delay are implemented here.
+//
+// Each rank machine generates its own inhbt_act_faw_r and inhbt_rd.
+// These per rank machines are driven into the bank machines. Each
+// bank machines selects the correct inhibits based on the rank
+// of its current request.
+//*****************************************************************************
+
+`timescale 1 ps / 1 ps
+
+module mig_7series_v1_8_rank_cntrl #
+ (
+ parameter TCQ = 100, // clk->out delay (sim only)
+ parameter BURST_MODE = ""8"", // Burst length
+ parameter DQRD2DQWR_DLY = 2, // RD->WR DQ Bus Delay
+ parameter CL = 5, // Read CAS latency
+ parameter CWL = 5, // Write CAS latency
+ parameter ID = 0, // Unique ID for each instance
+ parameter nBANK_MACHS = 4, // # bank machines in MC
+ parameter nCK_PER_CLK = 2, // DRAM clock : MC clock
+ parameter nFAW = 30, // four activate window (CKs)
+ parameter nREFRESH_BANK = 8, // # REF commands to pull-in
+ parameter nRRD = 4, // ACT->ACT period (CKs)
+ parameter nWTR = 4, // Internal write->read
+ // delay (CKs)
+ parameter PERIODIC_RD_TIMER_DIV = 20, // Maintenance prescaler divisor
+ // for periodic read timer
+ parameter RANK_BM_BV_WIDTH = 16, // Width required to broadcast a
+ // single bit rank signal among
+ // all the bank machines
+ parameter RANK_WIDTH = 2, // # of bits to count ranks
+ parameter RANKS = 4, // # of ranks of DRAM
+ parameter REFRESH_TIMER_DIV = 39 // Maintenance prescaler divivor
+ // for refresh timer
+ )
+ (
+
+ // Maintenance requests
+
+ output periodic_rd_request,
+ output wire refresh_request,
+
+ // Inhibit signals
+
+ output reg inhbt_act_faw_r,
+ output reg inhbt_rd,
+ output reg inhbt_wr,
+
+ // System Inputs
+
+ input clk,
+ input rst,
+
+ // User maintenance requests
+
+ input app_periodic_rd_req,
+ input app_ref_req,
+
+ // Inputs
+
+ input [RANK_BM_BV_WIDTH-1:0] act_this_rank_r,
+ input clear_periodic_rd_request,
+ input col_rd_wr,
+ input init_calib_complete,
+ input insert_maint_r1,
+ input maint_prescaler_tick_r,
+ input [RANK_WIDTH-1:0] maint_rank_r,
+ input maint_zq_r,
+ input maint_sre_r,
+ input maint_srx_r,
+ input [(RANKS*nBANK_MACHS)-1:0] rank_busy_r,
+ input refresh_tick,
+ input [nBANK_MACHS-1:0] sending_col,
+ input [nBANK_MACHS-1:0] sending_row,
+ input [RANK_BM_BV_WIDTH-1:0] rd_this_rank_r,
+ input [RANK_BM_BV_WIDTH-1:0] wr_this_rank_r
+
+ );
+
+ //***************************************************************************
+ // RRD configuration. The bank machines have a mechanism to prevent RAS to
+ // RAS on adjacent fabric CLK states to the same rank. When
+ // nCK_PER_CLK == 1, this translates to a minimum of 2 for nRRD, 4 for nRRD
+ // when nCK_PER_CLK == 2 and 8 for nRRD when nCK_PER_CLK == 4. Some of the
+ // higher clock rate DDR3 DRAMs have nRRD > 4. The additional RRD inhibit
+ // is worked into the inhbt_faw signal.
+ //***************************************************************************
+
+ localparam nADD_RRD = nRRD -
+ (
+ (nCK_PER_CLK == 1) ? 2 :
+ (nCK_PER_CLK == 2) ? 4 :
+ /*(nCK_PER_CLK == 4)*/ 8
+ );
+
+ // divide by nCK_PER_CLK and add a cycle if there\'s a remainder
+ localparam nRRD_CLKS =
+ (nCK_PER_CLK == 1) ? nADD_RRD :
+ (nCK_PER_CLK == 2) ? ((nADD_RRD/2)+(nADD_RRD%2)) :
+ /*(nCK_PER_CLK == 4)*/ ((nADD_RRD/4)+((nADD_RRD%4) ? 1 : 0));
+
+ // take binary log to obtain counter width and add a tick for the idle cycle
+ localparam ADD_RRD_CNTR_WIDTH = clogb2(nRRD_CLKS + /* idle state */ 1);
+
+ //***************************************************************************
+ // Internal signals
+ //***************************************************************************
+ reg act_this_rank;
+ integer i; // loop invariant
+
+ //***************************************************************************
+ // Function clogb2
+ // Description:
+ // This function performs binary logarithm and rounds up
+ // Inputs:
+ // size: integer to perform binary log upon
+ // Outputs:
+ // clogb2: result of binary logarithm, rounded up
+ //***************************************************************************
+
+ function integer clogb2 (input integer size);
+ begin
+
+ size = size - 1;
+
+ // increment clogb2 from 1 for each bit in size
+ for (clogb2 = 1; size > 1; clogb2 = clogb2 + 1)
+ size = size >> 1;
+
+ end
+ endfunction // clogb2
+
+ //***************************************************************************
+ // Determine if this rank has been activated. act_this_rank_r is a
+ // registered bit vector from individual bank machines indicating the
+ // corresponding bank machine is sending
+ // an activate. Timing is improved with this method.
+ //***************************************************************************
+
+ always @(/*AS*/act_this_rank_r or sending_row) begin
+
+ act_this_rank = 1\'b0;
+
+ for (i = 0; i < nBANK_MACHS; i = i + 1)
+ act_this_rank =
+ act_this_rank || (sending_row[i] && act_this_rank_r[(i*RANKS)+ID]);
+
+ end
+
+
+
+ reg add_rrd_inhbt = 1\'b0;
+ generate
+ if (nADD_RRD > 0 && ADD_RRD_CNTR_WIDTH > 1) begin :add_rdd1
+ reg[ADD_RRD_CNTR_WIDTH-1:0] add_rrd_ns;
+ reg[ADD_RRD_CNTR_WIDTH-1:0] add_rrd_r;
+ always @(/*AS*/act_this_rank or add_rrd_r or rst) begin
+ add_rrd_ns = add_rrd_r;
+ if (rst) add_rrd_ns = {ADD_RRD_CNTR_WIDTH{1\'b0}};
+ else
+ if (act_this_rank)
+ add_rrd_ns = nRRD_CLKS[0+:ADD_RRD_CNTR_WIDTH];
+ else if (|add_rrd_r) add_rrd_ns =
+ add_rrd_r - {{ADD_RRD_CNTR_WIDTH-1{1\'b0}}, 1\'b1};
+ end
+ always @(posedge clk) add_rrd_r <= #TCQ add_rrd_ns;
+ always @(/*AS*/add_rrd_ns) add_rrd_inhbt = |add_rrd_ns;
+ end // add_rdd1
+ else if (nADD_RRD > 0) begin :add_rdd0
+ reg[ADD_RRD_CNTR_WIDTH-1:0] add_rrd_ns;
+ reg[ADD_RRD_CNTR_WIDTH-1:0] add_rrd_r;
+ always @(/*AS*/act_this_rank or add_rrd_r or rst) begin
+ add_rrd_ns = add_rrd_r;
+ if (rst) add_rrd_ns = {ADD_RRD_CNTR_WIDTH{1\'b0}};
+ else
+ if (act_this_rank)
+ add_rrd_ns = nRRD_CLKS[0+:ADD_RRD_CNTR_WIDTH];
+ else if (|add_rrd_r) add_rrd_ns =
+ add_rrd_r - {1\'b1};
+ end
+ always @(posedge clk) add_rrd_r <= #TCQ add_rrd_ns;
+ always @(/*AS*/add_rrd_ns) add_rrd_inhbt = |add_rrd_ns;
+ end // add_rdd0
+ endgenerate
+
+
+// Compute inhbt_act_faw_r. Only allow a limited number of activates
+// in a window. Both the number of activates and the window are
+// configurable. This depends on the RRD mechanism to prevent
+// two consecutive activates to the same rank.
+//
+// Subtract three from the specified nFAW. Subtract three because:
+// -Zero for the delay into the SRL is really one state.
+// -Sending_row is used to trigger the delay. Sending_row is one
+// state delayed from the arb.
+// -inhbt_act_faw_r is registered to make timing work, hence the
+// generation needs to be one state early.
+
+ localparam nFAW_CLKS = (nCK_PER_CLK == 1)
+ ? nFAW
+ : (nCK_PER_CLK == 2) ? ((nFAW/2) + (nFAW%2)) :
+ ((nFAW/4) + ((nFAW%4) ? 1 : 0));
+
+ generate
+ begin : inhbt_act_faw
+ wire act_delayed;
+ wire [4:0] shift_depth = nFAW_CLKS[4:0] - 5\'d3;
+
+ SRLC32E #(.INIT(32\'h00000000) ) SRLC32E0
+ (.Q(act_delayed), // SRL data output
+ .Q31(), // SRL cascade output pin
+ .A(shift_depth), // 5-bit shift depth select input
+ .CE(1\'b1), // Clock enable input
+ .CLK(clk), // Clock input
+ .D(act_this_rank) // SRL data input
+ );
+
+ reg [2:0] faw_cnt_ns;
+ reg [2:0] faw_cnt_r;
+ reg inhbt_act_faw_ns;
+ always @(/*AS*/act_delayed or act_this_rank or add_rrd_inhbt
+ or faw_cnt_r or rst) begin
+ if (rst) faw_cnt_ns = 3\'b0;
+ else begin
+ faw_cnt_ns = faw_cnt_r;
+ if (act_this_rank) faw_cnt_ns = faw_cnt_r + 3\'b1;
+ if (act_delayed) faw_cnt_ns = faw_cnt_ns - 3\'b1;
+ end
+ inhbt_act_faw_ns = (faw_cnt_ns == 3\'h4) || add_rrd_inhbt;
+ end
+ always @(posedge clk) faw_cnt_r <= #TCQ faw_cnt_ns;
+ always @(posedge clk) inhbt_act_faw_r <= #TCQ inhbt_act_faw_ns;
+ end // block: inhbt_act_faw
+ endgenerate
+
+
+// In the DRAM spec, tWTR starts from CK following the end of the data
+// burst. Since we don\'t directly have that spec, the wtr timer is
+// based on when the CAS write command is sent to the DRAM.
+//
+// To compute the wtr timer value, first compute the time from the write command
+// to the read command. This is CWL + data_time + nWTR.
+//
+// Two is subtracted from the required wtr time since the timer
+// starts two states after the arbitration cycle.
+
+ localparam ONE = 1;
+ localparam TWO = 2;
+
+ localparam CASWR2CASRD = CWL + (BURST_MODE == ""4"" ? 2 : 4) + nWTR;
+ localparam CASWR2CASRD_CLKS = (nCK_PER_CLK == 1)
+ ? CASWR2CASRD :
+ (nCK_PER_CLK == 2)
+ ? ((CASWR2CASRD / 2) + (CASWR2CASRD % 2)) :
+ ((CASWR2CASRD / 4) + ((CASWR2CASRD % 4) ? 1 :0));
+ localparam WTR_CNT_WIDTH = clogb2(CASWR2CASRD_CLKS);
+
+ generate
+ begin : wtr_timer
+
+ reg write_this_rank;
+ always @(/*AS*/sending_col or wr_this_rank_r) begin
+ write_this_rank = 1\'b0;
+ for (i = 0; i < nBANK_MACHS; i = i + 1)
+ write_this_rank =
+ write_this_rank || (sending_col[i] && wr_this_rank_r[(i*RANKS)+ID]);
+ end
+
+ reg [WTR_CNT_WIDTH-1:0] wtr_cnt_r;
+ reg [WTR_CNT_WIDTH-1:0] wtr_cnt_ns;
+
+ always @(/*AS*/rst or write_this_rank or wtr_cnt_r)
+ if (rst) wtr_cnt_ns = {WTR_CNT_WIDTH{1\'b0}};
+ else begin
+ wtr_cnt_ns = wtr_cnt_r;
+ if (write_this_rank) wtr_cnt_ns =
+ CASWR2CASRD_CLKS[WTR_CNT_WIDTH-1:0] - ONE[WTR_CNT_WIDTH-1:0];
+ else if (|wtr_cnt_r) wtr_cnt_ns = wtr_cnt_r - ONE[WTR_CNT_WIDTH-1:0];
+ end
+
+ wire inhbt_rd_ns = |wtr_cnt_ns;
+
+ always @(posedge clk) wtr_cnt_r <= #TCQ wtr_cnt_ns;
+ always @(inhbt_rd_ns) inhbt_rd = inhbt_rd_ns;
+
+ end
+ endgenerate
+
+// In the DRAM spec (with AL = 0), the read-to-write command delay is implied to
+// be CL + data_time + 2 tCK - CWL. The CL + data_time - CWL terms ensure the
+// read and write data do not collide on the DQ bus. The 2 tCK ensures a gap
+// between them. Here, we allow the user to tune this fixed term via the
+// DQRD2DQWR_DLY parameter. There\'s a potential for optimization by relocating
+// this to the rank_common module, since this is a DQ/DQS bus-level requirement,
+// not a per-rank requirement.
+
+ localparam CASRD2CASWR = CL + (BURST_MODE == ""4"" ? 2 : 4) + DQRD2DQWR_DLY - CWL;
+ localparam CASRD2CASWR_CLKS = (nCK_PER_CLK == 1)
+ ? CASRD2CASWR :
+ (nCK_PER_CLK == 2)
+ ? ((CASRD2CASWR / 2) + (CASRD2CASWR % 2)) :
+ ((CASRD2CASWR / 4) + ((CASRD2CASWR % 4) ? 1 :0));
+ localparam RTW_CNT_WIDTH = clogb2(CASRD2CASWR_CLKS);
+
+ generate
+ begin : rtw_timer
+
+ reg read_this_rank;
+ always @(/*AS*/sending_col or rd_this_rank_r) begin
+ read_this_rank = 1\'b0;
+ for (i = 0; i < nBANK_MACHS; i = i + 1)
+ read_this_rank =
+ read_this_rank || (sending_col[i] && rd_this_rank_r[(i*RANKS)+ID]);
+ end
+
+ reg [RTW_CNT_WIDTH-1:0] rtw_cnt_r;
+ reg [RTW_CNT_WIDTH-1:0] rtw_cnt_ns;
+
+ always @(/*AS*/rst or col_rd_wr or sending_col or rtw_cnt_r)
+ if (rst) rtw_cnt_ns = {RTW_CNT_WIDTH{1\'b0}};
+ else begin
+ rtw_cnt_ns = rtw_cnt_r;
+ if (col_rd_wr && |sending_col) rtw_cnt_ns =
+ CASRD2CASWR_CLKS[RTW_CNT_WIDTH-1:0] - ONE[RTW_CNT_WIDTH-1:0];
+ else if (|rtw_cnt_r) rtw_cnt_ns = rtw_cnt_r - ONE[RTW_CNT_WIDTH-1:0];
+ end
+
+ wire inhbt_wr_ns = |rtw_cnt_ns;
+
+ always @(posedge clk) rtw_cnt_r <= #TCQ rtw_cnt_ns;
+ always @(inhbt_wr_ns) inhbt_wr = inhbt_wr_ns;
+
+ end
+ endgenerate
+
+// Refresh request generation. Implement a ""refresh bank"". Referred
+// to as pullin-in refresh in the JEDEC spec.
+// The refresh_rank_r counter increments when a refresh to this
+// rank has been decoded. In the up direction, the count saturates
+// at nREFRESH_BANK. As specified in the JEDEC spec, nREFRESH_BANK
+// is normally eight. The counter decrements with each refresh_tick,
+// saturating at zero. A refresh will be requests when the rank is
+// not busy and refresh_rank_r != nREFRESH_BANK, or refresh_rank_r
+// equals zero.
+
+ localparam REFRESH_BANK_WIDTH = clogb2(nREFRESH_BANK + 1);
+
+
+ generate begin : refresh_generation
+ reg my_rank_busy;
+ always @(/*AS*/rank_busy_r) begin
+ my_rank_busy = 1\'b0;
+ for (i=0; i < nBANK_MACHS; i=i+1)
+ my_rank_busy = my_rank_busy || rank_busy_r[(i*RANKS)+ID];
+ end
+
+ wire my_refresh =
+ insert_maint_r1 && ~maint_zq_r && ~maint_sre_r && ~maint_srx_r &&
+ (maint_rank_r == ID[RANK_WIDTH-1:0]);
+
+ reg [REFRESH_BANK_WIDTH-1:0] refresh_bank_r;
+ reg [REFRESH_BANK_WIDTH-1:0] refresh_bank_ns;
+ always @(/*AS*/app_ref_req or init_calib_complete or my_refresh
+ or refresh_bank_r or refresh_tick)
+ if (~init_calib_complete)
+ if (REFRESH_TIMER_DIV == 0)
+ refresh_bank_ns = nREFRESH_BANK[0+:REFRESH_BANK_WIDTH];
+ else refresh_bank_ns = {REFRESH_BANK_WIDTH{1\'b0}};
+ else
+ case ({my_refresh, refresh_tick, app_ref_req})
+ 3\'b000, 3\'b110, 3\'b101, 3\'b111 : refresh_bank_ns = refresh_bank_r;
+ 3\'b010, 3\'b001, 3\'b011 : refresh_bank_ns =
+ (|refresh_bank_r)?
+ refresh_bank_r - ONE[0+:REFRESH_BANK_WIDTH]:
+ refresh_bank_r;
+ 3\'b100 : refresh_bank_ns =
+ refresh_bank_r + ONE[0+:REFRESH_BANK_WIDTH];
+ endcase // case ({my_refresh, refresh_tick})
+ always @(posedge clk) refresh_bank_r <= #TCQ refresh_bank_ns;
+
+ `ifdef MC_SVA
+ refresh_bank_overflow: assert property (@(posedge clk)
+ (rst || (refresh_bank_r <= nREFRESH_BANK)));
+ refresh_bank_underflow: assert property (@(posedge clk)
+ (rst || ~(~|refresh_bank_r && ~my_refresh && refresh_tick)));
+ refresh_hi_priority: cover property (@(posedge clk)
+ (rst && ~|refresh_bank_ns && (refresh_bank_r ==
+ ONE[0+:REFRESH_BANK_WIDTH])));
+ refresh_bank_full: cover property (@(posedge clk)
+ (rst && (refresh_bank_r ==
+ nREFRESH_BANK[0+:REFRESH_BANK_WIDTH])));
+ `endif
+
+ assign refresh_request = init_calib_complete &&
+ (~|refresh_bank_r ||
+ ((refresh_bank_r != nREFRESH_BANK[0+:REFRESH_BANK_WIDTH]) && ~my_rank_busy));
+
+ end
+ endgenerate
+
+// Periodic read request generation.
+
+ localparam PERIODIC_RD_TIMER_WIDTH = clogb2(PERIODIC_RD_TIMER_DIV + /*idle state*/ 1);
+
+
+ generate begin : periodic_rd_generation
+ if ( PERIODIC_RD_TIMER_DIV != 0 ) begin // enable periodic reads
+ reg read_this_rank;
+ always @(/*AS*/rd_this_rank_r or sending_col) begin
+ read_this_rank = 1\'b0;
+ for (i = 0; i < nBANK_MACHS; i = i + 1)
+ read_this_rank =
+ read_this_rank || (sending_col[i] && rd_this_rank_r[(i*RANKS)+ID]);
+ end
+
+ reg read_this_rank_r;
+ reg read_this_rank_r1;
+ always @(posedge clk) read_this_rank_r <= #TCQ read_this_rank;
+ always @(posedge clk) read_this_rank_r1 <= #TCQ read_this_rank_r;
+ wire int_read_this_rank = read_this_rank &&
+ (((nCK_PER_CLK == 4) && read_this_rank_r) ||
+\t\t\t\t ((nCK_PER_CLK != 4) && read_this_rank_r1));
+
+ reg periodic_rd_cntr1_ns;
+ reg periodic_rd_cntr1_r;
+ always @(/*AS*/clear_periodic_rd_request or periodic_rd_cntr1_r) begin
+ periodic_rd_cntr1_ns = periodic_rd_cntr1_r;
+ if (clear_periodic_rd_request)
+ periodic_rd_cntr1_ns = periodic_rd_cntr1_r + 1\'b1;
+ end
+ always @(posedge clk) begin
+ if (rst) periodic_rd_cntr1_r <= #TCQ 1\'b0;
+ else periodic_rd_cntr1_r <= #TCQ periodic_rd_cntr1_ns;
+ end
+
+ reg [PERIODIC_RD_TIMER_WIDTH-1:0] periodic_rd_timer_r;
+ reg [PERIODIC_RD_TIMER_WIDTH-1:0] periodic_rd_timer_ns;
+ always @(/*AS*/init_calib_complete or maint_prescaler_tick_r
+ or periodic_rd_timer_r or int_read_this_rank) begin
+ periodic_rd_timer_ns = periodic_rd_timer_r;
+ if (~init_calib_complete)
+ periodic_rd_timer_ns = {PERIODIC_RD_TIMER_WIDTH{1\'b0}};
+ else if (int_read_this_rank)
+ periodic_rd_timer_ns =
+ PERIODIC_RD_TIMER_DIV[0+:PERIODIC_RD_TIMER_WIDTH];
+ else if (|periodic_rd_timer_r && maint_prescaler_tick_r)
+ periodic_rd_timer_ns =
+ periodic_rd_timer_r - ONE[0+:PERIODIC_RD_TIMER_WIDTH];
+ end
+ always @(posedge clk) periodic_rd_timer_r <= #TCQ periodic_rd_timer_ns;
+
+ wire periodic_rd_timer_one = maint_prescaler_tick_r &&
+ (periodic_rd_timer_r == ONE[0+:PERIODIC_RD_TIMER_WIDTH]);
+
+ reg periodic_rd_request_r;
+ wire periodic_rd_request_ns = ~rst &&
+ ((app_periodic_rd_req && init_calib_complete) ||
+ ((PERIODIC_RD_TIMER_DIV != 0) && ~init_calib_complete) ||
+ // (~(read_this_rank || clear_periodic_rd_request) &&
+ (~((int_read_this_rank) || (clear_periodic_rd_request && periodic_rd_cntr1_r)) &&
+ (periodic_rd_request_r || periodic_rd_timer_one)));
+ always @(posedge clk) periodic_rd_request_r <=
+ #TCQ periodic_rd_request_ns;
+
+ `ifdef MC_SVA
+ read_clears_periodic_rd_request: cover property (@(posedge clk)
+ (rst && (periodic_rd_request_r && read_this_rank)));
+ `endif
+
+ assign periodic_rd_request = init_calib_complete && periodic_rd_request_r;
+ end else
+ assign periodic_rd_request = 1\'b0; //to disable periodic reads
+
+ end
+ endgenerate
+
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//
+// (c) Copyright 2009-2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//-----------------------------------------------------------------------------
+// Project : Virtex-6 Integrated Block for PCI Express
+// File : pcie_pipe_misc_v6.v
+// Version : 2.4
+//--
+//-- Description: Misc PIPE module for Virtex6 PCIe Block
+//--
+//--
+//--
+//--------------------------------------------------------------------------------
+
+`timescale 1ns/1ns
+
+module pcie_pipe_misc_v6 #
+(
+ parameter PIPE_PIPELINE_STAGES = 0 // 0 - 0 stages, 1 - 1 stage, 2 - 2 stages
+)
+(
+
+ input wire pipe_tx_rcvr_det_i ,
+ input wire pipe_tx_reset_i ,
+ input wire pipe_tx_rate_i ,
+ input wire pipe_tx_deemph_i ,
+ input wire [2:0] pipe_tx_margin_i ,
+ input wire pipe_tx_swing_i ,
+
+ output wire pipe_tx_rcvr_det_o ,
+ output wire pipe_tx_reset_o ,
+ output wire pipe_tx_rate_o ,
+ output wire pipe_tx_deemph_o ,
+ output wire [2:0] pipe_tx_margin_o ,
+ output wire pipe_tx_swing_o ,
+
+ input wire pipe_clk ,
+ input wire rst_n
+);
+
+//******************************************************************//
+// Reality check. //
+//******************************************************************//
+
+ localparam TCQ = 1; // clock to out delay model
+
+ reg pipe_tx_rcvr_det_q ;
+ reg pipe_tx_reset_q ;
+ reg pipe_tx_rate_q ;
+ reg pipe_tx_deemph_q ;
+ reg [2:0] pipe_tx_margin_q ;
+ reg pipe_tx_swing_q ;
+
+ reg pipe_tx_rcvr_det_qq ;
+ reg pipe_tx_reset_qq ;
+ reg pipe_tx_rate_qq ;
+ reg pipe_tx_deemph_qq ;
+ reg [2:0] pipe_tx_margin_qq ;
+ reg pipe_tx_swing_qq ;
+
+ generate
+
+ if (PIPE_PIPELINE_STAGES == 0) begin
+
+
+ assign pipe_tx_rcvr_det_o = pipe_tx_rcvr_det_i;
+ assign pipe_tx_reset_o = pipe_tx_reset_i;
+ assign pipe_tx_rate_o = pipe_tx_rate_i;
+ assign pipe_tx_deemph_o = pipe_tx_deemph_i;
+ assign pipe_tx_margin_o = pipe_tx_margin_i;
+ assign pipe_tx_swing_o = pipe_tx_swing_i;
+
+ end else if (PIPE_PIPELINE_STAGES == 1) begin
+
+ always @(posedge pipe_clk) begin
+
+ if (rst_n) begin
+
+ pipe_tx_rcvr_det_q <= #TCQ 0;
+ pipe_tx_reset_q <= #TCQ 1\'b1;
+ pipe_tx_rate_q <= #TCQ 0;
+ pipe_tx_deemph_q <= #TCQ 1\'b1;
+ pipe_tx_margin_q <= #TCQ 0;
+ pipe_tx_swing_q <= #TCQ 0;
+
+ end else begin
+
+ pipe_tx_rcvr_det_q <= #TCQ pipe_tx_rcvr_det_i;
+ pipe_tx_reset_q <= #TCQ pipe_tx_reset_i;
+ pipe_tx_rate_q <= #TCQ pipe_tx_rate_i;
+ pipe_tx_deemph_q <= #TCQ pipe_tx_deemph_i;
+ pipe_tx_margin_q <= #TCQ pipe_tx_margin_i;
+ pipe_tx_swing_q <= #TCQ pipe_tx_swing_i;
+
+ end
+
+ end
+
+ assign pipe_tx_rcvr_det_o = pipe_tx_rcvr_det_q;
+ assign pipe_tx_reset_o = pipe_tx_reset_q;
+ assign pipe_tx_rate_o = pipe_tx_rate_q;
+ assign pipe_tx_deemph_o = pipe_tx_deemph_q;
+ assign pipe_tx_margin_o = pipe_tx_margin_q;
+ assign pipe_tx_swing_o = pipe_tx_swing_q;
+
+ end else if (PIPE_PIPELINE_STAGES == 2) begin
+
+ always @(posedge pipe_clk) begin
+
+ if (rst_n) begin
+
+ pipe_tx_rcvr_det_q <= #TCQ 0;
+ pipe_tx_reset_q <= #TCQ 1\'b1;
+ pipe_tx_rate_q <= #TCQ 0;
+ pipe_tx_deemph_q <= #TCQ 1\'b1;
+ pipe_tx_margin_q <= #TCQ 0;
+ pipe_tx_swing_q <= #TCQ 0;
+
+ pipe_tx_rcvr_det_qq <= #TCQ 0;
+ pipe_tx_reset_qq <= #TCQ 1\'b1;
+ pipe_tx_rate_qq <= #TCQ 0;
+ pipe_tx_deemph_qq <= #TCQ 1\'b1;
+ pipe_tx_margin_qq <= #TCQ 0;
+ pipe_tx_swing_qq <= #TCQ 0;
+
+ end else begin
+
+ pipe_tx_rcvr_det_q <= #TCQ pipe_tx_rcvr_det_i;
+ pipe_tx_reset_q <= #TCQ pipe_tx_reset_i;
+ pipe_tx_rate_q <= #TCQ pipe_tx_rate_i;
+ pipe_tx_deemph_q <= #TCQ pipe_tx_deemph_i;
+ pipe_tx_margin_q <= #TCQ pipe_tx_margin_i;
+ pipe_tx_swing_q <= #TCQ pipe_tx_swing_i;
+
+ pipe_tx_rcvr_det_qq <= #TCQ pipe_tx_rcvr_det_q;
+ pipe_tx_reset_qq <= #TCQ pipe_tx_reset_q;
+ pipe_tx_rate_qq <= #TCQ pipe_tx_rate_q;
+ pipe_tx_deemph_qq <= #TCQ pipe_tx_deemph_q;
+ pipe_tx_margin_qq <= #TCQ pipe_tx_margin_q;
+ pipe_tx_swing_qq <= #TCQ pipe_tx_swing_q;
+
+ end
+
+ end
+
+ assign pipe_tx_rcvr_det_o = pipe_tx_rcvr_det_qq;
+ assign pipe_tx_reset_o = pipe_tx_reset_qq;
+ assign pipe_tx_rate_o = pipe_tx_rate_qq;
+ assign pipe_tx_deemph_o = pipe_tx_deemph_qq;
+ assign pipe_tx_margin_o = pipe_tx_margin_qq;
+ assign pipe_tx_swing_o = pipe_tx_swing_qq;
+
+ end
+
+ endgenerate
+
+endmodule
+"
+"//--------------------------------------------------------------------------------
+// Project : SWITCH
+// File : rx_engine.v
+// Version : 0.1
+// Author : Vipin.K
+//
+// Description: 64 bit PCIe transaction layer receive unit
+//
+//--------------------------------------------------------------------------------
+
+`timescale 1ns/1ns
+
+module rx_engine #(
+ parameter C_DATA_WIDTH = 64, // RX interface data width
+ parameter FPGA_ADDR_MAX = 'h400
+) (
+ input clk_i, // 250Mhz clock from PCIe core
+ input rst_n, // Active low reset
+ // AXI-S
+ input [C_DATA_WIDTH-1:0] m_axis_rx_tdata,
+ input m_axis_rx_tlast,
+ input m_axis_rx_tvalid,
+ output reg m_axis_rx_tready,
+ //Tx engine
+ input compl_done_i, // Tx engine indicating completion packet is sent
+ output reg req_compl_wd_o, // Request Tx engine for completion packet transmission
+ output reg [31:0] tx_reg_data_o, // Data for completion packet
+ output reg [2:0] req_tc_o, // Memory Read TC
+ output reg req_td_o, // Memory Read TD
+ output reg req_ep_o, // Memory Read EP
+ output reg [1:0] req_attr_o, // Memory Read Attribute
+ output reg [9:0] req_len_o, // Memory Read Length (1DW)
+ output reg [15:0] req_rid_o, // Memory Read Requestor ID
+ output reg [7:0] req_tag_o, // Memory Read Tag
+ output reg [6:0] req_addr_o, // Memory Read Address
+ //Register file
+ output reg [31:0] reg_data_o, // Write data to register
+ output reg reg_data_valid_o, // Register write data is valid
+ output reg [9:0] reg_addr_o, // Register address
+ input fpga_reg_wr_ack_i, // Register write acknowledge
+ output reg fpga_reg_rd_o, // Register read enable
+ input [31:0] reg_data_i, // Register read data
+ input fpga_reg_rd_ack_i, // Register read acknowledge
+ output reg [7:0] cpld_tag_o,
+ //User interface
+ output reg [31:0] user_data_o, // User write data
+ output reg [19:0] user_addr_o, // User address
+ output reg user_wr_req_o, // User write request
+ //input user_wr_ack_i, // User write acknowledge
+ input [31:0] user_data_i, // User read data
+ input user_rd_ack_i, // User read acknowledge
+ output reg user_rd_req_o, // User read request
+ //DDR interface
+ output reg [63:0] rcvd_data_o, // Memory ready completion data after DMA read request
+ output reg rcvd_data_valid_o // Completion data is valid
+);
+
+ // Local Registers
+ wire sop;
+ reg [2:0] state;
+\t reg in_packet_q;
+ reg [31:0] rx_tdata_p;
+ reg rcv_data;
+\t reg lock_tag;
+\t reg user_wr_ack;
+\t
+ // State Machine state declaration
+\tlocalparam IDLE = 'd0,
+\t SEND_DATA = 'd1,
+ WAIT_FPGA_DATA = 'd2,
+ WAIT_USR_DATA = 'd3,
+ WAIT_TX_ACK = 'd4,
+ WR_DATA = 'd5,
+ RX_DATA = 'd6;
+\t\t\t\t\t
+ // TLP packet type encoding
+\tlocalparam MEM_RD = 7'b0000000,
+ MEM_WR = 7'b1000000,
+ CPLD = 7'b1001010;
+\t\t\t\t\t
+ assign sop = !in_packet_q && m_axis_rx_tvalid; //start of a new packet
+
+ // Generate a signal that indicates if we are currently receiving a packet.
+ // This value is one clock cycle delayed from what is actually on the AXIS
+ // data bus.
+ always@(posedge clk_i)
+ begin
+ if(!rst_n)
+ in_packet_q <= 1'b0;
+ else if (m_axis_rx_tvalid && m_axis_rx_tready && m_axis_rx_tlast)
+ in_packet_q <= 1'b0;
+ else if (sop && m_axis_rx_tready)
+ in_packet_q <= 1'b1;
+ end
+
+ \t\t\t\t\t
+ //The receive state machine
+ always @ ( posedge clk_i )
+ begin
+ if (!rst_n ) begin
+ m_axis_rx_tready <= 1'b0;
+ req_compl_wd_o <= 1'b0;
+ state <= IDLE;
+ user_rd_req_o <= 1'b0;
+ user_wr_req_o <= 1'b0;
+ rcv_data <= 1'b0;
+ fpga_reg_rd_o <= 1'b0;
+ reg_data_valid_o <= 1'b0;
+ end
+ else
+ begin
+ case (state)
+ IDLE : begin
+ m_axis_rx_tready <= 1'b1; // Indicate ready to accept TLPs
+ reg_data_valid_o <= 1'b0;
+\t\t\t\t\t\t user_wr_req_o <= 1'b0;
+\t\t\t\t\t\t req_len_o <= m_axis_rx_tdata[9:0]; // Place the packet info on the bus for Tx engine
+ req_attr_o <= m_axis_rx_tdata[13:12];
+ req_ep_o <= m_axis_rx_tdata[14];
+ req_td_o <= m_axis_rx_tdata[15];
+ req_tc_o <= m_axis_rx_tdata[22:20];
+ req_rid_o <= m_axis_rx_tdata[63:48];
+ req_tag_o <= m_axis_rx_tdata[47:40];
+ if (sop)
+ begin // Valid data on the bus
+\t\t\t\t\t\t if(m_axis_rx_tdata[30:24] == MEM_RD) // If memory ready request
+ state <= SEND_DATA;
+\t\t\t\t\t\t else if(m_axis_rx_tdata[30:24] == MEM_WR) // If memory write request\t
+\t\t\t\t\t\t\t state <= WR_DATA;
+ else if(m_axis_rx_tdata[30:24] == CPLD) // If completion packet
+\t\t\t\t\t\t\t\tbegin
+ state <= RX_DATA;
+\t\t\t\t\t\t\t\t\tlock_tag <= 1'b1;
+\t\t\t\t\t\t\t\tend\t
+ end
+ end
+ SEND_DATA: begin
+ if (m_axis_rx_tvalid && m_axis_rx_tlast)
+ begin
+ req_addr_o <= m_axis_rx_tdata[6:0];
+ m_axis_rx_tready <= 1'b0; // Block further TLPs until the requested data is sent by Tx engine
+ user_addr_o <= m_axis_rx_tdata[19:0];
+ reg_addr_o <= m_axis_rx_tdata[9:0];
+ if(m_axis_rx_tdata[21:0] < FPGA_ADDR_MAX) //Check 22 bits since PCIe bar0 is for 4M
+ begin
+ state <= WAIT_FPGA_DATA;
+ fpga_reg_rd_o <= 1'b1;
+ end
+ else
+ begin
+ state <= WAIT_USR_DATA;
+ user_rd_req_o <= 1'b1;
+ end
+ end
+ end
+ WAIT_FPGA_DATA:begin
+\t\t\t\t\t fpga_reg_rd_o <= 1'b0;
+ if(fpga_reg_rd_ack_i)
+ begin
+ req_compl_wd_o <= 1'b1; //Request Tx engine to send data
+ tx_reg_data_o <= reg_data_i;
+ state <= WAIT_TX_ACK; //Wait for ack from Tx engine for data sent
+ end
+ end
+ WAIT_USR_DATA:begin
+ if(user_rd_ack_i)
+ begin
+ user_rd_req_o <= 1'b0;
+ req_compl_wd_o <= 1'b1;
+ tx_reg_data_o <= user_data_i;
+ state <= WAIT_TX_ACK;
+ end
+ end
+ WAIT_TX_ACK: begin
+ if(compl_done_i)
+ begin
+ state <= IDLE;
+ req_compl_wd_o <= 1'b0;
+\t\t\t\t\t\t\t m_axis_rx_tready <= 1'b1;
+ end
+ end
+\t\t\t\tWR_DATA:begin
+ reg_data_valid_o <= 1'b0;
+ user_wr_req_o <= 1'b0;
+ if (m_axis_rx_tvalid && m_axis_rx_tlast)
+ begin
+\t\t\t\t\t\t m_axis_rx_tready <= 1'b0;
+ reg_data_o <= m_axis_rx_tdata[63:32];
+ reg_addr_o <= m_axis_rx_tdata[9:0];
+ user_data_o <= m_axis_rx_tdata[63:32];
+ user_addr_o <= m_axis_rx_tdata[19:0];
+ if(m_axis_rx_tdata[21:0] < FPGA_ADDR_MAX) // If the data is intended for global registers
+ begin
+ reg_data_valid_o <= 1'b1;
+ end
+ else
+ begin
+ user_wr_req_o <= 1'b1;
+ end
+ end
+ if (fpga_reg_wr_ack_i | user_wr_ack)
+ begin
+ state <= IDLE;
+ m_axis_rx_tready <= 1'b1;\t\t\t\t\t\t\t\t
+ end
+\t\t\t\tend
+ RX_DATA:begin
+\t\t\t\t lock_tag <= 1'b0;
+ if(m_axis_rx_tvalid && m_axis_rx_tlast)
+ begin
+ rcv_data <= 1'b0;
+ state <= IDLE;
+\t\t\t\t\tm_axis_rx_tready <= 1'b1;
+ end
+ else
+ rcv_data <= 1'b1;
+ end
+ endcase
+ end
+ end
+
+ //Packing data from the received completion packet. Required since the TLP header is 3 DWORDs.
+ always @(posedge clk_i)
+ begin
+ rx_tdata_p <= m_axis_rx_tdata[63:32];
+\t\t user_wr_ack <= user_wr_req_o;
+ if(rcv_data & m_axis_rx_tvalid)
+ begin
+ rcvd_data_valid_o <= 1'b1;
+ rcvd_data_o <= {rx_tdata_p,m_axis_rx_tdata[31:0]};
+ end
+ else
+ rcvd_data_valid_o <= 1'b0;
+ end
+\t
+\t always @(posedge clk_i)
+\t begin
+\t if(lock_tag)
+\t cpld_tag_o <= m_axis_rx_tdata[15:8];
+\t end
+
+endmodule
+
+"
+"//*****************************************************************************
+// (c) Copyright 2008 - 2012 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : %version
+// \\ \\ Application : MIG
+// / / Filename : ui_rd_data.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : 7-Series
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+// User interface read buffer. Re orders read data returned from the
+// memory controller back to the request order.
+//
+// Consists of a large buffer for the data, a status RAM and two counters.
+//
+// The large buffer is implemented with distributed RAM in 6 bit wide,
+// 1 read, 1 write mode. The status RAM is implemented with a distributed
+// RAM configured as 2 bits wide 1 read/write, 1 read mode.
+//
+// As read requests are received from the application, the data_buf_addr
+// counter supplies the data_buf_addr sent into the memory controller.
+// With each read request, the counter is incremented, eventually rolling
+// over. This mechanism labels each read request with an incrementing number.
+//
+// When the memory controller returns read data, it echos the original
+// data_buf_addr with the read data.
+//
+// The status RAM is indexed with the same address as the data buffer
+// RAM. Each word of the data buffer RAM has an associated status bit
+// and ""end"" bit. Requests of size 1 return a data burst on two consecutive
+// states. Requests of size zero return with a single assertion of rd_data_en.
+//
+// Upon returning data, the status and end bits are updated for each
+// corresponding location in the status RAM indexed by the data_buf_addr
+// echoed on the rd_data_addr field.
+//
+// The other side of the status and data RAMs is indexed by the rd_buf_indx.
+// The rd_buf_indx constantly monitors the status bit it is currently
+// pointing to. When the status becomes set to the proper state (more on
+// this later) read data is returned to the application, and the rd_buf_indx
+// is incremented.
+//
+// At rst the rd_buf_indx is initialized to zero. Data will not have been
+// returned from the memory controller yet, so there is nothing to return
+// to the application. Evenutally, read requests will be made, and the
+// memory controller will return the corresponding data. The memory
+// controller may not return this data in the request order. In which
+// case, the status bit at location zero, will not indicate
+// the data for request zero is ready. Eventually, the memory controller
+// will return data for request zero. The data is forwarded on to the
+// application, and rd_buf_indx is incremented to point to the next status
+// bits and data in the buffers. The status bit will be examined, and if
+// data is valid, this data will be returned as well. This process
+// continues until the status bit indexed by rd_buf_indx indicates data
+// is not ready. This may be because the rd_data_buf
+// is empty, or that some data was returned out of order. Since rd_buf_indx
+// always increments sequentially, data is always returned to the application
+// in request order.
+//
+// Some further discussion of the status bit is in order. The rd_data_buf
+// is a circular buffer. The status bit is a single bit. Distributed RAM
+// supports only a single write port. The write port is consumed by
+// memory controller read data updates. If a simple \'1\' were used to
+// indicate the status, when rd_data_indx rolled over it would immediately
+// encounter a one for a request that may not be ready.
+//
+// This problem is solved by causing read data returns to flip the
+// status bit, and adding hi order bit beyond the size required to
+// index the rd_data_buf. Data is considered ready when the status bit
+// and this hi order bit are equal.
+//
+// The status RAM needs to be initialized to zero after reset. This is
+// accomplished by cycling through all rd_buf_indx valus and writing a
+// zero to the status bits directly following deassertion of reset. This
+// mechanism is used for similar purposes
+// for the wr_data_buf.
+//
+// When ORDERING == ""STRICT"", read data reordering is unnecessary. For thi
+// case, most of the logic in the block is not generated.
+
+`timescale 1 ps / 1 ps
+
+// User interface read data.
+
+module mig_7series_v1_8_ui_rd_data #
+ (
+ parameter TCQ = 100,
+ parameter APP_DATA_WIDTH = 256,
+ parameter DATA_BUF_ADDR_WIDTH = 5,
+ parameter ECC = ""OFF"",
+ parameter nCK_PER_CLK = 2 ,
+ parameter ORDERING = ""NORM""
+ )
+ (/*AUTOARG*/
+ // Outputs
+ ram_init_done_r, ram_init_addr, app_rd_data_valid, app_rd_data_end,
+ app_rd_data, app_ecc_multiple_err, rd_buf_full, rd_data_buf_addr_r,
+ // Inputs
+ rst, clk, rd_data_en, rd_data_addr, rd_data_offset, rd_data_end,
+ rd_data, ecc_multiple, rd_accepted
+ );
+
+ input rst;
+ input clk;
+
+ output wire ram_init_done_r;
+ output wire [3:0] ram_init_addr;
+
+// rd_buf_indx points to the status and data storage rams for
+// reading data out to the app.
+ reg [5:0] rd_buf_indx_r;
+(* keep = ""true"", max_fanout = 10 *) reg ram_init_done_r_lcl;
+ assign ram_init_done_r = ram_init_done_r_lcl;
+ wire app_rd_data_valid_ns;
+ wire single_data;
+ reg [5:0] rd_buf_indx_ns;
+ generate begin : rd_buf_indx
+ wire upd_rd_buf_indx = ~ram_init_done_r_lcl || app_rd_data_valid_ns;
+// Loop through all status write addresses once after rst. Initializes
+// the status and pointer RAMs.
+ wire ram_init_done_ns =
+ ~rst && (ram_init_done_r_lcl || (rd_buf_indx_r[4:0] == 5\'h1f));
+ always @(posedge clk) ram_init_done_r_lcl <= #TCQ ram_init_done_ns;
+
+ always @(/*AS*/rd_buf_indx_r or rst or single_data
+ or upd_rd_buf_indx) begin
+ rd_buf_indx_ns = rd_buf_indx_r;
+ if (rst) rd_buf_indx_ns = 6\'b0;
+ else if (upd_rd_buf_indx) rd_buf_indx_ns =
+ // need to use every slot of RAMB32 if all address bits are used
+ rd_buf_indx_r + 6\'h1 + (DATA_BUF_ADDR_WIDTH == 5 ? 0 : single_data);
+ end
+ always @(posedge clk) rd_buf_indx_r <= #TCQ rd_buf_indx_ns;
+ end
+ endgenerate
+ assign ram_init_addr = rd_buf_indx_r[3:0];
+
+ input rd_data_en;
+ input [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr;
+ input rd_data_offset;
+ input rd_data_end;
+ input [APP_DATA_WIDTH-1:0] rd_data;
+(* keep = ""true"", max_fanout = 10 *) output reg app_rd_data_valid;
+ output reg app_rd_data_end;
+ output reg [APP_DATA_WIDTH-1:0] app_rd_data;
+ input [3:0] ecc_multiple;
+ reg [2*nCK_PER_CLK-1:0] app_ecc_multiple_err_r = \'b0;
+ output wire [2*nCK_PER_CLK-1:0] app_ecc_multiple_err;
+ assign app_ecc_multiple_err = app_ecc_multiple_err_r;
+ input rd_accepted;
+ output wire rd_buf_full;
+ output wire [DATA_BUF_ADDR_WIDTH-1:0] rd_data_buf_addr_r;
+
+// Compute dimensions of read data buffer. Depending on width of
+// DQ bus and DRAM CK
+// to fabric ratio, number of RAM32Ms is variable. RAM32Ms are used in
+// single write, single read, 6 bit wide mode.
+ localparam RD_BUF_WIDTH = APP_DATA_WIDTH + (ECC == ""OFF"" ? 0 : 2*nCK_PER_CLK);
+ localparam FULL_RAM_CNT = (RD_BUF_WIDTH/6);
+ localparam REMAINDER = RD_BUF_WIDTH % 6;
+ localparam RAM_CNT = FULL_RAM_CNT + ((REMAINDER == 0 ) ? 0 : 1);
+ localparam RAM_WIDTH = (RAM_CNT*6);
+ generate
+ if (ORDERING == ""STRICT"") begin : strict_mode
+ assign app_rd_data_valid_ns = 1\'b0;
+ assign single_data = 1\'b0;
+ assign rd_buf_full = 1\'b0;
+ reg [DATA_BUF_ADDR_WIDTH-1:0] rd_data_buf_addr_r_lcl;
+ wire [DATA_BUF_ADDR_WIDTH-1:0] rd_data_buf_addr_ns =
+ rst
+ ? 0
+ : rd_data_buf_addr_r_lcl + rd_accepted;
+ always @(posedge clk) rd_data_buf_addr_r_lcl <=
+ #TCQ rd_data_buf_addr_ns;
+ assign rd_data_buf_addr_r = rd_data_buf_addr_ns;
+// app_* signals required to be registered.
+ if (ECC == ""OFF"") begin : ecc_off
+ always @(/*AS*/rd_data) app_rd_data = rd_data;
+ always @(/*AS*/rd_data_en) app_rd_data_valid = rd_data_en;
+ always @(/*AS*/rd_data_end) app_rd_data_end = rd_data_end;
+ end
+ else begin : ecc_on
+ always @(posedge clk) app_rd_data <= #TCQ rd_data;
+ always @(posedge clk) app_rd_data_valid <= #TCQ rd_data_en;
+ always @(posedge clk) app_rd_data_end <= #TCQ rd_data_end;
+ always @(posedge clk) app_ecc_multiple_err_r <= #TCQ ecc_multiple;
+ end
+ end
+ else begin : not_strict_mode
+(* keep = ""true"", max_fanout = 10 *) wire rd_buf_we = ~ram_init_done_r_lcl || rd_data_en;
+ // In configurations where read data is returned in a single fabric cycle
+ // the offset is always zero and we can use the bit to get a deeper
+ // FIFO. The RAMB32 has 5 address bits, so when the DATA_BUF_ADDR_WIDTH
+ // is set to use them all, discard the offset. Otherwise, include the
+ // offset.
+ wire [4:0] rd_buf_wr_addr = DATA_BUF_ADDR_WIDTH == 5 ?
+ rd_data_addr :
+ {rd_data_addr, rd_data_offset};
+ wire [1:0] rd_status;
+// Instantiate status RAM. One bit for status and one for ""end"".
+ begin : status_ram
+// Turns out read to write back status is a timing path. Update
+// the status in the ram on the state following the read. Bypass
+// the write data into the status read path.
+ wire [4:0] status_ram_wr_addr_ns = ram_init_done_r_lcl
+ ? rd_buf_wr_addr
+ : rd_buf_indx_r[4:0];
+ reg [4:0] status_ram_wr_addr_r;
+ always @(posedge clk) status_ram_wr_addr_r <=
+ #TCQ status_ram_wr_addr_ns;
+ wire [1:0] wr_status;
+// Not guaranteed to write second status bit. If it is written, always
+// copy in the first status bit.
+ reg wr_status_r1;
+ always @(posedge clk) wr_status_r1 <= #TCQ wr_status[0];
+ wire [1:0] status_ram_wr_data_ns =
+ ram_init_done_r_lcl
+ ? {rd_data_end, ~(rd_data_offset
+ ? wr_status_r1
+ : wr_status[0])}
+ : 2\'b0;
+ reg [1:0] status_ram_wr_data_r;
+ always @(posedge clk) status_ram_wr_data_r <=
+ #TCQ status_ram_wr_data_ns;
+ reg rd_buf_we_r1;
+ always @(posedge clk) rd_buf_we_r1 <= #TCQ rd_buf_we;
+ RAM32M
+ #(.INIT_A(64\'h0000000000000000),
+ .INIT_B(64\'h0000000000000000),
+ .INIT_C(64\'h0000000000000000),
+ .INIT_D(64\'h0000000000000000)
+ ) RAM32M0 (
+ .DOA(rd_status),
+ .DOB(),
+ .DOC(wr_status),
+ .DOD(),
+ .DIA(status_ram_wr_data_r),
+ .DIB(2\'b0),
+ .DIC(status_ram_wr_data_r),
+ .DID(status_ram_wr_data_r),
+ .ADDRA(rd_buf_indx_r[4:0]),
+ .ADDRB(5\'b0),
+ .ADDRC(status_ram_wr_addr_ns),
+ .ADDRD(status_ram_wr_addr_r),
+ .WE(rd_buf_we_r1),
+ .WCLK(clk)
+ );
+ end // block: status_ram
+
+ wire [RAM_WIDTH-1:0] rd_buf_out_data;
+ begin : rd_buf
+ wire [RAM_WIDTH-1:0] rd_buf_in_data;
+ if (REMAINDER == 0)
+ if (ECC == ""OFF"")
+ assign rd_buf_in_data = rd_data;
+ else
+ assign rd_buf_in_data = {ecc_multiple, rd_data};
+ else
+ if (ECC == ""OFF"")
+ assign rd_buf_in_data = {{6-REMAINDER{1\'b0}}, rd_data};
+ else
+ assign rd_buf_in_data =
+ {{6-REMAINDER{1\'b0}}, ecc_multiple, rd_data};
+
+ // Dedicated copy for driving distributed RAM.
+ (* keep = ""true"" *)
+ reg [4:0] rd_buf_indx_copy_r;
+ always @(posedge clk) rd_buf_indx_copy_r <= #TCQ rd_buf_indx_ns[4:0];
+
+ genvar i;
+ for (i=0; i 1)
+ begin
+ if(dma_data_avail_i)
+ begin
+ rd_dma_fifo_o <= 1'b1;
+ state <= DDR_WR;
+ rd_data_cnt <= rd_data_cnt + 1'b1;
+ end
+ else
+ state <= START;
+ if(rd_data_cnt == 0)
+ o_switch_recv_buffer <= 1'b1;
+ end
+ else
+ begin
+ state <= IDLE;
+ o_clr_recv_buffer <= 1'b1;
+ end
+ end
+ end
+ DDR_PW1:begin
+ if(ddr_wr_ack_i)
+ begin
+ ddr_wr_req_o <= 1'b1;
+ ddr_wr_be_n_o <= ddr_be[31:0];;
+ state <= DDR_PW2;
+ end
+ end\t
+ DDR_PW2:begin
+ if(ddr_wr_ack_i)
+ begin
+ ddr_wr_req_o <= 1'b0;
+ pio_wr_ack_o <= 1'b1;
+ end
+ \t\t\t if(~pio_wr_req_p1)
+ \t\t\t begin
+ \t\t\t state <= IDLE;
+ \t\t\t\t pio_wr_ack_o <= 1'b0;
+ \t\t\t end\t
+ \t\t\t end\t
+ DDR_RD:begin
+ if(ddr_rd_ack_i)
+ begin
+ ddr_rd_req_o <= 1'b0;
+ state <= RD_DAT1;
+ end
+ end
+ \t\t \t RD_DAT1:begin
+\t\t\t\t\t if(ddr_data_valid_i)
+ \t\t\t begin
+\t\t\t\t\t case(pio_fpga_addr_i[5:2])
+ 'd0:begin
+ pio_data_o <= ddr_data_i[255:224];
+ end
+ 'd1:begin
+ pio_data_o <= ddr_data_i[223:192];
+ end
+ 'd2:begin
+ pio_data_o <= ddr_data_i[191:160];
+ end
+ 'd3:begin
+ pio_data_o <= ddr_data_i[159:128];
+ end
+ 'd4:begin
+ pio_data_o <= ddr_data_i[127:96];
+ end
+ 'd5:begin
+ pio_data_o <= ddr_data_i[95:64];
+ end
+ 'd6:begin
+ pio_data_o <= ddr_data_i[63:32];
+ end
+ 'd7:begin
+ pio_data_o <= ddr_data_i[31:0];
+\t\t\t\t\t end
+\t\t\t\t\t endcase
+ \t\t\t state <= RD_DAT2;\t\t\t\t\t\t\t\t
+ \t\t\t end\t
+ \t\t\t end
+ RD_DAT2:begin
+ \t\t\t if(ddr_data_valid_i)
+ \t\t\t\t begin
+ pio_rd_ack_o <= 1'b1;
+\t\t\t\t\t\t\t\tcase(pio_fpga_addr_i[5:2])
+\t 'd8:begin
+ pio_data_o <= ddr_data_i[255:224];
+ end
+ 'd9:begin
+ pio_data_o <= ddr_data_i[223:192];
+ end
+ 'd10:begin
+ pio_data_o <= ddr_data_i[191:160];
+ end
+ 'd11:begin
+ pio_data_o <= ddr_data_i[159:128];
+ end
+ 'd12:begin
+ pio_data_o <= ddr_data_i[127:96];
+ end
+ 'd13:begin
+ pio_data_o <= ddr_data_i[95:64];
+ end
+ 'd14:begin
+ pio_data_o <= ddr_data_i[63:32];
+ end
+ 'd15:begin
+ pio_data_o <= ddr_data_i[31:0];
+ end\t\t\t\t\t\t\t
+\t\t\t\t\t\t\t\tendcase
+ end
+ \t\t\t\t if(~pio_rd_req_p1)
+ \t\t\t\t begin
+ \t\t\t\t state <= IDLE;
+ \t\t\t\t pio_rd_ack_o <= 1'b0;
+ clr_rcv_data_cntr <= 1'b1;
+ \t\t\t\t end
+ \t\t\t end\t
+ CHLEN:begin
+ \t\t\t if(rd_wr_len <= 2)
+ \t\t begin
+ \t\t\t\t last_read_flag <= 1'b1;
+ \t\t\t\t end
+ if(buffer_space >= 2 & ~rd_fifo_full_i)
+ begin
+ \t\t\t\t state <= RDDR;
+ issue_rd <= 1'b1;
+\t\t\t\t\t\t\t\tddr_rd_req_o <= 1'b1;
+ end
+ end
+ \t\t\t RDDR:begin \t\t\t
+ issue_rd <= 1'b0;
+ \t\t\t\t if(ddr_rd_ack_i)
+ \t\t\t\t begin
+ \t\t\t\t ddr_rd_req_o <= 1'b0;
+ ddr_addr_o <= ddr_addr_o + 4'd8;
+ \t\t\t\t if(last_read_flag)
+ \t\t\t\t\t begin
+ \t\t\t\t\t state <= PACK;
+ last_read_flag <= 1'b0;
+ \t\t\t\t\t end\t\t
+ \t\t\t\t\t else if(buffer_space >= 2 & ~rd_fifo_full_i)\t
+ begin
+\t\t\t\t\t\t\t\t issue_rd <= 1'b1;
+\t\t\t\t\t\t\t\t\t ddr_rd_req_o <= 1'b1;
+\t\t\t\t\t\t\t\t\t state <= RDDR;\t\t
+ if(rd_wr_len == 4)
+ \t\t begin
+ \t\t\t\t last_read_flag <= 1'b1;
+\t\t\t\t\t\t\t\t\t end\t
+ \t\t\t\t end\t \t\t\t\t\t\t\t\t
+ else\t\t\t\t\t\t\t\t
+ \t\t\t\t\t state <= CHLEN;
+\t\t\t\t\t\t\t\t\t \t\t\t\t\t\t\t\t\t
+ \t\t\t\t\t if(rd_wr_len >= 2)
+ \t\t\t\t\t rd_wr_len <= rd_wr_len - 2'd2;
+ \t\t\t\t end
+ \t\t\t end
+ PACK:begin
+ fpga_system_dma_ack_o <= 1'b0;
+ if(rcv_data_cntr >= data_len)
+ begin
+ if(rd_fifo_empty_p)
+ fpga_system_dma_ack_o <= 1'b1;
+ end
+ if(fpga_system_dma_ack_o & ~system_dma_req_p)
+ begin
+ fpga_system_dma_ack_o <= 1'b0;
+ state <= IDLE;
+ clr_rcv_data_cntr <= 1'b1;
+ end
+ end
+ endcase
+ end
+ end
+
+ //Since the DDR IP receives back to back read requests and acks, there should be some way to prevent the receive
+ //fifos from over flowing. This block prevents queing more than 8 read requests. For better performance increase
+ //the initial buffer space, then the config buffer depth should be also increased
+ always @(posedge ddr_clk_i)
+ begin
+ if(reset)
+ begin
+ buffer_space <= 'd64;
+ end
+ else
+ begin
+ if(clr_rcv_data_cntr)
+ buffer_space <= 'd64;
+ else if(issue_rd & ~ddr_data_valid_i)
+ buffer_space <= buffer_space - 2'd2;
+ else if(issue_rd & ddr_data_valid_i)
+ buffer_space <= buffer_space - 1'd1;
+ else if(ddr_data_valid_i)
+ buffer_space <= buffer_space + 1'd1;
+ end
+ end
+
+ //Counts the number of bytes received
+ always @(posedge ddr_clk_i)
+ begin
+ if(reset)
+ rcv_data_cntr <= 0;
+ else
+ begin
+ if(clr_rcv_data_cntr)
+ rcv_data_cntr <= 'd0;
+ else if(ddr_data_valid_i)
+ rcv_data_cntr <= rcv_data_cntr + 1'd1;
+ end
+ end
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//
+// (c) Copyright 2010-2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//-----------------------------------------------------------------------------
+// Project : Series-7 Integrated Block for PCI Express
+// File : pcie_7x_v1_8_pcie_pipe_misc.v
+// Version : 1.7
+//
+// Description: Misc PIPE module for 7-Series PCIe Block
+//
+//
+//
+//--------------------------------------------------------------------------------
+
+`timescale 1ps/1ps
+
+module pcie_7x_v1_8_pcie_pipe_misc #
+(
+ parameter PIPE_PIPELINE_STAGES = 0 // 0 - 0 stages, 1 - 1 stage, 2 - 2 stages
+)
+(
+
+ input wire pipe_tx_rcvr_det_i , // PIPE Tx Receiver Detect
+ input wire pipe_tx_reset_i , // PIPE Tx Reset
+ input wire pipe_tx_rate_i , // PIPE Tx Rate
+ input wire pipe_tx_deemph_i , // PIPE Tx Deemphasis
+ input wire [2:0] pipe_tx_margin_i , // PIPE Tx Margin
+ input wire pipe_tx_swing_i , // PIPE Tx Swing
+
+ output wire pipe_tx_rcvr_det_o , // Pipelined PIPE Tx Receiver Detect
+ output wire pipe_tx_reset_o , // Pipelined PIPE Tx Reset
+ output wire pipe_tx_rate_o , // Pipelined PIPE Tx Rate
+ output wire pipe_tx_deemph_o , // Pipelined PIPE Tx Deemphasis
+ output wire [2:0] pipe_tx_margin_o , // Pipelined PIPE Tx Margin
+ output wire pipe_tx_swing_o , // Pipelined PIPE Tx Swing
+
+ input wire pipe_clk , // PIPE Clock
+ input wire rst_n // Reset
+);
+
+//******************************************************************//
+// Reality check. //
+//******************************************************************//
+
+ parameter TCQ = 1; // clock to out delay model
+
+ reg pipe_tx_rcvr_det_q ;
+ reg pipe_tx_reset_q ;
+ reg pipe_tx_rate_q ;
+ reg pipe_tx_deemph_q ;
+ reg [2:0] pipe_tx_margin_q ;
+ reg pipe_tx_swing_q ;
+
+ reg pipe_tx_rcvr_det_qq ;
+ reg pipe_tx_reset_qq ;
+ reg pipe_tx_rate_qq ;
+ reg pipe_tx_deemph_qq ;
+ reg [2:0] pipe_tx_margin_qq ;
+ reg pipe_tx_swing_qq ;
+
+ generate
+
+ if (PIPE_PIPELINE_STAGES == 0) begin : pipe_stages_0
+
+ assign pipe_tx_rcvr_det_o = pipe_tx_rcvr_det_i;
+ assign pipe_tx_reset_o = pipe_tx_reset_i;
+ assign pipe_tx_rate_o = pipe_tx_rate_i;
+ assign pipe_tx_deemph_o = pipe_tx_deemph_i;
+ assign pipe_tx_margin_o = pipe_tx_margin_i;
+ assign pipe_tx_swing_o = pipe_tx_swing_i;
+
+ end // if (PIPE_PIPELINE_STAGES == 0)
+ else if (PIPE_PIPELINE_STAGES == 1) begin : pipe_stages_1
+
+ always @(posedge pipe_clk) begin
+
+ if (rst_n)
+ begin
+
+ pipe_tx_rcvr_det_q <= #TCQ 0;
+ pipe_tx_reset_q <= #TCQ 1\'b1;
+ pipe_tx_rate_q <= #TCQ 0;
+ pipe_tx_deemph_q <= #TCQ 1\'b1;
+ pipe_tx_margin_q <= #TCQ 0;
+ pipe_tx_swing_q <= #TCQ 0;
+
+ end
+ else
+ begin
+
+ pipe_tx_rcvr_det_q <= #TCQ pipe_tx_rcvr_det_i;
+ pipe_tx_reset_q <= #TCQ pipe_tx_reset_i;
+ pipe_tx_rate_q <= #TCQ pipe_tx_rate_i;
+ pipe_tx_deemph_q <= #TCQ pipe_tx_deemph_i;
+ pipe_tx_margin_q <= #TCQ pipe_tx_margin_i;
+ pipe_tx_swing_q <= #TCQ pipe_tx_swing_i;
+
+ end
+
+ end
+
+ assign pipe_tx_rcvr_det_o = pipe_tx_rcvr_det_q;
+ assign pipe_tx_reset_o = pipe_tx_reset_q;
+ assign pipe_tx_rate_o = pipe_tx_rate_q;
+ assign pipe_tx_deemph_o = pipe_tx_deemph_q;
+ assign pipe_tx_margin_o = pipe_tx_margin_q;
+ assign pipe_tx_swing_o = pipe_tx_swing_q;
+
+ end // if (PIPE_PIPELINE_STAGES == 1)
+ else if (PIPE_PIPELINE_STAGES == 2) begin : pipe_stages_2
+
+ always @(posedge pipe_clk) begin
+
+ if (rst_n)
+ begin
+
+ pipe_tx_rcvr_det_q <= #TCQ 0;
+ pipe_tx_reset_q <= #TCQ 1\'b1;
+ pipe_tx_rate_q <= #TCQ 0;
+ pipe_tx_deemph_q <= #TCQ 1\'b1;
+ pipe_tx_margin_q <= #TCQ 0;
+ pipe_tx_swing_q <= #TCQ 0;
+
+ pipe_tx_rcvr_det_qq <= #TCQ 0;
+ pipe_tx_reset_qq <= #TCQ 1\'b1;
+ pipe_tx_rate_qq <= #TCQ 0;
+ pipe_tx_deemph_qq <= #TCQ 1\'b1;
+ pipe_tx_margin_qq <= #TCQ 0;
+ pipe_tx_swing_qq <= #TCQ 0;
+
+ end
+ else
+ begin
+
+ pipe_tx_rcvr_det_q <= #TCQ pipe_tx_rcvr_det_i;
+ pipe_tx_reset_q <= #TCQ pipe_tx_reset_i;
+ pipe_tx_rate_q <= #TCQ pipe_tx_rate_i;
+ pipe_tx_deemph_q <= #TCQ pipe_tx_deemph_i;
+ pipe_tx_margin_q <= #TCQ pipe_tx_margin_i;
+ pipe_tx_swing_q <= #TCQ pipe_tx_swing_i;
+
+ pipe_tx_rcvr_det_qq <= #TCQ pipe_tx_rcvr_det_q;
+ pipe_tx_reset_qq <= #TCQ pipe_tx_reset_q;
+ pipe_tx_rate_qq <= #TCQ pipe_tx_rate_q;
+ pipe_tx_deemph_qq <= #TCQ pipe_tx_deemph_q;
+ pipe_tx_margin_qq <= #TCQ pipe_tx_margin_q;
+ pipe_tx_swing_qq <= #TCQ pipe_tx_swing_q;
+
+ end
+
+ end
+
+ assign pipe_tx_rcvr_det_o = pipe_tx_rcvr_det_qq;
+ assign pipe_tx_reset_o = pipe_tx_reset_qq;
+ assign pipe_tx_rate_o = pipe_tx_rate_qq;
+ assign pipe_tx_deemph_o = pipe_tx_deemph_qq;
+ assign pipe_tx_margin_o = pipe_tx_margin_qq;
+ assign pipe_tx_swing_o = pipe_tx_swing_qq;
+
+ end // if (PIPE_PIPELINE_STAGES == 2)
+
+ endgenerate
+
+endmodule
+
+"
+"//-----------------------------------------------------------------------------
+//
+// (c) Copyright 2009-2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//-----------------------------------------------------------------------------
+// Project : Virtex-6 Integrated Block for PCI Express
+// File : pcie_bram_v6.v
+// Version : 2.4
+//--
+//-- Description: BlockRAM module for Virtex6 PCIe Block
+//--
+//--
+//--
+//--------------------------------------------------------------------------------
+
+`timescale 1ns/1ns
+
+module pcie_bram_v6
+ #(
+ parameter DOB_REG = 0,// 1 use the output register 0 don\'t use the output register
+ parameter WIDTH = 0 // supported WIDTH\'s are: 4, 9, 18, 36 (uses RAMB36) and 72 (uses RAMB36SDP)
+ )
+ (
+ input user_clk_i,// user clock
+ input reset_i, // bram reset
+
+ input wen_i, // write enable
+ input [12:0] waddr_i, // write address
+ input [WIDTH - 1:0] wdata_i, // write data
+
+ input ren_i, // read enable
+ input rce_i, // output register clock enable
+ input [12:0] raddr_i, // read address
+
+ output [WIDTH - 1:0] rdata_o // read data
+ );
+
+ // map the address bits
+ localparam ADDR_MSB = ((WIDTH == 4) ? 12 :
+ (WIDTH == 9) ? 11 :
+ (WIDTH == 18) ? 10 :
+ (WIDTH == 36) ? 9 :
+ 8
+ );
+
+ // set the width of the tied off low address bits
+ localparam ADDR_LO_BITS = ((WIDTH == 4) ? 2 :
+ (WIDTH == 9) ? 3 :
+ (WIDTH == 18) ? 4 :
+ (WIDTH == 36) ? 5 :
+ 0 // for WIDTH 72 use RAMB36SDP
+ );
+
+ // map the data bits
+ localparam D_MSB = ((WIDTH == 4) ? 3 :
+ (WIDTH == 9) ? 7 :
+ (WIDTH == 18) ? 15 :
+ (WIDTH == 36) ? 31 :
+ 63
+ );
+
+ // map the data parity bits
+ localparam DP_LSB = D_MSB + 1;
+
+ localparam DP_MSB = ((WIDTH == 4) ? 4 :
+ (WIDTH == 9) ? 8 :
+ (WIDTH == 18) ? 17 :
+ (WIDTH == 36) ? 35 :
+ 71
+ );
+
+ localparam DPW = DP_MSB - DP_LSB + 1;
+
+ localparam WRITE_MODE = ""NO_CHANGE"";
+
+ //synthesis translate_off
+ initial begin
+ //$display(""[%t] %m DOB_REG %0d WIDTH %0d ADDR_MSB %0d ADDR_LO_BITS %0d DP_MSB %0d DP_LSB %0d D_MSB %0d"",
+ // $time, DOB_REG, WIDTH, ADDR_MSB, ADDR_LO_BITS, DP_MSB, DP_LSB, D_MSB);
+
+ case (WIDTH)
+ 4,9,18,36,72:;
+ default:
+ begin
+ $display(""[%t] %m Error WIDTH %0d not supported"", $time, WIDTH);
+ $finish;
+ end
+ endcase // case (WIDTH)
+ end
+ //synthesis translate_on
+
+ generate
+ if (WIDTH == 72) begin : use_ramb36sdp
+
+ // use RAMB36SDP if the width is 72
+ RAMB36SDP #(
+ .DO_REG (DOB_REG)
+ )
+ ramb36sdp(
+ .WRCLK (user_clk_i),
+ .SSR (1\'b0),
+ .WRADDR (waddr_i[ADDR_MSB:0]),
+ .DI (wdata_i[D_MSB:0]),
+ .DIP (wdata_i[DP_MSB:DP_LSB]),
+ .WREN (wen_i),
+ .WE ({8{wen_i}}),
+ .DBITERR (),
+ .ECCPARITY (),
+ .SBITERR (),
+
+ .RDCLK (user_clk_i),
+ .RDADDR (raddr_i[ADDR_MSB:0]),
+ .DO (rdata_o[D_MSB:0]),
+ .DOP (rdata_o[DP_MSB:DP_LSB]),
+ .RDEN (ren_i),
+ .REGCE (rce_i)
+ );
+
+ // use RAMB36\'s if the width is 4, 9, 18, or 36
+ end else if (WIDTH == 36) begin : use_ramb36
+
+ RAMB36 #(
+ .DOA_REG (0),
+ .DOB_REG (DOB_REG),
+ .READ_WIDTH_A (0),
+ .READ_WIDTH_B (WIDTH),
+ .WRITE_WIDTH_A (WIDTH),
+ .WRITE_WIDTH_B (0),
+ .WRITE_MODE_A (WRITE_MODE)
+ )
+ ramb36(
+ .CLKA (user_clk_i),
+ .SSRA (1\'b0),
+ .REGCEA (1\'b0),
+ .CASCADEINLATA (1\'b0),
+ .CASCADEINREGA (1\'b0),
+ .CASCADEOUTLATA (),
+ .CASCADEOUTREGA (),
+ .DOA (),
+ .DOPA (),
+ .ADDRA ({1\'b1, waddr_i[ADDR_MSB:0], {ADDR_LO_BITS{1\'b1}}}),
+ .DIA (wdata_i[D_MSB:0]),
+ .DIPA (wdata_i[DP_MSB:DP_LSB]),
+ .ENA (wen_i),
+ .WEA ({4{wen_i}}),
+
+ .CLKB (user_clk_i),
+ .SSRB (1\'b0),
+ .WEB (4\'b0),
+ .CASCADEINLATB (1\'b0),
+ .CASCADEINREGB (1\'b0),
+ .CASCADEOUTLATB (),
+ .CASCADEOUTREGB (),
+ .DIB (32\'b0),
+ .DIPB ( 4\'b0),
+ .ADDRB ({1\'b1, raddr_i[ADDR_MSB:0], {ADDR_LO_BITS{1\'b1}}}),
+ .DOB (rdata_o[D_MSB:0]),
+ .DOPB (rdata_o[DP_MSB:DP_LSB]),
+ .ENB (ren_i),
+ .REGCEB (rce_i)
+ );
+
+ end else if (WIDTH < 36 && WIDTH > 4) begin : use_ramb36
+
+ wire [31 - D_MSB - 1 : 0] dob_unused;
+ wire [ 4 - DPW - 1 : 0] dopb_unused;
+
+ RAMB36 #(
+ .DOA_REG (0),
+ .DOB_REG (DOB_REG),
+ .READ_WIDTH_A (0),
+ .READ_WIDTH_B (WIDTH),
+ .WRITE_WIDTH_A (WIDTH),
+ .WRITE_WIDTH_B (0),
+ .WRITE_MODE_A (WRITE_MODE)
+ )
+ ramb36(
+ .CLKA (user_clk_i),
+ .SSRA (1\'b0),
+ .REGCEA (1\'b0),
+ .CASCADEINLATA (1\'b0),
+ .CASCADEINREGA (1\'b0),
+ .CASCADEOUTLATA (),
+ .CASCADEOUTREGA (),
+ .DOA (),
+ .DOPA (),
+ .ADDRA ({1\'b1, waddr_i[ADDR_MSB:0], {ADDR_LO_BITS{1\'b1}}}),
+ .DIA ({{31 - D_MSB{1\'b0}},wdata_i[D_MSB:0]}),
+ .DIPA ({{ 4 - DPW {1\'b0}},wdata_i[DP_MSB:DP_LSB]}),
+ .ENA (wen_i),
+ .WEA ({4{wen_i}}),
+
+ .CLKB (user_clk_i),
+ .SSRB (1\'b0),
+ .WEB (4\'b0),
+ .CASCADEINLATB (1\'b0),
+ .CASCADEINREGB (1\'b0),
+ .CASCADEOUTLATB (),
+ .CASCADEOUTREGB (),
+ .DIB (32\'b0),
+ .DIPB ( 4\'b0),
+ .ADDRB ({1\'b1, raddr_i[ADDR_MSB:0], {ADDR_LO_BITS{1\'b1}}}),
+ .DOB ({dob_unused, rdata_o[D_MSB:0]}),
+ .DOPB ({dopb_unused, rdata_o[DP_MSB:DP_LSB]}),
+ .ENB (ren_i),
+ .REGCEB (rce_i)
+ );
+
+ end else if (WIDTH == 4) begin : use_ramb36
+
+ wire [31 - D_MSB - 1 : 0] dob_unused;
+
+ RAMB36 #(
+ .DOB_REG (DOB_REG),
+ .READ_WIDTH_A (0),
+ .READ_WIDTH_B (WIDTH),
+ .WRITE_WIDTH_A (WIDTH),
+ .WRITE_WIDTH_B (0),
+ .WRITE_MODE_A (WRITE_MODE)
+ )
+ ramb36(
+ .CLKA (user_clk_i),
+ .SSRA (1\'b0),
+ .REGCEA (1\'b0),
+ .CASCADEINLATA (1\'b0),
+ .CASCADEINREGA (1\'b0),
+ .CASCADEOUTLATA (),
+ .CASCADEOUTREGA (),
+ .DOA (),
+ .DOPA (),
+ .ADDRA ({1\'b1, waddr_i[ADDR_MSB:0], {ADDR_LO_BITS{1\'b1}}}),
+ .DIA ({{31 - D_MSB{1\'b0}},wdata_i[D_MSB:0]}),
+ //.DIPA (wdata_i[DP_MSB:DP_LSB]),
+ .ENA (wen_i),
+ .WEA ({4{wen_i}}),
+
+ .CLKB (user_clk_i),
+ .SSRB (1\'b0),
+ .WEB (4\'b0),
+ .CASCADEINLATB (1\'b0),
+ .CASCADEINREGB (1\'b0),
+ .CASCADEOUTLATB (),
+ .CASCADEOUTREGB (),
+ .ADDRB ({1\'b1, raddr_i[ADDR_MSB:0], {ADDR_LO_BITS{1\'b1}}}),
+ .DOB ({dob_unused,rdata_o[D_MSB:0]}),
+ //.DOPB (rdata_o[DP_MSB:DP_LSB]),
+ .ENB (ren_i),
+ .REGCEB (rce_i)
+ );
+
+ end // block: use_ramb36
+ endgenerate
+
+endmodule // pcie_bram_v6
+"
+"//--------------------------------------------------------------------------------
+// Project : SWITCH
+// File : v6_emac_v2_2.v
+// Version : 0.2
+// Author : Shreejith S
+//
+// Description: EMAC Instantiation - XILINX
+//
+//--------------------------------------------------------------------------------
+
+//
+// (c) Copyright 2010-2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+// Description: This is the Verilog module instantiation for the Virtex-6
+// Embedded Tri-Mode Ethernet MAC.
+//
+// ------------------------------------------------------------------------------
+
+ module v6_emac_v2_2
+ (
+
+ //-------------------------------------------------------------------------
+ // Clock signals - used in rgmii and serial modes
+ //-------------------------------------------------------------------------
+ input gtx_clk,
+
+ //-------------------------------------------------------------------------
+ // Receiver Interface.
+ //-------------------------------------------------------------------------
+ input rx_axi_clk,
+ output rx_reset_out,
+ output [7:0] rx_axis_mac_tdata,
+ output rx_axis_mac_tvalid,
+ output rx_axis_mac_tlast,
+ output rx_axis_mac_tuser,
+
+ // RX sideband signals
+ output [27:0] rx_statistics_vector,
+ output rx_statistics_valid,
+
+ //-------------------------------------------------------------------------
+ // Transmitter Interface
+ //-------------------------------------------------------------------------
+ input tx_axi_clk,
+ output tx_reset_out,
+ input [7:0] tx_axis_mac_tdata,
+ input tx_axis_mac_tvalid,
+ input tx_axis_mac_tlast,
+ input tx_axis_mac_tuser,
+ output tx_axis_mac_tready,
+
+ // TX sideband signals
+ output tx_retransmit,
+ output tx_collision,
+ input [7:0] tx_ifg_delay,
+ output [31:0] tx_statistics_vector,
+ output tx_statistics_valid,
+
+ //-------------------------------------------------------------------------
+ // Flow Control
+ //-------------------------------------------------------------------------
+ input pause_req,
+ input [15:0] pause_val,
+
+ //-------------------------------------------------------------------------
+ // Speed interface
+ //-------------------------------------------------------------------------
+ output speed_is_10_100,
+
+ //-------------------------------------------------------------------------
+ // GMII/MII Interface
+ //-------------------------------------------------------------------------
+ output [7:0] gmii_txd,
+ output gmii_tx_en,
+ output gmii_tx_er,
+ input gmii_col,
+ input gmii_crs,
+ input [7:0] gmii_rxd,
+ input gmii_rx_dv,
+ input gmii_rx_er,
+
+
+
+
+ //-------------------------------------------------------------------------
+ // Resets
+ //-------------------------------------------------------------------------
+
+ input glbl_rstn,
+ input rx_axi_rstn,
+ input tx_axi_rstn
+
+ );
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2008 - 2012 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : %version
+// \\ \\ Application : MIG
+// / / Filename : ddr_mc_phy_wrapper.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Oct 10 2010
+// \\___\\/\\___\\
+//
+//Device : 7 Series
+//Design Name : DDR3 SDRAM
+//Purpose : Wrapper file that encompasses the MC_PHY module
+// instantiation and handles the vector remapping between
+// the MC_PHY ports and the user\'s DDR3 ports. Vector
+// remapping affects DDR3 control, address, and DQ/DQS/DM.
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+`timescale 1 ps / 1 ps
+
+module mig_7series_v1_8_ddr_mc_phy_wrapper #
+ (
+ parameter TCQ = 100, // Register delay (simulation only)
+ parameter tCK = 2500, // ps
+ parameter BANK_TYPE = ""HP_IO"", // # = ""HP_IO"", ""HPL_IO"", ""HR_IO"", ""HRL_IO""
+ parameter DATA_IO_PRIM_TYPE = ""DEFAULT"", // # = ""HP_LP"", ""HR_LP"", ""DEFAULT""
+ parameter DATA_IO_IDLE_PWRDWN = ""ON"", // ""ON"" or ""OFF""
+ parameter IODELAY_GRP = ""IODELAY_MIG"",
+ parameter nCK_PER_CLK = 4, // Memory:Logic clock ratio
+ parameter nCS_PER_RANK = 1, // # of unique CS outputs per rank
+ parameter BANK_WIDTH = 3, // # of bank address
+ parameter CKE_WIDTH = 1, // # of clock enable outputs
+ parameter CS_WIDTH = 1, // # of chip select
+ parameter CK_WIDTH = 1, // # of CK
+ parameter CWL = 5, // CAS Write latency
+ parameter DDR2_DQSN_ENABLE = ""YES"", // Enable differential DQS for DDR2
+ parameter DM_WIDTH = 8, // # of data mask
+ parameter DQ_WIDTH = 16, // # of data bits
+ parameter DQS_CNT_WIDTH = 3, // ceil(log2(DQS_WIDTH))
+ parameter DQS_WIDTH = 8, // # of strobe pairs
+ parameter DRAM_TYPE = ""DDR3"", // DRAM type (DDR2, DDR3)
+ parameter RANKS = 4, // # of ranks
+ parameter ODT_WIDTH = 1, // # of ODT outputs
+ parameter REG_CTRL = ""OFF"", // ""ON"" for registered DIMM
+ parameter ROW_WIDTH = 16, // # of row/column address
+ parameter USE_CS_PORT = 1, // Support chip select output
+ parameter USE_DM_PORT = 1, // Support data mask output
+ parameter USE_ODT_PORT = 1, // Support ODT output
+ parameter IBUF_LPWR_MODE = ""OFF"", // input buffer low power option
+ parameter LP_DDR_CK_WIDTH = 2,
+
+ // Hard PHY parameters
+ parameter PHYCTL_CMD_FIFO = ""FALSE"",
+ parameter DATA_CTL_B0 = 4\'hc,
+ parameter DATA_CTL_B1 = 4\'hf,
+ parameter DATA_CTL_B2 = 4\'hf,
+ parameter DATA_CTL_B3 = 4\'hf,
+ parameter DATA_CTL_B4 = 4\'hf,
+ parameter BYTE_LANES_B0 = 4\'b1111,
+ parameter BYTE_LANES_B1 = 4\'b0000,
+ parameter BYTE_LANES_B2 = 4\'b0000,
+ parameter BYTE_LANES_B3 = 4\'b0000,
+ parameter BYTE_LANES_B4 = 4\'b0000,
+ parameter PHY_0_BITLANES = 48\'h0000_0000_0000,
+ parameter PHY_1_BITLANES = 48\'h0000_0000_0000,
+ parameter PHY_2_BITLANES = 48\'h0000_0000_0000,
+ // Parameters calculated outside of this block
+ parameter HIGHEST_BANK = 3, // Highest I/O bank index
+ parameter HIGHEST_LANE = 12, // Highest byte lane index
+ // ** Pin mapping parameters
+ // Parameters for mapping between hard PHY and physical DDR3 signals
+ // There are 2 classes of parameters:
+ // - DQS_BYTE_MAP, CK_BYTE_MAP, CKE_ODT_BYTE_MAP: These consist of
+ // 8-bit elements. Each element indicates the bank and byte lane
+ // location of that particular signal. The bit lane in this case
+ // doesn\'t need to be specified, either because there\'s only one
+ // pin pair in each byte lane that the DQS or CK pair can be
+ // located at, or in the case of CKE_ODT_BYTE_MAP, only the byte
+ // lane needs to be specified in order to determine which byte
+ // lane generates the RCLK (Note that CKE, and ODT must be located
+ // in the same bank, thus only one element in CKE_ODT_BYTE_MAP)
+ // [7:4] = bank # (0-4)
+ // [3:0] = byte lane # (0-3)
+ // - All other MAP parameters: These consist of 12-bit elements. Each
+ // element indicates the bank, byte lane, and bit lane location of
+ // that particular signal:
+ // [11:8] = bank # (0-4)
+ // [7:4] = byte lane # (0-3)
+ // [3:0] = bit lane # (0-11)
+ // Note that not all elements in all parameters will be used - it
+ // depends on the actual widths of the DDR3 buses. The parameters are
+ // structured to support a maximum of:
+ // - DQS groups: 18
+ // - data mask bits: 18
+ // In addition, the default parameter size of some of the parameters will
+ // support a certain number of bits, however, this can be expanded at
+ // compile time by expanding the width of the vector passed into this
+ // parameter
+ // - chip selects: 10
+ // - bank bits: 3
+ // - address bits: 16
+ parameter CK_BYTE_MAP
+ = 144\'h00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00,
+ parameter ADDR_MAP
+ = 192\'h000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000,
+ parameter BANK_MAP = 36\'h000_000_000,
+ parameter CAS_MAP = 12\'h000,
+ parameter CKE_ODT_BYTE_MAP = 8\'h00,
+ parameter CKE_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter ODT_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter CKE_ODT_AUX = ""FALSE"",
+ parameter CS_MAP = 120\'h000_000_000_000_000_000_000_000_000_000,
+ parameter PARITY_MAP = 12\'h000,
+ parameter RAS_MAP = 12\'h000,
+ parameter WE_MAP = 12\'h000,
+ parameter DQS_BYTE_MAP
+ = 144\'h00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00,
+ // DATAx_MAP parameter is used for byte lane X in the design
+ parameter DATA0_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA1_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA2_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA3_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA4_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA5_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA6_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA7_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA8_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA9_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA10_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA11_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA12_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA13_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA14_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA15_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA16_MAP = 96\'h000_000_000_000_000_000_000_000,
+ parameter DATA17_MAP = 96\'h000_000_000_000_000_000_000_000,
+ // MASK0_MAP used for bytes [8:0], MASK1_MAP for bytes [17:9]
+ parameter MASK0_MAP = 108\'h000_000_000_000_000_000_000_000_000,
+ parameter MASK1_MAP = 108\'h000_000_000_000_000_000_000_000_000,
+ // Simulation options
+ parameter SIM_CAL_OPTION = ""NONE"",
+
+ // The PHY_CONTROL primitive in the bank where PLL exists is declared
+ // as the Master PHY_CONTROL.
+ parameter MASTER_PHY_CTL = 1
+ )
+ (
+ input rst,
+ input clk,
+ input freq_refclk,
+ input mem_refclk,
+ input pll_lock,
+ input sync_pulse,
+ input idelayctrl_refclk,
+ input phy_cmd_wr_en,
+ input phy_data_wr_en,
+ input [31:0] phy_ctl_wd,
+ input phy_ctl_wr,
+ input phy_if_empty_def,
+ input phy_if_reset,
+ input [5:0] data_offset_1,
+ input [5:0] data_offset_2,
+ input [3:0] aux_in_1,
+ input [3:0] aux_in_2,
+ output [4:0] idelaye2_init_val,
+ output [5:0] oclkdelay_init_val,
+ output if_empty,
+ output phy_ctl_full,
+ output phy_cmd_full,
+ output phy_data_full,
+ output phy_pre_data_a_full,
+ output [(CK_WIDTH * LP_DDR_CK_WIDTH)-1:0] ddr_clk,
+ output phy_mc_go,
+ input phy_write_calib,
+ input phy_read_calib,
+ input calib_in_common,
+ input [5:0] calib_sel,
+ input [HIGHEST_BANK-1:0] calib_zero_inputs,
+ input [HIGHEST_BANK-1:0] calib_zero_ctrl,
+ input [2:0] po_fine_enable,
+ input [2:0] po_coarse_enable,
+ input [2:0] po_fine_inc,
+ input [2:0] po_coarse_inc,
+ input po_counter_load_en,
+ input po_counter_read_en,
+ input [2:0] po_sel_fine_oclk_delay,
+ input [8:0] po_counter_load_val,
+ output [8:0] po_counter_read_val,
+ output [5:0] pi_counter_read_val,
+ input [HIGHEST_BANK-1:0] pi_rst_dqs_find,
+ input pi_fine_enable,
+ input pi_fine_inc,
+ input pi_counter_load_en,
+ input [5:0] pi_counter_load_val,
+ input idelay_ce,
+ input idelay_inc,
+ input idelay_ld,
+ input idle,
+ output pi_phase_locked,
+ output pi_phase_locked_all,
+ output pi_dqs_found,
+ output pi_dqs_found_all,
+ output pi_dqs_out_of_range,
+ // From/to calibration logic/soft PHY
+ input phy_init_data_sel,
+ input [nCK_PER_CLK*ROW_WIDTH-1:0] mux_address,
+ input [nCK_PER_CLK*BANK_WIDTH-1:0] mux_bank,
+ input [nCK_PER_CLK-1:0] mux_cas_n,
+ input [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] mux_cs_n,
+ input [nCK_PER_CLK-1:0] mux_ras_n,
+ input [1:0] mux_odt,
+ input [nCK_PER_CLK-1:0] mux_cke,
+ input [nCK_PER_CLK-1:0] mux_we_n,
+ input [nCK_PER_CLK-1:0] parity_in,
+ input [2*nCK_PER_CLK*DQ_WIDTH-1:0] mux_wrdata,
+ input [2*nCK_PER_CLK*(DQ_WIDTH/8)-1:0] mux_wrdata_mask,
+ input mux_reset_n,
+ output [2*nCK_PER_CLK*DQ_WIDTH-1:0] rd_data,
+ // Memory I/F
+ output [ROW_WIDTH-1:0] ddr_addr,
+ output [BANK_WIDTH-1:0] ddr_ba,
+ output ddr_cas_n,
+ output [CKE_WIDTH-1:0] ddr_cke,
+ output [CS_WIDTH*nCS_PER_RANK-1:0] ddr_cs_n,
+ output [DM_WIDTH-1:0] ddr_dm,
+ output [ODT_WIDTH-1:0] ddr_odt,
+ output ddr_parity,
+ output ddr_ras_n,
+ output ddr_we_n,
+ output ddr_reset_n,
+ inout [DQ_WIDTH-1:0] ddr_dq,
+ inout [DQS_WIDTH-1:0] ddr_dqs,
+ inout [DQS_WIDTH-1:0] ddr_dqs_n
+
+ ,input dbg_pi_counter_read_en
+ ,output ref_dll_lock
+ ,input rst_phaser_ref
+ ,output [11:0] dbg_pi_phase_locked_phy4lanes
+ ,output [11:0] dbg_pi_dqs_found_lanes_phy4lanes
+ );
+
+ function [71:0] generate_bytelanes_ddr_ck;
+ input [143:0] ck_byte_map;
+ integer v ;
+ begin
+ generate_bytelanes_ddr_ck = \'b0 ;
+ for (v = 0; v < CK_WIDTH; v = v + 1) begin
+ if ((CK_BYTE_MAP[((v*8)+4)+:4]) == 2)
+ generate_bytelanes_ddr_ck[48+(4*v)+1*(CK_BYTE_MAP[(v*8)+:4])] = 1\'b1;
+ else if ((CK_BYTE_MAP[((v*8)+4)+:4]) == 1)
+ generate_bytelanes_ddr_ck[24+(4*v)+1*(CK_BYTE_MAP[(v*8)+:4])] = 1\'b1;
+ else
+ generate_bytelanes_ddr_ck[4*v+1*(CK_BYTE_MAP[(v*8)+:4])] = 1\'b1;
+ end
+ end
+ endfunction
+
+ function [(2*CK_WIDTH*8)-1:0] generate_ddr_ck_map;
+ input [143:0] ck_byte_map;
+ integer g;
+ begin
+ generate_ddr_ck_map = \'b0 ;
+ for(g = 0 ; g < CK_WIDTH ; g= g + 1) begin
+ generate_ddr_ck_map[(g*2*8)+:8] = (ck_byte_map[(g*8)+:4] == 4\'d0) ? ""A"" :
+ (ck_byte_map[(g*8)+:4] == 4\'d1) ? ""B"" :
+ (ck_byte_map[(g*8)+:4] == 4\'d2) ? ""C"" : ""D"" ;
+ generate_ddr_ck_map[(((g*2)+1)*8)+:8] = (ck_byte_map[((g*8)+4)+:4] == 4\'d0) ? ""0"" :
+ (ck_byte_map[((g*8)+4)+:4] == 4\'d1) ? ""1"" : ""2"" ; //each STRING charater takes 0 location
+ end
+ end
+ endfunction
+
+
+
+ // Enable low power mode for input buffer
+ localparam IBUF_LOW_PWR
+ = (IBUF_LPWR_MODE == ""OFF"") ? ""FALSE"" :
+ ((IBUF_LPWR_MODE == ""ON"") ? ""TRUE"" : ""ILLEGAL"");
+
+ // Ratio of data to strobe
+ localparam DQ_PER_DQS = DQ_WIDTH / DQS_WIDTH;
+ // number of data phases per internal clock
+ localparam PHASE_PER_CLK = 2*nCK_PER_CLK;
+ // used to determine routing to OUT_FIFO for control/address for 2:1
+ // vs. 4:1 memory:internal clock ratio modes
+ localparam PHASE_DIV = 4 / nCK_PER_CLK;
+
+ localparam CLK_PERIOD = tCK * nCK_PER_CLK;
+
+ // Create an aggregate parameters for data mapping to reduce # of generate
+ // statements required in remapping code. Need to account for the case
+ // when the DQ:DQS ratio is not 8:1 - in this case, each DATAx_MAP
+ // parameter will have fewer than 8 elements used
+ localparam FULL_DATA_MAP = {DATA17_MAP[12*DQ_PER_DQS-1:0],
+ DATA16_MAP[12*DQ_PER_DQS-1:0],
+ DATA15_MAP[12*DQ_PER_DQS-1:0],
+ DATA14_MAP[12*DQ_PER_DQS-1:0],
+ DATA13_MAP[12*DQ_PER_DQS-1:0],
+ DATA12_MAP[12*DQ_PER_DQS-1:0],
+ DATA11_MAP[12*DQ_PER_DQS-1:0],
+ DATA10_MAP[12*DQ_PER_DQS-1:0],
+ DATA9_MAP[12*DQ_PER_DQS-1:0],
+ DATA8_MAP[12*DQ_PER_DQS-1:0],
+ DATA7_MAP[12*DQ_PER_DQS-1:0],
+ DATA6_MAP[12*DQ_PER_DQS-1:0],
+ DATA5_MAP[12*DQ_PER_DQS-1:0],
+ DATA4_MAP[12*DQ_PER_DQS-1:0],
+ DATA3_MAP[12*DQ_PER_DQS-1:0],
+ DATA2_MAP[12*DQ_PER_DQS-1:0],
+ DATA1_MAP[12*DQ_PER_DQS-1:0],
+ DATA0_MAP[12*DQ_PER_DQS-1:0]};
+ // Same deal, but for data mask mapping
+ localparam FULL_MASK_MAP = {MASK1_MAP, MASK0_MAP};
+ localparam TMP_BYTELANES_DDR_CK = generate_bytelanes_ddr_ck(CK_BYTE_MAP) ;
+ localparam TMP_GENERATE_DDR_CK_MAP = generate_ddr_ck_map(CK_BYTE_MAP) ;
+
+ // Temporary parameters to determine which bank is outputting the CK/CK#
+ // Eventually there will be support for multiple CK/CK# output
+ //localparam TMP_DDR_CLK_SELECT_BANK = (CK_BYTE_MAP[7:4]);
+ //// Temporary method to force MC_PHY to generate ODDR associated with
+ //// CK/CK# output only for a single byte lane in the design. All banks
+ //// that won\'t be generating the CK/CK# will have ""UNUSED"" as their
+ //// PHY_GENERATE_DDR_CK parameter
+ //localparam TMP_PHY_0_GENERATE_DDR_CK
+ // = (TMP_DDR_CLK_SELECT_BANK != 0) ? ""UNUSED"" :
+ // ((CK_BYTE_MAP[1:0] == 2\'b00) ? ""A"" :
+ // ((CK_BYTE_MAP[1:0] == 2\'b01) ? ""B"" :
+ // ((CK_BYTE_MAP[1:0] == 2\'b10) ? ""C"" : ""D"")));
+ //localparam TMP_PHY_1_GENERATE_DDR_CK
+ // = (TMP_DDR_CLK_SELECT_BANK != 1) ? ""UNUSED"" :
+ // ((CK_BYTE_MAP[1:0] == 2\'b00) ? ""A"" :
+ // ((CK_BYTE_MAP[1:0] == 2\'b01) ? ""B"" :
+ // ((CK_BYTE_MAP[1:0] == 2\'b10) ? ""C"" : ""D"")));
+ //localparam TMP_PHY_2_GENERATE_DDR_CK
+ // = (TMP_DDR_CLK_SELECT_BANK != 2) ? ""UNUSED"" :
+ // ((CK_BYTE_MAP[1:0] == 2\'b00) ? ""A"" :
+ // ((CK_BYTE_MAP[1:0] == 2\'b01) ? ""B"" :
+ // ((CK_BYTE_MAP[1:0] == 2\'b10) ? ""C"" : ""D"")));
+
+ // Function to generate MC_PHY parameters PHY_BITLANES_OUTONLYx
+ // which indicates which bit lanes in data byte lanes are
+ // output-only bitlanes (e.g. used specifically for data mask outputs)
+ function [143:0] calc_phy_bitlanes_outonly;
+ input [215:0] data_mask_in;
+ integer z;
+ begin
+ calc_phy_bitlanes_outonly = \'b0;
+ // Only enable BITLANES parameters for data masks if, well, if
+ // the data masks are actually enabled
+ if (USE_DM_PORT == 1)
+ for (z = 0; z < DM_WIDTH; z = z + 1)
+ calc_phy_bitlanes_outonly[48*data_mask_in[(12*z+8)+:3] +
+ 12*data_mask_in[(12*z+4)+:2] +
+ data_mask_in[12*z+:4]] = 1\'b1;
+ end
+ endfunction
+
+ localparam PHY_BITLANES_OUTONLY = calc_phy_bitlanes_outonly(FULL_MASK_MAP);
+ localparam PHY_0_BITLANES_OUTONLY = PHY_BITLANES_OUTONLY[47:0];
+ localparam PHY_1_BITLANES_OUTONLY = PHY_BITLANES_OUTONLY[95:48];
+ localparam PHY_2_BITLANES_OUTONLY = PHY_BITLANES_OUTONLY[143:96];
+
+ // Determine which bank and byte lane generates the RCLK used to clock
+ // out the auxilliary (ODT, CKE) outputs
+ localparam CKE_ODT_RCLK_SELECT_BANK_AUX_ON
+ = (CKE_ODT_BYTE_MAP[7:4] == 4\'h0) ? 0 :
+ ((CKE_ODT_BYTE_MAP[7:4] == 4\'h1) ? 1 :
+ ((CKE_ODT_BYTE_MAP[7:4] == 4\'h2) ? 2 :
+ ((CKE_ODT_BYTE_MAP[7:4] == 4\'h3) ? 3 :
+ ((CKE_ODT_BYTE_MAP[7:4] == 4\'h4) ? 4 : -1))));
+ localparam CKE_ODT_RCLK_SELECT_LANE_AUX_ON
+ = (CKE_ODT_BYTE_MAP[3:0] == 4\'h0) ? ""A"" :
+ ((CKE_ODT_BYTE_MAP[3:0] == 4\'h1) ? ""B"" :
+ ((CKE_ODT_BYTE_MAP[3:0] == 4\'h2) ? ""C"" :
+ ((CKE_ODT_BYTE_MAP[3:0] == 4\'h3) ? ""D"" : ""ILLEGAL"")));
+
+ localparam CKE_ODT_RCLK_SELECT_BANK_AUX_OFF
+ = (CKE_MAP[11:8] == 4\'h0) ? 0 :
+ ((CKE_MAP[11:8] == 4\'h1) ? 1 :
+ ((CKE_MAP[11:8] == 4\'h2) ? 2 :
+ ((CKE_MAP[11:8] == 4\'h3) ? 3 :
+ ((CKE_MAP[11:8] == 4\'h4) ? 4 : -1))));
+ localparam CKE_ODT_RCLK_SELECT_LANE_AUX_OFF
+ = (CKE_MAP[7:4] == 4\'h0) ? ""A"" :
+ ((CKE_MAP[7:4] == 4\'h1) ? ""B"" :
+ ((CKE_MAP[7:4] == 4\'h2) ? ""C"" :
+ ((CKE_MAP[7:4] == 4\'h3) ? ""D"" : ""ILLEGAL"")));
+
+
+ localparam CKE_ODT_RCLK_SELECT_BANK = (CKE_ODT_AUX == ""TRUE"") ? CKE_ODT_RCLK_SELECT_BANK_AUX_ON : CKE_ODT_RCLK_SELECT_BANK_AUX_OFF ;
+ localparam CKE_ODT_RCLK_SELECT_LANE = (CKE_ODT_AUX == ""TRUE"") ? CKE_ODT_RCLK_SELECT_LANE_AUX_ON : CKE_ODT_RCLK_SELECT_LANE_AUX_OFF ;
+
+
+ //***************************************************************************
+ // OCLKDELAYED tap setting calculation:
+ // Parameters for calculating amount of phase shifting output clock to
+ // achieve 90 degree offset between DQS and DQ on writes
+ //***************************************************************************
+
+ //90 deg equivalent to 0.25 for MEM_RefClk <= 300 MHz
+ // and 1.25 for Mem_RefClk > 300 MHz
+ localparam PO_OCLKDELAY_INV = (((SIM_CAL_OPTION == ""NONE"") && (tCK > 2500)) || (tCK >= 3333)) ? ""FALSE"" : ""TRUE"";
+
+ //DIV1: MemRefClk >= 400 MHz, DIV2: 200 <= MemRefClk < 400,
+ //DIV4: MemRefClk < 200 MHz
+ localparam PHY_0_A_PI_FREQ_REF_DIV = tCK > 5000 ? ""DIV4"" :
+ tCK > 2500 ? ""DIV2"": ""NONE"";
+
+ localparam FREQ_REF_DIV = (PHY_0_A_PI_FREQ_REF_DIV == ""DIV4"" ? 4 :
+ PHY_0_A_PI_FREQ_REF_DIV == ""DIV2"" ? 2 : 1);
+
+ // Intrinsic delay between OCLK and OCLK_DELAYED Phaser Output
+ localparam real INT_DELAY = 0.4392/FREQ_REF_DIV + 100.0/tCK;
+
+ // Whether OCLK_DELAY output comes inverted or not
+ localparam real HALF_CYCLE_DELAY = 0.5*(PO_OCLKDELAY_INV == ""TRUE"" ? 1 : 0);
+
+ // Phaser-Out Stage3 Tap delay for 90 deg shift.
+ // Maximum tap delay is FreqRefClk period distributed over 64 taps
+ // localparam real TAP_DELAY = MC_OCLK_DELAY/64/FREQ_REF_DIV;
+ localparam real MC_OCLK_DELAY = ((PO_OCLKDELAY_INV == ""TRUE"" ? 1.25 : 0.25) -
+ (INT_DELAY + HALF_CYCLE_DELAY))
+ * 63 * FREQ_REF_DIV;
+ //localparam integer PHY_0_A_PO_OCLK_DELAY = MC_OCLK_DELAY;
+
+ localparam integer PHY_0_A_PO_OCLK_DELAY_HW
+ = (tCK <= 938) ? 23 :
+ (tCK <= 1072) ? 24 :
+ (tCK <= 1250) ? 25 :
+ (tCK <= 1500) ? 26 : 27;
+
+ // Note that simulation requires a different value than in H/W because of the
+ // difference in the way delays are modeled
+ localparam integer PHY_0_A_PO_OCLK_DELAY = (SIM_CAL_OPTION == ""NONE"") ?
+ (tCK > 2500) ? 8 : 30 :
+ MC_OCLK_DELAY;
+
+ // Initial DQ IDELAY value
+ localparam PHY_0_A_IDELAYE2_IDELAY_VALUE = (SIM_CAL_OPTION != ""FAST_CAL"") ? 0 :
+ (tCK < 1000) ? 0 :
+ (tCK < 1330) ? 0 :
+ (tCK < 2300) ? 0 :
+ (tCK < 2500) ? 2 : 0;
+ //localparam PHY_0_A_IDELAYE2_IDELAY_VALUE = 0;
+
+ // Aux_out parameters RD_CMD_OFFSET = CL+2? and WR_CMD_OFFSET = CWL+3?
+ localparam PHY_0_RD_CMD_OFFSET_0 = 10;
+ localparam PHY_0_RD_CMD_OFFSET_1 = 10;
+ localparam PHY_0_RD_CMD_OFFSET_2 = 10;
+ localparam PHY_0_RD_CMD_OFFSET_3 = 10;
+ // 4:1 and 2:1 have WR_CMD_OFFSET values for ODT timing
+ localparam PHY_0_WR_CMD_OFFSET_0 = (nCK_PER_CLK == 4) ? 8 : 4;
+ localparam PHY_0_WR_CMD_OFFSET_1 = (nCK_PER_CLK == 4) ? 8 : 4;
+ localparam PHY_0_WR_CMD_OFFSET_2 = (nCK_PER_CLK == 4) ? 8 : 4;
+ localparam PHY_0_WR_CMD_OFFSET_3 = (nCK_PER_CLK == 4) ? 8 : 4;
+ // 4:1 and 2:1 have different values
+ localparam PHY_0_WR_DURATION_0 = 7;
+ localparam PHY_0_WR_DURATION_1 = 7;
+ localparam PHY_0_WR_DURATION_2 = 7;
+ localparam PHY_0_WR_DURATION_3 = 7;
+ // Aux_out parameters for toggle mode (CKE)
+ localparam CWL_M = (REG_CTRL == ""ON"") ? CWL + 1 : CWL;
+ localparam PHY_0_CMD_OFFSET = (nCK_PER_CLK == 4) ? (CWL_M % 2) ? 8 : 9 :
+ (CWL < 7) ?
+ 4 + ((CWL_M % 2) ? 0 : 1) :
+ 5 + ((CWL_M % 2) ? 0 : 1);
+
+ // temporary parameter to enable/disable PHY PC counters. In both 4:1 and
+ // 2:1 cases, this should be disabled. For now, enable for 4:1 mode to
+ // avoid making too many changes at once.
+ localparam PHY_COUNT_EN = (nCK_PER_CLK == 4) ? ""TRUE"" : ""FALSE"";
+
+
+ wire [((HIGHEST_LANE+3)/4)*4-1:0] aux_out;
+ wire [HIGHEST_LANE-1:0] mem_dqs_in;
+ wire [HIGHEST_LANE-1:0] mem_dqs_out;
+ wire [HIGHEST_LANE-1:0] mem_dqs_ts;
+ wire [HIGHEST_LANE*10-1:0] mem_dq_in;
+ wire [HIGHEST_LANE*12-1:0] mem_dq_out;
+ wire [HIGHEST_LANE*12-1:0] mem_dq_ts;
+ wire [DQ_WIDTH-1:0] in_dq;
+ wire [DQS_WIDTH-1:0] in_dqs;
+ wire [ROW_WIDTH-1:0] out_addr;
+ wire [BANK_WIDTH-1:0] out_ba;
+ wire out_cas_n;
+ wire [CS_WIDTH*nCS_PER_RANK-1:0] out_cs_n;
+ wire [DM_WIDTH-1:0] out_dm;
+ wire [ODT_WIDTH -1:0] out_odt;
+ wire [CKE_WIDTH -1 :0] out_cke ;
+ wire [DQ_WIDTH-1:0] out_dq;
+ wire [DQS_WIDTH-1:0] out_dqs;
+ wire out_parity;
+ wire out_ras_n;
+ wire out_we_n;
+ wire [HIGHEST_LANE*80-1:0] phy_din;
+ wire [HIGHEST_LANE*80-1:0] phy_dout;
+ wire phy_rd_en;
+ wire [DM_WIDTH-1:0] ts_dm;
+ wire [DQ_WIDTH-1:0] ts_dq;
+ wire [DQS_WIDTH-1:0] ts_dqs;
+
+ reg [31:0] phy_ctl_wd_i1;
+ reg [31:0] phy_ctl_wd_i2;
+ reg phy_ctl_wr_i1;
+ reg phy_ctl_wr_i2;
+ reg [5:0] data_offset_1_i1;
+ reg [5:0] data_offset_1_i2;
+ reg [5:0] data_offset_2_i1;
+ reg [5:0] data_offset_2_i2;
+ wire [31:0] phy_ctl_wd_temp;
+ wire phy_ctl_wr_temp;
+ wire [5:0] data_offset_1_temp;
+ wire [5:0] data_offset_2_temp;
+ wire [5:0] data_offset_1_of;
+ wire [5:0] data_offset_2_of;
+ wire [31:0] phy_ctl_wd_of;
+(* keep = ""true"", max_fanout = 1 *) wire phy_ctl_wr_of;
+ wire phy_ctl_full_temp;
+
+ wire data_io_idle_pwrdwn;
+
+ // Always read from input data FIFOs when not empty
+ assign phy_rd_en = !if_empty;
+
+ // IDELAYE2 initial value
+ assign idelaye2_init_val = PHY_0_A_IDELAYE2_IDELAY_VALUE;
+ assign oclkdelay_init_val = PHY_0_A_PO_OCLK_DELAY;
+
+ // Idle powerdown when there are no pending reads in the MC
+ assign data_io_idle_pwrdwn = DATA_IO_IDLE_PWRDWN == ""ON"" ? idle : 1\'b0;
+
+ //***************************************************************************
+ // Auxiliary output steering
+ //***************************************************************************
+
+ // For a 4 rank I/F the aux_out[3:0] from the addr/ctl bank will be
+ // mapped to ddr_odt and the aux_out[7:4] from one of the data banks
+ // will map to ddr_cke. For I/Fs less than 4 the aux_out[3:0] from the
+ // addr/ctl bank would bank would map to both ddr_odt and ddr_cke.
+ generate
+ if(CKE_ODT_AUX == ""TRUE"")begin:cke_thru_auxpins
+ if (CKE_WIDTH == 1) begin : gen_cke
+ // Explicitly instantiate OBUF to ensure that these are present
+ // in the netlist. Typically this is not required since NGDBUILD
+ // at the top-level knows to infer an I/O/IOBUF and therefore a
+ // top-level LOC constraint can be attached to that pin. This does
+ // not work when a hierarchical flow is used and the LOC is applied
+ // at the individual core-level UCF
+ OBUF u_cke_obuf
+ (
+ .I (aux_out[4*CKE_ODT_RCLK_SELECT_BANK]),
+ .O (ddr_cke)
+ );
+ end else begin: gen_2rank_cke
+ OBUF u_cke0_obuf
+ (
+ .I (aux_out[4*CKE_ODT_RCLK_SELECT_BANK]),
+ .O (ddr_cke[0])
+ );
+ OBUF u_cke1_obuf
+ (
+ .I (aux_out[4*CKE_ODT_RCLK_SELECT_BANK+2]),
+ .O (ddr_cke[1])
+ );
+ end
+ end
+ endgenerate
+
+ generate
+ if(CKE_ODT_AUX == ""TRUE"")begin:odt_thru_auxpins
+ if (USE_ODT_PORT == 1) begin : gen_use_odt
+ // Explicitly instantiate OBUF to ensure that these are present
+ // in the netlist. Typically this is not required since NGDBUILD
+ // at the top-level knows to infer an I/O/IOBUF and therefore a
+ // top-level LOC constraint can be attached to that pin. This does
+ // not work when a hierarchical flow is used and the LOC is applied
+ // at the individual core-level UCF
+ OBUF u_odt_obuf
+ (
+ .I (aux_out[4*CKE_ODT_RCLK_SELECT_BANK+1]),
+ .O (ddr_odt[0])
+ );
+ if (ODT_WIDTH == 2 && RANKS == 1) begin: gen_2port_odt
+ OBUF u_odt1_obuf
+ (
+ .I (aux_out[4*CKE_ODT_RCLK_SELECT_BANK+2]),
+ .O (ddr_odt[1])
+ );
+ end else if (ODT_WIDTH == 2 && RANKS == 2) begin: gen_2rank_odt
+ OBUF u_odt1_obuf
+ (
+ .I (aux_out[4*CKE_ODT_RCLK_SELECT_BANK+3]),
+ .O (ddr_odt[1])
+ );
+ end else if (ODT_WIDTH == 3 && RANKS == 1) begin: gen_3port_odt
+ OBUF u_odt1_obuf
+ (
+ .I (aux_out[4*CKE_ODT_RCLK_SELECT_BANK+2]),
+ .O (ddr_odt[1])
+ );
+ OBUF u_odt2_obuf
+ (
+ .I (aux_out[4*CKE_ODT_RCLK_SELECT_BANK+3]),
+ .O (ddr_odt[2])
+ );
+ end
+ end else begin
+ assign ddr_odt = \'b0;
+ end
+ end
+ endgenerate
+
+ //***************************************************************************
+ // Read data bit steering
+ //***************************************************************************
+
+ // Transpose elements of rd_data_map to form final read data output:
+ // phy_din elements are grouped according to ""physical bit"" - e.g.
+ // for nCK_PER_CLK = 4, there are 8 data phases transfered per physical
+ // bit per clock cycle:
+ // = {dq0_fall3, dq0_rise3, dq0_fall'b'2, dq0_rise2,
+ // dq0_fall1, dq0_rise1, dq0_fall0, dq0_rise0}
+ // whereas rd_data is are grouped according to ""phase"" - e.g.
+ // = {dq7_rise0, dq6_rise0, dq5_rise0, dq4_rise0,
+ // dq3_rise0, dq2_rise0, dq1_rise0, dq0_rise0}
+ // therefore rd_data is formed by transposing phy_din - e.g.
+ // for nCK_PER_CLK = 4, and DQ_WIDTH = 16, and assuming MC_PHY
+ // bit_lane[0] maps to DQ[0], and bit_lane[1] maps to DQ[1], then
+ // the assignments for bits of rd_data corresponding to DQ[1:0]
+ // would be:
+ // {rd_data[112], rd_data[96], rd_data[80], rd_data[64],
+ // rd_data[48], rd_data[32], rd_data[16], rd_data[0]} = phy_din[7:0]
+ // {rd_data[113], rd_data[97], rd_data[81], rd_data[65],
+ // rd_data[49], rd_data[33], rd_data[17], rd_data[1]} = phy_din[15:8]
+ generate
+ genvar i, j;
+ for (i = 0; i < DQ_WIDTH; i = i + 1) begin: gen_loop_rd_data_1
+ for (j = 0; j < PHASE_PER_CLK; j = j + 1) begin: gen_loop_rd_data_2
+ assign rd_data[DQ_WIDTH*j + i]
+ = phy_din[(320*FULL_DATA_MAP[(12*i+8)+:3]+
+ 80*FULL_DATA_MAP[(12*i+4)+:2] +
+ 8*FULL_DATA_MAP[12*i+:4]) + j];
+ end
+ end
+ endgenerate
+
+ //***************************************************************************
+ // Control/address
+ //***************************************************************************
+
+ assign out_cas_n
+ = mem_dq_out[48*CAS_MAP[10:8] + 12*CAS_MAP[5:4] + CAS_MAP[3:0]];
+
+ generate
+ // if signal placed on bit lanes [0-9]
+ if (CAS_MAP[3:0] < 4\'hA) begin: gen_cas_lt10
+ // Determine routing based on clock ratio mode. If running in 4:1
+ // mode, then all four bits from logic are used. If 2:1 mode, only
+ // 2-bits are provided by logic, and each bit is repeated 2x to form
+ // 4-bit input to IN_FIFO, e.g.
+ // 4:1 mode: phy_dout[] = {in[3], in[2], in[1], in[0]}
+ // 2:1 mode: phy_dout[] = {in[1], in[1], in[0], in[0]}
+ assign phy_dout[(320*CAS_MAP[10:8] + 80*CAS_MAP[5:4] +
+ 8*CAS_MAP[3:0])+:4]
+ = {mux_cas_n[3/PHASE_DIV], mux_cas_n[2/PHASE_DIV],
+ mux_cas_n[1/PHASE_DIV], mux_cas_n[0]};
+ end else begin: gen_cas_ge10
+ // If signal is placed in bit lane [10] or [11], route to upper
+ // nibble of phy_dout lane [5] or [6] respectively (in this case
+ // phy_dout lane [5, 6] are multiplexed to take input for two
+ // different SDR signals - this is how bits[10,11] need to be
+ // provided to the OUT_FIFO
+ assign phy_dout[(320*CAS_MAP[10:8] + 80*CAS_MAP[5:4] +
+ 8*(CAS_MAP[3:0]-5) + 4)+:4]
+ = {mux_cas_n[3/PHASE_DIV], mux_cas_n[2/PHASE_DIV],
+ mux_cas_n[1/PHASE_DIV], mux_cas_n[0]};
+ end
+ endgenerate
+
+ assign out_ras_n
+ = mem_dq_out[48*RAS_MAP[10:8] + 12*RAS_MAP[5:4] + RAS_MAP[3:0]];
+
+ generate
+ if (RAS_MAP[3:0] < 4\'hA) begin: gen_ras_lt10
+ assign phy_dout[(320*RAS_MAP[10:8] + 80*RAS_MAP[5:4] +
+ 8*RAS_MAP[3:0])+:4]
+ = {mux_ras_n[3/PHASE_DIV], mux_ras_n[2/PHASE_DIV],
+ mux_ras_n[1/PHASE_DIV], mux_ras_n[0]};
+ end else begin: gen_ras_ge10
+ assign phy_dout[(320*RAS_MAP[10:8] + 80*RAS_MAP[5:4] +
+ 8*(RAS_MAP[3:0]-5) + 4)+:4]
+ = {mux_ras_n[3/PHASE_DIV], mux_ras_n[2/PHASE_DIV],
+ mux_ras_n[1/PHASE_DIV], mux_ras_n[0]};
+ end
+ endgenerate
+
+ assign out_we_n
+ = mem_dq_out[48*WE_MAP[10:8] + 12*WE_MAP[5:4] + WE_MAP[3:0]];
+
+ generate
+ if (WE_MAP[3:0] < 4\'hA) begin: gen_we_lt10
+ assign phy_dout[(320*WE_MAP[10:8] + 80*WE_MAP[5:4] +
+ 8*WE_MAP[3:0])+:4]
+ = {mux_we_n[3/PHASE_DIV], mux_we_n[2/PHASE_DIV],
+ mux_we_n[1/PHASE_DIV], mux_we_n[0]};
+ end else begin: gen_we_ge10
+ assign phy_dout[(320*WE_MAP[10:8] + 80*WE_MAP[5:4] +
+ 8*(WE_MAP[3:0]-5) + 4)+:4]
+ = {mux_we_n[3/PHASE_DIV], mux_we_n[2/PHASE_DIV],
+ mux_we_n[1/PHASE_DIV], mux_we_n[0]};
+ end
+ endgenerate
+
+ generate
+ if (REG_CTRL == ""ON"") begin: gen_parity_out
+ // Generate addr/ctrl parity output only for DDR3 and DDR2 registered DIMMs
+ assign out_parity
+ = mem_dq_out[48*PARITY_MAP[10:8] + 12*PARITY_MAP[5:4] +
+ PARITY_MAP[3:0]];
+ if (PARITY_MAP[3:0] < 4\'hA) begin: gen_lt10
+ assign phy_dout[(320*PARITY_MAP[10:8] + 80*PARITY_MAP[5:4] +
+ 8*PARITY_MAP[3:0])+:4]
+ = {parity_in[3/PHASE_DIV], parity_in[2/PHASE_DIV],
+ parity_in[1/PHASE_DIV], parity_in[0]};
+ end else begin: gen_ge10
+ assign phy_dout[(320*PARITY_MAP[10:8] + 80*PARITY_MAP[5:4] +
+ 8*(PARITY_MAP[3:0]-5) + 4)+:4]
+ = {parity_in[3/PHASE_DIV], parity_in[2/PHASE_DIV],
+ parity_in[1/PHASE_DIV], parity_in[0]};
+ end
+ end
+ endgenerate
+
+ //*****************************************************************
+
+ generate
+ genvar m, n,x;
+
+ //*****************************************************************
+ // Control/address (multi-bit) buses
+ //*****************************************************************
+
+ // Row/Column address
+ for (m = 0; m < ROW_WIDTH; m = m + 1) begin: gen_addr_out
+ assign out_addr[m]
+ = mem_dq_out[48*ADDR_MAP[(12*m+8)+:3] +
+ 12*ADDR_MAP[(12*m+4)+:2] +
+ ADDR_MAP[12*m+:4]];
+
+ if (ADDR_MAP[12*m+:4] < 4\'hA) begin: gen_lt10
+ // For multi-bit buses, we also have to deal with transposition
+ // when going from the logic-side control bus to phy_dout
+ for (n = 0; n < 4; n = n + 1) begin: loop_xpose
+ assign phy_dout[320*ADDR_MAP[(12*m+8)+:3] +
+ 80*ADDR_MAP[(12*m+4)+:2] +
+ 8*ADDR_MAP[12*m+:4] + n]
+ = mux_address[ROW_WIDTH*(n/PHASE_DIV) + m];
+ end
+ end else begin: gen_ge10
+ for (n = 0; n < 4; n = n + 1) begin: loop_xpose
+ assign phy_dout[320*ADDR_MAP[(12*m+8)+:3] +
+ 80*ADDR_MAP[(12*m+4)+:2] +
+ 8*(ADDR_MAP[12*m+:4]-5) + 4 + n]
+ = mux_address[ROW_WIDTH*(n/PHASE_DIV) + m];
+ end
+ end
+ end
+
+ // Bank address
+ for (m = 0; m < BANK_WIDTH; m = m + 1) begin: gen_ba_out
+ assign out_ba[m]
+ = mem_dq_out[48*BANK_MAP[(12*m+8)+:3] +
+ 12*BANK_MAP[(12*m+4)+:2] +
+ BANK_MAP[12*m+:4]];
+
+ if (BANK_MAP[12*m+:4] < 4\'hA) begin: gen_lt10
+ for (n = 0; n < 4; n = n + 1) begin: loop_xpose
+ assign phy_dout[320*BANK_MAP[(12*m+8)+:3] +
+ 80*BANK_MAP[(12*m+4)+:2] +
+ 8*BANK_MAP[12*m+:4] + n]
+ = mux_bank[BANK_WIDTH*(n/PHASE_DIV) + m];
+ end
+ end else begin: gen_ge10
+ for (n = 0; n < 4; n = n + 1) begin: loop_xpose
+ assign phy_dout[320*BANK_MAP[(12*m+8)+:3] +
+ 80*BANK_MAP[(12*m+4)+:2] +
+ 8*(BANK_MAP[12*m+:4]-5) + 4 + n]
+ = mux_bank[BANK_WIDTH*(n/PHASE_DIV) + m];
+ end
+ end
+ end
+
+ // Chip select
+ if (USE_CS_PORT == 1) begin: gen_cs_n_out
+ for (m = 0; m < CS_WIDTH*nCS_PER_RANK; m = m + 1) begin: gen_cs_out
+ assign out_cs_n[m]
+ = mem_dq_out[48*CS_MAP[(12*m+8)+:3] +
+ 12*CS_MAP[(12*m+4)+:2] +
+ CS_MAP[12*m+:4]];
+ if (CS_MAP[12*m+:4] < 4\'hA) begin: gen_lt10
+ for (n = 0; n < 4; n = n + 1) begin: loop_xpose
+ assign phy_dout[320*CS_MAP[(12*m+8)+:3] +
+ 80*CS_MAP[(12*m+4)+:2] +
+ 8*CS_MAP[12*m+:4] + n]
+ = mux_cs_n[CS_WIDTH*nCS_PER_RANK*(n/PHASE_DIV) + m];
+ end
+ end else begin: gen_ge10
+ for (n = 0; n < 4; n = n + 1) begin: loop_xpose
+ assign phy_dout[320*CS_MAP[(12*m+8)+:3] +
+ 80*CS_MAP[(12*m+4)+:2] +
+ 8*(CS_MAP[12*m+:4]-5) + 4 + n]
+ = mux_cs_n[CS_WIDTH*nCS_PER_RANK*(n/PHASE_DIV) + m];
+ end
+ end
+ end
+ end
+
+
+ if(CKE_ODT_AUX == ""FALSE"") begin
+ // ODT_ports
+ wire [ODT_WIDTH*nCK_PER_CLK -1 :0] mux_odt_remap ;
+
+ if(RANKS == 1) begin
+ for(x =0 ; x < nCK_PER_CLK ; x = x+1) begin
+ assign mux_odt_remap[(x*ODT_WIDTH)+:ODT_WIDTH] = {ODT_WIDTH{mux_odt[0]}} ;
+ end
+ end else begin
+ for(x =0 ; x < 2*nCK_PER_CLK ; x = x+2) begin
+ assign mux_odt_remap[(x*ODT_WIDTH/RANKS)+:ODT_WIDTH/RANKS] = {ODT_WIDTH/RANKS{mux_odt[0]}} ;
+ assign mux_odt_remap[((x*ODT_WIDTH/RANKS)+(ODT_WIDTH/RANKS))+:ODT_WIDTH/RANKS] = {ODT_WIDTH/RANKS{mux_odt[1]}} ;
+ end
+ end
+
+ if (USE_ODT_PORT == 1) begin: gen_odt_out
+ for (m = 0; m < ODT_WIDTH; m = m + 1) begin: gen_odt_out_1
+ assign out_odt[m]
+ = mem_dq_out[48*ODT_MAP[(12*m+8)+:3] +
+ 12*ODT_MAP[(12*m+4)+:2] +
+ ODT_MAP[12*m+:4]];
+ if (ODT_MAP[12*m+:4] < 4\'hA) begin: gen_lt10
+ for (n = 0; n < 4; n = n + 1) begin: loop_xpose
+ assign phy_dout[320*ODT_MAP[(12*m+8)+:3] +
+ 80*ODT_MAP[(12*m+4)+:2] +
+ 8*ODT_MAP[12*m+:4] + n]
+ = mux_odt_remap[ODT_WIDTH*(n/PHASE_DIV) + m];
+ end
+ end else begin: gen_ge10
+ for (n = 0; n < 4; n = n + 1) begin: loop_xpose
+ assign phy_dout[320*ODT_MAP[(12*m+8)+:3] +
+ 80*ODT_MAP[(12*m+4)+:2] +
+ 8*(ODT_MAP[12*m+:4]-5) + 4 + n]
+ = mux_odt_remap[ODT_WIDTH*(n/PHASE_DIV) + m];
+ end
+ end
+ end
+ end
+
+
+ wire [CKE_WIDTH*nCK_PER_CLK -1:0] mux_cke_remap ;
+
+ for(x = 0 ; x < nCK_PER_CLK ; x = x +1) begin
+ assign mux_cke_remap[(x*CKE_WIDTH)+:CKE_WIDTH] = {CKE_WIDTH{mux_cke[x]}} ;
+ end
+
+
+
+ for (m = 0; m < CKE_WIDTH; m = m + 1) begin: gen_cke_out
+ assign out_cke[m]
+ = mem_dq_out[48*CKE_MAP[(12*m+8)+:3] +
+ 12*CKE_MAP[(12*m+4)+:2] +
+ CKE_MAP[12*m+:4]];
+ if (CKE_MAP[12*m+:4] < 4\'hA) begin: gen_lt10
+ for (n = 0; n < 4; n = n + 1) begin: loop_xpose
+ assign phy_dout[320*CKE_MAP[(12*m+8)+:3] +
+ 80*CKE_MAP[(12*m+4)+:2] +
+ 8*CKE_MAP[12*m+:4] + n]
+ = mux_cke_remap[CKE_WIDTH*(n/PHASE_DIV) + m];
+ end
+ end else begin: gen_ge10
+ for (n = 0; n < 4; n = n + 1) begin: loop_xpose
+ assign phy_dout[320*CKE_MAP[(12*m+8)+:3] +
+ 80*CKE_MAP[(12*m+4)+:2] +
+ 8*(CKE_MAP[12*m+:4]-5) + 4 + n]
+ = mux_cke_remap[CKE_WIDTH*(n/PHASE_DIV) + m];
+ end
+ end
+ end
+ end
+
+ //*****************************************************************
+ // Data mask
+ //*****************************************************************
+
+ if (USE_DM_PORT == 1) begin: gen_dm_out
+ for (m = 0; m < DM_WIDTH; m = m + 1) begin: gen_dm_out
+ assign out_dm[m]
+ = mem_dq_out[48*FULL_MASK_MAP[(12*m+8)+:3] +
+ 12*FULL_MASK_MAP[(12*m+4)+:2] +
+ FULL_MASK_MAP[12*m+:4]];
+ assign ts_dm[m]
+ = mem_dq_ts[48*FULL_MASK_MAP[(12*m+8)+:3] +
+ 12*FULL_MASK_MAP[(12*m+4)+:2] +
+ FULL_MASK_MAP[12*m+:4]];
+ for (n = 0; n < PHASE_PER_CLK; n = n + 1) begin: loop_xpose
+ assign phy_dout[320*FULL_MASK_MAP[(12*m+8)+:3] +
+ 80*FULL_MASK_MAP[(12*m+4)+:2] +
+ 8*FULL_MASK_MAP[12*m+:4] + n]
+ = mux_wrdata_mask[DM_WIDTH*n + m];
+ end
+ end
+ end
+
+ //*****************************************************************
+ // Input and output DQ
+ //*****************************************************************
+
+ for (m = 0; m < DQ_WIDTH; m = m + 1) begin: gen_dq_inout
+ // to MC_PHY
+ assign mem_dq_in[40*FULL_DATA_MAP[(12*m+8)+:3] +
+ 10*FULL_DATA_MAP[(12*m+4)+:2] +
+ FULL_DATA_MAP[12*m+:4]]
+ = in_dq[m];
+ // to I/O buffers
+ assign out_dq[m]
+ = mem_dq_out[48*FULL_DATA_MAP[(12*m+8)+:3] +
+ 12*FULL_DATA_MAP[(12*m+4)+:2] +
+ FULL_DATA_MAP[12*m+:4]];
+ assign ts_dq[m]
+ = mem_dq_ts[48*FULL_DATA_MAP[(12*m+8)+:3] +
+ 12*FULL_DATA_MAP[(12*m+4)+:2] +
+ FULL_DATA_MAP[12*m+:4]];
+ for (n = 0; n < PHASE_PER_CLK; n = n + 1) begin: loop_xpose
+ assign phy_dout[320*FULL_DATA_MAP[(12*m+8)+:3] +
+ 80*FULL_DATA_MAP[(12*m+4)+:2] +
+ 8*FULL_DATA_MAP[12*m+:4] + n]
+ = mux_wrdata[DQ_WIDTH*n + m];
+ end
+ end
+
+ //*****************************************************************
+ // Input and output DQS
+ //*****************************************************************
+
+ for (m = 0; m < DQS_WIDTH; m = m + 1) begin: gen_dqs_inout
+ // to MC_PHY
+ assign mem_dqs_in[4*DQS_BYTE_MAP[(8*m+4)+:3] + DQS_BYTE_MAP[(8*m)+:2]]
+ = in_dqs[m];
+ // to I/O buffers
+ assign out_dqs[m]
+ = mem_dqs_out[4*DQS_BYTE_MAP[(8*m+4)+:3] + DQS_BYTE_MAP[(8*m)+:2]];
+ assign ts_dqs[m]
+ = mem_dqs_ts[4*DQS_BYTE_MAP[(8*m+4)+:3] + DQS_BYTE_MAP[(8*m)+:2]];
+ end
+ endgenerate
+
+ //***************************************************************************
+ // Memory I/F output and I/O buffer instantiation
+ //***************************************************************************
+
+ // Note on instantiation - generally at the minimum, it\'s not required to
+ // instantiate the output buffers - they can be inferred by the synthesis
+ // tool, and there aren\'t any attributes that need to be associated with
+ // them. Consider as a future option to take out the OBUF instantiations
+
+ OBUF u_cas_n_obuf
+ (
+ .I (out_cas_n),
+ .O (ddr_cas_n)
+ );
+
+ OBUF u_ras_n_obuf
+ (
+ .I (out_ras_n),
+ .O (ddr_ras_n)
+ );
+
+ OBUF u_we_n_obuf
+ (
+ .I (out_we_n),
+ .O (ddr_we_n)
+ );
+
+ generate
+ genvar p;
+
+ for (p = 0; p < ROW_WIDTH; p = p + 1) begin: gen_addr_obuf
+ OBUF u_addr_obuf
+ (
+ .I (out_addr[p]),
+ .O (ddr_addr[p])
+ );
+ end
+
+ for (p = 0; p < BANK_WIDTH; p = p + 1) begin: gen_bank_obuf
+ OBUF u_bank_obuf
+ (
+ .I (out_ba[p]),
+ .O (ddr_ba[p])
+ );
+ end
+
+ if (USE_CS_PORT == 1) begin: gen_cs_n_obuf
+ for (p = 0; p < CS_WIDTH*nCS_PER_RANK; p = p + 1) begin: gen_cs_obuf
+ OBUF u_cs_n_obuf
+ (
+ .I (out_cs_n[p]),
+ .O (ddr_cs_n[p])
+ );
+ end
+ end
+ if(CKE_ODT_AUX == ""FALSE"")begin:cke_odt_thru_outfifo
+ if (USE_ODT_PORT== 1) begin: gen_odt_obuf
+ for (p = 0; p < ODT_WIDTH; p = p + 1) begin: gen_odt_obuf
+ OBUF u_cs_n_obuf
+ (
+ .I (out_odt[p]),
+ .O (ddr_odt[p])
+ );
+ end
+ end
+ for (p = 0; p < CKE_WIDTH; p = p + 1) begin: gen_cke_obuf
+ OBUF u_cs_n_obuf
+ (
+ .I (out_cke[p]),
+ .O (ddr_cke[p])
+ );
+ end
+ end
+
+ if (REG_CTRL == ""ON"") begin: gen_parity_obuf
+ // Generate addr/ctrl parity output only for DDR3 registered DIMMs
+ OBUF u_parity_obuf
+ (
+ .I (out_parity),
+ .O (ddr_parity)
+ );
+ end else begin: gen_parity_tieoff
+ assign ddr_parity = 1\'b0;
+ end
+
+ if ((DRAM_TYPE == ""DDR3"") || (REG_CTRL == ""ON"")) begin: gen_reset_obuf
+ // Generate reset output only for DDR3 and DDR2 RDIMMs
+ OBUF u_reset_obuf
+ (
+ .I (mux_reset_n),
+ .O (ddr_reset_n)
+ );
+ end else begin: gen_reset_tieoff
+ assign ddr_reset_n = 1\'b1;
+ end
+
+ if (USE_DM_PORT == 1) begin: gen_dm_obuf
+ for (p = 0; p < DM_WIDTH; p = p + 1) begin: loop_dm
+ OBUFT u_dm_obuf
+ (
+ .I (out_dm[p]),
+ .T (ts_dm[p]),
+ .O (ddr_dm[p])
+ );
+ end
+ end else begin: gen_dm_tieoff
+ assign ddr_dm = \'b0;
+ end
+
+ if (DATA_IO_PRIM_TYPE == ""HP_LP"") begin: gen_dq_iobuf_HP
+ for (p = 0; p < DQ_WIDTH; p = p + 1) begin: gen_dq_iobuf
+ IOBUF_DCIEN #
+ (
+ .IBUF_LOW_PWR (IBUF_LOW_PWR)
+ )
+ u_iobuf_dq
+ (
+ .DCITERMDISABLE (data_io_idle_pwrdwn),
+ .IBUFDISABLE (data_io_idle_pwrdwn),
+ .I (out_dq[p]),
+ .T (ts_dq[p]),
+ .O (in_dq[p]),
+ .IO (ddr_dq[p])
+ );
+ end
+ end else if (DATA_IO_PRIM_TYPE == ""HR_LP"") begin: gen_dq_iobuf_HR
+ for (p = 0; p < DQ_WIDTH; p = p + 1) begin: gen_dq_iobuf
+ IOBUF_INTERMDISABLE #
+ (
+ .IBUF_LOW_PWR (IBUF_LOW_PWR)
+ )
+ u_iobuf_dq
+ (
+ .INTERMDISABLE (data_io_idle_pwrdwn),
+ .IBUFDISABLE (data_io_idle_pwrdwn),
+ .I (out_dq[p]),
+ .T (ts_dq[p]),
+ .O (in_dq[p]),
+ .IO (ddr_dq[p])
+ );
+ end
+ end else begin: gen_dq_iobuf_default
+ for (p = 0; p < DQ_WIDTH; p = p + 1) begin: gen_dq_iobuf
+ IOBUF #
+ (
+ .IBUF_LOW_PWR (IBUF_LOW_PWR)
+ )
+ u_iobuf_dq
+ (
+ .I (out_dq[p]),
+ .T (ts_dq[p]),
+ .O (in_dq[p]),
+ .IO (ddr_dq[p])
+ );
+ end
+ end
+
+ if (DATA_IO_PRIM_TYPE == ""HP_LP"") begin: gen_dqs_iobuf_HP
+ for (p = 0; p < DQS_WIDTH; p = p + 1) begin: gen_dqs_iobuf
+ if ((DRAM_TYPE == ""DDR2"") &&
+ (DDR2_DQSN_ENABLE != ""YES"")) begin: gen_ddr2_dqs_se
+ IOBUF_DCIEN #
+ (
+ .IBUF_LOW_PWR (IBUF_LOW_PWR)
+ )
+ u_iobuf_dqs
+ (
+ .DCITERMDISABLE (data_io_idle_pwrdwn),
+ .IBUFDISABLE (data_io_idle_pwrdwn),
+ .I (out_dqs[p]),
+ .T (ts_dqs[p]),
+ .O (in_dqs[p]),
+ .IO (ddr_dqs[p])
+ );
+ assign ddr_dqs_n[p] = 1\'b0;
+ end else begin: gen_dqs_diff
+ IOBUFDS_DCIEN #
+ (
+ .IBUF_LOW_PWR (IBUF_LOW_PWR),
+ .DQS_BIAS (""TRUE"")
+ )
+ u_iobuf_dqs
+ (
+ .DCITERMDISABLE (data_io_idle_pwrdwn),
+ .IBUFDISABLE (data_io_idle_pwrdwn),
+ .I (out_dqs[p]),
+ .T (ts_dqs[p]),
+ .O (in_dqs[p]),
+ .IO (ddr_dqs[p]),
+ .IOB (ddr_dqs_n[p])
+ );
+ end
+ end
+ end else if (DATA_IO_PRIM_TYPE == ""HR_LP"") begin: gen_dqs_iobuf_HR
+ for (p = 0; p < DQS_WIDTH; p = p + 1) begin: gen_dqs_iobuf
+ if ((DRAM_TYPE == ""DDR2"") &&
+ (DDR2_DQSN_ENABLE != ""YES"")) begin: gen_ddr2_dqs_se
+ IOBUF_INTERMDISABLE #
+ (
+ .IBUF_LOW_PWR (IBUF_LOW_PWR)
+ )
+ u_iobuf_dqs
+ (
+ .INTERMDISABLE (data_io_idle_pwrdwn),
+ .IBUFDISABLE (data_io_idle_pwrdwn),
+ .I (out_dqs[p]),
+ .T (ts_dqs[p]),
+ .O (in_dqs[p]),
+ .IO (ddr_dqs[p])
+ );
+ assign ddr_dqs_n[p] = 1\'b0;
+ end else begin: gen_dqs_diff
+ IOBUFDS_INTERMDISABLE #
+ (
+ .IBUF_LOW_PWR (IBUF_LOW_PWR),
+ .DQS_BIAS (""TRUE"")
+ )
+ u_iobuf_dqs
+ (
+ .INTERMDISABLE (data_io_idle_pwrdwn),
+ .IBUFDISABLE (data_io_idle_pwrdwn),
+ .I (out_dqs[p]),
+ .T (ts_dqs[p]),
+ .O (in_dqs[p]),
+ .IO (ddr_dqs[p]),
+ .IOB (ddr_dqs_n[p])
+ );
+ end
+ end
+ end else begin: gen_dqs_iobuf_default
+ for (p = 0; p < DQS_WIDTH; p = p + 1) begin: gen_dqs_iobuf
+ if ((DRAM_TYPE == ""DDR2"") &&
+ (DDR2_DQSN_ENABLE != ""YES"")) begin: gen_ddr2_dqs_se
+ IOBUF #
+ (
+ .IBUF_LOW_PWR (IBUF_LOW_PWR)
+ )
+ u_iobuf_dqs
+ (
+ .I (out_dqs[p]),
+ .T (ts_dqs[p]),
+ .O (in_dqs[p]),
+ .IO (ddr_dqs[p])
+ );
+ assign ddr_dqs_n[p] = 1\'b0;
+ end else begin: gen_dqs_diff
+ IOBUFDS #
+ (
+ .IBUF_LOW_PWR (IBUF_LOW_PWR),
+ .DQS_BIAS (""TRUE"")
+ )
+ u_iobuf_dqs
+ (
+ .I (out_dqs[p]),
+ .T (ts_dqs[p]),
+ .O (in_dqs[p]),
+ .IO (ddr_dqs[p]),
+ .IOB (ddr_dqs_n[p])
+ );
+ end
+ end
+ end
+
+ endgenerate
+
+ always @(posedge clk) begin
+ phy_ctl_wd_i1 <= #TCQ phy_ctl_wd;
+ phy_ctl_wr_i1 <= #TCQ phy_ctl_wr;
+ phy_ctl_wd_i2 <= #TCQ phy_ctl_wd_i1;
+ phy_ctl_wr_i2 <= #TCQ phy_ctl_wr_i1;
+ data_offset_1_i1 <= #TCQ data_offset_1;
+ data_offset_1_i2 <= #TCQ data_offset_1_i1;
+ data_offset_2_i1 <= #TCQ data_offset_2;
+ data_offset_2_i2 <= #TCQ data_offset_2_i1;
+ end
+
+
+ // 2 cycles of command delay needed for 4;1 mode. 2:1 mode does not need it.
+ // 2:1 mode the command goes through pre fifo
+ assign phy_ctl_wd_temp = (nCK_PER_CLK == 4) ? phy_ctl_wd_i2 : phy_ctl_wd_of;
+ assign phy_ctl_wr_temp = (nCK_PER_CLK == 4) ? phy_ctl_wr_i2 : phy_ctl_wr_of;
+ assign data_offset_1_temp = (nCK_PER_CLK == 4) ? data_offset_1_i2 : data_offset_1_of;
+ assign data_offset_2_temp = (nCK_PER_CLK == 4) ? data_offset_2_i2 : data_offset_2_of;
+
+ generate
+ begin
+
+ mig_7series_v1_8_ddr_of_pre_fifo #
+ (
+ .TCQ (25),
+ .DEPTH (8),
+ .WIDTH (44)
+ )
+ phy_ctl_pre_fifo
+ (
+ .clk (clk),
+ .rst (rst),
+ .full_in (phy_ctl_full_temp),
+ .wr_en_in (phy_ctl_wr),
+ .d_in ({data_offset_2, data_offset_1, phy_ctl_wd}),
+ .wr_en_out (phy_ctl_wr_of),
+ .d_out ({data_offset_2_of, data_offset_1_of, phy_ctl_wd_of})
+ );
+
+ end
+ endgenerate
+
+
+
+ //***************************************************************************
+ // Hard PHY instantiation
+ //***************************************************************************
+
+ assign phy_ctl_full = phy_ctl_full_temp;
+
+ mig_7series_v1_8_ddr_mc_phy #
+ (
+ .BYTE_LANES_B0 (BYTE_LANES_B0),
+ .BYTE_LANES_B1 (BYTE_LANES_B1),
+ .BYTE_LANES_B2 (BYTE_LANES_B2),
+ .BYTE_LANES_B3 (BYTE_LANES_B3),
+ .BYTE_LANES_B4 (BYTE_LANES_B4),
+ .DATA_CTL_B0 (DATA_CTL_B0),
+ .DATA_CTL_B1 (DATA_CTL_B1),
+ .DATA_CTL_B2 (DATA_CTL_B2),
+ .DATA_CTL_B3 (DATA_CTL_B3),
+ .DATA_CTL_B4 (DATA_CTL_B4),
+ .PHY_0_BITLANES (PHY_0_BITLANES),
+ .PHY_1_BITLANES (PHY_1_BITLANES),
+ .PHY_2_BITLANES (PHY_2_BITLANES),
+ .PHY_0_BITLANES_OUTONLY (PHY_0_BITLANES_OUTONLY),
+ .PHY_1_BITLANES_OUTONLY (PHY_1_BITLANES_OUTONLY),
+ .PHY_2_BITLANES_OUTONLY (PHY_2_BITLANES_OUTONLY),
+ .RCLK_SELECT_BANK (CKE_ODT_RCLK_SELECT_BANK),
+ .RCLK_SELECT_LANE (CKE_ODT_RCLK_SELECT_LANE),
+ //.CKE_ODT_AUX (CKE_ODT_AUX),
+ .GENERATE_DDR_CK_MAP (TMP_GENERATE_DDR_CK_MAP),
+ .BYTELANES_DDR_CK (TMP_BYTELANES_DDR_CK),
+ .NUM_DDR_CK (CK_WIDTH),
+ .LP_DDR_CK_WIDTH (LP_DDR_CK_WIDTH),
+ .PO_CTL_COARSE_BYPASS (""FALSE""),
+ .PHYCTL_CMD_FIFO (""FALSE""),
+ .PHY_CLK_RATIO (nCK_PER_CLK),
+ .MASTER_PHY_CTL (MASTER_PHY_CTL),
+ .PHY_FOUR_WINDOW_CLOCKS (63),
+ .PHY_EVENTS_DELAY (18),
+ .PHY_COUNT_EN (""FALSE""), //PHY_COUNT_EN
+ .PHY_SYNC_MODE (""FALSE""),
+ .SYNTHESIS ((SIM_CAL_OPTION == ""NONE"") ? ""TRUE"" : ""FALSE""),
+ .PHY_DISABLE_SEQ_MATCH (""TRUE""), //""TRUE""
+ .PHY_0_GENERATE_IDELAYCTRL (""FALSE""),
+ .PHY_0_A_PI_FREQ_REF_DIV (PHY_0_A_PI_FREQ_REF_DIV),
+ .PHY_0_CMD_OFFSET (PHY_0_CMD_OFFSET), //for CKE
+ .PHY_0_RD_CMD_OFFSET_0 (PHY_0_RD_CMD_OFFSET_0),
+ .PHY_0_RD_CMD_OFFSET_1 (PHY_0_RD_CMD_OFFSET_1),
+ .PHY_0_RD_CMD_OFFSET_2 (PHY_0_RD_CMD_OFFSET_2),
+ .PHY_0_RD_CMD_OFFSET_3 (PHY_0_RD_CMD_OFFSET_3),
+ .PHY_0_RD_DURATION_0 (6),
+ .PHY_0_RD_DURATION_1 (6),
+ .PHY_0_RD_DURATION_2 (6),
+ .PHY_0_RD_DURATION_3 (6),
+ .PHY_0_WR_CMD_OFFSET_0 (PHY_0_WR_CMD_OFFSET_0),
+ .PHY_0_WR_CMD_OFFSET_1 (PHY_0_WR_CMD_OFFSET_1),
+ .PHY_0_WR_CMD_OFFSET_2 (PHY_0_WR_CMD_OFFSET_2),
+ .PHY_0_WR_CMD_OFFSET_3 (PHY_0_WR_CMD_OFFSET_3),
+ .PHY_0_WR_DURATION_0 (PHY_0_WR_DURATION_0),
+ .PHY_0_WR_DURATION_1 (PHY_0_WR_DURATION_1),
+ .PHY_0_WR_DURATION_2 (PHY_0_WR_DURATION_2),
+ .PHY_0_WR_DURATION_3 (PHY_0_WR_DURATION_3),
+ .PHY_0_AO_TOGGLE ((RANKS == 1) ? 4\'b0001 : 4\'b0101),
+ .PHY_0_A_PO_OCLK_DELAY (PHY_0_A_PO_OCLK_DELAY),
+ .PHY_0_B_PO_OCLK_DELAY (PHY_0_A_PO_OCLK_DELAY),
+ .PHY_0_C_PO_OCLK_DELAY (PHY_0_A_PO_OCLK_DELAY),
+ .PHY_0_D_PO_OCLK_DELAY (PHY_0_A_PO_OCLK_DELAY),
+ .PHY_0_A_PO_OCLKDELAY_INV (PO_OCLKDELAY_INV),
+ .PHY_0_A_IDELAYE2_IDELAY_VALUE (PHY_0_A_IDELAYE2_IDELAY_VALUE),
+ .PHY_0_B_IDELAYE2_IDELAY_VALUE (PHY_0_A_IDELAYE2_IDELAY_VALUE),
+ .PHY_0_C_IDELAYE2_IDELAY_VALUE (PHY_0_A_IDELAYE2_IDELAY_VALUE),
+ .PHY_0_D_IDELAYE2_IDELAY_VALUE (PHY_0_A_IDELAYE2_IDELAY_VALUE),
+ .PHY_1_GENERATE_IDELAYCTRL (""FALSE""),
+ //.PHY_1_GENERATE_DDR_CK (TMP_PHY_1_GENERATE_DDR_CK),
+ //.PHY_1_NUM_DDR_CK (1),
+ .PHY_1_A_PO_OCLK_DELAY (PHY_0_A_PO_OCLK_DELAY),
+ .PHY_1_B_PO_OCLK_DELAY (PHY_0_A_PO_OCLK_DELAY),
+ .PHY_1_C_PO_OCLK_DELAY (PHY_0_A_PO_OCLK_DELAY),
+ .PHY_1_D_PO_OCLK_DELAY (PHY_0_A_PO_OCLK_DELAY),
+ .PHY_1_A_IDELAYE2_IDELAY_VALUE (PHY_0_A_IDELAYE2_IDELAY_VALUE),
+ .PHY_1_B_IDELAYE2_IDELAY_VALUE (PHY_0_A_IDELAYE2_IDELAY_VALUE),
+ .PHY_1_C_IDELAYE2_IDELAY_VALUE (PHY_0_A_IDELAYE2_IDELAY_VALUE),
+ .PHY_1_D_IDELAYE2_IDELAY_VALUE (PHY_0_A_IDELAYE2_IDELAY_VALUE),
+ .PHY_2_GENERATE_IDELAYCTRL (""FALSE""),
+ //.PHY_2_GENERATE_DDR_CK (TMP_PHY_2_GENERATE_DDR_CK),
+ //.PHY_2_NUM_DDR_CK (1),
+ .PHY_2_A_PO_OCLK_DELAY (PHY_0_A_PO_OCLK_DELAY),
+ .PHY_2_B_PO_OCLK_DELAY (PHY_0_A_PO_OCLK_DELAY),
+ .PHY_2_C_PO_OCLK_DELAY (PHY_0_A_PO_OCLK_DELAY),
+ .PHY_2_D_PO_OCLK_DELAY (PHY_0_A_PO_OCLK_DELAY),
+ .PHY_2_A_IDELAYE2_IDELAY_VALUE (PHY_0_A_IDELAYE2_IDELAY_VALUE),
+ .PHY_2_B_IDELAYE2_IDELAY_VALUE (PHY_0_A_IDELAYE2_IDELAY_VALUE),
+ .PHY_2_C_IDELAYE2_IDELAY_VALUE (PHY_0_A_IDELAYE2_IDELAY_VALUE),
+ .PHY_2_D_IDELAYE2_IDELAY_VALUE (PHY_0_A_IDELAYE2_IDELAY_VALUE),
+ .TCK (tCK),
+ .PHY_0_IODELAY_GRP (IODELAY_GRP)
+ ,.PHY_1_IODELAY_GRP (IODELAY_GRP)
+ ,.PHY_2_IODELAY_GRP (IODELAY_GRP)
+ ,.BANK_TYPE (BANK_TYPE)
+ ,.CKE_ODT_AUX (CKE_ODT_AUX)
+ )
+ u_ddr_mc_phy
+ (
+ .rst (rst),
+ // Don\'t use MC_PHY to generate DDR_RESET_N output. Instead
+ // generate this output outside of MC_PHY (and synchronous to CLK)
+ .ddr_rst_in_n (1\'b1),
+ .phy_clk (clk),
+ .freq_refclk (freq_refclk),
+ .mem_refclk (mem_refclk),
+ // Remove later - always same connection as phy_clk port
+ .mem_refclk_div4 (clk),
+ .pll_lock (pll_lock),
+ .auxout_clk (),
+ .sync_pulse (sync_pulse),
+ // IDELAYCTRL instantiated outside of mc_phy module
+ .idelayctrl_refclk (),
+ .phy_dout (phy_dout),
+ .phy_cmd_wr_en (phy_cmd_wr_en),
+ .phy_data_wr_en (phy_data_wr_en),
+ .phy_rd_en (phy_rd_en),
+ .phy_ctl_wd (phy_ctl_wd_temp),
+ .phy_ctl_wr (phy_ctl_wr_temp),
+ .if_empty_def (phy_if_empty_def),
+ .if_rst (phy_if_reset),
+ .phyGo (\'b1),
+ .aux_in_1 (aux_in_1),
+ .aux_in_2 (aux_in_2),
+ // No support yet for different data offsets for different I/O banks
+ // (possible use in supporting wider range of skew among bytes)
+ .data_offset_1 (data_offset_1_temp),
+ .data_offset_2 (data_offset_2_temp),
+ .cke_in (),
+ .if_a_empty (),
+ .if_empty (if_empty),
+ .if_empty_or (),
+ .if_empty_and (),
+ .of_ctl_a_full (),
+ // .of_data_a_full (phy_data_full),
+ .of_ctl_full (phy_cmd_full),
+ .of_data_full (),
+ .pre_data_a_full (phy_pre_data_a_full),
+ .idelay_ld (idelay_ld),
+ .idelay_ce (idelay_ce),
+ .idelay_inc (idelay_inc),
+ .input_sink (),
+ .phy_din (phy_din),
+ .phy_ctl_a_full (),
+ .phy_ctl_full (phy_ctl_full_temp),
+ .mem_dq_out (mem_dq_out),
+ .mem_dq_ts (mem_dq_ts),
+ .mem_dq_in (mem_dq_in),
+ .mem_dqs_out (mem_dqs_out),
+ .mem_dqs_ts (mem_dqs_ts),
+ .mem_dqs_in (mem_dqs_in),
+ .aux_out (aux_out),
+ .phy_ctl_ready (),
+ .rst_out (),
+ .ddr_clk (ddr_clk),
+ //.rclk (),
+ .mcGo (phy_mc_go),
+ .phy_write_calib (phy_write_calib),
+ .phy_read_calib (phy_read_calib),
+ .calib_sel (calib_sel),
+ .calib_in_common (calib_in_common),
+ .calib_zero_inputs (calib_zero_inputs),
+ .calib_zero_ctrl (calib_zero_ctrl),
+ .calib_zero_lanes (\'b0),
+ .po_fine_enable (po_fine_enable),
+ .po_coarse_enable (po_coarse_enable),
+ .po_fine_inc (po_fine_inc),
+ .po_coarse_inc (po_coarse_inc),
+ .po_counter_load_en (po_counter_load_en),
+ .po_sel_fine_oclk_delay (po_sel_fine_oclk_delay),
+ .po_counter_load_val (po_counter_load_val),
+ .po_counter_read_en (po_counter_read_en),
+ .po_coarse_overflow (),
+ .po_fine_overflow (),
+ .po_counter_read_val (po_counter_read_val),
+ .pi_rst_dqs_find (pi_rst_dqs_find),
+ .pi_fine_enable (pi_fine_enable),
+ .pi_fine_inc (pi_fine_inc),
+ .pi_counter_load_en (pi_counter_load_en),
+ .pi_counter_read_en (dbg_pi_counter_read_en),
+ .pi_counter_load_val (pi_counter_load_val),
+ .pi_fine_overflow (),
+ .pi_counter_read_val (pi_counter_read_val),
+ .pi_phase_locked (pi_phase_locked),
+ .pi_phase_locked_all (pi_phase_locked_all),
+ .pi_dqs_found (),
+ .pi_dqs_found_any (pi_dqs_found),
+ .pi_dqs_found_all (pi_dqs_found_all),
+ .pi_dqs_found_lanes (dbg_pi_dqs_found_lanes_phy4lanes),
+ // Currently not being used. May be used in future if periodic
+ // reads become a requirement. This output could be used to signal
+ // a catastrophic failure in read capture and the need for
+ // re-calibration.
+ .pi_dqs_out_of_range (pi_dqs_out_of_range)
+
+ ,.ref_dll_lock (ref_dll_lock)
+ ,.pi_phase_locked_lanes (dbg_pi_phase_locked_phy4lanes)
+// ,.rst_phaser_ref (rst_phaser_ref)
+ );
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2008 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : %version
+// \\ \\ Application : MIG
+// / / Filename : col_mach.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : 7-Series
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+// The column machine manages the dq bus. Since there is a single DQ
+// bus, and the column part of the DRAM is tightly coupled to this DQ
+// bus, conceptually, the DQ bus and all of the column hardware in
+// a multi rank DRAM array are managed as a single unit.
+//
+//
+// The column machine does not ""enforce"" the column timing directly.
+// It generates information and sends it to the bank machines. If the
+// bank machines incorrectly make a request, the column machine will
+// simply overwrite the existing request with the new request even
+// if this would result in a timing or protocol violation.
+//
+// The column machine
+// hosts the block that controls read and write data transfer
+// to and from the dq bus.
+//
+// And if configured, there is provision for tracking the address
+// of a command as it moves through the column pipeline. This
+// address will be logged for detected ECC errors.
+
+`timescale 1 ps / 1 ps
+
+module mig_7series_v1_8_col_mach #
+ (
+ parameter TCQ = 100,
+ parameter BANK_WIDTH = 3,
+ parameter BURST_MODE = ""8"",
+ parameter COL_WIDTH = 12,
+ parameter CS_WIDTH = 4,
+ parameter DATA_BUF_ADDR_WIDTH = 8,
+ parameter DATA_BUF_OFFSET_WIDTH = 1,
+ parameter DELAY_WR_DATA_CNTRL = 0,
+ parameter DQS_WIDTH = 8,
+ parameter DRAM_TYPE = ""DDR3"",
+ parameter EARLY_WR_DATA_ADDR = ""OFF"",
+ parameter ECC = ""OFF"",
+ parameter MC_ERR_ADDR_WIDTH = 31,
+ parameter nCK_PER_CLK = 2,
+ parameter nPHY_WRLAT = 0,
+ parameter RANK_WIDTH = 2,
+ parameter ROW_WIDTH = 16
+ )
+ (/*AUTOARG*/
+ // Outputs
+ dq_busy_data, wr_data_offset, mc_wrdata_en, wr_data_en,
+ wr_data_addr, rd_rmw, ecc_err_addr, ecc_status_valid, wr_ecc_buf, rd_data_end,
+ rd_data_addr, rd_data_offset, rd_data_en, col_read_fifo_empty,
+ // Inputs
+ clk, rst, sent_col, col_size, col_wr_data_buf_addr,
+ phy_rddata_valid, col_periodic_rd, col_data_buf_addr, col_rmw,
+ col_rd_wr, col_ra, col_ba, col_row, col_a
+ );
+
+ input clk;
+ input rst;
+
+ input sent_col;
+ input col_rd_wr;
+
+ output reg dq_busy_data = 1\'b0;
+
+// The following generates a column command disable based mostly on the type
+// of DRAM and the fabric to DRAM CK ratio.
+ generate
+ if ((nCK_PER_CLK == 1) && ((BURST_MODE == ""8"") || (DRAM_TYPE == ""DDR3"")))
+ begin : three_bumps
+ reg [1:0] granted_col_d_r;
+ wire [1:0] granted_col_d_ns = {sent_col, granted_col_d_r[1]};
+ always @(posedge clk) granted_col_d_r <= #TCQ granted_col_d_ns;
+ always @(/*AS*/granted_col_d_r or sent_col)
+ dq_busy_data = sent_col || |granted_col_d_r;
+ end
+ if (((nCK_PER_CLK == 2) && ((BURST_MODE == ""8"") || (DRAM_TYPE == ""DDR3"")))
+ || ((nCK_PER_CLK == 1) && ((BURST_MODE == ""4"") || (DRAM_TYPE == ""DDR2""))))
+ begin : one_bump
+ always @(/*AS*/sent_col) dq_busy_data = sent_col;
+ end
+ endgenerate
+
+// This generates a data offset based on fabric clock to DRAM CK ratio and
+// the size bit. Note that this is different that the dq_busy_data signal
+// generated above.
+ reg [1:0] offset_r = 2\'b0;
+ reg [1:0] offset_ns = 2\'b0;
+
+ input col_size;
+ wire data_end;
+ generate
+
+ if(nCK_PER_CLK == 4) begin : data_valid_4_1
+
+ // For 4:1 mode all data is transfered in a single beat so the default
+ // values of 0 for offset_r/offset_ns suffice - just tie off data_end
+ assign data_end = 1\'b1;
+
+ end
+
+ else begin
+
+ if(DATA_BUF_OFFSET_WIDTH == 2) begin : data_valid_1_1
+
+ always @(col_size or offset_r or rst or sent_col) begin
+ if (rst) offset_ns = 2\'b0;
+ else begin
+ offset_ns = offset_r;
+ if (sent_col) offset_ns = 2\'b1;
+ else if (|offset_r && (offset_r != {col_size, 1\'b1}))
+ offset_ns = offset_r + 2\'b1;
+ else offset_ns = 2\'b0;
+ end
+
+ end
+
+ always @(posedge clk) offset_r <= #TCQ offset_ns;
+ assign data_end = col_size ? (offset_r == 2\'b11) : offset_r[0];
+
+ end
+
+ else begin : data_valid_2_1
+
+ always @(col_size or rst or sent_col)
+ offset_ns[0] = rst ? 1\'b0 : sent_col && col_size;
+ always @(posedge clk) offset_r[0] <= #TCQ offset_ns[0];
+ assign data_end = col_size ? offset_r[0] : 1\'b1;
+
+ end
+
+ end
+
+ endgenerate
+
+ reg [DATA_BUF_OFFSET_WIDTH-1:0] offset_r1 = {DATA_BUF_OFFSET_WIDTH{1\'b0}};
+ reg [DATA_BUF_OFFSET_WIDTH-1:0] offset_r2 = {DATA_BUF_OFFSET_WIDTH{1\'b0}};
+ reg col_rd_wr_r1;
+ reg col_rd_wr_r2;
+ generate
+ if ((nPHY_WRLAT >= 1) || (DELAY_WR_DATA_CNTRL == 1)) begin : offset_pipe_0
+ always @(posedge clk) offset_r1 <=
+ #TCQ offset_r[DATA_BUF_OFFSET_WIDTH-1:0];
+ always @(posedge clk) col_rd_wr_r1 <= #TCQ col_rd_wr;
+ end
+ if(nPHY_WRLAT == 2) begin : offset_pipe_1
+ always @(posedge clk) offset_r2 <=
+ #TCQ offset_r1[DATA_BUF_OFFSET_WIDTH-1:0];
+ always @(posedge clk) col_rd_wr_r2 <= #TCQ col_rd_wr_r1;
+ end
+ endgenerate
+
+ output wire [DATA_BUF_OFFSET_WIDTH-1:0] wr_data_offset;
+ assign wr_data_offset = (DELAY_WR_DATA_CNTRL == 1)
+ ? offset_r1[DATA_BUF_OFFSET_WIDTH-1:0]
+ : (EARLY_WR_DATA_ADDR == ""OFF"")
+ ? offset_r[DATA_BUF_OFFSET_WIDTH-1:0]
+ : offset_ns[DATA_BUF_OFFSET_WIDTH-1:0];
+
+ reg sent_col_r1;
+ reg sent_col_r2;
+ always @(posedge clk) sent_col_r1 <= #TCQ sent_col;
+ always @(posedge clk) sent_col_r2 <= #TCQ sent_col_r1;
+
+ wire wrdata_en = (nPHY_WRLAT == 0) ?
+ (sent_col || |offset_r) & ~col_rd_wr :
+ (nPHY_WRLAT == 1) ?
+ (sent_col_r1 || |offset_r1) & ~col_rd_wr_r1 :
+ //(nPHY_WRLAT >= 2) ?
+ (sent_col_r2 || |offset_r2) & ~col_rd_wr_r2;
+
+ output wire mc_wrdata_en;
+ assign mc_wrdata_en = wrdata_en;
+
+ output wire wr_data_en;
+ assign wr_data_en = (DELAY_WR_DATA_CNTRL == 1)
+ ? ((sent_col_r1 || |offset_r1) && ~col_rd_wr_r1)
+ : ((sent_col || |offset_r) && ~col_rd_wr);
+
+
+ input [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr;
+ output wire [DATA_BUF_ADDR_WIDTH-1:0] wr_data_addr;
+ generate
+ if (DELAY_WR_DATA_CNTRL == 1) begin : delay_wr_data_cntrl_eq_1
+ reg [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr_r;
+ always @(posedge clk) col_wr_data_buf_addr_r <=
+ #TCQ col_wr_data_buf_addr;
+ assign wr_data_addr = col_wr_data_buf_addr_r;
+ end
+ else begin : delay_wr_data_cntrl_ne_1
+ assign wr_data_addr = col_wr_data_buf_addr;
+ end
+ endgenerate
+
+// CAS-RD to mc_rddata_en
+
+ wire read_data_valid = (sent_col || |offset_r) && col_rd_wr;
+
+function integer clogb2 (input integer size); // ceiling logb2
+ begin
+ size = size - 1;
+ for (clogb2=1; size>1; clogb2=clogb2+1)
+ size = size >> 1;
+ end
+endfunction // clogb2
+
+// Implement FIFO that records reads as they are sent to the DRAM.
+// When phy_rddata_valid is returned some unknown time later, the
+// FIFO output is used to control how the data is interpreted.
+
+ input phy_rddata_valid;
+ output wire rd_rmw;
+ output reg [MC_ERR_ADDR_WIDTH-1:0] ecc_err_addr;
+ output reg ecc_status_valid;
+ output reg wr_ecc_buf;
+ output reg rd_data_end;
+ output reg [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr;
+ output reg [DATA_BUF_OFFSET_WIDTH-1:0] rd_data_offset;
+ (* keep = ""true"", max_fanout = 10 *) output reg rd_data_en /* synthesis syn_maxfan = 10 */;
+ output col_read_fifo_empty;
+
+ input col_periodic_rd;
+ input [DATA_BUF_ADDR_WIDTH-1:0] col_data_buf_addr;
+ input col_rmw;
+ input [RANK_WIDTH-1:0] col_ra;
+ input [BANK_WIDTH-1:0] col_ba;
+ input [ROW_WIDTH-1:0] col_row;
+ input [ROW_WIDTH-1:0] col_a;
+
+ // Real column address (skip A10/AP and A12/BC#). The maximum width is 12;
+ // the width will be tailored for the target DRAM downstream.
+ wire [11:0] col_a_full;
+
+ // Minimum row width is 12; take remaining 11 bits after omitting A10/AP
+ assign col_a_full[10:0] = {col_a[11], col_a[9:0]};
+
+ // Get the 12th bit when row address width accommodates it; omit A12/BC#
+ assign col_a_full[11] = ROW_WIDTH >= 14 ? col_a[13] : 0;
+
+ // Extract only the width of the target DRAM
+ wire [COL_WIDTH-1:0] col_a_extracted = col_a_full[COL_WIDTH-1:0];
+
+ localparam MC_ERR_LINE_WIDTH = MC_ERR_ADDR_WIDTH-DATA_BUF_OFFSET_WIDTH;
+ localparam FIFO_WIDTH = 1 /*data_end*/ +
+ 1 /*periodic_rd*/ +
+ DATA_BUF_ADDR_WIDTH +
+ DATA_BUF_OFFSET_WIDTH +
+ ((ECC == ""OFF"") ? 0 : 1+MC_ERR_LINE_WIDTH);
+ localparam FULL_RAM_CNT = (FIFO_WIDTH/6);
+ localparam REMAINDER = FIFO_WIDTH % 6;
+ localparam RAM_CNT = FULL_RAM_CNT + ((REMAINDER == 0 ) ? 0 : 1);
+ localparam RAM_WIDTH = (RAM_CNT*6);
+
+ generate
+ begin : read_fifo
+
+ wire [MC_ERR_LINE_WIDTH:0] ecc_line;
+ if (CS_WIDTH == 1)
+ assign ecc_line = {col_rmw, col_ba, col_row, col_a_extracted};
+ else
+ assign ecc_line = {col_rmw,
+ col_ra,
+ col_ba,
+ col_row,
+ col_a_extracted};
+
+ wire [FIFO_WIDTH-1:0] real_fifo_data;
+ if (ECC == ""OFF"")
+ assign real_fifo_data = {data_end,
+ col_periodic_rd,
+ col_data_buf_addr,
+ offset_r[DATA_BUF_OFFSET_WIDTH-1:0]};
+ else
+ assign real_fifo_data = {data_end,
+ col_periodic_rd,
+ col_data_buf_addr,
+ offset_r[DATA_BUF_OFFSET_WIDTH-1:0],
+ ecc_line};
+
+ wire [RAM_WIDTH-1:0] fifo_in_data;
+ if (REMAINDER == 0)
+ assign fifo_in_data = real_fifo_data;
+ else
+ assign fifo_in_data = {{6-REMAINDER{1\'b0}}, real_fifo_data};
+
+ wire [RAM_WIDTH-1:0] fifo_out_data_ns;
+
+ reg [4:0] head_r;
+ wire [4:0] head_ns = rst ? 5\'b0 : read_data_valid
+ ? (head_r + 5\'b1)
+ : head_r;
+ always @(posedge clk) head_r <= #TCQ head_ns;
+
+
+ reg [4:0] tail_r;
+ wire [4:0] tail_ns = rst ? 5\'b0 : phy_rddata_valid
+ ? (tail_r + 5\'b1)
+ : tail_r;
+ always @(posedge clk) tail_r <= #TCQ tail_ns;
+
+ assign col_read_fifo_empty = head_r == tail_r ? 1\'b1 : 1\'b0;
+
+ genvar i;
+ for (i=0; iout delay (sim only)
+ parameter nCWL = 5, // Write CAS latency (in clk cyc)
+ parameter DRAM_TYPE = ""DDR3"", // Memory I/F type: ""DDR3"", ""DDR2""
+ parameter WRLVL = ""ON"", // ""OFF"" for ""DDR3"" component interface
+ parameter REFCLK_FREQ = 300.0, // IODELAY Reference Clock freq (MHz)
+ parameter IBUF_LPWR_MODE = ""OFF"", // Input buffer low power mode
+ parameter IODELAY_HP_MODE = ""ON"", // IODELAY High Performance Mode
+ parameter IODELAY_GRP = ""IODELAY_MIG"" // May be assigned unique name
+ // when mult IP cores in design
+ )
+ (
+ input clk_mem,
+ input clk,
+ input rst,
+ input clk_cpt,
+ input clk_rsync,
+ input rst_rsync,
+ // IODELAY I/F
+ input [4:0] dlyval,
+ // Write datapath I/F
+ input inv_dqs,
+ input [1:0] wr_calib_dly,
+ input [3:0] dq_oe_n,
+ input wr_data_rise0,
+ input wr_data_fall0,
+ input wr_data_rise1,
+ input wr_data_fall1,
+ // Read datapath I/F
+ input [1:0] rd_bitslip_cnt,
+ input [1:0] rd_clkdly_cnt,
+ input rd_clkdiv_inv,
+ output rd_data_rise0,
+ output rd_data_fall0,
+ output rd_data_rise1,
+ output rd_data_fall1,
+ // DDR3 bus signals
+ inout ddr_dq,
+ // Debug Port
+ output [4:0] dq_tap_cnt
+ );
+
+ // Set performance mode for IODELAY (power vs. performance tradeoff)
+ localparam HIGH_PERFORMANCE_MODE
+ = (IODELAY_HP_MODE == ""OFF"") ? ""FALSE"" :
+ ((IODELAY_HP_MODE == ""ON"") ? ""TRUE"" : ""ILLEGAL"");
+ // Enable low power mode for input buffer
+ localparam IBUF_LOW_PWR
+ = (IBUF_LPWR_MODE == ""OFF"") ? ""FALSE"" :
+ ((IBUF_LPWR_MODE == ""ON"") ? ""TRUE"" : ""ILLEGAL"");
+
+ wire dq_in;
+ wire dq_iodelay;
+ wire dq_oe_n_r;
+ wire dq_oq;
+ wire iodelay_dout;
+ wire iserdes_clk;
+ wire iserdes_clkb;
+ wire [5:0] iserdes_q;
+ wire [5:0] iserdes_q_mux;
+ reg [5:0] iserdes_q_neg_r;
+ reg [5:0] iserdes_q_r;
+ reg ocb_d1;
+ reg ocb_d2;
+ reg ocb_d3;
+ reg ocb_d4;
+ wire ocb_tfb; // Must be connected to T input of IODELAY
+ // TFB turns IODELAY to ODELAY enabling
+ // CLKPERFDELAY required to lock out TQ
+ wire [3:0] rddata;
+ reg tri_en1_r1;
+ reg tri_en2_r1;
+ reg tri_en3_r1;
+ reg tri_en4_r1;
+ reg wr_data_fall0_r1;
+ reg wr_data_fall0_r2;
+ reg wr_data_fall0_r3;
+ reg wr_data_fall0_r4;
+ reg wr_data_fall1_r1;
+ reg wr_data_fall1_r2;
+ reg wr_data_fall1_r3;
+ reg wr_data_fall1_r4;
+ reg wr_data_rise0_r1;
+ reg wr_data_rise0_r2;
+ reg wr_data_rise0_r3;
+ reg wr_data_rise0_r4;
+ reg wr_data_rise1_r1;
+ reg wr_data_rise1_r2;
+ reg wr_data_rise1_r3;
+ reg wr_data_rise1_r4;
+
+ //***************************************************************************
+ // Bidirectional I/O
+ //***************************************************************************
+
+ IOBUF #
+ (
+ .IBUF_LOW_PWR (IBUF_LOW_PWR)
+ )
+ u_iobuf_dq
+ (
+ .I (dq_iodelay),
+ .T (dq_oe_n_r),
+ .IO (ddr_dq),
+ .O (dq_in)
+ );
+
+ //***************************************************************************
+ // Programmable Delay element - used for both input and output paths
+ //***************************************************************************
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""IO""),
+ .HIGH_PERFORMANCE_MODE (HIGH_PERFORMANCE_MODE),
+ .IDELAY_TYPE (""VAR_LOADABLE""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""VAR_LOADABLE""),
+ .ODELAY_VALUE (0),
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""DATA"")
+ )
+ u_iodelay_dq
+ (
+ .DATAOUT (dq_iodelay),
+ .C (clk_rsync),
+ .CE (1\'b0),
+ .DATAIN (1\'b0),
+ .IDATAIN (dq_in),
+ .INC (1\'b0),
+ .ODATAIN (dq_oq),
+ .RST (1\'b1),
+ .T (ocb_tfb),
+ .CNTVALUEIN (dlyval),
+ .CNTVALUEOUT (dq_tap_cnt),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+
+ //***************************************************************************
+ // Write Path
+ //***************************************************************************
+
+ //*****************************************************************
+ // Write Bitslip
+ //*****************************************************************
+
+ // dfi_wrdata_en0 - even clk cycles channel 0
+ // dfi_wrdata_en1 - odd clk cycles channel 1
+ // tphy_wrlat set to 0 clk cycle for CWL = 5,6,7,8
+ // Valid dfi_wrdata* sent 1 clk cycle after dfi_wrdata_en* is asserted
+ // WC for OCB (Output Circular Buffer) assertion for 1 clk cycle
+ // WC aligned with dfi_wrdata_en*
+
+ // first rising edge data (rise0)
+ // first falling edge data (fall0)
+ // second rising edge data (rise1)
+ // second falling edge data (fall1)
+ always @(posedge clk) begin
+ wr_data_rise0_r1 <= #TCQ wr_data_rise0;
+ wr_data_fall0_r1 <= #TCQ wr_data_fall0;
+ wr_data_rise1_r1 <= #TCQ wr_data_rise1;
+ wr_data_fall1_r1 <= #TCQ wr_data_fall1;
+ wr_data_rise0_r2 <= #TCQ wr_data_rise0_r1;
+ wr_data_fall0_r2 <= #TCQ wr_data_fall0_r1;
+ wr_data_rise1_r2 <= #TCQ wr_data_rise1_r1;
+ wr_data_fall1_r2 <= #TCQ wr_data_fall1_r1;
+ wr_data_rise0_r3 <= #TCQ wr_data_rise0_r2;
+ wr_data_fall0_r3 <= #TCQ wr_data_fall0_r2;
+ wr_data_rise1_r3 <= #TCQ wr_data_rise1_r2;
+ wr_data_fall1_r3 <= #TCQ wr_data_fall1_r2;
+ wr_data_rise0_r4 <= #TCQ wr_data_rise0_r3;
+ wr_data_fall0_r4 <= #TCQ wr_data_fall0_r3;
+ wr_data_rise1_r4 <= #TCQ wr_data_rise1_r3;
+ wr_data_fall1_r4 <= #TCQ wr_data_fall1_r3;
+ end
+
+ // Different nCWL values: 5, 6, 7, 8, 9
+ generate
+ if (DRAM_TYPE == ""DDR3"")begin: gen_ddr3_write_lat
+ if ((nCWL == 5) | (nCWL == 7) | (nCWL == 9)) begin: gen_ncwl_odd
+ always @(posedge clk) begin
+ if (WRLVL == ""OFF"") begin
+ ocb_d1 <= #TCQ wr_data_rise0_r1;
+ ocb_d2 <= #TCQ wr_data_fall0_r1;
+ ocb_d3 <= #TCQ wr_data_rise1_r1;
+ ocb_d4 <= #TCQ wr_data_fall1_r1;
+ end else begin
+ // write command sent by MC on channel1
+ // D3,D4 inputs of the OCB used to send write command to DDR3
+
+ // Shift bitslip logic by 1 or 2 clk_mem cycles
+ // Write calibration currently supports only upto 2 clk_mem cycles
+ case ({wr_calib_dly[1:0], inv_dqs})
+ // 0 clk_mem delay required as per write calibration
+ 3\'b000: begin
+ ocb_d1 <= #TCQ wr_data_fall0_r1;
+ ocb_d2 <= #TCQ wr_data_rise1_r1;
+ ocb_d3 <= #TCQ wr_data_fall1_r1;
+ ocb_d4 <= #TCQ wr_data_rise0;
+ end
+ // DQS inverted during write leveling
+ 3\'b001: begin
+ ocb_d1 <= #TCQ wr_data_rise0_r1;
+ ocb_d2 <= #TCQ wr_data_fall0_r1;
+ ocb_d3 <= #TCQ wr_data_rise1_r1;
+ ocb_d4 <= #TCQ wr_data_fall1_r1;
+ end
+ // 1 clk_mem delay required as per write cal
+ 3\'b010: begin
+ ocb_d1 <= #TCQ wr_data_fall1_r2;
+ ocb_d2 <= #TCQ wr_data_rise0_r1;
+ ocb_d3 <= #TCQ wr_data_fall0_r1;
+ ocb_d4 <= #TCQ wr_data_rise1_r1;
+ end
+ // DQS inverted during write leveling
+ // 1 clk_mem delay required per write cal
+ 3\'b011: begin
+ ocb_d1 <= #TCQ wr_data_rise1_r2;
+ ocb_d2 <= #TCQ wr_data_fall1_r2;
+ ocb_d3 <= #TCQ wr_data_rise0_r1;
+ ocb_d4 <= #TCQ wr_data_fall0_r1;
+ end
+ // 2 clk_mem delay required as per write cal
+ 3\'b100: begin
+ ocb_d1 <= #TCQ wr_data_fall0_r2;
+ ocb_d2 <= #TCQ wr_data_rise1_r2;
+ ocb_d3 <= #TCQ wr_data_fall1_r2;
+ ocb_d4 <= #TCQ wr_data_rise0_r1;
+ end
+ // DQS inverted during write leveling
+ // 2 clk_mem delay required as per write cal
+ 3\'b101: begin
+ ocb_d1 <= #TCQ wr_data_rise0_r2;
+ ocb_d2 <= #TCQ wr_data_fall0_r2;
+ ocb_d3 <= #TCQ wr_data_rise1_r2;
+ ocb_d4 <= #TCQ wr_data_fall1_r2;
+ end
+ // 3 clk_mem delay required as per write cal
+ 3\'b110: begin
+ ocb_d1 <= #TCQ wr_data_fall1_r3;
+ ocb_d2 <= #TCQ wr_data_rise0_r2;
+ ocb_d3 <= #TCQ wr_data_fall0_r2;
+ ocb_d4 <= #TCQ wr_data_rise1_r2;
+ end
+ // DQS inverted during write leveling
+ // 3 clk_mem delay required as per write cal
+ 3\'b111: begin
+ ocb_d1 <= #TCQ wr_data_rise1_r3;
+ ocb_d2 <= #TCQ wr_data_fall1_r3;
+ ocb_d3 <= #TCQ wr_data_rise0_r2;
+ ocb_d4 <= #TCQ wr_data_fall0_r2;
+ end
+ // defaults to 0 clk_mem delay
+ default: begin
+ ocb_d1 <= #TCQ wr_data_fall0_r1;
+ ocb_d2 <= #TCQ wr_data_rise1_r1;
+ ocb_d3 <= #TCQ wr_data_fall1_r1;
+ ocb_d4 <= #TCQ wr_data_rise0;
+ end
+ endcase
+ end
+ end
+ end else if ((nCWL == 6) | (nCWL == 8)) begin: gen_ncwl_even
+ always @(posedge clk) begin
+ if (WRLVL == ""OFF"") begin
+ ocb_d1 <= #TCQ wr_data_rise1_r2;
+ ocb_d2 <= #TCQ wr_data_fall1_r2;
+ ocb_d3 <= #TCQ wr_data_rise0_r1;
+ ocb_d4 <= #TCQ wr_data_fall0_r1;
+ end else begin
+ // write command sent by MC on channel1
+ // D3,D4 inputs of the OCB used to send write command to DDR3
+
+ // Shift bitslip logic by 1 or 2 clk_mem cycles
+ // Write calibration currently supports only upto 2 clk_mem cycles
+ case ({wr_calib_dly[1:0], inv_dqs})
+ // 0 clk_mem delay required as per write calibration
+ // could not test 0011 case
+ 3\'b000: begin
+ ocb_d1 <= #TCQ wr_data_fall1_r2;
+ ocb_d2 <= #TCQ wr_data_rise0_r1;
+ ocb_d3 <= #TCQ wr_data_fall0_r1;
+ ocb_d4 <= #TCQ wr_data_rise1_r1;
+ end
+ // DQS inverted during write leveling
+ 3\'b001: begin
+ ocb_d1 <= #TCQ wr_data_rise1_r2;
+ ocb_d2 <= #TCQ wr_data_fall1_r2;
+ ocb_d3 <= #TCQ wr_data_rise0_r1;
+ ocb_d4 <= #TCQ wr_data_fall0_r1;
+ end
+ // 1 clk_mem delay required as per write cal
+ 3\'b010: begin
+ ocb_d1 <= #TCQ wr_data_fall0_r2;
+ ocb_d2 <= #TCQ wr_data_rise1_r2;
+ ocb_d3 <= #TCQ wr_data_fall1_r2;
+ ocb_d4 <= #TCQ wr_data_rise0_r1;
+ end
+ // DQS inverted during write leveling
+ // 1 clk_mem delay required as per write cal
+ 3\'b011: begin
+ ocb_d1 <= #TCQ wr_data_rise0_r2;
+ ocb_d2 <= #TCQ wr_data_fall0_r2;
+ ocb_d3 <= #TCQ wr_data_rise1_r2;
+ ocb_d4 <= #TCQ wr_data_fall1_r2;
+ end
+ // 2 clk_mem delay required as per write cal
+ 3\'b100: begin
+ ocb_d1 <= #TCQ wr_data_fall1_r3;
+ ocb_d2 <= #TCQ wr_data_rise0_r2;
+ ocb_d3 <= #TCQ wr_data_fall0_r2;
+ ocb_d4 <= #TCQ wr_data_rise1_r2;
+ end
+ // DQS inverted during write leveling
+ // 2 clk_mem delay required as per write cal
+ 3\'b101: begin
+ ocb_d1 <= #TCQ wr_data_rise1_r3;
+ ocb_d2 <= #TCQ wr_data_fall1_r3;
+ ocb_d3 <= #TCQ wr_data_rise0_r2;
+ ocb_d4 <= #TCQ wr_data_fall0_r2;
+ end
+ // 3 clk_mem delay required as per write cal
+ 3\'b110: begin
+ ocb_d1 <= #TCQ wr_data_fall0_r3;
+ ocb_d2 <= #TCQ wr_data_rise1_r3;
+ ocb_d3 <= #TCQ wr_data_fall1_r3;
+ ocb_d4 <= #TCQ wr_data_rise0_r2;
+ end
+ // DQS inverted during write leveling
+ // 3 clk_mem delay required as per write cal
+ 3\'b111: begin
+ ocb_d1 <= #TCQ wr_data_rise0_r3;
+ ocb_d2 <= #TCQ wr_data_fall0_r3;
+ ocb_d3 <= #TCQ wr_data_rise1_r3;
+ ocb_d4 <= #TCQ wr_data_fall1_r3;
+ end
+ // defaults to 0 clk_mem delay
+ default: begin
+ ocb_d1 <= #TCQ wr_data_fall1_r2;
+ ocb_d2 <= #TCQ wr_data_rise0_r1;
+ ocb_d3 <= #TCQ wr_data_fall0_r1;
+ ocb_d4 <= #TCQ wr_data_rise1_r1;
+ end
+ endcase
+ end
+ end
+ end
+ end else begin: ddr2_write_lat
+ if (nCWL == 2) begin: gen_ddr2_ncwl2
+ always @(wr_data_rise1_r1 or wr_data_fall1_r1 or
+ wr_data_rise0 or wr_data_fall0) begin
+ ocb_d1 = wr_data_rise1_r1;
+ ocb_d2 = wr_data_fall1_r1;
+ ocb_d3 = wr_data_rise0;
+ ocb_d4 = wr_data_fall0;
+ end
+ end else if (nCWL == 3) begin: gen_ddr2_ncwl3
+ always @(posedge clk) begin
+ ocb_d1 <= #TCQ wr_data_rise0;
+ ocb_d2 <= #TCQ wr_data_fall0;
+ ocb_d3 <= #TCQ wr_data_rise1;
+ ocb_d4 <= #TCQ wr_data_fall1;
+ end
+ end else if (nCWL == 4) begin: gen_ddr2_ncwl4
+ always @(posedge clk) begin
+ ocb_d1 <= wr_data_rise1_r1;
+ ocb_d2 <= wr_data_fall1_r1;
+ ocb_d3 <= wr_data_rise0;
+ ocb_d4 <= wr_data_fall0;
+ end
+ end else if (nCWL == 5) begin: gen_ddr2_ncwl5
+ always @(posedge clk) begin
+ ocb_d1 <= #TCQ wr_data_rise0_r1;
+ ocb_d2 <= #TCQ wr_data_fall0_r1;
+ ocb_d3 <= #TCQ wr_data_rise1_r1;
+ ocb_d4 <= #TCQ wr_data_fall1_r1;
+ end
+ end else if (nCWL == 6) begin: gen_ddr2_ncwl6
+ always @(posedge clk) begin
+ ocb_d1 <= wr_data_rise1_r2;
+ ocb_d2 <= wr_data_fall1_r2;
+ ocb_d3 <= wr_data_rise0_r1;
+ ocb_d4 <= wr_data_fall0_r1;
+ end
+ end
+ end
+ endgenerate
+
+ //***************************************************************************
+ // on a write, rising edge of DQS corresponds to rising edge of clk_mem
+ // We also know:
+ // 1. DQS driven 1/2 clk_mem cycle after corresponding DQ edge
+ // 2. first rising DQS edge driven on falling edge of clk_mem
+ // 3. DQ to be delayed 1/4 clk_mem cycle using ODELAY taps
+ // 4. therefore, rising data driven on rising edge of clk_mem
+ //***************************************************************************
+
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b0),
+ .INIT_TQ (1\'b1),
+ .INTERFACE_TYPE (""DEFAULT""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_oserdes_dq
+ (
+ .OCBEXTEND (),
+ .OFB (),
+ .OQ (dq_oq),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (dq_oe_n_r),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (),
+ .CLKPERFDELAY (),
+ .D1 (ocb_d1),
+ .D2 (ocb_d2),
+ .D3 (ocb_d3),
+ .D4 (ocb_d4),
+ .D5 (),
+ .D6 (),
+ .OCE (1\'b1),
+ .ODV (1\'b0),
+ .SHIFTIN1 (),
+ .SHIFTIN2 (),
+ .RST (rst),
+ .T1 (dq_oe_n[0]),
+ .T2 (dq_oe_n[1]),
+ .T3 (dq_oe_n[2]),
+ .T4 (dq_oe_n[3]),
+ .TFB (ocb_tfb),
+ .TCE (1\'b1),
+ .WC (1\'b0)
+ );
+
+ //***************************************************************************
+ // Read Path
+ //***************************************************************************
+
+ // Assign equally to avoid delta-delay issues in simulation
+ assign iserdes_clk = clk_cpt;
+ assign iserdes_clkb = ~clk_cpt;
+
+ ISERDESE1 #
+ (
+ .DATA_RATE (""DDR""),
+ .DATA_WIDTH (4),
+ .DYN_CLKDIV_INV_EN (""TRUE""),
+ .DYN_CLK_INV_EN (""FALSE""),
+ .INIT_Q1 (1\'b0),
+ .INIT_Q2 (1\'b0),
+ .INIT_Q3 (1\'b0),
+ .INIT_Q4 (1\'b0),
+ .INTERFACE_TYPE (""MEMORY_DDR3""),
+ .NUM_CE (2),
+ .IOBDELAY (""IFD""),
+ .OFB_USED (""FALSE""),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_Q1 (1\'b0),
+ .SRVAL_Q2 (1\'b0),
+ .SRVAL_Q3 (1\'b0),
+ .SRVAL_Q4 (1\'b0)
+ )
+ u_iserdes_dq
+ (
+ .O (),
+ .Q1 (iserdes_q[0]),
+ .Q2 (iserdes_q[1]),
+ .Q3 (iserdes_q[2]),
+ .Q4 (iserdes_q[3]),
+ .Q5 (iserdes_q[4]),
+ .Q6 (iserdes_q[5]),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .BITSLIP (1\'b0),
+ .CE1 (1\'b1),
+ .CE2 (1\'b1),
+ .CLK (iserdes_clk),
+ .CLKB (iserdes_clkb),
+ .CLKDIV (clk_rsync),
+ .D (),
+ .DDLY (dq_iodelay),
+ .DYNCLKDIVSEL (rd_clkdiv_inv),
+ .DYNCLKSEL (1\'b0),
+ .OCLK (clk_mem), // Not used, but connect to avoid DRC
+ .OFB (1\'b0),
+ .RST (rst_rsync),
+ .SHIFTIN1 (1\'b0),
+ .SHIFTIN2 (1\'b0)
+ );
+
+ //*****************************************************************
+ // Selectable registers on ISERDES data outputs depending on
+ // whether DYNCLKDIVSEL is enabled or not
+ //*****************************************************************
+
+ // Capture first using CLK_RSYNC falling edge domain, then transfer
+ // to rising edge CLK_RSYNC. We could also attempt to transfer
+ // directly from falling edge CLK_RSYNC domain (in ISERDES) to
+ // rising edge CLK_RSYNC domain in fabric. This is allowed as long
+ // as the half-cycle timing on these paths can be met.
+ always @(negedge clk_rsync)
+ iserdes_q_neg_r <= #TCQ iserdes_q;
+ always @(posedge clk_rsync)
+ iserdes_q_r <= #TCQ iserdes_q_neg_r;
+
+ assign iserdes_q_mux = (rd_clkdiv_inv) ? iserdes_q_r : iserdes_q;
+
+ //*****************************************************************
+ // Read bitslip logic
+ //*****************************************************************
+
+ rd_bitslip #
+ (
+ .TCQ(TCQ)
+ )
+ u_rd_bitslip
+ (
+ .clk (clk_rsync),
+ .bitslip_cnt (rd_bitslip_cnt),
+ .clkdly_cnt (rd_clkdly_cnt),
+ .din (iserdes_q_mux),
+ .qout (rddata)
+ );
+
+ assign rd_data_rise0 = rddata[3];
+ assign rd_data_fall0 = rddata[2];
+ assign rd_data_rise1 = rddata[1];
+ assign rd_data_fall1 = rddata[0];
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2008-2009 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : 3.91
+// \\ \\ Application : MIG
+// / / Filename : bank_mach.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : Virtex-6
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+// Top level bank machine block. A structural block instantiating the configured
+// individual bank machines, and a common block that computes various items shared
+// by all bank machines.
+
+`timescale 1ns/1ps
+
+module bank_mach #
+ (
+ parameter TCQ = 100,
+ parameter ADDR_CMD_MODE = ""1T"",
+ parameter BANK_WIDTH = 3,
+ parameter BM_CNT_WIDTH = 2,
+ parameter BURST_MODE = ""8"",
+ parameter COL_WIDTH = 12,
+ parameter CS_WIDTH = 4,
+ parameter CWL = 5,
+ parameter DATA_BUF_ADDR_WIDTH = 8,
+ parameter DRAM_TYPE = ""DDR3"",
+ parameter EARLY_WR_DATA_ADDR = ""OFF"",
+ parameter ECC = ""OFF"",
+ parameter LOW_IDLE_CNT = 1,
+ parameter nBANK_MACHS = 4,
+ parameter nCK_PER_CLK = 2,
+ parameter nCNFG2RD_EN = 2,
+ parameter nCNFG2WR = 2,
+ parameter nCS_PER_RANK = 1,
+ parameter nOP_WAIT = 0,
+ parameter nRAS = 20,
+ parameter nRCD = 5,
+ parameter nRFC = 44,
+ parameter nRTP = 4,
+ parameter nRP = 10,
+ parameter nSLOTS = 2,
+ parameter nWR = 6,
+ parameter ORDERING = ""NORM"",
+ parameter RANK_BM_BV_WIDTH = 16,
+ parameter RANK_WIDTH = 2,
+ parameter RANKS = 4,
+ parameter ROW_WIDTH = 16,
+ parameter RTT_NOM = ""40"",
+ parameter RTT_WR = ""120"",
+ parameter STARVE_LIMIT = 2,
+ parameter SLOT_0_CONFIG = 8\'b0000_0101,
+ parameter SLOT_1_CONFIG = 8\'b0000_1010,
+ parameter tZQCS = 64
+ )
+ (/*AUTOARG*/
+ // Outputs
+ maint_wip_r, insert_maint_r1, dfi_we_n1, dfi_we_n0, dfi_ras_n1,
+ dfi_ras_n0, dfi_odt_wr1, dfi_odt_wr0, dfi_odt_nom1, dfi_odt_nom0,
+ dfi_cs_n1, dfi_cs_n0, dfi_cas_n1, dfi_cas_n0, dfi_bank1, dfi_bank0,
+ dfi_address1, dfi_address0, col_wr_data_buf_addr, col_size, col_row,
+ col_rmw, col_ra, col_periodic_rd, col_data_buf_addr, col_ba, col_a,
+ bank_mach_next, accept_ns, accept, io_config, io_config_strobe,
+ sending_row, sending_col, sent_col, periodic_rd_ack_r,
+ act_this_rank_r, wr_this_rank_r, rd_this_rank_r, rank_busy_r,
+ // Inputs
+ wtr_inhbt_config_r, use_addr, slot_1_present, slot_0_present, size,
+ rst, row, rd_rmw, rd_data_addr, rank, periodic_rd_rank_r,
+ periodic_rd_r, maint_zq_r, maint_req_r, maint_rank_r,
+ inhbt_wr_config, inhbt_rd_r, inhbt_rd_config, inhbt_act_faw_r,
+ hi_priority, dq_busy_data, dfi_rddata_valid, dfi_init_complete,
+ data_buf_addr, col, cmd, clk, bank
+ );
+
+ function integer clogb2 (input integer size); // ceiling logb2
+ begin
+ size = size - 1;
+ for (clogb2=1; size>1; clogb2=clogb2+1)
+ size = size >> 1;
+ end
+ endfunction // clogb2
+
+ localparam RANK_VECT_INDX = (nBANK_MACHS *RANK_WIDTH) - 1;
+ localparam BANK_VECT_INDX = (nBANK_MACHS * BANK_WIDTH) - 1;
+ localparam ROW_VECT_INDX = (nBANK_MACHS * ROW_WIDTH) - 1;
+ localparam DATA_BUF_ADDR_VECT_INDX = (nBANK_MACHS * DATA_BUF_ADDR_WIDTH) - 1;
+ localparam nRAS_CLKS = (nCK_PER_CLK == 1) ? nRAS : ((nRAS/2) + (nRAS % 2));
+ localparam nWTP = CWL + ((BURST_MODE == ""4"") ? 2 : 4) + nWR;
+// Unless 2T mode, add one to nWTP_CLKS. This accounts for loss of one DRAM CK
+// due to column command to row command fixed offset.
+ localparam nWTP_CLKS = (nCK_PER_CLK == 1)
+ ? nWTP
+ : (nWTP/2) + ((ADDR_CMD_MODE == ""2T"") ? nWTP%2 : 1);
+ localparam RAS_TIMER_WIDTH = clogb2(((nRAS_CLKS > nWTP_CLKS)
+ ? nRAS_CLKS
+ : nWTP_CLKS) - 1);
+
+ /*AUTOINPUT*/
+ // Beginning of automatic inputs (from unused autoinst inputs)
+ input [BANK_WIDTH-1:0] bank; // To bank0 of bank_cntrl.v
+ input clk; // To bank0 of bank_cntrl.v, ...
+ input [2:0] cmd; // To bank0 of bank_cntrl.v, ...
+ input [COL_WIDTH-1:0] col; // To bank0 of bank_cntrl.v
+ input [DATA_BUF_ADDR_WIDTH-1:0] data_buf_addr;// To bank0 of bank_cntrl.v
+ input dfi_init_complete; // To bank_common0 of bank_common.v
+ input dfi_rddata_valid; // To bank0 of bank_cntrl.v
+ input dq_busy_data; // To bank0 of bank_cntrl.v
+ input hi_priority; // To bank0 of bank_cntrl.v, ...
+ input [RANKS-1:0] inhbt_act_faw_r; // To bank0 of bank_cntrl.v
+ input inhbt_rd_config; // To bank0 of bank_cntrl.v
+ input [RANKS-1:0] inhbt_rd_r; // To bank0 of bank_cntrl.v
+ input inhbt_wr_config; // To bank0 of bank_cntrl.v
+ input [RANK_WIDTH-1:0] maint_rank_r; // To bank0 of bank_cntrl.v, ...
+ input maint_req_r; // To bank0 of bank_cntrl.v, ...
+ input maint_zq_r; // To bank0 of bank_cntrl.v, ...
+ input periodic_rd_r; // To bank_common0 of bank_common.v
+ input [RANK_WIDTH-1:0] periodic_rd_rank_r; // To bank0 of bank_cntrl.v
+ input [RANK_WIDTH-1:0] rank; // To bank0 of bank_cntrl.v
+ input [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr; // To bank0 of bank_cntrl.v
+ input rd_rmw; // To bank0 of bank_cntrl.v
+ input [ROW_WIDTH-1:0] row; // To bank0 of bank_cntrl.v
+ input rst; // To bank0 of bank_cntrl.v, ...
+ input size; // To bank0 of bank_cntrl.v
+ input [7:0] slot_0_present; // To bank_common0 of bank_common.v, ...
+ input [7:0] slot_1_present; // To bank_common0 of bank_common.v, ...
+ input use_addr; // To bank0 of bank_cntrl.v, ...
+ input [RANKS-1:0] wtr_inhbt_config_r; // To bank0 of bank_cntrl.v
+ // End of automatics
+
+ /*AUTOOUTPUT*/
+ // Beginning of automatic outputs (from unused autoinst outputs)
+ output accept; // From bank_common0 of bank_common.v
+ output accept_ns; // From bank_common0 of bank_common.v
+ output [BM_CNT_WIDTH-1:0] bank_mach_next; // From bank_common0 of bank_common.v
+ output [ROW_WIDTH-1:0] col_a; // From arb_mux0 of arb_mux.v
+ output [BANK_WIDTH-1:0] col_ba; // From arb_mux0 of arb_mux.v
+ output [DATA_BUF_ADDR_WIDTH-1:0] col_data_buf_addr;// From arb_mux0 of arb_mux.v
+ output col_periodic_rd; // From arb_mux0 of arb_mux.v
+ output [RANK_WIDTH-1:0] col_ra; // From arb_mux0 of arb_mux.v
+ output col_rmw; // From arb_mux0 of arb_mux.v
+ output [ROW_WIDTH-1:0] col_row; // From arb_mux0 of arb_mux.v
+ output col_size; // From arb_mux0 of arb_mux.v
+ output [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr;// From arb_mux0 of arb_mux.v
+ output [ROW_WIDTH-1:0] dfi_address0; // From arb_mux0 of arb_mux.v
+ output [ROW_WIDTH-1:0] dfi_address1; // From arb_mux0 of arb_mux.v
+ output [BANK_WIDTH-1:0] dfi_bank0; // From arb_mux0 of arb_mux.v
+ output [BANK_WIDTH-1:0] dfi_bank1; // From arb_mux0 of arb_mux.v
+ output dfi_cas_n0; // From arb_mux0 of arb_mux.v
+ output dfi_cas_n1; // From arb_mux0 of arb_mux.v
+ output [(CS_WIDTH*nCS_PER_RANK)-1:0] dfi_cs_n0;// From arb_mux0 of arb_mux.v
+ output [(CS_WIDTH*nCS_PER_RANK)-1:0] dfi_cs_n1;// From arb_mux0 of arb_mux.v
+ output [(nSLOTS*nCS_PER_RANK)-1:0] dfi_odt_nom0;// From arb_mux0 of arb_mux.v
+ output [(nSLOTS*nCS_PER_RANK)-1:0] dfi_odt_nom1;// From arb_mux0 of arb_mux.v
+ output [(nSLOTS*nCS_PER_RANK)-1:0] dfi_odt_wr0;// From arb_mux0 of arb_mux.v
+ output [(nSLOTS*nCS_PER_RANK)-1:0] dfi_odt_wr1;// From arb_mux0 of arb_mux.v
+ output dfi_ras_n0; // From arb_mux0 of arb_mux.v
+ output dfi_ras_n1; // From arb_mux0 of arb_mux.v
+ output dfi_we_n0; // From arb_mux0 of arb_mux.v
+ output dfi_we_n1; // From arb_mux0 of arb_mux.v
+ output insert_maint_r1; // From arb_mux0 of arb_mux.v
+ output maint_wip_r; // From bank_common0 of bank_common.v
+ // End of automatics
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire accept_internal_r; // From bank_common0 of bank_common.v
+ wire accept_req; // From bank_common0 of bank_common.v
+ wire adv_order_q; // From bank_common0 of bank_common.v
+ wire force_io_config_rd_r; // From bank_common0 of bank_common.v
+ wire [BM_CNT_WIDTH-1:0] idle_cnt; // From bank_common0 of bank_common.v
+ wire insert_maint_r; // From bank_common0 of bank_common.v
+ wire io_config_valid_r; // From arb_mux0 of arb_mux.v
+ wire low_idle_cnt_r; // From bank_common0 of bank_common.v
+ wire maint_idle; // From bank_common0 of bank_common.v
+ wire [BM_CNT_WIDTH-1:0] order_cnt; // From bank_common0 of bank_common.v
+ wire periodic_rd_insert; // From bank_common0 of bank_common.v
+ wire [BM_CNT_WIDTH-1:0] rb_hit_busy_cnt; // From bank_common0 of bank_common.v
+ wire sent_row; // From arb_mux0 of arb_mux.v
+ wire was_priority; // From bank_common0 of bank_common.v
+ wire was_wr; // From bank_common0 of bank_common.v
+ // End of automatics
+
+ output [RANK_WIDTH:0] io_config;
+ output io_config_strobe;
+
+ wire [nBANK_MACHS-1:0] rts_row;
+ wire [nBANK_MACHS-1:0] rts_col;
+ wire [nBANK_MACHS-1:0] col_rdy_wr;
+ wire [nBANK_MACHS-1:0] rtc;
+ output wire [nBANK_MACHS-1:0] sending_row;
+ output wire [nBANK_MACHS-1:0] sending_col;
+ output wire sent_col;
+
+ output periodic_rd_ack_r;
+
+ wire [DATA_BUF_ADDR_VECT_INDX:0] req_data_buf_addr_r;
+ wire [nBANK_MACHS-1:0] req_size_r;
+ wire [RANK_VECT_INDX:0] req_rank_r;
+ wire [BANK_VECT_INDX:0] req_bank_r;
+ wire [ROW_VECT_INDX:0] req_row_r;
+ wire [ROW_VECT_INDX:0] col_addr;
+ wire [nBANK_MACHS-1:0] req_periodic_rd_r;
+ wire [nBANK_MACHS-1:0] req_wr_r;
+ wire [nBANK_MACHS-1:0] rd_wr_r;
+ wire [nBANK_MACHS-1:0] req_ras;
+ wire [nBANK_MACHS-1:0] req_cas;
+ wire [ROW_VECT_INDX:0] row_addr;
+ wire [nBANK_MACHS-1:0] row_cmd_wr;
+ wire [nBANK_MACHS-1:0] demand_priority;
+ wire [nBANK_MACHS-1:0] demand_act_priority;
+
+ output wire [RANK_BM_BV_WIDTH-1:0] act_this_rank_r;
+ output wire [RANK_BM_BV_WIDTH-1:0] wr_this_rank_r;
+ output wire [RANK_BM_BV_WIDTH-1:0] rd_this_rank_r;
+
+ wire [nBANK_MACHS-1:0] idle_ns;
+ wire [nBANK_MACHS-1:0] rb_hit_busy_r;
+ wire [nBANK_MACHS-1:0] bm_end;
+ wire [nBANK_MACHS-1:0] passing_open_bank;
+ wire [nBANK_MACHS-1:0] ordered_r;
+ wire [nBANK_MACHS-1:0] ordered_issued;
+ wire [nBANK_MACHS-1:0] rb_hit_busy_ns;
+ wire [nBANK_MACHS-1:0] maint_hit;
+ wire [nBANK_MACHS-1:0] idle_r;
+ wire [nBANK_MACHS-1:0] head_r;
+ wire [nBANK_MACHS-1:0] start_rcd;
+
+ wire [nBANK_MACHS-1:0] end_rtp;
+ wire [nBANK_MACHS-1:0] op_exit_req;
+ wire [nBANK_MACHS-1:0] op_exit_grant;
+ wire [nBANK_MACHS-1:0] start_pre_wait;
+
+ wire [(RAS_TIMER_WIDTH*nBANK_MACHS)-1:0] ras_timer_ns;
+
+ output wire [(RANKS*nBANK_MACHS)-1:0] rank_busy_r;
+
+ genvar ID;
+ generate for (ID=0; ID=0;dump_index=dump_index-1)
+ if (dump_index>=index-ones) next_combo[dump_index] = 1\'b1;
+ end
+ seen0 = ~i[index];
+ end // else: !if(trig1)
+ end
+ end // function
+ endfunction // next_combo
+
+ wire [ECC_WIDTH-1:0] ht_matrix [CODE_WIDTH-1:0];
+ output wire [CODE_WIDTH*ECC_WIDTH-1:0] h_rows;
+
+ localparam COMBOS_3 = combos(ECC_WIDTH, 3);
+ localparam COMBOS_5 = combos(ECC_WIDTH, 5);
+ genvar n;
+ genvar s;
+ generate
+ for (n=0; n= 2) begin : pipe_2_lane
+
+ pcie_7x_v1_8_pcie_pipe_lane # (
+
+ .PIPE_PIPELINE_STAGES(PIPE_PIPELINE_STAGES)
+
+ )
+ pipe_lane_1_i (
+
+ .pipe_rx_char_is_k_o(pipe_rx1_char_is_k_o),
+ .pipe_rx_data_o(pipe_rx1_data_o),
+ .pipe_rx_valid_o(pipe_rx1_valid_o),
+ .pipe_rx_chanisaligned_o(pipe_rx1_chanisaligned_o),
+ .pipe_rx_status_o(pipe_rx1_status_o),
+ .pipe_rx_phy_status_o(pipe_rx1_phy_status_o),
+ .pipe_rx_elec_idle_o(pipe_rx1_elec_idle_o),
+ .pipe_rx_polarity_i(pipe_rx1_polarity_i),
+ .pipe_tx_compliance_i(pipe_tx1_compliance_i),
+ .pipe_tx_char_is_k_i(pipe_tx1_char_is_k_i),
+ .pipe_tx_data_i(pipe_tx1_data_i),
+ .pipe_tx_elec_idle_i(pipe_tx1_elec_idle_i),
+ .pipe_tx_powerdown_i(pipe_tx1_powerdown_i),
+
+ .pipe_rx_char_is_k_i(pipe_rx1_char_is_k_i),
+ .pipe_rx_data_i(pipe_rx1_data_i),
+ .pipe_rx_valid_i(pipe_rx1_valid_i),
+ .pipe_rx_chanisaligned_i(pipe_rx1_chanisaligned_i),
+ .pipe_rx_status_i(pipe_rx1_status_i),
+ .pipe_rx_phy_status_i(pipe_rx1_phy_status_i),
+ .pipe_rx_elec_idle_i(pipe_rx1_elec_idle_i),
+ .pipe_rx_polarity_o(pipe_rx1_polarity_o),
+ .pipe_tx_compliance_o(pipe_tx1_compliance_o),
+ .pipe_tx_char_is_k_o(pipe_tx1_char_is_k_o),
+ .pipe_tx_data_o(pipe_tx1_data_o),
+ .pipe_tx_elec_idle_o(pipe_tx1_elec_idle_o),
+ .pipe_tx_powerdown_o(pipe_tx1_powerdown_o),
+
+ .pipe_clk(pipe_clk),
+ .rst_n(rst_n)
+
+ );
+
+ end // if (LINK_CAP_MAX_LINK_WIDTH >= 2)
+ else
+ begin
+ assign pipe_rx1_char_is_k_o = 2\'b00;
+ assign pipe_rx1_data_o = 16\'h0000;
+ assign pipe_rx1_valid_o = 1\'b0;
+ assign pipe_rx1_chanisaligned_o = 1\'b0;
+ assign pipe_rx1_status_o = 3\'b000;
+ assign pipe_rx1_phy_status_o = 1\'b0;
+ assign pipe_rx1_elec_idle_o = 1\'b1;
+ assign pipe_rx1_polarity_o = 1\'b0;
+ assign pipe_tx1_compliance_o = 1\'b0;
+ assign pipe_tx1_char_is_k_o = 2\'b00;
+ assign pipe_tx1_data_o = 16\'h0000;
+ assign pipe_tx1_elec_idle_o = 1\'b1;
+ assign pipe_tx1_powerdown_o = 2\'b00;
+ end // if !(LINK_CAP_MAX_LINK_WIDTH >= 2)
+
+ if (LINK_CAP_MAX_LINK_WIDTH >= 4) begin : pipe_4_lane
+
+ pcie_7x_v1_8_pcie_pipe_lane # (
+
+ .PIPE_PIPELINE_STAGES(PIPE_PIPELINE_STAGES)
+ )
+ pipe_lane_2_i (
+
+ .pipe_rx_char_is_k_o(pipe_rx2_char_is_k_o),
+ .pipe_rx_data_o(pipe_rx2_data_o),
+ .pipe_rx_valid_o(pipe_rx2_valid_o),
+ .pipe_rx_chanisaligned_o(pipe_rx2_chanisaligned_o),
+ .pipe_rx_status_o(pipe_rx2_status_o),
+ .pipe_rx_phy_status_o(pipe_rx2_phy_status_o),
+ .pipe_rx_elec_idle_o(pipe_rx2_elec_idle_o),
+ .pipe_rx_polarity_i(pipe_rx2_polarity_i),
+ .pipe_tx_compliance_i(pipe_tx2_compliance_i),
+ .pipe_tx_char_is_k_i(pipe_tx2_char_is_k_i),
+ .pipe_tx_data_i(pipe_tx2_data_i),
+ .pipe_tx_elec_idle_i(pipe_tx2_elec_idle_i),
+ .pipe_tx_powerdown_i(pipe_tx2_powerdown_i),
+
+ .pipe_rx_char_is_k_i(pipe_rx2_char_is_k_i),
+ .pipe_rx_data_i(pipe_rx2_data_i),
+ .pipe_rx_valid_i(pipe_rx2_valid_i),
+ .pipe_rx_chanisaligned_i(pipe_rx2_chanisaligned_i),
+ .pipe_rx_status_i(pipe_rx2_status_i),
+ .pipe_rx_phy_status_i(pipe_rx2_phy_status_i),
+ .pipe_rx_elec_idle_i(pipe_rx2_elec_idle_i),
+ .pipe_rx_polarity_o(pipe_rx2_polarity_o),
+ .pipe_tx_compliance_o(pipe_tx2_compliance_o),
+ .pipe_tx_char_is_k_o(pipe_tx2_char_is_k_o),
+ .pipe_tx_data_o(pipe_tx2_data_o),
+ .pipe_tx_elec_idle_o(pipe_tx2_elec_idle_o),
+ .pipe_tx_powerdown_o(pipe_tx2_powerdown_o),
+
+ .pipe_clk(pipe_clk),
+ .rst_n(rst_n)
+
+ );
+
+ pcie_7x_v1_8_pcie_pipe_lane # (
+
+ .PIPE_PIPELINE_STAGES(PIPE_PIPELINE_STAGES)
+
+ )
+ pipe_lane_3_i (
+
+ .pipe_rx_char_is_k_o(pipe_rx3_char_is_k_o),
+ .pipe_rx_data_o(pipe_rx3_data_o),
+ .pipe_rx_valid_o(pipe_rx3_valid_o),
+ .pipe_rx_chanisaligned_o(pipe_rx3_chanisaligned_o),
+ .pipe_rx_status_o(pipe_rx3_status_o),
+ .pipe_rx_phy_status_o(pipe_rx3_phy_status_o),
+ .pipe_rx_elec_idle_o(pipe_rx3_elec_idle_o),
+ .pipe_rx_polarity_i(pipe_rx3_polarity_i),
+ .pipe_tx_compliance_i(pipe_tx3_compliance_i),
+ .pipe_tx_char_is_k_i(pipe_tx3_char_is_k_i),
+ .pipe_tx_data_i(pipe_tx3_data_i),
+ .pipe_tx_elec_idle_i(pipe_tx3_elec_idle_i),
+ .pipe_tx_powerdown_i(pipe_tx3_powerdown_i),
+
+ .pipe_rx_char_is_k_i(pipe_rx3_char_is_k_i),
+ .pipe_rx_data_i(pipe_rx3_data_i),
+ .pipe_rx_valid_i(pipe_rx3_valid_i),
+ .pipe_rx_chanisaligned_i(pipe_rx3_chanisaligned_i),
+ .pipe_rx_status_i(pipe_rx3_status_i),
+ .pipe_rx_phy_status_i(pipe_rx3_phy_status_i),
+ .pipe_rx_elec_idle_i(pipe_rx3_elec_idle_i),
+ .pipe_rx_polarity_o(pipe_rx3_polarity_o),
+ .pipe_tx_compliance_o(pipe_tx3_compliance_o),
+ .pipe_tx_char_is_k_o(pipe_tx3_char_is_k_o),
+ .pipe_tx_data_o(pipe_tx3_data_o),
+ .pipe_tx_elec_idle_o(pipe_tx3_elec_idle_o),
+ .pipe_tx_powerdown_o(pipe_tx3_powerdown_o),
+
+ .pipe_clk(pipe_clk),
+ .rst_n(rst_n)
+
+ );
+
+ end // if (LINK_CAP_MAX_LINK_WIDTH >= 4)
+ else
+ begin
+ assign pipe_rx2_char_is_k_o = 2\'b00;
+ assign pipe_rx2_data_o = 16\'h0000;
+ assign pipe_rx2_valid_o = 1\'b0;
+ assign pipe_rx2_chanisaligned_o = 1\'b0;
+ assign pipe_rx2_status_o = 3\'b000;
+ assign pipe_rx2_phy_status_o = 1\'b0;
+ assign pipe_rx2_elec_idle_o = 1\'b1;
+ assign pipe_rx2_polarity_o = 1\'b0;
+ assign pipe_tx2_compliance_o = 1\'b0;
+ assign pipe_tx2_char_is_k_o = 2\'b00;
+ assign pipe_tx2_data_o = 16\'h0000;
+ assign pipe_tx2_elec_idle_o = 1\'b1;
+ assign pipe_tx2_powerdown_o = 2\'b00;
+
+ assign pipe_rx3_char_is_k_o = 2\'b00;
+ assign pipe_rx3_data_o = 16\'h0000;
+ assign pipe_rx3_valid_o = 1\'b0;
+ assign pipe_rx3_chanisaligned_o = 1\'b0;
+ assign pipe_rx3_status_o = 3\'b000;
+ assign pipe_rx3_phy_status_o = 1\'b0;
+ assign pipe_rx3_elec_idle_o = 1\'b1;
+ assign pipe_rx3_polarity_o = 1\'b0;
+ assign pipe_tx3_compliance_o = 1\'b0;
+ assign pipe_tx3_char_is_k_o = 2\'b00;
+ assign pipe_tx3_data_o = 16\'h0000;
+ assign pipe_tx3_elec_idle_o = 1\'b1;
+ assign pipe_tx3_powerdown_o = 2\'b00;
+ end // if !(LINK_CAP_MAX_LINK_WIDTH >= 4)
+
+ if (LINK_CAP_MAX_LINK_WIDTH >= 8) begin : pipe_8_lane
+
+ pcie_7x_v1_8_pcie_pipe_lane # (
+
+ .PIPE_PIPELINE_STAGES(PIPE_PIPELINE_STAGES)
+
+ )
+ pipe_lane_4_i (
+
+ .pipe_rx_char_is_k_o(pipe_rx4_char_is_k_o),
+ .pipe_rx_data_o(pipe_rx4_data_o),
+ .pipe_rx_valid_o(pipe_rx4_valid_o),
+ .pipe_rx_chanisaligned_o(pipe_rx4_chanisaligned_o),
+ .pipe_rx_status_o(pipe_rx4_status_o),
+ .pipe_rx_phy_status_o(pipe_rx4_phy_status_o),
+ .pipe_rx_elec_idle_o(pipe_rx4_elec_idle_o),
+ .pipe_rx_polarity_i(pipe_rx4_polarity_i),
+ .pipe_tx_compliance_i(pipe_tx4_compliance_i),
+ .pipe_tx_char_is_k_i(pipe_tx4_char_is_k_i),
+ .pipe_tx_data_i(pipe_tx4_data_i),
+ .pipe_tx_elec_idle_i(pipe_tx4_elec_idle_i),
+ .pipe_tx_powerdown_i(pipe_tx4_powerdown_i),
+
+ .pipe_rx_char_is_k_i(pipe_rx4_char_is_k_i),
+ .pipe_rx_data_i(pipe_rx4_data_i),
+ .pipe_rx_valid_i(pipe_rx4_valid_i),
+ .pipe_rx_chanisaligned_i(pipe_rx4_chanisaligned_i),
+ .pipe_rx_status_i(pipe_rx4_status_i),
+ .pipe_rx_phy_status_i(pipe_rx4_phy_status_i),
+ .pipe_rx_elec_idle_i(pipe_rx4_elec_idle_i),
+ .pipe_rx_polarity_o(pipe_rx4_polarity_o),
+ .pipe_tx_compliance_o(pipe_tx4_compliance_o),
+ .pipe_tx_char_is_k_o(pipe_tx4_char_is_k_o),
+ .pipe_tx_data_o(pipe_tx4_data_o),
+ .pipe_tx_elec_idle_o(pipe_tx4_elec_idle_o),
+ .pipe_tx_powerdown_o(pipe_tx4_powerdown_o),
+
+ .pipe_clk(pipe_clk),
+ .rst_n(rst_n)
+
+ );
+
+ pcie_7x_v1_8_pcie_pipe_lane # (
+
+ .PIPE_PIPELINE_STAGES(PIPE_PIPELINE_STAGES)
+
+ )
+ pipe_lane_5_i (
+
+ .pipe_rx_char_is_k_o(pipe_rx5_char_is_k_o),
+ .pipe_rx_data_o(pipe_rx5_data_o),
+ .pipe_rx_valid_o(pipe_rx5_valid_o),
+ .pipe_rx_chanisaligned_o(pipe_rx5_chanisaligned_o),
+ .pipe_rx_status_o(pipe_rx5_status_o),
+ .pipe_rx_phy_status_o(pipe_rx5_phy_status_o),
+ .pipe_rx_elec_idle_o(pipe_rx5_elec_idle_o),
+ .pipe_rx_polarity_i(pipe_rx5_polarity_i),
+ .pipe_tx_compliance_i(pipe_tx5_compliance_i),
+ .pipe_tx_char_is_k_i(pipe_tx5_char_is_k_i),
+ .pipe_tx_data_i(pipe_tx5_data_i),
+ .pipe_tx_elec_idle_i(pipe_tx5_elec_idle_i),
+ .pipe_tx_powerdown_i(pipe_tx5_powerdown_i),
+
+ .pipe_rx_char_is_k_i(pipe_rx5_char_is_k_i),
+ .pipe_rx_data_i(pipe_rx5_data_i),
+ .pipe_rx_valid_i(pipe_rx5_valid_i),
+ .pipe_rx_chanisaligned_i(pipe_rx5_chanisaligned_i),
+ .pipe_rx_status_i(pipe_rx5_status_i),
+ .pipe_rx_phy_status_i(pipe_rx5_phy_status_i),
+ .pipe_rx_elec_idle_i(pipe_rx5_elec_idle_i),
+ .pipe_rx_polarity_o(pipe_rx5_polarity_o),
+ .pipe_tx_compliance_o(pipe_tx5_compliance_o),
+ .pipe_tx_char_is_k_o(pipe_tx5_char_is_k_o),
+ .pipe_tx_data_o(pipe_tx5_data_o),
+ .pipe_tx_elec_idle_o(pipe_tx5_elec_idle_o),
+ .pipe_tx_powerdown_o(pipe_tx5_powerdown_o),
+
+ .pipe_clk(pipe_clk),
+ .rst_n(rst_n)
+
+ );
+
+ pcie_7x_v1_8_pcie_pipe_lane # (
+
+ .PIPE_PIPELINE_STAGES(PIPE_PIPELINE_STAGES)
+
+ )
+ pipe_lane_6_i (
+
+ .pipe_rx_char_is_k_o(pipe_rx6_char_is_k_o),
+ .pipe_rx_data_o(pipe_rx6_data_o),
+ .pipe_rx_valid_o(pipe_rx6_valid_o),
+ .pipe_rx_chanisaligned_o(pipe_rx6_chanisaligned_o),
+ .pipe_rx_status_o(pipe_rx6_status_o),
+ .pipe_rx_phy_status_o(pipe_rx6_phy_status_o),
+ .pipe_rx_elec_idle_o(pipe_rx6_elec_idle_o),
+ .pipe_rx_polarity_i(pipe_rx6_polarity_i),
+ .pipe_tx_compliance_i(pipe_tx6_compliance_i),
+ .pipe_tx_char_is_k_i(pipe_tx6_char_is_k_i),
+ .pipe_tx_data_i(pipe_tx6_data_i),
+ .pipe_tx_elec_idle_i(pipe_tx6_elec_idle_i),
+ .pipe_tx_powerdown_i(pipe_tx6_powerdown_i),
+
+ .pipe_rx_char_is_k_i(pipe_rx6_char_is_k_i),
+ .pipe_rx_data_i(pipe_rx6_data_i),
+ .pipe_rx_valid_i(pipe_rx6_valid_i),
+ .pipe_rx_chanisaligned_i(pipe_rx6_chanisaligned_i),
+ .pipe_rx_status_i(pipe_rx6_status_i),
+ .pipe_rx_phy_status_i(pipe_rx6_phy_status_i),
+ .pipe_rx_elec_idle_i(pipe_rx6_elec_idle_i),
+ .pipe_rx_polarity_o(pipe_rx6_polarity_o),
+ .pipe_tx_compliance_o(pipe_tx6_compliance_o),
+ .pipe_tx_char_is_k_o(pipe_tx6_char_is_k_o),
+ .pipe_tx_data_o(pipe_tx6_data_o),
+ .pipe_tx_elec_idle_o(pipe_tx6_elec_idle_o),
+ .pipe_tx_powerdown_o(pipe_tx6_powerdown_o),
+
+ .pipe_clk(pipe_clk),
+ .rst_n(rst_n)
+
+ );
+
+ pcie_7x_v1_8_pcie_pipe_lane # (
+
+ .PIPE_PIPELINE_STAGES(PIPE_PIPELINE_STAGES)
+
+ )
+ pipe_lane_7_i (
+
+ .pipe_rx_char_is_k_o(pipe_rx7_char_is_k_o),
+ .pipe_rx_data_o(pipe_rx7_data_o),
+ .pipe_rx_valid_o(pipe_rx7_valid_o),
+ .pipe_rx_chanisaligned_o(pipe_rx7_chanisaligned_o),
+ .pipe_rx_status_o(pipe_rx7_status_o),
+ .pipe_rx_phy_status_o(pipe_rx7_phy_status_o),
+ .pipe_rx_elec_idle_o(pipe_rx7_elec_idle_o),
+ .pipe_rx_polarity_i(pipe_rx7_polarity_i),
+ .pipe_tx_compliance_i(pipe_tx7_compliance_i),
+ .pipe_tx_char_is_k_i(pipe_tx7_char_is_k_i),
+ .pipe_tx_data_i(pipe_tx7_data_i),
+ .pipe_tx_elec_idle_i(pipe_tx7_elec_idle_i),
+ .pipe_tx_powerdown_i(pipe_tx7_powerdown_i),
+
+ .pipe_rx_char_is_k_i(pipe_rx7_char_is_k_i),
+ .pipe_rx_data_i(pipe_rx7_data_i),
+ .pipe_rx_valid_i(pipe_rx7_valid_i),
+ .pipe_rx_chanisaligned_i(pipe_rx7_chanisaligned_i),
+ .pipe_rx_status_i(pipe_rx7_status_i),
+ .pipe_rx_phy_status_i(pipe_rx7_phy_status_i),
+ .pipe_rx_elec_idle_i(pipe_rx7_elec_idle_i),
+ .pipe_rx_polarity_o(pipe_rx7_polarity_o),
+ .pipe_tx_compliance_o(pipe_tx7_compliance_o),
+ .pipe_tx_char_is_k_o(pipe_tx7_char_is_k_o),
+ .pipe_tx_data_o(pipe_tx7_data_o),
+ .pipe_tx_elec_idle_o(pipe_tx7_elec_idle_o),
+ .pipe_tx_powerdown_o(pipe_tx7_powerdown_o),
+
+ .pipe_clk(pipe_clk),
+ .rst_n(rst_n)
+
+ );
+
+ end // if (LINK_CAP_MAX_LINK_WIDTH >= 8)
+ else
+ begin
+ assign pipe_rx4_char_is_k_o = 2\'b00;
+ assign pipe_rx4_data_o = 16\'h0000;
+ assign pipe_rx4_valid_o = 1\'b0;
+ assign pipe_rx4_chanisaligned_o = 1\'b0;
+ assign pipe_rx4_status_o = 3\'b000;
+ assign pipe_rx4_phy_status_o = 1\'b0;
+ assign pipe_rx4_elec_idle_o = 1\'b1;
+ assign pipe_rx4_polarity_o = 1\'b0;
+ assign pipe_tx4_compliance_o = 1\'b0;
+ assign pipe_tx4_char_is_k_o = 2\'b00;
+ assign pipe_tx4_data_o = 16\'h0000;
+ assign pipe_tx4_elec_idle_o = 1\'b1;
+ assign pipe_tx4_powerdown_o = 2\'b00;
+
+ assign pipe_rx5_char_is_k_o = 2\'b00;
+ assign pipe_rx5_data_o = 16\'h0000;
+ assign pipe_rx5_valid_o = 1\'b0;
+ assign pipe_rx5_chanisaligned_o = 1\'b0;
+ assign pipe_rx5_status_o = 3\'b000;
+ assign pipe_rx5_phy_status_o = 1\'b0;
+ assign pipe_rx5_elec_idle_o = 1\'b1;
+ assign pipe_rx5_polarity_o = 1\'b0;
+ assign pipe_tx5_compliance_o = 1\'b0;
+ assign pipe_tx5_char_is_k_o = 2\'b00;
+ assign pipe_tx5_data_o = 16\'h0000;
+ assign pipe_tx5_elec_idle_o = 1\'b1;
+ assign pipe_tx5_powerdown_o = 2\'b00;
+
+ assign pipe_rx6_char_is_k_o = 2\'b00;
+ assign pipe_rx6_data_o = 16\'h0000;
+ assign pipe_rx6_valid_o = 1\'b0;
+ assign pipe_rx6_chanisaligned_o = 1\'b0;
+ assign pipe_rx6_status_o = 3\'b000;
+ assign pipe_rx6_phy_status_o = 1\'b0;
+ assign pipe_rx6_elec_idle_o = 1\'b1;
+ assign pipe_rx6_polarity_o = 1\'b0;
+ assign pipe_tx6_compliance_o = 1\'b0;
+ assign pipe_tx6_char_is_k_o = 2\'b00;
+ assign pipe_tx6_data_o = 16\'h0000;
+ assign pipe_tx6_elec_idle_o = 1\'b1;
+ assign pipe_tx6_powerdown_o = 2\'b00;
+
+ assign pipe_rx7_char_is_k_o = 2\'b00;
+ assign pipe_rx7_data_o = 16\'h0000;
+ assign pipe_rx7_valid_o = 1\'b0;
+ assign pipe_rx7_chanisaligned_o = 1\'b0;
+ assign pipe_rx7_status_o = 3\'b000;
+ assign pipe_rx7_phy_status_o = 1\'b0;
+ assign pipe_rx7_elec_idle_o = 1\'b1;
+ assign pipe_rx7_polarity_o = 1\'b0;
+ assign pipe_tx7_compliance_o = 1\'b0;
+ assign pipe_tx7_char_is_k_o = 2\'b00;
+ assign pipe_tx7_data_o = 16\'h0000;
+ assign pipe_tx7_elec_idle_o = 1\'b1;
+ assign pipe_tx7_powerdown_o = 2\'b00;
+ end // if !(LINK_CAP_MAX_LINK_WIDTH >= 8)
+
+ endgenerate
+
+endmodule
+
+"
+"//--------------------------------------------------------------------------------
+// Project : SWITCH
+// File : pcie_top.v
+// Version : 0.1
+// Author : Vipin.K
+//
+// Description: Instantiates the Xilinx PCIe endpoint and the PCIe interface logic
+//
+//--------------------------------------------------------------------------------
+
+module pcie_top # (
+ parameter PL_FAST_TRAIN = ""FALSE"",
+ parameter C_DATA_WIDTH = 64, // RX/TX interface data width
+ parameter KEEP_WIDTH = C_DATA_WIDTH / 8, // KEEP width
+ parameter NUM_PCIE_STRM = 4,
+ parameter RECONFIG_ENABLE = 1,
+ parameter RCM_ENABLE = 1
+)
+(
+ output [3:0] pci_exp_txp,
+ output [3:0] pci_exp_txn,
+ input [3:0] pci_exp_rxp,
+ input [3:0] pci_exp_rxn,
+ input sys_clk_p,
+ input sys_clk_n,
+ input sys_reset_n,
+ input i_ddr_clk,
+ output o_ddr_wr_req,
+ output [255:0] o_ddr_wr_data,
+ output [31:0] o_ddr_wr_be,
+ input i_ddr_wr_ack,
+ output [31:0] o_ddr_addr,
+ output ddr_rd_req_o,
+ input ddr_rd_ack_i,
+ input ddr_rd_valid_i,
+ input [255:0] ddr_rd_data_i,
+ output user_clk_o,
+ output pcie_clk_o,
+ output user_reset_o,
+ output [31:0] user_data_o,
+ output [19:0] user_addr_o,
+ output user_wr_req_o,
+ input [31:0] user_data_i,
+ input user_rd_ack_i,
+ output user_rd_req_o,
+ input user_intr_req_i,
+ output user_intr_ack_o,
+ //user stream interface
+ output user_str1_data_valid_o,
+ input user_str1_ack_i,
+ output [63:0] user_str1_data_o,
+ input user_str1_data_valid_i,
+ output user_str1_ack_o,
+ input [63:0] user_str1_data_i,
+ output user_str2_data_valid_o,
+ input user_str2_ack_i,
+ output [63:0] user_str2_data_o,
+ input user_str2_data_valid_i,
+ output user_str2_ack_o,
+ input [63:0] user_str2_data_i,
+ output user_str3_data_valid_o,
+ input user_str3_ack_i,
+ output [63:0] user_str3_data_o,
+ input user_str3_data_valid_i,
+ output user_str3_ack_o,
+ input [63:0] user_str3_data_i,
+ output user_str4_data_valid_o,
+ input user_str4_ack_i,
+ output [63:0] user_str4_data_o,
+ input user_str4_data_valid_i,
+ output user_str4_ack_o,
+ input [63:0] user_str4_data_i,
+ //To user ddr stream controllers
+ output [31:0] o_ddr_user1_str_addr,
+ output [31:0] o_ddr_user1_str_len,
+ output o_ddr_user1_str_en,
+ input i_ddr_user1_str_done,
+ output o_ddr_user1_str_done_ack,
+ output o_user1_ddr_str_en,
+ input i_user1_ddr_str_done,
+ output o_user1_ddr_str_done_ack,
+ output [31:0] o_user1_ddr_str_addr,
+ output [31:0] o_user1_ddr_str_len,
+ output [31:0] o_ddr_user2_str_addr,
+ output [31:0] o_ddr_user2_str_len,
+ output o_ddr_user2_str_en,
+ input i_ddr_user2_str_done,
+ output o_ddr_user2_str_done_ack,
+ output o_user2_ddr_str_en,
+ input i_user2_ddr_str_done,
+ output o_user2_ddr_str_done_ack,
+ output [31:0] o_user2_ddr_str_addr,
+ output [31:0] o_user2_ddr_str_len,
+ output [31:0] o_ddr_user3_str_addr,
+ output [31:0] o_ddr_user3_str_len,
+ output o_ddr_user3_str_en,
+ input i_ddr_user3_str_done,
+ output o_ddr_user3_str_done_ack,
+ output o_user3_ddr_str_en,
+ input i_user3_ddr_str_done,
+ output o_user3_ddr_str_done_ack,
+ output [31:0] o_user3_ddr_str_addr,
+ output [31:0] o_user3_ddr_str_len,
+ output [31:0] o_ddr_user4_str_addr,
+ output [31:0] o_ddr_user4_str_len,
+ output o_ddr_user4_str_en,
+ input i_ddr_user4_str_done,
+ output o_ddr_user4_str_done_ack,
+ output o_user4_ddr_str_en,
+ input i_user4_ddr_str_done,
+ output o_user4_ddr_str_done_ack,
+ output [31:0] o_user4_ddr_str_addr,
+ output [31:0] o_user4_ddr_str_len,
+ output pcie_link_status,
+ input clk_sysmon_i,
+ //Link status
+ input i_ddr_link_stat,
+ input i_enet_link_stat,
+ //ethernet
+ output o_enet_clk,
+ output o_enet_enable,
+ output o_enet_loopback,
+ output [31:0] o_enet_send_data_size,
+ output [31:0] o_enet_rcv_data_size,
+ output [31:0] o_enet_ddr_src_addr,
+ output [31:0] o_enet_ddr_dest_addr,
+ input [31:0] i_enet_rx_cnt,
+ input [31:0] i_enet_tx_cnt,
+ input i_enet_rx_done,
+ input i_enet_tx_done
+
+ );
+
+
+ // Tx
+ wire [5:0] tx_buf_av;
+ wire [3:0] s_axis_tx_tuser;
+ wire [C_DATA_WIDTH-1:0] s_axis_tx_tdata;
+ wire [KEEP_WIDTH-1:0] s_axis_tx_tkeep;
+ // Rx
+ wire [C_DATA_WIDTH-1:0] m_axis_rx_tdata;
+ wire [KEEP_WIDTH-1:0] m_axis_rx_tkeep;
+ wire [21:0] m_axis_rx_tuser;
+
+ // Flow Control
+ wire [11:0] fc_cpld;
+ wire [7:0] fc_cplh;
+ wire [11:0] fc_npd;
+ wire [7:0] fc_nph;
+ wire [11:0] fc_pd;
+ wire [7:0] fc_ph;
+ wire [2:0] fc_sel;
+
+
+ //-------------------------------------------------------
+ // 3. Configuration (CFG) Interface
+ //-------------------------------------------------------
+
+ wire [31:0] cfg_do;
+ wire [31:0] cfg_di;
+ wire [3:0] cfg_byte_en;
+ wire [9:0] cfg_dwaddr;
+ wire [47:0] cfg_err_tlp_cpl_header;
+ wire [7:0] cfg_interrupt_di;
+ wire [7:0] cfg_interrupt_do;
+ wire [2:0] cfg_interrupt_mmenable;
+ wire [7:0] cfg_bus_number;
+ wire [4:0] cfg_device_number;
+ wire [2:0] cfg_function_number;
+ wire [15:0] cfg_status;
+ wire [15:0] cfg_command;
+ wire [15:0] cfg_dstatus;
+ wire [15:0] cfg_dcommand;
+ wire [15:0] cfg_lstatus;
+ wire [15:0] cfg_lcommand;
+ wire [15:0] cfg_dcommand2;
+ wire [2:0] cfg_pcie_link_state;
+ wire [63:0] cfg_dsn;
+
+ //-------------------------------------------------------
+ // 4. Physical Layer Control and Status (PL) Interface
+ //-------------------------------------------------------
+
+ wire [2:0] pl_initial_link_width;
+ wire [1:0] pl_lane_reversal_mode;
+ wire [5:0] pl_ltssm_state;
+ wire [1:0] pl_sel_link_width;
+ wire [1:0] pl_directed_link_change;
+ wire [1:0] pl_directed_link_width;
+
+ //-------------------------------------------------------
+
+IBUFDS_GTXE1 refclk_ibuf (.O(sys_clk_c), .ODIV2(), .I(sys_clk_p), .IB(sys_clk_n), .CEB(1\'b0));
+
+assign pcie_link_status = user_lnk_up_int1;
+assign pcie_clk_o = user_clk;
+
+
+
+v6_pcie_v2_5 #(
+ .PL_FAST_TRAIN ( PL_FAST_TRAIN )
+) core (
+
+ //-------------------------------------------------------
+ // 1. PCI Express (pci_exp) Interface
+ //-------------------------------------------------------
+
+ // Tx
+ .pci_exp_txp( pci_exp_txp ),
+ .pci_exp_txn( pci_exp_txn ),
+
+ // Rx
+ .pci_exp_rxp( pci_exp_rxp ),
+ .pci_exp_rxn( pci_exp_rxn ),
+
+ //-------------------------------------------------------
+ // 2. AXI-S Interface
+ //-------------------------------------------------------
+
+ // Common
+ .user_clk_out( user_clk ),
+ .user_reset_out( user_reset_int1 ),
+ .user_lnk_up( user_lnk_up_int1 ),
+ .enet_clk( o_enet_clk ),
+
+ // Tx
+ .s_axis_tx_tready( s_axis_tx_tready ),
+ .s_axis_tx_tdata( s_axis_tx_tdata ),
+ .s_axis_tx_tkeep( s_axis_tx_tkeep ),
+ .s_axis_tx_tuser( s_axis_tx_tuser ),
+ .s_axis_tx_tlast( s_axis_tx_tlast ),
+ .s_axis_tx_tvalid( s_axis_tx_tvalid ),
+ .tx_cfg_gnt( tx_cfg_gnt ),
+ .tx_cfg_req( tx_cfg_req ),
+ .tx_buf_av( tx_buf_av ),
+ .tx_err_drop( tx_err_drop ),
+
+ // Rx
+ .m_axis_rx_tdata( m_axis_rx_tdata ),
+ .m_axis_rx_tkeep( m_axis_rx_tkeep ),
+ .m_axis_rx_tlast( m_axis_rx_tlast ),
+ .m_axis_rx_tvalid( m_axis_rx_tvalid ),
+ .m_axis_rx_tready( m_axis_rx_tready ),
+ .m_axis_rx_tuser ( m_axis_rx_tuser ),
+ .rx_np_ok( rx_np_ok ),
+
+ // Flow Control
+ .fc_cpld( fc_cpld ),
+ .fc_cplh( fc_cplh ),
+ .fc_npd( fc_npd ),
+ .fc_nph( fc_nph ),
+ .fc_pd( fc_pd ),
+ .fc_ph( fc_ph ),
+ .fc_sel( fc_sel ),
+
+
+ //-------------------------------------------------------
+ // 3. Configuration (CFG) Interface
+ //-------------------------------------------------------
+
+ .cfg_do( cfg_do ),
+ .cfg_rd_wr_done( cfg_rd_wr_done),
+ .cfg_di( cfg_di ),
+ .cfg_byte_en( cfg_byte_en ),
+ .cfg_dwaddr( cfg_dwaddr ),
+ .cfg_wr_en( cfg_wr_en ),
+ .cfg_rd_en( cfg_rd_en ),
+
+ .cfg_err_cor( cfg_err_cor ),
+ .cfg_err_ur( cfg_err_ur ),
+ .cfg_err_ecrc( cfg_err_ecrc ),
+ .cfg_err_cpl_timeout( cfg_err_cpl_timeout ),
+ .cfg_err_cpl_abort( cfg_err_cpl_abort ),
+ .cfg_err_cpl_unexpect( cfg_err_cpl_unexpect ),
+ .cfg_err_posted( cfg_err_posted ),
+ .cfg_err_locked( cfg_err_locked ),
+ .cfg_err_tlp_cpl_header( cfg_err_tlp_cpl_header ),
+ .cfg_err_cpl_rdy( cfg_err_cpl_rdy ),
+ .cfg_interrupt( cfg_interrupt ),
+ .cfg_interrupt_rdy( cfg_interrupt_rdy ),
+ .cfg_interrupt_assert( cfg_interrupt_assert ),
+ .cfg_interrupt_di( cfg_interrupt_di ),
+ .cfg_interrupt_do( cfg_interrupt_do ),
+ .cfg_interrupt_mmenable( cfg_interrupt_mmenable ),
+ .cfg_interrupt_msienable( cfg_interrupt_msienable ),
+ .cfg_interrupt_msixenable( cfg_interrupt_msixenable ),
+ .cfg_interrupt_msixfm( cfg_interrupt_msixfm ),
+ .cfg_turnoff_ok( cfg_turnoff_ok ),
+ .cfg_to_turnoff( cfg_to_turnoff ),
+ .cfg_trn_pending( cfg_trn_pending ),
+ .cfg_pm_wake( cfg_pm_wake ),
+ .cfg_bus_number( cfg_bus_number ),
+ .cfg_device_number( cfg_device_number ),
+ .cfg_function_number( cfg_function_number ),
+ .cfg_status( cfg_status ),
+ .cfg_command( cfg_command ),
+ .cfg_dstatus( cfg_dstatus ),
+ .cfg_dcommand( cfg_dcommand ),
+ .cfg_lstatus( cfg_lstatus ),
+ .cfg_lcommand( cfg_lcommand ),
+ .cfg_dcommand2( cfg_dcommand2 ),
+ .cfg_pcie_link_state( cfg_pcie_link_state ),
+ .cfg_dsn( cfg_dsn ),
+ .cfg_pmcsr_pme_en( ),
+ .cfg_pmcsr_pme_status( ),
+ .cfg_pmcsr_powerstate( ),
+
+ //-------------------------------------------------------
+ // 4. Physical Layer Control and Status (PL) Interface
+ //-------------------------------------------------------
+
+ .pl_initial_link_width( pl_initial_link_width ),
+ .pl_lane_reversal_mode( pl_lane_reversal_mode ),
+ .pl_link_gen2_capable( pl_link_gen2_capable ),
+ .pl_link_partner_gen2_supported( pl_link_partner_gen2_supported ),
+ .pl_link_upcfg_capable( pl_link_upcfg_capable ),
+ .pl_ltssm_state( pl_ltssm_state ),
+ .pl_received_hot_rst( pl_received_hot_rst ),
+ .pl_sel_link_rate( pl_sel_link_rate ),
+ .pl_sel_link_width( pl_sel_link_width ),
+ .pl_directed_link_auton( pl_directed_link_auton ),
+ .pl_directed_link_change( pl_directed_link_change ),
+ .pl_directed_link_speed( pl_directed_link_speed ),
+ .pl_directed_link_width( pl_directed_link_width ),
+ .pl_upstream_prefer_deemph( pl_upstream_prefer_deemph ),
+
+ //-------------------------------------------------------
+ // 5. System (SYS) Interface
+ //-------------------------------------------------------
+
+ .sys_clk( sys_clk_c ),
+ .sys_reset( !sys_reset_n )
+);
+
+
+pcie_app #(
+ .C_DATA_WIDTH( C_DATA_WIDTH ),
+ .KEEP_WIDTH( KEEP_WIDTH ),
+ .NUM_PCIE_STRM(NUM_PCIE_STRM),
+ .RECONFIG_ENABLE(RECONFIG_ENABLE),
+ .RCM_ENABLE(RCM_ENABLE)
+ )app (
+
+ //-------------------------------------------------------
+ // 1. AXI-S Interface
+ //-------------------------------------------------------
+
+ // Common
+ .pcie_core_clk( user_clk ),
+ .user_reset( user_reset_int1 ),
+ .user_lnk_up( user_lnk_up_int1 ),
+
+ // Tx
+
+ .s_axis_tx_tready( s_axis_tx_tready ),
+ .s_axis_tx_tdata( s_axis_tx_tdata ),
+ .s_axis_tx_tkeep( s_axis_tx_tkeep ),
+ .s_axis_tx_tuser( s_axis_tx_tuser ),
+ .s_axis_tx_tlast( s_axis_tx_tlast ),
+ .s_axis_tx_tvalid( s_axis_tx_tvalid ),
+ .tx_cfg_gnt( tx_cfg_gnt ),
+
+ // Rx
+ .m_axis_rx_tdata( m_axis_rx_tdata ),
+ .m_axis_rx_tlast( m_axis_rx_tlast ),
+ .m_axis_rx_tvalid( m_axis_rx_tvalid ),
+ .m_axis_rx_tready( m_axis_rx_tready ),
+ .rx_np_ok( rx_np_ok ),
+ .fc_sel( fc_sel ),
+ //-------------------------------------------------------
+ // 2. Configuration (CFG) Interface
+ //-------------------------------------------------------
+ .cfg_di( cfg_di ),
+ .cfg_byte_en( cfg_byte_en ),
+ .cfg_dwaddr( cfg_dwaddr ),
+ .cfg_wr_en( cfg_wr_en ),
+ .cfg_rd_en( cfg_rd_en ),
+ .cfg_err_cor( cfg_err_cor ),
+ .cfg_err_ur( cfg_err_ur ),
+ .cfg_err_ecrc( cfg_err_ecrc ),
+ .cfg_err_cpl_timeout( cfg_err_cpl_timeout ),
+ .cfg_err_cpl_abort( cfg_err_cpl_abort ),
+ .cfg_err_cpl_unexpect( cfg_err_cpl_unexpect ),
+ .cfg_err_posted( cfg_err_posted ),
+ .cfg_err_locked( cfg_err_locked ),
+ .cfg_err_tlp_cpl_header( cfg_err_tlp_cpl_header ),
+ .cfg_interrupt( cfg_interrupt ),
+ .cfg_interrupt_rdy( cfg_interrupt_rdy ),
+ .cfg_interrupt_assert( cfg_interrupt_assert ),
+ .cfg_interrupt_di( cfg_interrupt_di ),
+ .cfg_turnoff_ok( cfg_turnoff_ok ),
+ .cfg_trn_pending( cfg_trn_pending ),
+ .cfg_pm_wake( cfg_pm_wake ),
+ .cfg_bus_number( cfg_bus_number ),
+ .cfg_device_number( cfg_device_number ),
+ .cfg_function_number( cfg_function_number ),
+ .cfg_dsn( cfg_dsn ),
+
+ //-------------------------------------------------------
+ // 3. Physical Layer Control and Status (PL) Interface
+ //-------------------------------------------------------
+ .pl_directed_link_auton( pl_directed_link_auton ),
+ .pl_directed_link_change( pl_directed_link_change ),
+ .pl_directed_link_speed( pl_directed_link_speed ),
+ .pl_directed_link_width( pl_directed_link_width ),
+ .pl_upstream_prefer_deemph( pl_upstream_prefer_deemph ),
+ .i_ddr_clk(i_ddr_clk),
+ .o_ddr_wr_req(o_ddr_wr_req),
+ .o_ddr_wr_data(o_ddr_wr_data),
+ .o_ddr_wr_be(o_ddr_wr_be),
+ .i_ddr_wr_ack(i_ddr_wr_ack),
+ .o_ddr_addr(o_ddr_addr),
+ .ddr_rd_req_o(ddr_rd_req_o),
+ .ddr_rd_ack_i(ddr_rd_ack_i),
+ .ddr_rd_valid_i(ddr_rd_valid_i),
+ .ddr_rd_data_i(ddr_rd_data_i),
+ .user_clk_o(user_clk_o),
+ .user_reset_o(user_reset_o),
+ .user_data_o(user_data_o),
+ .user_addr_o(user_addr_o),
+ .user_wr_req_o(user_wr_req_o),
+ .user_data_i(user_data_i),
+ .user_rd_ack_i(user_rd_ack_i),
+ .user_rd_req_o(user_rd_req_o),
+ .user_intr_req_i(user_intr_req_i),
+ .user_intr_ack_o(user_intr_ack_o),
+ .user_str1_data_valid_o(user_str1_data_valid_o),
+ .user_str1_ack_i(user_str1_ack_i),
+ .user_str1_data_o(user_str1_data_o),
+ .user_str1_data_valid_i(user_str1_data_valid_i),
+ .user_str1_ack_o(user_str1_ack_o),
+ .user_str1_data_i(user_str1_data_i),
+ .user_str2_data_valid_o(user_str2_data_valid_o),
+ .user_str2_ack_i(user_str2_ack_i),
+ .user_str2_data_o(user_str2_data_o),
+ .user_str2_data_valid_i(user_str2_data_valid_i),
+ .user_str2_ack_o(user_str2_ack_o),
+ .user_str2_data_i(user_str2_data_i),
+ .user_str3_data_valid_o(user_str3_data_valid_o),
+ .user_str3_ack_i(user_str3_ack_i),
+ .user_str3_data_o(user_str3_data_o),
+ .user_str3_data_valid_i(user_str3_data_valid_i),
+ .user_str3_ack_o(user_str3_ack_o),
+ .user_str3_data_i(user_str3_data_i),
+ .user_str4_data_valid_o(user_str4_data_valid_o),
+ .user_str4_ack_i(user_str4_ack_i),
+ .user_str4_data_o(user_str4_data_o),
+ .user_str4_data_valid_i(user_str4_data_valid_i),
+ .user_str4_ack_o(user_str4_ack_o),
+ .user_str4_data_i(user_str4_data_i),
+ .o_ddr_user1_str_en(o_ddr_user1_str_en),
+ .i_ddr_user1_str_done(i_ddr_user1_str_done),
+ .o_ddr_user1_str_done_ack(o_ddr_user1_str_done_ack),
+ .o_ddr_user1_str_addr(o_ddr_user1_str_addr),
+ .o_ddr_user1_str_len(o_ddr_user1_str_len),
+ .o_user1_ddr_str_en(o_user1_ddr_str_en),
+ .i_user1_ddr_str_done(i_user1_ddr_str_done),
+ .o_user1_ddr_str_done_ack(o_user1_ddr_str_done_ack),
+ .o_user1_ddr_str_addr(o_user1_ddr_str_addr),
+ .o_user1_ddr_str_len(o_user1_ddr_str_len), \t
+ .o_ddr_user2_str_addr(o_ddr_user2_str_addr),
+ .o_ddr_user2_str_len(o_ddr_user2_str_len),
+ .o_ddr_user2_str_en(o_ddr_user2_str_en),
+ .i_ddr_user2_str_done(i_ddr_user2_str_done),
+ .o_ddr_user2_str_done_ack(o_ddr_user2_str_done_ack),
+ .o_user2_ddr_str_en(o_user2_ddr_str_en),
+ .i_user2_ddr_str_done(i_user2_ddr_str_done),
+ .o_user2_ddr_str_done_ack(o_user2_ddr_str_done_ack),
+ .o_user2_ddr_str_addr(o_user2_ddr_str_addr),
+ .o_user2_ddr_str_len(o_user2_ddr_str_len),
+ .o_ddr_user3_str_addr(o_ddr_user3_str_addr),
+ .o_ddr_user3_str_len(o_ddr_user3_str_len),
+ .o_ddr_user3_str_en(o_ddr_user3_str_en),
+ .i_ddr_user3_str_done(i_ddr_user3_str_done),
+ .o_ddr_user3_str_done_ack(o_ddr_user3_str_done_ack),
+ .o_user3_ddr_str_en(o_user3_ddr_str_en),
+ .i_user3_ddr_str_done(i_user3_ddr_str_done),
+ .o_user3_ddr_str_done_ack(o_user3_ddr_str_done_ack),
+ .o_user3_ddr_str_addr(o_user3_ddr_str_addr),
+ .o_user3_ddr_str_len(o_user3_ddr_str_len),
+ .o_ddr_user4_str_addr(o_ddr_user4_str_addr),
+ .o_ddr_user4_str_len(o_ddr_user4_str_len),
+ .o_ddr_user4_str_en(o_ddr_user4_str_en),
+ .i_ddr_user4_str_done(i_ddr_user4_str_done),
+ .o_ddr_user4_str_done_ack(o_ddr_user4_str_done_ack),
+ .o_user4_ddr_str_en(o_user4_ddr_str_en),
+ .i_user4_ddr_str_done(i_user4_ddr_str_done),
+ .o_user4_ddr_str_done_ack(o_user4_ddr_str_done_ack),
+ .o_user4_ddr_str_addr(o_user4_ddr_str_addr),
+ .o_user4_ddr_str_len(o_user4_ddr_str_len),
+ .clk_sysmon_i(clk_sysmon_i),
+ .i_ddr_link_stat(i_ddr_link_stat),
+ .i_enet_link_stat(i_enet_link_stat),
+ .o_enet_enable(o_enet_enable),
+ .o_enet_loopback(o_enet_loopback),
+ .o_enet_send_data_size(o_enet_send_data_size),
+ .o_enet_rcv_data_size(o_enet_rcv_data_size),
+ .o_enet_ddr_src_addr(o_enet_ddr_src_addr),
+ .o_enet_ddr_dest_addr(o_enet_ddr_dest_addr),
+ .i_enet_rx_cnt(i_enet_rx_cnt),
+ .i_enet_tx_cnt(i_enet_tx_cnt),
+ .i_enet_rx_done(i_enet_rx_done),
+ .i_enet_tx_done(i_enet_tx_done)
+\t
+);
+
+endmodule
+"
+"//--------------------------------------------------------------------------------
+// Project : SWITCH
+// File : v6_emac_v2_2_fifo.v
+// Version : 0.2
+// Author : Shreejith S
+//
+// Description: Ethernet V6 EMAC TOP BLOCK - XILINX
+//
+//--------------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//
+// (c) Copyright 2004-2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+// Description: This is the block level Verilog design for the Virtex-6
+// Embedded Tri-Mode Ethernet MAC Example Design.
+//
+// This block level:
+//
+// * instantiates appropriate PHY interface module (GMII/MII/RGMII)
+// as required based on the user configuration;
+//
+// Please refer to the Datasheet, Getting Started Guide, and
+// the Virtex-6 Embedded Tri-Mode Ethernet MAC User Gude for further information.
+//
+//
+// -----------------------------------------|
+// | BLOCK LEVEL WRAPPER |
+// | |
+// | --------------------- |
+// | | V6 EMAC | |
+// | | CORE | --------- |
+// | | | | | |
+// --|--->| Tx Tx |--| |--->|
+// | | AXI PHY | | | |
+// | | I/F I/F | | | |
+// | | | | PHY | |
+// | | | | I/F | |
+// | | | | | |
+// | | Rx Rx | | | |
+// | | AXI PHY | | | |
+// <-|----| I/F I/F |<-| |<---|
+// | | | --------- |
+// | | | |
+// | --------------------- |
+// | |
+// -----------------------------------------|
+//
+
+`timescale 1 ps/1 ps
+
+
+//------------------------------------------------------------------------------
+// The entity declaration for the block level example design.
+//------------------------------------------------------------------------------
+
+module v6_emac_v2_2_block (
+ input gtx_clk,
+
+ // Receiver Interface
+ //--------------------------
+ output [27:0] rx_statistics_vector,
+ output rx_statistics_valid,
+
+ output rx_mac_aclk,
+ output rx_reset,
+ output [7:0] rx_axis_mac_tdata,
+ output rx_axis_mac_tvalid,
+ output rx_axis_mac_tlast,
+ output rx_axis_mac_tuser,
+
+ // Transmitter Interface
+ //-----------------------------
+ input [7:0] tx_ifg_delay,
+ output [31:0] tx_statistics_vector,
+ output tx_statistics_valid,
+
+ output tx_mac_aclk,
+ output tx_reset,
+ input [7:0] tx_axis_mac_tdata,
+ input tx_axis_mac_tvalid,
+ input tx_axis_mac_tlast,
+ input tx_axis_mac_tuser,
+ output tx_axis_mac_tready,
+ output tx_collision,
+ output tx_retransmit,
+
+ // MAC Control Interface
+ //----------------------
+ input pause_req,
+ input [15:0] pause_val,
+
+ // Reference clock for IDELAYCTRL\'s
+ input refclk,
+\t\t
+\t\tinput loopback_enable,
+
+ // GMII Interface
+ //---------------
+ output [7:0] gmii_txd,
+ output gmii_tx_en,
+ output gmii_tx_er,
+ output gmii_tx_clk,
+ input [7:0] gmii_rxd,
+ input gmii_rx_dv,
+ input gmii_rx_er,
+ input gmii_rx_clk,
+ input gmii_col,
+ input gmii_crs,
+ input mii_tx_clk,
+
+ output mdio_out,
+\t\tinput mdio_in,
+\t\toutput mdc_out,
+\t\toutput mdio_t,
+
+ // asynchronous reset
+ //---------------
+ input glbl_rstn,
+ input rx_axi_rstn,
+ input tx_axi_rstn
+
+ );
+
+
+ //---------------------------------------------------------------------------
+ // internal signals used in this block level wrapper.
+ //---------------------------------------------------------------------------
+ wire idelayctrl_reset_sync; // Used to create a reset pulse in the IDELAYCTRL refclk domain.
+ reg [3:0] idelay_reset_cnt; // Counter to create a long IDELAYCTRL reset pulse.
+ reg idelayctrl_reset; // The reset pulse for the IDELAYCTRL.
+
+ wire gmii_tx_en_int; // Internal gmii_tx_en signal.
+ wire gmii_tx_er_int; // Internal gmii_tx_er signal.
+ wire [7:0] gmii_txd_int; // Internal gmii_txd signal.
+ wire gmii_rx_dv_int; // gmii_rx_dv registered in IOBs.
+ wire gmii_rx_er_int; // gmii_rx_er registered in IOBs.
+ wire [7:0] gmii_rxd_int; // gmii_rxd registered in IOBs.
+ wire gmii_col_int; // Collision signal from the PHY module
+ wire gmii_crs_int; // Carrier Sense signal from the PHY module
+
+
+
+ wire speedis10100_int; // Asserted when speed is 10Mb/s or 100Mb/s.
+
+ (* KEEP = ""TRUE"" *)
+ wire rx_mac_aclk_int; // Internal receive gmii/mii clock signal.
+
+ (* KEEP = ""TRUE"" *)
+ wire tx_mac_aclk_int; // Internal transmit gmii/mii clock signal.
+
+ wire gtx_resetn;
+ wire tx_reset_int; // Synchronous reset in the MAC and gmii Tx domain
+ wire rx_reset_int; // Synchronous reset in the MAC and gmii Rx domain
+
+ wire [27:0] rx_statistics_vector_int;
+ wire rx_statistics_valid_int;
+ wire [31:0] tx_statistics_vector_int;
+ wire tx_statistics_valid_int;
+
+ // AXI-Lite interface
+ (* KEEP = ""TRUE"" *)
+ wire [31:0] s_axi_awaddr;
+ (* KEEP = ""TRUE"" *)
+ wire s_axi_awvalid;
+ (* KEEP = ""TRUE"" *)
+ wire s_axi_awready;
+ (* KEEP = ""TRUE"" *)
+ wire [31:0] s_axi_wdata;
+ (* KEEP = ""TRUE"" *)
+ wire s_axi_wvalid;
+ (* KEEP = ""TRUE"" *)
+ wire s_axi_wready;
+ (* KEEP = ""TRUE"" *)
+ wire [1:0] s_axi_bresp;
+ (* KEEP = ""TRUE"" *)
+ wire s_axi_bvalid;
+ (* KEEP = ""TRUE"" *)
+ wire s_axi_bready;
+ (* KEEP = ""TRUE"" *)
+ wire [31:0] s_axi_araddr;
+ (* KEEP = ""TRUE"" *)
+ wire s_axi_arvalid;
+ (* KEEP = ""TRUE"" *)
+ wire s_axi_arready;
+ (* KEEP = ""TRUE"" *)
+ wire [31:0] s_axi_rdata;
+ (* KEEP = ""TRUE"" *)
+ wire [1:0] s_axi_rresp;
+ (* KEEP = ""TRUE"" *)
+ wire s_axi_rvalid;
+ (* KEEP = ""TRUE"" *)
+ wire s_axi_rready;
+
+ wire bus2ip_clk;
+ wire bus2ip_reset;
+
+ wire [31:0] bus2ip_addr;
+ wire bus2ip_cs;
+ wire bus2ip_rdce;
+ wire bus2ip_wrce;
+ wire [31:0] bus2ip_data;
+ wire [31:0] ip2bus_data;
+ wire ip2bus_wrack;
+ wire ip2bus_rdack;
+ wire ip2bus_error;
+
+
+
+ reg reinit_phy,loopback_sts;
+
+ assign gtx_resetn = glbl_rstn;
+ assign s_axi_resetn = glbl_rstn;
+ // assign outputs
+ assign rx_reset = rx_reset_int;
+ assign tx_reset = tx_reset_int;
+ // Assign the internal clock signals to output ports.
+ assign tx_mac_aclk = tx_mac_aclk_int;
+ assign rx_mac_aclk = rx_mac_aclk_int;
+\tassign s_axi_aclk = gtx_clk;
+\talways @ (posedge s_axi_aclk)
+\tbegin
+\t\tif(~glbl_rstn) begin
+\t\t\treinit_phy <= 1\'b0;
+\t\t\tloopback_sts <= 1\'b0;
+\t\tend
+\t\telse begin
+\t\t\treinit_phy <= 1\'b0;
+\t\t\tif (loopback_sts != loopback_enable)
+\t\t\t\treinit_phy <= 1\'b1;
+\t\t\tloopback_sts <= loopback_enable;
+\t\tend
+ end
+ //---------------------------------------------------------------------------
+ // An IDELAYCTRL primitive needs to be instantiated for the Fixed Tap Delay
+ // mode of the IDELAY.
+ // All IDELAYs in Fixed Tap Delay mode and the IDELAYCTRL primitives have
+ // to be LOC\'ed in the UCF file.
+ //---------------------------------------------------------------------------
+ IDELAYCTRL dlyctrl (
+ .RDY (),
+ .REFCLK (refclk),
+ .RST (idelayctrl_reset)
+ );
+
+
+ // Create a synchronous reset in the IDELAYCTRL refclk clock domain.
+ reset_sync idelayctrl_reset_gen (
+ .clk (refclk),
+ .enable (1\'b1),
+ .reset_in (!glbl_rstn),
+ .reset_out (idelayctrl_reset_sync)
+ );
+
+
+ // Reset circuitry for the IDELAYCTRL reset.
+
+ // The IDELAYCTRL must experience a pulse which is at least 50 ns in
+ // duration. This is ten clock cycles of the 200MHz refclk. Here we
+ // drive the reset pulse for 12 clock cycles.
+ always @(posedge refclk)
+ begin
+ if (idelayctrl_reset_sync) begin
+ idelay_reset_cnt <= 4\'b0000;
+ idelayctrl_reset <= 1\'b1;
+ end
+ else begin
+ case (idelay_reset_cnt)
+ 4\'b0000 : idelay_reset_cnt <= 4\'b0001;
+ 4\'b0001 : idelay_reset_cnt <= 4\'b0010;
+ 4\'b0010 : idelay_reset_cnt <= 4\'b0011;
+ 4\'b0011 : idelay_reset_cnt <= 4\'b0100;
+ 4\'b0100 : idelay_reset_cnt <= 4\'b0101;
+ 4\'b0101 : idelay_reset_cnt <= 4\'b0110;
+ 4\'b0110 : idelay_reset_cnt <= 4\'b0111;
+ 4\'b0111 : idelay_reset_cnt <= 4\'b1000;
+ 4\'b1000 : idelay_reset_cnt <= 4\'b1001;
+ 4\'b1001 : idelay_reset_cnt <= 4\'b1010;
+ 4\'b1010 : idelay_reset_cnt <= 4\'b1011;
+ 4\'b1011 : idelay_reset_cnt <= 4\'b1100;
+ default : idelay_reset_cnt <= 4\'b1100;
+ endcase
+ if (idelay_reset_cnt === 4\'b1100) begin
+ idelayctrl_reset <= 1\'b0;
+ end
+ else begin
+ idelayctrl_reset <= 1\'b1;
+ end
+ end
+ end
+
+
+ //----------------------------------------------------------------------------
+ // Generate TX_MAC_ACLK_INT.
+ // At 1000Mb/s we select GTX_CLK (CLK) to provide this. At 10/100 we use
+ // the MII interface clock (MII_TX_CLK) sourced by the PHY.
+ //----------------------------------------------------------------------------
+
+ /*BUFGMUX BUFGMUX_SPEED_CLK (
+ .O (tx_mac_aclk_int),
+ .I0 (gtx_clk),
+ .I1 (mii_tx_clk),
+ .S (speedis10100_int)
+ );*/
+\t
+\tassign tx_mac_aclk_int = gtx_clk;
+\t
+
+ //---------------------------------------------------------------------------
+ // Instantiate GMII Interface
+ //---------------------------------------------------------------------------
+
+ // Instantiate the GMII physical interface logic
+ gmii_if gmii_interface(
+ // Synchronous resets
+ .tx_reset (tx_reset_int),
+ .rx_reset (rx_reset_int),
+
+ // Current operating speed is 10/100
+ .speed_is_10_100 (speedis10100_int),
+
+ // The following ports are the GMII physical interface: these will be at
+ // pins on the FPGA
+ .gmii_txd (gmii_txd),
+ .gmii_tx_en (gmii_tx_en),
+ .gmii_tx_er (gmii_tx_er),
+ .gmii_tx_clk (gmii_tx_clk),
+ .gmii_col (gmii_col),
+ .gmii_crs (gmii_crs),
+ .gmii_rxd (gmii_rxd),
+ .gmii_rx_dv (gmii_rx_dv),
+ .gmii_rx_er (gmii_rx_er),
+ .gmii_rx_clk (gmii_rx_clk),
+
+ // The following ports are the internal GMII connections from IOB logic
+ // to the TEMAC core
+ .txd_from_mac (gmii_txd_int),
+ .tx_en_from_mac (gmii_tx_en_int),
+ .tx_er_from_mac (gmii_tx_er_int),
+ .tx_clk (tx_mac_aclk_int),
+ .col_to_mac (gmii_col_int),
+ .crs_to_mac (gmii_crs_int),
+ .rxd_to_mac (gmii_rxd_int),
+ .rx_dv_to_mac (gmii_rx_dv_int),
+ .rx_er_to_mac (gmii_rx_er_int),
+
+ // Receiver clock for the MAC and Client Logic
+ .rx_clk (rx_mac_aclk_int)
+ );
+
+
+
+ assign rx_statistics_vector = rx_statistics_vector_int;
+ assign rx_statistics_valid = rx_statistics_valid_int;
+ assign tx_statistics_vector = tx_statistics_vector_int;
+ assign tx_statistics_valid = tx_statistics_valid_int;
+
+ //---------------------------------------------------------------------------
+ // Instantiate the Hard MAC core
+ //---------------------------------------------------------------------------
+ v6_emac_v2_3 v6emac_core(
+
+ //-------------------------------------------------------------------------
+ // Clock signals - used in rgmii and serial modes
+ //-------------------------------------------------------------------------
+ .gtx_clk (gtx_clk),
+
+ //-------------------------------------------------------------------------
+ // Receiver Interface.
+ //-------------------------------------------------------------------------
+ .rx_axi_clk (rx_mac_aclk_int),
+ .rx_reset_out (rx_reset_int),
+ .rx_axis_mac_tdata (rx_axis_mac_tdata),
+ .rx_axis_mac_tvalid (rx_axis_mac_tvalid),
+ .rx_axis_mac_tlast (rx_axis_mac_tlast),
+ .rx_axis_mac_tuser (rx_axis_mac_tuser),
+
+ // RX sideband signals
+ .rx_statistics_vector (rx_statistics_vector_int),
+ .rx_statistics_valid (rx_statistics_valid_int),
+
+ //-------------------------------------------------------------------------
+ // Transmitter Interface
+ //-------------------------------------------------------------------------
+ .tx_axi_clk (tx_mac_aclk_int),
+ .tx_reset_out (tx_reset_int),
+ .tx_axis_mac_tdata (tx_axis_mac_tdata),
+ .tx_axis_mac_tvalid (tx_axis_mac_tvalid),
+ .tx_axis_mac_tlast (tx_axis_mac_tlast),
+ .tx_axis_mac_tuser (tx_axis_mac_tuser),
+ .tx_axis_mac_tready (tx_axis_mac_tready),
+
+ // TX sideband signals
+ .tx_retransmit (tx_retransmit),
+ .tx_collision (tx_collision),
+ .tx_ifg_delay (tx_ifg_delay),
+ .tx_statistics_vector (tx_statistics_vector_int),
+ .tx_statistics_valid (tx_statistics_valid_int),
+
+ //-------------------------------------------------------------------------
+ // Flow Control
+ //-------------------------------------------------------------------------
+ .pause_req (pause_req),
+ .pause_val (pause_val),
+
+ //-------------------------------------------------------------------------
+ // Speed interface
+ //-------------------------------------------------------------------------
+ .speed_is_10_100 (speedis10100_int),
+
+ //-------------------------------------------------------------------------
+ // GMII/MII Interface
+ //-------------------------------------------------------------------------
+ .gmii_txd (gmii_txd_int),
+ .gmii_tx_en (gmii_tx_en_int),
+ .gmii_tx_er (gmii_tx_er_int),
+// .gmii_crs (gmii_crs_int),
+// .gmii_col (gmii_col_int),
+ .gmii_rxd (gmii_rxd_int),
+ .gmii_rx_dv (gmii_rx_dv_int),
+ .gmii_rx_er (gmii_rx_er_int),
+
+ \t.mdc_out(mdc_out), // output mdc_out
+\t\t.mdio_in(mdio_in), // input mdio_in
+\t\t.mdio_out(mdio_out), // output mdio_out
+\t\t.mdio_tri(mdio_t), // output mdio_tri
+\t\t.bus2ip_clk(bus2ip_clk), // input bus2ip_clk
+\t\t.bus2ip_reset(bus2ip_reset), // input bus2ip_reset
+\t\t.bus2ip_addr(bus2ip_addr), // input [31 : 0] bus2ip_addr
+\t\t.bus2ip_cs(bus2ip_cs), // input bus2ip_cs
+\t\t.bus2ip_rdce(bus2ip_rdce), // input bus2ip_rdce
+\t\t.bus2ip_wrce(bus2ip_wrce), // input bus2ip_wrce
+\t\t.bus2ip_data(bus2ip_data), // input [31 : 0] bus2ip_data
+\t\t.ip2bus_data(ip2bus_data), // output [31 : 0] ip2bus_data
+\t\t.ip2bus_wrack(ip2bus_wrack), // output ip2bus_wrack
+\t\t.ip2bus_rdack(ip2bus_rdack), // output ip2bus_rdack
+\t\t.ip2bus_error(ip2bus_error), // output ip2bus_error
+
+
+
+ //-------------------------------------------------------------------------
+ // Resets
+ //-------------------------------------------------------------------------
+
+ .glbl_rstn (gtx_resetn),
+ .rx_axi_rstn (rx_axi_rstn),
+ .tx_axi_rstn (tx_axi_rstn)
+
+ );
+
+ //----------------------------------------------------------------------------
+ // Instantiate the AXI-LITE Controller
+
+ axi_lite_sm #(
+ .MAC_BASE_ADDR (32\'h0)
+ ) axi_lite_controller (
+ .s_axi_aclk (s_axi_aclk),
+ .s_axi_resetn (s_axi_resetn),
+
+\t\t.phy_loopback (loopback_sts),
+\t\t.if_enable (reinit_phy),
+ .s_axi_awaddr (s_axi_awaddr),
+ .s_axi_awvalid (s_axi_awvalid),
+ .s_axi_awready (s_axi_awready),
+
+ .s_axi_wdata (s_axi_wdata),
+ .s_axi_wvalid (s_axi_wvalid),
+ .s_axi_wready (s_axi_wready),
+
+ .s_axi_bresp (s_axi_bresp),
+ .s_axi_bvalid (s_axi_bvalid),
+ .s_axi_bready (s_axi_bready),
+
+ .s_axi_araddr (s_axi_araddr),
+ .s_axi_arvalid (s_axi_arvalid),
+ .s_axi_arready (s_axi_arready),
+
+ .s_axi_rdata (s_axi_rdata),
+ .s_axi_rresp (s_axi_rresp),
+ .s_axi_rvalid (s_axi_rvalid),
+ .s_axi_rready (s_axi_rready)
+ );
+
+
+ // instantiate the axi_ipif block
+ axi4_lite_ipif_wrapper #(
+ .C_BASE_ADDRESS (32\'d0)
+ ) axi_lite_ipif (
+ // System signals
+ .s_axi_aclk (s_axi_aclk),
+ .s_axi_aresetn (s_axi_resetn),
+ .s_axi_awaddr (s_axi_awaddr),
+ .s_axi_awvalid (s_axi_awvalid),
+ .s_axi_awready (s_axi_awready),
+ .s_axi_wdata (s_axi_wdata),
+ .s_axi_wvalid (s_axi_wvalid),
+ .s_axi_wready (s_axi_wready),
+ .s_axi_bresp (s_axi_bresp),
+ .s_axi_bvalid (s_axi_bvalid),
+ .s_axi_bready (s_axi_bready),
+ .s_axi_araddr (s_axi_araddr),
+ .s_axi_arvalid (s_axi_arvalid),
+ .s_axi_arready (s_axi_arready),
+ .s_axi_rdata (s_axi_rdata),
+ .s_axi_rresp (s_axi_rresp),
+ .s_axi_rvalid (s_axi_rvalid),
+ .s_axi_rready (s_axi_rready),
+ // controls to the ipif
+ .bus2ip_clk (bus2ip_clk),
+ .bus2ip_reset (bus2ip_reset),
+ .bus2ip_addr (bus2ip_addr),
+ .bus2ip_cs (bus2ip_cs),
+ .bus2ip_rdce (bus2ip_rdce),
+ .bus2ip_wrce (bus2ip_wrce),
+ .bus2ip_data (bus2ip_data),
+ .ip2bus_data (ip2bus_data),
+ .ip2bus_wrack (ip2bus_wrack),
+ .ip2bus_rdack (ip2bus_rdack),
+ .ip2bus_error (ip2bus_error)
+ );
+
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2008 - 2012 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : %version
+// \\ \\ Application : MIG
+// / / Filename : ddr_of_pre_fifo.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Feb 08 2011
+// \\___\\/\\___\\
+//
+//Device : 7 Series
+//Design Name : DDR3 SDRAM
+//Purpose : Extends the depth of a PHASER OUT_FIFO up to 4 entries
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+/******************************************************************************
+**$Id: ddr_of_pre_fifo.v,v 1.1 2011/06/02 08:35:07 mishra Exp $
+**$Date: 2011/06/02 08:35:07 $
+**$Author: mishra $
+**$Revision: 1.1 $
+**$Source: /devl/xcs/repo/env/Databases/ip/src2/O/mig_7series_v1_3/data/dlib/7series/ddr3_sdram/verilog/rtl/phy/ddr_of_pre_fifo.v,v $
+******************************************************************************/
+
+`timescale 1 ps / 1 ps
+
+module mig_7series_v1_8_ddr_of_pre_fifo #
+ (
+ parameter TCQ = 100, // clk->out delay (sim only)
+ parameter DEPTH = 4, // # of entries
+ parameter WIDTH = 32 // data bus width
+ )
+ (
+ input clk, // clock
+ input rst, // synchronous reset
+ input full_in, // FULL flag from OUT_FIFO
+ input wr_en_in, // write enable from controller
+ input [WIDTH-1:0] d_in, // write data from controller
+ output wr_en_out, // write enable to OUT_FIFO
+ output [WIDTH-1:0] d_out, // write data to OUT_FIFO
+ output afull // almost full signal to controller
+ );
+
+ // # of bits used to represent read/write pointers
+ localparam PTR_BITS
+ = (DEPTH == 2) ? 1 :
+ ((DEPTH == 3) || (DEPTH == 4)) ? 2 :
+ (((DEPTH == 5) || (DEPTH == 6) ||
+ (DEPTH == 7) || (DEPTH == 8)) ? 3 :
+ DEPTH == 9 ? 4 : \'bx);
+
+ // Set watermark. Always give the MC 5 cycles to engage flow control.
+ localparam ALMOST_FULL_VALUE = DEPTH - 5;
+
+ integer i;
+
+ reg [WIDTH-1:0] mem[0:DEPTH-1] /* synthesis syn_ramstyle = ""registers"" */;
+(* keep = ""true"", max_fanout = 3 *) reg [2:0] my_empty;
+(* keep = ""true"", max_fanout = 3 *) reg [2:0] my_full;
+(* keep = ""true"", max_fanout = 10 *) reg [PTR_BITS-1:0] rd_ptr;
+ // synthesis attribute MAX_FANOUT of rd_ptr is 10;
+(* keep = ""true"", max_fanout = 10 *) reg [PTR_BITS-1:0] wr_ptr;
+ // synthesis attribute MAX_FANOUT of wr_ptr is 10;
+ reg [PTR_BITS:0] entry_cnt;
+ wire [PTR_BITS-1:0] nxt_rd_ptr;
+ wire [PTR_BITS-1:0] nxt_wr_ptr;
+ wire [WIDTH-1:0] mem_out;
+ wire wr_en;
+
+ assign d_out = my_empty[0] ? d_in : mem_out;
+ assign wr_en_out = !full_in && (!my_empty[1] || wr_en_in);
+ assign wr_en = wr_en_in & ((!my_empty[2] & !full_in)|(!my_full[2] & full_in));
+
+ always @ (posedge clk)
+ if (wr_en)
+ mem[wr_ptr] <= #TCQ d_in;
+
+ assign mem_out = mem[rd_ptr];
+
+ assign nxt_rd_ptr = (rd_ptr + 1\'b1)%DEPTH;
+
+ always @ (posedge clk)
+ begin
+ if (rst)
+ rd_ptr <= \'b0;
+ else if ((!my_empty[2]) & (!full_in))
+ rd_ptr <= nxt_rd_ptr;
+ end
+
+ always @ (posedge clk)
+ begin
+ if (rst)
+ my_empty <= 3\'b111;
+ else if (my_empty[2] & !my_full[1] & full_in & wr_en_in)
+ my_empty <= 3\'b000;
+ else if (!my_empty[2] & !my_full[1] & !full_in & !wr_en_in) begin
+ my_empty[0] <= (nxt_rd_ptr == wr_ptr);
+ my_empty[1] <= (nxt_rd_ptr == wr_ptr);
+ my_empty[2] <= (nxt_rd_ptr == wr_ptr);
+ end
+ end
+
+ assign nxt_wr_ptr = (wr_ptr + 1\'b1)%DEPTH;
+
+ always @ (posedge clk)
+ begin
+ if (rst)
+ wr_ptr <= \'b0;
+ else if ((wr_en_in) & ((!my_empty[2] & !full_in) | (!my_full[1] & full_in)))
+ wr_ptr <= nxt_wr_ptr;
+ end
+
+ always @ (posedge clk)
+ begin
+ if (rst)
+ my_full <= 3\'b000;
+ else if (!my_empty[2] & my_full[0] & !full_in & !wr_en_in)
+ my_full <= 3\'b000;
+ else if (!my_empty[2] & !my_full[0] & full_in & wr_en_in) begin
+ my_full[0] <= (nxt_wr_ptr == rd_ptr);
+ my_full[1] <= (nxt_wr_ptr == rd_ptr);
+ my_full[2] <= (nxt_wr_ptr == rd_ptr);
+ end
+ end
+
+ always @ (posedge clk)
+ begin
+ if (rst)
+ entry_cnt <= \'b0;
+ else if (wr_en_in & full_in & !my_full[1])
+ entry_cnt <= entry_cnt + 1\'b1;
+ else if (!wr_en_in & !full_in & !my_empty[2])
+ entry_cnt <= entry_cnt - 1\'b1;
+ end
+
+ assign afull = (entry_cnt >= ALMOST_FULL_VALUE);
+
+endmodule
+"
+"//--------------------------------------------------------------------------------
+// Project : SWITCH
+// File : user_ddr_strm_arbitrator.v
+// Version : 0.1
+// Author : Vipin.K
+//
+// Description: Arbitrator for user DDR stream generator
+//--------------------------------------------------------------------------------
+
+
+`define MAX_SLAVE 16
+module user_ddr_strm_arbitrator #(
+ parameter NUM_SLAVES = 'd4,
+ parameter ADDR_WIDTH = 'd32,
+ parameter DATA_WIDTH = 'd256,
+\t parameter BE_WIDTH = 'd32
+ )
+ (
+ input i_clk,
+ input i_rst_n,
+\t //Read request ports
+ input [NUM_SLAVES-1:0] i_ddr_rd_req,
+ output reg [NUM_SLAVES-1:0] o_ddr_rd_ack,
+ input [ADDR_WIDTH*NUM_SLAVES-1 : 0] i_ddr_rd_addr,
+ output reg [DATA_WIDTH-1:0] o_ddr_rd_data,
+ output reg [NUM_SLAVES-1:0] o_ddr_rd_data_valid,
+ //Write request ports
+ input [NUM_SLAVES-1:0] i_ddr_wr_req,
+ output reg [NUM_SLAVES-1:0] o_ddr_wr_ack,
+ input [ADDR_WIDTH*NUM_SLAVES-1 : 0] i_ddr_wr_addr,
+ input [DATA_WIDTH*NUM_SLAVES-1:0] i_ddr_wr_data,
+ input [BE_WIDTH*NUM_SLAVES-1:0] i_ddr_wr_be_n,
+ //To ddr
+ input [DATA_WIDTH-1:0] i_ddr_data,
+ output [DATA_WIDTH-1:0] o_ddr_data,
+ output [BE_WIDTH-1:0] o_ddr_be_n,
+ output reg o_ddr_rd_req,
+ output [ADDR_WIDTH-1:0] o_ddr_wr_addr,
+ output [ADDR_WIDTH-1:0] o_ddr_rd_addr,
+ input i_ddr_rd_ack,
+ input i_ddr_rd_data_valid,
+ output o_ddr_wr_req,
+ input i_ddr_wr_ack\t
+ );
+
+reg [$clog2(NUM_SLAVES)-1:0] current_wr_slave_served;
+reg [$clog2(NUM_SLAVES)-1:0] current_rd_slave_served;
+
+wire [$clog2(NUM_SLAVES)-1:0] fifo_wr_data;
+wire [$clog2(NUM_SLAVES)-1:0] expected_buff;
+wire some_other_wr_req;
+wire some_other_rd_req;
+wire wr_strm_fifo_rdy;
+reg fifo_wr;
+wire fifo_rdy;
+reg ddr_wr_ack;
+
+assign o_ddr_rd_addr = i_ddr_rd_addr[current_rd_slave_served*ADDR_WIDTH+:ADDR_WIDTH];
+assign some_other_wr_req = |i_ddr_wr_req[NUM_SLAVES-1:0];
+assign some_other_rd_req = |i_ddr_rd_req[NUM_SLAVES-1:0];
+
+always @(*)
+begin
+ ddr_wr_ack = wr_strm_fifo_rdy & i_ddr_wr_req[current_wr_slave_served];
+ o_ddr_rd_ack = {NUM_SLAVES{1'b0}};
+ o_ddr_rd_ack[current_rd_slave_served] = i_ddr_rd_ack;
+ o_ddr_rd_req = i_ddr_rd_req[current_rd_slave_served];
+ o_ddr_wr_ack = {NUM_SLAVES{1'b0}};
+ o_ddr_wr_ack[current_wr_slave_served] = ddr_wr_ack;
+end
+
+always @(*)
+begin
+ o_ddr_rd_data <= i_ddr_data;
+ o_ddr_rd_data_valid <= {NUM_SLAVES{1'b0}};
+ o_ddr_rd_data_valid[expected_buff] <= i_ddr_rd_data_valid;
+end
+
+localparam IDLE = 'd0,
+ DDR_RD_REQ = 'd1;
+
+reg rd_state;
+reg [1:0] wr_state;
+
+assign fifo_wr_data = current_rd_slave_served;
+
+always @(posedge i_clk)
+begin
+ if(!i_rst_n)
+ begin
+ current_wr_slave_served <= 0;
+ end
+ else
+ begin
+ if(i_ddr_wr_req[current_wr_slave_served])
+ begin
+ current_wr_slave_served <= current_wr_slave_served;
+\t\t end\t
+ else if(some_other_wr_req)
+ begin
+ current_wr_slave_served <= current_wr_slave_served + 1'b1;
+ end
+ end
+end\t
+
+always @(posedge i_clk)
+begin
+ if(!i_rst_n)
+ begin
+ rd_state <= IDLE;
+ current_rd_slave_served <= 0;
+ fifo_wr <= 1'b0;
+ end
+ else
+ begin
+ case(rd_state)
+ IDLE:begin
+ fifo_wr <= 1'b0;
+ if(i_ddr_rd_req[current_rd_slave_served])
+ begin
+ rd_state <= DDR_RD_REQ;
+ fifo_wr <= 1'b1;
+ end
+ else if(some_other_rd_req)
+ begin
+ current_rd_slave_served <= current_rd_slave_served + 1'b1;
+ end
+ end
+ DDR_RD_REQ:begin
+ fifo_wr <= 1'b0;
+ if(i_ddr_rd_ack)
+ begin
+ fifo_wr <= 1'b1;
+ rd_state <= IDLE;
+ end
+ end
+ endcase
+ end
+end
+
+
+ddr_wr_stream_fifo ddr_wr_stream_fifo (
+ .s_aclk(i_clk), // input s_aclk
+ .s_aresetn(i_rst_n), // input s_aresetn
+ .s_axis_tvalid(i_ddr_wr_req[current_wr_slave_served]), // input s_axis_tvalid
+ .s_axis_tready(wr_strm_fifo_rdy), // output s_axis_tready
+ .s_axis_tdata({i_ddr_wr_be_n[current_wr_slave_served*BE_WIDTH+:BE_WIDTH],i_ddr_wr_addr[current_wr_slave_served*ADDR_WIDTH+:ADDR_WIDTH],i_ddr_wr_data[current_wr_slave_served*DATA_WIDTH+:DATA_WIDTH]}), // input [511 : 0] s_axis_tdata
+ .m_axis_tvalid(o_ddr_wr_req), // output m_axis_tvalid
+ .m_axis_tready(i_ddr_wr_ack), // input m_axis_tready
+ .m_axis_tdata({o_ddr_be_n,o_ddr_wr_addr,o_ddr_data}) // output [511 : 0] m_axis_tdata
+);
+
+track_fifo track_fifo (
+ .s_aclk(i_clk), // input s_aclk
+ .s_aresetn(i_rst_n), // input s_aresetn
+ .s_axis_tvalid(fifo_wr), // input s_axis_tvalid
+ .s_axis_tready(), // output s_axis_tready fifo_rdy
+ .s_axis_tdata(fifo_wr_data), // input [7 : 0] s_axis_tdata
+ .m_axis_tvalid(), // output m_axis_tvalid
+ .m_axis_tready(i_ddr_rd_data_valid), // input m_axis_tready
+ .m_axis_tdata(expected_buff) // output [7 : 0] m_axis_tdata
+);
+
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//
+// (c) Copyright 2009-2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//-----------------------------------------------------------------------------
+// Project : Virtex-6 Integrated Block for PCI Express
+// File : pcie_upconfig_fix_3451_v6.v
+// Version : 2.4
+//--
+//-- Description: Virtex6 Workaround for Root Port Upconfigurability Bug
+//--
+//--
+//--------------------------------------------------------------------------------
+
+`timescale 1ns/1ns
+
+module pcie_upconfig_fix_3451_v6 # (
+
+ parameter UPSTREAM_FACING = ""TRUE"",
+ parameter PL_FAST_TRAIN = ""FALSE"",
+ parameter LINK_CAP_MAX_LINK_WIDTH = 6\'h08,
+ parameter TCQ = 1
+
+)
+(
+
+ input pipe_clk,
+ input pl_phy_lnkup_n,
+
+ input [5:0] pl_ltssm_state,
+ input pl_sel_lnk_rate,
+ input [1:0] pl_directed_link_change,
+
+ input [3:0] cfg_link_status_negotiated_width,
+ input [15:0] pipe_rx0_data,
+ input [1:0] pipe_rx0_char_isk,
+
+ output filter_pipe
+
+);
+
+
+ reg reg_filter_pipe;
+ reg [15:0] reg_tsx_counter;
+ wire [15:0] tsx_counter;
+
+ wire [5:0] cap_link_width;
+
+ // Corrupting all Tsx on all lanes as soon as we do R.RC->R.RI transition to allow time for
+ // the core to see the TS1s on all the lanes being configured at the same time
+ // R.RI has a 2ms timeout.Corrupting tsxs for ~1/4 of that time
+ // 225 pipe_clk cycles-sim_fast_train
+ // 60000 pipe_clk cycles-without sim_fast_train
+ // Not taking any action when PLDIRECTEDLINKCHANGE is set
+
+// Detect xx, COM then PAD,xx or COM,PAD then PAD,xx
+// data0 will be the first symbol on lane 0, data1 will be the next symbol.
+// Don\'t look for PAD on data1 since it\'s unnecessary.
+// COM=0xbc and PAD=0xf7 (and isk).
+// detect if (data & 0xb4) == 0xb4 and isk, and then
+// if (data & 0x4b) == 0x08 or 0x43. This distinguishes COM and PAD, using
+// no more than a 6-input LUT, so should be ""free"".
+
+reg reg_filter_used, reg_com_then_pad;
+reg reg_data0_b4, reg_data0_08, reg_data0_43;
+reg reg_data1_b4, reg_data1_08, reg_data1_43;
+reg reg_data0_com, reg_data1_com, reg_data1_pad;
+
+wire data0_b4 = pipe_rx0_char_isk[0] &&
+ ((pipe_rx0_data[7:0] & 8\'hb4) == 8\'hb4);
+wire data0_08 = ((pipe_rx0_data[7:0] & 8\'h4b) == 8\'h08);
+wire data0_43 = ((pipe_rx0_data[7:0] & 8\'h4b) == 8\'h43);
+wire data1_b4 = pipe_rx0_char_isk[1] &&
+ ((pipe_rx0_data[15:8] & 8\'hb4) == 8\'hb4);
+wire data1_08 = ((pipe_rx0_data[15:8] & 8\'h4b) == 8\'h08);
+wire data1_43 = ((pipe_rx0_data[15:8] & 8\'h4b) == 8\'h43);
+
+wire data0_com = reg_data0_b4 && reg_data0_08;
+wire data1_com = reg_data1_b4 && reg_data1_08;
+wire data0_pad = reg_data0_b4 && reg_data0_43;
+wire data1_pad = reg_data1_b4 && reg_data1_43;
+
+wire com_then_pad0 = reg_data0_com && reg_data1_pad && data0_pad;
+wire com_then_pad1 = reg_data1_com && data0_pad && data1_pad;
+wire com_then_pad = (com_then_pad0 || com_then_pad1) && ~reg_filter_used;
+wire filter_used = (pl_ltssm_state == 6\'h20) &&
+ (reg_filter_pipe || reg_filter_used);
+
+ always @(posedge pipe_clk) begin
+
+ reg_data0_b4 <= #TCQ data0_b4;
+ reg_data0_08 <= #TCQ data0_08;
+ reg_data0_43 <= #TCQ data0_43;
+ reg_data1_b4 <= #TCQ data1_b4;
+ reg_data1_08 <= #TCQ data1_08;
+ reg_data1_43 <= #TCQ data1_43;
+ reg_data0_com <= #TCQ data0_com;
+ reg_data1_com <= #TCQ data1_com;
+ reg_data1_pad <= #TCQ data1_pad;
+ reg_com_then_pad <= #TCQ (~pl_phy_lnkup_n) ? com_then_pad : 1\'b0;
+ reg_filter_used <= #TCQ (~pl_phy_lnkup_n) ? filter_used : 1\'b0;
+
+ end
+
+ always @ (posedge pipe_clk) begin
+
+ if (pl_phy_lnkup_n) begin
+
+ reg_tsx_counter <= #TCQ 16\'h0;
+ reg_filter_pipe <= #TCQ 1\'b0;
+
+ end else if ((pl_ltssm_state == 6\'h20) &&
+ reg_com_then_pad &&
+ (cfg_link_status_negotiated_width != cap_link_width) &&
+ (pl_directed_link_change[1:0] == 2\'b00)) begin
+
+ reg_tsx_counter <= #TCQ 16\'h0;
+ reg_filter_pipe <= #TCQ 1\'b1;
+
+ end else if (filter_pipe == 1\'b1) begin
+
+ if (tsx_counter < ((PL_FAST_TRAIN == ""TRUE"") ? 16\'d225: pl_sel_lnk_rate ? 16\'d800 : 16\'d400)) begin
+
+ reg_tsx_counter <= #TCQ tsx_counter + 1\'b1;
+ reg_filter_pipe <= #TCQ 1\'b1;
+
+ end else begin
+
+ reg_tsx_counter <= #TCQ 16\'h0;
+ reg_filter_pipe <= #TCQ 1\'b0;
+
+ end
+
+ end
+
+ end
+
+ assign filter_pipe = (UPSTREAM_FACING == ""TRUE"") ? 1\'b0 : reg_filter_pipe;
+ assign tsx_counter = reg_tsx_counter;
+
+ assign cap_link_width = LINK_CAP_MAX_LINK_WIDTH;
+
+endmodule
+"
+"//--------------------------------------------------------------------------------
+// Project : UPRA
+// File : track_buff.v
+// Version : 0.1
+// Author : Vipin.K
+//
+// Description: Buffer to track the back to back DDR read operation
+//
+//--------------------------------------------------------------------------------
+module track_buff(
+input i_clk,
+input i_data,
+input [7:0] i_wr_ptr,
+input [7:0] i_rd_ptr,
+input i_wr_en,
+output o_data
+);
+
+reg [0:0] mem[255:0];
+
+always @(posedge i_clk)
+begin
+ if(i_wr_en)
+ mem[i_wr_ptr] <= i_data;
+end
+
+
+assign o_data = mem[i_rd_ptr];
+
+endmodule"
+"//*****************************************************************************
+// (c) Copyright 2009 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor: Xilinx
+// \\ \\ \\/ Version: 3.91
+// \\ \\ Application: MIG
+// / / Filename: phy_pd.v
+// /___/ /\\ Date Last Modified: $Date: 2011/06/02 07:18:03 $
+// \\ \\ / \\ Date Created: Aug 03 2009
+// \\___\\/\\___\\
+//
+//Device: Virtex-6
+//Design Name: DDR3 SDRAM
+//Purpose:
+// This module is replicated in phy_pd_top for each DQS signal. This module
+// contains the logic that calibrates PD (moves DQS such that clk_cpt rising
+// edge is aligned with DQS rising edge) and maintains this phase relationship
+// by moving clk_cpt as necessary.
+//
+//Reference:
+//Revision History:
+//*****************************************************************************
+
+/******************************************************************************
+**$Id: phy_pd.v,v 1.1 2011/06/02 07:18:03 mishra Exp $
+**$Date: 2011/06/02 07:18:03 $
+**$Author: mishra $
+**$Revision: 1.1 $
+**$Source: /devl/xcs/repo/env/Databases/ip/src2/O/mig_v3_9/data/dlib/virtex6/ddr3_sdram/verilog/rtl/phy/phy_pd.v,v $
+******************************************************************************/
+
+`timescale 1ps/1ps
+
+module phy_pd #
+ (
+ parameter TCQ = 100,
+ parameter SIM_CAL_OPTION = ""NONE"", // ""NONE"", ""FAST_CAL"", ""SKIP_CAL""
+ // (same as ""NONE"")
+ parameter PD_LHC_WIDTH = 16 // synth low & high cntr physical width
+ )
+ (
+ output [99:0] dbg_pd, // debug signals
+ input [4:0] dqs_dly_val_in,
+ output [4:0] dqs_dly_val,
+ output reg pd_en_maintain, // maintenance enable
+ output reg pd_incdec_maintain, // maintenance inc/dec
+ output pd_cal_done, // calibration done (level)
+ input pd_cal_start, // calibration start (pulse or level)
+ input dfi_init_complete,
+ input pd_read_valid, // advance cntrs only when true
+ input [1:0] trip_points, // the 2 rising clock samples of the
+ // nibble
+ // debug
+ input dbg_pd_off,
+ input dbg_pd_maintain_off,
+ input dbg_pd_inc_cpt, // one clk period pulse
+ input dbg_pd_dec_cpt, // one clk period pulse
+ input dbg_pd_inc_dqs, // one clk period pulse
+ input dbg_pd_dec_dqs, // one clk period pulse
+ input dbg_pd_disab_hyst,
+ input [3:0] dbg_pd_msb_sel, // selects effective msb of high &
+ // low cntrs
+ input clk, // clkmem/2
+ input rst //
+ );
+
+ //***************************************************************************
+ // Local parameters (other than state assignments)
+ //***************************************************************************
+
+ // merge two SIM_CAL_OPTION values into new localparam
+ localparam FAST_SIM = ((SIM_CAL_OPTION == ""FAST_CAL"") | (SIM_CAL_OPTION == ""FAST_WIN_DETECT"")) ? ""YES"" : ""NO"";
+
+ // width of low and high counters
+ localparam LHC_WIDTH = (FAST_SIM == ""YES"") ? 6 : PD_LHC_WIDTH;
+
+ // width of calibration done counter (6 for synthesis, less for simulation)
+ localparam CDC_WIDTH = (FAST_SIM == ""YES"") ? 3 : 6;
+
+ localparam RVPLS_WIDTH = 1; // this controls the pipeline delay of pd_read_valid
+ // set to 1 for normal operation
+
+ //***************************************************************************
+ // Internal signals
+ //***************************************************************************
+
+ wire pd_en_maintain_d;
+ wire pd_incdec_maintain_d;
+ wire [LHC_WIDTH-1:0] low_d;
+ wire [LHC_WIDTH-1:0] high_d;
+
+ reg ld_dqs_dly_val_r; // combinatorial
+ reg [4:0] dqs_dly_val_r;
+ wire pd_cal_done_i; // pd_cal_done internal
+
+ reg first_calib_sample;
+ reg rev_direction;
+ wire rev_direction_ce;
+
+ wire pd_en_calib; // calibration enable
+ wire pd_incdec_calib; // calibration inc/dec
+
+ reg pd_en;
+ wire pd_incdec;
+
+ reg reset; // rst is synchronized to clk
+ reg [2:0] pd_state_r;
+ reg [2:0] pd_next_state; // combinatorial
+ reg [LHC_WIDTH-1:0] low; // low counter
+ reg [LHC_WIDTH-1:0] high; // high counter
+ wire samples_done;
+ reg [2:0] samples_done_pl;
+ wire inc_cntrs;
+ wire clr_low_high;
+ wire low_high_ce;
+ wire update_phase;
+ reg [CDC_WIDTH-1:0] calib_done_cntr;
+ wire calib_done_cntr_inc;
+ wire calib_done_cntr_ce;
+ wire high_ge_low;
+ reg [1:0] l_addend;
+ reg [1:0] h_addend;
+ wire read_valid_pl;
+ wire enab_maintenance;
+
+ reg [3:0] pd_done_state_r;
+ reg [3:0] pd_done_next_state;
+ reg pd_incdec_done; // combinatorial
+ reg pd_incdec_done_next; // combinatorial
+
+ wire block_change;
+ reg low_nearly_done;
+ reg high_nearly_done;
+
+ reg low_done;
+ reg high_done;
+ wire [3:0] hyst_mux_sel;
+ wire [3:0] mux_sel;
+ reg low_mux; // combinatorial
+ reg high_mux; // combinatorial
+ reg low_nearly_done_r;
+ reg high_nearly_done_r;
+
+ //***************************************************************************
+ // low_done and high_done
+ //***************************************************************************
+
+ // select MSB during calibration - during maintanence,
+ // determined by dbg_pd_msb_sel. Add case to handle
+ // fast simulation to prevent overflow of counter
+ // since LHC_WIDTH is set to small value for fast sim
+ assign mux_sel = pd_cal_done_i ?
+ ((FAST_SIM == ""YES"") ? (LHC_WIDTH-1) : dbg_pd_msb_sel) :
+ (LHC_WIDTH-1);
+
+ always @(mux_sel or low) low_mux = low[mux_sel];
+
+ always @(mux_sel or high) high_mux = high[mux_sel];
+
+ always @(posedge clk)
+ begin
+ if (clr_low_high)
+ begin
+ low_done <= #TCQ 1\'b0;
+ high_done <= #TCQ 1\'b0;
+ end
+ else
+ begin
+ low_done <= #TCQ low_mux;
+ high_done <= #TCQ high_mux;
+ end
+ end
+
+ //***************************************************************************
+ // block_change (hysteresis) logic
+ //***************************************************************************
+
+ // select MSB used to determine hysteresis level. Add case to handle
+ // fast simulation to prevent out-of-bounds index since LHC_WIDTH is set
+ // to small value for fast sim. If DEBUG PORT is disabled, dbg_pd_msb_sel
+ // must be hardcoded to appropriate value in upper-level module.
+ assign hyst_mux_sel = (FAST_SIM == ""YES"") ?
+ (LHC_WIDTH-2) : dbg_pd_msb_sel - 1;
+
+ always @(hyst_mux_sel or low) low_nearly_done = low[hyst_mux_sel];
+ always @(hyst_mux_sel or high) high_nearly_done = high[hyst_mux_sel];
+
+ always @(posedge clk) // pipeline low_nearly_done and high_nearly_done
+ begin
+ if (reset | (dbg_pd_disab_hyst))
+ begin
+ low_nearly_done_r <= #TCQ 1\'b0;
+ high_nearly_done_r <= #TCQ 1\'b0;
+ end
+ else
+ begin
+ low_nearly_done_r <= #TCQ low_nearly_done;
+ high_nearly_done_r <= #TCQ high_nearly_done;
+ end
+ end
+
+ assign block_change = ((high_done & low_done)
+ | (high_done ? low_nearly_done_r : high_nearly_done_r));
+
+ //***************************************************************************
+ // samples_done and high_ge_low
+ //***************************************************************************
+
+ assign samples_done = (low_done | high_done) & ~clr_low_high; // ~clr_low_high makes samples_done de-assert one cycle sooner
+
+ assign high_ge_low = high_done;
+
+ //***************************************************************************
+ // Debug
+ //***************************************************************************
+
+ // Temporary debug assignments and logic - remove for release code.
+
+ // Disabling of PD is allowed either before or after calibration
+ // Usage: dbg_pd_off = 1 to disable PD. If disabled prior to initialization
+ // it should remain off - turning it on later will result in bad behavior
+ // since the DQS early/late tap delays will not have been properly initialized.
+ // If disabled after initial calibration, it can later be re-enabled
+ // without reseting the system.
+
+ reg pd_incdec_tp; // debug test point
+ always @(posedge clk)
+ if (reset) pd_incdec_tp <= #TCQ 1\'b0;
+ else if(pd_en) pd_incdec_tp <= #TCQ pd_incdec;
+
+ assign dbg_pd[0] = pd_en;
+ assign dbg_pd[1] = pd_incdec;
+ assign dbg_pd[2] = pd_cal_done_i;
+ assign dbg_pd[3] = pd_cal_start;
+ assign dbg_pd[4] = samples_done;
+ assign dbg_pd[5] = inc_cntrs;
+ assign dbg_pd[6] = clr_low_high;
+ assign dbg_pd[7] = low_high_ce;
+ assign dbg_pd[8] = update_phase;
+ assign dbg_pd[9] = calib_done_cntr_inc;
+ assign dbg_pd[10] = calib_done_cntr_ce;
+ assign dbg_pd[11] = first_calib_sample;
+ assign dbg_pd[12] = rev_direction;
+ assign dbg_pd[13] = rev_direction_ce;
+ assign dbg_pd[14] = pd_en_calib;
+ assign dbg_pd[15] = pd_incdec_calib;
+ assign dbg_pd[16] = read_valid_pl;
+ assign dbg_pd[17] = pd_read_valid;
+ assign dbg_pd[18] = pd_incdec_tp;
+ assign dbg_pd[19] = block_change;
+ assign dbg_pd[20] = low_nearly_done_r;
+ assign dbg_pd[21] = high_nearly_done_r;
+ assign dbg_pd[23:22] = \'b0; // spare scalor bits
+ assign dbg_pd[29:24] = {1\'b0, dqs_dly_val_r}; // 1 spare bit
+ assign dbg_pd[33:30] = {1\'b0, pd_state_r}; // 1 spare bit
+ assign dbg_pd[37:34] = {1\'b0, pd_next_state}; // 1 spare bit
+ assign dbg_pd[53:38] = high; // 16 bits max
+ assign dbg_pd[69:54] = low; // 16 bits max
+ assign dbg_pd[73:70] = pd_done_state_r;
+ assign dbg_pd[81:74] = {{8-CDC_WIDTH{1\'b0}}, calib_done_cntr}; // 8 bits max
+ assign dbg_pd[83:82] = l_addend;
+ assign dbg_pd[85:84] = h_addend;
+ assign dbg_pd[87:86] = trip_points;
+ assign dbg_pd[99:88] = \'b0; // spare
+
+ //***************************************************************************
+ // pd_read_valid pipeline shifter
+ //***************************************************************************
+
+ generate
+ begin: gen_rvpls
+
+ if(RVPLS_WIDTH == 0)
+ begin
+ assign read_valid_pl = pd_read_valid;
+ end
+ else if(RVPLS_WIDTH == 1)
+ begin
+ reg [RVPLS_WIDTH-1:0] read_valid_shftr;
+
+ always @(posedge clk)
+ if (reset) read_valid_shftr <= #TCQ \'b0;
+ else read_valid_shftr <= #TCQ pd_read_valid;
+
+ assign read_valid_pl = read_valid_shftr[RVPLS_WIDTH-1];
+ end
+ else
+ begin
+ reg [RVPLS_WIDTH-1:0] read_valid_shftr;
+
+ always @(posedge clk)
+ if (reset) read_valid_shftr <= #TCQ \'b0;
+ else read_valid_shftr <= #TCQ {read_valid_shftr[RVPLS_WIDTH-2:0], pd_read_valid};
+
+ assign read_valid_pl = read_valid_shftr[RVPLS_WIDTH-1];
+ end
+ end
+ endgenerate
+
+ //***************************************************************************
+ // phase shift interface
+ //***************************************************************************
+
+ always @(posedge clk)
+ if (reset) pd_en <= #TCQ 1\'b0;
+ else pd_en <= #TCQ update_phase;
+
+ assign pd_incdec = high_ge_low;
+
+ //***************************************************************************
+ // inc/dec control
+ //***************************************************************************
+
+ assign rev_direction_ce = first_calib_sample & pd_en & (pd_incdec ~^ dqs_dly_val_r[4]);
+
+ always @(posedge clk)
+ begin
+ if (reset)
+ begin
+ first_calib_sample <= #TCQ 1\'b1;
+ rev_direction <= #TCQ 1\'b0;
+ end
+ else
+ begin
+ if(pd_en) first_calib_sample <= #TCQ 1\'b0;
+ if(rev_direction_ce) rev_direction <= #TCQ 1\'b1;
+ end
+ end
+
+ assign pd_en_calib = (pd_en & ~pd_cal_done_i & ~first_calib_sample) | dbg_pd_inc_dqs | dbg_pd_dec_dqs;
+ assign pd_incdec_calib = (pd_incdec ^ rev_direction) | dbg_pd_inc_dqs;
+
+ assign enab_maintenance = dfi_init_complete & ~dbg_pd_maintain_off;
+ assign pd_en_maintain_d = (pd_en & pd_cal_done_i & enab_maintenance & ~block_change) | dbg_pd_inc_cpt | dbg_pd_dec_cpt;
+ assign pd_incdec_maintain_d = (~pd_incdec_calib | dbg_pd_inc_cpt) & ~dbg_pd_dec_cpt;
+
+ always @(posedge clk) // pipeline maintenance control signals
+ begin
+ if (reset)
+ begin
+ pd_en_maintain <= #TCQ 1\'b0;
+ pd_incdec_maintain <= #TCQ 1\'b0;
+ end
+ else
+ begin
+ pd_en_maintain <= #TCQ pd_en_maintain_d;
+ pd_incdec_maintain <= #TCQ pd_incdec_maintain_d;
+ end
+ end
+
+ //***************************************************************************
+ // dqs delay value counter
+ //***************************************************************************
+
+ always @(posedge clk)
+ begin
+ if (rst)
+ begin
+ dqs_dly_val_r <= #TCQ 5\'b0_0000;
+ end
+ else if(ld_dqs_dly_val_r)
+ begin
+ dqs_dly_val_r <= #TCQ dqs_dly_val_in;
+ end
+ else
+ begin
+ if(pd_en_calib)
+ begin
+ if(pd_incdec_calib) dqs_dly_val_r <= #TCQ dqs_dly_val_r + 1;
+ else dqs_dly_val_r <= #TCQ dqs_dly_val_r - 1;
+ end
+ end
+ end
+
+ assign dqs_dly_val = dqs_dly_val_r;
+
+ //***************************************************************************
+ // reset synchronization
+ //***************************************************************************
+
+ always @(posedge clk or posedge rst)
+ if (rst) reset <= #TCQ 1\'b1;
+ else reset <= #TCQ 1\'b0;
+
+ //***************************************************************************
+ // pd state assignments
+ //***************************************************************************
+
+ localparam PD_IDLE = 3\'h0;
+ localparam PD_CLR_CNTRS = 3\'h1;
+ localparam PD_INC_CNTRS = 3\'h2;
+ localparam PD_UPDATE = 3\'h3;
+ localparam PD_WAIT = 3\'h4;
+
+ //***************************************************************************
+ // State register
+ //***************************************************************************
+
+ always @(posedge clk)
+ if (reset) pd_state_r <= #TCQ \'b0;
+ else pd_state_r <= #TCQ pd_next_state;
+
+ //***************************************************************************
+ // Next pd state
+ //***************************************************************************
+
+ always @(pd_state_r or pd_cal_start or dbg_pd_off or samples_done_pl[2] or pd_incdec_done)
+ begin
+ pd_next_state = PD_IDLE; // default state is idle
+ ld_dqs_dly_val_r = 1\'b0;
+ case (pd_state_r)
+ PD_IDLE : begin // (0) wait for pd_cal_start
+ if(pd_cal_start)
+ begin
+ pd_next_state = PD_CLR_CNTRS;
+ ld_dqs_dly_val_r = 1\'b1;
+ end
+ end
+ PD_CLR_CNTRS : begin // (1) clr low and high counters
+ if(~dbg_pd_off) pd_next_state = PD_INC_CNTRS;
+ else pd_next_state = PD_CLR_CNTRS;
+ end
+ PD_INC_CNTRS : begin // (2) conditionally inc low and high counters
+ if(samples_done_pl[2]) pd_next_state = PD_UPDATE;
+ else pd_next_state = PD_INC_CNTRS;
+ end
+ PD_UPDATE : begin // (3) pulse pd_en
+ pd_next_state = PD_WAIT;
+ end
+ PD_WAIT : begin // (4) wait for pd_incdec_done
+ if(pd_incdec_done) pd_next_state = PD_CLR_CNTRS;
+ else pd_next_state = PD_WAIT;
+ end
+ endcase
+ end
+
+ //***************************************************************************
+ // pd state translations
+ //***************************************************************************
+
+ assign inc_cntrs = (pd_state_r == PD_INC_CNTRS) & read_valid_pl & ~samples_done;
+ assign clr_low_high = reset | (pd_state_r == PD_CLR_CNTRS);
+ assign low_high_ce = inc_cntrs;
+ assign update_phase = (pd_state_r == PD_UPDATE);
+
+ //***************************************************************************
+ // pd_cal_done generator
+ //***************************************************************************
+
+ assign calib_done_cntr_inc = high_ge_low ~^ calib_done_cntr[0];
+ assign calib_done_cntr_ce = update_phase & ~calib_done_cntr[CDC_WIDTH-1] & ~first_calib_sample;
+
+ always @(posedge clk)
+ if (reset) calib_done_cntr <= #TCQ \'b0;
+ else if(calib_done_cntr_ce) calib_done_cntr <= #TCQ calib_done_cntr + calib_done_cntr_inc;
+
+ assign pd_cal_done_i = calib_done_cntr[CDC_WIDTH-1] | dbg_pd_off;
+ assign pd_cal_done = pd_cal_done_i;
+
+ //***************************************************************************
+ // addemd gemerators (pipelined)
+ //***************************************************************************
+
+ // trip_points h_addend l_addend
+ // ----------- -------- --------
+ // 00 00 10
+ // 01 01 01
+ // 10 01 01
+ // 11 10 00
+
+ always @(posedge clk)
+ begin
+ if (reset)
+ begin
+ l_addend <= #TCQ \'b0;
+ h_addend <= #TCQ \'b0;
+ end
+ else
+ begin
+ l_addend <= #TCQ {~trip_points[1] & ~trip_points[0], trip_points[1] ^ trip_points[0]};
+ h_addend <= #TCQ { trip_points[1] & trip_points[0], trip_points[1] ^ trip_points[0]};
+ end
+ end
+
+ //***************************************************************************
+ // low counter
+ //***************************************************************************
+
+ assign low_d = low + {{LHC_WIDTH-2{1\'b0}}, l_addend};
+
+ always @(posedge clk)
+ if (clr_low_high) low <= #TCQ \'b0;
+ else if(low_high_ce) low <= #TCQ low_d;
+
+ //***************************************************************************
+ // high counter
+ //***************************************************************************
+
+ assign high_d = high + {{LHC_WIDTH-2{1\'b0}}, h_addend};
+
+ always @(posedge clk)
+ if (clr_low_high) high <= #TCQ \'b0;
+ else if(low_high_ce) high <= #TCQ high_d;
+
+ //***************************************************************************
+ // samples_done pipeline shifter
+ //***************************************************************************
+
+ // This shifter delays samples_done rising edge until the nearly_done logic has completed
+ // the pass through its pipeline.
+
+ always @(posedge clk)
+ if (reset) samples_done_pl <= #TCQ \'b0;
+ else samples_done_pl <= #TCQ {samples_done_pl[1] & samples_done,
+ samples_done_pl[0] & samples_done, samples_done};
+
+ //***************************************************************************
+ // pd_done logic
+ //***************************************************************************
+
+ // This logic adds a delay after pd_en is pulsed. This delay is necessary
+ // to allow the effect of the delay tap change to cycle through to the addends,
+ // where it can then be sampled in the low and high counters.
+
+ localparam PD_DONE_IDLE = 4\'d0;
+ localparam PD_DONE_MAX = 4\'d10;
+
+ // pd_done registers
+ always @(posedge clk)
+ begin
+ if (reset)
+ begin
+ pd_done_state_r <= #TCQ \'b0;
+ pd_incdec_done <= #TCQ 1\'b0;
+ end
+ else
+ begin
+ pd_done_state_r <= #TCQ pd_done_next_state;
+ pd_incdec_done <= #TCQ pd_incdec_done_next;
+ end
+ end
+
+ // pd_done next generator
+ always @(pd_done_state_r or pd_en)
+ begin
+ pd_done_next_state = pd_done_state_r + 1; // dflt pd_done_next_state is + 1
+ pd_incdec_done_next = 1\'b0; // dflt pd_incdec_done is false
+
+ case (pd_done_state_r)
+ PD_DONE_IDLE : begin // (0) wait for pd_en
+ if(~pd_en) pd_done_next_state = PD_DONE_IDLE;
+ end
+ PD_DONE_MAX : begin // (10)
+ pd_done_next_state = PD_DONE_IDLE;
+ pd_incdec_done_next = 1\'b1;
+ end
+ endcase
+ end
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2008-2009 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : 3.91
+// \\ \\ Application : MIG
+// / / Filename : rank_mach.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : Virtex-6
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+// Top level rank machine structural block. This block
+// instantiates a configurable number of rank controller blocks.
+
+`timescale 1 ns / 1 ps
+
+module rank_mach #
+ (
+ parameter BURST_MODE = ""8"",
+ parameter CS_WIDTH = 4,
+ parameter DRAM_TYPE = ""DDR3"",
+ parameter MAINT_PRESCALER_DIV = 40,
+ parameter nBANK_MACHS = 4,
+ parameter nCK_PER_CLK = 2,
+ parameter CL = 5,
+ parameter nFAW = 30,
+ parameter nREFRESH_BANK = 8,
+ parameter nRRD = 4,
+ parameter nWTR = 4,
+ parameter PERIODIC_RD_TIMER_DIV = 20,
+ parameter RANK_BM_BV_WIDTH = 16,
+ parameter RANK_WIDTH = 2,
+ parameter RANKS = 4,
+ parameter REFRESH_TIMER_DIV = 39,
+ parameter PHASE_DETECT = ""OFF"",
+ parameter ZQ_TIMER_DIV = 640000
+ )
+ (/*AUTOARG*/
+ // Outputs
+ periodic_rd_rank_r, periodic_rd_r, maint_req_r, inhbt_act_faw_r,
+ inhbt_rd_r, wtr_inhbt_config_r, maint_rank_r, maint_zq_r,
+ // Inputs
+ wr_this_rank_r, slot_1_present, slot_0_present, sending_row,
+ sending_col, rst, rd_this_rank_r, rank_busy_r, periodic_rd_ack_r,
+ maint_wip_r, insert_maint_r1, dfi_init_complete, clk, app_zq_req,
+ app_ref_req, app_periodic_rd_req, act_this_rank_r
+ );
+
+ /*AUTOINPUT*/
+ // Beginning of automatic inputs (from unused autoinst inputs)
+ input [RANK_BM_BV_WIDTH-1:0] act_this_rank_r; // To rank_cntrl0 of rank_cntrl.v
+ input app_periodic_rd_req; // To rank_cntrl0 of rank_cntrl.v
+ input app_ref_req; // To rank_cntrl0 of rank_cntrl.v
+ input app_zq_req; // To rank_common0 of rank_common.v
+ input clk; // To rank_cntrl0 of rank_cntrl.v, ...
+ input dfi_init_complete; // To rank_cntrl0 of rank_cntrl.v, ...
+ input insert_maint_r1; // To rank_cntrl0 of rank_cntrl.v, ...
+ input maint_wip_r; // To rank_common0 of rank_common.v
+ input periodic_rd_ack_r; // To rank_common0 of rank_common.v
+ input [(RANKS*nBANK_MACHS)-1:0] rank_busy_r; // To rank_cntrl0 of rank_cntrl.v
+ input [RANK_BM_BV_WIDTH-1:0] rd_this_rank_r; // To rank_cntrl0 of rank_cntrl.v
+ input rst; // To rank_cntrl0 of rank_cntrl.v, ...
+ input [nBANK_MACHS-1:0] sending_col; // To rank_cntrl0 of rank_cntrl.v
+ input [nBANK_MACHS-1:0] sending_row; // To rank_cntrl0 of rank_cntrl.v
+ input [7:0] slot_0_present; // To rank_common0 of rank_common.v
+ input [7:0] slot_1_present; // To rank_common0 of rank_common.v
+ input [RANK_BM_BV_WIDTH-1:0] wr_this_rank_r; // To rank_cntrl0 of rank_cntrl.v
+ // End of automatics
+
+ /*AUTOOUTPUT*/
+ // Beginning of automatic outputs (from unused autoinst outputs)
+ output maint_req_r; // From rank_common0 of rank_common.v
+ output periodic_rd_r; // From rank_common0 of rank_common.v
+ output [RANK_WIDTH-1:0] periodic_rd_rank_r; // From rank_common0 of rank_common.v
+ // End of automatics
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire maint_prescaler_tick_r; // From rank_common0 of rank_common.v
+ wire refresh_tick; // From rank_common0 of rank_common.v
+ // End of automatics
+
+
+ output [RANKS-1:0] inhbt_act_faw_r;
+ output [RANKS-1:0] inhbt_rd_r;
+ output [RANKS-1:0] wtr_inhbt_config_r;
+ output [RANK_WIDTH-1:0] maint_rank_r;
+ output maint_zq_r;
+
+ wire [RANKS-1:0] refresh_request;
+ wire [RANKS-1:0] periodic_rd_request;
+ wire [RANKS-1:0] clear_periodic_rd_request;
+
+ genvar ID;
+ generate
+ for (ID=0; IDout delay (sim only)
+ parameter nCK_PER_CLK = 2, // # of memory clocks per CLK
+ parameter CLK_PERIOD = 3333, // Internal clock period (in ps)
+ parameter REFCLK_FREQ = 300.0, // IODELAY Reference Clock freq (MHz)
+ parameter DQS_WIDTH = 1, // # of DQS (strobe),
+ parameter nDQS_COL0 = 4, // # DQS groups in I/O column #1
+ parameter nDQS_COL1 = 4, // # DQS groups in I/O column #2
+ parameter nDQS_COL2 = 0, // # DQS groups in I/O column #3
+ parameter nDQS_COL3 = 0, // # DQS groups in I/O column #4
+ parameter IODELAY_GRP = ""IODELAY_MIG"" // May be assigned unique name
+ // when mult IP cores in design
+ )
+ (
+ input clk_mem, // Memory clock
+ input clk, // Internal (logic) half-rate clock
+ input clk_rd_base, // Base capture clock
+ input rst, // Logic reset
+ input dlyrst_cpt, // Capture clock IDELAY shared reset
+ input [DQS_WIDTH-1:0] dlyce_cpt, // Capture clock IDELAY enable
+ input [DQS_WIDTH-1:0] dlyinc_cpt, // Capture clock IDELAY inc/dec
+ input dlyrst_rsync, // Resync clock IDELAY reset
+ input [3:0] dlyce_rsync, // Resync clock IDELAY enable
+ input [3:0] dlyinc_rsync, // Resync clock IDELAY inc/dec
+ output [DQS_WIDTH-1:0] clk_cpt, // Data capture clock
+ output [3:0] clk_rsync, // Resynchronization clock
+ output reg [3:0] rst_rsync, // Resync clock domain reset
+ // debug control signals
+ output [5*DQS_WIDTH-1:0] dbg_cpt_tap_cnt, // CPT IODELAY tap count
+ output [19:0] dbg_rsync_tap_cnt // RSYNC IODELAY tap count
+ );
+
+ // # cycles after deassertion of master reset when OSERDES used to
+ // forward CPT and RSYNC clocks are taken out of reset
+ localparam RST_OSERDES_SYNC_NUM = 9;
+
+ // NOTE: All these parameters must be <= 8, otherwise, you\'ll need to
+ // individually change the width of the respective counter
+ localparam EN_CLK_ON_CNT = 8;
+ localparam EN_CLK_OFF_CNT = 8;
+ localparam RST_OFF_CNT = 8;
+ localparam WC_OSERDES_RST_CNT = 8;
+
+ // Calculate appropriate MMCM multiplication factor to keep VCO frequency
+ // in allowable range, and at the same time as high as possible in order
+ // to keep output jitter as low as possible
+ // VCO frequency = CLKIN frequency * CLKFBOUT_MULT_F / DIVCLK_DIVIDE
+ // NOTES:
+ // 1. DIVCLK_DIVIDE can be 1 or 2 depending on the input frequency
+ // and assumed speedgrade (change starting with MIG 3.3 - before
+ // DIVCLK_DIVIDE was always set to 1 - this exceeded the allowable
+ // PFD clock period when using a -2 part at higher than 533MHz freq.
+ // 2. Period of the input clock provided by the user is assumed to
+ // be = CLK_PERIOD / nCK_PER_CLK
+ localparam CLKIN_PERIOD = CLK_PERIOD/nCK_PER_CLK;
+
+ // Maximum skew between BUFR and BUFIO networks across 3 banks in ps.
+ // Includes all skew starting from when the base clock exits read MMCM
+ localparam CLK_CPT_SKEW_PS = 200;
+ // Amount to shift BUFR (in ps) by in order to accomodate all possibilites
+ // of BUFIO-BUFR skew after read calibration
+ // = T/2 + CLK_CPT_SKEW, where T = memory clock period
+ localparam RSYNC_SHIFT_PS = ((CLK_PERIOD / nCK_PER_CLK)/2) + CLK_CPT_SKEW_PS;
+ // Amount to shift in RSYNC_SHIFT_PS in # of IODELAY taps. Cap at 31.
+ localparam RSYNC_SHIFT_TAPS
+ = (((RSYNC_SHIFT_PS + (1000000/(REFCLK_FREQ*64)) - 1)/
+ (1000000/(REFCLK_FREQ*64))) > 31 ? 31 :
+ ((RSYNC_SHIFT_PS + (1000000/(REFCLK_FREQ*64)) - 1)/
+ (1000000/(REFCLK_FREQ*64))));
+
+ // States for reset deassertion and clock generation state machine
+ localparam RESET_IDLE = 3\'b000;
+ localparam RESET_PULSE_WC = 3\'b001;
+ localparam RESET_ENABLE_CLK = 3\'b010;
+ localparam RESET_DISABLE_CLK = 3\'b011;
+ localparam RESET_DEASSERT_RST = 3\'b100;
+ localparam RESET_PULSE_CLK = 3\'b101;
+ localparam RESET_DONE = 3\'b110;
+
+ wire [DQS_WIDTH-1:0] clk_cpt_tmp;
+ wire [DQS_WIDTH-1:0] cpt_odelay;
+ wire [DQS_WIDTH-1:0] cpt_oserdes;
+ reg [3:0] en_clk_off_cnt_r;
+ reg [3:0] en_clk_on_cnt_r;
+ reg [DQS_WIDTH-1:0] en_clk_cpt_even_r;
+ reg [DQS_WIDTH-1:0] en_clk_cpt_odd_r;
+ reg [3:0] en_clk_rsync_even_r;
+ reg [3:0] en_clk_rsync_odd_r;
+ wire [DQS_WIDTH-1:0] ocbextend_cpt;
+ reg [DQS_WIDTH-1:0] ocbextend_cpt_r;
+ wire [3:0] ocbextend_rsync;
+ reg [3:0] ocbextend_rsync_r;
+ reg [2:0] reset_state_r;
+ reg [3:0] rst_off_cnt_r;
+ wire rst_oserdes;
+ reg [RST_OSERDES_SYNC_NUM-1:0] rst_oserdes_sync_r;
+ reg rst_rsync_pre_r;
+ wire [3:0] rsync_bufr;
+ wire [3:0] rsync_odelay;
+ wire [3:0] rsync_oserdes;
+ reg [3:0] wc_oserdes_cnt_r;
+ reg wc_oserdes_r;
+
+ reg [DQS_WIDTH-1:0] dlyrst_cpt_r;
+ reg [3:0] dlyrst_rsync_r;
+ reg [DQS_WIDTH-1:0] rst_oserdes_cpt_r;
+ reg [3:0] rst_oserdes_rsync_r;
+ // XST attributes for local reset trees - prohibit equivalent register
+ // removal to prevent ""sharing"" w/ other local reset trees
+ // synthesis attribute shreg_extract of dlyrst_cpt_r is ""no"";
+ // synthesis attribute equivalent_register_removal of dlyrst_cpt_r is ""no""
+ // synthesis attribute shreg_extract of dlyrst_rsync_r is ""no"";
+ // synthesis attribute equivalent_register_removal of dlyrst_rsync_r is ""no""
+ // synthesis attribute shreg_extract of rst_oserdes_cpt_r is ""no"";
+ // synthesis attribute equivalent_register_removal of rst_oserdes_cpt_r is ""no""
+ // synthesis attribute shreg_extract of rst_oserdes_rsync_r is ""no"";
+ // synthesis attribute equivalent_register_removal of rst_oserdes_rsync_r is ""no""
+
+ //***************************************************************************
+ // RESET GENERATION AND SYNCHRONIZATION:
+ // Reset and clock assertion must be carefully done in order to ensure that
+ // the ISERDES internal CLK-divide-by-2 element of all DQ/DQS bits are phase
+ // aligned prior to adjustment of individual CPT clocks. This allows us to
+ // synchronize data capture to the BUFR domain using a single BUFR -
+ // otherwise, if some CLK-div-by-2 clocks are 180 degrees phase shifted
+ // from others, then it becomes impossible to provide meeting timing for
+ // the BUFIO-BUFR capture across all bits.
+ // 1. The various stages required to generate the forwarded capture and
+ // resynchronization clocks (both PERF and BUFG clocks are involved)
+ // 2. The need to ensure that the divide-by-2 elements in all ISERDES and
+ // BUFR blocks power up in the ""same state"" (e.g. on the first clock
+ // edge that they receive, they should drive out logic high). Otherwise
+ // these clocks can be either 0 or 180 degrees out of phase, which makes
+ // it hard to synchronize data going from the ISERDES CLK-div-2 domain
+ // to the BUFR domain.
+ // 3. On a related note, the OSERDES blocks are used to generate clocks
+ // for the ISERDES and BUFR elements. Because the OSERDES OCB feature
+ // is used to synchronize from the BUFG to PERF domain (and provide the
+ // ability to gate these clocks), we have to account for the possibility
+ // that the latency across different OCB blocks can vary (by 1 clock
+ // cycle). This means that if the same control is provided to all
+ // clock-forwaring OSERDES, there can be an extra clock pulse produced
+ // by some OSERDES blocks compared to others - this in turn will also
+ // cause the ISERDES and BUFR divide-by-2 outputs to go out of phase.
+ // Therefore, the OSERDES.OCBEXTEND pins of all these clock-forwarding
+ // OSERDES must be monitored. If there is a difference in the OCBEXTEND
+ // values across all the OSERDES, some OSERDES must have a clock pulse
+ // removed in order to ensure phase matching across all the ISERDES and
+ // BUFR divide-by-2 elements
+ // Reset sequence:
+ // 1. Initially all resets are asserted
+ // 2. Once both MMCMs lock, deassert reset for OSERDESs responsible for
+ // clock forwarding for CPT and RSYNC clocks. Deassertion is
+ // synchronous to clk.
+ // 3. Pulse WC for the CPT and RSYNC clock OSERDESs. WC must be
+ // synchronous to clk, and is initially deasserted, then pulsed
+ // 8 clock cycles after OSERDES reset deassertion. Keep en_clk = 1
+ // to enable the OSERDES outputs.
+ // - At this point the CPT/RSYNC clocks are active
+ // 4. Disable CPT and RSYNC clocks (en_clk=0). Keep rst_rsync asserted
+ // - At this point the CPT/RSYNC clocks are flatlined
+ // 5. Deassert rst_rsync. This is done to ensure that the divide-by-2
+ // circuits in all the ISERDES and BURFs will be in the same ""state""
+ // when the clock is once again restored. Otherwise, if rst_rsync were
+ // deasserted while the CPT clocks were active, it\'s not possible to
+ // guarantee that the reset will be deasserted synchronously with
+ // respect to the capture clock for all ISERDES.
+ // 6. Observe the OCBEXTEND for each of the CPT and RSYNC OSERDES. For
+ // those that have an OCBEXTEND value of 1, drive a single clock
+ // pulse out prior to the next step where the clocks are permanently
+ // reenabled. This will ""equalize"" the phases of all the ISERDES and
+ // BUFR divide-by-2 elements.
+ // 7. Permanently re-enable CPT and RSYNC clocks.
+ // NOTES:
+ // 1. May need to revisit reenabling of CPT and RSYNC clocks - may be
+ // fair amount of ISI on the first few edges of the clock. Could
+ // instead drive out a slower rate clock initially after re-enabling
+ // the clocks.
+ // 2. May need to revisit formula for positioning of RSYNC clock so that
+ // a single RSYNC clock can resynchronize data for all CPT blocks. This
+ // can either be a ""static"" calculation, or a dynamic calibration step.
+ //***************************************************************************
+
+ //*****************************************************************
+ // Keep all logic driven by PLL performance path in reset until master
+ // logic reset deasserted
+ //*****************************************************************
+
+ always @(posedge clk)
+ if (rst)
+ rst_oserdes_sync_r <= #TCQ {(RST_OSERDES_SYNC_NUM){1\'b1}};
+ else
+ rst_oserdes_sync_r <= #TCQ rst_oserdes_sync_r << 1;
+
+ assign rst_oserdes = rst_oserdes_sync_r[RST_OSERDES_SYNC_NUM-1];
+
+ always @(posedge clk) begin
+ if (rst_oserdes) begin
+ en_clk_off_cnt_r <= #TCQ \'b0;
+ en_clk_on_cnt_r <= #TCQ \'b0;
+ en_clk_cpt_even_r <= #TCQ \'b0;
+ en_clk_cpt_odd_r <= #TCQ \'b0;
+ en_clk_rsync_even_r <= #TCQ \'b0;
+ en_clk_rsync_odd_r <= #TCQ \'b0;
+ rst_off_cnt_r <= #TCQ \'b0;
+ rst_rsync_pre_r <= #TCQ 1\'b1;
+ reset_state_r <= #TCQ RESET_IDLE;
+ wc_oserdes_cnt_r <= #TCQ \'b0;
+ wc_oserdes_r <= #TCQ 1\'b0;
+ end else begin
+ // Default assignments
+ en_clk_cpt_even_r <= #TCQ \'b0;
+ en_clk_cpt_odd_r <= #TCQ \'b0;
+ en_clk_rsync_even_r <= #TCQ \'b0;
+ en_clk_rsync_odd_r <= #TCQ \'b0;
+ rst_rsync_pre_r <= #TCQ 1\'b1;
+ wc_oserdes_r <= #TCQ 1\'b0;
+
+ (* full_case, parallel_case *) case (reset_state_r)
+ // Wait for both MMCM\'s to lock
+ RESET_IDLE: begin
+ wc_oserdes_cnt_r <= #TCQ 3\'b000;
+ reset_state_r <= #TCQ RESET_PULSE_WC;
+ end
+
+ // Pulse WC some time after reset to OSERDES is deasserted
+ RESET_PULSE_WC: begin
+ wc_oserdes_cnt_r <= #TCQ wc_oserdes_cnt_r + 1;
+ if (wc_oserdes_cnt_r == WC_OSERDES_RST_CNT-1) begin
+ wc_oserdes_r <= #TCQ 1\'b1;
+ reset_state_r <= #TCQ RESET_ENABLE_CLK;
+ end
+ end
+
+ // Drive out a few clocks to make sure reset is recognized for
+ // those circuits that require a synchronous reset
+ RESET_ENABLE_CLK: begin
+ en_clk_cpt_even_r <= #TCQ {DQS_WIDTH{1\'b1}};
+ en_clk_cpt_odd_r <= #TCQ {DQS_WIDTH{1\'b1}};
+ en_clk_rsync_even_r <= #TCQ 4\'b1111;
+ en_clk_rsync_odd_r <= #TCQ 4\'b1111;
+ en_clk_on_cnt_r <= #TCQ en_clk_on_cnt_r + 1;
+ if (en_clk_on_cnt_r == EN_CLK_ON_CNT-1)
+ reset_state_r <= #TCQ RESET_DISABLE_CLK;
+ end
+
+ // Disable clocks in preparation for disabling reset
+ RESET_DISABLE_CLK: begin
+ en_clk_off_cnt_r <= #TCQ en_clk_off_cnt_r + 1;
+ if (en_clk_off_cnt_r == EN_CLK_OFF_CNT-1)
+ reset_state_r <= #TCQ RESET_DEASSERT_RST;
+ end
+
+ // Deassert reset while clocks are inactive
+ RESET_DEASSERT_RST: begin
+ rst_rsync_pre_r <= #TCQ 1\'b0;
+ rst_off_cnt_r <= #TCQ rst_off_cnt_r + 1;
+ if (rst_off_cnt_r == RST_OFF_CNT-1)
+ reset_state_r <= #TCQ RESET_PULSE_CLK;
+ end
+
+ // Pulse extra clock to those CPT/RSYNC OSERDES that need it
+ RESET_PULSE_CLK: begin
+ en_clk_cpt_even_r <= #TCQ ocbextend_cpt_r;
+ en_clk_cpt_odd_r <= #TCQ \'b0;
+ en_clk_rsync_even_r <= #TCQ ocbextend_rsync_r;
+ en_clk_rsync_odd_r <= #TCQ \'b0;
+ rst_rsync_pre_r <= #TCQ 1\'b0;
+ reset_state_r <= #TCQ RESET_DONE;
+ end
+
+ // Permanently enable clocks
+ RESET_DONE: begin
+ en_clk_cpt_even_r <= #TCQ {DQS_WIDTH{1\'b1}};
+ en_clk_cpt_odd_r <= #TCQ {DQS_WIDTH{1\'b1}};
+ en_clk_rsync_even_r <= #TCQ 4\'b1111;
+ en_clk_rsync_odd_r <= #TCQ 4\'b1111;
+ rst_rsync_pre_r <= #TCQ 1\'b0;
+ end
+ endcase
+ end
+ end
+
+ //*****************************************************************
+ // Reset pipelining - register reset signals to prevent large (and long)
+ // fanouts during physical compilation of the design - in particular when
+ // the design spans multiple I/O columns. Create one for every CPT and
+ // RSYNC clock OSERDES - might be overkill (one per I/O column may be
+ // enough). Note this adds a one cycle delay between when the FSM below
+ // is taken out of reset, and when the OSERDES are taken out of reset -
+ // this should be accounted for by the FSM logic
+ //*****************************************************************
+
+ always @(posedge clk) begin
+ dlyrst_cpt_r <= #TCQ {DQS_WIDTH{dlyrst_cpt}};
+ dlyrst_rsync_r <= #TCQ {4{dlyrst_rsync}};
+ rst_oserdes_cpt_r <= #TCQ {DQS_WIDTH{rst_oserdes}};
+ rst_oserdes_rsync_r <= #TCQ {4{rst_oserdes}};
+ end
+
+ //*****************************************************************
+ // Miscellaneous signals
+ //*****************************************************************
+
+ // NOTE: Deassertion of RST_RSYNC does not have to be synchronous
+ // w/r/t CLK_RSYNC[x] - because CLK_RSYNC[x] is inactive when
+ // reset is deasserted. Note all RST_RSYNC bits will be used -
+ // depends on # of I/O columns used
+ always @(posedge clk)
+ rst_rsync <= #TCQ {4{rst_rsync_pre_r}};
+
+ // Register OCBEXTEND from CPT and RSYNC OSERDES - although these will
+ // be static signals by the time they\'re used by the state machine
+ always @(posedge clk) begin
+ ocbextend_cpt_r <= #TCQ ocbextend_cpt;
+ ocbextend_rsync_r <= #TCQ ocbextend_rsync;
+ end
+
+ //***************************************************************************
+ // Generation for each of the individual DQS group clocks. Also generate
+ // resynchronization clock.
+ // NOTES:
+ // 1. BUFO drives OSERDES which in turn drives corresponding IODELAY
+ // 2. Another mechanism may exist where BUFO drives the IODELAY input
+ // combinationally (bypassing the last stage flip-flop in OSERDES)
+ //***************************************************************************
+
+ //*****************************************************************
+ // Clock forwarding:
+ // Use OSERDES to forward clock even though only basic ODDR
+ // functionality is needed - use case for ODDR connected to
+ // performance path may not be supported, and may later want
+ // to add clock-gating capability to CPT clock to decrease
+ // IODELAY loading time when switching ranks
+ //*****************************************************************
+
+ //*******************************************************
+ // Capture clocks
+ //*******************************************************
+
+ generate
+ genvar ck_i;
+ for (ck_i = 0; ck_i < DQS_WIDTH; ck_i = ck_i+1) begin: gen_ck_cpt
+
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b0),
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""MEMORY_DDR3""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_oserdes_cpt
+ (
+ .OCBEXTEND (ocbextend_cpt[ck_i]),
+ .OFB (cpt_oserdes[ck_i]),
+ .OQ (),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (clk_rd_base),
+ .CLKPERFDELAY (),
+ .D1 (en_clk_cpt_odd_r[ck_i]), // Gating of fwd\'ed clock
+ .D2 (1\'b0),
+ .D3 (en_clk_cpt_even_r[ck_i]), // Gating of fwd\'ed clock
+ .D4 (1\'b0),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (1\'b1),
+ .SHIFTIN1 (),
+ .SHIFTIN2 (),
+ .RST (rst_oserdes_cpt_r[ck_i]),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (wc_oserdes_r)
+ );
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (""TRUE""),
+ .IDELAY_TYPE (""FIXED""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""VARIABLE""),
+ .ODELAY_VALUE (0),
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""CLOCK"")
+ )
+ u_odelay_cpt
+ (
+ .DATAOUT (cpt_odelay[ck_i]),
+ .C (clk),
+ .CE (dlyce_cpt[ck_i]),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (dlyinc_cpt[ck_i]),
+ .ODATAIN (cpt_oserdes[ck_i]),
+ .RST (dlyrst_cpt_r[ck_i]),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (dbg_cpt_tap_cnt[5*ck_i+4:5*ck_i]),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+
+ BUFIO u_bufio_cpt
+ (
+ .I (cpt_odelay[ck_i]),
+ .O (clk_cpt_tmp[ck_i])
+ );
+
+ // Use for simulation purposes only
+ assign #0.1 clk_cpt[ck_i] = clk_cpt_tmp[ck_i];
+
+ end
+ endgenerate
+
+ //*******************************************************
+ // Resynchronization clock
+ //*******************************************************
+
+ generate
+ // I/O column #1
+ if (nDQS_COL0 > 0) begin: gen_loop_col0
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b0),
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""MEMORY_DDR3""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_oserdes_rsync
+ (
+ .OCBEXTEND (ocbextend_rsync[0]),
+ .OFB (rsync_oserdes[0]),
+ .OQ (),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (clk_rd_base),
+ .CLKPERFDELAY (),
+ .D1 (en_clk_rsync_odd_r[0]), // Gating of fwd\'ed clock
+ .D2 (1\'b0),
+ .D3 (en_clk_rsync_even_r[0]),// Gating of fwd\'ed clock
+ .D4 (1\'b0),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (1\'b1),
+ .SHIFTIN1 (),
+ .SHIFTIN2 (),
+ .RST (rst_oserdes_rsync_r[0]),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (wc_oserdes_r)
+ );
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (""TRUE""),
+ .IDELAY_TYPE (""FIXED""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""VARIABLE""),
+ .ODELAY_VALUE (16), // Set at midpt for CLKDIVINV cal
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""CLOCK"")
+ )
+ u_odelay_rsync
+ (
+ .DATAOUT (rsync_odelay[0]),
+ .C (clk),
+ .CE (dlyce_rsync[0]),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (dlyinc_rsync[0]),
+ .ODATAIN (rsync_oserdes[0]),
+ .RST (dlyrst_rsync_r[0]),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (dbg_rsync_tap_cnt[4:0]),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+
+ BUFR #
+ (
+ .BUFR_DIVIDE (""2""),
+ .SIM_DEVICE (""VIRTEX6"")
+ )
+ u_bufr_rsync
+ (
+ .I (rsync_odelay[0]),
+ .O (rsync_bufr[0]),
+ .CE (1\'b1),
+ .CLR (rst_rsync[0])
+ );
+ end
+
+ // I/O column #2
+ if (nDQS_COL1 > 0) begin: gen_loop_col1
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b0),
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""MEMORY_DDR3""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_oserdes_rsync
+ (
+ .OCBEXTEND (ocbextend_rsync[1]),
+ .OFB (rsync_oserdes[1]),
+ .OQ (),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (clk_rd_base),
+ .CLKPERFDELAY (),
+ .D1 (en_clk_rsync_odd_r[1]), // Gating of fwd\'ed clock
+ .D2 (1\'b0),
+ .D3 (en_clk_rsync_even_r[1]),// Gating of fwd\'ed clock
+ .D4 (1\'b0),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (1\'b1),
+ .SHIFTIN1 (),
+ .SHIFTIN2 (),
+ .RST (rst_oserdes_rsync_r[1]),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (wc_oserdes_r)
+ );
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (""TRUE""),
+ .IDELAY_TYPE (""FIXED""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""VARIABLE""),
+ .ODELAY_VALUE (16), // Set at midpt for CLKDIVINV cal
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""CLOCK"")
+ )
+ u_odelay_rsync
+ (
+ .DATAOUT (rsync_odelay[1]),
+ .C (clk),
+ .CE (dlyce_rsync[1]),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (dlyinc_rsync[1]),
+ .ODATAIN (rsync_oserdes[1]),
+ .RST (dlyrst_rsync_r[1]),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (dbg_rsync_tap_cnt[9:5]),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+
+ BUFR #
+ (
+ .BUFR_DIVIDE (""2""),
+ .SIM_DEVICE (""VIRTEX6"")
+ )
+ u_bufr_rsync
+ (
+ .I (rsync_odelay[1]),
+ .O (rsync_bufr[1]),
+ .CE (1\'b1),
+ .CLR (rst_rsync[1])
+ );
+ end
+
+ // I/O column #3
+ if (nDQS_COL2 > 0) begin: gen_loop_col2
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b0),
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""MEMORY_DDR3""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_oserdes_rsync
+ (
+ .OCBEXTEND (ocbextend_rsync[2]),
+ .OFB (rsync_oserdes[2]),
+ .OQ (),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (clk_rd_base),
+ .CLKPERFDELAY (),
+ .D1 (en_clk_rsync_odd_r[2]), // Gating of fwd\'ed clock
+ .D2 (1\'b0),
+ .D3 (en_clk_rsync_even_r[2]),// Gating of fwd\'ed clock
+ .D4 (1\'b0),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (1\'b1),
+ .SHIFTIN1 (),
+ .SHIFTIN2 (),
+ .RST (rst_oserdes_rsync_r[2]),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (wc_oserdes_r)
+ );
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (""TRUE""),
+ .IDELAY_TYPE (""FIXED""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""VARIABLE""),
+ .ODELAY_VALUE (16), // Set at midpt for CLKDIVINV cal
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""CLOCK"")
+ )
+ u_odelay_rsync
+ (
+ .DATAOUT (rsync_odelay[2]),
+ .C (clk),
+ .CE (dlyce_rsync[2]),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (dlyinc_rsync[2]),
+ .ODATAIN (rsync_oserdes[2]),
+ .RST (dlyrst_rsync_r[2]),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (dbg_rsync_tap_cnt[14:10]),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+
+ BUFR #
+ (
+ .BUFR_DIVIDE (""2""),
+ .SIM_DEVICE (""VIRTEX6"")
+ )
+ u_bufr_rsync
+ (
+ .I (rsync_odelay[2]),
+ .O (rsync_bufr[2]),
+ .CE (1\'b1),
+ .CLR (rst_rsync[2])
+ );
+ end
+
+ // I/O column #4
+ if (nDQS_COL3 > 0) begin: gen_loop_col3
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b0),
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""MEMORY_DDR3""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_oserdes_rsync
+ (
+ .OCBEXTEND (ocbextend_rsync[3]),
+ .OFB (rsync_oserdes[3]),
+ .OQ (),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (clk_rd_base),
+ .CLKPERFDELAY (),
+ .D1 (en_clk_rsync_odd_r[3]), // Gating of fwd\'ed clock
+ .D2 (1\'b0),
+ .D3 (en_clk_rsync_even_r[3]),// Gating of fwd\'ed clock
+ .D4 (1\'b0),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (1\'b1),
+ .SHIFTIN1 (),
+ .SHIFTIN2 (),
+ .RST (rst_oserdes_rsync_r[3]),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (wc_oserdes_r)
+ );
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (""TRUE""),
+ .IDELAY_TYPE (""FIXED""), // See CR 511257
+ .IDELAY_VALUE (0), // See CR 511257
+ .ODELAY_TYPE (""VARIABLE""),
+ .ODELAY_VALUE (16), // Set at midpt for CLKDIVINV cal
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""CLOCK"")
+ )
+ u_odelay_rsync
+ (
+ .DATAOUT (rsync_odelay[3]),
+ .C (clk),
+ .CE (dlyce_rsync[3]),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (dlyinc_rsync[3]),
+ .ODATAIN (rsync_oserdes[3]),
+ .RST (dlyrst_rsync_r[3]),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (dbg_rsync_tap_cnt[19:15]),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+
+ BUFR #
+ (
+ .BUFR_DIVIDE (""2""),
+ .SIM_DEVICE (""VIRTEX6"")
+ )
+ u_bufr_rsync
+ (
+ .I (rsync_odelay[3]),
+ .O (rsync_bufr[3]),
+ .CE (1\'b1),
+ .CLR (rst_rsync[3])
+ );
+ end
+ endgenerate
+
+ assign clk_rsync = rsync_bufr;
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2008-2009 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : 3.91
+// \\ \\ Application : MIG
+// / / Filename : ecc_merge_enc.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : Virtex-6
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+`timescale 1ps/1ps
+
+module ecc_merge_enc
+ #(
+ parameter TCQ = 100,
+ parameter PAYLOAD_WIDTH = 64,
+ parameter CODE_WIDTH = 72,
+ parameter DATA_BUF_ADDR_WIDTH = 4,
+ parameter DATA_BUF_OFFSET_WIDTH = 1,
+ parameter DATA_WIDTH = 64,
+ parameter DQ_WIDTH = 72,
+ parameter ECC_WIDTH = 8
+ )
+ (
+ /*AUTOARG*/
+ // Outputs
+ dfi_wrdata, dfi_wrdata_mask,
+ // Inputs
+ clk, rst, wr_data, wr_data_mask, rd_merge_data, h_rows, raw_not_ecc
+ );
+
+ input clk;
+ input rst;
+
+ input [4*PAYLOAD_WIDTH-1:0] wr_data;
+ input [4*DATA_WIDTH/8-1:0] wr_data_mask;
+ input [4*DATA_WIDTH-1:0] rd_merge_data;
+
+ reg [4*PAYLOAD_WIDTH-1:0] wr_data_r;
+ reg [4*DATA_WIDTH/8-1:0] wr_data_mask_r;
+ reg [4*DATA_WIDTH-1:0] rd_merge_data_r;
+
+ always @(posedge clk) wr_data_r <= #TCQ wr_data;
+ always @(posedge clk) wr_data_mask_r <= #TCQ wr_data_mask;
+ always @(posedge clk) rd_merge_data_r <= #TCQ rd_merge_data;
+
+ // Merge new data with memory read data.
+ wire [4*PAYLOAD_WIDTH-1:0] merged_data;
+ genvar h;
+ genvar i;
+ generate
+ for (h=0; h<4; h=h+1) begin : merge_data_outer
+ for (i=0; i DATA_WIDTH)
+ assign merged_data[(h+1)*PAYLOAD_WIDTH-1-:PAYLOAD_WIDTH-DATA_WIDTH]=
+ wr_data_r[(h+1)*PAYLOAD_WIDTH-1-:PAYLOAD_WIDTH-DATA_WIDTH];
+
+ end
+ endgenerate
+
+ // Generate ECC and overlay onto dfi_wrdata.
+ input [CODE_WIDTH*ECC_WIDTH-1:0] h_rows;
+ input [3:0] raw_not_ecc;
+ reg [3:0] raw_not_ecc_r;
+ always @(posedge clk) raw_not_ecc_r <= #TCQ raw_not_ecc;
+ output reg [4*DQ_WIDTH-1:0] dfi_wrdata;
+ genvar j;
+ integer k;
+ generate
+ for (j=0; j<4; j=j+1) begin : ecc_word
+ always @(/*AS*/h_rows or merged_data or raw_not_ecc_r) begin
+ dfi_wrdata[j*DQ_WIDTH+:DQ_WIDTH] =
+ {{DQ_WIDTH-PAYLOAD_WIDTH{1\'b0}},
+ merged_data[j*PAYLOAD_WIDTH+:PAYLOAD_WIDTH]};
+ for (k=0; k| | TX AXI FIFO | |---->| Tx Tx |--------->
+// | | | | | | AXI-S PHY | |
+// | | |_________________| | | I/F I/F | |
+// | | | | | |
+// AXI | | 10/100/1G | | V6 EMAC CORE | |
+// Stream | | ETHERNET FIFO | | BLOCK WRAPPER | | PHY I/F
+// | | | | | |
+// | | _________________ | | | |
+// | | | | | | | |
+// <--------| | RX AXI FIFO | |<----| Rx Rx |<---------
+// | | | | | | AXI-S PHY | |
+// | | |_________________| | | I/F I/F | |
+// | |_____________________| |______________________| |
+// | |
+// |_________________________________________________________|
+//
+
+`timescale 1 ps/1 ps
+
+
+//------------------------------------------------------------------------------
+// The module declaration for the FIFO Block level wrapper.
+//------------------------------------------------------------------------------
+
+module v6_emac_v2_2_fifo_block (
+ input gtx_clk,
+
+ // Receiver Statistics Interface
+ //---------------------------------------
+ output rx_mac_aclk,
+ output rx_reset,
+ output [27:0] rx_statistics_vector,
+ output rx_statistics_valid,
+
+ // Receiver (AXI-S) Interface
+ //----------------------------------------
+ input rx_fifo_clock,
+ input rx_fifo_resetn,
+ output [7:0] rx_axis_fifo_tdata,
+ output rx_axis_fifo_tvalid,
+ input rx_axis_fifo_tready,
+ output rx_axis_fifo_tlast,
+
+ // Transmitter Statistics Interface
+ //------------------------------------------
+ output tx_mac_aclk,
+ output tx_reset,
+ input [7:0] tx_ifg_delay,
+ output [31:0] tx_statistics_vector,
+ output tx_statistics_valid,
+
+ // Transmitter (AXI-S) Interface
+ //-------------------------------------------
+ input tx_fifo_clock,
+ input tx_fifo_resetn,
+ input [7:0] tx_axis_fifo_tdata,
+ input tx_axis_fifo_tvalid,
+ output tx_axis_fifo_tready,
+ input tx_axis_fifo_tlast,
+
+ // MAC Control Interface
+ //------------------------
+ input pause_req,
+ input [15:0] pause_val,
+
+
+ // Reference clock for IDELAYCTRL\'s
+ input refclk,
+
+ // GMII Interface
+ //---------------
+ output [7:0] gmii_txd,
+ output gmii_tx_en,
+ output gmii_tx_er,
+ output gmii_tx_clk,
+ input [7:0] gmii_rxd,
+ input gmii_rx_dv,
+ input gmii_rx_er,
+ input gmii_rx_clk,
+ input gmii_col,
+ input gmii_crs,
+ input mii_tx_clk,
+
+ output mdio_out,
+\t\tinput mdio_in,
+\t\toutput mdc_out,
+\t\toutput mdio_t,
+\t\tinput loopback_enable,
+
+
+ // asynchronous reset
+ //---------------
+ input glbl_rstn,
+ input rx_axi_rstn,
+ input tx_axi_rstn,
+
+\t\toutput reg o_tx_mac_count
+
+ );
+/*
+reg [1:0] tx_mac_done_state;
+
+ //----------------------------------------------------------------------------
+ // Internal signals used in this fifo block level wrapper.
+ //----------------------------------------------------------------------------
+
+ // Note: KEEP attributes preserve signal names so they can be displayed in
+ // simulator wave windows
+
+ wire rx_mac_aclk_int; // MAC Rx clock
+ wire tx_mac_aclk_int; // MAC Tx clock
+
+ wire rx_reset_int; // MAC Rx reset
+ wire tx_reset_int; // MAC Tx reset
+
+ // MAC receiver client I/F
+ (* KEEP = ""TRUE"" *)
+ wire [7:0] rx_axis_mac_tdata;
+
+ (* KEEP = ""TRUE"" *)
+ wire rx_axis_mac_tvalid;
+
+ (* KEEP = ""TRUE"" *)
+ wire rx_axis_mac_tlast;
+
+ (* KEEP = ""TRUE"" *)
+ wire rx_axis_mac_tuser;
+
+ // MAC transmitter client I/F
+ (* KEEP = ""TRUE"" *)
+ wire [7:0] tx_axis_mac_tdata;
+
+ (* KEEP = ""TRUE"" *)
+ wire tx_axis_mac_tvalid;
+
+ (* KEEP = ""TRUE"" *)
+ wire tx_axis_mac_tready;
+
+ (* KEEP = ""TRUE"" *)
+ wire tx_axis_mac_tlast;
+
+ (* KEEP = ""TRUE"" *)
+ wire tx_axis_mac_tuser;
+
+ wire tx_collision;
+ wire tx_retransmit;
+
+
+ //----------------------------------------------------------------------------
+ // Connect the output clock signals
+ //----------------------------------------------------------------------------
+
+ assign rx_mac_aclk = rx_mac_aclk_int;
+ assign tx_mac_aclk = tx_mac_aclk_int;
+ assign rx_reset = rx_reset_int;
+ assign tx_reset = tx_reset_int;
+
+ //----------------------------------------------------------------------------
+ // Instantiate the V6 Hard EMAC Block wrapper
+ //----------------------------------------------------------------------------
+ v6_emac_v2_2_block v6emac_block (
+ .gtx_clk (gtx_clk),
+
+ // Receiver Interface
+ //--------------------------
+ .rx_statistics_vector (rx_statistics_vector),
+ .rx_statistics_valid (rx_statistics_valid),
+
+ .rx_mac_aclk (rx_mac_aclk_int),
+ .rx_reset (rx_reset_int),
+ .rx_axis_mac_tdata (rx_axis_mac_tdata),
+ .rx_axis_mac_tvalid (rx_axis_mac_tvalid),
+ .rx_axis_mac_tlast (rx_axis_mac_tlast),
+ .rx_axis_mac_tuser (rx_axis_mac_tuser),
+
+ // Transmitter Interface
+ //-----------------------------
+ .tx_ifg_delay (tx_ifg_delay),
+ .tx_statistics_vector (tx_statistics_vector),
+ .tx_statistics_valid (tx_statistics_valid),
+
+ .tx_mac_aclk (tx_mac_aclk_int),
+ .tx_reset (tx_reset_int),
+ .tx_axis_mac_tdata (tx_axis_mac_tdata),
+ .tx_axis_mac_tvalid (tx_axis_mac_tvalid),
+ .tx_axis_mac_tlast (tx_axis_mac_tlast),
+ .tx_axis_mac_tuser (tx_axis_mac_tuser),
+ .tx_axis_mac_tready (tx_axis_mac_tready),
+ .tx_collision (tx_collision),
+ .tx_retransmit (tx_retransmit),
+
+ // MAC Control Interface
+ //----------------------
+ .pause_req (pause_req),
+ .pause_val (pause_val),
+
+ // Reference clock for IDELAYCTRL\'s
+ .refclk (refclk),
+
+ // GMII Interface
+ //---------------
+ .gmii_txd (gmii_txd),
+ .gmii_tx_en (gmii_tx_en),
+ .gmii_tx_er (gmii_tx_er),
+ .gmii_tx_clk (gmii_tx_clk),
+ .gmii_rxd (gmii_rxd),
+ .gmii_rx_dv (gmii_rx_dv),
+ .gmii_rx_er (gmii_rx_er),
+ .gmii_rx_clk (gmii_rx_clk),
+ .gmii_col (gmii_col),
+ .gmii_crs (gmii_crs),
+ .mii_tx_clk (mii_tx_clk),
+\t\t.mdio_out (mdio_out),
+\t\t.mdio_in (mdio_in),
+\t\t.mdc_out (mdc_out),
+\t\t.mdio_t (mdio_t),
+\t\t.loopback_enable (loopback_enable),
+
+
+ .glbl_rstn (glbl_rstn),
+ .rx_axi_rstn (rx_axi_rstn),
+ .tx_axi_rstn (tx_axi_rstn)
+
+ );
+
+
+ //----------------------------------------------------------------------------
+ // Instantiate the user side FIFO
+ //----------------------------------------------------------------------------
+ // create inverted mac resets as the FIFO expects AXI compliant resets
+ assign tx_mac_resetn = !tx_reset_int;
+ assign rx_mac_resetn = !rx_reset_int;
+
+ ten_100_1g_eth_fifo #
+ (
+ .FULL_DUPLEX_ONLY (0)
+ )
+ user_side_FIFO
+ (
+ // Transmit FIFO MAC TX Interface
+ .tx_fifo_aclk (tx_fifo_clock),
+ .tx_fifo_resetn (tx_fifo_resetn),
+ .tx_axis_fifo_tdata (tx_axis_fifo_tdata),
+ .tx_axis_fifo_tvalid (tx_axis_fifo_tvalid),
+ .tx_axis_fifo_tlast (tx_axis_fifo_tlast),
+ .tx_axis_fifo_tready (tx_axis_fifo_tready),
+
+ .tx_mac_aclk (tx_mac_aclk_int),
+ .tx_mac_resetn (tx_mac_resetn),
+ .tx_axis_mac_tdata (tx_axis_mac_tdata),
+ .tx_axis_mac_tvalid (tx_axis_mac_tvalid),
+ .tx_axis_mac_tlast (tx_axis_mac_tlast),
+ .tx_axis_mac_tready (tx_axis_mac_tready),
+ .tx_axis_mac_tuser (tx_axis_mac_tuser),
+
+ .tx_fifo_overflow (),
+ .tx_fifo_status (),
+ .tx_collision (tx_collision),
+ .tx_retransmit (tx_retransmit),
+
+ .rx_fifo_aclk (rx_fifo_clock),
+ .rx_fifo_resetn (rx_fifo_resetn),
+ .rx_axis_fifo_tdata (rx_axis_fifo_tdata),
+ .rx_axis_fifo_tvalid (rx_axis_fifo_tvalid),
+ .rx_axis_fifo_tlast (rx_axis_fifo_tlast),
+ .rx_axis_fifo_tready (rx_axis_fifo_tready),
+
+ .rx_mac_aclk (rx_mac_aclk_int),
+ .rx_mac_resetn (rx_mac_resetn),
+ .rx_axis_mac_tdata (rx_axis_mac_tdata),
+ .rx_axis_mac_tvalid (rx_axis_mac_tvalid),
+ .rx_axis_mac_tlast (rx_axis_mac_tlast),
+ .rx_axis_mac_tready (), // not used as MAC cannot throttle
+ .rx_axis_mac_tuser (rx_axis_mac_tuser),
+
+ .rx_fifo_status (),
+ .rx_fifo_overflow ()
+ );
+
+always @ (posedge tx_mac_aclk_int)
+begin
+\tif (tx_reset_int) begin
+\t\ttx_mac_done_state <= 2\'d0;
+\t\to_tx_mac_count <= 1\'b0;
+\tend
+\telse begin
+\t\to_tx_mac_count <= 1\'b0;
+\t\tcase (tx_mac_done_state)
+\t\t2\'d0 : begin
+\t\t\tif (tx_axis_mac_tvalid)
+\t\t\t\ttx_mac_done_state <= 2\'d1;
+\t\tend
+\t\t2\'d1 : begin
+\t\t\tif (tx_collision || tx_retransmit)
+\t\t\t\tif (tx_axis_mac_tlast)
+\t\t\t\t\ttx_mac_done_state <= 2\'d2;
+\t\t\t\telse
+\t\t\t\t\ttx_mac_done_state <= 2\'d3;
+\t\t\telse if (tx_axis_mac_tlast) begin
+\t\t\t\ttx_mac_done_state <= 2\'d2;
+\t\t\t\to_tx_mac_count <= 1\'b1;
+\t\t\tend
+\t\tend
+\t\t2\'d2 : tx_mac_done_state <= 2\'d0;
+\t\t2\'d3 : if (tx_axis_mac_tlast)
+\t\t\ttx_mac_done_state <= 2\'d0;
+\t\tendcase
+\tend
+end
+\t\t\t
+*/
+endmodule
+"
+"//-----------------------------------------------------------------------------
+//
+// (c) Copyright 2010-2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//-----------------------------------------------------------------------------
+// Project : Series-7 Integrated Block for PCI Express
+// File : pcie_7x_v1_8_axi_basic_tx_pipeline.v
+// Version : 1.7
+// //
+// Description: //
+// AXI to TRN TX pipeline. Converts transmitted data from AXI protocol to //
+// TRN. //
+// //
+// Notes: //
+// Optional notes section. //
+// //
+// Hierarchical: //
+// axi_basic_top //
+// axi_basic_tx //
+// axi_basic_tx_pipeline //
+// //
+//----------------------------------------------------------------------------//
+
+`timescale 1ps/1ps
+
+module pcie_7x_v1_8_axi_basic_tx_pipeline #(
+ parameter C_DATA_WIDTH = 128, // RX/TX interface data width
+ parameter C_PM_PRIORITY = ""FALSE"", // Disable TX packet boundary thrtl
+ parameter TCQ = 1, // Clock to Q time
+
+ // Do not override parameters below this line
+ parameter REM_WIDTH = (C_DATA_WIDTH == 128) ? 2 : 1, // trem/rrem width
+ parameter KEEP_WIDTH = C_DATA_WIDTH / 8 // KEEP width
+ ) (
+ //---------------------------------------------//
+ // User Design I/O //
+ //---------------------------------------------//
+
+ // AXI TX
+ //-----------
+ input [C_DATA_WIDTH-1:0] s_axis_tx_tdata, // TX data from user
+ input s_axis_tx_tvalid, // TX data is valid
+ output s_axis_tx_tready, // TX ready for data
+ input [KEEP_WIDTH-1:0] s_axis_tx_tkeep, // TX strobe byte enables
+ input s_axis_tx_tlast, // TX data is last
+ input [3:0] s_axis_tx_tuser, // TX user signals
+
+ //---------------------------------------------//
+ // PCIe Block I/O //
+ //---------------------------------------------//
+
+ // TRN TX
+ //-----------
+ output [C_DATA_WIDTH-1:0] trn_td, // TX data from block
+ output trn_tsof, // TX start of packet
+ output trn_teof, // TX end of packet
+ output trn_tsrc_rdy, // TX source ready
+ input trn_tdst_rdy, // TX destination ready
+ output trn_tsrc_dsc, // TX source discontinue
+ output [REM_WIDTH-1:0] trn_trem, // TX remainder
+ output trn_terrfwd, // TX error forward
+ output trn_tstr, // TX streaming enable
+ output trn_tecrc_gen, // TX ECRC generate
+ input trn_lnk_up, // PCIe link up
+
+ // System
+ //-----------
+ input tready_thrtl, // TREADY from thrtl ctl
+ input user_clk, // user clock from block
+ input user_rst // user reset from block
+);
+
+
+// Input register stage
+reg [C_DATA_WIDTH-1:0] reg_tdata;
+reg reg_tvalid;
+reg [KEEP_WIDTH-1:0] reg_tkeep;
+reg [3:0] reg_tuser;
+reg reg_tlast;
+reg reg_tready;
+
+// Pipeline utility signals
+reg trn_in_packet;
+reg axi_in_packet;
+reg flush_axi;
+wire disable_trn;
+reg reg_disable_trn;
+
+wire axi_beat_live = s_axis_tx_tvalid && s_axis_tx_tready;
+wire axi_end_packet = axi_beat_live && s_axis_tx_tlast;
+
+
+//----------------------------------------------------------------------------//
+// Convert TRN data format to AXI data format. AXI is DWORD swapped from TRN. //
+// 128-bit: 64-bit: 32-bit: //
+// TRN DW0 maps to AXI DW3 TRN DW0 maps to AXI DW1 TNR DW0 maps to AXI DW0 //
+// TRN DW1 maps to AXI DW2 TRN DW1 maps to AXI DW0 //
+// TRN DW2 maps to AXI DW1 //
+// TRN DW3 maps to AXI DW0 //
+//----------------------------------------------------------------------------//
+generate
+ if(C_DATA_WIDTH == 128) begin : td_DW_swap_128
+ assign trn_td = {reg_tdata[31:0],
+ reg_tdata[63:32],
+ reg_tdata[95:64],
+ reg_tdata[127:96]};
+ end
+ else if(C_DATA_WIDTH == 64) begin : td_DW_swap_64
+ assign trn_td = {reg_tdata[31:0], reg_tdata[63:32]};
+ end
+ else begin : td_DW_swap_32
+ assign trn_td = reg_tdata;
+ end
+endgenerate
+
+
+//----------------------------------------------------------------------------//
+// Create trn_tsof. If we\'re not currently in a packet and TVALID goes high, //
+// assert TSOF. //
+//----------------------------------------------------------------------------//
+assign trn_tsof = reg_tvalid && !trn_in_packet;
+
+
+//----------------------------------------------------------------------------//
+// Create trn_in_packet. This signal tracks if the TRN interface is currently //
+// in the middle of a packet, which is needed to generate trn_tsof //
+//----------------------------------------------------------------------------//
+always @(posedge user_clk) begin
+ if(user_rst) begin
+ trn_in_packet <= #TCQ 1\'b0;
+ end
+ else begin
+ if(trn_tsof && trn_tsrc_rdy && trn_tdst_rdy && !trn_teof) begin
+ trn_in_packet <= #TCQ 1\'b1;
+ end
+ else if((trn_in_packet && trn_teof && trn_tsrc_rdy) || !trn_lnk_up) begin
+ trn_in_packet <= #TCQ 1\'b0;
+ end
+ end
+end
+
+
+//----------------------------------------------------------------------------//
+// Create axi_in_packet. This signal tracks if the AXI interface is currently //
+// in the middle of a packet, which is needed in case the link goes down. //
+//----------------------------------------------------------------------------//
+always @(posedge user_clk) begin
+ if(user_rst) begin
+ axi_in_packet <= #TCQ 1\'b0;
+ end
+ else begin
+ if(axi_beat_live && !s_axis_tx_tlast) begin
+ axi_in_packet <= #TCQ 1\'b1;
+ end
+ else if(axi_beat_live) begin
+ axi_in_packet <= #TCQ 1\'b0;
+ end
+ end
+end
+
+
+//----------------------------------------------------------------------------//
+// Create disable_trn. This signal asserts when the link goes down and //
+// triggers the deassertiong of trn_tsrc_rdy. The deassertion of disable_trn //
+// depends on C_PM_PRIORITY, as described below. //
+//----------------------------------------------------------------------------//
+generate
+ // In the C_PM_PRIORITY pipeline, we disable the TRN interfacefrom the time
+ // the link goes down until the the AXI interface is ready to accept packets
+ // again (via assertion of TREADY). By waiting for TREADY, we allow the
+ // previous value buffer to fill, so we\'re ready for any throttling by the
+ // user or the block.
+ if(C_PM_PRIORITY == ""TRUE"") begin : pm_priority_trn_flush
+ always @(posedge user_clk) begin
+ if(user_rst) begin
+ reg_disable_trn <= #TCQ 1\'b1;
+ end
+ else begin
+ // When the link goes down, disable the TRN interface.
+ if(!trn_lnk_up)
+ begin
+ reg_disable_trn <= #TCQ 1\'b1;
+ end
+
+ // When the link comes back up and the AXI interface is ready, we can
+ // release the pipeline and return to normal operation.
+ else if(!flush_axi && s_axis_tx_tready) begin
+ reg_disable_trn <= #TCQ 1\'b0;
+ end
+ end
+ end
+
+ assign disable_trn = reg_disable_trn;
+ end
+
+ // In the throttle-controlled pipeline, we don\'t have a previous value buffer.
+ // The throttle control mechanism handles TREADY, so all we need to do is
+ // detect when the link goes down and disable the TRN interface until the link
+ // comes back up and the AXI interface is finished flushing any packets.
+ else begin : thrtl_ctl_trn_flush
+ always @(posedge user_clk) begin
+ if(user_rst) begin
+ reg_disable_trn <= #TCQ 1\'b0;
+ end
+ else begin
+ // If the link is down and AXI is in packet, disable TRN and look for
+ // the end of the packet
+ if(axi_in_packet && !trn_lnk_up && !axi_end_packet)
+ begin
+ reg_disable_trn <= #TCQ 1\'b1;
+ end
+
+ // AXI packet is ending, so we\'re done flushing
+ else if(axi_end_packet) begin
+ reg_disable_trn <= #TCQ 1\'b0;
+ end
+ end
+ end
+
+ // Disable the TRN interface if link is down or we\'re still flushing the AXI
+ // interface.
+ assign disable_trn = reg_disable_trn || !trn_lnk_up;
+ end
+endgenerate
+
+
+//----------------------------------------------------------------------------//
+// Convert STRB to RREM. Here, we are converting the encoding method for the //
+// location of the EOF from AXI (tkeep) to TRN flavor (rrem). //
+//----------------------------------------------------------------------------//
+generate
+ if(C_DATA_WIDTH == 128) begin : tkeep_to_trem_128
+ //---------------------------------------//
+ // Conversion table: //
+ // trem | tkeep //
+ // [1] [0] | [15:12] [11:8] [7:4] [3:0] //
+ // ------------------------------------- //
+ // 1 1 | D3 D2 D1 D0 //
+ // 1 0 | -- D2 D1 D0 //
+ // 0 1 | -- -- D1 D0 //
+ // 0 0 | -- -- -- D0 //
+ //---------------------------------------//
+
+ wire axi_DW_1 = reg_tkeep[7];
+ wire axi_DW_2 = reg_tkeep[11];
+ wire axi_DW_3 = reg_tkeep[15];
+ assign trn_trem[1] = axi_DW_2;
+ assign trn_trem[0] = axi_DW_3 || (axi_DW_1 && !axi_DW_2);
+ end
+ else if(C_DATA_WIDTH == 64) begin : tkeep_to_trem_64
+ assign trn_trem = reg_tkeep[7];
+ end
+ else begin : tkeep_to_trem_32
+ assign trn_trem = 1\'b0;
+ end
+endgenerate
+
+
+//----------------------------------------------------------------------------//
+// Create remaining TRN signals //
+//----------------------------------------------------------------------------//
+assign trn_teof = reg_tlast;
+assign trn_tecrc_gen = reg_tuser[0];
+assign trn_terrfwd = reg_tuser[1];
+assign trn_tstr = reg_tuser[2];
+assign trn_tsrc_dsc = reg_tuser[3];
+
+
+//----------------------------------------------------------------------------//
+// Pipeline stage //
+//----------------------------------------------------------------------------//
+// We need one of two approaches for the pipeline stage depending on the
+// C_PM_PRIORITY parameter.
+generate
+ reg reg_tsrc_rdy;
+
+ // If set to FALSE, that means the user wants to use the TX packet boundary
+ // throttling feature. Since all Block throttling will now be predicted, we
+ // can use a simple straight-through pipeline.
+ if(C_PM_PRIORITY == ""FALSE"") begin : throttle_ctl_pipeline
+ always @(posedge user_clk) begin
+ if(user_rst) begin
+ reg_tdata <= #TCQ {C_DATA_WIDTH{1\'b0}};
+ reg_tvalid <= #TCQ 1\'b0;
+ reg_tkeep <= #TCQ {KEEP_WIDTH{1\'b0}};
+ reg_tlast <= #TCQ 1\'b0;
+ reg_tuser <= #TCQ 4\'h0;
+ reg_tsrc_rdy <= #TCQ 1\'b0;
+ end
+ else begin
+ reg_tdata <= #TCQ s_axis_tx_tdata;
+ reg_tvalid <= #TCQ s_axis_tx_tvalid;
+ reg_tkeep <= #TCQ s_axis_tx_tkeep;
+ reg_tlast <= #TCQ s_axis_tx_tlast;
+ reg_tuser <= #TCQ s_axis_tx_tuser;
+
+ // Hold trn_tsrc_rdy low when flushing a packet.
+ reg_tsrc_rdy <= #TCQ axi_beat_live && !disable_trn;
+ end
+ end
+
+ assign trn_tsrc_rdy = reg_tsrc_rdy;
+
+ // With TX packet boundary throttling, TREADY is pipelined in
+ // axi_basic_tx_thrtl_ctl and wired through here.
+ assign s_axis_tx_tready = tready_thrtl;
+ end
+
+ //**************************************************************************//
+
+ // If C_PM_PRIORITY is set to TRUE, that means the user prefers to have all PM
+ // functionality intact isntead of TX packet boundary throttling. Now the
+ // Block could back-pressure at any time, which creates the standard problem
+ // of potential data loss due to the handshaking latency. Here we need a
+ // previous value buffer, just like the RX data path.
+ else begin : pm_prioity_pipeline
+ reg [C_DATA_WIDTH-1:0] tdata_prev;
+ reg tvalid_prev;
+ reg [KEEP_WIDTH-1:0] tkeep_prev;
+ reg tlast_prev;
+ reg [3:0] tuser_prev;
+ reg reg_tdst_rdy;
+
+ wire data_hold;
+ reg data_prev;
+
+
+ //------------------------------------------------------------------------//
+ // Previous value buffer //
+ // --------------------- //
+ // We are inserting a pipeline stage in between AXI and TRN, which causes //
+ // some issues with handshaking signals trn_tsrc_rdy/s_axis_tx_tready. //
+ // The added cycle of latency in the path causes the Block to fall behind //
+ // the AXI interface whenever it throttles. //
+ // //
+ // To avoid loss of data, we must keep the previous value of all //
+ // s_axis_tx_* signals in case the Block throttles. //
+ //------------------------------------------------------------------------//
+ always @(posedge user_clk) begin
+ if(user_rst) begin
+ tdata_prev <= #TCQ {C_DATA_WIDTH{1\'b0}};
+ tvalid_prev <= #TCQ 1\'b0;
+ tkeep_prev <= #TCQ {KEEP_WIDTH{1\'b0}};
+ tlast_prev <= #TCQ 1\'b0;
+ tuser_prev <= #TCQ 4\'h 0;
+ end
+ else begin
+ // prev buffer works by checking s_axis_tx_tready. When
+ // s_axis_tx_tready is asserted, a new value is present on the
+ // interface.
+ if(!s_axis_tx_tready) begin
+ tdata_prev <= #TCQ tdata_prev;
+ tvalid_prev <= #TCQ tvalid_prev;
+ tkeep_prev <= #TCQ tkeep_prev;
+ tlast_prev <= #TCQ tlast_prev;
+ tuser_prev <= #TCQ tuser_prev;
+ end
+ else begin
+ tdata_prev <= #TCQ s_axis_tx_tdata;
+ tvalid_prev <= #TCQ s_axis_tx_tvalid;
+ tkeep_prev <= #TCQ s_axis_tx_tkeep;
+ tlast_prev <= #TCQ s_axis_tx_tlast;
+ tuser_prev <= #TCQ s_axis_tx_tuser;
+ end
+ end
+ end
+
+ // Create special buffer which locks in the proper value of TDATA depending
+ // on whether the user is throttling or not. This buffer has three states:
+ //
+ // HOLD state: TDATA maintains its current value
+ // - the Block has throttled the PCIe block
+ // PREVIOUS state: the buffer provides the previous value on TDATA
+ // - the Block has finished throttling, and is a little
+ // behind the user
+ // CURRENT state: the buffer passes the current value on TDATA
+ // - the Block is caught up and ready to receive the
+ // latest data from the user
+ always @(posedge user_clk) begin
+ if(user_rst) begin
+ reg_tdata <= #TCQ {C_DATA_WIDTH{1\'b0}};
+ reg_tvalid <= #TCQ 1\'b0;
+ reg_tkeep <= #TCQ {KEEP_WIDTH{1\'b0}};
+ reg_tlast <= #TCQ 1\'b0;
+ reg_tuser <= #TCQ 4\'h0;
+
+ reg_tdst_rdy <= #TCQ 1\'b0;
+ end
+ else begin
+ reg_tdst_rdy <= #TCQ trn_tdst_rdy;
+
+ if(!data_hold) begin
+ // PREVIOUS state
+ if(data_prev) begin
+ reg_tdata <= #TCQ tdata_prev;
+ reg_tvalid <= #TCQ tvalid_prev;
+ reg_tkeep <= #TCQ tkeep_prev;
+ reg_tlast <= #TCQ tlast_prev;
+ reg_tuser <= #TCQ tuser_prev;
+ end
+
+ // CURRENT state
+ else begin
+ reg_tdata <= #TCQ s_axis_tx_tdata;
+ reg_tvalid <= #TCQ s_axis_tx_tvalid;
+ reg_tkeep <= #TCQ s_axis_tx_tkeep;
+ reg_tlast <= #TCQ s_axis_tx_tlast;
+ reg_tuser <= #TCQ s_axis_tx_tuser;
+ end
+ end
+ // else HOLD state
+ end
+ end
+
+
+ // Logic to instruct pipeline to hold its value
+ assign data_hold = trn_tsrc_rdy && !trn_tdst_rdy;
+
+
+ // Logic to instruct pipeline to use previous bus values. Always use
+ // previous value after holding a value.
+ always @(posedge user_clk) begin
+ if(user_rst) begin
+ data_prev <= #TCQ 1\'b0;
+ end
+ else begin
+ data_prev <= #TCQ data_hold;
+ end
+ end
+
+
+ //------------------------------------------------------------------------//
+ // Create trn_tsrc_rdy. If we\'re flushing the TRN hold trn_tsrc_rdy low. //
+ //------------------------------------------------------------------------//
+ assign trn_tsrc_rdy = reg_tvalid && !disable_trn;
+
+
+ //------------------------------------------------------------------------//
+ // Create TREADY //
+ //------------------------------------------------------------------------//
+ always @(posedge user_clk) begin
+ if(user_rst) begin
+ reg_tready <= #TCQ 1\'b0;
+ end
+ else begin
+ // If the link went down and we need to flush a packet in flight, hold
+ // TREADY high
+ if(flush_axi && !axi_end_packet) begin
+ reg_tready <= #TCQ 1\'b1;
+ end
+
+ // If the link is up, TREADY is as follows:
+ // TREADY = 1 when trn_tsrc_rdy == 0
+ // - While idle, keep the pipeline primed and ready for the next
+ // packet
+ //
+ // TREADY = trn_tdst_rdy when trn_tsrc_rdy == 1
+ // - While in packet, throttle pipeline based on state of TRN
+ else if(trn_lnk_up) begin
+ reg_tready <= #TCQ trn_tdst_rdy || !trn_tsrc_rdy;
+ end
+
+ // If the link is down and we\'re not flushing a packet, hold TREADY low
+ // wait for link to come back up
+ else begin
+ reg_tready <= #TCQ 1\'b0;
+ end
+ end
+ end
+
+ assign s_axis_tx_tready = reg_tready;
+ end
+
+
+ //--------------------------------------------------------------------------//
+ // Create flush_axi. This signal detects if the link goes down while the //
+ // AXI interface is in packet. In this situation, we need to flush the //
+ // packet through the AXI interface and discard it. //
+ //--------------------------------------------------------------------------//
+ always @(posedge user_clk) begin
+ if(user_rst) begin
+ flush_axi <= #TCQ 1\'b0;
+ end
+ else begin
+ // If the AXI interface is in packet and the link goes down, purge it.
+ if(axi_in_packet && !trn_lnk_up && !axi_end_packet) begin
+ flush_axi <= #TCQ 1\'b1;
+ end
+
+ // The packet is finished, so we\'re done flushing.
+ else if(axi_end_packet) begin
+ flush_axi <= #TCQ 1\'b0;
+ end
+ end
+ end
+endgenerate
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2009 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor: Xilinx
+// \\ \\ \\/ Version: 3.91
+// \\ \\ Application: MIG
+// / / Filename: phy_clock_io.v
+// /___/ /\\ Date Last Modified: $Date: 2011/06/02 07:18:02 $
+// \\ \\ / \\ Date Created: Aug 03 2009
+// \\___\\/\\___\\
+//
+//Device: Virtex-6
+//Design Name: DDR3 SDRAM
+//Purpose:
+//Purpose:
+// Top-level for CK/CK# clock forwarding to memory
+//Reference:
+//Revision History:
+//*****************************************************************************
+
+/******************************************************************************
+**$Id: phy_clock_io.v,v 1.1 2011/06/02 07:18:02 mishra Exp $
+**$Date: 2011/06/02 07:18:02 $
+**$Author: mishra $
+**$Revision: 1.1 $
+**$Source: /devl/xcs/repo/env/Databases/ip/src2/O/mig_v3_9/data/dlib/virtex6/ddr3_sdram/verilog/rtl/phy/phy_clock_io.v,v $
+******************************************************************************/
+
+`timescale 1ps/1ps
+
+module phy_clock_io #
+ (
+ parameter TCQ = 100, // clk->out delay (sim only)
+ parameter CK_WIDTH = 2, // # of clock output pairs
+ parameter WRLVL = ""OFF"", // Enable write leveling
+ parameter DRAM_TYPE = ""DDR3"", // Memory I/F type: ""DDR3"", ""DDR2""
+ parameter REFCLK_FREQ = 300.0, // IODELAY Reference Clock freq (MHz)
+ parameter IODELAY_GRP = ""IODELAY_MIG"" // May be assigned unique name
+ // when mult IP cores in design
+ )
+ (
+ input clk_mem, // full rate core clock
+ input clk, // half rate core clock
+ input rst, // half rate core clk reset
+ output [CK_WIDTH-1:0] ddr_ck_p, // forwarded diff. clock to memory
+ output [CK_WIDTH-1:0] ddr_ck_n // forwarded diff. clock to memory
+ );
+
+ //***************************************************************************
+
+ generate
+ genvar ck_i;
+ for (ck_i = 0; ck_i < CK_WIDTH; ck_i = ck_i + 1) begin: gen_ck
+ phy_ck_iob #
+ (
+ .TCQ (TCQ),
+ .WRLVL (WRLVL),
+ .DRAM_TYPE (DRAM_TYPE),
+ .REFCLK_FREQ (REFCLK_FREQ),
+ .IODELAY_GRP (IODELAY_GRP)
+ )
+ u_phy_ck_iob
+ (
+ .clk_mem (clk_mem),
+ .clk (clk),
+ .rst (rst),
+ .ddr_ck_p (ddr_ck_p[ck_i]),
+ .ddr_ck_n (ddr_ck_n[ck_i])
+ );
+ end
+ endgenerate
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2009 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor: Xilinx
+// \\ \\ \\/ Version: 3.91
+// \\ \\ Application: MIG
+// / / Filename: phy_wrlvl.v
+// /___/ /\\ Date Last Modified: $Date: 2011/06/02 07:18:04 $
+// \\ \\ / \\ Date Created: Mon Jun 23 2008
+// \\___\\/\\___\\
+//
+//Device: Virtex-6
+//Design Name: DDR3 SDRAM
+//Purpose:
+// Memory initialization and overall master state control during
+// initialization and calibration. Specifically, the following functions
+// are performed:
+// 1. Memory initialization (initial AR, mode register programming, etc.)
+// 2. Initiating write leveling
+// 3. Generate training pattern writes for read leveling. Generate
+// memory readback for read leveling.
+// This module has a DFI interface for providing control/address and write
+// data to the rest of the PHY datapath during initialization/calibration.
+// Once initialization is complete, control is passed to the MC.
+// NOTES:
+// 1. Multiple CS (multi-rank) not supported
+// 2. DDR2 not supported
+// 3. ODT not supported
+//Reference:
+//Revision History:
+//*****************************************************************************
+
+/******************************************************************************
+**$Id: phy_wrlvl.v,v 1.1 2011/06/02 07:18:04 mishra Exp $
+**$Date: 2011/06/02 07:18:04 $
+**$Author: mishra $
+**$Revision: 1.1 $
+**$Source: /devl/xcs/repo/env/Databases/ip/src2/O/mig_v3_9/data/dlib/virtex6/ddr3_sdram/verilog/rtl/phy/phy_wrlvl.v,v $
+******************************************************************************/
+
+`timescale 1ps/1ps
+
+module phy_wrlvl #
+ (
+ parameter TCQ = 100,
+ parameter DQS_CNT_WIDTH = 3,
+ parameter DQ_WIDTH = 64,
+ parameter SHIFT_TBY4_TAP = 7,
+ parameter DQS_WIDTH = 2,
+ parameter DRAM_WIDTH = 8,
+ parameter CS_WIDTH = 1,
+ parameter CAL_WIDTH = ""HALF"",
+ parameter DQS_TAP_CNT_INDEX = 42,
+ parameter SIM_CAL_OPTION = ""NONE""
+ )
+ (
+ input clk,
+ input rst,
+ input [2:0] calib_width,
+ input [1:0] rank_cnt,
+ input wr_level_start,
+ input wl_sm_start,
+ input [(DQ_WIDTH)-1:0] rd_data_rise0,
+ // indicates read level stage 2 error
+ input rdlvl_error,
+ // read level stage 2 failing byte
+ input [DQS_CNT_WIDTH-1:0] rdlvl_err_byte,
+ input [1:0] rdlvl_done,
+
+ output wr_level_done,
+ // to phy_init for cs logic
+ output wrlvl_rank_done,
+ output [DQS_TAP_CNT_INDEX:0] dlyval_wr_dqs,
+ output [DQS_TAP_CNT_INDEX:0] dlyval_wr_dq,
+ output [DQS_WIDTH-1:0] inv_dqs,
+ // resume read level stage 2 with write bit slip adjust
+ output reg rdlvl_resume,
+ //write bit slip adjust
+ output [2*DQS_WIDTH-1:0] wr_calib_dly,
+ output reg wrcal_err,
+ output reg wrlvl_err,
+ // Debug ports
+ output [4:0] dbg_wl_tap_cnt,
+ output dbg_wl_edge_detect_valid,
+ output [(DQS_WIDTH)-1:0] dbg_rd_data_edge_detect,
+ output [(DQS_WIDTH)-1:0] dbg_rd_data_inv_edge_detect,
+ output [DQS_CNT_WIDTH:0] dbg_dqs_count,
+ output [3:0] dbg_wl_state
+ );
+
+
+ localparam WL_IDLE = 4\'h0;
+ localparam WL_INIT = 4\'h1;
+ localparam WL_DEL_INC = 4\'h2;
+ localparam WL_WAIT = 4\'h3;
+ localparam WL_EDGE_CHECK = 4\'h4;
+ localparam WL_DQS_CHECK = 4\'h5;
+ localparam WL_DQS_CNT = 4\'h6;
+ localparam WL_INV_DQS = 4\'h7;
+ localparam WL_WAIT_DQ = 4\'h8;
+
+
+ integer d, e, f, g, h, i, j, k, l, m, n, p, q, r, s;
+
+ reg [DQS_CNT_WIDTH:0] dqs_count_r;
+ reg [DQS_CNT_WIDTH:0] dqs_count_rep1;
+ reg [DQS_CNT_WIDTH:0] dqs_count_rep2;
+ reg [DQS_CNT_WIDTH-1:0] rdlvl_err_byte_r;
+ reg [1:0] rank_cnt_r;
+ reg [DQS_WIDTH-1:0] rd_data_rise_wl_r;
+ reg [DQS_WIDTH-1:0] rd_data_previous_r;
+ reg [DQS_WIDTH-1:0] rd_data_inv_dqs_previous_r;
+ reg [DQS_WIDTH-1:0] rd_data_edge_detect_r;
+ reg [DQS_WIDTH-1:0] rd_data_inv_edge_detect_r;
+ reg wr_level_done_r;
+ reg wrlvl_rank_done_r;
+ reg wr_level_start_r;
+ reg [3:0] wl_state_r, wl_state_r1;
+ reg wl_edge_detect_valid_r;
+ reg [4:0] wl_tap_count_r;
+ reg [5*DQS_WIDTH-1:0] wl_dqs_tap_count_r[0:CS_WIDTH-1];
+ reg rdlvl_error_r;
+ reg rdlvl_error_r1;
+ reg rdlvl_resume_r;
+ reg rdlvl_resume_r1;
+ reg rdlvl_resume_r2;
+ reg rdlvl_done_r1;
+ reg [2*DQS_WIDTH-1:0] wr_calib_dly_r;
+ reg [DQS_WIDTH-1:0] set_one_flag;
+ reg [DQS_WIDTH-1:0] set_two_flag;
+ reg [DQS_WIDTH-1:0] inv_dqs_wl;
+ reg [DQS_WIDTH-1:0] inv_dqs_r[0:CS_WIDTH-1];
+ reg [5*DQS_WIDTH-1:0] dlyval_wr_dqs_r[0:CS_WIDTH-1];
+ reg [5*DQS_WIDTH-1:0] dlyval_wr_dq_r[0:CS_WIDTH-1];
+ reg [DQS_WIDTH-1:0] inv_dqs_wl_r[0:CS_WIDTH-1];
+ reg [2*DQS_WIDTH-1:0] wr_calib_dly_r1[0:CS_WIDTH-1];
+ reg [1:0] tmp_calib_dly_r;
+ reg [4:0] dq_tap_wl[0:DQS_WIDTH-1];
+ reg [4:0] dq_tap[0:CS_WIDTH-1][0:DQS_WIDTH-1];
+ reg dq_cnt_inc;
+
+ reg [1:0] stable_cnt;
+ reg [1:0] inv_stable_cnt;
+
+
+
+ // Debug ports
+ assign dbg_wl_edge_detect_valid = wl_edge_detect_valid_r;
+ assign dbg_rd_data_edge_detect = rd_data_edge_detect_r;
+ assign dbg_rd_data_inv_edge_detect = rd_data_inv_edge_detect_r;
+ assign dbg_wl_tap_cnt = wl_tap_count_r;
+ assign dbg_dqs_count = dqs_count_r;
+ assign dbg_wl_state = wl_state_r;
+
+
+ assign dlyval_wr_dqs = dlyval_wr_dqs_r[rank_cnt];
+ assign dlyval_wr_dq = dlyval_wr_dq_r[rank_cnt];
+ assign inv_dqs = inv_dqs_wl_r[rank_cnt];
+ assign wr_calib_dly = wr_calib_dly_r1[rank_cnt];
+
+ generate
+ genvar cal_i;
+ for (cal_i = 0; cal_i < CS_WIDTH; cal_i = cal_i + 1) begin: gen_rank
+ always @(posedge clk) begin
+ if (rst) begin
+ inv_dqs_wl_r[cal_i] <= #TCQ {DQS_WIDTH{1\'b0}};
+ dlyval_wr_dqs_r[cal_i] <= #TCQ {5*DQS_WIDTH{1\'b0}};
+ end else begin
+ inv_dqs_wl_r[cal_i] <= #TCQ inv_dqs_r[cal_i];
+ dlyval_wr_dqs_r[cal_i] <= #TCQ wl_dqs_tap_count_r[cal_i];
+ end
+ end
+ end
+ endgenerate
+
+
+ always @(posedge clk) begin
+ if (rst) begin
+ for (i = 0; i < CS_WIDTH; i = i + 1) begin: rst_wr_calib_dly_r1_loop
+ wr_calib_dly_r1[i] <= #TCQ \'b0;
+ end
+ end else begin
+ wr_calib_dly_r1[rank_cnt] <= #TCQ wr_calib_dly_r;
+ if (CS_WIDTH == 4) begin
+ wr_calib_dly_r1[1] <= #TCQ wr_calib_dly_r1[0];
+ wr_calib_dly_r1[2] <= #TCQ wr_calib_dly_r1[0];
+ wr_calib_dly_r1[3] <= #TCQ wr_calib_dly_r1[0];
+ end else if (CS_WIDTH == 3) begin
+ wr_calib_dly_r1[1] <= #TCQ wr_calib_dly_r1[0];
+ wr_calib_dly_r1[2] <= #TCQ wr_calib_dly_r1[0];
+ end else if (CS_WIDTH == 2)
+ wr_calib_dly_r1[1] <= #TCQ wr_calib_dly_r1[0];
+ end
+ end
+
+
+ assign wr_level_done = wr_level_done_r;
+ assign wrlvl_rank_done = wrlvl_rank_done_r;
+
+
+ // only storing the rise data for checking. The data comming back during
+ // write leveling will be a static value. Just checking for rise data is
+ // enough.
+
+genvar rd_i;
+generate
+ for(rd_i = 0; rd_i < DQS_WIDTH; rd_i = rd_i +1)begin: gen_rd
+ always @(posedge clk)
+ rd_data_rise_wl_r[rd_i] <=
+ #TCQ |rd_data_rise0[(rd_i*DRAM_WIDTH)+DRAM_WIDTH-1:rd_i*DRAM_WIDTH];
+ end
+endgenerate
+
+
+ // storing the previous data for checking later.
+ always @(posedge clk)begin
+ if (~inv_dqs_wl[dqs_count_rep2] & ((wl_state_r == WL_INIT) |
+ ((wl_state_r == WL_EDGE_CHECK) & (wl_edge_detect_valid_r))))
+ rd_data_previous_r <= #TCQ rd_data_rise_wl_r;
+ end
+
+ always @(posedge clk)begin
+ if (inv_dqs_wl[dqs_count_rep2] &
+ ((wl_state_r == WL_EDGE_CHECK) & (wl_edge_detect_valid_r)))
+ rd_data_inv_dqs_previous_r <= #TCQ rd_data_rise_wl_r;
+ end
+
+ // Counter to track stable value of feedback data to mitigate
+ // false edge detection in unstable jitter region
+ always @(posedge clk)begin
+ if (rst | (wl_state_r == WL_DQS_CNT))
+ stable_cnt <= #TCQ 2\'d0;
+ else if (~inv_dqs_wl[dqs_count_rep2] & (wl_tap_count_r > 5\'d0) &
+ (wl_state_r == WL_EDGE_CHECK) & (wl_edge_detect_valid_r)) begin
+ if ((rd_data_previous_r[dqs_count_rep1] == rd_data_rise_wl_r[dqs_count_rep1])
+ & (stable_cnt < 2\'d3))
+ stable_cnt <= #TCQ stable_cnt + 1;
+ else if (rd_data_previous_r[dqs_count_rep1] != rd_data_rise_wl_r[dqs_count_rep1])
+ stable_cnt <= #TCQ 2\'d0;
+ end
+ end
+
+ always @(posedge clk)begin
+ if (rst | (wl_state_r == WL_DQS_CNT))
+ inv_stable_cnt <= #TCQ 2\'d0;
+ else if (inv_dqs_wl[dqs_count_rep2] & (wl_tap_count_r > 5\'d0) &
+ ((wl_state_r == WL_EDGE_CHECK) & (wl_edge_detect_valid_r))) begin
+ if ((rd_data_inv_dqs_previous_r[dqs_count_rep1] ==
+ rd_data_rise_wl_r[dqs_count_rep1]) &
+ (inv_stable_cnt < 2\'d3))
+ inv_stable_cnt <= #TCQ inv_stable_cnt + 1;
+ else if (rd_data_inv_dqs_previous_r[dqs_count_rep1] !=
+ rd_data_rise_wl_r[dqs_count_rep1])
+ inv_stable_cnt <= #TCQ 2\'d0;
+ end
+ end
+
+
+ //checking for transition from 0 to 1
+ always @(posedge clk)begin
+ if (rst) begin
+ rd_data_inv_edge_detect_r <= #TCQ {DQS_WIDTH{1\'b0}};
+ rd_data_edge_detect_r <= #TCQ {DQS_WIDTH{1\'b0}};
+ end else if (inv_dqs_wl[dqs_count_rep2]) begin
+ if (inv_stable_cnt == 2\'d3)
+ rd_data_inv_edge_detect_r <= #TCQ (~rd_data_inv_dqs_previous_r &
+ rd_data_rise_wl_r);
+ else
+ rd_data_inv_edge_detect_r <= #TCQ {DQS_WIDTH{1\'b0}};
+ end else if (~inv_dqs_wl[dqs_count_rep2]) begin
+ if (stable_cnt == 2\'d3)
+ rd_data_edge_detect_r <= #TCQ (~rd_data_previous_r &
+ rd_data_rise_wl_r);
+ else
+ rd_data_edge_detect_r <= #TCQ {DQS_WIDTH{1\'b0}};
+ end
+ end
+
+// Below 320 MHz it can take less than SHIFT_TBY4_TAP taps for DQS
+// to be aligned to CK resulting in an underflow for DQ IODELAY taps
+// (DQS taps-SHIFT_TBY4_TAP). In this case DQ will be set to 0 taps.
+// This is non-optimal because DQS and DQ are not exactly 90 degrees
+// apart. Since there is relatively more margin at frequencies below
+// 320 MHz this setting should be okay.
+generate
+ always @(posedge clk) begin
+ if (rst) begin
+ for (e = 0; e < CS_WIDTH; e = e +1) begin: tap_offset_rank
+ for(f = 0; f < DQS_WIDTH; f = f +1) begin: tap_offset_dqs_cnt
+ dq_tap[e][f] <= #TCQ 5\'d0;
+ end
+ end
+ end else if (~wr_level_done_r) begin
+ dq_tap[rank_cnt_r][dqs_count_r] <= #TCQ dq_tap_wl[dqs_count_r];
+ end else if ((SIM_CAL_OPTION == ""FAST_CAL"") & wr_level_done_r) begin
+ for (l = 0; l < CS_WIDTH; l = l +1) begin: dq_tap_rank_cnt
+ for(n = 0; n < DQS_WIDTH; n = n +1) begin: dq_tap_dqs_cnt
+ dq_tap[l][n] <= #TCQ dq_tap_wl[0];
+ end
+ end
+ end else if (wr_level_done_r & (CAL_WIDTH == ""HALF"") &
+ (CS_WIDTH == 4)) begin
+ for (g = 0; g < DQS_WIDTH; g = g +1) begin: rank_dqs_cnt
+ dq_tap[2][g] <= #TCQ dq_tap[0][g];
+ dq_tap[3][g] <= #TCQ dq_tap[1][g];
+ end
+ end else if (wr_level_done_r & (CAL_WIDTH == ""HALF"") &
+ (CS_WIDTH == 2)) begin
+ for (h = 0; h < DQS_WIDTH; h = h + 1) begin: dqs_cnt
+ dq_tap[1][h] <= #TCQ dq_tap[0][h];
+ end
+ end
+ end
+endgenerate
+
+
+
+
+ // registring the write level start signal
+ always@(posedge clk) begin
+ wr_level_start_r <= #TCQ wr_level_start;
+ end
+
+
+ // Storing inv_dqs values during DQS write leveling
+ always @(posedge clk) begin
+ if (rst) begin
+ for (j = 0; j < CS_WIDTH; j = j + 1) begin: rst_inv_dqs_r_loop
+ inv_dqs_r[j] <= #TCQ \'b0;
+ end
+ end else if ((wl_state_r == WL_INV_DQS) |
+ (wl_state_r == WL_EDGE_CHECK)) begin
+ inv_dqs_r[rank_cnt_r] <= #TCQ inv_dqs_wl;
+ end else if ((SIM_CAL_OPTION == ""FAST_CAL"") & (wl_state_r == WL_DQS_CHECK)) begin
+ for (r = 0; r < CS_WIDTH; r = r +1) begin: inv_rank_cnt
+ for(s = 0; s < DQS_WIDTH; s = s +1) begin: inv_dqs_cnt
+ inv_dqs_r[r][s] <= #TCQ inv_dqs_wl[0];
+ end
+ end
+ end else if (wr_level_done_r & (CAL_WIDTH == ""HALF"") &
+ (CS_WIDTH == 4)) begin
+ inv_dqs_r[2] <= #TCQ inv_dqs_r[0];
+ inv_dqs_r[3] <= #TCQ inv_dqs_r[1];
+ end else if (wr_level_done_r & (CAL_WIDTH == ""HALF"") &
+ (CS_WIDTH == 2)) begin
+ inv_dqs_r[1] <= #TCQ inv_dqs_r[0];
+ end
+
+ end
+
+ // Storing DQS tap values at the end of each DQS write leveling
+
+
+ always @(posedge clk) begin
+ // MODIFIED, RC, 060908
+ if (rst) begin
+ for (k = 0; k < CS_WIDTH; k = k + 1) begin: rst_wl_dqs_tap_count_loop
+ wl_dqs_tap_count_r[k] <= #TCQ \'b0;
+ end
+ end else if ((wl_state_r == WL_DQS_CNT) | (wl_state_r == WL_WAIT))begin
+ wl_dqs_tap_count_r[rank_cnt_r][(5*dqs_count_r)+:5]
+ <= #TCQ wl_tap_count_r;
+ end else if ((SIM_CAL_OPTION == ""FAST_CAL"") & (wl_state_r == WL_DQS_CHECK)) begin
+ for (p = 0; p < CS_WIDTH; p = p +1) begin: dqs_tap_rank_cnt
+ for(q = 0; q < DQS_WIDTH; q = q +1) begin: dqs_tap_dqs_cnt
+ wl_dqs_tap_count_r[p][(5*q)+:5] <= #TCQ wl_tap_count_r;
+ end
+ end
+ end else if (wr_level_done_r & (CAL_WIDTH == ""HALF"") &
+ (CS_WIDTH == 4) & (SIM_CAL_OPTION != ""FAST_CAL"")) begin
+ wl_dqs_tap_count_r[2] <= #TCQ wl_dqs_tap_count_r[0];
+ wl_dqs_tap_count_r[3] <= #TCQ wl_dqs_tap_count_r[1];
+ end else if (wr_level_done_r & (CAL_WIDTH == ""HALF"") &
+ (CS_WIDTH == 2) & (SIM_CAL_OPTION != ""FAST_CAL"")) begin
+ wl_dqs_tap_count_r[1] <= #TCQ wl_dqs_tap_count_r[0];
+ end
+ end
+
+
+
+ // assign DQS output tap count to DQ with the 90 degree offset
+
+ generate
+ genvar rank_i;
+ genvar dq_i;
+ for (rank_i = 0; rank_i < CS_WIDTH; rank_i = rank_i + 1) begin: gen_dq_rank
+ for(dq_i = 0; dq_i < DQS_WIDTH; dq_i = dq_i +1) begin: gen_dq_tap_cnt
+ // MODIFIED, RC, 060908 - timing when DQ IODELAY value is changed
+ // does not need to be precise as long as we\'re not changing while
+ // looking for edge on DQ
+ always @(posedge clk)
+ dlyval_wr_dq_r[rank_i][5*dq_i+:5]
+ <= #TCQ dq_tap[rank_i][dq_i];
+ end
+ end
+ endgenerate
+
+
+
+ // state machine to initiate the write leveling sequence
+ // The state machine operates on one byte at a time.
+ // It will increment the delays to the DQS OSERDES
+ // and sample the DQ from the memory. When it detects
+ // a transition from 1 to 0 then the write leveling is considered
+ // done.
+ always @(posedge clk) begin
+ if(rst)begin
+ for(m = 0; m < DQS_WIDTH; m = m +1) begin: tap_offset_wl_rst
+ dq_tap_wl[m] <= #TCQ 5\'d0;
+ end
+ wrlvl_err <= #TCQ 1\'b0;
+ wr_level_done_r <= #TCQ 1\'b0;
+ wrlvl_rank_done_r <= #TCQ 1\'b0;
+ inv_dqs_wl <= #TCQ {DQS_WIDTH{1\'b0}};
+ dqs_count_r <= #TCQ {DQS_CNT_WIDTH+1{1\'b0}};
+ dqs_count_rep1 <= #TCQ {DQS_CNT_WIDTH+1{1\'b0}};
+ dqs_count_rep2 <= #TCQ {DQS_CNT_WIDTH+1{1\'b0}};
+ dq_cnt_inc <= #TCQ 1\'b1;
+ rank_cnt_r <= #TCQ 2\'b00;
+ wl_state_r <= #TCQ WL_IDLE;
+ wl_state_r1 <= #TCQ WL_IDLE;
+ wl_edge_detect_valid_r <= #TCQ 1\'b0;
+ wl_tap_count_r <= #TCQ 5\'b0;
+ end else begin
+ wl_state_r1 <= #TCQ wl_state_r;
+ case (wl_state_r)
+
+ WL_IDLE: begin
+ inv_dqs_wl <= #TCQ {DQS_WIDTH{1\'b0}};
+ wrlvl_rank_done_r <= #TCQ 1\'d0;
+ if(!wr_level_done_r & wr_level_start_r & wl_sm_start)
+ wl_state_r <= #TCQ WL_INIT;
+ end
+
+ WL_INIT: begin
+ wl_edge_detect_valid_r <= #TCQ 1\'b0;
+ wrlvl_rank_done_r <= #TCQ 1\'d0;
+ if(wl_sm_start)
+ wl_state_r <= #TCQ WL_EDGE_CHECK; //WL_DEL_INC;
+ end
+
+ WL_DEL_INC: begin // Inc DQS ODELAY tap
+ wl_state_r <= #TCQ WL_WAIT;
+ wl_edge_detect_valid_r <= #TCQ 1\'b0;
+ wl_tap_count_r <= #TCQ wl_tap_count_r + 1\'b1;
+ end
+
+ WL_WAIT: begin
+ if (wl_sm_start)
+ wl_state_r <= #TCQ WL_WAIT_DQ;
+ end
+ WL_WAIT_DQ: begin
+ if (wl_sm_start)
+ wl_state_r <= #TCQ WL_EDGE_CHECK;
+ end
+
+ WL_EDGE_CHECK: begin // Look for the edge
+ if (wl_edge_detect_valid_r == 1\'b0) begin
+ wl_state_r <= #TCQ WL_WAIT;
+ wl_edge_detect_valid_r <= #TCQ 1\'b1;
+ end
+ // 0->1 transition detected with non-inv DQS
+ // Minimum of 8 taps between DQS and DQ when
+ // SHIFT_TBY4_TAP > 10
+ else if(rd_data_edge_detect_r[dqs_count_r] &&
+ ((wl_tap_count_r >= SHIFT_TBY4_TAP) ||
+ ((wl_tap_count_r > 5\'d7) && (SHIFT_TBY4_TAP>10))) &&
+ wl_edge_detect_valid_r)
+ begin
+ wl_state_r <= #TCQ WL_DQS_CNT;
+ inv_dqs_wl[dqs_count_rep2] <= #TCQ 1\'b0;
+ wl_tap_count_r <= #TCQ wl_tap_count_r;
+ if (wl_tap_count_r < SHIFT_TBY4_TAP)
+ dq_tap_wl[dqs_count_r] <= #TCQ 5\'d0;
+ else
+ dq_tap_wl[dqs_count_r]
+ <= #TCQ wl_tap_count_r - SHIFT_TBY4_TAP;
+ end
+ // 0->1 transition detected with inv DQS
+ // Minimum of 8 taps between DQS and DQ when
+ // SHIFT_TBY4_TAP > 10
+ else if (rd_data_inv_edge_detect_r[dqs_count_r] &&
+ ((wl_tap_count_r >= SHIFT_TBY4_TAP) ||
+ ((wl_tap_count_r > 5\'d7) && (SHIFT_TBY4_TAP>10))) &&
+ wl_edge_detect_valid_r)
+ begin
+ wl_state_r <= #TCQ WL_DQS_CNT;
+ inv_dqs_wl[dqs_count_rep2] <= #TCQ 1\'b1;
+ wl_tap_count_r <= #TCQ wl_tap_count_r;
+ if (wl_tap_count_r < SHIFT_TBY4_TAP)
+ dq_tap_wl[dqs_count_r] <= #TCQ 5\'d0;
+ else
+ dq_tap_wl[dqs_count_r]
+ <= #TCQ wl_tap_count_r - SHIFT_TBY4_TAP;
+ end
+ else if (wl_tap_count_r > 5\'d30)
+ wrlvl_err <= #TCQ 1\'b1;
+ else
+ wl_state_r <= #TCQ WL_INV_DQS;
+ end
+ WL_INV_DQS: begin
+ inv_dqs_wl[dqs_count_rep2] <= #TCQ ~inv_dqs_wl[dqs_count_rep2];
+ wl_edge_detect_valid_r <= #TCQ 1\'b0;
+ if (inv_dqs_wl[dqs_count_rep2] == 1\'b1)
+ wl_state_r <= #TCQ WL_DEL_INC;
+ else begin
+ wl_state_r <= #TCQ WL_WAIT;
+ end
+ end
+
+ WL_DQS_CNT: begin
+ if ((SIM_CAL_OPTION == ""FAST_CAL"") ||
+ (dqs_count_r == (DQS_WIDTH-1))) begin
+ dqs_count_r <= #TCQ dqs_count_r;
+ dqs_count_rep1 <= #TCQ dqs_count_rep1;
+ dqs_count_rep2 <= #TCQ dqs_count_rep2;
+ dq_cnt_inc <= #TCQ 1\'b0;
+ end else begin
+ dqs_count_r <= #TCQ dqs_count_r + 1\'b1;
+ dqs_count_rep1 <= #TCQ dqs_count_rep1 + 1\'b1;
+ dqs_count_rep2 <= #TCQ dqs_count_rep2 + 1\'b1;
+ dq_cnt_inc <= #TCQ 1\'b1;
+ end
+ wl_state_r <= #TCQ WL_DQS_CHECK;
+ wl_edge_detect_valid_r <= #TCQ 1\'b0;
+ end
+
+ WL_DQS_CHECK: begin // check if all DQS have been calibrated
+ wl_tap_count_r <= #TCQ 5\'b0;
+ if (dq_cnt_inc == 1\'b0)begin
+ wrlvl_rank_done_r <= #TCQ 1\'d1;
+ wl_state_r <= #TCQ WL_IDLE;
+ if ((SIM_CAL_OPTION == ""FAST_CAL"") ||
+ (rank_cnt_r == calib_width -1)) begin
+ wr_level_done_r <= #TCQ 1\'d1;
+ rank_cnt_r <= #TCQ 2\'b00;
+ end else begin
+ wr_level_done_r <= #TCQ 1\'d0;
+ rank_cnt_r <= #TCQ rank_cnt_r + 1\'b1;
+ dqs_count_r <= #TCQ 5\'d0;
+ dqs_count_rep1 <= #TCQ 5\'d0;
+ dqs_count_rep2 <= #TCQ 5\'d0;
+ end
+ end else
+ wl_state_r <= #TCQ WL_INIT;
+ end
+ endcase
+ end
+ end // always @ (posedge clk)
+
+// Write calibration during/after stage 2 read leveling
+
+ //synthesis translate_off
+ always @(posedge rdlvl_error) begin
+ if (!rst && rdlvl_error && !rdlvl_error_r &&
+ (wr_calib_dly_r[2*rdlvl_err_byte_r+0] == 1\'b1) &&
+ (wr_calib_dly_r[2*rdlvl_err_byte_r+1] == 1\'b1))
+ $display (""PHY_WRLVL: Write Calibration Error at %t"", $time);
+ end
+ //synthesis translate_on
+
+
+ always @ (posedge clk) begin
+ rdlvl_err_byte_r <= #TCQ rdlvl_err_byte;
+ end
+
+ always @(posedge clk) begin
+ if (rst) begin
+ rdlvl_error_r <= #TCQ 1\'b0;
+ rdlvl_error_r1 <= #TCQ 1\'b0;
+ rdlvl_resume <= #TCQ 1\'b0;
+ rdlvl_resume_r <= #TCQ 1\'b0;
+ rdlvl_resume_r1<= #TCQ 1\'b0;
+ rdlvl_resume_r2<= #TCQ 1\'b0;
+ rdlvl_done_r1 <= #TCQ 1\'b0;
+ end else begin
+ rdlvl_error_r <= #TCQ rdlvl_error;
+ rdlvl_error_r1 <= #TCQ rdlvl_error_r;
+ rdlvl_resume_r <= #TCQ rdlvl_error_r & ~rdlvl_error_r1;
+ rdlvl_resume_r1<= #TCQ rdlvl_resume_r;
+ rdlvl_resume_r2<= #TCQ rdlvl_resume_r1;
+ rdlvl_resume <= #TCQ (rdlvl_resume_r | rdlvl_resume_r1
+ | rdlvl_resume_r2);
+ rdlvl_done_r1 <= #TCQ rdlvl_done[1];
+
+ end
+ end
+
+ always @(posedge clk) begin
+ if (rst) begin
+ wrcal_err <= #TCQ 1\'b0;
+ end else if (rdlvl_error && !rdlvl_error_r &&
+ (wr_calib_dly_r[2*rdlvl_err_byte_r+0] == 1\'b1) &&
+ (wr_calib_dly_r[2*rdlvl_err_byte_r+1] == 1\'b1)) begin
+ wrcal_err <= #TCQ 1\'b1;
+ end else begin
+ wrcal_err <= #TCQ wrcal_err;
+ end
+ end
+
+ always @(posedge clk) begin
+ if (rst)
+ tmp_calib_dly_r <= #TCQ 2\'b00;
+ else if (rdlvl_done[1] && (SIM_CAL_OPTION == ""FAST_CAL""))
+ tmp_calib_dly_r <= #TCQ wr_calib_dly_r[1:0];
+ end
+
+// wr_calib_dly only increments from 0 to a max value of 3
+// Write bitslip logic only supports upto 3 clk_mem cycles
+ always @(posedge clk) begin
+ if (rst)
+ wr_calib_dly_r <= #TCQ {2*DQS_WIDTH{1\'b0}};
+ else if (rdlvl_done_r1 && (SIM_CAL_OPTION == ""FAST_CAL"")) begin
+ for (d = 0; d < DQS_WIDTH; d = d + 1) begin
+ wr_calib_dly_r[2*d+:2] <= #TCQ tmp_calib_dly_r;
+ end
+ end else if (rdlvl_error && !rdlvl_error_r) begin
+ if (set_two_flag[rdlvl_err_byte_r]) begin
+ wr_calib_dly_r[2*rdlvl_err_byte_r+0] <= #TCQ 1\'b1;
+ wr_calib_dly_r[2*rdlvl_err_byte_r+1] <= #TCQ 1\'b1;
+ end else if (set_one_flag[rdlvl_err_byte_r]) begin
+ wr_calib_dly_r[2*rdlvl_err_byte_r+0] <= #TCQ 1\'b0;
+ wr_calib_dly_r[2*rdlvl_err_byte_r+1] <= #TCQ 1\'b1;
+ end else begin
+ wr_calib_dly_r[2*rdlvl_err_byte_r+0] <= #TCQ 1\'b1;
+ wr_calib_dly_r[2*rdlvl_err_byte_r+1] <= #TCQ 1\'b0;
+ end
+ end
+ end
+
+// set_one_flag determines if wr_calib_dly_r must be incremented to \'2\'
+ generate
+ genvar wcal_i;
+ for(wcal_i = 0; wcal_i < DQS_WIDTH; wcal_i = wcal_i +1) begin: gen_wcal_set_one
+ always @(posedge clk) begin
+ if (rst)
+ set_one_flag[wcal_i] <= #TCQ 1\'b0;
+ else if (!set_one_flag[wcal_i] && rdlvl_error_r &&
+ ~rdlvl_error_r1 && (rdlvl_err_byte_r == wcal_i))
+ set_one_flag[wcal_i] <= #TCQ 1\'b1;
+ end
+ end
+ endgenerate
+
+// set_two_flag determines if wr_calib_dly_r must be incremented to \'3\'
+ generate
+ genvar two_i;
+ for(two_i = 0; two_i < DQS_WIDTH; two_i = two_i +1) begin: gen_wcal_set_two
+ always @(posedge clk) begin
+ if (rst)
+ set_two_flag[two_i] <= #TCQ 1\'b0;
+ else if (set_one_flag[two_i] && rdlvl_error_r &&
+ ~rdlvl_error_r1 && (rdlvl_err_byte_r == two_i))
+ set_two_flag[two_i] <= #TCQ 1\'b1;
+ end
+ end
+ endgenerate
+
+
+endmodule
+
+
+
+
+
+
+
+"
+"//*****************************************************************************
+// (c) Copyright 2008 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : %version
+// \\ \\ Application : MIG
+// / / Filename : rank_common.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : 7-Series
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+// Block for logic common to all rank machines. Contains
+// a clock prescaler, and arbiters for refresh and periodic
+// read functions.
+
+`timescale 1 ps / 1 ps
+
+module mig_7series_v1_8_rank_common #
+ (
+ parameter TCQ = 100,
+ parameter DRAM_TYPE = ""DDR3"",
+ parameter MAINT_PRESCALER_DIV = 40,
+ parameter nBANK_MACHS = 4,
+ parameter nCKESR = 4,
+ parameter nCK_PER_CLK = 2,
+ parameter PERIODIC_RD_TIMER_DIV = 20,
+ parameter RANK_WIDTH = 2,
+ parameter RANKS = 4,
+ parameter REFRESH_TIMER_DIV = 39,
+ parameter ZQ_TIMER_DIV = 640000
+ )
+ (/*AUTOARG*/
+ // Outputs
+ maint_prescaler_tick_r, refresh_tick, maint_zq_r, maint_sre_r, maint_srx_r,
+ maint_req_r, maint_rank_r, clear_periodic_rd_request, periodic_rd_r,
+ periodic_rd_rank_r, app_ref_ack, app_zq_ack, app_sr_active, maint_ref_zq_wip,
+ // Inputs
+ clk, rst, init_calib_complete, app_ref_req, app_zq_req, app_sr_req,
+ insert_maint_r1, refresh_request, maint_wip_r, slot_0_present, slot_1_present,
+ periodic_rd_request, periodic_rd_ack_r
+ );
+
+ function integer clogb2 (input integer size); // ceiling logb2
+ begin
+ size = size - 1;
+ for (clogb2=1; size>1; clogb2=clogb2+1)
+ size = size >> 1;
+ end
+ endfunction // clogb2
+
+ input clk;
+ input rst;
+
+// Maintenance and periodic read prescaler. Nominally 200 nS.
+ localparam ONE = 1;
+ localparam MAINT_PRESCALER_WIDTH = clogb2(MAINT_PRESCALER_DIV + 1);
+ input init_calib_complete;
+ reg maint_prescaler_tick_r_lcl;
+ generate
+ begin : maint_prescaler
+ reg [MAINT_PRESCALER_WIDTH-1:0] maint_prescaler_r;
+ reg [MAINT_PRESCALER_WIDTH-1:0] maint_prescaler_ns;
+ wire maint_prescaler_tick_ns =
+ (maint_prescaler_r == ONE[MAINT_PRESCALER_WIDTH-1:0]);
+ always @(/*AS*/init_calib_complete or maint_prescaler_r
+ or maint_prescaler_tick_ns) begin
+ maint_prescaler_ns = maint_prescaler_r;
+ if (~init_calib_complete || maint_prescaler_tick_ns)
+ maint_prescaler_ns = MAINT_PRESCALER_DIV[MAINT_PRESCALER_WIDTH-1:0];
+ else if (|maint_prescaler_r)
+ maint_prescaler_ns = maint_prescaler_r - ONE[MAINT_PRESCALER_WIDTH-1:0];
+ end
+ always @(posedge clk) maint_prescaler_r <= #TCQ maint_prescaler_ns;
+
+ always @(posedge clk) maint_prescaler_tick_r_lcl <=
+ #TCQ maint_prescaler_tick_ns;
+ end
+ endgenerate
+ output wire maint_prescaler_tick_r;
+ assign maint_prescaler_tick_r = maint_prescaler_tick_r_lcl;
+
+// Refresh timebase. Nominically 7800 nS.
+ localparam REFRESH_TIMER_WIDTH = clogb2(REFRESH_TIMER_DIV + /*idle*/ 1);
+ wire refresh_tick_lcl;
+ generate
+ begin : refresh_timer
+ reg [REFRESH_TIMER_WIDTH-1:0] refresh_timer_r;
+ reg [REFRESH_TIMER_WIDTH-1:0] refresh_timer_ns;
+ always @(/*AS*/init_calib_complete or maint_prescaler_tick_r_lcl
+ or refresh_tick_lcl or refresh_timer_r) begin
+ refresh_timer_ns = refresh_timer_r;
+ if (~init_calib_complete || refresh_tick_lcl)
+ refresh_timer_ns = REFRESH_TIMER_DIV[REFRESH_TIMER_WIDTH-1:0];
+ else if (|refresh_timer_r && maint_prescaler_tick_r_lcl)
+ refresh_timer_ns =
+ refresh_timer_r - ONE[REFRESH_TIMER_WIDTH-1:0];
+ end
+ always @(posedge clk) refresh_timer_r <= #TCQ refresh_timer_ns;
+ assign refresh_tick_lcl = (refresh_timer_r ==
+ ONE[REFRESH_TIMER_WIDTH-1:0]) && maint_prescaler_tick_r_lcl;
+ end
+ endgenerate
+ output wire refresh_tick;
+ assign refresh_tick = refresh_tick_lcl;
+
+// ZQ timebase. Nominally 128 mS
+ localparam ZQ_TIMER_WIDTH = clogb2(ZQ_TIMER_DIV + 1);
+ input app_zq_req;
+ input insert_maint_r1;
+ reg maint_zq_r_lcl;
+ reg zq_request = 1\'b0;
+ generate
+ if (DRAM_TYPE == ""DDR3"") begin : zq_cntrl
+ reg zq_tick = 1\'b0;
+ if (ZQ_TIMER_DIV !=0) begin : zq_timer
+ reg [ZQ_TIMER_WIDTH-1:0] zq_timer_r;
+ reg [ZQ_TIMER_WIDTH-1:0] zq_timer_ns;
+ always @(/*AS*/init_calib_complete or maint_prescaler_tick_r_lcl
+ or zq_tick or zq_timer_r) begin
+ zq_timer_ns = zq_timer_r;
+ if (~init_calib_complete || zq_tick)
+ zq_timer_ns = ZQ_TIMER_DIV[ZQ_TIMER_WIDTH-1:0];
+ else if (|zq_timer_r && maint_prescaler_tick_r_lcl)
+ zq_timer_ns = zq_timer_r - ONE[ZQ_TIMER_WIDTH-1:0];
+ end
+ always @(posedge clk) zq_timer_r <= #TCQ zq_timer_ns;
+ always @(/*AS*/maint_prescaler_tick_r_lcl or zq_timer_r)
+ zq_tick = (zq_timer_r ==
+ ONE[ZQ_TIMER_WIDTH-1:0] && maint_prescaler_tick_r_lcl);
+ end // zq_timer
+
+// ZQ request. Set request with timer tick, and when exiting PHY init. Never
+// request if ZQ_TIMER_DIV == 0.
+ begin : zq_request_logic
+ wire zq_clears_zq_request = insert_maint_r1 && maint_zq_r_lcl;
+ reg zq_request_r;
+ wire zq_request_ns = ~rst && (DRAM_TYPE == ""DDR3"") &&
+ ((~init_calib_complete && (ZQ_TIMER_DIV != 0)) ||
+ (zq_request_r && ~zq_clears_zq_request) ||
+ zq_tick ||
+ (app_zq_req && init_calib_complete));
+ always @(posedge clk) zq_request_r <= #TCQ zq_request_ns;
+ always @(/*AS*/init_calib_complete or zq_request_r)
+ zq_request = init_calib_complete && zq_request_r;
+ end // zq_request_logic
+ end
+ endgenerate
+
+ // Self-refresh control
+ localparam nCKESR_CLKS = (nCKESR / nCK_PER_CLK) + (nCKESR % nCK_PER_CLK ? 1 : 0);
+ localparam CKESR_TIMER_WIDTH = clogb2(nCKESR_CLKS + 1);
+ input app_sr_req;
+ reg maint_sre_r_lcl;
+ reg maint_srx_r_lcl;
+ reg sre_request = 1\'b0;
+ wire inhbt_srx;
+
+ generate begin : sr_cntrl
+
+ // SRE request. Set request with user request.
+ begin : sre_request_logic
+
+ reg sre_request_r;
+ wire sre_clears_sre_request = insert_maint_r1 && maint_sre_r_lcl;
+
+ wire sre_request_ns = ~rst && ((sre_request_r && ~sre_clears_sre_request)
+ || (app_sr_req && init_calib_complete && ~maint_sre_r_lcl));
+
+ always @(posedge clk) sre_request_r <= #TCQ sre_request_ns;
+
+ always @(init_calib_complete or sre_request_r)
+ sre_request = init_calib_complete && sre_request_r;
+
+ end // sre_request_logic
+
+ // CKESR timer: Self-Refresh must be maintained for a minimum of tCKESR
+ begin : ckesr_timer
+
+ reg [CKESR_TIMER_WIDTH-1:0] ckesr_timer_r = {CKESR_TIMER_WIDTH{1\'b0}};
+ reg [CKESR_TIMER_WIDTH-1:0] ckesr_timer_ns = {CKESR_TIMER_WIDTH{1\'b0}};
+
+ always @(insert_maint_r1 or ckesr_timer_r or maint_sre_r_lcl) begin
+
+ ckesr_timer_ns = ckesr_timer_r;
+
+ if (insert_maint_r1 && maint_sre_r_lcl)
+ ckesr_timer_ns = nCKESR_CLKS[CKESR_TIMER_WIDTH-1:0];
+ else if(|ckesr_timer_r)
+ ckesr_timer_ns = ckesr_timer_r - ONE[CKESR_TIMER_WIDTH-1:0];
+
+ end
+
+ always @(posedge clk) ckesr_timer_r <= #TCQ ckesr_timer_ns;
+
+ assign inhbt_srx = |ckesr_timer_r;
+
+ end // ckesr_timer
+
+ end
+
+ endgenerate
+
+// DRAM maintenance operations of refresh and ZQ calibration, and self-refresh
+// DRAM maintenance operations and self-refresh have their own channel in the
+// queue. There is also a single, very simple bank machine
+// dedicated to these operations. Its assumed that the
+// maintenance operations can be completed quickly enough
+// to avoid any queuing.
+//
+// ZQ, refresh and self-refresh requests share a channel into controller.
+// Self-refresh is appended to the uppermost bit of the request bus and ZQ is
+// appended just below that.
+
+ input[RANKS-1:0] refresh_request;
+ input maint_wip_r;
+ reg maint_req_r_lcl;
+ reg [RANK_WIDTH-1:0] maint_rank_r_lcl;
+ input [7:0] slot_0_present;
+ input [7:0] slot_1_present;
+
+ generate
+ begin : maintenance_request
+
+// Maintenance request pipeline.
+ reg upd_last_master_r;
+ reg new_maint_rank_r;
+ wire maint_busy = upd_last_master_r || new_maint_rank_r ||
+ maint_req_r_lcl || maint_wip_r;
+ wire [RANKS+1:0] maint_request = {sre_request, zq_request, refresh_request[RANKS-1:0]};
+ wire upd_last_master_ns = |maint_request && ~maint_busy;
+ always @(posedge clk) upd_last_master_r <= #TCQ upd_last_master_ns;
+ always @(posedge clk) new_maint_rank_r <= #TCQ upd_last_master_r;
+ always @(posedge clk) maint_req_r_lcl <= #TCQ new_maint_rank_r;
+
+// Arbitrate maintenance requests.
+ wire [RANKS+1:0] maint_grant_ns;
+ wire [RANKS+1:0] maint_grant_r;
+ mig_7series_v1_8_round_robin_arb #
+ (.WIDTH (RANKS+2))
+ maint_arb0
+ (.grant_ns (maint_grant_ns),
+ .grant_r (maint_grant_r),
+ .upd_last_master (upd_last_master_r),
+ .current_master (maint_grant_r),
+ .req (maint_request),
+ .disable_grant (1\'b0),
+ /*AUTOINST*/
+ // Inputs
+ .clk (clk),
+ .rst (rst));
+
+// Look at arbitration results. Decide if ZQ, refresh or self-refresh.
+// If refresh select the maintenance rank from the winning rank controller.
+// If ZQ or self-refresh, generate a sequence of rank numbers corresponding to
+// slots populated maint_rank_r is not used for comparisons in the queue for ZQ
+// or self-refresh requests. The bank machine will enable CS for the number of
+// states equal to the the number of occupied slots. This will produce a
+// command to every occupied slot, but not in any particular order.
+ wire [7:0] present = slot_0_present | slot_1_present;
+ integer i;
+ reg [RANK_WIDTH-1:0] maint_rank_ns;
+ wire maint_zq_ns = ~rst && (upd_last_master_r
+ ? maint_grant_r[RANKS]
+ : maint_zq_r_lcl);
+ wire maint_srx_ns = ~rst && (maint_sre_r_lcl
+ ? ~app_sr_req & ~inhbt_srx
+ : maint_srx_r_lcl && upd_last_master_r
+ ? maint_grant_r[RANKS+1]
+ : maint_srx_r_lcl);
+ wire maint_sre_ns = ~rst && (upd_last_master_r
+ ? maint_grant_r[RANKS+1]
+ : maint_sre_r_lcl && ~maint_srx_ns);
+ always @(/*AS*/maint_grant_r or maint_rank_r_lcl or maint_zq_ns
+ or maint_sre_ns or maint_srx_ns or present or rst
+ or upd_last_master_r) begin
+ if (rst) maint_rank_ns = {RANK_WIDTH{1\'b0}};
+ else begin
+ maint_rank_ns = maint_rank_r_lcl;
+ if (maint_zq_ns || maint_sre_ns || maint_srx_ns) begin
+ maint_rank_ns = maint_rank_r_lcl + ONE[RANK_WIDTH-1:0];
+ for (i=0; i<8; i=i+1)
+ if (~present[maint_rank_ns])
+ maint_rank_ns = maint_rank_ns + ONE[RANK_WIDTH-1:0];
+ end
+ else
+ if (upd_last_master_r)
+ for (i=0; i= 2*nCK_PER_CLK
+// Output notes:
+// The output of this module consists of 2*nCK_PER_CLK bits, these contain
+// the value of the LFSR output for the next 2*CK_PER_CLK bit times. Note
+// that prbs_o[0] contains the bit value for the ""earliest"" bit time.
+//
+//Reference:
+//Revision History:
+//
+//*****************************************************************************
+
+/******************************************************************************
+**$Id: ddr_prbs_gen.v,v 1.1 2011/06/02 08:35:10 mishra Exp $
+**$Date: 2011/06/02 08:35:10 $
+**$Author: mishra $
+**$Revision: 1.1 $
+**$Source: /devl/xcs/repo/env/Databases/ip/src2/O/mig_7series_v1_3/data/dlib/7series/ddr3_sdram/verilog/rtl/phy/ddr_prbs_gen.v,v $
+******************************************************************************/
+
+
+`timescale 1ps/1ps
+
+module mig_7series_v1_8_ddr_prbs_gen #
+ (
+ parameter TCQ = 100, // clk->out delay (sim only)
+ parameter PRBS_WIDTH = 64 // LFSR shift register length
+ )
+ (
+ input clk_i, // input clock
+ input clk_en_i, // clock enable
+ input rst_i, // synchronous reset
+ input [PRBS_WIDTH-1:0] prbs_seed_i, // initial LFSR seed
+ input phy_if_empty, // IN_FIFO empty flag
+ input prbs_rdlvl_start, // PRBS read lveling start
+ output [PRBS_WIDTH-1:0] prbs_o // generated pseudo random data
+ );
+
+ //***************************************************************************
+
+ function integer clogb2 (input integer size);
+ begin
+ size = size - 1;
+ for (clogb2=1; size>1; clogb2=clogb2+1)
+ size = size >> 1;
+ end
+ endfunction
+
+ // Number of internal clock cycles before the PRBS sequence will repeat
+ localparam PRBS_SEQ_LEN_CYCLES = 128;
+ localparam PRBS_SEQ_LEN_CYCLES_BITS = clogb2(PRBS_SEQ_LEN_CYCLES);
+
+ reg phy_if_empty_r;
+ reg reseed_prbs_r;
+ reg [PRBS_SEQ_LEN_CYCLES_BITS-1:0] sample_cnt_r;
+ reg [PRBS_WIDTH - 1 :0] prbs;
+ reg [PRBS_WIDTH :1] lfsr_q;
+
+ //***************************************************************************
+ always @(posedge clk_i) begin
+ phy_if_empty_r <= #TCQ phy_if_empty;
+ end
+
+ //***************************************************************************
+ // Generate PRBS reset signal to ensure that PRBS sequence repeats after
+ // every 2**PRBS_WIDTH samples. Basically what happens is that we let the
+ // LFSR run for an extra cycle after ""truly PRBS"" 2**PRBS_WIDTH - 1
+ // samples have past. Once that extra cycle is finished, we reseed the LFSR
+ always @(posedge clk_i)
+ begin
+ if (rst_i || ~clk_en_i) begin
+ sample_cnt_r <= #TCQ \'b0;
+ reseed_prbs_r <= #TCQ 1\'b0;
+ end else if (clk_en_i && (~phy_if_empty_r || ~prbs_rdlvl_start)) begin
+ // The rollver count should always be [(power of 2) - 1]
+ sample_cnt_r <= #TCQ sample_cnt_r + 1;
+ // Assert PRBS reset signal so that it is simultaneously with the
+ // last sample of the sequence
+ if (sample_cnt_r == PRBS_SEQ_LEN_CYCLES - 2)
+ reseed_prbs_r <= #TCQ 1\'b1;
+ else
+ reseed_prbs_r <= #TCQ 1\'b0;
+ end
+ end
+
+ always @ (posedge clk_i)
+ begin
+//reset it to a known good state to prevent it locks up
+ if ((reseed_prbs_r && clk_en_i) || rst_i || ~clk_en_i) begin
+ lfsr_q[4:1] <= #TCQ prbs_seed_i[3:0] | 4\'h5;
+ lfsr_q[PRBS_WIDTH:5] <= #TCQ prbs_seed_i[PRBS_WIDTH-1:4];
+ end
+ else if (clk_en_i && (~phy_if_empty_r || ~prbs_rdlvl_start)) begin
+ lfsr_q[PRBS_WIDTH:31] <= #TCQ lfsr_q[PRBS_WIDTH-1:30];
+ lfsr_q[30] <= #TCQ lfsr_q[16] ^ lfsr_q[13] ^ lfsr_q[5] ^ lfsr_q[1];
+ lfsr_q[29:9] <= #TCQ lfsr_q[28:8];
+ lfsr_q[8] <= #TCQ lfsr_q[32] ^ lfsr_q[7];
+ lfsr_q[7] <= #TCQ lfsr_q[32] ^ lfsr_q[6];
+ lfsr_q[6:4] <= #TCQ lfsr_q[5:3];
+ lfsr_q[3] <= #TCQ lfsr_q[32] ^ lfsr_q[2];
+ lfsr_q[2] <= #TCQ lfsr_q[1] ;
+ lfsr_q[1] <= #TCQ lfsr_q[32];
+ end
+ end
+
+ always @ (lfsr_q[PRBS_WIDTH:1]) begin
+ prbs = lfsr_q[PRBS_WIDTH:1];
+ end
+
+ assign prbs_o = prbs;
+
+endmodule
+
+
+"
+"//--------------------------------------------------------------------------------
+// Project : SWITCH
+// File : sync_block.v
+// Version : 0.2
+// Author : Shreejith S
+//
+// Description: Clock Domain Crossing Synchronisation - XILINX
+//
+//
+//-----------------------------------------------------------------------------
+//
+// (c) Copyright 2001-2008 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//------------------------------------------------------------------------------
+// Description: Used on signals crossing from one clock domain to
+// another, this is a flip-flop pair, with both flops
+// placed together with RLOCs into the same slice. Thus
+// the routing delay between the two is minimum to safe-
+// guard against metastability issues.
+
+`timescale 1ps / 1ps
+
+module sync_block #(
+ parameter INITIALISE = 2\'b00
+)
+(
+ input clk, // clock to be sync\'ed to
+ input data_in, // Data to be \'synced\'
+ output data_out // synced data
+);
+
+ // Internal Signals
+ wire data_sync1;
+ wire data_sync2;
+
+
+ (* ASYNC_REG = ""TRUE"", RLOC = ""X0Y0"" *)
+ FD #(
+ .INIT (INITIALISE[0])
+ ) data_sync (
+ .C (clk),
+ .D (data_in),
+ .Q (data_sync1)
+ );
+
+
+ (* RLOC = ""X0Y0"" *)
+ FD #(
+ .INIT (INITIALISE[1])
+ ) data_sync_reg (
+ .C (clk),
+ .D (data_sync1),
+ .Q (data_sync2)
+ );
+
+
+ assign data_out = data_sync2;
+
+
+endmodule
+
+
+"
+"//-----------------------------------------------------------------------------
+//
+// (c) Copyright 2009-2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//-----------------------------------------------------------------------------
+// Project : Virtex-6 Integrated Block for PCI Express
+// File : pcie_pipe_lane_v6.v
+// Version : 2.4
+//--
+//-- Description: PIPE per lane module for Virtex6 PCIe Block
+//--
+//--
+//--
+//--------------------------------------------------------------------------------
+
+`timescale 1ns/1ns
+
+module pcie_pipe_lane_v6 #
+(
+ parameter PIPE_PIPELINE_STAGES = 0, // 0 - 0 stages, 1 - 1 stage, 2 - 2 stages
+ parameter TCQ = 1 // clock to out delay model
+)
+(
+ output wire [ 1:0] pipe_rx_char_is_k_o ,
+ output wire [15:0] pipe_rx_data_o ,
+ output wire pipe_rx_valid_o ,
+ output wire pipe_rx_chanisaligned_o ,
+ output wire [ 2:0] pipe_rx_status_o ,
+ output wire pipe_rx_phy_status_o ,
+ output wire pipe_rx_elec_idle_o ,
+ input wire pipe_rx_polarity_i ,
+ input wire pipe_tx_compliance_i ,
+ input wire [ 1:0] pipe_tx_char_is_k_i ,
+ input wire [15:0] pipe_tx_data_i ,
+ input wire pipe_tx_elec_idle_i ,
+ input wire [ 1:0] pipe_tx_powerdown_i ,
+
+ input wire [ 1:0] pipe_rx_char_is_k_i ,
+ input wire [15:0] pipe_rx_data_i ,
+ input wire pipe_rx_valid_i ,
+ input wire pipe_rx_chanisaligned_i ,
+ input wire [ 2:0] pipe_rx_status_i ,
+ input wire pipe_rx_phy_status_i ,
+ input wire pipe_rx_elec_idle_i ,
+ output wire pipe_rx_polarity_o ,
+ output wire pipe_tx_compliance_o ,
+ output wire [ 1:0] pipe_tx_char_is_k_o ,
+ output wire [15:0] pipe_tx_data_o ,
+ output wire pipe_tx_elec_idle_o ,
+ output wire [ 1:0] pipe_tx_powerdown_o ,
+
+ input wire pipe_clk ,
+ input wire rst_n
+);
+
+//******************************************************************//
+// Reality check. //
+//******************************************************************//
+
+
+ reg [ 1:0] pipe_rx_char_is_k_q ;
+ reg [15:0] pipe_rx_data_q ;
+ reg pipe_rx_valid_q ;
+ reg pipe_rx_chanisaligned_q ;
+ reg [ 2:0] pipe_rx_status_q ;
+ reg pipe_rx_phy_status_q ;
+ reg pipe_rx_elec_idle_q ;
+
+ reg pipe_rx_polarity_q ;
+ reg pipe_tx_compliance_q ;
+ reg [ 1:0] pipe_tx_char_is_k_q ;
+ reg [15:0] pipe_tx_data_q ;
+ reg pipe_tx_elec_idle_q ;
+ reg [ 1:0] pipe_tx_powerdown_q ;
+
+ reg [ 1:0] pipe_rx_char_is_k_qq ;
+ reg [15:0] pipe_rx_data_qq ;
+ reg pipe_rx_valid_qq ;
+ reg pipe_rx_chanisaligned_qq;
+ reg [ 2:0] pipe_rx_status_qq ;
+ reg pipe_rx_phy_status_qq ;
+ reg pipe_rx_elec_idle_qq ;
+
+ reg pipe_rx_polarity_qq ;
+ reg pipe_tx_compliance_qq ;
+ reg [ 1:0] pipe_tx_char_is_k_qq ;
+ reg [15:0] pipe_tx_data_qq ;
+ reg pipe_tx_elec_idle_qq ;
+ reg [ 1:0] pipe_tx_powerdown_qq ;
+
+ generate
+
+ if (PIPE_PIPELINE_STAGES == 0) begin
+
+ assign pipe_rx_char_is_k_o = pipe_rx_char_is_k_i;
+ assign pipe_rx_data_o = pipe_rx_data_i;
+ assign pipe_rx_valid_o = pipe_rx_valid_i;
+ assign pipe_rx_chanisaligned_o = pipe_rx_chanisaligned_i;
+ assign pipe_rx_status_o = pipe_rx_status_i;
+ assign pipe_rx_phy_status_o = pipe_rx_phy_status_i;
+ assign pipe_rx_elec_idle_o = pipe_rx_elec_idle_i;
+
+ assign pipe_rx_polarity_o = pipe_rx_polarity_i;
+ assign pipe_tx_compliance_o = pipe_tx_compliance_i;
+ assign pipe_tx_char_is_k_o = pipe_tx_char_is_k_i;
+ assign pipe_tx_data_o = pipe_tx_data_i;
+ assign pipe_tx_elec_idle_o = pipe_tx_elec_idle_i;
+ assign pipe_tx_powerdown_o = pipe_tx_powerdown_i;
+
+ end else if (PIPE_PIPELINE_STAGES == 1) begin
+
+ always @(posedge pipe_clk) begin
+
+ if (rst_n) begin
+
+ pipe_rx_char_is_k_q <= #TCQ 0;
+ pipe_rx_data_q <= #TCQ 0;
+ pipe_rx_valid_q <= #TCQ 0;
+ pipe_rx_chanisaligned_q <= #TCQ 0;
+ pipe_rx_status_q <= #TCQ 0;
+ pipe_rx_phy_status_q <= #TCQ 0;
+ pipe_rx_elec_idle_q <= #TCQ 0;
+
+ pipe_rx_polarity_q <= #TCQ 0;
+ pipe_tx_compliance_q <= #TCQ 0;
+ pipe_tx_char_is_k_q <= #TCQ 0;
+ pipe_tx_data_q <= #TCQ 0;
+ pipe_tx_elec_idle_q <= #TCQ 1\'b1;
+ pipe_tx_powerdown_q <= #TCQ 2\'b10;
+
+ end else begin
+
+ pipe_rx_char_is_k_q <= #TCQ pipe_rx_char_is_k_i;
+ pipe_rx_data_q <= #TCQ pipe_rx_data_i;
+ pipe_rx_valid_q <= #TCQ pipe_rx_valid_i;
+ pipe_rx_chanisaligned_q <= #TCQ pipe_rx_chanisaligned_i;
+ pipe_rx_status_q <= #TCQ pipe_rx_status_i;
+ pipe_rx_phy_status_q <= #TCQ pipe_rx_phy_status_i;
+ pipe_rx_elec_idle_q <= #TCQ pipe_rx_elec_idle_i;
+
+ pipe_rx_polarity_q <= #TCQ pipe_rx_polarity_i;
+ pipe_tx_compliance_q <= #TCQ pipe_tx_compliance_i;
+ pipe_tx_char_is_k_q <= #TCQ pipe_tx_char_is_k_i;
+ pipe_tx_data_q <= #TCQ pipe_tx_data_i;
+ pipe_tx_elec_idle_q <= #TCQ pipe_tx_elec_idle_i;
+ pipe_tx_powerdown_q <= #TCQ pipe_tx_powerdown_i;
+
+ end
+
+ end
+
+ assign pipe_rx_char_is_k_o = pipe_rx_char_is_k_q;
+ assign pipe_rx_data_o = pipe_rx_data_q;
+ assign pipe_rx_valid_o = pipe_rx_valid_q;
+ assign pipe_rx_chanisaligned_o = pipe_rx_chanisaligned_q;
+ assign pipe_rx_status_o = pipe_rx_status_q;
+ assign pipe_rx_phy_status_o = pipe_rx_phy_status_q;
+ assign pipe_rx_elec_idle_o = pipe_rx_elec_idle_q;
+
+ assign pipe_rx_polarity_o = pipe_rx_polarity_q;
+ assign pipe_tx_compliance_o = pipe_tx_compliance_q;
+ assign pipe_tx_char_is_k_o = pipe_tx_char_is_k_q;
+ assign pipe_tx_data_o = pipe_tx_data_q;
+ assign pipe_tx_elec_idle_o = pipe_tx_elec_idle_q;
+ assign pipe_tx_powerdown_o = pipe_tx_powerdown_q;
+
+ end else if (PIPE_PIPELINE_STAGES == 2) begin
+
+ always @(posedge pipe_clk) begin
+
+ if (rst_n) begin
+
+ pipe_rx_char_is_k_q <= #TCQ 0;
+ pipe_rx_data_q <= #TCQ 0;
+ pipe_rx_valid_q <= #TCQ 0;
+ pipe_rx_chanisaligned_q <= #TCQ 0;
+ pipe_rx_status_q <= #TCQ 0;
+ pipe_rx_phy_status_q <= #TCQ 0;
+ pipe_rx_elec_idle_q <= #TCQ 0;
+
+ pipe_rx_polarity_q <= #TCQ 0;
+ pipe_tx_compliance_q <= #TCQ 0;
+ pipe_tx_char_is_k_q <= #TCQ 0;
+ pipe_tx_data_q <= #TCQ 0;
+ pipe_tx_elec_idle_q <= #TCQ 1\'b1;
+ pipe_tx_powerdown_q <= #TCQ 2\'b10;
+
+ pipe_rx_char_is_k_qq <= #TCQ 0;
+ pipe_rx_data_qq <= #TCQ 0;
+ pipe_rx_valid_qq <= #TCQ 0;
+ pipe_rx_chanisaligned_qq <= #TCQ 0;
+ pipe_rx_status_qq <= #TCQ 0;
+ pipe_rx_phy_status_qq <= #TCQ 0;
+ pipe_rx_elec_idle_qq <= #TCQ 0;
+
+ pipe_rx_polarity_qq <= #TCQ 0;
+ pipe_tx_compliance_qq <= #TCQ 0;
+ pipe_tx_char_is_k_qq <= #TCQ 0;
+ pipe_tx_data_qq <= #TCQ 0;
+ pipe_tx_elec_idle_qq <= #TCQ 1\'b1;
+ pipe_tx_powerdown_qq <= #TCQ 2\'b10;
+
+ end else begin
+
+ pipe_rx_char_is_k_q <= #TCQ pipe_rx_char_is_k_i;
+ pipe_rx_data_q <= #TCQ pipe_rx_data_i;
+ pipe_rx_valid_q <= #TCQ pipe_rx_valid_i;
+ pipe_rx_chanisaligned_q <= #TCQ pipe_rx_chanisaligned_i;
+ pipe_rx_status_q <= #TCQ pipe_rx_status_i;
+ pipe_rx_phy_status_q <= #TCQ pipe_rx_phy_status_i;
+ pipe_rx_elec_idle_q <= #TCQ pipe_rx_elec_idle_i;
+
+ pipe_rx_polarity_q <= #TCQ pipe_rx_polarity_i;
+ pipe_tx_compliance_q <= #TCQ pipe_tx_compliance_i;
+ pipe_tx_char_is_k_q <= #TCQ pipe_tx_char_is_k_i;
+ pipe_tx_data_q <= #TCQ pipe_tx_data_i;
+ pipe_tx_elec_idle_q <= #TCQ pipe_tx_elec_idle_i;
+ pipe_tx_powerdown_q <= #TCQ pipe_tx_powerdown_i;
+
+ pipe_rx_char_is_k_qq <= #TCQ pipe_rx_char_is_k_q;
+ pipe_rx_data_qq <= #TCQ pipe_rx_data_q;
+ pipe_rx_valid_qq <= #TCQ pipe_rx_valid_q;
+ pipe_rx_chanisaligned_qq <= #TCQ pipe_rx_chanisaligned_q;
+ pipe_rx_status_qq <= #TCQ pipe_rx_status_q;
+ pipe_rx_phy_status_qq <= #TCQ pipe_rx_phy_status_q;
+ pipe_rx_elec_idle_qq <= #TCQ pipe_rx_elec_idle_q;
+
+ pipe_rx_polarity_qq <= #TCQ pipe_rx_polarity_q;
+ pipe_tx_compliance_qq <= #TCQ pipe_tx_compliance_q;
+ pipe_tx_char_is_k_qq <= #TCQ pipe_tx_char_is_k_q;
+ pipe_tx_data_qq <= #TCQ pipe_tx_data_q;
+ pipe_tx_elec_idle_qq <= #TCQ pipe_tx_elec_idle_q;
+ pipe_tx_powerdown_qq <= #TCQ pipe_tx_powerdown_q;
+
+ end
+
+ end
+
+ assign pipe_rx_char_is_k_o = pipe_rx_char_is_k_qq;
+ assign pipe_rx_data_o = pipe_rx_data_qq;
+ assign pipe_rx_valid_o = pipe_rx_valid_qq;
+ assign pipe_rx_chanisaligned_o = pipe_rx_chanisaligned_qq;
+ assign pipe_rx_status_o = pipe_rx_status_qq;
+ assign pipe_rx_phy_status_o = pipe_rx_phy_status_qq;
+ assign pipe_rx_elec_idle_o = pipe_rx_elec_idle_qq;
+
+ assign pipe_rx_polarity_o = pipe_rx_polarity_qq;
+ assign pipe_tx_compliance_o = pipe_tx_compliance_qq;
+ assign pipe_tx_char_is_k_o = pipe_tx_char_is_k_qq;
+ assign pipe_tx_data_o = pipe_tx_data_qq;
+ assign pipe_tx_elec_idle_o = pipe_tx_elec_idle_qq;
+ assign pipe_tx_powerdown_o = pipe_tx_powerdown_qq;
+
+ end
+
+ endgenerate
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2009 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor: Xilinx
+// \\ \\ \\/ Version: 3.91
+// \\ \\ Application: MIG
+// / / Filename: phy_rddata_sync.v
+// /___/ /\\ Date Last Modified: $Date: 2011/06/02 07:18:04 $
+// \\ \\ / \\ Date Created: Aug 03 2009
+// \\___\\/\\___\\
+//
+//Device: Virtex-6
+//Design Name: DDR3 SDRAM
+//Purpose:
+// Synchronization of captured read data along with appropriately delayed
+// valid signal (both in clk_rsync domain) to MC/PHY rdlvl logic clock (clk)
+//Reference:
+//Revision History:
+//*****************************************************************************
+
+/******************************************************************************
+**$Id: phy_rddata_sync.v,v 1.1 2011/06/02 07:18:04 mishra Exp $
+**$Date: 2011/06/02 07:18:04 $
+**$Author: mishra $
+**$Revision: 1.1 $
+**$Source: /devl/xcs/repo/env/Databases/ip/src2/O/mig_v3_9/data/dlib/virtex6/ddr3_sdram/verilog/rtl/phy/phy_rddata_sync.v,v $
+******************************************************************************/
+
+`timescale 1ps/1ps
+
+
+module phy_rddata_sync #
+ (
+ parameter TCQ = 100, // clk->out delay (sim only)
+ parameter DQ_WIDTH = 64, // # of DQ (data)
+ parameter DQS_WIDTH = 8, // # of DQS (strobe)
+ parameter DRAM_WIDTH = 8, // # of DQ per DQS
+ parameter nDQS_COL0 = 4, // # DQS groups in I/O column #1
+ parameter nDQS_COL1 = 4, // # DQS groups in I/O column #2
+ parameter nDQS_COL2 = 4, // # DQS groups in I/O column #3
+ parameter nDQS_COL3 = 4, // # DQS groups in I/O column #4
+ parameter DQS_LOC_COL0 = 32\'h03020100, // DQS grps in col #1
+ parameter DQS_LOC_COL1 = 32\'h07060504, // DQS grps in col #2
+ parameter DQS_LOC_COL2 = 0, // DQS grps in col #3
+ parameter DQS_LOC_COL3 = 0 // DQS grps in col #4
+ )
+ (
+ input clk,
+ input [3:0] clk_rsync,
+ input [3:0] rst_rsync,
+ // Captured data in resync clock domain
+ input [DQ_WIDTH-1:0] rd_data_rise0,
+ input [DQ_WIDTH-1:0] rd_data_fall0,
+ input [DQ_WIDTH-1:0] rd_data_rise1,
+ input [DQ_WIDTH-1:0] rd_data_fall1,
+ input [DQS_WIDTH-1:0] rd_dqs_rise0,
+ input [DQS_WIDTH-1:0] rd_dqs_fall0,
+ input [DQS_WIDTH-1:0] rd_dqs_rise1,
+ input [DQS_WIDTH-1:0] rd_dqs_fall1,
+ // Synchronized data/valid back to MC/PHY rdlvl logic
+ output reg [4*DQ_WIDTH-1:0] dfi_rddata,
+ output reg [4*DQS_WIDTH-1:0] dfi_rd_dqs
+ );
+
+ // Ensure nonzero width for certain buses to prevent syntax errors
+ // during compile in the event they are not used (e.g. buses that have to
+ // do with column #2 in a single column design never get used, although
+ // those buses still will get declared)
+ localparam COL0_VECT_WIDTH = (nDQS_COL0 > 0) ? nDQS_COL0 : 1;
+ localparam COL1_VECT_WIDTH = (nDQS_COL1 > 0) ? nDQS_COL1 : 1;
+ localparam COL2_VECT_WIDTH = (nDQS_COL2 > 0) ? nDQS_COL2 : 1;
+ localparam COL3_VECT_WIDTH = (nDQS_COL3 > 0) ? nDQS_COL3 : 1;
+
+ reg [4*DRAM_WIDTH*COL0_VECT_WIDTH-1:0] data_c0;
+ reg [4*DRAM_WIDTH*COL1_VECT_WIDTH-1:0] data_c1;
+ reg [4*DRAM_WIDTH*COL2_VECT_WIDTH-1:0] data_c2;
+ reg [4*DRAM_WIDTH*COL3_VECT_WIDTH-1:0] data_c3;
+ reg [DQ_WIDTH-1:0] data_fall0_sync;
+ reg [DQ_WIDTH-1:0] data_fall1_sync;
+ reg [DQ_WIDTH-1:0] data_rise0_sync;
+ reg [DQ_WIDTH-1:0] data_rise1_sync;
+ wire [4*DRAM_WIDTH*COL0_VECT_WIDTH-1:0] data_sync_c0;
+ wire [4*DRAM_WIDTH*COL1_VECT_WIDTH-1:0] data_sync_c1;
+ wire [4*DRAM_WIDTH*COL2_VECT_WIDTH-1:0] data_sync_c2;
+ wire [4*DRAM_WIDTH*COL3_VECT_WIDTH-1:0] data_sync_c3;
+ reg [4*COL0_VECT_WIDTH-1:0] dqs_c0;
+ reg [4*COL1_VECT_WIDTH-1:0] dqs_c1;
+ reg [4*COL2_VECT_WIDTH-1:0] dqs_c2;
+ reg [4*COL3_VECT_WIDTH-1:0] dqs_c3;
+ reg [DQS_WIDTH-1:0] dqs_fall0_sync;
+ reg [DQS_WIDTH-1:0] dqs_fall1_sync;
+ reg [DQS_WIDTH-1:0] dqs_rise0_sync;
+ reg [DQS_WIDTH-1:0] dqs_rise1_sync;
+ wire [4*COL0_VECT_WIDTH-1:0] dqs_sync_c0;
+ wire [4*COL1_VECT_WIDTH-1:0] dqs_sync_c1;
+ wire [4*COL2_VECT_WIDTH-1:0] dqs_sync_c2;
+ wire [4*COL3_VECT_WIDTH-1:0] dqs_sync_c3;
+
+ //***************************************************************************
+ // Synchronization of both data and active/valid signal from clk_rsync to
+ // clk domain
+ // NOTES:
+ // 1. For now, assume both rddata_valid0 and rddata_valid1 are driven at
+ // same time. PHY returns data aligned in this manner
+ // 2. Circular buffer implementation is preliminary (i.e. shortcuts have
+ // been taken!). Will later need some sort of calibration.
+ // - Substitute this with enhanced circular buffer design for
+ // release (5 deep design)
+ // 3. Up to 4 circular buffers are used, one for each CLK_RSYNC[x] domain.
+ // 4. RD_ACTIVE synchronized to CLK_RSYNC[0] circular buffer. This is
+ // TEMPORARY only. For release, do not need this - RD_ACTIVE will
+ //. remain totally in the
+ // A single circular buffer is used for the entire data bus. This will
+ // be an issue in H/W - will need to examine this based on clock
+ // frequency, and skew matching achievable in H/W.
+ //***************************************************************************
+
+ generate
+ genvar c0_i;
+ if (nDQS_COL0 > 0) begin: gen_c0
+ for (c0_i = 0; c0_i < nDQS_COL0; c0_i = c0_i + 1) begin: gen_loop_c0
+ // Steer data to circular buffer - merge FALL/RISE data into single bus
+ always @(rd_dqs_fall0 or rd_dqs_fall1 or
+ rd_dqs_rise0 or rd_dqs_rise1)
+ dqs_c0[4*(c0_i+1)-1-:4]
+ = {rd_dqs_fall1[DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]],
+ rd_dqs_rise1[DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]],
+ rd_dqs_fall0[DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]],
+ rd_dqs_rise0[DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]]};
+ always @(rd_data_rise0 or rd_data_rise1 or
+ rd_data_fall0 or rd_data_fall1)
+ data_c0[4*DRAM_WIDTH*(c0_i+1)-1-:4*DRAM_WIDTH]
+ = {rd_data_fall1[DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i])],
+ rd_data_rise1[DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i])],
+ rd_data_fall0[DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i])],
+ rd_data_rise0[DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i])]};
+
+ // Reassemble data from circular buffer
+ always @(dqs_sync_c0[4*c0_i] or
+ dqs_sync_c0[4*c0_i+1] or
+ dqs_sync_c0[4*c0_i+2] or
+ dqs_sync_c0[4*c0_i+3]) begin
+ dqs_fall1_sync[DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]]
+ = dqs_sync_c0[4*c0_i+3];
+ dqs_rise1_sync[DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]]
+ = dqs_sync_c0[4*c0_i+2];
+ dqs_fall0_sync[DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]]
+ = dqs_sync_c0[4*c0_i+1];
+ dqs_rise0_sync[DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]]
+ = dqs_sync_c0[4*c0_i];
+ end
+
+
+ always @(data_sync_c0[4*DRAM_WIDTH*c0_i+DRAM_WIDTH-1:4*DRAM_WIDTH*c0_i] or
+ data_sync_c0[4*DRAM_WIDTH*c0_i+2*DRAM_WIDTH-1:4*DRAM_WIDTH*c0_i+DRAM_WIDTH] or
+ data_sync_c0[4*DRAM_WIDTH*c0_i+3*DRAM_WIDTH-1:4*DRAM_WIDTH*c0_i+2*DRAM_WIDTH] or
+ data_sync_c0[4*DRAM_WIDTH*c0_i+4*DRAM_WIDTH-1:4*DRAM_WIDTH*c0_i+3*DRAM_WIDTH]) begin
+ data_fall1_sync[DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i])]
+ = data_sync_c0[4*DRAM_WIDTH*c0_i+4*DRAM_WIDTH-1:4*DRAM_WIDTH*c0_i+3*DRAM_WIDTH];
+ data_rise1_sync[DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i])]
+ = data_sync_c0[4*DRAM_WIDTH*c0_i+3*DRAM_WIDTH-1:4*DRAM_WIDTH*c0_i+2*DRAM_WIDTH];
+ data_fall0_sync[DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i])]
+ = data_sync_c0[4*DRAM_WIDTH*c0_i+2*DRAM_WIDTH-1:4*DRAM_WIDTH*c0_i+DRAM_WIDTH];
+ data_rise0_sync[DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL0[(8*(c0_i+1))-1:8*c0_i])]
+ = data_sync_c0[4*DRAM_WIDTH*c0_i+DRAM_WIDTH-1:4*DRAM_WIDTH*c0_i];
+ end
+ end
+
+ circ_buffer #
+ (
+ .TCQ (TCQ),
+ .DATA_WIDTH ((4*nDQS_COL0)+(4*DRAM_WIDTH*nDQS_COL0)),
+ .BUF_DEPTH (6)
+ )
+ u_rddata_sync_c0
+ (
+ .rclk (clk),
+ .wclk (clk_rsync[0]),
+ .rst (rst_rsync[0]),
+ .wdata ({dqs_c0,data_c0}),
+ .rdata ({dqs_sync_c0,data_sync_c0})
+ );
+ end
+ endgenerate
+
+ generate
+ genvar c1_i;
+ if (nDQS_COL1 > 0) begin: gen_c1
+ for (c1_i = 0; c1_i < nDQS_COL1; c1_i = c1_i + 1) begin: gen_loop_c1
+ // Steer data to circular buffer - merge FALL/RISE data into single bus
+ always @(rd_dqs_fall0 or rd_dqs_fall1 or
+ rd_dqs_rise0 or rd_dqs_rise1)
+ dqs_c1[4*(c1_i+1)-1-:4]
+ = {rd_dqs_fall1[DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]],
+ rd_dqs_rise1[DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]],
+ rd_dqs_fall0[DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]],
+ rd_dqs_rise0[DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]]};
+ always @(rd_data_rise0 or rd_data_rise1 or
+ rd_data_fall0 or rd_data_fall1)
+ data_c1[4*DRAM_WIDTH*(c1_i+1)-1-:4*DRAM_WIDTH]
+ = {rd_data_fall1[DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i])],
+ rd_data_rise1[DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i])],
+ rd_data_fall0[DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i])],
+ rd_data_rise0[DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i])]};
+
+ // Reassemble data from circular buffer
+ always @(dqs_sync_c1[4*c1_i] or
+ dqs_sync_c1[4*c1_i+1] or
+ dqs_sync_c1[4*c1_i+2] or
+ dqs_sync_c1[4*c1_i+3] ) begin
+ dqs_fall1_sync[DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]]
+ = dqs_sync_c1[4*c1_i+3];
+ dqs_rise1_sync[DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]]
+ = dqs_sync_c1[4*c1_i+2];
+ dqs_fall0_sync[DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]]
+ = dqs_sync_c1[4*c1_i+1];
+ dqs_rise0_sync[DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]]
+ = dqs_sync_c1[4*c1_i];
+ end
+
+ always @(data_sync_c1[4*DRAM_WIDTH*c1_i+DRAM_WIDTH-1:4*DRAM_WIDTH*c1_i] or
+ data_sync_c1[4*DRAM_WIDTH*c1_i+2*DRAM_WIDTH-1:4*DRAM_WIDTH*c1_i+DRAM_WIDTH] or
+ data_sync_c1[4*DRAM_WIDTH*c1_i+3*DRAM_WIDTH-1:4*DRAM_WIDTH*c1_i+2*DRAM_WIDTH] or
+ data_sync_c1[4*DRAM_WIDTH*c1_i+4*DRAM_WIDTH-1:4*DRAM_WIDTH*c1_i+3*DRAM_WIDTH]) begin
+ data_fall1_sync[DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i])]
+ = data_sync_c1[4*DRAM_WIDTH*c1_i+4*DRAM_WIDTH-1:4*DRAM_WIDTH*c1_i+3*DRAM_WIDTH];
+ data_rise1_sync[DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i])]
+ = data_sync_c1[4*DRAM_WIDTH*c1_i+3*DRAM_WIDTH-1:4*DRAM_WIDTH*c1_i+2*DRAM_WIDTH];
+ data_fall0_sync[DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i])]
+ = data_sync_c1[4*DRAM_WIDTH*c1_i+2*DRAM_WIDTH-1:4*DRAM_WIDTH*c1_i+DRAM_WIDTH];
+ data_rise0_sync[DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL1[(8*(c1_i+1))-1:8*c1_i])]
+ = data_sync_c1[4*DRAM_WIDTH*c1_i+DRAM_WIDTH-1:4*DRAM_WIDTH*c1_i];
+ end
+ end
+
+ circ_buffer #
+ (
+ .TCQ (TCQ),
+ .DATA_WIDTH ((4*nDQS_COL1)+(4*DRAM_WIDTH*nDQS_COL1)),
+ .BUF_DEPTH (6)
+ )
+ u_rddata_sync_c1
+ (
+ .rclk (clk),
+ .wclk (clk_rsync[1]),
+ .rst (rst_rsync[1]),
+ .wdata ({dqs_c1,data_c1}),
+ .rdata ({dqs_sync_c1,data_sync_c1})
+ );
+ end
+ endgenerate
+
+ generate
+ genvar c2_i;
+ if (nDQS_COL2 > 0) begin: gen_c2
+ for (c2_i = 0; c2_i < nDQS_COL2; c2_i = c2_i + 1) begin: gen_loop_c2
+ // Steer data to circular buffer - merge FALL/RISE data into single bus
+ always @(rd_dqs_fall0 or rd_dqs_fall1 or
+ rd_dqs_rise0 or rd_dqs_rise1)
+ dqs_c2[4*(c2_i+1)-1-:4]
+ = {rd_dqs_fall1[DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]],
+ rd_dqs_rise1[DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]],
+ rd_dqs_fall0[DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]],
+ rd_dqs_rise0[DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]]};
+ always @(rd_data_fall0 or rd_data_fall1 or
+ rd_data_rise0 or rd_data_rise1)
+ data_c2[4*DRAM_WIDTH*(c2_i+1)-1-:4*DRAM_WIDTH]
+ = {rd_data_fall1[DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i])],
+ rd_data_rise1[DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i])],
+ rd_data_fall0[DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i])],
+ rd_data_rise0[DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i])]};
+
+ // Reassemble data from circular buffer
+ always @(dqs_sync_c2[4*c2_i] or
+ dqs_sync_c2[4*c2_i+1] or
+ dqs_sync_c2[4*c2_i+2] or
+ dqs_sync_c2[4*c2_i+3] ) begin
+ dqs_fall1_sync[DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]]
+ = dqs_sync_c2[4*c2_i+3];
+ dqs_rise1_sync[DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]]
+ = dqs_sync_c2[4*c2_i+2];
+ dqs_fall0_sync[DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]]
+ = dqs_sync_c2[4*c2_i+1];
+ dqs_rise0_sync[DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]]
+ = dqs_sync_c2[4*c2_i];
+ end
+
+ always @(data_sync_c2[4*DRAM_WIDTH*c2_i+DRAM_WIDTH-1:4*DRAM_WIDTH*c2_i] or
+ data_sync_c2[4*DRAM_WIDTH*c2_i+2*DRAM_WIDTH-1:4*DRAM_WIDTH*c2_i+DRAM_WIDTH] or
+ data_sync_c2[4*DRAM_WIDTH*c2_i+3*DRAM_WIDTH-1:4*DRAM_WIDTH*c2_i+2*DRAM_WIDTH] or
+ data_sync_c2[4*DRAM_WIDTH*c2_i+4*DRAM_WIDTH-1:4*DRAM_WIDTH*c2_i+3*DRAM_WIDTH]) begin
+ data_fall1_sync[DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i])]
+ = data_sync_c2[4*DRAM_WIDTH*c2_i+4*DRAM_WIDTH-1:4*DRAM_WIDTH*c2_i+3*DRAM_WIDTH];
+ data_rise1_sync[DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i])]
+ = data_sync_c2[4*DRAM_WIDTH*c2_i+3*DRAM_WIDTH-1:4*DRAM_WIDTH*c2_i+2*DRAM_WIDTH];
+ data_fall0_sync[DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i])]
+ = data_sync_c2[4*DRAM_WIDTH*c2_i+2*DRAM_WIDTH-1:4*DRAM_WIDTH*c2_i+DRAM_WIDTH];
+ data_rise0_sync[DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL2[(8*(c2_i+1))-1:8*c2_i])]
+ = data_sync_c2[4*DRAM_WIDTH*c2_i+DRAM_WIDTH-1:4*DRAM_WIDTH*c2_i];
+ end
+ end
+
+ circ_buffer #
+ (
+ .TCQ (TCQ),
+ .DATA_WIDTH ((4*nDQS_COL2)+(4*DRAM_WIDTH*nDQS_COL2)),
+ .BUF_DEPTH (6)
+ )
+ u_rddata_sync_c2
+ (
+ .rclk (clk),
+ .wclk (clk_rsync[2]),
+ .rst (rst_rsync[2]),
+ .wdata ({dqs_c2,data_c2}),
+ .rdata ({dqs_sync_c2,data_sync_c2})
+ );
+ end
+ endgenerate
+
+ generate
+ genvar c3_i;
+ if (nDQS_COL3 > 0) begin: gen_c3
+ for (c3_i = 0; c3_i < nDQS_COL3; c3_i = c3_i + 1) begin: gen_loop_c3
+ // Steer data to circular buffer - merge FALL/RISE data into
+ // single bus
+ always @(rd_dqs_fall0 or rd_dqs_fall1 or
+ rd_dqs_rise0 or rd_dqs_rise1)
+ dqs_c3[4*(c3_i+1)-1-:4]
+ = {rd_dqs_fall1[DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]],
+ rd_dqs_rise1[DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]],
+ rd_dqs_fall0[DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]],
+ rd_dqs_rise0[DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]]};
+ always @(rd_data_fall0 or rd_data_fall1 or
+ rd_data_rise0 or rd_data_rise1)
+ data_c3[4*DRAM_WIDTH*(c3_i+1)-1-:4*DRAM_WIDTH]
+ = {rd_data_fall1[DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i])],
+ rd_data_rise1[DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i])],
+ rd_data_fall0[DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i])],
+ rd_data_rise0[DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i])]};
+
+ // Reassemble data from circular buffer
+ always @(dqs_sync_c3[4*c3_i] or
+ dqs_sync_c3[4*c3_i+1] or
+ dqs_sync_c3[4*c3_i+2] or
+ dqs_sync_c3[4*c3_i+3]) begin
+ dqs_fall1_sync[DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]]
+ = dqs_sync_c3[4*c3_i+3];
+ dqs_rise1_sync[DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]]
+ = dqs_sync_c3[4*c3_i+2];
+ dqs_fall0_sync[DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]]
+ = dqs_sync_c3[4*c3_i+1];
+ dqs_rise0_sync[DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]]
+ = dqs_sync_c3[4*c3_i];
+ end
+
+ always @(data_sync_c3[4*DRAM_WIDTH*c3_i+DRAM_WIDTH-1:4*DRAM_WIDTH*c3_i] or
+ data_sync_c3[4*DRAM_WIDTH*c3_i+2*DRAM_WIDTH-1:4*DRAM_WIDTH*c3_i+DRAM_WIDTH] or
+ data_sync_c3[4*DRAM_WIDTH*c3_i+3*DRAM_WIDTH-1:4*DRAM_WIDTH*c3_i+2*DRAM_WIDTH] or
+ data_sync_c3[4*DRAM_WIDTH*c3_i+4*DRAM_WIDTH-1:4*DRAM_WIDTH*c3_i+3*DRAM_WIDTH]) begin
+ data_fall1_sync[DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i])]
+ = data_sync_c3[4*DRAM_WIDTH*c3_i+4*DRAM_WIDTH-1:4*DRAM_WIDTH*c3_i+3*DRAM_WIDTH];
+ data_rise1_sync[DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i])]
+ = data_sync_c3[4*DRAM_WIDTH*c3_i+3*DRAM_WIDTH-1:4*DRAM_WIDTH*c3_i+2*DRAM_WIDTH];
+ data_fall0_sync[DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i])]
+ = data_sync_c3[4*DRAM_WIDTH*c3_i+2*DRAM_WIDTH-1:4*DRAM_WIDTH*c3_i+DRAM_WIDTH];
+ data_rise0_sync[DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i]+1)-1:
+ DRAM_WIDTH*(DQS_LOC_COL3[(8*(c3_i+1))-1:8*c3_i])]
+ = data_sync_c3[4*DRAM_WIDTH*c3_i+DRAM_WIDTH-1:4*DRAM_WIDTH*c3_i];
+ end
+ end
+
+ circ_buffer #
+ (
+ .TCQ (TCQ),
+ .DATA_WIDTH ((4*nDQS_COL3)+(4*DRAM_WIDTH*nDQS_COL3)),
+ .BUF_DEPTH (6)
+ )
+ u_rddata_sync_c3
+ (
+ .rclk (clk),
+ .wclk (clk_rsync[3]),
+ .rst (rst_rsync[3]),
+ .wdata ({dqs_c3,data_c3}),
+ .rdata ({dqs_sync_c3,data_sync_c3})
+ );
+ end
+ endgenerate
+
+ //***************************************************************************
+
+ // Pipeline stage only required if timing not met otherwise
+ always @(posedge clk) begin
+ dfi_rddata <= #TCQ {data_fall1_sync,
+ data_rise1_sync,
+ data_fall0_sync,
+ data_rise0_sync};
+ dfi_rd_dqs <= #TCQ {dqs_fall1_sync,
+ dqs_rise1_sync,
+ dqs_fall0_sync,
+ dqs_rise0_sync};
+ end
+
+endmodule
+"
+"//--------------------------------------------------------------------------------
+// Project : SWITCH
+// File : user_pcie_stream_generator.v
+// Version : 0.1
+// Author : Vipin.K
+//
+// Description: PCIe to DRAM DMA controller
+//
+//--------------------------------------------------------------------------------
+
+module pcie_ddr_dma_controller(
+ input pcie_clk_i,
+ input ddr_clk_i,
+ input rst_n,
+ //Register Set I/f
+ input ctrl_en_i,
+ output reg dma_done_o,
+ input dma_done_ack_i,
+ input [31:0] dma_src_addr_i,
+ input [31:0] dma_len_i,
+ //Tx engine
+ output reg dma_rd_req_o,
+ input dma_req_ack_i,
+ output reg [11:0] dma_rd_req_len_o,
+ output reg [31:0] dma_rd_req_addr_o,\t
+ output reg [7:0] dma_rd_tag_o,
+ //Rx engine
+ input [7:0] dma_tag_i,
+ input dma_data_valid_i,
+ input [63:0] dma_data_i,
+ //Mem Ctrl
+ input fifo_rd_i,
+ output reg fifo_empty_o,
+ output reg [255:0]ddr_data_o,
+ input [255:0]ddr_data_i,
+ input ddr_rd_valid_i,
+ input ddr_fifo_rd_i,
+ output reg [63:0] pcie_data_o,
+ output ddr_fifo_empty_o,
+ output [10:0] ddr_fifo_data_cnt_o,
+ output ddr_fifo_full_o,
+ input i_clr_recv_buffer,
+ input i_switch_recv_buffer
+);
+
+
+parameter IDLE = 'd0,
+ REQ_BUF1 = 'd1,
+ WAIT_BUF1_ACK = 'd2,
+ REQ_BUF2 = 'd3,
+ WAIT_BUF2_ACK = 'd4,
+ REQ_BUF3 = 'd5,
+ WAIT_BUF3_ACK = 'd6,
+ REQ_BUF4 = 'd7,
+ WAIT_BUF4_ACK = 'd8,
+ INT_RESET = 'd9,
+ CLR_CNTR = 'd10;
+
+reg [3:0] state;
+reg last_flag;
+reg [31:0] rd_len;
+reg [28:0] rcvd_data_cnt;
+reg [31:0] expected_data_cnt;
+reg [9:0] fifo_1_expt_cnt;
+reg [9:0] fifo_2_expt_cnt;
+reg [9:0] fifo_3_expt_cnt;
+reg [9:0] fifo_4_expt_cnt;
+reg [9:0] fifo_1_rcv_cnt;
+reg [9:0] fifo_2_rcv_cnt;
+reg [9:0] fifo_3_rcv_cnt;
+reg [9:0] fifo_4_rcv_cnt;
+reg clr_rcv_data_cntr;
+reg current_read_fifo;
+wire fifo1_rd_en;
+wire fifo2_rd_en;
+wire [255:0] fifo1_rd_data;
+wire [255:0] fifo2_rd_data;
+wire [255:0] fifo3_rd_data;
+wire [255:0] fifo4_rd_data;
+wire fifo1_empty;
+wire fifo2_empty;
+wire fifo3_empty;
+wire fifo4_empty;
+reg fifo1_empty_p;
+reg fifo1_empty_p1;
+reg fifo2_empty_p;
+reg fifo2_empty_p1;
+reg fifo3_empty_p;
+reg fifo3_empty_p1;
+reg fifo4_empty_p;
+reg fifo4_empty_p1;
+reg clr_fifo1_data_cntr;
+reg clr_fifo2_data_cntr;
+reg clr_fifo3_data_cntr;
+reg clr_fifo4_data_cntr;
+reg [63:0] dma_data_p;
+reg [255:0] fifo1_rd_data_p;
+reg [255:0] fifo2_rd_data_p;
+reg [255:0] fifo3_rd_data_p;
+reg [255:0] fifo4_rd_data_p;
+
+
+wire fifo_full;
+reg fifo1_wr_en;
+reg fifo2_wr_en;
+reg fifo3_wr_en;
+reg fifo4_wr_en;
+reg [3:0] fifo_rd_en;
+wire all_fifos_empty;
+wire[63:0] pcie_rd_fifo_data;
+
+always @(posedge pcie_clk_i)
+begin
+ if(ddr_fifo_rd_i)
+ pcie_data_o <= pcie_rd_fifo_data;
+
+ if(dma_data_valid_i & (dma_tag_i == 8'd0))
+ fifo1_wr_en <= 1'b1;
+ else
+ fifo1_wr_en <= 1'b0;
+
+ if(dma_data_valid_i & (dma_tag_i == 8'd1))
+ fifo2_wr_en <= 1'b1;
+ else
+ fifo2_wr_en <= 1'b0;
+
+ dma_data_p <= dma_data_i;
+end
+
+assign all_fifos_empty = fifo1_empty_p1 & fifo2_empty_p1;
+
+always @(*)
+begin
+ fifo_rd_en <= 4'h0;
+ fifo_rd_en[current_read_fifo] <= fifo_rd_i;
+end
+
+always @(*)
+begin
+ case(current_read_fifo)
+ 1'b0:begin
+ ddr_data_o <= fifo1_rd_data_p;
+ fifo_empty_o <= fifo1_empty;
+ end
+ 1'b1:begin
+ ddr_data_o <= fifo2_rd_data_p;
+ fifo_empty_o <= fifo2_empty;
+ end
+ endcase
+end
+
+always @(posedge ddr_clk_i)
+begin
+ if(fifo_rd_en[0])
+ fifo1_rd_data_p <= fifo1_rd_data;
+ if(fifo_rd_en[1])
+ fifo2_rd_data_p <= fifo2_rd_data;
+end
+
+always @(posedge pcie_clk_i)
+begin
+ if(!rst_n)
+ begin
+ state <= IDLE;
+ dma_rd_req_o <= 1'b0;
+ dma_done_o <= 1'b0;
+ last_flag <= 1'b0;
+ clr_fifo1_data_cntr <= 1'b1;
+ clr_fifo2_data_cntr <= 1'b1;
+ clr_fifo3_data_cntr <= 1'b1;
+ clr_fifo4_data_cntr <= 1'b1;
+ end
+ else
+ begin
+ case(state)
+ IDLE:begin
+ dma_done_o <= 1'b0;
+ last_flag <= 1'b0;
+ clr_rcv_data_cntr <= 1'b1;
+ expected_data_cnt <= dma_len_i;
+ dma_rd_req_addr_o <= dma_src_addr_i;
+ rd_len <= dma_len_i;
+ fifo_1_expt_cnt <= 10'd0;
+ fifo_2_expt_cnt <= 10'd0;
+ fifo_3_expt_cnt <= 10'd0;
+ fifo_4_expt_cnt <= 10'd0;
+ clr_fifo1_data_cntr <= 1'b0;
+ clr_fifo2_data_cntr <= 1'b0;
+ clr_fifo3_data_cntr <= 1'b0;
+ clr_fifo4_data_cntr <= 1'b0;
+ if(ctrl_en_i) //DDR DMA is enabled
+ begin
+ state <= REQ_BUF1;
+ end
+ end
+ REQ_BUF1:begin
+ clr_rcv_data_cntr <= 1'b0;
+ if((fifo_1_rcv_cnt >= fifo_1_expt_cnt) & fifo1_empty_p1) //If all data for the FIFO has arrived and written into DDR
+ begin
+ state <= WAIT_BUF1_ACK;
+ dma_rd_req_o <= 1'b1;
+ dma_rd_tag_o <= 8'd0;
+ clr_fifo1_data_cntr <= 1'b1;//Clear received cntr for FIFO1 since new request starting
+ if(rd_len <= 'd4096)
+ begin
+ dma_rd_req_len_o <= rd_len[11:0];
+ //fifo_1_expt_cnt <= rd_len[11:0];
+ last_flag <= 1'b1;
+ end
+ else
+ begin
+ dma_rd_req_len_o <= 0;
+ fifo_1_expt_cnt <= 10'd512;
+ end
+ end
+ end
+ WAIT_BUF1_ACK:begin
+ clr_fifo1_data_cntr <= 1'b0;
+ if(dma_req_ack_i)
+ begin
+ dma_rd_req_o <= 1'b0;
+ if(last_flag) //If all data is read, wait until complete data is received
+ begin
+ state <= INT_RESET;
+ end
+ else
+ begin
+ state <= REQ_BUF2;
+ rd_len <= rd_len - 'd4096;
+ dma_rd_req_addr_o <= dma_rd_req_addr_o + 'd4096;
+ end
+ end
+ end
+ REQ_BUF2:begin
+ if((fifo_2_rcv_cnt >= fifo_2_expt_cnt) & fifo2_empty_p1) //If all data for the FIFO has arrived and written into DDR
+ begin
+ state <= WAIT_BUF2_ACK;
+ dma_rd_req_o <= 1'b1;
+ dma_rd_tag_o <= 8'd1;
+ clr_fifo2_data_cntr <= 1'b1; //Clear received cntr for FIFO1 since new request starting
+ if(rd_len <= 'd4096)
+ begin
+ dma_rd_req_len_o <= rd_len[11:0];
+ //fifo_2_expt_cnt <= rd_len[11:0];
+ last_flag <= 1'b1;
+ end
+ else
+ begin
+ dma_rd_req_len_o <= 0;
+ fifo_2_expt_cnt <= 10'd512;
+ end
+ end
+ end
+ WAIT_BUF2_ACK:begin
+ clr_fifo2_data_cntr <= 1'b0;
+ if(dma_req_ack_i)
+ begin
+ dma_rd_req_o <= 1'b0;
+ if(last_flag) //If all data is read, wait until complete data is received
+ begin
+ state <= INT_RESET;
+ end
+ else
+ begin
+ state <= REQ_BUF1;//REQ_BUF3;
+ rd_len <= rd_len - 'd4096;
+ dma_rd_req_addr_o <= dma_rd_req_addr_o + 'd4096;
+ end
+ end
+ end
+ INT_RESET:begin
+ if(rcvd_data_cnt >= expected_data_cnt[31:3]) //When both FIFOs are empty, go to idle
+ begin
+ dma_done_o <= 1'b1;
+ end
+ if(~ctrl_en_i & dma_done_ack_i)
+ begin
+ state <= CLR_CNTR;
+ dma_done_o <= 1'b0;
+ end
+ end
+ CLR_CNTR:begin
+ if(all_fifos_empty)
+ begin
+ clr_rcv_data_cntr <= 1'b1;
+ clr_fifo1_data_cntr <= 1'b1;
+ clr_fifo2_data_cntr <= 1'b1;
+ clr_fifo3_data_cntr <= 1'b1;
+ clr_fifo4_data_cntr <= 1'b1;
+ state <= IDLE;
+ end
+ end
+ endcase
+ end
+end
+
+
+
+always @(posedge pcie_clk_i)
+begin
+ if(!rst_n)
+ rcvd_data_cnt <= 0;
+ else
+ begin
+ if(clr_rcv_data_cntr)
+ rcvd_data_cnt <= 0;
+ else if(fifo1_wr_en|fifo2_wr_en)
+ rcvd_data_cnt <= rcvd_data_cnt + 1'd1;
+ end
+end
+
+always @(posedge pcie_clk_i)
+begin
+ if(!rst_n)
+ fifo_1_rcv_cnt <= 0;
+ else
+ begin
+ if(clr_fifo1_data_cntr)
+ fifo_1_rcv_cnt <= 0;
+ else if(fifo1_wr_en)
+ fifo_1_rcv_cnt <= fifo_1_rcv_cnt + 1'd1;
+ end
+end
+
+always @(posedge pcie_clk_i)
+begin
+ if(!rst_n)
+ fifo_2_rcv_cnt <= 0;
+ else
+ begin
+ if(clr_fifo2_data_cntr)
+ fifo_2_rcv_cnt <= 0;
+ else if(fifo2_wr_en)
+ fifo_2_rcv_cnt <= fifo_2_rcv_cnt + 1'd1;
+ end
+end
+
+
+always @(posedge ddr_clk_i)
+begin
+ if(i_clr_recv_buffer)
+ current_read_fifo <= 1'b0;
+ else if(i_switch_recv_buffer)
+ current_read_fifo <= current_read_fifo + 1'b1;;
+end
+
+always @(posedge pcie_clk_i)
+begin
+ fifo1_empty_p <= fifo1_empty;
+ fifo1_empty_p1 <= fifo1_empty_p;
+ fifo2_empty_p <= fifo2_empty;
+ fifo2_empty_p1 <= fifo2_empty_p;
+end
+
+ //DMA receive fifo
+data_fifo wr_df_1(
+ .rst(~rst_n),
+ .wr_clk(pcie_clk_i),
+ .rd_clk(ddr_clk_i),
+ .din(dma_data_p),
+ .wr_en(fifo1_wr_en),
+ .rd_en(fifo_rd_en[0]),
+ .dout(fifo1_rd_data),//ddr_data_o
+ .full(),//fifo1_full
+ .empty(fifo1_empty)
+);
+
+ //DMA receive fifo
+data_fifo wr_df_2(
+ .rst(~rst_n),
+ .wr_clk(pcie_clk_i),
+ .rd_clk(ddr_clk_i),
+ .din(dma_data_p),
+ .wr_en(fifo2_wr_en),
+ .rd_en(fifo_rd_en[1]),
+ .dout(fifo2_rd_data), //ddr_data_o
+ .full(), //fifo_full
+ .empty(fifo2_empty) //
+);
+
+//DMA transmit fifo
+ddr_rd_fifo rd_df (
+ .rst(~rst_n),
+ .wr_clk(ddr_clk_i),
+ .rd_clk(pcie_clk_i),
+ .din(ddr_data_i),
+ .wr_en(ddr_rd_valid_i),
+ .rd_en(ddr_fifo_rd_i),
+ .dout(pcie_rd_fifo_data),
+ .full(),
+ .empty(ddr_fifo_empty_o),
+ .rd_data_count(ddr_fifo_data_cnt_o),
+ .prog_full(ddr_fifo_full_o)
+);
+
+endmodule
+"
+"module fifo_128_8(\r
+input wire i_clk,\r
+input wire i_rst_n,\r
+input wire i_slv_valid,
+output wire o_slv_rdy,\r
+input wire [63:0] i_slv_data,\r
+output reg [7:0] o_mst_data,\r
+output wire o_mst_valid,
+input i_mst_rdy\r
+);\r
+\r
+reg [63:0] mem [0:15];\r
+reg [3:0] wr_addr;\r
+reg [6:0] rd_addr;\r
+reg [7:0] data_count;\r
+\r
+assign o_mst_valid = (data_count > 0) ? 1'b1 : 1'b0;
+assign o_slv_rdy = (data_count < 120) ? 1'b1 : 1'b0;
+assign valid_wr = i_slv_valid & o_slv_rdy;
+assign valid_rd = o_mst_valid & i_mst_rdy;\r
+\r
+always @(posedge i_clk)\r
+begin\r
+ if(!i_rst_n)\r
+\t begin\r
+\t wr_addr <= 0;\r
+\tend\r
+\telse\r
+\tbegin\r
+\t if(valid_wr)\r
+\t\tbegin\r
+\t\t mem[wr_addr] <= i_slv_data;\r
+\t\t\t wr_addr <= wr_addr + 1;\r
+\t\tend\t\r
+\tend\r
+end\r
+\r
+\r
+always @(posedge i_clk)\r
+begin\r
+ if(!i_rst_n)\r
+\tbegin\r
+\t rd_addr <= 0;\r
+\tend\r
+\telse\r
+\tbegin\r
+\t if(valid_rd)\r
+\t\t begin\r
+\t\t\trd_addr <= rd_addr + 1'b1;\r
+\t\tend\t\r
+\tend\r
+end
+
+always@(*)
+begin
+ case(rd_addr[2:0])
+\t 0:begin
+\t\t o_mst_data <= mem[rd_addr[6:3]][7:0];
+\t\t end
+\t 1:begin
+\t\t o_mst_data <= mem[rd_addr[6:3]][15:8];
+\t\t end
+\t 2:begin
+\t\t o_mst_data <= mem[rd_addr[6:3]][23:16];
+\t\t end
+\t\t 3:begin
+\t\t o_mst_data <= mem[rd_addr[6:3]][31:24];
+\t\t end
+\t 4:begin
+\t\t o_mst_data <= mem[rd_addr[6:3]][39:32];
+\t\t end
+\t 5:begin
+\t\t o_mst_data <= mem[rd_addr[6:3]][47:40];
+\t\t end
+\t 6:begin
+\t\t o_mst_data <= mem[rd_addr[6:3]][55:48];
+\t\t end
+\t\t 7:begin
+\t\t o_mst_data <= mem[rd_addr[6:3]][63:56];
+\t\t end\t
+\t endcase
+end\r
+\r
+always @(posedge i_clk)\r
+begin\r
+ if(!i_rst_n)\r
+\tbegin\r
+\t data_count <= 0;\r
+\tend\r
+\telse\r
+\tbegin\r
+ if(valid_wr & !valid_rd)\r
+\t\t data_count <= data_count + 8;\r
+\t\telse if(!valid_wr & valid_rd)\r
+ data_count <= data_count - 1'b1;
+\t\telse if(valid_wr & valid_rd)\r
+ data_count <= data_count + 7;\t\t\t \r
+\tend\r
+end\r
+\r
+endmodule\r
+"
+"/*******************************************************************************
+* This file is owned and controlled by Xilinx and must be used solely *
+* for design, simulation, implementation and creation of design files *
+* limited to Xilinx devices or technologies. Use with non-Xilinx *
+* devices or technologies is expressly prohibited and immediately *
+* terminates your license. *
+* *
+* XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION ""AS IS"" SOLELY *
+* FOR USE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR XILINX DEVICES. BY *
+* PROVIDING THIS DESIGN, CODE, OR INFORMATION AS ONE POSSIBLE *
+* IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD, XILINX IS *
+* MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE FROM ANY *
+* CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING ANY *
+* RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY *
+* DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE *
+* IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR *
+* REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF *
+* INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE. *
+* *
+* Xilinx products are not intended for use in life support appliances, *
+* devices, or systems. Use in such applications are expressly *
+* prohibited. *
+* *
+* (c) Copyright 1995-2013 Xilinx, Inc. *
+* All rights reserved. *
+*******************************************************************************/
+// You must compile the wrapper file tx_fifo.v when simulating
+// the core, tx_fifo. When compiling the wrapper file, be sure to
+// reference the XilinxCoreLib Verilog simulation library. For detailed
+// instructions, please refer to the ""CORE Generator Help"".
+
+// The synthesis directives ""translate_off/translate_on"" specified below are
+// supported by Xilinx, Mentor Graphics and Synplicity synthesis
+// tools. Ensure they are correct for your synthesis tool(s).
+
+`timescale 1ns/1ps
+
+module tx_fifo(
+ rst,
+ wr_clk,
+ rd_clk,
+ din,
+ wr_en,
+ rd_en,
+ dout,
+ full,
+ empty,
+ rd_data_count,
+ wr_data_count
+);
+
+input rst;
+input wr_clk;
+input rd_clk;
+input [63 : 0] din;
+input wr_en;
+input rd_en;
+output [7 : 0] dout;
+output full;
+output empty;
+output [13 : 0] rd_data_count;
+output [10 : 0] wr_data_count;
+
+endmodule"
+"//*****************************************************************************
+// (c) Copyright 2008 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : %version
+// \\ \\ Application : MIG
+// / / Filename : bank_cntrl.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : 7-Series
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+// Structural block instantiating the three sub blocks that make up
+// a bank machine.
+`timescale 1ps/1ps
+
+module mig_7series_v1_8_bank_cntrl #
+ (
+ parameter TCQ = 100,
+ parameter ADDR_CMD_MODE = ""1T"",
+ parameter BANK_WIDTH = 3,
+ parameter BM_CNT_WIDTH = 2,
+ parameter BURST_MODE = ""8"",
+ parameter COL_WIDTH = 12,
+ parameter CWL = 5,
+ parameter DATA_BUF_ADDR_WIDTH = 8,
+ parameter DRAM_TYPE = ""DDR3"",
+ parameter ECC = ""OFF"",
+ parameter ID = 4,
+ parameter nBANK_MACHS = 4,
+ parameter nCK_PER_CLK = 2,
+ parameter nOP_WAIT = 0,
+ parameter nRAS_CLKS = 10,
+ parameter nRCD = 5,
+ parameter nRTP = 4,
+ parameter nRP = 10,
+ parameter nWTP_CLKS = 5,
+ parameter ORDERING = ""NORM"",
+ parameter RANK_WIDTH = 2,
+ parameter RANKS = 4,
+ parameter RAS_TIMER_WIDTH = 5,
+ parameter ROW_WIDTH = 16,
+ parameter STARVE_LIMIT = 2
+ )
+ (/*AUTOARG*/
+ // Outputs
+ wr_this_rank_r, start_rcd, start_pre_wait, rts_row, rts_col, rts_pre, rtc,
+ row_cmd_wr, row_addr, req_size_r, req_row_r, req_ras,
+ req_periodic_rd_r, req_cas, req_bank_r, rd_this_rank_r,
+ rb_hit_busy_ns, ras_timer_ns, rank_busy_r, ordered_r,
+ ordered_issued, op_exit_req, end_rtp, demand_priority,
+ demand_act_priority, col_rdy_wr, col_addr, act_this_rank_r, idle_ns,
+ req_wr_r, rd_wr_r, bm_end, idle_r, head_r, req_rank_r,
+ rb_hit_busy_r, passing_open_bank, maint_hit, req_data_buf_addr_r,
+ // Inputs
+ was_wr, was_priority, use_addr, start_rcd_in,
+ size, sent_row, sent_col, sending_row, sending_pre, sending_col, rst, row,
+ req_rank_r_in, rd_rmw, rd_data_addr, rb_hit_busy_ns_in,
+ rb_hit_busy_cnt, ras_timer_ns_in, rank, periodic_rd_rank_r,
+ periodic_rd_insert, periodic_rd_ack_r, passing_open_bank_in,
+ order_cnt, op_exit_grant, maint_zq_r, maint_sre_r, maint_req_r, maint_rank_r,
+ maint_idle, low_idle_cnt_r, rnk_config_valid_r, inhbt_rd, inhbt_wr,
+ rnk_config_strobe, rnk_config, inhbt_act_faw_r, idle_cnt, hi_priority,
+ dq_busy_data, phy_rddata_valid, demand_priority_in, demand_act_priority_in,
+ data_buf_addr, col, cmd, clk, bm_end_in, bank, adv_order_q,
+ accept_req, accept_internal_r, rnk_config_kill_rts_col, phy_mc_ctl_full,
+ phy_mc_cmd_full, phy_mc_data_full
+ );
+
+ /*AUTOINPUT*/
+ // Beginning of automatic inputs (from unused autoinst inputs)
+ input accept_internal_r; // To bank_queue0 of bank_queue.v
+ input accept_req; // To bank_queue0 of bank_queue.v
+ input adv_order_q; // To bank_queue0 of bank_queue.v
+ input [BANK_WIDTH-1:0] bank; // To bank_compare0 of bank_compare.v
+ input [(nBANK_MACHS*2)-1:0] bm_end_in; // To bank_queue0 of bank_queue.v
+ input clk; // To bank_compare0 of bank_compare.v, ...
+ input [2:0] cmd; // To bank_compare0 of bank_compare.v
+ input [COL_WIDTH-1:0] col; // To bank_compare0 of bank_compare.v
+ input [DATA_BUF_ADDR_WIDTH-1:0] data_buf_addr;// To bank_compare0 of bank_compare.v
+ input [(nBANK_MACHS*2)-1:0] demand_act_priority_in;// To bank_state0 of bank_state.v
+ input [(nBANK_MACHS*2)-1:0] demand_priority_in;// To bank_state0 of bank_state.v
+ input phy_rddata_valid; // To bank_state0 of bank_state.v
+ input dq_busy_data; // To bank_state0 of bank_state.v
+ input hi_priority; // To bank_compare0 of bank_compare.v
+ input [BM_CNT_WIDTH-1:0] idle_cnt; // To bank_queue0 of bank_queue.v
+ input [RANKS-1:0] inhbt_act_faw_r; // To bank_state0 of bank_state.v
+ input [RANKS-1:0] inhbt_rd; // To bank_state0 of bank_state.v
+ input [RANKS-1:0] inhbt_wr; // To bank_state0 of bank_state.v
+ input [RANK_WIDTH-1:0]rnk_config; // To bank_state0 of bank_state.v
+ input rnk_config_strobe; // To bank_state0 of bank_state.v
+ input rnk_config_kill_rts_col;// To bank_state0 of bank_state.v
+ input rnk_config_valid_r; // To bank_state0 of bank_state.v
+ input low_idle_cnt_r; // To bank_state0 of bank_state.v
+ input maint_idle; // To bank_queue0 of bank_queue.v
+ input [RANK_WIDTH-1:0] maint_rank_r; // To bank_compare0 of bank_compare.v
+ input maint_req_r; // To bank_queue0 of bank_queue.v
+ input maint_zq_r; // To bank_compare0 of bank_compare.v
+ input maint_sre_r; // To bank_compare0 of bank_compare.v
+ input op_exit_grant; // To bank_state0 of bank_state.v
+ input [BM_CNT_WIDTH-1:0] order_cnt; // To bank_queue0 of bank_queue.v
+ input [(nBANK_MACHS*2)-1:0] passing_open_bank_in;// To bank_queue0 of bank_queue.v
+ input periodic_rd_ack_r; // To bank_queue0 of bank_queue.v
+ input periodic_rd_insert; // To bank_compare0 of bank_compare.v
+ input [RANK_WIDTH-1:0] periodic_rd_rank_r; // To bank_compare0 of bank_compare.v
+ input phy_mc_ctl_full;
+ input phy_mc_cmd_full;
+ input phy_mc_data_full;
+ input [RANK_WIDTH-1:0] rank; // To bank_compare0 of bank_compare.v
+ input [(2*(RAS_TIMER_WIDTH*nBANK_MACHS))-1:0] ras_timer_ns_in;// To bank_state0 of bank_state.v
+ input [BM_CNT_WIDTH-1:0] rb_hit_busy_cnt; // To bank_queue0 of bank_queue.v
+ input [(nBANK_MACHS*2)-1:0] rb_hit_busy_ns_in;// To bank_queue0 of bank_queue.v
+ input [DATA_BUF_ADDR_WIDTH-1:0] rd_data_addr; // To bank_state0 of bank_state.v
+ input rd_rmw; // To bank_state0 of bank_state.v
+ input [(RANK_WIDTH*nBANK_MACHS*2)-1:0] req_rank_r_in;// To bank_state0 of bank_state.v
+ input [ROW_WIDTH-1:0] row; // To bank_compare0 of bank_compare.v
+ input rst; // To bank_state0 of bank_state.v, ...
+ input sending_col; // To bank_compare0 of bank_compare.v, ...
+ input sending_row; // To bank_state0 of bank_state.v
+ input sending_pre;
+ input sent_col; // To bank_state0 of bank_state.v
+ input sent_row; // To bank_state0 of bank_state.v
+ input size; // To bank_compare0 of bank_compare.v
+ input [(nBANK_MACHS*2)-1:0] start_rcd_in; // To bank_state0 of bank_state.v
+ input use_addr; // To bank_queue0 of bank_queue.v
+ input was_priority; // To bank_queue0 of bank_queue.v
+ input was_wr; // To bank_queue0 of bank_queue.v
+ // End of automatics
+
+ /*AUTOOUTPUT*/
+ // Beginning of automatic outputs (from unused autoinst outputs)
+ output [RANKS-1:0] act_this_rank_r; // From bank_state0 of bank_state.v
+ output [ROW_WIDTH-1:0] col_addr; // From bank_compare0 of bank_compare.v
+ output col_rdy_wr; // From bank_state0 of bank_state.v
+ output demand_act_priority; // From bank_state0 of bank_state.v
+ output demand_priority; // From bank_state0 of bank_state.v
+ output end_rtp; // From bank_state0 of bank_state.v
+ output op_exit_req; // From bank_state0 of bank_state.v
+ output ordered_issued; // From bank_queue0 of bank_queue.v
+ output ordered_r; // From bank_queue0 of bank_queue.v
+ output [RANKS-1:0] rank_busy_r; // From bank_compare0 of bank_compare.v
+ output [RAS_TIMER_WIDTH-1:0] ras_timer_ns; // From bank_state0 of bank_state.v
+ output rb_hit_busy_ns; // From bank_compare0 of bank_compare.v
+ output [RANKS-1:0] rd_this_rank_r; // From bank_state0 of bank_state.v
+ output [BANK_WIDTH-1:0] req_bank_r; // From bank_compare0 of bank_compare.v
+ output req_cas; // From bank_compare0 of bank_compare.v
+ output req_periodic_rd_r; // From bank_compare0 of bank_compare.v
+ output req_ras; // From bank_compare0 of bank_compare.v
+ output [ROW_WIDTH-1:0] req_row_r; // From bank_compare0 of bank_compare.v
+ output req_size_r; // From bank_compare0 of bank_compare.v
+ output [ROW_WIDTH-1:0] row_addr; // From bank_compare0 of bank_compare.v
+ output row_cmd_wr; // From bank_compare0 of bank_compare.v
+ output rtc; // From bank_state0 of bank_state.v
+ output rts_col; // From bank_state0 of bank_state.v
+ output rts_row; // From bank_state0 of bank_state.v
+ output rts_pre;
+ output start_pre_wait; // From bank_state0 of bank_state.v
+ output start_rcd; // From bank_state0 of bank_state.v
+ output [RANKS-1:0] wr_this_rank_r; // From bank_state0 of bank_state.v
+ // End of automatics
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire act_wait_r; // From bank_state0 of bank_state.v
+ wire allow_auto_pre; // From bank_state0 of bank_state.v
+ wire auto_pre_r; // From bank_queue0 of bank_queue.v
+ wire bank_wait_in_progress; // From bank_state0 of bank_state.v
+ wire order_q_zero; // From bank_queue0 of bank_queue.v
+ wire pass_open_bank_ns; // From bank_queue0 of bank_queue.v
+ wire pass_open_bank_r; // From bank_queue0 of bank_queue.v
+ wire pre_wait_r; // From bank_state0 of bank_state.v
+ wire precharge_bm_end; // From bank_state0 of bank_state.v
+ wire q_has_priority; // From bank_queue0 of bank_queue.v
+ wire q_has_rd; // From bank_queue0 of bank_queue.v
+ wire [nBANK_MACHS*2-1:0] rb_hit_busies_r; // From bank_queue0 of bank_queue.v
+ wire rcv_open_bank; // From bank_queue0 of bank_queue.v
+ wire rd_half_rmw; // From bank_state0 of bank_state.v
+ wire req_priority_r; // From bank_compare0 of bank_compare.v
+ wire row_hit_r; // From bank_compare0 of bank_compare.v
+ wire tail_r; // From bank_queue0 of bank_queue.v
+ wire wait_for_maint_r; // From bank_queue0 of bank_queue.v
+ // End of automatics
+
+ output idle_ns;
+ output req_wr_r;
+ output rd_wr_r;
+ output bm_end;
+ output idle_r;
+ output head_r;
+ output [RANK_WIDTH-1:0] req_rank_r;
+ output rb_hit_busy_r;
+ output passing_open_bank;
+ output maint_hit;
+ output [DATA_BUF_ADDR_WIDTH-1:0] req_data_buf_addr_r;
+
+ mig_7series_v1_8_bank_compare #
+ (/*AUTOINSTPARAM*/
+ // Parameters
+ .BANK_WIDTH (BANK_WIDTH),
+ .TCQ (TCQ),
+ .BURST_MODE (BURST_MODE),
+ .COL_WIDTH (COL_WIDTH),
+ .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH),
+ .ECC (ECC),
+ .RANK_WIDTH (RANK_WIDTH),
+ .RANKS (RANKS),
+ .ROW_WIDTH (ROW_WIDTH))
+ bank_compare0
+ (/*AUTOINST*/
+ // Outputs
+ .req_data_buf_addr_r (req_data_buf_addr_r[DATA_BUF_ADDR_WIDTH-1:0]),
+ .req_periodic_rd_r (req_periodic_rd_r),
+ .req_size_r (req_size_r),
+ .rd_wr_r (rd_wr_r),
+ .req_rank_r (req_rank_r[RANK_WIDTH-1:0]),
+ .req_bank_r (req_bank_r[BANK_WIDTH-1:0]),
+ .req_row_r (req_row_r[ROW_WIDTH-1:0]),
+ .req_wr_r (req_wr_r),
+ .req_priority_r (req_priority_r),
+ .rb_hit_busy_r (rb_hit_busy_r),
+ .rb_hit_busy_ns (rb_hit_busy_ns),
+ .row_hit_r (row_hit_r),
+ .maint_hit (maint_hit),
+ .col_addr (col_addr[ROW_WIDTH-1:0]),
+ .req_ras (req_ras),
+ .req_cas (req_cas),
+ .row_cmd_wr (row_cmd_wr),
+ .row_addr (row_addr[ROW_WIDTH-1:0]),
+ .rank_busy_r (rank_busy_r[RANKS-1:0]),
+ // Inputs
+ .clk (clk),
+ .idle_ns (idle_ns),
+ .idle_r (idle_r),
+ .data_buf_addr (data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]),
+ .periodic_rd_insert (periodic_rd_insert),
+ .size (size),
+ .cmd (cmd[2:0]),
+ .sending_col (sending_col),
+ .rank (rank[RANK_WIDTH-1:0]),
+ .periodic_rd_rank_r (periodic_rd_rank_r[RANK_WIDTH-1:0]),
+ .bank (bank[BANK_WIDTH-1:0]),
+ .row (row[ROW_WIDTH-1:0]),
+ .col (col[COL_WIDTH-1:0]),
+ .hi_priority (hi_priority),
+ .maint_rank_r (maint_rank_r[RANK_WIDTH-1:0]),
+ .maint_zq_r (maint_zq_r),
+ .maint_sre_r (maint_sre_r),
+ .auto_pre_r (auto_pre_r),
+ .rd_half_rmw (rd_half_rmw),
+ .act_wait_r (act_wait_r));
+
+ mig_7series_v1_8_bank_state #
+ (/*AUTOINSTPARAM*/
+ // Parameters
+ .TCQ (TCQ),
+ .ADDR_CMD_MODE (ADDR_CMD_MODE),
+ .BM_CNT_WIDTH (BM_CNT_WIDTH),
+ .BURST_MODE (BURST_MODE),
+ .CWL (CWL),
+ .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH),
+ .DRAM_TYPE (DRAM_TYPE),
+ .ECC (ECC),
+ .ID (ID),
+ .nBANK_MACHS (nBANK_MACHS),
+ .nCK_PER_CLK (nCK_PER_CLK),
+ .nOP_WAIT (nOP_WAIT),
+ .nRAS_CLKS (nRAS_CLKS),
+ .nRP (nRP),
+ .nRTP (nRTP),
+ .nRCD (nRCD),
+ .nWTP_CLKS (nWTP_CLKS),
+ .ORDERING (ORDERING),
+ .RANKS (RANKS),
+ .RANK_WIDTH (RANK_WIDTH),
+ .RAS_TIMER_WIDTH (RAS_TIMER_WIDTH),
+ .STARVE_LIMIT (STARVE_LIMIT))
+ bank_state0
+ (/*AUTOINST*/
+ // Outputs
+ .start_rcd (start_rcd),
+ .act_wait_r (act_wait_r),
+ .rd_half_rmw (rd_half_rmw),
+ .ras_timer_ns (ras_timer_ns[RAS_TIMER_WIDTH-1:0]),
+ .end_rtp (end_rtp),
+ .bank_wait_in_progress (bank_wait_in_progress),
+ .start_pre_wait (start_pre_wait),
+ .op_exit_req (op_exit_req),
+ .pre_wait_r (pre_wait_r),
+ .allow_auto_pre (allow_auto_pre),
+ .precharge_bm_end (precharge_bm_end),
+ .demand_act_priority (demand_act_priority),
+ .rts_row (rts_row),
+ .rts_pre (rts_pre),
+ .act_this_rank_r (act_this_rank_r[RANKS-1:0]),
+ .demand_priority (demand_priority),
+ .col_rdy_wr (col_rdy_wr),
+ .rts_col (rts_col),
+ .wr_this_rank_r (wr_this_rank_r[RANKS-1:0]),
+ .rd_this_rank_r (rd_this_rank_r[RANKS-1:0]),
+ // Inputs
+ .clk (clk),
+ .rst (rst),
+ .bm_end (bm_end),
+ .pass_open_bank_r (pass_open_bank_r),
+ .sending_row (sending_row),
+ .sending_pre (sending_pre),
+ .rcv_open_bank (rcv_open_bank),
+ .sending_col (sending_col),
+ .rd_wr_r (rd_wr_r),
+ .req_wr_r (req_wr_r),
+ .rd_data_addr (rd_data_addr[DATA_BUF_ADDR_WIDTH-1:0]),
+ .req_data_buf_addr_r (req_data_buf_addr_r[DATA_BUF_ADDR_WIDTH-1:0]),
+ .phy_rddata_valid (phy_rddata_valid),
+ .rd_rmw (rd_rmw),
+ .ras_timer_ns_in (ras_timer_ns_in[(2*(RAS_TIMER_WIDTH*nBANK_MACHS))-1:0]),
+ .rb_hit_busies_r (rb_hit_busies_r[(nBANK_MACHS*2)-1:0]),
+ .idle_r (idle_r),
+ .passing_open_bank (passing_open_bank),
+ .low_idle_cnt_r (low_idle_cnt_r),
+ .op_exit_grant (op_exit_grant),
+ .tail_r (tail_r),
+ .auto_pre_r (auto_pre_r),
+ .pass_open_bank_ns (pass_open_bank_ns),
+ .phy_mc_cmd_full (phy_mc_cmd_full),
+ .phy_mc_ctl_full (phy_mc_ctl_full),
+ .phy_mc_data_full (phy_mc_data_full),
+ .rnk_config (rnk_config[RANK_WIDTH-1:0]),
+ .rnk_config_strobe (rnk_config_strobe),
+ .rnk_config_kill_rts_col (rnk_config_kill_rts_col),
+ .rnk_config_valid_r (rnk_config_valid_r),
+ .rtc (rtc),
+ .req_rank_r (req_rank_r[RANK_WIDTH-1:0]),
+ .req_rank_r_in (req_rank_r_in[(RANK_WIDTH*nBANK_MACHS*2)-1:0]),
+ .start_rcd_in (start_rcd_in[(nBANK_MACHS*2)-1:0]),
+ .inhbt_act_faw_r (inhbt_act_faw_r[RANKS-1:0]),
+ .wait_for_maint_r (wait_for_maint_r),
+ .head_r (head_r),
+ .sent_row (sent_row),
+ .demand_act_priority_in (demand_act_priority_in[(nBANK_MACHS*2)-1:0]),
+ .order_q_zero (order_q_zero),
+ .sent_col (sent_col),
+ .q_has_rd (q_has_rd),
+ .q_has_priority (q_has_priority),
+ .req_priority_r (req_priority_r),
+ .idle_ns (idle_ns),
+ .demand_priority_in (demand_priority_in[(nBANK_MACHS*2)-1:0]),
+ .inhbt_rd (inhbt_rd[RANKS-1:0]),
+ .inhbt_wr (inhbt_wr[RANKS-1:0]),
+ .dq_busy_data (dq_busy_data));
+
+ mig_7series_v1_8_bank_queue #
+ (/*AUTOINSTPARAM*/
+ // Parameters
+ .TCQ (TCQ),
+ .BM_CNT_WIDTH (BM_CNT_WIDTH),
+ .nBANK_MACHS (nBANK_MACHS),
+ .ORDERING (ORDERING),
+ .ID (ID))
+ bank_queue0
+ (/*AUTOINST*/
+ // Outputs
+ .head_r (head_r),
+ .tail_r (tail_r),
+ .idle_ns (idle_ns),
+ .idle_r (idle_r),
+ .pass_open_bank_ns (pass_open_bank_ns),
+ .pass_open_bank_r (pass_open_bank_r),
+ .auto_pre_r (auto_pre_r),
+ .bm_end (bm_end),
+ .passing_open_bank (passing_open_bank),
+ .ordered_issued (ordered_issued),
+ .ordered_r (ordered_r),
+ .order_q_zero (order_q_zero),
+ .rcv_open_bank (rcv_open_bank),
+ .rb_hit_busies_r (rb_hit_busies_r[nBANK_MACHS*2-1:0]),
+ .q_has_rd (q_has_rd),
+ .q_has_priority (q_has_priority),
+ .wait_for_maint_r (wait_for_maint_r),
+ // Inputs
+ .clk (clk),
+ .rst (rst),
+ .accept_internal_r (accept_internal_r),
+ .use_addr (use_addr),
+ .periodic_rd_ack_r (periodic_rd_ack_r),
+ .bm_end_in (bm_end_in[(nBANK_MACHS*2)-1:0]),
+ .idle_cnt (idle_cnt[BM_CNT_WIDTH-1:0]),
+ .rb_hit_busy_cnt (rb_hit_busy_cnt[BM_CNT_WIDTH-1:0]),
+ .accept_req (accept_req),
+ .rb_hit_busy_r (rb_hit_busy_r),
+ .maint_idle (maint_idle),
+ .maint_hit (maint_hit),
+ .row_hit_r (row_hit_r),
+ .pre_wait_r (pre_wait_r),
+ .allow_auto_pre (allow_auto_pre),
+ .sending_col (sending_col),
+ .req_wr_r (req_wr_r),
+ .rd_wr_r (rd_wr_r),
+ .bank_wait_in_progress (bank_wait_in_progress),
+ .precharge_bm_end (precharge_bm_end),
+ .adv_order_q (adv_order_q),
+ .order_cnt (order_cnt[BM_CNT_WIDTH-1:0]),
+ .rb_hit_busy_ns_in (rb_hit_busy_ns_in[(nBANK_MACHS*2)-1:0]),
+ .passing_open_bank_in (passing_open_bank_in[(nBANK_MACHS*2)-1:0]),
+ .was_wr (was_wr),
+ .maint_req_r (maint_req_r),
+ .was_priority (was_priority));
+
+endmodule // bank_cntrl
+"
+"//-----------------------------------------------------------------------------
+//
+// (c) Copyright 2009-2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//-----------------------------------------------------------------------------
+// Project : Virtex-6 Integrated Block for PCI Express
+// File : gtx_wrapper_v6.v
+// Version : 2.4
+
+//-- Description: GTX module for Virtex6 PCIe Block
+//--
+//--
+//--
+//--------------------------------------------------------------------------------
+
+`timescale 1ns/1ns
+
+module gtx_wrapper_v6 (
+
+ // TX
+ TX,
+ TX_,
+ TxData,
+ TxDataK,
+ TxElecIdle,
+ TxCompliance,
+
+ // RX
+ RX,
+ RX_,
+ RxData,
+ RxDataK,
+ RxPolarity,
+ RxValid,
+ RxElecIdle,
+ RxStatus,
+
+ // other
+ GTRefClkout,
+ plm_in_l0,
+ plm_in_rl,
+ plm_in_dt,
+ plm_in_rs,
+ RxPLLLkDet,
+ TxDetectRx,
+ PhyStatus,
+ TXPdownAsynch,
+ PowerDown,
+ Rate,
+ Reset_n,
+ GTReset_n,
+ PCLK,
+ REFCLK,
+ TxDeemph,
+ TxMargin,
+ TxSwing,
+ ChanIsAligned,
+ local_pcs_reset,
+ RxResetDone,
+ SyncDone,
+ DRPCLK,
+ TxOutClk
+
+ );
+
+ parameter NO_OF_LANES = 1;
+ parameter REF_CLK_FREQ = 0;
+ parameter PL_FAST_TRAIN = ""FALSE"";
+
+ localparam GTX_PLL_DIVSEL_FB = (REF_CLK_FREQ == 0) ? 5 :
+ (REF_CLK_FREQ == 1) ? 4 :
+ (REF_CLK_FREQ == 2) ? 2 : 0;
+ localparam SIMULATION = (PL_FAST_TRAIN == ""TRUE"") ? 1 : 0;
+
+ localparam RXPLL_CP_CFG = (REF_CLK_FREQ == 0) ? 8\'h05 :
+ (REF_CLK_FREQ == 1) ? 8\'h05 :
+ (REF_CLK_FREQ == 2) ? 8\'h05 : 8\'h05;
+
+ localparam TXPLL_CP_CFG = (REF_CLK_FREQ == 0) ? 8\'h05 :
+ (REF_CLK_FREQ == 1) ? 8\'h05 :
+ (REF_CLK_FREQ == 2) ? 8\'h05 : 8\'h05;
+
+ localparam RX_CLK25_DIVIDER = (REF_CLK_FREQ == 0) ? 4 :
+ (REF_CLK_FREQ == 1) ? 5 :
+ (REF_CLK_FREQ == 2) ? 10 : 10 ;
+
+ localparam TX_CLK25_DIVIDER = (REF_CLK_FREQ == 0) ? 4 :
+ (REF_CLK_FREQ == 1) ? 5 :
+ (REF_CLK_FREQ == 2) ? 10 : 10 ;
+
+ // TX
+ output [NO_OF_LANES-1:0] TX;
+ output [NO_OF_LANES-1:0] TX_;
+ input [(NO_OF_LANES*16)-1:0] TxData;
+ input [(NO_OF_LANES*2)-1:0] TxDataK;
+ input [NO_OF_LANES-1:0] TxElecIdle;
+ input [NO_OF_LANES-1:0] TxCompliance;
+
+ // RX
+ input [NO_OF_LANES-1:0] RX;
+ input [NO_OF_LANES-1:0] RX_;
+ output [(NO_OF_LANES*16)-1:0] RxData;
+ output [(NO_OF_LANES*2)-1:0] RxDataK;
+ input [NO_OF_LANES-1:0] RxPolarity;
+ output [NO_OF_LANES-1:0] RxValid;
+ output [NO_OF_LANES-1:0] RxElecIdle;
+ output [(NO_OF_LANES*3)-1:0] RxStatus;
+ // other
+ output [NO_OF_LANES-1:0] GTRefClkout;
+ input plm_in_l0;
+ input plm_in_rl;
+ input plm_in_dt;
+ input plm_in_rs;
+ output [NO_OF_LANES-1:0] RxPLLLkDet;
+ input TxDetectRx;
+ output [NO_OF_LANES-1:0] PhyStatus;
+ input PCLK;
+ output [NO_OF_LANES-1:0] ChanIsAligned;
+ input TXPdownAsynch;
+
+ input [(NO_OF_LANES*2)-1:0] PowerDown;
+ input Rate;
+ input Reset_n;
+ input GTReset_n;
+ input REFCLK;
+ input TxDeemph;
+ input TxMargin;
+ input TxSwing;
+ input local_pcs_reset;
+ output RxResetDone;
+ output SyncDone;
+ input DRPCLK;
+ output TxOutClk;
+ genvar i;
+
+ // dummy signals to avoid port mismatch with DUAL_GTX
+ wire [15:0] RxData_dummy;
+ wire [1:0] RxDataK_dummy;
+ wire [15:0] TxData_dummy;
+ wire [1:0] TxDataK_dummy;
+
+ // inputs
+ wire [(NO_OF_LANES*16)-1:0] GTX_TxData = TxData;
+ wire [(NO_OF_LANES*2)-1:0] GTX_TxDataK = TxDataK;
+ wire [(NO_OF_LANES)-1:0] GTX_TxElecIdle = TxElecIdle;
+ wire [(NO_OF_LANES-1):0] GTX_TxCompliance = TxCompliance;
+ wire [(NO_OF_LANES)-1:0] GTX_RXP = RX[(NO_OF_LANES)-1:0];
+ wire [(NO_OF_LANES)-1:0] GTX_RXN = RX_[(NO_OF_LANES)-1:0];
+
+ // outputs
+ wire [(NO_OF_LANES)-1:0] GTX_TXP;
+ wire [(NO_OF_LANES)-1:0] GTX_TXN;
+ wire [(NO_OF_LANES*16)-1:0] GTX_RxData;
+ wire [(NO_OF_LANES*2)-1:0] GTX_RxDataK;
+ wire [(NO_OF_LANES)-1:0] GTX_RxPolarity = RxPolarity ;
+ wire [(NO_OF_LANES)-1:0] GTX_RxValid;
+ wire [(NO_OF_LANES)-1:0] GTX_RxElecIdle;
+ wire [(NO_OF_LANES-1):0] GTX_RxResetDone;
+ wire [(NO_OF_LANES*3)-1:0] GTX_RxChbondLevel;
+ wire [(NO_OF_LANES*3)-1:0] GTX_RxStatus;
+
+
+ wire [3:0] RXCHBOND [NO_OF_LANES+1:0];
+ wire [3:0] TXBYPASS8B10B = 4\'b0000;
+ wire RXDEC8B10BUSE = 1\'b1;
+ wire [NO_OF_LANES-1:0] GTX_PhyStatus;
+ wire RESETDONE [NO_OF_LANES-1:0];
+ wire REFCLK;
+ wire GTXRESET = 1\'b0;
+
+ wire [NO_OF_LANES-1:0] SYNC_DONE;
+ wire [NO_OF_LANES-1:0] OUT_DIV_RESET;
+ wire [NO_OF_LANES-1:0] PCS_RESET;
+ wire [NO_OF_LANES-1:0] TXENPMAPHASEALIGN;
+ wire [NO_OF_LANES-1:0] TXPMASETPHASE;
+ wire [NO_OF_LANES-1:0] TXRESETDONE;
+ wire [NO_OF_LANES-1:0] TXRATEDONE;
+ wire [NO_OF_LANES-1:0] PHYSTATUS;
+ wire [NO_OF_LANES-1:0] RXVALID;
+ wire [NO_OF_LANES-1:0] RATE_CLK_SEL;
+ wire [NO_OF_LANES-1:0] TXOCLK;
+ wire [NO_OF_LANES-1:0] TXDLYALIGNDISABLE;
+ wire [NO_OF_LANES-1:0] TXDLYALIGNRESET;
+
+
+ reg [(NO_OF_LANES-1):0] GTX_RxResetDone_q;
+ reg [(NO_OF_LANES-1):0] TXRESETDONE_q;
+
+ wire [NO_OF_LANES-1:0] RxValid;
+
+
+ wire [(NO_OF_LANES*8-1):0] daddr;
+ wire [NO_OF_LANES-1:0] den;
+ wire [(NO_OF_LANES*16-1):0] din;
+ wire [NO_OF_LANES-1:0] dwe;
+
+ wire [(NO_OF_LANES*4-1):0] drpstate;
+ wire [NO_OF_LANES-1:0] drdy;
+ wire [(NO_OF_LANES*16-1):0] dout;
+
+ wire write_drp_cb_fts;
+ wire write_drp_cb_ts1;
+
+ assign RxResetDone = &(GTX_RxResetDone_q[(NO_OF_LANES)-1:0]);
+ assign TX[(NO_OF_LANES)-1:0] = GTX_TXP[(NO_OF_LANES)-1:0];
+ assign TX_[(NO_OF_LANES)-1:0] = GTX_TXN[(NO_OF_LANES)-1:0];
+ assign RXCHBOND[0] = 4\'b0000;
+ assign TxData_dummy = 16\'b0;
+ assign TxDataK_dummy = 2\'b0;
+ assign SyncDone = &(SYNC_DONE[(NO_OF_LANES)-1:0]);
+ assign TxOutClk = TXOCLK[0];
+
+ assign write_drp_cb_fts = plm_in_l0;
+ assign write_drp_cb_ts1 = plm_in_rl | plm_in_dt;
+
+ // pipeline to improve timing
+ always @ (posedge PCLK) begin
+
+ GTX_RxResetDone_q[(NO_OF_LANES)-1:0] <= GTX_RxResetDone[(NO_OF_LANES)-1:0];
+ TXRESETDONE_q[(NO_OF_LANES)-1:0] <= TXRESETDONE[(NO_OF_LANES)-1:0];
+
+ end
+
+ generate
+ begin: no_of_lanes
+
+ for (i=0; i < NO_OF_LANES; i=i+1) begin: GTXD
+
+ assign GTX_RxChbondLevel[(3*i)+2:(3*i)] = (NO_OF_LANES-(i+1));
+
+ GTX_DRP_CHANALIGN_FIX_3752_V6 # (
+ .C_SIMULATION(SIMULATION)
+ ) GTX_DRP_CHANALIGN_FIX_3752 (
+
+ .dwe(dwe[i]),
+ .din(din[(16*i)+15:(16*i)]),
+ .den(den[i]),
+ .daddr(daddr[(8*i)+7:(8*i)]),
+ .drpstate(drpstate[(4*i)+3:(4*i)]),
+ .write_ts1(write_drp_cb_ts1),
+ .write_fts(write_drp_cb_fts),
+ .dout(dout[(16*i)+15:(16*i)]),
+ .drdy(drdy[i]),
+ .Reset_n(Reset_n),
+ .drp_clk(DRPCLK)
+
+ );
+
+ GTX_RX_VALID_FILTER_V6 # (
+ .CLK_COR_MIN_LAT(28)
+ )
+ GTX_RX_VALID_FILTER (
+
+ .USER_RXCHARISK ( RxDataK[(2*i)+1:2*i] ), //O
+ .USER_RXDATA ( RxData[(16*i)+15:(16*i)+0] ), //O
+ .USER_RXVALID ( RxValid[i] ), //O
+ .USER_RXELECIDLE ( RxElecIdle[i] ), //O
+ .USER_RX_STATUS ( RxStatus[(3*i)+2:(3*i)] ), //O
+ .USER_RX_PHY_STATUS ( PhyStatus[i] ), //O
+
+
+ .GT_RXCHARISK ( GTX_RxDataK[(2*i)+1:2*i] ), //I
+ .GT_RXDATA ( GTX_RxData[(16*i)+15:(16*i)+0] ), //I
+ .GT_RXVALID ( GTX_RxValid[i] ), //I
+ .GT_RXELECIDLE ( GTX_RxElecIdle[i] ), //I
+ .GT_RX_STATUS ( GTX_RxStatus[(3*i)+2:(3*i)] ), //I
+ .GT_RX_PHY_STATUS ( PHYSTATUS[i] ),
+
+ .PLM_IN_L0 ( plm_in_l0 ), //I
+ .PLM_IN_RS ( plm_in_rs ), //I
+ .USER_CLK ( PCLK ), //I
+ .RESET ( !Reset_n ) //I
+
+ );
+
+ GTX_TX_SYNC_RATE_V6 # (
+ .C_SIMULATION(SIMULATION)
+ )
+ GTX_TX_SYNC (
+
+ .ENPMAPHASEALIGN ( TXENPMAPHASEALIGN[i] ), //O
+ .PMASETPHASE ( TXPMASETPHASE[i] ), //O
+ .SYNC_DONE ( SYNC_DONE[i] ), //O
+ .OUT_DIV_RESET ( OUT_DIV_RESET[i] ), //O
+ .PCS_RESET ( PCS_RESET[i] ), //O
+ .USER_PHYSTATUS ( PHYSTATUS[i] ), //O
+ .TXALIGNDISABLE ( TXDLYALIGNDISABLE[i] ), //O
+ .DELAYALIGNRESET ( TXDLYALIGNRESET[i] ), //O
+
+ .USER_CLK ( PCLK), //I
+ .RESET ( !Reset_n ), //I
+ .RATE ( Rate ), //I
+ .RATEDONE ( TXRATEDONE[i] ), //I
+ .GT_PHYSTATUS ( GTX_PhyStatus[i] ), //I
+ .RESETDONE ( TXRESETDONE_q[i] & GTX_RxResetDone_q[i] ) //I
+
+ );
+
+ GTXE1 # (
+
+ .TX_DRIVE_MODE(""PIPE""),
+ .TX_DEEMPH_1(5\'b10010),
+ .TX_MARGIN_FULL_0(7\'b100_1101),
+
+ .TX_CLK_SOURCE(""RXPLL""),
+ .POWER_SAVE(10\'b0000110100),
+ .CM_TRIM ( 2\'b01 ),
+ .PMA_CDR_SCAN ( 27\'h640404C ),
+ .PMA_CFG( 76\'h0040000040000000003 ),
+ .RCV_TERM_GND (""TRUE""),
+ .RCV_TERM_VTTRX (""FALSE""),
+ .RX_DLYALIGN_EDGESET(5\'b00010),
+ .RX_DLYALIGN_LPFINC(4\'b0110),
+ .RX_DLYALIGN_OVRDSETTING(8\'b10000000),
+ .TERMINATION_CTRL(5\'b00000),
+ .TERMINATION_OVRD(""FALSE""),
+ .TX_DLYALIGN_LPFINC(4\'b0110),
+ .TX_DLYALIGN_OVRDSETTING(8\'b10000000),
+ .TXPLL_CP_CFG( TXPLL_CP_CFG ),
+ .OOBDETECT_THRESHOLD( 3\'b011 ),
+ .RXPLL_CP_CFG ( RXPLL_CP_CFG ),
+ //.TX_DETECT_RX_CFG( 14\'h1832 ),
+ .TX_TDCC_CFG ( 2\'b11 ),
+ .BIAS_CFG ( 17\'h00000 ),
+ .AC_CAP_DIS ( ""FALSE"" ),
+ .DFE_CFG ( 8\'b00011011 ),
+ .SIM_TX_ELEC_IDLE_LEVEL(""1""),
+ .SIM_RECEIVER_DETECT_PASS(""TRUE""),
+ .RX_EN_REALIGN_RESET_BUF(""FALSE""),
+ .TX_IDLE_ASSERT_DELAY(3\'b100), // TX-idle-set-to-idle (13 UI)
+ .TX_IDLE_DEASSERT_DELAY(3\'b010), // TX-idle-to-diff (7 UI)
+ .CHAN_BOND_SEQ_2_CFG(5\'b11111), // 5\'b11111 for PCIE mode, 5\'b00000 for other modes
+ .CHAN_BOND_KEEP_ALIGN(""TRUE""),
+ .RX_IDLE_HI_CNT(4\'b1000),
+ .RX_IDLE_LO_CNT(4\'b0000),
+ .RX_EN_IDLE_RESET_BUF(""TRUE""),
+ .TX_DATA_WIDTH(20),
+ .RX_DATA_WIDTH(20),
+ .ALIGN_COMMA_WORD(1),
+ .CHAN_BOND_1_MAX_SKEW(7),
+ .CHAN_BOND_2_MAX_SKEW(1),
+ .CHAN_BOND_SEQ_1_1(10\'b0001000101), // D5.2 (end TS2)
+ .CHAN_BOND_SEQ_1_2(10\'b0001000101), // D5.2 (end TS2)
+ .CHAN_BOND_SEQ_1_3(10\'b0001000101), // D5.2 (end TS2)
+ .CHAN_BOND_SEQ_1_4(10\'b0110111100), // K28.5 (COM)
+ .CHAN_BOND_SEQ_1_ENABLE(4\'b1111), // order is 4321
+ .CHAN_BOND_SEQ_2_1(10\'b0100111100), // K28.1 (FTS)
+ .CHAN_BOND_SEQ_2_2(10\'b0100111100), // K28.1 (FTS)
+ .CHAN_BOND_SEQ_2_3(10\'b0110111100), // K28.5 (COM)
+ .CHAN_BOND_SEQ_2_4(10\'b0100111100), // K28.1 (FTS)
+ .CHAN_BOND_SEQ_2_ENABLE(4\'b1111), // order is 4321
+ .CHAN_BOND_SEQ_2_USE(""TRUE""),
+ .CHAN_BOND_SEQ_LEN(4), // 1..4
+ .RX_CLK25_DIVIDER(RX_CLK25_DIVIDER),
+ .TX_CLK25_DIVIDER(TX_CLK25_DIVIDER),
+ .CLK_COR_ADJ_LEN(1), // 1..4
+ .CLK_COR_DET_LEN(1), // 1..4
+ .CLK_COR_INSERT_IDLE_FLAG(""FALSE""),
+ .CLK_COR_KEEP_IDLE(""FALSE""),
+ .CLK_COR_MAX_LAT(30),
+ .CLK_COR_MIN_LAT(28),
+ .CLK_COR_PRECEDENCE(""TRUE""),
+ .CLK_CORRECT_USE(""TRUE""),
+ .CLK_COR_REPEAT_WAIT(0),
+ .CLK_COR_SEQ_1_1(10\'b0100011100), // K28.0 (SKP)
+ .CLK_COR_SEQ_1_2(10\'b0000000000),
+ .CLK_COR_SEQ_1_3(10\'b0000000000),
+ .CLK_COR_SEQ_1_4(10\'b0000000000),
+ .CLK_COR_SEQ_1_ENABLE(4\'b1111),
+ .CLK_COR_SEQ_2_1(10\'b0000000000),
+ .CLK_COR_SEQ_2_2(10\'b0000000000),
+ .CLK_COR_SEQ_2_3(10\'b0000000000),
+ .CLK_COR_SEQ_2_4(10\'b0000000000),
+ .CLK_COR_SEQ_2_ENABLE(4\'b1111),
+ .CLK_COR_SEQ_2_USE(""FALSE""),
+ .COMMA_10B_ENABLE(10\'b1111111111),
+ .COMMA_DOUBLE(""FALSE""),
+ .DEC_MCOMMA_DETECT(""TRUE""),
+ .DEC_PCOMMA_DETECT(""TRUE""),
+ .DEC_VALID_COMMA_ONLY(""TRUE""),
+ .MCOMMA_10B_VALUE(10\'b1010000011),
+ .MCOMMA_DETECT(""TRUE""),
+ .PCI_EXPRESS_MODE(""TRUE""),
+ .PCOMMA_10B_VALUE(10\'b0101111100),
+ .PCOMMA_DETECT(""TRUE""),
+ .RXPLL_DIVSEL_FB(GTX_PLL_DIVSEL_FB), // 1..5, 8, 10
+ .TXPLL_DIVSEL_FB(GTX_PLL_DIVSEL_FB), // 1..5, 8, 10
+ .RXPLL_DIVSEL_REF(1), // 1..6, 8, 10, 12, 16, 20
+ .TXPLL_DIVSEL_REF(1), // 1..6, 8, 10, 12, 16, 20
+ .RXPLL_DIVSEL_OUT(2), // 1, 2, 4
+ .TXPLL_DIVSEL_OUT(2), // 1, 2, 4
+ .RXPLL_DIVSEL45_FB(5),
+ .TXPLL_DIVSEL45_FB(5),
+ .RX_BUFFER_USE(""TRUE""),
+ .RX_DECODE_SEQ_MATCH(""TRUE""),
+ .RX_LOS_INVALID_INCR(8), // power of 2: 1..128
+ .RX_LOSS_OF_SYNC_FSM(""FALSE""),
+ .RX_LOS_THRESHOLD(128), // power of 2: 4..512
+ .RX_SLIDE_MODE(""OFF""), // 00=OFF 01=AUTO 10=PCS 11=PMA
+ .RX_XCLK_SEL (""RXREC""),
+ .TX_BUFFER_USE(""FALSE""), // Must be set to FALSE for use by PCIE
+ .TX_XCLK_SEL (""TXUSR""), // Must be set to TXUSR for use by PCIE
+ .TXPLL_LKDET_CFG (3\'b101),
+ .RX_EYE_SCANMODE (2\'b00),
+ .RX_EYE_OFFSET (8\'h4C),
+ .PMA_RX_CFG ( 25\'h05ce049 ),
+ .TRANS_TIME_NON_P2(8\'h2), // Reduced simulation time
+ .TRANS_TIME_FROM_P2(12\'h03c), // Reduced simulation time
+ .TRANS_TIME_TO_P2(10\'h064), // Reduced simulation time
+ .TRANS_TIME_RATE(8\'hD7), // Reduced simulation time
+ .SHOW_REALIGN_COMMA(""FALSE""),
+ .TX_PMADATA_OPT(1\'b1), // Lockup latch between PCS and PMA
+ .PMA_TX_CFG( 20\'h80082 ), // Aligns posedge of USRCLK
+ .TXOUTCLK_CTRL(""TXPLLREFCLK_DIV1"")
+
+ )
+ GTX (
+
+ .COMFINISH (),
+ .COMINITDET (),
+ .COMSASDET (),
+ .COMWAKEDET (),
+ .DADDR (daddr[(8*i)+7:(8*i)]),
+ .DCLK (DRPCLK),
+ .DEN (den[i]),
+ .DFECLKDLYADJ ( 6\'h0 ),
+ .DFECLKDLYADJMON (),
+ .DFEDLYOVRD ( 1\'b0 ),
+ .DFEEYEDACMON (),
+ .DFESENSCAL (),
+ .DFETAP1 (0),
+ .DFETAP1MONITOR (),
+ .DFETAP2 (5\'h0),
+ .DFETAP2MONITOR (),
+ .DFETAP3 (4\'h0),
+ .DFETAP3MONITOR (),
+ .DFETAP4 (4\'h0),
+ .DFETAP4MONITOR (),
+ .DFETAPOVRD ( 1\'b1 ),
+ .DI (din[(16*i)+15:(16*i)]),
+ .DRDY (drdy[i]),
+ .DRPDO (dout[(16*i)+15:(16*i)]),
+ .DWE (dwe[i]),
+ .GATERXELECIDLE ( 1\'b0 ),
+ .GREFCLKRX (0),
+ .GREFCLKTX (0),
+ .GTXRXRESET ( ~GTReset_n ),
+ .GTXTEST ( {11\'b10000000000,OUT_DIV_RESET[i],1\'b0} ),
+ .GTXTXRESET ( ~GTReset_n ),
+ .LOOPBACK ( 3\'b000 ),
+ .MGTREFCLKFAB (),
+ .MGTREFCLKRX ( {1\'b0,REFCLK} ),
+ .MGTREFCLKTX ( {1\'b0,REFCLK} ),
+ .NORTHREFCLKRX (0),
+ .NORTHREFCLKTX (0),
+ .PHYSTATUS ( GTX_PhyStatus[i] ),
+ .PLLRXRESET ( 1\'b0 ),
+ .PLLTXRESET ( 1\'b0 ),
+ .PRBSCNTRESET ( 1\'b0 ),
+ .RXBUFRESET ( 1\'b0 ),
+ .RXBUFSTATUS (),
+ .RXBYTEISALIGNED (),
+ .RXBYTEREALIGN (),
+ .RXCDRRESET ( 1\'b0 ),
+ .RXCHANBONDSEQ (),
+ .RXCHANISALIGNED ( ChanIsAligned[i] ),
+ .RXCHANREALIGN (),
+ .RXCHARISCOMMA (),
+ .RXCHARISK ( {RxDataK_dummy[1:0], GTX_RxDataK[(2*i)+1:2*i]} ),
+ .RXCHBONDI ( RXCHBOND[i] ),
+ .RXCHBONDLEVEL ( GTX_RxChbondLevel[(3*i)+2:(3*i)] ),
+ .RXCHBONDMASTER ( (i == 0) ),
+ .RXCHBONDO ( RXCHBOND[i+1] ),
+ .RXCHBONDSLAVE ( (i > 0) ),
+ .RXCLKCORCNT (),
+ .RXCOMMADET (),
+ .RXCOMMADETUSE ( 1\'b1 ),
+ .RXDATA ( {RxData_dummy[15:0],GTX_RxData[(16*i)+15:(16*i)+0]} ),
+ .RXDATAVALID (),
+ .RXDEC8B10BUSE ( RXDEC8B10BUSE ),
+ .RXDISPERR (),
+ .RXDLYALIGNDISABLE ( 1\'b1),
+ .RXELECIDLE ( GTX_RxElecIdle[i] ),
+ .RXENCHANSYNC ( 1\'b1 ),
+ .RXENMCOMMAALIGN ( 1\'b1 ),
+ .RXENPCOMMAALIGN ( 1\'b1 ),
+ .RXENPMAPHASEALIGN ( 1\'b0 ),
+ .RXENPRBSTST ( 3\'b0 ),
+ .RXENSAMPLEALIGN ( 1\'b0 ),
+ .RXDLYALIGNMONENB ( 1\'b1 ),
+ .RXEQMIX ( 10\'b0110000011 ),
+ .RXGEARBOXSLIP ( 1\'b0 ),
+ .RXHEADER (),
+ .RXHEADERVALID (),
+ .RXLOSSOFSYNC (),
+ .RXN ( GTX_RXN[i] ),
+ .RXNOTINTABLE (),
+ .RXOVERSAMPLEERR (),
+ .RXP ( GTX_RXP[i] ),
+ .RXPLLLKDET ( RxPLLLkDet[i] ),
+ .RXPLLLKDETEN ( 1\'b1 ),
+ .RXPLLPOWERDOWN ( 1\'b0 ),
+ .RXPLLREFSELDY ( 3\'b000 ),
+ .RXPMASETPHASE ( 1\'b0 ),
+ .RXPOLARITY ( GTX_RxPolarity[i] ),
+ .RXPOWERDOWN ( PowerDown[(2*i)+1:(2*i)] ),
+ .RXPRBSERR (),
+ .RXRATE ( {1\'b1, Rate} ),
+ .RXRATEDONE ( ),
+ .RXRECCLK ( RXRECCLK ),
+ .RXRECCLKPCS ( ),
+ .RXRESET ( ~GTReset_n | local_pcs_reset | PCS_RESET[i] ),
+ .RXRESETDONE ( GTX_RxResetDone[i] ),
+ .RXRUNDISP (),
+ .RXSLIDE ( 1\'b0 ),
+ .RXSTARTOFSEQ (),
+ .RXSTATUS ( GTX_RxStatus[(3*i)+2:(3*i)] ),
+ .RXUSRCLK ( PCLK ),
+ .RXUSRCLK2 ( PCLK ),
+ .RXVALID (GTX_RxValid[i]),
+ .SOUTHREFCLKRX (0),
+ .SOUTHREFCLKTX (0),
+ .TSTCLK0 ( 1\'b0 ),
+ .TSTCLK1 ( 1\'b0 ),
+ .TSTIN ( {20{1\'b1}} ),
+ .TSTOUT (),
+ .TXBUFDIFFCTRL ( 3\'b111 ),
+ .TXBUFSTATUS (),
+ .TXBYPASS8B10B ( TXBYPASS8B10B[3:0] ),
+ .TXCHARDISPMODE ( {3\'b000, GTX_TxCompliance[i]} ),
+ .TXCHARDISPVAL ( 4\'b0000 ),
+ .TXCHARISK ( {TxDataK_dummy[1:0], GTX_TxDataK[(2*i)+1:2*i]} ),
+ .TXCOMINIT ( 1\'b0 ),
+ .TXCOMSAS ( 1\'b0 ),
+ .TXCOMWAKE ( 1\'b0 ),
+ .TXDATA ( {TxData_dummy[15:0], GTX_TxData[(16*i)+15:(16*i)+0]} ),
+ .TXDEEMPH ( TxDeemph ),
+ .TXDETECTRX ( TxDetectRx ),
+ .TXDIFFCTRL ( 4\'b1111 ),
+ .TXDLYALIGNDISABLE ( TXDLYALIGNDISABLE[i] ),
+ .TXDLYALIGNRESET ( TXDLYALIGNRESET[i] ),
+ .TXELECIDLE ( GTX_TxElecIdle[i] ),
+ .TXENC8B10BUSE ( 1\'b1 ),
+ .TXENPMAPHASEALIGN ( TXENPMAPHASEALIGN[i] ),
+ .TXENPRBSTST (),
+ .TXGEARBOXREADY (),
+ .TXHEADER (0),
+ .TXINHIBIT ( 1\'b0 ),
+ .TXKERR (),
+ .TXMARGIN ( {TxMargin, 2\'b00} ),
+ .TXN ( GTX_TXN[i] ),
+ .TXOUTCLK ( TXOCLK[i] ),
+ .TXOUTCLKPCS (),
+ .TXP ( GTX_TXP[i] ),
+ .TXPDOWNASYNCH ( TXPdownAsynch ),
+ .TXPLLLKDET ( ),
+ .TXPLLLKDETEN ( 1\'b0 ),
+ .TXPLLPOWERDOWN ( 1\'b0 ),
+ .TXPLLREFSELDY ( 3\'b000 ),
+ .TXPMASETPHASE ( TXPMASETPHASE[i] ),
+ .TXPOLARITY ( 1\'b0 ),
+ .TXPOSTEMPHASIS (0),
+ .TXPOWERDOWN ( PowerDown[(2*i)+1:(2*i)] ),
+ .TXPRBSFORCEERR (0),
+ .TXPREEMPHASIS (0),
+ .TXRATE ( {1\'b1, Rate} ),
+ .TXRESET ( ~GTReset_n | local_pcs_reset | PCS_RESET[i] ),
+ .TXRESETDONE ( TXRESETDONE[i] ),
+ .TXRUNDISP (),
+ .TXSEQUENCE (0),
+ .TXSTARTSEQ (0),
+ .TXSWING ( TxSwing ),
+ .TXUSRCLK ( PCLK ),
+ .TXUSRCLK2 ( PCLK ),
+ .USRCODEERR (0),
+ .IGNORESIGDET (0),
+ .PERFCLKRX (0),
+ .PERFCLKTX (0),
+ .RXDLYALIGNMONITOR (),
+ .RXDLYALIGNOVERRIDE ( 1\'b0 ),
+ .RXDLYALIGNRESET (0),
+ .RXDLYALIGNSWPPRECURB ( 1\'b1 ),
+ .RXDLYALIGNUPDSW ( 1\'b0 ),
+ .TXDLYALIGNMONITOR (),
+ .TXDLYALIGNOVERRIDE ( 1\'b0 ),
+ .TXDLYALIGNUPDSW ( 1\'b0 ),
+ .TXDLYALIGNMONENB ( 1\'b1 ),
+ .TXRATEDONE ( TXRATEDONE[i] )
+
+
+ );
+ end
+
+ end
+ endgenerate
+
+endmodule
+"
+"//--------------------------------------------------------------------------------
+// Project : SWITCH
+// File : top.v
+// Version : 0.1
+// Author : Vipin.K
+//
+// Description: Arbitrator to arbitrate among PSGs to access PCIe core
+//
+//--------------------------------------------------------------------------------
+
+
+`define MAX_SLAVE 16
+module user_dma_req_arbitrator #(
+ parameter NUM_SLAVES = 'd4,
+ parameter ADDR_WIDTH = 'd32,
+ parameter LEN_WIDTH = 'd12,
+ parameter TAG_WIDTH = 'd8,
+ parameter DATA_WIDTH = 'd64,
+ parameter DMA_LEN = 'd5
+ )
+ (
+ input i_clk,
+ input i_rst_n,
+ //To PSG slaves
+ input [NUM_SLAVES-1:0] i_slave_dma_req,
+ input [ADDR_WIDTH*NUM_SLAVES-1:0] i_slave_dma_addr,
+ input [LEN_WIDTH*NUM_SLAVES-1:0] i_slave_dma_len,
+ input [TAG_WIDTH*NUM_SLAVES-1 :0] i_slave_dma_tag,
+ output reg [NUM_SLAVES-1:0] o_slave_dma_ack,
+
+ input [NUM_SLAVES-1:0] i_slave_dma_data_avail,
+ input [ADDR_WIDTH*NUM_SLAVES-1:0] i_slave_dma_wr_addr,
+ output reg [NUM_SLAVES-1:0] o_slave_dma_data_rd,
+ input [NUM_SLAVES*DATA_WIDTH-1:0] i_slave_dma_data,
+ input [NUM_SLAVES*DMA_LEN-1:0] i_slave_dma_wr_len,
+ output reg [NUM_SLAVES-1:0] o_slave_dma_done,
+ //To PCIe Tx engine
+ output reg o_dma_req,
+ input i_dma_ack,
+ output reg [ADDR_WIDTH-1:0] o_dma_req_addr,
+ output reg [LEN_WIDTH-1:0] o_dma_req_len,
+ output reg [TAG_WIDTH-1:0] o_dma_req_tag,
+
+ output reg o_dma_data_avail,
+ output reg [ADDR_WIDTH-1:0] o_dma_wr_addr,
+ input i_dma_data_rd,
+ output reg [DATA_WIDTH-1:0] o_dma_data,
+ output reg [DMA_LEN-1:0] o_dma_len,
+ input i_dma_done
+ );
+
+reg [$clog2(NUM_SLAVES)-1:0] current_req_slave_served;
+reg [$clog2(NUM_SLAVES)-1:0] current_dma_slave_served;
+
+
+localparam IDLE = 'd0,
+ DMA_REQ = 'd1;
+
+reg rd_state;
+reg wr_state;
+wire some_other_wr_req;
+wire some_other_rd_req;
+
+assign some_other_wr_req = |i_slave_dma_data_avail[NUM_SLAVES-1:0];
+assign some_other_rd_req = |i_slave_dma_req[NUM_SLAVES-1:0];
+
+always@(*)
+begin
+ o_slave_dma_data_rd <= {NUM_SLAVES{1'b0}};
+ o_slave_dma_data_rd[current_dma_slave_served] <= i_dma_data_rd;
+ o_dma_data <= i_slave_dma_data[current_dma_slave_served*DATA_WIDTH+:DATA_WIDTH];
+ o_dma_req_addr <= i_slave_dma_addr[current_req_slave_served*ADDR_WIDTH+:ADDR_WIDTH];
+ o_dma_req_len <= i_slave_dma_len[current_req_slave_served*LEN_WIDTH+:LEN_WIDTH];
+ o_dma_req_tag <= i_slave_dma_tag[current_req_slave_served*TAG_WIDTH+:TAG_WIDTH];
+ o_dma_wr_addr <= i_slave_dma_wr_addr[current_dma_slave_served*ADDR_WIDTH+:ADDR_WIDTH];
+ o_dma_len <= i_slave_dma_wr_len[current_dma_slave_served*DMA_LEN+:DMA_LEN];
+ o_slave_dma_done <= {NUM_SLAVES{1'b0}};
+ o_slave_dma_done[current_dma_slave_served] <= i_dma_done;
+ o_dma_req <= i_slave_dma_req[current_req_slave_served];
+ o_slave_dma_ack <= {NUM_SLAVES{1'b0}};
+ o_slave_dma_ack[current_req_slave_served] <= i_dma_ack;
+ o_dma_data_avail <= i_slave_dma_data_avail[current_dma_slave_served];
+
+end
+
+always @(posedge i_clk)
+begin
+ if(!i_rst_n)
+ begin
+ rd_state <= IDLE;
+ current_req_slave_served <= 0;
+ end
+ else
+ begin
+ case(rd_state)
+ IDLE:begin
+ if(i_slave_dma_req[current_req_slave_served])
+ begin
+ rd_state <= DMA_REQ;
+ end
+ else if(some_other_rd_req)
+ current_req_slave_served <= current_req_slave_served + 1'b1;
+ end
+ DMA_REQ:begin
+ if(i_dma_ack)
+ begin
+ rd_state <= IDLE;
+ end
+ end
+ endcase
+ end
+end
+
+always @(posedge i_clk)
+begin
+ if(!i_rst_n)
+ begin
+ wr_state <= IDLE;
+ current_dma_slave_served <= 0;
+ end
+ else
+ begin
+ case(wr_state)
+ IDLE:begin
+ if(i_slave_dma_data_avail[current_dma_slave_served])
+ begin
+ wr_state <= DMA_REQ;
+ end
+ else if(some_other_wr_req)
+ current_dma_slave_served <= current_dma_slave_served + 1'b1;
+ end
+ DMA_REQ:begin
+ if(i_dma_done)
+ begin
+ wr_state <= IDLE;
+ end
+ end
+ endcase
+ end
+end
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2009 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor: Xilinx
+// \\ \\ \\/ Version:
+// \\ \\ Application: MIG
+// / / Filename: phy_rdlvl.v
+// /___/ /\\ Date Last Modified: $Date: 2011/06/02 07:18:04 $
+// \\ \\ / \\ Date Created:
+// \\___\\/\\___\\
+//
+//Device: Virtex-6
+//Design Name: DDR3 SDRAM
+//Purpose:
+// Read leveling calibration logic
+// NOTES:
+// 1. DQ per-bit deskew is not yet supported
+//Reference:
+//Revision History:
+//*****************************************************************************
+
+/******************************************************************************
+**$Id: phy_rdlvl.v,v 1.1 2011/06/02 07:18:04 mishra Exp $
+**$Date: 2011/06/02 07:18:04 $
+**$Author: mishra $
+**$Revision: 1.1 $
+**$Source: /devl/xcs/repo/env/Databases/ip/src2/O/mig_v3_9/data/dlib/virtex6/ddr3_sdram/verilog/rtl/phy/phy_rdlvl.v,v $
+******************************************************************************/
+
+`timescale 1ps/1ps
+
+module phy_rdlvl #
+ (
+ parameter TCQ = 100, // clk->out delay (sim only)
+ parameter nCK_PER_CLK = 2, // # of memory clocks per CLK
+ parameter CLK_PERIOD = 3333, // Internal clock period (in ps)
+ parameter REFCLK_FREQ = 300, // IODELAY Reference Clock freq (MHz)
+ parameter DQ_WIDTH = 64, // # of DQ (data)
+ parameter DQS_CNT_WIDTH = 3, // = ceil(log2(DQS_WIDTH))
+ parameter DQS_WIDTH = 8, // # of DQS (strobe)
+ parameter DRAM_WIDTH = 8, // # of DQ per DQS
+ parameter DRAM_TYPE = ""DDR3"", // Memory I/F type: ""DDR3"", ""DDR2""
+ parameter PD_TAP_REQ = 10, // # of IODELAY taps reserved for PD
+ parameter nCL = 5, // Read CAS latency (in clk cyc)
+ parameter SIM_CAL_OPTION = ""NONE"", // Skip various calibration steps
+ parameter DEBUG_PORT = ""OFF"" // Enable debug port
+ )
+ (
+ input clk,
+ input rst,
+ // Calibration status, control signals
+ input [1:0] rdlvl_start,
+ input rdlvl_clkdiv_start,
+ input rdlvl_rd_active,
+ output reg [1:0] rdlvl_done,
+ output reg rdlvl_clkdiv_done,
+ output reg [1:0] rdlvl_err,
+ output reg rdlvl_prech_req,
+ input prech_done,
+ // Captured data in resync clock domain
+ input [DQ_WIDTH-1:0] rd_data_rise0,
+ input [DQ_WIDTH-1:0] rd_data_fall0,
+ input [DQ_WIDTH-1:0] rd_data_rise1,
+ input [DQ_WIDTH-1:0] rd_data_fall1,
+ // Stage 1 calibration outputs
+ output reg [DQS_WIDTH-1:0] dlyce_cpt,
+ output reg dlyinc_cpt,
+ output reg [3:0] dlyce_rsync,
+ output reg dlyinc_rsync,
+ output reg [5*DQS_WIDTH-1:0] dlyval_dq,
+ output reg [5*DQS_WIDTH-1:0] dlyval_dqs,
+ // Stage 2 calibration inputs/outputs
+ output reg [2*DQS_WIDTH-1:0] rd_bitslip_cnt,
+ output reg [2*DQS_WIDTH-1:0] rd_clkdly_cnt,
+ output reg [4:0] rd_active_dly,
+ input rdlvl_pat_resume, // resume pattern calib
+ output reg rdlvl_pat_err, // error during pattern cal
+ output [DQS_CNT_WIDTH-1:0] rdlvl_pat_err_cnt, // erroring DQS group
+ // Resynchronization clock (clkinv_inv) calibration outputs
+ output [DQS_WIDTH-1:0] rd_clkdiv_inv,
+ // Debug Port
+ output [5*DQS_WIDTH-1:0] dbg_cpt_first_edge_cnt,
+ output [5*DQS_WIDTH-1:0] dbg_cpt_second_edge_cnt,
+ output reg [3*DQS_WIDTH-1:0] dbg_rd_bitslip_cnt,
+ output [DQS_WIDTH-1:0] dbg_rd_clkdiv_inv,
+ output reg [2*DQS_WIDTH-1:0] dbg_rd_clkdly_cnt,
+ output reg [4:0] dbg_rd_active_dly,
+ input dbg_idel_up_all,
+ input dbg_idel_down_all,
+ input dbg_idel_up_cpt,
+ input dbg_idel_down_cpt,
+ input dbg_idel_up_rsync,
+ input dbg_idel_down_rsync,
+ input [DQS_CNT_WIDTH-1:0] dbg_sel_idel_cpt,
+ input dbg_sel_all_idel_cpt,
+ input [DQS_CNT_WIDTH-1:0] dbg_sel_idel_rsync,
+ input dbg_sel_all_idel_rsync,
+ output [255:0] dbg_phy_rdlvl
+ );
+
+ // minimum time (in IDELAY taps) for which capture data must be stable for
+ // algorithm to consider a valid data eye to be found. The read leveling
+ // logic will ignore any window found smaller than this value. Limitations
+ // on how small this number can be is determined by: (1) the algorithmic
+ // limitation of how many taps wide the data eye can be (3 taps), and (2)
+ // how wide regions of ""instability"" that occur around the edges of the
+ // read valid window can be (i.e. need to be able to filter out ""false""
+ // windows that occur for a short # of taps around the edges of the true
+ // data window, although with multi-sampling during read leveling, this is
+ // not as much a concern) - the larger the value, the more protection
+ // against ""false"" windows
+ localparam MIN_EYE_SIZE = (DRAM_TYPE == ""DDR3"") ? 3 : 6;
+ // # of clock cycles to wait after changing IDELAY value or read data MUX
+ // to allow both IDELAY chain to settle, and for delayed input to
+ // propagate thru ISERDES
+ localparam PIPE_WAIT_CNT = 16;
+ // Length of calibration sequence (in # of words)
+ localparam CAL_PAT_LEN = 8;
+ // Read data shift register length
+ localparam RD_SHIFT_LEN = CAL_PAT_LEN/(2*nCK_PER_CLK);
+ // Amount to shift by if one edge found (= 0.5*(bit_period)). Limit to 31
+ localparam integer IODELAY_TAP_RES = 1000000/(REFCLK_FREQ * 64);
+ localparam TBY4_TAPS
+ = (((CLK_PERIOD/nCK_PER_CLK/4)/IODELAY_TAP_RES) > 31) ? 31 :
+ ((CLK_PERIOD/nCK_PER_CLK/4)/IODELAY_TAP_RES);
+ // Maximum amount to wait after read issued until read data returned
+ localparam MAX_RD_DLY_CNT = 32;
+ // # of cycles to wait after changing RDEN count value
+ localparam RDEN_WAIT_CNT = 8;
+ // used during read enable calibration - difference between what the
+ // calibration logic measured read enable delay to be, and what it needs
+ // to set the value of the read active delay control to be
+ localparam RDEN_DELAY_OFFSET = 5;
+ // # of read data samples to examine when detecting whether an edge has
+ // occured during stage 1 calibration. Width of local param must be
+ // changed as appropriate. Note that there are two counters used, each
+ // counter can be changed independently of the other - they are used in
+ // cascade to create a larger counter
+ localparam [11:0] DETECT_EDGE_SAMPLE_CNT0 = 12\'hFFF;
+ localparam [11:0] DETECT_EDGE_SAMPLE_CNT1 = 12\'h001;
+ // # of taps in IDELAY chain. When the phase detector taps are reserved
+ // before the start of calibration, reduce half that amount from the
+ // total available taps.
+ localparam IODELAY_TAP_LEN = 32 - (PD_TAP_REQ/2);
+ // Half the PD taps
+ localparam PD_HALF_TAP = (PD_TAP_REQ/2);
+
+ localparam [4:0] CAL1_IDLE = 5\'h00;
+ localparam [4:0] CAL1_NEW_DQS_WAIT = 5\'h01;
+ localparam [4:0] CAL1_IDEL_STORE_FIRST = 5\'h02;
+ localparam [4:0] CAL1_DETECT_EDGE = 5\'h03;
+ localparam [4:0] CAL1_IDEL_STORE_OLD = 5\'h04;
+ localparam [4:0] CAL1_IDEL_INC_CPT = 5\'h05;
+ localparam [4:0] CAL1_IDEL_INC_CPT_WAIT = 5\'h06;
+ localparam [4:0] CAL1_CALC_IDEL = 5\'h07;
+ localparam [4:0] CAL1_IDEL_DEC_CPT = 5\'h08;
+ localparam [4:0] CAL1_NEXT_DQS = 5\'h09;
+ localparam [4:0] CAL1_DONE = 5\'h0A;
+ localparam [4:0] CAL1_RST_CPT = 5\'h0B;
+ localparam [4:0] CAL1_DETECT_EDGE_DQ = 5\'h0C;
+ localparam [4:0] CAL1_IDEL_INC_DQ = 5\'h0D;
+ localparam [4:0] CAL1_IDEL_INC_DQ_WAIT = 5\'h0E;
+ localparam [4:0] CAL1_CALC_IDEL_DQ = 5\'h0F;
+ localparam [4:0] CAL1_IDEL_INC_DQ_CPT = 5\'h10;
+ localparam [4:0] CAL1_IDEL_INC_PD_CPT = 5\'h11;
+ localparam [4:0] CAL1_IDEL_PD_ADJ = 5\'h12;
+ localparam [4:0] CAL1_SKIP_RDLVL_INC_IDEL = 5\'h1F; // Only for simulation
+
+ localparam CAL2_IDLE = 3\'h0;
+ localparam CAL2_READ_WAIT = 3\'h1;
+ localparam CAL2_DETECT_MATCH = 3\'h2;
+ localparam CAL2_BITSLIP_WAIT = 3\'h3;
+ localparam CAL2_NEXT_DQS = 3\'h4;
+ localparam CAL2_DONE = 3\'h5;
+ localparam CAL2_ERROR_TO = 3\'h6;
+
+ localparam [3:0] CAL_CLKDIV_IDLE = 4\'h0;
+ localparam [3:0] CAL_CLKDIV_NEW_DQS_WAIT = 4\'h1;
+ localparam [3:0] CAL_CLKDIV_IDEL_STORE_REF = 4\'h2;
+ localparam [3:0] CAL_CLKDIV_DETECT_EDGE = 4\'h3;
+ localparam [3:0] CAL_CLKDIV_IDEL_INCDEC_RSYNC = 4\'h4;
+ localparam [3:0] CAL_CLKDIV_IDEL_INCDEC_RSYNC_WAIT = 4\'h5;
+ localparam [3:0] CAL_CLKDIV_IDEL_SET_MIDPT_RSYNC = 4\'h6;
+ localparam [3:0] CAL_CLKDIV_NEXT_CHECK = 4\'h7;
+ localparam [3:0] CAL_CLKDIV_NEXT_DQS = 4\'h8;
+ localparam [3:0] CAL_CLKDIV_DONE = 4\'h9;
+
+ integer i;
+ integer j;
+ integer x;
+ genvar z;
+
+ reg cal_clkdiv_clkdiv_inv_r;
+ reg [DQS_CNT_WIDTH-1:0] cal_clkdiv_cnt_clkdiv_r;
+ reg cal_clkdiv_dlyce_rsync_r;
+ reg cal_clkdiv_dlyinc_rsync_r;
+ reg cal_clkdiv_idel_rsync_inc_r;
+ reg cal_clkdiv_prech_req_r;
+ reg cal_clkdiv_store_sr_req_r;
+ reg [3:0] cal_clkdiv_state_r;
+ reg [DQS_CNT_WIDTH-1:0] cal1_cnt_cpt_r;
+ reg cal1_dlyce_cpt_r;
+ reg cal1_dlyinc_cpt_r;
+ reg [4:0] cal1_dq_tap_cnt_r;
+ reg cal1_dq_taps_inc_r;
+ wire cal1_found_edge;
+ reg cal1_prech_req_r;
+ reg [4:0] cal1_state_r;
+ reg cal1_store_sr_req_r;
+ reg [2*DQS_WIDTH-1:0] cal2_clkdly_cnt_r;
+ reg [1:0] cal2_cnt_bitslip_r;
+ reg [4:0] cal2_cnt_rd_dly_r;
+ reg [DQS_CNT_WIDTH-1:0] cal2_cnt_rden_r;
+ reg [DQS_WIDTH-1:0] cal2_deskew_err_r;
+ reg [4:0] cal2_dly_cnt_delta_r[DQS_WIDTH-1:0];
+ reg cal2_done_r;
+ reg cal2_done_r1;
+ reg cal2_done_r2;
+ reg cal2_done_r3;
+ reg [5*DQS_WIDTH-1:0] cal2_dly_cnt_r;
+ reg cal2_en_dqs_skew_r;
+ reg [4:0] cal2_max_cnt_rd_dly_r;
+ reg cal2_prech_req_r;
+ reg [4:0] cal2_rd_active_dly_r;
+ reg [2*DQS_WIDTH-1:0] cal2_rd_bitslip_cnt_r;
+ reg [2:0] cal2_state_r;
+ reg [DQS_WIDTH-1:0] clkdiv_inv_r;
+ reg [2:0] cnt_eye_size_r;
+ reg [5:0] cnt_idel_dec_cpt_r;
+ reg [4:0] cnt_idel_inc_cpt_r;
+ reg [4:0] cnt_idel_skip_idel_r;
+ reg [3:0] cnt_pipe_wait_r;
+ reg [2:0] cnt_rden_wait_r;
+ reg [3:0] cnt_shift_r;
+ reg [11:0] detect_edge_cnt0_r;
+ reg detect_edge_cnt1_en_r;
+ reg [11:0] detect_edge_cnt1_r;
+ reg detect_edge_done_r;
+ reg detect_edge_start_r;
+ wire dlyce_or;
+ reg [5*DQS_WIDTH-1:0] dlyval_dq_reg_r;
+ reg [4:0] first_edge_taps_r;
+ reg found_edge_r;
+ reg found_edge_latched_r;
+ reg found_edge_valid_r;
+ reg found_dq_edge_r;
+ reg found_first_edge_r;
+ reg found_jitter_latched_r;
+ reg found_second_edge_r;
+ reg found_stable_eye_r;
+ reg found_two_edge_r;
+ reg [4:0] idel_tap_cnt_cpt_r;
+ reg [4:0] idel_tap_delta_rsync_r;
+ reg idel_tap_limit_cpt_r;
+ reg idel_tap_limit_dq_r;
+ reg last_tap_jitter_r;
+ reg [4:0] min_rsync_marg_r;
+ reg [DRAM_WIDTH-1:0] mux_rd_fall0_r;
+ reg [DRAM_WIDTH-1:0] mux_rd_fall1_r;
+ reg [DRAM_WIDTH-1:0] mux_rd_rise0_r;
+ reg [DRAM_WIDTH-1:0] mux_rd_rise1_r;
+ reg new_cnt_clkdiv_r;
+ reg new_cnt_cpt_r;
+ reg [RD_SHIFT_LEN-1:0] old_sr_fall0_r [DRAM_WIDTH-1:0];
+ reg [RD_SHIFT_LEN-1:0] old_sr_fall1_r [DRAM_WIDTH-1:0];
+ reg [RD_SHIFT_LEN-1:0] old_sr_rise0_r [DRAM_WIDTH-1:0];
+ reg [RD_SHIFT_LEN-1:0] old_sr_rise1_r [DRAM_WIDTH-1:0];
+ reg old_sr_valid_r;
+ reg pat_data_match_r;
+ wire [RD_SHIFT_LEN-1:0] pat_fall0 [3:0];
+ wire [RD_SHIFT_LEN-1:0] pat_fall1 [3:0];
+ reg [DRAM_WIDTH-1:0] pat_match_fall0_r;
+ reg pat_match_fall0_and_r;
+ reg [DRAM_WIDTH-1:0] pat_match_fall1_r;
+ reg pat_match_fall1_and_r;
+ reg [DRAM_WIDTH-1:0] pat_match_rise0_r;
+ reg pat_match_rise0_and_r;
+ reg [DRAM_WIDTH-1:0] pat_match_rise1_r;
+ reg pat_match_rise1_and_r;
+ wire [RD_SHIFT_LEN-1:0] pat_rise0 [3:0];
+ wire [RD_SHIFT_LEN-1:0] pat_rise1 [3:0];
+ wire pipe_wait;
+ reg pol_min_rsync_marg_r;
+ reg prev_found_edge_r;
+ reg prev_found_edge_valid_r;
+ reg prev_match_fall0_and_r;
+ reg [DRAM_WIDTH-1:0] prev_match_fall0_r;
+ reg prev_match_fall1_and_r;
+ reg [DRAM_WIDTH-1:0] prev_match_fall1_r;
+ reg prev_match_rise0_and_r;
+ reg [DRAM_WIDTH-1:0] prev_match_rise0_r;
+ reg prev_match_rise1_and_r;
+ reg [DRAM_WIDTH-1:0] prev_match_rise1_r;
+ reg prev_match_valid_r;
+ reg prev_match_valid_r1;
+ reg [RD_SHIFT_LEN-1:0] prev_sr_fall0_r [DRAM_WIDTH-1:0];
+ reg [RD_SHIFT_LEN-1:0] prev_sr_fall1_r [DRAM_WIDTH-1:0];
+ reg [RD_SHIFT_LEN-1:0] prev_sr_rise0_r [DRAM_WIDTH-1:0];
+ reg [RD_SHIFT_LEN-1:0] prev_sr_rise1_r [DRAM_WIDTH-1:0];
+ reg [DQS_CNT_WIDTH-1:0] rd_mux_sel_r;
+ reg rd_active_posedge_r;
+ reg rd_active_r;
+ reg rden_wait_r;
+ reg [4:0] right_edge_taps_r;
+ reg [4:0] second_edge_taps_r;
+ reg [4:0] second_edge_dq_taps_r;
+ reg [RD_SHIFT_LEN-1:0] sr_fall0_r [DRAM_WIDTH-1:0];
+ reg [RD_SHIFT_LEN-1:0] sr_fall1_r [DRAM_WIDTH-1:0];
+ reg [RD_SHIFT_LEN-1:0] sr_rise0_r [DRAM_WIDTH-1:0];
+ reg [RD_SHIFT_LEN-1:0] sr_rise1_r [DRAM_WIDTH-1:0];
+ reg sr_match_fall0_and_r;
+ reg [DRAM_WIDTH-1:0] sr_match_fall0_r;
+ reg sr_match_fall1_and_r;
+ reg [DRAM_WIDTH-1:0] sr_match_fall1_r;
+ reg sr_match_valid_r;
+ reg sr_match_valid_r1;
+ reg sr_match_rise0_and_r;
+ reg [DRAM_WIDTH-1:0] sr_match_rise0_r;
+ reg sr_match_rise1_and_r;
+ reg [DRAM_WIDTH-1:0] sr_match_rise1_r;
+ reg store_sr_done_r;
+ reg store_sr_r;
+ reg sr_valid_r;
+ reg [5:0] tby4_r;
+
+ // Debug
+ reg [4:0] dbg_cpt_first_edge_taps [0:DQS_WIDTH-1];
+ reg [4:0] dbg_cpt_second_edge_taps [0:DQS_WIDTH-1];
+
+ //***************************************************************************
+ // Debug
+ //***************************************************************************
+
+ assign dbg_phy_rdlvl[1:0] = rdlvl_start[1:0];
+ assign dbg_phy_rdlvl[2] = found_edge_r;
+ assign dbg_phy_rdlvl[3] = pat_data_match_r;
+ assign dbg_phy_rdlvl[6:4] = cal2_state_r[2:0];
+ assign dbg_phy_rdlvl[8:7] = cal2_cnt_bitslip_r[1:0];
+ assign dbg_phy_rdlvl[13:9] = cal1_state_r[4:0];
+ assign dbg_phy_rdlvl[20:14] = {1\'b0, cnt_idel_dec_cpt_r};
+ assign dbg_phy_rdlvl[21] = found_first_edge_r;
+ assign dbg_phy_rdlvl[22] = found_second_edge_r;
+ assign dbg_phy_rdlvl[23] = old_sr_valid_r;
+ assign dbg_phy_rdlvl[24] = store_sr_r;
+ assign dbg_phy_rdlvl[32:25] = {sr_fall1_r[0][1:0], sr_rise1_r[0][1:0],
+ sr_fall0_r[0][1:0], sr_rise0_r[0][1:0]};
+ assign dbg_phy_rdlvl[40:33] = {old_sr_fall1_r[0][1:0],
+ old_sr_rise1_r[0][1:0],
+ old_sr_fall0_r[0][1:0],
+ old_sr_rise0_r[0][1:0]};
+ assign dbg_phy_rdlvl[41] = sr_valid_r;
+ assign dbg_phy_rdlvl[42] = found_stable_eye_r;
+ assign dbg_phy_rdlvl[47:43] = idel_tap_cnt_cpt_r;
+ assign dbg_phy_rdlvl[48] = idel_tap_limit_cpt_r;
+ assign dbg_phy_rdlvl[53:49] = first_edge_taps_r;
+ assign dbg_phy_rdlvl[58:54] = second_edge_taps_r;
+ assign dbg_phy_rdlvl[64:59] = tby4_r;
+ assign dbg_phy_rdlvl[67:65] = cnt_eye_size_r;
+ assign dbg_phy_rdlvl[72:68] = cal1_dq_tap_cnt_r;
+ assign dbg_phy_rdlvl[73] = found_dq_edge_r;
+ assign dbg_phy_rdlvl[74] = found_edge_valid_r;
+ assign dbg_phy_rdlvl[78:75] = cal1_cnt_cpt_r;
+ assign dbg_phy_rdlvl[82:79] = cal2_cnt_rden_r;
+ assign dbg_phy_rdlvl[83] = cal1_dlyce_cpt_r;
+ assign dbg_phy_rdlvl[84] = cal1_dlyinc_cpt_r;
+ assign dbg_phy_rdlvl[85] = found_edge_r;
+ assign dbg_phy_rdlvl[86] = found_first_edge_r;
+ assign dbg_phy_rdlvl[91:87] = right_edge_taps_r;
+ assign dbg_phy_rdlvl[96:92] = second_edge_dq_taps_r;
+ assign dbg_phy_rdlvl[102:97] = tby4_r;
+ assign dbg_phy_rdlvl[103] = cal_clkdiv_clkdiv_inv_r;
+ assign dbg_phy_rdlvl[104] = cal_clkdiv_dlyce_rsync_r;
+ assign dbg_phy_rdlvl[105] = cal_clkdiv_dlyinc_rsync_r;
+ assign dbg_phy_rdlvl[106] = cal_clkdiv_idel_rsync_inc_r;
+ assign dbg_phy_rdlvl[107] = pol_min_rsync_marg_r;
+ assign dbg_phy_rdlvl[111:108] = cal_clkdiv_state_r;
+ assign dbg_phy_rdlvl[115:112] = cal_clkdiv_cnt_clkdiv_r;
+ assign dbg_phy_rdlvl[120:116] = idel_tap_delta_rsync_r;
+ assign dbg_phy_rdlvl[125:121] = min_rsync_marg_r;
+ assign dbg_phy_rdlvl[134:126] = clkdiv_inv_r;
+ assign dbg_phy_rdlvl[135] = rdlvl_clkdiv_start;
+ assign dbg_phy_rdlvl[136] = rdlvl_clkdiv_done;
+ assign dbg_phy_rdlvl[255:137] = \'b0;
+
+ //***************************************************************************
+ // Debug output
+ //***************************************************************************
+
+ // Record first and second edges found during CPT calibration
+ generate
+ genvar ce_i;
+ for (ce_i = 0; ce_i < DQS_WIDTH; ce_i = ce_i + 1) begin: gen_dbg_cpt_edge
+ assign dbg_cpt_first_edge_cnt[(5*ce_i)+4:(5*ce_i)]
+ = dbg_cpt_first_edge_taps[ce_i];
+ assign dbg_cpt_second_edge_cnt[(5*ce_i)+4:(5*ce_i)]
+ = dbg_cpt_second_edge_taps[ce_i];
+ always @(posedge clk)
+ if (rst) begin
+ dbg_cpt_first_edge_taps[ce_i] <= #TCQ \'b0;
+ dbg_cpt_second_edge_taps[ce_i] <= #TCQ \'b0;
+ end else begin
+ // Record tap counts of first and second edge edges during
+ // CPT calibration for each DQS group. If neither edge has
+ // been found, then those taps will remain 0
+ if ((cal1_state_r == CAL1_CALC_IDEL) ||
+ (cal1_state_r == CAL1_RST_CPT)) begin
+ if (found_first_edge_r && (cal1_cnt_cpt_r == ce_i))
+ dbg_cpt_first_edge_taps[ce_i]
+ <= #TCQ first_edge_taps_r;
+ if (found_second_edge_r && (cal1_cnt_cpt_r == ce_i))
+ dbg_cpt_second_edge_taps[ce_i]
+ <= #TCQ second_edge_taps_r;
+ end
+ end
+ end
+ endgenerate
+
+ always @(posedge clk) begin
+ dbg_rd_active_dly <= #TCQ cal2_rd_active_dly_r;
+ dbg_rd_clkdly_cnt <= #TCQ cal2_clkdly_cnt_r;
+ end
+
+ // cal2_rd_bitslip_cnt_r is only 2*DQS_WIDTH (2 bits per DQS group), but
+ // is expanded to 3 bits per DQS group to maintain width compatibility with
+ // previous definition of dbg_rd_bitslip_cnt (not a huge issue, should
+ // align these eventually - minimize impact on debug designs)
+ generate
+ genvar d_i;
+ for (d_i = 0; d_i < DQS_WIDTH; d_i = d_i + 1) begin: gen_dbg_rd_bitslip
+ always @(posedge clk) begin
+ dbg_rd_bitslip_cnt[3*d_i+:2] <= #TCQ cal2_rd_bitslip_cnt_r[2*d_i+:2];
+ dbg_rd_bitslip_cnt[3*d_i+2] <= #TCQ 1\'b0;
+ end
+ end
+ endgenerate
+
+ //***************************************************************************
+ // Data mux to route appropriate bit to calibration logic - i.e. calibration
+ // is done sequentially, one bit (or DQS group) at a time
+ //***************************************************************************
+
+ always @(posedge clk) begin
+ (* full_case, parallel_case *) case ({rdlvl_clkdiv_done, rdlvl_done[0]})
+ 2\'b00: rd_mux_sel_r <= #TCQ cal1_cnt_cpt_r;
+ 2\'b01: rd_mux_sel_r <= #TCQ cal_clkdiv_cnt_clkdiv_r;
+ 2\'b10: rd_mux_sel_r <= #TCQ cal2_cnt_rden_r; // don\'t care
+ 2\'b11: rd_mux_sel_r <= #TCQ cal2_cnt_rden_r;
+ endcase
+ end
+
+ // Register outputs for improved timing.
+ // NOTE: Will need to change when per-bit DQ deskew is supported.
+ // Currenly all bits in DQS group are checked in aggregate
+ generate
+ genvar mux_i;
+ for (mux_i = 0; mux_i < DRAM_WIDTH; mux_i = mux_i + 1) begin: gen_mux_rd
+ always @(posedge clk) begin
+ mux_rd_rise0_r[mux_i] <= #TCQ rd_data_rise0[DRAM_WIDTH*rd_mux_sel_r +
+ mux_i];
+ mux_rd_fall0_r[mux_i] <= #TCQ rd_data_fall0[DRAM_WIDTH*rd_mux_sel_r +
+ mux_i];
+ mux_rd_rise1_r[mux_i] <= #TCQ rd_data_rise1[DRAM_WIDTH*rd_mux_sel_r +
+ mux_i];
+ mux_rd_fall1_r[mux_i] <= #TCQ rd_data_fall1[DRAM_WIDTH*rd_mux_sel_r +
+ mux_i];
+ end
+ end
+ endgenerate
+
+ //***************************************************************************
+ // Demultiplexor to control IODELAY tap values
+ //***************************************************************************
+
+ // Capture clock
+ always @(posedge clk) begin
+ dlyce_cpt <= #TCQ \'b0;
+ dlyinc_cpt <= #TCQ \'b0;
+
+ if (cal1_dlyce_cpt_r) begin
+ if ((SIM_CAL_OPTION == ""NONE"") ||
+ (SIM_CAL_OPTION == ""FAST_WIN_DETECT"")) begin
+ // Change only specified DQS group\'s capture clock
+ dlyce_cpt[rd_mux_sel_r] <= #TCQ 1\'b1;
+ dlyinc_cpt <= #TCQ cal1_dlyinc_cpt_r;
+ end else if ((SIM_CAL_OPTION == ""FAST_CAL"") ||
+ (SIM_CAL_OPTION == ""SKIP_CAL"")) begin
+ // if simulating, and ""shortcuts"" for calibration enabled, apply
+ // results to all other elements (i.e. assume delay on all
+ // bits/bytes is same). Also do the same if skipping calibration
+ // (the logic will still increment IODELAY to the ""hardcoded"" value)
+ dlyce_cpt <= #TCQ {DQS_WIDTH{1\'b1}};
+ dlyinc_cpt <= #TCQ cal1_dlyinc_cpt_r;
+ end
+ end else if (DEBUG_PORT == ""ON"") begin
+ // simultaneously inc/dec all CPT idelays
+ if (dbg_idel_up_all || dbg_idel_down_all || dbg_sel_all_idel_cpt) begin
+ dlyce_cpt <= #TCQ {DQS_WIDTH{dbg_idel_up_all | dbg_idel_down_all |
+ dbg_idel_up_cpt | dbg_idel_down_cpt}};
+ dlyinc_cpt <= #TCQ dbg_idel_up_all | dbg_idel_up_cpt;
+ end else begin
+ // select specific cpt clock for adjustment
+ dlyce_cpt[dbg_sel_idel_cpt] <= #TCQ dbg_idel_up_cpt |
+ dbg_idel_down_cpt;
+ dlyinc_cpt <= #TCQ dbg_idel_up_cpt;
+ end
+ end
+ end
+
+ // Resync clock
+ always @(posedge clk) begin
+ dlyce_rsync <= #TCQ \'b0;
+ dlyinc_rsync <= #TCQ \'b0;
+
+ if (cal_clkdiv_dlyce_rsync_r) begin
+ // When shifting RSYNC, shift all BUFR IODELAYs. This is allowed
+ // because only one DQS-group\'s data is being checked at any one
+ // time, and at the end of calibration, all of the BUFR IODELAYs
+ // will be reset to the starting tap value
+ dlyce_rsync <= #TCQ {DQS_WIDTH{1\'b1}};
+ dlyinc_rsync <= #TCQ cal_clkdiv_dlyinc_rsync_r;
+ end else if (DEBUG_PORT == ""ON"") begin
+ // simultaneously inc/dec all RSYNC idelays
+ if (dbg_idel_up_all || dbg_idel_down_all || dbg_sel_all_idel_rsync) begin
+ dlyce_rsync <= #TCQ {4{dbg_idel_up_all |
+ dbg_idel_down_all |
+ dbg_idel_up_rsync |
+ dbg_idel_down_rsync}};
+ dlyinc_rsync <= #TCQ dbg_idel_up_all | dbg_idel_up_rsync;
+ end else begin
+ // select specific rsync clock for adjustment
+ dlyce_rsync[dbg_sel_idel_rsync] <= #TCQ dbg_idel_up_rsync |
+ dbg_idel_down_rsync;
+ dlyinc_rsync <= #TCQ dbg_idel_up_rsync;
+ end
+ end
+ end
+
+ // DQ parallel load tap values
+ // Currently no debug port option to change DQ taps
+ // NOTE: This values are not initially assigned after reset - until
+ // a particular byte is being calibrated, the IDELAY dlyval values from
+ // this module will be X\'s in simulation - this will be okay - those
+ // IDELAYs won\'t be used until the byte is calibrated
+ always @(posedge clk) begin
+ // If read leveling is not complete, calibration logic has complete
+ // control of loading of DQ IDELAY taps
+ if ((SIM_CAL_OPTION == ""NONE"") ||
+ (SIM_CAL_OPTION == ""FAST_WIN_DETECT"")) begin
+ // Load all IDELAY value for all bits in that byte with the same
+ // value. Eventually this will be changed to accomodate different
+ // tap counts across the bits in a DQS group (i.e. ""per-bit"" cal)
+ dlyval_dq_reg_r[5*cal1_cnt_cpt_r+:5] <= #TCQ {cal1_dq_tap_cnt_r};
+ end else if (SIM_CAL_OPTION == ""FAST_CAL"") begin
+ // For simulation purposes, to reduce time associated with
+ // calibration, calibrate only one DQS group, and load all IODELAY
+ // values for all DQS groups with same value
+ dlyval_dq_reg_r <= #TCQ {DQS_WIDTH{cal1_dq_tap_cnt_r}};
+ end else if (SIM_CAL_OPTION == ""SKIP_CAL"") begin
+ // If skipping calibration altogether (only for simulation), set
+ // all the DQ IDELAY delay values to 0
+ dlyval_dq_reg_r <= #TCQ \'b0;
+ end
+ end
+
+ // Register for timing (help with logic placement) - we\'re gonna need
+ // all the help we can get
+ // dlyval_dqs is assigned the value of dq taps. It is used in the PD module.
+ // Changes will be made to this assignment when perbit deskew is done.
+ always @(posedge clk) begin
+ dlyval_dq <= #TCQ dlyval_dq_reg_r;
+ dlyval_dqs <= #TCQ dlyval_dq_reg_r;
+ end
+
+ //***************************************************************************
+ // Generate signal used to delay calibration state machine - used when:
+ // (1) IDELAY value changed
+ // (2) RD_MUX_SEL value changed
+ // Use when a delay is necessary to give the change time to propagate
+ // through the data pipeline (through IDELAY and ISERDES, and fabric
+ // pipeline stages)
+ //***************************************************************************
+
+ // combine requests to modify any of the IDELAYs into one
+ assign dlyce_or = cal1_dlyce_cpt_r |
+ new_cnt_cpt_r |
+ (cal1_state_r == CAL1_IDEL_INC_DQ) |
+ cal_clkdiv_dlyce_rsync_r |
+ new_cnt_clkdiv_r;
+
+ // NOTE: Can later recode to avoid combinational path, but be careful about
+ // timing effect on main state logic
+ assign pipe_wait = dlyce_or || (cnt_pipe_wait_r != PIPE_WAIT_CNT-1);
+
+ always @(posedge clk)
+ if (rst)
+ cnt_pipe_wait_r <= #TCQ 4\'b0000;
+ else if (dlyce_or)
+ cnt_pipe_wait_r <= #TCQ 4\'b0000;
+ else if (cnt_pipe_wait_r != PIPE_WAIT_CNT-1)
+ cnt_pipe_wait_r <= #TCQ cnt_pipe_wait_r + 1;
+
+ //***************************************************************************
+ // generate request to PHY_INIT logic to issue precharged. Required when
+ // calibration can take a long time (during which there are only constant
+ // reads present on this bus). In this case need to issue perioidic
+ // precharges to avoid tRAS violation. This signal must meet the following
+ // requirements: (1) only transition from 0->1 when prech is first needed,
+ // (2) stay at 1 and only transition 1->0 when RDLVL_PRECH_DONE asserted
+ //***************************************************************************
+
+ always @(posedge clk)
+ if (rst)
+ rdlvl_prech_req <= #TCQ 1\'b0;
+ else
+ // Combine requests from all stages here'b'
+ rdlvl_prech_req <= #TCQ cal1_prech_req_r | cal2_prech_req_r |
+ cal_clkdiv_prech_req_r;
+
+ //***************************************************************************
+ // Shift register to store last RDDATA_SHIFT_LEN cycles of data from ISERDES
+ // NOTE: Written using discrete flops, but SRL can be used if the matching
+ // logic does the comparison sequentially, rather than parallel
+ //***************************************************************************
+
+ generate
+ genvar rd_i;
+ for (rd_i = 0; rd_i < DRAM_WIDTH; rd_i = rd_i + 1) begin: gen_sr
+ always @(posedge clk) begin
+ sr_rise0_r[rd_i] <= #TCQ {sr_rise0_r[rd_i][RD_SHIFT_LEN-2:0],
+ mux_rd_rise0_r[rd_i]};
+ sr_fall0_r[rd_i] <= #TCQ {sr_fall0_r[rd_i][RD_SHIFT_LEN-2:0],
+ mux_rd_fall0_r[rd_i]};
+ sr_rise1_r[rd_i] <= #TCQ {sr_rise1_r[rd_i][RD_SHIFT_LEN-2:0],
+ mux_rd_rise1_r[rd_i]};
+ sr_fall1_r[rd_i] <= #TCQ {sr_fall1_r[rd_i][RD_SHIFT_LEN-2:0],
+ mux_rd_fall1_r[rd_i]};
+ end
+ end
+ endgenerate
+
+ //***************************************************************************
+ // First stage calibration: Capture clock
+ //***************************************************************************
+
+ //*****************************************************************
+ // Free-running counter to keep track of when to do parallel load of
+ // data from memory
+ //*****************************************************************
+
+ always @(posedge clk)
+ if (rst) begin
+ cnt_shift_r <= #TCQ \'b0;
+ sr_valid_r <= #TCQ 1\'b0;
+ end else begin
+ if (cnt_shift_r == RD_SHIFT_LEN-1) begin
+ sr_valid_r <= #TCQ 1\'b1;
+ cnt_shift_r <= #TCQ \'b0;
+ end else begin
+ sr_valid_r <= #TCQ 1\'b0;
+ cnt_shift_r <= #TCQ cnt_shift_r + 1;
+ end
+ end
+
+ //*****************************************************************
+ // Logic to determine when either edge of the data eye encountered
+ // Pre- and post-IDELAY update data pattern is compared, if they
+ // differ, than an edge has been encountered. Currently no attempt
+ // made to determine if the data pattern itself is ""correct"", only
+ // whether it changes after incrementing the IDELAY (possible
+ // future enhancement)
+ //*****************************************************************
+
+ assign store_sr_req = cal1_store_sr_req_r || cal_clkdiv_store_sr_req_r;
+
+ // Simple handshaking - when calib state machines want the OLD SR
+ // value to get loaded, it requests for it to be loaded. One the
+ // next sr_valid_r pulse, it does get loaded, and store_sr_done_r
+ // is then pulsed asserted to indicate this, and we all go on our
+ // merry way
+ always @(posedge clk)
+ if (rst) begin
+ store_sr_done_r <= #TCQ 1\'b0;
+ store_sr_r <= #TCQ 1\'b0;
+ end else begin
+ store_sr_done_r <= sr_valid_r & store_sr_r;
+ if (store_sr_req)
+ store_sr_r <= #TCQ 1\'b1;
+ else if (sr_valid_r && store_sr_r)
+ store_sr_r <= #TCQ 1\'b0;
+ end
+
+ // Determine if the comparison logic is putting out a valid
+ // output - as soon as a request is made to load in a new value
+ // for the OLD_SR shift register, the valid pipe is cleared. It
+ // then gets asserted once the new value gets loaded into the
+ // OLD_SR register
+ always @(posedge clk)
+ if (rst) begin
+ sr_match_valid_r <= #TCQ 1\'b0;
+ sr_match_valid_r1 <= #TCQ 1\'b0;
+ old_sr_valid_r <= #TCQ 1\'b0;
+ end else begin
+ // Flag to indicate whether data in OLD_SR register is valid
+ if (store_sr_req)
+ old_sr_valid_r <= #TCQ 1\'b0;
+ else if (store_sr_done_r)
+ old_sr_valid_r <= #TCQ 1\'b1;
+ // Immediately flush valid pipe to prevent any logic from
+ // acting on compare results using previous OLD_SR data
+ if (store_sr_req) begin
+ sr_match_valid_r <= #TCQ 1\'b0;
+ sr_match_valid_r1 <= #TCQ 1\'b0;
+ end else begin
+ sr_match_valid_r <= #TCQ old_sr_valid_r & sr_valid_r;
+ sr_match_valid_r1 <= #TCQ sr_match_valid_r;
+ end
+ end
+
+ // Create valid qualifier for previous sample compare - might not
+ // be needed - check previous sample compare timing
+ always @(posedge clk)
+ if (rst) begin
+ prev_match_valid_r <= #TCQ 1\'b0;
+ prev_match_valid_r1 <= #TCQ 1\'b0;
+ end else begin
+ prev_match_valid_r <= #TCQ sr_valid_r;
+ prev_match_valid_r1 <= #TCQ prev_match_valid_r;
+ end
+
+ // Transfer current data to old data, prior to incrementing IDELAY
+ generate
+ for (z = 0; z < DRAM_WIDTH; z = z + 1) begin: gen_old_sr
+ always @(posedge clk) begin
+ if (sr_valid_r) begin
+ // Load last sample (i.e. from current sampling interval)
+ prev_sr_rise0_r[z] <= #TCQ sr_rise0_r[z];
+ prev_sr_fall0_r[z] <= #TCQ sr_fall0_r[z];
+ prev_sr_rise1_r[z] <= #TCQ sr_rise1_r[z];
+ prev_sr_fall1_r[z] <= #TCQ sr_fall1_r[z];
+ end
+ if (sr_valid_r && store_sr_r) begin
+ old_sr_rise0_r[z] <= #TCQ sr_rise0_r[z];
+ old_sr_fall0_r[z] <= #TCQ sr_fall0_r[z];
+ old_sr_rise1_r[z] <= #TCQ sr_rise1_r[z];
+ old_sr_fall1_r[z] <= #TCQ sr_fall1_r[z];
+ end
+ end
+ end
+ endgenerate
+
+ //*******************************************************
+ // Match determination occurs over 3 cycles - pipelined for better timing
+ //*******************************************************
+
+ // CYCLE1: Compare all bits in DQS grp, generate separate term for each
+ // bit for each cycle of training seq. For example, if training seq = 4
+ // words, and there are 8-bits per DQS group, then there is total of
+ // 8*4 = 32 terms generated in this cycle
+ generate
+ genvar sh_i;
+ for (sh_i = 0; sh_i < DRAM_WIDTH; sh_i = sh_i + 1) begin: gen_sr_match
+ always @(posedge clk) begin
+ if (sr_valid_r) begin
+ // Structure HDL such that X on data bus will result in a mismatch
+ // This is required for memory models that can drive the bus with
+ // X\'s to model uncertainty regions (e.g. Denali)
+
+ // Check current sample vs. sample from last IODELAY tap
+ if (sr_rise0_r[sh_i] == old_sr_rise0_r[sh_i])
+ sr_match_rise0_r[sh_i] <= #TCQ 1\'b1;
+ else
+ sr_match_rise0_r[sh_i] <= #TCQ 1\'b0;
+
+ if (sr_fall0_r[sh_i] == old_sr_fall0_r[sh_i])
+ sr_match_fall0_r[sh_i] <= #TCQ 1\'b1;
+ else
+ sr_match_fall0_r[sh_i] <= #TCQ 1\'b0;
+
+ if (sr_rise1_r[sh_i] == old_sr_rise1_r[sh_i])
+ sr_match_rise1_r[sh_i] <= #TCQ 1\'b1;
+ else
+ sr_match_rise1_r[sh_i] <= #TCQ 1\'b0;
+
+ if (sr_fall1_r[sh_i] == old_sr_fall1_r[sh_i])
+ sr_match_fall1_r[sh_i] <= #TCQ 1\'b1;
+ else
+ sr_match_fall1_r[sh_i] <= #TCQ 1\'b0;
+
+ // Check current sample vs. sample from current IODELAY tap
+ if (sr_rise0_r[sh_i] == prev_sr_rise0_r[sh_i])
+ prev_match_rise0_r[sh_i] <= #TCQ 1\'b1;
+ else
+ prev_match_rise0_r[sh_i] <= #TCQ 1\'b0;
+
+ if (sr_fall0_r[sh_i] == prev_sr_fall0_r[sh_i])
+ prev_match_fall0_r[sh_i] <= #TCQ 1\'b1;
+ else
+ prev_match_fall0_r[sh_i] <= #TCQ 1\'b0;
+
+ if (sr_rise1_r[sh_i] == prev_sr_rise1_r[sh_i])
+ prev_match_rise1_r[sh_i] <= #TCQ 1\'b1;
+ else
+ prev_match_rise1_r[sh_i] <= #TCQ 1\'b0;
+
+ if (sr_fall1_r[sh_i] == prev_sr_fall1_r[sh_i])
+ prev_match_fall1_r[sh_i] <= #TCQ 1\'b1;
+ else
+ prev_match_fall1_r[sh_i] <= #TCQ 1\'b0;
+
+ end
+ end
+ end
+ endgenerate
+
+ // CYCLE 2: Logical AND match terms from all bits in DQS group together
+ always @(posedge clk) begin
+ // Check current sample vs. sample from last IODELAY tap
+ sr_match_rise0_and_r <= #TCQ &sr_match_rise0_r;
+ sr_match_fall0_and_r <= #TCQ &sr_match_fall0_r;
+ sr_match_rise1_and_r <= #TCQ &sr_match_rise1_r;
+ sr_match_fall1_and_r <= #TCQ &sr_match_fall1_r;
+ // Check current sample vs. sample from current IODELAY tap
+ prev_match_rise0_and_r <= #TCQ &prev_match_rise0_r;
+ prev_match_fall0_and_r <= #TCQ &prev_match_fall0_r;
+ prev_match_rise1_and_r <= #TCQ &prev_match_rise1_r;
+ prev_match_fall1_and_r <= #TCQ &prev_match_fall1_r;
+ end
+
+ // CYCLE 3: During the third cycle of compare, the comparison output
+ // over all the cycles of the training sequence is output
+ always @(posedge clk) begin
+ // Found edge only asserted if OLD_SR shift register contents are valid
+ // and a match has not occurred - since we\'re using this shift register
+ // scheme, we need to qualify the match with the valid signals because
+ // the ""old"" and ""current"" shift register contents can\'t be compared on
+ // every clock cycle, only when the shift register is ""fully loaded""
+ found_edge_r
+ <= #TCQ ((!sr_match_rise0_and_r || !sr_match_fall0_and_r ||
+ !sr_match_rise1_and_r || !sr_match_fall1_and_r) &&
+ sr_match_valid_r1);
+ found_edge_valid_r <= #TCQ sr_match_valid_r1;
+
+ prev_found_edge_r
+ <= #TCQ ((!prev_match_rise0_and_r || !prev_match_fall0_and_r ||
+ !prev_match_rise1_and_r || !prev_match_fall1_and_r) &&
+ prev_match_valid_r1);
+ prev_found_edge_valid_r <= #TCQ prev_match_valid_r1;
+ end
+
+ //*******************************************************
+ // Counters for tracking # of samples compared
+ // For each comparision point (i.e. to determine if an edge has
+ // occurred after each IODELAY increment when read leveling),
+ // multiple samples are compared in order to average out the effects
+ // of jitter. If any one of these samples is different than the ""old""
+ // sample corresponding to the previous IODELAY value, then an edge
+ // is declared to be detected.
+ //*******************************************************
+
+ // Two counters are used to keep track of # of samples compared, in
+ // order to make it easier to meeting timing on these paths
+
+ // First counter counts the number of samples directly
+ always @(posedge clk)
+ if (rst)
+ detect_edge_cnt0_r <= #TCQ \'b0;
+ else begin
+ if (detect_edge_start_r)
+ detect_edge_cnt0_r <= #TCQ \'b0;
+ else if (found_edge_valid_r)
+ detect_edge_cnt0_r <= #TCQ detect_edge_cnt0_r + 1;
+ end
+
+ always @(posedge clk)
+ if (rst)
+ detect_edge_cnt1_en_r <= #TCQ 1\'b0;
+ else begin
+ if (((SIM_CAL_OPTION == ""FAST_CAL"") ||
+ (SIM_CAL_OPTION == ""FAST_WIN_DETECT"")) &&
+ (detect_edge_cnt0_r == 12\'h001))
+ // Bypass multi-sampling for stage 1 when simulating with
+ // either fast calibration option, or with multi-sampling
+ // disabled
+ detect_edge_cnt1_en_r <= #TCQ 1\'b1;
+ else if (detect_edge_cnt0_r == DETECT_EDGE_SAMPLE_CNT0)
+ detect_edge_cnt1_en_r <= #TCQ 1\'b1;
+ else
+ detect_edge_cnt1_en_r <= #TCQ 1\'b0;
+ end
+
+ // Counter #2
+ always @(posedge clk)
+ if (rst)
+ detect_edge_cnt1_r <= #TCQ \'b0;
+ else begin
+ if (detect_edge_start_r)
+ detect_edge_cnt1_r <= #TCQ \'b0;
+ else if (detect_edge_cnt1_en_r)
+ detect_edge_cnt1_r <= #TCQ detect_edge_cnt1_r + 1;
+ end
+
+ always @(posedge clk)
+ if (rst)
+ detect_edge_done_r <= #TCQ 1\'b0;
+ else begin
+ if (detect_edge_start_r)
+ detect_edge_done_r <= #TCQ \'b0;
+ else if (((SIM_CAL_OPTION == ""FAST_CAL"") ||
+ (SIM_CAL_OPTION == ""FAST_WIN_DETECT"")) &&
+ (detect_edge_cnt1_r == 12\'h001))
+ // Bypass multi-sampling for stage 1 when simulating with
+ // either fast calibration option, or with multi-sampling
+ // disabled
+ detect_edge_done_r <= #TCQ 1\'b1;
+ else if (detect_edge_cnt1_r == DETECT_EDGE_SAMPLE_CNT1)
+ detect_edge_done_r <= #TCQ 1\'b1;
+ end
+
+ //*****************************************************************
+ // Keep track of how long we\'ve been in the same data eye
+ // (i.e. over how many taps we have not yet found an eye)
+ //*****************************************************************
+
+ // An actual edge occurs when either: (1) difference in read data between
+ // current IODELAY tap and previous IODELAY tap (yes, this is confusing,
+ // since this condition is represented by found_edge_latched_r), (2) if
+ // the previous IODELAY tap read data was jittering (in which case it
+ // doesn\'t matter what the current IODELAY tap sample looks like)
+ assign cal1_found_edge = found_edge_latched_r | last_tap_jitter_r;
+
+ always @(posedge clk)
+ // Reset to 0 every time we begin processing a new DQS group
+ if ((cal1_state_r == CAL1_IDLE) || (cal1_state_r == CAL1_NEXT_DQS)) begin
+ cnt_eye_size_r <= #TCQ 3\'b000;
+ found_stable_eye_r <= #TCQ 1\'b0;
+ last_tap_jitter_r <= #TCQ 1\'b0;
+ found_edge_latched_r <= #TCQ 1\'b0;
+ found_jitter_latched_r <= #TCQ 1\'b0;
+ end else if (cal1_state_r != CAL1_DETECT_EDGE) begin
+ // Reset ""latched"" signals before looking for an edge
+ found_edge_latched_r <= #TCQ 1\'b0;
+ found_jitter_latched_r <= #TCQ 1\'b0;
+ end else if (cal1_state_r == CAL1_DETECT_EDGE) begin
+ if (!detect_edge_done_r) begin
+ // While sampling:
+ // Latch if we\'ve found an edge (i.e. difference between current
+ // and previous IODELAY tap), and/or jitter (difference between
+ // current and previous sample - on the same IODELAY tap). It is
+ // possible to find an edge, and not jitter, but not vice versa
+ if (found_edge_r)
+ found_edge_latched_r <= #TCQ 1\'b1;
+ if (prev_found_edge_r)
+ found_jitter_latched_r <= #TCQ 1\'b1;
+ end else begin
+ // Once the sample interval is over, it\'s time for housekeeping:
+
+ // If jitter found during current tap, record for future compares
+ last_tap_jitter_r <= #TCQ found_jitter_latched_r;
+
+ // If we found an edge, or if the previous IODELAY tap had jitter
+ // then reset stable window counter to 0 - obviously we\'re not in
+ // the data valid window. Note that we care about whether jitter
+ // occurred during the previous tap because it\'s possible to not
+ // find an edge (in terms of how it\'s determined in found_edge_r)
+ // even though jitter occured during the previous tap.
+ if (cal1_found_edge) begin
+ cnt_eye_size_r <= #TCQ 3\'b000;
+ found_stable_eye_r <= #TCQ 1\'b0;
+ end else begin
+ // Otherwise, everytime we look for an edge, and don\'t find
+ // one, increment counter until minimum eye size encountered -
+ // note this counter does not track the eye size, but only if
+ // it exceeded minimum size
+ if (cnt_eye_size_r == MIN_EYE_SIZE-1)
+ found_stable_eye_r <= #TCQ 1\'b1;
+ else begin
+ found_stable_eye_r <= #TCQ 1\'b0;
+ cnt_eye_size_r <= #TCQ cnt_eye_size_r + 1;
+ end
+ end
+ end
+ end
+
+ //*****************************************************************
+ // keep track of edge tap counts found, and current capture clock
+ // tap count
+ //*****************************************************************
+
+ always @(posedge clk)
+ if (rst) begin
+ idel_tap_cnt_cpt_r <= #TCQ \'b0;
+ idel_tap_limit_cpt_r <= #TCQ 1\'b0;
+ end else begin
+ if (new_cnt_cpt_r) begin
+ idel_tap_cnt_cpt_r <= #TCQ 5\'b00000;
+ idel_tap_limit_cpt_r <= #TCQ 1\'b0;
+ end else if (cal1_dlyce_cpt_r) begin
+ if (cal1_dlyinc_cpt_r)
+ idel_tap_cnt_cpt_r <= #TCQ idel_tap_cnt_cpt_r + 1;
+ else
+ idel_tap_cnt_cpt_r <= #TCQ idel_tap_cnt_cpt_r - 1;
+ // Assert if tap limit has been reached
+ if ((idel_tap_cnt_cpt_r == IODELAY_TAP_LEN-2) && cal1_dlyinc_cpt_r)
+ idel_tap_limit_cpt_r <= #TCQ 1\'b1;
+ else
+ idel_tap_limit_cpt_r <= #TCQ 1\'b0;
+ end
+ end
+
+ //*****************************************************************
+ // keep track of when DQ tap limit is reached
+ //*****************************************************************
+
+ always @(posedge clk)
+ if (rst)
+ idel_tap_limit_dq_r <= #TCQ \'b0;
+ else begin
+ if (new_cnt_cpt_r)
+ idel_tap_limit_dq_r <= #TCQ 1\'b0;
+ else if (cal1_dq_tap_cnt_r == IODELAY_TAP_LEN-1)
+ idel_tap_limit_dq_r <= #TCQ 1\'b1;
+ end
+
+ //*****************************************************************
+
+ always @(posedge clk)
+ if (rst) begin
+ cal1_cnt_cpt_r <= #TCQ \'b0;
+ cal1_dlyce_cpt_r <= #TCQ 1\'b0;
+ cal1_dlyinc_cpt_r <= #TCQ 1\'b0;
+ cal1_dq_tap_cnt_r <= #TCQ 5\'b00000;
+ cal1_dq_taps_inc_r <= #TCQ 1\'b0;
+ cal1_prech_req_r <= #TCQ 1\'b0;
+ cal1_store_sr_req_r <= #TCQ 1\'b0;
+ cal1_state_r <= #TCQ CAL1_IDLE;
+ cnt_idel_dec_cpt_r <= #TCQ 6\'bxxxxxx;
+ cnt_idel_inc_cpt_r <= #TCQ 5\'bxxxxx;
+ cnt_idel_skip_idel_r <= #TCQ 5\'bxxxxx;
+ detect_edge_start_r <= #TCQ 1\'b0;
+ found_dq_edge_r <= #TCQ 1\'b0;
+ found_two_edge_r <= #TCQ 1\'b0;
+ found_first_edge_r <= #TCQ 1\'b0;
+ found_second_edge_r <= #TCQ 1\'b0;
+ first_edge_taps_r <= #TCQ 5\'bxxxxx;
+ new_cnt_cpt_r <= #TCQ 1\'b0;
+ rdlvl_done[0] <= #TCQ 1\'b0;
+ rdlvl_err[0] <= #TCQ 1\'b0;
+ right_edge_taps_r <= #TCQ 5\'bxxxxx;
+ second_edge_taps_r <= #TCQ 5\'bxxxxx;
+ second_edge_dq_taps_r <= #TCQ 5\'bxxxxx;
+ end else begin
+ // default (inactive) states for all ""pulse"" outputs
+ cal1_prech_req_r <= #TCQ 1\'b0;
+ cal1_dlyce_cpt_r <= #TCQ 1\'b0;
+ cal1_dlyinc_cpt_r <= #TCQ 1\'b0;
+ cal1_store_sr_req_r <= #TCQ 1\'b0;
+ detect_edge_start_r <= #TCQ 1\'b0;
+ new_cnt_cpt_r <= #TCQ 1\'b0;
+
+ case (cal1_state_r)
+
+ CAL1_IDLE:
+ if (rdlvl_start[0]) begin
+ if (SIM_CAL_OPTION == ""SKIP_CAL"") begin
+ // ""Hardcoded"" calibration option
+ cnt_idel_skip_idel_r <= #TCQ TBY4_TAPS;
+ cal1_state_r <= #TCQ CAL1_SKIP_RDLVL_INC_IDEL;
+ end else begin
+ new_cnt_cpt_r <= #TCQ 1\'b1;
+ cal1_state_r <= #TCQ CAL1_NEW_DQS_WAIT;
+ end
+ end
+
+ // Wait for various MUXes associated with a new DQS group to
+ // change - also gives time for the read data shift register
+ // to load with the updated data for the new DQS group
+ CAL1_NEW_DQS_WAIT:
+ if (!pipe_wait)
+ cal1_state_r <= #TCQ CAL1_IDEL_STORE_FIRST;
+
+ // When first starting calibration for a DQS group, save the
+ // current value of the read data shift register, and use this
+ // as a reference. Note that for the first iteration of the
+ // edge detection loop, we will in effect be checking for an edge
+ // at IODELAY taps = 0 - normally, we are comparing the read data
+ // for IODELAY taps = N, with the read data for IODELAY taps = N-1
+ // An edge can only be found at IODELAY taps = 0 if the read data
+ // is changing during this time (possible due to jitter)
+ CAL1_IDEL_STORE_FIRST: begin
+ cal1_store_sr_req_r <= #TCQ 1\'b1;
+ detect_edge_start_r <= #TCQ 1\'b1;
+ if (store_sr_done_r)begin
+ if(cal1_dq_taps_inc_r) // if using dq taps
+ cal1_state_r <= #TCQ CAL1_DETECT_EDGE_DQ;
+ else
+ cal1_state_r <= #TCQ CAL1_DETECT_EDGE;
+ end
+ end
+
+ // Check for presence of data eye edge
+ CAL1_DETECT_EDGE: begin
+ if (detect_edge_done_r) begin
+ if (cal1_found_edge) begin
+ // Sticky bit - asserted after we encounter an edge, although
+ // the current edge may not be considered the ""first edge"" this
+ // just means we found at least one edge
+ found_first_edge_r <= #TCQ 1\'b1;
+
+ // For use during ""low-frequency"" edge detection:
+ // Prevent underflow if we find an edge right away - at any
+ // rate, if we do, and later we don\'t find a second edge by
+ // using DQ taps, then we\'re running at a very low
+ // frequency, and we really don\'t care about whether the
+ // first edge found is a ""left"" or ""right"" edge - we have
+ // more margin to absorb any inaccuracy
+ if (!found_first_edge_r) begin
+ if (idel_tap_cnt_cpt_r == 5\'b00000)
+ right_edge_taps_r <= #TCQ 5\'b00000;
+ else
+ right_edge_taps_r <= #TCQ idel_tap_cnt_cpt_r - 1;
+ end
+
+ // Both edges of data valid window found:
+ // If we\'ve found a second edge after a region of stability
+ // then we must have just passed the second (""right"" edge of
+ // the window. Record this second_edge_taps = current tap-1,
+ // because we\'re one past the actual second edge tap, where
+ // the edge taps represent the extremes of the data valid
+ // window (i.e. smallest & largest taps where data still valid
+ if (found_first_edge_r && found_stable_eye_r) begin
+ found_second_edge_r <= #TCQ 1\'b1;
+ second_edge_taps_r <= #TCQ idel_tap_cnt_cpt_r - 1;
+ cal1_state_r <= #TCQ CAL1_CALC_IDEL;
+ end else begin
+ // Otherwise, an edge was found (just not the ""second"" edge)
+ // then record current tap count - this may be the ""left""
+ // edge of the current data valid window
+ first_edge_taps_r <= #TCQ idel_tap_cnt_cpt_r;
+ // If we haven\'t run out of taps, then keep incrementing
+ if (!idel_tap_limit_cpt_r)
+ cal1_state_r <= #TCQ CAL1_IDEL_STORE_OLD;
+ else begin
+ // If we ran out of taps moving the capture clock, and we
+ // haven\'t found second edge, then try to find edges by
+ // moving the DQ IODELAY taps
+ cal1_state_r <= #TCQ CAL1_RST_CPT;
+ // Using this counter to reset the CPT taps to zero
+ // taps + any PD taps
+ cnt_idel_dec_cpt_r <= #TCQ IODELAY_TAP_LEN - 1;
+ end
+ end
+ end else begin
+ // Otherwise, if we haven\'t found an edge....
+ if (!idel_tap_limit_cpt_r)
+ // If we still have taps left to use, then keep incrementing
+ cal1_state_r <= #TCQ CAL1_IDEL_STORE_OLD;
+ else begin
+ // If we ran out of taps moving the capture clock, and we
+ // haven\'t found even one or second edge, then try to find
+ // edges by moving the DQ IODELAY taps
+ cal1_state_r <= #TCQ CAL1_RST_CPT;
+ // Using this counter to reset the CPT taps to zero
+ // taps + any PD taps
+ cnt_idel_dec_cpt_r <= #TCQ IODELAY_TAP_LEN - 1;
+ end
+ end
+ end
+ end
+
+ // Store the current read data into the read data shift register
+ // before incrementing the tap count and doing this again
+ CAL1_IDEL_STORE_OLD: begin
+ cal1_store_sr_req_r <= #TCQ 1\'b1;
+ if (store_sr_done_r)begin
+ if(cal1_dq_taps_inc_r) // if using dq taps
+ cal1_state_r <= #TCQ CAL1_IDEL_INC_DQ;
+ else
+ cal1_state_r <= #TCQ CAL1_IDEL_INC_CPT;
+ end
+ end
+
+ // Increment IDELAY for both capture and resync clocks
+ CAL1_IDEL_INC_CPT: begin
+ cal1_dlyce_cpt_r <= #TCQ 1\'b1;
+ cal1_dlyinc_cpt_r <= #TCQ 1\'b1;
+ cal1_state_r <= #TCQ CAL1_IDEL_INC_CPT_WAIT;
+ end
+
+ // Wait for IDELAY for both capture and resync clocks, and internal
+ // nodes within ISERDES to settle, before checking again for an edge
+ CAL1_IDEL_INC_CPT_WAIT: begin
+ detect_edge_start_r <= #TCQ 1\'b1;
+ if (!pipe_wait)
+ cal1_state_r <= #TCQ CAL1_DETECT_EDGE;
+ end
+
+ // Calculate final value of IDELAY. At this point, one or both
+ // edges of data eye have been found, and/or all taps have been
+ // exhausted looking for the edges
+ // NOTE: We\'re calculating the amount to decrement by, not the
+ // absolute setting for DQ IDELAY
+ CAL1_CALC_IDEL: begin
+ //*******************************************************
+ // Now take care of IDELAY for capture clock:
+ // Explanation of calculations:
+ // 1. If 2 edges found, final IDELAY value =
+ // TAPS = FE_TAPS + ((SE_TAPS-FE_TAPS)/2)
+ // 2. If 1 edge found, final IDELAY value is either:
+ // TAPS = FE_TAPS - TBY4_TAPS, or
+ // TAPS = FE_TAPS + TBY4_TAPS
+ // Depending on which is achievable without overflow
+ // (and with bias toward having fewer taps)
+ // 3. If no edges found, then final IDELAY value is:
+ // TAPS = 15
+ // This is the best we can do with the information we
+ // have it guarantees we have at least 15 taps of
+ // margin on either side of calibration point
+ // How the final IDELAY tap is reached:
+ // 1. If 2 edges found, current tap count = SE_TAPS + 1
+ // * Decrement by [(SE_TAPS-FE_TAPS)/2] + 1
+ // 2. If 1 edge found, current tap count = 31
+ // * Decrement by 31 - FE_TAPS - TBY4, or
+ // * Decrement by 31 - FE_TAPS + TBY4
+ // 3. If no edges found
+ // * Decrement by 16
+ //*******************************************************
+
+ // CASE1: If 2 edges found.
+ // Only CASE1 will be true. Due to the low frequency fixes
+ // the SM will not transition to this state when two edges are not
+ // found.
+ if (found_second_edge_r)
+ // SYNTHESIS_NOTE: May want to pipeline this operation
+ // over multiple cycles for better timing. If so, need
+ // to add delay state in CAL1 state machine
+ cnt_idel_dec_cpt_r
+ <= #TCQ (({1\'b0, second_edge_taps_r} -
+ {1\'b0, first_edge_taps_r})>>1) + 1;
+ // CASE 2: 1 edge found
+ // NOTE: Need to later add logic to prevent decrementing below 0
+ else if (found_first_edge_r)
+ if (first_edge_taps_r >= IODELAY_TAP_LEN/2 &&
+ ((first_edge_taps_r+TBY4_TAPS) < (IODELAY_TAP_LEN - 1)))
+ // final IDELAY value = [FIRST_EDGE_TAPS-CLK_MEM_PERIOD/2]
+ cnt_idel_dec_cpt_r
+ <= #TCQ (IODELAY_TAP_LEN-1) - first_edge_taps_r - TBY4_TAPS;
+ else
+ // final IDELAY value = [FIRST_EDGE_TAPS+CLK_MEM_PERIOD/2]
+ cnt_idel_dec_cpt_r
+ <= #TCQ (IODELAY_TAP_LEN-1) - first_edge_taps_r + TBY4_TAPS;
+ else
+ // CASE 3: No edges found, decrement by half tap length
+ cnt_idel_dec_cpt_r <= #TCQ IODELAY_TAP_LEN/2;
+
+ // Now use the value we just calculated to decrement CPT taps
+ // to the desired calibration point
+ cal1_state_r <= #TCQ CAL1_IDEL_DEC_CPT;
+ end
+
+ // decrement capture clock IDELAY for final adjustment - center
+ // capture clock in middle of data eye. This adjustment will occur
+ // only when both the edges are found usign CPT taps. Must do this
+ // incrementally to avoid clock glitching (since CPT drives clock
+ // divider within each ISERDES)
+ CAL1_IDEL_DEC_CPT: begin
+ cal1_dlyce_cpt_r <= #TCQ 1\'b1;
+ cal1_dlyinc_cpt_r <= #TCQ 1\'b0;
+ // once adjustment is complete, we\'re done with calibration for
+ // this DQS, repeat for next DQS
+ cnt_idel_dec_cpt_r <= #TCQ cnt_idel_dec_cpt_r - 1;
+ if (cnt_idel_dec_cpt_r == 6\'b000001)
+ cal1_state_r <= #TCQ CAL1_IDEL_PD_ADJ;
+ end
+
+ // Determine whether we\'re done, or have more DQS\'s to calibrate
+ // Also request precharge after every byte, as appropriate
+ CAL1_NEXT_DQS: begin
+ cal1_prech_req_r <= #TCQ 1\'b1;
+ // Prepare for another iteration with next DQS group
+ found_dq_edge_r <= #TCQ 1\'b0;
+ found_two_edge_r <= #TCQ 1\'b0;
+ found_first_edge_r <= #TCQ 1\'b0;
+ found_second_edge_r <= #TCQ 1\'b0;
+ cal1_dq_taps_inc_r <= #TCQ 1\'b0;
+
+ // Wait until precharge that occurs in between calibration of
+ // DQS groups is finished
+ if (prech_done) begin
+ if ((cal1_cnt_cpt_r >= DQS_WIDTH-1) ||
+ (SIM_CAL_OPTION == ""FAST_CAL""))
+ cal1_state_r <= #TCQ CAL1_DONE;
+ else begin
+ // Process next DQS group
+ new_cnt_cpt_r <= #TCQ 1\'b1;
+ cal1_dq_tap_cnt_r <= #TCQ 5\'d0;
+ cal1_cnt_cpt_r <= #TCQ cal1_cnt_cpt_r + 1;
+ cal1_state_r <= #TCQ CAL1_NEW_DQS_WAIT;
+ end
+ end
+ end
+
+ CAL1_RST_CPT: begin
+ cal1_dq_taps_inc_r <= #TCQ 1\'b1;
+
+ // If we never found even one edge by varying CPT taps, then
+ // as an approximation set first edge tap indicators to 31. This
+ // will be used later in the low-frequency portion of calibration
+ if (!found_first_edge_r) begin
+ first_edge_taps_r <= #TCQ IODELAY_TAP_LEN - 1;
+ right_edge_taps_r <= #TCQ IODELAY_TAP_LEN - 1;
+ end
+
+ if (cnt_idel_dec_cpt_r == 6\'b000000) begin
+ // once the decerement is done. Go back to the CAL1_NEW_DQS_WAIT
+ // state to load the correct data for comparison and to start
+ // with DQ taps.
+ cal1_state_r <= #TCQ CAL1_NEW_DQS_WAIT;
+ // Start with a DQ tap value of 0
+ cal1_dq_tap_cnt_r <= #TCQ 5\'d0;
+ end else begin
+ // decrement both CPT taps to initial value.
+ // DQ IODELAY taps will be used to find the edges
+ cal1_dlyce_cpt_r <= #TCQ 1\'b1;
+ cal1_dlyinc_cpt_r <= #TCQ 1\'b0;
+ cnt_idel_dec_cpt_r <= #TCQ cnt_idel_dec_cpt_r - 1;
+ end
+ end
+
+ // When two edges are not found using CPT taps, finding edges
+ // using DQ taps.
+ CAL1_DETECT_EDGE_DQ: begin
+ if (detect_edge_done_r) begin
+ // when using DQ taps make sure the window size is at least 10.
+ // DQ taps used only in low frequency designs.
+ if ((found_edge_r) && (~found_first_edge_r ||
+ (tby4_r > 6\'d5))) begin
+ // Sticky bit - asserted after we encounter first edge
+ // If we\'ve found a second edge(using dq taps) after a region
+ // of stability ( using tby4_r count) then this must be the
+ // second (""using dq taps"") edge of the window
+ found_dq_edge_r <= #TCQ 1\'b1;
+ found_two_edge_r <= #TCQ found_first_edge_r;
+ cal1_state_r <= #TCQ CAL1_CALC_IDEL_DQ;
+ // Recording the dq taps when an edge is found. Account for
+ // the case when an edge is found at DQ IODELAY = 0 taps -
+ // possible because of jitter
+ if (cal1_dq_tap_cnt_r != 5\'d0)
+ second_edge_dq_taps_r <= #TCQ cal1_dq_tap_cnt_r - 1;
+ else
+ second_edge_dq_taps_r <= #TCQ 5\'d0;
+ end else begin
+ // No more DQ taps to increment - set left edge tap distance
+ // to 31 as an approximation, and move on to figuring out
+ // what needs to be done to center (or approximately center)
+ // sampling point in middle of read window
+ if (idel_tap_limit_dq_r) begin
+ cal1_state_r <= #TCQ CAL1_CALC_IDEL_DQ;
+ second_edge_dq_taps_r <= #TCQ IODELAY_TAP_LEN - 1;
+ end else
+ cal1_state_r <= #TCQ CAL1_IDEL_STORE_OLD;
+ end
+ end
+ end
+
+ CAL1_IDEL_INC_DQ: begin
+ cal1_dq_tap_cnt_r <= #TCQ cal1_dq_tap_cnt_r + 1;
+ cal1_state_r <= #TCQ CAL1_IDEL_INC_DQ_WAIT;
+ end
+
+ // Wait for IDELAY for DQ, and internal nodes within ISERDES
+ // to settle, before checking again for an edge
+ CAL1_IDEL_INC_DQ_WAIT: begin
+ detect_edge_start_r <= #TCQ 1\'b1;
+ if (!pipe_wait)
+ cal1_state_r <= #TCQ CAL1_DETECT_EDGE_DQ;
+ end
+
+ CAL1_CALC_IDEL_DQ: begin
+ cal1_state_r <= #TCQ CAL1_IDEL_INC_DQ_CPT;
+ cal1_dq_tap_cnt_r <= #TCQ 5\'d0;
+ cnt_idel_inc_cpt_r <= #TCQ 5\'d0;
+
+ // ------------------------------------------------------------
+ // Determine whether to move DQ or CPT IODELAY taps to best
+ // position sampling point in data valid window. In general,
+ // we want to avoid setting DQ IODELAY taps to a nonzero value
+ // in order to avoid adding IODELAY pattern-dependent jitter.
+ // ------------------------------------------------------------
+ // At this point, we have the following products of calibration:
+ // 1. right_edge_taps_r: distance in IODELAY taps from start
+ // position to right margin of current data valid window.
+ // Measured using CPT IODELAY.
+ // 2. first_edge_taps_r: distance in IODELAY taps from start
+ // position to start of left edge of next data valid window.
+ // Note that {first_edge_taps_r - right_edge_taps_r} = width
+ // of the uncertainty or noise region between consecutive
+ // data eyes. Measured using CPT IODELAY.
+ // 3. second_edge_dq_taps_r: distance in IODELAY taps from left
+ // edge of current data valid window. Measured using DQ
+ // IODELAY.
+ // 4. tby4_r: half the width of the eye as calculated by
+ // {second_edge_dq_taps_r + first_edge_taps_r}
+ // ------------------------------------------------------------
+ // If two edges are found (one each from moving CPT, and DQ
+ // IODELAYs), then the following cases are considered for setting
+ // final DQ and CPT delays (in the following order):
+ // 1. second_edge_dq_taps_r <= tby4_r:
+ // * incr. CPT taps by {second_edge_dq_taps_r - tby4_r}
+ // this means that there is more taps available to the right
+ // of the starting position
+ // 2. first_edge_taps_r + tby4_r <= 31 taps (IODELAY length)
+ // * incr CPT taps by {tby4_r}
+ // this means we have enough CPT taps available to us to
+ // position the sampling point in the middle of the next
+ // sampling window. Alternately, we could have instead
+ // positioned ourselves in the middle of the current window
+ // by using DQ taps, but if possible avoid using DQ taps
+ // because of pattern-dependent jitter
+ // 3. otherwise, our only recourse is to move DQ taps in order
+ // to center the sampling point in the middle of the current
+ // data valid window
+ // * set DQ taps to {tby4_r - right_edge_taps_r}
+ // ------------------------------------------------------------
+ // Note that the case where only one edge is found, either using
+ // CPT or DQ IODELAY taps is a subset of the above 3 cases, which
+ // can be approximated by setting either right_edge_taps_r = 31,
+ // or second_edge_dq_taps_r = 31. This doesn\'t result in an exact
+ // centering, but this will only occur at an extremely low
+ // frequency, and exact centering is not required
+ // ------------------------------------------------------------
+ if (second_edge_dq_taps_r <= tby4_r)
+ cnt_idel_inc_cpt_r <= #TCQ tby4_r - second_edge_dq_taps_r;
+ else if ((first_edge_taps_r + tby4_r) <= IODELAY_TAP_LEN-1)
+ cnt_idel_inc_cpt_r <= #TCQ first_edge_taps_r + tby4_r;
+ else
+ cal1_dq_tap_cnt_r <= #TCQ tby4_r - right_edge_taps_r;
+ end
+
+ // increment capture clock IDELAY for final adjustment - center
+ // capture clock in middle of data eye. This state transition will
+ // occur when only one edge or no edge is found using CPT taps
+ CAL1_IDEL_INC_DQ_CPT: begin
+ if (cnt_idel_inc_cpt_r == 6\'b000000)
+ // once adjustment is complete, we\'re done with calibration for
+ // this DQS, repeat for next DQS.
+ cal1_state_r <= #TCQ CAL1_IDEL_PD_ADJ;
+ else begin
+ cal1_dlyce_cpt_r <= #TCQ 1\'b1;
+ cal1_dlyinc_cpt_r <= #TCQ 1\'b1;
+ cnt_idel_inc_cpt_r <= #TCQ cnt_idel_inc_cpt_r - 1;
+ end
+ end
+
+ CAL1_IDEL_PD_ADJ: begin
+ // If CPT is < than half the required PD taps then move the
+ // CPT taps the DQ taps togather
+ if(idel_tap_cnt_cpt_r < (PD_HALF_TAP))begin
+ cal1_dlyce_cpt_r <= #TCQ 1\'b1;
+ cal1_dlyinc_cpt_r <= #TCQ 1\'b1;
+ cal1_dq_tap_cnt_r <= #TCQ cal1_dq_tap_cnt_r + 1;
+ end else
+ cal1_state_r <= #TCQ CAL1_NEXT_DQS;
+ end
+
+ // Done with this stage of calibration
+ // if used, allow DEBUG_PORT to control taps
+ CAL1_DONE:
+ rdlvl_done[0] <= #TCQ 1\'b1;
+
+ // Used for simulation only - hardcode IDELAY values for all rdlvl
+ // associated IODELAYs - kind of a cheesy way of providing for
+ // simulation, but I don\'t feel like modifying PHY_DQ_IOB to add
+ // extra parameters just for simulation. This part shouldn\'t get
+ // synthesized.
+ CAL1_SKIP_RDLVL_INC_IDEL: begin
+ cal1_dlyce_cpt_r <= #TCQ 1\'b1;
+ cal1_dlyinc_cpt_r <= #TCQ 1\'b1;
+ cnt_idel_skip_idel_r <= #TCQ cnt_idel_skip_idel_r - 1;
+ if (cnt_idel_skip_idel_r == 5\'b00001)
+ cal1_state_r <= #TCQ CAL1_DONE;
+ end
+
+ end'b'case
+ end
+
+ //***************************************************************************
+ // Calculates the window size during calibration.
+ // Value is used only when two edges are not found using the CPT taps.
+ // cal1_dq_tap_cnt_r deceremented by 1 to account for the correct window.
+ //***************************************************************************
+
+ always @(posedge clk) begin
+ if (cal1_dq_tap_cnt_r > 5\'d0)
+ tby4_r <= #TCQ ((cal1_dq_tap_cnt_r - 1) + right_edge_taps_r)>>1;
+ else
+ tby4_r <= #TCQ ((cal1_dq_tap_cnt_r) + right_edge_taps_r)>>1;
+ end
+
+ //***************************************************************************
+ // Stage 2 calibration: Read Enable
+ // Read enable calibration determines the ""round-trip"" time (in # of CLK
+ // cycles) between when a read command is issued by the controller, and
+ // when the corresponding read data is synchronized by into the CLK domain
+ //***************************************************************************
+
+ always @(posedge clk) begin
+ rd_active_r <= #TCQ rdlvl_rd_active;
+ rd_active_posedge_r <= #TCQ rdlvl_rd_active & ~rd_active_r;
+ end
+
+ //*****************************************************************
+ // Expected data pattern when properly aligned through bitslip
+ // Based on pattern of ({rise,fall}) =
+ // 0xF, 0x0, 0xA, 0x5, 0x5, 0xA, 0x9, 0x6
+ // Examining only the LSb of each DQS group, pattern is =
+ // bit3: 1, 0, 1, 0, 0, 1, 1, 0
+ // bit2: 1, 0, 0, 1, 1, 0, 0, 1
+ // bit1: 1, 0, 1, 0, 0, 1, 0, 1
+ // bit0: 1, 0, 0, 1, 1, 0, 1, 0
+ // Change the hard-coded pattern below accordingly as RD_SHIFT_LEN
+ // and the actual training pattern contents change
+ //*****************************************************************
+
+ assign pat_rise0[3] = 2\'b10;
+ assign pat_fall0[3] = 2\'b01;
+ assign pat_rise1[3] = 2\'b11;
+ assign pat_fall1[3] = 2\'b00;
+
+ assign pat_rise0[2] = 2\'b11;
+ assign pat_fall0[2] = 2\'b00;
+ assign pat_rise1[2] = 2\'b00;
+ assign pat_fall1[2] = 2\'b11;
+
+ assign pat_rise0[1] = 2\'b10;
+ assign pat_fall0[1] = 2\'b01;
+ assign pat_rise1[1] = 2\'b10;
+ assign pat_fall1[1] = 2\'b01;
+
+ assign pat_rise0[0] = 2\'b11;
+ assign pat_fall0[0] = 2\'b00;
+ assign pat_rise1[0] = 2\'b01;
+ assign pat_fall1[0] = 2\'b10;
+
+ // Do not need to look at sr_valid_r - the pattern can occur anywhere
+ // during the shift of the data shift register - as long as the order
+ // of the bits in the training sequence is correct. Each bit of each
+ // byte is compared to expected pattern - this is not strictly required.
+ // This was done to prevent (and ""drastically decrease"") the chance that
+ // invalid data clocked in when the DQ bus is tri-state (along with a
+ // combination of the correct data) will resemble the expected data
+ // pattern. A better fix for this is to change the training pattern and/or
+ // make the pattern longer.
+ generate
+ genvar pt_i;
+ for (pt_i = 0; pt_i < DRAM_WIDTH; pt_i = pt_i + 1) begin: gen_pat_match
+ always @(posedge clk) begin
+ if (sr_rise0_r[pt_i] == pat_rise0[pt_i%4])
+ pat_match_rise0_r[pt_i] <= #TCQ 1\'b1;
+ else
+ pat_match_rise0_r[pt_i] <= #TCQ 1\'b0;
+
+ if (sr_fall0_r[pt_i] == pat_fall0[pt_i%4])
+ pat_match_fall0_r[pt_i] <= #TCQ 1\'b1;
+ else
+ pat_match_fall0_r[pt_i] <= #TCQ 1\'b0;
+
+ if (sr_rise1_r[pt_i] == pat_rise1[pt_i%4])
+ pat_match_rise1_r[pt_i] <= #TCQ 1\'b1;
+ else
+ pat_match_rise1_r[pt_i] <= #TCQ 1\'b0;
+
+ if (sr_fall1_r[pt_i] == pat_fall1[pt_i%4])
+ pat_match_fall1_r[pt_i] <= #TCQ 1\'b1;
+ else
+ pat_match_fall1_r[pt_i] <= #TCQ 1\'b0;
+ end
+ end
+ endgenerate
+
+ always @(posedge clk) begin
+ pat_match_rise0_and_r <= #TCQ &pat_match_rise0_r;
+ pat_match_fall0_and_r <= #TCQ &pat_match_fall0_r;
+ pat_match_rise1_and_r <= #TCQ &pat_match_rise1_r;
+ pat_match_fall1_and_r <= #TCQ &pat_match_fall1_r;
+ pat_data_match_r <= #TCQ (pat_match_rise0_and_r &&
+ pat_match_fall0_and_r &&
+ pat_match_rise1_and_r &&
+ pat_match_fall1_and_r);
+ end
+
+ // Generic counter to force wait after either bitslip value or
+ // CNT_RDEN is changed - allows time for old contents of read pipe
+ // to flush out
+ always @(posedge clk)
+ if (rst) begin
+ rden_wait_r <= #TCQ 1\'b0;
+ cnt_rden_wait_r <= #TCQ \'b0;
+ end else begin
+ if (cal2_state_r != CAL2_READ_WAIT) begin
+ rden_wait_r <= #TCQ 1\'b1;
+ cnt_rden_wait_r <= #TCQ \'b0;
+ end else begin
+ cnt_rden_wait_r <= #TCQ cnt_rden_wait_r + 1;
+ if (cnt_rden_wait_r == RDEN_WAIT_CNT-1)
+ rden_wait_r <= #TCQ 1\'b0;
+ end
+ end
+
+ // Register output for timing purposes
+ always @(posedge clk) begin
+ rd_bitslip_cnt <= #TCQ cal2_rd_bitslip_cnt_r;
+ rd_active_dly <= #TCQ cal2_rd_active_dly_r;
+ end
+
+ //*****************************************************************
+ // Calibration state machine for determining polarity of ISERDES
+ // CLKDIV invert control on a per-DQS group basis
+ // This stage is used to choose the best phase of the resync clock
+ // (on a per-DQS group basis) - ""best phase"" meaning the phase that
+ // results in the largest possible margin in the CLK-to-RSYNC clock
+ // domain transfer within the ISERDES.
+ // NOTE: This stage actually takes place after stage 1 calibration.
+ // For the time being, the signal naming convention associated with
+ // this stage will be known as ""cal_clkdiv"". However, it really is
+ // another stage of calibration - should be stage 2, and what is
+ // currently stage 2 (rd_active_dly calibration) should be changed
+ // to stage 3.
+ //*****************************************************************
+
+ assign rd_clkdiv_inv = clkdiv_inv_r;
+ assign dbg_rd_clkdiv_inv = clkdiv_inv_r;
+
+ always @(posedge clk)
+ if (rst) begin
+ cal_clkdiv_clkdiv_inv_r <= #TCQ 1\'b0;
+ cal_clkdiv_cnt_clkdiv_r <= #TCQ \'b0;
+ cal_clkdiv_dlyce_rsync_r <= #TCQ 1\'b0;
+ cal_clkdiv_dlyinc_rsync_r <= #TCQ 1\'b0;
+ cal_clkdiv_idel_rsync_inc_r <= #TCQ 1\'b0;
+ cal_clkdiv_prech_req_r <= #TCQ 1\'b0;
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_IDLE;
+ cal_clkdiv_store_sr_req_r <= #TCQ 1\'b0;
+ clkdiv_inv_r <= #TCQ \'b0;
+ idel_tap_delta_rsync_r <= #TCQ 5\'b00000;
+ min_rsync_marg_r <= #TCQ 5\'bxxxxx;
+ new_cnt_clkdiv_r <= #TCQ 1\'b0;
+ pol_min_rsync_marg_r <= #TCQ 1\'b0;
+ rdlvl_clkdiv_done <= #TCQ 1\'b0;
+ end else begin
+ // default (inactive) states for all ""pulse"" outputs
+ cal_clkdiv_dlyce_rsync_r <= #TCQ 1\'b0;
+ cal_clkdiv_prech_req_r <= #TCQ 1\'b0;
+ cal_clkdiv_store_sr_req_r <= #TCQ 1\'b0;
+ new_cnt_clkdiv_r <= #TCQ 1\'b0;
+
+ case (cal_clkdiv_state_r)
+
+ CAL_CLKDIV_IDLE:
+ if (rdlvl_clkdiv_start) begin
+ if (SIM_CAL_OPTION == ""SKIP_CAL"") begin
+ // ""Hardcoded"" calibration option - for all DQS groups
+ // do not invert rsync clock
+ clkdiv_inv_r <= #TCQ \'b0;
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_DONE;
+ end else begin
+ new_cnt_clkdiv_r <= #TCQ 1\'b1;
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_NEW_DQS_WAIT;
+ end
+ end
+
+ // Wait for various MUXes associated with a new DQS group to
+ // change - also gives time for the read data shift register
+ // to load with the updated data for the new DQS group
+ CAL_CLKDIV_NEW_DQS_WAIT: begin
+ // Reset smallest recorded margin
+ min_rsync_marg_r <= #TCQ 5\'b10000;
+ pol_min_rsync_marg_r <= 1\'b0;
+ if (!pipe_wait)
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_IDEL_STORE_REF;
+ end
+
+ // For a given polarity of the rsync clock, save the initial data
+ // value and use this as a reference to decide when an ""edge"" has
+ // been encountered as the rsync clock is shifted
+ CAL_CLKDIV_IDEL_STORE_REF: begin
+ cal_clkdiv_store_sr_req_r <= #TCQ 1\'b1;
+ if (store_sr_done_r)
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_DETECT_EDGE;
+ end
+
+ // Check for presence of cpt-rsync clock synchronization ""edge""
+ // This occurs when the captured data sequence changes as the RSYNC
+ // clock is shifted
+ CAL_CLKDIV_DETECT_EDGE:
+ if (found_edge_valid_r) begin
+ // If an edge found, or we\'ve run out of taps looking for an
+ // edge, then:
+ // (1) If the current margin found is the smallest, then
+ // record it, as well as whether the CLKDIV was inverted
+ // or not when this margin was measured
+ // (2) Reverse the direction of IDEL_RSYNC_INC and/or invert
+ // CLKDIV. We only invert CLKDIV if we just finished
+ // incrementing the RSYNC IODELAY with CLKDIV not inverted
+ // (3) Restore the original RSYNC clock delay in preparation
+ // for either further measurements with the current DQS
+ // group, or with the next DQS group
+ if ((idel_tap_delta_rsync_r == 5\'b01111) || found_edge_r) begin
+ // record the margin if it\'s the smallest found so far
+ if (idel_tap_delta_rsync_r < min_rsync_marg_r) begin
+ min_rsync_marg_r <= #TCQ idel_tap_delta_rsync_r;
+ pol_min_rsync_marg_r <= #TCQ cal_clkdiv_clkdiv_inv_r;
+ end
+ // Reverse direction of RSYNC inc/dec
+ cal_clkdiv_idel_rsync_inc_r <= #TCQ ~cal_clkdiv_idel_rsync_inc_r;
+ // Check whether to also invert CLKDIV (see above comments)
+ if (cal_clkdiv_idel_rsync_inc_r) begin
+ cal_clkdiv_clkdiv_inv_r
+ <= #TCQ ~cal_clkdiv_clkdiv_inv_r;
+ clkdiv_inv_r[cal_clkdiv_cnt_clkdiv_r]
+ <= #TCQ ~cal_clkdiv_clkdiv_inv_r;
+ end
+ // Proceed to restoring original RSYNC clock delay
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_IDEL_SET_MIDPT_RSYNC;
+ end else begin
+ // Otherwise, increment or decrement RSYNC phase, keep
+ // looking for an edge
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_IDEL_INCDEC_RSYNC;
+ end
+ end
+
+ // Increment or decrement RSYNC IODELAY by 1
+ CAL_CLKDIV_IDEL_INCDEC_RSYNC: begin
+ cal_clkdiv_dlyce_rsync_r <= #TCQ 1\'b1;
+ cal_clkdiv_dlyinc_rsync_r <= #TCQ cal_clkdiv_idel_rsync_inc_r;
+ cal_clkdiv_state_r
+ <= #TCQ CAL_CLKDIV_IDEL_INCDEC_RSYNC_WAIT;
+ idel_tap_delta_rsync_r <= #TCQ idel_tap_delta_rsync_r + 1;
+ end
+
+ // Wait for RSYNC IODELAY, internal nodes within ISERDES, and
+ // comparison logic shift register to settle, before checking again
+ // for an edge
+ CAL_CLKDIV_IDEL_INCDEC_RSYNC_WAIT: begin
+ if (!pipe_wait)
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_DETECT_EDGE;
+ end
+
+ // Restore RSYNC IODELAY to starting value
+ CAL_CLKDIV_IDEL_SET_MIDPT_RSYNC:
+ // Check case if we found an edge at starting tap (possible if
+ // we start at or near (near enough for jitter to affect us)
+ // the transfer point between the CLK and RSYNC clock domains
+ if (idel_tap_delta_rsync_r == 5\'b00000)
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_NEXT_CHECK;
+ else begin
+ cal_clkdiv_dlyce_rsync_r <= #TCQ 1\'b1;
+ // inc/dec the RSYNC IODELAY in the opposite directionas
+ // the just-finished search. This is a bit confusing, but note
+ // that after finishing the search, we always invert
+ // IDEL_RSYNC_INC prior to arriving at this state
+ cal_clkdiv_dlyinc_rsync_r <= #TCQ cal_clkdiv_idel_rsync_inc_r;
+ idel_tap_delta_rsync_r <= #TCQ idel_tap_delta_rsync_r - 1;
+ if (idel_tap_delta_rsync_r == 5\'b00001)
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_NEXT_CHECK;
+ end
+
+ // Determine where to go next:
+ // (1) start looking for an edge in the other direction (CLKDIV
+ // polarity unchanged)
+ // (2) change CLKDIV polarity, resample and record a reference
+ // data value, and start looking for an edge
+ // (3) if we\'ve searched all 4 possibilities (CLKDIV inverted,
+ // not inverted, RSYNC shifted in left and right directions)
+ // then decide which clock polarity is best to use for CLKDIV
+ // and proceed to next DQS
+ // NOTE: When we\'re comparing the current ""state"" (using both
+ // IDEL_RSYNC_INC and CLKDIV_INV) we are comparing what the
+ // next value of these signals will be, not what they were
+ // for the phase of edge detection just finished. Therefore
+ // IDEL_RSYNC_INC=0 and CLKDIV_INV=1 means we are about to
+ // decrement RSYNC with CLKDIV inverted (or in other words,
+ // we just searched with incrementing RSYNC, and CLKDIV not
+ // inverted)
+ CAL_CLKDIV_NEXT_CHECK:
+ // Wait for any residual change effects (CLKDIV inversion, RSYNC
+ // IODELAY inc/dec) from previous state to finish
+ if (!pipe_wait) begin
+ if (!cal_clkdiv_idel_rsync_inc_r && !cal_clkdiv_clkdiv_inv_r) begin
+ // If we\'ve searched all 4 possibilities, then decide which
+ // is the ""best"" clock polarity (which is to say, whichever
+ // polarity which DID NOT result in the minimum margin found)
+ // to use and proceed to next DQS
+ if (SIM_CAL_OPTION == ""FAST_CAL"")
+ // if simulating, and ""shortcuts"" for calibration enabled,
+ // apply results to all other elements (i.e. assume delay
+ // on all bits/bytes is same)
+ clkdiv_inv_r <= #TCQ {DQS_WIDTH{~pol_min_rsync_marg_r}};
+ else
+ // Otherwise, apply result only to current DQS group
+ clkdiv_inv_r[cal_clkdiv_cnt_clkdiv_r]
+ <= #TCQ ~pol_min_rsync_marg_r;
+
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_NEXT_DQS;
+ end else if (!cal_clkdiv_idel_rsync_inc_r &&
+ cal_clkdiv_clkdiv_inv_r)
+ // If we\'ve finished searching with CLKDIV not inverted
+ // Now store a new reference value for edge-detection
+ // comparison purposes and begin looking for an edge
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_IDEL_STORE_REF;
+ else
+ // Otherwise, we\'ve just finished checking by decrementing
+ // RSYNC. Now look for an edge by incrementing RSYNC
+ // (keep the CLKDIV polarity unchanged)
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_DETECT_EDGE;
+ end
+
+ // Determine whether we\'re done, or have more DQS\'s to calibrate
+ // Also request precharge after every byte
+ CAL_CLKDIV_NEXT_DQS: begin
+ cal_clkdiv_prech_req_r <= #TCQ 1\'b1;
+
+ // Wait until precharge that occurs in between calibration of
+ // DQS groups is finished
+ if (prech_done) begin
+ if ((cal_clkdiv_cnt_clkdiv_r >= DQS_WIDTH-1) ||
+ (SIM_CAL_OPTION == ""FAST_CAL""))
+ // If FAST_CAL enabled, only cal first DQS group - the results
+ // (aka CLKDIV invert) have been applied to all DQS groups
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_DONE;
+ else begin
+ // Otherwise increment DQS group counter and keep going
+ new_cnt_clkdiv_r <= #TCQ 1\'b1;
+ cal_clkdiv_cnt_clkdiv_r <= #TCQ cal_clkdiv_cnt_clkdiv_r + 1;
+ cal_clkdiv_state_r <= #TCQ CAL_CLKDIV_NEW_DQS_WAIT;
+ end
+ end
+ end
+
+ // Done with this stage of calibration
+ CAL_CLKDIV_DONE:
+ rdlvl_clkdiv_done <= #TCQ 1\'b1;
+
+ endcase
+ end
+
+ //*****************************************************************
+ // Stage 2 state machine
+ //*****************************************************************
+
+ // when calibrating, check to see which clock cycle (after the read is
+ // issued) does the expected data pattern arrive. Record this result
+ // NOTES:
+ // 1. An error condition can occur due to two reasons:
+ // a. If the matching logic waits a long enough amount of time
+ // and the expected data pattern is not received (longer than
+ // the theoretical maximum time that the data can take, factoring
+ // in CAS latency, prop delays, etc.), then flag an error.
+ // However, the error may be ""recoverable"" in that the write
+ // logic is still calibrating itself (in this case part of the
+ // write calibration is intertwined with the this stage of read
+ // calibration - write logic writes a pattern to the memory, then
+ // relies on rdlvl to find that pattern - if it doesn\'t, wrlvl
+ // changes its timing and tries again. By design, if the write path
+ // timing is incorrect, the rdlvl logic will never find the
+ // pattern). Because of this, there is a mechanism to restart
+ // this stage of rdlvl if an ""error"" is found.
+ // b. If the delay between different DQS groups is too large.
+ // There will be a maximum ""skew"" between different DQS groups
+ // based on routing, clock skew, etc.
+
+ // NOTE: Can add error checking here in case valid data not found on any
+ // of the available pipeline stages
+ always @(posedge clk) begin
+ if (rst) begin
+ cal2_cnt_bitslip_r <= #TCQ \'b0;
+ cal2_cnt_rd_dly_r <= #TCQ \'b0;
+ cal2_cnt_rden_r <= #TCQ \'b0;
+ cal2_done_r <= #TCQ 1\'b0;
+ cal2_en_dqs_skew_r <= #TCQ \'b0;
+ cal2_max_cnt_rd_dly_r <= #TCQ \'b0;
+ cal2_prech_req_r <= #TCQ 1\'b0;
+ cal2_rd_bitslip_cnt_r <= #TCQ \'b0;
+ cal2_state_r <= #TCQ CAL2_IDLE;
+ rdlvl_pat_err <= #TCQ 1\'b0;
+ end else begin
+ cal2_prech_req_r <= #TCQ 1\'b0;
+
+ case (cal2_state_r)
+ CAL2_IDLE:
+ if (rdlvl_start[1]) begin
+ if (SIM_CAL_OPTION == ""SKIP_CAL"") begin
+ // If skip rdlvl, then proceed to end. Also hardcode bitslip
+ // values based on CAS latency
+ cal2_state_r <= #TCQ CAL2_DONE;
+ case (nCL)
+ 5: cal2_rd_bitslip_cnt_r <= #TCQ {DQS_WIDTH{2\'b11}};
+ 6: cal2_rd_bitslip_cnt_r <= #TCQ {DQS_WIDTH{2\'b01}};
+ 7: cal2_rd_bitslip_cnt_r <= #TCQ {DQS_WIDTH{2\'b11}};
+ 8: cal2_rd_bitslip_cnt_r <= #TCQ {DQS_WIDTH{2\'b01}};
+ 9: cal2_rd_bitslip_cnt_r <= #TCQ {DQS_WIDTH{2\'b11}};
+ 10: cal2_rd_bitslip_cnt_r <= #TCQ {DQS_WIDTH{2\'b01}};
+ 11: cal2_rd_bitslip_cnt_r <= #TCQ {DQS_WIDTH{2\'b11}};
+ endcase
+ end else
+ cal2_state_r <= #TCQ CAL2_READ_WAIT;
+ end
+
+ // General wait state to wait for read pipe contents to settle
+ // either after bitslip is changed
+ CAL2_READ_WAIT: begin
+ // Reset read delay counter after bitslip is changed - with every
+ // new bitslip setting, we need to remeasure the read delay
+ cal2_cnt_rd_dly_r <= #TCQ \'b0;
+ // Wait for rising edge of synchronized rd_active signal from
+ // controller, then starts counting clock cycles until the correct
+ // pattern is returned from memory. Also make sure that we\'ve
+ // waited long enough after incrementing CNT_RDEN to allow data
+ // to change, and ISERDES pipeline to flush out
+ if ((rd_active_posedge_r == 1\'b1) && !rden_wait_r)
+ cal2_state_r <= #TCQ CAL2_DETECT_MATCH;
+ end
+
+ // Wait until either a match is found, or until enough cycles
+ // have passed that there could not possibly be a match
+ CAL2_DETECT_MATCH: begin
+ // Increment delay counter for every cycle we\'re in this state
+ cal2_cnt_rd_dly_r <= #TCQ cal2_cnt_rd_dly_r + 1;
+
+ if (pat_data_match_r)
+ // If found data match, then move on to next DQS group
+ cal2_state_r <= #TCQ CAL2_NEXT_DQS;
+ else if (cal2_cnt_rd_dly_r == MAX_RD_DLY_CNT-1) begin
+ if (cal2_cnt_bitslip_r != 2\'b11) begin
+ // If we\'ve waited enough cycles for worst possible ""round-trip""
+ // delay, then try next bitslip setting, and repeat this process
+ cal2_state_r <= #TCQ CAL2_READ_WAIT;
+ cal2_cnt_bitslip_r <= #TCQ cal2_cnt_bitslip_r + 1;
+ // Update bitslip count for current DQS group
+ if (SIM_CAL_OPTION == ""FAST_CAL"") begin
+ // Increment bitslip count - for simulation, update bitslip
+ // count for all DQS groups with same value
+ for (i = 0; i < DQS_WIDTH; i = i + 1) begin: loop_sim_bitslip
+ cal2_rd_bitslip_cnt_r[2*i+:2]
+ <= #TCQ cal2_rd_bitslip_cnt_r[2*i+:2] + 1;
+ end
+ end else
+ // Otherwise, increment only for current DQS group
+ cal2_rd_bitslip_cnt_r[2*(cal2_cnt_rden_r)+:2]
+ <= #TCQ cal2_rd_bitslip_cnt_r[2*(cal2_cnt_rden_r)+:2] + 1;
+ end else
+ // Otherwise, if we\'ve already exhausted all bitslip settings
+ // and still haven\'t found a match, the boat has **possibly **
+ // sunk (may be an error due to write calibration still
+ // figuring out its own timing)
+ cal2_state_r <= #TCQ CAL2_ERROR_TO;
+ end
+ end
+
+ // Final processing for current DQS group. Move on to next group
+ // Determine read enable delay between current DQS and DQS[0]
+ CAL2_NEXT_DQS: begin
+ // At this point, we\'ve just found the correct pattern for the
+ // current DQS group. Now check to see how long it took for the
+ // pattern to return. Record the current delay time, as well as
+ // the maximum time required across all the bytes
+ if (cal2_cnt_rd_dly_r > cal2_max_cnt_rd_dly_r)
+ cal2_max_cnt_rd_dly_r <= #TCQ cal2_cnt_rd_dly_r;
+ if (SIM_CAL_OPTION == ""FAST_CAL"") begin
+ // For simulation, update count for all DQS groups
+ for (j = 0; j < DQS_WIDTH; j = j + 1) begin: loop_sim_
+ cal2_dly_cnt_r[5*j+:5] <= #TCQ cal2_cnt_rd_dly_r;
+ end
+ end else
+ cal2_dly_cnt_r[5*(cal2_cnt_rden_r)+:5] <= #TCQ cal2_cnt_rd_dly_r;
+
+ // Request bank/row precharge, and wait for its completion. Always
+ // precharge after each DQS group to avoid tRAS(max) violation
+ cal2_prech_req_r <= #TCQ 1\'b1;
+ if (prech_done)
+ if (((DQS_WIDTH == 1) || (SIM_CAL_OPTION == ""FAST_CAL"")) ||
+ (cal2_cnt_rden_r == DQS_WIDTH-1)) begin
+ // If either FAST_CAL is enabled and first DQS group is
+ // finished, or if the last DQS group was just finished,
+ // then indicate that we can switch to final values for
+ // byte skews, and signal end of stage 2 calibration
+ cal2_en_dqs_skew_r <= #TCQ 1\'b1;
+ cal2_state_r <= #TCQ CAL2_DONE;
+ end else begin
+ // Continue to next DQS group
+ cal2_cnt_rden_r <= #TCQ cal2_cnt_rden_r + 1;
+ cal2_cnt_bitslip_r <= #TCQ 2\'b00;
+ cal2_state_r <= #TCQ CAL2_READ_WAIT;
+ end
+ end
+
+ // Finished with read enable calibration
+ CAL2_DONE:
+ cal2_done_r <= #TCQ 1\'b1;
+
+ // Error detected due to timeout from waiting for expected data pat
+ // Also assert error in this case, but also allow opportunity for
+ // external control logic to resume the calibration at this point
+ CAL2_ERROR_TO: begin
+ // Assert error even though error might be temporary (until write
+ // calibration logic asserts RDLVL_PAT_RESUME
+ rdlvl_pat_err <= #TCQ 1\'b1;
+ // Wait for resume signal from write calibration logic
+ if (rdlvl_pat_resume) begin
+ // Similarly, reset bitslip control for current DQS group to 0
+ cal2_rd_bitslip_cnt_r[2*(cal2_cnt_rden_r)+:2] <= #TCQ 2\'b00;
+ cal2_cnt_bitslip_r <= #TCQ 2\'b00;
+ cal2_state_r <= #TCQ CAL2_READ_WAIT;
+ rdlvl_pat_err <= #TCQ 1\'b0;
+ end
+ end
+ endcase
+ end
+ end
+
+ // Display which DQS group failed when timeout error occurs during pattern
+ // calibration. NOTE: Only valid when rdlvl_pat_err = 1
+ assign rdlvl_pat_err_cnt = cal2_cnt_rden_r;
+
+ // Final output: determine amount to delay rd_active signal by
+ always @(posedge clk)
+ if (SIM_CAL_OPTION == ""SKIP_CAL"")
+ // Hardcoded option (for simulation only). The results are very
+ // specific for a testbench w/o additional net delays using a Micron
+ // memory model. Any other configuration may not work.
+ case (nCL)
+ 5: cal2_rd_active_dly_r <= #TCQ 10;
+ 6: cal2_rd_active_dly_r <= #TCQ 10;
+ 7: cal2_rd_active_dly_r <= #TCQ 11;
+ 8: cal2_rd_active_dly_r <= #TCQ 11;
+ 9: cal2_rd_active_dly_r <= #TCQ 12;
+ 10: cal2_rd_active_dly_r <= #TCQ 12;
+ 11: cal2_rd_active_dly_r <= #TCQ 13;
+ endcase
+ else if (!rdlvl_done[1])
+ // Before calibration is complete, set RD_ACTIVE to minimum delay
+ cal2_rd_active_dly_r <= #TCQ \'b0;
+ else
+ // Set RD_ACTIVE based on maximum DQS group delay
+ cal2_rd_active_dly_r <= #TCQ cal2_max_cnt_rd_dly_r - RDEN_DELAY_OFFSET;
+
+ generate
+ genvar dqs_i;
+ for (dqs_i = 0; dqs_i < DQS_WIDTH; dqs_i = dqs_i + 1) begin: gen_dly
+ // Determine difference between delay for each DQS group, and the
+ // DQS group with the maximum delay
+ always @(posedge clk)
+ cal2_dly_cnt_delta_r[dqs_i]
+ <= #TCQ cal2_max_cnt_rd_dly_r - cal2_dly_cnt_r[5*dqs_i+:5];
+ // Delay those DQS groups with less than the maximum delay
+ always @(posedge clk) begin
+ if (rst) begin
+ cal2_clkdly_cnt_r[2*dqs_i+:2] <= #TCQ 2\'b00;
+ cal2_deskew_err_r[dqs_i] <= #TCQ 1\'b0;
+ end else if (!cal2_en_dqs_skew_r) begin
+ // While calibrating, do not skew individual bytes
+ cal2_clkdly_cnt_r[2*dqs_i+:2] <= #TCQ 2\'b00;
+ cal2_deskew_err_r[dqs_i] <= #TCQ 1\'b0;
+ end else begin
+ // Once done calibrating, go ahead and skew individual bytes
+ case (cal2_dly_cnt_delta_r[dqs_i])
+ 5\'b00000: begin
+ cal2_clkdly_cnt_r[2*dqs_i+:2] <= #TCQ 2\'b00;
+ cal2_deskew_err_r[dqs_i] <= #TCQ 1\'b0;
+ end
+ 5\'b00001: begin
+ cal2_clkdly_cnt_r[2*dqs_i+:2] <= #TCQ 2\'b01;
+ cal2_deskew_err_r[dqs_i] <= #TCQ 1\'b0;
+ end
+ 5\'b00010: begin
+ cal2_clkdly_cnt_r[2*dqs_i+:2] <= #TCQ 2\'b10;
+ cal2_deskew_err_r[dqs_i] <= #TCQ 1\'b0;
+ end
+ 5\'b00011: begin
+ cal2_clkdly_cnt_r[2*dqs_i+:2] <= #TCQ 2\'b11;
+ cal2_deskew_err_r[dqs_i] <= #TCQ 1\'b0;
+ end
+ default: begin
+ // If there\'s more than 3 cycles of skew between different
+ // then flag error
+ cal2_clkdly_cnt_r[2*dqs_i+:2] <= #TCQ 2\'bxx;
+ cal2_deskew_err_r[dqs_i] <= #TCQ 1\'b1;
+ end
+ endcase
+ end
+ end
+ end
+ endgenerate
+
+ always @(posedge clk)
+ rd_clkdly_cnt <= #TCQ cal2_clkdly_cnt_r;
+
+ // Assert when non-recoverable error occurs during stage 2 cal
+ always @(posedge clk)
+ if (rst)
+ rdlvl_err[1] <= #TCQ 1\'b0;
+ else
+ // Combine errors from each of the individual DQS group deskews
+ rdlvl_err[1] <= #TCQ | cal2_deskew_err_r;
+
+ // Delay assertion of RDLVL_DONE for stage 2 by a few cycles after
+ // we\'ve reached CAL2_DONE to account for fact that the proper deskew
+ // delays still need to be calculated, and driven to the individual
+ // DQ/DQS delay blocks. It\'s not an exact science, the # of delay cycles
+ // is sufficient. Feel free to add more delay if the calculation or FSM
+ // logic is later changed.
+ always @(posedge clk)
+ if (rst) begin
+ cal2_done_r1 <= #TCQ 1\'b0;
+ cal2_done_r2 <= #TCQ 1\'b0;
+ cal2_done_r3 <= #TCQ 1\'b0;
+ rdlvl_done[1] <= #TCQ 1\'b0;
+ end else begin
+ cal2_done_r1 <= #TCQ cal2_done_r;
+ cal2_done_r2 <= #TCQ cal2_done_r1;
+ cal2_done_r3 <= #TCQ cal2_done_r2;
+ rdlvl_done[1] <= #TCQ cal2_done_r3;
+ end
+
+
+endmodule
+"
+"
+//-----------------------------------------------------------------------------
+//
+// (c) Copyright 2009-2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//-----------------------------------------------------------------------------
+// Project : Virtex-6 Integrated Block for PCI Express
+// File : gtx_drp_chanalign_fix_3752_v6.v
+// Version : 2.4
+//--
+//-- Description: Virtex6 Workaround for deadlock due lane-lane skew Bug
+//--
+//--
+//--
+//--------------------------------------------------------------------------------
+
+`timescale 1ns / 1ps
+module GTX_DRP_CHANALIGN_FIX_3752_V6
+#(
+ parameter TCQ = 1,
+ parameter C_SIMULATION = 0 // Set to 1 for simulation
+)
+(
+ output reg dwe,
+ output reg [15:0] din, //THIS IS THE INPUT TO THE DRP
+ output reg den,
+ output reg [7:0] daddr,
+ output reg [3:0] drpstate,
+ input write_ts1,
+ input write_fts,
+ input [15:0] dout, //THIS IS THE OUTPUT OF THE DRP
+ input drdy,
+ input Reset_n,
+ input drp_clk
+
+);
+
+
+ reg [7:0] next_daddr;
+ reg [3:0] next_drpstate;
+
+
+
+ reg write_ts1_gated;
+ reg write_fts_gated;
+
+
+ localparam DRP_IDLE_FTS = 1;
+ localparam DRP_IDLE_TS1 = 2;
+ localparam DRP_RESET = 3;
+ localparam DRP_WRITE_FTS = 6;
+ localparam DRP_WRITE_DONE_FTS = 7;
+ localparam DRP_WRITE_TS1 = 8;
+ localparam DRP_WRITE_DONE_TS1 = 9;
+ localparam DRP_COM = 10\'b0110111100;
+ localparam DRP_FTS = 10\'b0100111100;
+ localparam DRP_TS1 = 10\'b0001001010;
+
+
+ always @(posedge drp_clk) begin
+
+ if ( ~Reset_n ) begin
+
+ daddr <= #(TCQ) 8\'h8;
+ drpstate <= #(TCQ) DRP_RESET;
+
+
+ write_ts1_gated <= #(TCQ) 0;
+ write_fts_gated <= #(TCQ) 0;
+
+ end else begin
+
+ daddr <= #(TCQ) next_daddr;
+ drpstate <= #(TCQ) next_drpstate;
+
+
+
+ write_ts1_gated <= #(TCQ) write_ts1;
+ write_fts_gated <= #(TCQ) write_fts;
+
+ end
+
+ end
+
+
+ always @(*) begin
+
+ // DEFAULT CONDITIONS
+ next_drpstate=drpstate;
+ next_daddr=daddr;
+ den=0;
+ din=0;
+ dwe=0;
+
+ case(drpstate)
+
+ // RESET CONDITION, WE NEED TO READ THE TOP 6 BITS OF THE DRP REGISTER WHEN WE GET THE WRITE FTS TRIGGER
+ DRP_RESET : begin
+
+ next_drpstate= DRP_WRITE_TS1;
+ next_daddr=8\'h8;
+
+ end
+
+
+
+ // WRITE FTS SEQUENCE
+ DRP_WRITE_FTS : begin
+
+ den=1;
+ dwe=1;
+ case (daddr)
+ 8\'h8 : din = 16\'hFD3C;
+ 8\'h9 : din = 16\'hC53C;
+ 8\'hA : din = 16\'hFDBC;
+ 8\'hB : din = 16\'h853C;
+ endcase
+ next_drpstate=DRP_WRITE_DONE_FTS;
+
+ end
+
+ // WAIT FOR FTS SEQUENCE WRITE TO FINISH, ONCE WE FINISH ALL WRITES GO TO FTS IDLE
+ DRP_WRITE_DONE_FTS : begin
+
+ if(drdy) begin
+
+ if(daddr==8\'hB) begin
+
+ next_drpstate=DRP_IDLE_FTS;
+ next_daddr=8\'h8;
+
+ end else begin
+
+ next_drpstate=DRP_WRITE_FTS;
+ next_daddr=daddr+1\'b1;
+
+ end
+
+ end
+
+ end
+
+ // FTS IDLE: WAIT HERE UNTIL WE NEED TO WRITE TS1
+ DRP_IDLE_FTS : begin
+
+ if(write_ts1_gated) begin
+
+ next_drpstate=DRP_WRITE_TS1;
+ next_daddr=8\'h8;
+
+ end
+
+ end
+
+ // WRITE TS1 SEQUENCE
+ DRP_WRITE_TS1 : begin
+ den=1;
+ dwe=1;
+ case (daddr)
+ 8\'h8 : din = 16\'hFC4A;
+ 8\'h9 : din = 16\'hDC4A;
+ 8\'hA : din = 16\'hC04A;
+ 8\'hB : din = 16\'h85BC;
+ endcase
+ next_drpstate=DRP_WRITE_DONE_TS1;
+
+ end
+
+ // WAIT FOR TS1 SEQUENCE WRITE TO FINISH, ONCE WE FINISH ALL WRITES GO TO TS1 IDLE
+ DRP_WRITE_DONE_TS1 : begin
+
+ if(drdy) begin
+
+ if(daddr==8\'hB) begin
+
+ next_drpstate=DRP_IDLE_TS1;
+ next_daddr=8\'h8;
+
+ end else begin
+
+ next_drpstate=DRP_WRITE_TS1;
+ next_daddr=daddr+1\'b1;
+
+ end
+
+ end
+
+ end
+
+ // TS1 IDLE: WAIT HERE UNTIL WE NEED TO WRITE FTS
+ DRP_IDLE_TS1 : begin
+
+ if(write_fts_gated) begin
+
+ next_drpstate=DRP_WRITE_FTS;
+ next_daddr=8\'h8;
+
+ end
+
+ end
+
+ endcase
+
+ end
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2008 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : %version
+// \\ \\ Application : MIG
+// / / Filename : arb_mux.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : 7-Series
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+
+`timescale 1ps/1ps
+
+module mig_7series_v1_8_arb_mux #
+ (
+ parameter TCQ = 100,
+ parameter EVEN_CWL_2T_MODE = ""OFF"",
+ parameter ADDR_CMD_MODE = ""1T"",
+ parameter BANK_VECT_INDX = 11,
+ parameter BANK_WIDTH = 3,
+ parameter BURST_MODE = ""8"",
+ parameter CS_WIDTH = 4,
+ parameter CL = 5,
+ parameter CWL = 5,
+ parameter DATA_BUF_ADDR_VECT_INDX = 31,
+ parameter DATA_BUF_ADDR_WIDTH = 8,
+ parameter DRAM_TYPE = ""DDR3"",
+ parameter CKE_ODT_AUX = ""FALSE"", //Parameter to turn on/off the aux_out signal
+ parameter EARLY_WR_DATA_ADDR = ""OFF"",
+ parameter ECC = ""OFF"",
+ parameter nBANK_MACHS = 4,
+ parameter nCK_PER_CLK = 2, // # DRAM CKs per fabric CLKs
+ parameter nCS_PER_RANK = 1,
+ parameter nRAS = 37500, // ACT->PRE cmd period (CKs)
+ parameter nRCD = 12500, // ACT->R/W delay (CKs)
+ parameter nSLOTS = 2,
+ parameter nWR = 6, // Write recovery (CKs)
+ parameter RANKS = 1,
+ parameter RANK_VECT_INDX = 15,
+ parameter RANK_WIDTH = 2,
+ parameter ROW_VECT_INDX = 63,
+ parameter ROW_WIDTH = 16,
+ parameter RTT_NOM = ""40"",
+ parameter RTT_WR = ""120"",
+ parameter SLOT_0_CONFIG = 8\'b0000_0101,
+ parameter SLOT_1_CONFIG = 8\'b0000_1010
+ )
+ (/*AUTOARG*/
+ // Outputs
+ output [ROW_WIDTH-1:0] col_a, // From arb_select0 of arb_select.v
+ output [BANK_WIDTH-1:0] col_ba, // From arb_select0 of arb_select.v
+ output [DATA_BUF_ADDR_WIDTH-1:0] col_data_buf_addr,// From arb_select0 of arb_select.v
+ output col_periodic_rd, // From arb_select0 of arb_select.v
+ output [RANK_WIDTH-1:0] col_ra, // From arb_select0 of arb_select.v
+ output col_rmw, // From arb_select0 of arb_select.v
+ output col_rd_wr,
+ output [ROW_WIDTH-1:0] col_row, // From arb_select0 of arb_select.v
+ output col_size, // From arb_select0 of arb_select.v
+ output [DATA_BUF_ADDR_WIDTH-1:0] col_wr_data_buf_addr,// From arb_select0 of arb_select.v
+ output wire [nCK_PER_CLK-1:0] mc_ras_n,
+ output wire [nCK_PER_CLK-1:0] mc_cas_n,
+ output wire [nCK_PER_CLK-1:0] mc_we_n,
+ output wire [nCK_PER_CLK*ROW_WIDTH-1:0] mc_address,
+ output wire [nCK_PER_CLK*BANK_WIDTH-1:0] mc_bank,
+ output wire [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] mc_cs_n,
+ output wire [1:0] mc_odt,
+ output wire [nCK_PER_CLK-1:0] mc_cke,
+ output wire [3:0] mc_aux_out0,
+ output wire [3:0] mc_aux_out1,
+ output [2:0] mc_cmd,
+ output [5:0] mc_data_offset,
+ output [5:0] mc_data_offset_1,
+ output [5:0] mc_data_offset_2,
+ output [1:0] mc_cas_slot,
+ output [RANK_WIDTH-1:0] rnk_config, // From arb_select0 of arb_select.v
+ output rnk_config_valid_r, // From arb_row_col0 of arb_row_col.v
+ output [nBANK_MACHS-1:0] sending_row, // From arb_row_col0 of arb_row_col.v
+ output [nBANK_MACHS-1:0] sending_pre,
+ output sent_col, // From arb_row_col0 of arb_row_col.v
+ output sent_col_r, // From arb_row_col0 of arb_row_col.v
+ output sent_row, // From arb_row_col0 of arb_row_col.v
+ output [nBANK_MACHS-1:0] sending_col,
+ output rnk_config_strobe,
+ output insert_maint_r1,
+ output rnk_config_kill_rts_col,
+
+ // Inputs
+ input clk,
+ input rst,
+ input init_calib_complete,
+ input [6*RANKS-1:0] calib_rddata_offset,
+ input [6*RANKS-1:0] calib_rddata_offset_1,
+ input [6*RANKS-1:0] calib_rddata_offset_2,
+ input [ROW_VECT_INDX:0] col_addr, // To arb_select0 of arb_select.v
+ input [nBANK_MACHS-1:0] col_rdy_wr, // To arb_row_col0 of arb_row_col.v
+ input insert_maint_r, // To arb_row_col0 of arb_row_col.v
+ input [RANK_WIDTH-1:0] maint_rank_r, // To arb_select0 of arb_select.v
+ input maint_zq_r, // To arb_select0 of arb_select.v
+ input maint_sre_r, // To arb_select0 of arb_select.v
+ input maint_srx_r, // To arb_select0 of arb_select.v
+ input [nBANK_MACHS-1:0] rd_wr_r, // To arb_select0 of arb_select.v
+ input [BANK_VECT_INDX:0] req_bank_r, // To arb_select0 of arb_select.v
+ input [nBANK_MACHS-1:0] req_cas, // To arb_select0 of arb_select.v
+ input [DATA_BUF_ADDR_VECT_INDX:0] req_data_buf_addr_r,// To arb_select0 of arb_select.v
+ input [nBANK_MACHS-1:0] req_periodic_rd_r, // To arb_select0 of arb_select.v
+ input [RANK_VECT_INDX:0] req_rank_r, // To arb_select0 of arb_select.v
+ input [nBANK_MACHS-1:0] req_ras, // To arb_select0 of arb_select.v
+ input [ROW_VECT_INDX:0] req_row_r, // To arb_select0 of arb_select.v
+ input [nBANK_MACHS-1:0] req_size_r, // To arb_select0 of arb_select.v
+ input [nBANK_MACHS-1:0] req_wr_r, // To arb_select0 of arb_select.v
+ input [ROW_VECT_INDX:0] row_addr, // To arb_select0 of arb_select.v
+ input [nBANK_MACHS-1:0] row_cmd_wr, // To arb_select0 of arb_select.v
+ input [nBANK_MACHS-1:0] rtc, // To arb_row_col0 of arb_row_col.v
+ input [nBANK_MACHS-1:0] rts_col, // To arb_row_col0 of arb_row_col.v
+ input [nBANK_MACHS-1:0] rts_row, // To arb_row_col0 of arb_row_col.v
+ input [nBANK_MACHS-1:0] rts_pre, // To arb_row_col0 of arb_row_col.v
+ input [7:0] slot_0_present, // To arb_select0 of arb_select.v
+ input [7:0] slot_1_present // To arb_select0 of arb_select.v
+
+ );
+
+ /*AUTOINPUT*/
+ // Beginning of automatic inputs (from unused autoinst inputs)
+ // End of automatics
+
+ /*AUTOOUTPUT*/
+ // Beginning of automatic outputs (from unused autoinst outputs)
+
+ // End of automatics
+
+ /*AUTOWIRE*/
+ // Beginning of automatic wires (for undeclared instantiated-module outputs)
+ wire cs_en0; // From arb_row_col0 of arb_row_col.v
+ wire cs_en1; // From arb_row_col0 of arb_row_col.v
+ wire [nBANK_MACHS-1:0] grant_col_r; // From arb_row_col0 of arb_row_col.v
+ wire [nBANK_MACHS-1:0] grant_col_wr; // From arb_row_col0 of arb_row_col.v
+ wire [nBANK_MACHS-1:0] grant_config_r; // From arb_row_col0 of arb_row_col.v
+ wire [nBANK_MACHS-1:0] grant_row_r; // From arb_row_col0 of arb_row_col.v
+ wire [nBANK_MACHS-1:0] grant_pre_r; // From arb_row_col0 of arb_row_col.v
+ wire send_cmd0_row; // From arb_row_col0 of arb_row_col.v
+ wire send_cmd0_col; // From arb_row_col0 of arb_row_col.v
+ wire send_cmd1_row; // From arb_row_col0 of arb_row_col.v
+ wire send_cmd1_col;
+ wire send_cmd2_row;
+ wire send_cmd2_col;
+ wire send_cmd2_pre;
+ wire send_cmd3_col;
+ wire [5:0] col_channel_offset;
+ // End of automatics
+
+ wire sent_col_i;
+
+ assign sent_col = sent_col_i;
+
+ mig_7series_v1_8_arb_row_col #
+ (/*AUTOINSTPARAM*/
+ // Parameters
+ .TCQ (TCQ),
+ .ADDR_CMD_MODE (ADDR_CMD_MODE),
+ .CWL (CWL),
+ .EARLY_WR_DATA_ADDR (EARLY_WR_DATA_ADDR),
+ .nBANK_MACHS (nBANK_MACHS),
+ .nCK_PER_CLK (nCK_PER_CLK),
+ .nRAS (nRAS),
+ .nRCD (nRCD),
+ .nWR (nWR))
+ arb_row_col0
+ (/*AUTOINST*/
+ // Outputs
+ .grant_row_r (grant_row_r[nBANK_MACHS-1:0]),
+ .grant_pre_r (grant_pre_r[nBANK_MACHS-1:0]),
+ .sent_row (sent_row),
+ .sending_row (sending_row[nBANK_MACHS-1:0]),
+ .sending_pre (sending_pre[nBANK_MACHS-1:0]),
+ .grant_config_r (grant_config_r[nBANK_MACHS-1:0]),
+ .rnk_config_strobe (rnk_config_strobe),
+ .rnk_config_kill_rts_col (rnk_config_kill_rts_col),
+ .rnk_config_valid_r (rnk_config_valid_r),
+ .grant_col_r (grant_col_r[nBANK_MACHS-1:0]),
+ .sending_col (sending_col[nBANK_MACHS-1:0]),
+ .sent_col (sent_col_i),
+ .sent_col_r (sent_col_r),
+ .grant_col_wr (grant_col_wr[nBANK_MACHS-1:0]),
+ .send_cmd0_row (send_cmd0_row),
+ .send_cmd0_col (send_cmd0_col),
+ .send_cmd1_row (send_cmd1_row),
+ .send_cmd1_col (send_cmd1_col),
+ .send_cmd2_row (send_cmd2_row),
+ .send_cmd2_col (send_cmd2_col),
+ .send_cmd2_pre (send_cmd2_pre),
+ .send_cmd3_col (send_cmd3_col),
+ .col_channel_offset (col_channel_offset),
+ .cs_en0 (cs_en0),
+ .cs_en1 (cs_en1),
+ .cs_en2 (cs_en2),
+ .cs_en3 (cs_en3),
+ .insert_maint_r1 (insert_maint_r1),
+ // Inputs
+ .clk (clk),
+ .rst (rst),
+ .rts_row (rts_row[nBANK_MACHS-1:0]),
+ .rts_pre (rts_pre[nBANK_MACHS-1:0]),
+ .insert_maint_r (insert_maint_r),
+ .rts_col (rts_col[nBANK_MACHS-1:0]),
+ .rtc (rtc[nBANK_MACHS-1:0]),
+ .col_rdy_wr (col_rdy_wr[nBANK_MACHS-1:0]));
+
+ mig_7series_v1_8_arb_select #
+ (/*AUTOINSTPARAM*/
+ // Parameters
+ .TCQ (TCQ),
+ .EVEN_CWL_2T_MODE (EVEN_CWL_2T_MODE),
+ .ADDR_CMD_MODE (ADDR_CMD_MODE),
+ .BANK_VECT_INDX (BANK_VECT_INDX),
+ .BANK_WIDTH (BANK_WIDTH),
+ .BURST_MODE (BURST_MODE),
+ .CS_WIDTH (CS_WIDTH),
+ .CL (CL),
+ .CWL (CWL),
+ .DATA_BUF_ADDR_VECT_INDX (DATA_BUF_ADDR_VECT_INDX),
+ .DATA_BUF_ADDR_WIDTH (DATA_BUF_ADDR_WIDTH),
+ .DRAM_TYPE (DRAM_TYPE),
+ .EARLY_WR_DATA_ADDR (EARLY_WR_DATA_ADDR),
+ .ECC (ECC),
+ .CKE_ODT_AUX (CKE_ODT_AUX),
+ .nBANK_MACHS (nBANK_MACHS),
+ .nCK_PER_CLK (nCK_PER_CLK),
+ .nCS_PER_RANK (nCS_PER_RANK),
+ .nSLOTS (nSLOTS),
+ .RANKS (RANKS),
+ .RANK_VECT_INDX (RANK_VECT_INDX),
+ .RANK_WIDTH (RANK_WIDTH),
+ .ROW_VECT_INDX (ROW_VECT_INDX),
+ .ROW_WIDTH (ROW_WIDTH),
+ .RTT_NOM (RTT_NOM),
+ .RTT_WR (RTT_WR),
+ .SLOT_0_CONFIG (SLOT_0_CONFIG),
+ .SLOT_1_CONFIG (SLOT_1_CONFIG))
+ arb_select0
+ (/*AUTOINST*/
+ // Outputs
+ .col_periodic_rd (col_periodic_rd),
+ .col_ra (col_ra[RANK_WIDTH-1:0]),
+ .col_ba (col_ba[BANK_WIDTH-1:0]),
+ .col_a (col_a[ROW_WIDTH-1:0]),
+ .col_rmw (col_rmw),
+ .col_rd_wr (col_rd_wr),
+ .col_size (col_size),
+ .col_row (col_row[ROW_WIDTH-1:0]),
+ .col_data_buf_addr (col_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]),
+ .col_wr_data_buf_addr (col_wr_data_buf_addr[DATA_BUF_ADDR_WIDTH-1:0]),
+ .mc_bank (mc_bank),
+ .mc_address (mc_address),
+ .mc_ras_n (mc_ras_n),
+ .mc_cas_n (mc_cas_n),
+ .mc_we_n (mc_we_n),
+ .mc_cs_n (mc_cs_n),
+ .mc_odt (mc_odt),
+ .mc_cke (mc_cke),
+ .mc_aux_out0 (mc_aux_out0),
+ .mc_aux_out1 (mc_aux_out1),
+ .mc_cmd (mc_cmd),
+ .mc_data_offset (mc_data_offset),
+ .mc_data_offset_1 (mc_data_offset_1),
+ .mc_data_offset_2 (mc_data_offset_2),
+ .mc_cas_slot (mc_cas_slot),
+ .col_channel_offset (col_channel_offset),
+ .rnk_config (rnk_config),
+ // Inputs
+ .clk (clk),
+ .rst (rst),
+ .init_calib_complete (init_calib_complete),
+ .calib_rddata_offset (calib_rddata_offset),
+ .calib_rddata_offset_1 (calib_rddata_offset_1),
+ .calib_rddata_offset_2 (calib_rddata_offset_2),
+ .req_rank_r (req_rank_r[RANK_VECT_INDX:0]),
+ .req_bank_r (req_bank_r[BANK_VECT_INDX:0]),
+ .req_ras (req_ras[nBANK_MACHS-1:0]),
+ .req_cas (req_cas[nBANK_MACHS-1:0]),
+ .req_wr_r (req_wr_r[nBANK_MACHS-1:0]),
+ .grant_row_r (grant_row_r[nBANK_MACHS-1:0]),
+ .grant_pre_r (grant_pre_r[nBANK_MACHS-1:0]),
+ .row_addr (row_addr[ROW_VECT_INDX:0]),
+ .row_cmd_wr (row_cmd_wr[nBANK_MACHS-1:0]),
+ .insert_maint_r1 (insert_maint_r1),
+ .maint_zq_r (maint_zq_r),
+ .maint_sre_r (maint_sre_r),
+ .maint_srx_r (maint_srx_r),
+ .maint_rank_r (maint_rank_r[RANK_WIDTH-1:0]),
+ .req_periodic_rd_r (req_periodic_rd_r[nBANK_MACHS-1:0]),
+ .req_size_r (req_size_r[nBANK_MACHS-1:0]),
+ .rd_wr_r (rd_wr_r[nBANK_MACHS-1:0]),
+ .req_row_r (req_row_r[ROW_VECT_INDX:0]),
+ .col_addr (col_addr[ROW_VECT_INDX:0]),
+ .req_data_buf_addr_r (req_data_buf_addr_r[DATA_BUF_ADDR_VECT_INDX:0]),
+ .grant_col_r (grant_col_r[nBANK_MACHS-1:0]),
+ .grant_col_wr (grant_col_wr[nBANK_MACHS-1:0]),
+ .send_cmd0_row (send_cmd0_row),
+ .send_cmd0_col (send_cmd0_col),
+ .send_cmd1_row (send_cmd1_row),
+ .send_cmd1_col (send_cmd1_col),
+ .send_cmd2_row (send_cmd2_row),
+ .send_cmd2_col (send_cmd2_col),
+ .send_cmd2_pre (send_cmd2_pre),
+ .send_cmd3_col (send_cmd3_col),
+ .sent_col (EVEN_CWL_2T_MODE == ""ON"" ? sent_col_r : sent_col),
+ .cs_en0 (cs_en0),
+ .cs_en1 (cs_en1),
+ .cs_en2 (cs_en2),
+ .cs_en3 (cs_en3),
+ .grant_config_r (grant_config_r[nBANK_MACHS-1:0]),
+ .rnk_config_strobe (rnk_config_strobe),
+ .slot_0_present (slot_0_present[7:0]),
+ .slot_1_present (slot_1_present[7:0]));
+
+endmodule
+"
+"
+//-----------------------------------------------------------------------------
+//
+// (c) Copyright 2009-2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//-----------------------------------------------------------------------------
+// Project : Virtex-6 Integrated Block for PCI Express
+// File : gtx_rx_valid_filter_v6.v
+// Version : 2.4
+
+`timescale 1ns / 1ns
+
+module GTX_RX_VALID_FILTER_V6 #(
+
+ parameter CLK_COR_MIN_LAT = 28,
+ parameter TCQ = 1
+
+)
+(
+ output [1:0] USER_RXCHARISK,
+ output [15:0] USER_RXDATA,
+ output USER_RXVALID,
+ output USER_RXELECIDLE,
+ output [ 2:0] USER_RX_STATUS,
+ output USER_RX_PHY_STATUS,
+
+ input [1:0] GT_RXCHARISK,
+ input [15:0] GT_RXDATA,
+ input GT_RXVALID,
+ input GT_RXELECIDLE,
+ input [ 2:0] GT_RX_STATUS,
+ input GT_RX_PHY_STATUS,
+
+ input PLM_IN_L0,
+ input PLM_IN_RS,
+
+ input USER_CLK,
+ input RESET
+
+);
+
+
+
+ localparam EIOS_DET_IDL = 5\'b00001;
+ localparam EIOS_DET_NO_STR0 = 5\'b00010;
+ localparam EIOS_DET_STR0 = 5\'b00100;
+ localparam EIOS_DET_STR1 = 5\'b01000;
+ localparam EIOS_DET_DONE = 5\'b10000;
+
+ localparam EIOS_COM = 8\'hBC;
+ localparam EIOS_IDL = 8\'h7C;
+ localparam FTSOS_COM = 8\'hBC;
+ localparam FTSOS_FTS = 8\'h3C;
+
+ reg [4:0] reg_state_eios_det;
+ wire [4:0] state_eios_det;
+
+ reg reg_eios_detected;
+ wire eios_detected;
+
+ reg reg_symbol_after_eios;
+ wire symbol_after_eios;
+
+ localparam USER_RXVLD_IDL = 4\'b0001;
+ localparam USER_RXVLD_EI = 4\'b0010;
+ localparam USER_RXVLD_EI_DB0 = 4\'b0100;
+ localparam USER_RXVLD_EI_DB1 = 4\'b1000;
+
+ reg [3:0] reg_state_rxvld_ei;
+ wire [3:0] state_rxvld_ei;
+
+ reg [4:0] reg_rxvld_count;
+ wire [4:0] rxvld_count;
+
+ reg [3:0] reg_rxvld_fallback;
+ wire [3:0] rxvld_fallback;
+
+ reg [1:0] gt_rxcharisk_q;
+ reg [15:0] gt_rxdata_q;
+ reg gt_rxvalid_q;
+ reg gt_rxelecidle_q;
+ reg gt_rxelecidle_qq;
+
+ reg [ 2:0] gt_rx_status_q;
+ reg gt_rx_phy_status_q;
+ reg gt_rx_is_skp0_q;
+ reg gt_rx_is_skp1_q;
+
+ // EIOS detector
+
+ always @(posedge USER_CLK) begin
+
+ if (RESET) begin
+
+ reg_eios_detected <= #TCQ 1\'b0;
+ reg_state_eios_det <= #TCQ EIOS_DET_IDL;
+ reg_symbol_after_eios <= #TCQ 1\'b0;
+ gt_rxcharisk_q <= #TCQ 2\'b00;
+ gt_rxdata_q <= #TCQ 16\'h0;
+ gt_rxvalid_q <= #TCQ 1\'b0;
+ gt_rxelecidle_q <= #TCQ 1\'b0;
+ gt_rxelecidle_qq <= #TCQ 1\'b0;
+ gt_rx_status_q <= #TCQ 3\'b000;
+ gt_rx_phy_status_q <= #TCQ 1\'b0;
+ gt_rx_is_skp0_q <= #TCQ 1\'b0;
+ gt_rx_is_skp1_q <= #TCQ 1\'b0;
+
+ end else begin
+
+ reg_eios_detected <= #TCQ 1\'b0;
+ reg_symbol_after_eios <= #TCQ 1\'b0;
+ gt_rxcharisk_q <= #TCQ GT_RXCHARISK;
+ gt_rxdata_q <= #TCQ GT_RXDATA;
+ gt_rxvalid_q <= #TCQ GT_RXVALID;
+ gt_rxelecidle_q <= #TCQ GT_RXELECIDLE;
+ gt_rxelecidle_qq <= #TCQ gt_rxelecidle_q;
+ gt_rx_status_q <= #TCQ GT_RX_STATUS;
+ gt_rx_phy_status_q <= #TCQ GT_RX_PHY_STATUS;
+
+ if (GT_RXCHARISK[0] && GT_RXDATA[7:0] == FTSOS_FTS)
+ gt_rx_is_skp0_q <= #TCQ 1\'b1;
+ else
+ gt_rx_is_skp0_q <= #TCQ 1\'b0;
+
+ if (GT_RXCHARISK[1] && GT_RXDATA[15:8] == FTSOS_FTS)
+ gt_rx_is_skp1_q <= #TCQ 1\'b1;
+ else
+ gt_rx_is_skp1_q <= #TCQ 1\'b0;
+
+ case ( state_eios_det )
+
+ EIOS_DET_IDL : begin
+
+ if ((gt_rxcharisk_q[0]) && (gt_rxdata_q[7:0] == EIOS_COM) &&
+ (gt_rxcharisk_q[1]) && (gt_rxdata_q[15:8] == EIOS_IDL)) begin
+
+ reg_state_eios_det <= #TCQ EIOS_DET_NO_STR0;
+ reg_eios_detected <= #TCQ 1\'b1;
+
+ end else if ((gt_rxcharisk_q[1]) && (gt_rxdata_q[15:8] == EIOS_COM))
+ reg_state_eios_det <= #TCQ EIOS_DET_STR0;
+ else
+ reg_state_eios_det <= #TCQ EIOS_DET_IDL;
+
+ end
+
+ EIOS_DET_NO_STR0 : begin
+
+ if ((gt_rxcharisk_q[0] && (gt_rxdata_q[7:0] == EIOS_IDL)) &&
+ (gt_rxcharisk_q[1] && (gt_rxdata_q[15:8] == EIOS_IDL)))
+ reg_state_eios_det <= #TCQ EIOS_DET_DONE;
+ else
+ reg_state_eios_det <= #TCQ EIOS_DET_IDL;
+
+ end
+
+ EIOS_DET_STR0 : begin
+
+ if ((gt_rxcharisk_q[0] && (gt_rxdata_q[7:0] == EIOS_IDL)) &&
+ (gt_rxcharisk_q[1] && (gt_rxdata_q[15:8] == EIOS_IDL))) begin
+
+ reg_state_eios_det <= #TCQ EIOS_DET_STR1;
+ reg_eios_detected <= #TCQ 1\'b1;
+ reg_symbol_after_eios <= #TCQ 1\'b1;
+
+ end else
+ reg_state_eios_det <= #TCQ EIOS_DET_IDL;
+
+ end
+
+ EIOS_DET_STR1 : begin
+
+ if ((gt_rxcharisk_q[0]) && (gt_rxdata_q[7:0] == EIOS_IDL))
+ reg_state_eios_det <= #TCQ EIOS_DET_DONE;
+ else
+ reg_state_eios_det <= #TCQ EIOS_DET_IDL;
+
+ end
+
+ EIOS_DET_DONE : begin
+
+ reg_state_eios_det <= #TCQ EIOS_DET_IDL;
+
+ end
+
+ endcase
+
+ end
+
+ end
+ assign state_eios_det = reg_state_eios_det;
+ assign eios_detected = reg_eios_detected;
+ assign symbol_after_eios = reg_symbol_after_eios;
+
+ // user_rxvalid generation
+
+ always @(posedge USER_CLK) begin
+
+ if (RESET) begin
+
+ reg_state_rxvld_ei <= #TCQ USER_RXVLD_IDL;
+
+ end else begin
+
+ case ( state_rxvld_ei )
+
+ USER_RXVLD_IDL : begin
+
+ if (eios_detected)
+ reg_state_rxvld_ei <= #TCQ USER_RXVLD_EI;
+ else
+ reg_state_rxvld_ei <= #TCQ USER_RXVLD_IDL;
+
+ end
+
+ USER_RXVLD_EI : begin
+
+ if (!gt_rxvalid_q)
+ reg_state_rxvld_ei <= #TCQ USER_RXVLD_EI_DB0;
+ else if (rxvld_fallback == 4\'b1111)
+ reg_state_rxvld_ei <= #TCQ USER_RXVLD_IDL;
+ else
+ reg_state_rxvld_ei <= #TCQ USER_RXVLD_EI;
+
+ end
+
+ USER_RXVLD_EI_DB0 : begin
+
+ if (gt_rxvalid_q)
+ reg_state_rxvld_ei <= #TCQ USER_RXVLD_EI_DB1;
+ else if (!PLM_IN_L0)
+ reg_state_rxvld_ei <= #TCQ USER_RXVLD_IDL;
+ else
+ reg_state_rxvld_ei <= #TCQ USER_RXVLD_EI_DB0;
+
+ end
+
+ USER_RXVLD_EI_DB1 : begin
+
+ if (rxvld_count > CLK_COR_MIN_LAT)
+ reg_state_rxvld_ei <= #TCQ USER_RXVLD_IDL;
+ else
+ reg_state_rxvld_ei <= #TCQ USER_RXVLD_EI_DB1;
+
+ end
+
+ endcase
+
+ end
+
+ end
+ assign state_rxvld_ei = reg_state_rxvld_ei;
+
+ // RxValid counter
+
+ always @(posedge USER_CLK) begin
+
+ if (RESET) begin
+
+ reg_rxvld_count <= #TCQ 5\'b00000;
+
+ end else begin
+
+ if ((gt_rxvalid_q) && (state_rxvld_ei == USER_RXVLD_EI_DB1))
+ reg_rxvld_count <= #TCQ reg_rxvld_count + 1\'b1;
+ else
+ reg_rxvld_count <= #TCQ 5\'b00000;
+
+ end
+
+ end
+ assign rxvld_count = reg_rxvld_count;
+
+ // RxValid fallback
+
+ always @(posedge USER_CLK) begin
+
+ if (RESET) begin
+
+ reg_rxvld_fallback <= #TCQ 4\'b0000;
+
+ end else begin
+
+ if (state_rxvld_ei == USER_RXVLD_EI)
+ reg_rxvld_fallback <= #TCQ reg_rxvld_fallback + 1\'b1;
+ else
+ reg_rxvld_fallback <= #TCQ 4\'b0000;
+
+ end
+
+ end
+ assign rxvld_fallback = reg_rxvld_fallback;
+
+ // Delay pipe_rx_elec_idle
+
+ SRL16E #(.INIT(0)) rx_elec_idle_delay (.Q(USER_RXELECIDLE),
+ .D(gt_rxelecidle_q),
+ .CLK(USER_CLK),
+ .CE(1\'b1), .A3(1\'b1),.A2(1\'b1),.A1(1\'b1),.A0(1\'b1));
+
+
+reg awake_in_progress_q = 1\'b0;
+reg awake_see_com_q = 1\'b0;
+reg [3:0] awake_com_count_q = 4\'b0000;
+
+wire awake_see_com_0 = gt_rxvalid_q & (gt_rxcharisk_q[0] && (gt_rxdata_q[7:0] == EIOS_COM));
+wire awake_see_com_1 = gt_rxvalid_q & (gt_rxcharisk_q[1] && (gt_rxdata_q[15:8] == EIOS_COM));
+wire awake_see_com = (awake_see_com_0 || awake_see_com_1) && ~awake_see_com_q;
+
+// Count 8 COMs, (not back-to-back), when waking up from electrical idle
+// but not for L0s (which is L0).
+
+wire awake_done = awake_in_progress_q && (awake_com_count_q[3:0] >= 4\'hb);
+wire awake_start = (~gt_rxelecidle_q && gt_rxelecidle_qq) || PLM_IN_RS;
+
+wire awake_in_progress = awake_start || (~awake_done && awake_in_progress_q);
+wire [3:0] awake_com_count_inced = awake_com_count_q[3:0] + 4\'b0001;
+wire [3:0] awake_com_count = (~awake_in_progress_q) ? 4\'b0000 :
+ (awake_start) ? 4\'b0000 :
+ (awake_see_com_q) ? awake_com_count_inced[3:0] :
+ awake_com_count_q[3:0];
+
+wire rst_l = ~RESET;
+always @(posedge USER_CLK) begin
+ awake_see_com_q <= #TCQ (rst_l) ? awake_see_com : 1\'b0;
+ awake_in_progress_q <= #TCQ (rst_l) ? awake_in_progress : 1\'b0;
+ awake_com_count_q[3:0] <= #TCQ (rst_l) ? awake_com_count[3:0] : 4\'h0;
+end
+
+
+ assign USER_RXVALID = ((state_rxvld_ei == USER_RXVLD_IDL) && ~awake_in_progress_q) ? gt_rxvalid_q : 1\'b0;
+ assign USER_RXCHARISK[0] = USER_RXVALID ? gt_rxcharisk_q[0] : 1\'b0;
+ assign USER_RXCHARISK[1] = (USER_RXVALID && !symbol_after_eios) ? gt_rxcharisk_q[1] : 1\'b0;
+ assign USER_RXDATA[7:0] = (gt_rx_is_skp0_q) ? FTSOS_COM : gt_rxdata_q[7:0];
+ assign USER_RXDATA[15:8] = (gt_rx_is_skp1_q) ? FTSOS_COM : gt_rxdata_q[15:8];
+ assign USER_RX_STATUS = (state_rxvld_ei == USER_RXVLD_IDL) ? gt_rx_status_q : 3\'b000;
+ assign USER_RX_PHY_STATUS = gt_rx_phy_status_q;
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2009 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor: Xilinx
+// \\ \\ \\/ Version: 3.91
+// \\ \\ Application: MIG
+// / / Filename: phy_control_io.v
+// /___/ /\\ Date Last Modified: $Date: 2011/06/02 07:18:02 $
+// \\ \\ / \\ Date Created: Mon Jun 23 2008
+// \\___\\/\\___\\
+//
+//Device: Virtex-6
+//Design Name: DDR3 SDRAM
+//Purpose:
+// Instantiates IOB blocks for output-only control/address signals to DRAM
+//Reference:
+//Revision History:
+//*****************************************************************************
+
+/******************************************************************************
+**$Id: phy_control_io.v,v 1.1 2011/06/02 07:18:02 mishra Exp $
+**$Date: 2011/06/02 07:18:02 $
+**$Author: mishra $
+**$Revision: 1.1 $
+**$Source: /devl/xcs/repo/env/Databases/ip/src2/O/mig_v3_9/data/dlib/virtex6/ddr3_sdram/verilog/rtl/phy/phy_control_io.v,v $
+******************************************************************************/
+
+`timescale 1ps/1ps
+
+
+module phy_control_io #
+ (
+ parameter TCQ = 100, // clk->out delay (sim only)
+ parameter BANK_WIDTH = 2, // # of bank bits
+ parameter RANK_WIDTH = 1, // log2(CS_WIDTH)
+ parameter nCS_PER_RANK = 1, // # of unique CS outputs per rank
+ parameter CS_WIDTH = 1, // # of DRAM ranks
+ parameter CKE_WIDTH = 1, // # of cke outputs
+ parameter ROW_WIDTH = 14, // DRAM address bus width
+ parameter WRLVL = ""OFF"", // Enable write leveling
+ parameter nCWL = 5, // Write Latency
+ parameter DRAM_TYPE = ""DDR3"", // Memory I/F type: ""DDR3"", ""DDR2""
+ parameter REG_CTRL = ""ON"", // ""ON"" for registered DIMM
+ parameter REFCLK_FREQ = 300.0, // IODELAY Reference Clock freq (MHz)
+ parameter IODELAY_HP_MODE = ""ON"", // IODELAY High Performance Mode
+ parameter IODELAY_GRP = ""IODELAY_MIG"", // May be assigned unique name
+ // when mult IP cores in design
+ parameter DDR2_EARLY_CS = 0 // set = 1 for >200 MHz DDR2 UDIMM designs
+\t\t\t // for early launch of CS
+ )
+ (
+ input clk_mem, // full rate core clock
+ input clk, // half rate core clock
+ input rst, // half rate core clk reset
+ input mc_data_sel, // =1 for MC control, =0 for PHY
+ // DFI address/control
+ input [ROW_WIDTH-1:0] dfi_address0,
+ input [ROW_WIDTH-1:0] dfi_address1,
+ input [BANK_WIDTH-1:0] dfi_bank0,
+ input [BANK_WIDTH-1:0] dfi_bank1,
+ input dfi_cas_n0,
+ input dfi_cas_n1,
+ input [CKE_WIDTH-1:0] dfi_cke0,
+ input [CKE_WIDTH-1:0] dfi_cke1,
+ input [CS_WIDTH*nCS_PER_RANK-1:0] dfi_cs_n0,
+ input [CS_WIDTH*nCS_PER_RANK-1:0] dfi_cs_n1,
+ input [CS_WIDTH*nCS_PER_RANK-1:0] dfi_odt0,
+ input [CS_WIDTH*nCS_PER_RANK-1:0] dfi_odt1,
+ input dfi_ras_n0,
+ input dfi_ras_n1,
+ input dfi_reset_n,
+ input dfi_we_n0,
+ input dfi_we_n1,
+ // PHY address/control
+ input [ROW_WIDTH-1:0] phy_address0,
+ input [ROW_WIDTH-1:0] phy_address1,
+ input [BANK_WIDTH-1:0] phy_bank0,
+ input [BANK_WIDTH-1:0] phy_bank1,
+ input phy_cas_n0,
+ input phy_cas_n1,
+ input [CKE_WIDTH-1:0] phy_cke0,
+ input [CKE_WIDTH-1:0] phy_cke1,
+ input [CS_WIDTH*nCS_PER_RANK-1:0] phy_cs_n0,
+ input [CS_WIDTH*nCS_PER_RANK-1:0] phy_cs_n1,
+ input [CS_WIDTH*nCS_PER_RANK-1:0] phy_odt0,
+ input [CS_WIDTH*nCS_PER_RANK-1:0] phy_odt1,
+ input phy_ras_n0,
+ input phy_ras_n1,
+ input phy_reset_n,
+ input phy_we_n0,
+ input phy_we_n1,
+ // DDR3-side address/control
+ output [ROW_WIDTH-1:0] ddr_addr,
+ output [BANK_WIDTH-1:0] ddr_ba,
+ output ddr_ras_n,
+ output ddr_cas_n,
+ output ddr_we_n,
+ output [CKE_WIDTH-1:0] ddr_cke,
+ output [CS_WIDTH*nCS_PER_RANK-1:0] ddr_cs_n,
+ output [CS_WIDTH*nCS_PER_RANK-1:0] ddr_odt,
+ output ddr_parity,
+ output ddr_reset_n
+ );
+
+ // Set performance mode for IODELAY (power vs. performance tradeoff)
+ // COMMENTED, 022009, RICHC. This is temporary pending IR 509123
+ localparam HIGH_PERFORMANCE_MODE
+ = (IODELAY_HP_MODE == ""OFF"") ? ""FALSE"" :
+ ((IODELAY_HP_MODE == ""ON"") ? ""TRUE"" : ""ILLEGAL"");
+
+ // local parameter for the single rank DDR3 dimm case. This parameter will be
+ // set when the number of chip selects is == 2 for a single rank registered
+ // dimm.
+ localparam SINGLE_RANK_CS_REG
+ = ((REG_CTRL == ""ON"") && (DRAM_TYPE == ""DDR3"")
+ && (CS_WIDTH == 1) && (nCS_PER_RANK == 2));
+
+ wire [ROW_WIDTH-1:0] mux_addr0;
+ wire [ROW_WIDTH-1:0] mux_addr1;
+ wire [BANK_WIDTH-1:0] mux_ba0;
+ wire [BANK_WIDTH-1:0] mux_ba1;
+ wire mux_cas_n0;
+ wire mux_cas_n1;
+ wire [CKE_WIDTH-1:0] mux_cke0;
+ wire [CKE_WIDTH-1:0] mux_cke1;
+ reg [CS_WIDTH*nCS_PER_RANK-1:0] mux_cs_n0;
+ reg [CS_WIDTH*nCS_PER_RANK-1:0] mux_cs_n1;
+ reg [CS_WIDTH*nCS_PER_RANK-1:0] mux_cs_d1;
+ reg [CS_WIDTH*nCS_PER_RANK-1:0] mux_cs_d2;
+ reg [CS_WIDTH*nCS_PER_RANK-1:0] mux_cs_d3;
+ reg [CS_WIDTH*nCS_PER_RANK-1:0] mux_cs_d4;
+ reg [0:0] mux_ioconfig;
+ reg mux_ioconfig_en;
+ wire [CS_WIDTH*nCS_PER_RANK-1:0] mux_odt0;
+ wire [CS_WIDTH*nCS_PER_RANK-1:0] mux_odt1;
+ wire mux_ras_n0;
+ wire mux_ras_n1;
+ wire mux_reset_n;
+ wire mux_we_n0;
+ wire mux_we_n1;
+ wire oce_temp;
+ reg parity0;
+ reg parity1;
+ reg [3:0] rst_delayed;
+
+ wire [ROW_WIDTH-1:0] addr_odelay;
+ wire [ROW_WIDTH-1:0] addr_oq;
+ wire [BANK_WIDTH-1:0] ba_odelay;
+ wire [BANK_WIDTH-1:0] ba_oq;
+ wire cas_n_odelay;
+ wire cas_n_oq;
+ wire [CKE_WIDTH-1:0] cke_odelay;
+ wire [CKE_WIDTH-1:0] cke_oq;
+ wire [CS_WIDTH*nCS_PER_RANK-1:0] cs_n_odelay;
+ wire [CS_WIDTH*nCS_PER_RANK-1:0] cs_n_oq;
+ wire [CS_WIDTH*nCS_PER_RANK-1:0] odt_odelay;
+ wire [CS_WIDTH*nCS_PER_RANK-1:0] odt_oq;
+ wire parity_odelay;
+ wire parity_oq;
+ wire ras_n_odelay;
+ wire ras_n_oq;
+ wire rst_cke_odt;
+ reg rst_r;
+ reg oce_hack_r;
+ reg oce_hack_r1;
+ reg oce_hack_r2;
+ reg oce_hack_r3;
+ reg oce_hack_r4;
+ reg oce_hack_r5
+ /* synthesis syn_keep = 1 */;
+ wire we_n_odelay;
+ wire we_n_oq;
+
+ // XST attributes for local reset tree RST_R - prohibit equivalent
+ // register removal on RST_R to prevent ""sharing"" w/ other local reset trees
+ // synthesis attribute shreg_extract of rst_r is ""no"";
+ // synthesis attribute equivalent_register_removal of rst_r is ""no""
+
+ //***************************************************************************
+ // Reset pipelining - register reset signals to prevent large (and long)
+ // fanouts during physical compilation of the design. Create one local reset
+ // for most control/address OSERDES blocks - note that user may need to
+ // change this if control/address are more ""spread out"" through FPGA
+ //***************************************************************************
+
+ always @(posedge clk)
+ rst_r <= #TCQ rst;
+
+ //***************************************************************************
+ // Generate delayed version of global reset.
+ //***************************************************************************
+
+ always @(posedge clk) begin
+ rst_delayed[0] <= #TCQ rst;
+ rst_delayed[1] <= #TCQ rst_delayed[0];
+ rst_delayed[2] <= #TCQ rst_delayed[1];
+ rst_delayed[3] <= #TCQ rst_delayed[2];
+ end
+
+ // Drive ODT and CKE OSERDES with these resets in order to ensure that
+ // they remain low until after DDR_RESET_N is deasserted. This is done for
+ // simulation reasons only, as some memory models will issue an error if
+ // ODT/CKE are asserted prior to deassertion of RESET_N
+ assign rst_cke_odt = rst_delayed[3];
+
+ //***************************************************************************
+
+ // The following logic is only required to support DDR2 simulation, and is
+ // done to prevent glitching on the ODT and CKE signals after ""power-up"".
+ // Certain models will flag glitches on these lines as errors.
+ // To fix this, the OCE for OSERDES is used to prevent glitches. However,
+ // this may lead to setup time issues when running this design through
+ // ISE - because the OCE setup is w/r/t to CLK (i.e. the ""fast"" clock).
+ // It can be problematic to meet timing - therefore this path should be
+ // marked as a false path (TIG) because it will be asserted long before
+ // the OSERDES outputs need to be valid. This logic is disabled for the
+ // DDR3 case because it is not required
+ // LOGIC DESCRIPTION:
+ // Generating OCE for DDR2 ODT & CKE. The output of the OSERDES model toggles
+ // when it comes out of reset. This causes issues in simulation. Controlling
+ // it OCE until there is a library fix. OCE will be asserted after 10 clks
+ // after reset de-assertion
+
+ always @(posedge clk) begin
+ oce_hack_r <= #TCQ ~rst_delayed[3];
+ oce_hack_r1 <= #TCQ oce_hack_r;
+ oce_hack_r2 <= #TCQ oce_hack_r1;
+ oce_hack_r3 <= #TCQ oce_hack_r2;
+ oce_hack_r4 <= #TCQ oce_hack_r3;
+ oce_hack_r5 <= #TCQ oce_hack_r4;
+ end
+
+ // Only use for DDR2. For DDR3, drive to constant high
+ assign oce_temp = (DRAM_TYPE == ""DDR2"") ? oce_hack_r5 : 1\'b1;
+
+ //***************************************************************************
+ // MUX to choose from either PHY or controller for DRAM control
+ // NOTE: May need to add pipeline register to meet timing
+ //***************************************************************************
+
+ assign mux_addr0 = (mc_data_sel) ? dfi_address0 : phy_address0;
+ assign mux_addr1 = (mc_data_sel) ? dfi_address1 : phy_address1;
+ assign mux_ba0 = (mc_data_sel) ? dfi_bank0 : phy_bank0;
+ assign mux_ba1 = (mc_data_sel) ? dfi_bank1 : phy_bank1;
+ assign mux_cas_n0 = (mc_data_sel) ? dfi_cas_n0 : phy_cas_n0;
+ assign mux_cas_n1 = (mc_data_sel) ? dfi_cas_n1 : phy_cas_n1;
+ assign mux_cke0 = (mc_data_sel) ? dfi_cke0 : phy_cke0;
+ assign mux_cke1 = (mc_data_sel) ? dfi_cke1 : phy_cke1;
+ assign mux_odt0 = (mc_data_sel) ? dfi_odt0 : phy_odt0;
+ assign mux_odt1 = (mc_data_sel) ? dfi_odt1 : phy_odt1;
+ assign mux_ras_n0 = (mc_data_sel) ? dfi_ras_n0 : phy_ras_n0;
+ assign mux_ras_n1 = (mc_data_sel) ? dfi_ras_n1 : phy_ras_n1;
+ assign mux_reset_n= (mc_data_sel) ? dfi_reset_n : phy_reset_n;
+ assign mux_we_n0 = (mc_data_sel) ? dfi_we_n0 : phy_we_n0;
+ assign mux_we_n1 = (mc_data_sel) ? dfi_we_n1 : phy_we_n1;
+
+ //***************************************************************************
+ // assigning chip select values.
+ // For DDR3 Registered dimm\'s the chip select pins are toggled in a unique
+ // way to differentiate between register programming and regular DIMM access.
+ // For a single rank registered dimm with two chip selects the chip select
+ // will be toggled in the following manner:
+ // cs[0] =0, cs[1] = 0 the access is to the registered chip. On the
+ // remaining combinations the access is to the DIMM. The SINGLE_RANK_CS_REG
+ // parameter will be set for the above configurations and the chip select
+ // pins will be toggled as per the DDR3 registered DIMM requirements. The
+ // phy takes care of the register programming, and handles the chip
+ // select\'s correctly for calibration and initialization. But the controller
+ // does not know about this mode, the controller cs[1] bits will be tied to
+ // 1\'b1; All the controller access will be to the DIMM and none to the
+ // register chip. Rest of the DDR3 register dimm configurations are
+ // handled well by the controller.
+ //***************************************************************************
+
+ generate
+ if (SINGLE_RANK_CS_REG) begin: gen_single_rank
+ always @(mc_data_sel or dfi_cs_n0[0] or dfi_cs_n1[0] or
+ phy_cs_n0[0] or phy_cs_n1[0] or
+ phy_cs_n0[1] or phy_cs_n1[1])begin
+ if (mc_data_sel) begin
+ mux_cs_n0[0] = dfi_cs_n0[0];
+ mux_cs_n1[0] = dfi_cs_n1[0];
+ mux_cs_n0[1] = 1\'b1;
+ mux_cs_n1[1] = 1\'b1;
+ end else begin
+ mux_cs_n0[0] = phy_cs_n0[0];
+ mux_cs_n1[0] = phy_cs_n1[0];
+ mux_cs_n0[1] = phy_cs_n0[1];
+ mux_cs_n1[1] = phy_cs_n1[1];
+ end
+ end
+ end else begin: gen_mult_rank
+ always @(mc_data_sel or dfi_cs_n0 or dfi_cs_n1 or
+ phy_cs_n0 or phy_cs_n1) begin
+ if (mc_data_sel)begin
+ mux_cs_n0 = dfi_cs_n0;
+ mux_cs_n1 = dfi_cs_n1;
+ end else begin
+ mux_cs_n0 = phy_cs_n0;
+ mux_cs_n1 = phy_cs_n1;
+ end
+ end
+ end
+ endgenerate
+
+ // for DDR2 UDIMM designs the CS has to be launched early.
+ // Setting the OSERDES input based on the DDR2_EARLY_CS parameter.
+ // when this paramter is CS will be launched half a cycle early.
+ // Launching half a cycle early will cause simulation issues.
+ // Using synthesis options to control the assignment
+
+ always @(mux_cs_n0 or mux_cs_n1) begin
+ if(DDR2_EARLY_CS == 1) begin
+ mux_cs_d1 = mux_cs_n0;
+ mux_cs_d2 = mux_cs_n1;
+ mux_cs_d3 = mux_cs_n1;
+ mux_cs_d4 = mux_cs_n0;
+ end else begin
+ mux_cs_d1 = mux_cs_n0;
+ mux_cs_d2 = mux_cs_n0;
+ mux_cs_d3 = mux_cs_n1;
+ mux_cs_d4 = mux_cs_n1;
+ end // else: !if(DDR2_EARLY_CS == 1)
+
+ // For simulation override the assignment for
+ // synthesis do not override
+ // synthesis translate_off
+ mux_cs_d1 = mux_cs_n0;
+ mux_cs_d2 = mux_cs_n0;
+ mux_cs_d3 = mux_cs_n1;
+ mux_cs_d4 = mux_cs_n1;
+ // synthesis translate_on
+ end
+
+
+
+ // parity for reg dimm. Have to check the timing impact.
+ // Generate only for DDR3 RDIMM.
+ // registring with negedge. Half cycle path.
+ generate
+ if ((DRAM_TYPE == ""DDR3"") && (REG_CTRL == ""ON"")) begin: gen_ddr3_parity
+ always @(*) begin
+ parity0 = (^{mux_addr0, mux_ba0, mux_cas_n0,
+ mux_ras_n0, mux_we_n0});
+ end // always @ (*)
+ always @(posedge clk) begin
+ parity1 <= #TCQ(^{mux_addr1, mux_ba1, mux_cas_n1,
+ mux_ras_n1, mux_we_n1});
+ end
+ end else begin: gen_ddr3_noparity
+ always @(posedge clk) begin
+ parity0 <= #TCQ 1\'b0;
+ parity1 <= #TCQ 1\'b0;
+ end
+ end
+ endgenerate
+
+
+
+ //*****************************************************************
+ // DDR3 reset: Note that this output is generated with an ODDR clocked
+ // by the internal div-by-2 clock. It can be generated using the same
+ // OSERDES structure as for the other control/address signals. However
+ // there are no specific setup/hold requirements on reset_n w/r/t CK.
+ // In addition, this an ODDR was used to prevent any glitching on reset_n
+ // during startup. This was done for simulation considerations only -
+ // the glitch causes warnings with the Denali DDR3 model (but will not
+ // cause any issues in hardware).
+ //*****************************************************************
+
+ ODDR #
+ (
+ .DDR_CLK_EDGE (""SAME_EDGE""),
+ .INIT (1\'b0),
+ .SRTYPE (""ASYNC"")
+ )
+ u_out_reset_n
+ (
+ .Q (ddr_reset_n),
+ .C (clk),
+ .CE (1\'b1),
+ .D1 (mux_reset_n),
+ .D2 (mux_reset_n),
+ .R (rst_r),
+ .S (1\'b0)
+ );
+
+ //*****************************************************************
+ // Note on generation of Control/Address signals - there are
+ // several possible configurations that affect the configuration
+ // of the OSERDES and possible ODELAY for each output (this will
+ // also affect the CK/CK# outputs as well
+ // 1. DDR3, write-leveling: This is the simplest case. Use
+ // OSERDES without the ODELAY. Initially clock/control/address
+ // will be offset coming out of FPGA from DQ/DQS, but DQ/DQS
+ // will be adjusted so that DQS-CK alignment is established
+ // 2. DDR2 or DDR3 (no write-leveling): Both DQS and DQ will use
+ // ODELAY to delay output of OSERDES. To match this,
+ // CK/control/address must also delay their outputs using ODELAY
+ // (with delay = 0)
+ //*****************************************************************
+
+ //*****************************************************************
+ // RAS: = 1 at reset
+ //*****************************************************************
+
+ generate
+ if ((DRAM_TYPE == ""DDR3"") && (WRLVL == ""ON"")) begin: gen_ras_n_wrlvl
+
+ //*******************************************************
+ // CASE1: DDR3, write-leveling
+ //*******************************************************
+
+ assign ddr_ras_n = ras_n_oq;
+
+ end else begin: gen_ras_n_nowrlvl
+
+ //*******************************************************
+ // CASE2: DDR3, no write-leveling
+ //*******************************************************
+
+ assign ddr_ras_n = ras_n_odelay;
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (HIGH_PERFORMANCE_MODE),
+ .IDELAY_TYPE (""FIXED""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""FIXED""),
+ .ODELAY_VALUE (0),
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""DATA"")
+ )
+ u_iodelay_ras_n
+ (
+ .DATAOUT (ras_n_odelay),
+ .C (1\'b0),
+ .CE (1\'b0),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (1\'b0),
+ .ODATAIN (ras_n_oq),
+ .RST (1\'b0),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+ end
+ endgenerate
+
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b1), // 1 at reset
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""DEFAULT""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_out_ras_n
+ (
+ .OCBEXTEND (),
+ .OFB (),
+ .OQ (ras_n_oq),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (),
+ .CLKPERFDELAY (),
+ .D1 (mux_ras_n0),
+ .D2 (mux_ras_n0),
+ .D3 (mux_ras_n1),
+ .D4 (mux_ras_n1),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (1\'b1),
+ .SHIFTIN1 (),
+ .SHIFTIN2 (),
+ .RST (rst_r),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (1\'b0)
+ );
+
+ //*****************************************************************
+ // CAS: = 1 at reset
+ //*****************************************************************
+
+ generate
+ if ((DRAM_TYPE == ""DDR3"") && (WRLVL == ""ON"")) begin: gen_cas_n_wrlvl
+
+ assign ddr_cas_n = cas_n_oq;
+
+ end else begin: gen_cas_n_nowrlvl
+
+ assign ddr_cas_n = cas_n_odelay;
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (HIGH_PERFORMANCE_MODE),
+ .IDELAY_TYPE (""FIXED""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""FIXED""),
+ .ODELAY_VALUE (0),
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""DATA"")
+ )
+ u_iodelay_cas_n
+ (
+ .DATAOUT (cas_n_odelay),
+ .C (1\'b0),
+ .CE (1\'b0),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (1\'b0),
+ .ODATAIN (cas_n_oq),
+ .RST (1\'b0),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+ end
+ endgenerate
+
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b1), // 1 at reset
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""DEFAULT""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_out_cas_n
+ (
+ .OCBEXTEND (),
+ .OFB (),
+ .OQ (cas_n_oq),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (),
+ .CLKPERFDELAY (),
+ .D1 (mux_cas_n0),
+ .D2 (mux_cas_n0),
+ .D3 (mux_cas_n1),
+ .D4 (mux_cas_n1),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (1\'b1),
+ .SHIFTIN1 (),
+ .SHIFTIN2 (),
+ .RST (rst_r),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (1\'b0)
+ );
+
+ //*****************************************************************
+ // WE: = 1 at reset
+ //*****************************************************************
+
+ generate
+ if ((DRAM_TYPE == ""DDR3"") && (WRLVL == ""ON"")) begin: gen_we_n_wrlvl
+
+ assign ddr_we_n = we_n_oq;
+
+ end else begin: gen_we_n_nowrlvl
+
+ assign ddr_we_n = we_n_odelay;
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (HIGH_PERFORMANCE_MODE),
+ .IDELAY_TYPE (""FIXED""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""FIXED""),
+ .ODELAY_VALUE (0),
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""DATA"")
+ )
+ u_iodelay_we_n
+ (
+ .DATAOUT (we_n_odelay),
+ .C (1\'b0),
+ .CE (1\'b0),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (1\'b0),
+ .ODATAIN (we_n_oq),
+ .RST (1\'b0),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+ end
+ endgenerate
+
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b1), // 1 at reset
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""DEFAULT""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_out_we_n
+ (
+ .OCBEXTEND (),
+ .OFB (),
+ .OQ (we_n_oq),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (),
+ .CLKPERFDELAY (),
+ .D1 (mux_we_n0),
+ .D2 (mux_we_n0),
+ .D3 (mux_we_n1),
+ .D4 (mux_we_n1),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (1\'b1),
+ .SHIFTIN1 (),
+ .SHIFTIN2 (),
+ .RST (rst_r),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (1\'b0)
+ );
+
+ //*****************************************************************
+ // CKE: = 0 at reset
+ //*****************************************************************
+
+ generate
+ genvar cke_i;
+ for (cke_i = 0; cke_i < CKE_WIDTH; cke_i = cke_i + 1) begin: gen_cke
+
+ if ((DRAM_TYPE == ""DDR3"") && (WRLVL == ""ON"")) begin: gen_cke_wrlvl
+
+ assign ddr_cke[cke_i] = cke_oq[cke_i];
+
+ end else begin: gen_cke_nowrlvl
+
+ assign ddr_cke[cke_i] = cke_odelay[cke_i];
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (HIGH_PERFORMANCE_MODE),
+ .IDELAY_TYPE (""FIXED""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""FIXED""),
+ .ODELAY_VALUE (0),
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""DATA"")
+ )
+ u_iodelay_cke
+ (
+ .DATAOUT (cke_odelay[cke_i]),
+ .C (1\'b0),
+ .CE (1\'b0),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (1\'b0),
+ .ODATAIN (cke_oq[cke_i]),
+ .RST (1\'b0),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+ end
+
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b0), // 0 at reset
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""DEFAULT""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_out_cke
+ (
+ .OCBEXTEND (),
+ .OFB (),
+ .OQ (cke_oq[cke_i]),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (),
+ .CLKPERFDELAY (),
+ .D1 (mux_cke0[cke_i]),
+ .D2 (mux_cke0[cke_i]),
+ .D3 (mux_cke1[cke_i]),
+ .D4 (mux_cke1[cke_i]),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (oce_temp),
+ // Connect SHIFTIN1, SHIFTIN2 to 0 for simulation purposes
+ // (for all other OSERDES used in design, these are no-connects):
+ // ensures that CKE outputs are not X at start of simulation
+ // Certain DDR2 memory models may require that CK/CK# be valid
+ // throughout simulation
+ .SHIFTIN1 (1\'b0),
+ .SHIFTIN2 (1\'b0),
+ .RST (rst_cke_odt),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (1\'b0)
+ );
+
+ end
+ endgenerate
+
+ //*****************************************************************
+ // chip select = 1 at reset
+ //*****************************************************************
+
+ generate
+ genvar cs_i;
+ for (cs_i = 0; cs_i < CS_WIDTH*nCS_PER_RANK;
+ cs_i = cs_i + 1) begin: gen_cs_n
+
+ if ((DRAM_TYPE == ""DDR3"") && (WRLVL == ""ON"")) begin: gen_cs_n_wrlvl
+
+ assign ddr_cs_n[cs_i] = cs_n_oq[cs_i];
+
+ end else begin: gen_cs_n_nowrlvl
+
+ assign ddr_cs_n[cs_i] = cs_n_odelay[cs_i];
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (HIGH_PERFORMANCE_MODE),
+ .IDELAY_TYPE (""FIXED""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""FIXED""),
+ .ODELAY_VALUE (0),
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""DATA"")
+ )
+ u_iodelay_cs_n
+ (
+ .DATAOUT (cs_n_odelay[cs_i]),
+ .C (1\'b0),
+ .CE (1\'b0),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (1\'b0),
+ .ODATAIN (cs_n_oq[cs_i]),
+ .RST (1\'b0),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+ end
+
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b1), // 1 at reset
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""DEFAULT""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_out_cs_n
+ (
+ .OCBEXTEND (),
+ .OFB (),
+ .OQ (cs_n_oq[cs_i]),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (),
+ .CLKPERFDELAY (),
+ .D1 (mux_cs_d1[cs_i]),
+ .D2 (mux_cs_d2[cs_i]),
+ .D3 (mux_cs_d3[cs_i]),
+ .D4 (mux_cs_d4[cs_i]),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (1\'b1),
+ .SHIFTIN1 (),
+ .SHIFTIN2 (),
+ .RST (rst_r),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (1\'b0)
+ );
+ end
+ endgenerate
+
+ //*****************************************************************
+ // address: = X at reset
+ //*****************************************************************
+
+ generate
+ genvar addr_i;
+ for (addr_i = 0; addr_i < ROW_WIDTH; addr_i = addr_i + 1) begin: gen_addr
+
+ if ((DRAM_TYPE == ""DDR3"") && (WRLVL == ""ON"")) begin: gen_addr_wrlvl
+
+ assign ddr_addr[addr_i] = addr_oq[addr_i];
+
+ end else begin: gen_addr_nowrlvl
+
+ assign ddr_addr[addr_i] = addr_odelay[addr_i];
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (HIGH_PERFORMANCE_MODE),
+ .IDELAY_TYPE (""FIXED""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""FIXED""),
+ .ODELAY_VALUE (0),
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""DATA"")
+ )
+ u_iodelay_addr
+ (
+ .DATAOUT (addr_odelay[addr_i]),
+ .C (1\'b0),
+ .CE (1\'b0),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (1\'b0),
+ .ODATAIN (addr_oq[addr_i]),
+ .RST (1\'b0),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+ end
+
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b0), // 0 at reset
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""DEFAULT""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_out_addr
+ (
+ .OCBEXTEND (),
+ .OFB (),
+ .OQ (addr_oq[addr_i]),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (),
+ .CLKPERFDELAY (),
+ .D1 (mux_addr0[addr_i]),
+ .D2 (mux_addr0[addr_i]),
+ .D3 (mux_addr1[addr_i]),
+ .D4 (mux_addr1[addr_i]),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (1\'b1),
+ .SHIFTIN1 (),
+ .SHIFTIN2 (),
+ .RST (rst_r),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (1\'b0)
+ );
+ end
+ endgenerate
+
+ //*****************************************************************
+ // bank address = X at reset
+ //*****************************************************************
+
+ generate
+ genvar ba_i;
+ for (ba_i = 0; ba_i < BANK_WIDTH; ba_i = ba_i + 1) begin: gen_ba
+
+ if ((DRAM_TYPE == ""DDR3"") && (WRLVL == ""ON"")) begin: gen_ba_wrlvl
+
+ assign ddr_ba[ba_i] = ba_oq[ba_i];
+
+ end else begin: gen_ba_nowrlvl
+
+ assign ddr_ba[ba_i] = ba_odelay[ba_i];
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (HIGH_PERFORMANCE_MODE),
+ .IDELAY_TYPE (""FIXED""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""FIXED""),
+ .ODELAY_VALUE (0),
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""DATA"")
+ )
+ u_iodelay_ba
+ (
+ .DATAOUT (ba_odelay[ba_i]),
+ .C (1\'b0),
+ .CE (1\'b0),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (1\'b0),
+ .ODATAIN (ba_oq[ba_i]),
+ .RST (1\'b0),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+ end
+
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b0), // 0 at reset
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""DEFAULT""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_out_ba
+ (
+ .OCBEXTEND (),
+ .OFB (),
+ .OQ (ba_oq[ba_i]),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (),
+ .CLKPERFDELAY (),
+ .D1 (mux_ba0[ba_i]),
+ .D2 (mux_ba0[ba_i]),
+ .D3 (mux_ba1[ba_i]),
+ .D4 (mux_ba1[ba_i]),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (1\'b1),
+ .SHIFTIN1 (),
+ .SHIFTIN2 (),
+ .RST (rst_r),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (1\'b0)
+ );
+ end
+ endgenerate
+
+ //*****************************************************************
+ // ODT control = 0 at reset
+ //*****************************************************************
+
+ generate
+ genvar odt_i;
+ for (odt_i = 0; odt_i < CS_WIDTH*nCS_PER_RANK;
+ odt_i = odt_i + 1) begin: gen_odt
+
+ if ((DRAM_TYPE == ""DDR3"") && (WRLVL == ""ON"")) begin: gen_odt_wrlvl
+
+ assign ddr_odt[odt_i] = odt_oq[odt_i];
+
+ end else begin: gen_odt_nowrlvl
+
+ assign ddr_odt[odt_i] = odt_odelay[odt_i];
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (HIGH_PERFORMANCE_MODE),
+ .IDELAY_TYPE (""FIXED""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""FIXED""),
+ .ODELAY_VALUE (0),
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""DATA"")
+ )
+ u_iodelay_odt
+ (
+ .DATAOUT (odt_odelay[odt_i]),
+ .C (1\'b0),
+ .CE (1\'b0),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (1\'b0),
+ .ODATAIN (odt_oq[odt_i]),
+ .RST (1\'b0),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+ end
+
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b0), // 0 at reset
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""DEFAULT""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_out_odt
+ (
+ .OCBEXTEND (),
+ .OFB (),
+ .OQ (odt_oq[odt_i]),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (),
+ .CLKPERFDELAY (),
+ .D1 (mux_odt0[odt_i]),
+ .D2 (mux_odt0[odt_i]),
+ .D3 (mux_odt1[odt_i]),
+ .D4 (mux_odt1[odt_i]),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (oce_temp),
+ // Connect SHIFTIN1, SHIFTIN2 to 0 for simulation purposes
+ // (for all other OSERDES used in design, these are no-connects):
+ // ensures that ODT outputs are not X at start of simulation
+ // Certain DDR2 memory models may require that CK/CK# be valid
+ // throughout simulation
+ .SHIFTIN1 (1\'b0),
+ .SHIFTIN2 (1\'b0),
+ .RST (rst_cke_odt),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (1\'b0)
+ );
+ end
+ endgenerate
+
+ //*****************************************************************
+ // Parity for reg dimm. Parity output one cycle after the cs assertion
+ //*****************************************************************
+
+ generate
+ if ((DRAM_TYPE == ""DDR3"") && (WRLVL == ""ON"")) begin: gen_parity_wrlvl
+
+ assign ddr_parity = parity_oq;
+
+ end else begin: gen_parity_nowrlvl
+
+ assign ddr_parity = parity_odelay;
+
+ (* IODELAY_GROUP = IODELAY_GRP *) IODELAYE1 #
+ (
+ .CINVCTRL_SEL (""FALSE""),
+ .DELAY_SRC (""O""),
+ .HIGH_PERFORMANCE_MODE (HIGH_PERFORMANCE_MODE),
+ .IDELAY_TYPE (""FIXED""),
+ .IDELAY_VALUE (0),
+ .ODELAY_TYPE (""FIXED""),
+ .ODELAY_VALUE (0),
+ .REFCLK_FREQUENCY (REFCLK_FREQ),
+ .SIGNAL_PATTERN (""DATA"")
+ )
+ u_iodelay_parity
+ (
+ .DATAOUT (parity_odelay),
+ .C (1\'b0),
+ .CE (1\'b0),
+ .DATAIN (),
+ .IDATAIN (),
+ .INC (1\'b0),
+ .ODATAIN (parity_oq),
+ .RST (1\'b0),
+ .T (),
+ .CNTVALUEIN (),
+ .CNTVALUEOUT (),
+ .CLKIN (),
+ .CINVCTRL (1\'b0)
+ );
+ end
+ endgenerate
+
+ OSERDESE1 #
+ (
+ .DATA_RATE_OQ (""DDR""),
+ .DATA_RATE_TQ (""DDR""),
+ .DATA_WIDTH (4),
+ .DDR3_DATA (0),
+ .INIT_OQ (1\'b1), // 1 at reset
+ .INIT_TQ (1\'b0),
+ .INTERFACE_TYPE (""DEFAULT""),
+ .ODELAY_USED (0),
+ .SERDES_MODE (""MASTER""),
+ .SRVAL_OQ (1\'b0),
+ .SRVAL_TQ (1\'b0),
+ .TRISTATE_WIDTH (4)
+ )
+ u_out_parity
+ (
+ .OCBEXTEND (),
+ .OFB (),
+ .OQ (parity_oq),
+ .SHIFTOUT1 (),
+ .SHIFTOUT2 (),
+ .TQ (),
+ .CLK (clk_mem),
+ .CLKDIV (clk),
+ .CLKPERF (),
+ .CLKPERFDELAY (),
+ .D1 (parity1),
+ .D2 (parity1),
+ .D3 (parity0),
+ .D4 (parity0),
+ .D5 (),
+ .D6 (),
+ .ODV (1\'b0),
+ .OCE (1\'b1),
+ .SHIFTIN1 (),
+ .SHIFTIN2 (),
+ .RST (rst_r),
+ .T1 (1\'b0),
+ .T2 (1\'b0),
+ .T3 (1\'b0),
+ .T4 (1\'b0),
+ .TFB (),
+ .TCE (1\'b1),
+ .WC (1\'b0)
+ );
+
+'b'endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2008-2009 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : 3.91
+// \\ \\ Application : MIG
+// / / Filename : arb_row_col.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : Virtex-6
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+
+// This block receives request to send row and column commands and
+// requests to change the IO configuration. These requests come
+// the individual bank machines. The arbitration winner is selected
+// and driven back to the bank machines.
+//
+// The CS enables are generated. For 2:1 mode, row commands are sent
+// in the ""0"" phase, and column commands are sent in the ""1"" phase.
+//
+// In 2T mode, a further arbitration is performed between the row
+// and column commands. The winner of this arbitration inhibits
+// arbitration by the loser. The winner is allowed to arbitrate, the loser is
+// blocked until the next state. The winning address command
+// is repeated on both the ""0"" and the ""1"" phases and the CS
+// is asserted for just the ""1"" phase.
+
+`timescale 1 ps / 1 ps
+
+module arb_row_col #
+ (
+ parameter TCQ = 100,
+ parameter ADDR_CMD_MODE = ""1T"",
+ parameter EARLY_WR_DATA_ADDR = ""OFF"",
+ parameter nBANK_MACHS = 4,
+ parameter nCK_PER_CLK = 2,
+ parameter nCNFG2WR = 2
+ )
+ (/*AUTOARG*/
+ // Outputs
+ grant_row_r, sent_row, sending_row, grant_config_r,
+ io_config_strobe, force_io_config_rd_r1, io_config_valid_r,
+ grant_col_r, sending_col, sent_col, grant_col_wr, send_cmd0_col,
+ send_cmd1_row, cs_en0, cs_en1, insert_maint_r1,
+ // Inputs
+ clk, rst, rts_row, insert_maint_r, rts_col, rtc,
+ force_io_config_rd_r, col_rdy_wr
+ );
+
+ input clk;
+ input rst;
+
+ input [nBANK_MACHS-1:0] rts_row;
+ input insert_maint_r;
+ input [nBANK_MACHS-1:0] rts_col;
+ reg io_config_strobe_r;
+ wire block_grant_row;
+ wire block_grant_col;
+ wire io_config_kill_rts_col = (nCNFG2WR == 1) ? 1\'b0 : io_config_strobe_r;
+ wire [nBANK_MACHS-1:0] col_request;
+ wire granted_col_ns = |col_request;
+ wire [nBANK_MACHS-1:0] row_request =
+ rts_row & {nBANK_MACHS{~insert_maint_r}};
+ wire granted_row_ns = |row_request;
+ generate
+ if (ADDR_CMD_MODE == ""2T"") begin : row_col_2T_arb
+ assign col_request =
+ rts_col & {nBANK_MACHS{~(io_config_kill_rts_col || insert_maint_r)}};
+// Give column command priority whenever previous state has no row request.
+ wire [1:0] row_col_grant;
+ wire [1:0] current_master = ~granted_row_ns ? 2\'b10 : row_col_grant;
+ wire upd_last_master = ~granted_row_ns || |row_col_grant;
+ round_robin_arb #
+ (.WIDTH (2))
+ row_col_arb0
+ (.grant_ns (),
+ .grant_r (row_col_grant),
+ .upd_last_master (upd_last_master),
+ .current_master (current_master),
+ .clk (clk),
+ .rst (rst),
+ .req ({granted_row_ns, granted_col_ns}),
+ .disable_grant (1\'b0));
+ assign {block_grant_col, block_grant_row} = row_col_grant;
+ end
+ else begin : row_col_1T_arb
+ assign col_request = rts_col & {nBANK_MACHS{~io_config_kill_rts_col}};
+ assign block_grant_row = 1\'b0;
+ assign block_grant_col = 1\'b0;
+ end
+ endgenerate
+
+
+// Row address/command arbitration.
+ wire[nBANK_MACHS-1:0] grant_row_r_lcl;
+ output wire[nBANK_MACHS-1:0] grant_row_r;
+ assign grant_row_r = grant_row_r_lcl;
+ reg granted_row_r;
+ always @(posedge clk) granted_row_r <= #TCQ granted_row_ns;
+ wire sent_row_lcl = granted_row_r && ~block_grant_row;
+ output wire sent_row;
+ assign sent_row = sent_row_lcl;
+ round_robin_arb #
+ (.WIDTH (nBANK_MACHS))
+ row_arb0
+ (.grant_ns (),
+ .grant_r (grant_row_r_lcl[nBANK_MACHS-1:0]),
+ .upd_last_master (sent_row_lcl),
+ .current_master (grant_row_r_lcl[nBANK_MACHS-1:0]),
+ .clk (clk),
+ .rst (rst),
+ .req (row_request),
+ .disable_grant (1\'b0));
+
+ output wire [nBANK_MACHS-1:0] sending_row;
+ assign sending_row = grant_row_r_lcl & {nBANK_MACHS{~block_grant_row}};
+
+`ifdef MC_SVA
+ all_bank_machines_row_arb:
+ cover property (@(posedge clk) (~rst && &rts_row));
+`endif
+
+// IO config arbitration.
+ input [nBANK_MACHS-1:0] rtc;
+ wire [nBANK_MACHS-1:0] grant_config_r_lcl;
+ output wire [nBANK_MACHS-1:0] grant_config_r;
+ assign grant_config_r = grant_config_r_lcl;
+ wire upd_io_config_last_master;
+ round_robin_arb #
+ (.WIDTH (nBANK_MACHS))
+ config_arb0
+ (.grant_ns (),
+ .grant_r (grant_config_r_lcl[nBANK_MACHS-1:0]),
+ .upd_last_master (upd_io_config_last_master),
+ .current_master (grant_config_r_lcl[nBANK_MACHS-1:0]),
+ .clk (clk),
+ .rst (rst),
+ .req (rtc[nBANK_MACHS-1:0]),
+ .disable_grant (1\'b0));
+
+`ifdef MC_SVA
+ all_bank_machines_config_arb: cover property (@(posedge clk) (~rst && &rtc));
+`endif
+
+ input force_io_config_rd_r;
+ wire io_config_strobe_ns =
+ ~io_config_strobe_r && (|rtc || force_io_config_rd_r) && ~granted_col_ns;
+ always @(posedge clk) io_config_strobe_r <= #TCQ io_config_strobe_ns;
+
+ output wire io_config_strobe;
+ assign io_config_strobe = io_config_strobe_r;
+
+ reg force_io_config_rd_r1_lcl;
+ always @(posedge clk) force_io_config_rd_r1_lcl <=
+ #TCQ force_io_config_rd_r;
+
+ output wire force_io_config_rd_r1;
+ assign force_io_config_rd_r1 = force_io_config_rd_r1_lcl;
+
+ assign upd_io_config_last_master =
+ io_config_strobe_r && ~force_io_config_rd_r1_lcl;
+
+// Generate io_config_valid.
+ reg io_config_valid_r_lcl;
+ wire io_config_valid_ns;
+ assign io_config_valid_ns =
+ ~rst && (io_config_valid_r_lcl || io_config_strobe_ns);
+ always @(posedge clk) io_config_valid_r_lcl <= #TCQ io_config_valid_ns;
+ output wire io_config_valid_r;
+ assign io_config_valid_r = io_config_valid_r_lcl;
+
+// Column address/command arbitration.
+ wire [nBANK_MACHS-1:0] grant_col_r_lcl;
+ output wire [nBANK_MACHS-1:0] grant_col_r;
+ assign grant_col_r = grant_col_r_lcl;
+ reg granted_col_r;
+ always @(posedge clk) granted_col_r <= #TCQ granted_col_ns;
+ wire sent_col_lcl;
+ round_robin_arb #
+ (.WIDTH (nBANK_MACHS))
+ col_arb0
+ (.grant_ns (),
+ .grant_r (grant_col_r_lcl[nBANK_MACHS-1:0]),
+ .upd_last_master (sent_col_lcl),
+ .current_master (grant_col_r_lcl[nBANK_MACHS-1:0]),
+ .clk (clk),
+ .rst (rst),
+ .req (col_request),
+ .disable_grant (1\'b0));
+
+`ifdef MC_SVA
+ all_bank_machines_col_arb:
+ cover property (@(posedge clk) (~rst && &rts_col));
+`endif
+
+ output wire [nBANK_MACHS-1:0] sending_col;
+ assign sending_col = grant_col_r_lcl & {nBANK_MACHS{~block_grant_col}};
+ assign sent_col_lcl = granted_col_r && ~block_grant_col;
+ output wire sent_col;
+ assign sent_col = sent_col_lcl;
+
+ // If we need early wr_data_addr because ECC is on, arbitrate
+ // to see which bank machine might sent the next wr_data_addr;
+ input [nBANK_MACHS-1:0] col_rdy_wr;
+ output wire [nBANK_MACHS-1:0] grant_col_wr;
+ generate
+ if (EARLY_WR_DATA_ADDR == ""OFF"") begin : early_wr_addr_arb_off
+ assign grant_col_wr = {nBANK_MACHS{1\'b0}};
+ end
+ else begin : early_wr_addr_arb_on
+ wire [nBANK_MACHS-1:0] grant_col_wr_raw;
+ round_robin_arb #
+ (.WIDTH (nBANK_MACHS))
+ col_arb0
+ (.grant_ns (grant_col_wr_raw),
+ .grant_r (),
+ .upd_last_master (sent_col_lcl),
+ .current_master (grant_col_r_lcl[nBANK_MACHS-1:0]),
+ .clk (clk),
+ .rst (rst),
+ .req (col_rdy_wr),
+ .disable_grant (1\'b0));
+ reg [nBANK_MACHS-1:0] grant_col_wr_r;
+ wire [nBANK_MACHS-1:0] grant_col_wr_ns = granted_col_ns
+ ? grant_col_wr_raw
+ : grant_col_wr_r;
+ always @(posedge clk) grant_col_wr_r <= #TCQ grant_col_wr_ns;
+ assign grant_col_wr = grant_col_wr_ns;
+ end // block: early_wr_addr_arb_on
+ endgenerate
+
+ output reg send_cmd0_col = 1\'b0;
+ output reg send_cmd1_row = 1\'b0;
+
+ output reg cs_en0 = 1\'b0;
+ output reg cs_en1 = 1\'b0;
+
+ reg insert_maint_r1_lcl;
+ always @(posedge clk) insert_maint_r1_lcl <= #TCQ insert_maint_r;
+ output wire insert_maint_r1;
+ assign insert_maint_r1 = insert_maint_r1_lcl;
+
+ wire sent_row_or_maint = sent_row_lcl || insert_maint_r1_lcl;
+ generate
+ case ({(nCK_PER_CLK == 2), (ADDR_CMD_MODE == ""2T"")})
+ 2\'b00 : begin : one_one_not2T
+ end
+ 2\'b01 : begin : one_one_2T
+ end
+ 2\'b10 : begin : two_one_not2T
+ always @(/*AS*/sent_row_or_maint) cs_en0 = sent_row_or_maint;
+ always @(/*AS*/sent_col_lcl) cs_en1 = sent_col_lcl;
+ end
+ 2\'b11 : begin : two_one_2T
+ always @(/*AS*/sent_col_lcl or sent_row_or_maint) cs_en1 = sent_row_or_maint || sent_col_lcl;
+ always @(/*AS*/sent_col_lcl) send_cmd0_col = sent_col_lcl;
+ always @(/*AS*/sent_row_or_maint) send_cmd1_row = sent_row_or_maint;
+ end
+ endcase
+ endgenerate
+
+
+
+endmodule
+
+"
+"// file: system_mon.v
+// (c) Copyright 2009 - 2011 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+`timescale 1ns / 1 ps
+
+(* CORE_GENERATION_INFO = ""system_mon,xadc_wiz_v2_1,{component_name=system_mon,dclk_frequency=50,enable_busy=false,enable_convst=false,enable_convstclk=false,enable_dclk=true,enable_drp=true,enable_eoc=false,enable_eos=false,enable_vbram_alaram=false,enable_vccddro_alaram=false,enable_vccpaux_alaram=false,enable_Vccint_Alaram=false,enable_Vccaux_alaram=false,enable_vccpint_alaram=false,ot_alaram=false,user_temp_alaram=false,timing_mode=continuous,channel_averaging=256,sequencer_mode=on,startup_channel_selection=contineous_sequence}"" *)
+
+
+module sys_mon
+ (
+ DADDR_IN, // Address bus for the dynamic reconfiguration port
+ DCLK_IN, // Clock input for the dynamic reconfiguration port
+ DEN_IN, // Enable Signal for the dynamic reconfiguration port
+ DI_IN, // Input data bus for the dynamic reconfiguration port
+ DWE_IN, // Write Enable for the dynamic reconfiguration port
+ VAUXP12, // Auxiliary channel 12
+ VAUXN12,
+ VAUXP13, // Auxiliary channel 13
+ VAUXN13,
+ DO_OUT, // Output data bus for dynamic reconfiguration port
+ DRDY_OUT, // Data ready signal for the dynamic reconfiguration port
+ ALARM_OUT, // OR\'ed output of all the Alarms
+ VP_IN, // Dedicated Analog Input Pair
+ VN_IN);
+
+ input [6:0] DADDR_IN;
+ input DCLK_IN;
+ input DEN_IN;
+ input [15:0] DI_IN;
+ input DWE_IN;
+ input VAUXP12;
+ input VAUXN12;
+ input VAUXP13;
+ input VAUXN13;
+ input VP_IN;
+ input VN_IN;
+
+ output reg [15:0] DO_OUT;
+ output reg DRDY_OUT;
+ output ALARM_OUT;
+\t\t\t
+\t\t\t
+\t\t\t always @(posedge DCLK_IN)
+\t\t\t begin
+\t\t\t DO_OUT <= 16\'h0000;
+\t\t\t\t DRDY_OUT <= DEN_IN;
+\t\t\t end
+
+ /*wire FLOAT_VCCAUX;
+ wire FLOAT_VCCINT;
+ wire FLOAT_TEMP;
+ wire GND_BIT;
+ wire [2:0] GND_BUS3;
+ assign GND_BIT = 0;
+ wire [15:0] aux_channel_p;
+ wire [15:0] aux_channel_n;
+ wire [7:0] alm_int;
+ assign ALARM_OUT = alm_int[7];
+ assign aux_channel_p[0] = 1\'b0;
+ assign aux_channel_n[0] = 1\'b0;
+
+ assign aux_channel_p[1] = 1\'b0;
+ assign aux_channel_n[1] = 1\'b0;
+
+ assign aux_channel_p[2] = 1\'b0;
+ assign aux_channel_n[2] = 1\'b0;
+
+ assign aux_channel_p[3] = 1\'b0;
+ assign aux_channel_n[3] = 1\'b0;
+
+ assign aux_channel_p[4] = 1\'b0;
+ assign aux_channel_n[4] = 1\'b0;
+
+ assign aux_channel_p[5] = 1\'b0;
+ assign aux_channel_n[5] = 1\'b0;
+
+ assign aux_channel_p[6] = 1\'b0;
+ assign aux_channel_n[6] = 1\'b0;
+
+ assign aux_channel_p[7] = 1\'b0;
+ assign aux_channel_n[7] = 1\'b0;
+
+ assign aux_channel_p[8] = 1\'b0;
+ assign aux_channel_n[8] = 1\'b0;
+
+ assign aux_channel_p[9] = 1\'b0;
+ assign aux_channel_n[9] = 1\'b0;
+
+ assign aux_channel_p[10] = 1\'b0;
+ assign aux_channel_n[10] = 1\'b0;
+
+ assign aux_channel_p[11] = 1\'b0;
+ assign aux_channel_n[11] = 1\'b0;
+
+ assign aux_channel_p[12] = VAUXP12;
+ assign aux_channel_n[12] = VAUXN12;
+
+ assign aux_channel_p[13] = VAUXP13;
+ assign aux_channel_n[13] = VAUXN13;
+
+ assign aux_channel_p[14] = 1\'b0;
+ assign aux_channel_n[14] = 1\'b0;
+
+ assign aux_channel_p[15] = 1\'b0;
+ assign aux_channel_n[15] = 1\'b0;
+XADC #(
+ .INIT_40(16\'h3000), // config reg 0
+ .INIT_41(16\'h2f0f), // config reg 1
+ .INIT_42(16\'h0a00), // config reg 2
+ .INIT_48(16\'h0f00), // Sequencer channel selection
+ .INIT_49(16\'h3000), // Sequencer channel selection
+ .INIT_4A(16\'h0e00), // Sequencer Average selection
+ .INIT_4B(16\'h3000), // Sequencer Average selection
+ .INIT_4C(16\'h0000), // Sequencer Bipolar selection
+ .INIT_4D(16\'h0000), // Sequencer Bipolar selection
+ .INIT_4E(16\'h0000), // Sequencer Acq time selection
+ .INIT_4F(16\'h0000), // Sequencer Acq time selection
+ .INIT_50(16\'hb5ed), // Temp alarm trigger
+ .INIT_51(16\'h57e4), // Vccint upper alarm limit
+ .INIT_52(16\'ha147), // Vccaux upper alarm limit
+ .INIT_53(16\'hca33), // Temp alarm OT upper
+ .INIT_54(16\'ha93a), // Temp alarm reset
+ .INIT_55(16\'h52c6), // Vccint lower alarm limit
+ .INIT_56(16\'h9555), // Vccaux lower alarm limit
+ .INIT_57(16\'hae4e), // Temp alarm OT reset
+ .INIT_58(16\'h5999), // VBRAM upper alarm limit
+ .INIT_5C(16\'h5111), // VBRAM lower alarm limit
+ .SIM_DEVICE(""7SERIES""),
+ .SIM_MONITOR_FILE(""system_mon.txt"")
+)
+
+XADC_INST (
+ .CONVST(GND_BIT),
+ .CONVSTCLK(GND_BIT),
+ .DADDR(DADDR_IN[6:0]),
+ .DCLK(DCLK_IN),
+ .DEN(DEN_IN),
+ .DI(DI_IN[15:0]),
+ .DWE(DWE_IN),
+ .RESET(GND_BIT),
+ .VAUXN(aux_channel_n[15:0]),
+ .VAUXP(aux_channel_p[15:0]),
+ .ALM(alm_int),
+ .BUSY(),
+ .CHANNEL(),
+ .DO(DO_OUT[15:0]),
+ .DRDY(DRDY_OUT),
+ .EOC(),
+ .EOS(),
+ .JTAGBUSY(),
+ .JTAGLOCKED(),
+ .JTAGMODIFIED(),
+ .OT(),
+ .MUXADDR(),
+ .VP(VP_IN),
+ .VN(VN_IN)
+ );*/
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2009 - 2010 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor: Xilinx
+// \\ \\ \\/ Version: 3.91
+// \\ \\ Application: MIG
+// / / Filename: phy_rdctrl_sync.v
+// /___/ /\\ Date Last Modified: $Date: 2011/06/02 07:18:04 $
+// \\ \\ / \\ Date Created: Aug 03 2009
+// \\___\\/\\___\\
+//
+//Device: Virtex-6
+//Design Name: DDR3 SDRAM
+//Purpose:
+//Purpose:
+// Synchronization of read control signal from MC/PHY rdlvl logic (clk) to
+// read capture logic (clk_rsync) clock domain. Also adds additional delay
+// to account for read latency
+//Reference:
+//Revision History:
+//*****************************************************************************
+
+/******************************************************************************
+**$Id: phy_rdctrl_sync.v,v 1.1 2011/06/02 07:18:04 mishra Exp $
+**$Date: 2011/06/02 07:18:04 $
+**$Author: mishra $
+**$Revision: 1.1 $
+**$Source: /devl/xcs/repo/env/Databases/ip/src2/O/mig_v3_9/data/dlib/virtex6/ddr3_sdram/verilog/rtl/phy/phy_rdctrl_sync.v,v $
+******************************************************************************/
+
+`timescale 1ps/1ps
+
+module phy_rdctrl_sync #
+ (
+ parameter TCQ = 100
+ )
+ (
+ input clk,
+ input rst_rsync, // Use only CLK_RSYNC[0] reset
+ // Control for control sync logic
+ input mc_data_sel,
+ input [4:0] rd_active_dly,
+ // DFI signals from MC/PHY rdlvl logic
+ input dfi_rddata_en,
+ input phy_rddata_en,
+ // Control for read logic, initialization logic
+ output reg dfi_rddata_valid,
+ output reg dfi_rddata_valid_phy,
+ output reg rdpath_rdy // asserted when read path
+ // ready for use
+ );
+
+ // # of clock cycles after RST_RSYNC has deasserted before init/cal logic
+ // is taken out of reset. This is only needed for simulation when the ""no
+ // init/no cal"" option is selected. In this case, PHY_INIT will assert
+ // DFI_INIT_COMPLETE signal almost instantaneously once it is taken out
+ // of reset - however, there are certain pipe stages that must ""flush
+ // out"" (related to circular buffer synchronization) for a few cycles after
+ // RST_RSYNC is deasserted - in particular, the one related to generating
+ // DFI_RDDATA_VALID must not drive an unknown value on the bus after
+ // DFI_INIT_COMPLETE is asserted.
+ // NOTE: # of cycles of delay required depends on the circular buffer
+ // depth for RD_ACTIVE - it should >= (0.5*depth + 1)
+ localparam RDPATH_RDY_DLY = 10;
+
+ wire rddata_en;
+ wire rddata_en_rsync;
+ wire rddata_en_srl_out;
+ reg [RDPATH_RDY_DLY-1:0] rdpath_rdy_dly_r;
+
+ //***************************************************************************
+ // Delay RDDATA_EN by an amount determined during read-leveling
+ // calibration to reflect the round trip delay from command issuance until
+ // when read data is returned
+ //***************************************************************************
+
+ assign rddata_en = (mc_data_sel) ? dfi_rddata_en : phy_rddata_en;
+
+ // May need to flop output of SRL for better timing
+ SRLC32E u_rddata_en_srl
+ (
+ .Q (rddata_en_srl_out),
+ .Q31 (),
+ .A (rd_active_dly),
+ .CE (1\'b1),
+ .CLK (clk),
+ .D (rddata_en)
+ );
+
+ // Flop once more for better timing
+ always @(posedge clk) begin
+ // Only assert valid on DFI bus after initialization complete
+ dfi_rddata_valid <= #TCQ rddata_en_srl_out & mc_data_sel;
+ // Assert valid for PHY during initialization
+ dfi_rddata_valid_phy <= #TCQ rddata_en_srl_out;
+ end
+
+ //***************************************************************************
+ // Generate a signal that tells initialization logic that read path is
+ // ready for use (i.e. for read leveling). Use RST_RSYNC, and delay it by
+ // RDPATH_RDY_DLY clock cycles, then synchronize to CLK domain.
+ // NOTE: This logic only required for simulation; for final h/w, there will
+ // always be a long delay between RST_RSYNC deassertion and
+ // DFI_INIT_COMPLETE assertion (for DRAM init, and leveling)
+ //***************************************************************************
+
+ // First delay by X number of clock cycles to guarantee that RDPATH_RDY
+ // isn\'t asserted too soon after RST_RSYNC is deasserted (to allow various
+ // synchronization pipe stages to ""flush""). NOTE: Only RST_RSYNC[0] (or
+ // any of the up to 4 RST_RSYNC\'s) is used - any of them is sufficient
+ // close enough in timing to use
+ always @(posedge clk or posedge rst_rsync) begin
+ if (rst_rsync)
+ rdpath_rdy_dly_r <= #TCQ {{RDPATH_RDY_DLY}{1\'b0}};
+ else
+ rdpath_rdy_dly_r[RDPATH_RDY_DLY-1:1]
+ <= #TCQ {rdpath_rdy_dly_r[RDPATH_RDY_DLY-2:0], 1\'b1};
+ end
+
+ // Flop once more to prevent ISE tools from analyzing asynchronous path
+ // through this flop to receiving logic
+ always @(posedge clk)
+ rdpath_rdy <= rdpath_rdy_dly_r[RDPATH_RDY_DLY-1];
+
+endmodule
+"
+"//*****************************************************************************
+// (c) Copyright 2008-2009 Xilinx, Inc. All rights reserved.
+//
+// This file contains confidential and proprietary information
+// of Xilinx, Inc. and is protected under U.S. and
+// international copyright and other intellectual property
+// laws.
+//
+// DISCLAIMER
+// This disclaimer is not a license and does not grant any
+// rights to the materials distributed herewith. Except as
+// otherwise provided in a valid license issued to you by
+// Xilinx, and to the maximum extent permitted by applicable
+// law: (1) THESE MATERIALS ARE MADE AVAILABLE ""AS IS"" AND
+// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+// (2) Xilinx shall not be liable (whether in contract or tort,
+// including negligence, or under any other theory of
+// liability) for any loss or damage of any kind or nature
+// related to, arising under or in connection with these
+// materials, including for any direct, or any indirect,
+// special, incidental, or consequential loss or damage
+// (including loss of data, profits, goodwill, or any type of
+// loss or damage suffered as a result of any action brought
+// by a third party) even if such damage or loss was
+// reasonably foreseeable or Xilinx had been advised of the
+// possibility of the same.
+//
+// CRITICAL APPLICATIONS
+// Xilinx products are not designed or intended to be fail-
+// safe, or for use in any application requiring fail-safe
+// performance, such as life-support or safety devices or
+// systems, Class III medical devices, nuclear facilities,
+// applications related to the deployment of airbags, or any
+// other applications that could lead to death, personal
+// injury, or severe property or environmental damage
+// (individually and collectively, ""Critical
+// Applications""). Customer assumes the sole risk and
+// liability of any use of Xilinx products in Critical
+// Applications, subject only to applicable laws and
+// regulations governing limitations on product liability.
+//
+// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+// PART OF THIS FILE AT ALL TIMES.
+//
+//*****************************************************************************
+// ____ ____
+// / /\\/ /
+// /___/ \\ / Vendor : Xilinx
+// \\ \\ \\/ Version : 3.91
+// \\ \\ Application : MIG
+// / / Filename : ui_rd_data.v
+// /___/ /\\ Date Last Modified : $date$
+// \\ \\ / \\ Date Created : Tue Jun 30 2009
+// \\___\\/\\___\\
+//
+//Device : Virtex-6
+//Design Name : DDR3 SDRAM
+//Purpose :
+//Reference :
+//Revision History :
+//*****************************************************************************
+
+// User interface read buffer. Re orders read data returned from the
+// memory controller back to the request order.
+//
+// Consists of a large buffer for the data, a status RAM and two counters.
+//
+// The large buffer is implemented with distributed RAM in 6 bit wide,
+// 1 read, 1 write mode. The status RAM is implemented with a distributed
+// RAM configured as 2 bits wide 1 read/write, 1 read mode.
+//
+// As read requests are received from the application, the data_buf_addr
+// counter supplies the data_buf_addr sent into the memory controller.
+// With each read request, the counter is incremented, eventually rolling
+// over. This mechanism labels each read request with an incrementing number.
+//
+// When the memory controller returns read data, it echos the original
+// data_buf_addr with the read data.
+//
+// The status RAM is indexed with the same address as the data buffer
+// RAM. Each word of the data buffer RAM has an associated status bit
+// and ""end"" bit. Requests of size 1 return a data burst on two consecutive
+// states. Requests of size zero return with a single assertion of rd_data_en.
+//
+// Upon returning data, the status and end bits are updated for each
+// corresponding location in the status RAM indexed by the data_buf_addr
+// echoed on the rd_data_addr field.
+//
+// The other side of the status and data RAMs is indexed by the rd_buf_indx.
+// The rd_buf_indx constantly monitors the status bit it is currently
+// pointing to. When the status becomes set to the proper state (more on
+// this later) read data is returned to the application, and the rd_buf_indx
+// is incremented.
+//
+// At rst the rd_buf_indx is initialized to zero. Data will not have been
+// returned from the memory controller yet, so there is nothing to return
+// to the application. Evenutally, read requests will be made, and the
+// memory controller will return the corresponding data. The memory
+// controller may not return this data in the request order. In which
+// case, the status bit at location zero, will not indicate
+// the data for request zero is ready. Eventually, the memory controller
+// will return data for request zero. The data is forwarded on to the
+// application, and rd_buf_indx is incremented to point to the next status
+// bits and data in the buffers. The status bit will be examined, and if
+// data is valid, this data will be returned as well. This process
+// continues until the status bit indexed by rd_buf_indx indicates data
+// is not ready. This may be because the rd_data_buf
+// is empty, or that some data was returned out of order. Since rd_buf_indx
+// always increments sequentially, data is always returned to the application
+// in request order.
+//
+// Some further discussion of the status bit is in order. The rd_data_buf
+// is a circular buffer. The status bit is a single bit. Distributed RAM
+// supports only a single write port. The write port is consumed by
+// memory controller read data updates. If a simple \'1\' were used to
+// indicate the status, when rd_data_indx rolled over it would immediately
+// encounter a one for a request that may not be ready.
+//
+// This problem is solved by causing read data returns to flip the
+// status bit, and adding hi order bit beyond the size required to
+// index the rd_data_buf. Data is considered ready when the status bit
+// and this hi order bit are equal.
+//
+// The status RAM needs to be initialized to zero after reset. This is
+// accomplished by cycling through all rd_buf_indx valus and writing a
+// zero to the status bits directly following deassertion of reset. This
+// mechanism is used for similar purposes
+// for the wr_data_buf.
+//
+// When ORDERING == ""STRICT"", read data reordering is unnecessary. For thi
+// case, most of the logic in the block is not generated.
+
+`timescale 1 ps / 1 ps
+
+// User interface read data.
+
+module ui_rd_data #
+ (
+ parameter TCQ = 100,
+ parameter APP_DATA_WIDTH = 256,
+ parameter ECC = ""OFF"",
+ parameter ORDERING = ""NORM""
+ )
+ (/*AUTOARG*/
+ // Outputs
+ ram_init_done_r, ram_init_addr, app_rd_data_valid, app_rd_data_end,
+ app_rd_data, app_ecc_multiple_err, rd_buf_full, rd_data_buf_addr_r,
+ // Inputs
+ rst, clk, rd_data_en, rd_data_addr, rd_data_offset, rd_data_end,
+ rd_data, ecc_multiple, rd_accepted
+ );
+
+ input rst;
+ input clk;
+
+ output wire ram_init_done_r;
+ output wire [3:0] ram_init_addr;
+
+// rd_buf_indx points to the status and data storage rams for
+// reading data out to the app.
+ reg [5:0] rd_buf_indx_r;
+ reg ram_init_done_r_lcl;
+ assign ram_init_done_r = ram_init_done_r_lcl;
+ wire app_rd_data_valid_ns;
+ wire single_data;
+ reg [5:0] rd_buf_indx_ns;
+ generate begin : rd_buf_indx
+ wire upd_rd_buf_indx = ~ram_init_done_r_lcl || app_rd_data_valid_ns;
+// Loop through all status write addresses once after rst. Initializes
+// the status and pointer RAMs.
+ wire ram_init_done_ns =
+ ~rst && (ram_init_done_r_lcl || (rd_buf_indx_r[4:0] == 5\'h1f));
+ always @(posedge clk) ram_init_done_r_lcl <= #TCQ ram_init_done_ns;
+
+ always @(/*AS*/rd_buf_indx_r or rst or single_data
+ or upd_rd_buf_indx) begin
+ rd_buf_indx_ns = rd_buf_indx_r;
+ if (rst) rd_buf_indx_ns = 6\'b0;
+ else if (upd_rd_buf_indx) rd_buf_indx_ns =
+ rd_buf_indx_r + 6\'h1 + single_data;
+ end
+ always @(posedge clk) rd_buf_indx_r <= #TCQ rd_buf_indx_ns;
+ end
+ endgenerate
+ assign ram_init_addr = rd_buf_indx_r[3:0];
+
+ input rd_data_en;
+ input [3:0] rd_data_addr;
+ input rd_data_offset;
+ input rd_data_end;
+ input [APP_DATA_WIDTH-1:0] rd_data;
+ output reg app_rd_data_valid;
+ output reg app_rd_data_end;
+ output reg [APP_DATA_WIDTH-1:0] app_rd_data;
+ input [3:0] ecc_multiple;
+ reg [3:0] app_ecc_multiple_err_r = 4\'b0;
+ output wire [3:0] app_ecc_multiple_err;
+ assign app_ecc_multiple_err = app_ecc_multiple_err_r;
+ input rd_accepted;
+ output wire rd_buf_full;
+ output wire [3:0] rd_data_buf_addr_r;
+
+// Compute dimensions of read data buffer. Depending on width of
+// DQ bus and DRAM CK
+// to fabric ratio, number of RAM32Ms is variable. RAM32Ms are used in
+// single write, single read, 6 bit wide mode.
+ localparam RD_BUF_WIDTH = APP_DATA_WIDTH + (ECC == ""OFF"" ? 0 : 4);
+ localparam FULL_RAM_CNT = (RD_BUF_WIDTH/6);
+ localparam REMAINDER = RD_BUF_WIDTH % 6;
+ localparam RAM_CNT = FULL_RAM_CNT + ((REMAINDER == 0 ) ? 0 : 1);
+ localparam RAM_WIDTH = (RAM_CNT*6);
+ generate
+ if (ORDERING == ""STRICT"") begin : strict_mode
+ assign app_rd_data_valid_ns = 1\'b0;
+ assign single_data = 1\'b0;
+ assign rd_buf_full = 1\'b0;
+ reg [3:0] rd_data_buf_addr_r_lcl;
+ wire [3:0] rd_data_buf_addr_ns =
+ rst
+ ? 4\'b0
+ : rd_data_buf_addr_r_lcl + {3\'b0, rd_accepted};
+ always @(posedge clk) rd_data_buf_addr_r_lcl <=
+ #TCQ rd_data_buf_addr_ns;
+ assign rd_data_buf_addr_r = rd_data_buf_addr_ns;
+// app_* signals required to be registered.
+ if (ECC == ""OFF"") begin : ecc_off
+ always @(/*AS*/rd_data) app_rd_data = rd_data;
+ always @(/*AS*/rd_data_en) app_rd_data_valid = rd_data_en;
+ always @(/*AS*/rd_data_end) app_rd_data_end = rd_data_end;
+ end
+ else begin : ecc_on
+ always @(posedge clk) app_rd_data <= #TCQ rd_data;
+ always @(posedge clk) app_rd_data_valid <= #TCQ rd_data_en;
+ always @(posedge clk) app_rd_data_end <= #TCQ rd_data_end;
+ always @(posedge clk) app_ecc_multiple_err_r <= #TCQ ecc_multiple;
+ end
+ end
+ else begin : not_strict_mode
+ wire rd_buf_we = ~ram_init_done_r_lcl || rd_data_en;
+ wire [4:0] rd_buf_wr_addr = {rd_data_addr, rd_data_offset};
+ wire [1:0] rd_status;
+// Instantiate status RAM. One bit for status and one for ""end"".
+ begin : status_ram
+// Turns out read to write back status is a timing path. Update
+// the status in the ram on the state following the read. Bypass
+// the write data into the status read path.
+ wire [4:0] status_ram_wr_addr_ns = ram_init_done_r_lcl
+ ? rd_buf_wr_addr
+ : rd_buf_indx_r[4:0];
+ reg [4:0] status_ram_wr_addr_r;
+ always @(posedge clk) status_ram_wr_addr_r <=
+ #TCQ status_ram_wr_addr_ns;
+ wire [1:0] wr_status;
+// Not guaranteed to write second status bit. If it is written, always
+// copy in the first status bit.
+ reg wr_status_r1;
+ always @(posedge clk) wr_status_r1 <= #TCQ wr_status[0];
+ wire [1:0] status_ram_wr_data_ns =
+ ram_init_done_r_lcl
+ ? {rd_data_end, ~(rd_data_offset
+ ? wr_status_r1
+ : wr_status[0])}
+ : 2\'b0;
+ reg [1:0] status_ram_wr_data_r;
+ always @(posedge clk) status_ram_wr_data_r <=
+ #TCQ status_ram_wr_data_ns;
+ reg rd_buf_we_r1;
+ always @(posedge clk) rd_buf_we_r1 <= #TCQ rd_buf_we;
+ RAM32M
+ #(.INIT_A(64\'h0000000000000000),
+ .INIT_B(64\'h0000000000000000),
+ .INIT_C(64\'h0000000000000000),
+ .INIT_D(64\'h0000000000000000)
+ ) RAM32M0 (
+ .DOA(rd_status),
+ .DOB(),
+ .DOC(wr_status),
+ .DOD(),
+ .DIA(status_ram_wr_data_r),
+ .DIB(2\'b0),
+ .DIC(status_ram_wr_data_r),
+ .DID(status_ram_wr_data_r),
+ .ADDRA(rd_buf_indx_r[4:0]),
+ .ADDRB(5\'b0),
+ .ADDRC(status_ram_wr_addr_ns),
+ .ADDRD(status_ram_wr_addr_r),
+ .WE(rd_buf_we_r1),
+ .WCLK(clk)
+ );
+ end // block: status_ram
+
+ wire [RAM_WIDTH-1:0] rd_buf_out_data;
+ begin : rd_buf
+ wire [RAM_WIDTH-1:0] rd_buf_in_data;
+ if (REMAINDER == 0)
+ if (ECC == ""OFF"")
+ assign rd_buf_in_data = rd_data;
+ else
+ assign rd_buf_in_data = {ecc_multiple, rd_data};
+ else
+ if (ECC == ""OFF"")
+ assign rd_buf_in_data = {{6-REMAINDER{1\'b0}}, rd_data};
+ else
+ assign rd_buf_in_data =
+ {{6-REMAINDER{1\'b0}}, ecc_multiple, rd_data};
+
+ // Dedicated copy for driving distributed RAM.
+ (* equivalent_register_removal = ""no"" *)
+ reg [4:0] rd_buf_indx_copy_r;
+ always @(posedge clk) rd_buf_indx_copy_r <= #TCQ rd_buf_indx_ns[4:0];
+
+ genvar i;
+ for (i=0; i